import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
}
String vpnName = fibUtil.getVpnNameFromId(vpnId);
- LOG.debug("createremotefibentry: adding route {} for rd {} on remoteDpnId {}",
- vrfEntry.getDestPrefix(), rd, remoteDpnId);
+ LOG.debug("createremotefibentry: adding route {} for rd {} on remoteDpnId {}", vrfEntry.getDestPrefix(), rd,
+ remoteDpnId);
- List<AdjacencyResult> adjacencyResults = baseVrfEntryHandler.resolveAdjacency(remoteDpnId, vpnId, vrfEntry, rd);
- if (adjacencyResults.isEmpty()) {
- LOG.error("Could not get interface for route-paths: {} in vpn {} on DPN {}",
- vrfEntry.getRoutePaths(), rd, remoteDpnId);
- LOG.error("Failed to add Route: {} in vpn: {}", vrfEntry.getDestPrefix(), rd);
+ if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.STATIC) {
+ programRemoteFibEntry(remoteDpnId, vpnId, rd, vrfEntry, tx);
return;
}
-
+ // Handling static VRF entries
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
- List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker,
- vpnName, usedRds, vrfEntry.getDestPrefix());
- // create loadbalancing groups for extra routes only when the extra route is present behind
- // multiple VMs
+ List<Routes> vpnExtraRoutes =
+ VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, vpnName, usedRds, vrfEntry.getDestPrefix());
if (!vpnExtraRoutes.isEmpty()) {
- List<InstructionInfo> instructions = new ArrayList<>();
- // Obtain the local routes for this particular dpn.
- java.util.Optional<Routes> routes = vpnExtraRoutes
- .stream()
- .filter(route -> {
- Prefixes prefixToInterface = fibUtil.getPrefixToInterface(vpnId,
- FibUtil.getIpPrefix(route.getNexthopIpList().get(0)));
- if (prefixToInterface == null) {
- return false;
- }
- return remoteDpnId.equals(prefixToInterface.getDpnId());
- }).findFirst();
- long groupId = nextHopManager.createNextHopGroups(vpnId, rd, remoteDpnId, vrfEntry,
- routes.isPresent() ? routes.get() : null, vpnExtraRoutes);
- if (groupId == FibConstants.INVALID_GROUP_ID) {
- LOG.error("Unable to create Group for local prefix {} on rd {} on Node {}",
- vrfEntry.getDestPrefix(), rd, remoteDpnId.toString());
- return;
- }
- List<ActionInfo> actionInfos =
- Collections.singletonList(new ActionGroup(groupId));
- instructions.add(new InstructionApplyActions(actionInfos));
- String jobKey = FibUtil.getCreateRemoteNextHopJobKey(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
- jobCoordinator.enqueueJob(jobKey,
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(txn -> {
- baseVrfEntryHandler.makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions,
- NwConstants.ADD_FLOW, txn, null);
- })));
+ programRemoteFibWithLoadBalancingGroups(remoteDpnId, vpnId, rd, vrfEntry, vpnExtraRoutes);
} else {
- baseVrfEntryHandler.programRemoteFib(remoteDpnId, vpnId, vrfEntry,
- TransactionAdapter.toWriteTransaction(tx), rd, adjacencyResults, null);
+ // Program in case of other static VRF entries like floating IPs
+ programRemoteFibEntry(remoteDpnId, vpnId, rd, vrfEntry, tx);
}
+ }
+
+ private void programRemoteFibWithLoadBalancingGroups(final BigInteger remoteDpnId, final long vpnId, String rd,
+ final VrfEntry vrfEntry, List<Routes> vpnExtraRoutes) {
+ // create loadbalancing groups for extra routes only when the extra route is
+ // present behind multiple VMs
+ // Obtain the local routes for this particular dpn.
+ java.util.Optional<Routes> routes = vpnExtraRoutes.stream().filter(route -> {
+ Prefixes prefixToInterface =
+ fibUtil.getPrefixToInterface(vpnId, FibUtil.getIpPrefix(route.getNexthopIpList().get(0)));
+ if (prefixToInterface == null) {
+ return false;
+ }
+ return remoteDpnId.equals(prefixToInterface.getDpnId());
+ }).findFirst();
+ long groupId = nextHopManager.createNextHopGroups(vpnId, rd, remoteDpnId, vrfEntry,
+ routes.isPresent() ? routes.get() : null, vpnExtraRoutes);
+ if (groupId == FibConstants.INVALID_GROUP_ID) {
+ LOG.error("Unable to create Group for local prefix {} on rd {} on Node {}", vrfEntry.getDestPrefix(), rd,
+ remoteDpnId);
+ return;
+ }
+ List<ActionInfo> actionInfos = Collections.singletonList(new ActionGroup(groupId));
+ List<InstructionInfo> instructions = Lists.newArrayList(new InstructionApplyActions(actionInfos));
+ String jobKey = FibUtil.getCreateRemoteNextHopJobKey(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
+ jobCoordinator.enqueueJob(jobKey,
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(txn -> {
+ baseVrfEntryHandler.makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions,
+ NwConstants.ADD_FLOW, txn, null);
+ })));
LOG.debug("Successfully added FIB entry for prefix {} in vpnId {}", vrfEntry.getDestPrefix(), vpnId);
}
+ private void programRemoteFibEntry(final BigInteger remoteDpnId, final long vpnId, String rd,
+ final VrfEntry vrfEntry, TypedWriteTransaction<Configuration> tx) {
+ List<AdjacencyResult> adjacencyResults = baseVrfEntryHandler.resolveAdjacency(remoteDpnId, vpnId, vrfEntry, rd);
+ if (adjacencyResults.isEmpty()) {
+ LOG.error("Could not get interface for route-paths: {} in vpn {} on DPN {}", vrfEntry.getRoutePaths(), rd,
+ remoteDpnId);
+ LOG.error("Failed to add Route: {} in vpn: {}", vrfEntry.getDestPrefix(), rd);
+ return;
+ }
+ baseVrfEntryHandler.programRemoteFib(remoteDpnId, vpnId, vrfEntry, TransactionAdapter.toWriteTransaction(tx),
+ rd, adjacencyResults, null);
+ LOG.debug("Successfully programmed FIB entry for prefix {} in vpnId {}", vrfEntry.getDestPrefix(), vpnId);
+ }
+
protected void cleanUpOpDataForFib(Long vpnId, String primaryRd, final VrfEntry vrfEntry) {
/* Get interface info from prefix to interface mapping;
Use the interface info to get the corresponding vpn interface op DS entry,
//Is this fib route an extra route? If yes, get the nexthop which would be
//an adjacency in the vpn
Optional<Routes> extraRouteOptional = Optional.absent();
- if (usedRds.size() != 0) {
+ if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.STATIC && usedRds.size() != 0) {
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker,
fibUtil.getVpnNameFromId(vpnInstance.getVpnId()),
usedRds.get(0), vrfEntry.getDestPrefix());