Search in sources :

Example 1 with LossMeasurementEntry

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry in project onos by opennetworkinglab.

the class LmWebResourceTest method testGetAllLmsForMepEmpty.

@Test
public void testGetAllLmsForMepEmpty() throws CfmConfigException, SoamConfigException {
    List<LossMeasurementEntry> lmList = new ArrayList<>();
    expect(soamService.getAllLms(MDNAME1, MANAME1, MEPID1)).andReturn(lmList).anyTimes();
    replay(soamService);
    final WebTarget wt = target();
    final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/lm").request().get(String.class);
    assertThat(response, is("{\"lms\":[[]]}"));
}
Also used : ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) LossMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Example 2 with LossMeasurementEntry

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry in project onos by opennetworkinglab.

the class LmWebResource method getLm.

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

Example 3 with LossMeasurementEntry

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry in project onos by opennetworkinglab.

the class LmWebResource method getAllLmsForMep.

/**
 * Get all LMs for a Mep.
 *
 * @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 a Mep belonging to the MA
 * @return 200 OK with a list of LMs or 500 on error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getAllLmsForMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
    log.debug("GET all LMs called for MEP {}", mdName + "/" + maName + "/" + mepId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Collection<LossMeasurementEntry> lmCollection = get(SoamService.class).getAllLms(mdId, maId, mepIdObj);
        ArrayNode an = mapper().createArrayNode();
        an.add(codec(LossMeasurementEntry.class).encode(lmCollection, this));
        return ok(mapper().createObjectNode().set("lms", an)).build();
    } catch (CfmConfigException | SoamConfigException e) {
        log.error("Get LM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) LossMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 4 with LossMeasurementEntry

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry in project onos by opennetworkinglab.

the class LmEntryCodec method encode.

@Override
public ObjectNode encode(LossMeasurementEntry lm, CodecContext context) {
    checkNotNull(lm, "LM cannot be null");
    ObjectNode result = context.mapper().createObjectNode().put("lmId", lm.lmId().toString());
    if (lm.measuredForwardFlr() != null) {
        result.put("measuredForwardFlr", lm.measuredForwardFlr().percentValue());
    }
    if (lm.measuredBackwardFlr() != null) {
        result.put("measuredBackwardFlr", lm.measuredBackwardFlr().percentValue());
    }
    if (lm.measuredAvailabilityForwardStatus() != null) {
        result.put("measuredAvailabilityForwardStatus", lm.measuredAvailabilityForwardStatus().name());
    }
    if (lm.measuredAvailabilityBackwardStatus() != null) {
        result.put("measuredAvailabilityBackwardStatus", lm.measuredAvailabilityBackwardStatus().name());
    }
    if (lm.measuredForwardLastTransitionTime() != null) {
        result.put("measuredForwardLastTransitionTime", lm.measuredForwardLastTransitionTime().toString());
    }
    if (lm.measuredBackwardLastTransitionTime() != null) {
        result.put("measuredBackwardLastTransitionTime", lm.measuredBackwardLastTransitionTime().toString());
    }
    ObjectNode lmAttrs = new LmCreateCodec().encode(lm, context);
    Iterator<Entry<String, JsonNode>> elements = lmAttrs.fields();
    while (elements.hasNext()) {
        Entry<String, JsonNode> element = elements.next();
        result.set(element.getKey(), element.getValue());
    }
    if (lm.measurementCurrent() != null) {
        result.set("measurementCurrent", new LossMeasurementStatCurrentCodec().encode(lm.measurementCurrent(), context));
    }
    if (lm.measurementHistories() != null) {
        result.set("measurementHistories", new LossMeasurementStatHistoryCodec().encode(lm.measurementHistories(), context));
    }
    if (lm.availabilityCurrent() != null) {
        result.set("availabilityCurrent", new LossAvailabilityStatCurrentCodec().encode(lm.availabilityCurrent(), context));
    }
    if (lm.availabilityHistories() != null) {
        result.set("availabilityHistories", new LossAvailabilityStatHistoryCodec().encode(lm.availabilityHistories(), context));
    }
    return result;
}
Also used : Entry(java.util.Map.Entry) LossMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with LossMeasurementEntry

use of org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry in project onos by opennetworkinglab.

the class LmWebResourceTest method testGetAllLmsForMep.

@Test
public void testGetAllLmsForMep() throws CfmConfigException, SoamConfigException {
    List<LossMeasurementEntry> lmList = new ArrayList<>();
    lmList.add(lm1);
    lmList.add(lm2);
    expect(soamService.getAllLms(MDNAME1, MANAME1, MEPID1)).andReturn(lmList).anyTimes();
    replay(soamService);
    final WebTarget wt = target();
    final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/lm").request().get(String.class);
    assertThat(response, is("{\"lms\":[[" + "{" + "\"lmId\":\"1\"," + "\"lmCfgType\":\"LMLMM\"," + "\"version\":\"Y17312008\"," + "\"remoteMepId\":10," + "\"priority\":\"PRIO1\"," + "\"countersEnabled\":[]," + "\"measurementHistories\":[]," + "\"availabilityHistories\":[]" + "},{" + "\"lmId\":\"2\"," + "\"measuredForwardFlr\":51.0," + "\"measuredBackwardFlr\":49.9," + "\"measuredAvailabilityForwardStatus\":\"UNKNOWN\"," + "\"measuredAvailabilityBackwardStatus\":\"AVAILABLE\"," + "\"measuredForwardLastTransitionTime\":\"" + now + "\"," + "\"measuredBackwardLastTransitionTime\":\"" + now + "\"," + "\"lmCfgType\":\"LMLMM\"," + "\"version\":\"Y17312011\"," + "\"remoteMepId\":10," + "\"priority\":\"PRIO2\"," + "\"countersEnabled\":[]," + "\"measurementHistories\":[]," + "\"availabilityHistories\":[]" + "}]]}"));
}
Also used : ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) LossMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Aggregations

LossMeasurementEntry (org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 WebTarget (javax.ws.rs.client.WebTarget)2 Test (org.junit.Test)2 CfmResourceTest (org.onosproject.cfm.impl.CfmResourceTest)2 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)2 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)2 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)2 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)2 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)2 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Entry (java.util.Map.Entry)1 Path (javax.ws.rs.Path)1 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)1