Search in sources :

Example 6 with MaintenanceAssociation

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

use of org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation 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 8 with MaintenanceAssociation

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

the class CfmMdManagerTest method testCreateMaintenanceAssociation.

@Test
public void testCreateMaintenanceAssociation() throws CfmConfigException {
    MaintenanceAssociation maTest41 = DefaultMaintenanceAssociation.builder(MaIdCharStr.asMaId("test-ma-1-4"), 9).ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_1S).maNumericId((short) 4).addToRemoteMepIdList(MepId.valueOf((short) 401)).addToRemoteMepIdList(MepId.valueOf((short) 402)).addToComponentList(DefaultComponent.builder(4).tagType(Component.TagType.VLAN_STAG).build()).build();
    // Should return false, as this MA did not exist before
    assertFalse(service.createMaintenanceAssociation(MdIdCharStr.asMdId("test-md-1"), maTest41));
    assertEquals(3, service.getAllMaintenanceAssociation(MdIdCharStr.asMdId("test-md-1")).size());
    // Now try with an invalid mdName
    try {
        service.createMaintenanceAssociation(MdIdCharStr.asMdId("test-md-2"), maTest41);
    } catch (IllegalArgumentException e) {
        assertEquals("Unknown MD: test-md-2", e.getMessage());
    }
    // Now try replacing an MA with some new values or Remote MEP
    MaintenanceAssociation maTest11 = DefaultMaintenanceAssociation.builder(MaIdCharStr.asMaId("test-ma-1-1"), 9).ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN).maNumericId((short) 1).addToRemoteMepIdList(// Changed
    MepId.valueOf((short) 111)).addToRemoteMepIdList(// Changed
    MepId.valueOf((short) 112)).addToComponentList(DefaultComponent.builder(1).tagType(Component.TagType.VLAN_CTAG).build()).build();
    // Should return true, as this MA did exist before
    assertTrue(service.createMaintenanceAssociation(MdIdCharStr.asMdId("test-md-1"), maTest11));
    assertEquals(3, service.getAllMaintenanceAssociation(MdIdCharStr.asMdId("test-md-1")).size());
}
Also used : DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) Test(org.junit.Test)

Example 9 with MaintenanceAssociation

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

the class CfmMdManagerTest method setup.

@Before
public void setup() throws Exception, CfmConfigException {
    mdStore = new DistributedMdStore();
    MaintenanceAssociation maTest11 = DefaultMaintenanceAssociation.builder(MA_ID_1_1, MD_ID_1.getNameLength()).ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN).maNumericId((short) 1).addToRemoteMepIdList(MepId.valueOf((short) 101)).addToRemoteMepIdList(MepId.valueOf((short) 102)).addToComponentList(DefaultComponent.builder(1).tagType(Component.TagType.VLAN_CTAG).build()).build();
    MaintenanceAssociation maTest12 = DefaultMaintenanceAssociation.builder(MA_ID_1_2, MD_ID_1.getNameLength()).ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_10MIN).maNumericId((short) 2).addToRemoteMepIdList(MepId.valueOf((short) 201)).addToRemoteMepIdList(MepId.valueOf((short) 202)).addToComponentList(DefaultComponent.builder(2).tagType(Component.TagType.VLAN_CTAG).build()).build();
    MaintenanceDomain mdTest1 = DefaultMaintenanceDomain.builder(MD_ID_1).mdLevel(MaintenanceDomain.MdLevel.LEVEL1).mdNumericId((short) 1).addToMaList(maTest11).addToMaList(maTest12).build();
    TestUtils.setField(mdStore, "storageService", new TestStorageService());
    TestUtils.setField(mdStore, "clusterService", new CfmMdManagerTest.TestClusterService());
    TestUtils.setField(mdStore, "mastershipService", new CfmMdManagerTest.TestMastershipService());
    mdStore.activate();
    mdStore.createUpdateMaintenanceDomain(mdTest1);
    manager = new CfmMdManager();
    manager.store = mdStore;
    service = manager;
    TestUtils.setField(manager, "storageService", new TestStorageService());
    TestUtils.setField(manager, "coreService", new TestCoreService());
    TestUtils.setField(manager, "mepService", mepService);
    injectEventDispatcher(manager, new TestEventDispatcher());
    manager.appId = new CfmMdManagerTest.TestApplicationId(0, "CfmMdManagerTest");
    manager.activate();
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) TestStorageService(org.onosproject.store.service.TestStorageService) DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) Before(org.junit.Before)

Example 10 with MaintenanceAssociation

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

the class CfmMdManagerTest method testCreateMaintenanceDomain.

@Test
public void testCreateMaintenanceDomain() throws CfmConfigException {
    MaintenanceAssociation maTest21 = DefaultMaintenanceAssociation.builder(MaIdCharStr.asMaId("test-ma-2-1"), 9).ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_1S).maNumericId((short) 1).addToRemoteMepIdList(MepId.valueOf((short) 101)).addToRemoteMepIdList(MepId.valueOf((short) 102)).addToComponentList(DefaultComponent.builder(1).tagType(Component.TagType.VLAN_STAG).build()).build();
    MaintenanceDomain mdTest2 = DefaultMaintenanceDomain.builder(MdIdCharStr.asMdId("test-md-2")).mdLevel(MaintenanceDomain.MdLevel.LEVEL2).mdNumericId((short) 2).addToMaList(maTest21).build();
    // We expect false here because there should have been no previous value
    // with that ID in the store
    assertFalse(service.createMaintenanceDomain(mdTest2));
}
Also used : DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) DefaultMaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation) MaintenanceAssociation(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation) Test(org.junit.Test)

Aggregations

MaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation)25 DefaultMaintenanceAssociation (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation)19 Test (org.junit.Test)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 MaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 MdId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId)6 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 DefaultMaintenanceDomain (org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain)5 MaIdShort (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort)5 MepId (org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId)5 CfmConfigException (org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException)5 Path (javax.ws.rs.Path)4 CfmCodecContext (org.onosproject.cfm.CfmCodecContext)4