use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class L3vpnPopulator method addSubnetRouteFibEntry.
public void addSubnetRouteFibEntry(L3vpnInput input) {
String rd = input.getRd();
String vpnName = input.getVpnName();
String prefix = input.getSubnetIp();
String nextHop = input.getNextHopIp();
Uint32 label = Uint32.valueOf(input.getLabel());
Uint32 l3vni = Uint32.valueOf(input.getL3vni());
Uint32 elantag = Uint32.valueOf(input.getElanTag());
String networkName = input.getNetworkName();
String gwMacAddress = input.getGatewayMac();
SubnetRoute route = new SubnetRouteBuilder().setElantag(elantag).build();
// Only case when a route is considered as directly connected
RouteOrigin origin = RouteOrigin.CONNECTED;
VrfEntry vrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, nextHop, origin, networkName).addAugmentation(route).setL3vni(l3vni).setGatewayMacAddress(gwMacAddress).build();
LOG.debug("Created vrfEntry for {} nexthop {} label {} and elantag {}", prefix, nextHop, label, elantag);
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
Optional<VrfEntry> entry = Optional.empty();
try {
entry = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("addSubnetRouteFibEntry: Exception while reading vrfEntry for the prefix {} rd {}", prefix, rd, e);
}
if (!entry.isPresent()) {
List<VrfEntry> vrfEntryList = Collections.singletonList(vrfEntry);
InstanceIdentifier.InstanceIdentifierBuilder<VrfTables> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
VrfTables vrfTableNew = new VrfTablesBuilder().setRouteDistinguisher(rd).setVrfEntry(vrfEntryList).build();
vpnUtil.syncUpdate(LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Added vrfEntry for {} nexthop {} label {} rd {}" + " vpnName {}", prefix, nextHop, label, rd, vpnName);
} else {
// Found in MDSAL database
vpnUtil.syncWrite(LogicalDatastoreType.CONFIGURATION, vrfEntryId, vrfEntry);
LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Updated vrfEntry for {} nexthop {} label {} rd {}" + " vpnName {}", prefix, nextHop, label, rd, vpnName);
}
// Will be handled appropriately with the iRT patch for EVPN
if (input.getEncapType().equals(VrfEntryBase.EncapType.Mplsgre)) {
List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
if (vpnsToImportRoute.size() > 0) {
VrfEntry importingVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, nextHop, RouteOrigin.SELF_IMPORTED, rd).addAugmentation(route).build();
List<VrfEntry> importingVrfEntryList = Collections.singletonList(importingVrfEntry);
for (VpnInstanceOpDataEntry vpnInstance : vpnsToImportRoute) {
String importingRd = vpnInstance.getVrfId();
InstanceIdentifier<VrfTables> importingVrfTableId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(importingRd)).build();
VrfTables importingVrfTable = new VrfTablesBuilder().setRouteDistinguisher(importingRd).setVrfEntry(importingVrfEntryList).build();
vpnUtil.syncUpdate(LogicalDatastoreType.CONFIGURATION, importingVrfTableId, importingVrfTable);
LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Exported route rd {} prefix {} nexthop {}" + " label {} to vpn {} importingRd {}", rd, prefix, nextHop, label, vpnInstance.getVpnInstanceName(), importingRd);
}
}
}
LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Created vrfEntry for {} nexthop {} label {} and elantag {}" + "rd {} vpnName {}", prefix, nextHop, label, elantag, rd, vpnName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class L3vpnPopulator method addToLabelMapper.
public void addToLabelMapper(Uint32 label, Uint64 dpnId, String prefix, List<String> nextHopIpList, Uint32 vpnId, @Nullable String vpnInterfaceName, @Nullable Uint32 elanTag, boolean isSubnetRoute, String rd) {
final String labelStr = requireNonNull(label, "addToLabelMapper: label cannot be null or empty!").toString();
requireNonNull(prefix, "addToLabelMapper: prefix cannot be null or empty!");
requireNonNull(vpnId, "addToLabelMapper: vpnId cannot be null or empty!");
requireNonNull(rd, "addToLabelMapper: rd cannot be null or empty!");
if (!isSubnetRoute) {
// NextHop must be present for non-subnetroute entries
requireNonNull(nextHopIpList, "addToLabelMapper: nextHopIp cannot be null or empty!");
}
// FIXME: separate this out somehow?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(labelStr);
lock.lock();
try {
addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
LOG.info("addToLabelMapper: label {} dpn {} prefix {} nexthoplist {} vpnid {} vpnIntfcName {} rd {}" + " elanTag {}", labelStr, dpnId, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
if (dpnId != null) {
LabelRouteInfoBuilder lriBuilder = new LabelRouteInfoBuilder();
lriBuilder.setLabel(label).setDpnId(dpnId).setPrefix(prefix).setNextHopIpList(nextHopIpList).setParentVpnid(vpnId).setIsSubnetRoute(isSubnetRoute);
if (elanTag != null) {
lriBuilder.setElanTag(elanTag);
} else {
LOG.warn("addToLabelMapper: elanTag is null for label {} prefix {} rd {} vpnId {}", labelStr, prefix, rd, vpnId);
}
if (vpnInterfaceName != null) {
lriBuilder.setVpnInterfaceName(vpnInterfaceName);
} else {
LOG.warn("addToLabelMapper: vpn interface is null for label {} prefix {} rd {} vpnId {}", labelStr, prefix, rd, vpnId);
}
lriBuilder.setParentVpnRd(rd);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
List<String> vpnInstanceNames = Collections.singletonList(vpnInstanceOpDataEntry.getVpnInstanceName());
lriBuilder.setVpnInstanceList(vpnInstanceNames);
}
LabelRouteInfo lri = lriBuilder.build();
InstanceIdentifier<LabelRouteInfo> lriIid = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(label)).build();
tx.mergeParentStructureMerge(lriIid, lri);
LOG.info("addToLabelMapper: Added label route info to label {} prefix {} nextHopList {} vpnId {}" + " interface {} rd {} elantag {}", labelStr, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
} else {
LOG.warn("addToLabelMapper: Can't add entry to label map for label {} prefix {} nextHopList {}" + " vpnId {} interface {} rd {} elantag {}, dpnId is null", labelStr, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
}
}), LOG, "addToLabelMapper");
} finally {
lock.unlock();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method leakExtraRoutesToVpnEndpoint.
/*
* Checks if there are static routes in Vpn1 whose nexthop is Vpn2's endpoint.
* Those routes must be leaked to Vpn1.
*
* @param vpnLink
* @param vpn1Uuid
* @param vpn2Uuid
*/
private void leakExtraRoutesToVpnEndpoint(InterVpnLinkDataComposite vpnLink, String vpn1Uuid, String vpn2Uuid) {
String vpn1Rd = vpnUtil.getVpnRd(vpn1Uuid);
String vpn2Endpoint = vpnLink.getOtherEndpointIpAddr(vpn2Uuid);
List<VrfEntry> allVpnVrfEntries = vpnUtil.getAllVrfEntries(vpn1Rd);
for (VrfEntry vrfEntry : allVpnVrfEntries) {
vrfEntry.nonnullRoutePaths().values().stream().filter(routePath -> Objects.equals(routePath.getNexthopAddress(), vpn2Endpoint)).forEach(routePath -> {
// Vpn1 has a route pointing to Vpn2's endpoint. Forcing the leaking of the route will update
// the BGP accordingly
Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpn1Rd, vrfEntry.getDestPrefix()));
if (label.longValue() == VpnConstants.INVALID_LABEL) {
LOG.error("Unable to fetch label from Id Manager. Bailing out of leaking extra routes for " + "InterVpnLink {} rd {} prefix {}", vpnLink.getInterVpnLinkName(), vpn1Rd, vrfEntry.getDestPrefix());
} else {
leakRoute(vpnLink, vpn2Uuid, vpn1Uuid, vrfEntry.getDestPrefix(), label, RouteOrigin.value(vrfEntry.getOrigin()));
}
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method leakRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void leakRoute(InterVpnLinkDataComposite interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Uint32 label, @Nullable RouteOrigin forcedOrigin) {
String ivpnLinkName = interVpnLink.getInterVpnLinkName();
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.isVpnLinked(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, ivpnLinkName);
// The destination VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.isVpnLinked(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, ivpnLinkName);
String endpointIp = interVpnLink.getOtherEndpointIpAddr(dstVpnUuid);
String leakedOrigin = forcedOrigin != null ? forcedOrigin.getValue() : RouteOrigin.INTERVPN.getValue();
FibHelper.buildRoutePath(endpointIp, label);
VrfEntry newVrfEntry = new VrfEntryBuilder().withKey(new VrfEntryKey(prefix)).setDestPrefix(prefix).setRoutePaths(Collections.singletonList(FibHelper.buildRoutePath(endpointIp, label))).setOrigin(leakedOrigin).build();
String dstVpnRd = vpnUtil.getVpnRd(dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.put(newVrfEntryIid, newVrfEntry)), LOG, "Error adding VRF entry {}", newVrfEntry);
// Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
// endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
// VPN has been instantiated
List<Uint64> srcDpnList = interVpnLink.getEndpointDpnsByVpnName(srcVpnUuid);
List<String> nexthops = srcDpnList.stream().map(dpnId -> InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId)).collect(Collectors.toList());
LOG.debug("Advertising route in VPN={} [prefix={} label={} nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
try {
bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
prefix, nexthops, VrfEntry.EncapType.Mplsgre, label, Uint32.ZERO, /*l3vni*/
Uint32.ZERO, /*l2vni*/
null);
} catch (Exception e) {
LOG.error("Exception while advertising prefix {} on vpnRd {} for intervpn link", prefix, dstVpnRd, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method handleStaticRoute.
/*
* Takes care of an static route to see if flows related to interVpnLink
* must be installed in tables 20 and 17
*
* @param vpnId Vpn to which the route belongs
* @param route Route to handle. Will only be considered if its nexthop is the VPN's endpoint IpAddress
* at the other side of the InterVpnLink
* @param iVpnLink
*/
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleStaticRoute(String vpnId, Routes route, InterVpnLinkDataComposite ivpnLink) {
IpAddress nhIpAddr = route.getNexthop();
String routeNextHop = nhIpAddr.getIpv4Address() != null ? nhIpAddr.getIpv4Address().getValue() : nhIpAddr.getIpv6Address().getValue();
String destination = route.getDestination().stringValue();
// is nexthop the other endpoint's IP
String otherEndpoint = ivpnLink.getOtherEndpoint(vpnId);
if (!routeNextHop.equals(otherEndpoint)) {
LOG.debug("VPN {}: Route to {} nexthop={} points to an InterVpnLink endpoint, but its not " + "the other endpoint. Other endpoint is {}", vpnId, destination, routeNextHop, otherEndpoint);
return;
}
// Lets work: 1) write Fibentry, 2) advertise to BGP and 3) check if it must be leaked
String vpnRd = vpnUtil.getVpnRd(vpnId);
if (vpnRd == null) {
LOG.warn("Could not find Route-Distinguisher for VpnName {}", vpnId);
return;
}
Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnId, destination));
try {
interVpnLinkUtil.handleStaticRoute(ivpnLink, vpnId, destination, routeNextHop, label);
} catch (Exception e) {
LOG.error("Exception while advertising prefix for intervpn link", e);
}
}
Aggregations