Search in sources :

Example 11 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 12 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 13 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 14 with MepId

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

the class CfmMepManagerTest method testCreateMepBehaviorNotSupported.

@Test
public void testCreateMepBehaviorNotSupported() throws CfmConfigException {
    final DeviceId deviceId3 = DeviceId.deviceId("netconf:3.2.3.4:830");
    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(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
    replay(mdService);
    expect(deviceService.getDevice(deviceId3)).andReturn(device3).anyTimes();
    replay(deviceService);
    expect(driverService.getDriver(deviceId3)).andReturn(testDriver3).anyTimes();
    replay(driverService);
    MepId mepId3 = MepId.valueOf((short) 3);
    Mep mep3 = DefaultMep.builder(mepId3, deviceId3, PortNumber.portNumber(1), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
    try {
        mepManager.createMep(MDNAME1, MANAME1, mep3);
        fail("Expecting CfmConfigException because driver does not support behavior");
    } catch (CfmConfigException e) {
        assertEquals("Device netconf:3.2.3.4:830 does not support " + "CfmMepProgrammable behaviour.", 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) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultMep(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep) Mep(org.onosproject.incubator.net.l2monitoring.cfm.Mep) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MepId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId) Test(org.junit.Test)

Example 15 with MepId

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

the class DmWebResource method createDm.

/**
 * Create DM with MD name, MA name, Mep id and DM Json.
 *
 * @onos.rsModel DmCreate
 * @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 DM parameters
 * @return 201 Created or 304 if already exists or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createDm(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId, InputStream input) {
    log.debug("POST called to Create Dm");
    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<DelayMeasurementCreate> dmCodec = codec(DelayMeasurementCreate.class);
        DelayMeasurementCreate dm = dmCodec.decode((ObjectNode) cfg, this);
        get(SoamService.class).createDm(mdId, maId, mepIdObj, dm);
        return Response.created(new URI("md/" + mdName + "/ma/" + maName + "/mep/" + mepId + "/dm")).entity("{ \"success\":\"dm " + mdName + "/" + maName + "/" + mepId + " created\" }").build();
    } catch (CfmConfigException | SoamConfigException | IllegalArgumentException | IOException | URISyntaxException e) {
        log.error("Create DM 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) DelayMeasurementCreate(org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate) 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)

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