trying to fix flow state
Change-Id: I62845842c66cb99cb14bd54bc9602edf7c0cae39
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 fae1fe3..62e331f 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
@@ -15,19 +15,20 @@
private final FlowId id;
private final long created;
private final long life;
- private final long idle;
private final long packets;
private final long bytes;
+ private final FlowRuleState state;
public DefaultFlowRule(DeviceId deviceId,
- TrafficSelector selector, TrafficTreatment treatment, int priority) {
+ TrafficSelector selector, TrafficTreatment treatment,
+ int priority, FlowRuleState state) {
this.deviceId = deviceId;
this.priority = priority;
this.selector = selector;
this.treatment = treatment;
+ this.state = state;
this.life = 0;
- this.idle = 0;
this.packets = 0;
this.bytes = 0;
this.id = FlowId.valueOf(this.hashCode());
@@ -35,22 +36,32 @@
}
public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- long life, long idle, long packets, long bytes, Integer flowId) {
+ TrafficTreatment treatment, int priority, FlowRuleState state,
+ long life, long packets, long bytes, Integer flowId) {
this.deviceId = deviceId;
this.priority = priority;
this.selector = selector;
this.treatment = treatment;
+ this.state = state;
this.id = FlowId.valueOf(flowId);
this.life = life;
- this.idle = idle;
this.packets = packets;
this.bytes = bytes;
this.created = System.currentTimeMillis();
}
+ public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
+ TrafficTreatment treatement, int priority) {
+ this(deviceId, selector, treatement, priority, FlowRuleState.CREATED);
+ }
+
+ public DefaultFlowRule(FlowRule rule, FlowRuleState state) {
+ this(rule.deviceId(), rule.selector(), rule.treatment(),
+ rule.priority(), state);
+ }
+
@Override
public FlowId id() {
@@ -83,11 +94,6 @@
}
@Override
- public long idleMillis() {
- return idle;
- }
-
- @Override
public long packets() {
return packets;
}
@@ -98,6 +104,12 @@
}
@Override
+ public FlowRuleState state() {
+ return this.state;
+ }
+
+
+ @Override
/*
* The priority and statistics can change on a given treatment and selector
*
@@ -116,19 +128,14 @@
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
- if (obj instanceof FlowRule) {
- DefaultFlowRule that = (DefaultFlowRule) obj;
- if (!this.deviceId().equals(that.deviceId())) {
- return false;
- }
- if (!this.treatment().equals(that.treatment())) {
- return false;
- }
- if (!this.selector().equals(that.selector())) {
- return false;
- }
+ if (this == obj) {
return true;
}
+ if (obj instanceof FlowRule) {
+ FlowRule that = (FlowRule) obj;
+ return Objects.equals(deviceId, that.deviceId()) &&
+ Objects.equals(id, that.id());
+ }
return false;
}
@@ -144,5 +151,4 @@
.toString();
}
-
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowId.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowId.java
index 03140f7..c7c44cb 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowId.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowId.java
@@ -1,13 +1,15 @@
package org.onlab.onos.net.flow;
+import com.google.common.base.Objects;
+
/**
* Representation of a Flow ID.
*/
public final class FlowId {
- private final int flowid;
+ private final long flowid;
- private FlowId(int id) {
+ private FlowId(long id) {
this.flowid = id;
}
@@ -15,7 +17,24 @@
return new FlowId(id);
}
- public int value() {
+ public long value() {
return flowid;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj.getClass() == this.getClass()) {
+ FlowId that = (FlowId) obj;
+ return Objects.equal(this.flowid, that.flowid);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.flowid);
+ }
}
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 f2bc1a0..e72beed 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
@@ -8,6 +8,42 @@
*/
public interface FlowRule {
+
+ 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.
@@ -54,13 +90,6 @@
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
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 737ac28..df988fe 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
@@ -1,5 +1,6 @@
package org.onlab.onos.net.flow;
+import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.provider.ProviderService;
/**
@@ -35,6 +36,6 @@
*
* @param flowRules collection of flow rules
*/
- void pushFlowMetrics(Iterable<FlowRule> flowRules);
+ void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowRules);
}