[ONOS-8157] Adding port disable during periodic checkeker for device disconnections.
Change-Id: Ie44f2c485446e29ef4c39198e8bfe8461bd13c93
(cherry picked from commit 9f820659064984ca898ffd40083a1a4944097897)
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 be114c4..fbbb15d 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
@@ -542,6 +542,12 @@
if (updateMastershipFor(deviceId) == null
&& myRole == MASTER && isAvailable(deviceId)) {
log.info("Local Role {}, Marking unreachable device {} offline", MASTER, deviceId);
+ // Following the deviceDisconnected method logic (line 734) we are marking also all the
+ // ports as disabled.
+ List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId)
+ .map(desc -> ensurePortEnabledState(desc, false))
+ .collect(Collectors.toList());
+ store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
post(store.markOffline(deviceId));
}
} else {
@@ -563,6 +569,12 @@
term != null && localNodeId.equals(term.master()) &&
isAvailable(deviceId)) {
log.info("Marking unreachable device {} offline", deviceId);
+ // Following the deviceDisconnected method logic (line 734) we are marking also all the
+ // ports as disabled.
+ List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId)
+ .map(desc -> ensurePortEnabledState(desc, false))
+ .collect(Collectors.toList());
+ store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
post(store.markOffline(deviceId));
}
}
@@ -628,6 +640,15 @@
}
}
+ PortDescription ensurePortEnabledState(PortDescription desc, boolean enabled) {
+ if (desc.isEnabled() != enabled) {
+ return DefaultPortDescription.builder(desc)
+ .isEnabled(enabled)
+ .build();
+ }
+ return desc;
+ }
+
// Personalized device provider service issued to the supplied provider.
private class InternalDeviceProviderService
extends AbstractProviderService<DeviceProvider>
@@ -712,15 +733,6 @@
}
}
- private PortDescription ensurePortEnabledState(PortDescription desc, boolean enabled) {
- if (desc.isEnabled() != enabled) {
- return DefaultPortDescription.builder(desc)
- .isEnabled(enabled)
- .build();
- }
- return desc;
- }
-
@Override
public void deviceDisconnected(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);