mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 02:11:38 +02:00
[ONOS-6806] Add getAvailableDeviceCount method to DeviceService
Change-Id: Ieda7e66c1a1d25aa92b55542ecfe59652dac3bc5
This commit is contained in:
parent
d975bdf090
commit
32000d35b7
@ -38,6 +38,15 @@ public interface DeviceService
|
||||
*/
|
||||
int getDeviceCount();
|
||||
|
||||
/**
|
||||
* Returns the number of currently available devices known to the system.
|
||||
*
|
||||
* @return number of available devices
|
||||
*/
|
||||
default int getAvailableDeviceCount() {
|
||||
return getDeviceCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of the currently known infrastructure
|
||||
* devices.
|
||||
|
@ -55,6 +55,11 @@ public class DeviceServiceAdapter implements DeviceService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableDeviceCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Device> getDevices() {
|
||||
return Collections.emptyList();
|
||||
|
@ -62,6 +62,11 @@ public abstract class ForwardingDeviceService implements DeviceService {
|
||||
return delegate.getDeviceCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableDeviceCount() {
|
||||
return delegate.getAvailableDeviceCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Device> getDevices() {
|
||||
return delegate.getDevices();
|
||||
|
@ -208,6 +208,12 @@ public class DeviceManager
|
||||
return store.getDeviceCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableDeviceCount() {
|
||||
checkPermission(DEVICE_READ);
|
||||
return store.getAvailableDeviceCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Device> getDevices() {
|
||||
checkPermission(DEVICE_READ);
|
||||
|
@ -144,6 +144,7 @@ public class DeviceManagerTest {
|
||||
assertNotNull("one device expected", it.next());
|
||||
assertFalse("only one device expected", it.hasNext());
|
||||
assertEquals("incorrect device count", 1, service.getDeviceCount());
|
||||
assertEquals("incorrect available device count", 1, service.getAvailableDeviceCount());
|
||||
assertTrue("device should be available", service.isAvailable(DID1));
|
||||
}
|
||||
|
||||
@ -165,6 +166,7 @@ public class DeviceManagerTest {
|
||||
validateEvents(DEVICE_AVAILABILITY_CHANGED);
|
||||
|
||||
assertEquals("incorrect device count", 2, service.getDeviceCount());
|
||||
assertEquals("incorrect available device count", 2, service.getAvailableDeviceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -225,8 +227,8 @@ public class DeviceManagerTest {
|
||||
assertEquals("wrong port count", 2, service.getPorts(DID1).size());
|
||||
|
||||
Port port = service.getPort(DID1, P1);
|
||||
assertEquals("incorrect port", P1, service.getPort(DID1, P1).number());
|
||||
assertEquals("incorrect state", true, service.getPort(DID1, P1).isEnabled());
|
||||
assertEquals("incorrect port", P1, port.number());
|
||||
assertEquals("incorrect state", true, port.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -234,10 +236,12 @@ public class DeviceManagerTest {
|
||||
connectDevice(DID1, SW1);
|
||||
connectDevice(DID2, SW2);
|
||||
assertEquals("incorrect device count", 2, service.getDeviceCount());
|
||||
assertEquals("incorrect available device count", 2, service.getAvailableDeviceCount());
|
||||
admin.removeDevice(DID1);
|
||||
assertNull("device should not be found", service.getDevice(DID1));
|
||||
assertNotNull("device should be found", service.getDevice(DID2));
|
||||
assertEquals("incorrect device count", 1, service.getDeviceCount());
|
||||
assertEquals("incorrect available device count", 1, service.getAvailableDeviceCount());
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user