Search in sources :

Example 6 with SoamConfigException

use of org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException in project onos by opennetworkinglab.

the class DelayMeasurementCreateTest method setUp.

@Before
public void setUp() throws Exception, CfmConfigException, SoamConfigException {
    DelayMeasurementThreshold dmT1 = DefaultDelayMeasurementThreshold.builder(SoamId.valueOf(1)).averageFrameDelayBackward(Duration.ofMillis(123)).averageInterFrameDelayVariationForward(Duration.ofMillis(321)).build();
    DelayMeasurementThreshold dmT2 = DefaultDelayMeasurementThreshold.builder(SoamId.valueOf(2)).averageFrameDelayBackward(Duration.ofMillis(456)).averageInterFrameDelayVariationForward(Duration.ofMillis(654)).build();
    try {
        DefaultDmCreateBuilder builder = (DefaultDmCreateBuilder) DefaultDelayMeasurementCreate.builder(DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 12), Priority.PRIO6).addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MIN).addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_AVERAGE).addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_MAX).addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_FORWARD_BINS).binsPerFdInterval((short) 8).binsPerIfdvInterval((short) 9).ifdvSelectionOffset((short) 10).binsPerFdrInterval((short) 12).addToThresholds(dmT1).addToThresholds(dmT2).messagePeriod(Duration.ofMillis(100L)).frameSize((short) 64).dataPattern(DataPattern.ONES).testTlvIncluded(true).testTlvPattern(TestTlvPattern.NULL_SIGNAL_WITHOUT_CRC_32).measurementInterval(Duration.ofMinutes(15)).numberIntervalsStored((short) 32).alignMeasurementIntervals(true).alignMeasurementOffset(Duration.ofMinutes(4)).sessionType(SessionType.ONDEMAND).startTime(StartTime.relative(Duration.ofMinutes(7))).stopTime(StopTime.relative(Duration.ofMinutes(8)));
        dm1 = builder.build();
    } catch (SoamConfigException e) {
        throw new Exception(e);
    }
}
Also used : SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) DefaultDmCreateBuilder(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate.DefaultDmCreateBuilder) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) Before(org.junit.Before)

Example 7 with SoamConfigException

use of org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException in project onos by opennetworkinglab.

the class DelayMeasurementCreateTest method testInvalidStartTime.

@Test
public void testInvalidStartTime() throws CfmConfigException {
    OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1);
    try {
        DefaultDelayMeasurementCreate.builder(DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), Priority.PRIO6).startTime(StartTime.absolute(oneMinuteAgo.toInstant()));
        fail("Expected an exception to be thrown for align Start Time: " + oneMinuteAgo);
    } catch (SoamConfigException e) {
        assertEquals(SoamConfigException.class, e.getClass());
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) Test(org.junit.Test)

Example 8 with SoamConfigException

use of org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException in project onos by opennetworkinglab.

the class DmWebResource method createDm.

/**
 * Create DM with MD name, MA name, Mep id and DM Json.
 *
 * @onos.rsModel DmCreate
 * @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 belonging to the MEP
 * @param input A JSON formatted input stream specifying the DM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Dm");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Mep mep = get(CfmMepService.class).getMep(mdId, maId, mepIdObj);
        if (mep == null) {
            return Response.serverError().entity("{ \"failure\":\"mep " + mdName + "/" + maName + "/" + mepId + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<DelayMeasurementCreate> dmCodec = codec(DelayMeasurementCreate.class);
        DelayMeasurementCreate dm = dmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createDm(mdId, maId, mepIdObj, dm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/dm")).entity("{ \"success\":\"dm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create DM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) 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) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 9 with SoamConfigException

use of org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException 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)

Example 10 with SoamConfigException

use of org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException in project onos by opennetworkinglab.

the class DelayMeasurementCreateTest method testInvalidStopTime.

@Test
public void testInvalidStopTime() throws CfmConfigException {
    OffsetDateTime oneMinuteAgo = OffsetDateTime.now().minusMinutes(1);
    try {
        DefaultDelayMeasurementCreate.builder(DmType.DMDMM, Version.Y17312011, MepId.valueOf((short) 20), Priority.PRIO6).stopTime(StopTime.absolute(oneMinuteAgo.toInstant()));
        fail("Expected an exception to be thrown for align Stop Time: " + oneMinuteAgo);
    } catch (SoamConfigException e) {
        assertEquals(SoamConfigException.class, e.getClass());
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) Test(org.junit.Test)

Aggregations

SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)11 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)8 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)7 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)6 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)6 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 GET (javax.ws.rs.GET)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 OffsetDateTime (java.time.OffsetDateTime)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Test (org.junit.Test)2