Search in sources :

Example 66 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 clearFromVpnMaps.

private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
    Optional<VpnMap> optionalVpnMap;
    try {
        optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
        return;
    }
    if (optionalVpnMap.isPresent()) {
        VpnMap vpnMap = optionalVpnMap.get();
        VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
        List<RouterIds> rtrIds = new ArrayList<>(vpnMap.nonnullRouterIds().values());
        if (rtrIds == null) {
            rtrIds = new ArrayList<>();
        }
        if (routerId != null) {
            if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
                rtrIds.add(new RouterIdsBuilder().setRouterId(routerId).build());
                vpnMapBuilder.setRouterIds(rtrIds);
                try (AcquireResult lock = tryVpnLock(vpnId)) {
                    if (!lock.wasAcquired()) {
                        // FIXME: why do we even bother with locking if we do not honor it?!
                        logTryLockFailure(vpnId);
                    }
                    LOG.debug("removing vpnMaps node: {} ", vpnId);
                    try {
                        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
                    } catch (TransactionCommitFailedException e) {
                        LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
                    }
                }
                return;
            } else if (vpnMap.getNetworkIds() == null && !routerId.equals(vpnMap.getVpnId())) {
                rtrIds.remove(new RouterIdsBuilder().setRouterId(routerId).build());
                vpnMapBuilder.setRouterIds(rtrIds);
                LOG.debug("Removing routerId {} in vpnMaps for the vpn {}", routerId, vpnId.getValue());
            }
        }
        if (networkIds != null) {
            List<Uuid> vpnNw = vpnMap.getNetworkIds() != null ? new ArrayList<>(vpnMap.getNetworkIds()) : new ArrayList<>();
            vpnNw.removeAll(networkIds);
            if (vpnNw.isEmpty()) {
                LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
                vpnMapBuilder.setNetworkIds(null);
            } else {
                vpnMapBuilder.setNetworkIds(vpnNw);
            }
        }
        try (AcquireResult lock = tryVpnLock(vpnId)) {
            if (!lock.wasAcquired()) {
                // FIXME: why do we even bother with locking if we do not honor it?!
                logTryLockFailure(vpnId);
            }
            LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
            try {
                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
            } catch (TransactionCommitFailedException e) {
                LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
            }
        }
    } else {
        LOG.error("VPN : {} not found", vpnId.getValue());
    }
    LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
Also used : ArrayList(java.util.ArrayList) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapBuilder) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 67 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 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)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