use of org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate in project onos by opennetworkinglab.
the class MepLtCreateCodecTest method testDecodeMepLtCreateMepId.
@Test
public void testDecodeMepLtCreateMepId() throws JsonProcessingException, IOException {
String linktraceString = "{\"linktrace\": { " + "\"remoteMepId\": 20," + "\"defaultTtl\": 21," + "\"transmitLtmFlags\": \"use-fdb-only\"}}";
InputStream input = new ByteArrayInputStream(linktraceString.getBytes(StandardCharsets.UTF_8));
JsonNode cfg = mapper.readTree(input);
MepLtCreate mepLtCreate = context.codec(MepLtCreate.class).decode((ObjectNode) cfg, context);
assertNull(mepLtCreate.remoteMepAddress());
assertEquals(20, mepLtCreate.remoteMepId().id().shortValue());
assertEquals(21, mepLtCreate.defaultTtl().intValue());
assertEquals(BitSet.valueOf(new byte[] { 1 }), mepLtCreate.transmitLtmFlags());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate in project onos by opennetworkinglab.
the class MepLtCreateCodecTest method testEncodeMepLtCreate.
@Test
public void testEncodeMepLtCreate() {
MepId mepId1 = MepId.valueOf((short) 1);
MepLtCreate mepLtCreate1 = DefaultMepLtCreate.builder(mepId1).defaultTtl((short) 20).transmitLtmFlags(BitSet.valueOf(new byte[] { 1 })).build();
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("linktrace", context.codec(MepLtCreate.class).encode(mepLtCreate1, context));
assertEquals("{\"linktrace\":{" + "\"remoteMepId\":1," + "\"defaultTtl\":20," + "\"transmitLtmFlags\":\"use-fdb-only\"}}", node.toString());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate in project onos by opennetworkinglab.
the class CfmMepManagerTest method testTransmitLinktrace.
@Test
public void testTransmitLinktrace() throws CfmConfigException {
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);
MepLtCreate ltCreate = DefaultMepLtCreate.builder(MepId.valueOf((short) 11)).build();
try {
mepService.transmitLinktrace(MDNAME1, MANAME1, MEPID1, ltCreate);
} catch (UnsupportedOperationException e) {
assertEquals("Not yet implemented", e.getMessage());
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate in project onos by opennetworkinglab.
the class MepWebResource method transmitLinktrace.
/**
* Transmit Linktrace on MEP with MD name, MA name and Mep Id.
*
* @onos.rsModel MepLtTransmit
* @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 Linktrace parameters
* @return 202 Received with success message or 500 on error
*/
@PUT
@Path("{mep_id}/transmit-linktrace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLinktrace(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
log.debug("PUT called to Transmit Linktrace 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<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
get(CfmMepService.class).transmitLinktrace(md.mdId(), ma.maId(), mepId, ltCreate);
} catch (Exception | CfmConfigException e) {
log.error("Transmit Linktrace on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
return Response.accepted().entity("{ \"success\":\"Linktrace on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate in project onos by opennetworkinglab.
the class MepLtCreateCodec method decode.
/**
* Decodes the MepLtCreate entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded MepLtCreate
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public MepLtCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode linktraceNode = json.get(LINKTRACE);
JsonNode remoteMepIdNode = linktraceNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = linktraceNode.get(REMOTE_MEP_MAC);
MepLtCreate.MepLtCreateBuilder ltCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepId);
} else if (remoteMepMacNode != null) {
MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepMac);
} else {
throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
}
JsonNode defaultTtlNode = linktraceNode.get(DEFAULT_TTL);
if (defaultTtlNode != null) {
short defaultTtl = (short) defaultTtlNode.asInt();
ltCreateBuilder.defaultTtl(defaultTtl);
}
JsonNode transmitLtmFlagsNode = linktraceNode.get(TRANSMIT_LTM_FLAGS);
if (transmitLtmFlagsNode != null) {
if (transmitLtmFlagsNode.asText().isEmpty()) {
ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 0 }));
} else if (transmitLtmFlagsNode.asText().equals(USE_FDB_ONLY)) {
ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 1 }));
} else {
throw new IllegalArgumentException("Expecting value 'use-fdb-only' " + "or '' for " + TRANSMIT_LTM_FLAGS);
}
}
return ltCreateBuilder.build();
}
Aggregations