Committed by
Gerrit Code Review
[Emu] new ResourceService related bug fixes
- ResourceDeviceListener should also react to availability events. - Should check if device supports the behavior before retrieving Behaviour class - ResourceManager should unregister when requested - opticalUtils was specifying wrong driver name. Should've been "linc-oe" Change-Id: I9364b6307cb537b04b57ac00f2451c13e3379471
Showing
6 changed files
with
56 additions
and
5 deletions
... | @@ -35,7 +35,7 @@ public class ResourceAllocation { | ... | @@ -35,7 +35,7 @@ public class ResourceAllocation { |
35 | * Creates an instance with the specified subject, resource and consumer. | 35 | * Creates an instance with the specified subject, resource and consumer. |
36 | * | 36 | * |
37 | * @param resource resource of the subject | 37 | * @param resource resource of the subject |
38 | - * @param consumer consumer ot this resource | 38 | + * @param consumer consumer of this resource |
39 | */ | 39 | */ |
40 | public ResourceAllocation(ResourcePath resource, ResourceConsumer consumer) { | 40 | public ResourceAllocation(ResourcePath resource, ResourceConsumer consumer) { |
41 | this.resource = checkNotNull(resource); | 41 | this.resource = checkNotNull(resource); | ... | ... |
... | @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate; |
24 | import org.apache.felix.scr.annotations.Reference; | 24 | import org.apache.felix.scr.annotations.Reference; |
25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
26 | import org.apache.felix.scr.annotations.Service; | 26 | import org.apache.felix.scr.annotations.Service; |
27 | +import org.onlab.util.ItemNotFoundException; | ||
27 | import org.onosproject.net.Device; | 28 | import org.onosproject.net.Device; |
28 | import org.onosproject.net.DeviceId; | 29 | import org.onosproject.net.DeviceId; |
29 | import org.onosproject.net.device.DeviceService; | 30 | import org.onosproject.net.device.DeviceService; |
... | @@ -166,8 +167,13 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS | ... | @@ -166,8 +167,13 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS |
166 | Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE); | 167 | Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE); |
167 | String driverName = device.annotations().value(DRIVER); | 168 | String driverName = device.annotations().value(DRIVER); |
168 | if (driverName != null) { | 169 | if (driverName != null) { |
170 | + try { | ||
169 | return getDriver(driverName); | 171 | return getDriver(driverName); |
172 | + } catch (ItemNotFoundException e) { | ||
173 | + log.warn("Specified driver {} not found, falling back.", driverName); | ||
170 | } | 174 | } |
175 | + } | ||
176 | + | ||
171 | return nullIsNotFound(getDriver(device.manufacturer(), | 177 | return nullIsNotFound(getDriver(device.manufacturer(), |
172 | device.hwVersion(), device.swVersion()), | 178 | device.hwVersion(), device.swVersion()), |
173 | NO_DRIVER); | 179 | NO_DRIVER); | ... | ... |
... | @@ -32,6 +32,8 @@ import org.onosproject.net.behaviour.MplsQuery; | ... | @@ -32,6 +32,8 @@ import org.onosproject.net.behaviour.MplsQuery; |
32 | import org.onosproject.net.behaviour.VlanQuery; | 32 | import org.onosproject.net.behaviour.VlanQuery; |
33 | import org.onosproject.net.device.DeviceEvent; | 33 | import org.onosproject.net.device.DeviceEvent; |
34 | import org.onosproject.net.device.DeviceListener; | 34 | import org.onosproject.net.device.DeviceListener; |
35 | +import org.onosproject.net.device.DeviceService; | ||
36 | +import org.onosproject.net.driver.Driver; | ||
35 | import org.onosproject.net.driver.DriverHandler; | 37 | import org.onosproject.net.driver.DriverHandler; |
36 | import org.onosproject.net.driver.DriverService; | 38 | import org.onosproject.net.driver.DriverService; |
37 | import org.onosproject.net.newresource.ResourceAdminService; | 39 | import org.onosproject.net.newresource.ResourceAdminService; |
... | @@ -67,18 +69,22 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -67,18 +69,22 @@ final class ResourceDeviceListener implements DeviceListener { |
67 | private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); | 69 | private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); |
68 | 70 | ||
69 | private final ResourceAdminService adminService; | 71 | private final ResourceAdminService adminService; |
72 | + private final DeviceService deviceService; | ||
70 | private final DriverService driverService; | 73 | private final DriverService driverService; |
71 | private final ExecutorService executor; | 74 | private final ExecutorService executor; |
72 | 75 | ||
76 | + | ||
73 | /** | 77 | /** |
74 | * Creates an instance with the specified ResourceAdminService and ExecutorService. | 78 | * Creates an instance with the specified ResourceAdminService and ExecutorService. |
75 | * | 79 | * |
76 | * @param adminService instance invoked to register resources | 80 | * @param adminService instance invoked to register resources |
81 | + * @param deviceService {@link DeviceService} to be used. | ||
77 | * @param executor executor used for processing resource registration | 82 | * @param executor executor used for processing resource registration |
78 | */ | 83 | */ |
79 | - ResourceDeviceListener(ResourceAdminService adminService, DriverService driverService, | 84 | + ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService, |
80 | ExecutorService executor) { | 85 | ExecutorService executor) { |
81 | this.adminService = checkNotNull(adminService); | 86 | this.adminService = checkNotNull(adminService); |
87 | + this.deviceService = checkNotNull(deviceService); | ||
82 | this.driverService = checkNotNull(driverService); | 88 | this.driverService = checkNotNull(driverService); |
83 | this.executor = checkNotNull(executor); | 89 | this.executor = checkNotNull(executor); |
84 | } | 90 | } |
... | @@ -93,8 +99,21 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -93,8 +99,21 @@ final class ResourceDeviceListener implements DeviceListener { |
93 | case DEVICE_REMOVED: | 99 | case DEVICE_REMOVED: |
94 | unregisterDeviceResource(device); | 100 | unregisterDeviceResource(device); |
95 | break; | 101 | break; |
102 | + case DEVICE_AVAILABILITY_CHANGED: | ||
103 | + if (deviceService.isAvailable(device.id())) { | ||
104 | + registerDeviceResource(device); | ||
105 | + // TODO: do we need to walk the ports? | ||
106 | + } else { | ||
107 | + unregisterDeviceResource(device); | ||
108 | + } | ||
109 | + break; | ||
96 | case PORT_ADDED: | 110 | case PORT_ADDED: |
111 | + case PORT_UPDATED: | ||
112 | + if (event.port().isEnabled()) { | ||
97 | registerPortResource(device, event.port()); | 113 | registerPortResource(device, event.port()); |
114 | + } else { | ||
115 | + unregisterPortResource(device, event.port()); | ||
116 | + } | ||
98 | break; | 117 | break; |
99 | case PORT_REMOVED: | 118 | case PORT_REMOVED: |
100 | unregisterPortResource(device, event.port()); | 119 | unregisterPortResource(device, event.port()); |
... | @@ -168,12 +187,22 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -168,12 +187,22 @@ final class ResourceDeviceListener implements DeviceListener { |
168 | 187 | ||
169 | private SortedSet<OchSignal> queryLambdas(DeviceId did, PortNumber port) { | 188 | private SortedSet<OchSignal> queryLambdas(DeviceId did, PortNumber port) { |
170 | try { | 189 | try { |
190 | + // DriverHandler does not provide a way to check if a | ||
191 | + // behaviour is supported. | ||
192 | + Driver driver = driverService.getDriver(did); | ||
193 | + if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) { | ||
194 | + return Collections.emptySortedSet(); | ||
195 | + } | ||
171 | DriverHandler handler = driverService.createHandler(did); | 196 | DriverHandler handler = driverService.createHandler(did); |
172 | if (handler == null) { | 197 | if (handler == null) { |
173 | return Collections.emptySortedSet(); | 198 | return Collections.emptySortedSet(); |
174 | } | 199 | } |
175 | LambdaQuery query = handler.behaviour(LambdaQuery.class); | 200 | LambdaQuery query = handler.behaviour(LambdaQuery.class); |
201 | + if (query != null) { | ||
176 | return query.queryLambdas(port); | 202 | return query.queryLambdas(port); |
203 | + } else { | ||
204 | + return Collections.emptySortedSet(); | ||
205 | + } | ||
177 | } catch (ItemNotFoundException e) { | 206 | } catch (ItemNotFoundException e) { |
178 | return Collections.emptySortedSet(); | 207 | return Collections.emptySortedSet(); |
179 | } | 208 | } |
... | @@ -181,6 +210,14 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -181,6 +210,14 @@ final class ResourceDeviceListener implements DeviceListener { |
181 | 210 | ||
182 | private boolean isVlanEnabled(DeviceId device, PortNumber port) { | 211 | private boolean isVlanEnabled(DeviceId device, PortNumber port) { |
183 | try { | 212 | try { |
213 | + // DriverHandler does not provide a way to check if a | ||
214 | + // behaviour is supported. | ||
215 | + Driver driver = driverService.getDriver(device); | ||
216 | + if (driver == null || !driver.hasBehaviour(VlanQuery.class)) { | ||
217 | + // device does not support this | ||
218 | + return false; | ||
219 | + } | ||
220 | + | ||
184 | DriverHandler handler = driverService.createHandler(device); | 221 | DriverHandler handler = driverService.createHandler(device); |
185 | if (handler == null) { | 222 | if (handler == null) { |
186 | return false; | 223 | return false; |
... | @@ -195,6 +232,13 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -195,6 +232,13 @@ final class ResourceDeviceListener implements DeviceListener { |
195 | 232 | ||
196 | private boolean isMplsEnabled(DeviceId device, PortNumber port) { | 233 | private boolean isMplsEnabled(DeviceId device, PortNumber port) { |
197 | try { | 234 | try { |
235 | + // DriverHandler does not provide a way to check if a | ||
236 | + // behaviour is supported. | ||
237 | + Driver driver = driverService.getDriver(device); | ||
238 | + if (driver == null || !driver.hasBehaviour(MplsQuery.class)) { | ||
239 | + // device does not support this | ||
240 | + return false; | ||
241 | + } | ||
198 | DriverHandler handler = driverService.createHandler(device); | 242 | DriverHandler handler = driverService.createHandler(device); |
199 | if (handler == null) { | 243 | if (handler == null) { |
200 | return false; | 244 | return false; | ... | ... |
... | @@ -172,7 +172,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent | ... | @@ -172,7 +172,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent |
172 | public boolean unregisterResources(List<ResourcePath> resources) { | 172 | public boolean unregisterResources(List<ResourcePath> resources) { |
173 | checkNotNull(resources); | 173 | checkNotNull(resources); |
174 | 174 | ||
175 | - return store.register(resources); | 175 | + return store.unregister(resources); |
176 | } | 176 | } |
177 | 177 | ||
178 | private class InternalStoreDelegate implements ResourceStoreDelegate { | 178 | private class InternalStoreDelegate implements ResourceStoreDelegate { | ... | ... |
... | @@ -53,12 +53,13 @@ public final class ResourceRegistrar { | ... | @@ -53,12 +53,13 @@ public final class ResourceRegistrar { |
53 | 53 | ||
54 | @Activate | 54 | @Activate |
55 | public void activate() { | 55 | public void activate() { |
56 | - deviceListener = new ResourceDeviceListener(adminService, driverService, executor); | 56 | + deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor); |
57 | deviceService.addListener(deviceListener); | 57 | deviceService.addListener(deviceListener); |
58 | } | 58 | } |
59 | 59 | ||
60 | @Deactivate | 60 | @Deactivate |
61 | public void deactivate() { | 61 | public void deactivate() { |
62 | deviceService.removeListener(deviceListener); | 62 | deviceService.removeListener(deviceListener); |
63 | + executor.shutdownNow(); | ||
63 | } | 64 | } |
64 | } | 65 | } | ... | ... |
... | @@ -197,7 +197,7 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -197,7 +197,7 @@ class LINCSwitch(OpticalSwitch): |
197 | self.configDict[ 'uri' ] = 'of:' + self.dpid | 197 | self.configDict[ 'uri' ] = 'of:' + self.dpid |
198 | self.configDict[ 'annotations' ] = self.annotations | 198 | self.configDict[ 'annotations' ] = self.annotations |
199 | self.configDict[ 'annotations' ].setdefault('name', self.name) | 199 | self.configDict[ 'annotations' ].setdefault('name', self.name) |
200 | - self.configDict[ 'hw' ] = 'LINC-OE' | 200 | + self.configDict[ 'hw' ] = 'linc-oe' |
201 | self.configDict[ 'mfr' ] = 'Linc' | 201 | self.configDict[ 'mfr' ] = 'Linc' |
202 | self.configDict[ 'mac' ] = 'ffffffffffff' + self.dpid[-2] + self.dpid[-1] | 202 | self.configDict[ 'mac' ] = 'ffffffffffff' + self.dpid[-2] + self.dpid[-1] |
203 | self.configDict[ 'type' ] = self.switchType | 203 | self.configDict[ 'type' ] = self.switchType | ... | ... |
-
Please register or login to post a comment