Search in sources :

Example 1 with SoamId

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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) WebTarget(javax.ws.rs.client.WebTarget) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Example 2 with SoamId

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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) WebTarget(javax.ws.rs.client.WebTarget) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Example 3 with SoamId

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();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) LossMeasurementThreshold(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId)

Example 4 with SoamId

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();
    }
}
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) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 5 with SoamId

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();
    }
}
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) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) 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) 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)

Aggregations

SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)9 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)6 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)6 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)6 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)6 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 PUT (javax.ws.rs.PUT)2 WebTarget (javax.ws.rs.client.WebTarget)2 Test (org.junit.Test)2 CfmResourceTest (org.onosproject.cfm.impl.CfmResourceTest)2