[AETHER-539] Fix for flowId computation
This patch includes:
- New methods in the PortNumber to take into account the port name
- PortCriterion uses the new toString method to avoid mismatch
in the flowId computation
- The original toString() method is left unchanged to avoid
disply issues of the ports with names
Change-Id: I392281b5eee160227886f9738fae97f237b1b04f
diff --git a/core/api/src/main/java/org/onosproject/net/PortNumber.java b/core/api/src/main/java/org/onosproject/net/PortNumber.java
index 9d1d7b7..54c35fb 100644
--- a/core/api/src/main/java/org/onosproject/net/PortNumber.java
+++ b/core/api/src/main/java/org/onosproject/net/PortNumber.java
@@ -232,6 +232,15 @@
// enum name
return logical.toString();
}
+ return String.format("%s", UnsignedLongs.toString(number));
+ }
+
+ private String decodeLogicalPortExtended() {
+ Logical logical = LOGICAL.get().get(number);
+ if (logical != null) {
+ // enum name
+ return logical.toString();
+ }
return String.format("UNKNOWN(%s)", UnsignedLongs.toString(number));
}
@@ -250,7 +259,7 @@
@Override
public String toString() {
if (isLogical()) {
- return decodeLogicalPort();
+ return decodeLogicalPortExtended();
} else if (hasName()) {
// named port
if (number == NO_DISPLAY_NUMBER) {
@@ -264,11 +273,27 @@
}
}
+ // toString method that does not use the name.
+ // if it is a logical port will use either the enum or the number
+ // else if it has a name returns just the number
+ // else it does not have a name, it returns the number because name == number
+ public String toStringWithoutName() {
+ if (isLogical()) {
+ return decodeLogicalPort();
+ }
+ // Either named port or port without name
+ return UnsignedLongs.toString(number);
+ }
+
@Override
public int hashCode() {
return Long.hashCode(number);
}
+ public int hashCodeExtended() {
+ return Objects.hashCode(number, hasName() ? name : 0);
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/PortCriterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/PortCriterion.java
index af0673b..a2c49a1 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/PortCriterion.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/PortCriterion.java
@@ -54,7 +54,7 @@
@Override
public String toString() {
- return type().toString() + SEPARATOR + port;
+ return type().toString() + SEPARATOR + port.toStringWithoutName();
}
@Override