Send Barrier message to switches after populating routing rules

Change-Id: I987ed00c3ab0f70df6e6e53604c9714a64fa2b10
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index 25c0cff..a2b8a56 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -835,32 +835,9 @@
                     }
                 }
                 setRoutingRule(targetSw, destSw, fwdToSw, modified);
-            }
-
-            // Send Barrier Message and make sure all rules are set
-            // before we set the rules to next routers
-            // TODO: barriers to all switches in this update stage
-            IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
-                    getSwId(sw.getDpid().toString()));
-            if (sw13 != null) {
-                OFBarrierReplyFuture replyFuture = null;
-                try {
-                    replyFuture = sw13.sendBarrier();
-                } catch (IOException e) {
-                    log.error("Error sending barrier request to switch {}",
-                            sw13.getId(), e.getCause());
-                }
-                OFBarrierReply br = null;
-                try {
-                    br = replyFuture.get(2, TimeUnit.SECONDS);
-                } catch (TimeoutException | InterruptedException | ExecutionException e) {
-                    // XXX for some reason these exceptions are not being thrown
-                }
-                if (br == null) {
-                    log.warn("Did not receive barrier-reply from {}", sw13.getId());
-                    // XXX take corrective action
-                }
-
+                // Send Barrier Message and make sure all rules are set
+                // before we set the rules to next routers
+                sendBarrierAndCheckReply(targetSw);
             }
         }
 
@@ -1379,6 +1356,30 @@
         return adjecencyInfo.keySet();
     }
 
+    private void sendBarrierAndCheckReply(Switch sw) {
+        IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
+                getSwId(sw.getDpid().toString()));
+        if (sw13 != null) {
+            OFBarrierReplyFuture replyFuture = null;
+            try {
+                replyFuture = sw13.sendBarrier();
+            } catch (IOException e) {
+                log.error("Error sending barrier request to switch {}",
+                        sw13.getId(), e.getCause());
+            }
+            OFBarrierReply br = null;
+            try {
+                br = replyFuture.get(2, TimeUnit.SECONDS);
+            } catch (TimeoutException | InterruptedException | ExecutionException e) {
+                // XXX for some reason these exceptions are not being thrown
+            }
+            if (br == null) {
+                log.warn("Did not receive barrier-reply from {}", sw13.getId());
+                // XXX take corrective action
+            }
+        }
+    }
+
     /**
      * Returns the Adjacency Info for the node
      *