Unblock the Netvirt CSIT Issue from VPNManager
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / SubnetRouteInterfaceStateChangeListener.java
index a427fedb39086b6f1a50801e1f754ba63e4a3f25..f99931b111d0307ea39f73788deaecd4c199429c 100644 (file)
@@ -7,39 +7,43 @@
  */
 package org.opendaylight.netvirt.vpnmanager;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.PostConstruct;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
 import org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class SubnetRouteInterfaceStateChangeListener extends AsyncDataTreeChangeListenerBase<Interface,
-    SubnetRouteInterfaceStateChangeListener> {
+public class SubnetRouteInterfaceStateChangeListener extends AbstractAsyncDataTreeChangeListener<Interface> {
     private static final Logger LOG = LoggerFactory.getLogger(SubnetRouteInterfaceStateChangeListener.class);
     private static final String LOGGING_PREFIX = "SUBNETROUTE:";
     private final DataBroker dataBroker;
@@ -52,98 +56,96 @@ public class SubnetRouteInterfaceStateChangeListener extends AsyncDataTreeChange
     public SubnetRouteInterfaceStateChangeListener(final DataBroker dataBroker,
             final VpnSubnetRouteHandler vpnSubnetRouteHandler, final SubnetOpDpnManager subnetOpDpnManager,
             final INeutronVpnManager neutronVpnService, final JobCoordinator jobCoordinator) {
-        super(Interface.class, SubnetRouteInterfaceStateChangeListener.class);
+        super(dataBroker, LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(InterfacesState.class).child(Interface.class),
+                Executors.newListeningSingleThreadExecutor("SubnetRouteInterfaceStateChangeListener", LOG));
         this.dataBroker = dataBroker;
         this.vpnSubnetRouteHandler = vpnSubnetRouteHandler;
         this.subOpDpnManager = subnetOpDpnManager;
         this.neutronVpnManager = neutronVpnService;
         this.jobCoordinator = jobCoordinator;
+        start();
     }
 
-    @PostConstruct
     public void start() {
         LOG.info("{} start", getClass().getSimpleName());
-        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
 
     @Override
-    protected InstanceIdentifier<Interface> getWildCardPath() {
-        return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
 
-    @Override
-    protected SubnetRouteInterfaceStateChangeListener getDataTreeChangeListener() {
-        return SubnetRouteInterfaceStateChangeListener.this;
-    }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+    public void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
         LOG.trace("{} add: Received interface {} up event", LOGGING_PREFIX, intrf);
-        try {
-            if (L2vlan.class.equals(intrf.getType())) {
-                LOG.trace("SubnetRouteInterfaceListener add: Received interface {} up event", intrf);
-                if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
-                    List<Uuid> subnetIdList = getSubnetId(intrf);
-                    if (subnetIdList.isEmpty()) {
-                        LOG.trace("SubnetRouteInterfaceListener add: Port {} doesnt exist in configDS",
-                                intrf.getName());
-                        return;
-                    }
-                    for (Uuid subnetId : subnetIdList) {
-                        jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
-                            () -> {
-                                String interfaceName = intrf.getName();
-                                BigInteger dpnId = BigInteger.ZERO;
-                                LOG.info("{} add: Received port UP event for interface {} subnetId {}",
-                                        LOGGING_PREFIX, interfaceName, subnetId);
-                                try {
-                                    dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
-                                } catch (Exception e) {
-                                    LOG.error("{} add: Unable to obtain dpnId for interface {} in subnet {},"
-                                            + " subnetroute inclusion for this interface failed",
-                                            LOGGING_PREFIX, interfaceName, subnetId, e);
-                                }
-                                InstanceIdentifier<VpnInterface> id = VpnUtil
-                                        .getVpnInterfaceIdentifier(interfaceName);
-                                Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker,
-                                     LogicalDatastoreType.CONFIGURATION, id);
-                                List<ListenableFuture<Void>> futures = new ArrayList<>();
+        if (L2vlan.class.equals(intrf.getType())) {
+            LOG.trace("SubnetRouteInterfaceListener add: Received interface {} up event", intrf);
+            if (Interface.OperStatus.Up.equals(intrf.getOperStatus())) {
+                List<Uuid> subnetIdList = getSubnetId(intrf);
+                if (subnetIdList.isEmpty()) {
+                    LOG.trace("SubnetRouteInterfaceListener add: Port {} doesn't exist in configDS",
+                            intrf.getName());
+                    return;
+                }
+                for (Uuid subnetId : subnetIdList) {
+                    jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+                        () -> {
+                            String interfaceName = intrf.getName();
+                            Uint64 dpnId = Uint64.ZERO;
+                            LOG.info("{} add: Received port UP event for interface {} subnetId {}",
+                                    LOGGING_PREFIX, interfaceName, subnetId);
+                            try {
+                                dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
+                            } catch (NullPointerException e) {
+                                LOG.error("{} add: Unable to obtain dpnId for interface {} in subnet {},"
+                                                + " subnetroute inclusion for this interface failed", LOGGING_PREFIX,
+                                        interfaceName, subnetId, e);
+                            }
+                            List<ListenableFuture<Void>> futures = new ArrayList<>();
+                            try {
+                                InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
+                                Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptional(
+                                        dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                                 if (!cfgVpnInterface.isPresent()) {
                                     return futures;
                                 }
                                 vpnSubnetRouteHandler.onInterfaceUp(dpnId, intrf.getName(), subnetId);
-                                return futures;
-                            });
-                    }
+                                LOG.info("{} add: Processed interface {} up event", LOGGING_PREFIX, intrf.getName());
+                            } catch (InterruptedException | ExecutionException e) {
+                                LOG.error("add: Failed to read data store for interface {} dpn {}", interfaceName,
+                                        dpnId);
+                            }
+                            return futures;
+                        });
                 }
             }
-            LOG.info("{} add: Processed interface {} up event", LOGGING_PREFIX, intrf.getName());
-        } catch (Exception e) {
-            LOG.error("{} add: Exception observed in handling addition for VPN Interface {}.", LOGGING_PREFIX,
-                intrf.getName(), e);
         }
     }
 
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
-        try {
-            if (L2vlan.class.equals(intrf.getType())) {
-                LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
-                List<Uuid> subnetIdList = getSubnetId(intrf);
-                if (subnetIdList.isEmpty()) {
-                    LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesnt exist in configDS",
-                            intrf.getName());
-                    return;
-                }
-                for (Uuid subnetId : subnetIdList) {
-                    jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
-                        () -> {
+    public void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
+        if (L2vlan.class.equals(intrf.getType())) {
+            LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
+            List<Uuid> subnetIdList = getSubnetId(intrf);
+            if (subnetIdList.isEmpty()) {
+                LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesn't exist in configDS",
+                        intrf.getName());
+                return;
+            }
+            LOG.trace("{} remove: Processing interface {} down event in ", LOGGING_PREFIX, intrf.getName());
+            for (Uuid subnetId : subnetIdList) {
+                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+                    () -> {
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+                        try {
                             String interfaceName = intrf.getName();
-                            BigInteger dpnId = BigInteger.ZERO;
+                            Uint64 dpnId = Uint64.ZERO;
                             LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ",
                                     LOGGING_PREFIX, interfaceName, subnetId);
                             try {
@@ -155,26 +157,25 @@ public class SubnetRouteInterfaceStateChangeListener extends AsyncDataTreeChange
                             }
                             InstanceIdentifier<VpnInterface> id = VpnUtil
                                     .getVpnInterfaceIdentifier(interfaceName);
-                            Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker,
-                                     LogicalDatastoreType.CONFIGURATION, id);
-                            List<ListenableFuture<Void>> futures = new ArrayList<>();
+                            Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptional(
+                                    dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                             if (!cfgVpnInterface.isPresent()) {
                                 return futures;
                             }
                             boolean interfaceDownEligible = false;
-                            for (VpnInstanceNames vpnInterfaceVpnInstance
-                                 : cfgVpnInterface.get().getVpnInstanceNames()) {
+                            for (VpnInstanceNames vpnInterfaceVpnInstance :
+                                    cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
                                 String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil
-                                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
-                                Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker,
-                                       LogicalDatastoreType.OPERATIONAL, idOper);
+                                        .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
+                                Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker
+                                        .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                                 if (optVpnInterface.isPresent()) {
-                                    BigInteger dpnIdLocal = dpnId;
-                                    if (dpnIdLocal.equals(BigInteger.ZERO)) {
+                                    Uint64 dpnIdLocal = dpnId;
+                                    if (Uint64.ZERO.equals(dpnIdLocal)) {
                                         dpnIdLocal = optVpnInterface.get().getDpnId();
                                     }
-                                    if (!dpnIdLocal.equals(BigInteger.ZERO)) {
+                                    if (!Uint64.ZERO.equals(dpnIdLocal)) {
                                         interfaceDownEligible = true;
                                         break;
                                     }
@@ -183,105 +184,102 @@ public class SubnetRouteInterfaceStateChangeListener extends AsyncDataTreeChange
                             if (interfaceDownEligible) {
                                 vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
                             }
-                            return futures;
-                        });
-                }
+                            LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX,
+                                    intrf.getName());
+                        } catch (InterruptedException | ExecutionException e) {
+                            LOG.error("{} remove: Failed to read data store for {}", LOGGING_PREFIX, intrf.getName());
+                        }
+                        return futures;
+                    });
             }
-            LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX, intrf.getName());
-        } catch (Exception e) {
-            LOG.error("{} remove: Exception observed in handling deletion of VPN Interface {}.", LOGGING_PREFIX,
-                intrf.getName(), e);
         }
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    protected void update(InstanceIdentifier<Interface> identifier,
+    public void update(InstanceIdentifier<Interface> identifier,
         Interface original, Interface update) {
-        try {
-            String interfaceName = update.getName();
-            if (L2vlan.class.equals(update.getType())) {
-                LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX,
+        String interfaceName = update.getName();
+        if (L2vlan.class.equals(update.getType())) {
+            LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX,
                     original, update);
-                List<Uuid> subnetIdList = getSubnetId(update);
-                if (subnetIdList.isEmpty()) {
-                    LOG.error("SubnetRouteInterfaceListener update: Port {} doesnt exist in configDS",
-                            update.getName());
-                    return;
-                }
-                for (Uuid subnetId : subnetIdList) {
-                    jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
-                        () -> {
-                            List<ListenableFuture<Void>> futures = new ArrayList<>();
-                            BigInteger dpnId = BigInteger.ZERO;
-                            try {
-                                dpnId = InterfaceUtils.getDpIdFromInterface(update);
-                            } catch (Exception e) {
-                                LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet  {}. "
-                                                + "Fetching from vpn interface itself",
-                                        LOGGING_PREFIX, update.getName(), subnetId, e);
-                            }
+            List<Uuid> subnetIdList = getSubnetId(update);
+            if (subnetIdList.isEmpty()) {
+                LOG.error("SubnetRouteInterfaceListener update: Port {} doesn't exist in configDS",
+                        update.getName());
+                return;
+            }
+            for (Uuid subnetId : subnetIdList) {
+                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+                    () -> {
+                        Uint64 dpnId = Uint64.ZERO;
+                        try {
+                            dpnId = InterfaceUtils.getDpIdFromInterface(update);
+                        } catch (NullPointerException e) {
+                            LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet  {}. "
+                                            + "Fetching from vpn interface itself", LOGGING_PREFIX, update.getName(),
+                                    subnetId, e);
+                        }
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+                        try {
                             InstanceIdentifier<VpnInterface> id = VpnUtil
                                     .getVpnInterfaceIdentifier(interfaceName);
-                            Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker,
-                                     LogicalDatastoreType.CONFIGURATION, id);
+                            Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptional(
+                                    dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                             if (!cfgVpnInterface.isPresent()) {
                                 return futures;
                             }
                             boolean interfaceChangeEligible = false;
-                            for (VpnInstanceNames vpnInterfaceVpnInstance
-                                  : cfgVpnInterface.get().getVpnInstanceNames()) {
+                            for (VpnInstanceNames vpnInterfaceVpnInstance :
+                                    cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
                                 String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil
-                                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
-                                Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker,
-                                       LogicalDatastoreType.OPERATIONAL, idOper);
+                                        .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
+                                Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker
+                                        .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                                 if (optVpnInterface.isPresent()) {
-                                    BigInteger dpnIdLocal = dpnId;
-                                    if (dpnIdLocal.equals(BigInteger.ZERO)) {
+                                    Uint64 dpnIdLocal = dpnId;
+                                    if (Uint64.ZERO.equals(dpnIdLocal)) {
                                         dpnIdLocal = optVpnInterface.get().getDpnId();
                                     }
-                                    if (!dpnIdLocal.equals(BigInteger.ZERO)) {
+                                    if (!Uint64.ZERO.equals(dpnIdLocal)) {
                                         interfaceChangeEligible = true;
                                         break;
                                     }
                                 }
                             }
                             if (interfaceChangeEligible) {
-                                if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+                                if (Interface.OperStatus.Up.equals(update.getOperStatus())) {
                                     LOG.info("{} update: Received port UP event for interface {} in subnet {}",
                                             LOGGING_PREFIX, update.getName(), subnetId);
                                     vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
-                                } else if (update.getOperStatus().equals(Interface.OperStatus.Down)
-                                        || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
-                                    /*
-                                     * If the interface went down voluntarily (or) if the interface is not
-                                     * reachable from control-path involuntarily, trigger subnetRoute election
-                                     */
+                                } else if (Interface.OperStatus.Down.equals(update.getOperStatus())
+                                        || Interface.OperStatus.Unknown.equals(update.getOperStatus())) {
+                                /*
+                                 * If the interface went down voluntarily (or) if the interface is not
+                                 * reachable from control-path involuntarily, trigger subnetRoute election
+                                 */
                                     LOG.info("{} update: Received port {} event for interface {} in subnet {} ",
-                                            LOGGING_PREFIX, update.getOperStatus()
-                                            .equals(Interface.OperStatus.Unknown)
-                                            ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
+                                            LOGGING_PREFIX, Interface.OperStatus.Unknown.equals(update.getOperStatus())
+                                                    ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
                                     vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
                                 }
                             }
-                            return futures;
-                        });
-                }
+                        } catch (InterruptedException | ExecutionException e) {
+                            LOG.error("update: Failed to read data store for interface {} dpn {}", interfaceName,
+                                    dpnId);
+                        }
+                        return futures;
+                    });
             }
-            LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
-        } catch (Exception e) {
-            LOG.error("{} update: Exception observed in handling deletion of VPNInterface {}", LOGGING_PREFIX,
-                    update.getName(), e);
         }
+        LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
     }
 
-    @Nonnull
+    @NonNull
     protected List<Uuid> getSubnetId(Interface intrf) {
         List<Uuid> listSubnetIds = new ArrayList<>();
         if (!NeutronUtils.isUuid(intrf.getName())) {
-            LOG.debug("SubnetRouteInterfaceListener: Interface {} doesnt have valid uuid pattern", intrf.getName());
+            LOG.debug("SubnetRouteInterfaceListener: Interface {} doesn't have valid uuid pattern", intrf.getName());
             return listSubnetIds;
         }
 
@@ -299,9 +297,9 @@ public class SubnetRouteInterfaceStateChangeListener extends AsyncDataTreeChange
         if (port == null) {
             return listSubnetIds;
         }
-        List<FixedIps> portIps = port.getFixedIps();
-        if (port.getFixedIps() != null) {
-            for (FixedIps portIp : portIps) {
+        Map<FixedIpsKey, FixedIps> portIpsMap = port.getFixedIps();
+        if (portIpsMap != null) {
+            for (FixedIps portIp : portIpsMap.values()) {
                 listSubnetIds.add(portIp.getSubnetId());
             }
         }