Search in sources :

Example 11 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class CfmMdDeleteCommand method doExecute.

@Override
protected void doExecute() {
    CfmMdService service = get(CfmMdService.class);
    String[] nameParts = name.split("[()]");
    if (nameParts.length != 2) {
        throw new IllegalArgumentException("Invalid name format. " + "Must be in the format of <identifier(name-type)>");
    }
    MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
    try {
        boolean deleted = service.deleteMaintenanceDomain(mdId);
        print("Maintenance Domain %s is %ssuccessfully deleted.", mdId, deleted ? "" : "NOT ");
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)

Example 12 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class CfmMepManager method createMep.

@Override
public boolean createMep(MdId mdName, MaIdShort maName, Mep newMep) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, newMep.mepId());
    log.debug("Creating MEP " + newMep.mepId() + " on MD {}, MA {} on Device {}", mdName, maName, newMep.deviceId().toString());
    if (mepStore.getMep(key).isPresent()) {
        return false;
    }
    // Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);
    DeviceId mepDeviceId = newMep.deviceId();
    if (deviceService.getDevice(mepDeviceId) == null) {
        throw new CfmConfigException("Device not found " + mepDeviceId);
    } else if (!deviceService.getDevice(mepDeviceId).is(CfmMepProgrammable.class)) {
        throw new CfmConfigException("Device " + mepDeviceId + " does not support CfmMepProgrammable behaviour.");
    }
    boolean deviceResult = deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).createMep(mdName, maName, newMep);
    log.debug("MEP created on {}", mepDeviceId);
    if (deviceResult) {
        boolean alreadyExisted = mepStore.createUpdateMep(key, newMep);
        // Add to other Remote Mep List on other devices
        for (Mep mep : mepStore.getMepsByMdMa(mdName, maName)) {
            List<DeviceId> alreadyHandledDevices = new ArrayList<>();
            if (mep.deviceId().equals(mepDeviceId) || alreadyHandledDevices.contains(mep.deviceId())) {
                continue;
            }
            boolean created = deviceService.getDevice(mep.deviceId()).as(CfmMepProgrammable.class).createMaRemoteMepOnDevice(mdName, maName, newMep.mepId());
            alreadyHandledDevices.add(mep.deviceId());
            log.info("Created RMep entry on {} on device {}", mdName.mdName() + "/" + maName.maName(), mep.deviceId());
        }
        return !alreadyExisted;
    } else {
        return deviceResult;
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) CfmMepProgrammable(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable) ArrayList(java.util.ArrayList) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)

Example 13 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class CfmMepManager method processDeviceRemoved.

/**
 * This removes a MEP from the internal list of Meps, and updates remote meps list on other Meps.
 * Note: This does not call the device's CfmMepProgrammable, because there
 * would be no point as the device has already been removed from ONOS.
 * The configuration for this MEP may still be present on the actual device, and
 * any future config would have to be careful to wipe the Mep from the device
 * before applying a Mep again
 * @param removedDevice The device that has been removed
 */
protected void processDeviceRemoved(Device removedDevice) {
    log.warn("Remove Mep(s) associated with Device: " + removedDevice.id());
    Collection<Mep> mepListForDevice = mepStore.getMepsByDeviceId(removedDevice.id());
    for (Mep mep : mepStore.getAllMeps()) {
        for (Mep mepForDevice : mepListForDevice) {
            if (mep.mdId().equals(mepForDevice.mdId()) && mep.maId().equals(mepForDevice.maId())) {
                Device mepDevice = deviceService.getDevice(mep.deviceId());
                log.info("Removing Remote Mep {} from MA{} on device {}", mepForDevice.mepId(), mep.mdId().mdName() + "/" + mep.maId().maName(), mepDevice.id());
                try {
                    mepDevice.as(CfmMepProgrammable.class).deleteMaRemoteMepOnDevice(mep.mdId(), mep.maId(), mepForDevice.mepId());
                } catch (CfmConfigException e) {
                    log.error("Error when removing Remote Mep {} from MA {}. Continuing.", mep.mdId().mdName() + "/" + mep.maId().maName(), mepForDevice.mepId());
                }
            }
        }
    }
    for (Iterator<Mep> iter = mepListForDevice.iterator(); iter.hasNext(); ) {
        mepStore.deleteMep(new MepKeyId(iter.next()));
    }
}
Also used : Device(org.onosproject.net.Device) CfmMepProgrammable(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)

Example 14 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class CfmMepManager method processMaRemoved.

protected void processMaRemoved(MdId mdId, MaIdShort maId, MaintenanceDomain oldMd) {
    Set<DeviceId> deviceIdsRemoved = new HashSet<>();
    for (Iterator<Mep> iter = mepStore.getMepsByMdMa(mdId, maId).iterator(); iter.hasNext(); ) {
        Mep mepForMdMa = iter.next();
        DeviceId mepDeviceId = mepForMdMa.deviceId();
        try {
            deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).deleteMep(mdId, maId, mepForMdMa.mepId(), Optional.of(oldMd));
            deviceIdsRemoved.add(mepDeviceId);
        } catch (CfmConfigException e) {
            log.warn("Could not delete MEP {} from Device {}", mepForMdMa.mepId(), mepDeviceId, e);
        }
        iter.remove();
        log.info("Removed MEP {} from Device {} because MA {} was deleted", mepForMdMa.mepId(), mepDeviceId, mdId.mdName() + "/" + maId.maName());
    }
    deviceIdsRemoved.forEach(deviceId -> {
        try {
            deviceService.getDevice(deviceId).as(CfmMepProgrammable.class).deleteMaOnDevice(mdId, maId, Optional.of(oldMd));
        } catch (CfmConfigException e) {
            log.warn("Could not delete MA {} from Device {}", mdId.mdName() + "/" + maId.maName(), deviceId, e);
        }
    });
}
Also used : DeviceId(org.onosproject.net.DeviceId) CfmMepProgrammable(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) HashSet(java.util.HashSet)

Example 15 with CfmConfigException

use of org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException in project onos by opennetworkinglab.

the class CfmMepManager method processMdRemoved.

protected void processMdRemoved(MdId mdId, MaintenanceDomain oldMd) {
    Set<DeviceId> deviceIdsRemoved = new HashSet<>();
    for (Iterator<Mep> iter = mepStore.getMepsByMd(mdId).iterator(); iter.hasNext(); ) {
        Mep mep = iter.next();
        DeviceId mepDeviceId = mep.deviceId();
        try {
            deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).deleteMep(mdId, mep.maId(), mep.mepId(), Optional.of(oldMd));
            deviceIdsRemoved.add(mepDeviceId);
        } catch (CfmConfigException e) {
            log.warn("Could not delete MEP {} from Device {}", mep.mepId(), mepDeviceId, e);
        }
        iter.remove();
        log.info("Removed MEP {} from Device {} because MD {} was deleted", mep.mepId(), mepDeviceId, mdId.mdName());
    }
    deviceIdsRemoved.forEach(deviceId -> {
        try {
            deviceService.getDevice(deviceId).as(CfmMepProgrammable.class).deleteMdOnDevice(mdId, Optional.of(oldMd));
        } catch (CfmConfigException e) {
            log.warn("Could not delete MD {} from Device {}", mdId.mdName(), deviceId, e);
        }
    });
}
Also used : DeviceId(org.onosproject.net.DeviceId) CfmMepProgrammable(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) HashSet(java.util.HashSet)

Aggregations

CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)50 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)27 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)23 Consumes (javax.ws.rs.Consumes)22 Produces (javax.ws.rs.Produces)22 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)17 Path (javax.ws.rs.Path)14 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)14 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)13 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)12 DeviceId (org.onosproject.net.DeviceId)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 MepEntry (org.onosproject.incubator.net.l2monitoring.cfm.MepEntry)9 CfmMepProgrammable (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 GET (javax.ws.rs.GET)7 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)7 MepKeyId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)7 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)6