Search in sources :

Example 26 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class CloudScVpnInterfaceListener method add.

@Override
protected void add(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceAdded) {
    for (VpnInstanceNames vpnInstance : vpnIfaceAdded.getVpnInstanceNames()) {
        String vpnName = vpnInstance.getVpnName();
        if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets) && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
            continue;
        }
        try {
            Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
            if (!optScfInfoForVpn.isPresent()) {
                LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
                return;
            }
            vpnScHandler.bindScfOnVpnInterface(vpnIfaceAdded.getKey().getName(), optScfInfoForVpn.get().getScfTag());
        } catch (ReadFailedException e) {
            LOG.error("Error reading the SFC information for VPN {}", vpnName, e);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnToPseudoPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.cloud.servicechain.state.rev160711.vpn.to.pseudo.port.list.VpnToPseudoPortData)

Example 27 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance 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 28 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class NeutronEvpnManager method deleteEVPN.

public Future<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
    DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
    SettableFuture<RpcResult<DeleteEVPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    int warningcount = 0;
    List<Uuid> vpns = input.getId();
    for (Uuid vpn : vpns) {
        RpcError error;
        String msg;
        VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
        if (vpnInstance != null) {
            neutronvpnManager.removeVpn(vpn);
        } else {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
            warningcount++;
        }
    }
    if (failurecount != 0) {
        result.set(RpcResultBuilder.<DeleteEVPNOutput>failed().withRpcErrors(errorList).build());
    } else {
        List<String> errorResponseList = new ArrayList<>();
        if (!errorList.isEmpty()) {
            for (RpcError rpcError : errorList) {
                errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
            }
        } else {
            errorResponseList.add("Deletion of EVPN operation successful");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.<DeleteEVPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) DeleteEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteEVPNOutputBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 29 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance 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)

Example 30 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method addSubnetToVpn.

protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
    LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
    Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
    if (sn == null) {
        LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
        return;
    }
    if (vpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
            return;
        }
        final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
        LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance.toString());
        if (isVpnOfTypeL2(vpnInstance)) {
            neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
        }
    }
    if (internetVpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
            return;
        }
    }
    final Uuid internetId = internetVpnId;
    // Check if there are ports on this subnet and add corresponding vpn-interfaces
    List<Uuid> portList = sn.getPortList();
    if (portList != null) {
        for (final Uuid portId : portList) {
            String vpnInfName = portId.getValue();
            VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
            Port port = neutronvpnUtils.getNeutronPort(portId);
            if (port == null) {
                LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
                continue;
            }
            final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
            jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
                Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn, vpnIface);
                if (vpnIface == null) {
                    LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
                    Set<Uuid> listVpn = new HashSet<Uuid>();
                    if (vpnId != null) {
                        listVpn.add(vpnId);
                    }
                    if (internetId != null) {
                        listVpn.add(internetId);
                    }
                    writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
                    if (sn.getRouterId() != null) {
                        addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
                    }
                } else {
                    LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
                    if (vpnId != null) {
                        updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
                    }
                    if (internetId != null) {
                        updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
                    }
                }
            })));
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)39 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)23 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)19 BigInteger (java.math.BigInteger)18 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)17 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)16 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)15 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)14 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)14 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)13 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)13 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)13 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)12 List (java.util.List)10 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)9 Optional (com.google.common.base.Optional)7 PostConstruct (javax.annotation.PostConstruct)7 Inject (javax.inject.Inject)7 Singleton (javax.inject.Singleton)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)7