VPNv6 external network support for multiple router
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronPortChangeListener.java
index d5d440d0207ba253441b517b620c1c2b42a07fab..42f07a2cc43f3b373fee8db7bbf44377316cbbd8 100644 (file)
@@ -7,13 +7,15 @@
  */
 package org.opendaylight.netvirt.neutronvpn;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
-
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -24,18 +26,20 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.ObjectUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
+import org.opendaylight.genius.infra.Datastore;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
@@ -149,7 +153,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) {
-                handleRouterGatewayUpdated(input);
+                handleRouterGatewayUpdated(input, false);
                 portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
                 handleFloatingIpPortUpdated(null, input);
@@ -189,6 +193,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             } else if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())
                     || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
+                handleRouterGatewayUpdated(input, true);
                 elanService.removeKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue());
             }
         }
@@ -225,7 +230,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
-                handleRouterGatewayUpdated(update);
+                handleRouterGatewayUpdated(update, false);
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
                 handleFloatingIpPortUpdated(original, update);
             }
@@ -244,28 +249,28 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if (origSecurityEnabled || updatedSecurityEnabled) {
             InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
             jobCoordinator.enqueueJob("PORT- " + portName,
-                () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(confTx -> {
-                    Optional<Interface> optionalInf =
-                            confTx.read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier).checkedGet();
-                    if (optionalInf.isPresent()) {
-                        InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
-                        InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
-                                origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
-                        interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
-                        LOG.info("update: Of-port-interface updation for port {}", portName);
-                        // Update OFPort interface for this neutron port
-                        confTx.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
-                                interfaceBuilder.build());
-                    } else {
-                        LOG.warn("update: Interface {} is not present", portName);
-                    }
-                })));
+                () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+                    confTx -> {
+                        Optional<Interface> optionalInf =
+                                confTx.read(interfaceIdentifier).get();
+                        if (optionalInf.isPresent()) {
+                            InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
+                            InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
+                                    origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
+                            interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+                            LOG.info("update: Of-port-interface updation for port {}", portName);
+                            // Update OFPort interface for this neutron port
+                            confTx.put(interfaceIdentifier, interfaceBuilder.build());
+                        } else {
+                            LOG.warn("update: Interface {} is not present", portName);
+                        }
+                    })));
         }
     }
 
-    private void handleFloatingIpPortUpdated(Port original, Port update) {
-        if ((original == null || original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING))
-            && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+    private void handleFloatingIpPortUpdated(@Nullable Port original, Port update) {
+        if ((original == null || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(original.getDeviceId()))
+            && !NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(update.getDeviceId())) {
             // populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
             // fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
             addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
@@ -290,16 +295,16 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 listVpnIds.add(vpnId);
                 Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
                 List<Subnetmap> subnetMapList = new ArrayList<>();
-                List<FixedIps> portIps = routerPort.getFixedIps();
                 boolean portIsIpv6 = false;
-                for (FixedIps portIP : portIps) {
+                for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+                        Collections.<FixedIps>emptyList())) {
                     // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIP
                     // and addSubnetToVpn here
                     if (internetVpnId != null
                         && portIP.getIpAddress().getIpv6Address() != null) {
                         portIsIpv6 = true;
                     }
-                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+                    String ipValue = portIP.getIpAddress().stringValue();
                     Uuid subnetId = portIP.getSubnetId();
                     nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId,
                             routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
@@ -308,24 +313,22 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 }
                 if (portIsIpv6) {
                     listVpnIds.add(internetVpnId);
-                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(
-                                     IpVersionChoice.IPV6, internetVpnId)) {
-                        neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(),
-                                                                     IpVersionChoice.IPV6, true);
-                        neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
+                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(
+                                     IpVersionChoice.IPV6, routerId, true)) {
+                        neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6,
+                                true);
+                        neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, true);
                     }
                 }
                 if (! subnetMapList.isEmpty()) {
                     nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
                 }
-                for (FixedIps portIP : routerPort.getFixedIps()) {
-                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
-                    IpVersionChoice version = neutronvpnUtils.getIpVersionFromString(ipValue);
-                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
-                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
-                               version, true);
-                    }
-                    if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
+                IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+                for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+                        Collections.<FixedIps>emptyList())) {
+                    String ipValue = portIP.getIpAddress().stringValue();
+                    ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
+                    if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
                         nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(),
                                                         null /* internet-vpn-id */);
                     } else {
@@ -335,12 +338,21 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                             ipValue, routerPort.getMacAddress(),
                             routerPort.getUuid().getValue(), vpnId.getValue());
                 }
+                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, true)) {
+                    LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+                            ipVersion, vpnId.getValue());
+                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+                }
                 nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
-                nvpnNatManager.handleSubnetsForExternalRouter(routerId);
-                ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
-                    String portInterfaceName = createOfPortInterface(routerPort, confTx);
-                    createElanInterface(routerPort, portInterfaceName, confTx);
-                }), LOG, "Error creating ELAN interface for {}", routerPort);
+                jobCoordinator.enqueueJob(routerId.toString(), () -> {
+                    nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                    return Collections.emptyList();
+                });
+                ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                    confTx -> {
+                        String portInterfaceName = createOfPortInterface(routerPort, confTx);
+                        createElanInterface(routerPort, portInterfaceName, confTx);
+                    }), LOG, "Error creating ELAN interface for {}", routerPort);
             } else {
                 LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}"
                     + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
@@ -354,8 +366,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             Uuid routerId = new Uuid(routerPort.getDeviceId());
             Uuid infNetworkId = routerPort.getNetworkId();
             elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
-            Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true), routerId);
-            List<FixedIps> portIps = routerPort.getFixedIps();
+            Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true),
+                    routerId);
+            List<FixedIps> portIps = requireNonNullElse(routerPort.getFixedIps(), Collections.emptyList());
             boolean vpnInstanceInternetIpVersionRemoved = false;
             Uuid vpnInstanceInternetUuid = null;
             for (FixedIps portIP : portIps) {
@@ -379,62 +392,75 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
              *  cleanup of router interface flows*/
             nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(),
                                            null /* vpn-id */, null /* wrtConfigTxn*/);
+            final Uuid internetVpnId = vpnInstanceInternetUuid;
             // update RouterInterfaces map
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
-                boolean vpnInstanceIpVersionRemoved = false;
-                IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
-                for (FixedIps portIP : portIps) {
-                    Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
-                    // router Port have either IPv4 or IPv6, never both
-                    if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
-                        vpnInstanceIpVersionRemoved = true;
-                        vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                confTx -> {
+                    IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+                    for (FixedIps portIP : portIps) {
+                        Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
+                        // router Port have either IPv4 or IPv6, never both
+                        ipVersion = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+                        String ipValue = portIP.getIpAddress().stringValue();
+                        neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
+                        // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
+                        // and updateSubnetNodeWithFixedIP
+                        nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), internetVpnId);
+                        nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null,
+                            null, null, null);
                     }
-                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
-                    neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
-                    // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
-                    // and updateSubnetNodeWithFixedIP
-                    nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
-                            sn != null ? sn.getInternetVpnId() : null);
-                    nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
-                }
-                nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
-                deleteElanInterface(routerPort.getUuid().getValue(), confTx);
-                deleteOfPortInterface(routerPort, confTx);
-                nvpnNatManager.handleSubnetsForExternalRouter(routerId);
-                if (vpnInstanceIpVersionRemoved) {
-                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
-                            false);
-                }
-            }), LOG, "Error handling interface removal");
+                    nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
+                    deleteElanInterface(routerPort.getUuid().getValue(), confTx);
+                    deleteOfPortInterface(routerPort, confTx);
+                    jobCoordinator.enqueueJob(routerId.toString(), () -> {
+                        nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                        return Collections.emptyList();
+                    });
+                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, false)) {
+                        LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+                                ipVersion, vpnId.getValue());
+                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
+                    }
+                }), LOG, "Error handling interface removal");
             if (vpnInstanceInternetIpVersionRemoved) {
                 neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
                         IpVersionChoice.IPV6, false);
-                neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
+                neutronvpnUtils.updateVpnInstanceWithFallback(routerId, vpnInstanceInternetUuid, false);
             }
         }
     }
 
-    private void handleRouterGatewayUpdated(Port routerGwPort) {
+    private void handleRouterGatewayUpdated(Port routerGwPort, boolean isRtrGwRemoved) {
         Uuid routerId = new Uuid(routerGwPort.getDeviceId());
         Uuid networkId = routerGwPort.getNetworkId();
         Network network = neutronvpnUtils.getNeutronNetwork(networkId);
         if (network == null) {
             return;
         }
-        boolean isExternal = neutronvpnUtils.getIsExternal(network);
+        boolean isExternal = NeutronvpnUtils.getIsExternal(network);
         if (isExternal) {
             Uuid vpnInternetId = neutronvpnUtils.getVpnForNetwork(networkId);
             if (vpnInternetId != null) {
+                if (!isRtrGwRemoved) {
+                    nvpnManager.updateVpnMaps(vpnInternetId, null, routerId, null, null);
+                }
                 List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
                 for (Subnetmap sn : snList) {
                     if (sn.getNetworkId() == networkId) {
                         continue;
                     }
-                    if (neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
+                    if (NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
                         continue;
                     }
-                    nvpnManager.addSubnetToVpn(null, sn.getId(), vpnInternetId);
+                    if (isRtrGwRemoved) {
+                        nvpnManager.removeV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+                    } else {
+                        nvpnManager.addV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+                    }
+                }
+                //Update Internet BGP-VPN
+                if (isRtrGwRemoved) {
+                    nvpnManager.updateVpnMaps(vpnInternetId, null, null, null, null);
                 }
             }
         }
@@ -459,8 +485,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
     private void setupGwMac(Router router, Port routerGwPort, Uuid routerId) {
         gwMacResolver.sendArpRequestsToExtGateways(router);
-        setExternalGwMac(routerGwPort, routerId);
-
+        jobCoordinator.enqueueJob(routerId.toString(), () -> {
+            setExternalGwMac(routerGwPort, routerId);
+            return Collections.emptyList();
+        });
     }
 
     private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
@@ -483,6 +511,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
     }
 
+    @Nullable
     private String getPortHostId(final Port port) {
         if (port != null) {
             PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
@@ -493,6 +522,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return null;
     }
 
+    @Nullable
     private Hostconfig getHostConfig(final Port port) {
         String hostId = getPortHostId(port);
         if (hostId == null) {
@@ -505,7 +535,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             LOG.error("failed to read host config from host {}", hostId, e);
             return null;
         }
-        return hostConfig.isPresent() ? hostConfig.get() : null;
+        return hostConfig.orNull();
     }
 
     private boolean isPortBound(final Port port) {
@@ -532,13 +562,14 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return false;
     }
 
+    @Nullable
     private Map<String, JsonElement> unmarshal(final String profile) {
         if (null == profile) {
             return null;
         }
         Gson gson = new Gson();
         JsonObject jsonObject = gson.fromJson(profile, JsonObject.class);
-        Map<String, JsonElement> map = new HashMap();
+        Map<String, JsonElement> map = new HashMap<>();
         for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
             map.put(entry.getKey(), entry.getValue());
         }
@@ -575,15 +606,15 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortCreated(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpAddrsList = port.getFixedIps();
+        final List<FixedIps> portIpAddrsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
         if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
             return;
         }
         jobCoordinator.enqueueJob("PORT- " + portName, () -> {
             // add direct port to subnetMaps config DS
             if (!(NeutronUtils.isPortVnicTypeNormal(port)
-                || (isPortTypeSwitchdev(port)
-                && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT)))) {
+                || isPortTypeSwitchdev(port)
+                && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT))) {
                 for (FixedIps ip: portIpAddrsList) {
                     nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
                 }
@@ -591,7 +622,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                          + "OF Port interfaces are not created", portName);
                 return Collections.emptyList();
             }
-            return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                 LOG.info("Of-port-interface creation for port {}", portName);
                 // Create of-port interface for this neutron port
                 String portInterfaceName = createOfPortInterface(port, tx);
@@ -636,9 +667,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortDeleted(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpsList = port.getFixedIps();
+        final List<FixedIps> portIpsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
         jobCoordinator.enqueueJob("PORT- " + portName,
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                 if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
                     for (FixedIps ip : portIpsList) {
                         // remove direct port from subnetMaps config DS
@@ -665,6 +696,18 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         routerIds.add(subnetMap.getRouterId());
                     }
                     internetVpnId = subnetMap.getInternetVpnId();
+
+                    if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(port.getDeviceOwner())
+                        || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(port.getDeviceOwner())) {
+                        String ipAddress = ip.getIpAddress().stringValue();
+                        if (vpnId != null) {
+                            neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipAddress, confTx);
+                        }
+                        if (internetVpnId != null) {
+                            neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(),
+                                ipAddress, confTx);
+                        }
+                    }
                 }
                 if (vpnId != null || internetVpnId != null) {
                     // remove vpn-interface for this neutron port
@@ -699,8 +742,13 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                       + "during subnet deletion event.", portupdate.getUuid().getValue());
             return;
         }
+
+        if (NeutronConstants.IS_ODL_DHCP_PORT.test(portupdate)) {
+            return;
+        }
+
         jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                 final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
                         .collect(Collectors.toList());
                 final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId)
@@ -723,7 +771,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         }
                     }
                 }
-                Set<Uuid> newVpnIds = new HashSet();
+                Set<Uuid> newVpnIds = new HashSet<>();
                 Set<Uuid> newRouterIds = new HashSet<>();
                 for (Uuid snId: updateSnMapsIds) {
                     Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
@@ -762,6 +810,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             })));
     }
 
+    @Nullable
     private InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal,
             Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
             InterfaceBuilder interfaceBuilder) {
@@ -802,7 +851,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return interfaceAclBuilder;
     }
 
-    private String createOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
+    private String createOfPortInterface(Port port, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
         Interface inf = createInterface(port);
         String infName = inf.getName();
 
@@ -812,7 +861,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                     SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             interfaceIdentifier);
             if (!optionalInf.isPresent()) {
-                wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
+                wrtConfigTxn.put(interfaceIdentifier, inf);
             } else {
                 LOG.warn("Interface {} is already present", infName);
             }
@@ -849,7 +898,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return interfaceBuilder.build();
     }
 
-    private void deleteOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
+    private void deleteOfPortInterface(Port port, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
         String name = port.getUuid().getValue();
         LOG.debug("Removing OFPort Interface {}", name);
         InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
@@ -858,7 +907,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                     SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             interfaceIdentifier);
             if (optionalInf.isPresent()) {
-                wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
+                wrtConfigTxn.delete(interfaceIdentifier);
             } else {
                 LOG.warn("deleteOfPortInterface: Interface {} is not present", name);
             }
@@ -867,7 +916,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         }
     }
 
-    private void createElanInterface(Port port, String name, WriteTransaction wrtConfigTxn) {
+    private void createElanInterface(Port port, String name,
+                                     TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
         String elanInstanceName = port.getNetworkId().getValue();
         List<StaticMacEntries> staticMacEntries = NeutronvpnUtils.buildStaticMacEntry(port);
 
@@ -875,14 +925,14 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
                 .setName(name).setStaticMacEntries(staticMacEntries).withKey(new ElanInterfaceKey(name)).build();
-        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface);
+        wrtConfigTxn.put(id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
 
-    private void deleteElanInterface(String name, WriteTransaction wrtConfigTxn) {
+    private void deleteElanInterface(String name, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
                 .class, new ElanInterfaceKey(name)).build();
-        wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, id);
+        wrtConfigTxn.delete(id);
     }
 
     // TODO Clean up the exception handling