Cleaning up and enhancing driver subsystem and the flow objective subsystem.

Change-Id: Ica600ef1aaa46d19e764cd7a197454a4e0f85a08
diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
index 8b55fa3..4e9c6e4 100644
--- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
+++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
@@ -50,6 +50,11 @@
     public static final String PROTOCOL = "protocol";
 
     /**
+     * Annotation key for the device driver name.
+     */
+    public static final String DRIVER = "driver";
+
+    /**
      * Annotation key for durable links.
      */
     public static final String DURABLE = "durable";
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/Pipeliner.java b/core/api/src/main/java/org/onosproject/net/behaviour/Pipeliner.java
index c4700fc..eda131a 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/Pipeliner.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/Pipeliner.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.net.behaviour;
 
-import org.onlab.osgi.ServiceDirectory;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.driver.HandlerBehaviour;
 import org.onosproject.net.flowobjective.FilteringObjective;
@@ -31,20 +30,20 @@
 public interface Pipeliner extends HandlerBehaviour {
 
     /**
-     * Injecting the service directory into the driver.
+     * Initializes the driver with context required for its operation.
      *
      * @param deviceId the deviceId
-     * @param serviceDirectory the service directory.
+     * @param context  processing context
      */
-    void init(DeviceId deviceId, ServiceDirectory serviceDirectory);
+    void init(DeviceId deviceId, PipelinerContext context);
 
     /**
      * Installs the filtering rules onto the device.
      *
-     * @param filteringObjectives the collection of filters
+     * @param filterObjectives the collection of filters
      * @return a future indicating the success of the operation
      */
-     Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives);
+    Future<Boolean> filter(Collection<FilteringObjective> filterObjectives);
 
     /**
      * Installs the forwarding rules onto the device.
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/PipelinerContext.java b/core/api/src/main/java/org/onosproject/net/behaviour/PipelinerContext.java
new file mode 100644
index 0000000..c2c6dfd
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/PipelinerContext.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.behaviour;
+
+import org.onlab.osgi.ServiceDirectory;
+
+/**
+ * Processing context and supporting services for the pipeline behaviour.
+ */
+public interface PipelinerContext {
+
+    /**
+     * Returns the service directory which can be used to obtain references
+     * to various supporting services.
+     *
+     * @return service directory
+     */
+    ServiceDirectory directory();
+
+    // TODO: add means to store and access shared state
+}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
index e83afe8..0d9ad9a 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverData.java
@@ -29,27 +29,27 @@
  */
 public class DefaultDriverData implements DriverData {
 
-    private final Driver type;
+    private final Driver driver;
     private final Map<String, String> properties;
 
     /**
      * Creates new driver data.
      *
-     * @param type parent driver type
+     * @param driver parent driver type
      */
-    public DefaultDriverData(Driver type) {
-        this.type = type;
+    public DefaultDriverData(Driver driver) {
+        this.driver = driver;
         this.properties = new HashMap<>();
     }
 
     @Override
-    public Driver type() {
-        return type;
+    public Driver driver() {
+        return driver;
     }
 
     @Override
     public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
-        return type.createBehaviour(this, behaviourClass, false);
+        return driver.createBehaviour(this, behaviourClass, false);
     }
 
     @Override
@@ -83,7 +83,7 @@
     @Override
     public String toString() {
         return toStringHelper(this)
-                .add("type", type)
+                .add("type", driver)
                 .add("properties", properties)
                 .toString();
     }
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
index 247ccec..38ee3d5 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DefaultDriverHandler.java
@@ -34,13 +34,18 @@
     }
 
     @Override
+    public Driver driver() {
+        return data.driver();
+    }
+
+    @Override
     public DriverData data() {
         return data;
     }
 
     @Override
     public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
-        return data.type().createBehaviour(this.data, behaviourClass, true);
+        return data.driver().createBehaviour(this.data, behaviourClass, true);
     }
 
     @Override
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverData.java b/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
index ff4d622..4cf7093 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverData.java
@@ -28,7 +28,7 @@
      *
      * @return device driver
      */
-    Driver type();
+    Driver driver();
 
     /**
      * Returns the specified facet of behaviour to access the device data.
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 0fb46aa..6e8a354 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
@@ -21,6 +21,13 @@
 public interface DriverHandler {
 
     /**
+     * Returns the parent device driver.
+     *
+     * @return device driver
+     */
+    Driver driver();
+
+    /**
      * Returns the device driver data.
      *
      * @return device driver data
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverService.java b/core/api/src/main/java/org/onosproject/net/driver/DriverService.java
index 5d6d464..ffb7c93 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverService.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverService.java
@@ -38,6 +38,8 @@
      *
      * @param driverName driver name
      * @return driver
+     * @throws org.onlab.util.ItemNotFoundException if driver with the given
+     *                                              name is not found
      */
     Driver getDriver(String driverName);
 
@@ -53,25 +55,33 @@
     Driver getDriver(String mfr, String hw, String sw);
 
     /**
-     * Creates a new driver handler for the specified driver.
+     * Returns the driver for the specified device. If the device carries
+     * {@code driver} annotation, its value is used to look-up the driver.
+     * Otherwise, the device manufacturer, hardware and software version
+     * attributes are used to look-up the driver. First using their literal
+     * values and if no driver is found, using ERE matching against the
+     * driver manufacturer, hardware and software version fields.
      *
-     * @param driverName  driver name
-     * @param deviceId    device identifier
-     * @param credentials optional login credentials in string form
-     * @return driver handler
+     * @param deviceId device identifier
+     * @return driver or null of no matching one is found
+     * @throws org.onlab.util.ItemNotFoundException if device or driver for it
+     *                                              are not found
      */
-    DriverHandler createHandler(String driverName, DeviceId deviceId,
-                                String... credentials);
+    Driver getDriver(DeviceId deviceId);
 
     /**
-     * Creates a new driver handler for the specified driver data.
+     * Creates a new driver handler for interacting with the specified device.
+     * The driver is looked-up using the same semantics as
+     * {@link #getDriver(DeviceId)} method.
      *
-     * @param data        driver data
      * @param deviceId    device identifier
      * @param credentials optional login credentials in string form
      * @return driver handler
+     * @throws org.onlab.util.ItemNotFoundException if device or driver for it
+     *                                              are not found
      */
-    DriverHandler createHandler(DriverData data, DeviceId deviceId,
-                                String... credentials);
+    DriverHandler createHandler(DeviceId deviceId, String... credentials);
+
+    // TODO: Devise a mechanism for retaining DriverData for devices
 
 }
diff --git a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
index dc5e5e1..14af2b8 100644
--- a/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
+++ b/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java
@@ -21,14 +21,36 @@
 import java.util.concurrent.Future;
 
 /**
- * Created by ash on 07/04/15.
+ * Service for programming data plane flow rules in manner independent of
+ * specific device table pipeline configuration.
  */
 public interface FlowObjectiveService {
 
-    Future<Boolean> filter(DeviceId deviceId, Collection<FilteringObjective> filterObjectives);
+    /**
+     * Installs the filtering rules onto the specified device.
+     *
+     * @param deviceId            device identifier
+     * @param filteringObjectives the collection of filters
+     * @return a future indicating the success of the operation
+     */
+    Future<Boolean> filter(DeviceId deviceId, Collection<FilteringObjective> filteringObjectives);
 
+    /**
+     * Installs the forwarding rules onto the specified device.
+     *
+     * @param deviceId             device identifier
+     * @param forwardingObjectives the collection of forwarding objectives
+     * @return a future indicating the success of the operation
+     */
     Future<Boolean> forward(DeviceId deviceId, Collection<ForwardingObjective> forwardingObjectives);
 
+    /**
+     * Installs the next hop elements into the specified device.
+     *
+     * @param deviceId       device identifier
+     * @param nextObjectives the collection of next objectives
+     * @return a future indicating the success of the operation
+     */
     Future<Boolean> next(DeviceId deviceId, Collection<NextObjective> nextObjectives);
 
 }
diff --git a/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java b/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java
new file mode 100644
index 0000000..65454a7
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Abstractions for objective-based flow programming of data plane without
+ * requiring device pipeline structure awareness.
+ */
+package org.onosproject.net.flowobjective;
\ No newline at end of file