Thomas Vachuska
Committed by Gerrit Code Review

Fixed race-conditions in null providers.

Change-Id: Ie1acd9d74e1277776a5981d21043671010b37343
......@@ -382,7 +382,9 @@ public class DeviceManager
port.portSpeed())));
store.updatePorts(this.provider().id(), deviceId, descs);
try {
if (mastershipService.getLocalRole(deviceId) == MASTER) {
post(store.markOffline(deviceId));
}
} catch (IllegalStateException e) {
log.warn("Failed to mark {} offline", deviceId);
// only the MASTER should be marking off-line in normal cases,
......
......@@ -339,7 +339,6 @@ public class NullProviders {
packetProvider.stop();
flowRuleProvider.stop();
delay(500);
rejectMastership();
simulator.tearDownTopology();
simulator = null;
}
......@@ -396,7 +395,8 @@ public class NullProviders {
@Override
public boolean isReachable(DeviceId deviceId) {
return topoShape.equals("configured") || deviceService.isAvailable(deviceId);
return topoShape.equals("configured") ||
(simulator != null && simulator.contains(deviceId));
}
@Override
......
......@@ -182,9 +182,9 @@ public abstract class TopologySimulator {
new DefaultDeviceDescription(id.uri(), Device.Type.SWITCH,
"ON.Lab", "0.1", "0.1", "1234",
new ChassisId(i));
deviceIds.add(id);
deviceProviderService.deviceConnected(id, desc);
deviceProviderService.updatePorts(id, buildPorts(hostCount + infrastructurePorts));
deviceIds.add(id);
}
// /**
......@@ -287,10 +287,10 @@ public abstract class TopologySimulator {
* Removes any devices previously advertised by this provider.
*/
protected void removeDevices() {
prepareForDeviceEvents(deviceService.getDeviceCount());
deviceService.getDevices()
.forEach(device -> deviceService.removeDevice(device.id()));
prepareForDeviceEvents(deviceIds.size());
deviceIds.forEach(deviceProviderService::deviceDisconnected);
waitForDeviceEvents();
deviceIds.clear();
}
......@@ -358,6 +358,16 @@ public abstract class TopologySimulator {
return ports;
}
/**
* Indicates whether or not the simulation knows of this device.
*
* @param deviceId device identifier
* @return true if device is known
*/
public boolean contains(DeviceId deviceId) {
return deviceIds.contains(deviceId);
}
// Counts down number of device added/available/removed events.
private class DeviceEventCounter implements DeviceListener {
@Override
......