[ONOS-7555] Device local-status and device availability parameters are not synchronized in cluster
Change-Id: I1720dc471ce41aabefb84a537319f091f01d46f4
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 9f5040a..8a0e673 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
@@ -344,6 +344,14 @@
return (ls.connected) ? "connected " + timeAgo : "disconnected " + timeAgo;
}
+ private boolean isLocallyConnected(DeviceId deviceId) {
+ LocalStatus ls = deviceLocalStatus.get(deviceId);
+ if (ls == null) {
+ return false;
+ }
+ return ls.connected;
+ }
+
@Override
public long getLastUpdatedInstant(DeviceId deviceId) {
LocalStatus ls = deviceLocalStatus.get(deviceId);
@@ -353,14 +361,21 @@
return ls.dateTime.toEpochMilli();
}
- // Check a device for control channel connectivity.
+ // Check a device for control channel connectivity
+ // and changes local-status appropriately.
private boolean isReachable(DeviceId deviceId) {
if (deviceId == null) {
return false;
}
DeviceProvider provider = getProvider(deviceId);
if (provider != null) {
- return provider.isReachable(deviceId);
+ boolean reachable = provider.isReachable(deviceId);
+ if (reachable && !isLocallyConnected(deviceId)) {
+ deviceLocalStatus.put(deviceId, new LocalStatus(true, Instant.now()));
+ } else if (!reachable && isLocallyConnected(deviceId)) {
+ deviceLocalStatus.put(deviceId, new LocalStatus(false, Instant.now()));
+ }
+ return reachable;
} else {
log.debug("Provider not found for {}", deviceId);
return false;