Search in sources :

Example 6 with Bgpvpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateNetworksFromVpn.

/**
 * Parses and disassociates networks list from given VPN.
 *
 * @param vpnId Uuid of given VPN.
 * @param networkList List list of network Ids (Uuid), which will be disassociated.
 * @return list of formatted strings with detailed error messages.
 */
@NonNull
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<>();
    IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
    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()));
        return failedNwList;
    }
    for (Uuid nw : networkList) {
        List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
        if (networkSubnets == null) {
            passedNwList.add(nw);
            continue;
        }
        Network network = neutronvpnUtils.getNeutronNetwork(nw);
        if (network == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not found in ConfigDS", nw.getValue()));
            continue;
        }
        Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
        if (networkVpnId == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} is not associated to any VPN", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not associated to any VPN", nw.getValue()));
            continue;
        }
        if (!vpnId.equals(networkVpnId)) {
            LOG.error("dissociateNetworksFromVpn: Network {} is associated to another VPN {} instead of given {}", nw.getValue(), networkVpnId.getValue(), vpnId.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as it is associated to another " + "vpn %s instead of given %s", nw.getValue(), networkVpnId.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);
            // Handle external-Nw to BGPVPN Disassociation and still ext-router is being set with external-Nw
            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("dissociateNetworksFromVpn: External network {} is still 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;
                    }
                }
            }
        }
        for (Uuid subnet : networkSubnets) {
            Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
            if (subnetmap == null) {
                failedNwList.add(String.format("subnetmap %s not found for network %s", subnet.getValue(), nw.getValue()));
                LOG.error("dissociateNetworksFromVpn: Subnetmap for subnet {} not found when " + "dissociating network {} from VPN {}", subnet.getValue(), nw.getValue(), vpnId.getValue());
                continue;
            }
            IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
            if (!ipVersion.isIpVersionChosen(ipVers)) {
                ipVersion = ipVersion.addVersion(ipVers);
            }
            if (!NeutronvpnUtils.getIsExternal(network)) {
                LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
                removeSubnetFromVpn(vpnId, subnetmap, null);
                Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
                vpnManager.removeRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
                passedNwList.add(nw);
            }
        }
        if (ipVersion != IpVersionChoice.UNDEFINED) {
            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());
    return failedNwList;
}
Also used : ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) 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) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 7 with Bgpvpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortCreated.

private void handleNeutronPortCreated(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final String networkId = port.getNetworkId().getValue();
    final Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
    if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
        return;
    }
    if (!NeutronUtils.isPortVnicTypeNormal(port) && (!isPortTypeSwitchdev(port) || !isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT))) {
        for (FixedIps ip : keyFixedIpsMap.values()) {
            nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
        }
        LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "OF Port interfaces are not created", portName);
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        // add direct port to subnetMaps config DS
        // TODO: for direct port as well, operations should be carried out per subnet based on port IP
        ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
            LOG.info("Of-port-interface creation for port {}", portName);
            // Create of-port interface for this neutron port
            String portInterfaceName = createOfPortInterface(port, tx);
            LOG.debug("Creating ELAN Interface for port {}", portName);
            createElanInterface(port, portInterfaceName, tx);
            Set<Uuid> vpnIdList = new HashSet<>();
            Set<Uuid> routerIds = new HashSet<>();
            for (FixedIps ip : keyFixedIpsMap.values()) {
                Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
                if (subnetMap != null && subnetMap.getInternetVpnId() != null) {
                    if (!vpnIdList.contains(subnetMap.getInternetVpnId())) {
                        vpnIdList.add(subnetMap.getInternetVpnId());
                    }
                }
                if (subnetMap != null && subnetMap.getVpnId() != null) {
                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
                    Uuid vpnId = subnetMap.getVpnId();
                    if (vpnId != null) {
                        vpnIdList.add(vpnId);
                    }
                }
                if (subnetMap != null && subnetMap.getRouterId() != null) {
                    routerIds.add(subnetMap.getRouterId());
                }
            }
            if (!vpnIdList.isEmpty()) {
                // create new vpn-interface for neutron port
                LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName, networkId);
                nvpnManager.createVpnInterface(vpnIdList, port, tx);
                for (Uuid routerId : routerIds) {
                    nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue());
                }
            }
        });
        LoggingFutures.addErrorLogging(future, LOG, "handleNeutronPortCreated: Failed for port {} with networkId {}", portName, networkId);
        return Collections.singletonList(future);
    });
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Example 8 with Bgpvpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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 9 with Bgpvpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn in project netvirt by opendaylight.

the class NeutronBgpvpnChangeListener method remove.

@Override
public void remove(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn input) {
    LOG.trace("Removing Bgpvpn : key: {}, value={}", identifier, input);
    Uuid vpnId = input.getUuid();
    String vpnName = vpnId.getValue();
    if (!isBgpvpnTypeL3(input.getType())) {
        LOG.warn("BGPVPN type for VPN {} is not L3", vpnName);
        return;
    }
    NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
    try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
        if (!lock.wasAcquired()) {
            LOG.error("Remove BGPVPN: remove bgpvpn failed for vpn : {} due to failure in acquiring lock", vpnName);
            return;
        }
        neutronBgpvpnUtils.getUnProcessedRoutersMap().remove(input.getUuid());
        neutronBgpvpnUtils.getUnProcessedNetworksMap().remove(input.getUuid());
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("Failed to handle BGPVPN Remove for VPN {} as that VPN is not configured" + " yet as a VPN Instance", vpnName);
            return;
        }
        nvpnManager.removeVpn(input.getUuid());
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 10 with Bgpvpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)18 ArrayList (java.util.ArrayList)12 AcquireResult (org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)7 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 HashSet (java.util.HashSet)5 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)5 List (java.util.List)4 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)4 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)4 ExecutionException (java.util.concurrent.ExecutionException)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Collections.emptyList (java.util.Collections.emptyList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PreDestroy (javax.annotation.PreDestroy)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Executors (org.opendaylight.infrautils.utils.concurrent.Executors)2 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)2