use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class NexthopManager method createLocalNextHop.
public long createLocalNextHop(Uint32 vpnId, Uint64 dpnId, String ifName, String primaryIpAddress, String currDestIpPrefix, String gwMacAddress, Uint32 parentVpnId) {
// For VPN Imported routes, getting VPN Instance name using parentVpnId
String vpnName = parentVpnId != null ? fibUtil.getVpnNameFromId(parentVpnId) : fibUtil.getVpnNameFromId(vpnId);
if (vpnName == null) {
return 0;
}
String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, primaryIpAddress);
long groupId = createNextHopPointer(getNextHopKey(vpnId, primaryIpAddress));
if (groupId == 0) {
LOG.error("Unable to allocate groupId for vpnId {} , IntfName {}, primaryIpAddress {} curIpPrefix {}", vpnId, ifName, primaryIpAddress, currDestIpPrefix);
return groupId;
}
String nextHopLockStr = vpnId + primaryIpAddress;
String jobKey = FibUtil.getCreateLocalNextHopJobKey(vpnId, dpnId, currDestIpPrefix);
jobCoordinator.enqueueJob(jobKey, () -> {
try {
if (FibUtil.lockCluster(lockManager, nextHopLockStr, WAIT_TIME_TO_ACQUIRE_LOCK)) {
VpnNexthop nexthop = getVpnNexthop(vpnId, primaryIpAddress);
LOG.trace("nexthop: {} retrieved for vpnId {}, prefix {}, ifName {} on dpn {}", nexthop, vpnId, primaryIpAddress, ifName, dpnId);
if (nexthop == null) {
String encMacAddress = macAddress == null ? fibUtil.getMacAddressFromPrefix(ifName, vpnName, primaryIpAddress) : macAddress;
List<ActionInfo> listActionInfo = new ArrayList<>();
int actionKey = 0;
// MAC re-write
if (encMacAddress != null) {
if (gwMacAddress != null) {
LOG.trace("The Local NextHop Group Source Mac {} for VpnInterface {} on VPN {}", gwMacAddress, ifName, vpnId);
listActionInfo.add(new ActionSetFieldEthernetSource(actionKey++, new MacAddress(gwMacAddress)));
}
listActionInfo.add(new ActionSetFieldEthernetDestination(actionKey++, new MacAddress(encMacAddress)));
// listActionInfo.add(0, new ActionPopMpls());
} else {
LOG.error("mac address for new local nexthop group {} is null for vpnId {}, prefix {}, " + "ifName {} on dpn {}", groupId, vpnId, primaryIpAddress, ifName, dpnId);
}
List<ActionInfo> nhActionInfoList = getEgressActionsForInterface(ifName, actionKey, false, vpnId, currDestIpPrefix);
if (nhActionInfoList.isEmpty()) {
LOG.error("createLocalNextHop: Skipping, Empty list of egress actions received for " + "interface {} on dpn {} for vpn {} prefix {}", ifName, dpnId, vpnId, currDestIpPrefix);
}
listActionInfo.addAll(nhActionInfoList);
BucketInfo bucket = new BucketInfo(listActionInfo);
List<BucketInfo> listBucketInfo = new ArrayList<>();
listBucketInfo.add(bucket);
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, primaryIpAddress, GroupTypes.GroupAll, listBucketInfo);
LOG.trace("Install LNH Group: id {}, mac address {}, interface {} for prefix {}", groupId, encMacAddress, ifName, primaryIpAddress);
// Try to install group directly on the DPN bypassing the FRM, in order to avoid waiting for the
// group to get installed before programming the flows
installGroupOnDpn(groupId, dpnId, primaryIpAddress, listBucketInfo, getNextHopKey(vpnId, primaryIpAddress), GroupTypes.GroupAll);
// install Group
mdsalApiManager.syncInstallGroup(groupEntity);
// update MD-SAL DS
addVpnNexthopToDS(dpnId, vpnId, primaryIpAddress, currDestIpPrefix, groupId);
} else {
// Ignore adding new prefix , if it already exists
Map<IpAdjacenciesKey, IpAdjacencies> keyIpAdjacenciesMap = nexthop.getIpAdjacencies();
IpAdjacencies prefix = new IpAdjacenciesBuilder().setIpAdjacency(currDestIpPrefix).build();
if (keyIpAdjacenciesMap != null && keyIpAdjacenciesMap.values().contains(prefix)) {
LOG.trace("Prefix {} is already present in l3nextHop {} ", currDestIpPrefix, nexthop);
} else {
IpAdjacenciesBuilder ipPrefixesBuilder = new IpAdjacenciesBuilder().withKey(new IpAdjacenciesKey(currDestIpPrefix));
LOG.trace("Updating prefix {} to vpnNextHop {} Operational DS", currDestIpPrefix, nexthop);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIpPrefixIdentifier(vpnId, primaryIpAddress, currDestIpPrefix), ipPrefixesBuilder.build());
}
}
}
} finally {
FibUtil.unlockCluster(lockManager, nextHopLockStr);
}
return Collections.emptyList();
});
return groupId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class NexthopManager method getBucketsForLocalNexthop.
private List<BucketInfo> getBucketsForLocalNexthop(Uint32 vpnId, Uint64 dpnId, VrfEntry vrfEntry, Routes routes) {
@Nullable List<String> nexthopIpList = routes.getNexthopIpList();
if (LOG.isDebugEnabled()) {
LOG.debug("NexthopManager.getBucketsForLocalNexthop invoked with vpnId {} dpnId {} " + " vrfEntry.routePaths {}, routes.nexthopList {}", vpnId, dpnId, vrfEntry.getRoutePaths(), nexthopIpList);
}
List<BucketInfo> listBucketInfo = new CopyOnWriteArrayList<>();
if (nexthopIpList != null) {
nexthopIpList.parallelStream().forEach(nextHopIp -> {
String localNextHopIP;
if (isIpv4Address(nextHopIp)) {
localNextHopIP = nextHopIp + NwConstants.IPV4PREFIX;
} else {
localNextHopIP = nextHopIp + NwConstants.IPV6PREFIX;
}
Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
if (localNextHopInfo != null) {
long groupId = getLocalNextHopGroup(vpnId, localNextHopIP);
if (groupId == FibConstants.INVALID_GROUP_ID) {
LOG.error("Unable to allocate groupId for vpnId {} , prefix {} , interface {}", vpnId, vrfEntry.getDestPrefix(), localNextHopInfo.getVpnInterfaceName());
return;
}
List<ActionInfo> actionsInfos = Collections.singletonList(new ActionGroup(groupId));
BucketInfo bucket = new BucketInfo(actionsInfos);
bucket.setWeight(1);
listBucketInfo.add(bucket);
}
});
}
LOG.trace("LOCAL: listbucket {}, vpnId {}, dpnId {}, routes {}", listBucketInfo, vpnId, dpnId, routes);
return listBucketInfo;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class VrfEntryListener method deleteLocalFibEntry.
public List<Uint64> deleteLocalFibEntry(Uint32 vpnId, String rd, VrfEntry vrfEntry) {
List<Uint64> returnLocalDpnId = new ArrayList<>();
Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
String vpnName = fibUtil.getVpnNameFromId(vpnId);
boolean shouldUpdateNonEcmpLocalNextHop = true;
if (localNextHopInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
if (usedRds.size() > 1) {
LOG.error("The extra route prefix {} is still present in some DPNs in vpn {} on rd {}", vrfEntry.getDestPrefix(), vpnName, rd);
return returnLocalDpnId;
}
String vpnRd = !usedRds.isEmpty() ? usedRds.get(0) : rd;
// Is this fib route an extra route? If yes, get the nexthop which would be an adjacency
// in the vpn
Optional<Routes> extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, vpnRd, vrfEntry.getDestPrefix());
if (extraRouteOptional.isPresent()) {
Routes extraRoute = extraRouteOptional.get();
String ipPrefix;
if (isIpv4Address(extraRoute.getNexthopIpList().get(0))) {
ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV4PREFIX;
} else {
ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV6PREFIX;
}
if (extraRoute.getNexthopIpList().size() > 1) {
shouldUpdateNonEcmpLocalNextHop = false;
}
localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
if (localNextHopInfo != null) {
String localNextHopIP = localNextHopInfo.getIpAddress();
Uint64 dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnName, vpnId, rd, vrfEntry, shouldUpdateNonEcmpLocalNextHop);
if (!dpnId.equals(Uint64.ZERO)) {
LOG.trace("Deleting ECMP group for prefix {}, dpn {}", vrfEntry.getDestPrefix(), dpnId);
nextHopManager.deleteLoadBalancingNextHop(vpnId, dpnId, vrfEntry.getDestPrefix());
returnLocalDpnId.add(dpnId);
}
} else {
LOG.error("localNextHopInfo unavailable while deleting prefix {} with rds {}, primary rd {} in " + "vpn {}", vrfEntry.getDestPrefix(), usedRds, rd, vpnName);
}
}
if (localNextHopInfo == null) {
/* Imported VRF entry */
java.util.Optional<Uint32> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
Uint32 label = optionalLabel.get();
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
PrefixesBuilder prefixBuilder = new PrefixesBuilder();
prefixBuilder.setDpnId(lri.getDpnId());
Uint64 dpnId = checkDeleteLocalFibEntry(prefixBuilder.build(), nextHopAddressList.get(0), vpnName, vpnId, rd, vrfEntry, shouldUpdateNonEcmpLocalNextHop);
if (!dpnId.equals(Uint64.ZERO)) {
returnLocalDpnId.add(dpnId);
}
}
}
}
} else {
LOG.debug("Obtained prefix to interface for rd {} prefix {}", rd, vrfEntry.getDestPrefix());
String localNextHopIP = localNextHopInfo.getIpAddress();
Uint64 dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnName, vpnId, rd, vrfEntry, shouldUpdateNonEcmpLocalNextHop);
if (!dpnId.equals(Uint64.ZERO)) {
returnLocalDpnId.add(dpnId);
}
}
return returnLocalDpnId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class VrfEntryListener method deleteFibEntries.
private void deleteFibEntries(final InstanceIdentifier<VrfEntry> identifier, final VrfEntry vrfEntry) {
final VrfTablesKey vrfTableKey = identifier.firstKeyOf(VrfTables.class);
final String rd = vrfTableKey.getRouteDistinguisher();
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(vrfTableKey.getRouteDistinguisher());
if (vpnInstance == null) {
LOG.error("VPN Instance for rd {} is not available from VPN Op Instance Datastore", rd);
return;
}
final Map<VpnToDpnListKey, VpnToDpnList> keyVpnToDpnListMap;
if (vrfEntry.getParentVpnRd() != null && FibHelper.isControllerManagedNonSelfImportedRoute(RouteOrigin.value(vrfEntry.getOrigin()))) {
// This block MUST BE HIT only for PNF (Physical Network Function) FIB Entries.
VpnInstanceOpDataEntry parentVpnInstance = fibUtil.getVpnInstance(vrfEntry.getParentVpnRd());
keyVpnToDpnListMap = parentVpnInstance != null ? parentVpnInstance.getVpnToDpnList() : vpnInstance.getVpnToDpnList();
LOG.info("deleteFibEntries: Processing deletion of PNF FIB entry with rd {} prefix {}", vrfEntry.getParentVpnRd(), vrfEntry.getDestPrefix());
} else {
keyVpnToDpnListMap = vpnInstance.getVpnToDpnList();
}
SubnetRoute subnetRoute = vrfEntry.augmentation(SubnetRoute.class);
final java.util.Optional<Uint32> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
String vpnName = fibUtil.getVpnNameFromId(vpnInstance.getVpnId());
if (subnetRoute != null) {
long elanTag = subnetRoute.getElantag().toJava();
LOG.trace("SUBNETROUTE: deleteFibEntries: SubnetRoute augmented vrfentry found for rd {} prefix {}" + " with elantag {}", rd, vrfEntry.getDestPrefix(), elanTag);
if (keyVpnToDpnListMap != null) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForRdPrefix(rd, vrfEntry.getDestPrefix()), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (final VpnToDpnList curDpn : keyVpnToDpnListMap.values()) {
baseVrfEntryHandler.makeConnectedRoute(curDpn.getDpnId(), vpnInstance.getVpnId(), vrfEntry, vrfTableKey.getRouteDistinguisher(), null, NwConstants.DEL_FLOW, TransactionAdapter.toWriteTransaction(tx), null);
if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.SELF_IMPORTED) {
optionalLabel.ifPresent(label -> makeLFibTableEntry(curDpn.getDpnId(), label, null, DEFAULT_FIB_FLOW_PRIORITY, NwConstants.DEL_FLOW, tx));
}
installSubnetBroadcastAddrDropRule(curDpn.getDpnId(), rd, vpnInstance.getVpnId(), vrfEntry, NwConstants.DEL_FLOW, tx);
}
})));
}
return;
}
final List<Uint64> localDpnIdList = deleteLocalFibEntry(vpnInstance.getVpnId(), vrfTableKey.getRouteDistinguisher(), vrfEntry);
if (keyVpnToDpnListMap != null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
String jobKey;
Optional<Routes> extraRouteOptional;
// Is this fib route an extra route? If yes, get the nexthop which would be 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 {
// The first rd is retrieved from usedrds as Only 1 rd would be present as extra route prefix
// is not present in any other DPN
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRds.get(0), vrfEntry.getDestPrefix());
}
} else {
extraRouteOptional = Optional.empty();
}
jobCoordinator.enqueueJob(FibUtil.getJobKeyForRdPrefix(rd, vrfEntry.getDestPrefix()), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
if (localDpnIdList.size() <= 0) {
for (VpnToDpnList curDpn : keyVpnToDpnListMap.values()) {
baseVrfEntryHandler.deleteRemoteRoute(Uint64.ZERO, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(tx));
}
} else {
for (Uint64 localDpnId : localDpnIdList) {
for (VpnToDpnList curDpn : keyVpnToDpnListMap.values()) {
if (!Objects.equals(curDpn.getDpnId(), localDpnId)) {
baseVrfEntryHandler.deleteRemoteRoute(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(tx));
}
}
}
}
if (extraRouteOptional.isPresent()) {
// Remove select groups only for extra-routes
nextHopManager.removeNextHopPointer(nextHopManager.getRemoteSelectGroupKey(vpnInstance.getVpnId(), vrfEntry.getDestPrefix()));
nextHopManager.removeNextHopPointer(nextHopManager.getLocalSelectGroupKey(vpnInstance.getVpnId(), vrfEntry.getDestPrefix()));
}
})), MAX_RETRIES);
}
// The flow/group entry has been deleted from config DS; need to clean up associated operational
// DS entries in VPN Op DS, VpnInstanceOpData and PrefixToInterface to complete deletion
cleanUpOpDataForFib(vpnInstance.getVpnId(), vrfTableKey.getRouteDistinguisher(), vrfEntry);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class VrfEntryListener method programRemoteFibWithLoadBalancingGroups.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
private void programRemoteFibWithLoadBalancingGroups(final Uint64 remoteDpnId, final Uint32 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(Datastore.CONFIGURATION, txn -> {
baseVrfEntryHandler.makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, TransactionAdapter.toWriteTransaction(txn), null);
})));
LOG.debug("Successfully added FIB entry for prefix {} in vpnId {}", vrfEntry.getDestPrefix(), vpnId);
}
Aggregations