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