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;
}
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;
}
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);
}
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());
}
}
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();
}
}
Aggregations