Search in sources :

Example 1 with DmCreateBuilder

use of org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder in project onos by opennetworkinglab.

the class DmCreateCodecTest method testEncodeDelayMeasurementCreateCodecContext.

@Test
public void testEncodeDelayMeasurementCreateCodecContext() throws SoamConfigException {
    DmCreateBuilder builder = DefaultDelayMeasurementCreate.builder(DmType.DM1DMRX, Version.Y17312011, MepId.valueOf((short) 16), Priority.PRIO5);
    builder.addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_BACKWARD_MAX);
    builder.addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_TWO_WAY_MAX);
    builder.addToMeasurementsEnabled(MeasurementOption.INTER_FRAME_DELAY_VARIATION_BACKWARD_BINS);
    builder = (DmCreateBuilder) builder.messagePeriod(Duration.ofMillis(100));
    builder = (DmCreateBuilder) builder.frameSize((short) 1200);
    ObjectNode node = mapper.createObjectNode();
    node.set("dm", context.codec(DelayMeasurementCreate.class).encode(builder.build(), context));
    assertEquals(DmType.DM1DMRX.name(), node.get("dm").get("dmCfgType").asText());
    assertEquals(Version.Y17312011.name(), node.get("dm").get("version").asText());
    assertEquals(16, node.get("dm").get("remoteMepId").asInt());
    assertEquals(Priority.PRIO5.name(), node.get("dm").get("priority").asText());
    assertEquals(100, node.get("dm").get("messagePeriodMs").asInt());
    assertEquals(1200, node.get("dm").get("frameSize").asInt());
    assertEquals(3, ((ArrayNode) node.get("dm").get("measurementsEnabled")).size());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DmCreateBuilder(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder) Test(org.junit.Test)

Example 2 with DmCreateBuilder

use of org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder in project onos by opennetworkinglab.

the class DmCreateCodec method decode.

@Override
public DelayMeasurementCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode dmNode = json.get(DM);
    Version version = Version.Y17312011;
    if (dmNode.get(VERSION) != null) {
        version = Version.valueOf(dmNode.get(VERSION).asText());
    }
    DmType dmCfgType = DmType.DMDMM;
    if (dmNode.get(DM_CFG_TYPE) != null) {
        dmCfgType = DmType.valueOf(dmNode.get(DM_CFG_TYPE).asText(DMDMM));
    }
    MepId remoteMepId = MepId.valueOf(nullIsIllegal(dmNode.get(REMOTE_MEP_ID), REMOTE_MEP_ID + " is required").shortValue());
    Priority prio = Priority.valueOf(nullIsIllegal(dmNode.get(PRIORITY), PRIORITY + " is required in the format 'PRIOn'").asText());
    try {
        DmCreateBuilder builder = DefaultDelayMeasurementCreate.builder(dmCfgType, version, remoteMepId, prio);
        if (dmNode.get(MEASUREMENTS_ENABLED) != null) {
            context.codec(MeasurementOption.class).decode((ArrayNode) (dmNode.get(MEASUREMENTS_ENABLED)), context).forEach(builder::addToMeasurementsEnabled);
        }
        if (dmNode.get(BINS_PER_FD_INTERVAL) != null) {
            builder = builder.binsPerFdInterval((short) dmNode.get(BINS_PER_FD_INTERVAL).asInt());
        }
        if (dmNode.get(BINS_PER_IFDV_INTERVAL) != null) {
            builder = builder.binsPerIfdvInterval((short) dmNode.get(BINS_PER_IFDV_INTERVAL).asInt());
        }
        if (dmNode.get(IFDV_SELECTION_OFFSET) != null) {
            builder = builder.ifdvSelectionOffset((short) dmNode.get(IFDV_SELECTION_OFFSET).asInt());
        }
        if (dmNode.get(BINS_PER_FDR_INTERVAL) != null) {
            builder = builder.binsPerFdrInterval((short) dmNode.get(BINS_PER_FDR_INTERVAL).asInt());
        }
        if (dmNode.get(FRAME_SIZE) != null) {
            builder = (DmCreateBuilder) builder.frameSize((short) dmNode.get(FRAME_SIZE).asInt());
        }
        if (dmNode.get(MESSAGE_PERIOD_MS) != null) {
            builder = (DmCreateBuilder) builder.messagePeriod(Duration.ofMillis(dmNode.get(MESSAGE_PERIOD_MS).asInt()));
        }
        if (dmNode.get(MEASUREMENT_INTERVAL_MINS) != null) {
            builder = (DmCreateBuilder) builder.measurementInterval(Duration.ofMinutes(dmNode.get(MEASUREMENT_INTERVAL_MINS).asInt()));
        }
        if (dmNode.get(ALIGN_MEASUREMENT_INTERVALS) != null) {
            builder = (DmCreateBuilder) builder.alignMeasurementIntervals(dmNode.get(ALIGN_MEASUREMENT_INTERVALS).asBoolean());
        }
        if (dmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS) != null) {
            builder = (DmCreateBuilder) builder.alignMeasurementOffset(Duration.ofMinutes(dmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS).asInt()));
        }
        if (dmNode.get(START_TIME) != null) {
            builder = (DmCreateBuilder) builder.startTime(context.codec(StartTime.class).decode((ObjectNode) dmNode.get(START_TIME), context));
        }
        if (dmNode.get(STOP_TIME) != null) {
            builder = (DmCreateBuilder) builder.stopTime(context.codec(StopTime.class).decode((ObjectNode) dmNode.get(STOP_TIME), context));
        }
        return builder.build();
    } catch (SoamConfigException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : DmType(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType) 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) DmCreateBuilder(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder) 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

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DmCreateBuilder (org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmCreateBuilder)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Test (org.junit.Test)1 Priority (org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority)1 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)1 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)1 DmType (org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType)1 Version (org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version)1