Search in sources :

Example 1 with MaintenanceDomain

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) Test(org.junit.Test)

Example 2 with MaintenanceDomain

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) Test(org.junit.Test)

Example 3 with MaintenanceDomain

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());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with MaintenanceDomain

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());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with MaintenanceDomain

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();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)25 DefaultMaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain)18 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)6 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 DefaultMaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation)5 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)5 Path (javax.ws.rs.Path)4 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)4 PUT (javax.ws.rs.PUT)3