Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
tom
2014-09-06 23:24:20 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ad2d2096a74f05434cbcc04a1d798a0349fd96a6
ad2d2096
1 parent
24c55cd2
Added getDeviceCount and tests.
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
9 deletions
net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java
net/api/src/main/java/org/onlab/onos/net/device/DeviceService.java
View file @
ad2d209
...
...
@@ -14,12 +14,11 @@ import java.util.List;
public
interface
DeviceService
{
/**
* Returns the
current mastership role for the specified device
.
* Returns the
number of infrastructure devices known to the system
.
*
* @param deviceId device identifier
* @return designated mastership role
* @return number of infrastructure devices
*/
MastershipRole
getRole
(
DeviceId
deviceId
);
int
getDeviceCount
(
);
/**
* Returns a collection of the currently known infrastructure
...
...
@@ -37,6 +36,14 @@ public interface DeviceService {
*/
Device
getDevice
(
DeviceId
deviceId
);
/**
* Returns the current mastership role for the specified device.
*
* @param deviceId device identifier
* @return designated mastership role
*/
MastershipRole
getRole
(
DeviceId
deviceId
);
/**
* Returns the list of ports associated with the device.
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
View file @
ad2d209
...
...
@@ -69,9 +69,8 @@ public class SimpleDeviceManager
}
@Override
public
MastershipRole
getRole
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
store
.
getRole
(
deviceId
);
public
int
getDeviceCount
()
{
return
store
.
getDeviceCount
();
}
@Override
...
...
@@ -86,6 +85,12 @@ public class SimpleDeviceManager
}
@Override
public
MastershipRole
getRole
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
store
.
getRole
(
deviceId
);
}
@Override
public
List
<
Port
>
getPorts
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
store
.
getPorts
(
deviceId
);
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
View file @
ad2d209
...
...
@@ -28,7 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import
static
org
.
onlab
.
onos
.
net
.
device
.
DeviceEvent
.
Type
.*;
/**
* Manages inventory of infrastructure devices.
* Manages inventory of infrastructure devices using trivial in-memory
* implementation.
*/
class
SimpleDeviceStore
{
...
...
@@ -40,6 +41,15 @@ class SimpleDeviceStore {
private
final
Map
<
DeviceId
,
Map
<
PortNumber
,
Port
>>
devicePorts
=
new
HashMap
<>();
/**
* Returns the number of devices known to the system.
*
* @return number of devices
*/
public
int
getDeviceCount
()
{
return
devices
.
size
();
}
/**
* Returns an iterable collection of all devices known to the system.
*
* @return device collection
...
...
@@ -301,5 +311,4 @@ class SimpleDeviceStore {
new
DeviceEvent
(
DEVICE_REMOVED
,
device
,
null
);
}
}
}
...
...
net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java
View file @
ad2d209
...
...
@@ -103,6 +103,7 @@ public class SimpleDeviceManagerTest {
Iterator
<
Device
>
it
=
service
.
getDevices
().
iterator
();
assertNotNull
(
"one device expected"
,
it
.
next
());
assertFalse
(
"only one device expected"
,
it
.
hasNext
());
assertEquals
(
"incorrect device count"
,
1
,
service
.
getDeviceCount
());
}
@Test
...
...
@@ -119,6 +120,8 @@ public class SimpleDeviceManagerTest {
// Reconnect
connectDevice
(
DID1
,
SW1
);
validateEvents
(
DEVICE_AVAILABILITY_CHANGED
);
assertEquals
(
"incorrect device count"
,
2
,
service
.
getDeviceCount
());
}
@Test
...
...
@@ -197,9 +200,12 @@ public class SimpleDeviceManagerTest {
public
void
removeDevice
()
{
connectDevice
(
DID1
,
SW1
);
connectDevice
(
DID2
,
SW2
);
assertEquals
(
"incorrect device count"
,
2
,
service
.
getDeviceCount
());
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
());
}
protected
void
validateEvents
(
Enum
...
types
)
{
...
...
Please
register
or
login
to post a comment