Thomas Vachuska
Committed by Gerrit Code Review

Fixed race-conditions in null providers.

Change-Id: Ie1acd9d74e1277776a5981d21043671010b37343
...@@ -382,7 +382,9 @@ public class DeviceManager ...@@ -382,7 +382,9 @@ public class DeviceManager
382 port.portSpeed()))); 382 port.portSpeed())));
383 store.updatePorts(this.provider().id(), deviceId, descs); 383 store.updatePorts(this.provider().id(), deviceId, descs);
384 try { 384 try {
385 + if (mastershipService.getLocalRole(deviceId) == MASTER) {
385 post(store.markOffline(deviceId)); 386 post(store.markOffline(deviceId));
387 + }
386 } catch (IllegalStateException e) { 388 } catch (IllegalStateException e) {
387 log.warn("Failed to mark {} offline", deviceId); 389 log.warn("Failed to mark {} offline", deviceId);
388 // only the MASTER should be marking off-line in normal cases, 390 // only the MASTER should be marking off-line in normal cases,
......
...@@ -339,7 +339,6 @@ public class NullProviders { ...@@ -339,7 +339,6 @@ public class NullProviders {
339 packetProvider.stop(); 339 packetProvider.stop();
340 flowRuleProvider.stop(); 340 flowRuleProvider.stop();
341 delay(500); 341 delay(500);
342 - rejectMastership();
343 simulator.tearDownTopology(); 342 simulator.tearDownTopology();
344 simulator = null; 343 simulator = null;
345 } 344 }
...@@ -396,7 +395,8 @@ public class NullProviders { ...@@ -396,7 +395,8 @@ public class NullProviders {
396 395
397 @Override 396 @Override
398 public boolean isReachable(DeviceId deviceId) { 397 public boolean isReachable(DeviceId deviceId) {
399 - return topoShape.equals("configured") || deviceService.isAvailable(deviceId); 398 + return topoShape.equals("configured") ||
399 + (simulator != null && simulator.contains(deviceId));
400 } 400 }
401 401
402 @Override 402 @Override
......
...@@ -182,9 +182,9 @@ public abstract class TopologySimulator { ...@@ -182,9 +182,9 @@ public abstract class TopologySimulator {
182 new DefaultDeviceDescription(id.uri(), Device.Type.SWITCH, 182 new DefaultDeviceDescription(id.uri(), Device.Type.SWITCH,
183 "ON.Lab", "0.1", "0.1", "1234", 183 "ON.Lab", "0.1", "0.1", "1234",
184 new ChassisId(i)); 184 new ChassisId(i));
185 + deviceIds.add(id);
185 deviceProviderService.deviceConnected(id, desc); 186 deviceProviderService.deviceConnected(id, desc);
186 deviceProviderService.updatePorts(id, buildPorts(hostCount + infrastructurePorts)); 187 deviceProviderService.updatePorts(id, buildPorts(hostCount + infrastructurePorts));
187 - deviceIds.add(id);
188 } 188 }
189 189
190 // /** 190 // /**
...@@ -287,10 +287,10 @@ public abstract class TopologySimulator { ...@@ -287,10 +287,10 @@ public abstract class TopologySimulator {
287 * Removes any devices previously advertised by this provider. 287 * Removes any devices previously advertised by this provider.
288 */ 288 */
289 protected void removeDevices() { 289 protected void removeDevices() {
290 - prepareForDeviceEvents(deviceService.getDeviceCount()); 290 + prepareForDeviceEvents(deviceIds.size());
291 - deviceService.getDevices() 291 + deviceIds.forEach(deviceProviderService::deviceDisconnected);
292 - .forEach(device -> deviceService.removeDevice(device.id()));
293 waitForDeviceEvents(); 292 waitForDeviceEvents();
293 + deviceIds.clear();
294 } 294 }
295 295
296 296
...@@ -358,6 +358,16 @@ public abstract class TopologySimulator { ...@@ -358,6 +358,16 @@ public abstract class TopologySimulator {
358 return ports; 358 return ports;
359 } 359 }
360 360
361 + /**
362 + * Indicates whether or not the simulation knows of this device.
363 + *
364 + * @param deviceId device identifier
365 + * @return true if device is known
366 + */
367 + public boolean contains(DeviceId deviceId) {
368 + return deviceIds.contains(deviceId);
369 + }
370 +
361 // Counts down number of device added/available/removed events. 371 // Counts down number of device added/available/removed events.
362 private class DeviceEventCounter implements DeviceListener { 372 private class DeviceEventCounter implements DeviceListener {
363 @Override 373 @Override
......