NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / fibmanager / impl / src / main / java / org / opendaylight / netvirt / fibmanager / BaseVrfEntryHandler.java
index d02272020d1d9e47c74349873d9a52844b67cd48..c502c0f6292428b07aa75abaa43fdc8cb8634243 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.netvirt.fibmanager;
 import static java.util.stream.Collectors.toList;
 import static org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address;
 
-import com.google.common.base.Optional;
-import java.math.BigInteger;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -20,12 +18,13 @@ import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import javax.annotation.Nonnull;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
 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.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
@@ -36,7 +35,6 @@ import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
-import org.opendaylight.genius.mdsalutil.UpgradeState;
 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth;
 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp;
 import org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort;
@@ -59,10 +57,15 @@ import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.utils.batching.SubTransaction;
 import org.opendaylight.genius.utils.batching.SubTransactionImpl;
 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult;
 import org.opendaylight.netvirt.fibmanager.api.FibHelper;
 import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
 import org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper;
+import org.opendaylight.serviceutils.upgrade.UpgradeState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -90,15 +93,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.RoutesKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 @Singleton
 public class BaseVrfEntryHandler implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(BaseVrfEntryHandler.class);
-    private static final BigInteger COOKIE_VM_FIB_TABLE =  new BigInteger("8000003", 16);
+    private static final Uint64 COOKIE_VM_FIB_TABLE =  Uint64.valueOf("8000003", 16).intern();
     private static final int DEFAULT_FIB_FLOW_PRIORITY = 10;
 
     private final DataBroker dataBroker;
@@ -144,21 +148,22 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         }
     }
 
-    protected void deleteLocalAdjacency(final BigInteger dpId, final long vpnId, final String ipAddress,
+    protected void deleteLocalAdjacency(final Uint64 dpId, final Uint32 vpnId, final String ipAddress,
                               final String ipPrefixAddress) {
         LOG.trace("deleteLocalAdjacency called with dpid {}, vpnId{}, primaryIpAddress {} currIpPrefix {}",
                 dpId, vpnId, ipAddress, ipPrefixAddress);
         try {
             nextHopManager.removeLocalNextHop(dpId, vpnId, ipAddress, ipPrefixAddress);
         } catch (NullPointerException e) {
-            LOG.trace("", e);
+            // FIXME: NPEs should not be caught but rather their root cause should be eliminated
+            LOG.trace("Failed to remove nexthop", e);
         }
     }
 
-    @Nonnull
-    protected List<AdjacencyResult> resolveAdjacency(final BigInteger remoteDpnId, final long vpnId,
+    @NonNull
+    protected List<AdjacencyResult> resolveAdjacency(final Uint64 remoteDpnId, final Uint32 vpnId,
                                                      final VrfEntry vrfEntry, String rd) {
-        List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
+        List<RoutePaths> routePaths = new ArrayList<>(vrfEntry.nonnullRoutePaths());
         FibHelper.sortIpAddress(routePaths);
         List<AdjacencyResult> adjacencyList = new ArrayList<>();
         List<String> prefixIpList;
@@ -186,15 +191,16 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                     prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
                 } else {
                     List<String> prefixIpListLocal = new ArrayList<>();
-                    vpnExtraRoutes.forEach(route -> route.getNexthopIpList().forEach(extraRouteIp -> {
-                        String ipPrefix;
-                        if (isIpv4Address(extraRouteIp)) {
-                            ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
-                        } else {
-                            ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
-                        }
-                        prefixIpListLocal.add(ipPrefix);
-                    }));
+                    vpnExtraRoutes.stream().filter(route -> route.getNexthopIpList() != null).forEach(
+                        route -> route.getNexthopIpList().forEach(extraRouteIp -> {
+                            String ipPrefix;
+                            if (isIpv4Address(extraRouteIp)) {
+                                ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
+                            } else {
+                                ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
+                            }
+                            prefixIpListLocal.add(ipPrefix);
+                        }));
                     prefixIpList = prefixIpListLocal;
                 }
             } else {
@@ -226,14 +232,17 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                         .collect(toList()));
             }
         } catch (NullPointerException e) {
-            LOG.trace("", e);
+            // FIXME: NPEs should not be caught but rather their root cause should be eliminated
+            LOG.trace("Failed to remove adjacency", e);
         }
         return adjacencyList;
     }
 
-    protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd,
-                            List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx,
-                            List<SubTransaction> subTxns) {
+    // Allow deprecated TransactionRunner calls for now
+    @SuppressWarnings("ForbidCertainMethod")
+    protected void makeConnectedRoute(Uint64 dpId, Uint32 vpnId, VrfEntry vrfEntry, String rd,
+                                      @Nullable List<InstructionInfo> instructions, int addOrRemove,
+                                      WriteTransaction tx, @Nullable List<SubTransaction> subTxns) {
         if (tx == null) {
             ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
                 newTx -> makeConnectedRoute(dpId, vpnId, vrfEntry, rd, instructions, addOrRemove, newTx, subTxns)),
@@ -261,7 +270,8 @@ public class BaseVrfEntryHandler implements AutoCloseable {
 
         List<MatchInfo> matches = new ArrayList<>();
 
-        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
+        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
+            MetaDataUtil.METADATA_MASK_VRFID));
 
         if (destPrefix instanceof Inet4Address) {
             matches.add(MatchEthernetType.IPV4);
@@ -309,8 +319,8 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         }
     }
 
-    protected void addRewriteDstMacAction(long vpnId, VrfEntry vrfEntry, Prefixes prefixInfo,
-                                        List<ActionInfo> actionInfos) {
+    protected void addRewriteDstMacAction(Uint32 vpnId, VrfEntry vrfEntry, @Nullable Prefixes prefixInfo,
+                                          List<ActionInfo> actionInfos) {
         if (vrfEntry.getMac() != null) {
             actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(),
                     new MacAddress(vrfEntry.getMac())));
@@ -335,7 +345,19 @@ public class BaseVrfEntryHandler implements AutoCloseable {
             LOG.debug("Failed to get VPN name for vpnId {}", vpnId);
             return;
         }
-        String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefix);
+        String macAddress = null;
+        if (vrfEntry.getParentVpnRd() != null) {
+            // Handling iRT/eRT use-case for missing destination mac address in Remote FIB flow
+            Optional<VpnInstanceOpDataEntry> vpnInstance = fibUtil.getVpnInstanceOpData(vrfEntry.getParentVpnRd());
+            if (vpnInstance.isPresent()) {
+                macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnInstance.get().getVpnInstanceName(), ipPrefix);
+            } else {
+                LOG.warn("VpnInstance missing for Parent Rd {} value for prefix {}", vrfEntry.getParentVpnRd(),
+                        vrfEntry.getDestPrefix());
+            }
+        } else {
+            macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefix);
+        }
         if (macAddress == null) {
             LOG.warn("No MAC address found for VPN interface {} prefix {}", ifName, ipPrefix);
             return;
@@ -343,7 +365,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(), new MacAddress(macAddress)));
     }
 
-    protected void addTunnelInterfaceActions(AdjacencyResult adjacencyResult, long vpnId, VrfEntry vrfEntry,
+    protected void addTunnelInterfaceActions(AdjacencyResult adjacencyResult, Uint32 vpnId, VrfEntry vrfEntry,
                                            List<ActionInfo> actionInfos, String rd) {
         Class<? extends TunnelTypeBase> tunnelType =
                 VpnExtraRouteHelper.getTunnelType(nextHopManager.getItmManager(), adjacencyResult.getInterfaceName());
@@ -355,13 +377,13 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         // routePath this result is built for. If this is not possible construct a map which does
         // the same.
         String nextHopIp = adjacencyResult.getNextHopIp();
-        java.util.Optional<Long> optionalLabel = FibUtil.getLabelForNextHop(vrfEntry, nextHopIp);
+        java.util.Optional<Uint32> optionalLabel = FibUtil.getLabelForNextHop(vrfEntry, nextHopIp);
         if (!optionalLabel.isPresent()) {
             LOG.warn("NextHopIp {} not found in vrfEntry {}", nextHopIp, vrfEntry);
             return;
         }
-        long label = optionalLabel.get();
-        BigInteger tunnelId = null;
+        Uint32 label = optionalLabel.get();
+        Uint64 tunnelId = null;
         Prefixes prefixInfo = null;
         // FIXME vxlan vni bit set is not working properly with OVS.need to
         // revisit
@@ -379,37 +401,33 @@ public class BaseVrfEntryHandler implements AutoCloseable {
             }
             // Internet VPN VNI will be used as tun_id for NAT use-cases
             if (Prefixes.PrefixCue.Nat.equals(prefixInfo.getPrefixCue())) {
-                if (vrfEntry.getL3vni() != null && vrfEntry.getL3vni() != 0) {
-                    tunnelId = BigInteger.valueOf(vrfEntry.getL3vni());
+                if (vrfEntry.getL3vni() != null && vrfEntry.getL3vni().toJava() != 0) {
+                    tunnelId = Uint64.valueOf(vrfEntry.getL3vni().longValue());
                 }
             } else {
-                if (fibUtil.enforceVxlanDatapathSemanticsforInternalRouterVpn(prefixInfo.getSubnetId(), vpnId,
-                        rd)) {
-                    java.util.Optional<Long> optionalVni = fibUtil.getVniForVxlanNetwork(prefixInfo.getSubnetId());
-                    if (!optionalVni.isPresent()) {
-                        LOG.error("VNI not found for nexthop {} vrfEntry {} with subnetId {}", nextHopIp,
-                                vrfEntry, prefixInfo.getSubnetId());
-                        return;
-                    }
-                    tunnelId = BigInteger.valueOf(optionalVni.get());
+                if (FibUtil.isVxlanNetwork(prefixInfo.getNetworkType())) {
+                    tunnelId = Uint64.valueOf(prefixInfo.getSegmentationId().longValue());
                 } else {
-                    tunnelId = BigInteger.valueOf(label);
+                    LOG.warn("Network is not of type VXLAN for prefix {}."
+                            + "Going with default Lport Tag.", prefixInfo.toString());
+                    tunnelId = Uint64.valueOf(label.longValue());
                 }
             }
         } else {
-            tunnelId = BigInteger.valueOf(label);
+            tunnelId = Uint64.valueOf(label.longValue());
         }
         LOG.debug("adding set tunnel id action for label {}", label);
         actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
         addRewriteDstMacAction(vpnId, vrfEntry, prefixInfo, actionInfos);
     }
 
+    @Nullable
     private InstanceIdentifier<Interface> getFirstAbsentInterfaceStateIid(List<AdjacencyResult> adjacencyResults) {
         InstanceIdentifier<Interface> res = null;
         for (AdjacencyResult adjacencyResult : adjacencyResults) {
             String interfaceName = adjacencyResult.getInterfaceName();
             if (null == fibUtil.getInterfaceStateFromOperDS(interfaceName)) {
-                res = fibUtil.buildStateInterfaceId(interfaceName);
+                res = FibUtil.buildStateInterfaceId(interfaceName);
                 break;
             }
         }
@@ -417,10 +435,12 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         return res;
     }
 
-    public void programRemoteFib(final BigInteger remoteDpnId, final long vpnId,
-                                  final VrfEntry vrfEntry, WriteTransaction tx, String rd,
-                                  List<AdjacencyResult> adjacencyResults,
-                                  List<SubTransaction> subTxns) {
+    // Allow deprecated TransactionRunner calls for now
+    @SuppressWarnings("ForbidCertainMethod")
+    public void programRemoteFib(final Uint64 remoteDpnId, final Uint32 vpnId,
+                                 final VrfEntry vrfEntry, WriteTransaction tx, String rd,
+                                 List<AdjacencyResult> adjacencyResults,
+                                 @Nullable List<SubTransaction> subTxns) {
         if (upgradeState.isUpgradeInProgress()) {
             InstanceIdentifier<Interface> absentInterfaceStateIid = getFirstAbsentInterfaceStateIid(adjacencyResults);
             if (absentInterfaceStateIid != null) {
@@ -430,17 +450,17 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                     absentInterfaceStateIid,
                     (before, after) -> {
                         LOG.info("programRemoteFib: waited for and got interface state {}", absentInterfaceStateIid);
-                        txRunner.callWithNewWriteOnlyTransactionAndSubmit((wtx) -> {
-                            programRemoteFib(remoteDpnId, vpnId, vrfEntry, wtx, rd, adjacencyResults, null);
-                        });
+                        LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            (wtx) -> programRemoteFib(remoteDpnId, vpnId, vrfEntry, wtx, rd, adjacencyResults, null)),
+                            LOG, "Failed to program remote FIB {}", absentInterfaceStateIid);
                         return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
                     },
                     Duration.of(15, ChronoUnit.MINUTES),
                     (iid) -> {
                         LOG.error("programRemoteFib: timed out waiting for {}", absentInterfaceStateIid);
-                        txRunner.callWithNewWriteOnlyTransactionAndSubmit((wtx) -> {
-                            programRemoteFib(remoteDpnId, vpnId, vrfEntry, wtx, rd, adjacencyResults, null);
-                        });
+                        LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            (wtx) -> programRemoteFib(remoteDpnId, vpnId, vrfEntry, wtx, rd, adjacencyResults, null)),
+                            LOG, "Failed to program timed-out remote FIB {}", absentInterfaceStateIid);
                     });
                 return;
             }
@@ -456,7 +476,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                 addRewriteDstMacAction(vpnId, vrfEntry, null, actionInfos);
             }
             List<ActionInfo> egressActions = nextHopManager.getEgressActionsForInterface(egressInterface,
-                    actionInfos.size(), true);
+                    actionInfos.size(), true, vpnId, vrfEntry.getDestPrefix());
             if (egressActions.isEmpty()) {
                 LOG.error(
                         "Failed to retrieve egress action for prefix {} route-paths {} interface {}. "
@@ -470,9 +490,9 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, subTxns);
     }
 
-    public boolean checkDpnDeleteFibEntry(VpnNexthop localNextHopInfo, BigInteger remoteDpnId, long vpnId,
-                                           VrfEntry vrfEntry, String rd,
-                                           WriteTransaction tx, List<SubTransaction> subTxns) {
+    public boolean checkDpnDeleteFibEntry(VpnNexthop localNextHopInfo, Uint64 remoteDpnId, Uint32 vpnId,
+                                          VrfEntry vrfEntry, String rd,
+                                          WriteTransaction tx, @Nullable List<SubTransaction> subTxns) {
         boolean isRemoteRoute = true;
         if (localNextHopInfo != null) {
             isRemoteRoute = !remoteDpnId.equals(localNextHopInfo.getDpnId());
@@ -488,10 +508,12 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         }
     }
 
-    public void deleteRemoteRoute(final BigInteger localDpnId, final BigInteger remoteDpnId,
-                                  final long vpnId, final VrfTablesKey vrfTableKey,
+    // Allow deprecated TransactionRunner calls for now
+    @SuppressWarnings("ForbidCertainMethod")
+    public void deleteRemoteRoute(@Nullable final Uint64 localDpnId, final Uint64 remoteDpnId,
+                                  final Uint32 vpnId, final VrfTablesKey vrfTableKey,
                                   final VrfEntry vrfEntry, Optional<Routes> extraRouteOptional,
-                                  WriteTransaction tx) {
+                                  @Nullable WriteTransaction tx) {
         if (tx == null) {
             ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
                 newTx -> deleteRemoteRoute(localDpnId, remoteDpnId, vpnId, vrfTableKey, vrfEntry,
@@ -503,11 +525,10 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                 vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
         String rd = vrfTableKey.getRouteDistinguisher();
 
-        if (localDpnId != null && localDpnId != BigInteger.ZERO) {
+        if (localDpnId != null && !Uint64.ZERO.equals(localDpnId)) {
             // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
             if (extraRouteOptional.isPresent()) {
-                nextHopManager.setupLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix(),
-                        Collections.emptyList() /*listBucketInfo*/ , false);
+                nextHopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
             }
             makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW, tx, null);
             LOG.debug("Successfully delete FIB entry: vrfEntry={}, vpnId={}", vrfEntry.getDestPrefix(), vpnId);
@@ -517,8 +538,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         // below two reads are kept as is, until best way is found to identify dpnID
         VpnNexthop localNextHopInfo = nextHopManager.getVpnNexthop(vpnId, vrfEntry.getDestPrefix());
         if (extraRouteOptional.isPresent()) {
-            nextHopManager.setupLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix(),
-                    Collections.emptyList() /*listBucketInfo*/ , false);
+            nextHopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
         } else {
             checkDpnDeleteFibEntry(localNextHopInfo, remoteDpnId, vpnId, vrfEntry, rd, tx, null);
         }
@@ -531,19 +551,26 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                         new ExtraRoutesKey(vrfId)).child(Routes.class, new RoutesKey(ipPrefix)).build();
     }
 
-    public Routes getVpnToExtraroute(Long vpnId, String vpnRd, String destPrefix) {
+    @Nullable
+    public Routes getVpnToExtraroute(Uint32 vpnId, String vpnRd, String destPrefix) {
         String optVpnName = fibUtil.getVpnNameFromId(vpnId);
         if (optVpnName != null) {
-            InstanceIdentifier<Routes> vpnExtraRoutesId = getVpnToExtrarouteIdentifier(
-                    optVpnName, vpnRd, destPrefix);
-            return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnExtraRoutesId).orNull();
+            InstanceIdentifier<Routes> vpnExtraRoutesId = getVpnToExtrarouteIdentifier(optVpnName, vpnRd, destPrefix);
+            try {
+                return SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL,
+                        vpnExtraRoutesId).orElse(null);
+            } catch (ExecutionException | InterruptedException e) {
+                LOG.error("getVpnToExtraroute: Exception while reading vpn-to-extraroute DS for the prefix {} "
+                        + "rd {} vpnId {} ", destPrefix, vpnRd, vpnId, e);
+            }
         }
         return null;
     }
 
-    public FlowEntity buildL3vpnGatewayFlow(BigInteger dpId, String gwMacAddress, long vpnId) {
+    public FlowEntity buildL3vpnGatewayFlow(Uint64 dpId, String gwMacAddress, Uint32 vpnId) {
         List<MatchInfo> mkMatches = new ArrayList<>();
-        mkMatches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
+        mkMatches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
+            MetaDataUtil.METADATA_MASK_VRFID));
         mkMatches.add(new MatchEthernetDestination(new MacAddress(gwMacAddress)));
         List<InstructionInfo> mkInstructions = new ArrayList<>();
         mkInstructions.add(new InstructionGotoTable(NwConstants.L3_FIB_TABLE));
@@ -552,12 +579,13 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                 flowId, 20, flowId, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE, mkMatches, mkInstructions);
     }
 
-    public void installPingResponderFlowEntry(BigInteger dpnId, long vpnId, String routerInternalIp,
-                                              MacAddress routerMac, long label, int addOrRemove) {
+    public void installPingResponderFlowEntry(Uint64 dpnId, Uint32 vpnId, String routerInternalIp,
+                                              MacAddress routerMac, Uint32 label, int addOrRemove) {
 
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchIpProtocol.ICMP);
-        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
+        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
+            MetaDataUtil.METADATA_MASK_VRFID));
         matches.add(new MatchIcmpv4((short) 8, (short) 0));
         matches.add(MatchEthernetType.IPV4);
         matches.add(new MatchIpv4Destination(routerInternalIp, "32"));
@@ -575,7 +603,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
         // Set the ICMP type to 0 (echo reply)
         actionsInfos.add(new ActionSetIcmpType((short) 0));
 
-        actionsInfos.add(new ActionNxLoadInPort(BigInteger.ZERO));
+        actionsInfos.add(new ActionNxLoadInPort(Uint64.ZERO));
 
         actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));