Search in sources :

Example 1 with MepLbCreate

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

the class MepLbCreateCodecTest method testDecodeMepLbCreateMepId.

@Test
public void testDecodeMepLbCreateMepId() throws JsonProcessingException, IOException {
    String loopbackString = "{\"loopback\": {    \"remoteMepId\": 20," + "\"numberMessages\": 10,    \"vlanDropEligible\": true," + "\"vlanPriority\": 6,    \"dataTlvHex\": \"0A:BB:CC\" }}";
    InputStream input = new ByteArrayInputStream(loopbackString.getBytes(StandardCharsets.UTF_8));
    JsonNode cfg = mapper.readTree(input);
    MepLbCreate mepLbCreate = context.codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
    assertNull(mepLbCreate.remoteMepAddress());
    assertEquals(20, mepLbCreate.remoteMepId().id().shortValue());
    assertEquals(10, mepLbCreate.numberMessages().intValue());
    assertEquals(6, mepLbCreate.vlanPriority().ordinal());
    assertEquals(true, mepLbCreate.vlanDropEligible());
    assertEquals("0A:BB:CC".toLowerCase(), mepLbCreate.dataTlvHex());
}
Also used : MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 2 with MepLbCreate

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

the class MepLbCreateCodecTest method testDecodeMepLbCreateMepMac.

@Test
public void testDecodeMepLbCreateMepMac() throws JsonProcessingException, IOException {
    String loopbackString = "{\"loopback\": {    " + "\"remoteMepMac\": \"AA:BB:CC:DD:EE:FF\" }}";
    InputStream input = new ByteArrayInputStream(loopbackString.getBytes(StandardCharsets.UTF_8));
    JsonNode cfg = mapper.readTree(input);
    MepLbCreate mepLbCreate = context.codec(MepLbCreate.class).decode((ObjectNode) cfg, context);
    assertNull(mepLbCreate.remoteMepId());
    assertEquals("AA:BB:CC:DD:EE:FF", mepLbCreate.remoteMepAddress().toString());
    assertNull(mepLbCreate.dataTlvHex());
}
Also used : MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 3 with MepLbCreate

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

the class MepLbCreateCodec method decode.

/**
 * Decodes the MepLbCreate entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MepLbCreate
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MepLbCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode loopbackNode = json.get(LOOPBACK);
    JsonNode remoteMepIdNode = loopbackNode.get(REMOTE_MEP_ID);
    JsonNode remoteMepMacNode = loopbackNode.get(REMOTE_MEP_MAC);
    MepLbCreate.MepLbCreateBuilder lbCreateBuilder;
    if (remoteMepIdNode != null) {
        MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
        lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepId);
    } else if (remoteMepMacNode != null) {
        MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
        lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepMac);
    } else {
        throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
    }
    JsonNode numMessagesNode = loopbackNode.get(NUMBER_MESSAGES);
    if (numMessagesNode != null) {
        int numMessages = numMessagesNode.asInt();
        lbCreateBuilder.numberMessages(numMessages);
    }
    JsonNode vlanDropEligibleNode = loopbackNode.get(VLAN_DROP_ELIGIBLE);
    if (vlanDropEligibleNode != null) {
        boolean vlanDropEligible = vlanDropEligibleNode.asBoolean();
        lbCreateBuilder.vlanDropEligible(vlanDropEligible);
    }
    JsonNode vlanPriorityNode = loopbackNode.get(VLAN_PRIORITY);
    if (vlanPriorityNode != null) {
        short vlanPriority = (short) vlanPriorityNode.asInt();
        lbCreateBuilder.vlanPriority(Priority.values()[vlanPriority]);
    }
    JsonNode dataTlvHexNode = loopbackNode.get(DATA_TLV_HEX);
    if (dataTlvHexNode != null) {
        String dataTlvHex = loopbackNode.get(DATA_TLV_HEX).asText();
        if (!dataTlvHex.isEmpty()) {
            lbCreateBuilder.dataTlv(HexString.fromHexString(dataTlvHex));
        }
    }
    return lbCreateBuilder.build();
}
Also used : DefaultMepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate) MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Example 4 with MepLbCreate

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

the class CfmMepManagerTest method testTransmitLoopback.

@Test
public void testTransmitLoopback() {
    expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(DEVICE_ID1)).andReturn(testDriver).anyTimes();
    replay(driverService);
    MepLbCreate lbCreate = DefaultMepLbCreate.builder(MepId.valueOf((short) 11)).build();
    try {
        mepService.transmitLoopback(MDNAME1, MANAME1, MEPID1, lbCreate);
    } catch (CfmConfigException e) {
        fail("Not expecting an exception");
    }
}
Also used : DefaultMepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate) MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) Test(org.junit.Test)

Example 5 with MepLbCreate

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

the class MepWebResource method transmitLoopback.

/**
 * Transmit Loopback on MEP with MD name, MA name and Mep Id.
 *
 * @onos.rsModel MepLbTransmit
 * @param mdName The name of a Maintenance Domain
 * @param maName The name of a Maintenance Association belonging to the MD
 * @param mepIdShort The id of a MEP belonging to the MA
 * @param input A JSON formatted input stream specifying the Mep parameters
 * @return 202 Received with success message or 500 on error
 */
@PUT
@Path("{mep_id}/transmit-loopback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLoopback(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
    log.debug("PUT called to Transmit Loopback on Mep");
    MdId mdId = MdIdCharStr.asMdId(mdName);
    MaIdShort maId = MaIdCharStr.asMaId(maName);
    MaintenanceDomain md;
    Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
    if (mdOpt.isPresent()) {
        md = mdOpt.get();
    } else {
        return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
    }
    MaintenanceAssociation ma;
    Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
    if (maOpt.isPresent()) {
        ma = maOpt.get();
    } else {
        return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
    }
    MepId mepId = MepId.valueOf(mepIdShort);
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper(), input);
        JsonCodec<MepLbCreate> mepLbCreateCodec = codec(MepLbCreate.class);
        MepLbCreate lbCreate = mepLbCreateCodec.decode((ObjectNode) cfg, this);
        get(CfmMepService.class).transmitLoopback(md.mdId(), ma.maId(), mepId, lbCreate);
    } catch (Exception | CfmConfigException e) {
        log.error("Transmit Loopback on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
    return Response.accepted().entity("{ \"success\":\"Loopback on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepLbCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) MaIdShort(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) CfmMdService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

MepLbCreate (org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate)7 Test (org.junit.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 DefaultMepLbCreate (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate)4 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)3 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 WebTarget (javax.ws.rs.client.WebTarget)2 Response (javax.ws.rs.core.Response)2 DefaultMaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation)2 DefaultMaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain)2 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)2 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1