Showing
4 changed files
with
36 additions
and
9 deletions
... | @@ -14,12 +14,11 @@ import java.util.List; | ... | @@ -14,12 +14,11 @@ import java.util.List; |
14 | public interface DeviceService { | 14 | public interface DeviceService { |
15 | 15 | ||
16 | /** | 16 | /** |
17 | - * Returns the current mastership role for the specified device. | 17 | + * Returns the number of infrastructure devices known to the system. |
18 | * | 18 | * |
19 | - * @param deviceId device identifier | 19 | + * @return number of infrastructure devices |
20 | - * @return designated mastership role | ||
21 | */ | 20 | */ |
22 | - MastershipRole getRole(DeviceId deviceId); | 21 | + int getDeviceCount(); |
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Returns a collection of the currently known infrastructure | 24 | * Returns a collection of the currently known infrastructure |
... | @@ -37,6 +36,14 @@ public interface DeviceService { | ... | @@ -37,6 +36,14 @@ public interface DeviceService { |
37 | */ | 36 | */ |
38 | Device getDevice(DeviceId deviceId); | 37 | Device getDevice(DeviceId deviceId); |
39 | 38 | ||
39 | + /** | ||
40 | + * Returns the current mastership role for the specified device. | ||
41 | + * | ||
42 | + * @param deviceId device identifier | ||
43 | + * @return designated mastership role | ||
44 | + */ | ||
45 | + MastershipRole getRole(DeviceId deviceId); | ||
46 | + | ||
40 | 47 | ||
41 | /** | 48 | /** |
42 | * Returns the list of ports associated with the device. | 49 | * Returns the list of ports associated with the device. | ... | ... |
... | @@ -69,9 +69,8 @@ public class SimpleDeviceManager | ... | @@ -69,9 +69,8 @@ public class SimpleDeviceManager |
69 | } | 69 | } |
70 | 70 | ||
71 | @Override | 71 | @Override |
72 | - public MastershipRole getRole(DeviceId deviceId) { | 72 | + public int getDeviceCount() { |
73 | - checkNotNull(deviceId, DEVICE_ID_NULL); | 73 | + return store.getDeviceCount(); |
74 | - return store.getRole(deviceId); | ||
75 | } | 74 | } |
76 | 75 | ||
77 | @Override | 76 | @Override |
... | @@ -86,6 +85,12 @@ public class SimpleDeviceManager | ... | @@ -86,6 +85,12 @@ public class SimpleDeviceManager |
86 | } | 85 | } |
87 | 86 | ||
88 | @Override | 87 | @Override |
88 | + public MastershipRole getRole(DeviceId deviceId) { | ||
89 | + checkNotNull(deviceId, DEVICE_ID_NULL); | ||
90 | + return store.getRole(deviceId); | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
89 | public List<Port> getPorts(DeviceId deviceId) { | 94 | public List<Port> getPorts(DeviceId deviceId) { |
90 | checkNotNull(deviceId, DEVICE_ID_NULL); | 95 | checkNotNull(deviceId, DEVICE_ID_NULL); |
91 | return store.getPorts(deviceId); | 96 | return store.getPorts(deviceId); | ... | ... |
... | @@ -28,7 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -28,7 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument; |
28 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; | 28 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Manages inventory of infrastructure devices. | 31 | + * Manages inventory of infrastructure devices using trivial in-memory |
32 | + * implementation. | ||
32 | */ | 33 | */ |
33 | class SimpleDeviceStore { | 34 | class SimpleDeviceStore { |
34 | 35 | ||
... | @@ -40,6 +41,15 @@ class SimpleDeviceStore { | ... | @@ -40,6 +41,15 @@ class SimpleDeviceStore { |
40 | private final Map<DeviceId, Map<PortNumber, Port>> devicePorts = new HashMap<>(); | 41 | private final Map<DeviceId, Map<PortNumber, Port>> devicePorts = new HashMap<>(); |
41 | 42 | ||
42 | /** | 43 | /** |
44 | + * Returns the number of devices known to the system. | ||
45 | + * | ||
46 | + * @return number of devices | ||
47 | + */ | ||
48 | + public int getDeviceCount() { | ||
49 | + return devices.size(); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
43 | * Returns an iterable collection of all devices known to the system. | 53 | * Returns an iterable collection of all devices known to the system. |
44 | * | 54 | * |
45 | * @return device collection | 55 | * @return device collection |
... | @@ -301,5 +311,4 @@ class SimpleDeviceStore { | ... | @@ -301,5 +311,4 @@ class SimpleDeviceStore { |
301 | new DeviceEvent(DEVICE_REMOVED, device, null); | 311 | new DeviceEvent(DEVICE_REMOVED, device, null); |
302 | } | 312 | } |
303 | } | 313 | } |
304 | - | ||
305 | } | 314 | } | ... | ... |
... | @@ -103,6 +103,7 @@ public class SimpleDeviceManagerTest { | ... | @@ -103,6 +103,7 @@ public class SimpleDeviceManagerTest { |
103 | Iterator<Device> it = service.getDevices().iterator(); | 103 | Iterator<Device> it = service.getDevices().iterator(); |
104 | assertNotNull("one device expected", it.next()); | 104 | assertNotNull("one device expected", it.next()); |
105 | assertFalse("only one device expected", it.hasNext()); | 105 | assertFalse("only one device expected", it.hasNext()); |
106 | + assertEquals("incorrect device count", 1, service.getDeviceCount()); | ||
106 | } | 107 | } |
107 | 108 | ||
108 | @Test | 109 | @Test |
... | @@ -119,6 +120,8 @@ public class SimpleDeviceManagerTest { | ... | @@ -119,6 +120,8 @@ public class SimpleDeviceManagerTest { |
119 | // Reconnect | 120 | // Reconnect |
120 | connectDevice(DID1, SW1); | 121 | connectDevice(DID1, SW1); |
121 | validateEvents(DEVICE_AVAILABILITY_CHANGED); | 122 | validateEvents(DEVICE_AVAILABILITY_CHANGED); |
123 | + | ||
124 | + assertEquals("incorrect device count", 2, service.getDeviceCount()); | ||
122 | } | 125 | } |
123 | 126 | ||
124 | @Test | 127 | @Test |
... | @@ -197,9 +200,12 @@ public class SimpleDeviceManagerTest { | ... | @@ -197,9 +200,12 @@ public class SimpleDeviceManagerTest { |
197 | public void removeDevice() { | 200 | public void removeDevice() { |
198 | connectDevice(DID1, SW1); | 201 | connectDevice(DID1, SW1); |
199 | connectDevice(DID2, SW2); | 202 | connectDevice(DID2, SW2); |
203 | + assertEquals("incorrect device count", 2, service.getDeviceCount()); | ||
200 | admin.removeDevice(DID1); | 204 | admin.removeDevice(DID1); |
201 | assertNull("device should not be found", service.getDevice(DID1)); | 205 | assertNull("device should not be found", service.getDevice(DID1)); |
202 | assertNotNull("device should be found", service.getDevice(DID2)); | 206 | assertNotNull("device should be found", service.getDevice(DID2)); |
207 | + assertEquals("incorrect device count", 1, service.getDeviceCount()); | ||
208 | + | ||
203 | } | 209 | } |
204 | 210 | ||
205 | protected void validateEvents(Enum... types) { | 211 | protected void validateEvents(Enum... types) { | ... | ... |
-
Please register or login to post a comment