import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.utils.JvmGlobalLocks;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
import org.opendaylight.infrautils.utils.concurrent.NamedLocks;
import org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
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.vpn.instance.op.data.VpnInstanceOpDataEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry.BgpvpnType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks;
LOG.debug("updating existing vpninstance node");
} else {
builder = new VpnInstanceBuilder().withKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName)
- .setL2vpn(isL2Vpn).setL3vni(l3vni);
+ .setL2vpn(isL2Vpn).setL3vni(l3vni).setBgpvpnType(VpnInstance.BgpvpnType.InternalVPN);
}
if (irt != null && !irt.isEmpty()) {
if (ert != null && !ert.isEmpty()) {
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
if (rd != null && !rd.isEmpty()) {
- builder.setRouteDistinguisher(rd).setVpnTargets(vpnTargets);
+ builder.setRouteDistinguisher(rd).setVpnTargets(vpnTargets).setBgpvpnType(VpnInstance.BgpvpnType.BGPVPN);
}
builder.setIpAddressFamilyConfigured(VpnInstance.IpAddressFamilyConfigured.forValue(ipVersion.choice));
}
if (router != null) {
RouterIds vpnRouterId = new RouterIdsBuilder().setRouterId(router).build();
- List<RouterIds> rtrIds = builder.getRouterIds().values() != null
+ List<RouterIds> rtrIds = builder.getRouterIds() != null
? new ArrayList<>(builder.getRouterIds().values()) : null;
if (rtrIds == null) {
rtrIds = Collections.singletonList(vpnRouterId);
}
}
}
- return new AdjacenciesBuilder().setAdjacency(adjList).build();
+ return new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(adjList)).build();
+ }
+
+ private Map<AdjacencyKey, Adjacency> getAdjacencyMap(List<Adjacency> adjList) {
+ //convert to set to remove duplicates.
+ Set<Adjacency> adjset = adjList.stream().collect(Collectors.toSet());
+ Map<AdjacencyKey, Adjacency> adjacencyMap = new HashMap<>();
+ for (Adjacency adj : adjset) {
+ adjacencyMap.put(new AdjacencyKey(adj.getIpAddress()), adj);
+ }
+ return adjacencyMap;
}
protected void createVpnInterface(Collection<Uuid> vpnIds, Port port,
}
}
}
- Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(updatedAdjsList).build();
+ Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(updatedAdjsList)).build();
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, wrtConfigTxn);
}
protected void deleteVpnInterface(String infName, @Nullable String vpnId,
@Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(
+ LoggingFutures.addErrorLogging(
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> deleteVpnInterface(infName, vpnId, tx)),
LOG, "Error deleting VPN interface {} {}", infName, vpnId);
}
}
});
- ListenableFutures.addErrorLogging(future, LOG,
+ LoggingFutures.addErrorLogging(future, LOG,
"addSubnetToVpn: Failed while creating VPN interface for vpnId {}, portId {}"
+ "{}, subnetId {}", vpnId.getValue(), portId, subnet.getValue());
return Collections.singletonList(future);
subnetId.getValue());
}
});
- ListenableFutures.addErrorLogging(future, LOG,
+ LoggingFutures.addErrorLogging(future, LOG,
"removeSubnetFromVpn: Exception while processing deletion of VPN interfaces for port {}"
+ " belonging to subnet {} and vpnId {}",
portId.getValue(), subnetId.getValue(), vpnId.getValue());
.setVpnInstanceName(vpnName.getValue())
.build();
- ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(
+ LoggingFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(
vpnRpcService.removeStaticRoute(rpcInput)), LOG, "Remove VPN routes");
} else {
// Any other case is a fault.
.setNextHopIpList(nextHopList)
.withKey(new AdjacencyKey(destination))
.build();
+ List<Adjacency> newAdjList = Collections.singletonList(newAdj);
Adjacencies erAdjs =
- new AdjacenciesBuilder().setAdjacency(Collections.singletonList(newAdj)).build();
+ new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(newAdjList)).build();
VpnInterface vpnIf = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(infName))
.addAugmentation(Adjacencies.class, erAdjs).build();
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
}
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
- LOG.debug("associateRouterToVpn: Updating vpnInstanceOpDataEntrywith ip address family {} for VPN {} ",
+ LOG.debug("associateRouterToVpn: Updating vpnInstance ip address family {} for VPN {} ",
ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
}
updateVpnForSubnet(vpnId, routerId, sn.getId(), false);
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
- LOG.debug("dissociateRouterFromVpn; Updating vpnInstanceOpDataEntry with ip address family {} for VPN {} ",
+ LOG.debug("dissociateRouterFromVpn; Updating vpnInstance with ip address family {} for VPN {} ",
ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion,
false);
protected List<String> associateNetworksToVpn(@NonNull Uuid vpnId, @NonNull List<Uuid> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
+ ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
boolean isExternalNetwork = false;
if (networkList.isEmpty()) {
LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
return failedNwList;
}
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
+ boolean isIpFamilyUpdated = false;
for (Uuid nw : networkList) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
+ "another VPN %s", nw.getValue(), networkVpnId.getValue()));
continue;
}
- if (NeutronvpnUtils.getIsExternal(network) && !associateExtNetworkToVpn(vpnId, network)) {
- LOG.error("associateNetworksToVpn: Failed to associate Provider Network {} with VPN {}",
- nw.getValue(), vpnId.getValue());
- failedNwList.add(String.format("Failed to associate Provider Network %s with VPN %s",
- nw.getValue(), vpnId.getValue()));
- continue;
+ /* Handle association of external network(s) to Internet BGP-VPN use case outside of the
+ * networkList iteration
+ */
+ if (neutronvpnUtils.getIsExternal(network)) {
+ extNwMap.put(nw, network);
}
if (NeutronvpnUtils.getIsExternal(network)) {
isExternalNetwork = true;
ipVersion = ipVersion.addVersion(ipVers);
}
}
- if (ipVersion != IpVersionChoice.UNDEFINED) {
- LOG.debug("associateNetworksToVpn: Updating vpnInstanceOpDataEntry with ip address family {}"
+ //Update vpnInstance for IP address family
+ if (ipVersion != IpVersionChoice.UNDEFINED && !isIpFamilyUpdated) {
+ LOG.debug("associateNetworksToVpn: Updating vpnInstance with ip address family {}"
+ " for VPN {} ", ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ isIpFamilyUpdated = true;
}
for (Subnetmap subnetmap : subnetmapList) {
Uuid subnetId = subnetmap.getId();
}
}
passedNwList.add(nw);
+ //Handle association of external network(s) to Internet BGP-VPN Instance use case
+ if (!extNwMap.isEmpty() || extNwMap != null) {
+ for (Network extNw : extNwMap.values()) {
+ if (!associateExtNetworkToVpn(vpnId, extNw, vpnInstance.getBgpvpnType())) {
+ LOG.error("associateNetworksToVpn: Failed to associate Provider External Network {} with "
+ + "VPN {}", extNw, vpnId.getValue());
+ failedNwList.add(String.format("Failed to associate Provider External Network %s with "
+ + "VPN %s", extNw, vpnId.getValue()));
+ continue;
+ }
+ }
+ }
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("associateNetworksToVpn: Failed to associate VPN {} with networks {}: ", vpnId.getValue(),
return failedNwList;
}
- private boolean associateExtNetworkToVpn(@NonNull Uuid vpnId, @NonNull Network extNet) {
+ private boolean associateExtNetworkToVpn(@NonNull Uuid vpnId, @NonNull Network extNet,
+ VpnInstance.BgpvpnType bgpVpnType) {
if (!addExternalNetworkToVpn(extNet, vpnId)) {
return false;
}
- VpnInstanceOpDataEntry vpnOpDataEntry = neutronvpnUtils.getVpnInstanceOpDataEntryFromVpnId(vpnId.getValue());
- if (vpnOpDataEntry == null) {
- LOG.error("associateExtNetworkToVpn: can not find VpnOpDataEntry for VPN {}", vpnId.getValue());
- return false;
- }
- if (!vpnOpDataEntry.getBgpvpnType().equals(BgpvpnType.BGPVPNInternet)) {
- LOG.info("associateExtNetworkToVpn: set type {} for VPN {}", BgpvpnType.BGPVPNInternet, vpnId.getValue());
- neutronvpnUtils.updateVpnInstanceOpWithType(BgpvpnType.BGPVPNInternet, vpnId);
+ if (!bgpVpnType.equals(VpnInstance.BgpvpnType.InternetBGPVPN)) {
+ LOG.info("associateExtNetworkToVpn: External network {} is associated to VPN {}."
+ + "Hence set vpnInstance type to {} from {} ", extNet.key().getUuid().getValue(),
+ vpnId.getValue(), VpnInstance.BgpvpnType.InternetBGPVPN.getName(),
+ VpnInstance.BgpvpnType.BGPVPN.getName());
+ neutronvpnUtils.updateVpnInstanceWithBgpVpnType(VpnInstance.BgpvpnType.InternetBGPVPN, vpnId);
}
//Update VpnMap with ext-nw is needed first before processing V6 internet default fallback flows
List<Uuid> extNwList = Collections.singletonList(extNet.key().getUuid());
protected List<String> dissociateNetworksFromVpn(@NonNull Uuid vpnId, @NonNull List<Uuid> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
+ ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
if (networkList.isEmpty()) {
LOG.error("dissociateNetworksFromVpn: Failed as networks list is empty");
failedNwList.add(String.format("Failed to disassociate networks from VPN %s as networks list is empty",
vpnId.getValue()));
continue;
}
- if (NeutronvpnUtils.getIsExternal(network)) {
- if (disassociateExtNetworkFromVpn(vpnId, network)) {
- passedNwList.add(nw);
- } else {
- LOG.error("dissociateNetworksFromVpn: Failed to withdraw Provider Network {} from VPN {}",
- nw.getValue(), vpnId.getValue());
- failedNwList.add(String.format("Failed to withdraw Provider Network %s from VPN %s", nw.getValue(),
- vpnId.getValue()));
- continue;
- }
+ /* Handle disassociation of external network(s) from Internet BGP-VPN use case outside of the
+ * networkList iteration
+ */
+ if (neutronvpnUtils.getIsExternal(network)) {
+ extNwMap.put(nw, network);
}
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid subnet : networkSubnets) {
}
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
- LOG.debug("dissociateNetworksFromVpn: Updating vpnInstanceOpDataEntryupdate with ip address family {}"
+ LOG.debug("dissociateNetworksFromVpn: Updating vpnInstance with ip address family {}"
+ " for VPN {}", ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}
+ //Handle disassociation of external network(s) from Internet BGP-VPN Instance use case
+ if (!extNwMap.isEmpty() || extNwMap != null) {
+ for (Network extNw : extNwMap.values()) {
+ if (disassociateExtNetworkFromVpn(vpnId, extNw)) {
+ passedNwList.add(extNw.getUuid());
+ } else {
+ LOG.error("dissociateNetworksFromVpn: Failed to withdraw External Provider Network {} from VPN {}",
+ extNw, vpnId.getValue());
+ failedNwList.add(String.format("Failed to withdraw External Provider Network %s from VPN %s",
+ extNw, vpnId.getValue()));
+ continue;
+ }
+ }
+ }
clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully",
passedNwList, vpnId.getValue());
}
}
}
- //Set VPN Type is BGPVPNExternal from BGPVPNInternet
- LOG.info("disassociateExtNetworkFromVpn: set type {} for VPN {}",
- VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId.getValue());
- neutronvpnUtils.updateVpnInstanceOpWithType(VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId);
+ ///Set VPN Type is BGPVPN from InternetBGPVPN
+ LOG.info("disassociateExtNetworkFromVpn: Set BGP-VPN type with {} for VPN {} and update IPv6 address family. "
+ + "Since external network is disassociated from VPN {}",
+ VpnInstance.BgpvpnType.BGPVPN, extNet, vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithBgpVpnType(VpnInstance.BgpvpnType.BGPVPN, vpnId);
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet, vpnId)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
Uuid vpnId = input.getVpnId();
Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter
.input.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
- .associaterouter.input.RouterIds> keyRouterIdsMap = input.getRouterIds();
+ .associaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "associateRouter: RouterIds list is empty!");
Preconditions.checkNotNull(vpnId, "associateRouter; VpnId not found!");
Preconditions.checkNotNull(vpnId, "associateRouter; RouterIds not found!");
Uuid vpnId = input.getVpnId();
Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input
.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
- .dissociaterouter.input.RouterIds> keyRouterIdsMap = input.getRouterIds();
+ .dissociaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
String routerIdsString = "";
Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "dissociateRouter: RouterIds list is empty!");
Preconditions.checkNotNull(vpnId, "dissociateRouter: vpnId not found!");
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
createExternalVpnInterface(extNetId, elanInterface, tx);
}
LOG.error("No external ports attached for external network {}", extNetId.getValue());
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils
.buildVpnInterfaceIdentifier(elanInterface);
return;
}
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, networkUuid, isRouterInterface, tx)), LOG,
"Error writing VPN interface");
return;
}
if (wrtConfigTxn == null) {
LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;