Remove vpn-portip-to-port entry for Floating IP
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronPortChangeListener.java
index ddbb2ad81c5a341131e638be12f6ab83e9c27281..facce142fbf80a36038cdd111466c8893e48af54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.netvirt.neutronvpn;
 
-import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier;
-
 import com.google.common.base.Optional;
 import com.google.common.base.Strings;
-import com.google.common.util.concurrent.ListenableFuture;
 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;
 import java.util.HashMap;
@@ -27,16 +26,19 @@ import java.util.Set;
 import java.util.stream.Collectors;
 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.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
@@ -84,6 +86,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private final JobCoordinator jobCoordinator;
     private final NeutronvpnUtils neutronvpnUtils;
     private final HostConfigCache hostConfigCache;
+    private final DataTreeEventCallbackRegistrar eventCallbacks;
 
     public NeutronPortChangeListener(final DataBroker dataBroker,
                                      final NeutronvpnManager neutronvpnManager,
@@ -92,7 +95,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                                      final IElanService elanService,
                                      final JobCoordinator jobCoordinator,
                                      final NeutronvpnUtils neutronvpnUtils,
-                                     final HostConfigCache hostConfigCache) {
+                                     final HostConfigCache hostConfigCache,
+                                     final DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar) {
         super(Port.class, NeutronPortChangeListener.class);
         this.dataBroker = dataBroker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
@@ -103,6 +107,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         this.jobCoordinator = jobCoordinator;
         this.neutronvpnUtils = neutronvpnUtils;
         this.hostConfigCache = hostConfigCache;
+        this.eventCallbacks = dataTreeEventCallbackRegistrar;
     }
 
     @Override
@@ -134,10 +139,11 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                     portName, network);
             return;
         }
+
         neutronvpnUtils.addToPortCache(input);
         String portStatus = NeutronUtils.PORT_STATUS_DOWN;
         if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
-            if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
+            if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(input.getDeviceOwner())) {
                 handleRouterInterfaceAdded(input);
                 NeutronUtils.createPortStatus(input.getUuid().getValue(), NeutronUtils.PORT_STATUS_ACTIVE, dataBroker);
                 return;
@@ -164,7 +170,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     protected void remove(InstanceIdentifier<Port> identifier, Port input) {
         LOG.trace("Removing Port : key: {}, value={}", identifier, input);
         Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId());
-        if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
+        // need to proceed with deletion in case network is null for a case where v2 sync happens and a read for
+        // network from NN returns null, but the deletion process for port needs to continue
+        if (network != null && !NeutronvpnUtils.isNetworkTypeSupported(network)) {
             String portName = input.getUuid().getValue();
             LOG.warn("neutron vpn received a port remove() for a network without a provider extension augmentation "
                             + "or with an unsupported network type for the port {} which is part of network {}",
@@ -175,7 +183,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         NeutronUtils.deletePortStatus(input.getUuid().getValue(), dataBroker);
 
         if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
-            if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
+            if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(input.getDeviceOwner())) {
                 handleRouterInterfaceRemoved(input);
                 /* nothing else to do here */
                 return;
@@ -202,7 +210,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         Network network = neutronvpnUtils.getNeutronNetwork(update.getNetworkId());
         LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
-            LOG.error("neutron vpn received a port update() for a network without a provider extension augmentation "
+            LOG.warn("neutron vpn received a port update() for a network without a provider extension augmentation "
                     + "or with an unsupported network type for the port {} which is part of network {}",
                     portName, network);
             return;
@@ -212,7 +220,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if ((Strings.isNullOrEmpty(original.getDeviceOwner()) || Strings.isNullOrEmpty(original.getDeviceId())
                 || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equalsIgnoreCase(original.getDeviceId()))
                 && !Strings.isNullOrEmpty(update.getDeviceOwner()) && !Strings.isNullOrEmpty(update.getDeviceId())) {
-            if (update.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
+            if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(update.getDeviceOwner())) {
                 handleRouterInterfaceAdded(update);
                 return;
             }
@@ -235,12 +243,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
         if (origSecurityEnabled || updatedSecurityEnabled) {
             InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
-            jobCoordinator.enqueueJob("PORT- " + portName, () -> {
-                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                try {
+            jobCoordinator.enqueueJob("PORT- " + portName,
+                () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(confTx -> {
                     Optional<Interface> optionalInf =
-                            SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                                    interfaceIdentifier);
+                            confTx.read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier).checkedGet();
                     if (optionalInf.isPresent()) {
                         InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
                         InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
@@ -248,18 +254,12 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
                         LOG.info("update: Of-port-interface updation for port {}", portName);
                         // Update OFPort interface for this neutron port
-                        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
+                        confTx.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
                                 interfaceBuilder.build());
                     } else {
                         LOG.warn("update: Interface {} is not present", portName);
                     }
-                } catch (ReadFailedException e) {
-                    LOG.error("update: Failed to update interface {}", portName, e);
-                }
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
-                futures.add(wrtConfigTxn.submit());
-                return futures;
-            });
+                })));
         }
     }
 
@@ -337,10 +337,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 }
                 nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
                 nvpnNatManager.handleSubnetsForExternalRouter(routerId);
-                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
-                createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
-                wrtConfigTxn.submit();
+                ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(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,10 +354,7 @@ 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 = neutronvpnUtils.getVpnForRouter(routerId, true);
-            if (vpnId == null) {
-                vpnId = routerId;
-            }
+            Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true), routerId);
             List<FixedIps> portIps = routerPort.getFixedIps();
             boolean vpnInstanceInternetIpVersionRemoved = false;
             Uuid vpnInstanceInternetUuid = null;
@@ -383,35 +380,36 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(),
                                            null /* vpn-id */, null /* wrtConfigTxn*/);
             // update RouterInterfaces map
-            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-            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(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());
+                    }
+                    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);
                 }
-                String ipValue = String.valueOf(portIP.getIpAddress().getValue());
-                neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, wrtConfigTxn);
-                // 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(), wrtConfigTxn);
-            deleteOfPortInterface(routerPort, wrtConfigTxn);
-            wrtConfigTxn.submit();
-            nvpnNatManager.handleSubnetsForExternalRouter(routerId);
-            if (vpnInstanceIpVersionRemoved) {
-                neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
-                          false);
-            }
+                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");
             if (vpnInstanceInternetIpVersionRemoved) {
                 neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
-                                                             IpVersionChoice.IPV6, false);
+                        IpVersionChoice.IPV6, false);
                 neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
             }
         }
@@ -446,11 +444,23 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if (router == null) {
             LOG.warn("No router found for router GW port {} for router {}", routerGwPort.getUuid().getValue(),
                     routerId.getValue());
+            // NETVIRT-1249
+            eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
+                    neutronvpnUtils.getNeutronRouterIid(routerId), (unused, newRouter) -> {
+                    setupGwMac(newRouter, routerGwPort, routerId);
+                    return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
+                }, Duration.ofSeconds(3), iid -> {
+                    LOG.error("GwPort {} added without Router", routerGwPort.getUuid().getValue());
+                });
             return;
         }
-        gwMacResolver.sendArpRequestsToExtGateways(router);
+        setupGwMac(router, routerGwPort, routerId);
+    }
 
+    private void setupGwMac(Router router, Port routerGwPort, Uuid routerId) {
+        gwMacResolver.sendArpRequestsToExtGateways(router);
         setExternalGwMac(routerGwPort, routerId);
+
     }
 
     private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
@@ -475,7 +485,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
     private String getPortHostId(final Port port) {
         if (port != null) {
-            PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);
+            PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
             if (portBinding != null) {
                 return portBinding.getHostId();
             }
@@ -504,7 +514,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     }
 
     private boolean isPortVnicTypeDirect(Port port) {
-        PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);
+        PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
         if (portBinding == null || portBinding.getVnicType() == null) {
             // By default, VNIC_TYPE is NORMAL
             return false;
@@ -540,7 +550,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             return false;
         }
 
-        PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);
+        PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
         String profile = portBinding.getProfile();
         if (profile == null || profile.isEmpty()) {
             LOG.debug("Port {} has no binding:profile values", port.getUuid());
@@ -627,55 +637,64 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
         final List<FixedIps> portIpsList = port.getFixedIps();
-        jobCoordinator.enqueueJob("PORT- " + portName, () -> {
-            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-            List<ListenableFuture<Void>> futures = new ArrayList<>();
-            if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
-                for (FixedIps ip: portIpsList) {
-                    // remove direct port from subnetMaps config DS
-                    nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
-                }
-                LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;"
-                         + "Skipping OF Port interfaces removal", portName);
-                return futures;
-            }
-            Uuid vpnId = null;
-            Set<Uuid> routerIds = new HashSet<>();
-            Uuid internetVpnId = null;
-            for (FixedIps ip: portIpsList) {
-                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
-                if (subnetMap == null) {
-                    continue;
-                }
-                if (subnetMap.getVpnId() != null) {
-                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
-                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
-                    vpnId = subnetMap.getVpnId();
+        jobCoordinator.enqueueJob("PORT- " + portName,
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
+                if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
+                    for (FixedIps ip : portIpsList) {
+                        // remove direct port from subnetMaps config DS
+                        nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
+                    }
+                    LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;"
+                            + "Skipping OF Port interfaces removal", portName);
+                    return;
                 }
-                if (subnetMap.getRouterId() != null) {
-                    routerIds.add(subnetMap.getRouterId());
+                Uuid vpnId = null;
+                Set<Uuid> routerIds = new HashSet<>();
+                Uuid internetVpnId = null;
+                for (FixedIps ip : portIpsList) {
+                    Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
+                    if (subnetMap == null) {
+                        continue;
+                    }
+                    if (subnetMap.getVpnId() != null) {
+                        // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
+                        // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
+                        vpnId = subnetMap.getVpnId();
+                    }
+                    if (subnetMap.getRouterId() != null) {
+                        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 = String.valueOf(ip.getIpAddress().getValue());
+                        if (vpnId != null) {
+                            neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipAddress, confTx);
+                        }
+                        if (internetVpnId != null) {
+                            neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(),
+                                ipAddress, confTx);
+                        }
+                    }
                 }
-                internetVpnId = subnetMap.getInternetVpnId();
-            }
-            if (vpnId != null || internetVpnId != null) {
-                // remove vpn-interface for this neutron port
-                LOG.debug("removing VPN Interface for port {}", portName);
-                if (!routerIds.isEmpty()) {
-                    for (Uuid routerId : routerIds) {
-                        nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
+                if (vpnId != null || internetVpnId != null) {
+                    // remove vpn-interface for this neutron port
+                    LOG.debug("removing VPN Interface for port {}", portName);
+                    if (!routerIds.isEmpty()) {
+                        for (Uuid routerId : routerIds) {
+                            nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
+                        }
                     }
+                    nvpnManager.deleteVpnInterface(portName, null /* vpn-id */, confTx);
                 }
-                nvpnManager.deleteVpnInterface(portName, null /* vpn-id */, wrtConfigTxn);
-            }
-            // Remove of-port interface for this neutron port
-            // ELAN interface is also implicitly deleted as part of this operation
-            LOG.debug("Of-port-interface removal for port {}", portName);
-            deleteOfPortInterface(port, wrtConfigTxn);
-            //dissociate fixedIP from floatingIP if associated
-            nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
-            futures.add(wrtConfigTxn.submit());
-            return futures;
-        });
+                // Remove of-port interface for this neutron port
+                // ELAN interface is also implicitly deleted as part of this operation
+                LOG.debug("Of-port-interface removal for port {}", portName);
+                deleteOfPortInterface(port, confTx);
+                //dissociate fixedIP from floatingIP if associated
+                nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
+            })));
     }
 
 
@@ -693,14 +712,13 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             return;
         }
         jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
                 final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
                         .collect(Collectors.toList());
                 final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId)
                         .collect(Collectors.toList());
                 Set<Uuid> originalRouterIds = new HashSet<>();
                 Set<Uuid> oldVpnIds = new HashSet<>();
-                Uuid oldRouterId = null;
                 for (Uuid snId: originalSnMapsIds) {
                     if (!updateSnMapsIds.remove(snId)) {
                         // snId was present in originalSnMapsIds, but not in updateSnMapsIds
@@ -733,7 +751,6 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         }
                     }
                 }
-                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
                 if (!oldVpnIds.isEmpty()) {
                     LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
                     if (!originalRouterIds.isEmpty()) {
@@ -743,11 +760,11 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         }
                     }
                     nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(),
-                                                   null /* vpn-id */, wrtConfigTxn);
+                                                   null /* vpn-id */, confTx);
                 }
                 if (!newVpnIds.isEmpty()) {
                     LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
-                    nvpnManager.createVpnInterface(newVpnIds, portupdate, wrtConfigTxn);
+                    nvpnManager.createVpnInterface(newVpnIds, portupdate, confTx);
                     if (!newRouterIds.isEmpty()) {
                         for (Uuid routerId : newRouterIds) {
                             nvpnManager.addToNeutronRouterInterfacesMap(routerId,portupdate.getUuid().getValue());
@@ -776,7 +793,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         } else {
             if (updatedSecurityEnabled) {
                 // handle SG add/delete delta
-                InterfaceAcl interfaceAcl = interfaceBuilder.getAugmentation(InterfaceAcl.class);
+                InterfaceAcl interfaceAcl = interfaceBuilder.augmentation(InterfaceAcl.class);
                 interfaceAclBuilder = new InterfaceAclBuilder(interfaceAcl);
                 interfaceAclBuilder.setSecurityGroups(
                         NeutronvpnUtils.getUpdatedSecurityGroups(interfaceAcl.getSecurityGroups(),
@@ -822,6 +839,13 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         IfL2vlan.L2vlanMode l2VlanMode = IfL2vlan.L2vlanMode.Trunk;
         InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
         IfL2vlanBuilder ifL2vlanBuilder = new IfL2vlanBuilder();
+
+        Network network = neutronvpnUtils.getNeutronNetwork(port.getNetworkId());
+        Boolean isVlanTransparent = network.isVlanTransparent();
+        if (isVlanTransparent != null && isVlanTransparent) {
+            l2VlanMode = IfL2vlan.L2vlanMode.Transparent;
+        }
+
         ifL2vlanBuilder.setL2vlanMode(l2VlanMode);
 
         interfaceBuilder.setEnabled(true).setName(interfaceName).setType(L2vlan.class)
@@ -862,7 +886,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
                 .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
-                .setName(name).setStaticMacEntries(staticMacEntries).setKey(new ElanInterfaceKey(name)).build();
+                .setName(name).setStaticMacEntries(staticMacEntries).withKey(new ElanInterfaceKey(name)).build();
         wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
@@ -877,10 +901,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void addToFloatingIpPortInfo(Uuid floatingIpId, Uuid floatingIpPortId, Uuid floatingIpPortSubnetId, String
                                          floatingIpPortMacAddress) {
-        InstanceIdentifier id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
+        InstanceIdentifier id = NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         try {
             FloatingIpIdToPortMappingBuilder floatingipIdToPortMacMappingBuilder = new
-                FloatingIpIdToPortMappingBuilder().setKey(new FloatingIpIdToPortMappingKey(floatingIpId))
+                FloatingIpIdToPortMappingBuilder().withKey(new FloatingIpIdToPortMappingKey(floatingIpId))
                 .setFloatingIpId(floatingIpId).setFloatingIpPortId(floatingIpPortId)
                 .setFloatingIpPortSubnetId(floatingIpPortSubnetId)
                 .setFloatingIpPortMacAddress(floatingIpPortMacAddress);