use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePathsKey in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpDpnForVpn.
public void cleanUpDpnForVpn(final Uint64 dpnId, final Uint32 vpnId, final String rd, final FutureCallback<List<?>> callback) {
LOG.trace("cleanUpDpnForVpn: Remove dpn {} for vpn {} : cleanUpDpnForVpn", dpnId, rd);
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
List<ListenableFuture<?>> futures = new ArrayList<>();
if (!vrfTable.isPresent()) {
LOG.error("cleanUpDpnForVpn: VRF Table not available for RD {}", rd);
if (callback != null) {
ListenableFuture<List<Object>> 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());
}
}
installSubnetBroadcastAddrDropRule(dpnId, rd, vpnId, vrfEntry, NwConstants.DEL_FLOW, tx);
continue;
}
// ping responder for router interfaces
RouterInterface routerInt = vrfEntry.augmentation(RouterInterface.class);
if (routerInt != null) {
LOG.trace("Router augmented vrfentry found for rd:{}, uuid:{}, ip:{}, mac:{}", rd, routerInt.getUuid(), routerInt.getIpAddress(), routerInt.getMacAddress());
routerInterfaceVrfEntryHandler.installRouterFibEntry(vrfEntry, dpnId, vpnId, routerInt.getIpAddress(), new MacAddress(routerInt.getMacAddress()), NwConstants.DEL_FLOW);
continue;
}
// Handle local flow deletion for imports
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
java.util.Optional<Uint32> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
List<String> nextHopList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(optionalLabel.get());
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopList, lri) && Objects.equals(lri.getDpnId(), dpnId)) {
deleteLocalFibEntry(vpnId, rd, vrfEntry);
}
}
}
// Passing null as we don't know the dpn
// to which prefix is attached at this point
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
Optional<Routes> extraRouteOptional;
// an adjacency in the vpn
if (usedRds != null && !usedRds.isEmpty()) {
if (usedRds.size() > 1) {
LOG.error("The extra route prefix is still present in some DPNs");
return;
} else {
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRds.get(0), vrfEntry.getDestPrefix());
}
} else {
extraRouteOptional = Optional.empty();
}
if (RouteOrigin.BGP.getValue().equals(vrfEntry.getOrigin())) {
bgpRouteVrfEntryHandler.deleteRemoteRoute(null, dpnId, vpnId, vrfTable.get().key(), vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(tx), txnObjects);
} else {
if (subnetRoute == null || !fibUtil.isInterfacePresentInDpn(parentRd, dpnId)) {
baseVrfEntryHandler.deleteRemoteRoute(null, dpnId, vpnId, vrfTable.get().key(), vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(tx));
}
}
}
}));
} finally {
lock.unlock();
}
if (callback != null) {
ListenableFuture<List<Object>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
return futures;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePathsKey in project netvirt by opendaylight.
the class VrfEntryListener method manageRemoteRouteOnDPN.
public void manageRemoteRouteOnDPN(final boolean action, final Uint64 localDpnId, final Uint32 vpnId, final String rd, final String destPrefix, final String destTepIp, final Uint32 label) {
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
if (vpnInstance == null) {
LOG.error("VpnInstance for rd {} not present for prefix {}", rd, destPrefix);
return;
}
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, localDpnId), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
final ReentrantLock lock = lockFor(vpnInstance);
lock.lock();
try {
VrfTablesKey vrfTablesKey = new VrfTablesKey(rd);
VrfEntry vrfEntry = getVrfEntry(dataBroker, rd, destPrefix);
if (vrfEntry == null) {
return;
}
LOG.trace("manageRemoteRouteOnDPN :: action {}, DpnId {}, vpnId {}, rd {}, destPfx {}", action, localDpnId, vpnId, rd, destPrefix);
Map<RoutePathsKey, RoutePaths> keyRoutePathsMap = vrfEntry.getRoutePaths();
VrfEntry modVrfEntry;
if (keyRoutePathsMap == null || keyRoutePathsMap.isEmpty()) {
modVrfEntry = FibHelper.getVrfEntryBuilder(vrfEntry, label, Collections.singletonList(destTepIp), RouteOrigin.value(vrfEntry.getOrigin()), null).build();
} else {
modVrfEntry = vrfEntry;
}
if (action) {
LOG.trace("manageRemoteRouteOnDPN updated(add) vrfEntry :: {}", modVrfEntry);
createRemoteFibEntry(localDpnId, vpnId, vrfTablesKey.getRouteDistinguisher(), modVrfEntry, tx);
} else {
LOG.trace("manageRemoteRouteOnDPN updated(remove) vrfEntry :: {}", modVrfEntry);
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
if (usedRds.size() > 1) {
LOG.debug("The extra route prefix is still present in some DPNs");
return;
}
// Is this fib route an extra route? If yes, get the nexthop which would be
// an adjacency in the vpn
Optional<Routes> extraRouteOptional = Optional.empty();
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.STATIC && usedRds.size() != 0) {
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, fibUtil.getVpnNameFromId(vpnInstance.getVpnId()), usedRds.get(0), vrfEntry.getDestPrefix());
}
baseVrfEntryHandler.deleteRemoteRoute(null, localDpnId, vpnId, vrfTablesKey, modVrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(tx));
}
} finally {
lock.unlock();
}
})));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePathsKey in project netvirt by opendaylight.
the class FibUtil method checkFibEntryExist.
public static boolean checkFibEntryExist(DataBroker broker, String rd, String prefix, String nextHopIp) {
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
Optional<VrfEntry> entry;
try {
entry = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("checkFibEntryExist: Exception while reading vrfEntry DS for the prefix {} rd {} nexthop {}", prefix, rd, nextHopIp, e);
return false;
}
if (entry.isPresent()) {
Map<RoutePathsKey, RoutePaths> pathsMap = entry.get().nonnullRoutePaths();
for (RoutePaths path : pathsMap.values()) {
if (path.getNexthopAddress().equals(nextHopIp)) {
return true;
}
}
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePathsKey in project netvirt by opendaylight.
the class ShowFibCommand method printVrfTable.
private void printVrfTable(VrfTables vrfTable, PrintStream console, boolean isIpv4, boolean isIpv6, boolean isL2vpn, @Nullable String inputPrefixOrSubnet) {
Map<VrfEntryKey, VrfEntry> keyVrfEntryMap = vrfTable.getVrfEntry();
if (keyVrfEntryMap == null) {
LOG.warn("Null keyVrfEntryMap found for VPN with rd={}", vrfTable.getRouteDistinguisher());
return;
}
for (VrfEntry vrfEntry : keyVrfEntryMap.values()) {
boolean showIt = false;
if (isIpv4 && isIpv6 && isL2vpn) {
showIt = true;
}
if (!showIt && isIpv4) {
LOG.debug("is ipv4 address family=> vrfEntry.getDestPrefix() = {}", vrfEntry.getDestPrefix());
showIt = FibHelper.isIpv4Prefix(vrfEntry.getDestPrefix());
}
if (!showIt && isIpv6) {
LOG.debug("is ipv6 address family=> vrfEntry.getDestPrefix() = {}", vrfEntry.getDestPrefix());
showIt = FibHelper.isIpv6Prefix(vrfEntry.getDestPrefix());
}
if (!showIt && isL2vpn) {
if (vrfEntry.getEncapType() != null && !EncapType.Mplsgre.equals(vrfEntry.getEncapType())) {
LOG.debug("is l2vpn address family=> vrfEntry.getEncapType() = {}", vrfEntry.getEncapType());
showIt = true;
}
}
if (!showIt && inputPrefixOrSubnet != null) {
showIt = FibHelper.isBelongingPrefix(vrfEntry.getDestPrefix(), inputPrefixOrSubnet);
}
if (!showIt) {
continue;
}
Map<RoutePathsKey, RoutePaths> routePathsMap = vrfEntry.getRoutePaths();
if (routePathsMap == null || routePathsMap.isEmpty()) {
console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), "local", routePathsMap == null ? "<not set>" : "<empty>", vrfEntry.getOrigin()));
continue;
}
for (RoutePaths routePath : routePathsMap.values()) {
console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), routePath.getNexthopAddress(), routePath.getLabel(), vrfEntry.getOrigin()));
}
}
}
Aggregations