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\":[[]]}"));
}
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();
}
}
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();
}
}
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;
}
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\":[]" + "}]]}"));
}
Aggregations