use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables in project netvirt by opendaylight.
the class VrfEntryListener method populateFibOnNewDpn.
public void populateFibOnNewDpn(final BigInteger dpnId, final long vpnId, final String rd, final FutureCallback<List<Void>> callback) {
LOG.trace("New dpn {} for vpn {} : populateFibOnNewDpn", dpnId, rd);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
List<SubTransaction> txnObjects = new ArrayList<>();
if (!vrfTable.isPresent()) {
LOG.info("populateFibOnNewDpn: dpn: {}: VRF Table not yet available for RD {}", dpnId, rd);
if (callback != null) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
return;
}
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
futures.add(retryingTxRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
for (final VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
SubnetRoute subnetRoute = vrfEntry.getAugmentation(SubnetRoute.class);
if (subnetRoute != null) {
long elanTag = subnetRoute.getElantag();
installSubnetRouteInFib(dpnId, elanTag, rd, vpnId, vrfEntry, tx);
installSubnetBroadcastAddrDropRule(dpnId, rd, vpnId, vrfEntry, NwConstants.ADD_FLOW, tx);
continue;
}
RouterInterface routerInt = vrfEntry.getAugmentation(RouterInterface.class);
if (routerInt != null) {
LOG.trace("Router augmented vrfentry found rd:{}, uuid:{}, ip:{}, mac:{}", rd, routerInt.getUuid(), routerInt.getIpAddress(), routerInt.getMacAddress());
routerInterfaceVrfEntryHandler.installRouterFibEntry(vrfEntry, dpnId, vpnId, routerInt.getIpAddress(), new MacAddress(routerInt.getMacAddress()), NwConstants.ADD_FLOW);
continue;
}
// Handle local flow creation for imports
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
List<String> nextHopList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(optionalLabel.get());
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopList, lri)) {
if (lri.getDpnId().equals(dpnId)) {
createLocalFibEntry(vpnId, rd, vrfEntry);
continue;
}
}
}
}
boolean shouldCreateRemoteFibEntry = shouldCreateFibEntryForVrfAndVpnIdOnDpn(vpnId, vrfEntry, dpnId);
if (shouldCreateRemoteFibEntry) {
LOG.trace("Will create remote FIB entry for vrfEntry {} on DPN {}", vrfEntry, dpnId);
if (RouteOrigin.BGP.getValue().equals(vrfEntry.getOrigin())) {
bgpRouteVrfEntryHandler.createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx, txnObjects);
} else {
createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx);
}
}
}
}));
if (callback != null) {
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
}
return futures;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables in project netvirt by opendaylight.
the class VrfEntryListener method populateExternalRoutesOnDpn.
public void populateExternalRoutesOnDpn(final BigInteger dpnId, final long vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("populateExternalRoutesOnDpn : dpn {}, vpn {}, rd {}, localNexthopIp {} , remoteNextHopIp {} ", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
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);
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
WriteTransaction writeCfgTxn = dataBroker.newWriteOnlyTransaction();
vrfTable.get().getVrfEntry().stream().filter(vrfEntry -> RouteOrigin.BGP == RouteOrigin.value(vrfEntry.getOrigin())).forEach(bgpRouteVrfEntryHandler.getConsumerForCreatingRemoteFib(dpnId, vpnId, rd, remoteNextHopIp, vrfTable, writeCfgTxn, txnObjects));
futures.add(writeCfgTxn.submit());
}
return futures;
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables in project netvirt by opendaylight.
the class FibManagerTest method buildVrfTableId.
public static InstanceIdentifier<VrfTables> buildVrfTableId(String rd) {
InstanceIdentifierBuilder<VrfTables> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
return vrfTableId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables in project netvirt by opendaylight.
the class ShowFibCommand method printVrfTable.
private void printVrfTable(VrfTables vrfTable, PrintStream console, boolean isIpv4, boolean isIpv6, boolean isL2vpn, String inputPrefixOrSubnet) {
List<VrfEntry> vrfEntries = vrfTable.getVrfEntry();
if (vrfEntries == null) {
LOG.warn("Null vrfEntries found for VPN with rd={}", vrfTable.getRouteDistinguisher());
return;
}
for (VrfEntry vrfEntry : vrfEntries) {
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;
}
List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
if (routePaths == null || routePaths.isEmpty()) {
console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), "local", routePaths == null ? "<not set>" : "<empty>", vrfEntry.getOrigin()));
continue;
}
for (RoutePaths routePath : routePaths) {
console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), routePath.getNexthopAddress(), routePath.getLabel(), vrfEntry.getOrigin()));
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables in project netvirt by opendaylight.
the class ShowFibCommand method doExecute.
@Override
protected Object doExecute() {
PrintStream console = session.getConsole();
if (prefixOrSubnetOption != null && prefixOrSubnetOption.length() > 0) {
prefixOrSubnet = prefixOrSubnetOption.replace("[", "");
prefixOrSubnet = prefixOrSubnet.replace("]", "");
if (prefixOrSubnet.indexOf("/") < 0) {
String maskFull = null;
try {
Inet4Address tempAdd = (Inet4Address) InetAddress.getByName(prefixOrSubnet);
maskFull = "/32";
} catch (SecurityException | UnknownHostException | ClassCastException e) {
maskFull = null;
}
if (maskFull == null) {
try {
Inet6Address tempAdd = (Inet6Address) InetAddress.getByName(prefixOrSubnet);
maskFull = "/128";
} catch (SecurityException | UnknownHostException | ClassCastException e) {
maskFull = null;
}
}
if (maskFull == null) {
console.println("a part of cli " + SUBNET + " is wrong => " + prefixOrSubnet);
return usage(console);
}
prefixOrSubnet += maskFull;
}
}
console.println(HEADER);
if (options == null && prefixOrSubnet == null && (addrFamList == null || addrFamList.isEmpty())) {
InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
try {
FibEntries fibEntries = singleTxDb.syncRead(LogicalDatastoreType.CONFIGURATION, id);
List<VrfTables> vrfTablesList = fibEntries.getVrfTables();
if (vrfTablesList == null || vrfTablesList.isEmpty()) {
console.println(" No Fib entries found");
return null;
}
for (VrfTables vrfTable : vrfTablesList) {
printVrfTable(vrfTable, console);
}
} catch (ExpectedDataObjectNotFoundException e404) {
String errMsg = "FATAL: fib-entries container is missing from MD-SAL";
console.println("\n" + errMsg);
LOG.error(errMsg, e404);
} catch (ReadFailedException rfe) {
String errMsg = "Internal Error occurred while processing vpnservice:fib-show command";
console.println("\n" + errMsg);
LOG.error(errMsg, rfe);
}
return null;
} else {
String optionsLowerCase = options != null ? options.toLowerCase(Locale.getDefault()) : "";
switch(optionsLowerCase) {
case "fullhelp":
return usage(console);
default:
}
if ((addrFamList == null || addrFamList.isEmpty()) && (prefixOrSubnet == null || prefixOrSubnet.indexOf("/") < 5)) {
console.println("any address family is requiered or " + SUBNET + " is wrong");
usage(console);
} else {
boolean isIpv4 = false;
boolean isIpv6 = false;
boolean isL2vpn = false;
if (addrFamList != null && addrFamList.size() > 0) {
for (String addF : addrFamList) {
switch(addF.toLowerCase(Locale.getDefault())) {
case "ipv4":
isIpv4 = true;
break;
case "ipv6":
isIpv6 = true;
break;
case "l2vpn":
isL2vpn = true;
break;
default:
}
}
}
InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
try {
FibEntries fibEntries = singleTxDb.syncRead(LogicalDatastoreType.CONFIGURATION, id);
List<VrfTables> vrfTablesList = fibEntries.getVrfTables();
if (vrfTablesList == null || vrfTablesList.isEmpty()) {
console.println(" No Fib entries found");
return null;
}
for (VrfTables vrfTable : vrfTablesList) {
printVrfTable(vrfTable, console, isIpv4, isIpv6, isL2vpn, prefixOrSubnet);
}
} catch (ExpectedDataObjectNotFoundException e404) {
String errMsg = "FATAL: fib-entries container is missing from MD-SAL";
console.println("\n" + errMsg);
LOG.error(errMsg, e404);
} catch (ReadFailedException rfe) {
String errMsg = "Internal Error occurred while processing vpnservice:fib-show command";
console.println("\n" + errMsg);
LOG.error(errMsg, rfe);
}
return null;
}
}
return null;
}
Aggregations