Search in sources :

Example 1 with MdLevel

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

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DefaultMaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain)1 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)1 MdLevel (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain.MdLevel)1 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)1 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)1