Added a simple device manager to have a working provider broker.
Showing
3 changed files
with
106 additions
and
7 deletions
... | @@ -18,8 +18,9 @@ public interface Link extends Provided { // TODO: Also should extend graph Edge | ... | @@ -18,8 +18,9 @@ public interface Link extends Provided { // TODO: Also should extend graph Edge |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Signifies that this link is potentially comprised from multiple | 20 | * Signifies that this link is potentially comprised from multiple |
21 | - * underlying segments or hops, e.g. optical links, tunnel links, | 21 | + * underlying segments or hops, and as such should be used to tag |
22 | - * multi-hop links spanning 'dark' switches | 22 | + * links traversing optical paths, tunnels or intervening 'dark' |
23 | + * switches. | ||
23 | */ | 24 | */ |
24 | INDIRECT | 25 | INDIRECT |
25 | } | 26 | } | ... | ... |
1 | package org.onlab.onos.net.device; | 1 | package org.onlab.onos.net.device; |
2 | 2 | ||
3 | +import org.onlab.onos.net.DeviceId; | ||
3 | import org.onlab.onos.net.MastershipRole; | 4 | import org.onlab.onos.net.MastershipRole; |
4 | import org.onlab.onos.net.provider.ProviderService; | 5 | import org.onlab.onos.net.provider.ProviderService; |
5 | 6 | ||
... | @@ -19,28 +20,31 @@ public interface DeviceProviderService extends ProviderService<DeviceProvider> { | ... | @@ -19,28 +20,31 @@ public interface DeviceProviderService extends ProviderService<DeviceProvider> { |
19 | * @param deviceDescription information about network device | 20 | * @param deviceDescription information about network device |
20 | * @return mastership role chosen by the provider service | 21 | * @return mastership role chosen by the provider service |
21 | */ | 22 | */ |
22 | - MastershipRole deviceConnected(DeviceDescription deviceDescription); | 23 | + MastershipRole deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription); |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * Signals the core that a device has disconnected or is no longer reachable. | 26 | * Signals the core that a device has disconnected or is no longer reachable. |
26 | * | 27 | * |
27 | - * @param deviceDescription device to be removed | 28 | + * @param deviceId identity of the device to be removed |
28 | */ | 29 | */ |
29 | - void deviceDisconnected(DeviceDescription deviceDescription); | 30 | + void deviceDisconnected(DeviceId deviceId); |
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Sends information about all ports of a device. It is up to the core to | 33 | * Sends information about all ports of a device. It is up to the core to |
33 | * determine what has changed. | 34 | * determine what has changed. |
35 | + * <p/> | ||
34 | * | 36 | * |
37 | + * @param deviceId identity of the device | ||
35 | * @param ports list of device ports | 38 | * @param ports list of device ports |
36 | */ | 39 | */ |
37 | - void updatePorts(List<PortDescription> ports); | 40 | + void updatePorts(DeviceId deviceId, List<PortDescription> ports); |
38 | 41 | ||
39 | /** | 42 | /** |
40 | * Used to notify the core about port status change of a single port. | 43 | * Used to notify the core about port status change of a single port. |
41 | * | 44 | * |
45 | + * @param deviceId identity of the device | ||
42 | * @param port description of the port that changed | 46 | * @param port description of the port that changed |
43 | */ | 47 | */ |
44 | - void portStatusChanged(PortDescription port); | 48 | + void portStatusChanged(DeviceId deviceId, PortDescription port); |
45 | 49 | ||
46 | } | 50 | } | ... | ... |
1 | +package org.onlab.onos.net.impl; | ||
2 | + | ||
3 | +import org.apache.felix.scr.annotations.Activate; | ||
4 | +import org.apache.felix.scr.annotations.Component; | ||
5 | +import org.apache.felix.scr.annotations.Deactivate; | ||
6 | +import org.apache.felix.scr.annotations.Service; | ||
7 | +import org.onlab.onos.net.DeviceId; | ||
8 | +import org.onlab.onos.net.MastershipRole; | ||
9 | +import org.onlab.onos.net.device.DeviceDescription; | ||
10 | +import org.onlab.onos.net.device.DeviceProvider; | ||
11 | +import org.onlab.onos.net.device.DeviceProviderBroker; | ||
12 | +import org.onlab.onos.net.device.DeviceProviderService; | ||
13 | +import org.onlab.onos.net.device.PortDescription; | ||
14 | +import org.onlab.onos.net.provider.AbstractProviderBroker; | ||
15 | +import org.onlab.onos.net.provider.AbstractProviderService; | ||
16 | +import org.slf4j.Logger; | ||
17 | +import org.slf4j.LoggerFactory; | ||
18 | + | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +/** | ||
22 | + * Provides basic implementation of the device SB & NB APIs. | ||
23 | + */ | ||
24 | +@Component(immediate = true) | ||
25 | +@Service | ||
26 | +public class SimpleDeviceManager implements DeviceProviderBroker { | ||
27 | + | ||
28 | + private Logger log = LoggerFactory.getLogger(SimpleDeviceManager.class); | ||
29 | + | ||
30 | + private final DeviceProviderBroker broker = new InternalBroker(); | ||
31 | + | ||
32 | + @Activate | ||
33 | + public void activate() { | ||
34 | + log.info("Started"); | ||
35 | + } | ||
36 | + | ||
37 | + @Deactivate | ||
38 | + public void deactivate() { | ||
39 | + log.info("Stopped"); | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public DeviceProviderService register(DeviceProvider provider) { | ||
44 | + return broker.register(provider); | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public void unregister(DeviceProvider provider) { | ||
49 | + broker.unregister(provider); | ||
50 | + } | ||
51 | + | ||
52 | + // Internal delegate for tracking various providers and issuing them a | ||
53 | + // personalized provider service. | ||
54 | + private class InternalBroker extends AbstractProviderBroker<DeviceProvider, DeviceProviderService> | ||
55 | + implements DeviceProviderBroker { | ||
56 | + @Override | ||
57 | + protected DeviceProviderService createProviderService(DeviceProvider provider) { | ||
58 | + return new InternalDeviceProviderService(provider); | ||
59 | + } | ||
60 | + } | ||
61 | + | ||
62 | + // Personalized device provider service issued to the supplied provider. | ||
63 | + private class InternalDeviceProviderService extends AbstractProviderService<DeviceProvider> | ||
64 | + implements DeviceProviderService { | ||
65 | + | ||
66 | + public InternalDeviceProviderService(DeviceProvider provider) { | ||
67 | + super(provider); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public MastershipRole deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { | ||
72 | + log.info("Device {} connected: {}", deviceId, deviceDescription); | ||
73 | + return MastershipRole.MASTER; | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public void deviceDisconnected(DeviceId deviceId) { | ||
78 | + log.info("Device {} disconnected", deviceId); | ||
79 | + | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public void updatePorts(DeviceId deviceId, List<PortDescription> ports) { | ||
84 | + // FIXME: fix the interface to accept DeviceId separately | ||
85 | + log.info("Device {} ports updated: {}", ports); | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public void portStatusChanged(DeviceId deviceId, PortDescription port) { | ||
91 | + log.info("Device {} port status changed: {}", deviceId, port); | ||
92 | + } | ||
93 | + } | ||
94 | +} |
-
Please register or login to post a comment