Search in sources :

Example 1 with MepLtCreate

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

the class MepLtCreateCodecTest method testDecodeMepLtCreateMepId.

@Test
public void testDecodeMepLtCreateMepId() throws JsonProcessingException, IOException {
    String linktraceString = "{\"linktrace\": {    " + "\"remoteMepId\": 20," + "\"defaultTtl\": 21," + "\"transmitLtmFlags\": \"use-fdb-only\"}}";
    InputStream input = new ByteArrayInputStream(linktraceString.getBytes(StandardCharsets.UTF_8));
    JsonNode cfg = mapper.readTree(input);
    MepLtCreate mepLtCreate = context.codec(MepLtCreate.class).decode((ObjectNode) cfg, context);
    assertNull(mepLtCreate.remoteMepAddress());
    assertEquals(20, mepLtCreate.remoteMepId().id().shortValue());
    assertEquals(21, mepLtCreate.defaultTtl().intValue());
    assertEquals(BitSet.valueOf(new byte[] { 1 }), mepLtCreate.transmitLtmFlags());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultMepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 2 with MepLtCreate

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

the class MepLtCreateCodecTest method testEncodeMepLtCreate.

@Test
public void testEncodeMepLtCreate() {
    MepId mepId1 = MepId.valueOf((short) 1);
    MepLtCreate mepLtCreate1 = DefaultMepLtCreate.builder(mepId1).defaultTtl((short) 20).transmitLtmFlags(BitSet.valueOf(new byte[] { 1 })).build();
    ObjectMapper mapper = new ObjectMapper();
    CfmCodecContext context = new CfmCodecContext();
    ObjectNode node = mapper.createObjectNode();
    node.set("linktrace", context.codec(MepLtCreate.class).encode(mepLtCreate1, context));
    assertEquals("{\"linktrace\":{" + "\"remoteMepId\":1," + "\"defaultTtl\":20," + "\"transmitLtmFlags\":\"use-fdb-only\"}}", node.toString());
}
Also used : CfmCodecContext(org.onosproject.cfm.CfmCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 3 with MepLtCreate

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

the class CfmMepManagerTest method testTransmitLinktrace.

@Test
public void testTransmitLinktrace() throws CfmConfigException {
    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);
    MepLtCreate ltCreate = DefaultMepLtCreate.builder(MepId.valueOf((short) 11)).build();
    try {
        mepService.transmitLinktrace(MDNAME1, MANAME1, MEPID1, ltCreate);
    } catch (UnsupportedOperationException e) {
        assertEquals("Not yet implemented", e.getMessage());
    }
}
Also used : DefaultMepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) Test(org.junit.Test)

Example 4 with MepLtCreate

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

the class MepWebResource method transmitLinktrace.

/**
 * Transmit Linktrace on MEP with MD name, MA name and Mep Id.
 *
 * @onos.rsModel MepLtTransmit
 * @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 Linktrace parameters
 * @return 202 Received with success message or 500 on error
 */
@PUT
@Path("{mep_id}/transmit-linktrace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLinktrace(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
    log.debug("PUT called to Transmit Linktrace 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<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
        MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
        get(CfmMepService.class).transmitLinktrace(md.mdId(), ma.maId(), mepId, ltCreate);
    } catch (Exception | CfmConfigException e) {
        log.error("Transmit Linktrace on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
    return Response.accepted().entity("{ \"success\":\"Linktrace 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) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) 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)

Example 5 with MepLtCreate

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

the class MepLtCreateCodec method decode.

/**
 * Decodes the MepLtCreate entity from JSON.
 *
 * @param json    JSON to decode
 * @param context decoding context
 * @return decoded MepLtCreate
 * @throws java.lang.UnsupportedOperationException if the codec does not
 *                                                 support decode operations
 */
@Override
public MepLtCreate decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode linktraceNode = json.get(LINKTRACE);
    JsonNode remoteMepIdNode = linktraceNode.get(REMOTE_MEP_ID);
    JsonNode remoteMepMacNode = linktraceNode.get(REMOTE_MEP_MAC);
    MepLtCreate.MepLtCreateBuilder ltCreateBuilder;
    if (remoteMepIdNode != null) {
        MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
        ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepId);
    } else if (remoteMepMacNode != null) {
        MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
        ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepMac);
    } else {
        throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
    }
    JsonNode defaultTtlNode = linktraceNode.get(DEFAULT_TTL);
    if (defaultTtlNode != null) {
        short defaultTtl = (short) defaultTtlNode.asInt();
        ltCreateBuilder.defaultTtl(defaultTtl);
    }
    JsonNode transmitLtmFlagsNode = linktraceNode.get(TRANSMIT_LTM_FLAGS);
    if (transmitLtmFlagsNode != null) {
        if (transmitLtmFlagsNode.asText().isEmpty()) {
            ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 0 }));
        } else if (transmitLtmFlagsNode.asText().equals(USE_FDB_ONLY)) {
            ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 1 }));
        } else {
            throw new IllegalArgumentException("Expecting value 'use-fdb-only' " + "or '' for " + TRANSMIT_LTM_FLAGS);
        }
    }
    return ltCreateBuilder.build();
}
Also used : DefaultMepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate) MepLtCreate(org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)

Aggregations

MepLtCreate (org.onosproject.incubator.net.l2monitoring.cfm.MepLtCreate)6 DefaultMepLtCreate (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLtCreate)5 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)2 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)2 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)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 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 MacAddress (org.onlab.packet.MacAddress)1 DefaultMaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation)1