use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain in project onos by opennetworkinglab.
the class MaintenanceDomainCodecTest method testEncodeMd2.
@Test
public void testEncodeMd2() throws CfmConfigException {
MaintenanceDomain md2 = DefaultMaintenanceDomain.builder(MDID2_DOMAIN).mdLevel(MaintenanceDomain.MdLevel.LEVEL2).build();
ObjectNode node = mapper.createObjectNode();
node.set("md", context.codec(MaintenanceDomain.class).encode(md2, context));
assertEquals("{\"md\":{" + "\"mdName\":\"test.opennetworking.org\"," + "\"mdNameType\":\"DOMAINNAME\"," + "\"mdLevel\":\"LEVEL2\"," + "\"maList\":[]}}", node.toString());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain in project onos by opennetworkinglab.
the class MaintenanceDomainCodecTest method testEncodeMd3.
@Test
public void testEncodeMd3() throws CfmConfigException {
MaintenanceDomain md3 = DefaultMaintenanceDomain.builder(MDID3_MACUINT).mdLevel(MaintenanceDomain.MdLevel.LEVEL3).build();
ObjectNode node = mapper.createObjectNode();
node.set("md", context.codec(MaintenanceDomain.class).encode(md3, context));
assertEquals("{\"md\":{" + "\"mdName\":\"AA:BB:CC:DD:EE:FF:181\"," + "\"mdNameType\":\"MACANDUINT\"," + "\"mdLevel\":\"LEVEL3\"," + "\"maList\":[]}}", node.toString());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain in project onos by opennetworkinglab.
the class MaWebResourceTest method testCreateMa.
@Test
public void testCreateMa() throws CfmConfigException {
MaintenanceDomain md1 = DefaultMaintenanceDomain.builder(MDNAME1).mdLevel(MaintenanceDomain.MdLevel.LEVEL2).build();
expect(mdService.getMaintenanceDomain(MDNAME1)).andReturn(Optional.ofNullable(md1)).anyTimes();
expect(mdService.createMaintenanceAssociation(MDNAME1, ma1)).andReturn(false).anyTimes();
replay(mdService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("ma", context.codec(MaintenanceAssociation.class).encode(ma1, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma").request().post(Entity.json(node.toString()));
assertEquals(201, response.getStatus());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain in project onos by opennetworkinglab.
the class MdWebResourceTest method testCreateMd.
@Test
public void testCreateMd() throws CfmConfigException {
MaintenanceDomain md3 = DefaultMaintenanceDomain.builder(MdIdCharStr.asMdId("md-3")).mdLevel(MaintenanceDomain.MdLevel.LEVEL3).mdNumericId((short) 3).build();
expect(mdService.createMaintenanceDomain(mdList.get(1))).andReturn(false).anyTimes();
replay(mdService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("md", context.codec(MaintenanceDomain.class).encode(mdList.get(1), context));
final WebTarget wt = target();
final Response response = wt.path("md").request().post(Entity.json(node.toString()));
assertEquals(201, response.getStatus());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain 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