Eliminate redundant flow programming when host moves
When a host moves from [1A/1, 1B/1] to [1A/2, 1B/1], there is no need to program the pair link flow first.
Also update unit tests to verify this behavior.
Change-Id: I97c7ee5f0db891226c7ed477f5f05af5d6c1faa8
diff --git a/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java b/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
index ae35f7b..eee9900 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
@@ -216,8 +216,9 @@
// Note: Do not continue removing any rule
Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(prevLocation.deviceId());
Optional<PortNumber> pairLocalPort = srManager.getPairLocalPort(prevLocation.deviceId());
- if (pairDeviceId.isPresent() && pairLocalPort.isPresent() && newLocations.stream()
- .anyMatch(location -> location.deviceId().equals(pairDeviceId.get()))) {
+ if (pairDeviceId.isPresent() && pairLocalPort.isPresent() &&
+ newLocations.stream().anyMatch(location -> location.deviceId().equals(pairDeviceId.get())) &&
+ newLocations.stream().noneMatch(location -> location.deviceId().equals(prevLocation.deviceId()))) {
// NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
// when the host is untagged
VlanId vlanId = Optional.ofNullable(srManager.getInternalVlanId(prevLocation)).orElse(hostVlanId);