Net-odl full-sync. Set router ext gw MAC
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronPortChangeListener.java
index 045951cdb9abd107fb7170cbaf22463ae21315ef..d9aab7205a29a8d4bbbe0c512e2c31f213ecac5e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 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,
  */
 package org.opendaylight.netvirt.neutronvpn;
 
+import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier;
+
 import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
-import java.util.concurrent.Callable;
-
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+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.binding.api.*;
-import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+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.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
-import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
+import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 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.genius.interfacemanager.rev160406.IfL2vlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstanceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.PortAddedToSubnetBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.PortRemovedFromSubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
 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.ports.attributes.Ports;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.ext.rev160613.QosPortExtension;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<Port, NeutronPortChangeListener>
-        implements AutoCloseable {
+@Singleton
+public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<Port, NeutronPortChangeListener> {
     private static final Logger LOG = LoggerFactory.getLogger(NeutronPortChangeListener.class);
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
     private final NeutronvpnManager nvpnManager;
     private final NeutronvpnNatManager nvpnNatManager;
-    private final LockManagerService lockManager;
-    private final NotificationPublishService notificationPublishService;
     private final NeutronSubnetGwMacResolver gwMacResolver;
-    private OdlInterfaceRpcService odlInterfaceRpcService;
     private final IElanService elanService;
+    private final JobCoordinator jobCoordinator;
+    private final NeutronvpnUtils neutronvpnUtils;
 
+    @Inject
     public NeutronPortChangeListener(final DataBroker dataBroker,
-                                     final NeutronvpnManager nVpnMgr, final NeutronvpnNatManager nVpnNatMgr,
-                                     final NotificationPublishService notiPublishService,
-                                     final LockManagerService lockManager, NeutronSubnetGwMacResolver gwMacResolver,
-                                     final OdlInterfaceRpcService odlInterfaceRpcService,
-                                     final IElanService elanService) {
+                                     final NeutronvpnManager neutronvpnManager,
+                                     final NeutronvpnNatManager neutronvpnNatManager,
+                                     final NeutronSubnetGwMacResolver gwMacResolver,
+                                     final IElanService elanService,
+                                     final JobCoordinator jobCoordinator,
+                                     final NeutronvpnUtils neutronvpnUtils) {
         super(Port.class, NeutronPortChangeListener.class);
         this.dataBroker = dataBroker;
-        nvpnManager = nVpnMgr;
-        nvpnNatManager = nVpnNatMgr;
-        notificationPublishService = notiPublishService;
-        this.lockManager = lockManager;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+        nvpnManager = neutronvpnManager;
+        nvpnNatManager = neutronvpnNatManager;
         this.gwMacResolver = gwMacResolver;
-        this.odlInterfaceRpcService = odlInterfaceRpcService;
         this.elanService = elanService;
+        this.jobCoordinator = jobCoordinator;
+        this.neutronvpnUtils = neutronvpnUtils;
     }
 
-
-    public void start() {
-        LOG.info("{} start", getClass().getSimpleName());
+    @Override
+    @PostConstruct
+    public void init() {
+        LOG.info("{} init", getClass().getSimpleName());
         registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
     }
 
@@ -120,472 +114,143 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
 
     @Override
-    protected void add(InstanceIdentifier<Port> identifier, final Port input) {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Adding Port : key: " + identifier + ", value=" + input);
-        }
-        final Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, input.getNetworkId());
+    protected void add(InstanceIdentifier<Port> identifier, Port input) {
+        String portName = input.getUuid().getValue();
+        LOG.trace("Adding Port : key: {}, value={}", identifier, input);
+        Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
-            //FIXME: This should be removed when support for VLAN and GRE network types is added
-            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} "
-                    + "which is part of network {}.", input.getName(), network);
+            LOG.warn("neutron vpn received a port add() 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;
         }
-        NeutronvpnUtils.addToPortCache(input);
-
-        /* check if router interface has been created */
-        if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
+        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)) {
                 handleRouterInterfaceAdded(input);
-                /* nothing else to do here */
+                NeutronUtils.createPortStatus(input.getUuid().getValue(), NeutronUtils.PORT_STATUS_ACTIVE, dataBroker);
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) {
                 handleRouterGatewayUpdated(input);
+                portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
-                elanService.handleKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue(),
-                        NwConstants.ADD_FLOW);
+                handleFloatingIpPortUpdated(null, input);
+                portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             }
         }
         if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
-            final DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-            dataStoreCoordinator.enqueueJob("NPORT" + input.getKey().toString(),
-                    new Callable<List<ListenableFuture<Void>>>() {
-                        @Override
-                        public List<ListenableFuture<Void>> call() throws Exception {
-                            //TODO: Below reads can be optimized using ReadOnlyTransaction
-                            Uuid subnetId = input.getFixedIps().get(0).getSubnetId();
-                            InstanceIdentifier<Subnetmap> SubnetMapid = InstanceIdentifier.builder(Subnetmaps.class)
-                                    .child(Subnetmap.class, new SubnetmapKey(subnetId))
-                                    .build();
-                            SubnetmapBuilder builder = null;
-                            Uuid vpnId = null;
-                            Router rtr = null;
-                            Uuid routerId = null;
-                            String elanInstanceName = null;
-                            long etag = 0l;
-                            try {
-                                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, SubnetMapid);
-                                if (sn.isPresent()) {
-                                    builder = new SubnetmapBuilder(sn.get());
-                                    vpnId = builder.getVpnId();
-                                    LOG.debug("updating Subnet :existing: ");
-                                    elanInstanceName = sn.get().getNetworkId().getValue();
-                                } else {
-                                    builder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId);
-                                    LOG.debug("updating Subnet :new: ");
-                                }
-
-                            } catch (Exception e) {
-                                LOG.error("Updation of subnetMap failed for node: {}", subnetId.getValue());
-                            }
-                            if (vpnId != null) {
-                                // create vpn-interface on this neutron port
-                                LOG.debug("Adding VPN Interface");
-                                routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId();
-                                if (routerId != null) {
-                                    rtr = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
-                                }
-                            }
-                            InstanceIdentifier<RouterInterfaces> routerInterfacesId = nvpnManager.getRouterInterfacesId(routerId);
-                            Optional<RouterInterfaces> optRouterInterfaces = null;
-                            RouterInterfaces routerInterfaces = null;
-                            try {
-                                optRouterInterfaces = NeutronvpnUtils.read(dataBroker,
-                                        LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
-                                routerInterfaces = optRouterInterfaces.isPresent() ?
-                                        optRouterInterfaces.get() : null;
-
-                            } catch (Exception ex) {
-                                LOG.error("Failed to read Rouoter interface {} from routerID: {}  exception: {}",
-                                        routerInterfacesId, routerId, ex);
-                            }
-                            final RouterInterfaces routerInterfacesF = routerInterfaces;
-
-                            InstanceIdentifier<ElanInstance> elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class)
-                                    .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
-                            Optional<ElanInstance> elanInstance = null;
-                            try {
-                                elanInstance = NeutronvpnUtils.read(dataBroker,
-                                        LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
-                                etag = elanInstance.isPresent() ? elanInstance.get().getElanTag() : null;
-                            } catch (Exception ex) {
-                                LOG.error("Failed to read elan instance {} exception: {}",
-                                        elanInstanceName, ex);
-                            }
-
-                            final long elanTag = etag;
-                            final SubnetmapBuilder sNetMapBuilder = builder;
-                            final Uuid Uuidrouter = routerId;
-                            final Router rtrFinal = rtr;
-                            final Interface inf = createInterface(input);
-                            final String infName = inf.getName();
-                            InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
-                            try {
-                                Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                                        interfaceIdentifier);
-                                if (optionalInf.isPresent()) {
-                                    LOG.error("Interface {} is already present", infName);
-                                    return null;
-                                }
-                            } catch (Exception e) {
-                                LOG.error("failed to create interface {} due to the exception {} ", infName, e.getMessage());
-                            }
-
-                            final Uuid vpnIdFinal = vpnId;
-                            dataStoreCoordinator.enqueueJob("NPORT" + input.getName() + input.getUuid().toString(),
-                                    new Callable<List<ListenableFuture<Void>>>() {
-                                        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-                                        List<ListenableFuture<Void>> futures = new ArrayList<>();
-                                        String elanInstanceName = input.getNetworkId().getValue();
-
-                                        @Override
-                                        public List<ListenableFuture<Void>> call() throws Exception {
-                                            boolean isLockAcquired = false;
-                                            try {
-                                                if(NeutronvpnUtils.lock(lockManager, input.getUuid().getValue())) {
-                                                    if (NeutronvpnUtils.lock(lockManager,
-                                                            input.getFixedIps().get(0).getSubnetId().getValue())) {
-                                                        isLockAcquired = true;
-                                                    } else {
-                                                        LOG.error("Unable to acquire lock for subnet ID {}, belongs to port: {}",
-                                                                input.getFixedIps().get(0).getSubnetId().getValue(),
-                                                                input.getUuid().getValue());
-                                                        NeutronvpnUtils.unlock(lockManager, input.getUuid().getValue());
-                                                    }
-                                                } else {
-                                                    LOG.error("Unable to acquire for port: {}", input.getUuid().getValue());
-                                                }
-                                                LOG.debug("Adding vpn interface {}", infName);
-                                                handleNeutronPortCreated(input, elanTag, sNetMapBuilder, Uuidrouter,
-                                                        rtrFinal, inf, vpnIdFinal, routerInterfacesF, wrTx);
-                                                NeutronvpnUtils.addToPortCache(input);
-                                            } catch (Exception ex) {
-                                                LOG.error("Creation of vpninterface {} failed due to {}", infName, ex);
-                                            } finally {
-                                                if (isLockAcquired) {
-                                                    List<ListenableFuture<Void>> futures = new ArrayList<>();
-                                                    futures.add(wrTx.submit());
-                                                    //Unlocking shall be in reverse way of acquiring locks.
-                                                    NeutronvpnUtils.unlock(lockManager, input.getFixedIps().get(0).getSubnetId().getValue());
-                                                    NeutronvpnUtils.unlock(lockManager, input.getUuid().getValue());
-                                                }
-                                            }
-                                            return futures;
-                                        }
-                                    });
-                            return null;
-                        }
-                    });
+            handleNeutronPortCreated(input);
         }
+        NeutronUtils.createPortStatus(input.getUuid().getValue(), portStatus, dataBroker);
     }
 
     @Override
-    protected void remove(InstanceIdentifier<Port> identifier, final Port input) {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Removing Port : key: " + identifier + ", value=" + input);
-        }
-        final Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, input.getNetworkId());
+    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)) {
-            //FIXME: This should be removed when support for VLAN and GRE network types is added
-            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of " +
-                    "network {}.", input.getName(), 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 {}",
+                    portName, network);
             return;
         }
-        NeutronvpnUtils.removeFromPortCache(input);
+        neutronvpnUtils.removeFromPortCache(input);
+        NeutronUtils.deletePortStatus(input.getUuid().getValue(), dataBroker);
 
-        if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
+        if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
             if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceRemoved(input);
                 /* nothing else to do here */
                 return;
             } else if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())
                     || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
-                elanService.handleKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue(),
-                        NwConstants.DEL_FLOW);
+                elanService.removeKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue());
             }
         }
-        if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
-            final DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-            dataStoreCoordinator.enqueueJob("NPORT"+ input.getKey().toString(),
-                    new Callable<List<ListenableFuture<Void>>>() {
-                        @Override
-                        public List<ListenableFuture<Void>> call() throws Exception {
-                        // Preparation (couple of MDSAL-Reads) for Batching...
-                        String elanInstanceName = input.getNetworkId().getValue();
-                        InstanceIdentifier<ElanInstance>elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class)
-                                .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
-                        Optional<ElanInstance> elanInstance = null;
-                        long etag = 0L;
-                        try {
-                            elanInstance = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
-                            etag = elanInstance.isPresent() ? elanInstance.get().getElanTag() : null;
-
-                        } catch (Exception ex) {
-                            LOG.error("Failed to read elan instance {} exception: {}",
-                                    elanInstanceName, ex);
-                        }
-                        final long elanTag = etag;
-
-                        SubnetmapBuilder builder = null;
-                        Uuid routerId = null;
-                        InstanceIdentifier<Subnetmap> SubnetMapid = InstanceIdentifier.builder(Subnetmaps.class)
-                                .child(Subnetmap.class, new SubnetmapKey(input.getFixedIps().get(0).getSubnetId()))
-                                .build();
-
-                        final Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, SubnetMapid);
-                        if (sn.isPresent()) {
-                            builder = new SubnetmapBuilder(sn.get());
-                            routerId = builder.getRouterId();
-                        } else {
-                            LOG.warn("removing from non-existing subnetmap node: {} ", input.getFixedIps().get(0).getSubnetId());
-                        }
-                        InstanceIdentifier<RouterInterfaces> routerInterfacesId = nvpnManager.getRouterInterfacesId(routerId);
-                        Optional<RouterInterfaces> optRouterInterfaces = null;
-                        RouterInterfaces routerInterfaces = null;
-                        try {
-                            optRouterInterfaces = NeutronvpnUtils.read(dataBroker,
-                                    LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
-                            routerInterfaces = optRouterInterfaces.isPresent() ?
-                                    optRouterInterfaces.get() : null;
-
-                        } catch (Exception ex) {
-                            LOG.info("Failed to read Rouoter interface {} from routerID: {}  exception: {}",
-                                    routerInterfacesId, routerId, ex);
-                        }
-                        final RouterInterfaces routerInterfacesF = routerInterfaces;
-                        final SubnetmapBuilder snbuilder = builder;
-                            // Write/PUT operations.
-                        dataStoreCoordinator.enqueueJob("NPORT"+ input.getKey().toString(),
-                                new Callable<List<ListenableFuture<Void>>>() {
-                                    List<ListenableFuture<Void>> futures = new ArrayList<>();
-                                    WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-                                    @Override
-                                    public List<ListenableFuture<Void>> call() throws Exception {
-                                        boolean isLockAcquired = false;
-                                        try {
-                                            if(NeutronvpnUtils.lock(lockManager, input.getUuid().getValue())) {
-                                                if (NeutronvpnUtils.lock(lockManager,
-                                                        input.getFixedIps().get(0).getSubnetId().getValue())) {
-                                                    isLockAcquired = true;
-                                                } else {
-                                                    LOG.error("Unable to acquire lock for subnet ID {}, belongs to port: {}",
-                                                            input.getFixedIps().get(0).getSubnetId().getValue(),
-                                                            input.getUuid().getValue());
-                                                    NeutronvpnUtils.unlock(lockManager, input.getUuid().getValue());
-                                                }
-                                            } else {
-                                                LOG.error("Unable to acquire for port: {}", input.getUuid().getValue());
-                                            }
-                                            LOG.debug("Lock acquired on interface name {}", input.getUuid().getValue().toString());
-                                            handleNeutronPortDeleted(input, elanTag,  snbuilder, routerInterfacesF, wrTx);
-                                            NeutronvpnUtils.removeFromPortCache(input);
-                                        } catch (Exception e) {
-                                            LOG.error("Received exception during NeutronPortRemove of interface name: {}, exception: {}",
-                                                    input.getUuid().getValue().toString(), e);
-                                        } finally {
-                                            if (isLockAcquired) {
-                                                    futures.add(wrTx.submit());
-                                                //Unlocking shall be in reverse way of acquiring locks.
-                                                NeutronvpnUtils.unlock(lockManager, input.getFixedIps().get(0).getSubnetId().getValue());
-                                                NeutronvpnUtils.unlock(lockManager, input.getUuid().getValue());                                            }
-                                        }
-                                        return futures;
-                                    }
-                                });
-                    return null;
-                }
-            });
+        if (input.getFixedIps() != null) {
+            handleNeutronPortDeleted(input);
         }
     }
 
     @Override
     protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Updating Port : key: " + identifier + ", original value=" + original + ", update value=" +
-                    update);
-        }
-        Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, update.getNetworkId());
+        final String portName = update.getUuid().getValue();
+        LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
+        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 doesn't support vlan/gre network provider type for the port {} which is part of network {}."
-                    + " Skipping the processing of Port update DCN", update.getName(), network);
+            LOG.error("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;
         }
-        /* check if router interface has been updated */
-        if ((update.getDeviceOwner() != null) && (update.getDeviceId() != null)) {
+        neutronvpnUtils.addToPortCache(update);
+
+        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)) {
                 handleRouterInterfaceAdded(update);
-                /* nothing else to do here */
                 return;
             }
-
-        final List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<FixedIps>();
-        final List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<FixedIps>();
-
-        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-        // key here should be based on existing port information, so that earlier operation on port
-        // gets executed before update gets executed.
-        dataStoreCoordinator.enqueueJob("NPORT"+ original.getKey().toString(),
-                new Callable<List<ListenableFuture<Void>>>() {
-                    @Override
-                    public List<ListenableFuture<Void>> call() throws Exception {
-
-                        // Preparation (couple of MDSAL-Reads) for Batching...
-                        String elanInstanceName = update.getNetworkId().getValue();
-                        InstanceIdentifier<ElanInstance>elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class)
-                                .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
-                        Optional<ElanInstance> elanInstance = null;
-                        long etag = 0L;
-                        try {
-                            elanInstance = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId);
-                            etag = elanInstance.isPresent()?elanInstance.get().getElanTag():null;
-                        } catch (Exception ex) {
-                            LOG.error("Failed to read elan instance {} exception: {}",
-                                    elanInstanceName, ex);
-                        }
-                        final long elanTag = etag;
-                        SubnetmapBuilder builder = null;
-                        Uuid routerId = null;
-                        Router rtr = null;
-
-                        InstanceIdentifier<Subnetmap> SubnetMapid = InstanceIdentifier.builder(Subnetmaps.class)
-                                .child(Subnetmap.class, new SubnetmapKey(update.getFixedIps().get(0).getSubnetId()))
-                                .build();
-
-                        final Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, SubnetMapid);
-                        if (sn.isPresent()) {
-                            builder = new SubnetmapBuilder(sn.get());
-                            routerId = builder.getRouterId();
-                            if(routerId!=null){
-                                rtr = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
-                            }
-
-                        } else {
-                            LOG.warn("removing from non-existing subnetmap node: {} ", update.getFixedIps().get(0).getSubnetId());
-                        }
-                        InstanceIdentifier<RouterInterfaces> routerInterfacesId = nvpnManager.getRouterInterfacesId(routerId);
-                        Optional<RouterInterfaces> optRouterInterfaces = null;
-                        RouterInterfaces routerInterfaces = null;
-                        try {
-                            optRouterInterfaces = NeutronvpnUtils.read(dataBroker,
-                                    LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
-                            routerInterfaces = optRouterInterfaces.isPresent() ?
-                                    optRouterInterfaces.get() : null;
-
-                        } catch (Exception ex) {
-                            LOG.error("Failed to read Rouoter interface {} from routerID: {}  exception: {}",
-                                    routerInterfacesId, routerId, ex);
-                        }
-                        final RouterInterfaces routerInterfacesF = routerInterfaces;
-                        final SubnetmapBuilder snbuilder = builder;
-                        final Router rtrFinal = rtr;
-
-                        final Interface inf = updateInterface(original, update);
-                        final String infName = inf.getName();
-                        LOG.debug("Reading OFPort Interface {}", infName);
-                        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
-                        try {
-                            Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                                    interfaceIdentifier);
-                            if (optionalInf.isPresent()) {
-                            } else {
-                                LOG.error("Interface {} doesn't exist", infName);
-                            }
-                        } catch (Exception e) {
-                            LOG.error("failed to update interface {} due to the exception {} ", infName, e.getMessage());
-                        }
-                        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                        // key here should be based on existing port information, so that earlier operation on port
-                        // gets executed before update gets executed.
-                        dataStoreCoordinator.enqueueJob("NPORT" + original.getKey().toString(),
-                                new Callable<List<ListenableFuture<Void>>>() {
-                                    @Override
-                                    public List<ListenableFuture<Void>> call() throws Exception {
-                                        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-                                        List<ListenableFuture<Void>> futures = new ArrayList<>();
-
-                                        /* check if VIF type updated as part of port binding */
-                                        if (NeutronvpnUtils.isPortVifTypeUpdated(original, update)) {
-                                            updateOfPortInterface(original, update, wrTx);
-                                        }
-
-                                        if (!oldIPs.equals(newIPs)) {
-                                            boolean isLockAcquired = false;
-                                            try {
-                                                if(NeutronvpnUtils.lock(lockManager, update.getUuid().getValue())) {
-                                                    if (NeutronvpnUtils.lock(lockManager,
-                                                            update.getFixedIps().get(0).getSubnetId().getValue())) {
-                                                        isLockAcquired = true;
-                                                    } else {
-                                                        LOG.error("Unable to acquire lock for subnet ID {}, belongs to port: {}",
-                                                                update.getFixedIps().get(0).getSubnetId().getValue(),
-                                                                update.getUuid().getValue());
-                                                        NeutronvpnUtils.unlock(lockManager, update.getUuid().getValue());
-                                                    }
-                                                } else {
-                                                    LOG.error("Unable to acquire for port: {}", update.getUuid().getValue());
-                                                }
-                                                LOG.debug("Lock acquired on interface name {}", update.getUuid().getValue());
-
-                                                Iterator<FixedIps> iterator = newIPs.iterator();
-                                                while (iterator.hasNext()) {
-                                                    FixedIps ip = iterator.next();
-                                                    if (oldIPs.remove(ip)) {
-                                                        iterator.remove();
-                                                    }
-                                                }
-
-                                                handleNeutronPortUpdated(original, update, elanTag, snbuilder, rtrFinal,
-                                                        inf, routerInterfacesF, wrTx);
-                                                NeutronvpnUtils.addToPortCache(update);
-                                            } catch (Exception e) {
-                                                LOG.error("Received exception on NeutronPort Update interface name: {}, exception: {}",
-                                                        update.getUuid().getValue().toString(), e);
-                                            } finally {
-                                                if (isLockAcquired) {
-                                                    futures.add(wrTx.submit());
-                                                    NeutronvpnUtils.unlock(lockManager, update.getFixedIps().get(0).getSubnetId().getValue());
-                                                    NeutronvpnUtils.unlock(lockManager, update.getUuid().getValue());                                                  }
-                                            }
-                                        } else {
-                                            futures.add(wrTx.submit());
-                                        }
-                                        return futures;
-                                    }
-                                });
-            return null;
-            }
-        });
-               if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
+            if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
                 handleRouterGatewayUpdated(update);
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
-                elanService.handleKnownL3DmacAddress(update.getMacAddress().getValue(), update.getNetworkId().getValue(),
-                        NwConstants.ADD_FLOW);
+                handleFloatingIpPortUpdated(original, update);
+            }
+        } else {
+            Set<FixedIps> oldIPs = getFixedIpSet(original.getFixedIps());
+            Set<FixedIps> newIPs = getFixedIpSet(update.getFixedIps());
+            if (!oldIPs.equals(newIPs)) {
+                handleNeutronPortUpdated(original, update);
             }
         }
 
-        handlePortSecurityUpdated(original, update);
-
-        // check for QoS updates
-        QosPortExtension updateQos = update.getAugmentation(QosPortExtension.class);
-        QosPortExtension originalQos = original.getAugmentation(QosPortExtension.class);
-        if (originalQos == null && updateQos != null) {
-            // qos policy add
-            NeutronvpnUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
-            NeutronQosUtils.handleNeutronPortQosUpdate(dataBroker, odlInterfaceRpcService,
-                    update, updateQos.getQosPolicyId());
-        } else if (originalQos != null && updateQos != null
-                && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
-            // qos policy update
-            NeutronvpnUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
-            NeutronvpnUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
-            NeutronQosUtils.handleNeutronPortQosUpdate(dataBroker, odlInterfaceRpcService,
-                    update, updateQos.getQosPolicyId());
-        } else if (originalQos != null && updateQos == null) {
-            // qos policy delete
-            NeutronQosUtils.handleNeutronPortQosRemove(dataBroker, odlInterfaceRpcService,
-                    original, originalQos.getQosPolicyId());
-            NeutronvpnUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
+        // check if port security enabled/disabled as part of port update
+        boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(original);
+        boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(update);
+
+        if (origSecurityEnabled || updatedSecurityEnabled) {
+            InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
+            jobCoordinator.enqueueJob("PORT- " + portName, () -> {
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                try {
+                    Optional<Interface> optionalInf =
+                            SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                    interfaceIdentifier);
+                    if (optionalInf.isPresent()) {
+                        InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
+                        InterfaceAcl infAcl = handlePortSecurityUpdated(dataBroker, 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
+                        wrtConfigTxn.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;
+            });
+        }
+    }
+
+    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)) {
+            // 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)
+                    .getSubnetId(), update.getMacAddress().getValue());
+            elanService.addKnownL3DmacAddress(update.getMacAddress().getValue(), update.getNetworkId().getValue());
         }
     }
 
@@ -593,37 +258,51 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if (routerPort.getDeviceId() != null) {
             Uuid routerId = new Uuid(routerPort.getDeviceId());
             Uuid infNetworkId = routerPort.getNetworkId();
-            Uuid existingVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, infNetworkId);
+            Uuid existingVpnId = neutronvpnUtils.getVpnForNetwork(infNetworkId);
 
-            elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
-                    NwConstants.ADD_FLOW);
+            elanService.addKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
             if (existingVpnId == null) {
+                Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
+                if (vpnId == null) {
+                    vpnId = routerId;
+                }
+                List<Subnetmap> subnetMapList = new ArrayList<>();
+                List<FixedIps> portIps = routerPort.getFixedIps();
+                for (FixedIps portIP : portIps) {
+                    // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIP
+                    // and addSubnetToVpn here
+                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+                    Uuid subnetId = portIP.getSubnetId();
+                    nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId,
+                            routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue());
+                    Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
+                    subnetMapList.add(sn);
+                }
+                if (! subnetMapList.isEmpty()) {
+                    nvpnManager.createVpnInterface(vpnId, routerPort, null);
+                }
                 for (FixedIps portIP : routerPort.getFixedIps()) {
-                    if (portIP.getIpAddress().getIpv4Address() != null) {
-                        Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
-                        if (vpnId == null) {
-                            vpnId = routerId;
-                        }
-                        nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId());
-                        String ipValue = portIP.getIpAddress().getIpv4Address().getValue();
-                        nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), routerId,
-                                routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue());
-                        nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
-                        PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
-                        LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}",
-                                portIP.getIpAddress().getIpv4Address(),routerPort.getMacAddress(),
-                                routerPort.getUuid().getValue(), vpnId.getValue());
-                        NeutronvpnUtils.createVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue, routerPort
-                                .getUuid().getValue(), routerPort.getMacAddress().getValue(), true, true, false);
-                    } else {
-                        LOG.info("Skip router port {} with the following address {}",
-                                routerPort.getUuid().getValue(), portIP.getIpAddress().getIpv6Address());
+                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+                    if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(
+                                neutronvpnUtils.getSubnetmap(portIP.getSubnetId()), vpnId)) {
+                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
+                                NeutronvpnUtils.getIpVersionFromString(ipValue), true);
                     }
+                    nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId());
+                    LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}",
+                            ipValue, routerPort.getMacAddress(),
+                            routerPort.getUuid().getValue(), vpnId.getValue());
                 }
+                nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
+                nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
+                createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
+                wrtConfigTxn.submit();
             } else {
-                LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {} already" +
-                        " associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId
-                        .getValue(), existingVpnId.getValue());
+                LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}"
+                    + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
+                    routerId.getValue(), existingVpnId.getValue());
             }
         }
     }
@@ -632,25 +311,46 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if (routerPort.getDeviceId() != null) {
             Uuid routerId = new Uuid(routerPort.getDeviceId());
             Uuid infNetworkId = routerPort.getNetworkId();
-
-            elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
-                    NwConstants.DEL_FLOW);
-            for (FixedIps portIP : routerPort.getFixedIps()) {
-                if (portIP.getIpAddress().getIpv4Address() != null) {
-                    Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
-                    if(vpnId == null) {
-                        vpnId = routerId;
-                    }
-                    nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId());
-                    nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), null,
-                            null, null, null);
-                    nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
-                    String ipValue = portIP.getIpAddress().getIpv4Address().getValue();
-                    NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue);
-                } else {
-                    LOG.info("Skip router port {} with the following address {}",
-                            routerPort.getUuid().getValue(), portIP.getIpAddress().getIpv6Address());
+            elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
+            Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
+            if (vpnId == null) {
+                vpnId = routerId;
+            }
+            /* Remove ping responder for router interfaces
+             *  A router interface reference in a VPN will have to be removed before the host interface references
+             * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
+             *  is not the last entry to be removed for that subnet in the VPN.
+             *  If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
+             *  interface references in the vpn will already have been cleared, which will cause failures in
+             *  cleanup of router interface flows*/
+            nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(), null);
+            // update RouterInterfaces map
+            List<FixedIps> portIps = routerPort.getFixedIps();
+            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());
                 }
+                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());
+                nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), 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);
             }
         }
     }
@@ -658,356 +358,335 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleRouterGatewayUpdated(Port routerGwPort) {
         Uuid routerId = new Uuid(routerGwPort.getDeviceId());
         Uuid networkId = routerGwPort.getNetworkId();
-        elanService.handleKnownL3DmacAddress(routerGwPort.getMacAddress().getValue(), networkId.getValue(),
-                NwConstants.ADD_FLOW);
+        elanService.addKnownL3DmacAddress(routerGwPort.getMacAddress().getValue(), networkId.getValue());
 
-        Router router = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
+        Router router = neutronvpnUtils.getNeutronRouter(routerId);
         if (router == null) {
-            LOG.warn("No router found for router GW port {} router id {}", routerGwPort.getUuid(), routerId.getValue());
+            LOG.warn("No router found for router GW port {} for router {}", routerGwPort.getUuid().getValue(),
+                    routerId.getValue());
             return;
         }
-
         gwMacResolver.sendArpRequestsToExtGateways(router);
-    }
 
-    private Long getVpnIdFromUuid(Uuid vpnId) {
-        long vpn = 1;
-        InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstanceToVpnId.class).
-                child(VpnInstance.class, new VpnInstanceKey(vpnId.getValue())).build();
-        try {
-            Optional<VpnInstance> optional = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                    id);
-            if (optional.isPresent()) {
-                vpn = optional.get().getVpnId();
-            }
-        } catch (Exception e) {
-            LOG.error("Failed to retrieve vpn instance for the Subnet .", e.getMessage());
-        }
-        return vpn;
+        setExternalGwMac(routerGwPort, routerId);
     }
 
-    private void handleNeutronPortCreated(final Port port, final long elantag, final SubnetmapBuilder snetMapBuilder,
-                                          final Uuid routerId, final Router rtr, final Interface inf, final Uuid vpnId,
-                                          final RouterInterfaces routerInterfaces, final WriteTransaction wrTx) {
-
-        if (!NeutronUtils.isPortVnicTypeNormal(port)) {
-            nvpnManager.updateSubnetmapNodeWithPorts(port.getFixedIps().get(0).getSubnetId(), null, port.getUuid(),
-                    snetMapBuilder, wrTx);
-            LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created",
-                    port.getUuid().getValue());
+    private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
+        // During full-sync networking-odl syncs routers before ports. As such,
+        // the MAC of the router's gw port is not available to be set when the
+        // router is written. We catch that here.
+        InstanceIdentifier<Routers> routersId = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
+        Optional<Routers> optionalRouter = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId);
+        if (!optionalRouter.isPresent()) {
             return;
         }
-        LOG.info("Of-port-interface creation");
-        LOG.error("port is getting created using DJC");
-        // Create of-port interface for this neutron port
-        String portInterfaceName = createOfPortInterface(port, inf, wrTx);
-        LOG.debug("Creating ELAN Interface");
-        createElanInterface(port, portInterfaceName, wrTx);
-        LOG.debug("Add port to subnet");
-        // add port to local Subnets DS
-        addPortToSubnets(port, elantag, snetMapBuilder, vpnId, wrTx);
-
-        if (vpnId != null) {
-            // create vpn-interface on this neutron port
-            LOG.debug("Adding VPN Interface");
-            nvpnManager.createVpnInterface(vpnId, port, rtr, wrTx);
-            if(routerId != null) {
-                nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue(), routerInterfaces, wrTx);
-            }
+
+        Routers extRouters = optionalRouter.get();
+        if (extRouters.getExtGwMacAddress() != null) {
+            return;
         }
+
+        RoutersBuilder builder = new RoutersBuilder(extRouters);
+        builder.setExtGwMacAddress(routerGwPort.getMacAddress().getValue());
+        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
     }
 
-    private void handleNeutronPortDeleted(Port port, long elanTag, SubnetmapBuilder snb, RouterInterfaces routerInterfaces, WriteTransaction wrTx ) {
-        if (!NeutronUtils.isPortVnicTypeNormal(port)) {
-            nvpnManager.removePortsFromSubnetmapNode(port.getFixedIps().get(0).getSubnetId(), null, port.getUuid(),
-                    snb, wrTx);
-            LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created",
-                    port.getUuid().getValue());
+    private void handleNeutronPortCreated(final Port port) {
+        final String portName = port.getUuid().getValue();
+        final Uuid portId = port.getUuid();
+        final List<FixedIps> portIpAddrsList = port.getFixedIps();
+        if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
             return;
         }
-        //dissociate fixedIP from floatingIP if associated
-        nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
-        LOG.debug("Remove port from subnet");
-        // remove port from local Subnets DS
-        Uuid vpnId = removePortFromSubnets(port, elanTag, snb, wrTx);
-
-        if (vpnId != null) {
-            // remove vpn-interface for this neutron port
-            LOG.debug("removing VPN Interface");
-            nvpnManager.deleteVpnInterface(vpnId, port, wrTx);
-        }
-        // remove port from local Subnets DS
-        removePortFromSubnets(port, elanTag, snb, wrTx);
-        // 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");
-        deleteOfPortInterface(port, wrTx);
-        if (snb.getVpnId() != null) {
-            // remove vpn-interface for this neutron port
-            LOG.debug("removing VPN Interface");
-            nvpnManager.deleteVpnInterface(vpnId, port, wrTx);
-            Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId();
-            if (routerId != null) {
-                nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, port.getUuid().getValue(),  routerInterfaces, wrTx);
+        jobCoordinator.enqueueJob("PORT- " + portName, () -> {
+            // add direct port to subnetMaps config DS
+            if (!NeutronUtils.isPortVnicTypeNormal(port)) {
+                for (FixedIps ip: portIpAddrsList) {
+                    nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
+                }
+                LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
+                return Collections.emptyList();
             }
-        }
+            return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                LOG.info("Of-port-interface creation for port {}", portName);
+                // Create of-port interface for this neutron port
+                String portInterfaceName = createOfPortInterface(port, tx);
+                LOG.debug("Creating ELAN Interface for port {}", portName);
+                createElanInterface(port, portInterfaceName, tx);
+                Uuid vpnId = null;
+                Set<Uuid> routerIds = new HashSet<>();
+                for (FixedIps ip: portIpAddrsList) {
+                    Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
+                    if (subnetMap != null && 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 != null && subnetMap.getRouterId() != null) {
+                        routerIds.add(subnetMap.getRouterId());
+                    }
+                }
+                if (vpnId != null) {
+                    // create new vpn-interface for neutron port
+                    LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName,
+                            port.getNetworkId().toString());
+                    nvpnManager.createVpnInterface(vpnId, port, tx);
+                    if (!routerIds.isEmpty()) {
+                        for (Uuid routerId : routerIds) {
+                            nvpnManager.addToNeutronRouterInterfacesMap(routerId,port.getUuid().getValue());
+                        }
+                    }
+                }
+            }));
+        });
     }
 
-    private void handleNeutronPortUpdated(Port portoriginal, Port portupdate,
-                                          long elantag, SubnetmapBuilder snbuilder, Router rtr, Interface intf,
-                                          RouterInterfaces routerInterfaces, WriteTransaction wrTx) {
-        if (portoriginal.getFixedIps() == null || portoriginal.getFixedIps().isEmpty()) {
-            handleNeutronPortCreated(portupdate, elantag, snbuilder, snbuilder.getRouterId(), rtr, intf,
-                    snbuilder.getVpnId(), routerInterfaces, wrTx);
-            return;
-        }
-        LOG.debug("Add port to subnet");
-        // add port FixedIP to local Subnets DS
-        Uuid vpnIdup = addPortToSubnets(portupdate, elantag, snbuilder, snbuilder.getVpnId(), wrTx);
-
-        if (vpnIdup != null) {
-            nvpnManager.createVpnInterface(vpnIdup, portupdate, rtr, wrTx);
-            Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnIdup).getRouterId();
-            if(routerId != null) {
-                nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue(), routerInterfaces, wrTx);
+    private void handleNeutronPortDeleted(final Port port) {
+        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)) {
+                for (FixedIps ip: portIpsList) {
+                    // remove direct port from subnetMaps config DS
+                    nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
+                }
+                LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
+                return futures;
             }
-        }
+            Uuid vpnId = null;
+            Set<Uuid> routerIds = new HashSet<>();
+            for (FixedIps ip: portIpsList) {
+                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
+                if (subnetMap != null && 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());
+                    }
+                }
+            }
+            if (vpnId != 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, 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 port FixedIP from local Subnets DS
-        Uuid vpnIdor = removePortFromSubnets(portoriginal, elantag, snbuilder, wrTx);
 
-        if (vpnIdor != null) {
-            nvpnManager.deleteVpnInterface(vpnIdor, portoriginal, wrTx);
-            Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnIdor).getRouterId();
-            if(routerId != null) {
-                nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue(),
-                        routerInterfaces, wrTx);
-            }
-        if(rtr != null) {
-                nvpnManager.removeFromNeutronRouterInterfacesMap(snbuilder.getRouterId(), portoriginal.getUuid().getValue(),
-                        routerInterfaces, wrTx);
+    private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
+        final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
+        final List<FixedIps> portupdateIps = portupdate.getFixedIps();
+        if (portoriginalIps == null || portoriginalIps.isEmpty()) {
+            handleNeutronPortCreated(portupdate);
+            return;
         }
-    }
-}
-    private void handlePortSecurityUpdated(Port portOriginal, Port portUpdated) {
-        Boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(portOriginal);
-        Boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(portUpdated);
-        String interfaceName = portUpdated.getUuid().getValue();
-        Interface portInterface = NeutronvpnUtils.getOfPortInterface(dataBroker, portUpdated);
-        if (portInterface != null) {
-            InterfaceAclBuilder interfaceAclBuilder = null;
-            if (origSecurityEnabled != updatedSecurityEnabled) {
-                interfaceAclBuilder = new InterfaceAclBuilder();
-                interfaceAclBuilder.setPortSecurityEnabled(updatedSecurityEnabled);
-                if (updatedSecurityEnabled) {
-                    // Handle security group enabled
-                    NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, portUpdated);
-                } else {
-                    // Handle security group disabled
-                    interfaceAclBuilder.setSecurityGroups(Lists.newArrayList());
-                    interfaceAclBuilder.setAllowedAddressPairs(Lists.newArrayList());
+
+        if (portupdateIps == null || portupdateIps.isEmpty()) {
+            LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled "
+                      + "during subnet deletion event.", portupdate.getUuid().getValue());
+            return;
+        }
+        jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
+                        .collect(Collectors.toList());
+                final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId)
+                        .collect(Collectors.toList());
+                Uuid oldVpnId = null;
+                Set<Uuid> originalRouterIds = new HashSet<>();
+                for (Uuid snId: originalSnMapsIds) {
+                    if (!updateSnMapsIds.remove(snId)) {
+                        // snId was present in originalSnMapsIds, but not in updateSnMapsIds
+                        Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(),
+                                null);
+                        oldVpnId = subnetMapOld != null ? subnetMapOld.getVpnId() : null;
+                        if (subnetMapOld != null && subnetMapOld.getRouterId() != null) {
+                            originalRouterIds.add(subnetMapOld.getRouterId());
+                        }
+                    }
                 }
-            } else {
-                if (updatedSecurityEnabled) {
-                    // handle SG add/delete delta
-                    InterfaceAcl interfaceAcl = portInterface.getAugmentation(InterfaceAcl.class);
-                    interfaceAclBuilder = new InterfaceAclBuilder(interfaceAcl);
-                    interfaceAclBuilder.setSecurityGroups(
-                            NeutronvpnUtils.getUpdatedSecurityGroups(interfaceAcl.getSecurityGroups(),
-                                    portOriginal.getSecurityGroups(), portUpdated.getSecurityGroups()));
-                    List<AllowedAddressPairs> updatedAddressPairs = NeutronvpnUtils.getUpdatedAllowedAddressPairs(
-                            interfaceAcl.getAllowedAddressPairs(), portOriginal.getAllowedAddressPairs(),
-                            portUpdated.getAllowedAddressPairs());
-                    interfaceAclBuilder.setAllowedAddressPairs(NeutronvpnUtils.getAllowedAddressPairsForFixedIps(
-                            updatedAddressPairs, portOriginal.getMacAddress(), portOriginal.getFixedIps(),
-                            portUpdated.getFixedIps()));
+                Uuid newVpnId = null;
+                Set<Uuid> newRouterIds = new HashSet<>();
+                for (Uuid snId: updateSnMapsIds) {
+                    Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
+                    newVpnId = subnetMapNew != null ? subnetMapNew.getVpnId() : null;
+                    if (subnetMapNew != null && subnetMapNew.getRouterId() != null) {
+                        newRouterIds.add(subnetMapNew.getRouterId());
+                    }
                 }
-            }
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                if (oldVpnId != null) {
+                    LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
+                    if (!originalRouterIds.isEmpty()) {
+                        for (Uuid routerId : originalRouterIds) {
+                            nvpnManager.removeFromNeutronRouterInterfacesMap(routerId,
+                                    portoriginal.getUuid().getValue());
+                        }
+                    }
+                    nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(), wrtConfigTxn);
+                }
+                if (newVpnId != null) {
+                    LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
+                    nvpnManager.createVpnInterface(newVpnId, portupdate, wrtConfigTxn);
+                    if (!newRouterIds.isEmpty()) {
+                        for (Uuid routerId : newRouterIds) {
+                            nvpnManager.addToNeutronRouterInterfacesMap(routerId,portupdate.getUuid().getValue());
+                        }
+                    }
+                }
+            })));
+    }
 
-            if (interfaceAclBuilder != null) {
-                InterfaceBuilder builder = new InterfaceBuilder(portInterface).addAugmentation(InterfaceAcl.class,
-                        interfaceAclBuilder.build());
-                InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(interfaceName);
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, builder.build());
+    private static InterfaceAclBuilder handlePortSecurityUpdated(DataBroker dataBroker, Port portOriginal,
+            Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
+            InterfaceBuilder interfaceBuilder) {
+        InterfaceAclBuilder interfaceAclBuilder = null;
+        if (origSecurityEnabled != updatedSecurityEnabled) {
+            interfaceAclBuilder = new InterfaceAclBuilder();
+            interfaceAclBuilder.setPortSecurityEnabled(updatedSecurityEnabled);
+            if (updatedSecurityEnabled) {
+                // Handle security group enabled
+                NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, portUpdated);
+            } else {
+                // Handle security group disabled
+                interfaceAclBuilder.setSecurityGroups(new ArrayList<>());
+                interfaceAclBuilder.setAllowedAddressPairs(new ArrayList<>());
             }
         } else {
-            LOG.error("Interface {} is not present", interfaceName);
+            if (updatedSecurityEnabled) {
+                // handle SG add/delete delta
+                InterfaceAcl interfaceAcl = interfaceBuilder.getAugmentation(InterfaceAcl.class);
+                interfaceAclBuilder = new InterfaceAclBuilder(interfaceAcl);
+                interfaceAclBuilder.setSecurityGroups(
+                        NeutronvpnUtils.getUpdatedSecurityGroups(interfaceAcl.getSecurityGroups(),
+                                portOriginal.getSecurityGroups(), portUpdated.getSecurityGroups()));
+                List<AllowedAddressPairs> updatedAddressPairs = NeutronvpnUtils.getUpdatedAllowedAddressPairs(
+                        interfaceAcl.getAllowedAddressPairs(), portOriginal.getAllowedAddressPairs(),
+                        portUpdated.getAllowedAddressPairs());
+                interfaceAclBuilder.setAllowedAddressPairs(NeutronvpnUtils.getAllowedAddressPairsForFixedIps(
+                        updatedAddressPairs, portOriginal.getMacAddress(), portOriginal.getFixedIps(),
+                        portUpdated.getFixedIps()));
+            }
         }
+        return interfaceAclBuilder;
     }
 
-    private String createOfPortInterface(Port port, Interface inf, WriteTransaction wrTx) {
+    private String createOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
+        Interface inf = createInterface(port);
         String infName = inf.getName();
 
-        LOG.debug("Creating OFPort Interface {}", infName);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
-        if (wrTx == null) {
-            try {
-                Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                        interfaceIdentifier);
-                if (!optionalInf.isPresent()) {
-                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
-                } else {
-                    LOG.error("Interface {} is already present", infName);
-                }
-            } catch (Exception e) {
-                LOG.error("failed to create interface {} due to the exception {} ", infName, e.getMessage());
+        InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
+        try {
+            Optional<Interface> optionalInf =
+                    SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            interfaceIdentifier);
+            if (!optionalInf.isPresent()) {
+                wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
+            } else {
+                LOG.warn("Interface {} is already present", infName);
             }
-        } else {
-            wrTx.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf, true);
+        } catch (ReadFailedException e) {
+            LOG.error("failed to create interface {}", infName, e);
         }
         return infName;
     }
 
     private Interface createInterface(Port port) {
-        String parentRefName = NeutronvpnUtils.getVifPortName(port);
         String interfaceName = port.getUuid().getValue();
         IfL2vlan.L2vlanMode l2VlanMode = IfL2vlan.L2vlanMode.Trunk;
         InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
         IfL2vlanBuilder ifL2vlanBuilder = new IfL2vlanBuilder();
-
-        Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, port.getNetworkId());
         ifL2vlanBuilder.setL2vlanMode(l2VlanMode);
 
-        if(parentRefName != null) {
-            ParentRefsBuilder parentRefsBuilder = new ParentRefsBuilder().setParentInterface(parentRefName);
-            interfaceBuilder.addAugmentation(ParentRefs.class, parentRefsBuilder.build());
-        }
-
         interfaceBuilder.setEnabled(true).setName(interfaceName).setType(L2vlan.class)
                 .addAugmentation(IfL2vlan.class, ifL2vlanBuilder.build());
 
-        if (NeutronvpnUtils.isPortSecurityEnabled(port)) {
+        if (NeutronvpnUtils.getPortSecurityEnabled(port)) {
             InterfaceAclBuilder interfaceAclBuilder = new InterfaceAclBuilder();
             interfaceAclBuilder.setPortSecurityEnabled(true);
             NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, port);
             interfaceBuilder.addAugmentation(InterfaceAcl.class, interfaceAclBuilder.build());
+            neutronvpnUtils.populateSubnetIpPrefixes(port);
         }
         return interfaceBuilder.build();
     }
 
-    private void deleteOfPortInterface(Port port, WriteTransaction wrTx) {
+    private void deleteOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
         String name = port.getUuid().getValue();
         LOG.debug("Removing OFPort Interface {}", name);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
-        //MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
-        // If interface exists, will delete. No further check is required (TODO) ?
-        wrTx.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
-    }
-
-    private Interface updateInterface(Port original, Port update) {
-        String parentRefName = NeutronvpnUtils.getVifPortName(update);
-        String interfaceName = original.getUuid().getValue();
-        InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
-
-        if(parentRefName != null) {
-            ParentRefsBuilder parentRefsBuilder = new ParentRefsBuilder().setParentInterface(parentRefName);
-            interfaceBuilder.addAugmentation(ParentRefs.class, parentRefsBuilder.build());
+        InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+        try {
+            Optional<Interface> optionalInf =
+                    SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            interfaceIdentifier);
+            if (optionalInf.isPresent()) {
+                wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
+            } else {
+                LOG.warn("deleteOfPortInterface: Interface {} is not present", name);
+            }
+        } catch (ReadFailedException e) {
+            LOG.error("deleteOfPortInterface: Failed to delete interface {}", name, e);
         }
-
-        interfaceBuilder.setName(interfaceName);
-        return interfaceBuilder.build();
     }
 
-    private String updateOfPortInterface(Port original, Port updated, WriteTransaction wrTx) {
-        Interface inf = updateInterface(original, updated);
-        String infName = inf.getName();
-
-        LOG.debug("Updating OFPort Interface {}", infName);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
-        wrTx.merge( LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf, true);
-        return infName;
-    }
-
-    private void createElanInterface(Port port, String name, WriteTransaction tx) {
+    private void createElanInterface(Port port, String name, WriteTransaction wrtConfigTxn) {
         String elanInstanceName = port.getNetworkId().getValue();
-        List<PhysAddress> physAddresses = new ArrayList<>();
-        physAddresses.add(new PhysAddress(port.getMacAddress().getValue()));
+        List<StaticMacEntries> staticMacEntries = NeutronvpnUtils.buildStaticMacEntry(port);
 
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
                 .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
-                .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build();
-        if (tx == null) {
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, elanInterface);
-        } else {
-            tx.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface, true);
-        }
+                .setName(name).setStaticMacEntries(staticMacEntries).setKey(new ElanInterfaceKey(name)).build();
+        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
 
-    // adds port to subnet list and creates vpnInterface
-    private Uuid addPortToSubnets(Port port, long elanTag, SubnetmapBuilder snetMapBuilder, Uuid vpnId, WriteTransaction wrTx) {
-
-        Uuid subnetId = null;
-        String infName = port.getUuid().getValue();
-        Subnetmap subnetmap = null;
-        // find the subnet to which this port is associated
-        FixedIps ip = port.getFixedIps().get(0);
-        String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-            subnetId = ip.getSubnetId();
-        subnetmap = nvpnManager.updateSubnetmapNodeWithPorts(subnetId, port.getUuid(), null, snetMapBuilder, wrTx);
-        if (subnetmap != null) {
-            vpnId = subnetmap.getVpnId();
-        }
-        if(vpnId != null) {
-            checkAndPublishPortAddNotification(subnetmap.getSubnetIp(), subnetId, port.getUuid(), elanTag);
-            LOG.debug("Port added to subnet notification sent");
-        }
-        return vpnId;
-    }
-
-    private Uuid removePortFromSubnets(Port port, long elanTag, SubnetmapBuilder snbuilder, WriteTransaction wrTx) {
-        Uuid subnetId = null;
-        Uuid vpnId = null;
-        Subnetmap subnetmap = null;
-        // find the subnet to which this port is associated
-        FixedIps ip = port.getFixedIps().get(0);
-        String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-        LOG.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS", ipValue);
-        subnetId = ip.getSubnetId();
-        subnetmap = nvpnManager.removePortsFromSubnetmapNode(subnetId, port.getUuid(), null, snbuilder, wrTx);
-        if (subnetmap != null) {
-            vpnId = subnetmap.getVpnId();
-        }
-        if(vpnId != null) {
-            try {
-                checkAndPublishPortRemoveNotification(subnetmap.getSubnetIp(), subnetId, port.getUuid(), elanTag);
-            } catch (Exception e) {
-                LOG.error("Exception occurred during port {} remove notification :{}", port.getUuid().getValue(), e);
-            }
-        }
-        return vpnId;
+    private void deleteElanInterface(String name, WriteTransaction wrtConfigTxn) {
+        InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
+                .class, new ElanInterfaceKey(name)).build();
+        wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, id);
     }
 
-    private void checkAndPublishPortAddNotification(String subnetIp, Uuid subnetId, Uuid portId, Long elanTag){
-        PortAddedToSubnetBuilder builder = new PortAddedToSubnetBuilder();
-        LOG.info("publish notification called");
-
-        builder.setSubnetIp(subnetIp);
-        builder.setSubnetId(subnetId);
-        builder.setPortId(portId);
-        builder.setElanTag(elanTag);
-
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void addToFloatingIpPortInfo(Uuid floatingIpId, Uuid floatingIpPortId, Uuid floatingIpPortSubnetId, String
+                                         floatingIpPortMacAddress) {
+        InstanceIdentifier id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         try {
-            notificationPublishService.putNotification(builder.build());
-        } catch (Exception ex) {
-            LOG.error("Exception while publishing PORT-ADD notification subnetIP: {}: subnetID: {} Port: {} elanTag: {} ex: {}",
-                    subnetIp, subnetId, portId, elanTag, ex);
+            FloatingIpIdToPortMappingBuilder floatingipIdToPortMacMappingBuilder = new
+                FloatingIpIdToPortMappingBuilder().setKey(new FloatingIpIdToPortMappingKey(floatingIpId))
+                .setFloatingIpId(floatingIpId).setFloatingIpPortId(floatingIpPortId)
+                .setFloatingIpPortSubnetId(floatingIpPortSubnetId)
+                .setFloatingIpPortMacAddress(floatingIpPortMacAddress);
+            LOG.debug("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP"
+                + " Port Info Config DS", floatingIpId.getValue(), floatingIpPortId.getValue());
+            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+                floatingipIdToPortMacMappingBuilder.build());
+        } catch (Exception e) {
+            LOG.error("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP"
+                + " Port Info Config DS failed", floatingIpId.getValue(), floatingIpPortId.getValue(), e);
         }
     }
 
-    private void checkAndPublishPortRemoveNotification(String subnetIp, Uuid subnetId, Uuid portId, Long elanTag)
-            throws InterruptedException {
-        PortRemovedFromSubnetBuilder builder = new PortRemovedFromSubnetBuilder();
-
-        LOG.info("publish notification called");
-
-        builder.setPortId(portId);
-        builder.setSubnetIp(subnetIp);
-        builder.setSubnetId(subnetId);
-        builder.setElanTag(elanTag);
-
-        notificationPublishService.putNotification(builder.build());
+    private Set<FixedIps> getFixedIpSet(List<FixedIps> fixedIps) {
+        return fixedIps != null ? new HashSet<>(fixedIps) : Collections.emptySet();
     }
-
 }