Fix: do not add/remove security group rules if the device is offline
Change-Id: Id209233c1bdc8903bd9da32bfa746d5bf60fd946
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
index b94a2df..8330276 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
@@ -36,6 +36,7 @@
import org.onosproject.core.CoreService;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -176,6 +177,9 @@
protected DriverService driverService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
protected LeadershipService leadershipService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
@@ -381,6 +385,11 @@
return;
}
+ // if the device is not available we do not perform any action
+ if (instPort.deviceId() == null || !deviceService.isAvailable(instPort.deviceId())) {
+ return;
+ }
+
// in case a port is bound to multiple security groups, we do NOT remove
// egress rules unless all security groups bound to the port to be removed
Port osPort = osNetService.port(instPort.portId());