use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project openflowplugin by opendaylight.
the class FlatBatchGroupAdapters method adaptFlatBatchUpdateGroup.
/**
* Adapt flat batch update group.
* @param planStep batch step containing changes of the same type
* @param node pointer for RPC routing
* @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
* .opendaylight.groups.service.rev160315.SalGroupsBatchService#updateGroupsBatch(UpdateGroupsBatchInput)}
*/
public static UpdateGroupsBatchInput adaptFlatBatchUpdateGroup(final BatchPlanStep planStep, final NodeRef node) {
final List<BatchUpdateGroups> batchGroups = new ArrayList<>();
for (FlatBatchUpdateGroup batchUpdateGroup : planStep.<FlatBatchUpdateGroup>getTaskBag()) {
final BatchUpdateGroups updateGroups = new BatchUpdateGroupsBuilder(batchUpdateGroup).build();
batchGroups.add(updateGroups);
}
return new UpdateGroupsBatchInputBuilder().setBarrierAfter(planStep.isBarrierAfter()).setNode(node).setBatchUpdateGroups(batchGroups).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method addVpnInterfaceToVpn.
private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier, final VpnInterface vpnInterface, @Nullable final List<Adjacency> oldAdjs, @Nullable final List<Adjacency> newAdjs, final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class);
final String interfaceName = key.getName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
if (interfaceState != null) {
try {
final Uint64 dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
final int ifIndex = interfaceState.getIfIndex();
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
// TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
// (the inventory tx goes in last)
List<ListenableFuture<?>> futures = new ArrayList<>();
// set of prefix used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to
// missing remote next hop in bucket actions on bgp-vpn delete
Set<String> prefixListForRefreshFib = new HashSet<>();
ListenableFuture<?> confFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, invTx -> {
LOG.info("addVpnInterface: VPN Interface add event - intfName {} vpnName {}" + " on dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex, false, confTx, operTx, invTx, interfaceState, vpnName, prefixListForRefreshFib);
if (oldAdjs != null && !oldAdjs.equals(newAdjs)) {
LOG.info("addVpnInterface: Adjacency changed upon VPNInterface {}" + " Update for swapping VPN {} case.", interfaceName, vpnName);
if (newAdjs != null) {
for (Adjacency adj : newAdjs) {
if (oldAdjs.contains(adj)) {
oldAdjs.remove(adj);
} else {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, invTx, prefixListForRefreshFib);
}
}
}
}
for (Adjacency adj : oldAdjs) {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
}
}
}
})))));
Futures.addCallback(confFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
futures.add(confFuture);
Futures.addCallback(confFuture, new PostVpnInterfaceWorker(interfaceName, true, "Config"), MoreExecutors.directExecutor());
LOG.info("addVpnInterface: Addition of interface {} in VPN {} on dpn {}" + " processed successfully", interfaceName, vpnName, dpnId);
return futures;
});
} catch (NumberFormatException | IllegalStateException e) {
LOG.error("addVpnInterface: Unable to retrieve dpnId from interface operational data store for " + "interface {}. Interface addition on vpn {} failed", interfaceName, vpnName, e);
return;
}
} else if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
createFibEntryForRouterInterface(primaryRd, vpnInterface, interfaceName, confTx, vpnName);
LOG.info("addVpnInterface: Router interface {} for vpn {} on dpn {}", interfaceName, vpnName, vpnInterface.getDpnId());
});
LoggingFutures.addErrorLogging(future, LOG, "Error creating FIB entry for interface {} on VPN {}", vpnInterface.getName(), vpnName);
return Collections.singletonList(future);
});
} else {
LOG.info("addVpnInterface: Handling addition of VPN interface {} on vpn {} skipped as interfaceState" + " is not available", interfaceName, vpnName);
}
} else {
LOG.error("addVpnInterface: Handling addition of VPN interface {} on vpn {} dpn {} skipped" + " as vpn is pending delete", interfaceName, vpnName, vpnInterface.getDpnId());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInstanceAdjChange.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private List<ListenableFuture<?>> updateVpnInstanceAdjChange(VpnInterface original, VpnInterface update, String vpnInterfaceName, List<ListenableFuture<?>> futures) {
final Adjacencies origAdjs = original.augmentation(Adjacencies.class);
final List<Adjacency> oldAdjs = origAdjs != null && origAdjs.getAdjacency() != null ? new ArrayList<>(origAdjs.getAdjacency().values()) : new ArrayList<>();
final Adjacencies updateAdjs = update.augmentation(Adjacencies.class);
final List<Adjacency> newAdjs = updateAdjs != null && updateAdjs.getAdjacency() != null ? new ArrayList<>(updateAdjs.getAdjacency().values()) : new ArrayList<>();
final Uint64 dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
for (VpnInstanceNames vpnInterfaceVpnInstance : update.nonnullVpnInstanceNames().values()) {
String newVpnName = vpnInterfaceVpnInstance.getVpnName();
List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
// TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
// set of prefix used as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
// in bucket actions on bgp-vpn delete
Set<String> prefixListForRefreshFib = new HashSet<>();
ListenableFuture<?> configTxFuture = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterfaceName, newVpnName);
LOG.info("VPN Interface update event-intfName {} onto vpnName {} running config-driven", update.getName(), newVpnName);
// handle both addition and removal of adjacencies
// currently, new adjacency may be an extra route
boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(newVpnName);
if (!oldAdjs.equals(newAdjs)) {
for (Adjacency adj : copyNewAdjs) {
if (copyOldAdjs.contains(adj)) {
copyOldAdjs.remove(adj);
} else {
// add new adjacency
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
try {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, confTx, prefixListForRefreshFib);
} catch (RuntimeException e) {
LOG.error("Failed to add adjacency {} to vpn interface {} with" + " dpnId {}", adj, vpnInterfaceName, dpnId, e);
}
}
LOG.info("update: new Adjacency {} with nextHop {} label {} subnet {} " + " added to vpn interface {} on vpn {} dpnId {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName, dpnId);
}
}
for (Adjacency adj : copyOldAdjs) {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency && !adj.isPhysNetworkFunc()) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
// remove FIB entry
String vpnRd = vpnUtil.getVpnRd(newVpnName);
LOG.debug("update: remove prefix {} from the FIB and BGP entry " + "for the Vpn-Rd {} ", adj.getIpAddress(), vpnRd);
// remove BGP entry
fibManager.removeFibEntry(vpnRd, adj.getIpAddress(), null, confTx);
if (vpnRd != null && !vpnRd.equalsIgnoreCase(newVpnName)) {
bgpManager.withdrawPrefix(vpnRd, adj.getIpAddress());
}
} else {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
}
}
LOG.info("update: Adjacency {} with nextHop {} label {} subnet {} removed from" + " vpn interface {} on vpn {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName);
}
}
})));
Futures.addCallback(configTxFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
futures.add(configTxFuture);
for (ListenableFuture<?> future : futures) {
LoggingFutures.addErrorLogging(future, LOG, "update: failed for interface {} on vpn {}", update.getName(), update.getVpnInstanceNames());
}
} else {
LOG.error("update: Ignoring update of vpnInterface {}, as newVpnInstance {} with primaryRd {}" + " is already marked for deletion", vpnInterfaceName, newVpnName, primaryRd);
}
}
return futures;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInterfaceOnTepAdd.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateVpnInterfaceOnTepAdd(VpnInterfaceOpDataEntry vpnInterface, StateTunnelList stateTunnelList, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn) {
String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern();
AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
Map<AdjacencyKey, Adjacency> keyAdjacencyMap = adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency() : Collections.<AdjacencyKey, Adjacency>emptyMap();
if (keyAdjacencyMap.isEmpty()) {
LOG.trace("updateVpnInterfaceOnTepAdd: Adjacencies are empty for vpnInterface {} on dpn {}", vpnInterface, srcDpnId);
return;
}
String prefix = null;
List<Adjacency> value = new ArrayList<>();
boolean isFibNextHopAddReqd = false;
String vpnName = vpnInterface.getVpnInstanceName();
Uint32 vpnId = vpnUtil.getVpnId(vpnName);
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
LOG.info("updateVpnInterfaceOnTepAdd: AdjacencyList for interface {} on dpn {} vpn {} is {}", vpnInterface.getName(), vpnInterface.getDpnId(), vpnInterface.getVpnInstanceName(), keyAdjacencyMap);
for (Adjacency adj : keyAdjacencyMap.values()) {
String rd = adj.getVrfId();
rd = rd != null ? rd : vpnName;
prefix = adj.getIpAddress();
Uint32 label = adj.getLabel();
List<String> nhList = Collections.singletonList(srcTepIp);
List<String> nextHopList = adj.getNextHopIpList();
// Secondary adj nexthop is already pointing to primary adj IP address.
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
value.add(new AdjacencyBuilder(adj).setNextHopIpList(nhList).build());
if (nextHopList != null && !nextHopList.isEmpty()) {
/* everything right already */
} else {
isFibNextHopAddReqd = true;
}
} else {
Optional<VrfEntry> vrfEntryOptional = FibHelper.getVrfEntry(dataBroker, primaryRd, prefix);
if (!vrfEntryOptional.isPresent()) {
continue;
}
nhList = FibHelper.getNextHopListFromRoutePaths(vrfEntryOptional.get());
if (!nhList.contains(srcTepIp)) {
nhList.add(srcTepIp);
isFibNextHopAddReqd = true;
}
value.add(adj);
}
if (isFibNextHopAddReqd) {
updateLabelMapper(label, nhList);
LOG.info("updateVpnInterfaceOnTepAdd: Updated label mapper : label {} dpn {} prefix {} nexthoplist {}" + " vpn {} vpnid {} rd {} interface {}", label, srcDpnId, prefix, nhList, vpnInterface.getVpnInstanceName(), vpnId, rd, vpnInterface.getName());
// Update the VRF entry with nextHop
fibManager.updateRoutePathForFibEntry(primaryRd, prefix, srcTepIp, label, true, writeConfigTxn);
// Get the list of VPN's importing this route(prefix) .
// Then update the VRF entry with nhList
List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
fibManager.updateRoutePathForFibEntry(vpnRd, prefix, srcTepIp, label, true, writeConfigTxn);
LOG.info("updateVpnInterfaceOnTepAdd: Exported route with rd {} prefix {} nhList {} label {}" + " interface {} dpn {} from vpn {} to VPN {} vpnRd {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName, vpn.getVpnInstanceName(), vpnRd);
}
}
// since there is a nexthop change.
try {
if (!rd.equalsIgnoreCase(vpnName)) {
bgpManager.advertisePrefix(rd, null, /*macAddress*/
prefix, nhList, VrfEntry.EncapType.Mplsgre, label, Uint32.ZERO, /*evi*/
Uint32.ZERO, /*l2vni*/
null);
}
LOG.info("updateVpnInterfaceOnTepAdd: Advertised rd {} prefix {} nhList {} label {}" + " for interface {} on dpn {} vpn {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName);
} catch (Exception ex) {
LOG.error("updateVpnInterfaceOnTepAdd: Exception when advertising prefix {} nh {} label {}" + " on rd {} for interface {} on dpn {} vpn {}", prefix, nhList, label, rd, vpnInterface.getName(), srcDpnId, vpnName, ex);
}
}
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface).withKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName)).addAugmentation(aug).build();
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
writeOperTxn.mergeParentStructurePut(interfaceId, opInterface);
LOG.info("updateVpnInterfaceOnTepAdd: interface {} updated successully on tep add on dpn {} vpn {}", vpnInterface.getName(), srcDpnId, vpnName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method handleVpnInstanceUpdateForVpnInterface.
private boolean handleVpnInstanceUpdateForVpnInterface(InstanceIdentifier<VpnInterface> identifier, VpnInterface original, VpnInterface update, List<ListenableFuture<?>> futures) {
boolean isVpnInstanceUpdate = false;
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class);
final String interfaceName = key.getName();
List<String> oldVpnList = VpnUtil.getVpnListForVpnInterface(original);
List<String> oldVpnListCopy = new ArrayList<>();
oldVpnListCopy.addAll(oldVpnList);
List<String> newVpnList = VpnUtil.getVpnListForVpnInterface(update);
List<String> newVpnListCopy = new ArrayList<>();
newVpnListCopy.addAll(newVpnList);
oldVpnList.removeAll(newVpnList);
newVpnList.removeAll(oldVpnListCopy);
// This block will execute only on if there is a change in the VPN Instance.
if (!oldVpnList.isEmpty() || !newVpnList.isEmpty()) {
/*
* Internet BGP-VPN Instance update with single router:
* ====================================================
* In this case single VPN Interface will be part of maximum 2 VPN Instance only.
* 1st VPN Instance : router VPN or external BGP-VPN.
* 2nd VPN Instance : Internet BGP-VPN(router-gw update/delete) for public network access.
*
* VPN Instance UPDATE:
* oldVpnList = 0 and newVpnList = 1 (Internet BGP-VPN)
* oldVpnList = 1 and newVpnList = 0 (Internet BGP-VPN)
*
* External BGP-VPN Instance update with single router:
* ====================================================
* In this case single VPN interface will be part of maximum 1 VPN Instance only.
*
* Updated VPN Instance will be always either internal router VPN to
* external BGP-VPN or external BGP-VPN to internal router VPN swap.
*
* VPN Instance UPDATE:
* oldVpnList = 1 and newVpnList = 1 (router VPN to Ext-BGPVPN)
* oldVpnList = 1 and newVpnList = 1 (Ext-BGPVPN to router VPN)
*
* Dual Router VPN Instance Update:
* ================================
* In this case single VPN interface will be part of maximum 3 VPN Instance only.
*
* 1st VPN Instance : router VPN or external BGP-VPN-1.
* 2nd VPN Instance : router VPN or external BGP-VPN-2.
* 3rd VPN Instance : Internet BGP-VPN(router-gw update/delete) for public network access.
*
* Dual Router --> Associated with common external BGP-VPN Instance.
* 1st router and 2nd router are getting associated with single External BGP-VPN
* 1) add 1st router to external bgpvpn --> oldVpnList=1, newVpnList=1;
* 2) add 2nd router to the same external bgpvpn --> oldVpnList=1, newVpnList=0
* In this case, we need to call removeVpnInterfaceCall() followed by addVpnInterfaceCall()
*
*
*/
isVpnInstanceUpdate = true;
if (VpnUtil.isDualRouterVpnUpdate(oldVpnListCopy, newVpnListCopy)) {
if ((oldVpnListCopy.size() == 2 || oldVpnListCopy.size() == 3) && oldVpnList.size() == 1 && newVpnList.isEmpty()) {
// Identify the external BGP-VPN Instance and pass that value as newVpnList
List<String> externalBgpVpnList = new ArrayList<>();
for (String newVpnName : newVpnListCopy) {
String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnUtil.getVpnInstanceOpData(primaryRd);
if (vpnInstanceOpDataEntry.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPN) {
externalBgpVpnList.add(newVpnName);
break;
}
}
// This call will execute removeVpnInterfaceCall() followed by addVpnInterfaceCall()
updateVpnInstanceChange(identifier, interfaceName, original, update, oldVpnList, externalBgpVpnList, oldVpnListCopy, futures);
} else if ((oldVpnListCopy.size() == 2 || oldVpnListCopy.size() == 3) && oldVpnList.isEmpty() && newVpnList.size() == 1) {
// Identify the router VPN Instance and pass that value as oldVpnList
List<String> routerVpnList = new ArrayList<>();
for (String newVpnName : newVpnListCopy) {
String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnUtil.getVpnInstanceOpData(primaryRd);
if (vpnInstanceOpDataEntry.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPN) {
routerVpnList.add(newVpnName);
break;
}
}
// This call will execute removeVpnInterfaceCall() followed by addVpnInterfaceCall()
updateVpnInstanceChange(identifier, interfaceName, original, update, routerVpnList, newVpnList, oldVpnListCopy, futures);
} else {
// Handle remaining use cases.
updateVpnInstanceChange(identifier, interfaceName, original, update, oldVpnList, newVpnList, oldVpnListCopy, futures);
}
} else {
updateVpnInstanceChange(identifier, interfaceName, original, update, oldVpnList, newVpnList, oldVpnListCopy, futures);
}
}
return isVpnInstanceUpdate;
}
Aggregations