BUG 9014: Remove unnecessary Log statements for evpn/subnetroute
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / evpn / utils / EvpnUtils.java
index 0a2749725d8233e0ec85ed4900110f497ee547e0..b5468acba1b46caf7c6b2d601ffaf7858a1bed54 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.netvirt.elan.evpn.utils;
 
+import com.google.common.base.Optional;
+
 import java.math.BigInteger;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.function.BiPredicate;
 import java.util.function.Predicate;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -71,13 +74,12 @@ public class EvpnUtils {
         this.bgpManager = bgpManager;
     }
 
-    public boolean isWithdrawEvpnRT2Routes(EvpnAugmentation original, EvpnAugmentation update) {
-        return isNetDetach.test(original.getEvpnName(), update.getEvpnName());
+    public boolean isWithdrawEvpnRT2Routes(ElanInstance original, ElanInstance update) {
+        return isNetDetach.test(getEvpnNameFromElan(original), getEvpnNameFromElan(update));
     }
 
-    public boolean isAdvertiseEvpnRT2Routes(EvpnAugmentation original, EvpnAugmentation update) {
-        return isNetAttach.test(original.getEvpnName(), update.getEvpnName())
-                || isNetAttach.test(original.getL3vpnName(), update.getL3vpnName());
+    public boolean isAdvertiseEvpnRT2Routes(ElanInstance original, ElanInstance update) {
+        return isNetAttach.test(getEvpnNameFromElan(original), getEvpnNameFromElan(update));
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -95,6 +97,10 @@ public class EvpnUtils {
         ElanInstance elanInfo = elanUtils.getElanInstanceByName(broker, elanName);
         macEntries.stream().filter(isIpv4PrefixAvailable).forEach(macEntry -> {
             InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(macEntry.getInterface());
+            if (interfaceInfo == null) {
+                LOG.debug("advertiseEvpnRT2Routes, interfaceInfo is null for interface {}", macEntry.getInterface());
+                return;
+            }
             advertisePrefix(elanInfo, rd, macEntry.getMacAddress().getValue(),
                     macEntry.getIpPrefix().getIpv4Address().getValue(),
                     interfaceInfo.getInterfaceName(), interfaceInfo.getDpId());
@@ -123,30 +129,39 @@ public class EvpnUtils {
         }
 
         List<IpAddress> nexthopIpList = rpcResult.getResult().getNexthopipList();
-        return nexthopIpList.get(0).getIpv4Address().toString();
+        return nexthopIpList.get(0).getIpv4Address().getValue();
     }
 
-    public String getGatewayMacAddressForInterface(String vpnName, String ifName, String ipAddress) {
+    public Optional<String> getGatewayMacAddressForInterface(String vpnName,
+                                                                                    String ifName, String ipAddress) {
         VpnPortipToPort gwPort = vpnManager.getNeutronPortFromVpnPortFixedIp(broker, vpnName, ipAddress);
-        return gwPort != null && gwPort.isSubnetIp()
+        return Optional.of((gwPort != null && gwPort.isSubnetIp())
                 ? gwPort.getMacAddress()
-                : interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName).getMacAddress();
+                : interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName).getMacAddress());
     }
 
     public String getL3vpnNameFromElan(ElanInstance elanInfo) {
+        if (elanInfo == null) {
+            LOG.debug("getL3vpnNameFromElan :elanInfo is NULL");
+            return null;
+        }
         EvpnAugmentation evpnAugmentation = elanInfo.getAugmentation(EvpnAugmentation.class);
         return evpnAugmentation != null ? evpnAugmentation.getL3vpnName() : null;
     }
 
     public static String getEvpnNameFromElan(ElanInstance elanInfo) {
+        if (elanInfo == null) {
+            LOG.debug("getEvpnNameFromElan :elanInfo is NULL");
+            return null;
+        }
         EvpnAugmentation evpnAugmentation = elanInfo.getAugmentation(EvpnAugmentation.class);
         return evpnAugmentation != null ? evpnAugmentation.getEvpnName() : null;
     }
 
-    public String getEVpnRd(ElanInstance elanInfo) {
+    public String getEvpnRd(ElanInstance elanInfo) {
         String evpnName = getEvpnNameFromElan(elanInfo);
         if (evpnName == null) {
-            LOG.error("getEVpnRd : evpnName is NULL for elanInfo {}", elanInfo);
+            LOG.debug("getEvpnRd : evpnName is NULL for elanInfo {}", elanInfo);
             return null;
         }
         return vpnManager.getVpnRd(broker, evpnName);
@@ -154,7 +169,7 @@ public class EvpnUtils {
 
     public void advertisePrefix(ElanInstance elanInfo, String macAddress, String prefix,
                                  String interfaceName, BigInteger dpnId) {
-        String rd = getEVpnRd(elanInfo);
+        String rd = getEvpnRd(elanInfo);
         advertisePrefix(elanInfo, rd, macAddress, prefix, interfaceName, dpnId);
     }
 
@@ -162,12 +177,12 @@ public class EvpnUtils {
     private void advertisePrefix(ElanInstance elanInfo, String rd,
                                  String macAddress, String prefix, String interfaceName, BigInteger dpnId) {
         if (rd == null) {
-            LOG.error("advertisePrefix : rd is NULL for elanInfo {}, macAddress {}", elanInfo, macAddress);
+            LOG.debug("advertisePrefix : rd is NULL for elanInfo {}, macAddress {}", elanInfo, macAddress);
             return;
         }
         String nextHop = getEndpointIpAddressForDPN(dpnId);
         if (nextHop == null) {
-            LOG.error("Failed to get the dpn tep ip for dpn {}", dpnId);
+            LOG.debug("Failed to get the dpn tep ip for dpn {}", dpnId);
             return;
         }
         int vpnLabel = 0;
@@ -178,7 +193,10 @@ public class EvpnUtils {
         if (l3VpName != null) {
             VpnInstance l3VpnInstance = vpnManager.getVpnInstance(broker, l3VpName);
             l3vni = l3VpnInstance.getL3vni();
-            gatewayMacAddr = getGatewayMacAddressForInterface(l3VpName, interfaceName, prefix);
+            com.google.common.base.Optional<String> gatewayMac = getGatewayMacAddressForInterface(l3VpName,
+                    interfaceName, prefix);
+            gatewayMacAddr = gatewayMac.isPresent() ? gatewayMac.get() : null;
+
         }
         LOG.info("Advertising routes with rd {},  macAddress {}, prefix {}, nextHop {},"
                         + " vpnLabel {}, l3vni {}, l2vni {}, gatewayMac {}", rd, macAddress, prefix, nextHop,
@@ -193,6 +211,11 @@ public class EvpnUtils {
 
     public void advertisePrefix(ElanInstance elanInfo, MacEntry macEntry) {
         InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(macEntry.getInterface());
+        if (interfaceInfo == null) {
+            LOG.debug("advertisePrefix, interfaceInfo is null for interface {}", macEntry.getInterface());
+            return;
+        }
+
         if (!isIpv4PrefixAvailable.test(macEntry)) {
             LOG.debug("advertisePrefix macEntry does not have IPv4 prefix {}", macEntry);
             return;
@@ -203,19 +226,20 @@ public class EvpnUtils {
     }
 
     public void withdrawEvpnRT2Routes(EvpnAugmentation evpnAugmentation, String elanName) {
-        LOG.debug("Evpnaugmentation and elanname are {} {}", evpnAugmentation, elanName);
-        if (elanName == null || elanName.isEmpty()) {
-            LOG.error("EvpnUtils: in withdrawEvpnRT2Routes, elanName is {}", elanName);
+        if (evpnAugmentation == null || evpnAugmentation.getEvpnName() == null) {
+            LOG.trace("withdrawEvpnRT2Routes, evpnAugmentation is null");
             return;
         }
-        List<MacEntry> macEntries = elanUtils.getElanMacEntries(elanName);
-        if (macEntries == null || macEntries.isEmpty()) {
-            LOG.trace("withdrawEvpnRT2Routes : macEntries  is empty for elan {} ", elanName);
+
+        String evpnName = evpnAugmentation.getEvpnName();
+        String rd = vpnManager.getVpnRd(broker, evpnName);
+        if (rd == null) {
+            LOG.debug("withdrawEvpnRT2Routes : rd is null ", elanName);
             return;
         }
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
-        String rd = getEVpnRd(elanInfo);
-        if (rd == null) {
+        List<MacEntry> macEntries = elanUtils.getElanMacEntries(elanName);
+        if (macEntries == null || macEntries.isEmpty()) {
+            LOG.debug("withdrawEvpnRT2Routes : macEntries  is empty for elan {} ", elanName);
             return;
         }
         for (MacEntry macEntry : macEntries) {
@@ -230,7 +254,7 @@ public class EvpnUtils {
     }
 
     public void withdrawPrefix(ElanInstance elanInfo, String prefix) {
-        String rd = getEVpnRd(elanInfo);
+        String rd = getEvpnRd(elanInfo);
         if (rd == null) {
             return;
         }