Search in sources :

Example 6 with MdId

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

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

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

the class CfmMaAddCommand method doExecute.

@Override
protected void doExecute() {
    CfmMdService service = get(CfmMdService.class);
    String[] mdNameParts = mdName.split("[()]");
    if (mdNameParts.length != 2) {
        throw new IllegalArgumentException("Invalid name format. " + "Must be in the format of <identifier(name-type)>");
    }
    MdId mdId = CfmMdListMdCommand.parseMdName(mdNameParts[0] + "(" + mdNameParts[1] + ")");
    MaIdShort maId = CfmMdListMdCommand.parseMaName(name + "(" + nameType + ")");
    try {
        MaintenanceAssociation.MaBuilder builder = DefaultMaintenanceAssociation.builder(maId, mdId.getNameLength());
        if (ccmInterval != null && !ccmInterval.isEmpty()) {
            builder = builder.ccmInterval(MaintenanceAssociation.CcmInterval.valueOf(ccmInterval));
        }
        for (String rmep : rmepArray) {
            builder = builder.addToRemoteMepIdList(MepId.valueOf(Short.parseShort(rmep)));
        }
        if (numericId != null) {
            builder = builder.maNumericId(numericId);
        }
        if (componentId != null) {
            Component.ComponentBuilder compBuilder = DefaultComponent.builder(componentId);
            if (tagType != null && !tagType.isEmpty()) {
                compBuilder = compBuilder.tagType(Component.TagType.valueOf(tagType));
            }
            if (mhfCreationType != null && !mhfCreationType.isEmpty()) {
                compBuilder = compBuilder.mhfCreationType(Component.MhfCreationType.valueOf(mhfCreationType));
            }
            if (vid != null) {
                compBuilder = compBuilder.addToVidList(VlanId.vlanId(vid));
            }
            builder = builder.addToComponentList(compBuilder.build());
        }
        boolean created = service.createMaintenanceAssociation(mdId, builder.build());
        print("Maintenance Association %s is successfully %s on MD %s", maId, created ? "updated" : "created", mdId);
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) Component(org.onosproject.incubator.net.l2monitoring.cfm.Component) DefaultComponent(org.onosproject.incubator.net.l2monitoring.cfm.DefaultComponent) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)

Example 9 with MdId

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

the class CfmMaDeleteCommand method doExecute.

@Override
protected void doExecute() {
    CfmMdService service = get(CfmMdService.class);
    String[] nameParts = name.split("[()]");
    if (nameParts.length != MA_NAME_PARTS_COUNT) {
        throw new IllegalArgumentException("Invalid name format. Must be in " + "the format of <identifier(name-type)identifier(name-type)>");
    }
    MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
    MaIdShort maId = CfmMdListMdCommand.parseMaName(nameParts[2] + "(" + nameParts[3] + ")");
    try {
        boolean deleted = service.deleteMaintenanceAssociation(mdId, maId);
        print("Maintenance Association %s-%s is %ssuccessfully deleted.", mdId, maId, deleted ? "" : "NOT ");
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : 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) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)

Example 10 with MdId

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

the class CfmMdDeleteCommand method doExecute.

@Override
protected void doExecute() {
    CfmMdService service = get(CfmMdService.class);
    String[] nameParts = name.split("[()]");
    if (nameParts.length != 2) {
        throw new IllegalArgumentException("Invalid name format. " + "Must be in the format of <identifier(name-type)>");
    }
    MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
    try {
        boolean deleted = service.deleteMaintenanceDomain(mdId);
        print("Maintenance Domain %s is %ssuccessfully deleted.", mdId, deleted ? "" : "NOT ");
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)

Aggregations

MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)30 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)27 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)23 Consumes (javax.ws.rs.Consumes)21 Produces (javax.ws.rs.Produces)21 Path (javax.ws.rs.Path)14 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)14 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)12 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)10 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 GET (javax.ws.rs.GET)7 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)6 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 DELETE (javax.ws.rs.DELETE)5 PUT (javax.ws.rs.PUT)5