Search in sources :

Example 11 with Mep

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

the class CfmMepManager method getAllMeps.

@Override
public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName) throws CfmConfigException {
    // Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);
    Collection<Mep> mepStoreCollection = mepStore.getAllMeps();
    Collection<MepEntry> mepEntryCollection = new ArrayList<>();
    for (Mep mep : mepStoreCollection) {
        if (mep.mdId().equals(mdName) && mep.maId().equals(maName)) {
            DeviceId mepDeviceId = mep.deviceId();
            if (deviceService.getDevice(mepDeviceId) == null) {
                log.warn("Device not found/available " + mepDeviceId + " for MEP: " + mdName + "/" + maName + "/" + mep.mepId());
                continue;
            } else if (!deviceService.getDevice(mepDeviceId).is(CfmMepProgrammable.class)) {
                throw new CfmConfigException("Device " + mepDeviceId + " does not support CfmMepProgrammable behaviour.");
            }
            log.debug("Retrieving MEP results for Mep {} in MD {}, MA {} " + "on Device {}", mep.mepId(), mdName, maName, mepDeviceId);
            mepEntryCollection.add(deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).getMep(mdName, maName, mep.mepId()));
        }
    }
    return mepEntryCollection;
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)

Example 12 with Mep

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

the class CfmMepManager method deleteMep.

@Override
public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId, Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, mepId);
    // Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);
    // Get the device ID from the MEP
    Optional<Mep> deletedMep = mepStore.getMep(key);
    if (!deletedMep.isPresent()) {
        log.warn("MEP {} not found when deleting Mep", key);
        return false;
    }
    DeviceId mepDeviceId = deletedMep.get().deviceId();
    boolean deleted = mepStore.deleteMep(key);
    Device mepDevice = deviceService.getDevice(mepDeviceId);
    if (mepDevice == null || !mepDevice.is(CfmMepProgrammable.class)) {
        throw new CfmConfigException("Unexpeced fault on device driver for " + mepDeviceId);
    }
    try {
        deleted = mepDevice.as(CfmMepProgrammable.class).deleteMep(mdName, maName, mepId, oldMd);
    } catch (CfmConfigException e) {
        log.warn("MEP could not be deleted on device - perhaps it " + "does not exist. Continuing");
    }
    // Iterate through all other devices and remove as a Remote Mep
    int mepsOnMdCount = 0;
    int mepsOnMaCount = 0;
    List<DeviceId> alreadyHandledDevices = new ArrayList<>();
    for (Mep mep : mepStore.getAllMeps()) {
        if (mep.deviceId().equals(mepDeviceId) && mdName.equals(mep.mdId())) {
            mepsOnMdCount++;
            if (maName.equals(mep.maId())) {
                mepsOnMaCount++;
            }
        }
        if (mep.deviceId().equals(mepDeviceId) || !mep.mdId().equals(mdName) || !mep.maId().equals(maName) || alreadyHandledDevices.contains(mep.deviceId())) {
            continue;
        }
        deviceService.getDevice(mep.deviceId()).as(CfmMepProgrammable.class).deleteMaRemoteMepOnDevice(mdName, maName, mepId);
        alreadyHandledDevices.add(mep.deviceId());
        log.info("Deleted RMep entry on {} on device {}", mdName.mdName() + "/" + maName.maName(), mep.deviceId());
    }
    // If this is the last MA in this MD on device, then delete the MD from the device
    if (mepsOnMdCount == 0) {
        boolean deletedMd = deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).deleteMdOnDevice(mdName, oldMd);
        log.info("Deleted MD {} from Device {}", mdName.mdName(), mepDeviceId);
    } else if (mepsOnMaCount == 0) {
        boolean deletedMa = deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).deleteMaOnDevice(mdName, maName, oldMd);
        log.info("Deleted MA {} from Device {}", mdName.mdName() + "/" + maName.maName(), mepDeviceId);
    }
    return deleted;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) 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 Mep

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

the class CfmMepManager method transmitLoopback.

@Override
public void transmitLoopback(MdId mdName, MaIdShort maName, MepId mepId, MepLbCreate lbCreate) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, mepId);
    Mep mep = mepStore.getMep(key).orElseThrow(() -> new CfmConfigException("Mep " + mdName + "/" + maName + "/" + mepId + " not found when calling Transmit Loopback"));
    log.debug("Transmitting Loopback on MEP {} on Device {}", key, mep.deviceId());
    deviceService.getDevice(mep.deviceId()).as(CfmMepProgrammable.class).transmitLoopback(mdName, maName, mepId, lbCreate);
}
Also used : 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 Mep

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

the class CfmMepManagerTest method testCreateMepBehaviorNotSupported.

@Test
public void testCreateMepBehaviorNotSupported() throws CfmConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    Driver testDriver3 = new DefaultDriver(TEST_DRIVER_3, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_3, behaviours, new HashMap<>());
    Device device3 = new DefaultDevice(ProviderId.NONE, deviceId3, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_3, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER_3).build());
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, deviceId3, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    try {
        mepManager.createMep(MDNAME1, MANAME1, mep3);
        fail("Expecting CfmConfigException because driver does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 does not support " + "CfmMepProgrammable behaviour.", e.getMessage());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Driver(org.onosproject.net.driver.Driver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 15 with Mep

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

the class DmWebResource method createDm.

/**
 * Create DM with MD name, MA name, Mep id and DM Json.
 *
 * @onos.rsModel DmCreate
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param mepId The Id of the MEP belonging to the MEP
 * @param input A JSON formatted input stream specifying the DM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Dm");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Mep mep = get(CfmMepService.class).getMep(mdId, maId, mepIdObj);
        if (mep == null) {
            return Response.serverError().entity("{ \"failure\":\"mep " + mdName + "/" + maName + "/" + mepId + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<DelayMeasurementCreate> dmCodec = codec(DelayMeasurementCreate.class);
        DelayMeasurementCreate dm = dmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createDm(mdId, maId, mepIdObj, dm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/dm")).entity("{ \"success\":\"dm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create DM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)18 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)14 CfmMepProgrammable (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable)8 DeviceId (org.onosproject.net.DeviceId)8 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)6 MepKeyId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Consumes (javax.ws.rs.Consumes)4 Produces (javax.ws.rs.Produces)4 Test (org.junit.Test)4 DefaultMep (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep)4 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)3 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)3 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)3