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
alshabib
2014-09-07 19:09:34 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
4e475212aa4b89ae32fcd7c0b4692c3ad6e508d2
4e475212
2 parents
289652c5
ad2d2096
Merge branch 'master' of
ssh://gerrit.onlab.us:29418/onos-next
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
15 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 @
4e47521
...
...
@@ -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 @
4e47521
...
...
@@ -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
);
...
...
@@ -147,7 +152,7 @@ public class SimpleDeviceManager
public
void
deviceConnected
(
DeviceId
deviceId
,
DeviceDescription
deviceDescription
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
deviceDescription
,
DEVICE_DESCRIPTION_NULL
);
log
.
info
(
"Device {} connected
: {}"
,
deviceId
,
deviceDescription
);
log
.
info
(
"Device {} connected
"
,
deviceId
);
DeviceEvent
event
=
store
.
createOrUpdateDevice
(
provider
().
id
(),
deviceId
,
deviceDescription
);
post
(
event
);
...
...
@@ -165,7 +170,7 @@ public class SimpleDeviceManager
public
void
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
portDescriptions
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
portDescriptions
,
"Port descriptions list cannot be null"
);
log
.
info
(
"Device {} ports updated
: {}"
,
portDescriptions
);
log
.
info
(
"Device {} ports updated
"
,
deviceId
);
List
<
DeviceEvent
>
events
=
store
.
updatePorts
(
deviceId
,
portDescriptions
);
for
(
DeviceEvent
event
:
events
)
{
post
(
event
);
...
...
@@ -176,7 +181,7 @@ public class SimpleDeviceManager
public
void
portStatusChanged
(
DeviceId
deviceId
,
PortDescription
portDescription
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
portDescription
,
PORT_DESCRIPTION_NULL
);
log
.
info
(
"Device {} port status changed
: {}"
,
deviceId
,
portDescription
);
log
.
info
(
"Device {} port status changed
"
,
deviceId
);
DeviceEvent
event
=
store
.
updatePortStatus
(
deviceId
,
portDescription
);
post
(
event
);
}
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
View file @
4e47521
...
...
@@ -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
...
...
@@ -153,9 +163,9 @@ class SimpleDeviceStore {
Set
<
PortNumber
>
processed
=
new
HashSet
<>();
for
(
PortDescription
portDescription
:
portDescriptions
)
{
Port
port
=
ports
.
get
(
portDescription
.
portNumber
());
DeviceEvent
event
=
port
==
null
?
events
.
add
(
port
==
null
?
createPort
(
device
,
portDescription
,
ports
)
:
updatePort
(
device
,
port
,
portDescription
,
ports
);
updatePort
(
device
,
port
,
portDescription
,
ports
)
);
processed
.
add
(
portDescription
.
portNumber
());
}
...
...
@@ -198,7 +208,7 @@ class SimpleDeviceStore {
Iterator
<
PortNumber
>
iterator
=
ports
.
keySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
PortNumber
portNumber
=
iterator
.
next
();
if
(
processed
.
contains
(
portNumber
))
{
if
(
!
processed
.
contains
(
portNumber
))
{
events
.
add
(
new
DeviceEvent
(
PORT_REMOVED
,
device
,
ports
.
get
(
portNumber
)));
iterator
.
remove
();
...
...
@@ -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 @
4e47521
...
...
@@ -7,7 +7,10 @@ import org.onlab.onos.event.Event;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.Port
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.device.DefaultDeviceDescription
;
import
org.onlab.onos.net.device.DefaultPortDescription
;
import
org.onlab.onos.net.device.DeviceAdminService
;
import
org.onlab.onos.net.device.DeviceDescription
;
import
org.onlab.onos.net.device.DeviceEvent
;
...
...
@@ -16,6 +19,7 @@ import org.onlab.onos.net.device.DeviceProvider;
import
org.onlab.onos.net.device.DeviceProviderRegistry
;
import
org.onlab.onos.net.device.DeviceProviderService
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.AbstractProvider
;
import
org.onlab.onos.net.provider.ProviderId
;
...
...
@@ -42,6 +46,10 @@ public class SimpleDeviceManagerTest {
private
static
final
String
SW2
=
"3.9.5"
;
private
static
final
String
SN
=
"43311-12345"
;
private
static
final
PortNumber
P1
=
PortNumber
.
portNumber
(
1
);
private
static
final
PortNumber
P2
=
PortNumber
.
portNumber
(
2
);
private
static
final
PortNumber
P3
=
PortNumber
.
portNumber
(
3
);
private
SimpleDeviceManager
mgr
;
...
...
@@ -95,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
...
...
@@ -111,6 +120,8 @@ public class SimpleDeviceManagerTest {
// Reconnect
connectDevice
(
DID1
,
SW1
);
validateEvents
(
DEVICE_AVAILABILITY_CHANGED
);
assertEquals
(
"incorrect device count"
,
2
,
service
.
getDeviceCount
());
}
@Test
...
...
@@ -138,7 +149,64 @@ public class SimpleDeviceManagerTest {
assertEquals
(
"incorrect role"
,
MastershipRole
.
MASTER
,
provider
.
roleReceived
);
}
@Test
public
void
updatePorts
()
{
connectDevice
(
DID1
,
SW1
);
List
<
PortDescription
>
pds
=
new
ArrayList
<>();
pds
.
add
(
new
DefaultPortDescription
(
P1
,
true
));
pds
.
add
(
new
DefaultPortDescription
(
P2
,
true
));
pds
.
add
(
new
DefaultPortDescription
(
P3
,
true
));
providerService
.
updatePorts
(
DID1
,
pds
);
validateEvents
(
DEVICE_ADDED
,
PORT_ADDED
,
PORT_ADDED
,
PORT_ADDED
);
pds
.
clear
();
pds
.
add
(
new
DefaultPortDescription
(
P1
,
false
));
pds
.
add
(
new
DefaultPortDescription
(
P3
,
true
));
providerService
.
updatePorts
(
DID1
,
pds
);
validateEvents
(
PORT_UPDATED
,
PORT_REMOVED
);
}
@Test
public
void
updatePortStatus
()
{
connectDevice
(
DID1
,
SW1
);
List
<
PortDescription
>
pds
=
new
ArrayList
<>();
pds
.
add
(
new
DefaultPortDescription
(
P1
,
true
));
pds
.
add
(
new
DefaultPortDescription
(
P2
,
true
));
providerService
.
updatePorts
(
DID1
,
pds
);
validateEvents
(
DEVICE_ADDED
,
PORT_ADDED
,
PORT_ADDED
);
providerService
.
portStatusChanged
(
DID1
,
new
DefaultPortDescription
(
P1
,
false
));
validateEvents
(
PORT_UPDATED
);
providerService
.
portStatusChanged
(
DID1
,
new
DefaultPortDescription
(
P1
,
false
));
assertTrue
(
"no events expected"
,
listener
.
events
.
isEmpty
());
}
@Test
public
void
getPorts
()
{
connectDevice
(
DID1
,
SW1
);
List
<
PortDescription
>
pds
=
new
ArrayList
<>();
pds
.
add
(
new
DefaultPortDescription
(
P1
,
true
));
pds
.
add
(
new
DefaultPortDescription
(
P2
,
true
));
providerService
.
updatePorts
(
DID1
,
pds
);
validateEvents
(
DEVICE_ADDED
,
PORT_ADDED
,
PORT_ADDED
);
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
());
}
@Test
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
)
{
int
i
=
0
;
...
...
Please
register
or
login
to post a comment