Showing
4 changed files
with
35 additions
and
31 deletions
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import com.google.common.primitives.UnsignedLongs; | ||
4 | - | ||
5 | import java.util.Objects; | 3 | import java.util.Objects; |
6 | 4 | ||
7 | -import static com.google.common.base.Preconditions.checkArgument; | 5 | +import com.google.common.primitives.UnsignedLongs; |
8 | 6 | ||
9 | /** | 7 | /** |
10 | * Representation of a port number. | 8 | * Representation of a port number. |
... | @@ -17,9 +15,6 @@ public final class PortNumber { | ... | @@ -17,9 +15,6 @@ public final class PortNumber { |
17 | 15 | ||
18 | // Public creation is prohibited | 16 | // Public creation is prohibited |
19 | private PortNumber(long number) { | 17 | private PortNumber(long number) { |
20 | - checkArgument(number >= 0 && number < MAX_NUMBER, | ||
21 | - "Port number %d is outside the supported range [0, %d)", | ||
22 | - number, MAX_NUMBER); | ||
23 | this.number = number; | 18 | this.number = number; |
24 | } | 19 | } |
25 | 20 | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import com.google.common.testing.EqualsTester; | ||
4 | -import org.junit.Test; | ||
5 | - | ||
6 | import static org.junit.Assert.assertEquals; | 3 | import static org.junit.Assert.assertEquals; |
7 | import static org.onlab.onos.net.PortNumber.portNumber; | 4 | import static org.onlab.onos.net.PortNumber.portNumber; |
8 | 5 | ||
6 | +import org.junit.Test; | ||
7 | + | ||
8 | +import com.google.common.testing.EqualsTester; | ||
9 | + | ||
9 | /** | 10 | /** |
10 | * Test of the port number. | 11 | * Test of the port number. |
11 | */ | 12 | */ |
12 | public class PortNumberTest extends ElementIdTest { | 13 | public class PortNumberTest extends ElementIdTest { |
13 | 14 | ||
15 | + @Override | ||
14 | @Test | 16 | @Test |
15 | public void basics() { | 17 | public void basics() { |
16 | new EqualsTester() | 18 | new EqualsTester() |
17 | - .addEqualityGroup(portNumber(123), | 19 | + .addEqualityGroup(portNumber(123), |
18 | - portNumber("123")) | 20 | + portNumber("123")) |
19 | .addEqualityGroup(portNumber(321)) | 21 | .addEqualityGroup(portNumber(321)) |
20 | .testEquals(); | 22 | .testEquals(); |
21 | } | 23 | } |
... | @@ -25,13 +27,5 @@ public class PortNumberTest extends ElementIdTest { | ... | @@ -25,13 +27,5 @@ public class PortNumberTest extends ElementIdTest { |
25 | assertEquals("incorrect long value", 12345, portNumber(12345).toLong()); | 27 | assertEquals("incorrect long value", 12345, portNumber(12345).toLong()); |
26 | } | 28 | } |
27 | 29 | ||
28 | - @Test(expected = IllegalArgumentException.class) | ||
29 | - public void negative() { | ||
30 | - portNumber(-1); | ||
31 | - } | ||
32 | 30 | ||
33 | - @Test(expected = IllegalArgumentException.class) | ||
34 | - public void tooBig() { | ||
35 | - portNumber((2L * Integer.MAX_VALUE) + 2); | ||
36 | - } | ||
37 | } | 31 | } | ... | ... |
1 | package org.onlab.onos.of.drivers.impl; | 1 | package org.onlab.onos.of.drivers.impl; |
2 | 2 | ||
3 | +import java.util.Collections; | ||
3 | import java.util.List; | 4 | import java.util.List; |
4 | 5 | ||
5 | import org.onlab.onos.of.controller.Dpid; | 6 | import org.onlab.onos.of.controller.Dpid; |
6 | import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; | 7 | import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; |
7 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | 8 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
8 | import org.projectfloodlight.openflow.protocol.OFMessage; | 9 | import org.projectfloodlight.openflow.protocol.OFMessage; |
10 | +import org.projectfloodlight.openflow.protocol.OFPortDesc; | ||
9 | 11 | ||
10 | /** | 12 | /** |
11 | * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make | 13 | * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make |
... | @@ -56,4 +58,11 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch { | ... | @@ -56,4 +58,11 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch { |
56 | public void write(List<OFMessage> msgs) { | 58 | public void write(List<OFMessage> msgs) { |
57 | channel.write(msgs); | 59 | channel.write(msgs); |
58 | } | 60 | } |
61 | + | ||
62 | + @Override | ||
63 | + public List<OFPortDesc> getPorts() { | ||
64 | + return Collections.unmodifiableList(features.getPorts()); | ||
65 | + } | ||
66 | + | ||
67 | + | ||
59 | } | 68 | } | ... | ... |
providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
... | @@ -30,7 +30,9 @@ import org.onlab.onos.of.controller.OpenFlowController; | ... | @@ -30,7 +30,9 @@ import org.onlab.onos.of.controller.OpenFlowController; |
30 | import org.onlab.onos.of.controller.OpenFlowSwitch; | 30 | import org.onlab.onos.of.controller.OpenFlowSwitch; |
31 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; | 31 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; |
32 | import org.onlab.onos.of.controller.RoleState; | 32 | import org.onlab.onos.of.controller.RoleState; |
33 | +import org.projectfloodlight.openflow.protocol.OFPortConfig; | ||
33 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 34 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
35 | +import org.projectfloodlight.openflow.protocol.OFPortState; | ||
34 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
35 | 37 | ||
36 | /** | 38 | /** |
... | @@ -50,7 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -50,7 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
50 | 52 | ||
51 | private DeviceProviderService providerService; | 53 | private DeviceProviderService providerService; |
52 | 54 | ||
53 | - private OpenFlowSwitchListener listener = new InternalDeviceProvider(); | 55 | + private final OpenFlowSwitchListener listener = new InternalDeviceProvider(); |
54 | 56 | ||
55 | /** | 57 | /** |
56 | * Creates an OpenFlow device provider. | 58 | * Creates an OpenFlow device provider. |
... | @@ -119,17 +121,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -119,17 +121,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
119 | providerService.updatePorts(deviceId(uri), buildPortDescriptions(sw.getPorts())); | 121 | providerService.updatePorts(deviceId(uri), buildPortDescriptions(sw.getPorts())); |
120 | } | 122 | } |
121 | 123 | ||
122 | - private List<PortDescription> buildPortDescriptions( | ||
123 | - List<OFPortDesc> ports) { | ||
124 | - List<PortDescription> portDescs = new ArrayList<PortDescription>(); | ||
125 | - for (OFPortDesc port : ports) { | ||
126 | - PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | ||
127 | - | ||
128 | - portDescs.add(new DefaultPortDescription(portNo, | ||
129 | - port.getState())); | ||
130 | - } | ||
131 | - } | ||
132 | - | ||
133 | @Override | 124 | @Override |
134 | public void switchRemoved(Dpid dpid) { | 125 | public void switchRemoved(Dpid dpid) { |
135 | if (providerService == null) { | 126 | if (providerService == null) { |
... | @@ -149,6 +140,21 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -149,6 +140,21 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
149 | return uri; | 140 | return uri; |
150 | } | 141 | } |
151 | 142 | ||
143 | + private List<PortDescription> buildPortDescriptions( | ||
144 | + List<OFPortDesc> ports) { | ||
145 | + final List<PortDescription> portDescs = new ArrayList<PortDescription>(); | ||
146 | + PortNumber portNo; | ||
147 | + boolean enabled; | ||
148 | + for (OFPortDesc port : ports) { | ||
149 | + portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | ||
150 | + enabled = !port.getState().contains(OFPortState.LINK_DOWN) && | ||
151 | + !port.getConfig().contains(OFPortConfig.PORT_DOWN); | ||
152 | + portDescs.add(new DefaultPortDescription(portNo, | ||
153 | + enabled)); | ||
154 | + } | ||
155 | + return portDescs; | ||
156 | + } | ||
157 | + | ||
152 | } | 158 | } |
153 | 159 | ||
154 | } | 160 | } | ... | ... |
-
Please register or login to post a comment