Symmetric host probing and ignore probe for deleted hosts

Change-Id: I8a750239b9dbd8a913cd8b12debe318ed396fca9
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
index 3a144c6..7e3b3f5 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
+++ b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
@@ -254,7 +254,6 @@
             // Majorly for the 2nd step of [1A/x, 1B/x] -> [1A/x, 1B/y] -> [1A/y, 1B/y]
             // But will also cover [1A/x] -> [1A/y] -> [1A/y, 1B/y]
             if (srManager.activeProbing) {
-
                 srManager.getPairDeviceId(newLocation.deviceId()).ifPresent(pairDeviceId ->
                         srManager.getPairLocalPort(pairDeviceId).ifPresent(pairRemotePort ->
                                 probe(host, newLocation, pairDeviceId, pairRemotePort)
@@ -388,18 +387,36 @@
      * @param pairRemotePort pair remote port
      */
     private void probe(Host host, ConnectPoint location, DeviceId pairDeviceId, PortNumber pairRemotePort) {
+        //Check if the host still exists in the host store
+        if (hostService.getHost(host.id()) == null) {
+            log.debug("Host entry for host {} no more present. Aborting hostprobe discover for this host", host.id());
+            return;
+        }
         VlanId vlanToProbe = host.vlan().equals(VlanId.NONE) ?
                 srManager.getInternalVlanId(location) : host.vlan();
-        srManager.interfaceService.getInterfaces().stream()
-                .filter(i -> i.vlanTagged().contains(vlanToProbe) ||
-                        i.vlanUntagged().equals(vlanToProbe) ||
-                        i.vlanNative().equals(vlanToProbe))
-                .filter(i -> i.connectPoint().deviceId().equals(pairDeviceId))
-                .filter(i -> !i.connectPoint().port().equals(pairRemotePort))
-                .forEach(i -> {
-                    log.debug("Probing host {} on pair device {}", host.id(), i.connectPoint());
-                    srManager.probingService.probeHost(host, i.connectPoint(), ProbeMode.DISCOVER);
-                });
+        if (srManager.symmetricProbing) {
+            srManager.interfaceService.getInterfaces().stream()
+                    .filter(i -> i.vlanTagged().contains(vlanToProbe) ||
+                            i.vlanUntagged().equals(vlanToProbe) ||
+                            i.vlanNative().equals(vlanToProbe))
+                    .filter(i -> i.connectPoint().deviceId().equals(pairDeviceId))
+                    .filter(i -> i.connectPoint().port().equals(location.port()))
+                    .forEach(i -> {
+                        log.debug("Probing host {} on pair device {}", host.id(), i.connectPoint());
+                        srManager.probingService.probeHost(host, i.connectPoint(), ProbeMode.DISCOVER);
+                    });
+        } else {
+            srManager.interfaceService.getInterfaces().stream()
+                    .filter(i -> i.vlanTagged().contains(vlanToProbe) ||
+                            i.vlanUntagged().equals(vlanToProbe) ||
+                            i.vlanNative().equals(vlanToProbe))
+                    .filter(i -> i.connectPoint().deviceId().equals(pairDeviceId))
+                    .filter(i -> !i.connectPoint().port().equals(pairRemotePort))
+                    .forEach(i -> {
+                        log.debug("Probing host {} on pair device {}", host.id(), i.connectPoint());
+                        srManager.probingService.probeHost(host, i.connectPoint(), ProbeMode.DISCOVER);
+                    });
+        }
     }
 
     /**
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 584576a..20c1148 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -233,6 +233,10 @@
             label = "Enable active probing to discover dual-homed hosts.")
     boolean activeProbing = true;
 
+    @Property(name = "symmetricProbing", boolValue = false,
+            label = "Enable active probing to discover dual-homed hosts.")
+    boolean symmetricProbing = false;
+
     @Property(name = "singleHomedDown", boolValue = false,
             label = "Enable administratively taking down single-homed hosts "
                     + "when all uplinks are gone")
@@ -572,6 +576,13 @@
             log.info("{} active probing", activeProbing ? "Enabling" : "Disabling");
         }
 
+        String strSymmetricProving = Tools.get(properties, "symmetricProbing");
+        boolean expectSymmetricProbing = Boolean.parseBoolean(strSymmetricProving);
+        if (expectSymmetricProbing != symmetricProbing) {
+            symmetricProbing = expectSymmetricProbing;
+            log.info("{} symmetric probing", symmetricProbing ? "Enabling" : "Disabling");
+        }
+
         String strSingleHomedDown = Tools.get(properties, "singleHomedDown");
         boolean expectSingleHomedDown = Boolean.parseBoolean(strSingleHomedDown);
         if (expectSingleHomedDown != singleHomedDown) {