Search in sources :

Example 1 with VpnTarget

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

the class CoeUtils method createVpnInstance.

public static void createVpnInstance(String vpnName, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion, ReadWriteTransaction tx) throws ReadFailedException {
    List<VpnTarget> vpnTargetList = new ArrayList<>();
    LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
    VpnInstanceBuilder builder = new VpnInstanceBuilder().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setType(type).setL3vni(l3vni);
    if (irt != null && !irt.isEmpty()) {
        if (ert != null && !ert.isEmpty()) {
            List<String> commonRT = new ArrayList<>(irt);
            commonRT.retainAll(ert);
            for (String common : commonRT) {
                irt.remove(common);
                ert.remove(common);
                VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
                vpnTargetList.add(vpnTarget);
            }
        }
        for (String importRT : irt) {
            VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(importRT)).setVrfRTValue(importRT).setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
            vpnTargetList.add(vpnTarget);
        }
    }
    if (ert != null && !ert.isEmpty()) {
        for (String exportRT : ert) {
            VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
            vpnTargetList.add(vpnTarget);
        }
    }
    VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
    Ipv4FamilyBuilder ipv4vpnBuilder = new Ipv4FamilyBuilder().setVpnTargets(vpnTargets);
    Ipv6FamilyBuilder ipv6vpnBuilder = new Ipv6FamilyBuilder().setVpnTargets(vpnTargets);
    if (rd != null && !rd.isEmpty()) {
        ipv4vpnBuilder.setRouteDistinguisher(rd);
        ipv6vpnBuilder.setRouteDistinguisher(rd);
    }
    if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
        builder.setIpv4Family(ipv4vpnBuilder.build());
    }
    if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
        builder.setIpv6Family(ipv6vpnBuilder.build());
    }
    if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.UNDEFINED)) {
        builder.setIpv4Family(ipv4vpnBuilder.build());
    }
    VpnInstance newVpn = builder.build();
    LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
    InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
    tx.put(LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
}
Also used : VpnTargetKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTargetKey) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) VpnTargets(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets) Ipv6FamilyBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv6FamilyBuilder) VpnInstanceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceBuilder) Ipv4FamilyBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv4FamilyBuilder) VpnTarget(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget) VpnTargetBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTargetBuilder) VpnTargetsBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargetsBuilder) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)

Example 2 with VpnTarget

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

the class SubnetmapChangeListener method add.

@Override
public void add(InstanceIdentifier<Subnetmap> identifier, Subnetmap subnetmap) {
    LOG.debug("add: subnetmap method - key: {}, value: {}", identifier, subnetmap);
    Uuid subnetId = subnetmap.getId();
    Network network = vpnUtil.getNeutronNetwork(subnetmap.getNetworkId());
    if (network == null) {
        LOG.error("add: network was not found for subnetId {}", subnetId.getValue());
        return;
    }
    if (subnetmap.getVpnId() != null) {
        if (NetworkType.VLAN.equals(subnetmap.getNetworkType())) {
            vpnUtil.addRouterPortToElanDpnListForVlaninAllDpn(subnetmap.getVpnId().getValue());
        }
    }
    if (VpnUtil.getIsExternal(network)) {
        LOG.debug("SubnetmapListener:add: provider subnetwork {} is handling in " + "ExternalSubnetVpnInstanceListener", subnetId.getValue());
        return;
    }
    jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
        String elanInstanceName = subnetmap.getNetworkId().getValue();
        long elanTag = getElanTag(elanInstanceName);
        if (elanTag == 0L) {
            LOG.error("add: unable to fetch elantag from ElanInstance {} for subnet {}", elanInstanceName, subnetId.getValue());
            return Collections.emptyList();
        }
        Uuid vpnId = subnetmap.getVpnId();
        if (vpnId != null) {
            boolean isBgpVpn = !vpnId.equals(subnetmap.getRouterId());
            LOG.info("add: subnetmap {} with elanTag {} to VPN {}", subnetmap, elanTag, vpnId);
            vpnSubnetRouteHandler.onSubnetAddedToVpn(subnetmap, isBgpVpn, elanTag);
            if (isBgpVpn && subnetmap.getRouterId() == null) {
                Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
                if (!routeTargets.isEmpty()) {
                    // FIXME: separate this out somehow?
                    final ReentrantLock lock = JvmGlobalLocks.getLockForString(subnetmap.getSubnetIp());
                    lock.lock();
                    try {
                        vpnManager.updateRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
                    } finally {
                        lock.unlock();
                    }
                }
            }
        }
        return Collections.emptyList();
    });
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) 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)

Example 3 with VpnTarget

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

the class NeutronEvpnManager method getEVPN.

public ListenableFuture<RpcResult<GetEVPNOutput>> getEVPN(GetEVPNInput input) {
    GetEVPNOutputBuilder opBuilder = new GetEVPNOutputBuilder();
    SettableFuture<RpcResult<GetEVPNOutput>> result = SettableFuture.create();
    Uuid inputVpnId = input.getId();
    List<VpnInstance> vpns = new ArrayList<>();
    if (inputVpnId == null) {
        vpns = VpnHelper.getAllVpnInstances(dataBroker);
        if (!vpns.isEmpty()) {
            for (VpnInstance vpn : vpns) {
                if (vpn.getRouteDistinguisher() != null && vpn.isL2vpn()) {
                    vpns.add(vpn);
                }
            }
        } else {
            // No VPN present
            result.set(RpcResultBuilder.success(opBuilder.build()).build());
            return result;
        }
    } else {
        String name = inputVpnId.getValue();
        VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, name);
        if (vpnInstance != null && vpnInstance.getRouteDistinguisher() != null && vpnInstance.isL2vpn()) {
            vpns.add(vpnInstance);
        } else {
            result.set(RpcResultBuilder.<GetEVPNOutput>failed().withWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetEVPN failed because VPN {} is not present", name)).build());
        }
    }
    List<EvpnInstances> evpnList = new ArrayList<>();
    for (VpnInstance vpnInstance : vpns) {
        Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
        InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
        EvpnInstancesBuilder evpn = new EvpnInstancesBuilder();
        List<String> rd = vpnInstance.getRouteDistinguisher();
        List<String> ertList = new ArrayList<>();
        List<String> irtList = new ArrayList<>();
        for (VpnTarget vpnTarget : vpnInstance.getVpnTargets().nonnullVpnTarget().values()) {
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
                ertList.add(vpnTarget.getVrfRTValue());
            }
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
                irtList.add(vpnTarget.getVrfRTValue());
            }
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
                ertList.add(vpnTarget.getVrfRTValue());
                irtList.add(vpnTarget.getVrfRTValue());
            }
        }
        evpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
        try {
            Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
            if (optionalVpnMap.isPresent()) {
                VpnMap vpnMap = optionalVpnMap.get();
                evpn.setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
            }
        } catch (ExecutionException | InterruptedException e) {
            LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
            result.set(RpcResultBuilder.<GetEVPNOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Error reading the VPN map for " + vpnMapIdentifier, e).build());
            return result;
        }
        evpnList.add(evpn.build());
    }
    opBuilder.setEvpnInstances(evpnList);
    result.set(RpcResultBuilder.success(opBuilder.build()).build());
    return result;
}
Also used : GetEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutputBuilder) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) EvpnInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstances) 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) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) GetEVPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutput) EvpnInstancesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstancesBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with VpnTarget

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

the class VpnUtil method getRts.

static List<String> getRts(VpnInstanceOpDataEntry vpnInstance, VpnTarget.VrfRTType rtType) {
    String name = vpnInstance.getVpnInstanceName();
    List<String> rts = new ArrayList<>();
    VpnTargets targets = vpnInstance.getVpnTargets();
    if (targets == null) {
        LOG.debug("getRts: vpn targets not available for {}", name);
        return rts;
    }
    Map<VpnTargetKey, VpnTarget> keyVpnTargetMap = targets.getVpnTarget();
    if (keyVpnTargetMap == null) {
        LOG.debug("getRts: vpnTarget values not available for {}", name);
        return rts;
    }
    for (VpnTarget target : keyVpnTargetMap.values()) {
        // TODO: Check for RT type is Both
        if (target.getVrfRTType().equals(rtType) || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both)) {
            String rtValue = target.getVrfRTValue();
            rts.add(rtValue);
        }
    }
    return rts;
}
Also used : VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget) VpnTargetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTargetKey) ArrayList(java.util.ArrayList) VpnTargets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnTargets)

Example 5 with VpnTarget

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

the class InterVpnLinkLocator method getRts.

private List<String> getRts(VpnInstanceOpDataEntry vpnInstance, VpnTarget.VrfRTType rtType) {
    String name = vpnInstance.getVpnInstanceName();
    VpnTargets targets = vpnInstance.getVpnTargets();
    if (targets == null) {
        LOG.trace("vpn targets not available for {}", name);
        return new ArrayList<>();
    }
    Map<VpnTargetKey, VpnTarget> vpnTargets = targets.nonnullVpnTarget();
    if (vpnTargets == null) {
        LOG.trace("vpnTarget values not available for {}", name);
        return new ArrayList<>();
    }
    return vpnTargets.values().stream().filter(target -> Objects.equals(target.getVrfRTType(), rtType) || Objects.equals(target.getVrfRTType(), VpnTarget.VrfRTType.Both)).map(VpnTarget::getVrfRTValue).collect(Collectors.toList());
}
Also used : VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget) VpnTargetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTargetKey) VpnTargets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnTargets) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)14 VpnTarget (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget)10 ExecutionException (java.util.concurrent.ExecutionException)8 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)6 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 VpnTargetKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTargetKey)5 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 VpnTargets (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets)3 VpnTarget (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget)3 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey)3 VpnTargets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.VpnTargets)3 VpnTargetKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey)3 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)3 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Collections (java.util.Collections)2