use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronBgpvpnChangeListener method update.
@Override
public void update(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn original, Bgpvpn update) {
LOG.trace("Update Bgpvpn : key: {}, value={}", identifier, update);
if (Objects.equals(original, update)) {
return;
}
String vpnName = update.getUuid().getValue();
if (!isBgpvpnTypeL3(update.getType())) {
LOG.warn("BGPVPN type for VPN {} is not L3", vpnName);
return;
}
boolean rdIrtErtStringsValid = true;
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getRouteDistinguishers().stream().anyMatch(rdStr -> rdStr.contains(" ")));
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getImportTargets().stream().anyMatch(irtStr -> irtStr.contains(" ")));
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getExportTargets().stream().anyMatch(ertStr -> ertStr.contains(" ")));
if (!rdIrtErtStringsValid) {
LOG.error("Error encountered for BGPVPN {} with RD {} as RD/iRT/eRT contains whitespace characters", vpnName, update.getRouteDistinguishers());
return;
}
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Update VPN: update failed for vpn : {} due to failure in acquiring lock", vpnName);
return;
}
handleVpnInstanceUpdate(original.getUuid().getValue(), original.getRouteDistinguishers(), update.getRouteDistinguishers());
// TODO: Currently handling routers and networks for backward compatibility. Below logic needs to be
// removed once updated to latest BGPVPN API's.
Uuid vpnId = update.getUuid();
List<Uuid> oldNetworks = new ArrayList<>(original.getNetworks());
List<Uuid> newNetworks = new ArrayList<>(update.getNetworks());
handleNetworksUpdate(vpnId, oldNetworks, newNetworks);
List<Uuid> oldRouters = original.getRouters();
List<Uuid> newRouters = update.getRouters();
handleRoutersUpdate(vpnId, oldRouters, newRouters);
} catch (UnsupportedOperationException e) {
LOG.error("Error while processing Update Bgpvpn.", e);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronBgpvpnChangeListener method handleNetworksUpdate.
/**
* Handle networks update.
*
* @deprecated Retaining method for backward compatibility. Below method needs to be removed once
* updated to latest BGPVPN API's.
*
* @param vpnId the vpn id
* @param oldNetworks the old networks
* @param newNetworks the new networks
*/
@Deprecated
private void handleNetworksUpdate(Uuid vpnId, List<Uuid> oldNetworks, List<Uuid> newNetworks) {
if (newNetworks != null && !newNetworks.isEmpty()) {
if (oldNetworks != null && !oldNetworks.isEmpty()) {
if (oldNetworks != newNetworks) {
Iterator<Uuid> iter = newNetworks.iterator();
while (iter.hasNext()) {
Uuid net = iter.next();
if (oldNetworks.contains(net)) {
oldNetworks.remove(net);
iter.remove();
}
}
// clear removed networks
if (!oldNetworks.isEmpty()) {
LOG.trace("Removing old networks {} ", oldNetworks);
List<String> errorMessages = nvpnManager.dissociateNetworksFromVpn(vpnId, oldNetworks);
if (!errorMessages.isEmpty()) {
LOG.error("handleNetworksUpdate: dissociate old Networks not part of bgpvpn update," + " from vpn {} failed due to {}", vpnId.getValue(), errorMessages);
}
}
// add new (Delta) Networks
if (!newNetworks.isEmpty()) {
LOG.trace("Adding delta New networks {} ", newNetworks);
List<String> errorMessages = nvpnManager.associateNetworksToVpn(vpnId, newNetworks);
if (!errorMessages.isEmpty()) {
LOG.error("handleNetworksUpdate: associate new Networks not part of original bgpvpn," + " to vpn {} failed due to {}", vpnId.getValue(), errorMessages);
}
}
}
} else {
// add new Networks
LOG.trace("Adding New networks {} ", newNetworks);
List<String> errorMessages = nvpnManager.associateNetworksToVpn(vpnId, newNetworks);
if (!errorMessages.isEmpty()) {
LOG.error("handleNetworksUpdate: associate new Networks to vpn {} failed due to {}", vpnId.getValue(), errorMessages);
}
}
} else if (oldNetworks != null && !oldNetworks.isEmpty()) {
LOG.trace("Removing old networks {} ", oldNetworks);
List<String> errorMessages = nvpnManager.dissociateNetworksFromVpn(vpnId, oldNetworks);
if (!errorMessages.isEmpty()) {
LOG.error("handleNetworksUpdate: dissociate old Networks from vpn {} failed due to {}", vpnId.getValue(), errorMessages);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronBgpvpnNetworkAssociationChangeListener method add.
@Override
public void add(InstanceIdentifier<BgpvpnNetworkAssociation> identifier, BgpvpnNetworkAssociation input) {
LOG.trace("Adding Bgpvpn network association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid networkId = input.getNetworkId();
List<Uuid> networks = new ArrayList<>();
networks.add(networkId);
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Add network association: add association failed for vpn : {} and networkId: {} due to " + "failure in acquiring lock", vpnName, networkId.getValue());
return;
}
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
List<String> errorMessages = nvpnManager.associateNetworksToVpn(vpnId, networks);
if (!errorMessages.isEmpty()) {
LOG.error("BgpvpnNetworkAssociation add: associate network id {} to vpn {} failed due to {}", networkId.getValue(), vpnId.getValue(), errorMessages);
}
} else {
neutronBgpvpnUtils.addUnProcessedNetwork(vpnId, networkId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnNatManager method removeExternalNetwork.
public void removeExternalNetwork(Network net) {
Uuid extNetId = net.getUuid();
// Create and add Networks object for this External Network to the ExternalNetworks list
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
try {
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
LOG.trace("Removing Networks node {}", extNetId.getValue());
if (!optionalNets.isPresent()) {
LOG.error("External Network {} not available in the datastore", extNetId.getValue());
return;
}
// Delete Networks object from the ExternalNetworks list
LOG.trace("Deleting External Network {}", extNetId.getValue());
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
LOG.trace("Deleted External Network {} successfully from CONFIG Datastore", extNetId.getValue());
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
LOG.error("Deletion of External Network {} failed", extNetId.getValue(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method associateNetworksToVpn.
/**
* Parses and associates networks list with given VPN.
*
* @param vpnId Uuid of given VPN.
* @param networkList List list of network Ids (Uuid), which will be associated.
* @return list of formatted strings with detailed error messages.
*/
@NonNull
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());
failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty", vpnId.getValue()));
return failedNwList;
}
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
if (vpnInstance == null) {
LOG.error("associateNetworksToVpn: Can not find vpnInstance for VPN {} in ConfigDS", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: can not found vpnInstance for VPN %s " + "in ConfigDS", vpnId.getValue()));
return failedNwList;
}
try {
if (isVpnOfTypeL2(vpnInstance) && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
LOG.error("associateNetworksToVpn: EVPN {} supports only one network to be associated with", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: EVPN %s supports only one network to be " + "associated with", vpnId.getValue()));
return failedNwList;
}
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
boolean isIpFamilyUpdated = false;
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid nw : networkList) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("associateNetworksToVpn: Network {} not found in ConfigDS", nw.getValue());
failedNwList.add(String.format("Failed to associate network: network %s not found in ConfigDS", nw.getValue()));
continue;
}
NetworkProviderExtension providerExtension = network.augmentation(NetworkProviderExtension.class);
if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
LOG.error("associateNetworksToVpn: MultiSegmented network {} not supported in BGPVPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate multisegmented network %s with BGPVPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (networkVpnId != null) {
LOG.error("associateNetworksToVpn: Network {} already associated with another VPN {}", nw.getValue(), networkVpnId.getValue());
failedNwList.add(String.format("Failed to associate network %s as it is already associated to " + "another VPN %s", nw.getValue(), networkVpnId.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);
isExternalNetwork = true;
// Check whether router-gw is set with external network before external network to BGPVPN association
List<Uuid> routerList = neutronvpnUtils.getRouterIdsForExtNetwork(nw);
if (!routerList.isEmpty()) {
for (Uuid routerId : routerList) {
// If v6 subnet was already added to router means it requires IPv6 AddrFamily in VpnInstance
if (neutronvpnUtils.isV6SubnetPartOfRouter(routerId)) {
ipVersion = ipVersion.addVersion(IpVersionChoice.IPV6);
LOG.debug("associateNetworksToVpn: External network {} is already associated with " + "router(router-gw) {} and V6 subnet is part of that router. Hence Set IPv6 " + "address family type in Internet VPN Instance {}", network, routerId, vpnId);
break;
}
}
}
}
List<Subnetmap> subnetmapList = neutronvpnUtils.getSubnetmapListFromNetworkId(nw);
if (subnetmapList == null || subnetmapList.isEmpty()) {
passedNwList.add(nw);
continue;
}
if (vpnManager.checkForOverlappingSubnets(nw, subnetmapList, vpnId, routeTargets, failedNwList)) {
continue;
}
for (Subnetmap subnetmap : subnetmapList) {
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
if (!ipVersion.isIpVersionChosen(ipVers)) {
ipVersion = ipVersion.addVersion(ipVers);
}
}
// 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();
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnetId);
if (subnetVpnId != null) {
LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {}" + " as it is already associated", subnetId.getValue(), subnetVpnId.getValue());
failedNwList.add(String.format("Failed to associate subnet %s with VPN %s" + " as it is already associated", subnetId.getValue(), vpnId.getValue()));
continue;
}
if (!NeutronvpnUtils.getIsExternal(network)) {
LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnetId.getValue(), vpnId.getValue());
addSubnetToVpn(vpnId, subnetId, null);
vpnManager.updateRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
passedNwList.add(nw);
}
}
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(), networkList, e);
failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(), networkList, e));
}
// VpnMap update for ext-nw is already done in associateExtNetworkToVpn() method.
if (!isExternalNetwork) {
updateVpnMaps(vpnId, null, null, null, new ArrayList<>(passedNwList));
}
LOG.info("Network(s) {} associated to L3VPN {} successfully", passedNwList, vpnId.getValue());
return failedNwList;
}
Aggregations