Search in sources :

Example 71 with VpnInstance

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

the class VrfEntryListener method deleteLabelRouteInfo.

private boolean deleteLabelRouteInfo(LabelRouteInfo lri, String vpnInstanceName, WriteTransaction tx) {
    if (lri == null) {
        return true;
    }
    LOG.debug("deleting LRI : for label {} vpninstancename {}", lri.getLabel(), vpnInstanceName);
    InstanceIdentifier<LabelRouteInfo> lriId = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(lri.getLabel())).build();
    List<String> vpnInstancesList = lri.getVpnInstanceList() != null ? lri.getVpnInstanceList() : new ArrayList<>();
    if (vpnInstancesList.contains(vpnInstanceName)) {
        LOG.debug("vpninstance {} name is present", vpnInstanceName);
        vpnInstancesList.remove(vpnInstanceName);
    }
    if (vpnInstancesList.isEmpty()) {
        LOG.debug("deleting LRI instance object for label {}", lri.getLabel());
        if (tx != null) {
            tx.delete(LogicalDatastoreType.OPERATIONAL, lriId);
        } else {
            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId);
        }
        return true;
    } else {
        LOG.debug("updating LRI instance object for label {}", lri.getLabel());
        LabelRouteInfoBuilder builder = new LabelRouteInfoBuilder(lri).setVpnInstanceList(vpnInstancesList);
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId, builder.build());
    }
    return false;
}
Also used : LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) LabelRouteInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoBuilder) LabelRouteInfoKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoKey)

Example 72 with VpnInstance

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

the class EvpnVrfEntryHandler method deleteRemoteEvpnFlows.

private void deleteRemoteEvpnFlows(String rd, VrfEntry vrfEntry, VpnInstanceOpDataEntry vpnInstance, VrfTablesKey vrfTableKey, List<BigInteger> localDpnIdList) {
    List<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
    List<SubTransaction> subTxns = new ArrayList<>();
    if (vpnToDpnList != null) {
        jobCoordinator.enqueueJob("FIB" + rd + vrfEntry.getDestPrefix(), () -> {
            WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
            final Optional<Routes> extraRouteOptional = Optional.absent();
            if (localDpnIdList.size() <= 0) {
                for (VpnToDpnList curDpn1 : vpnToDpnList) {
                    if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
                        if (curDpn1.getDpnState() == VpnToDpnList.DpnState.Active) {
                            bgpRouteVrfEntryHandler.deleteRemoteRoute(BigInteger.ZERO, curDpn1.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx, subTxns);
                        }
                    } else {
                        deleteRemoteRoute(BigInteger.ZERO, curDpn1.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
                    }
                }
            } else {
                for (BigInteger localDpnId : localDpnIdList) {
                    for (VpnToDpnList curDpn2 : vpnToDpnList) {
                        if (!curDpn2.getDpnId().equals(localDpnId)) {
                            if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
                                if (curDpn2.getDpnState() == VpnToDpnList.DpnState.Active) {
                                    bgpRouteVrfEntryHandler.deleteRemoteRoute(localDpnId, curDpn2.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx, subTxns);
                                }
                            } else {
                                deleteRemoteRoute(localDpnId, curDpn2.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
                            }
                        }
                    }
                }
            }
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            futures.add(tx.submit());
            return futures;
        });
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)

Example 73 with VpnInstance

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

the class NeutronvpnManager method updateVpnInstanceNode.

private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion) {
    String vpnName = vpnId.getValue();
    VpnInstanceBuilder builder = null;
    List<VpnTarget> vpnTargetList = new ArrayList<>();
    boolean isLockAcquired = false;
    InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
    try {
        Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
        LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
        if (optionalVpn.isPresent()) {
            builder = new VpnInstanceBuilder(optionalVpn.get());
            LOG.debug("updating existing vpninstance node");
        } else {
            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();
        isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
    } finally {
        if (isLockAcquired) {
            vpnLock.unlock(vpnId);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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 74 with VpnInstance

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

the class NeutronvpnManager method writeVpnInterfaceToDs.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies, Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
    if (vpnIdList.isEmpty() || infName == null) {
        LOG.error("vpn id or interface is null");
        return;
    }
    List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
    for (Uuid vpnId : vpnIdList) {
        VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
        vpnIdListStruct.add(vpnInstance);
    }
    Boolean wrtConfigTxnPresent = true;
    if (wrtConfigTxn == null) {
        wrtConfigTxnPresent = false;
        wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
    if (adjacencies != null) {
        vpnb.addAugmentation(Adjacencies.class, adjacencies);
    }
    VpnInterface vpnIf = vpnb.build();
    try {
        LOG.info("Creating vpn interface {}", vpnIf);
        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
    } catch (Exception ex) {
        LOG.error("Creation of vpninterface {} failed", infName, ex);
    }
    if (!wrtConfigTxnPresent) {
        wrtConfigTxn.submit();
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) ArrayList(java.util.ArrayList) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 75 with VpnInstance

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

the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.

private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, WriteTransaction wrtConfigTxn) {
    if (vpnId == null || infName == null) {
        LOG.error("vpn id or interface is null");
        return;
    }
    if (wrtConfigTxn == null) {
        wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    boolean isLockAcquired = false;
    try {
        isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        if (optionalVpnInterface.isPresent()) {
            VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
            LOG.debug("Updating vpn interface {} with new adjacencies", infName);
            if (adjacencies == null) {
                if (isLockAcquired) {
                    interfaceLock.unlock(infName);
                }
                return;
            }
            vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
            if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
                List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
                if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
                    VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
                    listVpnInstances.add(vpnInstance);
                    vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
                }
            } else {
                VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
                List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
                listVpnInstances.add(vpnInstance);
                vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
            }
            LOG.info("Updating vpn interface {} with new adjacencies", infName);
            wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
        }
    } catch (IllegalStateException | ReadFailedException ex) {
        LOG.error("Update of vpninterface {} failed", infName, ex);
    } finally {
        if (isLockAcquired) {
            interfaceLock.unlock(infName);
        }
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)62 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)40 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)37 ExecutionException (java.util.concurrent.ExecutionException)36 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)31 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)26 List (java.util.List)24 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)23 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)22 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)22 Logger (org.slf4j.Logger)22 LoggerFactory (org.slf4j.LoggerFactory)22 Inject (javax.inject.Inject)21 Singleton (javax.inject.Singleton)21 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)21 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)20 FutureCallback (com.google.common.util.concurrent.FutureCallback)19 Futures (com.google.common.util.concurrent.Futures)19 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)19 Collections (java.util.Collections)19