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();
}
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()))));
}
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();
}
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));
}
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();
}
}
Aggregations