CORD-1583 More bug fixes in dual-ToR scenarios

 - reentrant lock was not being used correctly
 - fixHashGroup in group handler was not updating global store correctly
 - linkUp was not being noted in seenLinks if configuration came after switches connected
 - serialization error in global objective store due to missing kryo for Sets
 - damaged routepath computation was not taking pair-devs into account
 - switch failures were leading to improper ecmpSpg graph updates, and missed hash-group changes
 - implemented more next-objective verification as group sub-system can go out-of-sync with objective-store

Change-Id: If3cfdd715e9b69820894b49def31f75ceb748863
diff --git a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index e00d865..39b901b 100644
--- a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -1106,10 +1106,6 @@
 
     private void processLinkAdded(Link link) {
         log.info("** LINK ADDED {}", link.toString());
-        if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
-            log.warn("Source device of this link is not configured..not processing");
-            return;
-        }
         if (link.type() != Link.Type.DIRECT) {
             // NOTE: A DIRECT link might be transiently marked as INDIRECT
             //       if BDDP is received before LLDP. We can safely ignore that
@@ -1118,6 +1114,13 @@
                     link.src(), link.dst(), link.type());
             return;
         }
+        if (!deviceConfiguration.isConfigured(link.src().deviceId())) {
+            updateSeenLink(link, true);
+            // XXX revisit - what about devicePortMap
+            log.warn("Source device of this link is not configured.. "
+                    + "not processing further");
+            return;
+        }
 
         //Irrespective of whether the local is a MASTER or not for this device,
         //create group handler instance and push default TTP flow rules if needed,
@@ -1127,6 +1130,7 @@
         if (groupHandler != null) {
             groupHandler.portUpForLink(link);
         } else {
+            // XXX revisit/cleanup
             Device device = deviceService.getDevice(link.src().deviceId());
             if (device != null) {
                 log.warn("processLinkAdded: Link Added "
@@ -1189,7 +1193,12 @@
         if (groupHandler != null) {
             if (mastershipService.isLocalMaster(link.src().deviceId()) &&
                     isParallelLink(link)) {
+                log.debug("* retrying hash for parallel link removed:{}", link);
                 groupHandler.retryHash(link, true, false);
+            } else {
+                log.debug("Not attempting retry-hash for link removed: {} .. {}", link,
+                          (mastershipService.isLocalMaster(link.src().deviceId()))
+                                  ? "not parallel" : "not master");
             }
             // ensure local stores are updated
             groupHandler.portDown(link.src().port());