- if (vrfTable.isPresent()) {
- synchronized (vpnInstance.getVpnInstanceName().intern()) {
- futures.add(retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
- String vpnName = fibUtil.getVpnNameFromId(vpnInstance.getVpnId());
- for (final VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
- /* Handle subnet routes here */
- SubnetRoute subnetRoute = vrfEntry.augmentation(SubnetRoute.class);
- if (subnetRoute != null && !fibUtil
- .isInterfacePresentInDpn(vrfEntry.getParentVpnRd(), dpnId)) {
- LOG.trace("SUBNETROUTE: cleanUpDpnForVpn: Cleaning subnetroute {} on dpn {}"
- + " for vpn {}", vrfEntry.getDestPrefix(), dpnId, rd);
- baseVrfEntryHandler.makeConnectedRoute(dpnId, vpnId, vrfEntry, rd, null,
- NwConstants.DEL_FLOW, TransactionAdapter.toWriteTransaction(tx), null);
- List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
- if (routePaths != null) {
- for (RoutePaths routePath : routePaths) {
- makeLFibTableEntry(dpnId, routePath.getLabel(), null,
- DEFAULT_FIB_FLOW_PRIORITY,
- NwConstants.DEL_FLOW, tx);
- LOG.trace("SUBNETROUTE: cleanUpDpnForVpn: Released subnetroute label {}"
- + " for rd {} prefix {}", routePath.getLabel(), rd,
- vrfEntry.getDestPrefix());
- }
+ if (!vrfTable.isPresent()) {
+ LOG.error("cleanUpDpnForVpn: VRF Table not available for RD {}", rd);
+ if (callback != null) {
+ ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
+ Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
+ }
+ return futures;
+ }
+ final ReentrantLock lock = lockFor(vpnInstance);
+ lock.lock();
+ try {
+ futures.add(retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ String vpnName = fibUtil.getVpnNameFromId(vpnInstance.getVpnId());
+ for (final VrfEntry vrfEntry : vrfTable.get().nonnullVrfEntry().values()) {
+ /* parentRd is only filled for external PNF cases where the interface on the external
+ * network VPN are used to cleanup the flows. For all other cases, use "rd" for
+ * #fibUtil.isInterfacePresentInDpn().
+ * */
+ String parentRd = vrfEntry.getParentVpnRd() != null ? vrfEntry.getParentVpnRd()
+ : rd;
+ /* Handle subnet routes here */
+ SubnetRoute subnetRoute = vrfEntry.augmentation(SubnetRoute.class);
+ if (subnetRoute != null && !fibUtil
+ .isInterfacePresentInDpn(parentRd, dpnId)) {
+ LOG.trace("SUBNETROUTE: cleanUpDpnForVpn: Cleaning subnetroute {} on dpn {}"
+ + " for vpn {}", vrfEntry.getDestPrefix(), dpnId, rd);
+ baseVrfEntryHandler.makeConnectedRoute(dpnId, vpnId, vrfEntry, rd, null,
+ NwConstants.DEL_FLOW, TransactionAdapter.toWriteTransaction(tx), null);
+ Map<RoutePathsKey, RoutePaths> keyRoutePathsMap = vrfEntry.getRoutePaths();
+ if (keyRoutePathsMap != null) {
+ for (RoutePaths routePath : keyRoutePathsMap.values()) {
+ makeLFibTableEntry(dpnId, routePath.getLabel(), null,
+ DEFAULT_FIB_FLOW_PRIORITY,
+ NwConstants.DEL_FLOW, tx);
+ LOG.trace("SUBNETROUTE: cleanUpDpnForVpn: Released subnetroute label {}"
+ + " for rd {} prefix {}", routePath.getLabel(), rd,
+ vrfEntry.getDestPrefix());