CORD-394 Purge group/flow store when device goes offline
Stage 1: (this commit)
Add a component config purgeOnDisconnection, which is false by default.
When set to true, GroupManager and FlowManager will purge groups/flows
associated with a device when the device goes offline.
Stage 2: (upcoming commit)
Enable these configs in SegmentRoutingManager
Clean up group related information in SegmentRountingManager
Change-Id: I46d047d690d4641e030f6cdd084ce16ac02d8919
diff --git a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
index 4f4c06f..1d7ded1 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
@@ -67,8 +67,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -845,6 +847,21 @@
}
@Override
+ public void purgeGroupEntry(DeviceId deviceId) {
+ Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entryPendingRemove =
+ new HashSet<>();
+
+ groupStoreEntriesByKey.entrySet().stream()
+ .filter(entry -> entry.getKey().deviceId().equals(deviceId))
+ .forEach(entryPendingRemove::add);
+
+ entryPendingRemove.forEach(entry -> {
+ groupStoreEntriesByKey.remove(entry.getKey());
+ notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, entry.getValue()));
+ });
+ }
+
+ @Override
public void deviceInitialAuditCompleted(DeviceId deviceId,
boolean completed) {
synchronized (deviceAuditStatus) {