Added basic driver configuration for various HP product families.

Change-Id: Ifab3b5dba544e8f4117190a40dd062ccc5a1f19e
diff --git a/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineOld.java b/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineOld.java
new file mode 100644
index 0000000..6b82e6a
--- /dev/null
+++ b/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineOld.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * 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.drivers.hp;
+
+
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.NextGroup;
+import org.onosproject.net.behaviour.Pipeliner;
+import org.onosproject.net.behaviour.PipelinerContext;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleOperations;
+import org.onosproject.net.flow.FlowRuleOperationsContext;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flowobjective.FilteringObjective;
+import org.onosproject.net.flowobjective.FlowObjectiveStore;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.flowobjective.ObjectiveError;
+
+import org.slf4j.Logger;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ *  Driver for Hp. Default table starts from 200.
+ */
+public class HPPipelineOld extends AbstractHandlerBehaviour implements Pipeliner {
+
+
+    private final Logger log = getLogger(getClass());
+
+    private ServiceDirectory serviceDirectory;
+    private FlowRuleService flowRuleService;
+    private CoreService coreService;
+    private DeviceId deviceId;
+    private ApplicationId appId;
+    protected FlowObjectiveStore flowObjectiveStore;
+
+    //FIXME: hp table numbers are configurable . Set this parameter configurable
+    private static final int SOFTWARE_TABLE_START = 200;
+    private static final int TIME_OUT = 30;
+
+    @Override
+    public void init(DeviceId deviceId, PipelinerContext context) {
+        log.debug("Initiate HP pipeline");
+        this.serviceDirectory = context.directory();
+        this.deviceId = deviceId;
+
+        flowRuleService = serviceDirectory.get(FlowRuleService.class);
+        coreService = serviceDirectory.get(CoreService.class);
+        flowObjectiveStore = context.store();
+
+        appId = coreService.registerApplication(
+                "org.onosproject.driver.HpPipeline");
+    }
+
+    @Override
+    public void filter(FilteringObjective filter)  {
+        //Do nothing
+    }
+
+    @Override
+    public void forward(ForwardingObjective forwardObjective) {
+
+        Collection<FlowRule> rules;
+        FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
+
+        rules = processForward(forwardObjective);
+
+        switch (forwardObjective.op()) {
+            case ADD:
+                rules.stream()
+                        .filter(Objects::nonNull)
+                        .forEach(flowOpsBuilder::add);
+                break;
+            case REMOVE:
+                rules.stream()
+                        .filter(Objects::nonNull)
+                        .forEach(flowOpsBuilder::remove);
+                break;
+            default:
+                fail(forwardObjective, ObjectiveError.UNKNOWN);
+                log.warn("Unknown forwarding type {}");
+        }
+
+        flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {
+            @Override
+            public void onSuccess(FlowRuleOperations ops) {
+                pass(forwardObjective);
+            }
+
+            @Override
+            public void onError(FlowRuleOperations ops) {
+                fail(forwardObjective, ObjectiveError.FLOWINSTALLATIONFAILED);
+            }
+        }));
+
+    }
+
+    private Collection<FlowRule> processForward(ForwardingObjective fwd) {
+
+        log.debug("Processing forwarding object");
+
+        FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
+                .forDevice(deviceId)
+                .withSelector(fwd.selector())
+                .withTreatment(fwd.treatment())
+                .withPriority(fwd.priority())
+                .fromApp(fwd.appId())
+                .forTable(SOFTWARE_TABLE_START);
+
+        if (fwd.permanent()) {
+            ruleBuilder.makePermanent();
+        } else {
+            ruleBuilder.makeTemporary(TIME_OUT);
+        }
+
+        return Collections.singletonList(ruleBuilder.build());
+    }
+
+
+
+    @Override
+    public void next(NextObjective nextObjective) {
+        // Do nothing
+    }
+
+    @Override
+    public List<String> getNextMappings(NextGroup nextGroup) {
+        // TODO Implementation deferred to vendor
+        return null;
+    }
+
+    private void pass(Objective obj) {
+        obj.context().ifPresent(context -> context.onSuccess(obj));
+    }
+
+    private void fail(Objective obj, ObjectiveError error) {
+        obj.context().ifPresent(context -> context.onError(obj, error));
+    }
+
+
+}
diff --git a/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineV3800.java b/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineV3800.java
index 3eb3aea..9c16815 100644
--- a/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineV3800.java
+++ b/drivers/hp/src/main/java/org/onosproject/drivers/hp/HPPipelineV3800.java
@@ -38,6 +38,7 @@
  * Driver for HP3800 hybrid switches.
  */
 public class HPPipelineV3800 extends AbstractHPPipeline {
+    // FIXME: This class should probably be renamed not to imply it applies for the 3800 series solely.
 
     private static final int HP_TABLE_ZERO = 0;
     private static final int HP_HARDWARE_TABLE = 100;
diff --git a/drivers/hp/src/main/resources/hp-driver.xml b/drivers/hp/src/main/resources/hp-driver.xml
index 7fcb80a..4e67129 100644
--- a/drivers/hp/src/main/resources/hp-driver.xml
+++ b/drivers/hp/src/main/resources/hp-driver.xml
@@ -15,11 +15,47 @@
   ~ limitations under the License.
   -->
 <drivers>
-   <driver name="hp3800"
-            manufacturer="HP" hwVersion="3800-48G-4SFP+ Switch" swVersion="KA.16.03.0003">
+    <driver name="hp-switch">
         <behaviour api="org.onosproject.net.behaviour.Pipeliner"
                    impl="org.onosproject.drivers.hp.HPPipelineV3800"/>
         <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
                    impl="org.onosproject.drivers.hp.HPSwitchHandshaker"/>
     </driver>
+
+    <driver name="hp-2920" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="2920-(24G|48G).* Switch" swVersion=".*"/>
+
+    <driver name="hp-2930" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="2930[FM]-(8G|8SR|24G|40G|48G).* Switch" swVersion=".*"/>
+
+    <driver name="hp-3500" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch 3500.*" swVersion=".*"/>
+
+    <driver name="hp-3800" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="3800-(24G|24SFP|48G).* Switch" swVersion=".*"/>
+
+    <driver name="hp-3810" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="3810M-(16SFP|16SR|24G|24SFP|40G|48G).* Switch" swVersion=".*"/>
+
+    <driver name="hp-5400" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch (5406zl|5412zl)" swVersion=".*"/>
+
+    <driver name="hp-5400R" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch (5406Rzl2|5412Rzl2)" swVersion=".*"/>
+
+    <driver name="hp-6200" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch 6200zl-24G" swVersion=".*"/>
+
+    <driver name="hp-6600" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch (E6600|6600ml|6600).*" swVersion=".*"/>
+
+    <driver name="aruba-7000" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Aruba70(05|08|10|24|30)" swVersion=".*"/>
+
+    <driver name="aruba-7200" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Aruba72(05|10|20|40)" swVersion=".*"/>
+
+    <driver name="hp-8200" extends="hp-switch" manufacturer="(HP|Aruba)"
+            hwVersion="Switch 8212zl" swVersion=".*"/>
+
 </drivers>