Full long value for port numbers. Fix port number serializer.
Change-Id: I106ce3d39533e22f5a9a0e6972b91f669068198b
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 79068a9..18f822c 100644
--- a/core/api/src/main/java/org/onosproject/net/PortNumber.java
+++ b/core/api/src/main/java/org/onosproject/net/PortNumber.java
@@ -49,16 +49,19 @@
private final long number;
private final String name;
+ private final boolean hasName;
// Public creation is prohibited
private PortNumber(long number) {
this.number = number;
this.name = UnsignedLongs.toString(number);
+ this.hasName = false;
}
private PortNumber(long number, String name) {
this.number = number;
this.name = name;
+ this.hasName = true;
}
/**
@@ -99,7 +102,11 @@
* @return true if logical port number
*/
public boolean isLogical() {
- return number < 0 || number > MAX_NUMBER;
+ if (hasName) {
+ return false;
+ } else {
+ return (number < 0 || number > MAX_NUMBER);
+ }
}
/**
@@ -120,6 +127,16 @@
return name;
}
+ /**
+ * Indicates whether this port number was created with a port name,
+ * or only with a number.
+ *
+ * @return true if port was created with name
+ */
+ public boolean hasName() {
+ return hasName;
+ }
+
private String decodeLogicalPort() {
if (number == CONTROLLER_NUMBER) {
return "CONTROLLER";
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java
index 8c104fb..74db644 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/PortNumberSerializer.java
@@ -38,12 +38,19 @@
@Override
public void write(Kryo kryo, Output output, PortNumber object) {
+ output.writeBoolean(object.hasName());
output.writeLong(object.toLong());
+ if (object.hasName()) {
+ output.writeString(object.name());
+ }
}
@Override
- public PortNumber read(Kryo kryo, Input input,
- Class<PortNumber> type) {
- return PortNumber.portNumber(input.readLong());
+ public PortNumber read(Kryo kryo, Input input, Class<PortNumber> type) {
+ if (input.readBoolean()) {
+ return PortNumber.portNumber(input.readLong(), input.readString());
+ } else {
+ return PortNumber.portNumber(input.readLong());
+ }
}
}