Search in sources :

Example 16 with Mep

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

the class DeviceMepWebResource method getAllMepsForDevice.

/**
 * Get all MEPs by Device Id. The device should support Meps
 *
 * @param deviceId The id of a device.
 * @return 200 OK with a list of MEPS or 500 on error
 */
@GET
@Path("{device_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getAllMepsForDevice(@PathParam("device_id") String deviceId) {
    DeviceId deviceIdObj = DeviceId.deviceId(deviceId);
    log.debug("GET all Meps called for Device {}", deviceIdObj);
    try {
        Collection<Mep> mepCollection = get(CfmMepService.class).getAllMepsByDevice(deviceIdObj);
        ArrayNode an = mapper().createArrayNode();
        an.add(codec(Mep.class).encode(mepCollection, this));
        return ok(mapper().createObjectNode().set("meps", an)).build();
    } catch (CfmConfigException e) {
        log.error("Get all Meps on device {} failed because of exception", deviceIdObj, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) 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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 17 with Mep

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

the class MepWebResource method createMep.

/**
 * Create MEP with MD name, MA name and Mep Json.
 *
 * @onos.rsModel MepCreate
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param input A JSON formatted input stream specifying the Mep parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, InputStream input) {
    log.debug("POST called to Create Mep");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        MaIdShort maId = MaIdCharStr.asMaId(maName);
        MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).orElseThrow(() -> new IllegalArgumentException("MA " + mdName + "/" + maName + " not Found"));
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper(), input);
        JsonCodec<Mep> mepCodec = codec(Mep.class);
        Mep mep = ((MepCodec) mepCodec).decode((ObjectNode) cfg, this, mdName, maName);
        Boolean didNotExist = get(CfmMepService.class).createMep(mdId, maId, mep);
        if (!didNotExist) {
            return Response.notModified(mdName + "/" + ma.maId() + "/" + mep.mepId() + " already exists").build();
        }
        return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId() + "/mep/" + mep.mepId())).entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() + "/" + mep.mepId() + " created\" }").build();
    } catch (Exception | CfmConfigException e) {
        log.error("Create Mep on " + mdName + "/" + maName + " failed because of exception {}", e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MepCodec(org.onosproject.cfm.web.MepCodec) URI(java.net.URI) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) 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) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 18 with Mep

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

the class MepWebResourceTest method testCreateMep.

@Test
public void testCreateMep() throws CfmConfigException, IOException {
    MepId mepId2 = MepId.valueOf((short) 2);
    Mep mep2 = DefaultMep.builder(mepId2, DeviceId.deviceId("netconf:2.2.3.4:830"), PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).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, mep2)).andReturn(true).anyTimes();
    replay(mepService);
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("mep", context.codec(Mep.class).encode(mep2, 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 201", 201, 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)

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