[SONA] Fixes the bugs of removing VMs with two interfaces.
[Bug] When VMs with two interfaes are removed, connections between other VMs in difference nodes are broken.
Change-Id: I14afafbbf5afac4770b3c77c4a0bbea489e1d64d
diff --git a/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java b/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
index 5b6aabf..9abb442 100644
--- a/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
+++ b/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
@@ -43,6 +43,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Objects;
import java.util.Optional;
import static org.onosproject.openstacknetworking.Constants.*;
@@ -92,7 +93,7 @@
private void removeSwitchingRules(Host host) {
setFlowRulesForTunnelTag(host, false);
setFlowRulesForTrafficToSameCnode(host, false);
- setFlowRulesForTrafficToDifferentCnode(host, false);
+ removeFlowRuleForVMsInDiffrentCnode(host);
log.debug("Removed switching rule for {}", host);
}
@@ -181,6 +182,21 @@
SWITCHING_RULE_PRIORITY, install);
}
+ private void removeFlowRuleForVMsInDiffrentCnode(Host host) {
+ DeviceId deviceId = host.location().deviceId();
+ final boolean anyPortRemainedInSameCnode = hostService.getConnectedHosts(deviceId)
+ .stream()
+ .filter(this::isValidHost)
+ .anyMatch(h -> Objects.equals(getVni(h), getVni(host)));
+
+ getVmsInDifferentCnode(host).forEach(h -> {
+ setVxLanFlowRule(getVni(host), h.location().deviceId(), getIp(host), Ip4Address.valueOf(0), false);
+ if (!anyPortRemainedInSameCnode) {
+ setVxLanFlowRule(getVni(host), deviceId, getIp(h), Ip4Address.valueOf(0), false);
+ }
+ });
+ }
+
@Override
protected void hostDetected(Host host) {
populateSwitchingRules(host);