[SDFAB-359] Purge all on device disconnection

The previous logic was relying on the purgeOnDisconnection device configuration.
However, we want to allow flow rules to stay in the store when a device disconnects if those are
created by a different application. For this reason, we purge flow rule and groups explicitly on
device disconnection in SR by specifying the SR app ID.

Change-Id: I59369a1a18b82f134aaaab37be49e2ac746a4e9f
diff --git a/impl/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java b/impl/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
index 7980d25..3db48ab 100644
--- a/impl/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
+++ b/impl/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java
@@ -36,7 +36,6 @@
 import org.onosproject.net.HostId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.config.ConfigException;
-import org.onosproject.net.config.basics.BasicDeviceConfig;
 import org.onosproject.net.config.basics.BasicHostConfig;
 import org.onosproject.net.config.basics.InterfaceConfig;
 import org.onosproject.net.host.InterfaceIpAddress;
@@ -117,14 +116,6 @@
         Set<DeviceId> deviceSubjects =
                 srManager.cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
         deviceSubjects.forEach(subject -> {
-            BasicDeviceConfig basicDeviceConfig = srManager.cfgService.addConfig(subject, BasicDeviceConfig.class);
-            if (!basicDeviceConfig.purgeOnDisconnection()) {
-                // Setting purge on disconnection flag for the device SR has control over.
-                // addConfig returns a config if it exists or creates a new one.
-                log.info("PurgeOnDisconnection set to true for device {}", subject);
-                basicDeviceConfig.purgeOnDisconnection(true);
-                srManager.cfgService.applyConfig(subject, BasicDeviceConfig.class, basicDeviceConfig.node());
-            }
             SegmentRoutingDeviceConfig config =
                     srManager.cfgService.getConfig(subject, SegmentRoutingDeviceConfig.class);
             SegmentRouterInfo info = new SegmentRouterInfo();
diff --git a/impl/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/impl/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index c42773f..b12b229 100644
--- a/impl/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/impl/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -1689,6 +1689,12 @@
             .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id()));
 
         phasedRecoveryService.reset(device.id());
+
+        // Trigger purgeAll only on devices managed by SR, other devices rely on
+        // the purgeOnDisconnection device property.
+        if (deviceConfiguration.isConfigured(device.id())) {
+            flowObjectiveService.purgeAll(device.id(), appId);
+        }
     }
 
     /**
diff --git a/impl/src/test/java/org/onosproject/segmentrouting/config/DeviceConfigurationTest.java b/impl/src/test/java/org/onosproject/segmentrouting/config/DeviceConfigurationTest.java
index 5bb40f3..b0ab5e5 100644
--- a/impl/src/test/java/org/onosproject/segmentrouting/config/DeviceConfigurationTest.java
+++ b/impl/src/test/java/org/onosproject/segmentrouting/config/DeviceConfigurationTest.java
@@ -97,8 +97,6 @@
         srDevConfig.init(DEV1, CONFIG_KEY, jsonNode, mapper, config -> { });
         BasicDeviceConfig basicDeviceConfig = new BasicDeviceConfig();
         basicDeviceConfig.init(DEV1, DEV1.toString(), JsonNodeFactory.instance.objectNode(), mapper, config -> { });
-        BasicDeviceConfig purgeOnDisconnectConfig = basicDeviceConfig.purgeOnDisconnection(true);
-
 
         // Mock interface netcfg
         jsonStream = InterfaceConfig.class.getResourceAsStream("/interface1.json");
@@ -125,8 +123,6 @@
                 .andReturn(basicDeviceConfig).anyTimes();
         expect(networkConfigService.getConfig(DEV1, BasicDeviceConfig.class))
                 .andReturn(basicDeviceConfig).anyTimes();
-        expect(networkConfigService.applyConfig(DEV1, BasicDeviceConfig.class, purgeOnDisconnectConfig.node()))
-                .andReturn(purgeOnDisconnectConfig).anyTimes();
         expect(networkConfigService.getSubjects(ConnectPoint.class, InterfaceConfig.class))
                 .andReturn(Sets.newHashSet(CP1, CP2)).anyTimes();
         expect(networkConfigService.getConfig(CP1, InterfaceConfig.class)).andReturn(interfaceConfig1).anyTimes();
@@ -185,10 +181,4 @@
         assertTrue(devConfig.inSameSubnet(DEV1, PREFIX2.address()));
         assertFalse(devConfig.inSameSubnet(DEV1, ROUTE1.address()));
     }
-
-    @Test
-    public void getPurgeOnDisconnect() {
-        assertNotNull(networkConfigService.getConfig(DEV1, BasicDeviceConfig.class));
-        assertTrue(networkConfigService.getConfig(DEV1, BasicDeviceConfig.class).purgeOnDisconnection());
-    }
 }
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 85f9d9a..e1cb1b4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.onosproject</groupId>
         <artifactId>onos-dependencies</artifactId>
-        <version>2.5.1</version>
+        <version>2.5.3-SNAPSHOT</version>
     </parent>
 
     <groupId>org.onosproject</groupId>
@@ -111,6 +111,18 @@
         </repository>
     </repositories>
 
+    <pluginRepositories>
+        <pluginRepository>
+            <id>snapshots</id>
+            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>always</updatePolicy>
+                <checksumPolicy>fail</checksumPolicy>
+            </snapshots>
+        </pluginRepository>
+    </pluginRepositories>
+
     <distributionManagement>
         <snapshotRepository>
             <id>ossrh</id>