Search in sources :

Example 6 with MepEntry

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;
}
Also used : Entry(java.util.Map.Entry) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with MepEntry

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();
    }
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 8 with MepEntry

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\":[]}]]}"));
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 9 with MepEntry

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;
}
Also used : MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)

Example 10 with MepEntry

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);
}
Also used : SoamDmProgrammable(org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)

Aggregations

MepEntry (org.onosproject.incubator.net.l2monitoring.cfm.MepEntry)15 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)9 Test (org.junit.Test)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 DefaultMepEntry (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry)5 SoamDmProgrammable (org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable)4 ArrayList (java.util.ArrayList)3 WebTarget (javax.ws.rs.client.WebTarget)3 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)3 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)3 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)2 CfmResourceTest (org.onosproject.cfm.impl.CfmResourceTest)2 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)2