Search in sources :

Example 6 with VpnMapKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey in project netvirt by opendaylight.

the class NeutronvpnManager method getL3VPN.

/**
 * It handles the invocations to the neutronvpn:getL3VPN RPC method.
 */
@Override
public Future<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().getVpnInstance()) {
                    // from getL3VPN output
                    if (vpn.getIpv4Family().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().getIpv4Family().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 = vpnInstance.getIpv4Family().getRouteDistinguisher();
            List<String> ertList = new ArrayList<>();
            List<String> irtList = new ArrayList<>();
            if (vpnInstance.getIpv4Family().getVpnTargets() != null) {
                List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
                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());
                    }
                }
            }
            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();
                l3vpn.setRouterId(vpnMap.getRouterId()).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 (ReadFailedException ex) {
        result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
    }
    return result;
}
Also used : VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances) 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)

Example 7 with VpnMapKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey in project netvirt by opendaylight.

the class NeutronvpnUtils method getRouterforVpn.

protected Uuid getRouterforVpn(Uuid vpnId) {
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
    Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
    if (optionalVpnMap.isPresent()) {
        VpnMap vpnMap = optionalVpnMap.get();
        return vpnMap.getRouterId();
    }
    LOG.error("getRouterforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue());
    return null;
}
Also used : VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)

Example 8 with VpnMapKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey in project netvirt by opendaylight.

the class NeutronvpnUtils method getRouterIdfromVpnInstance.

public String getRouterIdfromVpnInstance(String vpnName) {
    // returns only router, attached to IPv4 networks
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(new Uuid(vpnName))).build();
    Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
    if (!optionalVpnMap.isPresent()) {
        LOG.error("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
        return null;
    }
    Uuid routerId = optionalVpnMap.get().getRouterId();
    if (routerId != null) {
        return routerId.getValue();
    }
    LOG.info("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)

Aggregations

VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)8 VpnMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)8 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 ArrayList (java.util.ArrayList)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 VpnTarget (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget)2 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)2 VpnMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapBuilder)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 VpnInstances (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances)1 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)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 GetL3VPNOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutput)1 GetL3VPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutputBuilder)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 L3vpnInstances (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances)1 L3vpnInstancesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getl3vpn.output.L3vpnInstancesBuilder)1