[CORD-2223] Avoid unnecessary probing when a host moves within the same switch
Change-Id: I777234564801ab236bf48ecf04ce75aaa1061a18
diff --git a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
index 16a8f24..f9821ed 100644
--- a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
+++ b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
@@ -407,10 +407,17 @@
Host existingHost = hostService.getHost(hid);
if (existingHost != null) {
Set<HostLocation> prevLocations = existingHost.locations();
- newLocations.addAll(prevLocations);
- if (!existingHost.locations().contains(hloc)) {
+ if (prevLocations.stream().noneMatch(loc -> loc.deviceId().equals(hloc.deviceId()))) {
+ // New location is on a device that we haven't seen before
+ // Could be a dual-home host. Append new location and send out the probe
+ newLocations.addAll(prevLocations);
probeLocations(existingHost);
+ } else {
+ // Move within the same switch
+ // Simply replace old location that is on the same device
+ prevLocations.stream().filter(loc -> !loc.deviceId().equals(hloc.deviceId()))
+ .forEach(newLocations::add);
}
}
}