the return of the flowentry

Change-Id: I7dbeb6af2014a4df5b0beb7fe0157eaaac63bd0f
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
index 9b44fc2..9011a93 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
@@ -18,10 +18,6 @@
     private final TrafficSelector selector;
     private final TrafficTreatment treatment;
     private final long created;
-    private final long life;
-    private final long packets;
-    private final long bytes;
-    private final FlowRuleState state;
 
     private final FlowId id;
 
@@ -29,90 +25,50 @@
 
     private final int timeout;
 
-    /**
-     * Creates a flow rule given the following paremeters.
-     * @param deviceId the device where the rule should be installed
-     * @param selector the traffic selection
-     * @param treatment how the seleted traffic should be handled
-     * @param priority the rule priority cannot be less than FlowRule.MIN_PRIORITY
-     * @param state the state in which the rule is
-     * @param life how long it has existed for (ms)
-     * @param packets number of packets it has seen
-     * @param bytes number of bytes  it has seen
-     * @param flowId the identifier
-     * @param timeout the rule's timeout (idle) not to exceed
-     *  FlowRule.MAX_TIMEOUT of idle time
-     */
+
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
-            TrafficTreatment treatment, int priority, FlowRuleState state,
-            long life, long packets, long bytes, long flowId,
+            TrafficTreatment treatment, int priority, long flowId,
             int timeout) {
         this.deviceId = deviceId;
         this.priority = priority;
         this.selector = selector;
         this.treatment = treatment;
-        this.state = state;
+        this.timeout = timeout;
+        this.created = System.currentTimeMillis();
+
         this.appId = ApplicationId.valueOf((int) (flowId >> 32));
         this.id = FlowId.valueOf(flowId);
-        this.life = life;
-        this.packets = packets;
-        this.bytes = bytes;
-        this.created = System.currentTimeMillis();
-        this.timeout = timeout;
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
             TrafficTreatment treatement, int priority, ApplicationId appId,
             int timeout) {
-        this(deviceId, selector, treatement, priority,
-                FlowRuleState.CREATED, appId, timeout);
-    }
 
-    public DefaultFlowRule(FlowRule rule, FlowRuleState state) {
-        this(rule.deviceId(), rule.selector(), rule.treatment(),
-                rule.priority(), state, rule.id(), rule.appId(),
-                rule.timeout());
-    }
-
-    private DefaultFlowRule(DeviceId deviceId,
-            TrafficSelector selector, TrafficTreatment treatment,
-            int priority, FlowRuleState state, ApplicationId appId,
-            int timeout) {
-        if (priority < MIN_PRIORITY) {
+        if (priority < FlowRule.MIN_PRIORITY) {
             throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY);
         }
+
         this.deviceId = deviceId;
         this.priority = priority;
         this.selector = selector;
-        this.treatment = treatment;
-        this.state = state;
-        this.life = 0;
-        this.packets = 0;
-        this.bytes = 0;
+        this.treatment = treatement;
         this.appId = appId;
-
         this.timeout = timeout;
+        this.created = System.currentTimeMillis();
 
         this.id = FlowId.valueOf((((long) appId().id()) << 32) | (this.hash() & 0xffffffffL));
-        this.created = System.currentTimeMillis();
     }
 
-    private DefaultFlowRule(DeviceId deviceId,
-            TrafficSelector selector, TrafficTreatment treatment,
-            int priority, FlowRuleState state, FlowId flowId, ApplicationId appId,
-            int timeout) {
-        this.deviceId = deviceId;
-        this.priority = priority;
-        this.selector = selector;
-        this.treatment = treatment;
-        this.state = state;
-        this.life = 0;
-        this.packets = 0;
-        this.bytes = 0;
-        this.appId = appId;
-        this.id = flowId;
-        this.timeout = timeout;
+    public DefaultFlowRule(FlowRule rule) {
+        this.deviceId = rule.deviceId();
+        this.priority = rule.priority();
+        this.selector = rule.selector();
+        this.treatment = rule.treatment();
+        this.appId = rule.appId();
+        this.id = rule.id();
+        this.timeout = rule.timeout();
         this.created = System.currentTimeMillis();
+
     }
 
 
@@ -146,26 +102,6 @@
         return treatment;
     }
 
-    @Override
-    public long life() {
-        return life;
-    }
-
-    @Override
-    public long packets() {
-        return packets;
-    }
-
-    @Override
-    public long bytes() {
-        return bytes;
-    }
-
-    @Override
-    public FlowRuleState state() {
-        return this.state;
-    }
-
 
     @Override
     /*
@@ -213,7 +149,6 @@
                 .add("selector", selector.criteria())
                 .add("treatment", treatment == null ? "N/A" : treatment.instructions())
                 .add("created", created)
-                .add("state", state)
                 .toString();
     }
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
index 9b76f32..8b30c74 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
@@ -12,41 +12,6 @@
     static final int MAX_TIMEOUT = 60;
     static final int MIN_PRIORITY = 0;
 
-    public enum FlowRuleState {
-        /**
-         * Indicates that this rule has been created.
-         */
-        CREATED,
-
-        /**
-         * Indicates that this rule has been submitted for addition.
-         * Not necessarily in  the flow table.
-         */
-        PENDING_ADD,
-
-        /**
-         * Rule has been added which means it is in the flow table.
-         */
-        ADDED,
-
-        /**
-         * Flow has been marked for removal, might still be in flow table.
-         */
-        PENDING_REMOVE,
-
-        /**
-         * Flow has been removed from flow table and can be purged.
-         */
-        REMOVED
-    }
-
-    /**
-     * Returns the flow rule state.
-     *
-     * @return flow rule state
-     */
-    FlowRuleState state();
-
     //TODO: build cookie value
     /**
      * Returns the ID of this flow.
@@ -93,27 +58,6 @@
     TrafficTreatment treatment();
 
     /**
-     * Returns the number of milliseconds this flow rule has been applied.
-     *
-     * @return number of millis
-     */
-    long life();
-
-    /**
-     * Returns the number of packets this flow rule has matched.
-     *
-     * @return number of packets
-     */
-    long packets();
-
-    /**
-     * Returns the number of bytes this flow rule has matched.
-     *
-     * @return number of bytes
-     */
-    long bytes();
-
-    /**
      * Returns the timeout for this flow requested by an application.
      * @return integer value of the timeout
      */
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
index 2076103..8164579 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProviderService.java
@@ -14,7 +14,7 @@
      *
      * @param flowRule information about the removed flow
      */
-    void flowRemoved(FlowRule flowRule);
+    void flowRemoved(FlowEntry flowEntry);
 
     /**
      * Pushes the collection of flow entries currently applied on the given
@@ -22,7 +22,7 @@
      *
      * @param flowRules collection of flow rules
      */
-    void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowRules);
+    void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries);
 
 
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java
index c09a56d..2ebc5a25 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java
@@ -20,7 +20,7 @@
      * @param deviceId device identifier
      * @return collection of flow rules
      */
-    Iterable<FlowRule> getFlowEntries(DeviceId deviceId);
+    Iterable<FlowEntry> getFlowEntries(DeviceId deviceId);
 
     // TODO: add createFlowRule factory method and execute operations method
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
index c6093384..4d68e74 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
@@ -14,7 +14,7 @@
      * @param rule the rule to look for
      * @return a flow rule
      */
-    FlowRule getFlowRule(FlowRule rule);
+    FlowEntry getFlowEntry(FlowRule rule);
 
     /**
      * Returns the flow entries associated with a device.
@@ -22,7 +22,7 @@
      * @param deviceId the device ID
      * @return the flow entries
      */
-    Iterable<FlowRule> getFlowEntries(DeviceId deviceId);
+    Iterable<FlowEntry> getFlowEntries(DeviceId deviceId);
 
     /**
      * Returns the flow entries associated with an application.
@@ -30,7 +30,7 @@
      * @param appId the application id
      * @return the flow entries
      */
-    Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId);
+    Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId);
 
     /**
      * Stores a new flow rule without generating events.
@@ -40,7 +40,8 @@
     void storeFlowRule(FlowRule rule);
 
     /**
-     * Deletes a flow rule without generating events.
+     * Marks a flow rule for deletion. Actual deletion will occur
+     * when the provider indicates that the flow has been removed.
      *
      * @param rule the flow rule to delete
      */
@@ -52,12 +53,12 @@
      * @param rule the flow rule to add or update
      * @return flow_added event, or null if just an update
      */
-    FlowRuleEvent addOrUpdateFlowRule(FlowRule rule);
+    FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule);
 
     /**
-     * @param rule the flow rule to remove
+     * @param rule the flow entry to remove
      * @return flow_removed event, or null if nothing removed
      */
-    FlowRuleEvent removeFlowRule(FlowRule rule);
+    FlowRuleEvent removeFlowRule(FlowEntry rule);
 
 }