Showing
3 changed files
with
68 additions
and
6 deletions
... | @@ -147,7 +147,7 @@ public class SimpleDeviceManager | ... | @@ -147,7 +147,7 @@ public class SimpleDeviceManager |
147 | public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { | 147 | public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { |
148 | checkNotNull(deviceId, DEVICE_ID_NULL); | 148 | checkNotNull(deviceId, DEVICE_ID_NULL); |
149 | checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL); | 149 | checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL); |
150 | - log.info("Device {} connected: {}", deviceId, deviceDescription); | 150 | + log.info("Device {} connected", deviceId); |
151 | DeviceEvent event = store.createOrUpdateDevice(provider().id(), | 151 | DeviceEvent event = store.createOrUpdateDevice(provider().id(), |
152 | deviceId, deviceDescription); | 152 | deviceId, deviceDescription); |
153 | post(event); | 153 | post(event); |
... | @@ -165,7 +165,7 @@ public class SimpleDeviceManager | ... | @@ -165,7 +165,7 @@ public class SimpleDeviceManager |
165 | public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { | 165 | public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { |
166 | checkNotNull(deviceId, DEVICE_ID_NULL); | 166 | checkNotNull(deviceId, DEVICE_ID_NULL); |
167 | checkNotNull(portDescriptions, "Port descriptions list cannot be null"); | 167 | checkNotNull(portDescriptions, "Port descriptions list cannot be null"); |
168 | - log.info("Device {} ports updated: {}", portDescriptions); | 168 | + log.info("Device {} ports updated", deviceId); |
169 | List<DeviceEvent> events = store.updatePorts(deviceId, portDescriptions); | 169 | List<DeviceEvent> events = store.updatePorts(deviceId, portDescriptions); |
170 | for (DeviceEvent event : events) { | 170 | for (DeviceEvent event : events) { |
171 | post(event); | 171 | post(event); |
... | @@ -176,7 +176,7 @@ public class SimpleDeviceManager | ... | @@ -176,7 +176,7 @@ public class SimpleDeviceManager |
176 | public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) { | 176 | public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) { |
177 | checkNotNull(deviceId, DEVICE_ID_NULL); | 177 | checkNotNull(deviceId, DEVICE_ID_NULL); |
178 | checkNotNull(portDescription, PORT_DESCRIPTION_NULL); | 178 | checkNotNull(portDescription, PORT_DESCRIPTION_NULL); |
179 | - log.info("Device {} port status changed: {}", deviceId, portDescription); | 179 | + log.info("Device {} port status changed", deviceId); |
180 | DeviceEvent event = store.updatePortStatus(deviceId, portDescription); | 180 | DeviceEvent event = store.updatePortStatus(deviceId, portDescription); |
181 | post(event); | 181 | post(event); |
182 | } | 182 | } | ... | ... |
... | @@ -153,9 +153,9 @@ class SimpleDeviceStore { | ... | @@ -153,9 +153,9 @@ class SimpleDeviceStore { |
153 | Set<PortNumber> processed = new HashSet<>(); | 153 | Set<PortNumber> processed = new HashSet<>(); |
154 | for (PortDescription portDescription : portDescriptions) { | 154 | for (PortDescription portDescription : portDescriptions) { |
155 | Port port = ports.get(portDescription.portNumber()); | 155 | Port port = ports.get(portDescription.portNumber()); |
156 | - DeviceEvent event = port == null ? | 156 | + events.add(port == null ? |
157 | createPort(device, portDescription, ports) : | 157 | createPort(device, portDescription, ports) : |
158 | - updatePort(device, port, portDescription, ports); | 158 | + updatePort(device, port, portDescription, ports)); |
159 | processed.add(portDescription.portNumber()); | 159 | processed.add(portDescription.portNumber()); |
160 | } | 160 | } |
161 | 161 | ||
... | @@ -198,7 +198,7 @@ class SimpleDeviceStore { | ... | @@ -198,7 +198,7 @@ class SimpleDeviceStore { |
198 | Iterator<PortNumber> iterator = ports.keySet().iterator(); | 198 | Iterator<PortNumber> iterator = ports.keySet().iterator(); |
199 | while (iterator.hasNext()) { | 199 | while (iterator.hasNext()) { |
200 | PortNumber portNumber = iterator.next(); | 200 | PortNumber portNumber = iterator.next(); |
201 | - if (processed.contains(portNumber)) { | 201 | + if (!processed.contains(portNumber)) { |
202 | events.add(new DeviceEvent(PORT_REMOVED, device, | 202 | events.add(new DeviceEvent(PORT_REMOVED, device, |
203 | ports.get(portNumber))); | 203 | ports.get(portNumber))); |
204 | iterator.remove(); | 204 | iterator.remove(); | ... | ... |
... | @@ -7,7 +7,10 @@ import org.onlab.onos.event.Event; | ... | @@ -7,7 +7,10 @@ import org.onlab.onos.event.Event; |
7 | import org.onlab.onos.net.Device; | 7 | import org.onlab.onos.net.Device; |
8 | import org.onlab.onos.net.DeviceId; | 8 | import org.onlab.onos.net.DeviceId; |
9 | import org.onlab.onos.net.MastershipRole; | 9 | import org.onlab.onos.net.MastershipRole; |
10 | +import org.onlab.onos.net.Port; | ||
11 | +import org.onlab.onos.net.PortNumber; | ||
10 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 12 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
13 | +import org.onlab.onos.net.device.DefaultPortDescription; | ||
11 | import org.onlab.onos.net.device.DeviceAdminService; | 14 | import org.onlab.onos.net.device.DeviceAdminService; |
12 | import org.onlab.onos.net.device.DeviceDescription; | 15 | import org.onlab.onos.net.device.DeviceDescription; |
13 | import org.onlab.onos.net.device.DeviceEvent; | 16 | import org.onlab.onos.net.device.DeviceEvent; |
... | @@ -16,6 +19,7 @@ import org.onlab.onos.net.device.DeviceProvider; | ... | @@ -16,6 +19,7 @@ import org.onlab.onos.net.device.DeviceProvider; |
16 | import org.onlab.onos.net.device.DeviceProviderRegistry; | 19 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
17 | import org.onlab.onos.net.device.DeviceProviderService; | 20 | import org.onlab.onos.net.device.DeviceProviderService; |
18 | import org.onlab.onos.net.device.DeviceService; | 21 | import org.onlab.onos.net.device.DeviceService; |
22 | +import org.onlab.onos.net.device.PortDescription; | ||
19 | import org.onlab.onos.net.provider.AbstractProvider; | 23 | import org.onlab.onos.net.provider.AbstractProvider; |
20 | import org.onlab.onos.net.provider.ProviderId; | 24 | import org.onlab.onos.net.provider.ProviderId; |
21 | 25 | ||
... | @@ -42,6 +46,10 @@ public class SimpleDeviceManagerTest { | ... | @@ -42,6 +46,10 @@ public class SimpleDeviceManagerTest { |
42 | private static final String SW2 = "3.9.5"; | 46 | private static final String SW2 = "3.9.5"; |
43 | private static final String SN = "43311-12345"; | 47 | private static final String SN = "43311-12345"; |
44 | 48 | ||
49 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
50 | + private static final PortNumber P2 = PortNumber.portNumber(2); | ||
51 | + private static final PortNumber P3 = PortNumber.portNumber(3); | ||
52 | + | ||
45 | 53 | ||
46 | private SimpleDeviceManager mgr; | 54 | private SimpleDeviceManager mgr; |
47 | 55 | ||
... | @@ -138,7 +146,61 @@ public class SimpleDeviceManagerTest { | ... | @@ -138,7 +146,61 @@ public class SimpleDeviceManagerTest { |
138 | assertEquals("incorrect role", MastershipRole.MASTER, provider.roleReceived); | 146 | assertEquals("incorrect role", MastershipRole.MASTER, provider.roleReceived); |
139 | } | 147 | } |
140 | 148 | ||
149 | + @Test | ||
150 | + public void updatePorts() { | ||
151 | + connectDevice(DID1, SW1); | ||
152 | + List<PortDescription> pds = new ArrayList<>(); | ||
153 | + pds.add(new DefaultPortDescription(P1, true)); | ||
154 | + pds.add(new DefaultPortDescription(P2, true)); | ||
155 | + pds.add(new DefaultPortDescription(P3, true)); | ||
156 | + providerService.updatePorts(DID1, pds); | ||
157 | + validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED, PORT_ADDED); | ||
158 | + pds.clear(); | ||
159 | + | ||
160 | + pds.add(new DefaultPortDescription(P1, false)); | ||
161 | + pds.add(new DefaultPortDescription(P3, true)); | ||
162 | + providerService.updatePorts(DID1, pds); | ||
163 | + validateEvents(PORT_UPDATED, PORT_REMOVED); | ||
164 | + } | ||
165 | + | ||
166 | + @Test | ||
167 | + public void updatePortStatus() { | ||
168 | + connectDevice(DID1, SW1); | ||
169 | + List<PortDescription> pds = new ArrayList<>(); | ||
170 | + pds.add(new DefaultPortDescription(P1, true)); | ||
171 | + pds.add(new DefaultPortDescription(P2, true)); | ||
172 | + providerService.updatePorts(DID1, pds); | ||
173 | + validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED); | ||
174 | + | ||
175 | + providerService.portStatusChanged(DID1, new DefaultPortDescription(P1, false)); | ||
176 | + validateEvents(PORT_UPDATED); | ||
177 | + providerService.portStatusChanged(DID1, new DefaultPortDescription(P1, false)); | ||
178 | + assertTrue("no events expected", listener.events.isEmpty()); | ||
179 | + } | ||
141 | 180 | ||
181 | + @Test | ||
182 | + public void getPorts() { | ||
183 | + connectDevice(DID1, SW1); | ||
184 | + List<PortDescription> pds = new ArrayList<>(); | ||
185 | + pds.add(new DefaultPortDescription(P1, true)); | ||
186 | + pds.add(new DefaultPortDescription(P2, true)); | ||
187 | + providerService.updatePorts(DID1, pds); | ||
188 | + validateEvents(DEVICE_ADDED, PORT_ADDED, PORT_ADDED); | ||
189 | + assertEquals("wrong port count", 2, service.getPorts(DID1).size()); | ||
190 | + | ||
191 | + Port port = service.getPort(DID1, P1); | ||
192 | + assertEquals("incorrect port", P1, service.getPort(DID1, P1).number()); | ||
193 | + assertEquals("incorrect state", true, service.getPort(DID1, P1).isEnabled()); | ||
194 | + } | ||
195 | + | ||
196 | + @Test | ||
197 | + public void removeDevice() { | ||
198 | + connectDevice(DID1, SW1); | ||
199 | + connectDevice(DID2, SW2); | ||
200 | + admin.removeDevice(DID1); | ||
201 | + assertNull("device should not be found", service.getDevice(DID1)); | ||
202 | + assertNotNull("device should be found", service.getDevice(DID2)); | ||
203 | + } | ||
142 | 204 | ||
143 | protected void validateEvents(Enum... types) { | 205 | protected void validateEvents(Enum... types) { |
144 | int i = 0; | 206 | int i = 0; | ... | ... |
-
Please register or login to post a comment