Augment SONA pipeline to support both vTap and vFlow stats features

Change-Id: If4adaf672f3b975bbe150b20b380a04183a837d0
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
index e2b6c9c..17a09e3 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
@@ -76,19 +76,32 @@
     public static final int PRIORITY_ARP_REPLY_RULE = 40000;
     public static final int PRIORITY_ARP_REQUEST_RULE = 40000;
 
+    // flow table index
     public static final int STAT_INBOUND_TABLE = 0;
-    public static final int DHCP_ARP_TABLE = 1;
-    public static final int FLAT_TABLE = 2;
-    public static final int VTAG_TABLE = 10;
-    public static final int ACL_TABLE = 20;
-    public static final int CT_TABLE = 21;
-    public static final int JUMP_TABLE = 30;
-    public static final int ROUTING_TABLE = 40;
-    public static final int STAT_OUTBOUND_TABLE = 49;
-    public static final int FORWARDING_TABLE = 50;
+    public static final int VTAP_INBOUND_TABLE = 1;
+    public static final int VTAP_INBOUND_MIRROR_TABLE = 2;
+    public static final int STAT_FLAT_OUTBOUND_TABLE = 10;
+    public static final int VTAP_FLAT_OUTBOUND_TABLE = 11;
+    public static final int VTAP_FLAT_OUTBOUND_MIRROR_TABLE = 12;
+    public static final int DHCP_ARP_TABLE = 5;
+    public static final int FLAT_TABLE = 20;
+    public static final int VTAG_TABLE = 30;
+    public static final int ACL_TABLE = 40;
+    public static final int CT_TABLE = 41;
+    public static final int JUMP_TABLE = 50;
+    public static final int ROUTING_TABLE = 60;
+    public static final int STAT_OUTBOUND_TABLE = 70;
+    public static final int VTAP_OUTBOUND_TABLE = 71;
+    public static final int VTAP_OUTBOUND_MIRROR_TABLE = 72;
+    public static final int FORWARDING_TABLE = 80;
     public static final int GW_COMMON_TABLE = 0;
     public static final int ERROR_TABLE = 100;
 
+    // group table index
+    public static final int VTAP_INBOUND_GROUP_TABLE = 1;
+    public static final int VTAP_FLAT_OUTBOUND_GROUP_TABLE = 2;
+    public static final int VTAP_OUTBOUND_GROUP_TABLE = 3;
+
     public static Map<String, String> portNamePrefixMap() {
         return PORT_NAME_PREFIX_MAP;
     }
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
index 0a060ff..018b1c2 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackFlowRuleManager.java
@@ -143,12 +143,28 @@
     }
 
     private void initializePipeline(DeviceId deviceId) {
-        connectTables(deviceId, Constants.STAT_INBOUND_TABLE, Constants.DHCP_ARP_TABLE);
+        // for inbound table transition
+        connectTables(deviceId, Constants.STAT_INBOUND_TABLE, Constants.VTAP_INBOUND_TABLE);
+        connectTables(deviceId, Constants.VTAP_INBOUND_TABLE, Constants.DHCP_ARP_TABLE);
+
+        // for vTag and ACL table transition
         connectTables(deviceId, Constants.DHCP_ARP_TABLE, Constants.VTAG_TABLE);
         connectTables(deviceId, Constants.VTAG_TABLE, Constants.ACL_TABLE);
         connectTables(deviceId, Constants.ACL_TABLE, Constants.JUMP_TABLE);
+
+        // for JUMP table transition
+        // we need JUMP table for bypassing routing table which contains large
+        // amount of flow rules which might cause performance degradation during
+        // table lookup
         setupJumpTable(deviceId);
-        connectTables(deviceId, Constants.STAT_OUTBOUND_TABLE, Constants.FORWARDING_TABLE);
+
+        // for outbound table transition
+        connectTables(deviceId, Constants.STAT_OUTBOUND_TABLE, Constants.VTAP_OUTBOUND_TABLE);
+        connectTables(deviceId, Constants.VTAP_OUTBOUND_TABLE, Constants.FORWARDING_TABLE);
+
+        // for FLAT outbound table transition
+        connectTables(deviceId, Constants.STAT_FLAT_OUTBOUND_TABLE, Constants.VTAP_FLAT_OUTBOUND_TABLE);
+        connectTables(deviceId, Constants.VTAP_FLAT_OUTBOUND_TABLE, Constants.FLAT_TABLE);
     }
 
     @Override
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
index f9dea2e..e3a20cb 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
@@ -71,10 +71,10 @@
 import static org.onosproject.net.flow.criteria.Criterion.Type.TCP_SRC;
 import static org.onosproject.net.flow.criteria.Criterion.Type.UDP_DST;
 import static org.onosproject.net.flow.criteria.Criterion.Type.UDP_SRC;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_ARP_TABLE;
-import static org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.STAT_INBOUND_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE;
 import static org.onosproject.openstacktelemetry.api.Constants.OPENSTACK_TELEMETRY_APP_ID;
 
 /**
@@ -399,12 +399,12 @@
         }
 
         if (srcDeviceId != null) {
-            connectTables(srcDeviceId, STAT_INBOUND_TABLE, DHCP_ARP_TABLE,
+            connectTables(srcDeviceId, STAT_INBOUND_TABLE, VTAP_INBOUND_TABLE,
                     statsFlowRule, METRIC_PRIORITY_SOURCE, install);
         }
 
         if (dstDeviceId != null) {
-            connectTables(dstDeviceId, STAT_OUTBOUND_TABLE, FORWARDING_TABLE,
+            connectTables(dstDeviceId, STAT_OUTBOUND_TABLE, VTAP_OUTBOUND_TABLE,
                     inverseFlowRule, METRIC_PRIORITY_TARGET, install);
         }
     }