A set of fixes to ensure that the FlowRuleManager can correctly account for flows
from the dataplane in a multi-table pipeline scenario

Change-Id: I9ca3ef9a77781f126a13538647c824b27f77101c
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
index c8105c9..f083d18 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
@@ -61,6 +61,23 @@
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
+                           TrafficTreatment treatment, int priority, long flowId,
+                           int timeout, boolean permanent, Type tableType) {
+        this.deviceId = deviceId;
+        this.priority = priority;
+        this.selector = selector;
+        this.treatment = treatment;
+        this.timeout = timeout;
+        this.permanent = permanent;
+        this.created = System.currentTimeMillis();
+
+        this.appId = (short) (flowId >>> 48);
+        this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
+        this.id = FlowId.valueOf(flowId);
+        this.type = tableType;
+    }
+
+    public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
                            TrafficTreatment treatment, int priority, ApplicationId appId,
                            int timeout, boolean permanent) {
         this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0),
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index 1d03bc1..bfdf86a 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -355,31 +355,29 @@
         @Override
         public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) {
             Set<FlowEntry> storedRules = Sets.newHashSet(store.getFlowEntries(deviceId));
-
-
-                for (FlowEntry rule : flowEntries) {
-                    try {
-                        if (storedRules.remove(rule)) {
-                            // we both have the rule, let's update some info then.
-                            flowAdded(rule);
-                        } else {
-                            // the device has a rule the store does not have
-                            extraneousFlow(rule);
-                        }
-                    } catch (Throwable e) {
-                        log.debug("Can't process added or extra rule {}", e.getMessage());
-                        continue;
+            for (FlowEntry rule : flowEntries) {
+                try {
+                    if (storedRules.remove(rule)) {
+                        // we both have the rule, let's update some info then.
+                        flowAdded(rule);
+                    } else {
+                        // the device has a rule the store does not have
+                        extraneousFlow(rule);
                     }
+                } catch (Throwable e) {
+                    log.debug("Can't process added or extra rule {}", e.getMessage());
+                    continue;
                 }
-                for (FlowEntry rule : storedRules) {
-                    try {
-                        // there are rules in the store that aren't on the switch
-                        flowMissing(rule);
-                    } catch (Throwable e) {
-                        log.debug("Can't add missing flow rule {}", e.getMessage());
-                        continue;
-                    }
+            }
+            for (FlowEntry rule : storedRules) {
+                try {
+                    // there are rules in the store that aren't on the switch
+                    flowMissing(rule);
+                } catch (Throwable e) {
+                    log.debug("Can't add missing flow rule {}", e.getMessage());
+                    continue;
                 }
+            }
 
         }