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\":[[]]}"));
}
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();
}
}
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();
}
}
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;
}
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<>());
}
Aggregations