use of org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate in project onos by opennetworkinglab.
the class MepLbCreateCodecTest method testDecodeMepLbCreateMepId.
@Test
public void testDecodeMepLbCreateMepId() throws JsonProcessingException, IOException {
String loopbackString = "{\"loopback\": { \"remoteMepId\": 20," + "\"numberMessages\": 10, \"vlanDropEligible\": true," + "\"vlanPriority\": 6, \"dataTlvHex\": \"0A:BB:CC\" }}";
InputStream input = new ByteArrayInputStream(loopbackString.getBytes(StandardCharsets.UTF_8));
JsonNode cfg = mapper.readTree(input);
MepLbCreate mepLbCreate = context.codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
assertNull(mepLbCreate.remoteMepAddress());
assertEquals(20, mepLbCreate.remoteMepId().id().shortValue());
assertEquals(10, mepLbCreate.numberMessages().intValue());
assertEquals(6, mepLbCreate.vlanPriority().ordinal());
assertEquals(true, mepLbCreate.vlanDropEligible());
assertEquals("0A:BB:CC".toLowerCase(), mepLbCreate.dataTlvHex());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate in project onos by opennetworkinglab.
the class MepLbCreateCodecTest method testDecodeMepLbCreateMepMac.
@Test
public void testDecodeMepLbCreateMepMac() throws JsonProcessingException, IOException {
String loopbackString = "{\"loopback\": { " + "\"remoteMepMac\": \"AA:BB:CC:DD:EE:FF\" }}";
InputStream input = new ByteArrayInputStream(loopbackString.getBytes(StandardCharsets.UTF_8));
JsonNode cfg = mapper.readTree(input);
MepLbCreate mepLbCreate = context.codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
assertNull(mepLbCreate.remoteMepId());
assertEquals("AA:BB:CC:DD:EE:FF", mepLbCreate.remoteMepAddress().toString());
assertNull(mepLbCreate.dataTlvHex());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate 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();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate in project onos by opennetworkinglab.
the class CfmMepManagerTest method testTransmitLoopback.
@Test
public void testTransmitLoopback() {
expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
replay(mdService);
expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
replay(deviceService);
expect(driverService.getDriver(DEVICE_ID1)).andReturn(testDriver).anyTimes();
replay(driverService);
MepLbCreate lbCreate = DefaultMepLbCreate.builder(MepId.valueOf((short) 11)).build();
try {
mepService.transmitLoopback(MDNAME1, MANAME1, MEPID1, lbCreate);
} catch (CfmConfigException e) {
fail("Not expecting an exception");
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate 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();
}
Aggregations