[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 4ef0884..1ba705e 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
@@ -341,6 +341,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);
@@ -350,14 +358,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;