Search in sources :

Example 1 with GetEVPNInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNInput 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)

Aggregations

ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)1 VpnTarget (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget)1 GetEVPNOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutput)1 GetEVPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutputBuilder)1 EvpnInstances (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstances)1 EvpnInstancesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstancesBuilder)1 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)1 VpnMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1