[ONOS-6806] Add getAvailableDeviceCount method to DeviceStore
Change-Id: I3f9e0bbd502e2a592da98436685fa2a192436ef8
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java b/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
index 626097d..cadfa25 100644
--- a/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceStore.java
@@ -39,6 +39,13 @@
int getDeviceCount();
/**
+ * Returns the number of currently available devices known to the system.
+ *
+ * @return number of devices
+ */
+ int getAvailableDeviceCount();
+
+ /**
* Returns an iterable collection of all devices known to the system.
*
* @return device collection
diff --git a/core/api/src/test/java/org/onosproject/net/device/DeviceStoreAdapter.java b/core/api/src/test/java/org/onosproject/net/device/DeviceStoreAdapter.java
index b09b35f..b4861ea 100644
--- a/core/api/src/test/java/org/onosproject/net/device/DeviceStoreAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/device/DeviceStoreAdapter.java
@@ -36,6 +36,11 @@
}
@Override
+ public int getAvailableDeviceCount() {
+ return 0;
+ }
+
+ @Override
public Iterable<Device> getDevices() {
return null;
}
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java
index 04d376c..a3761b0 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java
@@ -126,6 +126,11 @@
}
@Override
+ public int getAvailableDeviceCount() {
+ return availableDevices.size();
+ }
+
+ @Override
public Iterable<Device> getDevices() {
return Collections.unmodifiableCollection(devices.values());
}
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java
index f8eb1ba..c4ceb18 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java
@@ -156,6 +156,22 @@
}
@Test
+ public final void testGetAvailableDeviceCount() {
+ assertEquals("initialy empty", 0, deviceStore.getAvailableDeviceCount());
+
+ putDevice(DID1, SW1);
+ putDevice(DID2, SW2);
+
+ deviceStore.markOffline(DID1);
+
+ assertEquals("expect 1 available device", 1, deviceStore.getAvailableDeviceCount());
+
+ putDevice(DID1, SW1);
+
+ assertEquals("expect 2 available devices", 2, deviceStore.getAvailableDeviceCount());
+ }
+
+ @Test
public final void testGetDevices() {
assertEquals("initialy empty", 0, Iterables.size(deviceStore.getDevices()));
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
index 062fd46..e73eaea 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
@@ -247,6 +247,11 @@
}
@Override
+ public int getAvailableDeviceCount() {
+ return availableDevices.size();
+ }
+
+ @Override
public Device getDevice(DeviceId deviceId) {
return devices.get(deviceId);
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
index 00dacc2..7f1539d 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
@@ -276,6 +276,11 @@
}
@Override
+ public int getAvailableDeviceCount() {
+ return availableDevices.size();
+ }
+
+ @Override
public Iterable<Device> getDevices() {
return Collections.unmodifiableCollection(devices.values());
}
diff --git a/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java
index 4df97a1..4f9f20cd 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java
@@ -299,6 +299,22 @@
}
@Test
+ public final void testGetAvailableDeviceCount() {
+ assertEquals("initialy empty", 0, deviceStore.getAvailableDeviceCount());
+
+ putDevice(DID1, SW1);
+ putDevice(DID2, SW2);
+
+ deviceStore.markOffline(DID1);
+
+ assertEquals("expect 1 available device", 1, deviceStore.getAvailableDeviceCount());
+
+ deviceStore.markOnline(DID1);
+
+ assertEquals("expect 2 available devices", 2, deviceStore.getAvailableDeviceCount());
+ }
+
+ @Test
public final void testGetDevices() {
assertEquals("initialy empty", 0, Iterables.size(deviceStore.getDevices()));