Search in sources :

Example 21 with MepId

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

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

the class MepLtCreateCodec method decode.

/**
 * Decodes the MepLtCreate entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MepLtCreate
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MepLtCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode linktraceNode = json.get(LINKTRACE);
    JsonNode remoteMepIdNode = linktraceNode.get(REMOTE_MEP_ID);
    JsonNode remoteMepMacNode = linktraceNode.get(REMOTE_MEP_MAC);
    MepLtCreate.MepLtCreateBuilder ltCreateBuilder;
    if (remoteMepIdNode != null) {
        MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
        ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepId);
    } else if (remoteMepMacNode != null) {
        MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
        ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepMac);
    } else {
        throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
    }
    JsonNode defaultTtlNode = linktraceNode.get(DEFAULT_TTL);
    if (defaultTtlNode != null) {
        short defaultTtl = (short) defaultTtlNode.asInt();
        ltCreateBuilder.defaultTtl(defaultTtl);
    }
    JsonNode transmitLtmFlagsNode = linktraceNode.get(TRANSMIT_LTM_FLAGS);
    if (transmitLtmFlagsNode != null) {
        if (transmitLtmFlagsNode.asText().isEmpty()) {
            ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 0 }));
        } else if (transmitLtmFlagsNode.asText().equals(USE_FDB_ONLY)) {
            ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 1 }));
        } else {
            throw new IllegalArgumentException("Expecting value 'use-fdb-only' " + "or '' for " + TRANSMIT_LTM_FLAGS);
        }
    }
    return ltCreateBuilder.build();
}
Also used : DefaultMepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 23 with MepId

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

Example 24 with MepId

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

the class MepWebResourceTest method testCreateMep.

@Test
public void testCreateMep() throws CfmConfigException, IOException {
    MepId mepId2 = MepId.valueOf((short) 2);
    Mep mep2 = DefaultMep.builder(mepId2, DeviceId.deviceId("netconf:2.2.3.4:830"), PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    MaintenanceAssociation ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(mepService.createMep(MDNAME1, MANAME1, mep2)).andReturn(true).anyTimes();
    replay(mepService);
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("mep", context.codec(Mep.class).encode(mep2, context));
    final WebTarget wt = target();
    final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().post(Entity.json(node.toString()));
    assertEquals("Expecting 201", 201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 25 with MepId

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

the class LmCreateCodec method decode.

@Override
public LossMeasurementCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode lmNode = json.get(LM);
    Version version = Version.Y17312011;
    if (lmNode.get(VERSION) != null) {
        version = Version.valueOf(lmNode.get(VERSION).asText());
    }
    LmType lmCfgType = LmType.LMLMM;
    if (lmNode.get(LM_CFG_TYPE) != null) {
        lmCfgType = LmType.valueOf(lmNode.get(LM_CFG_TYPE).asText(LMLMM));
    }
    MepId remoteMepId = MepId.valueOf(nullIsIllegal(lmNode.get(REMOTE_MEP_ID), REMOTE_MEP_ID + " is required").shortValue());
    Priority prio = Priority.valueOf(nullIsIllegal(lmNode.get(PRIORITY), PRIORITY + " is required in the format 'PRIOn'").asText());
    try {
        LmCreateBuilder builder = DefaultLmCreate.builder(version, remoteMepId, prio, lmCfgType);
        if (lmNode.get(COUNTERS_ENABLED) != null) {
            context.codec(CounterOption.class).decode((ArrayNode) (lmNode.get(COUNTERS_ENABLED)), context).forEach(builder::addToCountersEnabled);
        }
        if (lmNode.get(THRESHOLDS) != null) {
            context.codec(LossMeasurementThreshold.class).decode((ArrayNode) (lmNode.get(THRESHOLDS)), context).forEach(builder::addToLossMeasurementThreshold);
        }
        if (lmNode.get(AVAILABILITY_MEASUREMENT_INTERVAL_MINS) != null) {
            builder = builder.availabilityMeasurementInterval(Duration.ofMinutes(lmNode.get(AVAILABILITY_MEASUREMENT_INTERVAL_MINS).asInt()));
        }
        if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_FLR_MEASUREMENTS) != null) {
            builder = builder.availabilityNumberConsecutiveFlrMeasurements(lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_FLR_MEASUREMENTS).asInt());
        }
        if (lmNode.get(AVAILABILITY_FLR_THRESHOLD_PCT) != null) {
            builder = builder.availabilityFlrThreshold(MilliPct.ofPercent((float) lmNode.get(AVAILABILITY_FLR_THRESHOLD_PCT).asDouble()));
        }
        if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_INTERVALS) != null) {
            builder = builder.availabilityNumberConsecutiveIntervals((short) lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_INTERVALS).asInt());
        }
        if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_HIGH_FLR) != null) {
            builder = builder.availabilityNumberConsecutiveHighFlr((short) lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_HIGH_FLR).asInt());
        }
        if (lmNode.get(FRAME_SIZE) != null) {
            builder = (LmCreateBuilder) builder.frameSize((short) lmNode.get(FRAME_SIZE).asInt());
        }
        if (lmNode.get(MESSAGE_PERIOD_MS) != null) {
            builder = (LmCreateBuilder) builder.messagePeriod(Duration.ofMillis(lmNode.get(MESSAGE_PERIOD_MS).asInt()));
        }
        if (lmNode.get(MEASUREMENT_INTERVAL_MINS) != null) {
            builder = (LmCreateBuilder) builder.measurementInterval(Duration.ofMinutes(lmNode.get(MEASUREMENT_INTERVAL_MINS).asInt()));
        }
        if (lmNode.get(ALIGN_MEASUREMENT_INTERVALS) != null) {
            builder = (LmCreateBuilder) builder.alignMeasurementIntervals(lmNode.get(ALIGN_MEASUREMENT_INTERVALS).asBoolean());
        }
        if (lmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS) != null) {
            builder = (LmCreateBuilder) builder.alignMeasurementOffset(Duration.ofMinutes(lmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS).asInt()));
        }
        if (lmNode.get(START_TIME) != null) {
            builder = (LmCreateBuilder) builder.startTime(context.codec(StartTime.class).decode((ObjectNode) lmNode.get(START_TIME), context));
        }
        if (lmNode.get(STOP_TIME) != null) {
            builder = (LmCreateBuilder) builder.stopTime(context.codec(StopTime.class).decode((ObjectNode) lmNode.get(STOP_TIME), context));
        }
        return builder.build();
    } catch (SoamConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : LmCreateBuilder(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmCreateBuilder) LmType(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate.LmType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Version(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version) Priority(org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority) JsonNode(com.fasterxml.jackson.databind.JsonNode) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Aggregations

MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)25 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)17 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)15 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)14 Consumes (javax.ws.rs.Consumes)13 Produces (javax.ws.rs.Produces)13 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Path (javax.ws.rs.Path)9 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Test (org.junit.Test)6 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)6 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 PUT (javax.ws.rs.PUT)5 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 GET (javax.ws.rs.GET)4