use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class VpnFloatingIpHandler method cleanupFibEntries.
@Override
public void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp, final long label, WriteTransaction removeFlowInvTx, ProviderTypes provType) {
// Remove Prefix from BGP
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName, LOG);
// Remove custom FIB routes
// Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
ListenableFuture<RpcResult<Void>> labelFuture = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> {
if (result.isSuccessful()) {
Boolean removeTunnelFlow = Boolean.TRUE;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
if (NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
removeTunnelFlow = Boolean.FALSE;
}
}
if (removeTunnelFlow) {
removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
}
removeLFibTableEntry(dpnId, label, removeFlowInvTx);
RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
return JdkFutureAdapters.listenInPoolThread(labelFuture1);
} else {
String errMsg = String.format("onRemoveFloatingIp :RPC call to remove custom FIB entries " + "on dpn %s for prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("onRemoveFloatingIp : Error in removing the label or custom fib entries", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.debug("onRemoveFloatingIp : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName);
} else {
LOG.error("onRemoveFloatingIp : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class VrfEntryListener method update.
@Override
// originalRoutePath is a little dicey - safest to keep the checking even if not needed.
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
protected void update(InstanceIdentifier<VrfEntry> identifier, VrfEntry original, VrfEntry update) {
Preconditions.checkNotNull(update, "VrfEntry should not be null or empty.");
final String rd = identifier.firstKeyOf(VrfTables.class).getRouteDistinguisher();
LOG.debug("UPDATE: Updating Fib Entries to rd {} prefix {} route-paths {} origin {} old-origin {}", rd, update.getDestPrefix(), update.getRoutePaths(), update.getOrigin(), original.getOrigin());
// Handle BGP Routes first
if (RouteOrigin.value(update.getOrigin()) == RouteOrigin.BGP) {
bgpRouteVrfEntryHandler.updateFlows(identifier, original, update, rd);
LOG.info("UPDATE: Updated BGP advertised Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
return;
}
if (RouteOrigin.value(update.getOrigin()) == RouteOrigin.STATIC) {
List<RoutePaths> originalRoutePath = original.getRoutePaths();
List<RoutePaths> updateRoutePath = update.getRoutePaths();
LOG.info("UPDATE: Original route-path {} update route-path {} ", originalRoutePath, updateRoutePath);
// Updates need to be handled for extraroute even if original vrf entry route path is null or
// updated vrf entry route path is null. This can happen during tunnel events.
Optional<VpnInstanceOpDataEntry> optVpnInstance = fibUtil.getVpnInstanceOpData(rd);
List<String> usedRds = new ArrayList<>();
if (optVpnInstance.isPresent()) {
usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, optVpnInstance.get().getVpnId(), update.getDestPrefix());
}
// has nexthop , route needs to be created on remote Dpns
if (originalRoutePath == null || originalRoutePath.isEmpty() && updateRoutePath != null && !updateRoutePath.isEmpty() && usedRds.isEmpty()) {
// TODO(vivek): Though ugly, Not handling this code now, as each
// tep add event will invoke flow addition
LOG.trace("Original VRF entry NH is null for destprefix {}. And the prefix is not an extra route." + " This event is IGNORED here.", update.getDestPrefix());
return;
}
// has nexthop empty'ed out, route needs to be removed from remote Dpns
if (updateRoutePath == null || updateRoutePath.isEmpty() && originalRoutePath != null && !originalRoutePath.isEmpty() && usedRds.isEmpty()) {
LOG.trace("Original VRF entry had valid NH for destprefix {}. And the prefix is not an extra route." + "This event is IGNORED here.", update.getDestPrefix());
return;
}
// Update the used rds and vpntoextraroute containers only for the deleted nextHops.
List<String> nextHopsRemoved = FibHelper.getNextHopListFromRoutePaths(original);
nextHopsRemoved.removeAll(FibHelper.getNextHopListFromRoutePaths(update));
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
nextHopsRemoved.parallelStream().forEach(nextHopRemoved -> fibUtil.updateUsedRdAndVpnToExtraRoute(writeOperTxn, nextHopRemoved, rd, update.getDestPrefix()));
CheckedFuture<Void, TransactionCommitFailedException> operFuture = writeOperTxn.submit();
try {
operFuture.get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Exception encountered while submitting operational future for update vrfentry {}", update, e);
}
createFibEntries(identifier, update);
LOG.info("UPDATE: Updated static Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
return;
}
// Handle all other routes only on a cluster reboot
if (original.equals(update)) {
// Reboot use-case
createFibEntries(identifier, update);
LOG.info("UPDATE: Updated Non-static Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
return;
}
LOG.info("UPDATE: Ignoring update for FIB entry with rd {} prefix {} route-origin {} route-paths {}", rd, update.getDestPrefix(), update.getOrigin(), update.getRoutePaths());
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class BgpRouteVrfEntryHandler method deleteFibEntries.
/*
Please note that the following deleteFibEntries will be invoked only for BGP Imported Routes.
The invocation of the following method is via delete() callback from the MDSAL Batching Infrastructure
provided by ResourceBatchingManager
*/
private void deleteFibEntries(WriteTransaction writeTx, final InstanceIdentifier<VrfEntry> identifier, final VrfEntry vrfEntry, List<SubTransaction> subTxns) {
final VrfTablesKey vrfTableKey = identifier.firstKeyOf(VrfTables.class);
String rd = vrfTableKey.getRouteDistinguisher();
final VpnInstanceOpDataEntry vpnInstance = getFibUtil().getVpnInstance(vrfTableKey.getRouteDistinguisher());
if (vpnInstance == null) {
LOG.debug("VPN Instance for rd {} is not available from VPN Op Instance Datastore", rd);
return;
}
String vpnName = getFibUtil().getVpnNameFromId(vpnInstance.getVpnId());
final Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
if (vpnToDpnList != null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
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 {
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRds.get(0), vrfEntry.getDestPrefix());
}
} else {
extraRouteOptional = Optional.absent();
}
for (VpnToDpnList curDpn : vpnToDpnList) {
if (curDpn.getDpnState() == VpnToDpnList.DpnState.Active) {
deleteRemoteRoute(BigInteger.ZERO, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, writeTx, subTxns);
}
}
}
}
Aggregations