Search in sources :

Example 1 with EvpnInstancesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstancesBuilder in project netvirt by opendaylight.

the class NeutronEvpnManager method getEVPN.

public Future<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.getIpv4Family().getRouteDistinguisher() != null && vpn.getType() == VpnInstance.Type.L2) {
                    vpns.add(vpn);
                }
            }
        } else {
            // No VPN present
            result.set(RpcResultBuilder.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
            return result;
        }
    } else {
        String name = inputVpnId.getValue();
        VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, name);
        if (vpnInstance != null && vpnInstance.getIpv4Family().getRouteDistinguisher() != null && vpnInstance.getType() == VpnInstance.Type.L2) {
            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.getIpv4Family().getRouteDistinguisher();
        List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
        List<String> ertList = new ArrayList<>();
        List<String> irtList = new ArrayList<>();
        for (VpnTarget vpnTarget : vpnTargetList) {
            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 (ReadFailedException 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.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
    return result;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) GetEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutputBuilder) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.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)

Aggregations

ArrayList (java.util.ArrayList)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 VpnTarget (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget)1 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)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