Search in sources :

Example 21 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 handleRoutersUpdate.

/**
 * Handle routers 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 oldRouters the old routers
 * @param newRouters the new routers
 */
@Deprecated
private void handleRoutersUpdate(Uuid vpnId, List<Uuid> oldRouters, List<Uuid> newRouters) {
    // TODO: check router ports ethertype to follow this restriction
    if (oldRouters != null && !oldRouters.isEmpty()) {
        // remove to oldRouters the newRouters if existing
        List<Uuid> oldRoutersCopy = new ArrayList<>();
        oldRoutersCopy.addAll(oldRouters);
        if (newRouters != null) {
            newRouters.forEach(r -> oldRoutersCopy.remove(r));
        }
        /* dissociate old router */
        oldRoutersCopy.forEach(r -> {
            nvpnManager.dissociateRouterFromVpn(vpnId, r);
        });
    }
    if (newRouters != null && !newRouters.isEmpty()) {
        if (newRouters.size() > NeutronConstants.MAX_ROUTERS_PER_BGPVPN) {
            LOG.debug("In handleRoutersUpdate: maximum allowed number of associated routers is 2. VPN: {} " + "is already associated with router: {} and with router: {}", vpnId, newRouters.get(0).getValue(), newRouters.get(1).getValue());
            return;
        } else {
            for (Uuid routerId : newRouters) {
                if (oldRouters != null && oldRouters.contains(routerId)) {
                    continue;
                }
                /* If the first time BGP-VPN is getting associated with router, then no need
                       to validate if the router is already been associated with any other BGP-VPN.
                       This will avoid unnecessary MD-SAL data store read operations in VPN-MAPS.
                     */
                if (oldRouters == null || oldRouters.isEmpty()) {
                    nvpnManager.associateRouterToVpn(vpnId, routerId);
                } else if (validateRouteInfo(routerId)) {
                    nvpnManager.associateRouterToVpn(vpnId, routerId);
                }
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList)

Example 22 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 add.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn input) {
    LOG.trace("Adding Bgpvpn : key: {}, value={}", identifier, input);
    String vpnName = input.getUuid().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("Add BGPVPN: add bgpvpn failed for vpn : {} due to failure in acquiring lock", vpnName);
            return;
        }
        // handle route-target(s)
        List<String> inputRouteList = input.getRouteTargets();
        List<String> inputImportRouteList = input.getImportTargets();
        List<String> inputExportRouteList = input.getExportTargets();
        Set<String> inputImportRouteSet = new HashSet<>();
        Set<String> inputExportRouteSet = new HashSet<>();
        if (inputRouteList != null && !inputRouteList.isEmpty()) {
            inputImportRouteSet.addAll(inputRouteList);
            inputExportRouteSet.addAll(inputRouteList);
        }
        if (inputImportRouteList != null && !inputImportRouteList.isEmpty()) {
            inputImportRouteSet.addAll(inputImportRouteList);
        }
        if (inputExportRouteList != null && !inputExportRouteList.isEmpty()) {
            inputExportRouteSet.addAll(inputExportRouteList);
        }
        List<String> importRouteTargets = new ArrayList<>(inputImportRouteSet);
        List<String> exportRouteTargets = new ArrayList<>(inputExportRouteSet);
        boolean rdIrtErtStringsValid;
        List<String> rdList = input.getRouteDistinguishers();
        if (rdList != null && !rdList.isEmpty()) {
            // get the primary RD for vpn instance, if exist
            rdIrtErtStringsValid = !(input.getRouteDistinguishers().stream().anyMatch(rdStr -> rdStr.contains(" ")));
            rdIrtErtStringsValid = rdIrtErtStringsValid && !(importRouteTargets.stream().anyMatch(irtStr -> irtStr.contains(" ")));
            rdIrtErtStringsValid = rdIrtErtStringsValid && !(exportRouteTargets.stream().anyMatch(ertStr -> ertStr.contains(" ")));
            if (!rdIrtErtStringsValid) {
                LOG.error("Error encountered for BGPVPN {} with RD {} as RD/iRT/eRT contains whitespace " + "characters", vpnName, input.getRouteDistinguishers());
                return;
            }
            String primaryRd = neutronvpnUtils.getVpnRd(vpnName);
            if (primaryRd == null) {
                primaryRd = rdList.get(0);
            }
            String[] rdParams = primaryRd.split(":");
            if (rdParams[0].trim().equals(adminRDValue)) {
                LOG.error("AS specific part of RD should not be same as that defined by DC Admin. Error " + "encountered for BGPVPN {} with RD {}", vpnName, primaryRd);
                return;
            }
            String vpnWithSameRd = neutronvpnUtils.getVpnForRD(primaryRd);
            if (vpnWithSameRd != null) {
                LOG.error("Creation of L3VPN failed for VPN {} as another VPN {} with the same RD {} " + "is already configured", vpnName, vpnWithSameRd, primaryRd);
                return;
            }
            String existingOperationalVpn = neutronvpnUtils.getExistingOperationalVpn(primaryRd);
            if (existingOperationalVpn != null) {
                LOG.error("checkVpnCreation: Creation of L3VPN failed for VPN {} as another VPN {} with the " + "same RD {} is still available.", vpnName, existingOperationalVpn, primaryRd);
                return;
            }
            List<Uuid> unpRtrs = neutronBgpvpnUtils.getUnprocessedRoutersForBgpvpn(input.getUuid());
            List<Uuid> unpNets = neutronBgpvpnUtils.getUnprocessedNetworksForBgpvpn(input.getUuid());
            // TODO: Currently handling routers and networks for backward compatibility. Below logic needs to be
            // removed once updated to latest BGPVPN API's.
            List<Uuid> inputRouters = input.getRouters();
            if (inputRouters != null && !inputRouters.isEmpty()) {
                if (unpRtrs != null) {
                    unpRtrs.addAll(inputRouters);
                } else {
                    unpRtrs = new ArrayList<>(inputRouters);
                }
            }
            if (unpRtrs != null && unpRtrs.size() > NeutronConstants.MAX_ROUTERS_PER_BGPVPN) {
                LOG.error("Creation of BGPVPN for rd {} failed: maximum allowed number of associated " + "routers is {}.", rdList, NeutronConstants.MAX_ROUTERS_PER_BGPVPN);
                return;
            }
            List<Uuid> inputNetworks = input.getNetworks();
            if (inputNetworks != null && !inputNetworks.isEmpty()) {
                if (unpNets != null) {
                    unpNets.addAll(inputNetworks);
                } else {
                    unpNets = new ArrayList<>(inputNetworks);
                }
            }
            try {
                nvpnManager.createVpn(input.getUuid(), input.getName(), input.getTenantId(), rdList, importRouteTargets, exportRouteTargets, unpRtrs, unpNets, false, /* isL2Vpn */
                0);
                neutronBgpvpnUtils.getUnProcessedRoutersMap().remove(input.getUuid());
                neutronBgpvpnUtils.getUnProcessedNetworksMap().remove(input.getUuid());
            } catch (Exception e) {
                LOG.error("Creation of BGPVPN {} failed with error ", vpnName, e);
            }
        } else {
            LOG.error("add: RD is absent for BGPVPN {}", vpnName);
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) NeutronConstants(org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants) BgpvpnTypeL3(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeL3) Bgpvpns(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.Bgpvpns) BgpvpnTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeBase) Bgpvpn(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) Set(java.util.Set) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NamedLocks(org.opendaylight.infrautils.utils.concurrent.NamedLocks) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) FrameworkUtil(org.osgi.framework.FrameworkUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ArrayList(java.util.ArrayList) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) HashSet(java.util.HashSet)

Example 23 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 handleNeutronPortDeleted.

private void handleNeutronPortDeleted(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
    if (!NeutronUtils.isPortVnicTypeNormal(port) && !isPortTypeSwitchdev(port)) {
        for (FixedIps ip : keyFixedIpsMap.values()) {
            // remove direct port from subnetMaps config DS
            // TODO: for direct port as well, operations should be carried out per subnet based on port IP
            nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
        }
        LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "Skipping OF Port interfaces removal", portName);
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
            Uuid vpnId = null;
            Set<Uuid> routerIds = new HashSet<>();
            Uuid internetVpnId = null;
            for (FixedIps ip : keyFixedIpsMap.values()) {
                Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
                if (subnetMap == null) {
                    continue;
                }
                if (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
                    vpnId = subnetMap.getVpnId();
                }
                if (subnetMap.getRouterId() != null) {
                    routerIds.add(subnetMap.getRouterId());
                }
                internetVpnId = subnetMap.getInternetVpnId();
                if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(port.getDeviceOwner()) || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(port.getDeviceOwner())) {
                    String ipAddress = ip.getIpAddress().stringValue();
                    if (vpnId != null) {
                        neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipAddress, confTx);
                    }
                    if (internetVpnId != null) {
                        neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(), ipAddress, confTx);
                    }
                }
            }
            if (vpnId != null || internetVpnId != null) {
                // remove vpn-interface for this neutron port
                LOG.debug("removing VPN Interface for port {}", portName);
                if (!routerIds.isEmpty()) {
                    for (Uuid routerId : routerIds) {
                        nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
                    }
                }
                nvpnManager.deleteVpnInterface(portName, null, /* vpn-id */
                confTx);
            }
            // Remove of-port interface for this neutron port
            // ELAN interface is also implicitly deleted as part of this operation
            LOG.debug("Of-port-interface removal for port {}", portName);
            deleteOfPortInterface(port, confTx);
            // dissociate fixedIP from floatingIP if associated
            nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
        });
        LoggingFutures.addErrorLogging(future, LOG, "handleNeutronPortDeleted: Failed to update interface {} with networkId", portName, port.getNetworkId().getValue());
        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 24 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 NeutronBgpvpnNetworkAssociationChangeListener method remove.

@Override
public void remove(InstanceIdentifier<BgpvpnNetworkAssociation> identifier, BgpvpnNetworkAssociation input) {
    LOG.trace("Removing 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("Remove network association: remove association failed for vpn : {} and networkId: {} due " + "to failure in acquiring lock", vpnName, networkId.getValue());
            return;
        }
        neutronBgpvpnUtils.removeUnProcessedNetwork(vpnId, networkId);
        VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
        if (vpnInstance != null) {
            List<String> errorMessages = nvpnManager.dissociateNetworksFromVpn(vpnId, networks);
            if (!errorMessages.isEmpty()) {
                LOG.error("BgpvpnNetworkAssociation remove: dissociate network id {} to vpn {} failed due to {}", networkId.getValue(), vpnName, errorMessages);
            }
        }
    }
}
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 25 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 disassociateExtNetworkFromVpn.

private boolean disassociateExtNetworkFromVpn(@NonNull Uuid vpnId, @NonNull Network extNet) {
    if (!removeExternalNetworkFromVpn(extNet)) {
        return false;
    }
    // check, if there is another Provider Networks associated with given VPN
    List<Uuid> vpnNets = getNetworksForVpn(vpnId);
    if (vpnNets != null) {
        // Remove currently disassociated network from the list
        vpnNets.remove(extNet.getUuid());
        for (Uuid netId : vpnNets) {
            if (NeutronvpnUtils.getIsExternal(getNeutronNetwork(netId))) {
                LOG.error("dissociateExtNetworkFromVpn: Internet VPN {} is still associated with Provider Network " + "{}", vpnId.getValue(), netId.getValue());
                return true;
            }
        }
    }
    // /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);
        if (sm == null) {
            LOG.error("disassociateExtNetworkFromVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
            continue;
        }
        IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
        if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
            continue;
        }
        if (ipVers.isIpVersionChosen(IpVersionChoice.IPV6)) {
            updateVpnInternetForSubnet(sm, vpnId, false);
        }
        if (!ipVersion.isIpVersionChosen(ipVers)) {
            ipVersion = ipVersion.addVersion(ipVers);
        }
    }
    if (ipVersion != IpVersionChoice.UNDEFINED) {
        neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, false);
        LOG.info("disassociateExtNetworkFromVpn: withdraw IPv6 Internet default route from VPN {}", vpnId.getValue());
        neutronvpnUtils.updateVpnInstanceWithFallback(/*routerId*/
        null, vpnId, false);
    }
    return true;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

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