Search in sources :

Example 1 with MepId

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

the class SoamManagerTest method testCreateDmNoBehavior.

@Test
public void testCreateDmNoBehavior() throws CfmConfigException, SoamConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    final MepId mepId3 = MepId.valueOf((short) 3);
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
    behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
    Driver testDriver3 = new DefaultDriver(TEST_DRIVER_3, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_3, behaviours, new HashMap<>());
    Device device3 = new DefaultDevice(ProviderId.NONE, deviceId3, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_3, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER_3).build());
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    MepEntry mep3 = DefaultMepEntry.builder(mepId3, deviceId3, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).buildEntry();
    expect(mepService.getMep(MDNAME1, MANAME1, mepId3)).andReturn(mep3).anyTimes();
    replay(mepService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    DelayMeasurementCreate dmCreate1 = DefaultDelayMeasurementCreate.builder(DelayMeasurementCreate.DmType.DM1DMTX, DelayMeasurementCreate.Version.Y17312011, MepId.valueOf((short) 11), Mep.Priority.PRIO3).binsPerFdInterval((short) 4).binsPerFdrInterval((short) 5).binsPerIfdvInterval((short) 6).build();
    try {
        soamManager.createDm(MDNAME1, MANAME1, mepId3, dmCreate1);
        fail("Expecting exception since device does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 from MEP :md-1/" + "ma-1-1/3 does not implement SoamDmProgrammable", e.getMessage());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) Behaviour(org.onosproject.net.driver.Behaviour) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Driver(org.onosproject.net.driver.Driver) DefaultDriver(org.onosproject.net.driver.DefaultDriver) MepEntry(org.onosproject.incubator.net.l2monitoring.cfm.MepEntry) DefaultMepEntry(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepEntry) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) DefaultDelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementCreate) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 2 with MepId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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 3 with MepId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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)

Example 4 with MepId

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

the class MepWebResource method abortLoopback.

/**
 * Abort Loopback on MEP with MD name, MA name and Mep Id.
 *
 * @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
 * @return 202 Received with success message or 500 on error
 */
@PUT
@Path("{mep_id}/abort-loopback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response abortLoopback(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort) {
    log.debug("PUT called to Abort 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 {
        get(CfmMepService.class).abortLoopback(md.mdId(), ma.maId(), mepId);
    } catch (CfmConfigException e) {
        log.error("Abort 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() + " aborted\" }").build();
}
Also used : 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) CfmMepService(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService) 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 MepId

use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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)

Aggregations

MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)25 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)17 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)15 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)14 Consumes (javax.ws.rs.Consumes)13 Produces (javax.ws.rs.Produces)13 SoamService (org.onosproject.incubator.net.l2monitoring.soam.SoamService)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Path (javax.ws.rs.Path)9 SoamConfigException (org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Test (org.junit.Test)6 Mep (org.onosproject.incubator.net.l2monitoring.cfm.Mep)6 CfmMepService (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService)6 SoamId (org.onosproject.incubator.net.l2monitoring.soam.SoamId)6 PUT (javax.ws.rs.PUT)5 MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 GET (javax.ws.rs.GET)4