CORD-45 CORD-394
Bugfix in group store - group delete state updated correctly.
SR app no longer deletes buckets in existing groups - workaround for OFDPA bug.
Instead it invalidates the entire group, thereby forcing new group creation.
Also incorporating Charles' changes to remove state from group and flow stores,
and the SR app when device goes offline.

Change-Id: I162d3fb6bf709a8f02b01b8d57e131c2bac9b46b
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
index 4e64c4b..0243693 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
@@ -288,6 +288,7 @@
             return;
         }
 
+        @SuppressWarnings("unused")
         MacAddress dstMac;
         try {
             dstMac = deviceConfig.getDeviceMac(portDeviceMap.get(port));
@@ -312,9 +313,17 @@
         log.debug("portDown: nsNextObjStore contents for device {}:{}",
                   deviceId, nsSet);
         for (NeighborSet ns : nsSet) {
-            Integer nextId = nsNextObjStore.
-                    get(new NeighborSetNextObjectiveStoreKey(deviceId, ns));
+            NeighborSetNextObjectiveStoreKey nsStoreKey =
+                    new NeighborSetNextObjectiveStoreKey(deviceId, ns);
+            Integer nextId = nsNextObjStore.get(nsStoreKey);
             if (nextId != null && isMaster) {
+                // XXX This is a workaround for BUG (CORD-611) in current switches.
+                // Should be temporary because this workaround prevents correct
+                // functionality in LAG recovery.
+                log.info("**portDown port:{} in device {}: Invalidating nextId {}",
+                         port, deviceId, nextId);
+                nsNextObjStore.remove(nsStoreKey);
+                /*
                 log.info("**portDown in device {}: Removing Bucket "
                         + "with Port {} to next object id {}",
                         deviceId,
@@ -341,7 +350,7 @@
                         removeFromExisting(new SRNextObjectiveContext(deviceId));
 
                 flowObjectiveService.next(deviceId, nextObjective);
-
+                */
                 // the removal of a bucket may actually change the neighborset
                 // update the global store
                 /*