Committed by
Gerrit Code Review
Add hasBehaviour to DriverHandler
Change-Id: I2bcfb06795b923de4356937a0baee35b37c7d979
Showing
3 changed files
with
16 additions
and
33 deletions
| ... | @@ -92,7 +92,7 @@ public interface Driver extends Annotations { | ... | @@ -92,7 +92,7 @@ public interface Driver extends Annotations { |
| 92 | 92 | ||
| 93 | /** | 93 | /** |
| 94 | * Indicates whether or not the driver, or any of its parents, support | 94 | * Indicates whether or not the driver, or any of its parents, support |
| 95 | - * the specified class of behaviour. It | 95 | + * the specified class of behaviour. |
| 96 | * | 96 | * |
| 97 | * @param behaviourClass behaviour class | 97 | * @param behaviourClass behaviour class |
| 98 | * @return true if behaviour is supported | 98 | * @return true if behaviour is supported | ... | ... |
| ... | @@ -44,6 +44,17 @@ public interface DriverHandler { | ... | @@ -44,6 +44,17 @@ public interface DriverHandler { |
| 44 | <T extends Behaviour> T behaviour(Class<T> behaviourClass); | 44 | <T extends Behaviour> T behaviour(Class<T> behaviourClass); |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | + * Indicates whether or not the driver, or any of its parents, support | ||
| 48 | + * the specified class of behaviour. | ||
| 49 | + * | ||
| 50 | + * @param behaviourClass behaviour class | ||
| 51 | + * @return true if behaviour is supported | ||
| 52 | + */ | ||
| 53 | + default boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) { | ||
| 54 | + return driver().hasBehaviour(behaviourClass); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 47 | * Returns the reference to the implementation of the specified service. | 58 | * Returns the reference to the implementation of the specified service. |
| 48 | * Provides access to run-time context. | 59 | * Provides access to run-time context. |
| 49 | * | 60 | * | ... | ... |
| ... | @@ -32,7 +32,6 @@ import org.onosproject.net.behaviour.VlanQuery; | ... | @@ -32,7 +32,6 @@ import org.onosproject.net.behaviour.VlanQuery; |
| 32 | import org.onosproject.net.device.DeviceEvent; | 32 | import org.onosproject.net.device.DeviceEvent; |
| 33 | import org.onosproject.net.device.DeviceListener; | 33 | import org.onosproject.net.device.DeviceListener; |
| 34 | import org.onosproject.net.device.DeviceService; | 34 | import org.onosproject.net.device.DeviceService; |
| 35 | -import org.onosproject.net.driver.Driver; | ||
| 36 | import org.onosproject.net.driver.DriverHandler; | 35 | import org.onosproject.net.driver.DriverHandler; |
| 37 | import org.onosproject.net.driver.DriverService; | 36 | import org.onosproject.net.driver.DriverService; |
| 38 | import org.onosproject.net.newresource.ResourceAdminService; | 37 | import org.onosproject.net.newresource.ResourceAdminService; |
| ... | @@ -162,14 +161,8 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -162,14 +161,8 @@ final class ResourceDeviceListener implements DeviceListener { |
| 162 | 161 | ||
| 163 | private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) { | 162 | private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) { |
| 164 | try { | 163 | try { |
| 165 | - // DriverHandler does not provide a way to check if a | ||
| 166 | - // behaviour is supported. | ||
| 167 | - Driver driver = driverService.getDriver(did); | ||
| 168 | - if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) { | ||
| 169 | - return Collections.emptySet(); | ||
| 170 | - } | ||
| 171 | DriverHandler handler = driverService.createHandler(did); | 164 | DriverHandler handler = driverService.createHandler(did); |
| 172 | - if (handler == null) { | 165 | + if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) { |
| 173 | return Collections.emptySet(); | 166 | return Collections.emptySet(); |
| 174 | } | 167 | } |
| 175 | LambdaQuery query = handler.behaviour(LambdaQuery.class); | 168 | LambdaQuery query = handler.behaviour(LambdaQuery.class); |
| ... | @@ -187,16 +180,8 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -187,16 +180,8 @@ final class ResourceDeviceListener implements DeviceListener { |
| 187 | 180 | ||
| 188 | private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) { | 181 | private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) { |
| 189 | try { | 182 | try { |
| 190 | - // DriverHandler does not provide a way to check if a | ||
| 191 | - // behaviour is supported. | ||
| 192 | - Driver driver = driverService.getDriver(device); | ||
| 193 | - if (driver == null || !driver.hasBehaviour(VlanQuery.class)) { | ||
| 194 | - // device does not support this | ||
| 195 | - return ImmutableSet.of(); | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | DriverHandler handler = driverService.createHandler(device); | 183 | DriverHandler handler = driverService.createHandler(device); |
| 199 | - if (handler == null) { | 184 | + if (handler == null || !handler.hasBehaviour(VlanQuery.class)) { |
| 200 | return ImmutableSet.of(); | 185 | return ImmutableSet.of(); |
| 201 | } | 186 | } |
| 202 | 187 | ||
| ... | @@ -212,15 +197,8 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -212,15 +197,8 @@ final class ResourceDeviceListener implements DeviceListener { |
| 212 | 197 | ||
| 213 | private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) { | 198 | private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) { |
| 214 | try { | 199 | try { |
| 215 | - // DriverHandler does not provide a way to check if a | ||
| 216 | - // behaviour is supported. | ||
| 217 | - Driver driver = driverService.getDriver(device); | ||
| 218 | - if (driver == null || !driver.hasBehaviour(MplsQuery.class)) { | ||
| 219 | - // device does not support this | ||
| 220 | - return ImmutableSet.of(); | ||
| 221 | - } | ||
| 222 | DriverHandler handler = driverService.createHandler(device); | 200 | DriverHandler handler = driverService.createHandler(device); |
| 223 | - if (handler == null) { | 201 | + if (handler == null || !handler.hasBehaviour(MplsQuery.class)) { |
| 224 | return ImmutableSet.of(); | 202 | return ImmutableSet.of(); |
| 225 | } | 203 | } |
| 226 | 204 | ||
| ... | @@ -236,14 +214,8 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -236,14 +214,8 @@ final class ResourceDeviceListener implements DeviceListener { |
| 236 | 214 | ||
| 237 | private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) { | 215 | private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) { |
| 238 | try { | 216 | try { |
| 239 | - // DriverHandler does not provide a way to check if a | ||
| 240 | - // behaviour is supported. | ||
| 241 | - Driver driver = driverService.getDriver(device); | ||
| 242 | - if (driver == null || !driver.hasBehaviour(TributarySlotQuery.class)) { | ||
| 243 | - return Collections.emptySet(); | ||
| 244 | - } | ||
| 245 | DriverHandler handler = driverService.createHandler(device); | 217 | DriverHandler handler = driverService.createHandler(device); |
| 246 | - if (handler == null) { | 218 | + if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) { |
| 247 | return Collections.emptySet(); | 219 | return Collections.emptySet(); |
| 248 | } | 220 | } |
| 249 | TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class); | 221 | TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class); | ... | ... |
-
Please register or login to post a comment