Bug 7939 - CSIT Sporadic failures - Flow(s) missing in VPNService suite on
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronvpnManager.java
index 6a5dc5885c878115161b94eff5103e5dc15b9ec8..dae53b2f6d45be84502a91bcf8d71b2cf17ddd31 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,
@@ -8,22 +8,36 @@
 package org.opendaylight.netvirt.neutronvpn;
 
 import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.EventListener;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.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.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
-import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
+import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
+import org.opendaylight.netvirt.neutronvpn.evpn.manager.NeutronEvpnManager;
+import org.opendaylight.netvirt.neutronvpn.evpn.utils.NeutronEvpnUtils;
+import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
+import org.opendaylight.netvirt.vpnmanager.api.VpnHelper;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets;
@@ -40,23 +54,24 @@ import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev14081
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 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.lockmanager.rev160413.LockManagerService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
-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.l3vpn.rev130911.Adjacencies;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.config.rev160806.NeutronvpnConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateRouterInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteEVPNInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteEVPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder;
@@ -64,6 +79,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev15060
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateRouterInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortOutputBuilder;
@@ -71,22 +88,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev15060
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.L3vpnInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpnBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpnBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.SubnetAddedToVpnBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.SubnetDeletedFromVpnBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.SubnetUpdatedInVpnBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstancesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort;
 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.router.interfaces.map.RouterInterfacesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfacesKey;
@@ -105,13 +118,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.A
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.ext.rev150712.NetworkL3Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.OperationalPortStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.Features;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.features.Feature;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.features.FeatureBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.features.FeatureKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
 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.provider.ext.rev150712.NetworkProviderExtension;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
@@ -123,297 +141,330 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, EventListener {
     private static final Logger LOG = LoggerFactory.getLogger(NeutronvpnManager.class);
     private final DataBroker dataBroker;
-    private final LockManagerService lockManager;
     private final NeutronvpnNatManager nvpnNatManager;
     private final NotificationPublishService notificationPublishService;
     private final VpnRpcService vpnRpcService;
     private final NeutronFloatingToFixedIpMappingChangeListener floatingIpMapListener;
-    private final IMdsalApiManager mdsalUtil;
     private final IElanService elanService;
-    Boolean isExternalVpn;
+    private final NeutronvpnConfig neutronvpnConfig;
+    private final IVpnManager vpnManager;
+    private final NeutronEvpnManager neutronEvpnManager;
+    private final NeutronEvpnUtils neutronEvpnUtils;
 
-    /**
-     * @param dataBroker DataBroker reference
-     * @param mdsalManager MDSAL Util API access
-     */
+    @Inject
     public NeutronvpnManager(
-            final DataBroker dataBroker, final IMdsalApiManager mdsalManager,
-            final NotificationPublishService notiPublishService, final NeutronvpnNatManager vpnNatMgr,
-            final LockManagerService lockManager, final VpnRpcService vpnRpcSrv,
-            final IElanService elanService,
-            final NeutronFloatingToFixedIpMappingChangeListener neutronFloatingToFixedIpMappingChangeListener) {
+            final DataBroker dataBroker, final NotificationPublishService notiPublishService,
+            final NeutronvpnNatManager vpnNatMgr, final VpnRpcService vpnRpcSrv, final IElanService elanService,
+            final NeutronFloatingToFixedIpMappingChangeListener neutronFloatingToFixedIpMappingChangeListener,
+            final NeutronvpnConfig neutronvpnConfig, final IVpnManager vpnManager) {
         this.dataBroker = dataBroker;
-        mdsalUtil = mdsalManager;
         nvpnNatManager = vpnNatMgr;
         notificationPublishService = notiPublishService;
         vpnRpcService = vpnRpcSrv;
         this.elanService = elanService;
         floatingIpMapListener = neutronFloatingToFixedIpMappingChangeListener;
-        this.lockManager = lockManager;
+        this.neutronvpnConfig = neutronvpnConfig;
+        this.vpnManager = vpnManager;
+        neutronEvpnManager = new NeutronEvpnManager(dataBroker, this);
+        neutronEvpnUtils = new NeutronEvpnUtils(dataBroker, vpnManager);
+
+        configureFeatures();
     }
 
     @Override
+    @PreDestroy
     public void close() throws Exception {
         LOG.info("{} close", getClass().getSimpleName());
     }
 
-    protected void updateSubnetNodeWithFixedIps(Uuid subnetId, Uuid routerId,
-                                                Uuid routerInterfaceName, String fixedIp,
-                                                String routerIntfMacAddress) {
-        Subnetmap subnetmap = null;
-        SubnetmapBuilder builder = null;
-        boolean isLockAcquired = false;
-        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
-                child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+    private void configureFeatures() {
+        InstanceIdentifier<Feature> iid = InstanceIdentifier.builder(
+                        Neutron.class).child(Features.class).child(
+                        Feature.class, new FeatureKey(OperationalPortStatus.class)).build();
+        Feature feature = new FeatureBuilder().setKey(new FeatureKey(OperationalPortStatus.class)).build();
         try {
-            Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-            if (sn.isPresent()) {
-                builder = new SubnetmapBuilder(sn.get());
-                if (routerId != null) {
-                    builder.setRouterId(routerId);
-                } else {
-                    builder.setRouterId(null);
-                }
-                if (routerInterfaceName != null) {
-                    builder.setRouterInterfaceName(routerInterfaceName);
-                } else {
-                    builder.setRouterInterfaceName(null);
-                }
-                if (routerIntfMacAddress != null) {
-                    builder.setRouterIntfMacAddress(routerIntfMacAddress);
-                } else {
-                    builder.setRouterIntfMacAddress(null);
-                }
-                if (fixedIp != null) {
-                    List<String> fixedIps = builder.getRouterInterfaceFixedIps();
-                    if (fixedIps == null) {
-                        fixedIps = new ArrayList<String>();
-                    }
-                    fixedIps.add(fixedIp);
-                    builder.setRouterInterfaceFixedIps(fixedIps);
-                } else {
-                    builder.setRouterInterfaceFixedIps(null);
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, iid, feature);
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Error configuring feature " + feature, e);
+        }
+    }
+
+    public String getOpenDaylightVniRangesConfig() {
+        return neutronvpnConfig.getOpendaylightVniRanges();
+    }
+
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId,
+                                       NetworkAttributes.NetworkType networkType, long segmentationId) {
+        try {
+            InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                        LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
+                if (sn.isPresent()) {
+                    LOG.error("subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
+                    return;
                 }
-                subnetmap = builder.build();
-                handleExternalSubnetPorts(subnetmap);
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-                LOG.debug("Creating/Updating subnetMap node for FixedIps: {} ", subnetId.getValue());
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+                SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId))
+                        .setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId)
+                        .setNetworkType(networkType).setSegmentationId(segmentationId);
+                LOG.debug("Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                        subnetMapIdentifier, subnetmapBuilder.build());
             }
         } catch (Exception e) {
-            LOG.error("Updation of subnetMap for FixedIps failed for node: {}", subnetId.getValue());
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
-            }
+            LOG.error("Creating subnetmap node failed for subnet {}", subnetId.getValue());
         }
     }
 
-    protected Subnetmap updateSubnetNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, Uuid routerId,
-                                         Uuid vpnId) {
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId) {
         Subnetmap subnetmap = null;
         SubnetmapBuilder builder = null;
-        boolean isLockAcquired = false;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
                 .child(Subnetmap.class, new SubnetmapKey(subnetId))
                 .build();
         try {
-            Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-            LOG.debug("updating Subnet :read: ");
-            if (sn.isPresent()) {
-                builder = new SubnetmapBuilder(sn.get());
-                LOG.debug("updating Subnet :existing: ");
-            } else {
-                builder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId);
-                LOG.debug("updating Subnet :new: ");
-            }
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+                if (sn.isPresent()) {
+                    builder = new SubnetmapBuilder(sn.get());
+                    LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
+                } else {
+                    LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
+                    return null;
+                }
+                if (routerId != null) {
+                    builder.setRouterId(routerId);
+                }
+                if (vpnId != null) {
+                    builder.setVpnId(vpnId);
+                }
 
-            if (subnetIp != null) {
-                builder.setSubnetIp(subnetIp);
-            }
-            if (routerId != null) {
-                builder.setRouterId(routerId);
-            }
-            if (networkId != null) {
-                builder.setNetworkId(networkId);
-            }
-            if (vpnId != null) {
-                builder.setVpnId(vpnId);
-            }
-            if (tenantId != null) {
-                builder.setTenantId(tenantId);
+                subnetmap = builder.build();
+                LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
             }
-
-            subnetmap = builder.build();
-            handleExternalSubnetPorts(subnetmap);
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-            LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
         } catch (Exception e) {
             LOG.error("Updation of subnetMap failed for node: {}", subnetId.getValue());
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
-            }
         }
         return subnetmap;
     }
 
-    protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId, Uuid vpnId, Uuid portId) {
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId,
+                                                Uuid routerInterfacePortId, String fixedIp,
+                                                String routerIntfMacAddress) {
         Subnetmap subnetmap = null;
-        boolean isLockAcquired = false;
-        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
-                .child(Subnetmap.class, new SubnetmapKey(subnetId))
-                .build();
+        SubnetmapBuilder builder = null;
+        InstanceIdentifier<Subnetmap> id =
+            InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
         try {
-            Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-            if (sn.isPresent()) {
-                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
-                if (routerId != null) {
-                    builder.setRouterId(null);
-                }
-                if (networkId != null) {
-                    builder.setNetworkId(null);
-                }
-                if (vpnId != null) {
-                    builder.setVpnId(null);
-                }
-                if (portId != null && builder.getPortList() != null) {
-                    List<Uuid> portList = builder.getPortList();
-                    portList.remove(portId);
-                    builder.setPortList(portList);
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+                if (sn.isPresent()) {
+                    builder = new SubnetmapBuilder(sn.get());
+                    LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+                        subnetId.getValue());
+                } else {
+                    LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
+                        subnetId.getValue());
+                    return;
                 }
-
+                builder.setRouterId(routerId);
+                builder.setRouterInterfacePortId(routerInterfacePortId);
+                builder.setRouterIntfMacAddress(routerIntfMacAddress);
+                builder.setRouterInterfaceFixedIp(fixedIp);
                 subnetmap = builder.build();
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-                LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
-            } else {
-                LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
+                LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
+                    subnetId.getValue());
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
             }
         } catch (Exception e) {
-            LOG.error("Removal from subnetmap failed for node: {}", subnetId.getValue());
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
-            }
+            LOG.error("WithRouterFixedIP: Updation of subnetMap for Router FixedIp failed for node: {}",
+                subnetId.getValue());
         }
-        return subnetmap;
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
         Subnetmap subnetmap = null;
-        boolean isLockAcquired = false;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
                 new SubnetmapKey(subnetId)).build();
         try {
-            Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-            if (sn.isPresent()) {
-                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
-                if (null != portId) {
-                    List<Uuid> portList = builder.getPortList();
-                    if (null == portList) {
-                        portList = new ArrayList<>();
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+                if (sn.isPresent()) {
+                    SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+                    if (null != portId) {
+                        List<Uuid> portList = builder.getPortList();
+                        if (null == portList) {
+                            portList = new ArrayList<>();
+                        }
+                        portList.add(portId);
+                        builder.setPortList(portList);
+                        LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
+                                portId.getValue());
                     }
-                    portList.add(portId);
-                    builder.setPortList(portList);
-                    LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
-                            portId.getValue());
-                }
-                if (null != directPortId) {
-                    List<Uuid> directPortList = builder.getDirectPortList();
-                    if (null == directPortList) {
-                        directPortList = new ArrayList<>();
+                    if (null != directPortId) {
+                        List<Uuid> directPortList = builder.getDirectPortList();
+                        if (null == directPortList) {
+                            directPortList = new ArrayList<>();
+                        }
+                        directPortList.add(directPortId);
+                        builder.setDirectPortList(directPortList);
+                        LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
+                                directPortId.getValue());
                     }
-                    directPortList.add(directPortId);
-                    builder.setDirectPortList(directPortList);
-                    LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
-                            directPortId.getValue());
+                    subnetmap = builder.build();
+                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+                            subnetmap);
+                } else {
+                    LOG.error("Trying to update non-existing subnetmap node {} ", subnetId.getValue());
                 }
-                subnetmap = builder.build();
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
-            } else {
-                LOG.error("Trying to update non-existing subnetmap node {} ", subnetId.getValue());
             }
         } catch (Exception e) {
             LOG.error("Updating port list of a given subnetMap failed for node: {} with exception{}",
                     subnetId.getValue(), e);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
+        }
+        return subnetmap;
+    }
+
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId, Uuid vpnId, Uuid portId) {
+        Subnetmap subnetmap = null;
+        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
+                .child(Subnetmap.class, new SubnetmapKey(subnetId))
+                .build();
+        try {
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+                if (sn.isPresent()) {
+                    SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+                    if (routerId != null) {
+                        builder.setRouterId(null);
+                    }
+                    if (networkId != null) {
+                        builder.setNetworkId(null);
+                    }
+                    if (vpnId != null) {
+                        builder.setVpnId(null);
+                    }
+                    if (portId != null && builder.getPortList() != null) {
+                        List<Uuid> portList = builder.getPortList();
+                        portList.remove(portId);
+                        builder.setPortList(portList);
+                    }
+
+                    subnetmap = builder.build();
+                    LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
+                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+                            subnetmap);
+                } else {
+                    LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
+                }
             }
+        } catch (Exception e) {
+            LOG.error("Removal from subnetmap failed for node: {}", subnetId.getValue());
         }
         return subnetmap;
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
         Subnetmap subnetmap = null;
-        boolean isLockAcquired = false;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
                 new SubnetmapKey(subnetId)).build();
         try {
-            Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-            if (sn.isPresent()) {
-                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
-                if (null != portId && null != builder.getPortList()) {
-                    List<Uuid> portList = builder.getPortList();
-                    portList.remove(portId);
-                    builder.setPortList(portList);
-                    LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
-                            subnetId.getValue());
-                }
-                if (null != directPortId && null != builder.getDirectPortList()) {
-                    List<Uuid> directPortList = builder.getDirectPortList();
-                    directPortList.remove(directPortId);
-                    builder.setDirectPortList(directPortList);
-                    LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId.getValue(),
-                            subnetId.getValue());
+            synchronized (subnetId.getValue().intern()) {
+                Optional<Subnetmap> sn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+                if (sn.isPresent()) {
+                    SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+                    if (null != portId && null != builder.getPortList()) {
+                        List<Uuid> portList = builder.getPortList();
+                        portList.remove(portId);
+                        builder.setPortList(portList);
+                        LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
+                                subnetId.getValue());
+                    }
+                    if (null != directPortId && null != builder.getDirectPortList()) {
+                        List<Uuid> directPortList = builder.getDirectPortList();
+                        directPortList.remove(directPortId);
+                        builder.setDirectPortList(directPortList);
+                        LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
+                                .getValue(), subnetId.getValue());
+                    }
+                    subnetmap = builder.build();
+                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+                            subnetmap);
+                } else {
+                    LOG.error("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
                 }
-                subnetmap = builder.build();
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
-            } else {
-                LOG.error("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
             }
         } catch (Exception e) {
             LOG.error("Removing a port from port list of a subnetmap failed for node: {} with expection {}",
                     subnetId.getValue(), e);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
-            }
         }
         return subnetmap;
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void deleteSubnetMapNode(Uuid subnetId) {
-        boolean isLockAcquired = false;
         InstanceIdentifier<Subnetmap> subnetMapIdentifier =
                 InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,new SubnetmapKey(subnetId)).build();
         LOG.debug("removing subnetMap node: {} ", subnetId.getValue());
         try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
-            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
+            synchronized (subnetId.getValue().intern()) {
+                SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                        subnetMapIdentifier);
+            }
         } catch (Exception e) {
             LOG.error("Delete subnetMap node failed for subnet : {} ", subnetId.getValue());
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
-            }
         }
     }
 
-    private void updateVpnInstanceNode(String vpnName, List<String> rd, List<String> irt, List<String> ert) {
+    public void updateVpnInstanceWithRDs(String vpnInstanceId, final List<String> rds) {
+        InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
+            .child(VpnInstance.class, new VpnInstanceKey(vpnInstanceId)).build();
+        Optional<VpnInstance> vpnInstanceConfig =
+            NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+        if (!vpnInstanceConfig.isPresent()) {
+            LOG.debug("No VpnInstance present under config vpnInstance:{}", vpnInstanceId);
+            return;
+        }
+        VpnInstance vpnInstance = vpnInstanceConfig.get();
+        VpnInstanceBuilder updateVpnInstanceBuilder = new VpnInstanceBuilder(vpnInstance);
+        Ipv4FamilyBuilder ipv4FamilyBuilder = new Ipv4FamilyBuilder(vpnInstance.getIpv4Family());
+        updateVpnInstanceBuilder.setIpv4Family(ipv4FamilyBuilder.setRouteDistinguisher(rds).build());
+        LOG.debug("Updating Config vpn-instance: {} with the list of RDs: {}", vpnInstanceId,rds);
+        try {
+            SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier,
+                    updateVpnInstanceBuilder.build());
+        } catch (TransactionCommitFailedException ex) {
+            LOG.warn("Error configuring feature ", ex);
+        }
+    }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void updateVpnInstanceNode(String vpnName, List<String> rd, List<String> irt, List<String> ert,
+                                       VpnInstance.Type type, long l3vni) {
         VpnInstanceBuilder builder = null;
         List<VpnTarget> vpnTargetList = new ArrayList<>();
         boolean isLockAcquired = false;
-        InstanceIdentifier<VpnInstance> vpnIdentifier =
-                InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class,new VpnInstanceKey(vpnName)).build();
+        InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
+            .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
         try {
             Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
                     vpnIdentifier);
@@ -422,7 +473,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 builder = new VpnInstanceBuilder(optionalVpn.get());
                 LOG.debug("updating existing vpninstance node");
             } else {
-                builder = new VpnInstanceBuilder().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName);
+                builder = new VpnInstanceBuilder().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName)
+                        .setType(type).setL3vni(l3vni);
             }
             if (irt != null && !irt.isEmpty()) {
                 if (ert != null && !ert.isEmpty()) {
@@ -460,22 +512,24 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             Ipv4FamilyBuilder ipv4vpnBuilder = new Ipv4FamilyBuilder().setVpnTargets(vpnTargets);
 
             if (rd != null && !rd.isEmpty()) {
-                ipv4vpnBuilder.setRouteDistinguisher(rd.get(0));
+                ipv4vpnBuilder.setRouteDistinguisher(rd);
             }
 
             VpnInstance newVpn = builder.setIpv4Family(ipv4vpnBuilder.build()).build();
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnName);
+            isLockAcquired = NeutronvpnUtils.lock(vpnName);
             LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
         } catch (Exception e) {
             LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
         } finally {
             if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, vpnName);
+                NeutronvpnUtils.unlock(vpnName);
             }
         }
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void deleteVpnMapsNode(Uuid vpnid) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -483,17 +537,19 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 .build();
         LOG.debug("removing vpnMaps node: {} ", vpnid.getValue());
         try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnid.getValue());
+            isLockAcquired = NeutronvpnUtils.lock(vpnid.getValue());
             MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
         } catch (Exception e) {
             LOG.error("Delete vpnMaps node failed for vpn : {} ", vpnid.getValue());
         } finally {
             if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, vpnid.getValue());
+                NeutronvpnUtils.unlock(vpnid.getValue());
             }
         }
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
         VpnMapBuilder builder;
         boolean isLockAcquired = false;
@@ -527,7 +583,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 builder.setNetworkIds(nwList);
             }
 
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnId.getValue());
+            isLockAcquired = NeutronvpnUtils.lock(vpnId.getValue());
             LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
             LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
@@ -535,11 +591,13 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
         } finally {
             if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, vpnId.getValue());
+                NeutronvpnUtils.unlock(vpnId.getValue());
             }
         }
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -554,14 +612,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
                     try {
                         // remove entire node in case of internal VPN
-                        isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnId.getValue());
+                        isLockAcquired = NeutronvpnUtils.lock(vpnId.getValue());
                         LOG.debug("removing vpnMaps node: {} ", vpnId);
                         MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
                     } catch (Exception e) {
                         LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
                     } finally {
                         if (isLockAcquired) {
-                            NeutronvpnUtils.unlock(lockManager, vpnId.getValue());
+                            NeutronvpnUtils.unlock(vpnId.getValue());
                         }
                     }
                     return;
@@ -582,7 +640,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             }
 
             try {
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnId.getValue());
+                isLockAcquired = NeutronvpnUtils.lock(vpnId.getValue());
                 LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
                 MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier,
                         vpnMapBuilder.build());
@@ -590,7 +648,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
             } finally {
                 if (isLockAcquired) {
-                    NeutronvpnUtils.unlock(lockManager, vpnId.getValue());
+                    NeutronvpnUtils.unlock(vpnId.getValue());
                 }
             }
         } else {
@@ -599,6 +657,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void deleteVpnInstance(Uuid vpnId) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
@@ -606,135 +666,145 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         new VpnInstanceKey(vpnId.getValue()))
                 .build();
         try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, vpnId.getValue());
+            isLockAcquired = NeutronvpnUtils.lock(vpnId.getValue());
             LOG.debug("Deleting vpnInstance {}", vpnId.getValue());
             MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
         } catch (Exception e) {
             LOG.error("Deletion of VPNInstance node failed for VPN {}", vpnId.getValue());
         } finally {
             if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, vpnId.getValue());
+                NeutronvpnUtils.unlock(vpnId.getValue());
             }
         }
     }
 
-    protected void createVpnInterface(Uuid vpnId, Port port) {
-        boolean isLockAcquired = false;
-        if (vpnId == null || port == null) {
-            return;
-        }
+    protected void createVpnInterface(Uuid vpnId, Uuid routerId, Port port,
+                                      WriteTransaction wrtConfigTxn) {
         String infName = port.getUuid().getValue();
         List<Adjacency> adjList = new ArrayList<>();
-        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
-
-        // find router associated to vpn
-        Uuid routerId = NeutronvpnUtils.getRouterforVpn(dataBroker, vpnId);
+        Boolean isRouterInterface = false;
+        if (port.getDeviceOwner() != null) {
+            isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF);
+        }
+        LOG.trace("createVpnInterface - isRouterInterface:{}", isRouterInterface);
         Router rtr = null;
         if (routerId != null) {
             rtr = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
         }
-        // find all subnets to which this port is associated
         List<FixedIps> ips = port.getFixedIps();
         // create adjacency list
         for (FixedIps ip : ips) {
             // create vm adjacency
-            StringBuilder IpPrefixBuild = new StringBuilder(ip.getIpAddress().getIpv4Address().getValue());
-            String IpPrefix = IpPrefixBuild.append("/32").toString();
-            Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(IpPrefix)).setIpAddress(IpPrefix)
-                    .setMacAddress(port.getMacAddress().getValue()).build();
+            String ipValue = String.valueOf(ip.getIpAddress().getValue());
+            String ipPrefix = (ip.getIpAddress().getIpv4Address() != null) ? ipValue + "/32" : ipValue + "/128";
+            Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix)
+                    .setMacAddress(port.getMacAddress().getValue()).setPrimaryAdjacency(true)
+                    .setSubnetId(ip.getSubnetId()).build();
             adjList.add(vmAdj);
             // create extra route adjacency
             if (rtr != null && rtr.getRoutes() != null) {
                 List<Routes> routeList = rtr.getRoutes();
-                List<Adjacency> erAdjList = addAdjacencyforExtraRoute(vpnId, routeList);
+                List<Adjacency> erAdjList = getAdjacencyforExtraRoute(vpnId, routeList, ipValue);
                 if (erAdjList != null && !erAdjList.isEmpty()) {
                     adjList.addAll(erAdjList);
                 }
             }
-            String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-            createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), false,
-                    true, false);
+            NeutronvpnUtils.createVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue, infName, port
+                            .getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
         }
         // create vpn-interface on this neutron port
         Adjacencies adjs = new AdjacenciesBuilder().setAdjacency(adjList).build();
-        VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
-                .setName(infName)
-                .setVpnInstanceName(vpnId.getValue())
-                .addAugmentation(Adjacencies.class, adjs);
-        VpnInterface vpnIf = vpnb.build();
-
-        try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-            LOG.debug("Creating vpn interface {}", vpnIf);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
-        } catch (Exception ex) {
-            LOG.error("Creation of vpninterface {} failed due to {}", infName, ex);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, infName);
-            }
+        writeVpnInterfaceToDs(vpnId, infName, adjs, isRouterInterface, wrtConfigTxn);
+        if (routerId != null) {
+            addToNeutronRouterInterfacesMap(routerId, infName);
         }
     }
 
-    protected void deleteVpnInterface(Uuid vpnId, Port port) {
-
-        if (port != null) {
-            boolean isLockAcquired = false;
-            String infName = port.getUuid().getValue();
-            InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
-
-            try {
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-                LOG.debug("Deleting vpn interface {}", infName);
-                MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void deleteVpnInterface(Uuid vpnId, Uuid routerId, Port port, WriteTransaction wrtConfigTxn) {
+        Boolean wrtConfigTxnPresent = true;
+        if (wrtConfigTxn == null) {
+            wrtConfigTxnPresent = false;
+            wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+        }
+        String infName = port.getUuid().getValue();
+        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
+        try {
+            LOG.debug("Deleting vpn interface {}", infName);
+            wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
 
-                List<FixedIps> ips = port.getFixedIps();
-                for (FixedIps ip : ips) {
-                    String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-                    removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue);
-                }
-            } catch (Exception ex) {
-                LOG.error("Deletion of vpninterface {} failed due to {}", infName, ex);
-            } finally {
-                if (isLockAcquired) {
-                    NeutronvpnUtils.unlock(lockManager, infName);
-                }
+            List<FixedIps> ips = port.getFixedIps();
+            for (FixedIps ip : ips) {
+                String ipValue = String.valueOf(ip.getIpAddress().getValue());
+                NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnId.getValue(),
+                        ipValue, wrtConfigTxn);
             }
+        } catch (Exception ex) {
+            LOG.error("Deletion of vpninterface {} failed due to {}", infName, ex);
+        }
+        if (routerId != null) {
+            removeFromNeutronRouterInterfacesMap(routerId, infName);
+        }
+        if (!wrtConfigTxnPresent) {
+            wrtConfigTxn.submit();
         }
     }
 
-    protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port) {
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated,
+                                      boolean isSubnetIp, WriteTransaction writeConfigTxn) {
         if (vpnId == null || port == null) {
             return;
         }
         boolean isLockAcquired = false;
         String infName = port.getUuid().getValue();
         InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
+
         try {
-            Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(dataBroker,
-                    LogicalDatastoreType.CONFIGURATION,
-                    vpnIfIdentifier);
+            isLockAcquired = NeutronvpnUtils.lock(infName);
+            Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
+                    .CONFIGURATION, vpnIfIdentifier);
             if (optionalVpnInterface.isPresent()) {
-                VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
-                VpnInterface vpnIf = vpnIfBuilder.setVpnInstanceName(vpnId.getValue()).build();
-                isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-                LOG.debug("Updating vpn interface {}", vpnIf);
-                MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
-
+                VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get())
+                        .setVpnInstanceName(vpnId.getValue());
+                LOG.debug("Updating vpn interface {}", infName);
+                if (!isBeingAssociated) {
+                    Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
+                    List<Adjacency> adjacencyList = (adjs != null) ? adjs.getAdjacency() : new ArrayList<>();
+                    Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
+                    while (adjacencyIter.hasNext()) {
+                        Adjacency adjacency = adjacencyIter.next();
+                        String mipToQuery = adjacency.getIpAddress().split("/")[0];
+                        InstanceIdentifier<LearntVpnVipToPort> id =
+                            NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
+                        Optional<LearntVpnVipToPort> optionalVpnVipToPort =
+                            NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+                        if (optionalVpnVipToPort.isPresent()) {
+                            LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {} "
+                                + "from VPN " + "{}", infName, vpnId, oldVpnId);
+                            adjacencyIter.remove();
+                            NeutronvpnUtils.removeLearntVpnVipToPort(dataBroker, oldVpnId.getValue(), mipToQuery);
+                            LOG.trace("Entry for fixedIP {} for port {} on VPN removed from "
+                                + "VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
+                        }
+                    }
+                    Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
+                    vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
+                }
                 List<FixedIps> ips = port.getFixedIps();
                 for (FixedIps ip : ips) {
-                    String ipValue = ip.getIpAddress().getIpv4Address().getValue();
+                    String ipValue = String.valueOf(ip.getIpAddress().getValue());
                     if (oldVpnId != null) {
-                        InstanceIdentifier<VpnPortipToPort> id = NeutronvpnUtils.buildVpnPortipToPortIdentifier
-                                (oldVpnId.getValue(), ipValue);
-                        Optional<VpnPortipToPort> optionalVpnPort = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-                        if (optionalVpnPort.isPresent()) {
-                            removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue);
-                        }
+                        NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, oldVpnId.getValue(),
+                                ipValue, writeConfigTxn);
                     }
-                    createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), false,
-                            true, false);
+                    NeutronvpnUtils.createVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue, infName, port
+                            .getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
                 }
+                writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
+                        .build());
             } else {
                 LOG.error("VPN Interface {} not found", infName);
             }
@@ -742,50 +812,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             LOG.error("Updation of vpninterface {} failed due to {}", infName, ex);
         } finally {
             if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, infName);
-            }
-        }
-    }
-
-
-    protected void createVpnInterface(Uuid vpnId, String infName) {
-        if (vpnId == null || infName == null) {
-            return;
-        }
-
-        boolean isLockAcquired = false;
-        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
-        VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
-                .setName(infName).setVpnInstanceName(vpnId.getValue()).build();
-        try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-            LOG.debug("Creating vpn interface {}", vpnIf);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
-        } catch (Exception ex) {
-            LOG.error("Creation of vpninterface {} failed due to {}", infName, ex);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, infName);
-            }
-        }
-    }
-
-    protected void deleteVpnInterface(String vpnName, String infName) {
-        if (vpnName == null || infName == null) {
-            return;
-        }
-
-        boolean isLockAcquired = false;
-        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
-        try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-            LOG.debug("Deleting vpn interface {}", infName);
-            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
-        } catch (Exception ex) {
-            LOG.error("Deletion of vpninterface {} failed due to {}", infName, ex);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, infName);
+                NeutronvpnUtils.unlock(infName);
             }
         }
     }
@@ -794,7 +821,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                     List<String> ert, Uuid router, List<Uuid> networks) {
 
         // Update VPN Instance node
-        updateVpnInstanceNode(vpn.getValue(), rd, irt, ert);
+        updateVpnInstanceNode(vpn.getValue(), rd, irt, ert, VpnInstance.Type.L3, 0 /*l3vni*/);
 
         // Update local vpn-subnet DS
         updateVpnMaps(vpn, name, router, tenant, networks);
@@ -802,26 +829,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         if (router != null) {
             Uuid existingVpn = NeutronvpnUtils.getVpnForRouter(dataBroker, router, true);
             if (existingVpn != null) {
-                List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(dataBroker, router);
-                if (routerSubnets != null) {
-                    // Update the router interfaces alone and exit
-                    for (Uuid subnetId : routerSubnets) {
-                        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
-                                child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
-                        Optional<Subnetmap> snMap = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-                        if (snMap.isPresent()) {
-                            Subnetmap sn = snMap.get();
-                            List<Uuid> portList = sn.getPortList();
-                            if (portList != null) {
-                                for (Uuid port : sn.getPortList()) {
-                                    addToNeutronRouterInterfacesMap(router, port.getValue());
-                                }
-                            }
-                        }
-                    }
-                }
-                LOG.info("Creation of Internal L3VPN skipped for VPN {} due to router {} already associated to " +
-                        "external VPN {}", vpn.getValue(), router.getValue(), existingVpn.getValue());
+                // use case when a cluster is rebooted and router add DCN is received, triggering #createL3InternalVpn
+
+                // if before reboot, router was already associated to VPN, should not proceed associating router to
+                // internal VPN. Adding to RouterInterfacesMap is also not needed since it's a config DS and will be
+                // preserved upon reboot.
+                // For a non-reboot case #associateRouterToInternalVPN already takes care of adding to
+                // RouterInterfacesMap via #createVPNInterface call.
+                LOG.info("Associating router to Internal VPN skipped for VPN {} due to router {} already associated "
+                    + "to external VPN {}", vpn.getValue(), router.getValue(), existingVpn.getValue());
                 return;
             }
             associateRouterToInternalVpn(vpn, router);
@@ -830,7 +846,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
     /**
      * Performs the creation of a Neutron L3VPN, associating the new VPN to the
-     * specified Neutron Networks and Routers
+     * specified Neutron Networks and Routers.
      *
      * @param vpn Uuid of the VPN tp be created
      * @param name Representative name of the new VPN
@@ -840,12 +856,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
      * @param ert A list of Export Route Targets
      * @param router UUID of the neutron router the VPN may be associated to
      * @param networks UUID of the neutron network the VPN may be associated to
+     * @param type Type of the VPN Instance
+     * @param l3vni L3VNI for the VPN Instance using VxLAN as the underlay
+     * @throws Exception if association of L3VPN failed
      */
-    public void createL3Vpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert,
-                            Uuid router, List<Uuid> networks) throws Exception {
+    public void createVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert,
+                            Uuid router, List<Uuid> networks, VpnInstance.Type type, long l3vni) throws Exception {
 
         // Update VPN Instance node
-        updateVpnInstanceNode(vpn.getValue(), rd, irt, ert);
+        updateVpnInstanceNode(vpn.getValue(), rd, irt, ert, type, l3vni);
 
         // Please note that router and networks will be filled into VPNMaps
         // by subsequent calls here to associateRouterToVpn and
@@ -858,7 +877,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         if (networks != null) {
             List<String> failStrings = associateNetworksToVpn(vpn, networks);
             if (failStrings != null &&  !failStrings.isEmpty()) {
-                LOG.error("L3VPN {} association to networks failed with error message {}. ",
+                LOG.error("VPN {} association to networks failed with error message {}. ",
                         vpn.getValue(), failStrings.get(0));
                 throw new Exception(failStrings.get(0));
             }
@@ -866,12 +885,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     /**
-     * It handles the invocations to the createL3VPN RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#createL3VPN
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNInput)
+     * It handles the invocations to the createVPN RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<CreateL3VPNOutput>> createL3VPN(CreateL3VPNInput input) {
 
         CreateL3VPNOutputBuilder opBuilder = new CreateL3VPNOutputBuilder();
@@ -884,6 +902,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         for (L3vpn vpn : vpns) {
             RpcError error = null;
             String msg;
+            if (NeutronvpnUtils.doesVpnExist(dataBroker, vpn.getId())) {
+                msg = String.format("Creation of L3VPN failed for VPN %s due to VPN with the same ID already present",
+                                vpn.getId().getValue());
+                LOG.warn(msg);
+                error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
+                errorList.add(error);
+                warningcount++;
+                continue;
+            }
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
                 msg = String.format("Creation of L3VPN failed for VPN %s due to absence of RD/iRT/eRT input",
                         vpn.getId().getValue());
@@ -893,9 +920,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 warningcount++;
                 continue;
             }
-            if (vpn.getRouteDistinguisher().size() > 1) {
-                msg = String.format("Creation of L3VPN failed for VPN %s due to multiple RD input %s",
-                        vpn.getId().getValue(), vpn.getRouteDistinguisher());
+            VpnInstance.Type vpnInstanceType = VpnInstance.Type.L3;
+            long l3vni = 0;
+            if (vpn.getL3vni() != null) {
+                l3vni = vpn.getL3vni();
+            }
+
+            List<String> existingRDs = NeutronvpnUtils.getExistingRDs(dataBroker);
+            if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
+                msg = String.format("Creation of L3VPN failed for VPN %s as another VPN with the same RD %s "
+                    + "is already configured",
+                    vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0));
                 LOG.warn(msg);
                 error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
                 errorList.add(error);
@@ -950,10 +985,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
             }
             try {
-                createL3Vpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(),
-                        vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds());
+                createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(),
+                        vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds(),
+                        vpnInstanceType, l3vni);
             } catch (Exception ex) {
-                msg = String.format("Creation of L3VPN failed for VPN %s", vpn.getId().getValue());
+                msg = String.format("Creation of VPN failed for VPN %s", vpn.getId().getValue());
                 LOG.error(msg, ex);
                 error = RpcResultBuilder.newError(ErrorType.APPLICATION, msg, ex.getMessage());
                 errorList.add(error);
@@ -963,7 +999,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         // if at least one succeeds; result is success
         // if none succeeds; result is failure
         if (failurecount + warningcount == vpns.size()) {
-            result.set(RpcResultBuilder.<CreateL3VPNOutput> failed().withRpcErrors(errorList).build());
+            result.set(RpcResultBuilder.<CreateL3VPNOutput>failed().withRpcErrors(errorList).build());
         } else {
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
@@ -976,18 +1012,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 errorResponseList.add("Operation successful with no errors");
             }
             opBuilder.setResponse(errorResponseList);
-            result.set(RpcResultBuilder.<CreateL3VPNOutput> success().withResult(opBuilder.build()).build());
+            result.set(RpcResultBuilder.<CreateL3VPNOutput>success().withResult(opBuilder.build()).build());
         }
         return result;
     }
 
     /**
-     * It handles the invocations to the neutronvpn:getL3VPN RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#getL3VPN
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNInput)
+     * It handles the invocations to the neutronvpn:getL3VPN RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<GetL3VPNOutput>> getL3VPN(GetL3VPNInput input) {
 
         GetL3VPNOutputBuilder opBuilder = new GetL3VPNOutputBuilder();
@@ -1000,32 +1035,31 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 // get all vpns
                 InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class)
                         .build();
-                Optional<VpnInstances> optionalVpns = NeutronvpnUtils.read(dataBroker,
-                        LogicalDatastoreType.CONFIGURATION,
-                        vpnsIdentifier);
-                if (optionalVpns.isPresent() && optionalVpns.get().getVpnInstance() != null) {
+                Optional<VpnInstances> optionalVpns = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
+                        .CONFIGURATION, vpnsIdentifier);
+                if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
                     for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
-                        // eliminating internal VPNs from getL3VPN output
+                        // eliminating implicitly created (router and VLAN provider external network specific) VPNs
+                        // from getL3VPN output
                         if (vpn.getIpv4Family().getRouteDistinguisher() != null) {
                             vpns.add(vpn);
                         }
                     }
                 } else {
                     // No VPN present
-                    result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL, "", "No VPN " +
-                            "is present").build());
+                    result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
                     return result;
                 }
             } else {
                 String name = inputVpnId.getValue();
                 InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
-                        .child(VpnInstance.class,
-                                new VpnInstanceKey(name))
-                        .build();
+                        .child(VpnInstance.class, new VpnInstanceKey(name)).build();
                 // read VpnInstance Info
                 Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
                         vpnIdentifier);
-                if (optionalVpn.isPresent()) {
+                // eliminating implicitly created (router or VLAN provider external network specific) VPN from
+                // getL3VPN output
+                if (optionalVpn.isPresent() && optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null) {
                     vpns.add(optionalVpn.get());
                 } else {
                     String message = String.format("GetL3VPN failed because VPN %s is not present", name);
@@ -1038,11 +1072,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             for (VpnInstance vpnInstance : vpns) {
                 Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
                 // create VpnMaps id
-                InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap
-                        .class, new VpnMapKey(vpnId)).build();
                 L3vpnInstancesBuilder l3vpn = new L3vpnInstancesBuilder();
 
-                List<String> rd = Arrays.asList(vpnInstance.getIpv4Family().getRouteDistinguisher().split(","));
+                List<String> rd = vpnInstance.getIpv4Family().getRouteDistinguisher();
                 List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
 
                 List<String> ertList = new ArrayList<>();
@@ -1062,6 +1094,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
 
                 l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
+                if (vpnInstance.getL3vni() != null) {
+                    l3vpn.setL3vni(vpnInstance.getL3vni());
+                }
+                InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap
+                        .class, new VpnMapKey(vpnId)).build();
                 Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
                         vpnMapIdentifier);
                 if (optionalVpnMap.isPresent()) {
@@ -1073,23 +1110,22 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             }
 
             opBuilder.setL3vpnInstances(l3vpnList);
-            result.set(RpcResultBuilder.<GetL3VPNOutput> success().withResult(opBuilder.build()).build());
+            result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
 
         } catch (Exception ex) {
-            String message = String.format("GetL3VPN failed due to %s", ex.getMessage());
+            String message = String.format("GetVPN failed due to %s", ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<GetL3VPNOutput> failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, message).build());
         }
         return result;
     }
 
     /**
-     * It handles the invocations to the neutronvpn:deleteL3VPN RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#deleteL3VPN
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNInput)
+     * It handles the invocations to the neutronvpn:deleteL3VPN RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<DeleteL3VPNOutput>> deleteL3VPN(DeleteL3VPNInput input) {
 
         DeleteL3VPNOutputBuilder opBuilder = new DeleteL3VPNOutputBuilder();
@@ -1104,11 +1140,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             String msg;
             try {
                 InstanceIdentifier<VpnInstance> vpnIdentifier =
-                        InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey
-                                (vpn.getValue())).build();
-                Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+                        InstanceIdentifier.builder(VpnInstances.class)
+                            .child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
+                Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
+                        .CONFIGURATION, vpnIdentifier);
                 if (optionalVpn.isPresent()) {
-                    removeL3Vpn(vpn);
+                    removeVpn(vpn);
                 } else {
                     msg = String.format("VPN with vpnid: %s does not exist", vpn.getValue());
                     LOG.warn(msg);
@@ -1127,7 +1164,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         // if at least one succeeds; result is success
         // if none succeeds; result is failure
         if (failurecount + warningcount == vpns.size()) {
-            result.set(RpcResultBuilder.<DeleteL3VPNOutput> failed().withRpcErrors(errorList).build());
+            result.set(RpcResultBuilder.<DeleteL3VPNOutput>failed().withRpcErrors(errorList).build());
         } else {
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
@@ -1140,154 +1177,144 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 errorResponseList.add("Operation successful with no errors");
             }
             opBuilder.setResponse(errorResponseList);
-            result.set(RpcResultBuilder.<DeleteL3VPNOutput> success().withResult(opBuilder.build()).build());
+            result.set(RpcResultBuilder.<DeleteL3VPNOutput>success().withResult(opBuilder.build()).build());
         }
         return result;
     }
 
-    protected void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
+    public void createVpnInstanceForSubnet(Uuid subnetId) {
+        LOG.debug("Creating/Updating L3 internalVPN for subnetID {} ", subnetId);
+        createL3InternalVpn(subnetId, subnetId.getValue(), null, null, null, null, null, null);
+    }
+
+    public void removeVpnInstanceForSubnet(Uuid subnetId) {
+        LOG.debug("Removing vpn-instance for subnetID {} ", subnetId);
+        removeVpn(subnetId);
+    }
+
+    protected void addSubnetToVpn(final Uuid vpnId, Uuid subnet) {
         LOG.debug("Adding subnet {} to vpn {}", subnet.getValue(), vpnId.getValue());
-        Subnetmap sn = updateSubnetNode(subnet, null, null, null, null, vpnId);
-        boolean isLockAcquired = false;
-        String lockName = vpnId.getValue() + subnet.getValue();
-        String elanInstanceName = sn.getNetworkId().getValue();
-        InstanceIdentifier<ElanInstance> elanIdentifierId =
-                InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class,
-                        new ElanInstanceKey(elanInstanceName)).build();
-        Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                elanIdentifierId);
-        long elanTag = elanInstance.get().getElanTag();
-        Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId();
-        if (vpnId.equals(routerId)) {
-            isExternalVpn = false;
-        } else {
-            isExternalVpn = true;
+        Subnetmap sn = updateSubnetNode(subnet, null, vpnId);
+        if (sn == null) {
+            LOG.error("subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId.getValue());
+            return;
         }
-        try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
-            checkAndPublishSubnetAddNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isExternalVpn, elanTag);
-            LOG.debug("Subnet added to Vpn notification sent");
-        } catch (Exception e) {
-            LOG.error("Subnet added to Vpn notification failed", e);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, lockName);
-            }
+        VpnMap vpnMap = NeutronvpnUtils.getVpnMap(dataBroker, vpnId);
+        if (vpnMap == null) {
+            LOG.error("No vpnMap for vpnId {}, cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
+            return;
+        }
+
+        final Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId();
+        final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
+        if (isVpnOfTypeL2(vpnInstance)) {
+            neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(),
+                    NeutronEvpnUtils.Operation.ADD);
         }
         // Check if there are ports on this subnet and add corresponding
         // vpn-interfaces
         List<Uuid> portList = sn.getPortList();
         if (portList != null) {
-            for (Uuid port : sn.getPortList()) {
-                LOG.debug("adding vpn-interface for port {}", port.getValue());
-                createVpnInterface(vpnId, NeutronvpnUtils.getNeutronPort(dataBroker, port));
-                if (routerId != null) {
-                    addToNeutronRouterInterfacesMap(routerId, port.getValue());
-                }
-            }
+            for (final Uuid portId : sn.getPortList()) {
+                LOG.debug("adding vpn-interface for port {}", portId.getValue());
+                final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+                portDataStoreCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
+                    WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                    List<ListenableFuture<Void>> futures = new ArrayList<>();
+                    createVpnInterface(vpnId, routerId, NeutronvpnUtils.getNeutronPort(dataBroker, portId),
+                            wrtConfigTxn);
+                    futures.add(wrtConfigTxn.submit());
+                    return futures;
+                });
+            }
+        }
+    }
+
+    private void updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
+        LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(),
+                oldVpnId.getValue(), newVpnId.getValue());
+        Subnetmap sn = updateSubnetNode(subnet, null, newVpnId);
+        if (sn == null) {
+            LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
+            return;
         }
-    }
 
-    protected void updateVpnForSubnet(Uuid vpnId, Uuid subnet, boolean isBeingAssociated) {
-        LOG.debug("Updating VPN {} for subnet {}", vpnId.getValue(), subnet.getValue());
-        // Read the subnet first to see if its already associated to a VPN
-        Uuid oldVpnId = null;
-        InstanceIdentifier<Subnetmap> snId = InstanceIdentifier.builder(Subnetmaps.class).
-                child(Subnetmap.class, new SubnetmapKey(subnet)).build();
-        Subnetmap sn = null;
-        Optional<Subnetmap> optSn = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, snId);
-        if (optSn.isPresent()) {
-            sn = optSn.get();
-            oldVpnId = sn.getVpnId();
-            List<String> ips = sn.getRouterInterfaceFixedIps();
-            if ( ips != null ) {
-                for (String ipValue : ips) {
-                    IpAddress ip = new IpAddress(ipValue.toCharArray());
-                    if (oldVpnId != null) {
-                        InstanceIdentifier<VpnPortipToPort> id = NeutronvpnUtils.buildVpnPortipToPortIdentifier(oldVpnId.getValue(), ipValue);
-                        Optional<VpnPortipToPort> optionalVpnPort = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
-                        if (optionalVpnPort.isPresent()) {
-                            removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue);
-                        }
-                    }
-                    createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, sn.getRouterInterfaceName().getValue(),
-                            sn.getRouterIntfMacAddress(), true, true, false);
-                }
-            } else {
-                LOG.warn("No fixed IPs configured for router interface. VpnId={}  subnetId={}", vpnId, subnet);
-            }
-
-        }
-        sn = updateSubnetNode(subnet, null, null, null, null, vpnId);
-        boolean isLockAcquired = false;
-        String lockName = vpnId.getValue() + subnet.getValue();
-        String elanInstanceName = sn.getNetworkId().getValue();
-        InstanceIdentifier<ElanInstance> elanIdentifierId =
-                InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class,
-                        new ElanInstanceKey(elanInstanceName)).build();
-        Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                elanIdentifierId);
-        long elanTag = elanInstance.get().getElanTag();
+        //Update Router Interface first synchronously.
+        //CAUTION:  Please DONOT make the router interface VPN Movement as an asynchronous commit again !
         try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
-            checkAndPublishSubnetUpdNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isBeingAssociated,
-                    elanTag);
-            LOG.debug("Subnet updated in Vpn notification sent");
-        } catch (Exception e) {
-            LOG.error("Subnet updated in Vpn notification failed", e);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, lockName);
-            }
+            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+            updateVpnInterface(newVpnId, oldVpnId,
+                    NeutronvpnUtils.getNeutronPort(dataBroker, sn.getRouterInterfacePortId()),
+                    isBeingAssociated, true, wrtConfigTxn);
+            wrtConfigTxn.submit().checkedGet();
+        } catch (TransactionCommitFailedException e) {
+            LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, returning",
+                    sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId);
+            return;
         }
+
         // Check for ports on this subnet and update association of
         // corresponding vpn-interfaces to external vpn
         List<Uuid> portList = sn.getPortList();
         if (portList != null) {
-            for (Uuid port : sn.getPortList()) {
-                LOG.debug("Updating vpn-interface for port {}", port.getValue());
-                updateVpnInterface(vpnId, oldVpnId, NeutronvpnUtils.getNeutronPort(dataBroker, port));
+            for (Uuid port : portList) {
+                LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}",
+                    port.getValue(), isBeingAssociated);
+                final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+                portDataStoreCoordinator.enqueueJob("PORT-" + port.getValue(), () -> {
+                    WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                    List<ListenableFuture<Void>> futures = new ArrayList<>();
+                    updateVpnInterface(newVpnId, oldVpnId, NeutronvpnUtils.getNeutronPort(dataBroker, port),
+                            isBeingAssociated, false, wrtConfigTxn);
+                    futures.add(wrtConfigTxn.submit());
+                    return futures;
+                });
             }
         }
     }
 
-    InstanceIdentifier<RouterInterfaces> getRouterInterfacesId(Uuid routerId) {
+    public InstanceIdentifier<RouterInterfaces> getRouterInterfacesId(Uuid routerId) {
         return InstanceIdentifier.builder(RouterInterfacesMap.class)
                 .child(RouterInterfaces.class, new RouterInterfacesKey(routerId)).build();
     }
-    void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
-        InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
-        Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
-                .CONFIGURATION, routerInterfacesId);
-        Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId
-                (interfaceName).build();
-        if (optRouterInterfaces.isPresent()) {
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces
-                    .class, new InterfacesKey(interfaceName)), routerInterface);
-        } else {
-            RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
-            List<Interfaces> interfaces = new ArrayList<>();
-            interfaces.add(routerInterface);
-            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId, builder.setInterfaces
-                    (interfaces).build());
-        }
-    }
-
-    void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
-        InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
-        Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
-                .CONFIGURATION, routerInterfacesId);
-        Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId
-                (interfaceName).build();
-        if (optRouterInterfaces.isPresent()) {
-            RouterInterfaces routerInterfaces = optRouterInterfaces.get();
-            List<Interfaces> interfaces = routerInterfaces.getInterfaces();
-            if (interfaces != null && interfaces.remove(routerInterface)) {
-                if (interfaces.isEmpty()) {
-                    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
-                } else {
-                    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                            routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
+
+    protected void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
+        synchronized (routerId.getValue().intern()) {
+            InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+            Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
+                    .CONFIGURATION, routerInterfacesId);
+            Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName))
+                .setInterfaceId(interfaceName).build();
+            if (optRouterInterfaces.isPresent()) {
+                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces
+                        .class, new InterfacesKey(interfaceName)), routerInterface);
+            } else {
+                RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
+                List<Interfaces> interfaces = new ArrayList<>();
+                interfaces.add(routerInterface);
+                MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces
+                        .class, new InterfacesKey(interfaceName)), routerInterface);
+            }
+        }
+    }
+
+    protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
+        synchronized (routerId.getValue().intern()) {
+            InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+            Optional<RouterInterfaces> optRouterInterfaces = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
+                    .CONFIGURATION, routerInterfacesId);
+            Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName))
+                .setInterfaceId(interfaceName).build();
+            if (optRouterInterfaces.isPresent()) {
+                RouterInterfaces routerInterfaces = optRouterInterfaces.get();
+                List<Interfaces> interfaces = routerInterfaces.getInterfaces();
+                if (interfaces != null && interfaces.remove(routerInterface)) {
+                    if (interfaces.isEmpty()) {
+                        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
+                    } else {
+                        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
+                    }
                 }
             }
         }
@@ -1304,11 +1331,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
      */
     public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
                                   HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
-        for ( Routes route : interVpnLinkRoutes ) {
+        for (Routes route : interVpnLinkRoutes) {
             String nexthop = String.valueOf(route.getNexthop().getValue());
             String destination = String.valueOf(route.getDestination().getValue());
             InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
-            if ( isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink) ) {
+            if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
                 AddStaticRouteInput rpcInput =
                         new AddStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop)
                                 .setVpnInstanceName(vpnName.getValue())
@@ -1317,7 +1344,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 RpcResult<AddStaticRouteOutput> rpcResult;
                 try {
                     rpcResult = labelOuputFtr.get();
-                    if ( rpcResult.isSuccessful() ) {
+                    if (rpcResult.isSuccessful()) {
                         LOG.debug("Label generated for destination {} is: {}",
                                 destination, rpcResult.getResult().getLabel());
                     } else {
@@ -1325,12 +1352,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 destination, nexthop, rpcResult.getErrors());
                     }
                 } catch (InterruptedException | ExecutionException e) {
-                    LOG.warn("Error happened while invoking addStaticRoute RPC: {}", e);
+                    LOG.warn("Error happened while invoking addStaticRoute RPC: ", e);
                 }
             } else {
                 // Any other case is a fault.
                 LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
-                        String.valueOf(route.getDestination().getValue()), nexthop );
+                        String.valueOf(route.getDestination().getValue()), nexthop);
                 continue;
             }
         }
@@ -1346,11 +1373,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
      */
     public void removeInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
                                      HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
-        for ( Routes route : interVpnLinkRoutes ) {
+        for (Routes route : interVpnLinkRoutes) {
             String nexthop = String.valueOf(route.getNexthop().getValue());
             String destination = String.valueOf(route.getDestination().getValue());
             InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
-            if ( isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink) ) {
+            if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
                 RemoveStaticRouteInput rpcInput =
                         new RemoveStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop)
                                 .setVpnInstanceName(vpnName.getValue())
@@ -1359,7 +1386,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             } else {
                 // Any other case is a fault.
                 LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
-                        String.valueOf(route.getDestination().getValue()), nexthop );
+                        String.valueOf(route.getDestination().getValue()), nexthop);
                 continue;
             }
         }
@@ -1372,14 +1399,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     private boolean isNexthopTheOtherVpnLinkEndpoint(String nexthop, String thisVpnUuid, InterVpnLink interVpnLink) {
         return
                 interVpnLink != null
-                        && (   (interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(thisVpnUuid)
+                        && ((interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(thisVpnUuid)
                         && interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(nexthop))
-                        || (interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(thisVpnUuid )
-                        && interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(nexthop)) );
+                        || (interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(thisVpnUuid)
+                        && interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(nexthop)));
     }
 
-    protected List<Adjacency> addAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
-        List<Adjacency> adjList = new ArrayList<Adjacency>();
+    protected List<Adjacency> getAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList, String fixedIp) {
+        List<Adjacency> adjList = new ArrayList<>();
         Map<String, List<String>> adjMap = new HashMap<>();
         for (Routes route : routeList) {
             if (route == null || route.getNexthop() == null || route.getDestination() == null) {
@@ -1387,80 +1414,81 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             } else {
                 String nextHop = String.valueOf(route.getNexthop().getValue());
                 String destination = String.valueOf(route.getDestination().getValue());
-                String infName = NeutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(dataBroker, vpnId.getValue(), nextHop);
-                if (infName == null) {
-                    LOG.error("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} with nexthop {}",
-                            destination, vpnId.getValue(), nextHop);
-                    // Proceed to process the next extra-route
+                if (!nextHop.equals(fixedIp)) {
+                    LOG.trace("FixedIP {} is not extra route nexthop for destination {}", fixedIp, destination);
                     continue;
                 }
-                LOG.trace("Adding extra route for destination {} onto vpn {} with nexthop {} and infName {}", destination,
-                        vpnId.getValue(), nextHop, infName);
-                List<String> hops = adjMap.get(destination);
-                if (hops == null){
-                    hops = new ArrayList<>();
-                    adjMap.put(destination, hops);
-                }
-                if (! hops.contains(nextHop))
+                LOG.trace("Adding extra route for destination {} onto vpn {} with nexthop {} ", destination,
+                        vpnId.getValue(), nextHop);
+                List<String> hops = adjMap.computeIfAbsent(destination, k -> new ArrayList<>());
+                if (!hops.contains(nextHop)) {
                     hops.add(nextHop);
+                }
             }
         }
 
         for (String destination : adjMap.keySet()) {
-            Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIpList(adjMap.get
-                    (destination)).setKey(new AdjacencyKey(destination)).build();
+            Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination)
+                .setNextHopIpList(adjMap.get(destination)).setKey(new AdjacencyKey(destination)).build();
             adjList.add(erAdj);
         }
+        return  adjList;
+    }
 
-        for (Adjacency adj : adjList) {
-            for(String nextHop : adj.getNextHopIpList()) {
-                String infName = NeutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(dataBroker, vpnId.getValue(), nextHop);
-                if ( infName != null ) {
-                    InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class)
-                            .child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void updateVpnInterfaceWithExtraRouteAdjacency(Uuid vpnId, List<Routes> routeList) {
+        for (Routes route : routeList) {
+            if (route == null || route.getNexthop() == null || route.getDestination() == null) {
+                LOG.error("Incorrect input received for extra route. {}", route);
+            } else {
+                String nextHop = String.valueOf(route.getNexthop().getValue());
+                String destination = String.valueOf(route.getDestination().getValue());
+                String infName = NeutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(dataBroker, vpnId.getValue(),
+                        nextHop);
+                if (infName != null) {
+                    LOG.trace("Updating extra route for destination {} onto vpn {} with nexthop {} and infName {}",
+                        destination, vpnId.getValue(), nextHop, infName);
                     boolean isLockAcquired = false;
                     try {
-                        Optional<VpnInterface> optionalVpnInterface =
-                                NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
-                        if (optionalVpnInterface.isPresent()) {
-                            Adjacency newAdj = new AdjacencyBuilder(adj).setNextHopIpList(Arrays.asList(nextHop))
-                                    .build();
-                            Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Arrays.asList(newAdj)).build();
-                            VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
-                                    .addAugmentation(Adjacencies.class, erAdjs).build();
-                            isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
-                            MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
-                        } else {
-                            LOG.error("VM adjacency for interface {} not present; cannot add extra route adjacency",
-                                    infName);
-                        }
+                        InstanceIdentifier<VpnInterface> identifier = InstanceIdentifier.builder(VpnInterfaces.class)
+                                .child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
+                        InstanceIdentifier<Adjacency> path = identifier.augmentation(Adjacencies.class)
+                            .child(Adjacency.class, new AdjacencyKey(destination));
+                        Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination)
+                            .setNextHopIpList(Collections.singletonList(nextHop)).setKey(new AdjacencyKey(destination))
+                            .build();
+                        isLockAcquired = NeutronvpnUtils.lock(infName);
+                        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, path, erAdj);
                     } catch (Exception e) {
-                        LOG.error("exception in adding extra route with destination: {}, next hop: {}", adj
-                                .getIpAddress(), nextHop, e);
+                        LOG.error("exception in adding extra route with destination: {}, next hop: {}",
+                            destination, nextHop, e);
                     } finally {
                         if (isLockAcquired) {
-                            NeutronvpnUtils.unlock(lockManager, infName);
+                            NeutronvpnUtils.unlock(infName);
                         }
                     }
                 } else {
-                    LOG.warn("Could not find suitable Interface for {}", nextHop);
+                    LOG.debug("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} "
+                        + "with nexthop {}", destination, vpnId.getValue(), nextHop);
                 }
-
             }
         }
-        return adjList;
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void removeAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
         for (Routes route : routeList) {
             if (route != null && route.getNexthop() != null && route.getDestination() != null) {
                 boolean isLockAcquired = false;
                 String nextHop = String.valueOf(route.getNexthop().getValue());
                 String destination = String.valueOf(route.getDestination().getValue());
-                String infName = NeutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(dataBroker, vpnId.getValue(), nextHop);
+                String infName = NeutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(dataBroker, vpnId.getValue(),
+                        nextHop);
                 if (infName == null) {
-                    LOG.error("Unable to find VPN NextHop interface to remove extra-route destination {} on VPN {} with nexthop {}",
-                            destination, vpnId.getValue(), nextHop);
+                    LOG.error("Unable to find VPN NextHop interface to remove extra-route destination {} on VPN {} "
+                            + "with nexthop {}", destination, vpnId.getValue(), nextHop);
                     // Proceed to remove the next extra-route
                     continue;
                 }
@@ -1493,7 +1521,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
 
                 try {
-                    isLockAcquired = NeutronvpnUtils.lock(lockManager, infName);
+                    isLockAcquired = NeutronvpnUtils.lock(infName);
                     if (updateNextHops) {
                         // An update must be done, not including the current next hop
                         InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(
@@ -1502,7 +1530,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 .setNextHopIpList(nextHopList)
                                 .setKey(new AdjacencyKey(destination))
                                 .build();
-                        Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Arrays.asList(newAdj)).build();
+                        Adjacencies erAdjs =
+                                new AdjacenciesBuilder().setAdjacency(Collections.singletonList(newAdj)).build();
                         VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
                                 .addAugmentation(Adjacencies.class, erAdjs).build();
                         MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
@@ -1515,7 +1544,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                     LOG.error("exception in deleting extra route: {}" + e);
                 } finally {
                     if (isLockAcquired) {
-                        NeutronvpnUtils.unlock(lockManager, infName);
+                        NeutronvpnUtils.unlock(infName);
                     }
                 }
             } else {
@@ -1524,10 +1553,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected void removeL3Vpn(Uuid id) {
+    public void removeVpn(Uuid id) {
         // read VPNMaps
         VpnMap vpnMap = NeutronvpnUtils.getVpnMap(dataBroker, id);
-        Uuid router = vpnMap.getRouterId();
+        Uuid router = (vpnMap != null) ? vpnMap.getRouterId() : null;
         // dissociate router
         if (router != null) {
             dissociateRouterFromVpn(id, router);
@@ -1543,45 +1572,42 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         deleteVpnInstance(id);
     }
 
-    protected void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
+    protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet) {
         LOG.debug("Removing subnet {} from vpn {}", subnet.getValue(), vpnId.getValue());
-        Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, subnet);
-        boolean isLockAcquired = false;
-        String lockName = vpnId.getValue() + subnet.getValue();
-        String elanInstanceName = sn.getNetworkId().getValue();
-        InstanceIdentifier<ElanInstance> elanIdentifierId =
-                InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class,
-                        new ElanInstanceKey(elanInstanceName)).build();
-        Optional<ElanInstance> elanInstance = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                elanIdentifierId);
-        long elanTag = elanInstance.get().getElanTag();
-        Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId();
-        if (vpnId.equals(routerId)) {
-            isExternalVpn = false;
-        } else {
-            isExternalVpn = true;
+        VpnMap vpnMap = NeutronvpnUtils.getVpnMap(dataBroker, vpnId);
+        if (vpnMap == null) {
+            LOG.error("No vpnMap for vpnId {}, cannot remove subnet {} from VPN",
+                    vpnId.getValue(), subnet.getValue());
+            return;
         }
-        try {
-            isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName);
-            checkAndPublishSubnetDelNotification(subnet, sn.getSubnetIp(), vpnId.getValue(), isExternalVpn, elanTag);
-            LOG.debug("Subnet removed from Vpn notification sent");
-        } catch (Exception e) {
-            LOG.error("Subnet removed from Vpn notification failed", e);
-        } finally {
-            if (isLockAcquired) {
-                NeutronvpnUtils.unlock(lockManager, lockName);
-            }
+
+        final Uuid routerId = vpnMap.getRouterId();
+        Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, subnet);
+        final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
+        if (isVpnOfTypeL2(vpnInstance)) {
+            neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(),
+                    NeutronEvpnUtils.Operation.DELETE);
         }
         if (sn != null) {
             // Check if there are ports on this subnet; remove corresponding vpn-interfaces
             List<Uuid> portList = sn.getPortList();
             if (portList != null) {
-                for (Uuid port : sn.getPortList()) {
-                    LOG.debug("removing vpn-interface for port {}", port.getValue());
-                    deleteVpnInterface(vpnId, NeutronvpnUtils.getNeutronPort(dataBroker, port));
-                    if (routerId != null) {
-                        removeFromNeutronRouterInterfacesMap(routerId, port.getValue());
-                    }
+                for (final Uuid portId : sn.getPortList()) {
+                    LOG.debug("removing vpn-interface for port {}", portId.getValue());
+                    final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+                    portDataStoreCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
+                        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+                        Port port = NeutronvpnUtils.getNeutronPort(dataBroker, portId);
+                        if (port != null) {
+                            deleteVpnInterface(vpnId, routerId, port, wrtConfigTxn);
+                        } else {
+                            LOG.error("Cannot proceed with deleteVpnInterface for port {} in subnet {} since port is "
+                                + "absent in Neutron config DS", portId.getValue(), subnet.getValue());
+                        }
+                        futures.add(wrtConfigTxn.submit());
+                        return futures;
+                    });
                 }
             }
             // update subnet-vpn association
@@ -1591,14 +1617,19 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
+    private boolean isVpnOfTypeL2(VpnInstance vpnInstance) {
+        return vpnInstance != null && vpnInstance.getType() == VpnInstance.Type.L2;
+    }
+
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
         updateVpnMaps(vpnId, null, routerId, null, null);
         LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
         List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(dataBroker, routerId);
-//        if (!vpnId.equals(routerId)) {
         if (routerSubnets != null) {
             for (Uuid subnetId : routerSubnets) {
-                updateVpnForSubnet(vpnId, subnetId, true);
+                updateVpnForSubnet(routerId, vpnId, subnetId, true);
             }
         }
         try {
@@ -1609,13 +1640,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             LOG.error("publishing of notification upon association of router {} to VPN {} failed : ", routerId
                     .getValue(), vpnId.getValue(), e);
         }
-//        }
-//        else {
-//            LOG.debug("Adding subnets to internal vpn {}", vpnId.getValue());
-//            for (Uuid subnet : routerSubnets) {
-//                addSubnetToVpn(vpnId, subnet);
-//            }
-//        }
     }
 
     protected void associateRouterToInternalVpn(Uuid vpnId, Uuid routerId) {
@@ -1626,13 +1650,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
 
         List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(dataBroker, routerId);
         if (routerSubnets != null) {
             for (Uuid subnetId : routerSubnets) {
                 LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
-                updateVpnForSubnet(routerId, subnetId, false);
+                updateVpnForSubnet(vpnId, routerId, subnetId, false);
             }
         }
         clearFromVpnMaps(vpnId, routerId, null);
@@ -1650,15 +1676,34 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         List<String> failedNwList = new ArrayList<>();
         List<Uuid> passedNwList = new ArrayList<>();
         if (!networks.isEmpty()) {
+            VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
+            if (vpnInstance == null) {
+                LOG.error("VPN %s not present when associating network to it", vpn.getValue());
+                failedNwList.add(String.format("Failed to associate network on vpn %s as vpn is not present",
+                        vpn.getValue()));
+                return failedNwList;
+            }
             // process corresponding subnets for VPN
             for (Uuid nw : networks) {
                 Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, nw);
+                NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
+                if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
+                    LOG.error("MultiSegmented networks not supported in VPN. Failed to associate network {} on vpn {}",
+                            nw.getValue(), vpn.getValue());
+                    failedNwList.add(String.format("Failed to associate network %s on vpn %s as it is multisegmented.",
+                            nw.getValue(), vpn.getValue()));
+                    continue;
+                }
                 Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, nw);
                 if (network == null) {
                     failedNwList.add(String.format("network %s not found", nw.getValue()));
                 } else if (vpnId != null) {
                     failedNwList.add(String.format("network %s already associated to another VPN %s", nw.getValue(),
                             vpnId.getValue()));
+                } else if (isVpnOfTypeL2(vpnInstance)
+                        && (neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance))) {
+                    LOG.error("EVPN supports only one network to be associated");
+                    failedNwList.add(String.format("EVPN supports only one network to be associated"));
                 } else {
                     List<Uuid> networkSubnets = NeutronvpnUtils.getSubnetIdsFromNetworkId(dataBroker, nw);
                     LOG.debug("Adding network subnets...{}", networkSubnets);
@@ -1670,8 +1715,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 addSubnetToVpn(vpn, subnet);
                                 passedNwList.add(nw);
                             } else {
-                                failedNwList.add(String.format("subnet %s already added as router interface bound to " +
-                                        "internal/external VPN %s", subnet.getValue (), subnetVpnId.getValue()));
+                                failedNwList.add(String.format("subnet %s already added as router interface bound to "
+                                    + "internal/external VPN %s", subnet.getValue(), subnetVpnId.getValue()));
                             }
                         }
                     }
@@ -1710,8 +1755,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                             failedNwList.add(String.format("input network %s not associated to any vpn yet", nw
                                     .getValue()));
                         } else {
-                            failedNwList.add(String.format("input network %s associated to a another vpn %s instead " +
-                                    "of the one given as input", nw.getValue(), vpnId.getValue()));
+                            failedNwList.add(String.format("input network %s associated to a another vpn %s instead "
+                                + "of the one given as input", nw.getValue(), vpnId.getValue()));
                         }
                     }
                     if (NeutronvpnUtils.getIsExternal(network)) {
@@ -1725,12 +1770,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     /**
-     * It handles the invocations to the neutronvpn:associateNetworks RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#associateNetworks
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInput)
+     * It handles the invocations to the neutronvpn:associateNetworks RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
 
         AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
@@ -1758,15 +1802,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: %s",
                         message);
                 opBuilder.setResponse(errorResponse);
-                result.set(RpcResultBuilder.<AssociateNetworksOutput> success().withResult(opBuilder.build()).build());
+                result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
             } else {
-                result.set(RpcResultBuilder.<AssociateNetworksOutput> success().build());
+                result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
             }
         } catch (Exception ex) {
             String message = String.format("associate Networks to vpn %s failed due to %s",
                     input.getVpnId().getValue(), ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<AssociateNetworksOutput> failed().withError(ErrorType.APPLICATION, message)
+            result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
                     .build());
         }
         LOG.debug("associateNetworks returns..");
@@ -1774,12 +1818,11 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     /**
-     * It handles the invocations to the neutronvpn:associateRouter RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#associateRouter
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateRouterInput)
+     * It handles the invocations to the neutronvpn:associateRouter RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<Void>> associateRouter(AssociateRouterInput input) {
 
         SettableFuture<RpcResult<Void>> result = SettableFuture.create();
@@ -1788,17 +1831,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         Uuid vpnId = input.getVpnId();
         Uuid routerId = input.getRouterId();
         try {
-            if (routerId != null && vpnId != null) {
-                Router rtr = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
-                VpnMap vpnMap = NeutronvpnUtils.getVpnMap(dataBroker, vpnId);
-                if (rtr != null && vpnMap != null) {
+            VpnMap vpnMap = NeutronvpnUtils.getVpnMap(dataBroker, vpnId);
+            Router rtr = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
+            if (vpnMap != null) {
+                if (rtr != null) {
                     Uuid extVpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
                     if (vpnMap.getRouterId() != null) {
                         returnMsg.append("vpn ").append(vpnId.getValue()).append(" already associated to router ")
                                 .append(vpnMap.getRouterId().getValue());
                     } else if (extVpnId != null) {
-                        returnMsg.append("router ").append(routerId.getValue()).append(" already associated to " +
-                                "another VPN ").append(extVpnId.getValue());
+                        returnMsg.append("router ").append(routerId.getValue()).append(" already associated to "
+                            + "another VPN ").append(extVpnId.getValue());
                     } else {
                         associateRouterToVpn(vpnId, routerId);
                     }
@@ -1812,28 +1855,28 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 String message = String.format("associate router to vpn %s failed due to %s", routerId.getValue(),
                         returnMsg);
                 LOG.error(message);
-                result.set(RpcResultBuilder.<Void> failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
+                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
                         .build());
             } else {
-                result.set(RpcResultBuilder.<Void> success().build());
+                result.set(RpcResultBuilder.<Void>success().build());
             }
         } catch (Exception ex) {
             String message = String.format("associate router %s to vpn %s failed due to %s", routerId.getValue(),
                     vpnId.getValue(), ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<Void> failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
         }
         LOG.debug("associateRouter returns..");
         return result;
     }
 
-    /** It handles the invocations to the neutronvpn:getFixedIPsForNeutronPort RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService#getFixedIPsForNeutronPort
-     * (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortInput)
+    /** It handles the invocations to the neutronvpn:getFixedIPsForNeutronPort RPC method.
      */
     @Override
-    public Future<RpcResult<GetFixedIPsForNeutronPortOutput>> getFixedIPsForNeutronPort(GetFixedIPsForNeutronPortInput input) {
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public Future<RpcResult<GetFixedIPsForNeutronPortOutput>> getFixedIPsForNeutronPort(
+        GetFixedIPsForNeutronPortInput input) {
         GetFixedIPsForNeutronPortOutputBuilder opBuilder = new GetFixedIPsForNeutronPortOutputBuilder();
         SettableFuture<RpcResult<GetFixedIPsForNeutronPortOutput>> result = SettableFuture.create();
         Uuid portId = input.getPortId();
@@ -1844,7 +1887,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             if (port != null) {
                 List<FixedIps> fixedIPs = port.getFixedIps();
                 for (FixedIps ip : fixedIPs) {
-                    fixedIPList.add(ip.getIpAddress().getIpv4Address().getValue());
+                    fixedIPList.add(String.valueOf(ip.getIpAddress().getValue()));
                 }
             } else {
                 returnMsg.append("neutron port: ").append(portId.getValue()).append(" not found");
@@ -1852,32 +1895,30 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             if (returnMsg.length() != 0) {
                 String message = String.format("Retrieval of FixedIPList for neutron port failed due to %s", returnMsg);
                 LOG.error(message);
-                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput> failed()
+                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed()
                         .withWarning(ErrorType.PROTOCOL, "invalid-value", message).build());
             } else {
                 opBuilder.setFixedIPs(fixedIPList);
-                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput> success().withResult(opBuilder.build())
+                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().withResult(opBuilder.build())
                         .build());
-                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput> success().build());
+                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().build());
             }
         } catch (Exception ex) {
             String message = String.format("Retrieval of FixedIPList for neutron port %s failed due to %s",
                     portId.getValue(), ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput> failed()
+            result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed()
                     .withError(ErrorType.APPLICATION, message).build());
         }
         return result;
     }
 
     /**
-     * It handles the invocations to the neutronvpn:dissociateNetworks RPC method
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-     * .rev150602.NeutronvpnService#dissociateNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt
-     * .neutronvpn.rev150602.DissociateNetworksInput)
+     * It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
 
         DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
@@ -1906,15 +1947,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: "
                         + message);
                 opBuilder.setResponse(errorResponse);
-                result.set(RpcResultBuilder.<DissociateNetworksOutput> success().withResult(opBuilder.build()).build());
+                result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
             } else {
-                result.set(RpcResultBuilder.<DissociateNetworksOutput> success().build());
+                result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
             }
         } catch (Exception ex) {
             String message = String.format("dissociate Networks to vpn %s failed due to %s",
                     input.getVpnId().getValue(), ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<DissociateNetworksOutput> failed().withError(ErrorType.APPLICATION, message)
+            result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
                     .build());
         }
         LOG.debug("dissociateNetworks returns..");
@@ -1923,12 +1964,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
     /**
      * It handles the invocations to the neutronvpn:dissociateRouter RPC method.
-     *
-     * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-     * .rev150602.NeutronvpnService#dissociateRouter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-     * .rev150602.DissociateRouterInput)
      */
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public Future<RpcResult<Void>> dissociateRouter(DissociateRouterInput input) {
 
         SettableFuture<RpcResult<Void>> result = SettableFuture.create();
@@ -1947,12 +1986,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                             dissociateRouterFromVpn(vpnId, routerId);
                         } else {
                             if (routerVpnId == null) {
-                                returnMsg.append("input router ").append(routerId.getValue()).append(" not associated" +
-                                        " to any vpn yet");
+                                returnMsg.append("input router ").append(routerId.getValue())
+                                    .append(" not associated to any vpn yet");
                             } else {
-                                returnMsg.append("input router ").append(routerId.getValue()).append(" associated to " +
-                                        "vpn ").append(routerVpnId.getValue()).append("instead of the vpn given as " +
-                                        "input");
+                                returnMsg.append("input router ").append(routerId.getValue())
+                                    .append(" associated to vpn ")
+                                    .append(routerVpnId.getValue()).append("instead of the vpn given as input");
                             }
                         }
                     } else {
@@ -1968,16 +2007,16 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 LOG.error(message);
                 String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: "
                         + message);
-                result.set(RpcResultBuilder.<Void> failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
+                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
                         .build());
             } else {
-                result.set(RpcResultBuilder.<Void> success().build());
+                result.set(RpcResultBuilder.<Void>success().build());
             }
         } catch (Exception ex) {
             String message = String.format("disssociate router %s to vpn %s failed due to %s", routerId.getValue(),
                     vpnId.getValue(), ex.getMessage());
             LOG.error(message, ex);
-            result.set(RpcResultBuilder.<Void> failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
         }
         LOG.debug("dissociateRouter returns..");
 
@@ -2006,7 +2045,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         deleteVpnInstance(routerId);
     }
 
-    protected Subnet getNeutronSubnet(Uuid subnetId){
+    protected Subnet getNeutronSubnet(Uuid subnetId) {
         return NeutronvpnUtils.getNeutronSubnet(dataBroker, subnetId);
     }
 
@@ -2031,36 +2070,30 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         return NeutronvpnUtils.getNeutronPort(dataBroker, portId);
     }
 
-    protected List<Uuid> getSubnetsforVpn(Uuid vpnid) {
-        List<Uuid> subnets = new ArrayList<>();
-        // read subnetmaps
-        InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
-        Optional<Subnetmaps> subnetmaps = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                subnetmapsid);
-        if (subnetmaps.isPresent() && subnetmaps.get().getSubnetmap() != null) {
-            List<Subnetmap> subnetMapList = subnetmaps.get().getSubnetmap();
-            for (Subnetmap subnetMap : subnetMapList) {
-                if (subnetMap.getVpnId() != null && subnetMap.getVpnId().equals(vpnid)) {
-                    subnets.add(subnetMap.getId());
-                }
-            }
-        }
-        return subnets;
+    protected Uuid getNetworkForSubnet(Uuid subnetId) {
+        return NeutronvpnUtils.getNetworkForSubnet(dataBroker, subnetId);
+    }
+
+    protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
+        return NeutronvpnUtils.getNetworksforVpn(dataBroker, vpnId);
     }
 
     /**
-     * Implementation of the "vpnservice:neutron-ports-show" Karaf CLI command
+     * Implementation of the "vpnservice:neutron-ports-show" Karaf CLI command.
      *
      * @return a List of String to be printed on screen
      */
+    // TODO Clean up the exception handling and the console output
+    @SuppressWarnings({"checkstyle:IllegalCatch", "checkstyle:RegexpSinglelineJava"})
     public List<String> showNeutronPortsCLI() {
         List<String> result = new ArrayList<>();
-        result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", "Port ID", "Mac Address", "Prefix Length", "IP " +
-                "Address"));
+        result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", "Port ID", "Mac Address", "Prefix Length",
+            "IP Address"));
         result.add("-------------------------------------------------------------------------------------------");
         InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
         try {
-            Optional<Ports> ports = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
+            Optional<Ports> ports =
+                NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
             if (ports.isPresent() && ports.get().getPort() != null) {
                 for (Port port : ports.get().getPort()) {
                     List<FixedIps> fixedIPs = port.getFixedIps();
@@ -2098,11 +2131,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     /**
-     * Implementation of the "vpnservice:l3vpn-config-show" karaf CLI command
+     * Implementation of the "vpnservice:l3vpn-config-show" karaf CLI command.
      *
      * @param vpnuuid Uuid of the VPN whose config must be shown
-     * @return
+     * @return formatted output list
      */
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     public List<String> showVpnConfigCLI(Uuid vpnuuid) {
         List<String> result = new ArrayList<>();
         if (vpnuuid == null) {
@@ -2125,20 +2159,21 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 result.add("");
                 result.add("------------------------------------------------------------------------------------");
                 result.add("");
-                List<L3vpnInstances> VpnList = rpcResult.getResult().getL3vpnInstances();
-                for (L3vpnInstance Vpn : VpnList) {
-                    String tenantId = Vpn.getTenantId() != null ? Vpn.getTenantId().getValue()
+                List<L3vpnInstances> vpnList = rpcResult.getResult().getL3vpnInstances();
+                for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
+                            .rev150602.VpnInstance vpn : vpnList) {
+                    String tenantId = vpn.getTenantId() != null ? vpn.getTenantId().getValue()
                             : "\"                 " + "                  \"";
-                    result.add(String.format(" %-37s %-37s %-7s ", Vpn.getId().getValue(), tenantId,
-                            Vpn.getRouteDistinguisher()));
+                    result.add(String.format(" %-37s %-37s %-7s ", vpn.getId().getValue(), tenantId,
+                            vpn.getRouteDistinguisher()));
                     result.add("");
-                    result.add(String.format(" %-80s ", Vpn.getImportRT()));
+                    result.add(String.format(" %-80s ", vpn.getImportRT()));
                     result.add("");
-                    result.add(String.format(" %-80s ", Vpn.getExportRT()));
+                    result.add(String.format(" %-80s ", vpn.getExportRT()));
                     result.add("");
 
-                    Uuid vpnid = Vpn.getId();
-                    List<Uuid> subnetList = getSubnetsforVpn(vpnid);
+                    Uuid vpnid = vpn.getId();
+                    List<Uuid> subnetList = NeutronvpnUtils.getSubnetsforVpn(dataBroker, vpnid);
                     if (!subnetList.isEmpty()) {
                         for (Uuid subnetuuid : subnetList) {
                             result.add(String.format(" %-76s ", subnetuuid.getValue()));
@@ -2152,10 +2187,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
             } else {
                 String errortag = rpcResult.getErrors().iterator().next().getTag();
-                if (errortag == "") {
+                if (Objects.equals(errortag, "")) {
                     System.out.println("");
                     System.out.println("No VPN has been configured yet");
-                } else if (errortag == "invalid-value") {
+                } else if (Objects.equals(errortag, "invalid-value")) {
                     System.out.println("");
                     System.out.println("VPN " + vpnuuid.getValue() + " is not present");
                 } else {
@@ -2170,55 +2205,93 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         return result;
     }
 
-    private String getshowVpnConfigCLIHelp() {
-        StringBuilder help = new StringBuilder("Usage:");
-        help.append("display vpn-config [-vid/--vpnid <id>]");
-        return help.toString();
-    }
-
-    private void checkAndPublishSubnetAddNotification(Uuid subnetId, String subnetIp, String vpnName,
-                                                      Boolean isExternalvpn, Long elanTag) throws InterruptedException {
-        SubnetAddedToVpnBuilder builder = new SubnetAddedToVpnBuilder();
-
-        LOG.info("publish notification called");
+    protected void createExternalVpnInterfaces(Uuid extNetId) {
+        if (extNetId == null) {
+            LOG.trace("external network is null");
+            return;
+        }
 
-        builder.setSubnetId(subnetId);
-        builder.setSubnetIp(subnetIp);
-        builder.setVpnName(vpnName);
-        builder.setExternalVpn(isExternalvpn);
-        builder.setElanTag(elanTag);
+        Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
+        if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
+            LOG.trace("No external ports attached to external network {}", extNetId.getValue());
+            return;
+        }
 
-        notificationPublishService.putNotification(builder.build());
+        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+        for (String elanInterface : extElanInterfaces) {
+            createExternalVpnInterface(extNetId, elanInterface, wrtConfigTxn);
+        }
+        wrtConfigTxn.submit();
     }
 
-    private void checkAndPublishSubnetDelNotification(Uuid subnetId, String subnetIp, String vpnName,
-                                                      Boolean isExternalvpn, Long elanTag) throws InterruptedException {
-        SubnetDeletedFromVpnBuilder builder = new SubnetDeletedFromVpnBuilder();
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    protected void removeExternalVpnInterfaces(Uuid extNetId) {
+        Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
+        if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
+            LOG.trace("No external ports attached for external network {}", extNetId);
+            return;
+        }
+        try {
 
-        LOG.info("publish notification called");
+            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+            for (String elanInterface : extElanInterfaces) {
+                InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils
+                        .buildVpnInterfaceIdentifier(elanInterface);
+                LOG.info("Removing vpn interface {}", elanInterface);
+                wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+            }
+            wrtConfigTxn.submit();
 
-        builder.setSubnetId(subnetId);
-        builder.setSubnetIp(subnetIp);
-        builder.setVpnName(vpnName);
-        builder.setExternalVpn(isExternalvpn);
-        builder.setElanTag(elanTag);
+        } catch (Exception ex) {
+            LOG.error("Removal of vpninterfaces {} failed due to {}", extElanInterfaces, ex);
+        }
+    }
 
-        notificationPublishService.putNotification(builder.build());
+    private void createExternalVpnInterface(Uuid vpnId, String infName, WriteTransaction wrtConfigTxn) {
+        writeVpnInterfaceToDs(vpnId, infName, null, false /* not a router iface */, wrtConfigTxn);
     }
 
-    private void checkAndPublishSubnetUpdNotification(Uuid subnetId, String subnetIp, String vpnName,
-                                                      Boolean isExternalvpn, Long elanTag) throws InterruptedException {
-        SubnetUpdatedInVpnBuilder builder = new SubnetUpdatedInVpnBuilder();
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void writeVpnInterfaceToDs(Uuid vpnId, String infName, Adjacencies adjacencies,
+            Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
+        if (vpnId == null || infName == null) {
+            LOG.debug("vpn id or interface is null");
+            return;
+        }
 
-        LOG.info("publish notification called");
+        Boolean wrtConfigTxnPresent = true;
+        if (wrtConfigTxn == null) {
+            wrtConfigTxnPresent = false;
+            wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+        }
+
+        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
+        VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName))
+                .setName(infName)
+                .setVpnInstanceName(vpnId.getValue())
+                .setRouterInterface(isRouterInterface);
+        if (adjacencies != null) {
+            vpnb.addAugmentation(Adjacencies.class, adjacencies);
+        }
+        VpnInterface vpnIf = vpnb.build();
+        try {
+            LOG.info("Creating vpn interface {}", vpnIf);
+            wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
+        } catch (Exception ex) {
+            LOG.error("Creation of vpninterface {} failed due to {}", infName, ex);
+        }
 
-        builder.setSubnetId(subnetId);
-        builder.setSubnetIp(subnetIp);
-        builder.setVpnName(vpnName);
-        builder.setExternalVpn(isExternalvpn);
-        builder.setElanTag(elanTag);
+        if (!wrtConfigTxnPresent) {
+            wrtConfigTxn.submit();
+        }
+    }
 
-        notificationPublishService.putNotification(builder.build());
+    private String getshowVpnConfigCLIHelp() {
+        StringBuilder help = new StringBuilder("Usage:");
+        help.append("display vpn-config [-vid/--vpnid <id>]");
+        return help.toString();
     }
 
     private void checkAndPublishRouterAssociatedtoVpnNotification(Uuid routerId, Uuid vpnId) throws
@@ -2231,8 +2304,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
     private void checkAndPublishRouterDisassociatedFromVpnNotification(Uuid routerId, Uuid vpnId) throws
             InterruptedException {
-        RouterDisassociatedFromVpn routerDisassociatedFromVpn = new RouterDisassociatedFromVpnBuilder().setRouterId
-                (routerId).setVpnId(vpnId).build();
+        RouterDisassociatedFromVpn routerDisassociatedFromVpn =
+            new RouterDisassociatedFromVpnBuilder().setRouterId(routerId).setVpnId(vpnId).build();
         LOG.info("publishing notification upon disassociation of router from VPN");
         notificationPublishService.putNotification(routerDisassociatedFromVpn);
     }
@@ -2241,40 +2314,18 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         floatingIpMapListener.dissociatefixedIPFromFloatingIP(fixedNeutronPortName);
     }
 
-    public void createVpnPortFixedIpToPort(String vpnName, String fixedIp,String portName, String macAddress,
-                                           boolean isSubnetIp, boolean isConfig, boolean isLearnt) {
-        NeutronvpnUtils.createVpnPortFixedIpToPort(dataBroker, vpnName, fixedIp, portName, macAddress, isSubnetIp,isConfig,isLearnt);
+    @Override
+    public Future<RpcResult<CreateEVPNOutput>> createEVPN(CreateEVPNInput input) {
+        return neutronEvpnManager.createEVPN(input);
     }
 
-    public void removeVpnPortFixedIpToPort(String vpnName, String fixedIp) {
-        NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnName, fixedIp);
+    @Override
+    public Future<RpcResult<GetEVPNOutput>> getEVPN(GetEVPNInput input) {
+        return neutronEvpnManager.getEVPN(input);
     }
 
-    private void handleExternalSubnetPorts(Subnetmap subnetmap) {
-        Uuid routerId = subnetmap.getRouterId();
-        Uuid subnetId = subnetmap.getId();
-        if (routerId == null) {
-            LOG.trace("No router attached to subnet {}", subnetId);
-            return;
-        }
-
-        InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
-        Optional<Routers> optionalRouters = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                routersIdentifier);
-        if (!optionalRouters.isPresent() || optionalRouters.get().getNetworkId() == null) {
-            LOG.trace("No external network attached to router {} subnet {}", routerId, subnetId);
-            return;
-        }
-
-        Uuid extNetId = optionalRouters.get().getNetworkId();
-        Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
-        if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
-            LOG.trace("No external ports attached to subnet {}", subnetmap.getId());
-            return;
-        }
-
-        for (String elanInterface : extElanInterfaces) {
-            createVpnInterface(subnetmap.getVpnId(), elanInterface);
-        }
+    @Override
+    public Future<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
+        return neutronEvpnManager.deleteEVPN(input);
     }
 }