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-08-27 19:27:47 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
32f66848bc363a79108fd22c4b8bec42d4737569
32f66848
1 parent
5ac5188d
Adding some flesh to the simple device manager.
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
172 additions
and
29 deletions
net/api/src/main/java/org/onlab/onos/event/EventDispatchService.java
net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java
net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.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/SimpleHostManager.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
net/api/src/main/java/org/onlab/onos/event/EventDispatchService.java
0 → 100644
View file @
32f6684
package
org
.
onlab
.
onos
.
event
;
/**
* Abstraction of an entity capable of accepting events to be posted and
* then dispatching them to the appropriate event sink.
*/
public
interface
EventDispatchService
extends
EventDispatcher
,
EventSinkBroker
{
}
net/api/src/main/java/org/onlab/onos/event/EventDispatcher.java
View file @
32f6684
...
...
@@ -6,13 +6,13 @@ package org.onlab.onos.event;
* Similarly, whether the events are accepted and dispatched synchronously
* or asynchronously is unspecified as well.
*/
public
interface
EventDispatcher
<
E
extends
Event
>
{
public
interface
EventDispatcher
{
/**
* Posts the specified event for dispatching.
*
* @param event event to be posted
*/
void
post
(
E
event
);
void
post
(
E
vent
event
);
}
...
...
net/api/src/main/java/org/onlab/onos/net/device/DeviceProviderService.java
View file @
32f6684
...
...
@@ -35,16 +35,16 @@ public interface DeviceProviderService extends ProviderService<DeviceProvider> {
* <p/>
*
* @param deviceId identity of the device
* @param ports list of device ports
* @param port
Description
s list of device ports
*/
void
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
ports
);
void
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
port
Description
s
);
/**
* Used to notify the core about port status change of a single port.
*
* @param deviceId identity of the device
* @param port description of the port that changed
* @param port
Description
description of the port that changed
*/
void
portStatusChanged
(
DeviceId
deviceId
,
PortDescription
port
);
void
portStatusChanged
(
DeviceId
deviceId
,
PortDescription
port
Description
);
}
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java
0 → 100644
View file @
32f6684
package
org
.
onlab
.
onos
.
net
.
trivial
.
impl
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceDescription
;
import
org.onlab.onos.net.device.DeviceEvent
;
import
org.onlab.onos.net.device.PortDescription
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* Manages inventory of infrastructure devices.
*/
public
class
DeviceStore
{
private
final
Map
<
DeviceId
,
Device
>
devices
=
new
ConcurrentHashMap
<>();
/**
* Creates a new infrastructure device, or updates an existing one using
* the supplied device description.
*
* @param deviceId device identifier
* @param deviceDescription device description
* @return ready to send event describing what occurred; null if no change
*/
public
DeviceEvent
createOrUpdateDevice
(
DeviceId
deviceId
,
DeviceDescription
deviceDescription
)
{
return
null
;
}
/**
* Removes the specified infrastructure device.
*
* @param deviceId device identifier
* @return ready to send event describing what occurred; null if no change
*/
public
DeviceEvent
removeDevice
(
DeviceId
deviceId
)
{
return
null
;
}
/**
* Updates the ports of the specified infrastructure device using the given
* list of port descriptions. The list is assumed to be comprehensive.
*
* @param deviceId device identifier
* @param portDescriptions list of port descriptions
* @return ready to send events describing what occurred; empty list if no change
*/
public
List
<
DeviceEvent
>
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
portDescriptions
)
{
return
new
ArrayList
<>();
}
/**
* Updates the port status of the specified infrastructure device using the
* given port description.
*
* @param deviceId device identifier
* @param portDescription port description
* @return ready to send event describing what occurred; null if no change
*/
public
DeviceEvent
updatePortStatus
(
DeviceId
deviceId
,
PortDescription
portDescription
)
{
return
null
;
}
}
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
View file @
32f6684
...
...
@@ -4,12 +4,20 @@ import org.apache.felix.scr.annotations.Activate;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.event.AbstractListenerManager
;
import
org.onlab.onos.event.EventDispatchService
;
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.DeviceDescription
;
import
org.onlab.onos.net.device.DeviceEvent
;
import
org.onlab.onos.net.device.DeviceListener
;
import
org.onlab.onos.net.device.DeviceProvider
;
import
org.onlab.onos.net.device.DeviceProviderBroker
;
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.AbstractProviderBroker
;
import
org.onlab.onos.net.provider.AbstractProviderService
;
...
...
@@ -18,48 +26,87 @@ import org.slf4j.LoggerFactory;
import
java.util.List
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
/**
* Provides basic implementation of the device SB & NB APIs.
*/
@Component
(
immediate
=
true
)
@Service
public
class
SimpleDeviceManager
implements
DeviceProviderBroker
{
public
class
SimpleDeviceManager
extends
AbstractProviderBroker
<
DeviceProvider
,
DeviceProviderService
>
implements
DeviceService
,
DeviceProviderBroker
{
public
static
final
String
DEVICE_ID_NULL
=
"Device ID cannot be null"
;
public
static
final
String
PORT_NUMBER_NULL
=
"Port number cannot be null"
;
public
static
final
String
DEVICE_DESCRIPTION_NULL
=
"Device description cannot be null"
;
public
static
final
String
PORT_DESCRIPTION_NULL
=
"Port description cannot be null"
;
private
Logger
log
=
LoggerFactory
.
getLogger
(
SimpleDeviceManager
.
class
);
private
final
DeviceProviderBroker
broker
=
new
InternalBroker
();
private
final
AbstractListenerManager
<
DeviceEvent
,
DeviceListener
>
listenerManager
=
new
AbstractListenerManager
<>();
private
EventDispatchService
eventDispatcher
;
private
final
DeviceStore
store
=
new
DeviceStore
();
@Activate
public
void
activate
()
{
// eventDispatcher.addSink(DeviceEvent.class, listenerManager);
log
.
info
(
"Started"
);
}
@Deactivate
public
void
deactivate
()
{
// eventDispatcher.removeSink(DeviceEvent.class);
log
.
info
(
"Stopped"
);
}
@Override
public
DeviceProviderService
register
(
DeviceProvider
provider
)
{
log
.
info
(
"Registering provider {}"
,
provider
.
id
());
return
broker
.
register
(
provider
);
public
MastershipRole
getRole
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
null
;
}
@Override
public
Iterable
<
Device
>
getDevices
()
{
return
null
;
}
@Override
public
void
unregister
(
DeviceProvider
provider
)
{
log
.
info
(
"Unregistering provider {}"
,
provider
.
id
());
broker
.
unregister
(
provider
);
public
Device
getDevice
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
null
;
}
@Override
public
List
<
Port
>
getPorts
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
null
;
}
@Override
public
Port
getPort
(
DeviceId
deviceId
,
PortNumber
portNumber
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
portNumber
,
PORT_NUMBER_NULL
);
return
null
;
}
@Override
public
void
addListener
(
DeviceListener
listener
)
{
listenerManager
.
addListener
(
listener
);
}
@Override
public
void
removeListener
(
DeviceListener
listener
)
{
listenerManager
.
removeListener
(
listener
);
}
// Internal delegate for tracking various providers and issuing them a
// personalized provider service.
private
class
InternalBroker
extends
AbstractProviderBroker
<
DeviceProvider
,
DeviceProviderService
>
implements
DeviceProviderBroker
{
@Override
protected
DeviceProviderService
createProviderService
(
DeviceProvider
provider
)
{
return
new
InternalDeviceProviderService
(
provider
);
}
}
// Personalized device provider service issued to the supplied provider.
private
class
InternalDeviceProviderService
extends
AbstractProviderService
<
DeviceProvider
>
...
...
@@ -71,26 +118,49 @@ public class SimpleDeviceManager implements DeviceProviderBroker {
@Override
public
MastershipRole
deviceConnected
(
DeviceId
deviceId
,
DeviceDescription
deviceDescription
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
deviceDescription
,
DEVICE_DESCRIPTION_NULL
);
log
.
info
(
"Device {} connected: {}"
,
deviceId
,
deviceDescription
);
DeviceEvent
event
=
store
.
createOrUpdateDevice
(
deviceId
,
deviceDescription
);
post
(
event
);
return
MastershipRole
.
MASTER
;
}
@Override
public
void
deviceDisconnected
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
log
.
info
(
"Device {} disconnected"
,
deviceId
);
DeviceEvent
event
=
store
.
removeDevice
(
deviceId
);
post
(
event
);
}
@Override
public
void
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
ports
)
{
public
void
updatePorts
(
DeviceId
deviceId
,
List
<
PortDescription
>
portDescriptions
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
portDescriptions
,
"Port descriptions list cannot be null"
);
// FIXME: fix the interface to accept DeviceId separately
log
.
info
(
"Device {} ports updated: {}"
,
ports
);
log
.
info
(
"Device {} ports updated: {}"
,
portDescriptions
);
List
<
DeviceEvent
>
events
=
store
.
updatePorts
(
deviceId
,
portDescriptions
);
for
(
DeviceEvent
event
:
events
)
{
post
(
event
);
}
}
@Override
public
void
portStatusChanged
(
DeviceId
deviceId
,
PortDescription
port
)
{
log
.
info
(
"Device {} port status changed: {}"
,
deviceId
,
port
);
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
);
DeviceEvent
event
=
store
.
updatePortStatus
(
deviceId
,
portDescription
);
post
(
event
);
}
}
// Posts the specified event to a local event dispatcher
private
void
post
(
DeviceEvent
event
)
{
if
(
event
!=
null
&&
eventDispatcher
!=
null
)
{
eventDispatcher
.
post
(
event
);
}
}
}
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostManager.java
View file @
32f6684
...
...
@@ -36,13 +36,11 @@ public class SimpleHostManager implements HostProviderBroker {
@Override
public
HostProviderService
register
(
HostProvider
provider
)
{
log
.
info
(
"Registering provider {}"
,
provider
.
id
());
return
broker
.
register
(
provider
);
}
@Override
public
void
unregister
(
HostProvider
provider
)
{
log
.
info
(
"Unregistering provider {}"
,
provider
.
id
());
broker
.
unregister
(
provider
);
}
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleLinkManager.java
View file @
32f6684
...
...
@@ -36,13 +36,11 @@ public class SimpleLinkManager implements LinkProviderBroker {
@Override
public
LinkProviderService
register
(
LinkProvider
provider
)
{
log
.
info
(
"Registering provider {}"
,
provider
.
id
());
return
broker
.
register
(
provider
);
}
@Override
public
void
unregister
(
LinkProvider
provider
)
{
log
.
info
(
"Unregistering provider {}"
,
provider
.
id
());
broker
.
unregister
(
provider
);
}
...
...
Please
register
or
login
to post a comment