Additional monitoring stats in server driver

This patch also performs some refactoring to make the
JSON parameters exchanged between the driver and the device
homogeneous (i.e., following the [a-z][A-Z]* pattern).

Code reviewed and minor refactoring.
Avoid exception when timing statistics are not present.
Handle device re-connections.
Server also reports a hardware queue index per core.

Addressed code reviewer's comments.

Change-Id: I6c9d0bbd5884267ee2fdb69bf50809694994c56d
Signed-off-by: Georgios Katsikas <katsikas.gp@gmail.com>
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java
index 9ea22b3..f30134d 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/CpuStatistics.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.drivers.server.stats;
 
+import java.util.Optional;
+
 /**
  * CPU statistics API.
  */
@@ -38,10 +40,63 @@
     float load();
 
     /**
+     * Returns the hardware queue identifier associated with this CPU core.
+     *
+     * @return hardware queue identifier
+     */
+    int queue();
+
+    /**
      * Returns the status (true=busy, false=free) of a CPU core.
      *
      * @return boolean CPU core status
      */
     boolean busy();
 
+    /**
+     * Returns the unit of throughput values.
+     *
+     * @return throughput monitoring unit
+     */
+    Optional<MonitoringUnit> throughputUnit();
+
+    /**
+     * Returns the average throughput of this CPU core,
+     * expressed in throughputUnit() monitoring units.
+     *
+     * @return average throughput of a CPU core
+     */
+    Optional<Float> averageThroughput();
+
+    /**
+     * Returns the unit of latency values.
+     *
+     * @return latency monitoring unit
+     */
+    Optional<MonitoringUnit> latencyUnit();
+
+    /**
+     * Returns the minimum latency incurred by a CPU core,
+     * expressed in latencyUnit() monitoring units.
+     *
+     * @return minimum latency incurred by a CPU core
+     */
+    Optional<Float> minLatency();
+
+    /**
+     * Returns the median latency incurred by a CPU core,
+     * expressed in latencyUnit() monitoring units.
+     *
+     * @return median latency incurred by a CPU core
+     */
+    Optional<Float> medianLatency();
+
+    /**
+     * Returns the maximum latency incurred by a CPU core,
+     * expressed in latencyUnit() monitoring units.
+     *
+     * @return maximum latency incurred by a CPU core
+     */
+    Optional<Float> maxLatency();
+
 }
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringUnit.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringUnit.java
new file mode 100644
index 0000000..0528a69
--- /dev/null
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/MonitoringUnit.java
@@ -0,0 +1,102 @@
+/*
+ * 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.server.stats;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Representation of a monitoring unit.
+ */
+public interface MonitoringUnit {
+
+    /**
+     * Throughput-related monitoring units.
+     */
+    public enum ThroughputUnit implements MonitoringUnit {
+
+        BPS("bps"),
+        KBPS("kbps"),
+        MBPS("mbps"),
+        GBPS("gbps");
+
+        private String throughputUnit;
+
+        // Statically maps throughput monitoring units to enum types
+        private static final Map<String, MonitoringUnit> MAP =
+            new HashMap<String, MonitoringUnit>();
+        static {
+            for (ThroughputUnit tu : ThroughputUnit.values()) {
+                MAP.put(tu.toString().toLowerCase(), (MonitoringUnit) tu);
+            }
+        }
+
+        private ThroughputUnit(String throughputUnit) {
+            this.throughputUnit = throughputUnit;
+        }
+
+        public static MonitoringUnit getByName(String tu) {
+            tu = tu.toLowerCase();
+            return MAP.get(tu);
+        }
+
+        @Override
+        public String toString() {
+            return this.throughputUnit;
+        }
+
+    };
+
+    /**
+     * Latency-related monitoring units.
+     */
+    public enum LatencyUnit implements MonitoringUnit {
+
+        NANO_SECOND("ns"),
+        MICRO_SECOND("us"),
+        MILLI_SECOND("ms"),
+        SECOND("s");
+
+        private String latencyUnit;
+
+        // Statically maps latency monitoring units to enum types
+        private static final Map<String, MonitoringUnit> MAP =
+            new HashMap<String, MonitoringUnit>();
+        static {
+            for (LatencyUnit lu : LatencyUnit.values()) {
+                MAP.put(lu.toString().toLowerCase(), (MonitoringUnit) lu);
+            }
+        }
+
+        private LatencyUnit(String latencyUnit) {
+            this.latencyUnit = latencyUnit;
+        }
+
+        public static MonitoringUnit getByName(String lu) {
+            lu = lu.toLowerCase();
+            return MAP.get(lu);
+        }
+
+        @Override
+        public String toString() {
+            return this.latencyUnit;
+        }
+
+    };
+
+    String toString();
+
+}
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java
index 102b186..9cf46dd 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/stats/TimingStatistics.java
@@ -22,6 +22,13 @@
 public interface TimingStatistics {
 
     /**
+     * Returns the unit of timing statistics.
+     *
+     * @return timing statistics' unit
+     */
+    MonitoringUnit unit();
+
+    /**
      * Time (ns) to parse the controller's deployment instruction.
      *
      * @return time in nanoseconds to parse a 'deploy' command