Search in sources :

Example 11 with MepEntry

use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.

the class CfmMepListCommand method doExecute.

@Override
protected void doExecute() {
    CfmMepService mepService = get(CfmMepService.class);
    CfmMdService mdService = get(CfmMdService.class);
    if (mdStr != null && !mdStr.isEmpty()) {
        MdId mdId = parseMdName(mdStr);
        print(printMdId(mdId));
        if (maStr != null && !maStr.isEmpty()) {
            MaIdShort maId = parseMaName(maStr);
            print(printMaId(maId));
            if (mepStr != null && !mepStr.isEmpty()) {
                MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
                try {
                    MepEntry mep = mepService.getMep(mdId, maId, mepId);
                    if (mep != null) {
                        print(printMepEntry(mep));
                    }
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Mep details {}", new MepKeyId(mdId, maId, mepId), e);
                }
            // MD, MA and MEP given
            } else {
                // MD and MA given but no MEP given
                try {
                    mepService.getAllMeps(mdId, maId).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), maId.maName(), e);
                }
            }
        } else {
            // MD given but no MA given
            mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), ma.maId().maName(), e);
                }
            });
        }
    } else {
        mdService.getAllMaintenanceDomain().forEach(md -> {
            print(printMdId(md.mdId()));
            mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", md.mdId().mdName(), ma.maId().maName(), e);
                }
            });
        });
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 12 with MepEntry

use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.

the class MepWebResource method getMep.

/**
 * Get MEP by 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 mepId The Id of the MEP
 * @return 200 OK with details of the MEP or 500 on error
 */
@GET
@Path("{mep_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
    log.debug("GET called for MEP {}", mdName + "/" + maName + "/" + mepId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepEntry mepEntry = get(CfmMepService.class).getMep(mdId, maId, MepId.valueOf(mepId));
        if (mepEntry == null) {
            return Response.serverError().entity("{ \"failure\":\"MEP " + mdName + "/" + maName + "/" + mepId + " not found\" }").build();
        }
        ObjectNode node = mapper().createObjectNode();
        node.set("mep", codec(MepEntry.class).encode(mepEntry, this));
        return ok(node).build();
    } catch (CfmConfigException e) {
        log.error("Get Mep {} failed because of exception", mdName + "/" + maName + "/" + mepId, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 13 with MepEntry

use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.

the class MepEntryCodecTest method testEncodeIterableOfMepEntryCodecContext.

@Test
public void testEncodeIterableOfMepEntryCodecContext() throws CfmConfigException {
    MepEntry mepEntry2 = DefaultMepEntry.builder(MepId.valueOf((short) 33), DeviceId.deviceId("netconf:4321:830"), PortNumber.portNumber(1), MepDirection.DOWN_MEP, MdIdCharStr.asMdId("md-2"), MaIdCharStr.asMaId("ma-2-2")).buildEntry();
    ArrayList<MepEntry> meps = new ArrayList<>();
    meps.add(mepEntry1);
    meps.add(mepEntry2);
    ObjectNode node = mapper.createObjectNode();
    node.set("mep", context.codec(MepEntry.class).encode(meps, context));
    Iterator<JsonNode> an = node.get("mep").elements();
    while (an.hasNext()) {
        JsonNode jn = an.next();
        assertEquals("md-", jn.get("mdName").asText().substring(0, 3));
    }
}
Also used : DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 14 with MepEntry

use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.

the class LmWebResourceTest method testCreateLm.

@Test
public void testCreateLm() throws CfmConfigException, SoamConfigException {
    MepEntry mep1 = DefaultMepEntry.builder(MEPID1, DeviceId.deviceId("netconf:1.2.3.4:830"), PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
    expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
    replay(mepService);
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("lm", context.codec(LossMeasurementCreate.class).encode(lm1, context));
    final WebTarget wt = target();
    final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/lm").request().post(Entity.json(node.toString()));
    assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Example 15 with MepEntry

use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.

the class DmWebResourceTest method testCreateDm.

@Test
public void testCreateDm() throws CfmConfigException, SoamConfigException {
    MepEntry mep1 = DefaultMepEntry.builder(MEPID1, DeviceId.deviceId("netconf:1.2.3.4:830"), PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
    expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
    replay(mepService);
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("dm", context.codec(DelayMeasurementCreate.class).encode(dm1, context));
    final WebTarget wt = target();
    final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/dm").request().post(Entity.json(node.toString()));
    assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Aggregations

MepEntry (org.onosproject.incubator.net.l2monitoring.cfm.MepEntry)15 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)9 Test (org.junit.Test)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 DefaultMepEntry (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry)5 SoamDmProgrammable (org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable)4 ArrayList (java.util.ArrayList)3 WebTarget (javax.ws.rs.client.WebTarget)3 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)3 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)3 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)2 CfmResourceTest (org.onosproject.cfm.impl.CfmResourceTest)2 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)2