Search in sources :

Example 26 with MdId

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

the class MepWebResource method getMep.

/**
 * Get MEP by MD name, MA name and Mep 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
 * @return 200 OK with details of the MEP or 500 on error
 */
@GET
@Path("{mep_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
    log.debug("GET called for MEP {}", mdName + "/" + maName + "/" + mepId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepEntry mepEntry = get(CfmMepService.class).getMep(mdId, maId, MepId.valueOf(mepId));
        if (mepEntry == null) {
            return Response.serverError().entity("{ \"failure\":\"MEP " + mdName + "/" + maName + "/" + mepId + " not found\" }").build();
        }
        ObjectNode node = mapper().createObjectNode();
        node.set("mep", codec(MepEntry.class).encode(mepEntry, this));
        return ok(node).build();
    } catch (CfmConfigException e) {
        log.error("Get Mep {} failed because of exception", mdName + "/" + maName + "/" + mepId, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 27 with MdId

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

the class MepWebResource method createMep.

/**
 * Create MEP with MD name, MA name and Mep Json.
 *
 * @onos.rsModel MepCreate
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param input A JSON formatted input stream specifying the Mep parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, InputStream input) {
    log.debug("POST called to Create Mep");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).orElseThrow(() -> new IllegalArgumentException("MA " + mdName + "/" + maName + " not Found"));
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper(), input);
        JsonCodec<Mep> mepCodec = codec(Mep.class);
        Mep mep = ((MepCodec) mepCodec).decode((ObjectNode) cfg, this, mdName, maName);
        Boolean didNotExist = get(CfmMepService.class).createMep(mdId, maId, mep);
        if (!didNotExist) {
            return Response.notModified(mdName + "/" + ma.maId() + "/" + mep.mepId() + " already exists").build();
        }
        return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId() + "/mep/" + mep.mepId())).entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() + "/" + mep.mepId() + " created\" }").build();
    } catch (Exception | CfmConfigException e) {
        log.error("Create Mep on " + mdName + "/" + maName + " failed because of exception {}", e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MepCodec(org.onosproject.cfm.web.MepCodec) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) 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) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 28 with MdId

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

the class MaintenanceDomainCodec method decode.

/**
 * Decodes the MaintenanceDomain entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MaintenanceDomain
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MaintenanceDomain decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode mdNode = json.get(MD);
    String mdName = nullIsIllegal(mdNode.get(MD_NAME), "mdName is required").asText();
    String mdNameType = MdId.MdNameType.CHARACTERSTRING.name();
    if (mdNode.get(MD_NAME_TYPE) != null) {
        mdNameType = mdNode.get(MD_NAME_TYPE).asText();
    }
    try {
        MdId mdId = MdMaNameUtil.parseMdName(mdNameType, mdName);
        MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain.builder(mdId);
        JsonNode mdLevelNode = mdNode.get(MD_LEVEL);
        if (mdLevelNode != null) {
            MdLevel mdLevel = MdLevel.valueOf(mdLevelNode.asText());
            builder = builder.mdLevel(mdLevel);
        }
        JsonNode mdNumericIdNode = mdNode.get(MD_NUMERIC_ID);
        if (mdNumericIdNode != null) {
            short mdNumericId = (short) mdNumericIdNode.asInt();
            builder = builder.mdNumericId(mdNumericId);
        }
        return builder.build();
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MdLevel(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain.MdLevel)

Example 29 with MdId

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

the class MepCodec method decode.

/**
 * Decodes the Mep entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @param mdName The MD name
 * @param maName The MA name
 * @return decoded Mep
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
public Mep decode(ObjectNode json, CodecContext context, String mdName, String maName) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode mepNode = json.get("mep");
    int mepId = Integer.parseInt(nullIsIllegal(mepNode.get("mepId"), "mepId is required").asText());
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(mepNode.get("deviceId"), "deviceId is required").asText());
    PortNumber port = PortNumber.portNumber(Long.parseLong(nullIsIllegal(mepNode.get("port"), "port is required").asText()));
    MepDirection direction = MepDirection.valueOf(nullIsIllegal(mepNode.get("direction"), "direction is required").asText());
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepBuilder mepBuilder = DefaultMep.builder(MepId.valueOf((short) mepId), deviceId, port, direction, mdId, maId);
        if (mepNode.get(PRIMARY_VID) != null) {
            mepBuilder.primaryVid(VlanId.vlanId((short) mepNode.get(PRIMARY_VID).asInt(0)));
        }
        if (mepNode.get(ADMINISTRATIVE_STATE) != null) {
            mepBuilder.administrativeState(mepNode.get(ADMINISTRATIVE_STATE).asBoolean());
        }
        if (mepNode.get(CCM_LTM_PRIORITY) != null) {
            mepBuilder.ccmLtmPriority(Priority.values()[mepNode.get(CCM_LTM_PRIORITY).asInt(0)]);
        }
        if (mepNode.get(CCI_ENABLED) != null) {
            mepBuilder.cciEnabled(mepNode.get(CCI_ENABLED).asBoolean());
        }
        if (mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT) != null) {
            mepBuilder.lowestFaultPriorityDefect(Mep.LowestFaultDefect.values()[mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT).asInt()]);
        }
        if (mepNode.get(DEFECT_ABSENT_TIME) != null) {
            mepBuilder.defectAbsentTime(Duration.parse(mepNode.get(DEFECT_ABSENT_TIME).asText()));
        }
        if (mepNode.get(DEFECT_PRESENT_TIME) != null) {
            mepBuilder.defectPresentTime(Duration.parse(mepNode.get(DEFECT_PRESENT_TIME).asText()));
        }
        if (mepNode.get(FNG_ADDRESS) != null) {
            mepBuilder.fngAddress((new FngAddressCodec()).decode((ObjectNode) mepNode, context));
        }
        return mepBuilder.build();
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MepBuilder(org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepBuilder) DeviceId(org.onosproject.net.DeviceId) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) JsonNode(com.fasterxml.jackson.databind.JsonNode) MepDirection(org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection) PortNumber(org.onosproject.net.PortNumber) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)

Example 30 with MdId

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

the class CfmMepListCommand method doExecute.

@Override
protected void doExecute() {
    CfmMepService mepService = get(CfmMepService.class);
    CfmMdService mdService = get(CfmMdService.class);
    if (mdStr != null && !mdStr.isEmpty()) {
        MdId mdId = parseMdName(mdStr);
        print(printMdId(mdId));
        if (maStr != null && !maStr.isEmpty()) {
            MaIdShort maId = parseMaName(maStr);
            print(printMaId(maId));
            if (mepStr != null && !mepStr.isEmpty()) {
                MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
                try {
                    MepEntry mep = mepService.getMep(mdId, maId, mepId);
                    if (mep != null) {
                        print(printMepEntry(mep));
                    }
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Mep details {}", new MepKeyId(mdId, maId, mepId), e);
                }
            // MD, MA and MEP given
            } else {
                // MD and MA given but no MEP given
                try {
                    mepService.getAllMeps(mdId, maId).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), maId.maName(), e);
                }
            }
        } else {
            // MD given but no MA given
            mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", mdId.mdName(), ma.maId().maName(), e);
                }
            });
        }
    } else {
        mdService.getAllMaintenanceDomain().forEach(md -> {
            print(printMdId(md.mdId()));
            mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
                print(printMaId(ma.maId()));
                try {
                    mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> print(printMepEntry(mep)));
                } catch (CfmConfigException e) {
                    log.error("Error retrieving Meps for {}/{}", md.mdId().mdName(), ma.maId().maName(), e);
                }
            });
        });
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) 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) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

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