Search in sources :

Example 1 with MepDirection

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection 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

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MepBuilder (org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepBuilder)1 MepDirection (org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection)1 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)1 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)1 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)1 DeviceId (org.onosproject.net.DeviceId)1 PortNumber (org.onosproject.net.PortNumber)1