Search in sources :

Example 46 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 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 47 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 NeutronRouterChangeListener method remove.

@Override
public void remove(InstanceIdentifier<Router> identifier, Router input) {
    LOG.trace("Removing router : key: {}, value={}", identifier, input);
    Uuid routerId = input.getUuid();
    /*External Router and networks is handled before deleting the internal VPN, as there is dependency
        on vpn operational data to release Lport tag in case of L3VPN over VxLAN*/
    if (input.getExternalGatewayInfo() != null) {
        Uuid extNetId = input.getExternalGatewayInfo().getExternalNetworkId();
        List<ExternalFixedIps> externalFixedIps = new ArrayList<ExternalFixedIps>(input.getExternalGatewayInfo().nonnullExternalFixedIps().values());
        jobCoordinator.enqueueJob(input.getUuid().toString(), () -> {
            nvpnNatManager.removeExternalNetworkFromRouter(extNetId, input, externalFixedIps);
            return Collections.emptyList();
        });
    }
    // NOTE: Pass an empty routerSubnetIds list, as router interfaces
    // will be removed from VPN by invocations from NeutronPortChangeListener
    List<Uuid> routerSubnetIds = new ArrayList<>();
    nvpnManager.handleNeutronRouterDeleted(routerId, routerSubnetIds);
    neutronvpnUtils.removeFromRouterCache(input);
    nvpnNatManager.removeNeutronRouterDpns(input);
}
Also used : ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList)

Example 48 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 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 49 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 VxlanGreConntrackBasedSnatService method addSnatAllSwitch.

@Override
public boolean addSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 primarySwitchId) {
    ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(confTx, routers.getNetworkId());
    LOG.debug("VxlanGreConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
    if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
        LOG.debug("handleSnatAllSwitch : Skip FLAT/VLAN provider networks.");
        return true;
    }
    return super.addSnatAllSwitch(confTx, routers, primarySwitchId);
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 50 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 VxlanGreConntrackBasedSnatService method addCentralizedRouter.

public boolean addCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 primarySwitchId, Uint64 dpnId) {
    ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
    LOG.debug("VxlanGreConntrackBasedSnatService: handleCentralizedRouter ProviderTypes {}", extNwProviderType);
    if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
        LOG.debug("handleCentralizedRouter : Skip FLAT/VLAN provider networks.");
        return true;
    }
    return super.addCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

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