ONOS-1438: Improved the routing rule population process for link add and failure; computes the routes changed from the link changes and populates the rules only for the routes.

Change-Id: Id4dbd80da37b333f2c19bc97333472dc8031481b
diff --git a/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index e5cf69f..0a466de 100644
--- a/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -40,6 +40,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -47,8 +48,9 @@
 
     private static final Logger log = LoggerFactory.getLogger(RoutingRulePopulator.class);
 
-    private SegmentRoutingManager srManager;
-    private NetworkConfigHandler config;
+    private final SegmentRoutingManager srManager;
+    private final NetworkConfigHandler config;
+    private AtomicLong rulePopulationCounter;
 
     /**
      * Creates a RoutingRulePopulator object.
@@ -58,6 +60,21 @@
     public RoutingRulePopulator(SegmentRoutingManager srManager) {
         this.srManager = srManager;
         this.config = checkNotNull(srManager.networkConfigHandler);
+        this.rulePopulationCounter = new AtomicLong(0);
+    }
+
+    /**
+     * Resets the population counter.
+     */
+    public void resetCounter() {
+        rulePopulationCounter.set(0);
+    }
+
+    /**
+     * Returns the number of rules populated.
+     */
+    public long getCounter() {
+        return rulePopulationCounter.get();
     }
 
     /**
@@ -87,6 +104,7 @@
                 srManager.appId, 600, false, FlowRule.Type.IP);
 
         srManager.flowRuleService.applyFlowRules(f);
+        rulePopulationCounter.incrementAndGet();
         log.debug("Flow rule {} is set to switch {}", f, deviceId);
     }
 
@@ -162,6 +180,7 @@
                 srManager.appId, 600, false, FlowRule.Type.IP);
 
         srManager.flowRuleService.applyFlowRules(f);
+        rulePopulationCounter.incrementAndGet();
         log.debug("IP flow rule {} is set to switch {}", f, deviceId);
 
         return true;
@@ -216,6 +235,7 @@
             FlowRule f = new DefaultFlowRule(deviceId, selector, treatment, 100,
                     srManager.appId, 600, false, FlowRule.Type.MPLS);
             srManager.flowRuleService.applyFlowRules(f);
+            rulePopulationCounter.incrementAndGet();
             log.debug("MPLS rule {} is set to {}", f, deviceId);
         }