Search in sources :

Example 31 with Networks

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);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 32 with Networks

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);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with Networks

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);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 34 with Networks

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);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with Networks

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;
}
Also used : VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworkProviderExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)43 ExecutionException (java.util.concurrent.ExecutionException)19 ArrayList (java.util.ArrayList)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)14 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)13 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)13 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)13 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)11 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)9 BigInteger (java.math.BigInteger)6 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks)6 NetworksKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey)6 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)5 HashSet (java.util.HashSet)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 AcquireResult (org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)4 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)4 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)4 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)4 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)4