Search in sources :

Example 1 with Mep

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.

the class MepWebResourceTest method testCreateMepAlreadyExists.

@Test
public void testCreateMepAlreadyExists() throws CfmConfigException, IOException {
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, DeviceId.deviceId("netconf:3.2.3.4:830"), PortNumber.portNumber(3), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).cciEnabled(true).ccmLtmPriority(Mep.Priority.PRIO3).administrativeState(false).primaryVid(VlanId.vlanId((short) 3)).defectAbsentTime(Duration.ofMinutes(2)).defectPresentTime(Duration.ofMinutes(3)).fngAddress(Mep.FngAddress.notSpecified()).lowestFaultPriorityDefect(Mep.LowestFaultDefect.ALL_DEFECTS).build();
    MaintenanceAssociation ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(mepService.createMep(MDNAME1, MANAME1, mep3)).andReturn(false).anyTimes();
    replay(mepService);
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("mep", context.codec(Mep.class).encode(mep3, context));
    final WebTarget wt = target();
    final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().post(Entity.json(node.toString()));
    assertEquals("Expecting 304", 304, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CfmCodecContext(org.onosproject.cfm.CfmCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) WebTarget(javax.ws.rs.client.WebTarget) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 2 with Mep

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.

the class LmWebResource method createLm.

/**
 * Create LM with MD name, MA name, Mep id and LM Json.
 *
 * @onos.rsModel LmCreate
 * @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 belonging to the MEP
 * @param input A JSON formatted input stream specifying the LM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createLm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Lm");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MepId mepIdObj = MepId.valueOf(mepId);
        Mep mep = get(CfmMepService.class).getMep(mdId, maId, mepIdObj);
        if (mep == null) {
            return Response.serverError().entity("{ \"failure\":\"mep " + mdName + "/" + maName + "/" + mepId + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<LossMeasurementCreate> lmCodec = codec(LossMeasurementCreate.class);
        LossMeasurementCreate lm = lmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createLm(mdId, maId, mepIdObj, lm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/lm")).entity("{ \"success\":\"lm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create LM on " + mdName + "/" + maName + "/" + mepId + " failed because of exception {}", e.toString());
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : SoamService(org.onosproject.incubator.net.l2monitoring.soam.SoamService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) LossMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate) SoamConfigException(org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with Mep

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep 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 4 with Mep

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.

the class CfmMepManagerTest method testCreateMep.

@Test
public void testCreateMep() throws CfmConfigException {
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
    expect(deviceService.getDevice(DEVICE_ID2)).andReturn(device2).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(DEVICE_ID1)).andReturn(testDriver).anyTimes();
    expect(driverService.getDriver(DEVICE_ID2)).andReturn(testDriver).anyTimes();
    replay(driverService);
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, DEVICE_ID1, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    // Expecting false - since it was not found
    assertTrue(mepManager.createMep(MDNAME1, MANAME1, mep3));
}
Also used : DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 5 with Mep

use of org.onosproject.incubator.net.l2monitoring.cfm.Mep in project onos by opennetworkinglab.

the class CfmMepManager method createMep.

@Override
public boolean createMep(MdId mdName, MaIdShort maName, Mep newMep) throws CfmConfigException {
    MepKeyId key = new MepKeyId(mdName, maName, newMep.mepId());
    log.debug("Creating MEP " + newMep.mepId() + " on MD {}, MA {} on Device {}", mdName, maName, newMep.deviceId().toString());
    if (mepStore.getMep(key).isPresent()) {
        return false;
    }
    // Will throw IllegalArgumentException if ma does not exist
    cfmMdService.getMaintenanceAssociation(mdName, maName);
    DeviceId mepDeviceId = newMep.deviceId();
    if (deviceService.getDevice(mepDeviceId) == null) {
        throw new CfmConfigException("Device not found " + mepDeviceId);
    } else if (!deviceService.getDevice(mepDeviceId).is(CfmMepProgrammable.class)) {
        throw new CfmConfigException("Device " + mepDeviceId + " does not support CfmMepProgrammable behaviour.");
    }
    boolean deviceResult = deviceService.getDevice(mepDeviceId).as(CfmMepProgrammable.class).createMep(mdName, maName, newMep);
    log.debug("MEP created on {}", mepDeviceId);
    if (deviceResult) {
        boolean alreadyExisted = mepStore.createUpdateMep(key, newMep);
        // Add to other Remote Mep List on other devices
        for (Mep mep : mepStore.getMepsByMdMa(mdName, maName)) {
            List<DeviceId> alreadyHandledDevices = new ArrayList<>();
            if (mep.deviceId().equals(mepDeviceId) || alreadyHandledDevices.contains(mep.deviceId())) {
                continue;
            }
            boolean created = deviceService.getDevice(mep.deviceId()).as(CfmMepProgrammable.class).createMaRemoteMepOnDevice(mdName, maName, newMep.mepId());
            alreadyHandledDevices.add(mep.deviceId());
            log.info("Created RMep entry on {} on device {}", mdName.mdName() + "/" + maName.maName(), mep.deviceId());
        }
        return !alreadyExisted;
    } else {
        return deviceResult;
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) CfmMepProgrammable(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable) ArrayList(java.util.ArrayList) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepKeyId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)

Aggregations

Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)18 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)14 CfmMepProgrammable (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable)8 DeviceId (org.onosproject.net.DeviceId)8 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)6 MepKeyId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Consumes (javax.ws.rs.Consumes)4 Produces (javax.ws.rs.Produces)4 Test (org.junit.Test)4 DefaultMep (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep)4 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)3 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)3 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)3