Fixed a bug that causes filtering objective being removed when it should not
Change-Id: I06a43dd644103d329d946af106c854987035997b
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index 1397774..9313f34 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -30,6 +30,7 @@
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
+import org.onosproject.net.Host;
import org.onosproject.net.flowobjective.DefaultObjectiveContext;
import org.onosproject.net.flowobjective.Objective;
import org.onosproject.net.flowobjective.ObjectiveContext;
@@ -1157,8 +1158,7 @@
VlanId innerVlan, boolean install) {
// We should trigger the removal of double tagged rules only when removing
// the filtering objective and no other hosts are connected to the same device port.
- boolean cleanupDoubleTaggedRules = srManager.hostService
- .getConnectedHosts(new ConnectPoint(deviceId, portNum)).size() == 0 && !install;
+ boolean cleanupDoubleTaggedRules = !anyDoubleTaggedHost(deviceId, portNum) && !install;
FilteringObjective.Builder fob = buildDoubleTaggedFilteringObj(deviceId, portNum,
outerVlan, innerVlan,
cleanupDoubleTaggedRules);
@@ -1180,6 +1180,23 @@
}
}
+ /**
+ * Checks if there is any double tagged host attached to given location.
+ * This method will match on the effective location of a host.
+ * That is, it will match on auxLocations when auxLocations is not null. Otherwise, it will match on locations.
+ *
+ * @param deviceId device ID
+ * @param portNum port number
+ * @return true if there is any host attached to given location.
+ */
+ private boolean anyDoubleTaggedHost(DeviceId deviceId, PortNumber portNum) {
+ ConnectPoint cp = new ConnectPoint(deviceId, portNum);
+ Set<Host> connectedHosts = srManager.hostService.getConnectedHosts(cp, false);
+ Set<Host> auxConnectedHosts = srManager.hostService.getConnectedHosts(cp, true);
+ return !auxConnectedHosts.isEmpty() ||
+ connectedHosts.stream().anyMatch(host -> host.auxLocations() == null);
+ }
+
private FilteringObjective.Builder buildDoubleTaggedFilteringObj(DeviceId deviceId, PortNumber portNum,
VlanId outerVlan, VlanId innerVlan,
boolean cleanupDoubleTaggedRules) {