Bugfix for multicast in multiple instances environment

Only the master of the source device do path calculations

Change-Id: I29f6d49f039d61014f0ff8ddce73db2ad18eb6e4
(cherry picked from commit a7da388b2f8d1601e71d915618509b03478a4a9b)
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
index 6f42cf6..36dc26b 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
@@ -196,6 +196,13 @@
         ConnectPoint sink = mcastRouteInfo.sink().orElse(null);
         IpAddress mcastIp = mcastRouteInfo.route().group();
 
+        // Continue only when this instance is the master of source device
+        if (!srManager.mastershipService.isLocalMaster(source.deviceId())) {
+            log.info("Skip {} due to lack of mastership of the source device {}",
+                    mcastIp, source.deviceId());
+            return;
+        }
+
         // When source and sink are on the same device
         if (source.deviceId().equals(sink.deviceId())) {
             // Source and sink are on even the same port. There must be something wrong.
@@ -238,6 +245,13 @@
      */
     private void processSinkAddedInternal(ConnectPoint source, ConnectPoint sink,
             IpAddress mcastIp) {
+        // Continue only when this instance is the master of source device
+        if (!srManager.mastershipService.isLocalMaster(source.deviceId())) {
+            log.info("Skip {} due to lack of mastership of the source device {}",
+                    source.deviceId());
+            return;
+        }
+
         // Process the ingress device
         addFilterToDevice(source.deviceId(), source.port(), assignedVlan(source));
 
@@ -305,6 +319,13 @@
                 return;
             }
 
+            // Continue only when this instance is the master of source device
+            if (!srManager.mastershipService.isLocalMaster(source.deviceId())) {
+                log.info("Skip {} due to lack of mastership of the source device {}",
+                        source.deviceId());
+                return;
+            }
+
             // Remove entire transit
             removeGroupFromDevice(transitDevice, mcastIp, assignedVlan(null));
 
@@ -612,12 +633,11 @@
                         MacAddress.IPV4_MULTICAST_MASK))
                 .addCondition(Criteria.matchVlanId(egressVlan()))
                 .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
-        // vlan assignment is valid only if this instance is master
-        if (srManager.mastershipService.isLocalMaster(deviceId)) {
-            TrafficTreatment tt = DefaultTrafficTreatment.builder()
-                    .pushVlan().setVlanId(assignedVlan).build();
-            filtBuilder.withMeta(tt);
-        }
+
+        TrafficTreatment tt = DefaultTrafficTreatment.builder()
+                .pushVlan().setVlanId(assignedVlan).build();
+        filtBuilder.withMeta(tt);
+
         return filtBuilder.permit().fromApp(srManager.appId);
     }