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/CfmWebComponent.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/CfmWebComponent.java
index 6ead985..a31a407 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/CfmWebComponent.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/CfmWebComponent.java
@@ -82,8 +82,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementThreshold.*;
-
/**
* Enables the CFM REST Web Service component at /onos/cfm.
* Each codec for the rest interfaces should be registered here.
@@ -95,6 +93,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CodecService codecService;
+ /**
+ * On activation of this component register these codecs with the codec service.
+ */
@Activate
public void activate() {
codecService.registerCodec(MaintenanceDomain.class,
@@ -146,7 +147,7 @@
new LossAvailabilityStatHistoryCodec());
codecService.registerCodec(CounterOption.class,
new LmCounterOptionCodec());
- codecService.registerCodec(ThresholdOption.class,
+ codecService.registerCodec(LossMeasurementThreshold.ThresholdOption.class,
new LmThresholdOptionCodec());
codecService.registerCodec(StartTime.class, new StartTimeCodec());
@@ -155,6 +156,9 @@
log.info("CFM Web Component Started");
}
+ /**
+ * On deactivation of this component unregister these codecs from the codec service.
+ */
@Deactivate
public void deactivate() {
log.info("CFM Web Component Stopped");
@@ -189,7 +193,7 @@
codecService.unregisterCodec(LossAvailabilityStatCurrent.class);
codecService.unregisterCodec(LossAvailabilityStatHistory.class);
codecService.unregisterCodec(CounterOption.class);
- codecService.unregisterCodec(ThresholdOption.class);
+ codecService.unregisterCodec(LossMeasurementThreshold.ThresholdOption.class);
}
}
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());
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaDeleteCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaDeleteCommand.java
index 4228b78..b28a35e 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaDeleteCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMaDeleteCommand.java
@@ -18,17 +18,8 @@
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
-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.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
@@ -39,58 +30,26 @@
description = "Delete a CFM Maintenance Association and its children.")
public class CfmMaDeleteCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "name",
+ private static final int MA_NAME_PARTS_COUNT = 4;
+ @Argument(name = "name",
description = "Maintenance Domain name and type (in brackets) " +
"and the Maintenance Association name and type (in brackets)",
- required = true, multiValued = false)
- String name = null;
+ required = true)
+ private String name = null;
@Override
protected void execute() {
CfmMdService service = get(CfmMdService.class);
String[] nameParts = name.split("[()]");
- if (nameParts.length != 4) {
+ if (nameParts.length != MA_NAME_PARTS_COUNT) {
throw new IllegalArgumentException("Invalid name format. Must be in " +
"the format of <identifier(name-type)identifier(name-type)>");
}
- MdId mdId = null;
- MdId.MdNameType nameTypeEnum = MdId.MdNameType.valueOf(nameParts[1]);
- switch (nameTypeEnum) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(nameParts[0]);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(nameParts[0]);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(nameParts[0]);
- }
+ MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
- MaIdShort maId = null;
- MaIdShort.MaIdType maNameTypeEnum = MaIdShort.MaIdType.valueOf(nameParts[3]);
- switch (maNameTypeEnum) {
- case TWOOCTET:
- maId = MaId2Octet.asMaId(nameParts[2]);
- break;
- case ICCY1731:
- maId = MaIdIccY1731.asMaId(nameParts[2]);
- break;
- case PRIMARYVID:
- maId = MaIdPrimaryVid.asMaId(nameParts[2]);
- break;
- case RFC2685VPNID:
- maId = MaIdRfc2685VpnId.asMaIdHex(nameParts[2]);
- break;
- case CHARACTERSTRING:
- default:
- maId = MaIdCharStr.asMaId(nameParts[2]);
- }
+ MaIdShort maId = CfmMdListMdCommand.parseMaName(nameParts[2] + "(" + nameParts[3] + ")");
try {
boolean deleted = service.deleteMaintenanceAssociation(mdId, maId);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdAddCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdAddCommand.java
index 922ed64..c73fff3 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdAddCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdAddCommand.java
@@ -21,15 +21,9 @@
import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
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.incubator.net.l2monitoring.cfm.service.CfmMdService;
-import java.util.Optional;
-
/**
* Adds a Maintenance Domain to the existing list.
*/
@@ -37,58 +31,39 @@
description = "Add a CFM Maintenance Domain.")
public class CfmMdAddCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "name-type",
+ @Argument(name = "name-type",
description = "Maintenance Domain name type",
- required = true, multiValued = false)
- String nameType = null;
+ required = true)
+ private String nameType = null;
@Argument(index = 1, name = "name",
description = "Maintenance Domain name. Restrictions apply depending " +
"on name-type. Leave empty if name type is none",
- required = true, multiValued = false)
- String name = null;
+ required = true)
+ private String name = null;
@Argument(index = 2, name = "level",
description = "Maintenance Domain level LEVEL0-LEVEL7",
- required = true, multiValued = false)
- String level = null;
+ required = true)
+ private String level = null;
@Argument(index = 3, name = "numeric-id",
- description = "An optional numeric id for Maintenance Domain [1-65535]",
- required = false, multiValued = false)
- short numericId = 0;
+ description = "An optional numeric id for Maintenance Domain [1-65535]")
+ private Short numericId = null;
@Override
protected void execute() {
CfmMdService service = get(CfmMdService.class);
- MdId mdId = null;
- MdId.MdNameType nameTypeEnum = MdId.MdNameType.valueOf(nameType);
- switch (nameTypeEnum) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(name);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(name);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(name);
- }
+ MdId mdId = CfmMdListMdCommand.parseMdName(name + "(" + nameType + ")");
+
MaintenanceDomain.MdLevel levelEnum =
MaintenanceDomain.MdLevel.valueOf(level);
- Optional<Short> numericIdOpt = Optional.empty();
- if (numericId > 0) {
- numericIdOpt = Optional.of(numericId);
- }
- MaintenanceDomain.MdBuilder builder = null;
try {
- builder = DefaultMaintenanceDomain.builder(mdId).mdLevel(levelEnum);
- if (numericIdOpt.isPresent()) {
- builder = builder.mdNumericId(numericIdOpt.get());
+ MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain
+ .builder(mdId).mdLevel(levelEnum);
+ if (numericId != null) {
+ builder = builder.mdNumericId(numericId);
}
boolean created = service.createMaintenanceDomain(builder.build());
print("Maintenance Domain with id %s is successfully %s.",
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdDeleteCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdDeleteCommand.java
index 3cf3c26..85f47eb 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdDeleteCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdDeleteCommand.java
@@ -19,10 +19,6 @@
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
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.incubator.net.l2monitoring.cfm.service.CfmMdService;
@@ -33,10 +29,10 @@
description = "Delete a CFM Maintenance Domain and its children.")
public class CfmMdDeleteCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "name",
+ @Argument(name = "name",
description = "Maintenance Domain name and type (in brackets)",
- required = true, multiValued = false)
- String name = null;
+ required = true)
+ private String name = null;
@Override
protected void execute() {
@@ -48,22 +44,7 @@
"Must be in the format of <identifier(name-type)>");
}
- MdId mdId = null;
- MdId.MdNameType nameTypeEnum = MdId.MdNameType.valueOf(nameParts[1]);
- switch (nameTypeEnum) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(nameParts[0]);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(nameParts[0]);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(nameParts[0]);
- }
+ MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
try {
boolean deleted = service.deleteMaintenanceDomain(mdId);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdListMdCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdListMdCommand.java
index 6f41005..7965113 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdListMdCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMdListMdCommand.java
@@ -20,84 +20,76 @@
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
-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.MdMaNameUtil;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
-import java.util.Optional;
-
/**
* Lists a particular Maintenance Domain.
*/
@Command(scope = "onos", name = "cfm-md-list",
description = "Lists a single CFM Maintenance Domain or all if none specified.")
public class CfmMdListMdCommand extends AbstractShellCommand {
- @Argument(index = 0, name = "name",
- description = "Maintenance Domain name and type (in brackets)",
- required = false, multiValued = false)
- String name = null;
+ @Argument(name = "name",
+ description = "Maintenance Domain name and type (in brackets)")
+ private String name = null;
@Override
protected void execute() {
- CfmMdService service = get(CfmMdService.class);
+ CfmMdService service;
+ service = get(CfmMdService.class);
if (name != null) {
MdId mdId = parseMdName(name);
print("Maintenance Domain:");
- Optional<MaintenanceDomain> md = service.getMaintenanceDomain(mdId);
- print(printMd(md));
- md.get().maintenanceAssociationList().forEach(ma -> printMa(Optional.of(ma)));
- } else {
- service.getAllMaintenanceDomain().forEach(md -> {
- print(printMd(Optional.of(md)));
+ service.getMaintenanceDomain(mdId).ifPresent(md -> {
+ print(printMd(md));
+ md.maintenanceAssociationList().forEach(CfmMdListMdCommand::printMa);
});
+ } else {
+ service.getAllMaintenanceDomain().forEach(md -> print(printMd(md)));
}
}
- public static String printMd(Optional<MaintenanceDomain> md) {
- if (!md.isPresent()) {
- return new String("MD not found");
+ private static String printMd(MaintenanceDomain md) {
+ if (md == null) {
+ return "MD not found";
} else {
- StringBuffer sb = new StringBuffer("\tMD: ");
- sb.append(md.get().mdId().mdName());
- sb.append("(" + md.get().mdId().nameType());
- sb.append(") Lvl:" + md.get().mdLevel().ordinal());
- sb.append(", Num: " + md.get().mdNumericId());
+ StringBuilder sb = new StringBuilder("\tMD: ");
+ sb.append(md.mdId().mdName());
+ sb.append("(");
+ sb.append(md.mdId().nameType());
+ sb.append(") Lvl:");
+ sb.append(md.mdLevel().ordinal());
+ sb.append(", Num: ");
+ sb.append(md.mdNumericId());
- md.get().maintenanceAssociationList().
- forEach(ma -> sb.append(printMa(Optional.of(ma))));
+ md.maintenanceAssociationList().
+ forEach(ma -> sb.append(printMa(ma)));
return sb.toString();
}
}
- public static String printMa(Optional<MaintenanceAssociation> ma) {
- if (!ma.isPresent()) {
+ private static String printMa(MaintenanceAssociation ma) {
+ if (ma == null) {
return "\n\tNo MA found";
}
StringBuilder sb = new StringBuilder("\n\t\tMA: ");
- sb.append(ma.get().maId().maName());
+ sb.append(ma.maId().maName());
sb.append("(");
- sb.append(ma.get().maId().nameType());
+ sb.append(ma.maId().nameType());
sb.append(") CCM: ");
- sb.append(ma.get().ccmInterval());
+ sb.append(ma.ccmInterval());
sb.append(" Num: ");
- sb.append(ma.get().maNumericId());
+ sb.append(ma.maNumericId());
- ma.get().remoteMepIdList().forEach(rmep -> {
+ ma.remoteMepIdList().forEach(rmep -> {
sb.append("\n\t\t\tRmep: ");
sb.append(rmep);
});
- ma.get().componentList().forEach(comp -> {
+ ma.componentList().forEach(comp -> {
sb.append("\n\t\t\tComponent: ");
sb.append(comp.componentId());
sb.append(" Perm: ");
@@ -116,59 +108,24 @@
return sb.toString();
}
- public static MdId parseMdName(String mdStr) {
+ static MdId parseMdName(String mdStr) {
String[] nameParts = mdStr.split("[()]");
if (nameParts.length != 2) {
throw new IllegalArgumentException("Invalid name format. " +
"Must be in the format of <identifier(name-type)>");
}
- MdId mdId = null;
- MdId.MdNameType nameTypeEnum = MdId.MdNameType.valueOf(nameParts[1]);
- switch (nameTypeEnum) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(nameParts[0]);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(nameParts[0]);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(nameParts[0]);
- }
- return mdId;
+ return MdMaNameUtil.parseMdName(nameParts[1], nameParts[0]);
}
- public static MaIdShort parseMaName(String maStr) {
+ static MaIdShort parseMaName(String maStr) {
String[] nameParts = maStr.split("[()]");
if (nameParts.length != 2) {
throw new IllegalArgumentException("Invalid name format. " +
"Must be in the format of <identifier(name-type)>");
}
- MaIdShort maId = null;
- MaIdShort.MaIdType nameTypeEnum = MaIdShort.MaIdType.valueOf(nameParts[1]);
- switch (nameTypeEnum) {
- case ICCY1731:
- maId = MaIdIccY1731.asMaId(nameParts[0]);
- break;
- case PRIMARYVID:
- maId = MaIdPrimaryVid.asMaId(nameParts[0]);
- break;
- case RFC2685VPNID:
- maId = MaIdRfc2685VpnId.asMaIdHex(nameParts[0]);
- break;
- case TWOOCTET:
- maId = MaId2Octet.asMaId(nameParts[0]);
- break;
- case CHARACTERSTRING:
- default:
- maId = MaIdCharStr.asMaId(nameParts[0]);
- }
- return maId;
+ return MdMaNameUtil.parseMaName(nameParts[1], nameParts[0]);
}
}
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListCommand.java
index b406947..55ed5ef 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListCommand.java
@@ -39,18 +39,15 @@
description = "Lists a filtered set of MEPs or all if no parameters specified.")
public class CfmMepListCommand extends AbstractShellCommand {
private final Logger log = getLogger(getClass());
- @Argument(index = 0, name = "md",
- description = "Maintenance Domain name and type (in brackets) - will use all MDs if not specified",
- required = false, multiValued = false)
- String mdStr = null;
+ @Argument(name = "md",
+ description = "Maintenance Domain name and type (in brackets) - will use all MDs if not specified")
+ private String mdStr = null;
@Argument(index = 1, name = "ma",
- description = "Maintenance Association name and type (in brackets) - requires MD",
- required = false, multiValued = false)
- String maStr = null;
+ description = "Maintenance Association name and type (in brackets) - requires MD")
+ private String maStr = null;
@Argument(index = 2, name = "mep",
- description = "MEP identifier - requires MD and MA",
- required = false, multiValued = false)
- String mepStr = null;
+ description = "MEP identifier - requires MD and MA")
+ private String mepStr = null;
@Override
protected void execute() {
@@ -83,9 +80,8 @@
} else {
//MD and MA given but no MEP given
try {
- mepService.getAllMeps(mdId, maId).forEach(mep -> {
- print(printMepEntry(mep));
- });
+ mepService.getAllMeps(mdId, maId)
+ .forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}",
mdId.mdName(), maId.maName(), e);
@@ -96,9 +92,8 @@
mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
print(printMaId(ma.maId()));
try {
- mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> {
- print(printMepEntry(mep));
- });
+ mepService.getAllMeps(mdId, ma.maId())
+ .forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}",
mdId.mdName(), ma.maId().maName(), e);
@@ -113,9 +108,8 @@
mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
print(printMaId(ma.maId()));
try {
- mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> {
- print(printMepEntry(mep));
- });
+ mepService.getAllMeps(md.mdId(), ma.maId())
+ .forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}",
md.mdId().mdName(), ma.maId().maName(), e);
@@ -130,25 +124,38 @@
* @param mep The MEPEntry to print
* @return A string with MepEntry details
*/
- public static String printMepEntry(MepEntry mep) {
+ private static String printMepEntry(MepEntry mep) {
StringBuffer sb = new StringBuffer("MEP: ");
sb.append(mep.mepId());
- sb.append(" Device:" + mep.deviceId());
- sb.append(", Port: " + mep.port());
- sb.append(", Vlan: " + mep.primaryVid());
- sb.append(", AdminSt: " + mep.administrativeState());
- sb.append(", CciEnabled: " + mep.cciEnabled());
- sb.append(", Priority: " + mep.ccmLtmPriority());
+ sb.append(" Device:");
+ sb.append(mep.deviceId());
+ sb.append(", Port: ");
+ sb.append(mep.port());
+ sb.append(", Vlan: ");
+ sb.append(mep.primaryVid());
+ sb.append(", AdminSt: ");
+ sb.append(mep.administrativeState());
+ sb.append(", CciEnabled: ");
+ sb.append(mep.cciEnabled());
+ sb.append(", Priority: ");
+ sb.append(mep.ccmLtmPriority());
sb.append("\n"); //The following are state
- sb.append(", Total CCMs: " + mep.totalCcmsTransmitted());
- sb.append(", MAC: " + mep.macAddress());
- sb.append(", Fault: " + mep.fngState());
+ sb.append(", Total CCMs: ");
+ sb.append(mep.totalCcmsTransmitted());
+ sb.append(", MAC: ");
+ sb.append(mep.macAddress());
+ sb.append(", Fault: ");
+ sb.append(mep.fngState());
mep.activeRemoteMepList().forEach(rmep -> {
- sb.append("\n\tRmep: " + rmep.remoteMepId());
- sb.append(", Mac: " + rmep.macAddress());
- sb.append(", State: " + rmep.state());
- sb.append(", Failed Time: " + rmep.failedOrOkTime());
+ sb.append("\n\tRmep: ");
+ sb.append(rmep.remoteMepId());
+ sb.append(", Mac: ");
+ sb.append(rmep.macAddress());
+ sb.append(", State: ");
+ sb.append(rmep.state());
+ sb.append(", Failed Time: ");
+ sb.append(rmep.failedOrOkTime());
});
@@ -156,18 +163,12 @@
return sb.toString();
}
- public static String printMdId(MdId mdId) {
- StringBuffer sb = new StringBuffer("MD: ");
- sb.append(mdId.mdName());
- sb.append("(" + mdId.nameType() + ")");
- return sb.toString();
+ private static String printMdId(MdId mdId) {
+ return "MD: " + mdId.mdName() + "(" + mdId.nameType() + ")";
}
- public static String printMaId(MaIdShort maId) {
- StringBuffer sb = new StringBuffer("MA: ");
- sb.append(maId.maName());
- sb.append("(" + maId.nameType() + ")");
- return sb.toString();
+ private static String printMaId(MaIdShort maId) {
+ return "MA: " + maId.maName() + "(" + maId.nameType() + ")";
}
}
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListDeviceCommand.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListDeviceCommand.java
index c99399a..5067cc1 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListDeviceCommand.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/CfmMepListDeviceCommand.java
@@ -22,9 +22,6 @@
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
import org.onosproject.net.DeviceId;
-import org.slf4j.Logger;
-
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Lists all the MEPs on a particular device.
@@ -32,11 +29,10 @@
@Command(scope = "onos", name = "cfm-mep-device-list",
description = "Lists a set of MEPs filtered by device.")
public class CfmMepListDeviceCommand extends AbstractShellCommand {
- private final Logger log = getLogger(getClass());
- @Argument(index = 0, name = "device",
+ @Argument(name = "device",
description = "Device Id",
- required = true, multiValued = false)
- String deviceStr = null;
+ required = true)
+ private String deviceStr = null;
@Override
protected void execute() {
@@ -44,9 +40,8 @@
if (deviceStr != null) {
DeviceId deviceId = DeviceId.deviceId(deviceStr);
try {
- mepService.getAllMepsByDevice(deviceId).forEach(mep -> {
- print(printMep(mep));
- });
+ mepService.getAllMepsByDevice(deviceId)
+ .forEach(mep -> print(printMep(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for Device {}",
deviceId, e);
@@ -59,19 +54,12 @@
* @param mep The MEP to print
* @return A string with MD name, MA name and Mep details
*/
- public static String printMep(Mep mep) {
- StringBuffer sb = new StringBuffer("MEP: ");
- sb.append(mep.mdId().mdName() + "/");
- sb.append(mep.maId().maName() + "/");
- sb.append(mep.mepId());
- sb.append(" Device:" + mep.deviceId());
- sb.append(", Port: " + mep.port());
- sb.append(", Vlan: " + mep.primaryVid());
- sb.append(", AdminSt: " + mep.administrativeState());
- sb.append(", CciEnabled: " + mep.cciEnabled());
- sb.append(", Priority: " + mep.ccmLtmPriority());
-
- return sb.toString();
+ private static String printMep(Mep mep) {
+ return "MEP: " + mep.mdId().mdName() + "/" + mep.maId().maName() + "/" +
+ mep.mepId() + " Device:" + mep.deviceId() + ", Port: " +
+ mep.port() + ", Vlan: " + mep.primaryVid() + ", AdminSt: " +
+ mep.administrativeState() + ", CciEnabled: " + mep.cciEnabled() +
+ ", Priority: " + mep.ccmLtmPriority();
}
}
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMaNameCompleter.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMaNameCompleter.java
index b484212..1463804 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMaNameCompleter.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMaNameCompleter.java
@@ -34,16 +34,8 @@
CfmMdService service = get(CfmMdService.class);
service.getAllMaintenanceDomain().forEach(md ->
md.maintenanceAssociationList().forEach(ma ->
- choices.add(new StringBuilder(md.mdId().mdName())
- .append("(")
- .append(md.mdId().nameType())
- .append(")")
- .append(ma.maId().maName())
- .append("(")
- .append(ma.maId().nameType())
- .append(")").toString())
- )
- );
+ choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + ")" +
+ ma.maId().maName() + "(" + ma.maId().nameType() + ")")));
return choices;
}
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMepIdCompleter.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMepIdCompleter.java
index 6019916..a26a460 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMepIdCompleter.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/cli/completer/CfmMepIdCompleter.java
@@ -41,32 +41,17 @@
CfmMepService mepService = get(CfmMepService.class);
mdService.getAllMaintenanceDomain().forEach(md -> {
- choices.add(new StringBuilder(md.mdId().mdName())
- .append("(")
- .append(md.mdId().nameType())
- .append(")").toString());
+ choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + ")");
md.maintenanceAssociationList().forEach(ma -> {
- choices.add(new StringBuilder(md.mdId().mdName())
- .append("(")
- .append(md.mdId().nameType())
- .append(") ")
- .append(ma.maId().maName())
- .append("(")
- .append(ma.maId().nameType())
- .append(")").toString());
+ choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() +
+ ") " + ma.maId().maName() + "(" + ma.maId().nameType() + ")");
try {
mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep ->
- choices.add(new StringBuilder(md.mdId().mdName())
- .append("(")
- .append(md.mdId().nameType())
- .append(") ")
- .append(ma.maId().maName())
- .append("(")
- .append(ma.maId().nameType())
- .append(") ")
- .append(mep.mepId()).toString())
+ choices.add(md.mdId().mdName() + "(" +
+ md.mdId().nameType() + ") " + ma.maId().maName() +
+ "(" + ma.maId().nameType() + ") " + mep.mepId())
);
} catch (CfmConfigException e) {
log.warn("Unable to retrieve mep details", e);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MaWebResource.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
index 85b7ac4..e0390a9 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
@@ -17,6 +17,7 @@
import java.io.InputStream;
import java.net.URI;
+import java.util.Optional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -134,9 +135,9 @@
log.debug("POST called to Create MA");
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
- MaintenanceDomain md = get(CfmMdService.class)
- .getMaintenanceDomain(mdId).get();
- if (md == null) {
+ Optional<MaintenanceDomain> md = get(CfmMdService.class)
+ .getMaintenanceDomain(mdId);
+ if (!md.isPresent()) {
return Response.serverError().entity("{ \"failure\":\"md "
+ mdName + " does not exist\" }").build();
}
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MdWebResource.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
index 0e523a7..aa16d9e 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
@@ -49,7 +49,6 @@
@Path("md")
public class MdWebResource extends AbstractWebResource {
private final Logger log = LoggerFactory.getLogger(getClass());
- public static final String JSON_NOT_NULL = "JsonNode can not be null";
/**
* Get all Maintenance Domains.
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MepWebResource.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
index 52d4150..a9d2c9e 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
@@ -180,7 +180,10 @@
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
- MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).get();
+ MaintenanceAssociation ma =
+ get(CfmMdService.class).getMaintenanceAssociation(mdId, maId)
+ .orElseThrow(() -> new IllegalArgumentException(
+ "MA " + mdName + "/" + maName + " not Found"));
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = mapper.readTree(input);
@@ -194,12 +197,14 @@
" already exists").build();
}
return Response
- .created(new URI("md/" + mdName + "/ma/" + ma.maId() + "/mep/" + mep.mepId()))
- .entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() + "/" + mep.mepId() + " created\" }")
+ .created(new URI("md/" + mdName + "/ma/" + ma.maId() +
+ "/mep/" + mep.mepId()))
+ .entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() +
+ "/" + mep.mepId() + " created\" }")
.build();
} catch (Exception | CfmConfigException e) {
log.error("Create Mep on " + mdName + "/" + maName + " failed because of exception {}",
- e.toString());
+ e);
return Response.serverError()
.entity("{ \"failure\":\"" + e.toString() + "\" }")
.build();
@@ -229,9 +234,25 @@
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
- MaintenanceDomain md = get(CfmMdService.class).getMaintenanceDomain(mdId).get();
- MaintenanceAssociation ma = get(CfmMdService.class)
- .getMaintenanceAssociation(mdId, maId).get();
+ MaintenanceDomain md;
+ Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
+ if (mdOpt.isPresent()) {
+ md = mdOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + mdName + " does not exist\" }")
+ .build();
+ }
+ MaintenanceAssociation ma;
+ Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class)
+ .getMaintenanceAssociation(mdId, maId);
+ if (maOpt.isPresent()) {
+ ma = maOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + maName + " does not exist\" }")
+ .build();
+ }
MepId mepId = MepId.valueOf(mepIdShort);
@@ -275,9 +296,25 @@
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
- MaintenanceDomain md = get(CfmMdService.class).getMaintenanceDomain(mdId).get();
- MaintenanceAssociation ma = get(CfmMdService.class)
- .getMaintenanceAssociation(mdId, maId).get();
+ MaintenanceDomain md;
+ Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
+ if (mdOpt.isPresent()) {
+ md = mdOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + mdName + " does not exist\" }")
+ .build();
+ }
+ MaintenanceAssociation ma;
+ Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class)
+ .getMaintenanceAssociation(mdId, maId);
+ if (maOpt.isPresent()) {
+ ma = maOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + maName + " does not exist\" }")
+ .build();
+ }
MepId mepId = MepId.valueOf(mepIdShort);
@@ -319,9 +356,25 @@
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
- MaintenanceDomain md = get(CfmMdService.class).getMaintenanceDomain(mdId).get();
- MaintenanceAssociation ma = get(CfmMdService.class)
- .getMaintenanceAssociation(mdId, maId).get();
+ MaintenanceDomain md;
+ Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
+ if (mdOpt.isPresent()) {
+ md = mdOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + mdName + " does not exist\" }")
+ .build();
+ }
+ MaintenanceAssociation ma;
+ Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class)
+ .getMaintenanceAssociation(mdId, maId);
+ if (maOpt.isPresent()) {
+ ma = maOpt.get();
+ } else {
+ return Response.serverError()
+ .entity("{ \"failure\":\"" + maName + " does not exist\" }")
+ .build();
+ }
MepId mepId = MepId.valueOf(mepIdShort);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/ComponentCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/ComponentCodec.java
index 6a53497..ee83dea 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/ComponentCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/ComponentCodec.java
@@ -42,6 +42,15 @@
private static final String MHF_CREATION_TYPE = "mhf-creation-type";
private static final String ID_PERMISSION = "id-permission";
+ /**
+ * Encodes the Component entity into JSON.
+ *
+ * @param component Component to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(Component component, CodecContext context) {
@@ -63,15 +72,31 @@
return (ObjectNode) context.mapper().createObjectNode().set(COMPONENT, node);
}
+ /**
+ * Encodes the collection of the Component entities.
+ *
+ * @param components collection of Component to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<Component> components, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
- components.forEach(component -> {
- an.add(encode(component, context));
- });
+ components.forEach(component -> an.add(encode(component, context)));
return an;
}
+ /**
+ * Decodes the Component entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded Component
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public Component decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -87,7 +112,7 @@
List<VlanId> vidList = (new VidCodec()).decode((ArrayNode)
nullIsIllegal(componentNode.get(VID_LIST), "vid-list is required"), context);
- if (vidList == null || vidList.size() < 1) {
+ if (vidList == null || vidList.isEmpty()) {
throw new IllegalArgumentException("A least one VID is required in component: " + componentId);
}
for (VlanId vid:vidList) {
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/FngAddressCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/FngAddressCodec.java
index 47cc9b6..1c0e725 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/FngAddressCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/FngAddressCodec.java
@@ -25,6 +25,8 @@
import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
import org.onosproject.incubator.net.l2monitoring.cfm.Mep.FngAddress;
+import java.util.Locale;
+
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
@@ -33,6 +35,15 @@
*/
public class FngAddressCodec extends JsonCodec<FngAddress> {
+ /**
+ * Encodes the FngAddress entity into JSON.
+ *
+ * @param fngAddress FngAddress to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(FngAddress fngAddress, CodecContext context) {
checkNotNull(fngAddress, "FngAddress cannot be null");
@@ -47,6 +58,15 @@
return result;
}
+ /**
+ * Decodes the FngAddress entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded FngAddress
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public FngAddress decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -57,7 +77,7 @@
String addressType = nullIsIllegal(node.get("address-type"),
"address type is required").asText();
- Mep.FngAddressType type = Mep.FngAddressType.valueOf(addressType.toUpperCase());
+ Mep.FngAddressType type = Mep.FngAddressType.valueOf(addressType.toUpperCase(Locale.ENGLISH));
JsonNode ipAddressNode = node.get("ipAddress");
switch (type) {
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceAssociationCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceAssociationCodec.java
index 6c3829f..b1b9baa 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceAssociationCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceAssociationCodec.java
@@ -27,12 +27,8 @@
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.CcmInterval;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation.MaBuilder;
-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.MdMaNameUtil;
import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
@@ -53,6 +49,15 @@
private static final String RMEP_LIST = "rmep-list";
private static final String MA = "ma";
+ /**
+ * Encodes the MaintenanceAssociation entity into JSON.
+ *
+ * @param ma MaintenanceAssociation to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MaintenanceAssociation ma, CodecContext context) {
checkNotNull(ma, "Maintenance Association cannot be null");
@@ -72,6 +77,16 @@
return result;
}
+ /**
+ * Decodes the MaintenanceAssociation entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @param mdNameLen the length of the corresponding MD's name
+ * @return decoded MaintenanceAssociation
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
public MaintenanceAssociation decode(ObjectNode json, CodecContext context, int mdNameLen) {
if (json == null || !json.isObject()) {
return null;
@@ -86,25 +101,7 @@
}
try {
- MaIdShort maId = null;
- MaIdShort.MaIdType maIdType = MaIdShort.MaIdType.valueOf(maNameType);
- switch (maIdType) {
- case PRIMARYVID:
- maId = MaIdPrimaryVid.asMaId(maName);
- break;
- case TWOOCTET:
- maId = MaId2Octet.asMaId(maName);
- break;
- case RFC2685VPNID:
- maId = MaIdRfc2685VpnId.asMaIdHex(maName);
- break;
- case ICCY1731:
- maId = MaIdIccY1731.asMaId(maName);
- break;
- case CHARACTERSTRING:
- default:
- maId = MaIdCharStr.asMaId(maName);
- }
+ MaIdShort maId = MdMaNameUtil.parseMaName(maNameType, maName);
MaBuilder builder =
DefaultMaintenanceAssociation.builder(maId, mdNameLen);
@@ -140,6 +137,15 @@
}
+ /**
+ * Encodes the collection of the MaintenanceAssociation entities.
+ *
+ * @param maEntities collection of MaintenanceAssociation to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<MaintenanceAssociation> maEntities, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceDomainCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceDomainCodec.java
index a6bcf01..89b7cc1 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceDomainCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MaintenanceDomainCodec.java
@@ -24,10 +24,7 @@
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain.MdLevel;
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.MdMaNameUtil;
import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -50,6 +47,15 @@
}
+ /**
+ * Encodes the MaintenanceDomain entity into JSON.
+ *
+ * @param md MaintenanceDomain to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MaintenanceDomain md, CodecContext context) {
checkNotNull(md, "Maintenance Domain cannot be null");
@@ -67,6 +73,15 @@
return result;
}
+ /**
+ * Decodes the MaintenanceDomain entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded MaintenanceDomain
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public MaintenanceDomain decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -82,24 +97,7 @@
}
try {
- MdId mdId = null;
- MdId.MdNameType nameType =
- MdId.MdNameType.valueOf(mdNameType);
- switch (nameType) {
- case DOMAINNAME:
- mdId = MdIdDomainName.asMdId(mdName);
- break;
- case MACANDUINT:
- mdId = MdIdMacUint.asMdId(mdName);
- break;
- case NONE:
- mdId = MdIdNone.asMdId();
- break;
- case CHARACTERSTRING:
- default:
- mdId = MdIdCharStr.asMdId(mdName);
- }
-
+ MdId mdId = MdMaNameUtil.parseMdName(mdNameType, mdName);
MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain.builder(mdId);
JsonNode mdLevelNode = mdNode.get(MD_LEVEL);
if (mdLevelNode != null) {
@@ -118,6 +116,15 @@
}
}
+ /**
+ * Encodes the collection of the MaintenanceDomain entities.
+ *
+ * @param mdEntities collection of MaintenanceDomain to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<MaintenanceDomain> mdEntities, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepCodec.java
index 73a58b6..a095da8 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepCodec.java
@@ -53,6 +53,17 @@
private static final String DEFECT_PRESENT_TIME = "defect-present-time";
private static final String DEFECT_ABSENT_TIME = "defect-absent-time";
+ /**
+ * Decodes the Mep entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @param mdName The MD name
+ * @param maName The MA name
+ * @return decoded Mep
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
public Mep decode(ObjectNode json, CodecContext context, String
mdName, String maName) {
if (json == null || !json.isObject()) {
@@ -127,6 +138,15 @@
}
}
+ /**
+ * Encodes the Mep entity into JSON.
+ *
+ * @param mep Mep to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(Mep mep, CodecContext context) {
checkNotNull(mep, "Mep cannot be null");
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepEntryCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepEntryCodec.java
index d1618a7..f1799fb 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepEntryCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepEntryCodec.java
@@ -34,6 +34,15 @@
*/
public class MepEntryCodec extends JsonCodec<MepEntry> {
+ /**
+ * Encodes the MepEntry entity into JSON.
+ *
+ * @param mepEntry MepEntry to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MepEntry mepEntry, CodecContext context) {
checkNotNull(mepEntry, "Mep cannot be null");
@@ -41,7 +50,7 @@
ObjectNode result = context.mapper().createObjectNode();
//Get the common attributes
- Mep mep = (Mep) mepEntry;
+ Mep mep = mepEntry;
ObjectNode mepAttrs = new MepCodec().encode(mep, context);
Iterator<Entry<String, JsonNode>> elements = mepAttrs.fields();
while (elements.hasNext()) {
@@ -81,6 +90,15 @@
return result;
}
+ /**
+ * Encodes the collection of the MepEntry entities.
+ *
+ * @param mepEntryEntities collection of MepEntry to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<MepEntry> mepEntryEntities, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbCreateCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbCreateCodec.java
index e29415c..8b80237 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbCreateCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbCreateCodec.java
@@ -42,6 +42,15 @@
public static final String VLAN_PRIORITY = "vlanPriority";
public static final String LOOPBACK = "loopback";
+ /**
+ * Encodes the MepLbCreate entity into JSON.
+ *
+ * @param mepLbCreate MepLbCreate to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MepLbCreate mepLbCreate, CodecContext context) {
checkNotNull(mepLbCreate, "Mep Lb Create cannot be null");
@@ -66,7 +75,15 @@
return result;
}
-
+ /**
+ * Decodes the MepLbCreate entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded MepLbCreate
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public MepLbCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -78,7 +95,7 @@
JsonNode remoteMepIdNode = loopbackNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = loopbackNode.get(REMOTE_MEP_MAC);
- MepLbCreate.MepLbCreateBuilder lbCreateBuilder = null;
+ MepLbCreate.MepLbCreateBuilder lbCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepId);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbEntryCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbEntryCodec.java
index 62409cd..8ff8e23 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbEntryCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLbEntryCodec.java
@@ -28,6 +28,15 @@
*/
public class MepLbEntryCodec extends JsonCodec<MepLbEntry> {
+ /**
+ * Encodes the MepLbEntry entity into JSON.
+ *
+ * @param mepLbEntry MepLbEntry to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MepLbEntry mepLbEntry, CodecContext context) {
checkNotNull(mepLbEntry, "Mep Lb Entry cannot be null");
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLtCreateCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLtCreateCodec.java
index 0141a73..ba7aabe 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLtCreateCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/MepLtCreateCodec.java
@@ -40,6 +40,15 @@
private static final String LINKTRACE = "linktrace";
private static final String USE_FDB_ONLY = "use-fdb-only";
+ /**
+ * Encodes the MepLtCreate entity into JSON.
+ *
+ * @param mepLtCreate MepLtCreate to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MepLtCreate mepLtCreate, CodecContext context) {
checkNotNull(mepLtCreate, "Mep Lt Create cannot be null");
@@ -62,7 +71,15 @@
return result;
}
-
+ /**
+ * Decodes the MepLtCreate entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded MepLtCreate
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public MepLtCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -74,7 +91,7 @@
JsonNode remoteMepIdNode = linktraceNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = linktraceNode.get(REMOTE_MEP_MAC);
- MepLtCreate.MepLtCreateBuilder ltCreateBuilder = null;
+ MepLtCreate.MepLtCreateBuilder ltCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepId);
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RMepCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RMepCodec.java
index ff4f775..6f4fc53 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RMepCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RMepCodec.java
@@ -33,20 +33,45 @@
*/
public class RMepCodec extends JsonCodec<MepId> {
+ /**
+ * Encodes the MepId entity into JSON.
+ *
+ * @param rmep MepId to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(MepId rmep, CodecContext context) {
return context.mapper().createObjectNode().put("rmep", rmep.id());
}
+ /**
+ * Encodes the collection of the MepId entities.
+ *
+ * @param rmeps collection of MepId to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<MepId> rmeps, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
- rmeps.forEach(rmep -> {
- an.add(encode(rmep, context));
- });
+ rmeps.forEach(rmep -> an.add(encode(rmep, context)));
return an;
}
+ /**
+ * Decodes the MepId entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded MepId
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public MepId decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -60,6 +85,15 @@
}
+ /**
+ * Decodes the MepId JSON array into a collection of entities.
+ *
+ * @param json JSON array to decode
+ * @param context decoding context
+ * @return collection of decoded MepId
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public List<MepId> decode(ArrayNode json, CodecContext context) {
List<MepId> rmepList = new ArrayList<>();
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RemoteMepEntryCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RemoteMepEntryCodec.java
index 4f8344a..329cc72 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RemoteMepEntryCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/RemoteMepEntryCodec.java
@@ -29,6 +29,15 @@
*/
public class RemoteMepEntryCodec extends JsonCodec<RemoteMepEntry> {
+ /**
+ * Encodes the RemoteMepEntry entity into JSON.
+ *
+ * @param remoteMepEntry RemoteMepEntry to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(RemoteMepEntry remoteMepEntry, CodecContext context) {
checkNotNull(remoteMepEntry, "Mep cannot be null");
@@ -62,6 +71,15 @@
return result;
}
+ /**
+ * Encodes the collection of the RemoteMepEntry entities.
+ *
+ * @param remoteMepEntries collection of RemoteMepEntry to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<RemoteMepEntry> remoteMepEntries,
CodecContext context) {
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/VidCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/VidCodec.java
index a673719..cf97f01 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/VidCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/cfm/web/VidCodec.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.cfm.web;
+import static org.onlab.packet.VlanId.MAX_VLAN;
import static org.onlab.util.Tools.nullIsIllegal;
import java.util.ArrayList;
@@ -33,20 +34,45 @@
*/
public class VidCodec extends JsonCodec<VlanId> {
+ /**
+ * Encodes the VlanId entity into JSON.
+ *
+ * @param vid VlanId to encode
+ * @param context encoding context
+ * @return JSON node
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ObjectNode encode(VlanId vid, CodecContext context) {
return context.mapper().createObjectNode().put("vid", vid.toString());
}
+ /**
+ * Encodes the collection of the VlanId entities.
+ *
+ * @param vids collection of VlanId to encode
+ * @param context encoding context
+ * @return JSON array
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support encode operations
+ */
@Override
public ArrayNode encode(Iterable<VlanId> vids, CodecContext context) {
ArrayNode an = context.mapper().createArrayNode();
- vids.forEach(vid -> {
- an.add(encode(vid, context));
- });
+ vids.forEach(vid -> an.add(encode(vid, context)));
return an;
}
+ /**
+ * Decodes the VlanId entity from JSON.
+ *
+ * @param json JSON to decode
+ * @param context decoding context
+ * @return decoded VlanId
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public VlanId decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
@@ -56,12 +82,21 @@
JsonNode vidNode = json.get("vid");
int vid = (nullIsIllegal(vidNode.asInt(), "vid is required"));
- if (vid < 0 || vid > 4095) {
+ if (vid < 0 || vid > MAX_VLAN) {
throw new IllegalArgumentException("VID values must be between 0 and 4095");
}
return VlanId.vlanId((short) vid);
}
+ /**
+ * Decodes the VlanId JSON array into a collection of entities.
+ *
+ * @param json JSON array to decode
+ * @param context decoding context
+ * @return collection of decoded VlanId
+ * @throws java.lang.UnsupportedOperationException if the codec does not
+ * support decode operations
+ */
@Override
public List<VlanId> decode(ArrayNode json, CodecContext context) {
List<VlanId> vidList = new ArrayList<>();
diff --git a/apps/cfm/nbi/src/main/java/org/onosproject/soam/web/LossMeasurementThresholdCodec.java b/apps/cfm/nbi/src/main/java/org/onosproject/soam/web/LossMeasurementThresholdCodec.java
index 3a17f94..da87a82 100644
--- a/apps/cfm/nbi/src/main/java/org/onosproject/soam/web/LossMeasurementThresholdCodec.java
+++ b/apps/cfm/nbi/src/main/java/org/onosproject/soam/web/LossMeasurementThresholdCodec.java
@@ -29,6 +29,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
+
import static org.onosproject.incubator.net.l2monitoring.soam.loss.DefaultLmThreshold.*;
/**
@@ -131,7 +132,7 @@
LossMeasurementThreshold.LmThresholdBuilder builder = builder(thresholdId);
if (thrNode.get("thresholds") != null) {
- context.codec(ThresholdOption.class)
+ context.codec(LossMeasurementThreshold.ThresholdOption.class)
.decode((ArrayNode) (thrNode.get("thresholds")), context)
.forEach(builder::addToThreshold);
}