use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier in project netvirt by opendaylight.
the class VpnInterfaceManager method addNewAdjToVpnInterface.
protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd, Adjacency adj, Uint64 dpnId, TypedWriteTransaction<Operational> writeOperTxn, TypedWriteTransaction<Configuration> writeConfigTxn, TypedReadWriteTransaction<Configuration> writeInvTxn, Set<String> prefixListForRefreshFib) throws ExecutionException, InterruptedException {
String interfaceName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getName();
String configVpnName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getVpnInstanceName();
try {
Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
String vpnName = currVpnIntf.getVpnInstanceName();
VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> optAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, adjPath);
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
Uint32 l3vni = vpnInstanceOpData.getL3vni() == null ? Uint32.ZERO : vpnInstanceOpData.getL3vni();
VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
List<Adjacency> adjacencies = new ArrayList<>();
if (optAdjacencies.isPresent() && optAdjacencies.get().getAdjacency() != null) {
adjacencies.addAll(optAdjacencies.get().getAdjacency().values());
}
Uint32 vpnId = vpnUtil.getVpnId(vpnName);
L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName).setInterfaceName(currVpnIntf.getName()).setPrimaryRd(primaryRd).setRd(primaryRd);
Adjacency operationalAdjacency = null;
// Handling dual stack neutron port primary adjacency
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency && !adj.isPhysNetworkFunc()) {
LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to existing interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, currVpnIntf.getName());
if (interfaceState != null) {
processVpnInterfaceAdjacencies(dpnId, currVpnIntf.getLportTag().intValue(), vpnName, primaryRd, currVpnIntf.getName(), vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, prefixListForRefreshFib);
}
}
if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty() && adj.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.LearntIp ? RouteOrigin.DYNAMIC : RouteOrigin.STATIC;
String nh = adj.getNextHopIpList().get(0);
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
// FIXME: separate out to somehow?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnPrefixKey);
lock.lock();
try {
java.util.Optional<String> rdToAllocate = vpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(vpnId, null, prefix, vpnName, nh, dpnId);
if (rdToAllocate.isPresent()) {
input.setRd(rdToAllocate.get());
operationalAdjacency = populator.createOperationalAdjacency(input);
int label = operationalAdjacency.getLabel().intValue();
vpnManager.addExtraRoute(vpnName, adj.getIpAddress(), nh, rdToAllocate.get(), currVpnIntf.getVpnInstanceName(), l3vni, origin, currVpnIntf.getName(), operationalAdjacency, encapType, prefixListForRefreshFib, writeConfigTxn);
LOG.info("addNewAdjToVpnInterface: Added extra route ip {} nh {} rd {} vpnname {} label {}" + " Interface {} on dpn {}", adj.getIpAddress(), nh, rdToAllocate.get(), vpnName, label, currVpnIntf.getName(), dpnId);
} else {
LOG.error("addNewAdjToVpnInterface: No rds to allocate extraroute vpn {} prefix {}", vpnName, prefix);
return;
}
// Keeping the MPLS check for now.
if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
vpnsToImportRoute.forEach(vpn -> {
if (vpn.getVrfId() != null) {
vpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(vpn.getVpnId(), vpnId, prefix, vpnUtil.getVpnName(vpn.getVpnId()), nh, dpnId).ifPresent(rds -> vpnManager.addExtraRoute(vpnUtil.getVpnName(vpn.getVpnId()), adj.getIpAddress(), nh, rds, currVpnIntf.getVpnInstanceName(), l3vni, RouteOrigin.SELF_IMPORTED, currVpnIntf.getName(), opAdjacency, encapType, prefixListForRefreshFib, writeConfigTxn));
}
});
}
} finally {
lock.unlock();
}
} else if (adj.isPhysNetworkFunc()) {
// PNF adjacency.
LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
InstanceIdentifier<VpnInterface> vpnIfaceConfigidentifier = VpnUtil.getVpnInterfaceIdentifier(currVpnIntf.getName());
Optional<VpnInterface> vpnIntefaceConfig = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfaceConfigidentifier);
Prefixes pnfPrefix = VpnUtil.getPrefixToInterface(Uint64.ZERO, currVpnIntf.getName(), prefix, Prefixes.PrefixCue.PhysNetFunc);
if (vpnIntefaceConfig.isPresent()) {
pnfPrefix = VpnUtil.getPrefixToInterface(Uint64.ZERO, currVpnIntf.getName(), prefix, vpnIntefaceConfig.get().getNetworkId(), vpnIntefaceConfig.get().getNetworkType(), vpnIntefaceConfig.get().getSegmentationId().toJava(), Prefixes.PrefixCue.PhysNetFunc);
}
String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
writeOperTxn.mergeParentStructureMerge(VpnUtil.getPrefixToInterfaceIdentifier(vpnUtil.getVpnId(adj.getSubnetId().getValue()), prefix), pnfPrefix);
fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(), adj.getIpAddress(), emptyList(), null, /* EncapType */
Uint32.ZERO, /* label */
Uint32.ZERO, /*l3vni*/
null, /* gw-mac */
parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
input.setRd(adj.getVrfId());
}
if (operationalAdjacency == null) {
operationalAdjacency = populator.createOperationalAdjacency(input);
}
adjacencies.add(operationalAdjacency);
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
VpnInterfaceOpDataEntry newVpnIntf = VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.getLportTag().toJava(), currVpnIntf.getGatewayMacAddress(), currVpnIntf.getGatewayIpAddress());
writeOperTxn.mergeParentStructureMerge(identifier, newVpnIntf);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("addNewAdjToVpnInterface: Failed to read data store for interface {} dpn {} vpn {} rd {} ip " + "{}", interfaceName, dpnId, configVpnName, primaryRd, adj.getIpAddress());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier 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.linkstate.rev200120.Identifier in project netvirt by opendaylight.
the class VpnInterfaceManager method addVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addVpnInterface(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, @Nullable final List<Adjacency> oldAdjs, @Nullable final List<Adjacency> newAdjs) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
addVpnInterfaceCall(identifier, vpnInterface, oldAdjs, newAdjs, vpnName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier in project netvirt by opendaylight.
the class VpnInterfaceManager method processVpnInterfaceAdjacencies.
@SuppressWarnings("checkstyle:IllegalCatch")
protected void processVpnInterfaceAdjacencies(Uint64 dpnId, final int lportTag, String vpnName, String primaryRd, String interfaceName, final Uint32 vpnId, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn, TypedReadWriteTransaction<Configuration> writeInvTxn, Interface interfaceState, Set<String> prefixListForRefreshFib) throws ExecutionException, InterruptedException {
InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
// Read NextHops
Optional<VpnInterface> vpnInteface = Optional.empty();
try {
vpnInteface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, identifier);
} catch (InterruptedException | ExecutionException e) {
LOG.error("processVpnInterfaceAdjacencies: Failed to read data store for interface {} vpn {} rd {}" + "dpn {}", interfaceName, vpnName, primaryRd, dpnId);
}
Uuid intfnetworkUuid = null;
NetworkType networkType = null;
long segmentationId = -1L;
Adjacencies adjacencies = null;
if (vpnInteface.isPresent()) {
intfnetworkUuid = vpnInteface.get().getNetworkId();
networkType = vpnInteface.get().getNetworkType();
segmentationId = vpnInteface.get().getSegmentationId().toJava();
adjacencies = vpnInteface.get().augmentation(Adjacencies.class);
if (adjacencies == null) {
addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null, /*adjacencies*/
lportTag, null, /*gwMac*/
null, /*gatewayIp*/
writeOperTxn);
return;
}
}
// Get the rd of the vpn instance
String nextHopIp = null;
String gatewayIp = null;
try {
nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
} catch (Exception e) {
LOG.error("processVpnInterfaceAdjacencies: Unable to retrieve endpoint ip address for " + "dpnId {} for vpnInterface {} vpnName {}", dpnId, interfaceName, vpnName);
}
List<String> nhList = new ArrayList<>();
if (nextHopIp != null) {
nhList.add(nextHopIp);
LOG.debug("processVpnInterfaceAdjacencies: NextHop for interface {} on dpn {} in vpn {} is {}", interfaceName, dpnId, vpnName, nhList);
}
Optional<String> gwMac = Optional.empty();
String vpnInterfaceSubnetGwMacAddress = null;
VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
Uint32 l3vni = vpnInstanceOpData.getL3vni() != null ? vpnInstanceOpData.getL3vni() : Uint32.ZERO;
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
Map<AdjacencyKey, Adjacency> nextHopsMap = adjacencies != null ? adjacencies.getAdjacency() : Collections.<AdjacencyKey, Adjacency>emptyMap();
List<Adjacency> value = new ArrayList<>();
for (Adjacency nextHop : nextHopsMap.values()) {
String rd = primaryRd;
String nexthopIpValue = nextHop.getIpAddress().split("/")[0];
if (vpnInstanceOpData.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.InternetBGPVPN && NWUtil.isIpv4Address(nexthopIpValue)) {
String prefix = nextHop.getIpAddress() == null ? "null" : VpnUtil.getIpPrefix(nextHop.getIpAddress());
LOG.debug("processVpnInterfaceAdjacencies: UnsupportedOperation : Not Adding prefix {} to interface {}" + " as InternetVpn has an IPV4 address {}", prefix, interfaceName, vpnName);
continue;
}
if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
Prefixes.PrefixCue prefixCue = nextHop.isPhysNetworkFunc() ? Prefixes.PrefixCue.PhysNetFunc : Prefixes.PrefixCue.None;
LOG.debug("processVpnInterfaceAdjacencies: Adding prefix {} to interface {} with nextHopsMap {} " + "on dpn {} for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
Prefixes prefixes = intfnetworkUuid != null ? VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, intfnetworkUuid, networkType, segmentationId, prefixCue) : VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, prefixCue);
writeOperTxn.mergeParentStructureMerge(VpnUtil.getPrefixToInterfaceIdentifier(vpnUtil.getVpnId(vpnName), prefix), prefixes);
final Uuid subnetId = nextHop.getSubnetId();
gatewayIp = nextHop.getSubnetGatewayIp();
if (gatewayIp == null) {
Optional<String> gatewayIpOptional = vpnUtil.getVpnSubnetGatewayIp(subnetId);
if (gatewayIpOptional.isPresent()) {
gatewayIp = gatewayIpOptional.get();
}
}
if (gatewayIp != null) {
gwMac = getMacAddressForSubnetIp(vpnName, interfaceName, gatewayIp);
if (gwMac.isPresent()) {
// A valid mac-address is available for this subnet-gateway-ip
// Use this for programming ARP_RESPONDER table here. And save this
// info into vpnInterface operational, so it can used in VrfEntryProcessor
// to populate L3_GW_MAC_TABLE there.
arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
vpnInterfaceSubnetGwMacAddress = gwMac.get();
} else {
// A valid mac-address is not available for this subnet-gateway-ip
// Use the connected-mac-address to configure ARP_RESPONDER Table.
// Save this connected-mac-address as gateway-mac-address for the
// VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
if (gwMac.isPresent()) {
vpnUtil.setupGwMacIfExternalVpn(dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
} else {
LOG.error("processVpnInterfaceAdjacencies: Gateway MAC for subnet ID {} could not be " + "obtained, cannot create ARP responder flow for interface name {}, vpnName {}, " + "gwIp {}", subnetId, interfaceName, vpnName, gatewayIp);
}
}
} else {
LOG.warn("processVpnInterfaceAdjacencies: Gateway IP for subnet ID {} could not be obtained, " + "cannot create ARP responder flow for interface name {}, vpnName {}", subnetId, interfaceName, vpnName);
gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
}
LOG.info("processVpnInterfaceAdjacencies: Added prefix {} to interface {} with nextHopsMap {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
} else {
// Extra route adjacency
String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
// FIXME: separate this out somehow?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnPrefixKey);
lock.lock();
try {
java.util.Optional<String> rdToAllocate = vpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(vpnId, null, prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
if (rdToAllocate.isPresent()) {
rd = rdToAllocate.get();
LOG.info("processVpnInterfaceAdjacencies: The rd {} is allocated for the extraroute {}", rd, prefix);
} else {
LOG.error("processVpnInterfaceAdjacencies: No rds to allocate extraroute {}", prefix);
continue;
}
} finally {
lock.unlock();
}
LOG.info("processVpnInterfaceAdjacencies: Added prefix {} and nextHopList {} as extra-route for vpn{}" + " interface {} on dpn {}", nextHop.getIpAddress(), nextHop.getNextHopIpList(), vpnName, interfaceName, dpnId);
}
// Please note that primary adjacency will use a subnet-gateway-mac-address that
// can be different from the gateway-mac-address within the VRFEntry as the
// gateway-mac-address is a superset.
RouteOrigin origin = VpnUtil.getRouteOrigin(nextHop.getAdjacencyType());
L3vpnInput input = new L3vpnInput().setNextHop(nextHop).setRd(rd).setVpnName(vpnName).setInterfaceName(interfaceName).setNextHopIp(nextHopIp).setPrimaryRd(primaryRd).setSubnetGatewayMacAddress(vpnInterfaceSubnetGwMacAddress).setRouteOrigin(origin);
Adjacency operationalAdjacency = null;
try {
operationalAdjacency = registeredPopulator.createOperationalAdjacency(input);
} catch (NullPointerException e) {
LOG.error("processVpnInterfaceAdjacencies: failed to create operational adjacency: input: {}, {}", input, e.getMessage());
return;
}
if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
vpnManager.addExtraRoute(vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), rd, vpnName, l3vni, origin, interfaceName, operationalAdjacency, encapType, prefixListForRefreshFib, writeConfigTxn);
}
value.add(operationalAdjacency);
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, aug, lportTag, gwMac.isPresent() ? gwMac.get() : null, gatewayIp, writeOperTxn);
L3vpnInput input = new L3vpnInput().setNextHopIp(nextHopIp).setL3vni(l3vni.longValue()).setPrimaryRd(primaryRd).setGatewayMac(gwMac.orElse(null)).setInterfaceName(interfaceName).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType);
for (Adjacency nextHop : aug.nonnullAdjacency().values()) {
// Adjacencies other than primary Adjacencies are handled in the addExtraRoute call above.
if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
RouteOrigin origin = VpnUtil.getRouteOrigin(nextHop.getAdjacencyType());
input.setNextHop(nextHop).setRd(nextHop.getVrfId()).setRouteOrigin(origin);
registeredPopulator.populateFib(input, writeConfigTxn);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier 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