Refactor of CFM code part 5 - SonarQube recommended code changes
previously:
Refactor of CFM code part 4 - Microsemi driver - updating modules.deps with the move of the driver code
Refactor of CFM code part 3 - Microsemi driver: moved everything out of drivers/microsemi to /drivers/microsemi/ea1000 to make room for future drivers
Refactor of CFM code parti 2 - API: moved everything from incubator/*/src/main/java/org/onosproject/incubator/net/l2monitoring to apps/cfm/*/src/main/java/org/onosproject/incubator/net/l2monitoring - this means that services belonging to l2 monitoring will now only be loaded when cfm app is started
Refactor of CFM code part 1 - NBI: moves the CLI and REST part of the app down a level to an nbi folder for a more consistent approach with other modules
Change-Id: I39b302fd8620f59d34ab41208cbc28765951aad4
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaAddCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaAddCommand.java
index d449cce..1fec9f3 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaAddCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaAddCommand.java
@@ -23,17 +23,8 @@
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultComponent;
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid;
-import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId;
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.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
@@ -44,60 +35,55 @@
@Command(scope = "onos", name = "cfm-ma-add",
description = "Add a CFM Maintenance Association to a Maintenance Domain.")
public class CfmMaAddCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "name",
+ @Argument(name = "name",
description = "Maintenance Domain name and type (in brackets)",
- required = true, multiValued = false)
- String mdName = null;
+ required = true)
+ private String mdName = null;
@Argument(index = 1, name = "name-type",
description = "Maintenance Assocation name type",
- required = true, multiValued = false)
- String nameType = null;
+ required = true)
+ private String nameType = null;
@Argument(index = 2, name = "name",
description = "Maintenance Assocation name. Restrictions apply depending " +
"on name-type",
- required = true, multiValued = false)
- String name = null;
+ required = true)
+ private String name = null;
@Argument(index = 3, name = "ccm-interval",
description = "CCM Interval values from list",
- required = true, multiValued = false)
- String ccmInterval = null;
+ required = true)
+ private String ccmInterval = null;
@Argument(index = 4, name = "numeric-id",
- description = "An optional numeric id for Maintenance Association [1-65535]",
- required = false, multiValued = false)
- short numericId = 0;
+ description = "An optional numeric id for Maintenance Association [1-65535]")
+ private Short numericId = null;
@Argument(index = 5, name = "component-id",
description = "An id for a Component in the Component List [1-65535]." +
"The CLI allows creation of only 1 component. If more are " +
- "required use the REST interface",
- required = false, multiValued = false)
- short componentId = 0;
+ "required use the REST interface")
+ private Short componentId = null;
@Argument(index = 6, name = "component-tag-type",
- description = "Tag Type value for the component",
- required = false, multiValued = false)
- String tagType = null;
+ description = "Tag Type value for the component")
+ private String tagType = null;
@Argument(index = 7, name = "component-mhf-creation",
- description = "MEP Half function creation type for the component",
- required = false, multiValued = false)
- String mhfCreationType = null;
+ description = "MEP Half function creation type for the component")
+ private String mhfCreationType = null;
@Argument(index = 8, name = "component-vid",
description = "A VID for the component [1-4095]. This CLI allows " +
"only the specification of 1 VID. If more are required use " +
- "the REST interface",
- required = false, multiValued = false)
- short vid = 0;
+ "the REST interface")
+ private Short vid = null;
@Argument(index = 9, name = "rmep",
description = "Remote Mep numeric identifier [1-8192]",
required = true, multiValued = true)
- String[] rmepArray = null;
+ private String[] rmepArray = null;
@Override
protected void execute() {
@@ -109,56 +95,23 @@
"Must be in the format of <identifier(name-type)>");
}
- MdId mdId = null;
- MdId.MdNameType mdNameTypeEnum = MdId.MdNameType.valueOf(mdNameParts[1]);
- switch (mdNameTypeEnum) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(mdNameParts[0]);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(mdNameParts[0]);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(mdNameParts[0]);
- }
+ MdId mdId = CfmMdListMdCommand.parseMdName(mdNameParts[0] + "(" + mdNameParts[1] + ")");
- MaIdShort maId = null;
- MaIdShort.MaIdType maNameTypeEnum = MaIdShort.MaIdType.valueOf(nameType);
- switch (maNameTypeEnum) {
- case TWOOCTET:
- maId = MaId2Octet.asMaId(name);
- break;
- case ICCY1731:
- maId = MaIdIccY1731.asMaId(name);
- break;
- case PRIMARYVID:
- maId = MaIdPrimaryVid.asMaId(name);
- break;
- case RFC2685VPNID:
- maId = MaIdRfc2685VpnId.asMaIdHex(name);
- break;
- case CHARACTERSTRING:
- default:
- maId = MaIdCharStr.asMaId(name);
- }
+ MaIdShort maId = CfmMdListMdCommand.parseMaName(name + "(" + nameType + ")");
- MaintenanceAssociation.MaBuilder builder = null;
try {
- builder = DefaultMaintenanceAssociation.builder(maId, mdId.getNameLength());
+ MaintenanceAssociation.MaBuilder builder = DefaultMaintenanceAssociation
+ .builder(maId, mdId.getNameLength());
if (ccmInterval != null && !ccmInterval.isEmpty()) {
builder = builder.ccmInterval(MaintenanceAssociation.CcmInterval.valueOf(ccmInterval));
}
for (String rmep:rmepArray) {
builder = builder.addToRemoteMepIdList(MepId.valueOf(Short.parseShort(rmep)));
}
- if (numericId > 0) {
+ if (numericId != null) {
builder = builder.maNumericId(numericId);
}
- if (componentId > 0) {
+ if (componentId != null) {
Component.ComponentBuilder compBuilder =
DefaultComponent.builder(componentId);
if (tagType != null && !tagType.isEmpty()) {
@@ -169,7 +122,7 @@
compBuilder = compBuilder.mhfCreationType(
Component.MhfCreationType.valueOf(mhfCreationType));
}
- if (vid > 0) {
+ if (vid != null) {
compBuilder = compBuilder.addToVidList(VlanId.vlanId(vid));
}
builder = builder.addToComponentList(compBuilder.build());