Fix to suppress severity
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / NeutronPortChangeListener.java
index 2c5fd96567eabe99b49564aa1d469e4d1c030f5e..b62774984dc26240791a97e8ef7a6d7aabaf1905 100644 (file)
@@ -15,7 +15,6 @@ import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
-
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -29,6 +28,7 @@ import java.util.stream.Collectors;
 import javax.annotation.PostConstruct;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.ObjectUtils;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -46,12 +46,17 @@ import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.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.rev160406.SplitHorizon;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.SplitHorizonBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 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;
@@ -64,6 +69,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.config.rev160806.NeutronvpnConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.port.id.subport.data.PortIdToSubport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
@@ -90,6 +97,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private final NeutronvpnUtils neutronvpnUtils;
     private final HostConfigCache hostConfigCache;
     private final DataTreeEventCallbackRegistrar eventCallbacks;
+    private final NeutronvpnConfig neutronvpnConfig;
 
     public NeutronPortChangeListener(final DataBroker dataBroker,
                                      final NeutronvpnManager neutronvpnManager,
@@ -99,7 +107,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                                      final JobCoordinator jobCoordinator,
                                      final NeutronvpnUtils neutronvpnUtils,
                                      final HostConfigCache hostConfigCache,
-                                     final DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar) {
+                                     final DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar,
+                                     final NeutronvpnConfig neutronvpnConfig) {
         super(Port.class, NeutronPortChangeListener.class);
         this.dataBroker = dataBroker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
@@ -111,6 +120,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         this.neutronvpnUtils = neutronvpnUtils;
         this.hostConfigCache = hostConfigCache;
         this.eventCallbacks = dataTreeEventCallbackRegistrar;
+        this.neutronvpnConfig = neutronvpnConfig;
+
     }
 
     @Override
@@ -133,6 +144,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
     @Override
     protected void add(InstanceIdentifier<Port> identifier, Port input) {
+        LOG.trace("Received port add event: port={}", input);
         String portName = input.getUuid().getValue();
         LOG.trace("Adding Port : key: {}, value={}", identifier, input);
         Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId());
@@ -152,7 +164,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) {
-                handleRouterGatewayUpdated(input);
+                handleRouterGatewayUpdated(input, false);
                 portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
                 handleFloatingIpPortUpdated(null, input);
@@ -192,6 +204,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             } else if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())
                     || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
+                handleRouterGatewayUpdated(input, true);
                 elanService.removeKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue());
             }
         }
@@ -202,6 +215,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
     @Override
     protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
+        LOG.trace("Received port update event: original={}, update={}", original, update);
         // Switchdev ports need to be bounded to a host before creation
         // in order to validate the supported vnic types from the hostconfig
         if (isPortTypeSwitchdev(original)
@@ -211,7 +225,6 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         }
         final String portName = update.getUuid().getValue();
         Network network = neutronvpnUtils.getNeutronNetwork(update.getNetworkId());
-        LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
         if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
             LOG.warn("neutron vpn received a port update() for a network without a provider extension augmentation "
                     + "or with an unsupported network type for the port {} which is part of network {}",
@@ -228,7 +241,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 return;
             }
             if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
-                handleRouterGatewayUpdated(update);
+                handleRouterGatewayUpdated(update, false);
             } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
                 handleFloatingIpPortUpdated(original, update);
             }
@@ -243,8 +256,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         // check if port security enabled/disabled as part of port update
         boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(original);
         boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(update);
-
-        if (origSecurityEnabled || updatedSecurityEnabled) {
+        boolean isDhcpServerPort = neutronvpnConfig.isLimitBumtrafficToDhcpserver()
+                               && NeutronvpnUtils.isDhcpServerPort(update);
+        if (origSecurityEnabled || updatedSecurityEnabled || isDhcpServerPort) {
             InstanceIdentifier<Interface>  interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
             jobCoordinator.enqueueJob("PORT- " + portName,
                 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
@@ -253,9 +267,18 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                                 confTx.read(interfaceIdentifier).get();
                         if (optionalInf.isPresent()) {
                             InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
-                            InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
-                                    origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
-                            interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+                            if (origSecurityEnabled || updatedSecurityEnabled) {
+                                InterfaceAcl infAcl = handlePortSecurityUpdated(original, update, origSecurityEnabled,
+                                        updatedSecurityEnabled, interfaceBuilder).build();
+                                interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+                            } else if (isDhcpServerPort) {
+                                Set<FixedIps> oldIPs = getFixedIpSet(original.getFixedIps());
+                                Set<FixedIps> newIPs = getFixedIpSet(update.getFixedIps());
+                                if (!oldIPs.equals(newIPs)) {
+                                    InterfaceAcl infAcl = neutronvpnUtils.getDhcpInterfaceAcl(update);
+                                    interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+                                }
+                            }
                             LOG.info("update: Of-port-interface updation for port {}", portName);
                             // Update OFPort interface for this neutron port
                             confTx.put(interfaceIdentifier, interfaceBuilder.build());
@@ -266,9 +289,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         }
     }
 
-    private void handleFloatingIpPortUpdated(Port original, Port update) {
-        if ((original == null || original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING))
-            && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+    private void handleFloatingIpPortUpdated(@Nullable Port original, Port update) {
+        if ((original == null || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(original.getDeviceId())
+                && !NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(update.getDeviceId()))) {
             // populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
             // fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
             addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
@@ -293,16 +316,15 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 listVpnIds.add(vpnId);
                 Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
                 List<Subnetmap> subnetMapList = new ArrayList<>();
-                List<FixedIps> portIps = routerPort.getFixedIps();
                 boolean portIsIpv6 = false;
-                for (FixedIps portIP : portIps) {
+                for (FixedIps portIP : routerPort.nonnullFixedIps()) {
                     // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIP
                     // and addSubnetToVpn here
                     if (internetVpnId != null
                         && portIP.getIpAddress().getIpv6Address() != null) {
                         portIsIpv6 = true;
                     }
-                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+                    String ipValue = portIP.getIpAddress().stringValue();
                     Uuid subnetId = portIP.getSubnetId();
                     nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId,
                             routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
@@ -311,24 +333,21 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 }
                 if (portIsIpv6) {
                     listVpnIds.add(internetVpnId);
-                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(
-                                     IpVersionChoice.IPV6, internetVpnId)) {
-                        neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(),
-                                                                     IpVersionChoice.IPV6, true);
-                        neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
+                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(
+                                     IpVersionChoice.IPV6, routerId, true)) {
+                        neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6,
+                                true);
+                        neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, true);
                     }
                 }
                 if (! subnetMapList.isEmpty()) {
                     nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
                 }
-                for (FixedIps portIP : routerPort.getFixedIps()) {
-                    String ipValue = String.valueOf(portIP.getIpAddress().getValue());
-                    IpVersionChoice version = neutronvpnUtils.getIpVersionFromString(ipValue);
-                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
-                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
-                               version, true);
-                    }
-                    if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
+                IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+                for (FixedIps portIP : routerPort.nonnullFixedIps()) {
+                    String ipValue = portIP.getIpAddress().stringValue();
+                    ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
+                    if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
                         nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(),
                                                         null /* internet-vpn-id */);
                     } else {
@@ -338,8 +357,16 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                             ipValue, routerPort.getMacAddress(),
                             routerPort.getUuid().getValue(), vpnId.getValue());
                 }
+                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, true)) {
+                    LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+                            ipVersion, vpnId.getValue());
+                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+                }
                 nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
-                nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                jobCoordinator.enqueueJob(routerId.toString(), () -> {
+                    nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                    return Collections.emptyList();
+                });
                 ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     confTx -> {
                         String portInterfaceName = createOfPortInterface(routerPort, confTx);
@@ -358,8 +385,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             Uuid routerId = new Uuid(routerPort.getDeviceId());
             Uuid infNetworkId = routerPort.getNetworkId();
             elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
-            Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true), routerId);
-            List<FixedIps> portIps = routerPort.getFixedIps();
+            Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true),
+                    routerId);
+            List<FixedIps> portIps = routerPort.nonnullFixedIps();
             boolean vpnInstanceInternetIpVersionRemoved = false;
             Uuid vpnInstanceInternetUuid = null;
             for (FixedIps portIP : portIps) {
@@ -383,64 +411,75 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
              *  cleanup of router interface flows*/
             nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(),
                                            null /* vpn-id */, null /* wrtConfigTxn*/);
+            final Uuid internetVpnId = vpnInstanceInternetUuid;
             // update RouterInterfaces map
             ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                 confTx -> {
-                    boolean vpnInstanceIpVersionRemoved = false;
-                    IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
+                    IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
                     for (FixedIps portIP : portIps) {
                         Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
                         // router Port have either IPv4 or IPv6, never both
-                        if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
-                            vpnInstanceIpVersionRemoved = true;
-                            vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
-                        }
-                        String ipValue = String.valueOf(portIP.getIpAddress().getValue());
+                        ipVersion = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+                        String ipValue = portIP.getIpAddress().stringValue();
                         neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
                         // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
                         // and updateSubnetNodeWithFixedIP
-                        nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
-                                sn != null ? sn.getInternetVpnId() : null);
+                        nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), internetVpnId);
                         nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null,
                             null, null, null);
                     }
                     nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
                     deleteElanInterface(routerPort.getUuid().getValue(), confTx);
                     deleteOfPortInterface(routerPort, confTx);
-                    nvpnNatManager.handleSubnetsForExternalRouter(routerId);
-                    if (vpnInstanceIpVersionRemoved) {
-                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
-                                false);
+                    jobCoordinator.enqueueJob(routerId.toString(), () -> {
+                        nvpnNatManager.handleSubnetsForExternalRouter(routerId);
+                        return Collections.emptyList();
+                    });
+                    if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, false)) {
+                        LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+                                ipVersion, vpnId.getValue());
+                        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
                     }
                 }), LOG, "Error handling interface removal");
             if (vpnInstanceInternetIpVersionRemoved) {
                 neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
                         IpVersionChoice.IPV6, false);
-                neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
+                neutronvpnUtils.updateVpnInstanceWithFallback(routerId, vpnInstanceInternetUuid, false);
             }
         }
     }
 
-    private void handleRouterGatewayUpdated(Port routerGwPort) {
+    private void handleRouterGatewayUpdated(Port routerGwPort, boolean isRtrGwRemoved) {
         Uuid routerId = new Uuid(routerGwPort.getDeviceId());
         Uuid networkId = routerGwPort.getNetworkId();
         Network network = neutronvpnUtils.getNeutronNetwork(networkId);
         if (network == null) {
             return;
         }
-        boolean isExternal = neutronvpnUtils.getIsExternal(network);
+        boolean isExternal = NeutronvpnUtils.getIsExternal(network);
         if (isExternal) {
             Uuid vpnInternetId = neutronvpnUtils.getVpnForNetwork(networkId);
             if (vpnInternetId != null) {
+                if (!isRtrGwRemoved) {
+                    nvpnManager.updateVpnMaps(vpnInternetId, null, routerId, null, null);
+                }
                 List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
                 for (Subnetmap sn : snList) {
                     if (sn.getNetworkId() == networkId) {
                         continue;
                     }
-                    if (neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
+                    if (NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
                         continue;
                     }
-                    nvpnManager.addSubnetToVpn(null, sn.getId(), vpnInternetId);
+                    if (isRtrGwRemoved) {
+                        nvpnManager.removeV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+                    } else {
+                        nvpnManager.addV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+                    }
+                }
+                //Update Internet BGP-VPN
+                if (isRtrGwRemoved) {
+                    nvpnManager.updateVpnMaps(vpnInternetId, null, null, null, null);
                 }
             }
         }
@@ -465,8 +504,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
     private void setupGwMac(Router router, Port routerGwPort, Uuid routerId) {
         gwMacResolver.sendArpRequestsToExtGateways(router);
-        setExternalGwMac(routerGwPort, routerId);
-
+        jobCoordinator.enqueueJob(routerId.toString(), () -> {
+            setExternalGwMac(routerGwPort, routerId);
+            return Collections.emptyList();
+        });
     }
 
     private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
@@ -489,6 +530,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
     }
 
+    @Nullable
     private String getPortHostId(final Port port) {
         if (port != null) {
             PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
@@ -499,6 +541,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return null;
     }
 
+    @Nullable
     private Hostconfig getHostConfig(final Port port) {
         String hostId = getPortHostId(port);
         if (hostId == null) {
@@ -511,7 +554,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             LOG.error("failed to read host config from host {}", hostId, e);
             return null;
         }
-        return hostConfig.isPresent() ? hostConfig.get() : null;
+        return hostConfig.orNull();
     }
 
     private boolean isPortBound(final Port port) {
@@ -526,7 +569,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             return false;
         }
         String vnicType = portBinding.getVnicType().trim().toLowerCase(Locale.getDefault());
-        return vnicType.equals(NeutronConstants.VNIC_TYPE_DIRECT);
+        return NeutronConstants.VNIC_TYPE_DIRECT.equals(vnicType);
     }
 
     private boolean isSupportedVnicTypeByHost(final Port port, final String vnicType) {
@@ -538,13 +581,14 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return false;
     }
 
+    @Nullable
     private Map<String, JsonElement> unmarshal(final String profile) {
         if (null == profile) {
             return null;
         }
         Gson gson = new Gson();
         JsonObject jsonObject = gson.fromJson(profile, JsonObject.class);
-        Map<String, JsonElement> map = new HashMap();
+        Map<String, JsonElement> map = new HashMap<>();
         for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
             map.put(entry.getKey(), entry.getValue());
         }
@@ -581,15 +625,15 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortCreated(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpAddrsList = port.getFixedIps();
+        final List<FixedIps> portIpAddrsList = port.nonnullFixedIps();
         if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
             return;
         }
         jobCoordinator.enqueueJob("PORT- " + portName, () -> {
             // add direct port to subnetMaps config DS
             if (!(NeutronUtils.isPortVnicTypeNormal(port)
-                || (isPortTypeSwitchdev(port)
-                && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT)))) {
+                || isPortTypeSwitchdev(port)
+                && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT))) {
                 for (FixedIps ip: portIpAddrsList) {
                     nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
                 }
@@ -642,7 +686,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortDeleted(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpsList = port.getFixedIps();
+        final List<FixedIps> portIpsList = port.nonnullFixedIps();
         jobCoordinator.enqueueJob("PORT- " + portName,
             () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                 if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
@@ -674,7 +718,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
                     if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(port.getDeviceOwner())
                         || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(port.getDeviceOwner())) {
-                        String ipAddress = String.valueOf(ip.getIpAddress().getValue());
+                        String ipAddress = ip.getIpAddress().stringValue();
                         if (vpnId != null) {
                             neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipAddress, confTx);
                         }
@@ -717,6 +761,11 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                       + "during subnet deletion event.", portupdate.getUuid().getValue());
             return;
         }
+
+        if (NeutronConstants.IS_ODL_DHCP_PORT.test(portupdate)) {
+            return;
+        }
+
         jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
             () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                 final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
@@ -741,7 +790,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                         }
                     }
                 }
-                Set<Uuid> newVpnIds = new HashSet();
+                Set<Uuid> newVpnIds = new HashSet<>();
                 Set<Uuid> newRouterIds = new HashSet<>();
                 for (Uuid snId: updateSnMapsIds) {
                     Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
@@ -780,6 +829,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             })));
     }
 
+    @Nullable
     private InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal,
             Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
             InterfaceBuilder interfaceBuilder) {
@@ -789,12 +839,12 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             interfaceAclBuilder.setPortSecurityEnabled(updatedSecurityEnabled);
             if (updatedSecurityEnabled) {
                 // Handle security group enabled
-                NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, portUpdated);
-                neutronvpnUtils.populateSubnetInfo(portUpdated);
+                neutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, portUpdated);
             } else {
                 // Handle security group disabled
                 interfaceAclBuilder.setSecurityGroups(new ArrayList<>());
                 interfaceAclBuilder.setAllowedAddressPairs(new ArrayList<>());
+                interfaceAclBuilder.setSubnetInfo(new ArrayList<>());
             }
         } else {
             if (updatedSecurityEnabled) {
@@ -813,7 +863,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
 
                 if (portOriginal.getFixedIps() != null
                         && !portOriginal.getFixedIps().equals(portUpdated.getFixedIps())) {
-                    neutronvpnUtils.populateSubnetInfo(portUpdated);
+                    neutronvpnUtils.populateSubnetInfo(interfaceAclBuilder, portUpdated);
                 }
             }
         }
@@ -850,6 +900,18 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         Boolean isVlanTransparent = network.isVlanTransparent();
         if (isVlanTransparent != null && isVlanTransparent) {
             l2VlanMode = IfL2vlan.L2vlanMode.Transparent;
+        } else {
+            PortIdToSubport portIdToSubport = neutronvpnUtils.getPortIdToSubport(port.getUuid());
+            if (portIdToSubport != null) {
+                l2VlanMode = IfL2vlan.L2vlanMode.TrunkMember;
+                ifL2vlanBuilder.setVlanId(new VlanId(portIdToSubport.getVlanId().intValue()));
+                String parentRefName = portIdToSubport.getTrunkPortId().getValue();
+                ParentRefsBuilder parentRefsBuilder = new ParentRefsBuilder().setParentInterface(parentRefName);
+                interfaceBuilder.addAugmentation(ParentRefs.class, parentRefsBuilder.build());
+                SplitHorizon splitHorizon =
+                        new SplitHorizonBuilder().setOverrideSplitHorizonProtection(true).build();
+                interfaceBuilder.addAugmentation(SplitHorizon.class, splitHorizon);
+            }
         }
 
         ifL2vlanBuilder.setL2vlanMode(l2VlanMode);
@@ -860,9 +922,10 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         if (NeutronvpnUtils.getPortSecurityEnabled(port)) {
             InterfaceAclBuilder interfaceAclBuilder = new InterfaceAclBuilder();
             interfaceAclBuilder.setPortSecurityEnabled(true);
-            NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, port);
+            neutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, port);
             interfaceBuilder.addAugmentation(InterfaceAcl.class, interfaceAclBuilder.build());
-            neutronvpnUtils.populateSubnetInfo(port);
+        } else if (neutronvpnConfig.isLimitBumtrafficToDhcpserver() && NeutronvpnUtils.isDhcpServerPort(port)) {
+            interfaceBuilder.addAugmentation(InterfaceAcl.class, neutronvpnUtils.getDhcpInterfaceAcl(port));
         }
         return interfaceBuilder.build();
     }