Suppress IPv6 flows when the device is not configured with IPv6

- Do not punt link local address if the device is not configured with ipv6Loopback
- Do not punt NDP and block DAD if the device is not configured with ipv6Loopback

Change-Id: Iaf36bcf9bf3c11bc199c271f1a03eb6ae448cfab
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index 8e0eb6a..b49b18f 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -1177,9 +1177,9 @@
         }
         Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId));
         allIps.add(routerIpv4);
-        allIps.add(routerLinkLocalIpv6);
         if (routerIpv6 != null) {
             allIps.add(routerIpv6);
+            allIps.add(routerLinkLocalIpv6);
         }
         if (pairRouterIpv4 != null) {
             allIps.add(pairRouterIpv4);
@@ -1284,17 +1284,19 @@
                 });
         srManager.flowObjectiveService.forward(deviceId, fwdObj);
 
-        // We punt all NDP packets towards the controller.
-        ndpFwdObjective(null, true, ARP_NDP_PRIORITY).forEach(builder -> {
-             ForwardingObjective obj = builder.add(new ObjectiveContext() {
-                @Override
-                public void onError(Objective objective, ObjectiveError error) {
-                    log.warn("Failed to install forwarding objective to punt NDP to {}: {}",
-                            deviceId, error);
-                }
+        if (isIpv6Configured(deviceId)) {
+            // We punt all NDP packets towards the controller.
+            ndpFwdObjective(null, true, ARP_NDP_PRIORITY).forEach(builder -> {
+                 ForwardingObjective obj = builder.add(new ObjectiveContext() {
+                    @Override
+                    public void onError(Objective objective, ObjectiveError error) {
+                        log.warn("Failed to install forwarding objective to punt NDP to {}: {}",
+                                deviceId, error);
+                    }
+                });
+                srManager.flowObjectiveService.forward(deviceId, obj);
             });
-            srManager.flowObjectiveService.forward(deviceId, obj);
-        });
+        }
 
         srManager.getPairLocalPort(deviceId).ifPresent(port -> {
             ForwardingObjective pairFwdObj;
@@ -1309,28 +1311,30 @@
                     });
             srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
 
-            // Do not punt NDP packets from pair port
-            ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).forEach(builder -> {
-                ForwardingObjective obj = builder.add(new ObjectiveContext() {
-                    @Override
-                    public void onError(Objective objective, ObjectiveError error) {
-                        log.warn("Failed to install forwarding objective to ignore ARP to {}: {}",
-                                deviceId, error);
-                    }
-                });
-                srManager.flowObjectiveService.forward(deviceId, obj);
-            });
-
-            // Do not forward DAD packets from pair port
-            pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2)
-                    .add(new ObjectiveContext() {
+            if (isIpv6Configured(deviceId)) {
+                // Do not punt NDP packets from pair port
+                ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).forEach(builder -> {
+                    ForwardingObjective obj = builder.add(new ObjectiveContext() {
                         @Override
                         public void onError(Objective objective, ObjectiveError error) {
-                            log.warn("Failed to install forwarding objective to drop DAD to {}: {}",
+                            log.warn("Failed to install forwarding objective to ignore ARP to {}: {}",
                                     deviceId, error);
                         }
                     });
-            srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
+                    srManager.flowObjectiveService.forward(deviceId, obj);
+                });
+
+                // Do not forward DAD packets from pair port
+                pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2)
+                        .add(new ObjectiveContext() {
+                            @Override
+                            public void onError(Objective objective, ObjectiveError error) {
+                                log.warn("Failed to install forwarding objective to drop DAD to {}: {}",
+                                        deviceId, error);
+                            }
+                        });
+                srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
+            }
         });
     }
 
@@ -1781,4 +1785,13 @@
         }
     }
 
+    private boolean isIpv6Configured(DeviceId deviceId) {
+        boolean isIpv6Configured;
+        try {
+            isIpv6Configured = (config.getRouterIpv6(deviceId) != null);
+        } catch (DeviceConfigNotFoundException e) {
+            isIpv6Configured = false;
+        }
+        return isIpv6Configured;
+    }
 }