Add hasBehaviour to DriverHandler

Change-Id: I2bcfb06795b923de4356937a0baee35b37c7d979
diff --git a/core/api/src/main/java/org/onosproject/net/driver/Driver.java b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
index 3dc0fdb0..afb6ae6 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/Driver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
@@ -92,7 +92,7 @@
 
     /**
      * Indicates whether or not the driver, or any of its parents, support
-     * the specified class of behaviour. It
+     * the specified class of behaviour.
      *
      * @param behaviourClass behaviour class
      * @return true if behaviour is supported
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java b/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
index 202708b..723e692 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverHandler.java
@@ -44,6 +44,17 @@
     <T extends Behaviour> T behaviour(Class<T> behaviourClass);
 
     /**
+     * Indicates whether or not the driver, or any of its parents, support
+     * the specified class of behaviour.
+     *
+     * @param behaviourClass behaviour class
+     * @return true if behaviour is supported
+     */
+    default boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) {
+        return driver().hasBehaviour(behaviourClass);
+    }
+
+    /**
      * Returns the reference to the implementation of the specified service.
      * Provides access to run-time context.
      *
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
index 9494cbe..b9b11dc 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
@@ -32,7 +32,6 @@
 import org.onosproject.net.device.DeviceEvent;
 import org.onosproject.net.device.DeviceListener;
 import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.Driver;
 import org.onosproject.net.driver.DriverHandler;
 import org.onosproject.net.driver.DriverService;
 import org.onosproject.net.newresource.ResourceAdminService;
@@ -162,14 +161,8 @@
 
     private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
         try {
-            // DriverHandler does not provide a way to check if a
-            // behaviour is supported.
-            Driver driver = driverService.getDriver(did);
-            if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) {
-                return Collections.emptySet();
-            }
             DriverHandler handler = driverService.createHandler(did);
-            if (handler == null) {
+            if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) {
                 return Collections.emptySet();
             }
             LambdaQuery query = handler.behaviour(LambdaQuery.class);
@@ -187,16 +180,8 @@
 
     private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) {
         try {
-            // DriverHandler does not provide a way to check if a
-            // behaviour is supported.
-            Driver driver = driverService.getDriver(device);
-            if (driver == null || !driver.hasBehaviour(VlanQuery.class)) {
-                // device does not support this
-                return ImmutableSet.of();
-            }
-
             DriverHandler handler = driverService.createHandler(device);
-            if (handler == null) {
+            if (handler == null || !handler.hasBehaviour(VlanQuery.class)) {
                 return ImmutableSet.of();
             }
 
@@ -212,15 +197,8 @@
 
     private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
         try {
-            // DriverHandler does not provide a way to check if a
-            // behaviour is supported.
-            Driver driver = driverService.getDriver(device);
-            if (driver == null || !driver.hasBehaviour(MplsQuery.class)) {
-                // device does not support this
-                return ImmutableSet.of();
-            }
             DriverHandler handler = driverService.createHandler(device);
-            if (handler == null) {
+            if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
                 return ImmutableSet.of();
             }
 
@@ -236,14 +214,8 @@
 
     private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) {
         try {
-            // DriverHandler does not provide a way to check if a
-            // behaviour is supported.
-            Driver driver = driverService.getDriver(device);
-            if (driver == null || !driver.hasBehaviour(TributarySlotQuery.class)) {
-                return Collections.emptySet();
-            }
             DriverHandler handler = driverService.createHandler(device);
-            if (handler == null) {
+            if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) {
                 return Collections.emptySet();
             }
             TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class);