VpnEngine: Robust handling of (lock, ID allocation/release) failures 64/87464/7
authorYenuganti Vasudha <yenuganti.vasudha@ericsson.com>
Thu, 6 Feb 2020 08:07:26 +0000 (13:37 +0530)
committerKarthikeyan Krishnan <karthikeyangceb007@gmail.com>
Wed, 12 Feb 2020 11:26:30 +0000 (11:26 +0000)
Signed-off-by: Yenuganti Vasudha <yenuganti.vasudha@ericsson.com>
Change-Id: Ie3ff8d197c96cbf5a2a5d91e55708cd228a1d22c

natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnInterfaceManager.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnRpcServiceImpl.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnSubnetRouteHandler.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/iplearn/LearntVpnVipToPortEventProcessor.java

index 7a4f5ed514a9d95fe3683de5b37aa8b1caf9842a..1aaac13b3f0c0b9742e4e29c13af83503881d1eb 100644 (file)
@@ -13,8 +13,10 @@ import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
+
 import java.math.BigInteger;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -2395,7 +2397,16 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                         NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
                         RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
                             .setVpnName(externalVpn).setIpPrefix(externalIp).build();
-                        return vpnService.removeVpnLabel(labelInput);
+                        Future<RpcResult<RemoveVpnLabelOutput>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
+                        if (labelFuture1.get() == null || !labelFuture1.get().isSuccessful()) {
+                            String errMsg = String.format(
+                                    "ExternalRoutersListener: RPC call to remove VPN label "
+                                            + "on dpn %s for prefix %s failed for vpn %s - %s",
+                                    dpnId, externalIp, result.getErrors());
+                            LOG.error(errMsg);
+                            return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+                        }
+                        return JdkFutureAdapters.listenInPoolThread(labelFuture1);
                     } else {
                         String errMsg =
                             String.format("RPC call to remove custom FIB entries on dpn %s for "
@@ -2499,7 +2510,17 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                         if (result.isSuccessful()) {
                             RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
                                     .setVpnName(vpnName).setIpPrefix(externalIp).build();
-                            return vpnService.removeVpnLabel(labelInput);
+                            Future<RpcResult<RemoveVpnLabelOutput>> labelFuture1 = vpnService
+                                    .removeVpnLabel(labelInput);
+                            if (labelFuture1.get() == null || !labelFuture1.get().isSuccessful()) {
+                                String errMsg = String.format(
+                                        "RPC call to remove VPN label on dpn %s for prefix %s "
+                                                + "failed for vpn %s - %s", dpnId, externalIp, vpnName,
+                                        result.getErrors());
+                                LOG.error(errMsg);
+                                return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+                            }
+                            return JdkFutureAdapters.listenInPoolThread(labelFuture1);
                         } else {
                             String errMsg =
                                     String.format("RPC call to remove custom FIB entries on dpn %s for "
index 67767058d7ebc6970cf70fbef19760f5b0fe9fb9..8d1d8a7ff24715c3fa10254ab5e4648876943d30 100644 (file)
@@ -13,13 +13,16 @@ import static org.opendaylight.netvirt.natservice.internal.NatUtil.buildfloating
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNull;
@@ -369,7 +372,16 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
                 removeLFibTableEntry(dpnId, label, confTx);
                 RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
                         .setVpnName(vpnName).setIpPrefix(externalIp).build();
-                return vpnService.removeVpnLabel(labelInput);
+                Future<RpcResult<RemoveVpnLabelOutput>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
+                if (labelFuture1.get() == null || !labelFuture1.get().isSuccessful()) {
+                    String errMsg = String.format(
+                            "VpnFloatingIpHandler: RPC call to remove VPN label on dpn %s "
+                                    + "for prefix %s failed for vpn %s - %s",
+                            dpnId, externalIp, vpnName, result.getErrors());
+                    LOG.error(errMsg);
+                    return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+                }
+                return JdkFutureAdapters.listenInPoolThread(labelFuture1);
             } else {
                 String errMsg = String.format("onRemoveFloatingIp :RPC call to remove custom FIB entries "
                         + "on dpn %s for prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
index 0daf6fd97348dd7e129e367d630b2a94fcb5893f..6c4f6e45cd6e93cc404ba40be741500f8331a736 100755 (executable)
@@ -2172,7 +2172,13 @@ public class VpnInterfaceManager extends AsyncDataTreeChangeListenerBase<VpnInte
 
                 Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
                         VpnUtil.getNextHopLabelKey(primaryRd, prefix));
-
+                if (label.longValue() == VpnConstants.INVALID_LABEL) {
+                    LOG.error(
+                            "createFibEntryForRouterInterface: Unable to retrieve label for vpn pool {}, "
+                                    + "vpninterface {}, vpn {}, rd {}",
+                            VpnConstants.VPN_IDPOOL_NAME, interfaceName, vpnName, primaryRd);
+                    return;
+                }
                 RouterInterface routerInt = new RouterInterfaceBuilder().setUuid(vpnName)
                         .setIpAddress(primaryInterfaceIp).setMacAddress(macAddress).build();
                 fibManager.addFibEntryForRouterInterface(primaryRd, prefix,
index cb02dc10577818d5c6418f9c66432276f182a34a..73f23f197e269d8dfa5f66af0fcff95f50a51820 100644 (file)
@@ -167,6 +167,8 @@ public class VpnManagerImpl implements IVpnManager {
             Future<RpcResult<CreateIdPoolOutput>> result = idManager.createIdPool(createPool);
             if (result != null && result.get().isSuccessful()) {
                 LOG.info("Created IdPool for VPN Service");
+            } else {
+                LOG.error("createIdPool: Unable to create ID pool for VPNService");
             }
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Failed to create idPool for VPN Service", e);
@@ -180,13 +182,15 @@ public class VpnManagerImpl implements IVpnManager {
                 .build();
         try {
             Future<RpcResult<CreateIdPoolOutput>> result = idManager.createIdPool(createPseudoLporTagPool);
-            if (result.get().isSuccessful()) {
+            if (result != null && result.get().isSuccessful()) {
                 LOG.debug("Created IdPool for Pseudo Port tags");
             } else {
-                Collection<RpcError> errors = result.get().getErrors();
                 StringBuilder errMsg = new StringBuilder();
-                for (RpcError err : errors) {
-                    errMsg.append(err.getMessage()).append("\n");
+                if (result != null && result.get() != null) {
+                    Collection<RpcError> errors = result.get().getErrors();
+                    for (RpcError err : errors) {
+                        errMsg.append(err.getMessage()).append("\n");
+                    }
                 }
                 LOG.error("IdPool creation for PseudoPort tags failed. Reasons: {}", errMsg);
             }
@@ -236,7 +240,7 @@ public class VpnManagerImpl implements IVpnManager {
             String dstVpnRd = vpnUtil.getVpnRd(dstVpnUuid);
             Uint32 newLabel = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
                     VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
-            if (newLabel.longValue() == 0) {
+            if (newLabel.longValue() == VpnConstants.INVALID_LABEL) {
                 LOG.error("addExtraRoute: Unable to fetch label from Id Manager. Bailing out of adding intervpnlink"
                         + " route for destination {}", destination);
                 return;
index 762940c8454b5ebd23791a019f4ec47b108c530f..0994ddb216d3c6ad28b45d8f076b8c503ea75d98 100644 (file)
@@ -92,7 +92,7 @@ public class VpnRpcServiceImpl implements VpnRpcService {
         String rd = vpnUtil.getVpnRd(vpnName);
         Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
             VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnName, ipPrefix));
-        if (label == null || label.longValue() == 0) {
+        if (label == null || label.longValue() == VpnConstants.INVALID_LABEL) {
             futureResult.set(RpcResultBuilder.<GenerateVpnLabelOutput>failed().withError(ErrorType.APPLICATION,
                     formatAndLog(LOG::error, "Could not retrieve the label for prefix {} in VPN {}", ipPrefix,
                             vpnName)).build());
@@ -155,13 +155,15 @@ public class VpnRpcServiceImpl implements VpnRpcService {
             return result;
         }
 
-        if (label == null || label.longValue() == 0) {
+        if (label == null || label.longValue() == VpnConstants.INVALID_LABEL) {
             label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
                 VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
-            if (label.longValue() == 0) {
+            if (label.longValue() == VpnConstants.INVALID_LABEL) {
                 String message = "Unable to retrieve a new Label for the new Route";
                 result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION,
                     message).build());
+                LOG.error("addStaticRoute: Unable to retrieve label for static route with destination {}, vpninstance"
+                        + " {}, nexthop {}", destination, vpnInstanceName, nexthop);
                 return result;
             }
         }
index 9a209feb814dc068f5ac2209325854eef1a00a88..2b16bbd9ecec0f664756edafdbba4d764f27022e 100644 (file)
@@ -833,6 +833,11 @@ public class VpnSubnetRouteHandler {
                 l3vni = subOpBuilder.getL3vni();
             } else {
                 label = subOpBuilder.getLabel();
+                if (label.longValue() == VpnConstants.INVALID_LABEL) {
+                    LOG.error("publishSubnetRouteToBgp: Label not found for rd {}, subnetIp {}",
+                            subOpBuilder.getVrfId(), subOpBuilder.getSubnetCidr());
+                    return;
+                }
             }
             bgpManager.advertisePrefix(subOpBuilder.getVrfId(), null /*macAddress*/, subOpBuilder.getSubnetCidr(),
                     Arrays.asList(nextHopIp), encapType,  label, l3vni,
index 24d60342707746d3554314b06afe0a6e8e2438ac..856cd180f723239525522bbae3a38e877878f0a0 100644 (file)
@@ -230,7 +230,7 @@ public class LearntVpnVipToPortEventProcessor
                     String rd = vpnUtil.getVpnRd(vpnInstName);
                     Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
                         VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnInstName, ip));
-                    if (label.longValue() == 0) {
+                    if (label.longValue() == VpnConstants.INVALID_LABEL) {
                         LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {}"
                                 + " to vpn interface {} for vpn {}", ip, vpnInterface, vpnInstName);
                         return;