Fixed race-conditions in null providers.
Change-Id: Ie1acd9d74e1277776a5981d21043671010b37343
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
index 0267c4f..527784f 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
@@ -382,7 +382,9 @@
port.portSpeed())));
store.updatePorts(this.provider().id(), deviceId, descs);
try {
- post(store.markOffline(deviceId));
+ 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,
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/NullProviders.java b/providers/null/src/main/java/org/onosproject/provider/nil/NullProviders.java
index d8ccb3e..3d75943 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/NullProviders.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/NullProviders.java
@@ -339,7 +339,6 @@
packetProvider.stop();
flowRuleProvider.stop();
delay(500);
- rejectMastership();
simulator.tearDownTopology();
simulator = null;
}
@@ -396,7 +395,8 @@
@Override
public boolean isReachable(DeviceId deviceId) {
- return topoShape.equals("configured") || deviceService.isAvailable(deviceId);
+ return topoShape.equals("configured") ||
+ (simulator != null && simulator.contains(deviceId));
}
@Override
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/TopologySimulator.java b/providers/null/src/main/java/org/onosproject/provider/nil/TopologySimulator.java
index 76ad8b4..9f2320e 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/TopologySimulator.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/TopologySimulator.java
@@ -182,9 +182,9 @@
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 @@
* 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 @@
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