Search in sources :

Example 1 with MepKeyId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId 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 2 with MepKeyId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId in project onos by opennetworkinglab.

the class CfmMepManager method getMep.

@Override
public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, mepId);
    // Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);
    Optional<Mep> mepOptional = mepStore.getMep(key);
    if (mepOptional.isPresent()) {
        Mep mep = mepOptional.get();
        DeviceId mepDeviceId = mep.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.");
        }
        log.debug("Retrieving MEP reults for Mep {} in MD {}, MA {} on Device {}", mep.mepId(), mdName, maName, mepDeviceId);
        return deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).getMep(mdName, maName, mepId);
    } else {
        return null;
    }
}
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) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)

Example 3 with MepKeyId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId 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 4 with MepKeyId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId in project onos by opennetworkinglab.

the class CfmMepListCommand method doExecute.

@Override
protected void doExecute() {
    CfmMepService mepService = get(CfmMepService.class);
    CfmMdService mdService = get(CfmMdService.class);
    if (mdStr != null && !mdStr.isEmpty()) {
        MdId mdId = parseMdName(mdStr);
        print(printMdId(mdId));
        if (maStr != null && !maStr.isEmpty()) {
            MaIdShort maId = parseMaName(maStr);
            print(printMaId(maId));
            if (mepStr != null && !mepStr.isEmpty()) {
                MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
                try {
                    MepEntry mep = mepService.getMep(mdId, maId, mepId);
                    if (mep != null) {
                        print(printMepEntry(mep));
                    }
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Mep details {}", new MepKeyId(mdId, maId, mepId), e);
                }
            // MD, MA and MEP given
            } else {
                // MD and MA given but no MEP given
                try {
                    mepService.getAllMeps(mdId, maId).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), maId.maName(), e);
                }
            }
        } else {
            // MD given but no MA given
            mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), ma.maId().maName(), e);
                }
            });
        }
    } else {
        mdService.getAllMaintenanceDomain().forEach(md -> {
            print(printMdId(md.mdId()));
            mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", md.mdId().mdName(), ma.maId().maName(), e);
                }
            });
        });
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 5 with MepKeyId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId in project onos by opennetworkinglab.

the class CfmMepManagerTest method setup.

@Before
public void setup() throws CfmConfigException {
    mepManager = new CfmMepManager();
    mepStore = new DistributedMepStore();
    storageService = new MockStorageService();
    ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
    ma2 = DefaultMaintenanceAssociation.builder(MANAME2, MDNAME2.getNameLength()).build();
    TestUtils.setField(mepStore, "storageService", storageService);
    ((DistributedMepStore) mepStore).activate();
    TestUtils.setField(mepManager, "coreService", new TestCoreService());
    TestUtils.setField(mepManager, "deviceService", deviceService);
    TestUtils.setField(mepManager, "cfmMdService", mdService);
    TestUtils.setField(mepManager, "mepStore", mepStore);
    injectEventDispatcher(mepManager, new TestEventDispatcher());
    mepService = mepManager;
    mepManager.activate();
    mep1 = DefaultMep.builder(MEPID1, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID1), mep1);
    mep11 = DefaultMep.builder(MEPID11, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID11), mep11);
    mep12 = DefaultMep.builder(MEPID12, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID12), mep12);
    mep2 = DefaultMep.builder(MEPID2, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID2), mep2);
    mep21 = DefaultMep.builder(MEPID21, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID21), mep21);
    mep22 = DefaultMep.builder(MEPID22, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
    mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID22), mep22);
    device1 = new DefaultDevice(ProviderId.NONE, DEVICE_ID1, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(1), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
    device2 = new DefaultDevice(ProviderId.NONE, DEVICE_ID2, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
    AbstractProjectableModel.setDriverService(null, driverService);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    behaviours.put(CfmMepProgrammable.class, TestCfmMepProgrammable.class);
    behaviours.put(SoamDmProgrammable.class, TestSoamDmProgrammable.class);
    testDriver = new DefaultDriver(TEST_DRIVER, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, behaviours, new HashMap<>());
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DefaultDevice(org.onosproject.net.DefaultDevice) ArrayList(java.util.ArrayList) DefaultDriver(org.onosproject.net.driver.DefaultDriver) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId) Before(org.junit.Before)

Aggregations

MepKeyId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)8 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)7 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)6 CfmMepProgrammable (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable)6 ArrayList (java.util.ArrayList)3 DeviceId (org.onosproject.net.DeviceId)3 Device (org.onosproject.net.Device)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 ChassisId (org.onlab.packet.ChassisId)1 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)1 MepEntry (org.onosproject.incubator.net.l2monitoring.cfm.MepEntry)1 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)1 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)1 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)1 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)1 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)1 DefaultDevice (org.onosproject.net.DefaultDevice)1 Behaviour (org.onosproject.net.driver.Behaviour)1 DefaultDriver (org.onosproject.net.driver.DefaultDriver)1