use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.local.routing.rev151009.LocalStaticConfig.NextHop 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.http.openconfig.net.yang.local.routing.rev151009.LocalStaticConfig.NextHop in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method handleStaticRoutes.
@Override
public void handleStaticRoutes(InterVpnLinkDataComposite ivpnLink) {
/*
* Checks if there are any static routes pointing to any of both
* InterVpnLink's endpoints. Goes through all routers checking if they have
* a route whose nexthop is an InterVpnLink endpoint
*/
// Map that corresponds a routerId with the L3VPN that it's been assigned to.
Map<String, String> routerXL3VpnMap = buildRouterXL3VPNMap();
// Retrieving all Routers
InstanceIdentifier<Routers> routersIid = InstanceIdentifier.builder(Neutron.class).child(Routers.class).build();
Optional<Routers> routerOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIid);
if (!routerOpData.isPresent()) {
return;
}
List<Router> routers = routerOpData.get().getRouter();
for (Router router : routers) {
String vpnId = routerXL3VpnMap.get(router.getUuid().getValue());
if (vpnId == null) {
LOG.warn("Could not find suitable VPN for router {}", router.getUuid());
// with next router
continue;
}
List<Routes> routerRoutes = router.getRoutes();
if (routerRoutes != null) {
for (Routes route : routerRoutes) {
handleStaticRoute(vpnId, route, ivpnLink);
}
}
}
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.local.routing.rev151009.LocalStaticConfig.NextHop 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, Long label, 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().setKey(new VrfEntryKey(prefix)).setDestPrefix(prefix).setRoutePaths(Collections.singletonList(FibHelper.buildRoutePath(endpointIp, label))).setOrigin(leakedOrigin).build();
String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
VpnUtil.asyncWrite(dataBroker, 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
List<BigInteger> 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.intValue(), 0, /*l3vni*/
0, /*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.http.openconfig.net.yang.local.routing.rev151009.LocalStaticConfig.NextHop in project netvirt by opendaylight.
the class InterVpnLinkListener method remove.
@Override
protected void remove(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink del) {
LOG.debug("Reacting to InterVpnLink {} removal", del.getName());
// Remove learnt routes
// Remove entries in the LPortDispatcher table
// Remove the corresponding entries in InterVpnLinkState
// For each endpoint, remove all routes that have been learnt by intervpnLink
String vpn1Uuid = del.getFirstEndpoint().getVpnUuid().getValue();
String rd1 = VpnUtil.getVpnRd(dataBroker, vpn1Uuid);
LOG.debug("Removing leaked routes in VPN {} rd={}", vpn1Uuid, rd1);
VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd1, RouteOrigin.INTERVPN);
List<VrfEntry> vrfEntriesSecondEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd1, del.getSecondEndpoint().getIpAddress().getValue());
String vpn2Uuid = del.getSecondEndpoint().getVpnUuid().getValue();
String rd2 = VpnUtil.getVpnRd(dataBroker, vpn2Uuid);
LOG.debug("Removing leaked routes in VPN {} rd={}", vpn2Uuid, rd2);
VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd2, RouteOrigin.INTERVPN);
List<VrfEntry> vrfEntriesFirstEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd2, del.getFirstEndpoint().getIpAddress().getValue());
Optional<InterVpnLinkState> optIVpnLinkState = InterVpnLinkUtil.getInterVpnLinkState(dataBroker, del.getName());
if (optIVpnLinkState.isPresent()) {
InterVpnLinkState interVpnLinkState = optIVpnLinkState.get();
boolean isVpnFirstEndPoint = true;
if (interVpnLinkState.getFirstEndpointState() != null) {
Long firstEndpointLportTag = interVpnLinkState.getFirstEndpointState().getLportTag();
removeVpnLinkEndpointFlows(del, vpn2Uuid, rd1, interVpnLinkState.getSecondEndpointState().getDpId(), firstEndpointLportTag.intValue(), del.getFirstEndpoint().getIpAddress().getValue(), vrfEntriesSecondEndpoint, isVpnFirstEndPoint);
} else {
LOG.info("Could not get first endpoint state attributes for InterVpnLink {}", del.getName());
}
isVpnFirstEndPoint = false;
if (interVpnLinkState.getSecondEndpointState() != null) {
Long secondEndpointLportTag = interVpnLinkState.getSecondEndpointState().getLportTag();
removeVpnLinkEndpointFlows(del, vpn1Uuid, rd2, interVpnLinkState.getFirstEndpointState().getDpId(), secondEndpointLportTag.intValue(), del.getSecondEndpoint().getIpAddress().getValue(), vrfEntriesFirstEndpoint, isVpnFirstEndPoint);
} else {
LOG.info("Could not get second endpoint state attributes for InterVpnLink {}", del.getName());
}
}
VpnUtil.removeVrfEntries(dataBroker, rd1, vrfEntriesSecondEndpoint);
VpnUtil.removeVrfEntries(dataBroker, rd2, vrfEntriesFirstEndpoint);
VpnUtil.withdrawRoutes(bgpManager, rd1, vrfEntriesSecondEndpoint);
VpnUtil.withdrawRoutes(bgpManager, rd2, vrfEntriesFirstEndpoint);
// Release idManager with LPortTag associated to endpoints
LOG.debug("Releasing InterVpnLink {} endpoints LportTags", del.getName());
InterVpnLinkKey key = del.getKey();
Uuid firstEndpointVpnUuid = del.getFirstEndpoint().getVpnUuid();
Uuid secondEndpointVpnUuid = del.getSecondEndpoint().getVpnUuid();
releaseVpnLinkLPortTag(key.getName() + firstEndpointVpnUuid.getValue());
releaseVpnLinkLPortTag(key.getName() + secondEndpointVpnUuid.getValue());
// Routes with nextHop pointing to an end-point of the inter-vpn-link are populated into FIB table.
// The action in that case is a nx_resubmit to LPortDispatcher table. This is done in FibManager.
// At this point. we need to check if is there any entry in FIB table pointing to LPortDispatcher table.
// Remove it in that case.
// Removing the InterVpnLinkState
InstanceIdentifier<InterVpnLinkState> interVpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(del.getName());
VpnUtil.delete(dataBroker, LogicalDatastoreType.CONFIGURATION, interVpnLinkStateIid);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.local.routing.rev151009.LocalStaticConfig.NextHop in project netvirt by opendaylight.
the class VpnRpcServiceImpl method addStaticRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
String destination = input.getDestination();
String vpnInstanceName = input.getVpnInstanceName();
String nexthop = input.getNexthop();
Long label = input.getLabel();
LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
if (!rpcErrors.isEmpty()) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
return result;
}
if (label == null || label == 0) {
label = (long) VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
if (label == 0) {
String message = "Unable to retrieve a new Label for the new Route";
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
}
String vpnRd = VpnUtil.getVpnRd(dataBroker, input.getVpnInstanceName());
VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
if (vpnRd == null) {
String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
if (optIVpnLink.isPresent()) {
try {
InterVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label.intValue(), dataBroker, fibManager, bgpManager);
} catch (Exception e) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
return result;
}
} else {
vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
null, /*Adjacency*/
encapType, null);
}
AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
result.set(RpcResultBuilder.success(labelOutput).build());
return result;
}
Aggregations