Search in sources :

Example 21 with MaIdShort

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

the class MepWebResource method transmitLinktrace.

/**
 * Transmit Linktrace on MEP with MD name, MA name and Mep Id.
 *
 * @onos.rsModel MepLtTransmit
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param mepIdShort The id of a MEP belonging to the MA
 * @param input A JSON formatted input stream specifying the Linktrace parameters
 * @return 202 Received with success message or 500 on error
 */
@PUT
@Path("{mep_id}/transmit-linktrace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLinktrace(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
    log.debug("PUT called to Transmit Linktrace on Mep");
    MdId mdId = MdIdCharStr.asMdId(mdName);
    MaIdShort maId = MaIdCharStr.asMaId(maName);
    MaintenanceDomain md;
    Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
    if (mdOpt.isPresent()) {
        md = mdOpt.get();
    } else {
        return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
    }
    MaintenanceAssociation ma;
    Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
    if (maOpt.isPresent()) {
        ma = maOpt.get();
    } else {
        return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
    }
    MepId mepId = MepId.valueOf(mepIdShort);
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
        MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
        get(CfmMepService.class).transmitLinktrace(md.mdId(), ma.maId(), mepId, ltCreate);
    } catch (Exception | CfmConfigException e) {
        log.error("Transmit Linktrace on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
    return Response.accepted().entity("{ \"success\":\"Linktrace on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) 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) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 22 with MaIdShort

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

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

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

the class MaintenanceAssociationCodec method decode.

/**
 * Decodes the MaintenanceAssociation entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @param mdNameLen the length of the corresponding MD's name
 * @return decoded MaintenanceAssociation
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
public MaintenanceAssociation decode(ObjectNode json, CodecContext context, int mdNameLen) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode maNode = json.get(MA);
    String maName = nullIsIllegal(maNode.get(MA_NAME), "maName is required").asText();
    String maNameType = MaIdShort.MaIdType.CHARACTERSTRING.name();
    if (maNode.get(MA_NAME_TYPE) != null) {
        maNameType = maNode.get(MA_NAME_TYPE).asText();
    }
    try {
        MaIdShort maId = MdMaNameUtil.parseMaName(maNameType, maName);
        MaBuilder builder = DefaultMaintenanceAssociation.builder(maId, mdNameLen);
        JsonNode maNumericIdNode = maNode.get(MA_NUMERIC_ID);
        if (maNumericIdNode != null) {
            short mdNumericId = (short) maNumericIdNode.asInt();
            builder = builder.maNumericId(mdNumericId);
        }
        if (maNode.get(CCM_INTERVAL) != null) {
            builder.ccmInterval(CcmInterval.valueOf(maNode.get(CCM_INTERVAL).asText()));
        }
        List<Component> componentList = (new ComponentCodec()).decode((ArrayNode) nullIsIllegal(maNode.get(COMPONENT_LIST), "component-list is required"), context);
        for (Component component : componentList) {
            builder = builder.addToComponentList(component);
        }
        JsonNode rmepListJson = maNode.get(RMEP_LIST);
        if (rmepListJson != null) {
            List<MepId> remoteMeps = (new RMepCodec()).decode((ArrayNode) rmepListJson, context);
            for (MepId remoteMep : remoteMeps) {
                builder = builder.addToRemoteMepIdList(remoteMep);
            }
        }
        return builder.build();
    } catch (CfmConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : MaBuilder(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.MaBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) Component(org.onosproject.incubator.net.l2monitoring.cfm.Component) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 25 with MaIdShort

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

Aggregations

MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)26 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)23 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)23 Consumes (javax.ws.rs.Consumes)19 Produces (javax.ws.rs.Produces)19 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)15 Path (javax.ws.rs.Path)13 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)7 GET (javax.ws.rs.GET)7 CfmMdService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService)7 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)6 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 PUT (javax.ws.rs.PUT)5 DELETE (javax.ws.rs.DELETE)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3