Search in sources :

Example 6 with MepId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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 7 with MepId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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 8 with MepId

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

the class LmWebResource method createLm.

/**
 * Create LM with MD name, MA name, Mep id and LM Json.
 *
 * @onos.rsModel LmCreate
 * @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 belonging to the MEP
 * @param input A JSON formatted input stream specifying the LM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createLm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Lm");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Mep mep = get(CfmMepService.class).getMep(mdId, maId, mepIdObj);
        if (mep == null) {
            return Response.serverError().entity("{ \"failure\":\"mep " + mdName + "/" + maName + "/" + mepId + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<LossMeasurementCreate> lmCodec = codec(LossMeasurementCreate.class);
        LossMeasurementCreate lm = lmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createLm(mdId, maId, mepIdObj, lm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/lm")).entity("{ \"success\":\"lm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create LM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) LossMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 9 with MepId

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

the class MepLbCreateCodec method decode.

/**
 * Decodes the MepLbCreate entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MepLbCreate
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MepLbCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode loopbackNode = json.get(LOOPBACK);
    JsonNode remoteMepIdNode = loopbackNode.get(REMOTE_MEP_ID);
    JsonNode remoteMepMacNode = loopbackNode.get(REMOTE_MEP_MAC);
    MepLbCreate.MepLbCreateBuilder lbCreateBuilder;
    if (remoteMepIdNode != null) {
        MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
        lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepId);
    } else if (remoteMepMacNode != null) {
        MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
        lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepMac);
    } else {
        throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
    }
    JsonNode numMessagesNode = loopbackNode.get(NUMBER_MESSAGES);
    if (numMessagesNode != null) {
        int numMessages = numMessagesNode.asInt();
        lbCreateBuilder.numberMessages(numMessages);
    }
    JsonNode vlanDropEligibleNode = loopbackNode.get(VLAN_DROP_ELIGIBLE);
    if (vlanDropEligibleNode != null) {
        boolean vlanDropEligible = vlanDropEligibleNode.asBoolean();
        lbCreateBuilder.vlanDropEligible(vlanDropEligible);
    }
    JsonNode vlanPriorityNode = loopbackNode.get(VLAN_PRIORITY);
    if (vlanPriorityNode != null) {
        short vlanPriority = (short) vlanPriorityNode.asInt();
        lbCreateBuilder.vlanPriority(Priority.values()[vlanPriority]);
    }
    JsonNode dataTlvHexNode = loopbackNode.get(DATA_TLV_HEX);
    if (dataTlvHexNode != null) {
        String dataTlvHex = loopbackNode.get(DATA_TLV_HEX).asText();
        if (!dataTlvHex.isEmpty()) {
            lbCreateBuilder.dataTlv(HexString.fromHexString(dataTlvHex));
        }
    }
    return lbCreateBuilder.build();
}
Also used : DefaultMepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate) MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 10 with MepId

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

the class CfmMepManagerTest method testCreateMep.

@Test
public void testCreateMep() throws CfmConfigException {
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
    expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(DEVICE_ID1)).andReturn(testDriver).anyTimes();
    expect(driverService.getDriver(DEVICE_ID2)).andReturn(testDriver).anyTimes();
    replay(driverService);
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, DEVICE_ID1, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    // Expecting false - since it was not found
    assertTrue(mepManager.createMep(MDNAME1, MANAME1, mep3));
}
Also used : DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Aggregations

MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)25 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)17 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)15 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)14 Consumes (javax.ws.rs.Consumes)13 Produces (javax.ws.rs.Produces)13 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Path (javax.ws.rs.Path)9 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Test (org.junit.Test)6 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)6 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 PUT (javax.ws.rs.PUT)5 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 GET (javax.ws.rs.GET)4