Adding a driver for OF-DPA in Qumran based switches.

Change-Id: I0dae54488e02dbd86c9bb81c556efba2f3f3f0dd
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa2Pipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa2Pipeline.java
index cd25643..77efbe6 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa2Pipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa2Pipeline.java
@@ -199,6 +199,15 @@
         return true;
     }
 
+    /**
+     * Determines whether in-port should be matched on in TMAC table rules.
+     *
+     * @return true if match on in-port should be programmed
+     */
+    protected boolean matchInPortTmacTable() {
+        return true;
+    }
+
     //////////////////////////////////////
     //  Flow Objectives
     //////////////////////////////////////
@@ -624,7 +633,9 @@
             // for unicast IP packets
             TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
             TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
-            selector.matchInPort(pnum);
+            if (matchInPortTmacTable()) {
+                selector.matchInPort(pnum);
+            }
             if (requireVlanExtensions()) {
                 selector.extension(ofdpaMatchVlanVid, deviceId);
             } else {
@@ -645,7 +656,9 @@
             //for MPLS packets
             selector = DefaultTrafficSelector.builder();
             treatment = DefaultTrafficTreatment.builder();
-            selector.matchInPort(pnum);
+            if (matchInPortTmacTable()) {
+                selector.matchInPort(pnum);
+            }
             if (requireVlanExtensions()) {
                 selector.extension(ofdpaMatchVlanVid, deviceId);
             } else {
@@ -668,7 +681,9 @@
              */
             selector = DefaultTrafficSelector.builder();
             treatment = DefaultTrafficTreatment.builder();
-            selector.matchInPort(pnum);
+            if (matchInPortTmacTable()) {
+                selector.matchInPort(pnum);
+            }
             if (requireVlanExtensions()) {
                 selector.extension(ofdpaMatchVlanVid, deviceId);
             } else {
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa3QmxPipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa3QmxPipeline.java
new file mode 100644
index 0000000..5790321
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/Ofdpa3QmxPipeline.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016-present 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.driver.pipeline;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collection;
+import org.onlab.packet.Ethernet;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.criteria.EthTypeCriterion;
+import org.onosproject.net.flow.criteria.IPCriterion;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.ObjectiveError;
+import org.slf4j.Logger;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Pipeliner for Broadcom OF-DPA 3.0 TTP, specifically for Qumran based switches.
+ */
+public class Ofdpa3QmxPipeline extends Ofdpa3Pipeline {
+    private final Logger log = getLogger(getClass());
+
+    @Override
+    protected void initDriverId() {
+        driverId = coreService.registerApplication(
+                "org.onosproject.driver.Ofdpa3QmxPipeline");
+    }
+
+    @Override
+    protected boolean matchInPortTmacTable() {
+        return false;
+    }
+
+    @Override
+    protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) {
+        TrafficSelector selector = fwd.selector();
+        EthTypeCriterion ethType =
+                (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
+        //XXX remove when support is added to Qumran based OF-DPA
+        if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4 ||
+                ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
+            log.warn("Routing table is currently unsupported in dev:{}", deviceId);
+            return ImmutableSet.of();
+        }
+
+        return super.processEthTypeSpecific(fwd);
+    }
+
+    @Override
+    protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
+         EthTypeCriterion ethType =
+                 (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE);
+         if (ethType == null) {
+             log.error("Versatile forwarding objective:{} must include ethType",
+                       fwd.id());
+             fail(fwd, ObjectiveError.BADPARAMS);
+             return ImmutableSet.of();
+         }
+         //XXX remove when support is added to Qumran based OF-DPA
+         if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
+             log.warn("ACL table for IPv6 is currently unsupported in dev:{}", deviceId);
+             return ImmutableSet.of();
+         }
+
+         if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
+             for (Criterion c : fwd.selector().criteria()) {
+                 if (c instanceof IPCriterion) {
+                     if (((IPCriterion) c).type() == Criterion.Type.IPV4_DST) {
+                         log.warn("ACL table for Dst IPv4 is currently "
+                                 + "unsupported in dev:{}", deviceId);
+                         return ImmutableSet.of();
+                     }
+                 }
+             }
+         }
+
+         return super.processVersatile(fwd);
+    }
+}