[ONOS-8087] Per device purgeOnDisconnection Flag

Change-Id: I7cb1db12a4d910d70123f116107a898bf9e6d278
(cherry picked from commit 32a9c0b2d92a76e743e9e64eb2f1c6db2da77d12)
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java
index 1a7ffd6..47c5375 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java
@@ -34,6 +34,7 @@
     private static final String HW_VERSION = "hwVersion";
     private static final String SW_VERSION = "swVersion";
     private static final String SERIAL = "serial";
+    private static final String PURGE_ON_DISCONNECT = "purgeOnDisconnection";
     private static final String DEVICE_KEY_ID = "deviceKeyId";
 
     private static final int DRIVER_MAX_LENGTH = 256;
@@ -54,7 +55,7 @@
                 && hasOnlyFields(ALLOWED, NAME, LOC_TYPE, LATITUDE, LONGITUDE,
                 GRID_Y, GRID_X, UI_TYPE, RACK_ADDRESS, OWNER, TYPE, DRIVER, ROLES,
                 MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
-                MANAGEMENT_ADDRESS, PIPECONF, DEVICE_KEY_ID)
+                MANAGEMENT_ADDRESS, PIPECONF, DEVICE_KEY_ID, PURGE_ON_DISCONNECT)
                 && isValidLength(DRIVER, DRIVER_MAX_LENGTH)
                 && isValidLength(MANUFACTURER, MANUFACTURER_MAX_LENGTH)
                 && isValidLength(HW_VERSION, MANUFACTURER_MAX_LENGTH)
@@ -252,6 +253,34 @@
                 deviceKeyId != null ? deviceKeyId.id() : null);
     }
 
+    /**
+     * Returns the device purgeOnDisconnection flag for this device.
+     *
+     * @return device purgeOnDisconnection, false if not set.
+     */
+    public boolean purgeOnDisconnection() {
+        return get(PURGE_ON_DISCONNECT, false);
+    }
+
+    /**
+     * Sets the purgeOnDisconnection flag for the device.
+     *
+     * @param purgeOnDisconnection purges flows, groups, meters on disconnection.
+     * @return self
+     */
+    public BasicDeviceConfig purgeOnDisconnection(boolean purgeOnDisconnection) {
+        return (BasicDeviceConfig) setOrClear(PURGE_ON_DISCONNECT, purgeOnDisconnection);
+    }
+
+    /**
+     * Returns if the device purgeOnDisconnection flag for this device has been explicitly configured.
+     *
+     * @return device purgeOnDisconnection explicitly configured, false if not.
+     */
+    public boolean isPurgeOnDisconnectionConfigured() {
+        return hasField(PURGE_ON_DISCONNECT);
+    }
+
     // TODO: device port meta-data to be configured via BasicPortsConfig
     // TODO: device credentials/keys; in a separate config