Consolidated FlowEntry into FlowRule

Change-Id: I349d73abba3336f4c79429efb5717e0a8c374a30
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
index 038a0d9..7181f02 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
@@ -16,7 +16,6 @@
 import org.onlab.onos.net.Device;
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.device.DeviceService;
-import org.onlab.onos.net.flow.FlowEntry;
 import org.onlab.onos.net.flow.FlowRule;
 import org.onlab.onos.net.flow.FlowRuleEvent;
 import org.onlab.onos.net.flow.FlowRuleListener;
@@ -63,13 +62,13 @@
     }
 
     @Override
-    public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
+    public Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
         return store.getFlowEntries(deviceId);
     }
 
     @Override
-    public List<FlowEntry> applyFlowRules(FlowRule... flowRules) {
-        List<FlowEntry> entries = new ArrayList<FlowEntry>();
+    public List<FlowRule> applyFlowRules(FlowRule... flowRules) {
+        List<FlowRule> entries = new ArrayList<FlowRule>();
 
         for (int i = 0; i < flowRules.length; i++) {
             FlowRule f = flowRules[i];
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleStore.java
index 4f23ff4..dd8dce8 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleStore.java
@@ -1,8 +1,7 @@
 package org.onlab.onos.net.trivial.flow.impl;
 
 import org.onlab.onos.net.DeviceId;
-import org.onlab.onos.net.flow.DefaultFlowEntry;
-import org.onlab.onos.net.flow.FlowEntry;
+import org.onlab.onos.net.flow.DefaultFlowRule;
 import org.onlab.onos.net.flow.FlowRule;
 import org.onlab.onos.net.flow.FlowRuleEvent;
 
@@ -18,7 +17,7 @@
 public class SimpleFlowRuleStore {
 
     // store entries as a pile of rules, no info about device tables
-    private final Multimap<DeviceId, FlowEntry> flowEntries = HashMultimap.create();
+    private final Multimap<DeviceId, FlowRule> flowEntries = HashMultimap.create();
 
     /**
      * Returns the flow entries associated with a device.
@@ -26,19 +25,19 @@
      * @param deviceId the device ID
      * @return the flow entries
      */
-    Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
+    Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
         return ImmutableSet.copyOf(flowEntries.get(deviceId));
     }
 
     /**
-     * Stores a new flow rule, and generates a FlowEntry for it.
+     * Stores a new flow rule, and generates a FlowRule for it.
      *
      * @param rule the flow rule to add
      * @return a flow entry
      */
-    FlowEntry storeFlowRule(FlowRule rule) {
+    FlowRule storeFlowRule(FlowRule rule) {
         DeviceId did = rule.deviceId();
-        FlowEntry entry = new DefaultFlowEntry(did,
+        FlowRule entry = new DefaultFlowRule(did,
                 rule.selector(), rule.treatment(), rule.priority());
         flowEntries.put(did, entry);
         return entry;
@@ -53,20 +52,14 @@
     FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) {
         DeviceId did = rule.deviceId();
 
-        FlowEntry entry = new DefaultFlowEntry(
-                did,
-                rule.selector(),
-                rule.treatment(),
-                rule.priority());
-
         // check if this new rule is an update to an existing entry
-        for (FlowEntry fe : flowEntries.get(did)) {
-            if (entry.equals(fe)) {
-                // TODO update the stats on this flowEntry?
+        for (FlowRule fe : flowEntries.get(did)) {
+            if (rule.equals(fe)) {
+                // TODO update the stats on this FlowRule?
                 return null;
             }
         }
-        flowEntries.put(did, entry);
+        flowEntries.put(did, rule);
         return new FlowRuleEvent(RULE_ADDED, rule);
     }
 
@@ -77,10 +70,8 @@
      */
     FlowRuleEvent removeFlowRule(FlowRule rule) {
 
-        FlowEntry rem = new DefaultFlowEntry(rule.deviceId(),
-                rule.selector(), rule.treatment(), rule.priority());
         synchronized (this) {
-            if (flowEntries.remove(rem.deviceId(), rem)) {
+            if (flowEntries.remove(rule.deviceId(), rule)) {
                 return new FlowRuleEvent(RULE_REMOVED, rule);
             } else {
                 return null;
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
index 9e8178a..1cf8a9f 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManagerTest.java
@@ -21,9 +21,7 @@
 import org.onlab.onos.net.PortNumber;
 import org.onlab.onos.net.device.DeviceListener;
 import org.onlab.onos.net.device.DeviceService;
-import org.onlab.onos.net.flow.DefaultFlowEntry;
 import org.onlab.onos.net.flow.DefaultFlowRule;
-import org.onlab.onos.net.flow.FlowEntry;
 import org.onlab.onos.net.flow.FlowRule;
 import org.onlab.onos.net.flow.FlowRuleEvent;
 import org.onlab.onos.net.flow.FlowRuleListener;
@@ -91,7 +89,7 @@
     private FlowRule flowRule(int tsval, int trval) {
         TestSelector ts = new TestSelector(tsval);
         TestTreatment tr = new TestTreatment(trval);
-        return new DefaultFlowRule(DID, ts, tr);
+        return new DefaultFlowRule(DID, ts, tr, 0);
     }
 
     private void addFlowRule(int hval) {
@@ -142,14 +140,14 @@
         FlowRule r3 = flowRule(1, 3);
 
         //current FlowRules always return 0. FlowEntries inherit the value
-        FlowEntry e1 = new DefaultFlowEntry(DID, ts, r1.treatment(), 0);
-        FlowEntry e2 = new DefaultFlowEntry(DID, ts, r2.treatment(), 0);
-        FlowEntry e3 = new DefaultFlowEntry(DID, ts, r3.treatment(), 0);
-        List<FlowEntry> fel = Lists.newArrayList(e1, e2, e3);
+        FlowRule e1 = new DefaultFlowRule(DID, ts, r1.treatment(), 0);
+        FlowRule e2 = new DefaultFlowRule(DID, ts, r2.treatment(), 0);
+        FlowRule e3 = new DefaultFlowRule(DID, ts, r3.treatment(), 0);
+        List<FlowRule> fel = Lists.newArrayList(e1, e2, e3);
 
         assertTrue("store should be empty",
                 Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
-        List<FlowEntry> ret = mgr.applyFlowRules(r1, r2, r3);
+        List<FlowRule> ret = mgr.applyFlowRules(r1, r2, r3);
         assertEquals("3 rules should exist", 3, flowCount());
         assertTrue("3 entries should result", fel.containsAll(ret));
     }
@@ -256,7 +254,7 @@
         }
 
         @Override
-        public Iterable<FlowEntry> getFlowMetrics(DeviceId deviceId) {
+        public Iterable<FlowRule> getFlowMetrics(DeviceId deviceId) {
             return null;
         }