import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NWUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder;
private final IVpnManager vpnManager;
private final ArpResponderHandler arpResponderHandler;
private final JobCoordinator jobCoordinator;
+ private final VpnUtil vpnUtil;
private final ConcurrentHashMap<String, Runnable> vpnIntfMap = new ConcurrentHashMap<>();
final IVpnManager vpnManager,
final ArpResponderHandler arpResponderHandler,
final JobCoordinator jobCoordinator,
- final CacheProvider cacheProvider) {
+ final CacheProvider cacheProvider,
+ final VpnUtil vpnUtil) {
super(VpnInterface.class, VpnInterfaceManager.class);
this.dataBroker = dataBroker;
this.vpnManager = vpnManager;
this.arpResponderHandler = arpResponderHandler;
this.jobCoordinator = jobCoordinator;
+ this.vpnUtil = vpnUtil;
vpnInstanceOpDataEntryCache = new InstanceIdDataObjectCache<>(VpnInstanceOpDataEntry.class, dataBroker,
LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(
final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
- String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
- if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+ String primaryRd = vpnUtil.getPrimaryRd(vpnName);
+ if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
- boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
+ boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
if (interfaceState != null) {
try {
final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
oldAdjs.remove(adj);
} else {
if (!isBgpVpnInternetVpn
- || VpnUtil.isAdjacencyEligibleToVpnInternet(
- dataBroker, adj)) {
+ || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier,
primaryRd, adj, dpnId, operTx, confTx);
}
}
for (Adjacency adj : oldAdjs) {
if (!isBgpVpnInternetVpn
- || VpnUtil.isAdjacencyEligibleToVpnInternet(
- dataBroker, adj)) {
+ || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId,
operTx, confTx);
}
Interface interfaceState,
final String vpnName) {
final String interfaceName = vpnInterface.getName();
- Optional<VpnInterfaceOpDataEntry> optOpVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker,
- interfaceName, vpnName);
+ Optional<VpnInterfaceOpDataEntry> optOpVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(interfaceName,
+ vpnName);
VpnInterfaceOpDataEntry opVpnInterface = optOpVpnInterface.isPresent() ? optOpVpnInterface.get() : null;
- boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
+ boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
if (!isInterfaceUp) {
LOG.info("processVpnInterfaceUp: Binding vpn service to interface {} onto dpn {} for vpn {}",
interfaceName, dpId, vpnName);
- long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
+ long vpnId = vpnUtil.getVpnId(vpnName);
if (vpnId == VpnConstants.INVALID_ID) {
LOG.warn("processVpnInterfaceUp: VpnInstance to VPNId mapping not available for VpnName {}"
+ " processing vpninterface {} on dpn {}, bailing out now.", vpnName, interfaceName,
}
boolean waitForVpnInterfaceOpRemoval = false;
- if (opVpnInterface != null && !opVpnInterface.isScheduledForRemove()) {
+ if (opVpnInterface != null) {
String opVpnName = opVpnInterface.getVpnInstanceName();
String primaryInterfaceIp = null;
if (opVpnName.equals(vpnName)) {
// If so, we have to process ADD, as this might be a DPN Restart with Remove and Add triggered
// back to back
// However, if the primary VRF Entry for this VPNInterface exists, please continue bailing out !
- List<Adjacency> adjs = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, interfaceName);
+ List<Adjacency> adjs = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(interfaceName);
if (adjs == null) {
LOG.error("processVpnInterfaceUp: VPN Interface {} on dpn {} for vpn {} failed as adjacencies"
+ " for this vpn interface could not be obtained", interfaceName, dpId,
return;
}
// Get the rd of the vpn instance
- VrfEntry vrf = VpnUtil.getVrfEntry(dataBroker, primaryRd, primaryInterfaceIp);
+ VrfEntry vrf = vpnUtil.getVrfEntry(primaryRd, primaryInterfaceIp);
if (vrf != null) {
LOG.error("processVpnInterfaceUp: VPN Interface {} on dpn {} for vpn {} already provisioned ,"
+ " bailing out from here.", interfaceName, dpId, vpnName);
processVpnInterfaceAdjacencies(dpId, lportTag, vpnName, primaryRd, interfaceName,
vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState);
if (!isBgpVpnInternetVpn) {
- VpnUtil.bindService(vpnName, interfaceName, dataBroker, false /*isTunnelInterface*/,
- jobCoordinator);
+ vpnUtil.bindService(vpnName, interfaceName, false /*isTunnelInterface*/);
}
LOG.info("processVpnInterfaceUp: Plumbed vpn interface {} onto dpn {} for vpn {}", interfaceName,
dpId, vpnName);
if (interfaceManager.isExternalInterface(interfaceName)) {
- processExternalVpnInterface(interfaceName, vpnName, vpnId, dpId, lportTag, writeInvTxn,
+ processExternalVpnInterface(interfaceName, vpnName, dpId, lportTag,
NwConstants.ADD_FLOW);
}
return;
LOG.warn("processVpnInterfaceUp: VPN Interface {} removal on dpn {} for vpn {}"
+ " by FIB did not complete on time," + " bailing addition ...", interfaceName,
dpId, vpnName);
- VpnUtil.unsetScheduledToRemoveForVpnInterface(txRunner, interfaceName);
+ vpnUtil.unsetScheduledToRemoveForVpnInterface(interfaceName);
return;
}
// VPNInterface got removed, proceed with Add
processVpnInterfaceAdjacencies(dpId, lportTag, vpnName, primaryRd, interfaceName,
vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState);
if (!isBgpVpnInternetVpn) {
- VpnUtil.bindService(vpnName, interfaceName, dataBroker, false/*isTunnelInterface*/, jobCoordinator);
+ vpnUtil.bindService(vpnName, interfaceName, false/*isTunnelInterface*/);
}
LOG.info("processVpnInterfaceUp: Plumbed vpn interface {} onto dpn {} for vpn {} after waiting for"
+ " FIB to clean up", interfaceName, dpId, vpnName);
if (interfaceManager.isExternalInterface(interfaceName)) {
- processExternalVpnInterface(interfaceName, vpnName, vpnId, dpId,
- lportTag, writeInvTxn, NwConstants.ADD_FLOW);
+ processExternalVpnInterface(interfaceName, vpnName, dpId,
+ lportTag, NwConstants.ADD_FLOW);
}
} else {
- // Interface is retained in the DPN, but its Link Up.
- // Advertise prefixes again for this interface to BGP
- InstanceIdentifier<VpnInterface> identifier =
- VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName());
- InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier =
- VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
- advertiseAdjacenciesForVpnToBgp(primaryRd, dpId, vpnInterfaceOpIdentifier, vpnName, interfaceName);
- // Perform similar operation as interface add event for extraroutes.
- InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
- Optional<Adjacencies> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
- if (!optAdjacencies.isPresent()) {
- LOG.trace("No config adjacencies present for vpninterface {}", vpnInterface);
- return;
- }
- List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
- for (Adjacency adjacency : adjacencies) {
- if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
- continue;
+ try {
+ // Interface is retained in the DPN, but its Link Up.
+ // Advertise prefixes again for this interface to BGP
+ InstanceIdentifier<VpnInterface> identifier =
+ VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName());
+ InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier =
+ VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
+ advertiseAdjacenciesForVpnToBgp(primaryRd, dpId, vpnInterfaceOpIdentifier, vpnName, interfaceName);
+ // Perform similar operation as interface add event for extraroutes.
+ InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
+ Optional<Adjacencies> optAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, path);
+ if (!optAdjacencies.isPresent()) {
+ LOG.trace("No config adjacencies present for vpninterface {}", vpnInterface);
+ return;
}
- // if BGPVPN Internet, filter only IPv6 Adjacencies
- if (isBgpVpnInternetVpn && !VpnUtil.isAdjacencyEligibleToVpnInternet(
- dataBroker, adjacency)) {
- continue;
+ List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
+ for (Adjacency adjacency : adjacencies) {
+ if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
+ continue;
+ }
+ // if BGPVPN Internet, filter only IPv6 Adjacencies
+ if (isBgpVpnInternetVpn && !vpnUtil.isAdjacencyEligibleToVpnInternet(adjacency)) {
+ continue;
+ }
+ addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adjacency,
+ dpId, writeOperTxn, writeConfigTxn);
}
- addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adjacency,
- dpId, writeOperTxn, writeConfigTxn);
+ } catch (ReadFailedException e) {
+ LOG.error("processVpnInterfaceUp: Failed to read data store for interface {} vpn {} rd {} dpn {}",
+ interfaceName, vpnName, primaryRd, dpId);
}
}
}
- private void processExternalVpnInterface(String interfaceName, String vpnName, long vpnId, BigInteger dpId,
- int lportTag, WriteTransaction writeInvTxn, int addOrRemove) {
+ private void processExternalVpnInterface(String interfaceName, String vpnName, BigInteger dpId,
+ int lportTag, int addOrRemove) {
Uuid extNetworkId;
try {
// vpn instance of ext-net interface is the network-id
return;
}
- List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, extNetworkId);
+ List<Uuid> routerIds = vpnUtil.getExternalNetworkRouterIds(extNetworkId);
if (routerIds == null || routerIds.isEmpty()) {
LOG.info("processExternalVpnInterface: No router is associated with {}."
+ " Bailing out of processing external vpn interface {} on dpn {} for vpn {}",
+ " for vpn {}", routerIds, interfaceName, dpId, vpnName);
for (Uuid routerId : routerIds) {
String routerName = routerId.getValue();
- BigInteger primarySwitch = VpnUtil.getPrimarySwitchForRouter(dataBroker, routerName);
+ BigInteger primarySwitch = vpnUtil.getPrimarySwitchForRouter(routerName);
if (Objects.equals(primarySwitch, dpId)) {
- Routers router = VpnUtil.getExternalRouter(dataBroker, routerName);
+ Routers router = vpnUtil.getExternalRouter(routerName);
if (router != null) {
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName,
VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), router.getExtGwMacAddress(),
- dpId, interfaceName, lportTag, writeInvTxn);
+ dpId, interfaceName, lportTag);
} else {
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName,
VpnUtil.getIpsListFromExternalIps(router.getExternalIps()),
return;
}
- //Read NextHops
- InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
- Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
- if (adjacencies.isPresent()) {
- List<Adjacency> nextHops = adjacencies.get().getAdjacency();
-
- if (!nextHops.isEmpty()) {
- LOG.debug("advertiseAdjacenciesForVpnToBgp: NextHops are {} for interface {} on dpn {} for vpn {}"
- + " rd {}", nextHops, interfaceName, dpnId, vpnName, rd);
- VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
- long l3vni = vpnInstanceOpData.getL3vni();
- VrfEntry.EncapType encapType = VpnUtil.isL3VpnOverVxLan(l3vni)
- ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
- for (Adjacency nextHop : nextHops) {
- if (nextHop.getAdjacencyType() == AdjacencyType.ExtraRoute) {
- continue;
- }
- String gatewayMac = null;
- long label = 0;
- if (VpnUtil.isL3VpnOverVxLan(l3vni)) {
- final VpnPortipToPort gwPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker,
- vpnInstanceOpData.getVpnInstanceName(), nextHop.getIpAddress());
- gatewayMac = arpResponderHandler.getGatewayMacAddressForInterface(gwPort, interfaceName).get();
- } else {
- label = nextHop.getLabel();
- }
- try {
- LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Adding Fib Entry rd {} prefix {}"
- + " nexthop {} label {}", rd, nextHop.getIpAddress(), nextHopIp, label);
- bgpManager.advertisePrefix(rd, nextHop.getMacAddress(), nextHop.getIpAddress(), nextHopIp,
- encapType, (int)label, l3vni, 0 /*l2vni*/,
- gatewayMac);
- LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Added Fib Entry rd {} prefix {}"
- + " nexthop {} label {} for interface {} on dpn {} for vpn {}", rd,
- nextHop.getIpAddress(), nextHopIp, label, interfaceName, dpnId, vpnName);
- } catch (Exception e) {
- LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to advertise prefix {} in vpn {} with rd {}"
- + " for interface {} on dpn {}", nextHop.getIpAddress(),
- vpnName, rd, interfaceName, dpnId, e);
+ try {
+ //Read NextHops
+ InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
+ Optional<AdjacenciesOp> adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, path);
+ if (adjacencies.isPresent()) {
+ List<Adjacency> nextHops = adjacencies.get().getAdjacency();
+ if (!nextHops.isEmpty()) {
+ LOG.debug("advertiseAdjacenciesForVpnToBgp: NextHops are {} for interface {} on dpn {} for vpn {}"
+ + " rd {}", nextHops, interfaceName, dpnId, vpnName, rd);
+ VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(rd);
+ long l3vni = vpnInstanceOpData.getL3vni();
+ VrfEntry.EncapType encapType = VpnUtil.isL3VpnOverVxLan(l3vni)
+ ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
+ for (Adjacency nextHop : nextHops) {
+ if (nextHop.getAdjacencyType() == AdjacencyType.ExtraRoute) {
+ continue;
+ }
+ String gatewayMac = null;
+ long label = 0;
+ if (VpnUtil.isL3VpnOverVxLan(l3vni)) {
+ final VpnPortipToPort gwPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(
+ vpnInstanceOpData.getVpnInstanceName(), nextHop.getIpAddress());
+ gatewayMac = arpResponderHandler.getGatewayMacAddressForInterface(gwPort, interfaceName)
+ .get();
+ } else {
+ label = nextHop.getLabel();
+ }
+ try {
+ LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Adding Fib Entry rd {} prefix {}"
+ + " nexthop {} label {}", rd, nextHop.getIpAddress(), nextHopIp, label);
+ bgpManager.advertisePrefix(rd, nextHop.getMacAddress(), nextHop.getIpAddress(), nextHopIp,
+ encapType, (int)label, l3vni, 0 /*l2vni*/,
+ gatewayMac);
+ LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Added Fib Entry rd {} prefix {}"
+ + " nexthop {} label {} for interface {} on dpn {} for vpn {}", rd,
+ nextHop.getIpAddress(), nextHopIp, label, interfaceName, dpnId, vpnName);
+ } catch (Exception e) {
+ LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to advertise prefix {} in vpn {}"
+ + " with rd {} for interface {} on dpn {}", nextHop.getIpAddress(), vpnName, rd,
+ interfaceName, dpnId, e);
+ }
}
}
}
+ } catch (ReadFailedException e) {
+ LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to read data store for interface {} dpn {} nexthop {}"
+ + "vpn {} rd {}", interfaceName, dpnId, nextHopIp, vpnName, rd);
}
}
String vpnName, String interfaceName, WriteTransaction writeConfigTxn) {
//Read NextHops
InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
- Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
-
- String rd = VpnUtil.getVpnRd(dataBroker, interfaceName);
+ String rd = vpnUtil.getVpnRd(interfaceName);
if (rd == null) {
LOG.error("withdrawAdjacenciesForVpnFromBgp: Unable to recover rd for interface {} in vpn {}",
interfaceName, vpnName);
}
LOG.info("withdrawAdjacenciesForVpnFromBgp: For interface {} in vpn {} with rd {}", interfaceName,
vpnName, rd);
+ Optional<AdjacenciesOp> adjacencies = Optional.absent();
+ try {
+ adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ path);
+ } catch (ReadFailedException e) {
+ LOG.error("withdrawAdjacenciesForVpnFromBgp: Failed to read data store for interface {} vpn {}",
+ interfaceName, vpnName);
+ }
if (adjacencies.isPresent()) {
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
// Read NextHops
InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
- Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
+ Optional<Adjacencies> adjacencies = Optional.absent();
+ try {
+ adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ path);
+ } catch (ReadFailedException e) {
+ LOG.error("processVpnInterfaceAdjacencies: Failed to read data store for interface {} vpn {} rd {}"
+ + "dpn {}", interfaceName, vpnName, primaryRd, dpnId);
+ }
if (!adjacencies.isPresent()) {
addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null/*adjacencies*/, lportTag,
null/*gwMac*/, writeOperTxn);
return;
}
-
// Get the rd of the vpn instance
String nextHopIp = null;
try {
}
Optional<String> gwMac = Optional.absent();
String vpnInterfaceSubnetGwMacAddress = null;
- VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
+ VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
Long l3vni = vpnInstanceOpData.getL3vni();
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
writeOperTxn.merge(
LogicalDatastoreType.OPERATIONAL,
VpnUtil.getPrefixToInterfaceIdentifier(
- VpnUtil.getVpnId(dataBroker, vpnName), prefix),
+ vpnUtil.getVpnId(vpnName), prefix),
VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, nextHop.getSubnetId(),
prefixCue), true);
final Uuid subnetId = nextHop.getSubnetId();
String gatewayIp = nextHop.getSubnetGatewayIp();
if (gatewayIp == null) {
- Optional<String> gatewayIpOptional = VpnUtil.getVpnSubnetGatewayIp(dataBroker, subnetId);
+ Optional<String> gatewayIpOptional = vpnUtil.getVpnSubnetGatewayIp(subnetId);
if (gatewayIpOptional.isPresent()) {
gatewayIp = gatewayIpOptional.get();
}
// VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
if (gwMac.isPresent()) {
- VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName,
- vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
+ vpnUtil.setupGwMacIfExternalVpn(dpnId, interfaceName, vpnId, writeInvTxn,
+ NwConstants.ADD_FLOW, gwMac.get());
arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName,
gatewayIp, gwMac.get());
} else {
String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
synchronized (vpnPrefixKey.intern()) {
- java.util.Optional<String> rdToAllocate = VpnUtil
- .allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null,
- prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
+ 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 {}",
private void addVpnInterfaceToOperational(String vpnName, String interfaceName, BigInteger dpnId, AdjacenciesOp aug,
long lportTag, String gwMac, WriteTransaction writeOperTxn) {
VpnInterfaceOpDataEntry opInterface =
- VpnUtil.getVpnInterfaceOpDataEntry(interfaceName, vpnName, aug, dpnId, Boolean.FALSE, lportTag, gwMac);
+ VpnUtil.getVpnInterfaceOpDataEntry(interfaceName, vpnName, aug, dpnId, lportTag, gwMac);
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
writeOperTxn.put(LogicalDatastoreType.OPERATIONAL, interfaceId, opInterface,
String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
- AdjacenciesOp adjacencies = vpnInterface.getAugmentation(AdjacenciesOp.class);
+ AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : new ArrayList<>();
if (adjList.isEmpty()) {
LOG.trace("updateVpnInterfaceOnTepAdd: Adjacencies are empty for vpnInterface {} on dpn {}",
List<Adjacency> value = new ArrayList<>();
boolean isNextHopAddReqd = false;
String vpnName = vpnInterface.getVpnInstanceName();
- long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
- String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
+ long 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(), adjList);
//Get the list of VPN's importing this route(prefix) .
// Then update the VRF entry with nhList
- List<VpnInstanceOpDataEntry> vpnsToImportRoute =
- VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
+ List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface)
- .setKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName))
+ .withKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName))
.addAugmentation(AdjacenciesOp.class, aug).build();
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
WriteTransaction writeConfigTxn,
WriteTransaction writeOperTxn) {
- AdjacenciesOp adjacencies = vpnInterface.getAugmentation(AdjacenciesOp.class);
+ AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : new ArrayList<>();
String prefix = null;
long label = 0;
String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
String vpnName = vpnInterface.getVpnInstanceName();
- long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
- String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
+ long vpnId = vpnUtil.getVpnId(vpnName);
+ String primaryRd = vpnUtil.getVpnRd(vpnName);
if (adjList != null) {
List<Adjacency> value = new ArrayList<>();
LOG.info("updateVpnInterfaceOnTepDelete: AdjacencyList for interface {} on dpn {} vpn {} is {}",
//Get the list of VPN's importing this route(prefix) .
// Then update the VRF entry with nhList
- List<VpnInstanceOpDataEntry> vpnsToImportRoute =
- VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
+ List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface)
- .setKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName))
+ .withKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName))
.addAugmentation(AdjacenciesOp.class, aug).build();
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
private List<VpnInstanceOpDataEntry> getVpnsExportingMyRoute(final String vpnName) {
List<VpnInstanceOpDataEntry> vpnsToExportRoute = new ArrayList<>();
- String vpnRd = VpnUtil.getVpnRd(dataBroker, vpnName);
- final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
+ String vpnRd = vpnUtil.getVpnRd(vpnName);
+ final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnUtil.getVpnInstanceOpData(vpnRd);
if (vpnInstanceOpDataEntry == null) {
LOG.debug("getVpnsExportingMyRoute: Could not retrieve vpn instance op data for {}"
+ " to check for vpns exporting the routes", vpnName);
};
vpnsToExportRoute =
- VpnUtil.getAllVpnInstanceOpData(dataBroker).stream().filter(excludeVpn).filter(matchRTs).collect(
+ vpnUtil.getAllVpnInstanceOpData().stream().filter(excludeVpn).filter(matchRTs).collect(
Collectors.toList());
return vpnsToExportRoute;
}
void handleVpnsExportingRoutes(String vpnName, String vpnRd) {
List<VpnInstanceOpDataEntry> vpnsToExportRoute = getVpnsExportingMyRoute(vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToExportRoute) {
- List<VrfEntry> vrfEntries = VpnUtil.getAllVrfEntries(dataBroker, vpn.getVrfId());
+ List<VrfEntry> vrfEntries = vpnUtil.getAllVrfEntries(vpn.getVrfId());
if (vrfEntries != null) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
for (VrfEntry vrfEntry : vrfEntries) {
LOG.info("handleVpnsExportingRoutes: Importing subnet route fib entry rd {} "
+ "prefix {} nexthop {} label {} to vpn {} vpnRd {}",
vpn.getVrfId(), prefix, nh, label, vpnName, vpnRd);
- SubnetRoute route = vrfEntry.getAugmentation(SubnetRoute.class);
+ SubnetRoute route = vrfEntry.augmentation(SubnetRoute.class);
importSubnetRouteForNewVpn(vpnRd, prefix, nh, label, route, vpn.getVrfId(),
confTx);
}
String gwMacAddress = null;
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
- final Optional<VpnInterfaceOpDataEntry> optVpnInterface =
- VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, interfaceId);
+ Optional<VpnInterfaceOpDataEntry> optVpnInterface = Optional.absent();
+ try {
+ optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, interfaceId);
+ } catch (ReadFailedException e) {
+ LOG.error("remove: Failed to read data store for interface {} vpn {}", interfaceName,
+ vpnName);
+ return;
+ }
if (interfaceState != null) {
try {
dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(
interfaceName, vpnName);
if (!isInterfaceStateDown) {
- final long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
- VpnUtil.scheduleVpnInterfaceForRemoval(dataBroker, interfaceName, dpId, vpnName, Boolean.TRUE,
- null);
- final boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
+ final long vpnId = vpnUtil.getVpnId(vpnName);
+ vpnUtil.scheduleVpnInterfaceForRemoval(interfaceName, dpId, vpnName, null);
+ final boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
removeAdjacenciesFromVpn(dpId, lportTag, interfaceName, vpnName,
vpnId, gwMac, writeConfigTxn, writeOperTxn, writeInvTxn);
if (interfaceManager.isExternalInterface(interfaceName)) {
- processExternalVpnInterface(interfaceName, vpnName, vpnId, dpId, lportTag, writeInvTxn,
- NwConstants.DEL_FLOW);
+ processExternalVpnInterface(interfaceName, vpnName, dpId, lportTag,
+ NwConstants.DEL_FLOW);
}
if (!isBgpVpnInternetVpn) {
- VpnUtil.unbindService(dataBroker, interfaceName, isInterfaceStateDown, jobCoordinator);
+ vpnUtil.unbindService(interfaceName, isInterfaceStateDown);
}
LOG.info("processVpnInterfaceDown: Unbound vpn service from interface {} on dpn {} for vpn {}"
+ " successful", interfaceName, dpId, vpnName);
WriteTransaction writeConfigTxn, final WriteTransaction writeOperTxn,
final WriteTransaction writeInvTxn) {
//Read NextHops
- InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil
- .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
- InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
- Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
-
- String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
- LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}",
- interfaceName, dpnId, vpnName, primaryRd);
- if (adjacencies.isPresent() && !adjacencies.get().getAdjacency().isEmpty()) {
- List<Adjacency> nextHops = adjacencies.get().getAdjacency();
- LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}",
- interfaceName, dpnId, vpnName, nextHops);
- for (Adjacency nextHop : nextHops) {
- if (nextHop.isPhysNetworkFunc()) {
- LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}",
- nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
- fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(),
- null/*writeCfgTxn*/);
- } else {
- String rd = nextHop.getVrfId();
- List<String> nhList;
- if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
- nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
+ try {
+ InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil
+ .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
+ InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
+ Optional<AdjacenciesOp> adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, path);
+ String primaryRd = vpnUtil.getVpnRd(vpnName);
+ LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}",
+ interfaceName, dpnId, vpnName, primaryRd);
+ if (adjacencies.isPresent() && !adjacencies.get().getAdjacency().isEmpty()) {
+ List<Adjacency> nextHops = adjacencies.get().getAdjacency();
+ LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}",
+ interfaceName, dpnId, vpnName, nextHops);
+ for (Adjacency nextHop : nextHops) {
+ if (nextHop.isPhysNetworkFunc()) {
+ LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}",
+ nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
+ fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(),
+ null/*writeCfgTxn*/);
} else {
- // This is a primary adjacency
- nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList()
- : Collections.emptyList();
- removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac,
- interfaceName, writeInvTxn);
- }
- if (!nhList.isEmpty()) {
- if (rd.equals(vpnName)) {
- //this is an internal vpn - the rd is assigned to the vpn instance name;
- //remove from FIB directly
- nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName,
- interfaceName, dpnId, writeConfigTxn));
+ String rd = nextHop.getVrfId();
+ List<String> nhList;
+ if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
+ nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
} else {
- removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd, interfaceName,
- writeConfigTxn);
+ // This is a primary adjacency
+ nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList()
+ : Collections.emptyList();
+ removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac,
+ interfaceName, writeInvTxn);
+ }
+ if (!nhList.isEmpty()) {
+ if (rd.equals(vpnName)) {
+ //this is an internal vpn - the rd is assigned to the vpn instance name;
+ //remove from FIB directly
+ nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName,
+ interfaceName, dpnId, writeConfigTxn));
+ } else {
+ removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd,
+ interfaceName, writeConfigTxn);
+ }
+ } else {
+ LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}"
+ + " interface {}", nextHop.getIpAddress(), rd,
+ nextHop.getAdjacencyType().toString(), interfaceName);
+ bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
+ fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), writeConfigTxn);
}
- } else {
- LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}"
- + " interface {}", nextHop.getIpAddress(), rd,
- nextHop.getAdjacencyType().toString(), interfaceName);
- bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
- fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), writeConfigTxn);
+ }
+ String ip = nextHop.getIpAddress().split("/")[0];
+ LearntVpnVipToPort vpnVipToPort = vpnUtil.getLearntVpnVipToPort(vpnName, ip);
+ if (vpnVipToPort != null) {
+ vpnUtil.removeLearntVpnVipToPort(vpnName, ip, null);
+ LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed LearntVpnVipToPort entry"
+ + " for Interface {} ip {} on dpn {} for vpn {}",
+ vpnVipToPort.getPortName(), ip, dpnId, vpnName);
+ }
+ VpnPortipToPort vpnPortipToPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnName, ip);
+ if (vpnPortipToPort != null) {
+ VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, ip, null);
+ LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed vpnPortipToPort entry for "
+ + "Interface {} ip {} on dpn {} for vpn {}",
+ vpnPortipToPort.getPortName(), ip, dpnId, vpnName);
}
}
- String ip = nextHop.getIpAddress().split("/")[0];
- LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, ip);
- if (vpnVipToPort != null) {
- VpnUtil.removeLearntVpnVipToPort(dataBroker, vpnName, ip, null);
- LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed adjacency for Interface {}"
- + " ip {} on dpn {} for vpn {} from VpnPortData Entry", vpnVipToPort.getPortName(),
- ip, dpnId, vpnName);
- }
+ } else {
+ // this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
+ LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies."
+ + " Removing it.", interfaceName, vpnName, dpnId);
+ writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, identifier);
}
- } else {
- // this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
- LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies."
- + " Removing it.", interfaceName, vpnName, dpnId);
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, identifier);
+ } catch (ReadFailedException e) {
+ LOG.error("removeAdjacenciesFromVpn: Failed to read data store for interface {} dpn {} vpn {}",
+ interfaceName, dpnId, vpnName);
}
}
BigInteger dpnId, String rd, String interfaceName,
WriteTransaction writeConfigTxn) {
List<VpnInstanceOpDataEntry> vpnsToImportRoute =
- VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
+ vpnUtil.getVpnsImportingMyRoute(vpnName);
nhList.forEach((nh) -> {
//IRT: remove routes from other vpns importing it
vpnManager.removePrefixFromBGP(primaryRd, rd, vpnName, nextHop.getIpAddress(),
// A valid mac-address was not available for this subnet-gateway-ip
// So a connected-mac-address was used for this subnet and we need
// to remove the flows for the same here from the L3_GW_MAC_TABLE.
- VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName,
- vpnId, writeInvTxn, NwConstants.DEL_FLOW, gwMac);
+ vpnUtil.setupGwMacIfExternalVpn(dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.DEL_FLOW, gwMac);
}
arpResponderHandler.removeArpResponderFlow(dpnId, lportTag, interfaceName, nextHop.getSubnetGatewayIp(),
subnetId);
}
private Optional<String> getMacAddressForSubnetIp(String vpnName, String ifName, String ipAddress) {
- VpnPortipToPort gwPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnName, ipAddress);
+ VpnPortipToPort gwPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnName, ipAddress);
//Check if a router gateway interface is available for the subnet gw is so then use Router interface
// else use connected interface
if (gwPort != null && gwPort.isSubnetIp()) {
update.getVpnInstanceNames());
final String vpnInterfaceName = update.getName();
final BigInteger dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
- final Adjacencies origAdjs = original.getAugmentation(Adjacencies.class);
+ final Adjacencies origAdjs = original.augmentation(Adjacencies.class);
final List<Adjacency> oldAdjs = origAdjs != null && origAdjs.getAdjacency()
!= null ? origAdjs.getAdjacency() : new ArrayList<>();
- final Adjacencies updateAdjs = update.getAugmentation(Adjacencies.class);
+ final Adjacencies updateAdjs = update.augmentation(Adjacencies.class);
final List<Adjacency> newAdjs = updateAdjs != null && updateAdjs.getAdjacency()
!= null ? updateAdjs.getAdjacency() : new ArrayList<>();
String newVpnName = vpnInterfaceVpnInstance.getVpnName();
List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
- String primaryRd = VpnUtil.getPrimaryRd(dataBroker, newVpnName);
- if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+ String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
+ if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterfaceName, () -> {
// TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> {
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(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(dataBroker, newVpnName);
+ boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(newVpnName);
if (!oldAdjs.equals(newAdjs)) {
for (Adjacency adj : copyNewAdjs) {
if (copyOldAdjs.contains(adj)) {
copyOldAdjs.remove(adj);
} else {
// add new adjacency - right now only extra route will hit this path
- if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker,
- adj)) {
+ if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj,
dpnId, operTx, confTx);
}
}
}
for (Adjacency adj : copyOldAdjs) {
- if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker,
- adj)) {
+ if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency
&& !adj.isPhysNetworkFunc()) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId,
operTx, confTx);
- Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, vpnInterfaceOpIdentifier);
- VpnInterfaceOpDataEntry vpnInterfaceOpDataEntry = optVpnInterface.get();
- long vpnId = VpnUtil.getVpnId(dataBroker, newVpnName);
- VpnUtil.removePrefixToInterfaceAdj(dataBroker, adj, vpnId,
- vpnInterfaceOpDataEntry, operTx);
+ Optional<VpnInterfaceOpDataEntry> optVpnInterface = operTx.read(
+ LogicalDatastoreType.OPERATIONAL, vpnInterfaceOpIdentifier).get();
+ if (optVpnInterface.isPresent()) {
+ VpnInterfaceOpDataEntry vpnInterfaceOpDataEntry = optVpnInterface.get();
+ long vpnId = vpnUtil.getVpnId(newVpnName);
+ vpnUtil.removePrefixToInterfaceAdj(adj, vpnId,
+ vpnInterfaceOpDataEntry, operTx);
+ } else {
+ LOG.info("update: Vpninterface {} not present in Operational",
+ vpnInterfaceName);
+ }
//remove FIB entry
- String vpnRd = VpnUtil.getVpnRd(dataBroker, newVpnName);
+ 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
}
}));
}));
+ for (ListenableFuture<Void> future : futures) {
+ ListenableFutures.addErrorLogging(future, LOG, "update: failed for interface {} on vpn {}",
+ update.getName(), update.getVpnInstanceNames());
+ }
return futures;
});
} else {
//Ignore
}
for (String newVpnName: newVpnList) {
- String primaryRd = VpnUtil.getPrimaryRd(dataBroker, newVpnName);
+ String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
isSwap = Boolean.TRUE;
- if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+ if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
LOG.info("handleVpnSwapForVpnInterface: VPN Interface update event - intfName {} onto vpnName {}"
+ "running config-driven swap addition", interfaceName, newVpnName);
- final Adjacencies origAdjs = original.getAugmentation(Adjacencies.class);
+ final Adjacencies origAdjs = original.augmentation(Adjacencies.class);
final List<Adjacency> oldAdjs = (origAdjs != null && origAdjs.getAdjacency() != null)
? origAdjs.getAdjacency() : new ArrayList<>();
- final Adjacencies updateAdjs = update.getAugmentation(Adjacencies.class);
+ final Adjacencies updateAdjs = update.augmentation(Adjacencies.class);
final List<Adjacency> newAdjs = (updateAdjs != null && updateAdjs.getAdjacency() != null)
? updateAdjs.getAdjacency() : new ArrayList<>();
}
private void updateLabelMapper(Long label, List<String> nextHopIpList) {
- Preconditions.checkNotNull(label, "updateLabelMapper: label cannot be null or empty!");
- synchronized (label.toString().intern()) {
- InstanceIdentifier<LabelRouteInfo> lriIid = InstanceIdentifier.builder(LabelRouteMap.class)
- .child(LabelRouteInfo.class, new LabelRouteInfoKey(label)).build();
- Optional<LabelRouteInfo> opResult = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, lriIid);
- if (opResult.isPresent()) {
- LabelRouteInfo labelRouteInfo =
- new LabelRouteInfoBuilder(opResult.get()).setNextHopIpList(nextHopIpList).build();
- MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriIid, labelRouteInfo);
+ try {
+ Preconditions.checkNotNull(label, "updateLabelMapper: label cannot be null or empty!");
+ synchronized (label.toString().intern()) {
+ InstanceIdentifier<LabelRouteInfo> lriIid = InstanceIdentifier.builder(LabelRouteMap.class)
+ .child(LabelRouteInfo.class, new LabelRouteInfoKey(label)).build();
+ Optional<LabelRouteInfo> opResult = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, lriIid);
+ if (opResult.isPresent()) {
+ LabelRouteInfo labelRouteInfo =
+ new LabelRouteInfoBuilder(opResult.get()).setNextHopIpList(nextHopIpList).build();
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriIid,
+ labelRouteInfo, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
+ }
}
+ LOG.info("updateLabelMapper: Updated label rotue info for label {} with nextHopList {}", label,
+ nextHopIpList);
+ } catch (ReadFailedException e) {
+ LOG.error("updateLabelMapper: Failed to read data store for label {} nexthopList {}", label,
+ nextHopIpList);
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("updateLabelMapper: Failed to commit to data store for label {} nexthopList {}", label,
+ nextHopIpList);
}
- LOG.info("updateLabelMapper: Updated label rotue info for label {} with nextHopList {}", label, nextHopIpList);
}
public synchronized void importSubnetRouteForNewVpn(String rd, String prefix, String nextHop, int label,
if (writeConfigTxn != null) {
writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew, true);
} else {
- VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
+ vpnUtil.syncUpdate(LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
}
LOG.info("SUBNETROUTE: importSubnetRouteForNewVpn: Created vrfEntry for rd {} prefix {} nexthop {} label {}"
+ " and elantag {}", rd, prefix, nextHop, label, route.getElantag());
protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd,
Adjacency adj, BigInteger dpnId, WriteTransaction writeOperTxn,
WriteTransaction writeConfigTxn) {
-
- Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(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(dataBroker, primaryRd);
- InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
- Optional<AdjacenciesOp> optAdjacencies = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, adjPath);
- boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
- VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
- long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
- VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
- List<Adjacency> adjacencies;
- if (optAdjacencies.isPresent()) {
- adjacencies = optAdjacencies.get().getAdjacency();
- } else {
- // This code will be hit in case of first PNF adjacency
- adjacencies = new ArrayList<>();
- }
- long vpnId = VpnUtil.getVpnId(dataBroker, 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, null, interfaceState);
+ 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);
+ long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
+ VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
+ List<Adjacency> adjacencies;
+ if (optAdjacencies.isPresent()) {
+ adjacencies = optAdjacencies.get().getAdjacency();
+ } else {
+ // This code will be hit in case of first PNF adjacency
+ adjacencies = new ArrayList<>();
}
- }
- if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty()
- && adj.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
- RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL
- : RouteOrigin.STATIC;
- String nh = adj.getNextHopIpList().get(0);
- String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
- synchronized (vpnPrefixKey.intern()) {
- java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(
- dataBroker, 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, 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;
- }
- // iRT/eRT use case Will be handled in a new patchset for L3VPN Over VxLAN.
- // Keeping the MPLS check for now.
- if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
- final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
- List<VpnInstanceOpDataEntry> vpnsToImportRoute =
- VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
- vpnsToImportRoute.forEach(vpn -> {
- if (vpn.getVrfId() != null) {
- VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(
- dataBroker, vpn.getVpnId(), vpnId, prefix,
- VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), nh, dpnId)
- .ifPresent(
- rds -> vpnManager.addExtraRoute(
- VpnUtil.getVpnName(dataBroker, vpn.getVpnId()),
- adj.getIpAddress(), nh, rds,
- currVpnIntf.getVpnInstanceName(),
- l3vni, RouteOrigin.SELF_IMPORTED,
- currVpnIntf.getName(), opAdjacency, encapType, writeConfigTxn));
- }
- });
+ long 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, null, interfaceState);
}
}
- } else if (adj.isPhysNetworkFunc()) { // PNF adjacency.
- LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix,
- currVpnIntf.getName(), vpnName);
+ if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty()
+ && adj.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
+ RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL
+ : RouteOrigin.STATIC;
+ String nh = adj.getNextHopIpList().get(0);
+ String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
+ synchronized (vpnPrefixKey.intern()) {
+ 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, 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;
+ }
+ // iRT/eRT use case Will be handled in a new patchset for L3VPN Over VxLAN.
+ // 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, writeConfigTxn));
+ }
+ });
+ }
+ }
+ } else if (adj.isPhysNetworkFunc()) { // PNF adjacency.
+ LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix,
+ currVpnIntf.getName(), vpnName);
- String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
+ String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
- writeOperTxn.merge(
- LogicalDatastoreType.OPERATIONAL,
- VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker,
- adj.getSubnetId().getValue()), prefix),
- VpnUtil.getPrefixToInterface(BigInteger.ZERO, currVpnIntf.getName(), prefix,
- adj.getSubnetId(), Prefixes.PrefixCue.PhysNetFunc), true);
+ writeOperTxn.merge(
+ LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(vpnUtil.getVpnId(adj.getSubnetId().getValue()),
+ prefix), VpnUtil.getPrefixToInterface(BigInteger.ZERO, currVpnIntf.getName(),
+ prefix, adj.getSubnetId(), Prefixes.PrefixCue.PhysNetFunc), true);
- fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(),
- adj.getIpAddress(), Collections.emptyList(), null /* EncapType */, 0 /* label */, 0 /*l3vni*/,
- null /* gw-mac */, parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
+ fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(),
+ adj.getIpAddress(), Collections.emptyList(), null /* EncapType */, 0 /* label */,
+ 0 /*l3vni*/, null /* gw-mac */, parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
- input.setRd(adj.getVrfId());
- }
- if (operationalAdjacency == null) {
- operationalAdjacency = populator.createOperationalAdjacency(input);
+ 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(),
+ currVpnIntf.getGatewayMacAddress());
+
+ writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
}
- adjacencies.add(operationalAdjacency);
- AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
- VpnInterfaceOpDataEntry newVpnIntf =
- VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(),
- aug, dpnId, currVpnIntf.isScheduledForRemove(), currVpnIntf.getLportTag(),
- currVpnIntf.getGatewayMacAddress());
-
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
+ } catch (ReadFailedException e) {
+ LOG.error("addNewAdjToVpnInterface: Failed to read data store for interface {} dpn {} vpn {} rd {} ip "
+ + "{}", interfaceName, dpnId, configVpnName, primaryRd, adj.getIpAddress());
}
}
private String getParentVpnRdForExternalSubnet(Adjacency adj) {
- Subnets subnets = VpnUtil.getExternalSubnet(dataBroker, adj.getSubnetId());
+ Subnets subnets = vpnUtil.getExternalSubnet(adj.getSubnetId());
return subnets != null ? subnets.getExternalNetworkId().getValue() : null;
}
protected void delAdjFromVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, Adjacency adj,
BigInteger dpnId, WriteTransaction writeOperTxn, WriteTransaction writeConfigTxn) {
- Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, identifier);
-
- if (optVpnInterface.isPresent()) {
- VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
-
- InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
- Optional<AdjacenciesOp> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
- if (optAdjacencies.isPresent()) {
- List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
-
- if (!adjacencies.isEmpty()) {
- LOG.trace("delAdjFromVpnInterface: Adjacencies are {}", adjacencies);
- Iterator<Adjacency> adjIt = adjacencies.iterator();
- while (adjIt.hasNext()) {
- Adjacency adjElem = adjIt.next();
- if (adjElem.getIpAddress().equals(adj.getIpAddress())) {
- String rd = adjElem.getVrfId();
- adjIt.remove();
-
- AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
- VpnInterfaceOpDataEntry newVpnIntf = VpnUtil
- .getVpnInterfaceOpDataEntry(currVpnIntf.getName(),
- currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.isScheduledForRemove(),
- currVpnIntf.getLportTag(), currVpnIntf.getGatewayMacAddress());
-
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
- if (adj.getNextHopIpList() != null) {
- for (String nh : adj.getNextHopIpList()) {
- deleteExtraRouteFromCurrentAndImportingVpns(
- currVpnIntf.getVpnInstanceName(), adj.getIpAddress(), nh, rd,
- currVpnIntf.getName(), writeConfigTxn);
+ String interfaceName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getName();
+ String vpnName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getVpnInstanceName();
+ try {
+ Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptional(
+ dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
+ if (optVpnInterface.isPresent()) {
+ VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
+ InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
+ Optional<AdjacenciesOp> optAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, path);
+ if (optAdjacencies.isPresent()) {
+ List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
+
+ if (!adjacencies.isEmpty()) {
+ LOG.trace("delAdjFromVpnInterface: Adjacencies are {}", adjacencies);
+ Iterator<Adjacency> adjIt = adjacencies.iterator();
+ while (adjIt.hasNext()) {
+ Adjacency adjElem = adjIt.next();
+ if (adjElem.getIpAddress().equals(adj.getIpAddress())) {
+ String rd = adjElem.getVrfId();
+ if (adj.getNextHopIpList() != null) {
+ for (String nh : adj.getNextHopIpList()) {
+ deleteExtraRouteFromCurrentAndImportingVpns(
+ currVpnIntf.getVpnInstanceName(), adj.getIpAddress(), nh, rd,
+ currVpnIntf.getName(), writeConfigTxn);
+ }
+ } else if (adj.isPhysNetworkFunc()) {
+ LOG.info("delAdjFromVpnInterface: deleting PNF adjacency prefix {} subnet {}",
+ adj.getIpAddress(), adj.getSubnetId());
+ fibManager.removeFibEntry(adj.getSubnetId().getValue(), adj.getIpAddress(),
+ writeConfigTxn);
}
- } else if (adj.isPhysNetworkFunc()) {
- LOG.info("delAdjFromVpnInterface: deleting PNF adjacency prefix {} subnet {}",
- adj.getIpAddress(), adj.getSubnetId());
- fibManager.removeFibEntry(adj.getSubnetId().getValue(), adj.getIpAddress(),
- writeConfigTxn);
+ break;
}
- break;
- }
+ }
}
+ LOG.info("delAdjFromVpnInterface: Removed adj {} on dpn {} rd {}", adj.getIpAddress(),
+ dpnId, adj.getVrfId());
+ } else {
+ LOG.error("delAdjFromVpnInterface: Cannnot DEL adjacency, since operational interface is "
+ + "unavailable dpnId {} adjIP {} rd {}", dpnId, adj.getIpAddress(), adj.getVrfId());
}
- LOG.info("delAdjFromVpnInterface: Removed adj {} on dpn {} rd {}", adj.getIpAddress(),
- dpnId, adj.getVrfId());
- } else {
- LOG.error("delAdjFromVpnInterface: Cannnot DEL adjacency, since operational interface is "
- + "unavailable dpnId {} adjIP {} rd {}", dpnId, adj.getIpAddress(), adj.getVrfId());
}
+ } catch (ReadFailedException e) {
+ LOG.error("delAdjFromVpnInterface: Failed to read data store for ip {} interface {} dpn {} vpn {}",
+ adj.getIpAddress(), interfaceName, dpnId, vpnName);
}
}
private void deleteExtraRouteFromCurrentAndImportingVpns(String vpnName, String destination, String nextHop,
String rd, String intfName, WriteTransaction writeConfigTxn) {
vpnManager.delExtraRoute(vpnName, destination, nextHop, rd, vpnName, intfName, writeConfigTxn);
- List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
+ List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
.child(RouterDpnList.class, new RouterDpnListKey(routerName)).build();
}
- protected void addToNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,
- WriteTransaction writeOperTxn) {
- BigInteger dpId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
- if (dpId.equals(BigInteger.ZERO)) {
- LOG.error("addToNeutronRouterDpnsMap: Could not retrieve dp id for interface {} to handle router {}"
- + " association model", vpnInterfaceName, routerName);
-
- return;
- }
- InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
-
- Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(dataBroker, LogicalDatastoreType
- .OPERATIONAL, routerDpnListIdentifier);
- RouterInterfaces routerInterface =
- new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(
- vpnInterfaceName).build();
- if (optionalRouterDpnList.isPresent()) {
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- RouterInterfaces.class, new RouterInterfacesKey(vpnInterfaceName)), routerInterface, true);
- } else {
- RouterDpnListBuilder builder = new RouterDpnListBuilder();
- builder.setRouterId(routerName);
- DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId);
- builder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
- getRouterId(routerName),
- builder.build(), true);
- }
- }
-
- protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,
- WriteTransaction writeOperTxn) {
- BigInteger dpId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
- if (dpId.equals(BigInteger.ZERO)) {
- LOG.error("removeFromNeutronRouterDpnsMap: Could not retrieve dp id for interface {} to handle router {}"
- + " dissociation model", vpnInterfaceName, routerName);
-
- return;
- }
- InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(dataBroker, LogicalDatastoreType
- .OPERATIONAL, routerDpnListIdentifier);
- if (optionalRouterDpnList.isPresent()) {
- List<RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
- RouterInterfaces routerInterface =
- new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(
- vpnInterfaceName).build();
-
- if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
- if (routerInterfaces.isEmpty()) {
- if (writeOperTxn != null) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- } else {
- MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- }
- } else {
- if (writeOperTxn != null) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- RouterInterfaces.class,
- new RouterInterfacesKey(vpnInterfaceName)));
- } else {
- MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL,
- routerDpnListIdentifier.child(
- RouterInterfaces.class,
- new RouterInterfacesKey(vpnInterfaceName)));
- }
- }
- }
- }
- }
-
- protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName, BigInteger dpId,
- WriteTransaction writeOperTxn) {
- if (dpId.equals(BigInteger.ZERO)) {
- LOG.error("removeFromNeutronRouterDpnsMap: Could not retrieve dp id for interface {} to handle router {}"
- + " dissociation model", vpnInterfaceName, routerName);
-
- return;
- }
- InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(dataBroker, LogicalDatastoreType
- .OPERATIONAL, routerDpnListIdentifier);
- if (optionalRouterDpnList.isPresent()) {
- List<RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
- RouterInterfaces routerInterface =
- new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(
- vpnInterfaceName).build();
- if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
- if (routerInterfaces.isEmpty()) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- } else {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- RouterInterfaces.class,
- new RouterInterfacesKey(vpnInterfaceName)));
- }
- }
- }
- }
-
protected void createFibEntryForRouterInterface(String primaryRd, VpnInterface vpnInterface, String interfaceName,
WriteTransaction writeConfigTxn, String vpnName) {
if (vpnInterface == null) {
return;
}
- List<Adjacency> adjs = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, interfaceName);
+ List<Adjacency> adjs = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(interfaceName);
if (adjs == null) {
LOG.error("createFibEntryForRouterInterface: VPN Interface {} of router addition failed as adjacencies for"
+ " this vpn interface could not be obtained. vpn {}", interfaceName, vpnName);
String macAddress = adj.getMacAddress();
String prefix = VpnUtil.getIpPrefix(primaryInterfaceIp);
- long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
- VpnUtil.getNextHopLabelKey(primaryRd, prefix));
+ long label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME,
+ VpnUtil.getNextHopLabelKey(primaryRd, prefix));
RouterInterface routerInt = new RouterInterfaceBuilder().setUuid(vpnName)
.setIpAddress(primaryInterfaceIp).setMacAddress(macAddress).build();
protected void deleteFibEntryForRouterInterface(VpnInterface vpnInterface,
WriteTransaction writeConfigTxn, String vpnName) {
- Adjacencies adjs = vpnInterface.getAugmentation(Adjacencies.class);
- String rd = VpnUtil.getVpnRd(dataBroker, vpnName);
+ Adjacencies adjs = vpnInterface.augmentation(Adjacencies.class);
+ String rd = vpnUtil.getVpnRd(vpnName);
if (adjs != null) {
List<Adjacency> adjsList = adjs.getAdjacency();
for (Adjacency adj : adjsList) {
}
public boolean isVpnInstanceReady(String vpnInstanceName) {
- String vpnRd = VpnUtil.getVpnRd(dataBroker, vpnInstanceName);
+ String vpnRd = vpnUtil.getVpnRd(vpnInstanceName);
if (vpnRd == null) {
return false;
}
- VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
+ VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnUtil.getVpnInstanceOpData(vpnRd);
return vpnInstanceOpDataEntry != null;
}
}
public void updateVpnInterfacesForUnProcessAdjancencies(String vpnName) {
- String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
- VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
+ String primaryRd = vpnUtil.getVpnRd(vpnName);
+ VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
if (vpnInstanceOpData == null) {
return;
}
return;
}
LOG.debug("Update the VpnInterfaces for Unprocessed Adjancencies for vpnName:{}", vpnName);
- vpnToDpnLists.forEach(vpnToDpnList -> vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
- InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId =
- VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
- Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
- if (!vpnInterfaceOptional.isPresent()) {
+ vpnToDpnLists.forEach(vpnToDpnList -> {
+ if (vpnToDpnList.getVpnInterfaces() == null) {
return;
}
- List<Adjacency> configVpnAdjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker,
- vpnInterface.getInterfaceName());
- if (configVpnAdjacencies == null) {
- LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
- return;
- }
- List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get()
- .getAugmentation(AdjacenciesOp.class).getAdjacency();
- // Due to insufficient rds, some of the extra route wont get processed when it is added.
- // The unprocessed adjacencies will be present in config vpn interface DS but will be missing
- // in operational DS. These unprocessed adjacencies will be handled below.
- // To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in operational
- // DS are retrieved which is used to call addNewAdjToVpnInterface method.
- configVpnAdjacencies.stream()
- .filter(adjacency -> operationVpnAdjacencies.stream()
- .noneMatch(operationalAdjacency ->
- operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress())))
- .forEach(adjacency -> {
- LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
- jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(),
- () -> {
- // TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
- if (VpnUtil.isAdjacencyEligibleToVpn(dataBroker, adjacency, vpnName)) {
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> futures.add(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- confTx -> addNewAdjToVpnInterface(existingVpnInterfaceId, primaryRd,
- adjacency, vpnInterfaceOptional.get().getDpnId(), confTx,
- operTx)))));
- return futures;
- } else {
- return Collections.emptyList();
- }
- });
- });
- }));
+ vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
+ try {
+ InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId =
+ VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
+ Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = SingleTransactionDataBroker
+ .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
+ if (!vpnInterfaceOptional.isPresent()) {
+ return;
+ }
+ List<Adjacency> configVpnAdjacencies = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(
+ vpnInterface.getInterfaceName());
+ if (configVpnAdjacencies == null) {
+ LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
+ return;
+ }
+ List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get()
+ .augmentation(AdjacenciesOp.class).getAdjacency();
+ // Due to insufficient rds, some of the extra route wont get processed when it is added.
+ // The unprocessed adjacencies will be present in config vpn interface DS but will be missing
+ // in operational DS. These unprocessed adjacencies will be handled below.
+ // To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in
+ // operational DS are retrieved which is used to call addNewAdjToVpnInterface method.
+ configVpnAdjacencies.stream()
+ .filter(adjacency -> operationVpnAdjacencies.stream()
+ .noneMatch(operationalAdjacency ->
+ operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress())))
+ .forEach(adjacency -> {
+ LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
+ jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(),
+ () -> {
+ // TODO Deal with sequencing — the config tx must only submitted
+ // if the oper tx goes in
+ if (vpnUtil.isAdjacencyEligibleToVpn(adjacency, vpnName)) {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx ->
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ confTx -> addNewAdjToVpnInterface(existingVpnInterfaceId,
+ primaryRd, adjacency, vpnInterfaceOptional.get()
+ .getDpnId(), confTx, operTx)))));
+ return futures;
+ } else {
+ return Collections.emptyList();
+ }
+ });
+ });
+ } catch (ReadFailedException e) {
+ LOG.error("updateVpnInterfacesForUnProcessAdjancencies: Failed to read data store for vpn {} rd {}",
+ vpnName, primaryRd);
+ }
+ });
+ });
}
private class PostVpnInterfaceWorker implements FutureCallback<Void> {
interfaceName, txnDestination, throwable);
} else {
LOG.error("VpnInterfaceManager: VrfEntries for {} removal failed", interfaceName, throwable);
- VpnUtil.unsetScheduledToRemoveForVpnInterface(txRunner, interfaceName);
+ vpnUtil.unsetScheduledToRemoveForVpnInterface(interfaceName);
}
}
}