use of org.onosproject.incubator.net.l2monitoring.soam.SoamId in project onos by opennetworkinglab.
the class DmWebResourceTest method testGetDmInvalid.
@Test
public void testGetDmInvalid() throws CfmConfigException, SoamConfigException, IOException {
SoamId dm3 = SoamId.valueOf(3);
expect(soamService.getDm(MDNAME1, MANAME1, MEPID1, dm3)).andReturn(null).anyTimes();
replay(soamService);
final WebTarget wt = target();
try {
final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/dm/" + dm3.value()).request().get(String.class);
fail("Expecting excpetion");
} catch (InternalServerErrorException e) {
ByteArrayInputStream is = (ByteArrayInputStream) e.getResponse().getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
assertEquals("{ \"failure\":\"DM md-1/ma-1-1/1/3 not found\" }", sb.toString());
}
}
use of org.onosproject.incubator.net.l2monitoring.soam.SoamId in project onos by opennetworkinglab.
the class LmWebResourceTest method testGetLmEmpty.
@Test
public void testGetLmEmpty() throws CfmConfigException, SoamConfigException, IOException {
SoamId lmId3 = SoamId.valueOf(3);
expect(soamService.getLm(MDNAME1, MANAME1, MEPID1, lmId3)).andReturn(null).anyTimes();
replay(soamService);
final WebTarget wt = target();
try {
final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/lm/" + lmId3.value()).request().get(String.class);
} catch (InternalServerErrorException e) {
ByteArrayInputStream is = (ByteArrayInputStream) e.getResponse().getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
assertEquals("{ \"failure\":\"LM md-1/ma-1-1/1/3 not found\" }", sb.toString());
}
}
use of org.onosproject.incubator.net.l2monitoring.soam.SoamId in project onos by opennetworkinglab.
the class LossMeasurementThresholdCodec method decode.
@Override
public LossMeasurementThreshold decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode thrNode = json.get("threshold");
SoamId thresholdId = SoamId.valueOf(nullIsIllegal(thrNode.get("id"), "thresholdId must not be null").asInt());
LossMeasurementThreshold.LmThresholdBuilder builder = builder(thresholdId);
if (thrNode.get("thresholds") != null) {
context.codec(LossMeasurementThreshold.ThresholdOption.class).decode((ArrayNode) (thrNode.get("thresholds")), context).forEach(builder::addToThreshold);
}
if (thrNode.get(MEASUREDFLRFORWARD) != null) {
builder.measuredFlrForward(MilliPct.ofPercent((float) thrNode.get(MEASUREDFLRFORWARD).asDouble()));
}
if (thrNode.get(MAXFLRFORWARD) != null) {
builder.maxFlrForward(MilliPct.ofPercent((float) thrNode.get(MAXFLRFORWARD).asDouble()));
}
if (thrNode.get(AVERAGEFLRFORWARD) != null) {
builder.averageFlrForward(MilliPct.ofPercent((float) thrNode.get(AVERAGEFLRFORWARD).asDouble()));
}
if (thrNode.get(MEASUREDFLRBACKWARD) != null) {
builder.measuredFlrBackward(MilliPct.ofPercent((float) thrNode.get(MEASUREDFLRBACKWARD).asDouble()));
}
if (thrNode.get(MAXFLRBACKWARD) != null) {
builder.maxFlrBackward(MilliPct.ofPercent((float) thrNode.get(MAXFLRBACKWARD).asDouble()));
}
if (thrNode.get(AVERAGEFLRBACKWARD) != null) {
builder.averageFlrBackward(MilliPct.ofPercent((float) thrNode.get(AVERAGEFLRBACKWARD).asDouble()));
}
if (thrNode.get(FORWARDHIGHLOSS) != null) {
builder.forwardHighLoss(thrNode.get(FORWARDHIGHLOSS).asLong());
}
if (thrNode.get(FORWARDCONSECUTIVEHIGHLOSS) != null) {
builder.forwardConsecutiveHighLoss(thrNode.get(FORWARDCONSECUTIVEHIGHLOSS).asLong());
}
if (thrNode.get(BACKWARDHIGHLOSS) != null) {
builder.backwardHighLoss(thrNode.get(BACKWARDHIGHLOSS).asLong());
}
if (thrNode.get(BACKWARDCONSECUTIVEHIGHLOSS) != null) {
builder.backwardConsecutiveHighLoss(thrNode.get(BACKWARDCONSECUTIVEHIGHLOSS).asLong());
}
if (thrNode.get(FORWARDUNAVAILABLECOUNT) != null) {
builder.forwardUnavailableCount(thrNode.get(FORWARDUNAVAILABLECOUNT).asLong());
}
if (thrNode.get(FORWARDAVAILABLERATIO) != null) {
builder.forwardAvailableRatio(MilliPct.ofPercent((float) thrNode.get(FORWARDAVAILABLERATIO).asDouble()));
}
if (thrNode.get(BACKWARDUNAVAILABLECOUNT) != null) {
builder.backwardUnavailableCount(thrNode.get(BACKWARDUNAVAILABLECOUNT).asLong());
}
if (thrNode.get(BACKWARDAVAILABLERATIO) != null) {
builder.backwardAvailableRatio(MilliPct.ofPercent((float) thrNode.get(BACKWARDAVAILABLERATIO).asDouble()));
}
return builder.build();
}
use of org.onosproject.incubator.net.l2monitoring.soam.SoamId in project onos by opennetworkinglab.
the class DmWebResource method clearDmHistory.
/**
* Clear DM history stats 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 dmId The Id of the DM
* @return 200 OK or 304 if not found, or 500 on error
*/
@PUT
@Path("{dm_id}/clear-history")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response clearDmHistory(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("dm_id") int dmId) {
log.debug("clear-history called for DM {}", mdName + "/" + maName + "/" + mepId + "/" + dmId);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepId mepIdObj = MepId.valueOf(mepId);
SoamId dmIdObj = SoamId.valueOf(dmId);
get(SoamService.class).clearDelayHistoryStats(mdId, maId, mepIdObj, dmIdObj);
return ok("{ \"success\":\"cleared DM history stats for " + mdName + "/" + maName + "/" + mepId + "/" + dmId + "\" }").build();
} catch (CfmConfigException e) {
log.error("Clear history stats for DM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + dmId, e.toString());
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.soam.SoamId in project onos by opennetworkinglab.
the class DmWebResource method getDm.
/**
* Get DM 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 dmId The Id of the DM
* @return 200 OK with details of the DM or 500 on error
*/
@GET
@Path("{dm_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("dm_id") int dmId) {
log.debug("GET called for DM {}", mdName + "/" + maName + "/" + mepId + "/" + dmId);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepId mepIdObj = MepId.valueOf(mepId);
SoamId dmIdObj = SoamId.valueOf(dmId);
DelayMeasurementEntry dm = get(SoamService.class).getDm(mdId, maId, mepIdObj, dmIdObj);
if (dm == null) {
return Response.serverError().entity("{ \"failure\":\"DM " + mdName + "/" + maName + "/" + mepId + "/" + dmId + " not found\" }").build();
}
ObjectNode node = mapper().createObjectNode();
node.set("dm", codec(DelayMeasurementEntry.class).encode(dm, this));
return ok(node).build();
} catch (CfmConfigException | SoamConfigException e) {
log.error("Get DM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + dmId, e.toString());
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
Aggregations