flowrule states functional
Change-Id: Id310f146d4ef2a59993f31d60062464a24df4560
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 829db3f..de59896 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,39 +1,28 @@
package org.onlab.onos.net.flow;
import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.slf4j.LoggerFactory.getLogger;
import java.util.Objects;
import org.onlab.onos.net.DeviceId;
+import org.slf4j.Logger;
public class DefaultFlowRule implements FlowRule {
+ private final Logger log = getLogger(getClass());
+
private final DeviceId deviceId;
private final int priority;
private final TrafficSelector selector;
private final TrafficTreatment treatment;
- private final FlowId id;
private final long created;
private final long life;
private final long packets;
private final long bytes;
private final FlowRuleState state;
-
- public DefaultFlowRule(DeviceId deviceId,
- 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.packets = 0;
- this.bytes = 0;
- this.id = FlowId.valueOf(this.hashCode());
- this.created = System.currentTimeMillis();
- }
+ private final FlowId id;
public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatment, int priority, FlowRuleState state,
@@ -59,7 +48,37 @@
public DefaultFlowRule(FlowRule rule, FlowRuleState state) {
this(rule.deviceId(), rule.selector(), rule.treatment(),
- rule.priority(), state);
+ rule.priority(), state, rule.id());
+ }
+
+ private DefaultFlowRule(DeviceId deviceId,
+ 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.packets = 0;
+ this.bytes = 0;
+ this.id = FlowId.valueOf(this.hashCode());
+ this.created = System.currentTimeMillis();
+ }
+
+ private DefaultFlowRule(DeviceId deviceId,
+ TrafficSelector selector, TrafficTreatment treatment,
+ int priority, FlowRuleState state, FlowId flowId) {
+ 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.id = flowId;
+ this.created = System.currentTimeMillis();
}
@@ -128,13 +147,14 @@
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
+
if (this == obj) {
return true;
}
if (obj instanceof FlowRule) {
- FlowRule that = (FlowRule) obj;
- return Objects.equals(deviceId, that.deviceId()) &&
- Objects.equals(id, that.id());
+ DefaultFlowRule that = (DefaultFlowRule) obj;
+ return Objects.equals(deviceId, that.deviceId) &&
+ Objects.equals(id, that.id);
}
return false;
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
index ce8e700..b17449d 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
@@ -19,7 +19,12 @@
/**
* Signifies that a flow rule has been removed.
*/
- RULE_REMOVED
+ RULE_REMOVED,
+
+ /**
+ * Signifies that a rule has been updated.
+ */
+ RULE_UPDATED
}
/**
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 df988fe..01e4372 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
@@ -24,6 +24,13 @@
void flowMissing(FlowRule flowRule);
/**
+ * Signals that a flow rule is on the switch but not in the store.
+ *
+ * @param flowRule the extra flow rule
+ */
+ void extraneousFlow(FlowRule flowRule);
+
+ /**
* Signals that a flow rule was indeed added.
*
* @param flowRule the added flow rule
@@ -38,4 +45,6 @@
*/
void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowRules);
+
+
}
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 d2b9432..9db035a 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
@@ -1,7 +1,5 @@
package org.onlab.onos.net.flow;
-import java.util.List;
-
import org.onlab.onos.net.DeviceId;
/**
@@ -31,10 +29,8 @@
* device reconnects to the controller.
*
* @param flowRules one or more flow rules
- * throws SomeKindOfException that indicates which ones were applied and
- * which ones failed
*/
- List<FlowRule> applyFlowRules(FlowRule... flowRules);
+ void applyFlowRules(FlowRule... flowRules);
/**
* Removes the specified flow rules from their respective devices. If the
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 6fdc993..0698721 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
@@ -16,12 +16,18 @@
Iterable<FlowRule> getFlowEntries(DeviceId deviceId);
/**
- * Stores a new flow rule, and generates a FlowRule for it.
+ * Stores a new flow rule without generating events.
*
* @param rule the flow rule to add
- * @return a flow entry
*/
- FlowRule storeFlowRule(FlowRule rule);
+ void storeFlowRule(FlowRule rule);
+
+ /**
+ * Deletes a flow rule without generating events.
+ *
+ * @param rule the flow rule to delete
+ */
+ void deleteFlowRule(FlowRule rule);
/**
* Stores a new flow rule, or updates an existing entry.