Search in sources :

Example 1 with DelayMeasurementEntry

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

the class DmWebResourceTest method testGetAllDmsForMepEmpty.

@Test
public void testGetAllDmsForMepEmpty() throws CfmConfigException, SoamConfigException {
    List<DelayMeasurementEntry> dmListEmpty = new ArrayList<>();
    expect(soamService.getAllDms(MDNAME1, MANAME1, MEPID1)).andReturn(dmListEmpty).anyTimes();
    replay(soamService);
    final WebTarget wt = target();
    final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/dm").request().get(String.class);
    assertThat(response, is("{\"dms\":[[]]}"));
}
Also used : DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) DefaultDelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) CfmResourceTest(org.onosproject.cfm.impl.CfmResourceTest)

Example 2 with DelayMeasurementEntry

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

the class DmWebResource method getAllDmsForMep.

/**
 * Get all DMs for a Mep.
 *
 * @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 a Mep belonging to the MA
 * @return 200 OK with a list of DMs or 500 on error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getAllDmsForMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
    log.debug("GET all DMs called for MEP {}", mdName + "/" + maName + "/" + mepId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Collection<DelayMeasurementEntry> dmCollection = get(SoamService.class).getAllDms(mdId, maId, mepIdObj);
        ArrayNode an = mapper().createArrayNode();
        an.add(codec(DelayMeasurementEntry.class).encode(dmCollection, this));
        return ok(mapper().createObjectNode().set("dms", an)).build();
    } catch (CfmConfigException | SoamConfigException e) {
        log.error("Get DM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 3 with DelayMeasurementEntry

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

the class DmWebResource method getDm.

/**
 * Get DM by MD name, MA name, Mep Id and Dm id.
 *
 * @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
 * @param dmId The Id of the DM
 * @return 200 OK with details of the DM or 500 on error
 */
@GET
@Path("{dm_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, @PathParam("dm_id") int dmId) {
    log.debug("GET called for DM {}", mdName + "/" + maName + "/" + mepId + "/" + dmId);
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        SoamId dmIdObj = SoamId.valueOf(dmId);
        DelayMeasurementEntry dm = get(SoamService.class).getDm(mdId, maId, mepIdObj, dmIdObj);
        if (dm == null) {
            return Response.serverError().entity("{ \"failure\":\"DM " + mdName + "/" + maName + "/" + mepId + "/" + dmId + " not found\" }").build();
        }
        ObjectNode node = mapper().createObjectNode();
        node.set("dm", codec(DelayMeasurementEntry.class).encode(dm, this));
        return ok(node).build();
    } catch (CfmConfigException | SoamConfigException e) {
        log.error("Get DM {} failed because of exception {}", mdName + "/" + maName + "/" + mepId + "/" + dmId, e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) SoamId(org.onosproject.incubator.net.l2monitoring.soam.SoamId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 4 with DelayMeasurementEntry

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

the class DmEntryCodec method encode.

@Override
public ObjectNode encode(DelayMeasurementEntry dm, CodecContext context) {
    checkNotNull(dm, "DM cannot be null");
    ObjectNode result = context.mapper().createObjectNode().put(DM_ID, dm.dmId().toString());
    if (dm.sessionStatus() != null) {
        result.put(SESSION_STATUS, dm.sessionStatus().name());
    }
    if (dm.frameDelayTwoWay() != null) {
        result.put(FRAME_DELAY_TWO_WAY, dm.frameDelayTwoWay().toString());
    }
    if (dm.frameDelayForward() != null) {
        result.put(FRAME_DELAY_FORWARD, dm.frameDelayForward().toString());
    }
    if (dm.frameDelayBackward() != null) {
        result.put(FRAME_DELAY_BACKWARD, dm.frameDelayBackward().toString());
    }
    if (dm.interFrameDelayVariationTwoWay() != null) {
        result.put(INTER_FRAME_DELAY_VARIATION_TWO_WAY, dm.interFrameDelayVariationTwoWay().toString());
    }
    if (dm.interFrameDelayVariationForward() != null) {
        result.put(INTER_FRAME_DELAY_VARIATION_FORWARD, dm.interFrameDelayVariationForward().toString());
    }
    if (dm.interFrameDelayVariationBackward() != null) {
        result.put(INTER_FRAME_DELAY_VARIATION_BACKWARD, dm.interFrameDelayVariationBackward().toString());
    }
    ObjectNode dmAttrs = new DmCreateCodec().encode(dm, context);
    Iterator<Entry<String, JsonNode>> elements = dmAttrs.fields();
    while (elements.hasNext()) {
        Entry<String, JsonNode> element = elements.next();
        result.set(element.getKey(), element.getValue());
    }
    if (dm.currentResult() != null) {
        result.set(CURRENT, new DelayMeasurementStatCurrentCodec().encode(dm.currentResult(), context));
    }
    if (dm.historicalResults() != null) {
        result.set(HISTORIC, new DelayMeasurementStatHistoryCodec().encode(dm.historicalResults(), context));
    }
    return result;
}
Also used : Entry(java.util.Map.Entry) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with DelayMeasurementEntry

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

the class SoamManagerTest method setup.

@Before
public void setup() throws CfmConfigException, SoamConfigException {
    soamManager = new SoamManager();
    TestUtils.setField(soamManager, "coreService", new TestCoreService());
    TestUtils.setField(soamManager, "cfmMepService", mepService);
    TestUtils.setField(soamManager, "deviceService", deviceService);
    injectEventDispatcher(soamManager, new TestEventDispatcher());
    soamService = soamManager;
    soamManager.activate();
    DelayMeasurementEntry dmEntry1 = DefaultDelayMeasurementEntry.builder(DMID101, DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO5).build();
    DelayMeasurementEntry dmEntry2 = DefaultDelayMeasurementEntry.builder(DMID102, DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO6).build();
    mep1 = DefaultMepEntry.builder(MEPID1, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).addToDelayMeasurementList(dmEntry1).addToDelayMeasurementList(dmEntry2).buildEntry();
    device1 = new DefaultDevice(ProviderId.NONE, DEVICE_ID1, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(1), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
    AbstractProjectableModel.setDriverService(null, driverService);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    behaviours.put(CfmMepProgrammable.class, TestCfmMepProgrammable.class);
    behaviours.put(SoamDmProgrammable.class, TestSoamDmProgrammable.class);
    testDriver = new DefaultDriver(TEST_DRIVER, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, behaviours, new HashMap<>());
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry) DefaultDelayMeasurementEntry(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry) DefaultDevice(org.onosproject.net.DefaultDevice) DefaultDriver(org.onosproject.net.driver.DefaultDriver) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Aggregations

DelayMeasurementEntry (org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry)8 DefaultDelayMeasurementEntry (org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 WebTarget (javax.ws.rs.client.WebTarget)2 CfmResourceTest (org.onosproject.cfm.impl.CfmResourceTest)2 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)2 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)2 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)2 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)2 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)2 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1