use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry 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);
}
});
});
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class MepWebResource method getMep.
/**
* Get MEP by MD name, MA name and Mep 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
* @return 200 OK with details of the MEP or 500 on error
*/
@GET
@Path("{mep_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
log.debug("GET called for MEP {}", mdName + "/" + maName + "/" + mepId);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepEntry mepEntry = get(CfmMepService.class).getMep(mdId, maId, MepId.valueOf(mepId));
if (mepEntry == null) {
return Response.serverError().entity("{ \"failure\":\"MEP " + mdName + "/" + maName + "/" + mepId + " not found\" }").build();
}
ObjectNode node = mapper().createObjectNode();
node.set("mep", codec(MepEntry.class).encode(mepEntry, this));
return ok(node).build();
} catch (CfmConfigException e) {
log.error("Get Mep {} failed because of exception", mdName + "/" + maName + "/" + mepId, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class MepEntryCodecTest method testEncodeIterableOfMepEntryCodecContext.
@Test
public void testEncodeIterableOfMepEntryCodecContext() throws CfmConfigException {
MepEntry mepEntry2 = DefaultMepEntry.builder(MepId.valueOf((short) 33), DeviceId.deviceId("netconf:4321:830"), PortNumber.portNumber(1), MepDirection.DOWN_MEP, MdIdCharStr.asMdId("md-2"), MaIdCharStr.asMaId("ma-2-2")).buildEntry();
ArrayList<MepEntry> meps = new ArrayList<>();
meps.add(mepEntry1);
meps.add(mepEntry2);
ObjectNode node = mapper.createObjectNode();
node.set("mep", context.codec(MepEntry.class).encode(meps, context));
Iterator<JsonNode> an = node.get("mep").elements();
while (an.hasNext()) {
JsonNode jn = an.next();
assertEquals("md-", jn.get("mdName").asText().substring(0, 3));
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class LmWebResourceTest method testCreateLm.
@Test
public void testCreateLm() throws CfmConfigException, SoamConfigException {
MepEntry mep1 = DefaultMepEntry.builder(MEPID1, DeviceId.deviceId("netconf:1.2.3.4:830"), PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
replay(mepService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("lm", context.codec(LossMeasurementCreate.class).encode(lm1, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/lm").request().post(Entity.json(node.toString()));
assertEquals(201, response.getStatus());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class DmWebResourceTest method testCreateDm.
@Test
public void testCreateDm() throws CfmConfigException, SoamConfigException {
MepEntry mep1 = DefaultMepEntry.builder(MEPID1, DeviceId.deviceId("netconf:1.2.3.4:830"), PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
replay(mepService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("dm", context.codec(DelayMeasurementCreate.class).encode(dm1, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep/" + MEPID1.value() + "/dm").request().post(Entity.json(node.toString()));
assertEquals(201, response.getStatus());
}
Aggregations