Extend the SONA pipeline to support gathering vFlow stats

Change-Id: Iee5f5fbcd96fb9d23226e837bebf2c4699c063de
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 f85d914..e2b6c9c 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,13 +76,15 @@
     public static final int PRIORITY_ARP_REPLY_RULE = 40000;
     public static final int PRIORITY_ARP_REQUEST_RULE = 40000;
 
-    public static final int DHCP_ARP_TABLE = 0;
-    public static final int FLAT_TABLE = 1;
+    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 GW_COMMON_TABLE = 0;
     public static final int ERROR_TABLE = 100;
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 48983e2..0a060ff 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,10 +143,12 @@
     }
 
     private void initializePipeline(DeviceId deviceId) {
+        connectTables(deviceId, Constants.STAT_INBOUND_TABLE, Constants.DHCP_ARP_TABLE);
         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);
         setupJumpTable(deviceId);
+        connectTables(deviceId, Constants.STAT_OUTBOUND_TABLE, Constants.FORWARDING_TABLE);
     }
 
     @Override
@@ -211,7 +213,7 @@
         selector = DefaultTrafficSelector.builder();
         treatment = DefaultTrafficTreatment.builder();
 
-        treatment.transition(Constants.FORWARDING_TABLE);
+        treatment.transition(Constants.STAT_OUTBOUND_TABLE);
 
         flowRule = DefaultFlowRule.builder()
                 .forDevice(deviceId)
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingArpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingArpHandler.java
index 3667d7c..4cadb17 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingArpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingArpHandler.java
@@ -90,7 +90,6 @@
 import static org.onosproject.openstacknetworking.api.Constants.ARP_PROXY_MODE;
 import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ARP_MODE_STR;
 import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_GATEWAY_MAC_STR;
-import static org.onosproject.openstacknetworking.api.Constants.DHCP_ARP_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.GW_COMMON_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
 import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_CONTROL_RULE;
@@ -752,7 +751,7 @@
                     selector,
                     treatment,
                     PRIORITY_ARP_CONTROL_RULE,
-                    DHCP_ARP_TABLE,
+                    GW_COMMON_TABLE,
                     install
             );
         }
@@ -776,7 +775,7 @@
                     selector,
                     treatment,
                     PRIORITY_ARP_CONTROL_RULE,
-                    DHCP_ARP_TABLE,
+                    GW_COMMON_TABLE,
                     install
             );
         }
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index 164b25b..142a9f7 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -86,7 +86,6 @@
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_EXTERNAL_ROUTER_MAC;
 import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_GATEWAY_MAC;
-import static org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.GW_COMMON_TABLE;
 import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
 import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE;
@@ -96,6 +95,7 @@
 import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_STATEFUL_SNAT_RULE;
 import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE;
 import static org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE;
+import static org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE;
 import static org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension;
 import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
 import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
@@ -541,7 +541,7 @@
 
                 treatment = DefaultTrafficTreatment.builder()
                         .setTunnelId(Long.parseLong(dstSegmentId))
-                        .transition(FORWARDING_TABLE)
+                        .transition(STAT_OUTBOUND_TABLE)
                         .build();
 
                 osFlowRuleService.setRule(
@@ -562,7 +562,7 @@
 
                 treatment = DefaultTrafficTreatment.builder()
                         .setTunnelId(Long.parseLong(dstSegmentId))
-                        .transition(FORWARDING_TABLE)
+                        .transition(STAT_OUTBOUND_TABLE)
                         .build();
 
                 osFlowRuleService.setRule(
@@ -584,7 +584,7 @@
 
                 treatment = DefaultTrafficTreatment.builder()
                         .setVlanId(VlanId.vlanId(dstSegmentId))
-                        .transition(FORWARDING_TABLE)
+                        .transition(STAT_OUTBOUND_TABLE)
                         .build();
 
                 osFlowRuleService.setRule(
@@ -605,7 +605,7 @@
 
                 treatment = DefaultTrafficTreatment.builder()
                         .setVlanId(VlanId.vlanId(dstSegmentId))
-                        .transition(FORWARDING_TABLE)
+                        .transition(STAT_OUTBOUND_TABLE)
                         .build();
 
                 osFlowRuleService.setRule(