use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class SoamManagerTest method testCreateDmNoBehavior.
@Test
public void testCreateDmNoBehavior() throws CfmConfigException, SoamConfigException {
final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
final MepId mepId3 = MepId.valueOf((short) 3);
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(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
replay(deviceService);
MepEntry mep3 = DefaultMepEntry.builder(mepId3, deviceId3, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
expect(mepService.getMep(MDNAME1, MANAME1, mepId3)).andReturn(mep3).anyTimes();
replay(mepService);
expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
replay(driverService);
DelayMeasurementCreate dmCreate1 = DefaultDelayMeasurementCreate.builder(DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO3).binsPerFdInterval((short) 4).binsPerFdrInterval((short) 5).binsPerIfdvInterval((short) 6).build();
try {
soamManager.createDm(MDNAME1, MANAME1, mepId3, dmCreate1);
fail("Expecting exception since device does not support behavior");
} catch (CfmConfigException e) {
assertEquals("Device netconf:3.2.3.4:830 from MEP :md-1/" + "ma-1-1/3 does not implement SoamDmProgrammable", e.getMessage());
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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.identifier.MepId in project onos by opennetworkinglab.
the class MepWebResource method transmitLoopback.
/**
* Transmit Loopback on MEP with MD name, MA name and Mep Id.
*
* @onos.rsModel MepLbTransmit
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param mepIdShort The id of a MEP belonging to the MA
* @param input A JSON formatted input stream specifying the Mep parameters
* @return 202 Received with success message or 500 on error
*/
@PUT
@Path("{mep_id}/transmit-loopback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLoopback(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
log.debug("PUT called to Transmit Loopback on Mep");
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceDomain md;
Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
if (mdOpt.isPresent()) {
md = mdOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
}
MaintenanceAssociation ma;
Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
if (maOpt.isPresent()) {
ma = maOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
}
MepId mepId = MepId.valueOf(mepIdShort);
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper(), input);
JsonCodec<MepLbCreate> mepLbCreateCodec = codec(MepLbCreate.class);
MepLbCreate lbCreate = mepLbCreateCodec.decode((ObjectNode) cfg, this);
get(CfmMepService.class).transmitLoopback(md.mdId(), ma.maId(), mepId, lbCreate);
} catch (Exception | CfmConfigException e) {
log.error("Transmit Loopback on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
return Response.accepted().entity("{ \"success\":\"Loopback on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class MepWebResource method abortLoopback.
/**
* Abort Loopback on MEP with MD name, MA name and Mep Id.
*
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param mepIdShort The id of a MEP belonging to the MA
* @return 202 Received with success message or 500 on error
*/
@PUT
@Path("{mep_id}/abort-loopback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response abortLoopback(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort) {
log.debug("PUT called to Abort Loopback on Mep");
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceDomain md;
Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
if (mdOpt.isPresent()) {
md = mdOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
}
MaintenanceAssociation ma;
Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
if (maOpt.isPresent()) {
ma = maOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
}
MepId mepId = MepId.valueOf(mepIdShort);
try {
get(CfmMepService.class).abortLoopback(md.mdId(), ma.maId(), mepId);
} catch (CfmConfigException e) {
log.error("Abort Loopback on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
return Response.accepted().entity("{ \"success\":\"Loopback on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " aborted\" }").build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class MepLbCreateCodec method decode.
/**
* Decodes the MepLbCreate entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded MepLbCreate
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public MepLbCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode loopbackNode = json.get(LOOPBACK);
JsonNode remoteMepIdNode = loopbackNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = loopbackNode.get(REMOTE_MEP_MAC);
MepLbCreate.MepLbCreateBuilder lbCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepId);
} else if (remoteMepMacNode != null) {
MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepMac);
} else {
throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
}
JsonNode numMessagesNode = loopbackNode.get(NUMBER_MESSAGES);
if (numMessagesNode != null) {
int numMessages = numMessagesNode.asInt();
lbCreateBuilder.numberMessages(numMessages);
}
JsonNode vlanDropEligibleNode = loopbackNode.get(VLAN_DROP_ELIGIBLE);
if (vlanDropEligibleNode != null) {
boolean vlanDropEligible = vlanDropEligibleNode.asBoolean();
lbCreateBuilder.vlanDropEligible(vlanDropEligible);
}
JsonNode vlanPriorityNode = loopbackNode.get(VLAN_PRIORITY);
if (vlanPriorityNode != null) {
short vlanPriority = (short) vlanPriorityNode.asInt();
lbCreateBuilder.vlanPriority(Priority.values()[vlanPriority]);
}
JsonNode dataTlvHexNode = loopbackNode.get(DATA_TLV_HEX);
if (dataTlvHexNode != null) {
String dataTlvHex = loopbackNode.get(DATA_TLV_HEX).asText();
if (!dataTlvHex.isEmpty()) {
lbCreateBuilder.dataTlv(HexString.fromHexString(dataTlvHex));
}
}
return lbCreateBuilder.build();
}
Aggregations