[ONOS-7704] device memory/cpu stats for pica8 switch using Switch_Inventory DB

Change-Id: I1956d06ab373119da59561252f5b35561f8f5619
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DeviceCpuStats.java b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceCpuStats.java
new file mode 100644
index 0000000..ccc1fc1
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceCpuStats.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016-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.net.behaviour;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+/**
+ * A representation of cpu stats of device.
+ */
+public class DeviceCpuStats {
+    private float used;
+
+    /**
+     * Instantiates DeviceCpuStats object with default value.
+     */
+    public DeviceCpuStats() {
+        used = 0.0f;
+    }
+
+    /**
+     * Creates DeviceCpuStats object with given value.
+     *
+     * @param used cpu usage of device
+     */
+    public DeviceCpuStats(float used) {
+        this.used = used;
+    }
+
+    /**
+     * Get cpu usage of device.
+     *
+     * @return usedCpu, cpu usage stats of device
+     */
+    public float getUsed() {
+        return used;
+    }
+
+    /**
+     * Set cpu usage of device.
+     *
+     * @param used cpu usage of device
+     */
+    public void setUsed(float used) {
+        this.used = used;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("used", used)
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DeviceCpuStats that = (DeviceCpuStats) o;
+        return Float.compare(that.used, used) == 0;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(used);
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DeviceMemoryStats.java b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceMemoryStats.java
new file mode 100644
index 0000000..e90d9e8
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceMemoryStats.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016-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.net.behaviour;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+/**
+ * A representation of memory stats of device.
+ */
+
+public class DeviceMemoryStats {
+    private long free = 0;  // in Bytes
+    private long used = 0;
+    private long total = 0;
+
+    /**
+     * Instantiates DeviceMemoryStats object.
+     */
+    public DeviceMemoryStats() {
+    }
+
+    /**
+     * Creates DeviceMemoryStats object with given data.
+     *
+     * @param free free memory
+     * @param used used memory
+     * @param total total memory
+     */
+    public DeviceMemoryStats(long free, long used, long total) {
+        this.free = free;
+        this.used = used;
+        this.total = total;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("free", free)
+                .add("used", used)
+                .add("total", total)
+                .toString();
+    }
+
+    /**
+     * Get total memory of device.
+     *
+     * @return totalMmeory, total memory
+     */
+    public long getTotal() {
+        return total;
+    }
+
+    /**
+     * Get used memory of device.
+     *
+     * @return usedMemory, used memory
+     */
+    public long getUsed() {
+        return used;
+    }
+
+    /**
+     * Get free memory of device.
+     *
+     * @return freeMemory, free memory
+     */
+    public long getFree() {
+        return free;
+    }
+
+    /**
+     * Set free memory of device.
+     *
+     * @param free free memory stats of device
+     */
+    public void setFree(long free) {
+        this.free = free;
+    }
+
+    /**
+     * Set used memory of device.
+     *
+     * @param used used memory stats of device
+     */
+    public void setUsed(long used) {
+        this.used = used;
+    }
+
+    /**
+     * Set total memory of device.
+     *
+     * @param total total memory stats of device
+     */
+    public void setTotal(long total) {
+        this.total = total;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DeviceMemoryStats that = (DeviceMemoryStats) o;
+        return free == that.free &&
+                used == that.used &&
+                total == that.total;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(free, used, total);
+    }
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStatisticsQuery.java b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStatisticsQuery.java
new file mode 100644
index 0000000..ba34872
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStatisticsQuery.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016-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.net.behaviour;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.Optional;
+
+/**
+ * A HandlerBehaviour to get System Stats for the Device.
+ */
+public interface DeviceSystemStatisticsQuery extends HandlerBehaviour {
+    /**
+     * Get System stats  available for the device.
+     * @return success or failure
+     */
+
+    Optional<DeviceSystemStats> getDeviceSystemStats();
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStats.java b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStats.java
new file mode 100644
index 0000000..ccddd85
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DeviceSystemStats.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016-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.net.behaviour;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+/**
+ * A representation of system stats of device.
+ */
+public class DeviceSystemStats {
+
+    private final DeviceMemoryStats memory;
+    private final DeviceCpuStats cpu;
+
+    /**
+     * Creates deviceSystemStats object.
+     *
+     * @param memoryStats memory statisics of the device
+     * @param cpuStats cpu statistics of the device
+     */
+    public DeviceSystemStats(DeviceMemoryStats memoryStats, DeviceCpuStats cpuStats) {
+        this.memory = memoryStats;
+        this.cpu = cpuStats;
+    }
+
+    /**
+     * Get memory usage statistics.
+     *
+     * @return deviceMemoryStats, device memory usage stats in KB
+     */
+    public DeviceMemoryStats getMemory() {
+        return this.memory;
+    }
+
+    /**
+     * Get cpu usage statistics.
+     *
+     * @return deviceCpuStats, device cpu usage stats
+     */
+    public DeviceCpuStats getCpu() {
+        return this.cpu;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("memory", memory)
+                .add("cpu", cpu)
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DeviceSystemStats that = (DeviceSystemStats) o;
+        return Objects.equals(memory, that.memory) &&
+                Objects.equals(cpu, that.cpu);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(memory, cpu);
+    }
+}
+
+