use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.
the class VpnManagerImpl method addExtraRoute.
@Override
public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID, Long l3vni, RouteOrigin origin, String intfName, Adjacency operationalAdj, VrfEntry.EncapType encapType, WriteTransaction writeConfigTxn) {
Boolean writeConfigTxnPresent = true;
if (writeConfigTxn == null) {
writeConfigTxnPresent = false;
writeConfigTxn = dataBroker.newWriteOnlyTransaction();
}
// add extra route to vpn mapping; advertise with nexthop as tunnel ip
VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, rd != null ? rd : routerID, destination), VpnUtil.getVpnToExtraroute(destination, Collections.singletonList(nextHop)));
BigInteger dpnId = null;
if (intfName != null && !intfName.isEmpty()) {
dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, intfName);
String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
if (nextHopIp == null || nextHopIp.isEmpty()) {
LOG.error("addExtraRoute: NextHop for interface {} is null / empty." + " Failed advertising extra route for rd {} prefix {} dpn {}", intfName, rd, destination, dpnId);
return;
}
nextHop = nextHopIp;
}
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
// TODO: This is a limitation to be stated in docs. When configuring static route to go to
// another VPN, there can only be one nexthop or, at least, the nexthop to the interVpnLink should be in
// first place.
Optional<InterVpnLinkDataComposite> optVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nextHop);
if (optVpnLink.isPresent() && optVpnLink.get().isActive()) {
InterVpnLinkDataComposite interVpnLink = optVpnLink.get();
// If the nexthop is the endpoint of Vpn2, then prefix must be advertised to Vpn1 in DC-GW, with nexthops
// pointing to the DPNs where Vpn1 is instantiated. LFIB in these DPNS must have a flow entry, with lower
// priority, where if Label matches then sets the lportTag of the Vpn2 endpoint and goes to LportDispatcher
// This is like leaking one of the Vpn2 routes towards Vpn1
String srcVpnUuid = interVpnLink.getVpnNameByIpAddress(nextHop);
String dstVpnUuid = interVpnLink.getOtherVpnNameByIpAddress(nextHop);
String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
long newLabel = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
if (newLabel == 0) {
LOG.error("addExtraRoute: Unable to fetch label from Id Manager. Bailing out of adding intervpnlink" + " route for destination {}", destination);
return;
}
ivpnLinkService.leakRoute(interVpnLink, srcVpnUuid, dstVpnUuid, destination, newLabel, RouteOrigin.STATIC);
} else {
Optional<Routes> optVpnExtraRoutes = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, rd != null ? rd : routerID, destination);
if (optVpnExtraRoutes.isPresent()) {
List<String> nhList = optVpnExtraRoutes.get().getNexthopIpList();
if (nhList != null && nhList.size() > 1) {
// If nhList is greater than one for vpnextraroute, a call to populatefib doesn't update vrfentry.
fibManager.refreshVrfEntry(primaryRd, destination);
} else {
L3vpnInput input = new L3vpnInput().setNextHop(operationalAdj).setNextHopIp(nextHop).setL3vni(l3vni).setPrimaryRd(primaryRd).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType).setRd(rd).setRouteOrigin(origin);
L3vpnRegistry.getRegisteredPopulator(encapType).populateFib(input, writeConfigTxn);
}
}
}
if (!writeConfigTxnPresent) {
writeConfigTxn.submit();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.
the class VpnUtil method getVrfEntriesByOrigin.
/**
* Retrieves the VrfEntries that belong to a given VPN filtered out by
* Origin, searching by its Route-Distinguisher.
*
* @param broker dataBroker service reference
* @param rd Route-distinguisher of the VPN
* @param originsToConsider Only entries whose origin is included in this list will be considered
* @return the list of VrfEntries
*/
public static List<VrfEntry> getVrfEntriesByOrigin(DataBroker broker, String rd, List<RouteOrigin> originsToConsider) {
List<VrfEntry> result = new ArrayList<>();
List<VrfEntry> allVpnVrfEntries = getAllVrfEntries(broker, rd);
for (VrfEntry vrfEntry : allVpnVrfEntries) {
if (originsToConsider.contains(RouteOrigin.value(vrfEntry.getOrigin()))) {
result.add(vrfEntry);
}
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.
the class VpnUtil method removeVrfEntriesByOrigin.
/**
* Remove from MDSAL all those VrfEntries in a VPN that have an specific RouteOrigin.
*
* @param broker dataBroker service reference
* @param rd Route Distinguisher
* @param origin Origin of the Routes to be removed (see {@link RouteOrigin})
*/
public static void removeVrfEntriesByOrigin(DataBroker broker, String rd, RouteOrigin origin) {
InstanceIdentifier<VrfTables> vpnVrfTableIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).build();
Optional<VrfTables> vrfTablesOpc = read(broker, LogicalDatastoreType.CONFIGURATION, vpnVrfTableIid);
if (vrfTablesOpc.isPresent()) {
VrfTables vrfTables = vrfTablesOpc.get();
WriteTransaction tx = broker.newWriteOnlyTransaction();
for (VrfEntry vrfEntry : vrfTables.getVrfEntry()) {
if (origin == RouteOrigin.value(vrfEntry.getOrigin())) {
tx.delete(LogicalDatastoreType.CONFIGURATION, vpnVrfTableIid.child(VrfEntry.class, vrfEntry.getKey()));
}
}
tx.submit();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.
the class InterVpnLinkUtil method leakRoute.
/**
* Leaks a route from one VPN to another. By default, the origin for this leaked route is INTERVPN.
*
* @param broker dataBroker service reference
* @param bgpManager Used to advertise routes to the BGP Router
* @param interVpnLink Reference to the object that holds the info about the link between the 2 VPNs
* @param srcVpnUuid UUID of the VPN that has the route that is going to be leaked to the other VPN
* @param dstVpnUuid UUID of the VPN that is going to receive the route
* @param prefix Prefix of the route
* @param label Label of the route in the original VPN
*/
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public static void leakRoute(DataBroker broker, IBgpManager bgpManager, InterVpnLink interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label) {
Preconditions.checkNotNull(interVpnLink);
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(srcVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, interVpnLink.getName());
// The destination VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, interVpnLink.getName());
boolean destinationIs1stEndpoint = interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid);
String endpointIp = destinationIs1stEndpoint ? interVpnLink.getSecondEndpoint().getIpAddress().getValue() : interVpnLink.getFirstEndpoint().getIpAddress().getValue();
VrfEntry newVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, endpointIp, RouteOrigin.INTERVPN, null).build();
String dstVpnRd = VpnUtil.getVpnRd(broker, dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
VpnUtil.asyncWrite(broker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, 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
Optional<InterVpnLinkState> optVpnLinkState = getInterVpnLinkState(broker, interVpnLink.getName());
if (optVpnLinkState.isPresent()) {
InterVpnLinkState vpnLinkState = optVpnLinkState.get();
List<BigInteger> dpnIdList = destinationIs1stEndpoint ? vpnLinkState.getFirstEndpointState().getDpId() : vpnLinkState.getSecondEndpointState().getDpId();
List<String> nexthops = new ArrayList<>();
for (BigInteger dpnId : dpnIdList) {
nexthops.add(InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId));
}
try {
LOG.debug("Advertising route in VPN={} [prefix={} label={} nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
newVrfEntry.getDestPrefix(), nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
0, /*l2vni*/
null);
} catch (Exception ex) {
LOG.error("Could not advertise prefix {} with label {} to VPN rd={}", newVrfEntry.getDestPrefix(), label.intValue(), dstVpnRd, ex);
}
} else {
LOG.warn("Error when advertising leaked routes: Could not find State for InterVpnLink={}", interVpnLink.getName());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.
the class FibDSWriter method addFibEntryToDS.
public synchronized void addFibEntryToDS(String rd, String prefix, List<String> nextHopList, VrfEntry.EncapType encapType, int label, long l3vni, String gatewayMacAddress, RouteOrigin origin) {
if (rd == null || rd.isEmpty()) {
LOG.error("Prefix {} not associated with vpn", prefix);
return;
}
Preconditions.checkNotNull(nextHopList, "NextHopList can't be null");
for (String nextHop : nextHopList) {
if (nextHop == null || nextHop.isEmpty()) {
LOG.error("nextHop list contains null element");
return;
}
LOG.debug("Created vrfEntry for {} nexthop {} label {}", prefix, nextHop, label);
}
// Looking for existing prefix in MDSAL database
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
VrfEntryBuilder vrfEntryBuilder = new VrfEntryBuilder().setDestPrefix(prefix).setOrigin(origin.getValue());
buildVpnEncapSpecificInfo(vrfEntryBuilder, encapType, label, l3vni, gatewayMacAddress, nextHopList);
bgpUtil.update(vrfEntryId, vrfEntryBuilder.build());
}
Aggregations