Search in sources :

Example 6 with MaintenanceDomain

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

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

the class CfmMdManagerTest method testGetAllMaintenanceDomain.

@Test
public void testGetAllMaintenanceDomain() {
    Collection<MaintenanceDomain> mdList = service.getAllMaintenanceDomain();
    assertEquals(1, mdList.size());
    MaintenanceDomain md = mdList.iterator().next();
    assertEquals(1, md.mdNumericId());
    assertEquals(2, md.maintenanceAssociationList().size());
    md.maintenanceAssociationList().iterator().forEachRemaining(ma -> assertTrue(ma.maId().maName().endsWith(String.valueOf(ma.maNumericId()))));
}
Also used : DefaultMaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) Test(org.junit.Test)

Example 8 with MaintenanceDomain

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

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

Example 10 with MaintenanceDomain

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

the class MaWebResource method createMaintenanceAssociation.

/**
 * Create Maintenance Association by MD and MA name.
 *
 * @onos.rsModel MaCreate
 * @param mdName The name of a Maintenance Domain
 * @param input A JSON formatted input stream specifying the MA parameters
 * @return 200 OK or 500 on error
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMaintenanceAssociation(@PathParam("md_name") String mdName, InputStream input) {
    log.debug("POST called to Create MA");
    try {
        MdId mdId = MdIdCharStr.asMdId(mdName);
        Optional<MaintenanceDomain> md = get(CfmMdService.class).getMaintenanceDomain(mdId);
        if (!md.isPresent()) {
            return Response.serverError().entity("{ \"failure\":\"md " + mdName + " does not exist\" }").build();
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode cfg = readTreeFromStream(mapper, input);
        JsonCodec<MaintenanceAssociation> maCodec = codec(MaintenanceAssociation.class);
        MaintenanceAssociation ma;
        try {
            ma = ((MaintenanceAssociationCodec) maCodec).decode((ObjectNode) cfg, this, mdId.getNameLength());
        } catch (Exception e) {
            log.error("Create MaintenanceAssociation on MD {} failed", mdName, e);
            return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
        }
        Boolean alreadyExists = get(CfmMdService.class).createMaintenanceAssociation(mdId, ma);
        if (alreadyExists) {
            return Response.notModified(mdName + "/" + ma.maId() + " already exists").build();
        }
        return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId())).entity("{ \"success\":\"" + mdName + "/" + ma.maId() + " created\" }").build();
    } catch (Exception | CfmConfigException e) {
        log.error("Create MaintenanceAssociation on MD {} failed", mdName, e);
        return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) CfmConfigException(org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException) MdId(org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId) MaintenanceDomain(org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain) 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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

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