Lower log level for non errors
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronPortChangeListener.java
index 2763453b6514a2bb8558b1ac8f1310228c4cd763..277ae145c4a78761ae5557e107fcabd9cd884f30 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,
@@ -10,18 +10,25 @@ package org.opendaylight.netvirt.neutronvpn;
 import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier;
 
 import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
+import com.google.common.base.Strings;
 import com.google.common.util.concurrent.ListenableFuture;
+
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
-import java.util.concurrent.Callable;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
@@ -34,65 +41,55 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.PortAddedToSubnetBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.PortRemovedFromSubnetBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.ext.rev160613.QosPortExtension;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<Port, NeutronPortChangeListener>
         implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NeutronPortChangeListener.class);
     private final DataBroker dataBroker;
     private final NeutronvpnManager nvpnManager;
     private final NeutronvpnNatManager nvpnNatManager;
-    private final NotificationPublishService notificationPublishService;
     private final NeutronSubnetGwMacResolver gwMacResolver;
-    private OdlInterfaceRpcService odlInterfaceRpcService;
     private final IElanService elanService;
 
+    @Inject
     public NeutronPortChangeListener(final DataBroker dataBroker,
-                                     final NeutronvpnManager nVpnMgr, final NeutronvpnNatManager nVpnNatMgr,
-                                     final NotificationPublishService notiPublishService,
+                                     final NeutronvpnManager neutronvpnManager,
+                                     final NeutronvpnNatManager neutronvpnNatManager,
                                      final NeutronSubnetGwMacResolver gwMacResolver,
-                                     final OdlInterfaceRpcService odlInterfaceRpcService,
                                      final IElanService elanService) {
         super(Port.class, NeutronPortChangeListener.class);
         this.dataBroker = dataBroker;
-        nvpnManager = nVpnMgr;
-        nvpnNatManager = nVpnNatMgr;
-        notificationPublishService = notiPublishService;
+        nvpnManager = neutronvpnManager;
+        nvpnNatManager = neutronvpnNatManager;
         this.gwMacResolver = gwMacResolver;
-        this.odlInterfaceRpcService = odlInterfaceRpcService;
         this.elanService = elanService;
     }
 
-
-    public void start() {
-        LOG.info("{} start", getClass().getSimpleName());
+    @Override
+    @PostConstruct
+    public void init() {
+        LOG.info("{} init", getClass().getSimpleName());
         registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
     }
 
@@ -113,36 +110,31 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         LOG.trace("Adding Port : key: {}, value={}", identifier, input);
         Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, input.getNetworkId());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
-            //FIXME: This should be removed when support for VLAN and GRE network types is added
-            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of " +
-                    "network {}.", portName, network);
+            LOG.warn("neutron vpn received a port add() for a network without a provider extension augmentation "
+                            + "or with an unsupported network type for the port {} which is part of network {}",
+                    portName, network);
             return;
         }
         NeutronvpnUtils.addToPortCache(input);
-
-        /* check if router interface has been created */
-        if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
+        String portStatus = NeutronUtils.PORT_STATUS_DOWN;
+        if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
             if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceAdded(input);
-                /* nothing else to do here */
+                NeutronUtils.createPortStatus(input.getUuid().getValue(), NeutronUtils.PORT_STATUS_ACTIVE, dataBroker);
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) {
                 handleRouterGatewayUpdated(input);
+                portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
-
-                // populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
-                // fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
-                addToFloatingIpPortInfo(new Uuid(input.getDeviceId()), input.getUuid(), input.getFixedIps().get(0)
-                                .getSubnetId(), input.getMacAddress().getValue());
-
-                elanService.handleKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue(),
-                        NwConstants.ADD_FLOW);
+                handleFloatingIpPortUpdated(null, input);
+                portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             }
         }
         if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
             handleNeutronPortCreated(input);
         }
+        NeutronUtils.createPortStatus(input.getUuid().getValue(), portStatus, dataBroker);
     }
 
     @Override
@@ -150,14 +142,16 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         LOG.trace("Removing Port : key: {}, value={}", identifier, input);
         Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, input.getNetworkId());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
-            //FIXME: This should be removed when support for VLAN and GRE network types is added
-            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of " +
-                    "network {}.", input.getUuid().getValue(), network);
+            String portName = input.getUuid().getValue();
+            LOG.warn("neutron vpn received a port remove() for a network without a provider extension augmentation "
+                            + "or with an unsupported network type for the port {} which is part of network {}",
+                    portName, network);
             return;
         }
         NeutronvpnUtils.removeFromPortCache(input);
+        NeutronUtils.deletePortStatus(input.getUuid().getValue(), dataBroker);
 
-        if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
+        if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
             if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceRemoved(input);
                 /* nothing else to do here */
@@ -176,106 +170,82 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     @Override
     protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
         final String portName = update.getUuid().getValue();
-        LOG.trace("Updating Port : key: {}, original value={}, update value={}", identifier, original, update);
+        LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
         Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, update.getNetworkId());
+        LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
-            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of " +
-                    "network {}. Skipping the processing of Port update DCN", portName, network);
+            LOG.error("neutron vpn received a port update() for a network without a provider extension augmentation "
+                    + "or with an unsupported network type for the port {} which is part of network {}",
+                    portName, network);
             return;
         }
         NeutronvpnUtils.addToPortCache(update);
 
-        /* check if router interface has been updated */
-        if ((update.getDeviceOwner() != null) && (update.getDeviceId() != null)) {
+        if ((Strings.isNullOrEmpty(original.getDeviceOwner()) || Strings.isNullOrEmpty(original.getDeviceId())
+                || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equalsIgnoreCase(original.getDeviceId()))
+                && !Strings.isNullOrEmpty(update.getDeviceOwner()) && !Strings.isNullOrEmpty(update.getDeviceId())) {
             if (update.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceAdded(update);
-                /* nothing else to do here */
                 return;
             }
+            if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
+                handleRouterGatewayUpdated(update);
+            } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
+                handleFloatingIpPortUpdated(original, update);
+            }
+        } else {
+            Set<FixedIps> oldIPs = getFixedIpSet(original.getFixedIps());
+            Set<FixedIps> newIPs = getFixedIpSet(update.getFixedIps());
+            if (!oldIPs.equals(newIPs)) {
+                handleNeutronPortUpdated(original, update);
+            }
         }
 
-        // check if VIF type updated as part of port binding
         // check if port security enabled/disabled as part of port update
-        boolean isPortVifTypeUpdated = NeutronvpnUtils.isPortVifTypeUpdated(original, update);
         boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(original);
         boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(update);
 
-        if (isPortVifTypeUpdated || origSecurityEnabled || updatedSecurityEnabled) {
+        if (origSecurityEnabled || updatedSecurityEnabled) {
             InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
             final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-            portDataStoreCoordinator.enqueueJob("PORT- " + portName, new Callable<List<ListenableFuture<Void>>>() {
-                @Override
-                public List<ListenableFuture<Void>> call() throws Exception {
-                    WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                    try {
-                        Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
-                                .CONFIGURATION, interfaceIdentifier);
-                        if (optionalInf.isPresent()) {
-                            InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
-                            if (isPortVifTypeUpdated && getParentRefsBuilder(update) != null) {
-                                interfaceBuilder.addAugmentation(ParentRefs.class, getParentRefsBuilder(update).build
-                                        ());
-                            }
-                            if (origSecurityEnabled || updatedSecurityEnabled) {
-                                InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
-                                        origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
-                                interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
-                            }
-                            LOG.info("Of-port-interface updation for port {}", portName);
-                            // Update OFPort interface for this neutron port
-                            wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
-                                    interfaceBuilder.build());
-                        } else {
-                            LOG.error("Interface {} is not present", portName);
-                        }
-                    } catch (Exception e) {
-                        LOG.error("Failed to update interface {} due to the exception {}", portName, e);
+            portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                try {
+                    Optional<Interface> optionalInf =
+                            SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                                    interfaceIdentifier);
+                    if (optionalInf.isPresent()) {
+                        InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
+                        InterfaceAcl infAcl = handlePortSecurityUpdated(dataBroker, original, update,
+                                origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
+                        interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+                        LOG.info("update: Of-port-interface updation for port {}", portName);
+                        // Update OFPort interface for this neutron port
+                        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
+                                interfaceBuilder.build());
+                    } else {
+                        LOG.warn("update: Interface {} is not present", portName);
                     }
-                    List<ListenableFuture<Void>> futures = new ArrayList<>();
-                    futures.add(wrtConfigTxn.submit());
-                    return futures;
+                } catch (ReadFailedException e) {
+                    LOG.error("update: Failed to update interface {}", portName, e);
                 }
+                List<ListenableFuture<Void>> futures = new ArrayList<>();
+                futures.add(wrtConfigTxn.submit());
+                return futures;
             });
         }
-        List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<FixedIps>();
-        List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<FixedIps>();
-        if (!oldIPs.equals(newIPs)) {
-            Iterator<FixedIps> iterator = newIPs.iterator();
-            while (iterator.hasNext()) {
-                FixedIps ip = iterator.next();
-                if (oldIPs.remove(ip)) {
-                    iterator.remove();
-                }
-            }
-            handleNeutronPortUpdated(original, update);
-        }
-        if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
-            handleRouterGatewayUpdated(update);
-        } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
+    }
+
+    private void handleFloatingIpPortUpdated(Port original, Port update) {
+        if (((original == null) || (original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)))
+            && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+            // populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
+            // fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
+            addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
+                    .getSubnetId(), update.getMacAddress().getValue());
             elanService.handleKnownL3DmacAddress(update.getMacAddress().getValue(), update.getNetworkId().getValue(),
                     NwConstants.ADD_FLOW);
         }
-        // check for QoS updates
-        QosPortExtension updateQos = update.getAugmentation(QosPortExtension.class);
-        QosPortExtension originalQos = original.getAugmentation(QosPortExtension.class);
-        if (originalQos == null && updateQos != null) {
-            // qos policy add
-            NeutronvpnUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
-            NeutronQosUtils.handleNeutronPortQosUpdate(dataBroker, odlInterfaceRpcService,
-                    update, updateQos.getQosPolicyId());
-        } else if (originalQos != null && updateQos != null
-                && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
-            // qos policy update
-            NeutronvpnUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
-            NeutronvpnUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
-            NeutronQosUtils.handleNeutronPortQosUpdate(dataBroker, odlInterfaceRpcService,
-                    update, updateQos.getQosPolicyId());
-        } else if (originalQos != null && updateQos == null) {
-            // qos policy delete
-            NeutronQosUtils.handleNeutronPortQosRemove(dataBroker, odlInterfaceRpcService,
-                    original, originalQos.getQosPolicyId());
-            NeutronvpnUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
-        }
     }
 
     private void handleRouterInterfaceAdded(Port routerPort) {
@@ -287,29 +257,41 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
                     NwConstants.ADD_FLOW);
             if (existingVpnId == null) {
+                Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
+                List<Subnetmap> subnetMapList = new ArrayList<>();
+                if (vpnId == null) {
+                    vpnId = routerId;
+                }
                 for (FixedIps portIP : routerPort.getFixedIps()) {
-                    Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
-                    if (vpnId == null) {
-                        vpnId = routerId;
-                    }
-                    // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIPs
+                    // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIP
                     // and addSubnetToVpn here
                     String ipValue = String.valueOf(portIP.getIpAddress().getValue());
-                    nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), routerId,
+                    Uuid subnetId = portIP.getSubnetId();
+                    nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId,
                             routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue());
+                    Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, subnetId);
+                    subnetMapList.add(sn);
+                }
+                if (! subnetMapList.isEmpty()) {
+                    nvpnManager.createVpnInterface(vpnId, routerPort, null);
+                }
+                for (FixedIps portIP : routerPort.getFixedIps()) {
+                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                     nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId());
-                    nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
-                    PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
                     LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}",
                             ipValue, routerPort.getMacAddress(),
                             routerPort.getUuid().getValue(), vpnId.getValue());
-                    // ping responder for router interfaces
-                    nvpnManager.createVpnInterface(vpnId, routerId, routerPort, null);
                 }
+                nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
+                createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
+                wrtConfigTxn.submit();
+                PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
             } else {
-                LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {} already" +
-                        " associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId
-                        .getValue(), existingVpnId.getValue());
+                LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {} already"
+                    + " associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
+                    routerId.getValue(), existingVpnId.getValue());
             }
         }
     }
@@ -321,22 +303,37 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
             elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
                     NwConstants.DEL_FLOW);
+            List<Subnetmap> subnetMapList = new ArrayList<>();
+            Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
+            if (vpnId == null) {
+                vpnId = routerId;
+            }
+            for (FixedIps portIP : routerPort.getFixedIps()) {
+                Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, portIP.getSubnetId());
+                subnetMapList.add(sn);
+            }
+            /* Remove ping responder for router interfaces
+             *  A router interface reference in a VPN will have to be removed before the host interface references
+             * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
+             *  is not the last entry to be removed for that subnet in the VPN.
+             *  If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
+             *  interface references in the vpn will already have been cleared, which will cause failures in
+             *  cleanup of router interface flows*/
+            nvpnManager.deleteVpnInterface(vpnId, routerPort, null);
             for (FixedIps portIP : routerPort.getFixedIps()) {
-                Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
-                if(vpnId == null) {
-                    vpnId = routerId;
-                }
                 // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
-                // and updateSubnetNodeWithFixedIPs
+                // and updateSubnetNodeWithFixedIP
                 nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId());
-                nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), null,
+                nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null,
                         null, null, null);
+                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+                deleteElanInterface(routerPort.getUuid().getValue(), wrtConfigTxn);
+                deleteOfPortInterface(routerPort, wrtConfigTxn);
+                wrtConfigTxn.submit();
                 nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
                 String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                 NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnId.getValue(),
                         ipValue, null /*writeTransaction*/);
-                // ping responder for router interfaces
-                nvpnManager.deleteVpnInterface(vpnId, routerId, routerPort, null);
             }
         }
     }
@@ -349,143 +346,153 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
         Router router = NeutronvpnUtils.getNeutronRouter(dataBroker, routerId);
         if (router == null) {
-            LOG.warn("No router found for router GW port {} router id {}", routerGwPort.getUuid(), routerId.getValue());
+            LOG.error("No router found for router GW port {} for router {}", routerGwPort.getUuid().getValue(),
+                    routerId.getValue());
             return;
         }
-        nvpnNatManager.addExternalRouter(router, dataBroker);
         gwMacResolver.sendArpRequestsToExtGateways(router);
     }
 
     private void handleNeutronPortCreated(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final Uuid subnetId = port.getFixedIps().get(0).getSubnetId();
+        final List<FixedIps> portIpAddrsList = port.getFixedIps();
         final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-        portDataStoreCoordinator.enqueueJob("PORT- " + portName, new Callable<List<ListenableFuture<Void>>>() {
-            @Override
-            public List<ListenableFuture<Void>> call() throws Exception {
-                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
-
-                // add direct port to subnetMaps config DS
-                if (!NeutronUtils.isPortVnicTypeNormal(port)) {
-                    nvpnManager.updateSubnetmapNodeWithPorts(subnetId, null, portId);
-                    LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
+        if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
+            return;
+        }
+        portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
+            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+            List<ListenableFuture<Void>> futures = new ArrayList<>();
+            // add direct port to subnetMaps config DS
+            if (!NeutronUtils.isPortVnicTypeNormal(port)) {
+                for (FixedIps ip: portIpAddrsList) {
+                    nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
                     futures.add(wrtConfigTxn.submit());
-                    return futures;
                 }
-                LOG.info("Of-port-interface creation for port {}", portName);
-                // Create of-port interface for this neutron port
-                String portInterfaceName = createOfPortInterface(port, wrtConfigTxn);
-                LOG.debug("Creating ELAN Interface for port {}", portName);
-                createElanInterface(port, portInterfaceName, wrtConfigTxn);
-
-                Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(subnetId, portId, null);
-                Uuid vpnId = (subnetMap != null) ? subnetMap.getVpnId() : null;
-                Uuid routerId = (subnetMap != null) ? subnetMap.getRouterId() : null;
-                if (vpnId != null) {
-                    // create vpn-interface on this neutron port
-                    LOG.debug("Adding VPN Interface for port {}", portName);
-                    nvpnManager.createVpnInterface(vpnId, routerId, port, wrtConfigTxn);
-                }
-                futures.add(wrtConfigTxn.submit());
+                LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
                 return futures;
             }
+            LOG.info("Of-port-interface creation for port {}", portName);
+            // Create of-port interface for this neutron port
+            String portInterfaceName = createOfPortInterface(port, wrtConfigTxn);
+            LOG.debug("Creating ELAN Interface for port {}", portName);
+            createElanInterface(port, portInterfaceName, wrtConfigTxn);
+            Uuid vpnId = null;
+            for (FixedIps ip: portIpAddrsList) {
+                Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
+                if (subnetMap != null && subnetMap.getVpnId() != null) {
+                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
+                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
+                    vpnId = subnetMap.getVpnId();
+                }
+            }
+            if (vpnId != null) {
+                // create new vpn-interface for neutron port
+                LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName,
+                           port.getNetworkId().toString());
+                nvpnManager.createVpnInterface(vpnId, port, wrtConfigTxn);
+            }
+            futures.add(wrtConfigTxn.submit());
+            return futures;
         });
     }
 
     private void handleNeutronPortDeleted(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final Uuid subnetId = port.getFixedIps().get(0).getSubnetId();
+        final List<FixedIps> portIpsList = port.getFixedIps();
         final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-        portDataStoreCoordinator.enqueueJob("PORT- " + portName, new Callable<List<ListenableFuture<Void>>>() {
-            @Override
-            public List<ListenableFuture<Void>> call() throws Exception {
-                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
-
-                // remove direct port from subnetMaps config DS
-                if (!NeutronUtils.isPortVnicTypeNormal(port)) {
-                    nvpnManager.removePortsFromSubnetmapNode(subnetId, null, portId);
-                    LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
+        portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
+            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+            List<ListenableFuture<Void>> futures = new ArrayList<>();
+            if (!NeutronUtils.isPortVnicTypeNormal(port)) {
+                for (FixedIps ip: portIpsList) {
+                    // remove direct port from subnetMaps config DS
+                    nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
                     futures.add(wrtConfigTxn.submit());
-                    return futures;
                 }
-                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(subnetId, portId, null);
-                Uuid vpnId = (subnetMap != null) ? subnetMap.getVpnId() : null;
-                Uuid routerId = (subnetMap != null) ? subnetMap.getRouterId() : null;
-                if (vpnId != null) {
-                    // remove vpn-interface for this neutron port
-                    LOG.debug("removing VPN Interface for port {}", portName);
-                    nvpnManager.deleteVpnInterface(vpnId, routerId, port, wrtConfigTxn);
-                }
-                // Remove of-port interface for this neutron port
-                // ELAN interface is also implicitly deleted as part of this operation
-                LOG.debug("Of-port-interface removal for port {}", portName);
-                deleteOfPortInterface(port, wrtConfigTxn);
-                //dissociate fixedIP from floatingIP if associated
-                nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
-                futures.add(wrtConfigTxn.submit());
+                LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
                 return futures;
             }
+            Uuid vpnId = null;
+            for (FixedIps ip: portIpsList) {
+                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
+                if (subnetMap != null && subnetMap.getVpnId() != null) {
+                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
+                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
+                    vpnId = subnetMap.getVpnId();
+                }
+            }
+            if (vpnId != null) {
+                // remove vpn-interface for this neutron port
+                LOG.debug("removing VPN Interface for port {}", portName);
+                nvpnManager.deleteVpnInterface(vpnId, port, wrtConfigTxn);
+            }
+            // Remove of-port interface for this neutron port
+            // ELAN interface is also implicitly deleted as part of this operation
+            LOG.debug("Of-port-interface removal for port {}", portName);
+            deleteOfPortInterface(port, wrtConfigTxn);
+            //dissociate fixedIP from floatingIP if associated
+            nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
+            futures.add(wrtConfigTxn.submit());
+            return futures;
         });
     }
 
+
     private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
-        if (portoriginal.getFixedIps() == null || portoriginal.getFixedIps().isEmpty()) {
+        final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
+        final List<FixedIps> portupdateIps = portupdate.getFixedIps();
+        LOG.trace("PORT ORIGINAL: {} from network {} with fixed IPs: {}; "
+                    + "PORT UPDATE: {} from network {} with fixed IPs: {}",
+                    portoriginal.getName(), portoriginal.getNetworkId().toString(), portoriginalIps.toString(),
+                    portupdate.getName(), portupdate.getNetworkId().toString(), portupdateIps.toString());
+        if (portoriginalIps == null || portoriginalIps.isEmpty()) {
             handleNeutronPortCreated(portupdate);
             return;
         }
-
-        if (portupdate.getFixedIps() == null || portupdate.getFixedIps().isEmpty()) {
-            LOG.debug("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled "
+        if (portupdateIps == null || portupdateIps.isEmpty()) {
+            LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled "
                       + "during subnet deletion event.", portupdate.getUuid().getValue());
             return;
         }
-
         final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-        portDataStoreCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), new
-                Callable<List<ListenableFuture<Void>>>() {
-                    @Override
-                    public List<ListenableFuture<Void>> call() throws Exception {
-                        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
-                        List<ListenableFuture<Void>> futures = new ArrayList<>();
-
-                        Uuid vpnIdNew = null;
-                        final Uuid subnetIdOr = portupdate.getFixedIps().get(0).getSubnetId();
-                        final Uuid subnetIdUp = portupdate.getFixedIps().get(0).getSubnetId();
-                        // check if subnet UUID has changed upon change in fixedIP
-                        final Boolean subnetUpdated = subnetIdUp.equals(subnetIdOr) ? false : true;
-
-                        if (subnetUpdated) {
-                            Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(subnetIdOr, portoriginal
-                                    .getUuid(), null);
-                            Uuid vpnIdOld = (subnetMapOld != null) ? subnetMapOld.getVpnId() : null;
-                            Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(subnetIdUp, portupdate
-                                            .getUuid(), null);
-                            vpnIdNew = (subnetMapNew != null) ? subnetMapNew.getVpnId() : null;
-                        }
-                        if (!subnetUpdated) {
-                            Subnetmap subnetmap = NeutronvpnUtils.getSubnetmap(dataBroker, subnetIdUp);
-                            vpnIdNew = subnetmap.getVpnId();
-                        }
-                        if (vpnIdNew != null) {
-                            // remove vpn-interface for this neutron port
-                            LOG.debug("removing VPN Interface for port {}", portupdate.getUuid().getValue());
-                            nvpnManager.deleteVpnInterface(vpnIdNew, null, portupdate, wrtConfigTxn);
-                            // create vpn-interface on this neutron port
-                            LOG.debug("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
-                            nvpnManager.createVpnInterface(vpnIdNew, null, portupdate, wrtConfigTxn);
-                        }
-                        futures.add(wrtConfigTxn.submit());
-                        return futures;
-                    }
-                });
+        portDataStoreCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> {
+            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+            List<ListenableFuture<Void>> futures = new ArrayList<>();
+            final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(ip -> ip.getSubnetId())
+                    .collect(Collectors.toList());
+            final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(ip -> ip.getSubnetId())
+                    .collect(Collectors.toList());
+            for (Uuid snId: originalSnMapsIds) {
+                if (!updateSnMapsIds.remove(snId)) {
+                    // snId was present in originalSnMapsIds, but not in updateSnMapsIds
+                    nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
+                }
+            }
+            for (Uuid snId: updateSnMapsIds) {
+                nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
+            }
+            final Uuid oldVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portoriginal.getNetworkId());
+            if (oldVpnId != null) {
+                LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
+                nvpnManager.deleteVpnInterface(oldVpnId, portoriginal, wrtConfigTxn);
+                futures.add(wrtConfigTxn.submit());
+            }
+            final Uuid newVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portupdate.getNetworkId());
+            if (newVpnId != null) {
+                LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
+                nvpnManager.createVpnInterface(newVpnId, portupdate, wrtConfigTxn);
+                futures.add(wrtConfigTxn.submit());
+            }
+            return futures;
+        });
     }
 
-    private static InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal, Port portUpdated, boolean
-            origSecurityEnabled, boolean updatedSecurityEnabled, InterfaceBuilder interfaceBuilder) {
+    private static InterfaceAclBuilder handlePortSecurityUpdated(DataBroker dataBroker, Port portOriginal,
+            Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
+            InterfaceBuilder interfaceBuilder) {
         String interfaceName = portUpdated.getUuid().getValue();
         InterfaceAclBuilder interfaceAclBuilder = null;
         if (origSecurityEnabled != updatedSecurityEnabled) {
@@ -496,8 +503,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, portUpdated);
             } else {
                 // Handle security group disabled
-                interfaceAclBuilder.setSecurityGroups(Lists.newArrayList());
-                interfaceAclBuilder.setAllowedAddressPairs(Lists.newArrayList());
+                interfaceAclBuilder.setSecurityGroups(new ArrayList<>());
+                interfaceAclBuilder.setAllowedAddressPairs(new ArrayList<>());
             }
         } else {
             if (updatedSecurityEnabled) {
@@ -522,37 +529,29 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         Interface inf = createInterface(port);
         String infName = inf.getName();
 
-        LOG.debug("Creating OFPort Interface {}", infName);
         InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
         try {
-            Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                    interfaceIdentifier);
+            Optional<Interface> optionalInf =
+                    SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            interfaceIdentifier);
             if (!optionalInf.isPresent()) {
                 wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
             } else {
-                LOG.error("Interface {} is already present", infName);
+                LOG.warn("Interface {} is already present", infName);
             }
-        } catch (Exception e) {
-            LOG.error("failed to create interface {} due to the exception {} ", infName, e.getMessage());
+        } catch (ReadFailedException e) {
+            LOG.error("failed to create interface {}", infName, e);
         }
         return infName;
     }
 
     private Interface createInterface(Port port) {
-        String parentRefName = NeutronvpnUtils.getVifPortName(port);
         String interfaceName = port.getUuid().getValue();
         IfL2vlan.L2vlanMode l2VlanMode = IfL2vlan.L2vlanMode.Trunk;
         InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
         IfL2vlanBuilder ifL2vlanBuilder = new IfL2vlanBuilder();
-
-        Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, port.getNetworkId());
         ifL2vlanBuilder.setL2vlanMode(l2VlanMode);
 
-        if(parentRefName != null) {
-            ParentRefsBuilder parentRefsBuilder = new ParentRefsBuilder().setParentInterface(parentRefName);
-            interfaceBuilder.addAugmentation(ParentRefs.class, parentRefsBuilder.build());
-        }
-
         interfaceBuilder.setEnabled(true).setName(interfaceName).setType(L2vlan.class)
                 .addAugmentation(IfL2vlan.class, ifL2vlanBuilder.build());
 
@@ -561,6 +560,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             interfaceAclBuilder.setPortSecurityEnabled(true);
             NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, port);
             interfaceBuilder.addAugmentation(InterfaceAcl.class, interfaceAclBuilder.build());
+            NeutronvpnUtils.populateSubnetIpPrefixes(dataBroker, port);
         }
         return interfaceBuilder.build();
     }
@@ -570,55 +570,59 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         LOG.debug("Removing OFPort Interface {}", name);
         InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
         try {
-            Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                    interfaceIdentifier);
+            Optional<Interface> optionalInf =
+                    SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                            interfaceIdentifier);
             if (optionalInf.isPresent()) {
                 wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
             } else {
-                LOG.error("Interface {} is not present", name);
+                LOG.warn("deleteOfPortInterface: Interface {} is not present", name);
             }
-        } catch (Exception e) {
-            LOG.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
+        } catch (ReadFailedException e) {
+            LOG.error("deleteOfPortInterface: Failed to delete interface {}", name, e);
         }
     }
 
-    private ParentRefsBuilder getParentRefsBuilder(Port update) {
-        String parentRefName = NeutronvpnUtils.getVifPortName(update);
-        if (parentRefName != null) {
-            return new ParentRefsBuilder().setParentInterface(parentRefName);
-        }
-        return null;
-    }
-
     private void createElanInterface(Port port, String name, WriteTransaction wrtConfigTxn) {
         String elanInstanceName = port.getNetworkId().getValue();
-        List<PhysAddress> physAddresses = new ArrayList<>();
-        physAddresses.add(new PhysAddress(port.getMacAddress().getValue()));
+        List<StaticMacEntries> staticMacEntries = NeutronvpnUtils.buildStaticMacEntry(port);
 
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
                 .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
-                .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build();
+                .setName(name).setStaticMacEntries(staticMacEntries).setKey(new ElanInterfaceKey(name)).build();
         wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
 
+    private void deleteElanInterface(String name, WriteTransaction wrtConfigTxn) {
+        InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
+                .class, new ElanInterfaceKey(name)).build();
+        wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, id);
+    }
+
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void addToFloatingIpPortInfo(Uuid floatingIpId, Uuid floatingIpPortId, Uuid floatingIpPortSubnetId, String
                                          floatingIpPortMacAddress) {
         InstanceIdentifier id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         try {
             FloatingIpIdToPortMappingBuilder floatingipIdToPortMacMappingBuilder = new
-                    FloatingIpIdToPortMappingBuilder().setKey(new FloatingIpIdToPortMappingKey(floatingIpId))
-                    .setFloatingIpId(floatingIpId).setFloatingIpPortId(floatingIpPortId).setFloatingIpPortSubnetId
-                            (floatingIpPortSubnetId).setFloatingIpPortMacAddress(floatingIpPortMacAddress);
-            LOG.debug("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP" +
-                            " Port Info Config DS", floatingIpId.getValue(), floatingIpPortId.getValue());
+                FloatingIpIdToPortMappingBuilder().setKey(new FloatingIpIdToPortMappingKey(floatingIpId))
+                .setFloatingIpId(floatingIpId).setFloatingIpPortId(floatingIpPortId)
+                .setFloatingIpPortSubnetId(floatingIpPortSubnetId)
+                .setFloatingIpPortMacAddress(floatingIpPortMacAddress);
+            LOG.debug("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP"
+                + " Port Info Config DS", floatingIpId.getValue(), floatingIpPortId.getValue());
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
-                    floatingipIdToPortMacMappingBuilder.build());
+                floatingipIdToPortMacMappingBuilder.build());
         } catch (Exception e) {
-            LOG.error("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP" +
-                    " Port Info Config DS failed with exception {}", floatingIpId.getValue(), floatingIpPortId
-                    .getValue(), e);
+            LOG.error("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP"
+                + " Port Info Config DS failed", floatingIpId.getValue(), floatingIpPortId.getValue(), e);
         }
     }
+
+    private Set<FixedIps> getFixedIpSet(List<FixedIps> fixedIps) {
+        return fixedIps != null ? new HashSet<>(fixedIps) : Collections.emptySet();
+    }
 }