Avoid full elan-interface read for gre/vxlan ext-network 80/84280/4
authorChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Mon, 9 Sep 2019 12:07:44 +0000 (17:37 +0530)
committerChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Fri, 8 Nov 2019 12:38:29 +0000 (12:38 +0000)
Description:
To handle flat/vlan provider type use-cases, when the subnet is created,
a NAT listener used to query the full elan-interface and try to identify
specific elan-interfaces associated with physical interfaces.

THis call is not required for every subnet creation and also for
gre/vxlan provider type networks.

Check been added to prevent unnecessary getAllElanInterface call to
prevent bulk read.

Change-Id: Id91797c047e0a45380d1cd0cddf963228fc645ac
Signed-off-by: Chetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworkGroupInstaller.java
neutronvpn/api/src/main/yang/neutronvpn.yang
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java

index efb7573568d2dbe6f77586dadfda68bea43a55fd..efa7ed3a3d6b0586b6481e8d989b19d04cae4fc0 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint64;
@@ -86,13 +87,12 @@ public class ExternalNetworkGroupInstaller {
 
         Uuid networkId = subnetMap.getNetworkId();
         Uuid subnetId = subnetMap.getId();
-        if (networkId == null) {
-            LOG.error("installExtNetGroupEntries : No network associated subnet id {}", subnetId.getValue());
-            return;
+        NetworkAttributes.NetworkType extNetworkType = subnetMap.getNetworkType();
+        if (externalGroupInstallationRequiredForExtNetwork(networkId, subnetMap.isExternal(),
+            extNetworkType, subnetId)) {
+            String macAddress = NatUtil.getSubnetGwMac(broker, subnetId, networkId.getValue());
+            installExtNetGroupEntries(subnetMap, macAddress);
         }
-
-        String macAddress = NatUtil.getSubnetGwMac(broker, subnetId, networkId.getValue());
-        installExtNetGroupEntries(subnetMap, macAddress);
     }
 
     public void installExtNetGroupEntries(Uuid subnetId, String macAddress) {
@@ -107,13 +107,13 @@ public class ExternalNetworkGroupInstaller {
                     subnetMap.getId());
             return;
         }
-        installExtNetGroupEntries(subnetMap, macAddress);
+        if (externalGroupInstallationRequiredForExtNetwork(subnetMap.getNetworkId(), subnetMap.isExternal(),
+            subnetMap.getNetworkType(), subnetId)) {
+            installExtNetGroupEntries(subnetMap, macAddress);
+        }
     }
 
     public void installExtNetGroupEntries(Uuid networkId, Uint64 dpnId) {
-        if (networkId == null) {
-            return;
-        }
 
         List<Uuid> subnetIds = NatUtil.getSubnetIdsFromNetworkId(broker, networkId);
         if (subnetIds.isEmpty()) {
@@ -165,22 +165,32 @@ public class ExternalNetworkGroupInstaller {
     }
 
     public void installExtNetGroupEntry(Uuid networkId, Uuid subnetId, Uint64 dpnId, String macAddress) {
-        String subnetName = subnetId.getValue();
-        String extInterface = elanService.getExternalElanInterface(networkId.getValue(), dpnId);
-        if (extInterface == null) {
-            LOG.warn("installExtNetGroupEntry : No external ELAN interface attached to network {} subnet {} DPN id {}",
-                    networkId, subnetName, dpnId);
-            //return;
+        Subnetmap subnetMap = NatUtil.getSubnetMap(broker, subnetId);
+        if (subnetMap == null) {
+            LOG.error("installExtNetGroupEntries : Subnetmap is null");
+            return;
         }
-        Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+        if (externalGroupInstallationRequiredForExtNetwork(networkId, subnetMap.isExternal(),
+            subnetMap.getNetworkType(), subnetId)) {
+            String subnetName = subnetId.getValue();
+            String extInterface = elanService.getExternalElanInterface(networkId.getValue(), dpnId);
+            if (extInterface == null) {
+                LOG.warn(
+                    "installExtNetGroupEntry : No external ELAN interface attached to network {} subnet {} DPN id {}",
+                    networkId, subnetName, dpnId);
+                //return;
+            }
+            Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
                 NatUtil.getGroupIdKey(subnetName));
-        if (groupId != NatConstants.INVALID_ID) {
-            LOG.info(
-                "installExtNetGroupEntry : Installing ext-net group {} entry for subnet {} with macAddress {} "
-                    + "(extInterface: {})", groupId, subnetName, macAddress, extInterface);
-            installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpnId);
-        } else {
-            LOG.error("installExtNetGroupEntry: Unable to get groupId for subnet:{}", subnetName);
+            if (groupId != NatConstants.INVALID_ID) {
+                LOG.info(
+                    "installExtNetGroupEntry : Installing ext-net group {} entry for subnet {} with macAddress {} "
+                        + "(extInterface: {})", groupId, subnetName, macAddress, extInterface);
+                installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpnId);
+            } else {
+                LOG.error("installExtNetGroupEntry: Unable to get groupId for subnet:{}",
+                    subnetName);
+            }
         }
     }
 
@@ -201,33 +211,35 @@ public class ExternalNetworkGroupInstaller {
 
         String subnetName = subnetMap.getId().getValue();
         Uuid networkId = subnetMap.getNetworkId();
-        if (networkId == null) {
-            LOG.error("removeExtNetGroupEntries : No external network associated subnet id {}", subnetName);
-            return;
-        }
-
-        Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
-        if (extInterfaces == null || extInterfaces.isEmpty()) {
-            LOG.debug("removeExtNetGroupEntries : No external ELAN interfaces attached to network {} subnet {}",
+        NetworkAttributes.NetworkType extNetworkType = subnetMap.getNetworkType();
+        if (externalGroupInstallationRequiredForExtNetwork(networkId, subnetMap.isExternal(),
+            extNetworkType, subnetMap.getId())) {
+            Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
+            if (extInterfaces == null || extInterfaces.isEmpty()) {
+                LOG.debug(
+                    "removeExtNetGroupEntries : No external ELAN interfaces attached to network {} subnet {}",
                     networkId, subnetName);
-            return;
-        }
+                return;
+            }
 
-        Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+            Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
                 NatUtil.getGroupIdKey(subnetName));
-        if (groupId != NatConstants.INVALID_ID) {
-            for (String extInterface : extInterfaces) {
-                GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId,
-                    extInterface);
-                if (groupEntity != null) {
-                    LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}",
-                        groupId, subnetName);
-                    natServiceCounters.removeExternalNetworkGroup();
-                    mdsalManager.syncRemoveGroup(groupEntity);
+            if (groupId != NatConstants.INVALID_ID) {
+                for (String extInterface : extInterfaces) {
+                    GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId,
+                        extInterface);
+                    if (groupEntity != null) {
+                        LOG.info(
+                            "removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}",
+                            groupId, subnetName);
+                        natServiceCounters.removeExternalNetworkGroup();
+                        mdsalManager.syncRemoveGroup(groupEntity);
+                    }
                 }
+            } else {
+                LOG.error("removeExtNetGroupEntries: Unable to get groupId for subnet:{}",
+                    subnetName);
             }
-        } else {
-            LOG.error("removeExtNetGroupEntries: Unable to get groupId for subnet:{}", subnetName);
         }
     }
 
@@ -276,4 +288,24 @@ public class ExternalNetworkGroupInstaller {
         return MDSALUtil.buildGroupEntity(dpId, groupId.longValue(), subnetName,
                 GroupTypes.GroupAll, new ArrayList<>());
     }
+
+    private boolean externalGroupInstallationRequiredForExtNetwork(Uuid networkId, boolean isExternal,
+        NetworkAttributes.NetworkType extNetworkType,
+        Uuid subnetId) {
+        if (networkId == null || !isExternal) {
+            LOG.debug("externalGroupInstallationRequiredForExtNetwork : network is null or not External Network:{} for"
+                + " subnet id {}", isExternal, subnetId.getValue());
+            return false;
+        }
+        // Installation of External Network Group is only required for flat/vlan use-cases.
+        if (extNetworkType == null
+            || extNetworkType == NetworkAttributes.NetworkType.GRE
+            || extNetworkType == NetworkAttributes.NetworkType.VXLAN) {
+            LOG.debug("Provider Type is either null or of type {} for network {}, subnet {} for which "
+                    + "ExternalNetwork Group installation not required",
+                extNetworkType, networkId.getValue(), subnetId.getValue());
+            return false;
+        }
+        return true;
+    }
 }
index 74bd4a4b5aa615e83b81d069069ed6044617c909..7489055842c4333d9e5f4957934f54ff2e46b2fc 100644 (file)
@@ -163,6 +163,7 @@ module neutronvpn {
                 If segment-type is vxlan, this ID is a vni.
                 If segment-type is flat/gre, this ID is set to 0";
         }
+        leaf external { type boolean; default false;}
     }
 
     container vpnMaps {
index d618f171266c6628604aa14321cef97afad7c9a4..7a5cce78df9ec8c6a81f48f173885e12b979f0e5 100644 (file)
@@ -121,9 +121,10 @@ public class NeutronSubnetChangeListener extends AsyncDataTreeChangeListenerBase
         Uuid subnetId = subnet.getUuid();
         ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(network);
         String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(network);
+        boolean isExternalNetwork = NeutronvpnUtils.getIsExternal(network);
         nvpnManager.createSubnetmapNode(subnetId, subnet.getCidr().stringValue(), subnet.getTenantId(), networkId,
                 providerType != null ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null,
-                segmentationId != null ? Long.parseLong(segmentationId) : 0L);
+                segmentationId != null ? Long.parseLong(segmentationId) : 0L, isExternalNetwork);
         createSubnetToNetworkMapping(subnetId, networkId);
     }
 
index da151f6828c6cd491db86071a5490f595669c399..3ddc234da49939583b2849f816eb99843441b549 100644 (file)
@@ -267,7 +267,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId,
-                                       NetworkAttributes.@Nullable NetworkType networkType, long segmentationId) {
+                                       NetworkAttributes.@Nullable NetworkType networkType, long segmentationId,
+                                        boolean isExternalNw) {
         try {
             InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
             final ReentrantLock lock = lockForUuid(subnetId);
@@ -283,7 +284,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
                 SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().withKey(new SubnetmapKey(subnetId))
                         .setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId)
-                        .setNetworkType(networkType).setSegmentationId(segmentationId);
+                        .setNetworkType(networkType).setSegmentationId(segmentationId).setExternal(isExternalNw);
                 LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}",
                     subnetId.getValue());
                 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,