Consolidated FlowEntry into FlowRule
Change-Id: I349d73abba3336f4c79429efb5717e0a8c374a30
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowEntry.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowEntry.java
deleted file mode 100644
index 295517b..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowEntry.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.onlab.onos.net.flow;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-
-import org.onlab.onos.net.DeviceId;
-
-public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry {
-
- private final int priority;
- private final long created;
- private final FlowId id;
-
- public DefaultFlowEntry(DefaultFlowEntry entry) {
- super(entry.deviceId(), entry.selector(), entry.treatment());
- this.priority = entry.priority;
- this.created = entry.created;
- this.id = entry.id;
- }
-
- public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority) {
- super(deviceId, selector, treatment);
- this.priority = priority;
- this.created = System.currentTimeMillis();
- this.id = FlowId.valueOf(this.hashCode());
- }
-
- @Override
- public FlowId id() {
- return null;
- }
-
- @Override
- public int priority() {
- return priority;
- }
-
- @Override
- public long lifeMillis() {
- return (created - System.currentTimeMillis());
- }
-
- @Override
- public long idleMillis() {
- return 0;
- }
-
- @Override
- public long packets() {
- return 0;
- }
-
- @Override
- public long bytes() {
- return 0;
- }
-
- @Override
- /*
- * currently uses the parts that definitely have a defined hashcode...
- *
- * (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- final int prime = 31;
- int result = prime * this.deviceId().hashCode();
- result = prime * result + this.priority;
- result = prime * result + this.selector().hashCode();
- result = prime * result + this.treatment().hashCode();
- return result;
- }
-
- @Override
- /*
- * The priority and statistics can change on a given treatment and selector
- *
- * (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (obj instanceof DefaultFlowEntry) {
- DefaultFlowEntry that = (DefaultFlowEntry) obj;
- if (!this.deviceId().equals(that.deviceId())) {
- return false;
- }
- if (!(this.priority == that.priority)) {
- return false;
- }
- return super.equals(obj);
- }
- return false;
- }
-
- @Override
- public String toString() {
- return toStringHelper(this)
- .add("id", id)
- .add("deviceId", deviceId())
- .add("priority", priority)
- .add("selector", selector())
- .add("treatment", treatment())
- .toString();
- }
-
-}
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 d20e79e..6801e8a 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
@@ -1,24 +1,37 @@
package org.onlab.onos.net.flow;
+import static com.google.common.base.MoreObjects.toStringHelper;
+
import org.onlab.onos.net.DeviceId;
public class DefaultFlowRule implements FlowRule {
+ private final DeviceId deviceId;
+ private final int priority;
private final TrafficSelector selector;
private final TrafficTreatment treatment;
- private final DeviceId deviceId;
+ private final FlowId id;
+ private final long created;
+
public DefaultFlowRule(DeviceId deviceId,
- TrafficSelector selector, TrafficTreatment treatment) {
- this.treatment = treatment;
- this.selector = selector;
+ TrafficSelector selector, TrafficTreatment treatment, int priority) {
this.deviceId = deviceId;
+ this.priority = priority;
+ this.selector = selector;
+ this.treatment = treatment;
+ this.id = FlowId.valueOf(this.hashCode());
+ this.created = System.currentTimeMillis();
+ }
+
+ @Override
+ public FlowId id() {
+ return id;
}
@Override
public int priority() {
- // is this supposed to be 0?
- return 0;
+ return priority;
}
@Override
@@ -37,6 +50,35 @@
}
@Override
+ public long lifeMillis() {
+ return (created - System.currentTimeMillis());
+ }
+
+ @Override
+ public long idleMillis() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public long packets() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public long bytes() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ /*
+ * The priority and statistics can change on a given treatment and selector
+ *
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
public int hashCode() {
final int prime = 31;
int result = prime * this.deviceId().hashCode();
@@ -69,5 +111,16 @@
return false;
}
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("id", id)
+ .add("deviceId", deviceId)
+ .add("priority", priority)
+ .add("selector", selector)
+ .add("treatment", treatment)
+ .add("created", created)
+ .toString();
+ }
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowEntry.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowEntry.java
deleted file mode 100644
index 7fee1c1..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowEntry.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.onlab.onos.net.flow;
-
-/**
- * Represents a flow rule and its associated accumulated metrics.
- */
-public interface FlowEntry extends FlowRule {
-
- /**
- * Returns the ID of this flow.
- *
- * @return the flow ID
- */
- FlowId id();
-
- /**
- * Returns the number of milliseconds this flow rule has been applied.
- *
- * @return number of millis
- */
- long lifeMillis();
-
- /**
- * Returns the number of milliseconds this flow rule has been idle.
- *
- * @return number of millis
- */
- long idleMillis();
-
- /**
- * 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();
-
-}
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 5f44630..f2bc1a0 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
@@ -9,6 +9,12 @@
public interface FlowRule {
//TODO: build cookie value
+ /**
+ * Returns the ID of this flow.
+ *
+ * @return the flow ID
+ */
+ FlowId id();
/**
* Returns the flow rule priority given in natural order; higher numbers
@@ -40,4 +46,32 @@
*/
TrafficTreatment treatment();
+ /**
+ * Returns the number of milliseconds this flow rule has been applied.
+ *
+ * @return number of millis
+ */
+ long lifeMillis();
+
+ /**
+ * Returns the number of milliseconds this flow rule has been idle.
+ *
+ * @return number of millis
+ */
+ long idleMillis();
+
+ /**
+ * 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();
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
index ca22c4f..b8aa0c2 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
@@ -34,6 +34,6 @@
* @param deviceId device identifier
* @return collection of flow entries
*/
- Iterable<FlowEntry> getFlowMetrics(DeviceId deviceId);
+ Iterable<FlowRule> getFlowMetrics(DeviceId deviceId);
}
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 ba75ae9..d2b9432 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
@@ -21,7 +21,7 @@
* @param deviceId device identifier
* @return collection of flow rules
*/
- Iterable<FlowEntry> getFlowEntries(DeviceId deviceId);
+ Iterable<FlowRule> getFlowEntries(DeviceId deviceId);
// TODO: add createFlowRule factory method and execute operations method
@@ -34,7 +34,7 @@
* throws SomeKindOfException that indicates which ones were applied and
* which ones failed
*/
- List<FlowEntry> applyFlowRules(FlowRule... flowRules);
+ List<FlowRule> applyFlowRules(FlowRule... flowRules);
/**
* Removes the specified flow rules from their respective devices. If the