Search in sources :

Example 6 with VpnInstances

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

the class NeutronvpnUtils method getExistingRDs.

public List<String> getExistingRDs() {
    List<String> existingRDs = new ArrayList<>();
    InstanceIdentifier<VpnInstances> path = InstanceIdentifier.builder(VpnInstances.class).build();
    Optional<VpnInstances> vpnInstancesOptional = read(LogicalDatastoreType.CONFIGURATION, path);
    if (vpnInstancesOptional.isPresent() && vpnInstancesOptional.get().getVpnInstance() != null) {
        for (VpnInstance vpnInstance : vpnInstancesOptional.get().getVpnInstance().values()) {
            List<String> rds = vpnInstance.getRouteDistinguisher();
            if (rds != null) {
                existingRDs.addAll(rds);
            }
        }
    }
    return existingRDs;
}
Also used : VpnInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList)

Example 7 with VpnInstances

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

the class NeutronvpnManager method getL3VPN.

/**
 * It handles the invocations to the neutronvpn:getL3VPN RPC method.
 */
@Override
public ListenableFuture<RpcResult<GetL3VPNOutput>> getL3VPN(GetL3VPNInput input) {
    GetL3VPNOutputBuilder opBuilder = new GetL3VPNOutputBuilder();
    SettableFuture<RpcResult<GetL3VPNOutput>> result = SettableFuture.create();
    Uuid inputVpnId = input.getId();
    List<VpnInstance> vpns = new ArrayList<>();
    List<L3vpnInstances> l3vpnList = new ArrayList<>();
    try {
        if (inputVpnId == null) {
            // get all vpns
            InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
            Optional<VpnInstances> optionalVpns = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
            if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
                for (VpnInstance vpn : optionalVpns.get().nonnullVpnInstance().values()) {
                    // from getL3VPN output
                    if (vpn.getRouteDistinguisher() != null) {
                        vpns.add(vpn);
                    }
                }
            } else {
                // No VPN present
                opBuilder.setL3vpnInstances(l3vpnList);
                result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
                return result;
            }
        } else {
            String name = inputVpnId.getValue();
            InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(name)).build();
            // read VpnInstance Info
            Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
            // getL3VPN output
            if (optionalVpn.isPresent() && optionalVpn.get().getRouteDistinguisher() != null) {
                vpns.add(optionalVpn.get());
            } else {
                result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetL3VPN failed because VPN {} is not present", name)).build());
            }
        }
        for (VpnInstance vpnInstance : vpns) {
            Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
            // create VpnMaps id
            L3vpnInstancesBuilder l3vpn = new L3vpnInstancesBuilder();
            List<String> rd = Collections.emptyList();
            if (vpnInstance.getRouteDistinguisher() != null) {
                rd = vpnInstance.getRouteDistinguisher();
            }
            List<String> ertList = new ArrayList<>();
            List<String> irtList = new ArrayList<>();
            if (vpnInstance.getVpnTargets() != null) {
                Map<VpnTargetKey, VpnTarget> keyVpnTargetMap = Collections.emptyMap();
                if (!vpnInstance.getVpnTargets().getVpnTarget().isEmpty()) {
                    keyVpnTargetMap = vpnInstance.getVpnTargets().getVpnTarget();
                }
                if (!keyVpnTargetMap.isEmpty()) {
                    for (VpnTarget vpnTarget : keyVpnTargetMap.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());
                        }
                    }
                }
            }
            l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
            if (vpnInstance.getL3vni() != null) {
                l3vpn.setL3vni(vpnInstance.getL3vni());
            }
            InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
            Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
            if (optionalVpnMap.isPresent()) {
                VpnMap vpnMap = optionalVpnMap.get();
                List<Uuid> rtrIds = new ArrayList<>();
                if (vpnMap.getRouterIds() != null && !vpnMap.getRouterIds().isEmpty()) {
                    for (RouterIds rtrId : vpnMap.getRouterIds().values()) {
                        rtrIds.add(rtrId.getRouterId());
                    }
                }
                l3vpn.setRouterIds(NeutronvpnUtils.getVpnInstanceRouterIdsList(rtrIds)).setNetworkIds(vpnMap.getNetworkIds()).setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
            }
            l3vpnList.add(l3vpn.build());
        }
        opBuilder.setL3vpnInstances(l3vpnList);
        result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
    } catch (ExecutionException | InterruptedException ex) {
        result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
    }
    return result;
}
Also used : VpnTargetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) GetL3VPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutput) L3vpnInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances) VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget) ExecutionException(java.util.concurrent.ExecutionException) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetL3VPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutputBuilder) VpnInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances) 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) L3vpnInstancesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstancesBuilder) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)

Aggregations

VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)7 ArrayList (java.util.ArrayList)5 VpnInstances (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances)4 HashSet (java.util.HashSet)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 PreDestroy (javax.annotation.PreDestroy)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)1 Executors (org.opendaylight.infrautils.utils.concurrent.Executors)1