[ONOS-7262] Cfm improvements to allow RMeps and Mds and Mas to be added and deleted
Change-Id: Ibffb13d046bfb29dbe88de7b558c95fbf9db046d
diff --git a/drivers/microsemi/BUCK b/drivers/microsemi/BUCK
index 80ef2c8..210d76cc 100644
--- a/drivers/microsemi/BUCK
+++ b/drivers/microsemi/BUCK
@@ -15,7 +15,8 @@
'//core/api:onos-api-tests',
'//drivers/netconf:onos-drivers-netconf-tests',
'//utils/osgi:onlab-osgi-tests',
- '//incubator/net:onos-incubator-net'
+ '//incubator/net:onos-incubator-net',
+ '//incubator/net:onos-incubator-net-tests'
]
APPS = [
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammable.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammable.java
index 143ee79..a5ff236 100755
--- a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammable.java
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammable.java
@@ -16,12 +16,17 @@
package org.onosproject.drivers.microsemi;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.drivers.microsemi.yang.utils.MaNameUtil.getApiMaIdFromYangMaName;
+import static org.onosproject.drivers.microsemi.yang.utils.MdNameUtil.getApiMdIdFromYangMdName;
+import static org.onosproject.drivers.microsemi.yang.utils.MdNameUtil.getYangMdNameFromApiMdId;
import static org.slf4j.LoggerFactory.getLogger;
import java.time.Duration;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.Optional;
-import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.util.HexString;
@@ -47,14 +52,12 @@
import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
@@ -62,7 +65,6 @@
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
-import org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes.DomainName;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfm;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfmOpParam;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.DefaultMefCfm;
@@ -83,11 +85,6 @@
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.ContinuityCheck;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultContinuityCheck;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.InterfaceEnum;
-import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultMacAddressAndUint;
-import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameCharacterString;
-import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameDomainName;
-import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameNone;
-import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.namedomainname.NameDomainNameUnion;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.remotemepstatetype.RemoteMepStateTypeEnum;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMacAddress;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMepId;
@@ -97,8 +94,6 @@
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.transmitloopbackinput.TargetAddress;
import org.onosproject.yang.gen.v1.mseasoamfm.rev20160229.mseasoamfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.AugmentedMseaCfmMaintenanceAssociationEndPoint;
import org.onosproject.yang.gen.v1.mseasoamfm.rev20160229.mseasoamfm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint;
-import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45;
-import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MacAddressAndUintStr;
import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MdLevelType;
import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MepIdType;
import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.PriorityType;
@@ -128,46 +123,34 @@
public boolean createMep(MdId mdName, MaIdShort maName, Mep mep)
throws CfmConfigException {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
- NetconfSession session = controller.getDevicesMap()
- .get(handler().data().deviceId()).getSession();
+ NetconfSession session = checkNotNull(controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession());
MseaCfmNetconfService mseaCfmService =
checkNotNull(handler().get(MseaCfmNetconfService.class));
+ CfmMepService cfmMepService =
+ checkNotNull(handler().get(CfmMepService.class));
MaintenanceAssociationEndPoint yangMep = buildYangMepFromApiMep(mep);
CfmMdService cfmMdService = checkNotNull(handler().get(CfmMdService.class));
- MaintenanceDomain md = cfmMdService.getMaintenanceDomain(mdName).get();
- MaintenanceAssociation ma = cfmMdService.getMaintenanceAssociation(mdName, maName).get();
+ MseaCfmOpParam mseaCfmOpParam = getMaYangObject(cfmMdService, mdName, maName);
- if (!ma.remoteMepIdList().contains(mep.mepId())) {
- throw new CfmConfigException("Mep Id " + mep.mepId() +
- " is not present in the remote Mep list for MA " + ma.maId() +
- ". This is required for EA1000.");
- } else if (md.mdNumericId() <= 0 || md.mdNumericId() > NUMERIC_ID_MAX) {
- throw new CfmConfigException("Numeric id of MD " + mdName + " must"
- + " be between 1 and 64 inclusive for EA1000");
- } else if (ma.maNumericId() <= 0 || ma.maNumericId() > NUMERIC_ID_MAX) {
- throw new CfmConfigException("Numeric id of MA " + maName + " must"
- + " be between 1 and 64 inclusive for EA1000");
- }
+ mseaCfmOpParam.mefCfm().maintenanceDomain().get(0)
+ .maintenanceAssociation().get(0).addToMaintenanceAssociationEndPoint(yangMep);
+ //Add this mepId to the list of remoteMeps on the device
+ mseaCfmOpParam.mefCfm().maintenanceDomain().get(0)
+ .maintenanceAssociation().get(0).addToRemoteMeps(MepIdType.of(mep.mepId().value()));
- org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
- .MaintenanceAssociation yangMa = buildYangMaFromApiMa(ma);
- yangMa.addToMaintenanceAssociationEndPoint(yangMep);
-
- org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm
- .mefcfm.MaintenanceDomain yangMd = buildYangMdFromApiMd(md);
- yangMd.addToMaintenanceAssociation(yangMa);
-
- MefCfm mefCfm = new DefaultMefCfm();
- mefCfm.addToMaintenanceDomain(yangMd);
-
- MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
- mseaCfmOpParam.mefCfm(mefCfm);
+ //Add all of the existing meps on this MD/MA to the remote meps list
+ cfmMepService.getAllMeps(mdName, maName).forEach(m -> {
+ mseaCfmOpParam.mefCfm().maintenanceDomain().get(0)
+ .maintenanceAssociation().get(0).addToRemoteMeps(MepIdType.of(m.mepId().value()));
+ });
try {
mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING);
log.info("Created MEP {} on device {}", mdName + "/" + maName +
"/" + mep.mepId(), handler().data().deviceId());
+
return true;
} catch (NetconfException e) {
log.error("Unable to create MEP {}/{}/{} on device {}",
@@ -177,11 +160,6 @@
}
@Override
- public Collection<MepEntry> getAllMeps(MdId mdName, MaIdShort maName) throws CfmConfigException {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
public MepEntry getMep(MdId mdName, MaIdShort maName, MepId mepId)
throws CfmConfigException {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
@@ -189,31 +167,20 @@
throw new CfmConfigException("Device is not ready - connecting or "
+ "disconnected for MEP " + mdName + "/" + maName + "/" + mepId);
}
- NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
+ NetconfSession session = checkNotNull(controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession());
MseaCfmNetconfService mseaCfmService = checkNotNull(handler().get(MseaCfmNetconfService.class));
try {
MseaCfm mseacfm =
mseaCfmService.getMepFull(mdName, maName, mepId, session);
- if (mseacfm != null && mseacfm.mefCfm() != null &&
- mseacfm.mefCfm().maintenanceDomain() != null) {
- for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.
- mseacfm.mefcfm.MaintenanceDomain replyMd :
- mseacfm.mefCfm().maintenanceDomain()) {
- for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.
- mseacfm.mefcfm.maintenancedomain.
- MaintenanceAssociation replyMa :
- replyMd.maintenanceAssociation()) {
- for (MaintenanceAssociationEndPoint replyMep :
- replyMa.maintenanceAssociationEndPoint()) {
- return buildApiMepEntryFromYangMep(
- replyMep, handler().data().deviceId(), mdName, maName);
- }
- }
- }
+ Collection<MepEntry> mepEntries = getMepEntriesFromYangResponse(mseacfm);
+ if (mepEntries == null || mepEntries.size() != 1) {
+ log.warn("Mep " + mepId + " not found on device " + handler().data().deviceId());
+ return null;
+ } else {
+ return mepEntries.stream().findFirst().get();
}
- log.warn("Mep " + mepId + " not found on device " + handler().data().deviceId());
- return null;
} catch (NetconfException e) {
log.error("Unable to get MEP {}/{}/{} on device {}",
mdName, maName, mepId, handler().data().deviceId());
@@ -221,12 +188,37 @@
}
}
+ private Collection<MepEntry> getMepEntriesFromYangResponse(MseaCfm mseacfm)
+ throws CfmConfigException {
+
+ Collection<MepEntry> mepEntries = new ArrayList<>();
+ if (mseacfm == null || mseacfm.mefCfm() == null || mseacfm.mefCfm().maintenanceDomain() == null) {
+ return mepEntries;
+ }
+
+ for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.
+ mseacfm.mefcfm.MaintenanceDomain replyMd:mseacfm.mefCfm().maintenanceDomain()) {
+ for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.
+ mseacfm.mefcfm.maintenancedomain.
+ MaintenanceAssociation replyMa:replyMd.maintenanceAssociation()) {
+ for (MaintenanceAssociationEndPoint replyMep:replyMa.maintenanceAssociationEndPoint()) {
+ mepEntries.add(buildApiMepEntryFromYangMep(
+ replyMep, handler().data().deviceId(), replyMd, replyMa));
+ }
+ }
+ }
+ return mepEntries;
+ }
+
@Override
- public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId) throws CfmConfigException {
+ public boolean deleteMep(MdId mdName, MaIdShort maName, MepId mepId,
+ Optional<MaintenanceDomain> oldMd) throws CfmConfigException {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
- NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
+ NetconfSession session = checkNotNull(controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession());
MseaCfmNetconfService mseaCfmService = checkNotNull(handler().get(MseaCfmNetconfService.class));
+ CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class));
MaintenanceAssociationEndPoint mep =
new DefaultMaintenanceAssociationEndPoint();
@@ -234,12 +226,34 @@
org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
.MaintenanceAssociation yangMa = new DefaultMaintenanceAssociation();
- yangMa.maNameAndTypeCombo(MaNameUtil.getYangMaNameFromApiMaId(maName));
+ Short maNumericId = null;
+ try {
+ maNumericId =
+ mdService.getMaintenanceAssociation(mdName, maName).get().maNumericId();
+ yangMa.id(maNumericId);
+ } catch (NoSuchElementException | IllegalArgumentException e) {
+ //The MA and/or MD have probably been deleted
+ // try to get numeric id values from oldMd
+ log.debug("Could not get MD/MA details from MD service during deletion of MEP {}." +
+ "Continuing with values from event", new MepKeyId(mdName, maName, mepId));
+ yangMa.id(getMaNumericId(oldMd.get(), maName));
+ }
+
yangMa.addToMaintenanceAssociationEndPoint(mep);
org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain yangMd =
new DefaultMaintenanceDomain();
- yangMd.mdNameAndTypeCombo(getYangMdNameFromApiMdId(mdName));
+ Short mdNumericId = null;
+ try {
+ mdNumericId = mdService.getMaintenanceDomain(mdName).get().mdNumericId();
+ yangMd.id(mdNumericId);
+ } catch (NoSuchElementException | IllegalArgumentException e) {
+ //The MD has probably been deleted
+ // try to get numeric id values from oldMd
+ log.debug("Could not get MD details from MD service during deletion of MEP {}." +
+ "Continuing with values from event", new MepKeyId(mdName, maName, mepId));
+ yangMd.id(oldMd.get().mdNumericId());
+ }
yangMd.addToMaintenanceAssociation(yangMa);
MefCfm mefCfm = new DefaultMefCfm();
@@ -254,14 +268,281 @@
"/" + mepId, handler().data().deviceId());
return true;
} catch (NetconfException e) {
- log.error("Unable to delete MEP {}/{}/{} on device {}",
- mdName, maName, mepId, handler().data().deviceId());
+ log.error("Unable to delete MEP {} ({}) on device {}",
+ mdName + "/" + maName + "/" + mepId,
+ mdNumericId + "/" + maNumericId, handler().data().deviceId(), e);
throw new CfmConfigException("Unable to delete MEP :" + e.getMessage());
}
}
@Override
+ public boolean createMdOnDevice(MdId mdId) throws CfmConfigException {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = checkNotNull(controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession());
+
+ CfmMdService cfmMdService = checkNotNull(handler().get(CfmMdService.class));
+ MaintenanceDomain md = cfmMdService.getMaintenanceDomain(mdId).get();
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm
+ .mefcfm.MaintenanceDomain yangMd = buildYangMdFromApiMd(md);
+
+ if (md.mdNumericId() <= 0 || md.mdNumericId() > NUMERIC_ID_MAX) {
+ throw new CfmConfigException("Numeric id of MD " + mdId + " must"
+ + " be between 1 and 64 inclusive for EA1000");
+ }
+
+ for (MaintenanceAssociation ma:md.maintenanceAssociationList()) {
+ if (ma.maNumericId() <= 0 || ma.maNumericId() > NUMERIC_ID_MAX) {
+ throw new CfmConfigException("Numeric id of MA " + mdId + " must"
+ + " be between 1 and 64 inclusive for EA1000");
+ }
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
+ .MaintenanceAssociation yangMa = buildYangMaFromApiMa(ma);
+ yangMd.addToMaintenanceAssociation(yangMa);
+ }
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(yangMd);
+
+ MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
+ mseaCfmOpParam.mefCfm(mefCfm);
+
+ MseaCfmNetconfService mseaCfmService =
+ checkNotNull(handler().get(MseaCfmNetconfService.class));
+
+ try {
+ boolean created = mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ log.info("Created MD {} on device {}", mdId.mdName(),
+ handler().data().deviceId());
+ return created;
+ } catch (NetconfException e) {
+ log.error("Unable to create MD {} on device {}",
+ mdId.mdName(), handler().data().deviceId());
+ throw new CfmConfigException("Unable to create MD :" + e.getMessage());
+ }
+ }
+
+ @Override
+ public boolean createMaOnDevice(MdId mdId, MaIdShort maId) throws CfmConfigException {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = checkNotNull(controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession());
+
+ CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class));
+ MseaCfmOpParam mseaCfmOpParam = getMaYangObject(mdService, mdId, maId);
+ MseaCfmNetconfService mseaCfmService =
+ checkNotNull(handler().get(MseaCfmNetconfService.class));
+
+ try {
+ boolean created = mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ log.info("Created MA {} on device {}", mdId.mdName() + "/" + maId.maName(),
+ handler().data().deviceId());
+ return created;
+ } catch (NetconfException e) {
+ log.error("Unable to create MA {} on device {}",
+ mdId.mdName() + "/" + maId.maName(), handler().data().deviceId());
+ throw new CfmConfigException("Unable to create MA :" + e.getMessage());
+ }
+ }
+
+ private static MseaCfmOpParam getMaYangObject(CfmMdService cfmMdService,
+ MdId mdName, MaIdShort maName) throws CfmConfigException {
+ MaintenanceDomain md = cfmMdService.getMaintenanceDomain(mdName).get();
+ MaintenanceAssociation ma = cfmMdService.getMaintenanceAssociation(mdName, maName).get();
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
+ .MaintenanceAssociation yangMa = buildYangMaFromApiMa(ma);
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm
+ .mefcfm.MaintenanceDomain yangMd = buildYangMdFromApiMd(md);
+ yangMd.addToMaintenanceAssociation(yangMa);
+
+ if (md.mdNumericId() <= 0 || md.mdNumericId() > NUMERIC_ID_MAX) {
+ throw new CfmConfigException("Numeric id of MD " + mdName + " must"
+ + " be between 1 and 64 inclusive for EA1000");
+ } else if (ma.maNumericId() <= 0 || ma.maNumericId() > NUMERIC_ID_MAX) {
+ throw new CfmConfigException("Numeric id of MA " + maName + " must"
+ + " be between 1 and 64 inclusive for EA1000");
+ }
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(yangMd);
+
+ MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
+ mseaCfmOpParam.mefCfm(mefCfm);
+
+ return mseaCfmOpParam;
+ }
+
+ @Override
+ public boolean deleteMdOnDevice(MdId mdId, Optional<MaintenanceDomain> oldMd)
+ throws CfmConfigException {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession();
+
+ //First check if this MD is known to ONOS if it is does it have MAs and
+ // do they have any Meps known to ONOS. If there are Meps throw an exception -
+ // the Meps should have been deleted first
+ //If there are none known to ONOS we do not check for Meps on the actual device
+ // - there might might be some orphaned ones down there - we want to delete these
+ //FIXME: When CfmMepService is extended to be persistent come back and enable check
+ CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class));
+ MseaCfmNetconfService mseaCfmService =
+ checkNotNull(handler().get(MseaCfmNetconfService.class));
+
+ MdNameAndTypeCombo mdName = getYangMdNameFromApiMdId(mdId);
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain yangMd =
+ new DefaultMaintenanceDomain();
+ Short mdNumericId = null;
+ try {
+ mdNumericId = mdService.getMaintenanceDomain(mdId).get().mdNumericId();
+ yangMd.id(mdNumericId);
+ } catch (NoSuchElementException e) {
+ yangMd.id(oldMd.get().mdNumericId());
+ }
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(yangMd);
+
+ MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
+ mseaCfmOpParam.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMd(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ log.info("Deleted MD {} on device {}", mdName,
+ handler().data().deviceId());
+ return deleted;
+ } catch (NetconfException e) {
+ log.error("Unable to delete MD {} ({}) on device {}",
+ mdName, mdNumericId, handler().data().deviceId());
+ throw new CfmConfigException("Unable to delete MD :" + e.getMessage());
+ }
+
+ }
+
+ @Override
+ public boolean deleteMaOnDevice(MdId mdId, MaIdShort maId, Optional<MaintenanceDomain> oldMd)
+ throws CfmConfigException {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession();
+
+ CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class));
+
+ MseaCfmNetconfService mseaCfmService =
+ checkNotNull(handler().get(MseaCfmNetconfService.class));
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
+ .MaintenanceAssociation yangMa = new DefaultMaintenanceAssociation();
+ Short maNumericId = null;
+ try {
+ maNumericId =
+ mdService.getMaintenanceAssociation(mdId, maId).get().maNumericId();
+ yangMa.id(maNumericId);
+ } catch (NoSuchElementException e) {
+ yangMa.id(getMaNumericId(oldMd.get(), maId));
+ }
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain yangMd =
+ new DefaultMaintenanceDomain();
+ Short mdNumericId = null;
+ try {
+ mdNumericId = mdService.getMaintenanceDomain(mdId).get().mdNumericId();
+ yangMd.id(mdNumericId);
+ } catch (NoSuchElementException e) {
+ yangMd.id(oldMd.get().mdNumericId());
+ }
+ yangMd.addToMaintenanceAssociation(yangMa);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(yangMd);
+
+ MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
+ mseaCfmOpParam.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMa(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ log.info("Deleted MA {} ({})on device {}", mdId.mdName() + "/" + maId.maName(),
+ mdNumericId + "/" + maNumericId, handler().data().deviceId());
+ return deleted;
+ } catch (NetconfException e) {
+ log.error("Unable to delete MA {} ({}) on device {}",
+ mdId.mdName() + "/" + maId.maName(),
+ mdNumericId + "/" + maNumericId, handler().data().deviceId());
+ throw new CfmConfigException("Unable to delete MA :" + e.getMessage());
+ }
+ }
+
+ @Override
+ public boolean createMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException {
+ return crDelMaRemoteMep(mdId, maId, remoteMep, true);
+ }
+
+ @Override
+ public boolean deleteMaRemoteMepOnDevice(MdId mdId, MaIdShort maId, MepId remoteMep) throws CfmConfigException {
+ return crDelMaRemoteMep(mdId, maId, remoteMep, false);
+ }
+
+ private boolean crDelMaRemoteMep(MdId mdId, MaIdShort maId, MepId remoteMep,
+ boolean isCreate) throws CfmConfigException {
+ NetconfController controller =
+ checkNotNull(handler().get(NetconfController.class));
+ NetconfSession session = controller.getDevicesMap()
+ .get(handler().data().deviceId()).getSession();
+
+ CfmMdService mdService = checkNotNull(handler().get(CfmMdService.class));
+
+ Short mdNumericId = mdService.getMaintenanceDomain(mdId).get().mdNumericId();
+ Short maNumericId =
+ mdService.getMaintenanceAssociation(mdId, maId).get().maNumericId();
+
+ MseaCfmNetconfService mseaCfmService =
+ checkNotNull(handler().get(MseaCfmNetconfService.class));
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain
+ .MaintenanceAssociation yangMa = new DefaultMaintenanceAssociation();
+ yangMa.id(maNumericId);
+ yangMa.addToRemoteMeps(MepIdType.of(remoteMep.value()));
+
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain yangMd =
+ new DefaultMaintenanceDomain();
+ yangMd.id(mdNumericId);
+ yangMd.addToMaintenanceAssociation(yangMa);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(yangMd);
+
+ MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam();
+ mseaCfmOpParam.mefCfm(mefCfm);
+
+ try {
+ boolean result = false;
+ if (isCreate) {
+ result = mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ } else {
+ result = mseaCfmService.deleteMseaMaRMep(mseaCfmOpParam, session, DatastoreId.RUNNING);
+ }
+ log.info("{} Remote MEP {} in MA {} on device {}", isCreate ? "Created" : "Deleted",
+ remoteMep, mdId.mdName() + "/" + maId.maName(), handler().data().deviceId());
+ return result;
+ } catch (NetconfException e) {
+ log.error("Unable to {} RemoteMep {} in MA {} on device {}",
+ isCreate ? "create" : "delete", remoteMep, mdId.mdName() + "/" + maId.maName(),
+ handler().data().deviceId());
+ throw new CfmConfigException("Unable to " + (isCreate ? "create" : "delete")
+ + " Remote Mep:" + e.getMessage());
+ }
+ }
+
+
+ @Override
public void transmitLoopback(MdId mdName, MaIdShort maName, MepId mepId,
MepLbCreate lbCreate) throws CfmConfigException {
NetconfController controller =
@@ -361,7 +642,7 @@
throw new UnsupportedOperationException("Not yet implemented");
}
- private org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
+ private static org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
.MaintenanceDomain buildYangMdFromApiMd(MaintenanceDomain md)
throws CfmConfigException {
MdNameAndTypeCombo mdName = getYangMdNameFromApiMdId(md.mdId());
@@ -375,44 +656,7 @@
return mdYang;
}
- protected static MdNameAndTypeCombo getYangMdNameFromApiMdId(MdId mdId)
- throws CfmConfigException {
- MdNameAndTypeCombo mdName;
- if (mdId instanceof MdIdDomainName) {
- boolean isIpAddr = false;
- try {
- if (IpAddress.valueOf(mdId.mdName()) != null) {
- isIpAddr = true;
- }
- } catch (IllegalArgumentException e) {
- //continue
- }
- if (isIpAddr) {
- mdName = new DefaultNameDomainName();
- ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion.of(
- org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes.
- IpAddress.fromString(mdId.mdName())));
- } else {
- mdName = new DefaultNameDomainName();
- ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion
- .of(DomainName.fromString(mdId.mdName())));
- }
- } else if (mdId instanceof MdIdMacUint) {
- mdName = new DefaultMacAddressAndUint();
- ((DefaultMacAddressAndUint) mdName).nameMacAddressAndUint(MacAddressAndUintStr.fromString(mdId.mdName()));
- } else if (mdId instanceof MdIdNone) {
- mdName = new DefaultNameNone();
- } else if (mdId instanceof MdIdCharStr) {
- mdName = new DefaultNameCharacterString();
- ((DefaultNameCharacterString) mdName).name(Identifier45.fromString(mdId.mdName()));
- } else {
- throw new CfmConfigException("Unexpected error creating MD " +
- mdId.getClass().getSimpleName());
- }
- return mdName;
- }
-
- private org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
+ private static org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
.maintenancedomain.MaintenanceAssociation buildYangMaFromApiMa(
MaintenanceAssociation apiMa) throws CfmConfigException {
@@ -422,12 +666,6 @@
.MaintenanceAssociation yamgMa = new DefaultMaintenanceAssociation();
yamgMa.maNameAndTypeCombo(maName);
- if (apiMa.remoteMepIdList() == null || apiMa.remoteMepIdList().size() < REMOTEMEPLIST_MIN_COUNT
- || apiMa.remoteMepIdList().size() > REMOTEMEPLIST_MAX_COUNT) {
- throw new CfmConfigException("EA1000 requires between " +
- REMOTEMEPLIST_MIN_COUNT + " and " + REMOTEMEPLIST_MAX_COUNT +
- " remote meps in an MA");
- }
for (MepId rmep:apiMa.remoteMepIdList()) {
yamgMa.addToRemoteMeps(MepIdType.of(rmep.id()));
}
@@ -486,7 +724,7 @@
return yamgMa;
}
- private MaintenanceAssociationEndPoint buildYangMepFromApiMep(Mep mep)
+ private static MaintenanceAssociationEndPoint buildYangMepFromApiMep(Mep mep)
throws CfmConfigException {
MaintenanceAssociationEndPoint mepBuilder =
new DefaultMaintenanceAssociationEndPoint();
@@ -515,14 +753,19 @@
private MepEntry buildApiMepEntryFromYangMep(
MaintenanceAssociationEndPoint yangMep, DeviceId deviceId,
- MdId mdName, MaIdShort maName) throws CfmConfigException {
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.
+ mseacfm.mefcfm.MaintenanceDomain replyMd,
+ org.onosproject.yang.gen.v1.mseacfm.rev20160229.
+ mseacfm.mefcfm.maintenancedomain.MaintenanceAssociation replyMa)
+ throws CfmConfigException {
MepId mepId = MepId.valueOf((short) yangMep.mepIdentifier().uint16());
MepEntry.MepEntryBuilder builder = DefaultMepEntry.builder(mepId,
deviceId,
(yangMep.yangAutoPrefixInterface() == InterfaceEnum.ETH0) ?
PortNumber.portNumber(0) : PortNumber.portNumber(1),
MepDirection.DOWN_MEP, //Always down for EA1000
- mdName, maName);
+ getApiMdIdFromYangMdName(replyMd.mdNameAndTypeCombo()),
+ getApiMaIdFromYangMaName(replyMa.maNameAndTypeCombo()));
if (yangMep.loopback() != null) {
MepLbEntryBuilder lbEntryBuilder = DefaultMepLbEntry.builder();
@@ -614,4 +857,10 @@
}
return rmepBuilder.build();
}
+
+ private static short getMaNumericId(MaintenanceDomain md, MaIdShort maId) {
+ return md.maintenanceAssociationList().stream()
+ .filter(ma -> maId.equals(ma.maId()))
+ .findFirst().get().maNumericId();
+ }
}
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/MseaCfmNetconfService.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/MseaCfmNetconfService.java
index 1bc32ca..cbe41ba 100644
--- a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/MseaCfmNetconfService.java
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/MseaCfmNetconfService.java
@@ -18,6 +18,7 @@
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
import org.onosproject.netconf.DatastoreId;
import org.onosproject.netconf.NetconfException;
@@ -29,6 +30,8 @@
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitlinktrace.TransmitLinktraceOutput;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.transmitloopback.TransmitLoopbackInput;
+import java.util.Optional;
+
/**
* Extension of mseaCfmService to include NETCONF sessions.
*
@@ -65,6 +68,19 @@
MseaCfm getMepFull(MdId mdId, MaIdShort maId, MepId mepId,
NetconfSession session) throws NetconfException;
+
+ /**
+ * Returns set of all MepIds from one Md or Ma or all.
+ *
+ * @param mdIdOptional An MdId to filter by, or empty to select all
+ * @param maIdOptional An MaId to filter by, or empty to select all
+ * @param session An active NETCONF session
+ * @param targetDs one of running, candidate or startup
+ * @return mseaCfm
+ * @throws NetconfException if the session has any error
+ */
+ MseaCfm getMepIds(Optional<MdId> mdIdOptional, Optional<MaIdShort> maIdOptional,
+ NetconfSession session, DatastoreId targetDs) throws NetconfException;
/**
* Returns attributes of DM.
*
@@ -102,10 +118,52 @@
* @param targetDs one of running, candidate or startup
* @return Boolean to indicate success or failure
* @throws NetconfException if the session has any error
+ * @throws CfmConfigException if the Cfm config has any error
*/
boolean deleteMseaMep(MseaCfmOpParam mseaCfm, NetconfSession session,
- DatastoreId targetDs) throws NetconfException;
+ DatastoreId targetDs) throws NetconfException, CfmConfigException;
+ /**
+ * Deletes named Ma of mseaCfm.
+ * Expects to see a list of Mas
+ *
+ * @param mseaCfm value of mseaCfm
+ * @param session An active NETCONF session
+ * @param targetDs one of running, candidate or startup
+ * @return Boolean to indicate success or failure
+ * @throws NetconfException if the session has any error
+ * @throws CfmConfigException if the Cfm config has any error
+ */
+ boolean deleteMseaMa(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException;
+
+ /**
+ * Deletes a remote Mep from an MA.
+ * Expects one or more RMeps
+ *
+ * @param mseaCfm value of mseaCfm
+ * @param session An active NETCONF session
+ * @param targetDs one of running, candidate or startup
+ * @return Boolean to indicate success or failure
+ * @throws NetconfException if the session has any error
+ * @throws CfmConfigException if the Cfm config has any error
+ */
+ boolean deleteMseaMaRMep(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException;
+
+ /**
+ * Deletes named Md of mseaCfm.
+ * Expects to see a list of Mds
+ *
+ * @param mseaCfm value of mseaCfm
+ * @param session An active NETCONF session
+ * @param targetDs one of running, candidate or startup
+ * @return Boolean to indicate success or failure
+ * @throws NetconfException if the session has any error
+ * @throws CfmConfigException if the Cfm config has any error
+ */
+ boolean deleteMseaMd(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException;
/**
* Deletes named delay measurements of mseaCfm.
@@ -116,9 +174,10 @@
* @param targetDs one of running, candidate or startup
* @return Boolean to indicate success or failure
* @throws NetconfException if the session has any error
+ * @throws CfmConfigException if the Cfm config has any error
*/
boolean deleteMseaCfmDm(MseaCfmOpParam mseaCfm, NetconfSession session,
- DatastoreId targetDs) throws NetconfException;
+ DatastoreId targetDs) throws NetconfException, CfmConfigException;
/**
* Service interface of transmitLoopback.
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/impl/MseaCfmManager.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/impl/MseaCfmManager.java
index c39625b..692e9a8 100644
--- a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/impl/MseaCfmManager.java
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/impl/MseaCfmManager.java
@@ -25,6 +25,7 @@
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
import org.onosproject.netconf.DatastoreId;
import org.onosproject.netconf.NetconfException;
@@ -42,6 +43,7 @@
import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.AugmentedMseaCfmMaintenanceAssociationEndPoint;
import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint;
import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.DelayMeasurement;
+import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MepIdType;
import org.onosproject.yang.model.DefaultModelObjectData;
import org.onosproject.yang.model.ModelConverter;
import org.onosproject.yang.model.ModelObject;
@@ -54,6 +56,7 @@
import org.onosproject.yang.runtime.DefaultCompositeStream;
import java.io.ByteArrayInputStream;
+import java.util.Optional;
import java.util.regex.Pattern;
/**
@@ -77,6 +80,19 @@
@Deprecated
protected static final Pattern REGEX_EMPTY_LAST_DEFECT_SENT =
Pattern.compile("(<msea-soam-fm:last-defect-sent)[ ]?(/>)", Pattern.DOTALL);
+ public static final String MEF_CFM = "mef-cfm";
+ public static final String MAINTENANCE_DOMAIN = "maintenance-domain";
+ public static final String ID = "id";
+ public static final String MAINTENANCE_ASSOCIATION = "maintenance-association";
+ public static final String TRANSMIT_LOOPBACK = "transmit-loopback";
+ public static final String ABORT_LOOPBACK = "abort-loopback";
+ public static final String MAINTENANCE_ASSOCIATION_END_POINT = "maintenance-association-end-point";
+ public static final String MEP_ID = "mep-id";
+ public static final String DELAY_MEASUREMENTS = "delay-measurements";
+ public static final String DELAY_MEASUREMENT = "delay-measurement";
+ public static final String DM_ID = "dm-id";
+ public static final String MEP_IDENTIFIER = "mep-identifier";
+ public static final String REMOTE_MEPS = "remote-meps";
@Activate
public void activate() {
@@ -153,6 +169,38 @@
}
@Override
+ public MseaCfm getMepIds(Optional<MdId> mdIdOptional, Optional<MaIdShort> maIdOptional,
+ NetconfSession session, DatastoreId targetDs) throws NetconfException {
+
+ ModelObjectData.Builder moQueryBldr = DefaultModelObjectData.builder();
+
+ ArrayList annotations = new ArrayList<AnnotatedNodeInfo>();
+ String xmlQueryStr = encodeMoToXmlStr(moQueryBldr.build(), annotations);
+
+ log.debug("Sending <get> for full MEP" +
+ " query on NETCONF session " + session.getSessionId() +
+ ":\n" + xmlQueryStr);
+
+ String xmlResult = session.get(xmlQueryStr, null);
+ xmlResult = removeRpcReplyData(xmlResult);
+ xmlResult = removeEmptyActiveDefects(xmlResult);
+ DefaultCompositeStream resultDcs = new DefaultCompositeStream(
+ null, new ByteArrayInputStream(xmlResult.getBytes()));
+ CompositeData compositeData = xSer.decode(resultDcs, yCtx);
+
+ ModelObjectData mod = ((ModelConverter) yangModelRegistry).createModel(compositeData.resourceData());
+
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ for (ModelObject mo:mod.modelObjects()) {
+ if (mo instanceof DefaultMefCfm) {
+ mseaCfm.mefCfm((DefaultMefCfm) mo);
+ }
+ }
+
+ return mseaCfm;
+ }
+
+ @Override
public MseaCfm getSoamDm(MdId mdName, MaIdShort maName, MepId mepId,
SoamId dmId, DmEntryParts parts, NetconfSession session)
throws NetconfException {
@@ -190,7 +238,7 @@
@Override
public boolean deleteMseaCfmDm(MseaCfmOpParam mseaCfm, NetconfSession session,
- DatastoreId targetDs) throws NetconfException {
+ DatastoreId targetDs) throws NetconfException, CfmConfigException {
ModelObjectData mseCfmDmList = DefaultModelObjectData.builder()
.addModelObject((ModelObject) mseaCfm).build();
@@ -198,7 +246,13 @@
ArrayList anis = new ArrayList<AnnotatedNodeInfo>();
if (mseaCfm != null && mseaCfm.mefCfm() != null) {
for (MaintenanceDomain md:mseaCfm.mefCfm().maintenanceDomain()) {
+ if (md.id() == 0) {
+ throw new CfmConfigException("An MD numeric ID must be given");
+ }
for (MaintenanceAssociation ma:md.maintenanceAssociation()) {
+ if (ma.id() == 0) {
+ throw new CfmConfigException("An MA numeric ID must be given");
+ }
for (MaintenanceAssociationEndPoint mep:ma.maintenanceAssociationEndPoint()) {
AugmentedMseaCfmMaintenanceAssociationEndPoint mepAugment =
mep.augmentation(DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint.class);
@@ -206,16 +260,16 @@
for (DelayMeasurement dms:mepAugment.delayMeasurements().delayMeasurement()) {
ResourceId.Builder ridBuilder = ResourceId.builder()
.addBranchPointSchema("/", null)
- .addBranchPointSchema("mef-cfm", MSEA_CFM_NS)
- .addBranchPointSchema("maintenance-domain", MSEA_CFM_NS)
- .addKeyLeaf("id", MSEA_CFM_NS, md.id())
- .addBranchPointSchema("maintenance-association", MSEA_CFM_NS)
- .addKeyLeaf("id", MSEA_CFM_NS, ma.id())
- .addBranchPointSchema("maintenance-association-end-point", MSEA_CFM_NS)
- .addKeyLeaf("mep-id", MSEA_CFM_NS, mep.mepIdentifier())
- .addBranchPointSchema("delay-measurements", MSEA_CFM_PM_NS)
- .addBranchPointSchema("delay-measurement", MSEA_CFM_PM_NS)
- .addKeyLeaf("dm-id", MSEA_CFM_PM_NS, mep.mepIdentifier());
+ .addBranchPointSchema(MEF_CFM, MSEA_CFM_NS)
+ .addBranchPointSchema(MAINTENANCE_DOMAIN, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, md.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, ma.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION_END_POINT, MSEA_CFM_NS)
+ .addKeyLeaf(MEP_ID, MSEA_CFM_NS, mep.mepIdentifier())
+ .addBranchPointSchema(DELAY_MEASUREMENTS, MSEA_CFM_PM_NS)
+ .addBranchPointSchema(DELAY_MEASUREMENT, MSEA_CFM_PM_NS)
+ .addKeyLeaf(DM_ID, MSEA_CFM_PM_NS, mep.mepIdentifier());
AnnotatedNodeInfo ani = DefaultAnnotatedNodeInfo.builder()
.resourceId(ridBuilder.build())
.addAnnotation(new DefaultAnnotation(NC_OPERATION, OP_DELETE))
@@ -233,7 +287,7 @@
@Override
public boolean deleteMseaMep(MseaCfmOpParam mseaCfm, NetconfSession session,
- DatastoreId targetDs) throws NetconfException {
+ DatastoreId targetDs) throws NetconfException, CfmConfigException {
ModelObjectData mseCfmMepList = DefaultModelObjectData.builder()
.addModelObject((ModelObject) mseaCfm.mefCfm()).build();
@@ -241,15 +295,100 @@
ArrayList anis = new ArrayList<AnnotatedNodeInfo>();
if (mseaCfm.mefCfm() != null) {
for (MaintenanceDomain md:mseaCfm.mefCfm().maintenanceDomain()) {
+ if (md.id() == 0) {
+ throw new CfmConfigException("An MD numeric ID must be given");
+ }
for (MaintenanceAssociation ma:md.maintenanceAssociation()) {
+ if (ma.id() == 0) {
+ throw new CfmConfigException("An MA numeric ID must be given");
+ }
for (MaintenanceAssociationEndPoint mep:ma.maintenanceAssociationEndPoint()) {
ResourceId.Builder ridBuilder = ResourceId.builder()
.addBranchPointSchema("/", null)
- .addBranchPointSchema("mef-cfm", MSEA_CFM_NS)
- .addBranchPointSchema("maintenance-domain", MSEA_CFM_NS)
- .addBranchPointSchema("maintenance-association", MSEA_CFM_NS)
- .addBranchPointSchema("maintenance-association-end-point", MSEA_CFM_NS)
- .addKeyLeaf("mep-identifier", MSEA_CFM_NS, mep.mepIdentifier().uint16());
+ .addBranchPointSchema(MEF_CFM, MSEA_CFM_NS)
+ .addBranchPointSchema(MAINTENANCE_DOMAIN, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, md.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, ma.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION_END_POINT, MSEA_CFM_NS)
+ .addKeyLeaf(MEP_IDENTIFIER, MSEA_CFM_NS, mep.mepIdentifier().uint16());
+ AnnotatedNodeInfo ani = DefaultAnnotatedNodeInfo.builder()
+ .resourceId(ridBuilder.build())
+ .addAnnotation(new DefaultAnnotation(NC_OPERATION, OP_DELETE))
+ .build();
+ anis.add(ani);
+ }
+ }
+ }
+ }
+
+ return setNetconfObject(mseCfmMepList, session, targetDs, anis);
+ }
+
+ @Override
+ public boolean deleteMseaMa(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException {
+
+ ModelObjectData mseCfmMepList = DefaultModelObjectData.builder()
+ .addModelObject((ModelObject) mseaCfm.mefCfm()).build();
+
+ ArrayList anis = new ArrayList<AnnotatedNodeInfo>();
+ if (mseaCfm != null && mseaCfm.mefCfm() != null) {
+ for (MaintenanceDomain md:mseaCfm.mefCfm().maintenanceDomain()) {
+ if (md.id() == 0) {
+ throw new CfmConfigException("An MD numeric ID must be given");
+ }
+ for (MaintenanceAssociation ma:md.maintenanceAssociation()) {
+ if (ma.id() == 0) {
+ throw new CfmConfigException("An MA numeric ID must be given");
+ }
+ ResourceId.Builder ridBuilder = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema(MEF_CFM, MSEA_CFM_NS)
+ .addBranchPointSchema(MAINTENANCE_DOMAIN, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, md.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, ma.id());
+
+ AnnotatedNodeInfo ani = DefaultAnnotatedNodeInfo.builder()
+ .resourceId(ridBuilder.build())
+ .addAnnotation(new DefaultAnnotation(NC_OPERATION, OP_DELETE))
+ .build();
+ anis.add(ani);
+ }
+ }
+ }
+
+ return setNetconfObject(mseCfmMepList, session, targetDs, anis);
+ }
+
+ @Override
+ public boolean deleteMseaMaRMep(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException {
+
+ ModelObjectData mseCfmMepList = DefaultModelObjectData.builder()
+ .addModelObject((ModelObject) mseaCfm.mefCfm()).build();
+
+ ArrayList anis = new ArrayList<AnnotatedNodeInfo>();
+ if (mseaCfm != null && mseaCfm.mefCfm() != null) {
+ for (MaintenanceDomain md:mseaCfm.mefCfm().maintenanceDomain()) {
+ if (md.id() == 0) {
+ throw new CfmConfigException("An MD numeric ID must be given");
+ }
+ for (MaintenanceAssociation ma:md.maintenanceAssociation()) {
+ if (ma.id() == 0) {
+ throw new CfmConfigException("An MA numeric ID must be given");
+ }
+ for (MepIdType rmep:ma.remoteMeps()) {
+ ResourceId.Builder ridBuilder = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema(MEF_CFM, MSEA_CFM_NS)
+ .addBranchPointSchema(MAINTENANCE_DOMAIN, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, md.id())
+ .addBranchPointSchema(MAINTENANCE_ASSOCIATION, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, ma.id())
+ .addLeafListBranchPoint(REMOTE_MEPS, MSEA_CFM_NS,
+ Integer.valueOf(rmep.uint16()));
AnnotatedNodeInfo ani = DefaultAnnotatedNodeInfo.builder()
.resourceId(ridBuilder.build())
.addAnnotation(new DefaultAnnotation(NC_OPERATION, OP_DELETE))
@@ -264,6 +403,35 @@
}
+ @Override
+ public boolean deleteMseaMd(MseaCfmOpParam mseaCfm, NetconfSession session,
+ DatastoreId targetDs) throws NetconfException, CfmConfigException {
+
+ ModelObjectData mseCfmMepList = DefaultModelObjectData.builder()
+ .addModelObject((ModelObject) mseaCfm.mefCfm()).build();
+
+ ArrayList anis = new ArrayList<AnnotatedNodeInfo>();
+ if (mseaCfm != null && mseaCfm.mefCfm() != null) {
+ for (MaintenanceDomain md:mseaCfm.mefCfm().maintenanceDomain()) {
+ if (md.id() == 0) {
+ throw new CfmConfigException("An MD numeric ID must be given");
+ }
+ ResourceId.Builder ridBuilder = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema(MEF_CFM, MSEA_CFM_NS)
+ .addBranchPointSchema(MAINTENANCE_DOMAIN, MSEA_CFM_NS)
+ .addKeyLeaf(ID, MSEA_CFM_NS, md.id());
+ AnnotatedNodeInfo ani = DefaultAnnotatedNodeInfo.builder()
+ .resourceId(ridBuilder.build())
+ .addAnnotation(new DefaultAnnotation(NC_OPERATION, OP_DELETE))
+ .build();
+ anis.add(ani);
+ }
+ }
+
+ return setNetconfObject(mseCfmMepList, session, targetDs, anis);
+ }
+
/**
* Call RPCs on the device through NETCONF.
*/
@@ -275,7 +443,7 @@
.addModelObject((ModelObject) inputVar).build();
customRpcNetconf(transLoopbackMo,
- "transmit-loopback", session);
+ TRANSMIT_LOOPBACK, session);
}
@Override
@@ -284,7 +452,7 @@
ModelObjectData abortLoopbackMo = DefaultModelObjectData.builder()
.addModelObject((ModelObject) inputVar).build();
- customRpcNetconf(abortLoopbackMo, "abort-loopback", session);
+ customRpcNetconf(abortLoopbackMo, ABORT_LOOPBACK, session);
}
@Override
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MaNameUtil.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MaNameUtil.java
index 16e9686..e18abe6 100644
--- a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MaNameUtil.java
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MaNameUtil.java
@@ -30,11 +30,14 @@
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameRfc2685VpnId;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameUint16;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameY1731Icc;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.NameCharacterString;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.nameprimaryvid.NamePrimaryVidUnion;
import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45;
/**
- * This is a workaround for Checkstyle issue.
+ * Utility for translating between Maintenance Association names in the CFM API model and the device YANG.
+ *
+ * This has to be in a separate file as a workaround for Checkstyle issue.
* https://github.com/checkstyle/checkstyle/issues/3850
* There are two types of DefaultNameCharacterString - one for MA and another for MD
* Putting both together in a file means that the full path has to be given which
@@ -46,6 +49,12 @@
//Hidden
}
+ /**
+ * Convert CFM API MA identifier to the YANG model MA identifier.
+ * @param maId Maintenance Association ID in CFM API
+ * @return Maintenance Association ID in YANG API
+ * @throws CfmConfigException If there's a problem with the name
+ */
public static MaNameAndTypeCombo getYangMaNameFromApiMaId(MaIdShort maId)
throws CfmConfigException {
MaNameAndTypeCombo maName;
@@ -70,4 +79,52 @@
}
return maName;
}
+
+ /**
+ * Convert YANG API MA identifier to the CFM API MA identifier.
+ * @param nameAndTypeCombo Maintenance Association ID in YANG API
+ * @return Maintenance Association ID in CFM API
+ */
+ public static MaIdShort getApiMaIdFromYangMaName(MaNameAndTypeCombo nameAndTypeCombo) {
+ MaIdShort maId;
+ if (nameAndTypeCombo instanceof DefaultNameCharacterString) {
+ maId = MaIdCharStr.asMaId(
+ ((DefaultNameCharacterString) nameAndTypeCombo).name().string());
+ } else if (nameAndTypeCombo instanceof DefaultNamePrimaryVid) {
+ if (((DefaultNamePrimaryVid) nameAndTypeCombo).namePrimaryVid().enumeration() != null) {
+ maId = MaIdPrimaryVid.asMaId(
+ ((DefaultNamePrimaryVid) nameAndTypeCombo).namePrimaryVid().enumeration().name());
+ } else if (((DefaultNamePrimaryVid) nameAndTypeCombo).namePrimaryVid().vlanIdType() != null) {
+ maId = MaIdPrimaryVid.asMaId(
+ ((DefaultNamePrimaryVid) nameAndTypeCombo).namePrimaryVid().vlanIdType().uint16());
+ } else {
+ throw new IllegalArgumentException("Unexpected primaryVid for " +
+ "MaNameAndTypeCombo: " + nameAndTypeCombo.toString());
+ }
+ } else if (nameAndTypeCombo instanceof DefaultNameUint16) {
+ maId = MaId2Octet.asMaId(((DefaultNameUint16) nameAndTypeCombo).nameUint16());
+
+ } else if (nameAndTypeCombo instanceof DefaultNameRfc2685VpnId) {
+ maId = MaIdRfc2685VpnId.asMaIdHex(
+ HexString.toHexString(
+ ((DefaultNameRfc2685VpnId) nameAndTypeCombo).nameRfc2685VpnId()));
+ } else if (nameAndTypeCombo instanceof DefaultNameY1731Icc) {
+ maId = MaIdIccY1731.asMaId(((DefaultNameY1731Icc) nameAndTypeCombo).nameY1731Icc().string());
+
+ } else {
+ throw new IllegalArgumentException("Unexpected type for " +
+ "MaNameAndTypeCombo: " + nameAndTypeCombo.toString());
+ }
+
+ return maId;
+ }
+
+ /**
+ * Cast the YANG generic type of MaNameAndTypeCombo specifically to char string.
+ * @param maName a YANG generic MaNameAndTypeCombo
+ * @return a YANG specific MaNameAndTypeCombo for Char string
+ */
+ public static NameCharacterString cast(MaNameAndTypeCombo maName) {
+ return (NameCharacterString) maName;
+ }
}
diff --git a/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MdNameUtil.java b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MdNameUtil.java
new file mode 100644
index 0000000..ba0cc96
--- /dev/null
+++ b/drivers/microsemi/src/main/java/org/onosproject/drivers/microsemi/yang/utils/MdNameUtil.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.microsemi.yang.utils;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes.DomainName;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultMacAddressAndUint;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameCharacterString;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameDomainName;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameNone;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.MacAddressAndUint;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.NameCharacterString;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.namedomainname.NameDomainNameUnion;
+import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45;
+import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MacAddressAndUintStr;
+
+/**
+ * Utility for translating between Maintenance Domain names in the CFM API model and the device YANG.
+ *
+ * This has to be in a separate file as a workaround for Checkstyle issue.
+ * https://github.com/checkstyle/checkstyle/issues/3850
+ * There are two types of DefaultNameCharacterString - one for MA and another for MD
+ * Putting both together in a file means that the full path has to be given which
+ * will then fail checkstyle
+ */
+public final class MdNameUtil {
+
+ private MdNameUtil() {
+ //Hidden
+ }
+
+ /**
+ * Convert CFM API MD identifier to the YANG model MD identifier.
+ * @param mdId Maintenance Domain ID in CFM API
+ * @return Maintenance Domain ID in YANG API
+ * @throws CfmConfigException If there's a problem with the name
+ */
+ public static MdNameAndTypeCombo getYangMdNameFromApiMdId(MdId mdId)
+ throws CfmConfigException {
+ MdNameAndTypeCombo mdName;
+ if (mdId instanceof MdIdDomainName) {
+ boolean isIpAddr = false;
+ try {
+ if (IpAddress.valueOf(mdId.mdName()) != null) {
+ isIpAddr = true;
+ }
+ } catch (IllegalArgumentException e) {
+ //continue
+ }
+ if (isIpAddr) {
+ mdName = new DefaultNameDomainName();
+ ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion.of(
+ org.onosproject.yang.gen.v1.ietfinettypes.rev20130715.ietfinettypes.
+ IpAddress.fromString(mdId.mdName())));
+ } else {
+ mdName = new DefaultNameDomainName();
+ ((DefaultNameDomainName) mdName).nameDomainName(NameDomainNameUnion
+ .of(DomainName.fromString(mdId.mdName())));
+ }
+ } else if (mdId instanceof MdIdMacUint) {
+ mdName = new DefaultMacAddressAndUint();
+ ((DefaultMacAddressAndUint) mdName).nameMacAddressAndUint(MacAddressAndUintStr.fromString(mdId.mdName()));
+ } else if (mdId instanceof MdIdNone) {
+ mdName = new DefaultNameNone();
+ } else if (mdId instanceof MdIdCharStr) {
+ mdName = new DefaultNameCharacterString();
+ ((DefaultNameCharacterString) mdName).name(Identifier45.fromString(mdId.mdName()));
+ } else {
+ throw new CfmConfigException("Unexpected error creating MD " +
+ mdId.getClass().getSimpleName());
+ }
+ return mdName;
+ }
+
+ /**
+ * Convert YANG API MD identifier to the CFM API MD identifier.
+ * @param nameAndTypeCombo Maintenance Domain ID in YANG API
+ * @return Maintenance Domain ID in CFM API
+ */
+ public static MdId getApiMdIdFromYangMdName(MdNameAndTypeCombo nameAndTypeCombo) {
+ MdId mdId;
+ if (nameAndTypeCombo instanceof DefaultNameDomainName) {
+ NameDomainNameUnion domainName =
+ ((DefaultNameDomainName) nameAndTypeCombo).nameDomainName();
+ if (domainName.ipAddress() != null) {
+ mdId = MdIdDomainName.asMdId(domainName.ipAddress().toString());
+ } else if (domainName.domainName() != null) {
+ mdId = MdIdDomainName.asMdId(domainName.domainName().string());
+ } else {
+ throw new IllegalArgumentException("Unexpected domainName for " +
+ "MdNameAndTypeCombo: " + nameAndTypeCombo.toString());
+ }
+ } else if (nameAndTypeCombo instanceof DefaultNameCharacterString) {
+ mdId = MdIdCharStr.asMdId(
+ ((NameCharacterString) nameAndTypeCombo).name().string());
+
+ } else if (nameAndTypeCombo instanceof DefaultMacAddressAndUint) {
+ mdId = MdIdMacUint.asMdId(
+ ((MacAddressAndUint) nameAndTypeCombo).nameMacAddressAndUint().string());
+
+ } else if (nameAndTypeCombo instanceof DefaultNameNone) {
+ mdId = MdIdNone.asMdId();
+ } else {
+ throw new IllegalArgumentException("Unexpected type for " +
+ "MdNameAndTypeCombo: " + nameAndTypeCombo.toString());
+ }
+
+ return mdId;
+ }
+
+ /**
+ * Cast the YANG generic type of MdNameAndTypeCombo specifically to char string.
+ * @param maName a YANG generic MdNameAndTypeCombo
+ * @return a YANG specific MdNameAndTypeCombo for Char string
+ */
+ public static NameCharacterString cast(MdNameAndTypeCombo maName) {
+ return (NameCharacterString) maName;
+ }
+}
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammableTest.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammableTest.java
index 20e80a1..1f87634 100644
--- a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammableTest.java
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/EA1000CfmMepProgrammableTest.java
@@ -20,11 +20,13 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.onosproject.drivers.microsemi.yang.utils.MdNameUtil.getYangMdNameFromApiMdId;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil;
+import org.onosproject.drivers.microsemi.yang.utils.MdNameUtil;
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate;
import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
@@ -38,21 +40,24 @@
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo;
import java.util.BitSet;
+import java.util.Optional;
/**
* Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface.
*/
public class EA1000CfmMepProgrammableTest {
- EA1000CfmMepProgrammable cfmProgrammable;
public static final MdId MD_ID_1 = MdIdCharStr.asMdId("md-1");
public static final MaIdShort MA_ID_11 = MaIdCharStr.asMaId("ma-1-1");
public static final MepId MEP_111 = MepId.valueOf((short) 1);
public static final MepId MEP_112 = MepId.valueOf((short) 2);
+ private CfmMepProgrammable cfmProgrammable;
+
@Before
public void setUp() throws Exception {
cfmProgrammable = new EA1000CfmMepProgrammable();
@@ -67,12 +72,6 @@
fail("Not yet implemented");
}
- @Ignore
- @Test
- public void testGetAllMeps() {
- fail("Not yet implemented");
- }
-
@Test
public void testGetMep() throws CfmConfigException {
MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111);
@@ -143,7 +142,107 @@
*/
@Test
public void testDeleteMep() throws CfmConfigException {
- assertTrue(cfmProgrammable.deleteMep(MD_ID_1, MA_ID_11, MEP_111));
+ assertTrue(cfmProgrammable.deleteMep(MD_ID_1, MA_ID_11, MEP_111, Optional.empty()));
+ }
+
+ /**
+ * Create the MD md-1 on the device.
+ * This will retrieve the MD from the MockCfmMdService and will create it
+ * and its MA on the device
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testCreateMaintenanceDomainOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-1"));
+ assertTrue(success);
+ }
+
+ /**
+ * Create the MD md-2 on the device.
+ * This will retrieve the MD from the MockCfmMdService and will create it on
+ * the device. This MD has no MA
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testCreateMaintenanceDomainOnDevice2() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.createMdOnDevice(MdIdCharStr.asMdId("md-2"));
+ assertTrue(success);
+ }
+
+ /**
+ * Delete the MD md-1 on the device.
+ * This will retrieve the MD from the MockCfmMdService and will delete it on
+ * the device.
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testDeleteMaintenanceDomainOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.deleteMdOnDevice(MdIdCharStr.asMdId("md-1"), Optional.empty());
+ assertTrue(success);
+ }
+
+
+ /**
+ * Create the MA ma-1-1 on the device.
+ * This will retrieve the MA from the MockCfmMdService and will create it
+ * on the device under md-1
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testCreateMaintenanceAssociationOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.createMaOnDevice(
+ MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"));
+ assertTrue(success);
+ }
+
+ /**
+ * Delete the MD md-1 on the device.
+ * This will retrieve the MD from the MockCfmMdService and will delete it on
+ * the device.
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testDeleteMaintenanceAssociationOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.deleteMaOnDevice(
+ MdIdCharStr.asMdId("md-1"),
+ MaIdCharStr.asMaId("ma-1-1"),
+ Optional.empty());
+ assertTrue(success);
+ }
+
+ /**
+ * Create the Remote Mep 10001 in ma-1-1 on the device.
+ * This will retrieve the MA from the MockCfmMdService and will create the
+ * new remote mep under it on the device
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testCreateRemoteMepOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.createMaRemoteMepOnDevice(
+ MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
+ MepId.valueOf((short) 1001));
+ assertTrue(success);
+ }
+
+ /**
+ * Delete the Remote Mep 1002 in ma-1-1 on the device.
+ * This will retrieve the MA from the MockCfmMdService and will delete the
+ * existing remote mep under it on the device
+ * Depends on sampleXmlRegexCreateMseaCfmMa
+ */
+ @Test
+ public void testDeleteRemoteMepOnDevice() throws CfmConfigException {
+ boolean success =
+ cfmProgrammable.deleteMaRemoteMepOnDevice(
+ MdIdCharStr.asMdId("md-1"), MaIdCharStr.asMaId("ma-1-1"),
+ MepId.valueOf((short) 1001));
+ assertTrue(success);
}
/**
@@ -167,25 +266,21 @@
cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111);
}
-// @Test
-// public void testTransmitLinktrace() {
-// fail("Not yet implemented");
-// }
+ @Ignore
+ @Test
+ public void testTransmitLinktrace() {
+ fail("Not yet implemented");
+ }
@Test
public void testGetYangMdNameFromApiMdId() throws CfmConfigException {
- MdNameAndTypeCombo name = EA1000CfmMepProgrammable
- .getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1"));
+ MdNameAndTypeCombo name = getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1"));
assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
.maintenancedomain.mdnameandtypecombo
.DefaultNameCharacterString.class, name.getClass());
-//There's a problem with checkstyle for typecast on really long paths
-// assertEquals("md-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com
-// .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm
-// .maintenancedomain.mdnameandtypecombo
-// .DefaultNameCharacterString) name).name().string());
+ assertEquals("md-1", MdNameUtil.cast(name).name().string());
}
@Test
@@ -196,11 +291,6 @@
.maintenancedomain.maintenanceassociation.manameandtypecombo
.DefaultNameCharacterString.class, name.getClass());
-//There's a problem with checkstyle for typecast on really long paths
-// assertEquals("ma-1-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com
-// .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm
-// .maintenancedomain.maintenanceassociation.manameandtypecombo
-// .DefaultNameCharacterString) name).name().string());
+ assertEquals("ma-1-1", MaNameUtil.cast(name).name().string());
}
-
}
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/MockEa1000DriverHandler.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/MockEa1000DriverHandler.java
index 58a8a5b..742f8c9 100644
--- a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/MockEa1000DriverHandler.java
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/MockEa1000DriverHandler.java
@@ -20,6 +20,7 @@
import org.onosproject.core.CoreService;
import org.onosproject.drivers.microsemi.yang.MockCfmMdService;
+import org.onosproject.drivers.microsemi.yang.MockCfmMepService;
import org.onosproject.drivers.microsemi.yang.MockMseaCfmManager;
import org.onosproject.drivers.microsemi.yang.MockMseaSaFilteringManager;
import org.onosproject.drivers.microsemi.yang.MockMseaUniEvcServiceManager;
@@ -31,6 +32,7 @@
import org.onosproject.drivers.netconf.MockNetconfController;
import org.onosproject.drivers.netconf.MockNetconfDevice;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.driver.Behaviour;
import org.onosproject.net.driver.DefaultDriver;
@@ -59,6 +61,7 @@
private MockMseaUniEvcServiceManager mseaUniEvcService;
private MockMseaCfmManager mseaCfmService;
private MockCfmMdService mockMdService;
+ private MockCfmMepService mockMepService;
private CoreService coreService;
public MockEa1000DriverHandler() throws NetconfException {
@@ -92,6 +95,9 @@
mockMdService = new MockCfmMdService();
mockMdService.activate();
+ mockMepService = new MockCfmMepService();
+ mockMepService.activate();
+
coreService = new MockCoreService();
coreService.registerApplication(MICROSEMI_DRIVERS);
}
@@ -131,6 +137,10 @@
} else if (serviceClass.equals(CfmMdService.class)) {
return (T) mockMdService;
+
+ } else if (serviceClass.equals(CfmMepService.class)) {
+ return (T) mockMepService;
+
}
return null;
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMdService.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMdService.java
index ba6d656..3d0fb5f 100644
--- a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMdService.java
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMdService.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.drivers.microsemi.yang;
+import org.onlab.packet.VlanId;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultComponent;
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation;
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
@@ -22,6 +24,7 @@
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
import org.onosproject.incubator.net.l2monitoring.cfm.impl.CfmMdManager;
import static org.easymock.EasyMock.*;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
@@ -29,6 +32,9 @@
import java.util.Optional;
+/**
+ * Supports testing of services that reply on the CfmMdService.
+ */
public class MockCfmMdService extends CfmMdManager {
@Override
@@ -40,6 +46,11 @@
.builder(MaIdCharStr.asMaId("ma-1-1"), 6)
.maNumericId((short) 1)
.ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_3MS)
+ .addToRemoteMepIdList(MepId.valueOf((short) 10))
+ .addToRemoteMepIdList(MepId.valueOf((short) 20))
+ .addToComponentList(
+ DefaultComponent.builder(1)
+ .addToVidList(VlanId.vlanId((short) 101)).build())
.build();
MdId md1Name = MdIdCharStr.asMdId("md-1");
@@ -50,14 +61,25 @@
.addToMaList(ma)
.build();
+ MdId md2Name = MdIdCharStr.asMdId("md-2");
+ MaintenanceDomain md2 = DefaultMaintenanceDomain
+ .builder(md1Name)
+ .mdNumericId((short) 2)
+ .mdLevel(MaintenanceDomain.MdLevel.LEVEL2)
+ .build();
+
expect(store.createUpdateMaintenanceDomain(md1))
.andReturn(true);
+ expect(store.createUpdateMaintenanceDomain(md2))
+ .andReturn(true);
expect(store.getMaintenanceDomain(md1Name))
.andReturn(Optional.of(md1)).anyTimes();
+ expect(store.getMaintenanceDomain(md2Name))
+ .andReturn(Optional.of(md2)).anyTimes();
replay(store);
} catch (CfmConfigException e) {
- throw new IllegalArgumentException("Error creating Md md-1 for test");
+ throw new IllegalArgumentException("Error creating MDs for test", e);
}
}
}
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMepService.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMepService.java
new file mode 100644
index 0000000..c00fc4e
--- /dev/null
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockCfmMepService.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.microsemi.yang;
+
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.ChassisId;
+import org.onosproject.common.event.impl.TestEventDispatcher;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.core.IdGenerator;
+import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMep;
+import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
+import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.CfmMdManager;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.CfmMepManager;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.TestCfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.impl.TestDeviceDiscoveryBehavior;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepProgrammable;
+import org.onosproject.incubator.net.l2monitoring.cfm.service.MepStore;
+import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable;
+import org.onosproject.incubator.net.l2monitoring.soam.impl.TestSoamDmProgrammable;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceDescriptionDiscovery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.onosproject.net.NetTestTools.injectEventDispatcher;
+
+/**
+ * Supports testing of services that reply on the CfmMepService.
+ */
+public class MockCfmMepService extends CfmMepManager {
+ private static final String TEST_MFR = "testMfr";
+ private static final String TEST_HW_VERSION = "testHwVersion";
+ private static final String TEST_SW_VERSION = "testSwVersion";
+ private static final String TEST_SN = "testSn";
+ private static final String TEST_DRIVER = "testDriver";
+ protected static final DeviceId DEVICE_ID1 = DeviceId.deviceId("netconf:1.2.3.4:830");
+
+
+ private final DriverService driverService = createMock(DriverService.class);
+
+ private Device device1;
+ private Driver testDriver;
+
+
+ @Override
+ public void activate() {
+ mepStore = createMock(MepStore.class);
+ cfmMdService = new MockCfmMdService();
+ deviceService = createMock(DeviceService.class);
+ ((CfmMdManager) cfmMdService).activate();
+
+ device1 = new DefaultDevice(
+ ProviderId.NONE, DEVICE_ID1, Device.Type.SWITCH,
+ TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN,
+ new ChassisId(1),
+ DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
+
+ Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
+ behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
+ behaviours.put(CfmMepProgrammable.class, TestCfmMepProgrammable.class);
+ behaviours.put(SoamDmProgrammable.class, TestSoamDmProgrammable.class);
+
+ TestUtils.setField(this, "coreService", new TestCoreService());
+ TestUtils.setField(this, "deviceService", deviceService);
+ injectEventDispatcher(this, new TestEventDispatcher());
+
+ testDriver = new DefaultDriver(
+ TEST_DRIVER, new ArrayList<Driver>(),
+ TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION,
+ behaviours, new HashMap<>());
+
+ try {
+ Mep mep1 = DefaultMep.builder(
+ MepId.valueOf((short) 10),
+ DEVICE_ID1,
+ PortNumber.P0,
+ Mep.MepDirection.UP_MEP,
+ MdIdCharStr.asMdId("md-1"),
+ MaIdCharStr.asMaId("ma-1-1"))
+ .build();
+
+ expect(mepStore.getMep(new MepKeyId(mep1))).andReturn(Optional.of(mep1)).anyTimes();
+ } catch (CfmConfigException e) {
+ throw new IllegalArgumentException("Error creating MEPs for test", e);
+ }
+ }
+
+ private class TestCoreService extends CoreServiceAdapter {
+
+ @Override
+ public IdGenerator getIdGenerator(String topic) {
+ return new IdGenerator() {
+ private AtomicLong counter = new AtomicLong(0);
+
+ @Override
+ public long getNewId() {
+ return counter.getAndIncrement();
+ }
+ };
+ }
+ }
+}
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockNetconfSessionEa1000.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockNetconfSessionEa1000.java
index b9d4342..6bf67c0 100644
--- a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockNetconfSessionEa1000.java
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MockNetconfSessionEa1000.java
@@ -478,11 +478,12 @@
+ "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ "(<mef-cfm).*"
+ "(<maintenance-domain>)\\R?"
- + "(<id/>)?\\R?"
- + "(<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>)\\R?"
+ + "(<id>[0-9]{1,5}</id>)?\\R?"
+ + "((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))?\\R?"
+ "(<maintenance-association>)\\R?"
- + "(<id/>)?\\R?"
- + "(<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>)\\R?"
+ + "(<id>[0-9]{1,5}</id>)?\\R?"
+ + "((<name>[a-zA-Z0-9\\-:\\.]{1,48}</name>)|"
+ + "(<name-primary-vid>[0-9]{1,4}</name-primary-vid>))?\\R?"
+ "(<maintenance-association-end-point nc:operation=\"delete\">)\\R?"
+ "(<mep-identifier>)[0-9]{1,4}(</mep-identifier>)\\R?"
+ "(</maintenance-association-end-point>)\\R?"
@@ -492,6 +493,85 @@
+ "(</config>)\\R?"
+ "(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+ //For testGetConfigMseaCfmEssentials
+ private Pattern sampleXmlRegexCreateMseaCfmMa =
+ Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
+ + "(<target>\\R?<running/>\\R?</target>)\\R?"
+ + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ + "(<mef-cfm).*"
+ + "(<maintenance-domain>)\\R?"
+ + "(<id>)([0-9]){1,4}(</id>)\\R?"
+ + "((<md-level>)([0-9]){1}(</md-level>))?\\R?"
+ + "((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))?\\R?"
+ + "((<maintenance-association>)\\R?"
+ + "(<id>)([0-9]){1,4}(</id>)\\R?"
+ + "((<ccm-interval>)(3.3ms)(</ccm-interval>))?\\R?"
+ + "((<remote-meps>)([0-9]){1,4}(</remote-meps>))*\\R?"
+ + "(((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))|"
+ + "((<name-primary-vid>)([0-9]){1,4}(</name-primary-vid>)))?\\R?"
+ + "((<component-list>)\\R?"
+ + "(<vid>)([0-9]){1,4}(</vid>)\\R?"
+ + "(</component-list>))?\\R?"
+ + "(</maintenance-association>))*\\R?"
+ + "(</maintenance-domain>)\\R?"
+ + "(</mef-cfm>)\\R?"
+ + "(</config>)\\R?"
+ + "(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+
+ //For testGetConfigMseaCfmEssentials
+ private Pattern sampleXmlRegexDeleteMseaCfmMa =
+ Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
+ + "(<target>\\R?<running/>\\R?</target>)\\R?"
+ + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ + "(<mef-cfm).*"
+ + "(<maintenance-domain>)\\R?"
+ + "((<id/>)|((<id>)([0-9]){1,4}(</id>)))?\\R?"
+ + "((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))?\\R?"
+ + "(<maintenance-association nc:operation=\"delete\">)\\R?"
+ + "((<id/>)|((<id>)([0-9]){1,4}(</id>)))?\\R?"
+ + "(((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))|"
+ + "((<name-primary-vid>)([0-9]){1,4}(</name-primary-vid>)))?\\R?"
+ + "(</maintenance-association>)\\R?"
+ + "(</maintenance-domain>)\\R?"
+ + "(</mef-cfm>)\\R?"
+ + "(</config>)\\R?"
+ + "(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+
+ //For testDeleteMseaMepRemoteMep
+ private Pattern sampleXmlRegexDeleteMseaCfmRmep =
+ Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
+ + "(<target>\\R?<running/>\\R?</target>)\\R?"
+ + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ + "(<mef-cfm).*"
+ + "(<maintenance-domain>)\\R?"
+ + "((<id>)[0-9]{1,4}(</id>))?\\R?"
+ + "((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))?\\R?"
+ + "(<maintenance-association>)\\R?"
+ + "((<id>)[0-9]{1,4}(</id>))?\\R?"
+ + "((<remote-meps nc:operation=\"delete\">)([0-9]){1,4}(</remote-meps>))*\\R?"
+ + "(((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))|"
+ + "((<name-primary-vid>)([0-9]){1,4}(</name-primary-vid>)))?\\R?"
+ + "(</maintenance-association>)\\R?"
+ + "(</maintenance-domain>)\\R?"
+ + "(</mef-cfm>)\\R?"
+ + "(</config>)\\R?"
+ + "(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+
+ //For testDeleteMseaMd
+ private Pattern sampleXmlRegexDeleteMseaCfmMd =
+ Pattern.compile("(<\\?xml).*(<rpc).*(<edit-config>)\\R?"
+ + "(<target>\\R?<running/>\\R?</target>)\\R?"
+ + "(<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">)\\R?"
+ + "(<mef-cfm).*"
+ + "(<maintenance-domain nc:operation=\"delete\">)\\R?"
+ + "((<id/>)|(<id>([0-9]){1,4}(</id>)))?\\R?"
+ + "(((<name>)([a-zA-Z0-9\\-:\\.]){1,48}(</name>))|\\R?"
+ + "((<name-domain-name>)([a-zA-Z0-9\\-\\.]){1,48}(</name-domain-name>)))?\\R?"
+ + "(</maintenance-domain>)\\R?"
+ + "(</mef-cfm>)\\R?"
+ + "(</config>)\\R?"
+ + "(</edit-config>)\\R?(</rpc>)\\R?(]]>){2}", Pattern.DOTALL);
+
private Pattern sampleXmlRegexTransmitLoopback =
Pattern.compile("(<\\?xml).*(<rpc).*\\R?"
@@ -1310,6 +1390,18 @@
} else if (sampleXmlRegexDeleteMseaCfmMep.matcher(request).matches()) {
return SAMPLE_REPLY_OK;
+ } else if (sampleXmlRegexCreateMseaCfmMa.matcher(request).matches()) {
+ return SAMPLE_REPLY_OK;
+
+ } else if (sampleXmlRegexDeleteMseaCfmMa.matcher(request).matches()) {
+ return SAMPLE_REPLY_OK;
+
+ } else if (sampleXmlRegexDeleteMseaCfmRmep.matcher(request).matches()) {
+ return SAMPLE_REPLY_OK;
+
+ } else if (sampleXmlRegexDeleteMseaCfmMd.matcher(request).matches()) {
+ return SAMPLE_REPLY_OK;
+
} else if (sampleXmlRegexGetMseaDelay.matcher(request).matches()) {
return SAMPLE_MSEACFM_DELAY_MEASUREMENT_FULL_REPLY;
diff --git a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MseaCfmManagerTest.java b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MseaCfmManagerTest.java
index fe99bf3..bb65a4d 100644
--- a/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MseaCfmManagerTest.java
+++ b/drivers/microsemi/src/test/java/org/onosproject/drivers/microsemi/yang/MseaCfmManagerTest.java
@@ -36,20 +36,31 @@
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.soam.SoamId;
+import org.onosproject.netconf.DatastoreId;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
import org.onosproject.yang.gen.v1.ietfyangtypes.rev20130715.ietfyangtypes.MacAddress;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfm;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfmOpParam;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.DefaultMefCfm;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.MefCfm;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.AbortLoopbackInput;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.abortloopback.DefaultAbortLoopbackInput;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.DefaultMaintenanceDomain;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.MaintenanceDomain;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.DefaultMaintenanceAssociation;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MaintenanceAssociation;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.DefaultMaintenanceAssociationEndPoint;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaintenanceAssociationEndPoint;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNamePrimaryVid;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.NamePrimaryVid;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.nameprimaryvid.NamePrimaryVidUnion;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameCharacterString;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.DefaultNameDomainName;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.NameCharacterString;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.NameDomainName;
+import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.mdnameandtypecombo.namedomainname.NameDomainNameUnion;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.AddressType;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMacAddress;
import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.targetaddressgroup.addresstype.DefaultMepId;
@@ -194,10 +205,173 @@
// mseaCfmService.setMseaCfm(mseaCfmOpParam, session, NcDsType.running);
}
+ /**
+ * Using mep Id 10.
+ */
@Test
+ public void testDeleteMseaMep() {
+ MaintenanceAssociationEndPoint mep10 = new DefaultMaintenanceAssociationEndPoint();
+ mep10.mepIdentifier(MepIdType.of(10));
+
+ MaintenanceAssociation ma1100 = new DefaultMaintenanceAssociation();
+ NamePrimaryVid pvid1100Name = new DefaultNamePrimaryVid();
+ pvid1100Name.namePrimaryVid(NamePrimaryVidUnion.fromString("1100"));
+ ma1100.maNameAndTypeCombo(pvid1100Name);
+ ma1100.id((short) 1100);
+ ma1100.addToMaintenanceAssociationEndPoint(mep10);
+
+ MaintenanceDomain md = new DefaultMaintenanceDomain();
+ NameCharacterString mdName = new DefaultNameCharacterString();
+ mdName.name(new Identifier45("md-1"));
+ md.mdNameAndTypeCombo(mdName);
+ md.id((short) 1);
+ md.addToMaintenanceAssociation(ma1100);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(md);
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ mseaCfm.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMep(mseaCfm, session, DatastoreId.RUNNING);
+ assertTrue(deleted);
+ } catch (NetconfException e) {
+ e.printStackTrace();
+ fail();
+ } catch (CfmConfigException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Using mep Id 10.
+ */
+ @Test
+ public void testDeleteMseaMa() {
+ MaintenanceAssociation ma1300 = new DefaultMaintenanceAssociation();
+ NamePrimaryVid pvid1300Name = new DefaultNamePrimaryVid();
+ pvid1300Name.namePrimaryVid(NamePrimaryVidUnion.fromString("1300"));
+ ma1300.id((short) 1300);
+ ma1300.maNameAndTypeCombo(pvid1300Name);
+
+ MaintenanceDomain md = new DefaultMaintenanceDomain();
+ NameCharacterString mdName = new DefaultNameCharacterString();
+ mdName.name(new Identifier45("md-13"));
+ md.mdNameAndTypeCombo(mdName);
+ md.id((short) 13);
+ md.addToMaintenanceAssociation(ma1300);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(md);
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ mseaCfm.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMa(mseaCfm, session, DatastoreId.RUNNING);
+ assertTrue(deleted);
+ } catch (NetconfException e) {
+ e.printStackTrace();
+ fail();
+ } catch (CfmConfigException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+ @Test
+ public void testDeleteMseaRemoteMep() {
+ MaintenanceAssociation ma1100 = new DefaultMaintenanceAssociation();
+ NamePrimaryVid pvid1100Name = new DefaultNamePrimaryVid();
+ pvid1100Name.namePrimaryVid(NamePrimaryVidUnion.fromString("1100"));
+ ma1100.maNameAndTypeCombo(pvid1100Name);
+ ma1100.id((short) 1100);
+ ma1100.addToRemoteMeps(MepIdType.of(100));
+ ma1100.addToRemoteMeps(MepIdType.of(101));
+
+ MaintenanceDomain md = new DefaultMaintenanceDomain();
+ NameCharacterString mdName = new DefaultNameCharacterString();
+ mdName.name(new Identifier45("md-1"));
+ md.mdNameAndTypeCombo(mdName);
+ md.id((short) 1);
+ md.addToMaintenanceAssociation(ma1100);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(md);
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ mseaCfm.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMaRMep(mseaCfm, session, DatastoreId.RUNNING);
+ assertTrue(deleted);
+ } catch (NetconfException e) {
+ e.printStackTrace();
+ fail();
+ } catch (CfmConfigException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Using mep Id 10.
+ */
+ @Test
+ public void testDeleteMseaMdById() {
+
+ MaintenanceDomain md = new DefaultMaintenanceDomain();
+ NameDomainName mdName = new DefaultNameDomainName();
+ mdName.nameDomainName(NameDomainNameUnion.fromString("www.opennetworking.org"));
+ md.mdNameAndTypeCombo(mdName);
+ md.id((short) 10);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(md);
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ mseaCfm.mefCfm(mefCfm);
+
+ try {
+ boolean deleted = mseaCfmService.deleteMseaMd(mseaCfm, session, DatastoreId.RUNNING);
+ assertTrue(deleted);
+ } catch (NetconfException e) {
+ e.printStackTrace();
+ fail();
+ } catch (CfmConfigException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Using mep Id 10.
+ */
+ @Test
+ public void testDeleteMseaMdByName() {
+
+ MaintenanceDomain md = new DefaultMaintenanceDomain();
+ NameDomainName mdName = new DefaultNameDomainName();
+ mdName.nameDomainName(NameDomainNameUnion.fromString("www.opennetworking.org"));
+ md.mdNameAndTypeCombo(mdName);
+
+ MefCfm mefCfm = new DefaultMefCfm();
+ mefCfm.addToMaintenanceDomain(md);
+ MseaCfmOpParam mseaCfm = new MseaCfmOpParam();
+ mseaCfm.mefCfm(mefCfm);
+
+ try {
+ mseaCfmService.deleteMseaMd(mseaCfm, session, DatastoreId.RUNNING);
+ fail("Should not have succeeded as no numeric id was given");
+ } catch (NetconfException | CfmConfigException e) {
+ assertEquals("An MD numeric ID must be given", e.getMessage());
+ }
+ }
+
+
/**
* Using Remote remote MEP ID and all arguments.
*/
+ @Test
public void testTransmitLoopback1() {
TransmitLoopbackInput lbTr1 = new DefaultTransmitLoopbackInput();
lbTr1.maintenanceDomain(Short.valueOf((short) 1));
@@ -221,10 +395,10 @@
}
}
- @Test
/**
* Using Remote Mac address in place of remote MEP ID and fewer arguments.
*/
+ @Test
public void testTransmitLoopback2() {
TransmitLoopbackInput lbTr2 = new DefaultTransmitLoopbackInput();