Committed by
Gerrit Code Review
PortNumber also backed by port name
Change-Id: Id47781be714bf1efe7d008c8e97ab172177a85f9
Showing
2 changed files
with
26 additions
and
10 deletions
... | @@ -15,10 +15,10 @@ | ... | @@ -15,10 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net; | 16 | package org.onosproject.net; |
17 | 17 | ||
18 | -import java.util.Objects; | ||
19 | - | ||
20 | import com.google.common.primitives.UnsignedLongs; | 18 | import com.google.common.primitives.UnsignedLongs; |
21 | 19 | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | /** | 22 | /** |
23 | * Representation of a port number. | 23 | * Representation of a port number. |
24 | */ | 24 | */ |
... | @@ -48,10 +48,17 @@ public final class PortNumber { | ... | @@ -48,10 +48,17 @@ public final class PortNumber { |
48 | public static final PortNumber CONTROLLER = new PortNumber(CONTROLLER_NUMBER); | 48 | public static final PortNumber CONTROLLER = new PortNumber(CONTROLLER_NUMBER); |
49 | 49 | ||
50 | private final long number; | 50 | private final long number; |
51 | + private final String name; | ||
51 | 52 | ||
52 | // Public creation is prohibited | 53 | // Public creation is prohibited |
53 | private PortNumber(long number) { | 54 | private PortNumber(long number) { |
54 | this.number = number; | 55 | this.number = number; |
56 | + this.name = UnsignedLongs.toString(number); | ||
57 | + } | ||
58 | + | ||
59 | + private PortNumber(long number, String name) { | ||
60 | + this.number = number; | ||
61 | + this.name = name; | ||
55 | } | 62 | } |
56 | 63 | ||
57 | /** | 64 | /** |
... | @@ -75,6 +82,17 @@ public final class PortNumber { | ... | @@ -75,6 +82,17 @@ public final class PortNumber { |
75 | } | 82 | } |
76 | 83 | ||
77 | /** | 84 | /** |
85 | + * Returns the port number representing the specified long value and name. | ||
86 | + * | ||
87 | + * @param number port number as long value | ||
88 | + * @param name port name as string value | ||
89 | + * @return port number | ||
90 | + */ | ||
91 | + public static PortNumber portNumber(long number, String name) { | ||
92 | + return new PortNumber(number, name); | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
78 | * Indicates whether or not this port number is a reserved logical one or | 96 | * Indicates whether or not this port number is a reserved logical one or |
79 | * whether it corresponds to a normal physical port of a device or NIC. | 97 | * whether it corresponds to a normal physical port of a device or NIC. |
80 | * | 98 | * |
... | @@ -115,7 +133,7 @@ public final class PortNumber { | ... | @@ -115,7 +133,7 @@ public final class PortNumber { |
115 | @Override | 133 | @Override |
116 | public String toString() { | 134 | public String toString() { |
117 | if (!isLogical()) { | 135 | if (!isLogical()) { |
118 | - return UnsignedLongs.toString(number); | 136 | + return name; |
119 | } else { | 137 | } else { |
120 | return decodeLogicalPort(); | 138 | return decodeLogicalPort(); |
121 | } | 139 | } | ... | ... |
... | @@ -15,12 +15,11 @@ | ... | @@ -15,12 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net; | 16 | package org.onosproject.net; |
17 | 17 | ||
18 | -import static org.junit.Assert.assertEquals; | 18 | +import com.google.common.testing.EqualsTester; |
19 | -import static org.onosproject.net.PortNumber.portNumber; | ||
20 | - | ||
21 | import org.junit.Test; | 19 | import org.junit.Test; |
22 | 20 | ||
23 | -import com.google.common.testing.EqualsTester; | 21 | +import static org.junit.Assert.assertEquals; |
22 | +import static org.onosproject.net.PortNumber.portNumber; | ||
24 | 23 | ||
25 | /** | 24 | /** |
26 | * Test of the port number. | 25 | * Test of the port number. |
... | @@ -30,9 +29,8 @@ public class PortNumberTest { | ... | @@ -30,9 +29,8 @@ public class PortNumberTest { |
30 | @Test | 29 | @Test |
31 | public void basics() { | 30 | public void basics() { |
32 | new EqualsTester() | 31 | new EqualsTester() |
33 | - .addEqualityGroup(portNumber(123), | 32 | + .addEqualityGroup(portNumber(123), portNumber("123")) |
34 | - portNumber("123")) | 33 | + .addEqualityGroup(portNumber(321), portNumber(321, "LIM-3-2-1")) |
35 | - .addEqualityGroup(portNumber(321)) | ||
36 | .testEquals(); | 34 | .testEquals(); |
37 | } | 35 | } |
38 | 36 | ... | ... |
-
Please register or login to post a comment