Search in sources :

Example 51 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance 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 52 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class NeutronBgpvpnRouterAssociationChangeListener method remove.

@Override
public void remove(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
    LOG.trace("Removing Bgpvpn router association : key: {}, value={}", identifier, input);
    Uuid vpnId = input.getBgpvpnId();
    String vpnName = vpnId.getValue();
    Uuid routerId = input.getRouterId();
    NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
    try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
        if (!lock.wasAcquired()) {
            LOG.error("Remove router association: remove association failed for vpn : {} and routerId: {} due" + " to failure in acquiring lock", vpnName, routerId.getValue());
            return;
        }
        neutronBgpvpnUtils.removeUnProcessedRouter(vpnId, routerId);
        VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
        if (vpnInstance != null) {
            nvpnManager.dissociateRouterFromVpn(vpnId, routerId);
        }
    }
}
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) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 53 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class NeutronBgpvpnRouterAssociationChangeListener method add.

@Override
public void add(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
    LOG.trace("Adding Bgpvpn router association : key: {}, value={}", identifier, input);
    Uuid vpnId = input.getBgpvpnId();
    String vpnName = vpnId.getValue();
    Uuid routerId = input.getRouterId();
    NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
    try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
        if (!lock.wasAcquired()) {
            LOG.error("Add router association: add association failed for vpn : {} and routerId: {} due to " + "failure in acquiring lock", vpnName, routerId.getValue());
            return;
        }
        VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
        if (vpnInstance != null) {
            if (validateRouteInfo(routerId, vpnId)) {
                nvpnManager.associateRouterToVpn(vpnId, routerId);
            }
        } else {
            neutronBgpvpnUtils.addUnProcessedRouter(vpnId, routerId);
        }
    }
}
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) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 54 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance 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 55 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method checkAlarmExtraRoutes.

/**
 * This method setup or down an alarm about extra route fault.
 * When extra routes are configured, through a router, if the number of nexthops is greater than the number of
 * available RDs, then an alarm and an error is generated.<br>
 * <b>Be careful</b> the routeList could be changed.
 *
 * @param vpnId the vpnId of vpn to control.
 * @param routeList the list of router to check, it could be modified.
 */
private void checkAlarmExtraRoutes(Uuid vpnId, List<Routes> routeList) {
    if (!neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes is not enable for vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
    if (vpnInstance == null || routeList == null || routeList.isEmpty() || !neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes have args null as following : vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    String primaryRd = neutronvpnUtils.getVpnRd(vpnId.getValue());
    if (primaryRd == null || primaryRd.equals(vpnId.getValue())) {
        LOG.debug("checkAlarmExtraRoutes. vpn {} is not a BGPVPN. cancel checkExtraRoute", vpnId);
        return;
    }
    for (Routes route : routeList) {
        // count  the number of nexthops for each same route.getDestingation().getValue()
        String destination = route.getDestination().stringValue();
        String nextHop = route.getNexthop().stringValue();
        List<String> nextHopList = new ArrayList<>();
        nextHopList.add(nextHop);
        int nbNextHops = 1;
        for (Routes routeTmp : routeList) {
            String routeDest = routeTmp.getDestination().stringValue();
            if (!destination.equals(routeDest)) {
                continue;
            }
            String routeNextH = routeTmp.getNexthop().stringValue();
            if (nextHop.equals(routeNextH)) {
                continue;
            }
            nbNextHops++;
            nextHopList.add(routeTmp.getNexthop().stringValue());
        }
        final List<String> rdList = new ArrayList<>();
        if (vpnInstance != null && vpnInstance.getRouteDistinguisher() != null) {
            vpnInstance.getRouteDistinguisher().forEach(rd -> {
                if (rd != null) {
                    rdList.add(rd);
                }
            });
        }
        // 1. VPN Instance Name
        String typeAlarm = "for vpnId: " + vpnId + " have exceeded next hops for prefixe";
        // 2. Router ID
        List<Uuid> routerUuidList = neutronvpnUtils.getRouterIdListforVpn(vpnId);
        Uuid routerUuid = routerUuidList.get(0);
        StringBuilder detailsAlarm = new StringBuilder("routerUuid: ");
        detailsAlarm.append(routerUuid == null ? vpnId.toString() : routerUuid.getValue());
        // 3. List of RDs associated with the VPN
        detailsAlarm.append(" List of RDs associated with the VPN: ");
        for (String s : rdList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        // 4. Prefix in question
        detailsAlarm.append(" for prefix: ");
        detailsAlarm.append(route.getDestination().stringValue());
        // 5. List of NHs for the prefix
        detailsAlarm.append(" for nextHops: ");
        for (String s : nextHopList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        if (rdList.size() < nbNextHops) {
            neutronvpnAlarm.raiseNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
        } else {
            neutronvpnAlarm.clearNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
        }
    }
}
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) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)

Aggregations

ArrayList (java.util.ArrayList)62 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)40 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)37 ExecutionException (java.util.concurrent.ExecutionException)36 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)31 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)26 List (java.util.List)24 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)23 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)22 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)22 Logger (org.slf4j.Logger)22 LoggerFactory (org.slf4j.LoggerFactory)22 Inject (javax.inject.Inject)21 Singleton (javax.inject.Singleton)21 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)21 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)20 FutureCallback (com.google.common.util.concurrent.FutureCallback)19 Futures (com.google.common.util.concurrent.Futures)19 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)19 Collections (java.util.Collections)19