use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class MepWebResourceTest method testCreateMepAlreadyExists.
@Test
public void testCreateMepAlreadyExists() throws CfmConfigException, IOException {
MepId mepId3 = MepId.valueOf((short) 3);
Mep mep3 = DefaultMep.builder(mepId3, DeviceId.deviceId("netconf:3.2.3.4:830"), PortNumber.portNumber(3), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).cciEnabled(true).ccmLtmPriority(Mep.Priority.PRIO3).administrativeState(false).primaryVid(VlanId.vlanId((short) 3)).defectAbsentTime(Duration.ofMinutes(2)).defectPresentTime(Duration.ofMinutes(3)).fngAddress(Mep.FngAddress.notSpecified()).lowestFaultPriorityDefect(Mep.LowestFaultDefect.ALL_DEFECTS).build();
MaintenanceAssociation ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
replay(mdService);
expect(mepService.createMep(MDNAME1, MANAME1, mep3)).andReturn(false).anyTimes();
replay(mepService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("mep", context.codec(Mep.class).encode(mep3, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().post(Entity.json(node.toString()));
assertEquals("Expecting 304", 304, response.getStatus());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class LmWebResource method createLm.
/**
* Create LM with MD name, MA name, Mep id and LM Json.
*
* @onos.rsModel LmCreate
* @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 LM parameters
* @return 201 Created or 304 if already exists or 500 on error
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createLm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
log.debug("POST called to Create Lm");
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<LossMeasurementCreate> lmCodec = codec(LossMeasurementCreate.class);
LossMeasurementCreate lm = lmCodec.decode((ObjectNode) cfg, this);
get(SoamService.class).createLm(mdId, maId, mepIdObj, lm);
return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/lm")).entity("{ \"success\":\"lm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
} catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
log.error("Create LM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class MepEntryCodec method encode.
/**
* Encodes the MepEntry entity into JSON.
*
* @param mepEntry MepEntry to encode
* @param context encoding context
* @return JSON node
* @throws java.lang.UnsupportedOperationException if the codec does not
* support encode operations
*/
@Override
public ObjectNode encode(MepEntry mepEntry, CodecContext context) {
checkNotNull(mepEntry, "Mep cannot be null");
ObjectNode result = context.mapper().createObjectNode();
// Get the common attributes
Mep mep = mepEntry;
ObjectNode mepAttrs = new MepCodec().encode(mep, context);
Iterator<Entry<String, JsonNode>> elements = mepAttrs.fields();
while (elements.hasNext()) {
Entry<String, JsonNode> element = elements.next();
result.set(element.getKey(), element.getValue());
}
if (mepEntry.macAddress() != null) {
result.put("macAddress", mepEntry.macAddress().toString());
}
if (mepEntry.loopbackAttributes() != null) {
result.set("loopback", new MepLbEntryCodec().encode(mepEntry.loopbackAttributes(), context));
}
if (mepEntry.activeRemoteMepList() != null) {
result.set("remoteMeps", new RemoteMepEntryCodec().encode(mepEntry.activeRemoteMepList(), context));
}
if (mepEntry.activeErrorCcmDefect()) {
result.put("activeErrorCcmDefect", true);
}
if (mepEntry.activeMacStatusDefect()) {
result.put("activeMacStatusDefect", true);
}
if (mepEntry.activeRdiCcmDefect()) {
result.put("activeRdiCcmDefect", true);
}
if (mepEntry.activeRemoteCcmDefect()) {
result.put("activeRemoteCcmDefect", true);
}
if (mepEntry.activeXconCcmDefect()) {
result.put("activeXconCcmDefect", true);
}
return result;
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.
the class CfmMepManagerTest method testCreateMep.
@Test
public void testCreateMep() throws CfmConfigException {
expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
replay(mdService);
expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
replay(deviceService);
expect(driverService.getDriver(DEVICE_ID1)).andReturn(testDriver).anyTimes();
expect(driverService.getDriver(DEVICE_ID2)).andReturn(testDriver).anyTimes();
replay(driverService);
MepId mepId3 = MepId.valueOf((short) 3);
Mep mep3 = DefaultMep.builder(mepId3, DEVICE_ID1, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
// Expecting false - since it was not found
assertTrue(mepManager.createMep(MDNAME1, MANAME1, mep3));
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Mep 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;
}
}
Aggregations