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-08 18:13:29 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
62b14185e6e8f672409f27570d7ef2afa004149b
62b14185
2 parents
fa322cb6
80c0e5e6
Merge branch 'master' of
ssh://gerrit.onlab.us:29418/onos-next
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
7 deletions
net/api/src/main/java/org/onlab/onos/net/DefaultEdgeLink.java
net/api/src/main/java/org/onlab/onos/net/HostLinks.java → net/api/src/main/java/org/onlab/onos/net/EdgeLink.java
net/api/src/main/java/org/onlab/onos/net/HostId.java
net/api/src/main/java/org/onlab/onos/net/Link.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/DefaultEdgeLink.java
0 → 100644
View file @
62b1418
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.onos.net.provider.ProviderId
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
/**
* Default edge link model implementation.
*/
public
class
DefaultEdgeLink
extends
DefaultLink
implements
EdgeLink
{
private
final
HostId
hostId
;
private
final
HostLocation
hostLocation
;
/**
* Creates an edge link using the supplied information.
*
* @param providerId provider identity
* @param hostPoint host-side connection point
* @param hostLocation location where host attaches to the network
* @param isIngress true to indicated host-to-network direction; false
* for network-to-host direction
*/
public
DefaultEdgeLink
(
ProviderId
providerId
,
ConnectPoint
hostPoint
,
HostLocation
hostLocation
,
boolean
isIngress
)
{
super
(
providerId
,
isIngress
?
hostLocation
:
hostPoint
,
isIngress
?
hostPoint
:
hostLocation
,
Type
.
EDGE
);
checkArgument
(
hostPoint
.
elementId
()
instanceof
HostId
,
"Host point does not refer to a host ID"
);
this
.
hostId
=
(
HostId
)
hostPoint
.
elementId
();
this
.
hostLocation
=
hostLocation
;
}
@Override
public
HostId
hostId
()
{
return
hostId
;
}
@Override
public
ConnectPoint
connectPoint
()
{
return
hostLocation
;
}
}
net/api/src/main/java/org/onlab/onos/net/
HostLinks
.java
→
net/api/src/main/java/org/onlab/onos/net/
EdgeLink
.java
View file @
62b1418
...
...
@@ -4,14 +4,14 @@ package org.onlab.onos.net;
* Abstraction of a link between an end-station host and the network
* infrastructure.
*/
public
interface
HostLinks
extends
Link
{
public
interface
EdgeLink
extends
Link
{
/**
* Returns the host identification.
*
* @return host identifier
*/
Elemen
tId
hostId
();
Hos
tId
hostId
();
/**
* Returns the connection point where the host attaches to the
...
...
net/api/src/main/java/org/onlab/onos/net/HostId.java
0 → 100644
View file @
62b1418
package
org
.
onlab
.
onos
.
net
;
import
java.net.URI
;
/**
* Immutable representation of a host identity.
*/
public
final
class
HostId
extends
ElementId
{
// Public construction is prohibited
private
HostId
(
URI
uri
)
{
super
(
uri
);
}
/**
* Creates a device id using the supplied URI.
*
* @param uri device URI
*/
public
static
HostId
hostId
(
URI
uri
)
{
return
new
HostId
(
uri
);
}
/**
* Creates a device id using the supplied URI string.
*
* @param string device URI string
*/
public
static
HostId
hostId
(
String
string
)
{
return
new
HostId
(
URI
.
create
(
string
));
}
}
net/api/src/main/java/org/onlab/onos/net/Link.java
View file @
62b1418
...
...
@@ -20,7 +20,12 @@ public interface Link extends Provided {
* links traversing optical paths, tunnels or intervening 'dark'
* switches.
*/
INDIRECT
INDIRECT
,
/**
* Signifies that this link is an edge, i.e. host link.
*/
EDGE
}
/**
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
View file @
62b1418
...
...
@@ -27,8 +27,11 @@ import org.onlab.onos.net.provider.AbstractProviderService;
import
org.slf4j.Logger
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
java
.
util
.
concurrent
.
Executors
.
newSingleThreadExecutor
;
import
static
org
.
onlab
.
util
.
Tools
.
namedThreads
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
/**
...
...
@@ -53,6 +56,9 @@ public class SimpleDeviceManager
private
final
SimpleDeviceStore
store
=
new
SimpleDeviceStore
();
private
final
ExecutorService
executor
=
newSingleThreadExecutor
(
namedThreads
(
"onos-device-%d"
));
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
EventDeliveryService
eventDispatcher
;
...
...
@@ -163,6 +169,11 @@ public class SimpleDeviceManager
DeviceEvent
event
=
store
.
createOrUpdateDevice
(
provider
().
id
(),
deviceId
,
deviceDescription
);
post
(
event
);
// If there was a change of any kind, trigger role selection process.
if
(
event
!=
null
)
{
triggerRoleSelection
(
event
.
subject
(),
provider
());
}
}
@Override
...
...
@@ -199,6 +210,22 @@ public class SimpleDeviceManager
}
}
/**
* Triggers asynchronous role selection.
*
* @param device device
* @param provider device provider
*/
private
void
triggerRoleSelection
(
final
Device
device
,
final
DeviceProvider
provider
)
{
executor
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
provider
.
roleChanged
(
device
,
store
.
getRole
(
device
.
id
()));
}
});
}
// Posts the specified event to the local event dispatcher.
private
void
post
(
DeviceEvent
event
)
{
if
(
event
!=
null
&&
eventDispatcher
!=
null
)
{
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
View file @
62b1418
...
...
@@ -96,6 +96,9 @@ class SimpleDeviceStore {
synchronized
(
this
)
{
devices
.
put
(
deviceId
,
device
);
availableDevices
.
add
(
deviceId
);
// For now claim the device as a master automatically.
roles
.
put
(
deviceId
,
MastershipRole
.
MASTER
);
}
return
new
DeviceEvent
(
DeviceEvent
.
Type
.
DEVICE_ADDED
,
device
,
null
);
}
...
...
net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManagerTest.java
View file @
62b1418
...
...
@@ -139,17 +139,17 @@ public class SimpleDeviceManagerTest {
@Test
public
void
getRole
()
{
connectDevice
(
DID1
,
SW1
);
assertEquals
(
"incorrect role"
,
MastershipRole
.
NONE
,
service
.
getRole
(
DID1
));
assertEquals
(
"incorrect role"
,
MastershipRole
.
MASTER
,
service
.
getRole
(
DID1
));
}
@Test
public
void
setRole
()
{
connectDevice
(
DID1
,
SW1
);
admin
.
setRole
(
DID1
,
MastershipRole
.
MASTER
);
admin
.
setRole
(
DID1
,
MastershipRole
.
STANDBY
);
validateEvents
(
DEVICE_ADDED
,
DEVICE_MASTERSHIP_CHANGED
);
assertEquals
(
"incorrect role"
,
MastershipRole
.
MASTER
,
service
.
getRole
(
DID1
));
assertEquals
(
"incorrect role"
,
MastershipRole
.
STANDBY
,
service
.
getRole
(
DID1
));
assertEquals
(
"incorrect device"
,
DID1
,
provider
.
deviceReceived
.
id
());
assertEquals
(
"incorrect role"
,
MastershipRole
.
MASTER
,
provider
.
roleReceived
);
assertEquals
(
"incorrect role"
,
MastershipRole
.
STANDBY
,
provider
.
roleReceived
);
}
@Test
...
...
Please
register
or
login
to post a comment