use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class MepEntryCodec method encode.
/**
* Encodes the MepEntry entity into JSON.
*
* @param mepEntry MepEntry to encode
* @param context encoding context
* @return JSON node
* @throws java.lang.UnsupportedOperationException if the codec does not
* support encode operations
*/
@Override
public ObjectNode encode(MepEntry mepEntry, CodecContext context) {
checkNotNull(mepEntry, "Mep cannot be null");
ObjectNode result = context.mapper().createObjectNode();
// Get the common attributes
Mep mep = mepEntry;
ObjectNode mepAttrs = new MepCodec().encode(mep, context);
Iterator<Entry<String, JsonNode>> elements = mepAttrs.fields();
while (elements.hasNext()) {
Entry<String, JsonNode> element = elements.next();
result.set(element.getKey(), element.getValue());
}
if (mepEntry.macAddress() != null) {
result.put("macAddress", mepEntry.macAddress().toString());
}
if (mepEntry.loopbackAttributes() != null) {
result.set("loopback", new MepLbEntryCodec().encode(mepEntry.loopbackAttributes(), context));
}
if (mepEntry.activeRemoteMepList() != null) {
result.set("remoteMeps", new RemoteMepEntryCodec().encode(mepEntry.activeRemoteMepList(), context));
}
if (mepEntry.activeErrorCcmDefect()) {
result.put("activeErrorCcmDefect", true);
}
if (mepEntry.activeMacStatusDefect()) {
result.put("activeMacStatusDefect", true);
}
if (mepEntry.activeRdiCcmDefect()) {
result.put("activeRdiCcmDefect", true);
}
if (mepEntry.activeRemoteCcmDefect()) {
result.put("activeRemoteCcmDefect", true);
}
if (mepEntry.activeXconCcmDefect()) {
result.put("activeXconCcmDefect", true);
}
return result;
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class MepWebResource method getAllMepsForMa.
/**
* Get all MEPs by MD name, MA name.
*
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @return 200 OK with a list of MEPS or 500 on error
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getAllMepsForMa(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName) {
log.debug("GET all Meps called for MA {}", mdName + "/" + maName);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
Collection<MepEntry> mepCollection = get(CfmMepService.class).getAllMeps(mdId, maId);
ArrayNode an = mapper().createArrayNode();
an.add(codec(MepEntry.class).encode(mepCollection, this));
return ok(mapper().createObjectNode().set("meps", an)).build();
} catch (CfmConfigException e) {
log.error("Get all Meps on {} failed because of exception", mdName + "/" + maName, 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 MepWebResourceTest method testGetAllMepsForMa1Mep.
@Test
public void testGetAllMepsForMa1Mep() throws CfmConfigException {
Collection<MepEntry> meps = new ArrayList<>();
meps.add(mepEntry1);
expect(mepService.getAllMeps(MDNAME1, MANAME1)).andReturn(meps).anyTimes();
replay(mepService);
final WebTarget wt = target();
final String response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().get(String.class);
assertThat(response, is("{\"meps\":" + "[[{" + "\"mepId\":" + MEPID1.value() + "," + "\"deviceId\":\"netconf:1.2.3.4:830\"," + "\"port\":1," + "\"direction\":\"UP_MEP\"," + "\"mdName\":\"" + MDNAME1.mdName() + "\"," + "\"maName\":\"" + MANAME1.maName() + "\"," + "\"administrative-state\":false," + "\"cci-enabled\":false," + "\"remoteMeps\":[]}]]}"));
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class CfmMepManager method getAllMeps.
@Override
public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName) throws CfmConfigException {
// Will throw IllegalArgumentException if ma does not exist
cfmMdService.getMaintenanceAssociation(mdName, maName);
Collection<Mep> mepStoreCollection = mepStore.getAllMeps();
Collection<MepEntry> mepEntryCollection = new ArrayList<>();
for (Mep mep : mepStoreCollection) {
if (mep.mdId().equals(mdName) && mep.maId().equals(maName)) {
DeviceId mepDeviceId = mep.deviceId();
if (deviceService.getDevice(mepDeviceId) == null) {
log.warn("Device not found/available " + mepDeviceId + " for MEP: " + mdName + "/" + maName + "/" + mep.mepId());
continue;
} else if (!deviceService.getDevice(mepDeviceId).is(CfmMepProgrammable.class)) {
throw new CfmConfigException("Device " + mepDeviceId + " does not support CfmMepProgrammable behaviour.");
}
log.debug("Retrieving MEP results for Mep {} in MD {}, MA {} " + "on Device {}", mep.mepId(), mdName, maName, mepDeviceId);
mepEntryCollection.add(deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).getMep(mdName, maName, mep.mepId()));
}
}
return mepEntryCollection;
}
use of org.onosproject.incubator.net.l2monitoring.cfm.MepEntry in project onos by opennetworkinglab.
the class SoamManager method getAllDms.
@Override
public Collection<DelayMeasurementEntry> getAllDms(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException, SoamConfigException {
MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
if (mep == null || mep.deviceId() == null) {
throw new CfmConfigException("MEP :" + mdName + "/" + maName + "/" + mepId + " does not exist");
} else if (deviceService.getDevice(mep.deviceId()) == null) {
throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" + mdName + "/" + maName + "/" + mepId + " does not exist");
} else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" + mdName + "/" + maName + "/" + mepId + " does not implement SoamDmProgrammable");
}
log.debug("Retrieving DMs for MD {}, MA {}, MEP {} on Device {}", mdName, maName, mepId, mep.deviceId());
return deviceService.getDevice(mep.deviceId()).as(SoamDmProgrammable.class).getAllDms(mdName, maName, mepId);
}
Aggregations