Safer get operations for the server driver
Also:
* REST attributes according to Contansts
* Additional action per rule
* Alphabetical order of static variables
Change-Id: I887ad2fe828ded217b707e9f914e1624232c4979
Signed-off-by: Georgios Katsikas <katsikas.gp@gmail.com>
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java b/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
index dbfe36b..1019c55 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/FlowRuleProgrammableServerImpl.java
@@ -52,8 +52,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.server.Constants.JSON;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
-import static org.onosproject.drivers.server.Constants.PARAM_ID;
import static org.onosproject.drivers.server.Constants.PARAM_CPUS;
+import static org.onosproject.drivers.server.Constants.PARAM_ID;
+import static org.onosproject.drivers.server.Constants.PARAM_NAME;
import static org.onosproject.drivers.server.Constants.PARAM_NICS;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_RX_FILTER;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_RX_FILTER_FD;
@@ -362,8 +363,8 @@
// Each rule has an ID and a content
ObjectNode ruleNode = mapper.createObjectNode();
- ruleNode.put("ruleId", nicRule.id().value());
- ruleNode.put("ruleContent", nicRule.ruleBody());
+ ruleNode.put(PARAM_ID, nicRule.id().value());
+ ruleNode.put(PARAM_RULE_CONTENT, nicRule.ruleBody());
ruleArrayNode.add(ruleNode);
}
@@ -374,7 +375,7 @@
}
ObjectNode nicObjNode = mapper.createObjectNode();
- nicObjNode.put("nicName", nic);
+ nicObjNode.put(PARAM_NAME, nic);
ArrayNode cpusArrayNode = nicObjNode.putArray(PARAM_CPUS);
@@ -384,7 +385,7 @@
ArrayNode ruleArrayNode = entry.getValue();
ObjectNode cpuObjNode = mapper.createObjectNode();
- cpuObjNode.put("cpuId", coreIndex);
+ cpuObjNode.put(PARAM_ID, coreIndex);
cpuObjNode.putArray(PARAM_RULES).addAll(ruleArrayNode);
cpusArrayNode.add(cpuObjNode);
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerBasicSystemOperations.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerBasicSystemOperations.java
index eb4536f..124de16 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerBasicSystemOperations.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerBasicSystemOperations.java
@@ -37,8 +37,8 @@
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.onosproject.drivers.server.Constants.JSON;
import static org.onosproject.drivers.server.Constants.MSG_HANDLER_NULL;
-import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
+import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.PARAM_TIME;
import static org.onosproject.drivers.server.Constants.URL_SRV_TIME_DISCOVERY;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java
index 346c8ca..ae3ed65 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerDevicesDiscovery.java
@@ -97,24 +97,9 @@
import static org.onosproject.drivers.server.Constants.MSG_NIC_NAME_NULL;
import static org.onosproject.drivers.server.Constants.MSG_NIC_PORT_NUMBER_NEGATIVE;
import static org.onosproject.drivers.server.Constants.MSG_STATS_TIMING_DEPLOY_INCONSISTENT;
-import static org.onosproject.drivers.server.Constants.PARAM_ID;
import static org.onosproject.drivers.server.Constants.PARAM_CAPACITY;
import static org.onosproject.drivers.server.Constants.PARAM_CHASSIS_ID;
import static org.onosproject.drivers.server.Constants.PARAM_CPUS;
-import static org.onosproject.drivers.server.Constants.PARAM_NICS;
-import static org.onosproject.drivers.server.Constants.PARAM_NAME;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_HIERARCHY;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_MODULES;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_FREE;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_TOTAL;
-import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_USED;
-import static org.onosproject.drivers.server.Constants.PARAM_MANUFACTURER;
-import static org.onosproject.drivers.server.Constants.PARAM_HW_VENDOR;
-import static org.onosproject.drivers.server.Constants.PARAM_SW_VENDOR;
-import static org.onosproject.drivers.server.Constants.PARAM_SERIAL;
-import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS;
-import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS_AUTOSCALE;
import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LEVEL;
import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LEVELS;
import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LINE_LEN;
@@ -137,8 +122,19 @@
import static org.onosproject.drivers.server.Constants.PARAM_CPU_STATUS;
import static org.onosproject.drivers.server.Constants.PARAM_CPU_THROUGHPUT;
import static org.onosproject.drivers.server.Constants.PARAM_CPU_VENDOR;
+import static org.onosproject.drivers.server.Constants.PARAM_HW_VENDOR;
+import static org.onosproject.drivers.server.Constants.PARAM_ID;
+import static org.onosproject.drivers.server.Constants.PARAM_MANUFACTURER;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_HIERARCHY;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_MODULES;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_FREE;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_TOTAL;
+import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_USED;
import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_WIDTH_DATA;
import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_WIDTH_TOTAL;
+import static org.onosproject.drivers.server.Constants.PARAM_NAME;
+import static org.onosproject.drivers.server.Constants.PARAM_NICS;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_HW_ADDR;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_PORT_TYPE;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_RX_FILTER;
@@ -156,18 +152,22 @@
import static org.onosproject.drivers.server.Constants.PARAM_MON_MAX;
import static org.onosproject.drivers.server.Constants.PARAM_MON_MIN;
import static org.onosproject.drivers.server.Constants.PARAM_MON_UNIT;
+import static org.onosproject.drivers.server.Constants.PARAM_SERIAL;
import static org.onosproject.drivers.server.Constants.PARAM_SPEED;
import static org.onosproject.drivers.server.Constants.PARAM_SPEED_CONF;
import static org.onosproject.drivers.server.Constants.PARAM_STATUS;
-import static org.onosproject.drivers.server.Constants.PARAM_TIMING_PARSE;
-import static org.onosproject.drivers.server.Constants.PARAM_TIMING_LAUNCH;
-import static org.onosproject.drivers.server.Constants.PARAM_TIMING_DEPLOY;
+import static org.onosproject.drivers.server.Constants.PARAM_SW_VENDOR;
import static org.onosproject.drivers.server.Constants.PARAM_TIMING_AUTOSCALE;
+import static org.onosproject.drivers.server.Constants.PARAM_TIMING_DEPLOY;
+import static org.onosproject.drivers.server.Constants.PARAM_TIMING_LAUNCH;
+import static org.onosproject.drivers.server.Constants.PARAM_TIMING_PARSE;
+import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS;
+import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS_AUTOSCALE;
import static org.onosproject.drivers.server.Constants.PARAM_TYPE;
import static org.onosproject.drivers.server.Constants.SLASH;
+import static org.onosproject.drivers.server.Constants.URL_SERVICE_CHAINS_STATS;
import static org.onosproject.drivers.server.Constants.URL_SRV_GLOBAL_STATS;
import static org.onosproject.drivers.server.Constants.URL_SRV_RESOURCE_DISCOVERY;
-import static org.onosproject.drivers.server.Constants.URL_SERVICE_CHAINS_STATS;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -891,6 +891,9 @@
Collection<CpuStatistics> cpuStats = Lists.newArrayList();
JsonNode cpuNode = objNode.path(PARAM_CPUS);
+ if (cpuNode.isMissingNode()) {
+ return cpuStats;
+ }
for (JsonNode cn : cpuNode) {
ObjectNode cpuObjNode = (ObjectNode) cn;
@@ -972,6 +975,9 @@
}
JsonNode memoryNode = objNode.path(PARAM_MEMORY);
+ if (memoryNode.isMissingNode()) {
+ return getZeroMemoryStatistics(deviceId);
+ }
ObjectNode memoryObjNode = (ObjectNode) memoryNode;
// Fetch memory statistics
@@ -1016,6 +1022,9 @@
Collection<PortStatistics> nicStats = Lists.newArrayList();
JsonNode nicNode = objNode.path(PARAM_NICS);
+ if (nicNode.isMissingNode()) {
+ return nicStats;
+ }
for (JsonNode nn : nicNode) {
ObjectNode nicObjNode = (ObjectNode) nn;
@@ -1070,18 +1079,17 @@
return timinsgStats;
}
- // If no timing statistics are present, then send zeros
- if (objNode.get(PARAM_TIMING_STATS) == null) {
+ // Get timing statistics
+ JsonNode timingNode = objNode.path(PARAM_TIMING_STATS);
+ if (timingNode.isMissingNode()) {
+ // If no timing statistics are present, then send zeros
return getZeroTimingStatistics();
}
+ ObjectNode timingObjNode = (ObjectNode) timingNode;
DefaultTimingStatistics.Builder timingBuilder =
DefaultTimingStatistics.builder();
- // Get timing statistics
- JsonNode timingNode = objNode.path(PARAM_TIMING_STATS);
- ObjectNode timingObjNode = (ObjectNode) timingNode;
-
// The unit of timing statistics
String timingStatsUnit = get(timingNode, PARAM_MON_UNIT);
if (!Strings.isNullOrEmpty(timingStatsUnit)) {
@@ -1127,6 +1135,23 @@
}
/**
+ * Return a memory statistics object with zero counters.
+ * This is useful when constructing MonitoringStatistics
+ * objects that do not require memory statistics.
+ *
+ * @param deviceId a device ID
+ * @return MemoryStatistics object
+ */
+ private MemoryStatistics getZeroMemoryStatistics(DeviceId deviceId) {
+ return DefaultMemoryStatistics.builder()
+ .setDeviceId(deviceId)
+ .setMemoryUsed(0)
+ .setMemoryFree(0)
+ .setMemoryTotal(0)
+ .build();
+ }
+
+ /**
* Return a timing statistics object with zero counters.
* This is useful when constructing MonitoringStatistics
* objects that do not require timers.
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerHandshaker.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerHandshaker.java
index b141533..f57e589 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerHandshaker.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerHandshaker.java
@@ -40,8 +40,8 @@
import static org.onosproject.drivers.server.Constants.JSON;
import static org.onosproject.drivers.server.Constants.PARAM_CONNECTION_STATUS;
import static org.onosproject.drivers.server.Constants.MSG_HANDLER_NULL;
-import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
+import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.URL_SRV_PROBE_CONNECT;
import static org.onosproject.drivers.server.Constants.URL_SRV_PROBE_DISCONNECT;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerInterfaceConfig.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerInterfaceConfig.java
index b7fd93f..820a657 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerInterfaceConfig.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerInterfaceConfig.java
@@ -38,8 +38,8 @@
import java.util.TreeSet;
import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
+import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.net.device.DeviceInterfaceDescription.Mode;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerQueueConfig.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerQueueConfig.java
index f50a169..f040a6e 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerQueueConfig.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerQueueConfig.java
@@ -48,8 +48,8 @@
import static org.onosproject.drivers.server.Constants.PARAM_NIC_MAX_RATE;
import static org.onosproject.drivers.server.Constants.PARAM_QUEUES;
import static org.onosproject.drivers.server.Constants.PARAM_TYPE;
-import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
+import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.URL_NIC_QUEUE_ADMIN;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerTableStatisticsDiscovery.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerTableStatisticsDiscovery.java
index f106d83..9aa65d9 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerTableStatisticsDiscovery.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerTableStatisticsDiscovery.java
@@ -41,18 +41,18 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.server.Constants.JSON;
-import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL;
-import static org.onosproject.drivers.server.Constants.MSG_NIC_TABLE_SIZE_NEGATIVE;
-import static org.onosproject.drivers.server.Constants.MSG_NIC_TABLE_INDEX_NEGATIVE;
+import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL;
import static org.onosproject.drivers.server.Constants.MSG_NIC_TABLE_COUNTER_NEGATIVE;
+import static org.onosproject.drivers.server.Constants.MSG_NIC_TABLE_INDEX_NEGATIVE;
+import static org.onosproject.drivers.server.Constants.MSG_NIC_TABLE_SIZE_NEGATIVE;
import static org.onosproject.drivers.server.Constants.PARAM_ID;
import static org.onosproject.drivers.server.Constants.PARAM_NICS;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE_ACTIVE_ENTRIES;
+import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE_MAX_SIZE;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE_PKTS_LOOKED_UP;
import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE_PKTS_MATCHED;
-import static org.onosproject.drivers.server.Constants.PARAM_NIC_TABLE_MAX_SIZE;
import static org.onosproject.drivers.server.Constants.URL_RULE_TABLE_STATS;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
index 0f2b2b9..b056916 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/devices/nic/DefaultNicFlowRule.java
@@ -170,7 +170,7 @@
}
// This action provides basic rule match counters
- // this.actions.add(new NicRuleAction(NicRuleAction.Action.COUNT));
+ this.actions.add(new NicRuleAction(NicRuleAction.Action.COUNT));
}
@Override