Fix for flow equality bug which can cause:
* multiple flows with the same match to be simultaneously present in the flow
store, and
* similar but different rule in switch and store, resulting in flows stuck in
PENDING_ADD state.
Fixes ONOS-2426.
Ported from onos-1.2 branch.
Change-Id: I4b4e444c3a6dba7e4d3278e9469069e2dbdb9b67
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
index 293f12f..44a4d36 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
@@ -249,6 +249,13 @@
}
@Override
+ public boolean exactMatch(FlowRule rule) {
+ return this.equals(rule) &&
+ Objects.equals(this.id, rule.id()) &&
+ Objects.equals(this.treatment, rule.treatment());
+ }
+
+ @Override
public String toString() {
return toStringHelper(this)
.add("id", Long.toHexString(id.value()))
@@ -370,7 +377,7 @@
}
private int hash() {
- return Objects.hash(deviceId, selector, treatment, tableId);
+ return Objects.hash(deviceId, priority, selector, tableId);
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
index 397149b..e446a9f 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
@@ -138,6 +138,34 @@
int tableId();
/**
+ * {@inheritDoc}
+ *
+ * Equality for flow rules only considers 'match equality'. This means that
+ * two flow rules with the same match conditions will be equal, regardless
+ * of the treatment or other characteristics of the flow.
+ *
+ * @param obj the reference object with which to compare.
+ * @return {@code true} if this object is the same as the obj
+ * argument; {@code false} otherwise.
+ */
+ boolean equals(Object obj);
+
+ /**
+ * Returns whether this flow rule is an exact match to the flow rule given
+ * in the argument.
+ * <p>
+ * Exact match means that deviceId, priority, selector,
+ * tableId, flowId and treatment are equal. Note that this differs from
+ * the notion of object equality for flow rules, which does not consider the
+ * flowId or treatment when testing equality.
+ * </p>
+ *
+ * @param rule other rule to match against
+ * @return true if the rules are an exact match, otherwise false
+ */
+ boolean exactMatch(FlowRule rule);
+
+ /**
* A flowrule builder.
*/
interface Builder {