Showing
17 changed files
with
256 additions
and
68 deletions
... | @@ -40,7 +40,7 @@ import static org.onlab.onos.net.DeviceId.deviceId; | ... | @@ -40,7 +40,7 @@ import static org.onlab.onos.net.DeviceId.deviceId; |
40 | description = "Lists all ports or all ports of a device") | 40 | description = "Lists all ports or all ports of a device") |
41 | public class DevicePortsListCommand extends DevicesListCommand { | 41 | public class DevicePortsListCommand extends DevicesListCommand { |
42 | 42 | ||
43 | - private static final String FMT = " port=%s, state=%s%s"; | 43 | + private static final String FMT = " port=%s, state=%s, type=%s, speed=%s%s"; |
44 | 44 | ||
45 | @Option(name = "-e", aliases = "--enabled", description = "Show only enabled ports", | 45 | @Option(name = "-e", aliases = "--enabled", description = "Show only enabled ports", |
46 | required = false, multiValued = false) | 46 | required = false, multiValued = false) |
... | @@ -110,10 +110,14 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -110,10 +110,14 @@ public class DevicePortsListCommand extends DevicesListCommand { |
110 | ports.add(mapper.createObjectNode() | 110 | ports.add(mapper.createObjectNode() |
111 | .put("port", port.number().toString()) | 111 | .put("port", port.number().toString()) |
112 | .put("isEnabled", port.isEnabled()) | 112 | .put("isEnabled", port.isEnabled()) |
113 | + .put("type", port.type().toString().toLowerCase()) | ||
114 | + .put("portSpeed", port.portSpeed()) | ||
113 | .set("annotations", annotations(mapper, port.annotations()))); | 115 | .set("annotations", annotations(mapper, port.annotations()))); |
114 | } | 116 | } |
115 | } | 117 | } |
116 | - return result.put("device", device.id().toString()).set("ports", ports); | 118 | + result.set("device", json(service, mapper, device)); |
119 | + result.set("ports", ports); | ||
120 | + return result; | ||
117 | } | 121 | } |
118 | 122 | ||
119 | // Determines if a port should be included in output. | 123 | // Determines if a port should be included in output. |
... | @@ -130,6 +134,7 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -130,6 +134,7 @@ public class DevicePortsListCommand extends DevicesListCommand { |
130 | for (Port port : ports) { | 134 | for (Port port : ports) { |
131 | if (isIncluded(port)) { | 135 | if (isIncluded(port)) { |
132 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled", | 136 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled", |
137 | + port.type().toString().toLowerCase(), port.portSpeed(), | ||
133 | annotations(port.annotations())); | 138 | annotations(port.annotations())); |
134 | } | 139 | } |
135 | } | 140 | } | ... | ... |
... | @@ -24,9 +24,27 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -24,9 +24,27 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
24 | */ | 24 | */ |
25 | public class DefaultPort extends AbstractAnnotated implements Port { | 25 | public class DefaultPort extends AbstractAnnotated implements Port { |
26 | 26 | ||
27 | + /** Default port speed in Mbps. */ | ||
28 | + public static final long DEFAULT_SPEED = 1_000; | ||
29 | + | ||
27 | private final Element element; | 30 | private final Element element; |
28 | private final PortNumber number; | 31 | private final PortNumber number; |
29 | private final boolean isEnabled; | 32 | private final boolean isEnabled; |
33 | + private final Type type; | ||
34 | + private final long portSpeed; | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates a network element attributed to the specified provider. | ||
38 | + * | ||
39 | + * @param element parent network element | ||
40 | + * @param number port number | ||
41 | + * @param isEnabled indicator whether the port is up and active | ||
42 | + * @param annotations optional key/value annotations | ||
43 | + */ | ||
44 | + public DefaultPort(Element element, PortNumber number, boolean isEnabled, | ||
45 | + Annotations... annotations) { | ||
46 | + this(element, number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations); | ||
47 | + } | ||
30 | 48 | ||
31 | /** | 49 | /** |
32 | * Creates a network element attributed to the specified provider. | 50 | * Creates a network element attributed to the specified provider. |
... | @@ -34,19 +52,49 @@ public class DefaultPort extends AbstractAnnotated implements Port { | ... | @@ -34,19 +52,49 @@ public class DefaultPort extends AbstractAnnotated implements Port { |
34 | * @param element parent network element | 52 | * @param element parent network element |
35 | * @param number port number | 53 | * @param number port number |
36 | * @param isEnabled indicator whether the port is up and active | 54 | * @param isEnabled indicator whether the port is up and active |
55 | + * @param type port type | ||
56 | + * @param portSpeed port speed in Mbs | ||
37 | * @param annotations optional key/value annotations | 57 | * @param annotations optional key/value annotations |
38 | */ | 58 | */ |
39 | - public DefaultPort(Element element, PortNumber number, | 59 | + public DefaultPort(Element element, PortNumber number, boolean isEnabled, |
40 | - boolean isEnabled, Annotations... annotations) { | 60 | + Type type, long portSpeed, Annotations... annotations) { |
41 | super(annotations); | 61 | super(annotations); |
42 | this.element = element; | 62 | this.element = element; |
43 | this.number = number; | 63 | this.number = number; |
44 | this.isEnabled = isEnabled; | 64 | this.isEnabled = isEnabled; |
65 | + this.type = type; | ||
66 | + this.portSpeed = portSpeed; | ||
67 | + | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public Element element() { | ||
72 | + return element; | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public PortNumber number() { | ||
77 | + return number; | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public boolean isEnabled() { | ||
82 | + return isEnabled; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public Type type() { | ||
87 | + return type; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public long portSpeed() { | ||
92 | + return portSpeed; | ||
45 | } | 93 | } |
46 | 94 | ||
47 | @Override | 95 | @Override |
48 | public int hashCode() { | 96 | public int hashCode() { |
49 | - return Objects.hash(number, isEnabled); | 97 | + return Objects.hash(number, isEnabled, type, portSpeed); |
50 | } | 98 | } |
51 | 99 | ||
52 | @Override | 100 | @Override |
... | @@ -58,7 +106,9 @@ public class DefaultPort extends AbstractAnnotated implements Port { | ... | @@ -58,7 +106,9 @@ public class DefaultPort extends AbstractAnnotated implements Port { |
58 | final DefaultPort other = (DefaultPort) obj; | 106 | final DefaultPort other = (DefaultPort) obj; |
59 | return Objects.equals(this.element.id(), other.element.id()) && | 107 | return Objects.equals(this.element.id(), other.element.id()) && |
60 | Objects.equals(this.number, other.number) && | 108 | Objects.equals(this.number, other.number) && |
61 | - Objects.equals(this.isEnabled, other.isEnabled); | 109 | + Objects.equals(this.isEnabled, other.isEnabled) && |
110 | + Objects.equals(this.type, other.type) && | ||
111 | + Objects.equals(this.portSpeed, other.portSpeed); | ||
62 | } | 112 | } |
63 | return false; | 113 | return false; |
64 | } | 114 | } |
... | @@ -69,22 +119,9 @@ public class DefaultPort extends AbstractAnnotated implements Port { | ... | @@ -69,22 +119,9 @@ public class DefaultPort extends AbstractAnnotated implements Port { |
69 | .add("element", element.id()) | 119 | .add("element", element.id()) |
70 | .add("number", number) | 120 | .add("number", number) |
71 | .add("isEnabled", isEnabled) | 121 | .add("isEnabled", isEnabled) |
122 | + .add("type", type) | ||
123 | + .add("portSpeed", portSpeed) | ||
72 | .toString(); | 124 | .toString(); |
73 | } | 125 | } |
74 | 126 | ||
75 | - @Override | ||
76 | - public PortNumber number() { | ||
77 | - return number; | ||
78 | - } | ||
79 | - | ||
80 | - @Override | ||
81 | - public boolean isEnabled() { | ||
82 | - return isEnabled; | ||
83 | - } | ||
84 | - | ||
85 | - @Override | ||
86 | - public Element element() { | ||
87 | - return element; | ||
88 | - } | ||
89 | - | ||
90 | } | 127 | } | ... | ... |
... | @@ -21,6 +21,26 @@ package org.onlab.onos.net; | ... | @@ -21,6 +21,26 @@ package org.onlab.onos.net; |
21 | */ | 21 | */ |
22 | public interface Port extends Annotated { | 22 | public interface Port extends Annotated { |
23 | 23 | ||
24 | + /** Represents coarse port type classification. */ | ||
25 | + public enum Type { | ||
26 | + /** | ||
27 | + * Signifies copper-based connectivity. | ||
28 | + */ | ||
29 | + COPPER, | ||
30 | + | ||
31 | + /** | ||
32 | + * Signifies optical fiber-based connectivity. | ||
33 | + */ | ||
34 | + FIBER | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the parent network element to which this port belongs. | ||
39 | + * | ||
40 | + * @return parent network element | ||
41 | + */ | ||
42 | + Element element(); | ||
43 | + | ||
24 | /** | 44 | /** |
25 | * Returns the port number. | 45 | * Returns the port number. |
26 | * | 46 | * |
... | @@ -36,12 +56,18 @@ public interface Port extends Annotated { | ... | @@ -36,12 +56,18 @@ public interface Port extends Annotated { |
36 | boolean isEnabled(); | 56 | boolean isEnabled(); |
37 | 57 | ||
38 | /** | 58 | /** |
39 | - * Returns the parent network element to which this port belongs. | 59 | + * Returns the port type. |
40 | * | 60 | * |
41 | - * @return parent network element | 61 | + * @return port type |
42 | */ | 62 | */ |
43 | - Element element(); | 63 | + Type type(); |
44 | 64 | ||
45 | - // set of port attributes | 65 | + /** |
66 | + * Returns the current port speed in Mbps. | ||
67 | + * | ||
68 | + * @return current port speed | ||
69 | + */ | ||
70 | + long portSpeed(); | ||
46 | 71 | ||
72 | + // TODO: more attributes? | ||
47 | } | 73 | } | ... | ... |
... | @@ -15,11 +15,12 @@ | ... | @@ -15,11 +15,12 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.device; | 16 | package org.onlab.onos.net.device; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
18 | import org.onlab.onos.net.AbstractDescription; | 19 | import org.onlab.onos.net.AbstractDescription; |
19 | import org.onlab.onos.net.PortNumber; | 20 | import org.onlab.onos.net.PortNumber; |
20 | import org.onlab.onos.net.SparseAnnotations; | 21 | import org.onlab.onos.net.SparseAnnotations; |
21 | 22 | ||
22 | -import com.google.common.base.MoreObjects; | 23 | +import static org.onlab.onos.net.Port.Type; |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * Default implementation of immutable port description. | 26 | * Default implementation of immutable port description. |
... | @@ -27,8 +28,12 @@ import com.google.common.base.MoreObjects; | ... | @@ -27,8 +28,12 @@ import com.google.common.base.MoreObjects; |
27 | public class DefaultPortDescription extends AbstractDescription | 28 | public class DefaultPortDescription extends AbstractDescription |
28 | implements PortDescription { | 29 | implements PortDescription { |
29 | 30 | ||
31 | + private static final long DEFAULT_SPEED = 1_000; | ||
32 | + | ||
30 | private final PortNumber number; | 33 | private final PortNumber number; |
31 | private final boolean isEnabled; | 34 | private final boolean isEnabled; |
35 | + private final Type type; | ||
36 | + private final long portSpeed; | ||
32 | 37 | ||
33 | /** | 38 | /** |
34 | * Creates a port description using the supplied information. | 39 | * Creates a port description using the supplied information. |
... | @@ -39,9 +44,34 @@ public class DefaultPortDescription extends AbstractDescription | ... | @@ -39,9 +44,34 @@ public class DefaultPortDescription extends AbstractDescription |
39 | */ | 44 | */ |
40 | public DefaultPortDescription(PortNumber number, boolean isEnabled, | 45 | public DefaultPortDescription(PortNumber number, boolean isEnabled, |
41 | SparseAnnotations... annotations) { | 46 | SparseAnnotations... annotations) { |
47 | + this(number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations); | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Creates a port description using the supplied information. | ||
52 | + * | ||
53 | + * @param number port number | ||
54 | + * @param isEnabled port enabled state | ||
55 | + * @param type port type | ||
56 | + * @param portSpeed port speed in Mbps | ||
57 | + * @param annotations optional key/value annotations map | ||
58 | + */ | ||
59 | + public DefaultPortDescription(PortNumber number, boolean isEnabled, | ||
60 | + Type type, long portSpeed, | ||
61 | + SparseAnnotations...annotations) { | ||
42 | super(annotations); | 62 | super(annotations); |
43 | this.number = number; | 63 | this.number = number; |
44 | this.isEnabled = isEnabled; | 64 | this.isEnabled = isEnabled; |
65 | + this.type = type; | ||
66 | + this.portSpeed = portSpeed; | ||
67 | + } | ||
68 | + | ||
69 | + // Default constructor for serialization | ||
70 | + private DefaultPortDescription() { | ||
71 | + this.number = null; | ||
72 | + this.isEnabled = false; | ||
73 | + this.portSpeed = DEFAULT_SPEED; | ||
74 | + this.type = Type.COPPER; | ||
45 | } | 75 | } |
46 | 76 | ||
47 | /** | 77 | /** |
... | @@ -52,7 +82,8 @@ public class DefaultPortDescription extends AbstractDescription | ... | @@ -52,7 +82,8 @@ public class DefaultPortDescription extends AbstractDescription |
52 | */ | 82 | */ |
53 | public DefaultPortDescription(PortDescription base, | 83 | public DefaultPortDescription(PortDescription base, |
54 | SparseAnnotations annotations) { | 84 | SparseAnnotations annotations) { |
55 | - this(base.portNumber(), base.isEnabled(), annotations); | 85 | + this(base.portNumber(), base.isEnabled(), base.type(), base.portSpeed(), |
86 | + annotations); | ||
56 | } | 87 | } |
57 | 88 | ||
58 | @Override | 89 | @Override |
... | @@ -66,17 +97,24 @@ public class DefaultPortDescription extends AbstractDescription | ... | @@ -66,17 +97,24 @@ public class DefaultPortDescription extends AbstractDescription |
66 | } | 97 | } |
67 | 98 | ||
68 | @Override | 99 | @Override |
100 | + public Type type() { | ||
101 | + return type; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public long portSpeed() { | ||
106 | + return portSpeed; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
69 | public String toString() { | 110 | public String toString() { |
70 | return MoreObjects.toStringHelper(getClass()) | 111 | return MoreObjects.toStringHelper(getClass()) |
71 | .add("number", number) | 112 | .add("number", number) |
72 | .add("isEnabled", isEnabled) | 113 | .add("isEnabled", isEnabled) |
114 | + .add("type", type) | ||
115 | + .add("portSpeed", portSpeed) | ||
73 | .add("annotations", annotations()) | 116 | .add("annotations", annotations()) |
74 | .toString(); | 117 | .toString(); |
75 | } | 118 | } |
76 | 119 | ||
77 | - // default constructor for serialization | ||
78 | - private DefaultPortDescription() { | ||
79 | - this.number = null; | ||
80 | - this.isEnabled = false; | ||
81 | - } | ||
82 | } | 120 | } | ... | ... |
... | @@ -18,13 +18,13 @@ package org.onlab.onos.net.device; | ... | @@ -18,13 +18,13 @@ package org.onlab.onos.net.device; |
18 | import org.onlab.onos.net.Description; | 18 | import org.onlab.onos.net.Description; |
19 | import org.onlab.onos.net.PortNumber; | 19 | import org.onlab.onos.net.PortNumber; |
20 | 20 | ||
21 | +import static org.onlab.onos.net.Port.Type; | ||
22 | + | ||
21 | /** | 23 | /** |
22 | * Information about a port. | 24 | * Information about a port. |
23 | */ | 25 | */ |
24 | public interface PortDescription extends Description { | 26 | public interface PortDescription extends Description { |
25 | 27 | ||
26 | - // TODO: possibly relocate this to a common ground so that this can also used by host tracking if required | ||
27 | - | ||
28 | /** | 28 | /** |
29 | * Returns the port number. | 29 | * Returns the port number. |
30 | * | 30 | * |
... | @@ -39,4 +39,18 @@ public interface PortDescription extends Description { | ... | @@ -39,4 +39,18 @@ public interface PortDescription extends Description { |
39 | */ | 39 | */ |
40 | boolean isEnabled(); | 40 | boolean isEnabled(); |
41 | 41 | ||
42 | + /** | ||
43 | + * Returns the port type. | ||
44 | + * | ||
45 | + * @return port type | ||
46 | + */ | ||
47 | + Type type(); | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns the current port speed in Mbps. | ||
51 | + * | ||
52 | + * @return current port speed | ||
53 | + */ | ||
54 | + long portSpeed(); | ||
55 | + | ||
42 | } | 56 | } | ... | ... |
... | @@ -23,6 +23,8 @@ import org.onlab.packet.ChassisId; | ... | @@ -23,6 +23,8 @@ import org.onlab.packet.ChassisId; |
23 | import static org.junit.Assert.assertEquals; | 23 | import static org.junit.Assert.assertEquals; |
24 | import static org.onlab.onos.net.Device.Type.SWITCH; | 24 | import static org.onlab.onos.net.Device.Type.SWITCH; |
25 | import static org.onlab.onos.net.DeviceId.deviceId; | 25 | import static org.onlab.onos.net.DeviceId.deviceId; |
26 | +import static org.onlab.onos.net.Port.Type.COPPER; | ||
27 | +import static org.onlab.onos.net.Port.Type.FIBER; | ||
26 | import static org.onlab.onos.net.PortNumber.portNumber; | 28 | import static org.onlab.onos.net.PortNumber.portNumber; |
27 | 29 | ||
28 | /** | 30 | /** |
... | @@ -35,15 +37,16 @@ public class DefaultPortTest { | ... | @@ -35,15 +37,16 @@ public class DefaultPortTest { |
35 | private static final DeviceId DID2 = deviceId("of:bar"); | 37 | private static final DeviceId DID2 = deviceId("of:bar"); |
36 | private static final PortNumber P1 = portNumber(1); | 38 | private static final PortNumber P1 = portNumber(1); |
37 | private static final PortNumber P2 = portNumber(2); | 39 | private static final PortNumber P2 = portNumber(2); |
40 | + private static final long SP1 = 1_000_000; | ||
38 | 41 | ||
39 | @Test | 42 | @Test |
40 | public void testEquality() { | 43 | public void testEquality() { |
41 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", | 44 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
42 | new ChassisId()); | 45 | new ChassisId()); |
43 | - Port p1 = new DefaultPort(device, portNumber(1), true); | 46 | + Port p1 = new DefaultPort(device, portNumber(1), true, COPPER, SP1); |
44 | - Port p2 = new DefaultPort(device, portNumber(1), true); | 47 | + Port p2 = new DefaultPort(device, portNumber(1), true, COPPER, SP1); |
45 | - Port p3 = new DefaultPort(device, portNumber(2), true); | 48 | + Port p3 = new DefaultPort(device, portNumber(2), true, FIBER, SP1); |
46 | - Port p4 = new DefaultPort(device, portNumber(2), true); | 49 | + Port p4 = new DefaultPort(device, portNumber(2), true, FIBER, SP1); |
47 | Port p5 = new DefaultPort(device, portNumber(1), false); | 50 | Port p5 = new DefaultPort(device, portNumber(1), false); |
48 | 51 | ||
49 | new EqualsTester().addEqualityGroup(p1, p2) | 52 | new EqualsTester().addEqualityGroup(p1, p2) |
... | @@ -56,10 +59,12 @@ public class DefaultPortTest { | ... | @@ -56,10 +59,12 @@ public class DefaultPortTest { |
56 | public void basics() { | 59 | public void basics() { |
57 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", | 60 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
58 | new ChassisId()); | 61 | new ChassisId()); |
59 | - Port port = new DefaultPort(device, portNumber(1), true); | 62 | + Port port = new DefaultPort(device, portNumber(1), true, FIBER, SP1); |
60 | assertEquals("incorrect element", device, port.element()); | 63 | assertEquals("incorrect element", device, port.element()); |
61 | assertEquals("incorrect number", portNumber(1), port.number()); | 64 | assertEquals("incorrect number", portNumber(1), port.number()); |
62 | assertEquals("incorrect state", true, port.isEnabled()); | 65 | assertEquals("incorrect state", true, port.isEnabled()); |
66 | + assertEquals("incorrect speed", SP1, port.portSpeed()); | ||
67 | + assertEquals("incorrect type", FIBER, port.type()); | ||
63 | } | 68 | } |
64 | 69 | ||
65 | } | 70 | } | ... | ... |
... | @@ -435,7 +435,8 @@ public class DeviceManager | ... | @@ -435,7 +435,8 @@ public class DeviceManager |
435 | return; | 435 | return; |
436 | } | 436 | } |
437 | //flag the device as online. Is there a better way to do this? | 437 | //flag the device as online. Is there a better way to do this? |
438 | - DeviceEvent devEvent = store.createOrUpdateDevice(device.providerId(), did, | 438 | + DeviceEvent devEvent = |
439 | + store.createOrUpdateDevice(device.providerId(), did, | ||
439 | new DefaultDeviceDescription( | 440 | new DefaultDeviceDescription( |
440 | did.uri(), device.type(), device.manufacturer(), | 441 | did.uri(), device.type(), device.manufacturer(), |
441 | device.hwVersion(), device.swVersion(), | 442 | device.hwVersion(), device.swVersion(), | ... | ... |
... | @@ -543,8 +543,9 @@ public class GossipDeviceStore | ... | @@ -543,8 +543,9 @@ public class GossipDeviceStore |
543 | Port newPort, | 543 | Port newPort, |
544 | Map<PortNumber, Port> ports) { | 544 | Map<PortNumber, Port> ports) { |
545 | if (oldPort.isEnabled() != newPort.isEnabled() || | 545 | if (oldPort.isEnabled() != newPort.isEnabled() || |
546 | + oldPort.type() != newPort.type() || | ||
547 | + oldPort.portSpeed() != newPort.portSpeed() || | ||
546 | !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { | 548 | !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { |
547 | - | ||
548 | ports.put(oldPort.number(), newPort); | 549 | ports.put(oldPort.number(), newPort); |
549 | return new DeviceEvent(PORT_UPDATED, device, newPort); | 550 | return new DeviceEvent(PORT_UPDATED, device, newPort); |
550 | } | 551 | } |
... | @@ -867,7 +868,10 @@ public class GossipDeviceStore | ... | @@ -867,7 +868,10 @@ public class GossipDeviceStore |
867 | } | 868 | } |
868 | } | 869 | } |
869 | 870 | ||
870 | - return new DefaultPort(device, number, isEnabled, annotations); | 871 | + return portDesc == null ? |
872 | + new DefaultPort(device, number, false, annotations) : | ||
873 | + new DefaultPort(device, number, isEnabled, portDesc.value().type(), | ||
874 | + portDesc.value().portSpeed(), annotations); | ||
871 | } | 875 | } |
872 | 876 | ||
873 | /** | 877 | /** | ... | ... |
... | @@ -115,6 +115,7 @@ public final class KryoNamespaces { | ... | @@ -115,6 +115,7 @@ public final class KryoNamespaces { |
115 | // | 115 | // |
116 | ControllerNode.State.class, | 116 | ControllerNode.State.class, |
117 | Device.Type.class, | 117 | Device.Type.class, |
118 | + Port.Type.class, | ||
118 | ChassisId.class, | 119 | ChassisId.class, |
119 | DefaultAnnotations.class, | 120 | DefaultAnnotations.class, |
120 | DefaultControllerNode.class, | 121 | DefaultControllerNode.class, | ... | ... |
... | @@ -15,13 +15,10 @@ | ... | @@ -15,13 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.serializers; | 16 | package org.onlab.onos.store.serializers; |
17 | 17 | ||
18 | -import static org.junit.Assert.assertEquals; | 18 | +import com.google.common.collect.ImmutableList; |
19 | -import static org.onlab.onos.net.DeviceId.deviceId; | 19 | +import com.google.common.collect.ImmutableMap; |
20 | -import static org.onlab.onos.net.PortNumber.portNumber; | 20 | +import com.google.common.collect.ImmutableSet; |
21 | -import static java.util.Arrays.asList; | 21 | +import com.google.common.testing.EqualsTester; |
22 | - | ||
23 | -import java.nio.ByteBuffer; | ||
24 | - | ||
25 | import org.junit.After; | 22 | import org.junit.After; |
26 | import org.junit.Before; | 23 | import org.junit.Before; |
27 | import org.junit.BeforeClass; | 24 | import org.junit.BeforeClass; |
... | @@ -50,10 +47,12 @@ import org.onlab.packet.IpPrefix; | ... | @@ -50,10 +47,12 @@ import org.onlab.packet.IpPrefix; |
50 | import org.onlab.packet.MacAddress; | 47 | import org.onlab.packet.MacAddress; |
51 | import org.onlab.util.KryoNamespace; | 48 | import org.onlab.util.KryoNamespace; |
52 | 49 | ||
53 | -import com.google.common.collect.ImmutableList; | 50 | +import java.nio.ByteBuffer; |
54 | -import com.google.common.collect.ImmutableMap; | 51 | + |
55 | -import com.google.common.collect.ImmutableSet; | 52 | +import static java.util.Arrays.asList; |
56 | -import com.google.common.testing.EqualsTester; | 53 | +import static org.junit.Assert.assertEquals; |
54 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
55 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
57 | 56 | ||
58 | public class KryoSerializerTest { | 57 | public class KryoSerializerTest { |
59 | 58 | ... | ... |
... | @@ -291,8 +291,9 @@ public class SimpleDeviceStore | ... | @@ -291,8 +291,9 @@ public class SimpleDeviceStore |
291 | Port newPort, | 291 | Port newPort, |
292 | Map<PortNumber, Port> ports) { | 292 | Map<PortNumber, Port> ports) { |
293 | if (oldPort.isEnabled() != newPort.isEnabled() || | 293 | if (oldPort.isEnabled() != newPort.isEnabled() || |
294 | + oldPort.type() != newPort.type() || | ||
295 | + oldPort.portSpeed() != newPort.portSpeed() || | ||
294 | !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { | 296 | !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { |
295 | - | ||
296 | ports.put(oldPort.number(), newPort); | 297 | ports.put(oldPort.number(), newPort); |
297 | return new DeviceEvent(PORT_UPDATED, device, newPort); | 298 | return new DeviceEvent(PORT_UPDATED, device, newPort); |
298 | } | 299 | } |
... | @@ -510,7 +511,10 @@ public class SimpleDeviceStore | ... | @@ -510,7 +511,10 @@ public class SimpleDeviceStore |
510 | } | 511 | } |
511 | } | 512 | } |
512 | 513 | ||
513 | - return new DefaultPort(device, number, isEnabled, annotations); | 514 | + return portDesc == null ? |
515 | + new DefaultPort(device, number, false, annotations) : | ||
516 | + new DefaultPort(device, number, isEnabled, portDesc.type(), | ||
517 | + portDesc.portSpeed(), annotations); | ||
514 | } | 518 | } |
515 | 519 | ||
516 | /** | 520 | /** | ... | ... |
... | @@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | import org.onlab.onos.net.Device; | 23 | import org.onlab.onos.net.Device; |
24 | import org.onlab.onos.net.DeviceId; | 24 | import org.onlab.onos.net.DeviceId; |
25 | import org.onlab.onos.net.MastershipRole; | 25 | import org.onlab.onos.net.MastershipRole; |
26 | +import org.onlab.onos.net.Port; | ||
26 | import org.onlab.onos.net.PortNumber; | 27 | import org.onlab.onos.net.PortNumber; |
27 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 28 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
28 | import org.onlab.onos.net.device.DefaultPortDescription; | 29 | import org.onlab.onos.net.device.DefaultPortDescription; |
... | @@ -43,14 +44,19 @@ import org.onlab.packet.ChassisId; | ... | @@ -43,14 +44,19 @@ import org.onlab.packet.ChassisId; |
43 | import org.projectfloodlight.openflow.protocol.OFFactory; | 44 | import org.projectfloodlight.openflow.protocol.OFFactory; |
44 | import org.projectfloodlight.openflow.protocol.OFPortConfig; | 45 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
45 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 46 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
47 | +import org.projectfloodlight.openflow.protocol.OFPortFeatures; | ||
46 | import org.projectfloodlight.openflow.protocol.OFPortState; | 48 | import org.projectfloodlight.openflow.protocol.OFPortState; |
47 | import org.projectfloodlight.openflow.protocol.OFPortStatus; | 49 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
50 | +import org.projectfloodlight.openflow.protocol.OFVersion; | ||
51 | +import org.projectfloodlight.openflow.types.PortSpeed; | ||
48 | import org.slf4j.Logger; | 52 | import org.slf4j.Logger; |
49 | 53 | ||
50 | import java.util.ArrayList; | 54 | import java.util.ArrayList; |
51 | import java.util.List; | 55 | import java.util.List; |
52 | 56 | ||
53 | import static org.onlab.onos.net.DeviceId.deviceId; | 57 | import static org.onlab.onos.net.DeviceId.deviceId; |
58 | +import static org.onlab.onos.net.Port.Type.COPPER; | ||
59 | +import static org.onlab.onos.net.Port.Type.FIBER; | ||
54 | import static org.onlab.onos.openflow.controller.Dpid.dpid; | 60 | import static org.onlab.onos.openflow.controller.Dpid.dpid; |
55 | import static org.onlab.onos.openflow.controller.Dpid.uri; | 61 | import static org.onlab.onos.openflow.controller.Dpid.uri; |
56 | import static org.slf4j.LoggerFactory.getLogger; | 62 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -63,6 +69,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -63,6 +69,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
63 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { | 69 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { |
64 | 70 | ||
65 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); | 71 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); |
72 | + private static final long MBPS = 1_000 * 1_000; | ||
66 | 73 | ||
67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
68 | protected DeviceProviderRegistry providerRegistry; | 75 | protected DeviceProviderRegistry providerRegistry; |
... | @@ -244,8 +251,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -244,8 +251,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
244 | * @param ports the list of ports | 251 | * @param ports the list of ports |
245 | * @return list of portdescriptions | 252 | * @return list of portdescriptions |
246 | */ | 253 | */ |
247 | - private List<PortDescription> buildPortDescriptions( | 254 | + private List<PortDescription> buildPortDescriptions(List<OFPortDesc> ports) { |
248 | - List<OFPortDesc> ports) { | ||
249 | final List<PortDescription> portDescs = new ArrayList<>(ports.size()); | 255 | final List<PortDescription> portDescs = new ArrayList<>(ports.size()); |
250 | for (OFPortDesc port : ports) { | 256 | for (OFPortDesc port : ports) { |
251 | portDescs.add(buildPortDescription(port)); | 257 | portDescs.add(buildPortDescription(port)); |
... | @@ -260,12 +266,25 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -260,12 +266,25 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
260 | * @return portDescription for the port. | 266 | * @return portDescription for the port. |
261 | */ | 267 | */ |
262 | private PortDescription buildPortDescription(OFPortDesc port) { | 268 | private PortDescription buildPortDescription(OFPortDesc port) { |
263 | - final PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | 269 | + PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
264 | - final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && | 270 | + boolean enabled = |
271 | + !port.getState().contains(OFPortState.LINK_DOWN) && | ||
265 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); | 272 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
266 | - return new DefaultPortDescription(portNo, enabled); | 273 | + Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
274 | + return new DefaultPortDescription(portNo, enabled, type, portSpeed(port)); | ||
267 | } | 275 | } |
268 | 276 | ||
277 | + private long portSpeed(OFPortDesc port) { | ||
278 | + if (port.getVersion() == OFVersion.OF_13) { | ||
279 | + return port.getCurrSpeed() / MBPS; | ||
280 | + } | ||
281 | + | ||
282 | + PortSpeed portSpeed = PortSpeed.SPEED_NONE; | ||
283 | + for (OFPortFeatures feat : port.getCurr()) { | ||
284 | + portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); | ||
285 | + } | ||
286 | + return portSpeed.getSpeedBps() / MBPS; | ||
287 | + } | ||
269 | } | 288 | } |
270 | 289 | ||
271 | } | 290 | } | ... | ... |
... | @@ -6,4 +6,4 @@ | ... | @@ -6,4 +6,4 @@ |
6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
7 | . $ONOS_ROOT/tools/build/envDefaults | 7 | . $ONOS_ROOT/tools/build/envDefaults |
8 | 8 | ||
9 | -cd $ONOS_ROOT && mvn clean install && cd docs && mvn javadoc:aggregate | 9 | +cd $ONOS_ROOT && mvn clean install "$@" && cd docs && mvn javadoc:aggregate | ... | ... |
... | @@ -34,6 +34,7 @@ alias mci='mvn clean install' | ... | @@ -34,6 +34,7 @@ alias mci='mvn clean install' |
34 | 34 | ||
35 | # Short-hand for ONOS build, package and test. | 35 | # Short-hand for ONOS build, package and test. |
36 | alias ob='onos-build' | 36 | alias ob='onos-build' |
37 | +alias obi='onos-build -Dmaven.test.failure.ignore=true' | ||
37 | alias obs='onos-build-selective' | 38 | alias obs='onos-build-selective' |
38 | alias op='onos-package' | 39 | alias op='onos-package' |
39 | alias ot='onos-test' | 40 | alias ot='onos-test' | ... | ... |
... | @@ -3,28 +3,33 @@ | ... | @@ -3,28 +3,33 @@ |
3 | { | 3 | { |
4 | "uri": "of:0000ffffffffff01", "mac": "ffffffffffff01", "type": "ROADM", | 4 | "uri": "of:0000ffffffffff01", "mac": "ffffffffffff01", "type": "ROADM", |
5 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM1", | 5 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM1", |
6 | - "annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 } | 6 | + "annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 }, |
7 | + "ports": [ { "port": 10, "speed": 100000, "type": "FIBER" }, { "port": 20, "speed": 0, "type": "FIBER" } ] | ||
7 | }, | 8 | }, |
8 | { | 9 | { |
9 | "uri": "of:0000ffffffffff02", "mac": "ffffffffffff02", "type": "ROADM", | 10 | "uri": "of:0000ffffffffff02", "mac": "ffffffffffff02", "type": "ROADM", |
10 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM2", | 11 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM2", |
11 | - "annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 } | 12 | + "annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 }, |
13 | + "ports": [ { "port": 11, "speed": 100000, "type": "FIBER" }, { "port": 21, "speed": 0, "type": "FIBER" } ] | ||
12 | }, | 14 | }, |
13 | { | 15 | { |
14 | "uri": "of:0000ffffffffff03", "mac": "ffffffffffff03", "type": "ROADM", | 16 | "uri": "of:0000ffffffffff03", "mac": "ffffffffffff03", "type": "ROADM", |
15 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM3", | 17 | "mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM3", |
16 | - "annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 } | 18 | + "annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 }, |
19 | + "ports": [ { "port": 30, "speed": 0, "type": "FIBER" }, { "port": 31, "speed": 0, "type": "FIBER" } ] | ||
17 | }, | 20 | }, |
18 | 21 | ||
19 | { | 22 | { |
20 | "uri": "of:0000ffffffff0001", "mac": "ffffffffff0003", "type": "SWITCH", | 23 | "uri": "of:0000ffffffff0001", "mac": "ffffffffff0003", "type": "SWITCH", |
21 | "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER1", | 24 | "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER1", |
22 | - "annotations": { "latitude": 37.6, "longitude": 122.3 } | 25 | + "annotations": { "latitude": 37.6, "longitude": 122.3 }, |
26 | + "ports": [ { "port": 1, "speed": 10000, "type": "COPPER" }, { "port": 2, "speed": 100000, "type": "FIBER" } ] | ||
23 | }, | 27 | }, |
24 | { | 28 | { |
25 | "uri": "of:0000ffffffff0002", "mac": "ffffffffff0002", "type": "SWITCH", | 29 | "uri": "of:0000ffffffff0002", "mac": "ffffffffff0002", "type": "SWITCH", |
26 | "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER2", | 30 | "mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER2", |
27 | - "annotations": { "latitude": 37.3, "longitude": 121.9 } | 31 | + "annotations": { "latitude": 37.3, "longitude": 121.9 }, |
32 | + "ports": [ { "port": 1, "speed": 10000, "type": "COPPER" }, { "port": 2, "speed": 100000, "type": "FIBER" } ] | ||
28 | } | 33 | } |
29 | ], | 34 | ], |
30 | 35 | ... | ... |
... | @@ -202,7 +202,7 @@ public final class IpAddress implements Comparable<IpAddress> { | ... | @@ -202,7 +202,7 @@ public final class IpAddress implements Comparable<IpAddress> { |
202 | 202 | ||
203 | @Override | 203 | @Override |
204 | public int hashCode() { | 204 | public int hashCode() { |
205 | - return Objects.hash(version, octets); | 205 | + return Objects.hash(version, Arrays.hashCode(octets)); |
206 | } | 206 | } |
207 | 207 | ||
208 | @Override | 208 | @Override | ... | ... |
... | @@ -19,17 +19,21 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,17 +19,21 @@ import com.fasterxml.jackson.databind.JsonNode; |
19 | import org.onlab.onos.net.ConnectPoint; | 19 | import org.onlab.onos.net.ConnectPoint; |
20 | import org.onlab.onos.net.DefaultAnnotations; | 20 | import org.onlab.onos.net.DefaultAnnotations; |
21 | import org.onlab.onos.net.Device; | 21 | import org.onlab.onos.net.Device; |
22 | +import org.onlab.onos.net.DeviceId; | ||
22 | import org.onlab.onos.net.Host; | 23 | import org.onlab.onos.net.Host; |
23 | import org.onlab.onos.net.HostId; | 24 | import org.onlab.onos.net.HostId; |
24 | import org.onlab.onos.net.HostLocation; | 25 | import org.onlab.onos.net.HostLocation; |
25 | import org.onlab.onos.net.Link; | 26 | import org.onlab.onos.net.Link; |
26 | import org.onlab.onos.net.MastershipRole; | 27 | import org.onlab.onos.net.MastershipRole; |
28 | +import org.onlab.onos.net.Port; | ||
27 | import org.onlab.onos.net.SparseAnnotations; | 29 | import org.onlab.onos.net.SparseAnnotations; |
28 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 30 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
31 | +import org.onlab.onos.net.device.DefaultPortDescription; | ||
29 | import org.onlab.onos.net.device.DeviceDescription; | 32 | import org.onlab.onos.net.device.DeviceDescription; |
30 | import org.onlab.onos.net.device.DeviceProvider; | 33 | import org.onlab.onos.net.device.DeviceProvider; |
31 | import org.onlab.onos.net.device.DeviceProviderRegistry; | 34 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
32 | import org.onlab.onos.net.device.DeviceProviderService; | 35 | import org.onlab.onos.net.device.DeviceProviderService; |
36 | +import org.onlab.onos.net.device.PortDescription; | ||
33 | import org.onlab.onos.net.host.DefaultHostDescription; | 37 | import org.onlab.onos.net.host.DefaultHostDescription; |
34 | import org.onlab.onos.net.host.HostProvider; | 38 | import org.onlab.onos.net.host.HostProvider; |
35 | import org.onlab.onos.net.host.HostProviderRegistry; | 39 | import org.onlab.onos.net.host.HostProviderRegistry; |
... | @@ -45,7 +49,9 @@ import org.onlab.packet.MacAddress; | ... | @@ -45,7 +49,9 @@ import org.onlab.packet.MacAddress; |
45 | import org.onlab.packet.VlanId; | 49 | import org.onlab.packet.VlanId; |
46 | 50 | ||
47 | import java.net.URI; | 51 | import java.net.URI; |
52 | +import java.util.ArrayList; | ||
48 | import java.util.Iterator; | 53 | import java.util.Iterator; |
54 | +import java.util.List; | ||
49 | 55 | ||
50 | import static com.google.common.base.Preconditions.checkNotNull; | 56 | import static com.google.common.base.Preconditions.checkNotNull; |
51 | import static org.onlab.onos.net.DeviceId.deviceId; | 57 | import static org.onlab.onos.net.DeviceId.deviceId; |
... | @@ -120,7 +126,30 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { | ... | @@ -120,7 +126,30 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { |
120 | DeviceDescription desc = | 126 | DeviceDescription desc = |
121 | new DefaultDeviceDescription(uri, type, mfr, hw, sw, serial, | 127 | new DefaultDeviceDescription(uri, type, mfr, hw, sw, serial, |
122 | cid, annotations); | 128 | cid, annotations); |
123 | - dps.deviceConnected(deviceId(uri), desc); | 129 | + DeviceId deviceId = deviceId(uri); |
130 | + dps.deviceConnected(deviceId, desc); | ||
131 | + | ||
132 | + JsonNode ports = node.get("ports"); | ||
133 | + if (ports != null) { | ||
134 | + parsePorts(dps, deviceId, ports); | ||
135 | + } | ||
136 | + } | ||
137 | + | ||
138 | + // Parses the given node with list of device ports. | ||
139 | + private void parsePorts(DeviceProviderService dps, DeviceId deviceId, JsonNode nodes) { | ||
140 | + List<PortDescription> ports = new ArrayList<>(); | ||
141 | + for (JsonNode node : nodes) { | ||
142 | + ports.add(parsePort(node)); | ||
143 | + } | ||
144 | + dps.updatePorts(deviceId, ports); | ||
145 | + } | ||
146 | + | ||
147 | + // Parses the given node with port information. | ||
148 | + private PortDescription parsePort(JsonNode node) { | ||
149 | + Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER")); | ||
150 | + return new DefaultPortDescription(portNumber(node.path("port").asLong(0)), | ||
151 | + node.path("enabled").asBoolean(true), | ||
152 | + type, node.path("speed").asLong(1_000)); | ||
124 | } | 153 | } |
125 | 154 | ||
126 | // Parses the given JSON and provides links as configured. | 155 | // Parses the given JSON and provides links as configured. | ... | ... |
-
Please register or login to post a comment