Search in sources :

Example 11 with Adjacencies

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

the class VpnInterfaceManager method removeAdjacenciesFromVpn.

private void removeAdjacenciesFromVpn(final Uint64 dpnId, final int lportTag, final String interfaceName, final String vpnName, final Uint32 vpnId, String gwMac, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn, TypedReadWriteTransaction<Configuration> writeInvTxn) throws ExecutionException, InterruptedException {
    // Read NextHops
    try {
        InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
        Optional<VpnInterfaceOpDataEntry> vpnInterfaceOpDataEnteryOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
        boolean isNonPrimaryAdjIp = false;
        String primaryRd = vpnUtil.getVpnRd(vpnName);
        LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}", interfaceName, dpnId, vpnName, primaryRd);
        if (!vpnInterfaceOpDataEnteryOptional.isPresent()) {
            LOG.error("removeAdjacenciesFromVpn: VpnInterfaceOpDataEntry-Oper DS is absent for Interface {} " + "on vpn {} dpn {}", interfaceName, vpnName, dpnId);
            return;
        }
        AdjacenciesOp adjacencies = vpnInterfaceOpDataEnteryOptional.get().augmentation(AdjacenciesOp.class);
        if (adjacencies != null && adjacencies.getAdjacency() != null) {
            Map<AdjacencyKey, Adjacency> nextHopsMap = adjacencies.nonnullAdjacency();
            LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}", interfaceName, dpnId, vpnName, nextHopsMap);
            for (Adjacency nextHop : nextHopsMap.values()) {
                if (nextHop.isPhysNetworkFunc()) {
                    LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}", nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
                    fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(), null, null);
                } else {
                    String rd = nextHop.getVrfId();
                    List<String> nhList;
                    if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
                        nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
                        isNonPrimaryAdjIp = Boolean.TRUE;
                    } else {
                        // This is a primary adjacency
                        nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList() : emptyList();
                        removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac, vpnInterfaceOpDataEnteryOptional.get().getGatewayIpAddress(), interfaceName, writeInvTxn);
                        isNonPrimaryAdjIp = Boolean.FALSE;
                    }
                    if (!nhList.isEmpty()) {
                        if (Objects.equals(primaryRd, vpnName)) {
                            // this is an internal vpn - the rd is assigned to the vpn instance name;
                            // remove from FIB directly
                            nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName, interfaceName, dpnId, writeConfigTxn, writeOperTxn));
                        } else {
                            removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd, interfaceName, isNonPrimaryAdjIp, writeConfigTxn, writeOperTxn);
                        }
                    } else {
                        LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}" + " interface {}", nextHop.getIpAddress(), rd, nextHop.getAdjacencyType().toString(), interfaceName);
                        bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
                        fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), null, writeConfigTxn);
                    }
                }
                String ip = nextHop.getIpAddress().split("/")[0];
                LearntVpnVipToPort vpnVipToPort = vpnUtil.getLearntVpnVipToPort(vpnName, ip);
                if (vpnVipToPort != null && vpnVipToPort.getPortName().equals(interfaceName)) {
                    vpnUtil.removeLearntVpnVipToPort(vpnName, ip, null);
                    LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed LearntVpnVipToPort entry" + " for Interface {} ip {} on dpn {} for vpn {}", vpnVipToPort.getPortName(), ip, dpnId, vpnName);
                }
                // Remove the MIP-IP from VpnPortIpToPort.
                if (isNonPrimaryAdjIp) {
                    VpnPortipToPort persistedIp = vpnUtil.getVpnPortipToPort(vpnName, ip);
                    if (persistedIp != null && persistedIp.isLearntIp() && persistedIp.getPortName().equals(interfaceName)) {
                        VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, ip, null);
                        LOG.info("removeAdjacenciesFromVpn: Learnt-IP: {} interface {} of vpn {} removed " + "from VpnPortipToPort", persistedIp.getPortFixedip(), persistedIp.getPortName(), vpnName);
                    }
                }
                VpnPortipToPort vpnPortipToPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnName, ip);
                if (vpnPortipToPort != null) {
                    VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, ip, null);
                    LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed vpnPortipToPort entry for " + "Interface {} ip {} on dpn {} for vpn {}", vpnPortipToPort.getPortName(), ip, dpnId, vpnName);
                }
            }
        } else {
            // this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
            LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies." + " Removing it.", interfaceName, vpnName, dpnId);
            writeOperTxn.delete(identifier);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("removeAdjacenciesFromVpn: Failed to read data store for interface {} dpn {} vpn {}", interfaceName, dpnId, vpnName);
    }
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with Adjacencies

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

the class VpnInterfaceManager method createFibEntryForRouterInterface.

protected void createFibEntryForRouterInterface(String primaryRd, VpnInterface vpnInterface, String interfaceName, TypedWriteTransaction<Configuration> writeConfigTxn, String vpnName) {
    if (vpnInterface == null) {
        return;
    }
    List<Adjacency> adjs = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(interfaceName);
    if (adjs == null) {
        LOG.error("createFibEntryForRouterInterface: VPN Interface {} of router addition failed as adjacencies for" + " this vpn interface could not be obtained. vpn {}", interfaceName, vpnName);
        return;
    }
    for (Adjacency adj : adjs) {
        if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            String primaryInterfaceIp = adj.getIpAddress();
            String macAddress = adj.getMacAddress();
            String prefix = VpnUtil.getIpPrefix(primaryInterfaceIp);
            Uint32 label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(primaryRd, prefix));
            if (label.longValue() == VpnConstants.INVALID_LABEL) {
                LOG.error("createFibEntryForRouterInterface: Unable to retrieve label for vpn pool {}, " + "vpninterface {}, vpn {}, rd {}", VpnConstants.VPN_IDPOOL_NAME, interfaceName, vpnName, primaryRd);
                return;
            }
            RouterInterface routerInt = new RouterInterfaceBuilder().setUuid(vpnName).setIpAddress(primaryInterfaceIp).setMacAddress(macAddress).build();
            fibManager.addFibEntryForRouterInterface(primaryRd, prefix, routerInt, label, writeConfigTxn);
            LOG.info("createFibEntryForRouterInterface: Router interface {} for vpn {} rd {} prefix {} label {}" + " macAddress {} processed successfully;", interfaceName, vpnName, primaryRd, prefix, label, macAddress);
        } else {
            LOG.error("createFibEntryForRouterInterface: VPN Interface {} of router addition failed as primary" + " adjacency for this vpn interface could not be obtained. rd {} vpnName {}", interfaceName, primaryRd, vpnName);
        }
    }
}
Also used : RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) RouterInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterfaceBuilder) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 13 with Adjacencies

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

the class VpnInterfaceManager method addNewAdjToVpnInterface.

protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd, Adjacency adj, Uint64 dpnId, TypedWriteTransaction<Operational> writeOperTxn, TypedWriteTransaction<Configuration> writeConfigTxn, TypedReadWriteTransaction<Configuration> writeInvTxn, Set<String> prefixListForRefreshFib) throws ExecutionException, InterruptedException {
    String interfaceName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getName();
    String configVpnName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getVpnInstanceName();
    try {
        Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
        if (optVpnInterface.isPresent()) {
            VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
            String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
            String vpnName = currVpnIntf.getVpnInstanceName();
            VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
            InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
            Optional<AdjacenciesOp> optAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, adjPath);
            boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
            VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
            Uint32 l3vni = vpnInstanceOpData.getL3vni() == null ? Uint32.ZERO : vpnInstanceOpData.getL3vni();
            VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
            List<Adjacency> adjacencies = new ArrayList<>();
            if (optAdjacencies.isPresent() && optAdjacencies.get().getAdjacency() != null) {
                adjacencies.addAll(optAdjacencies.get().getAdjacency().values());
            }
            Uint32 vpnId = vpnUtil.getVpnId(vpnName);
            L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName).setInterfaceName(currVpnIntf.getName()).setPrimaryRd(primaryRd).setRd(primaryRd);
            Adjacency operationalAdjacency = null;
            // Handling dual stack neutron port primary adjacency
            if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency && !adj.isPhysNetworkFunc()) {
                LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to existing interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
                Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, currVpnIntf.getName());
                if (interfaceState != null) {
                    processVpnInterfaceAdjacencies(dpnId, currVpnIntf.getLportTag().intValue(), vpnName, primaryRd, currVpnIntf.getName(), vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, prefixListForRefreshFib);
                }
            }
            if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty() && adj.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
                RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.LearntIp ? RouteOrigin.DYNAMIC : RouteOrigin.STATIC;
                String nh = adj.getNextHopIpList().get(0);
                String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
                // FIXME: separate out to somehow?
                final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnPrefixKey);
                lock.lock();
                try {
                    java.util.Optional<String> rdToAllocate = vpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(vpnId, null, prefix, vpnName, nh, dpnId);
                    if (rdToAllocate.isPresent()) {
                        input.setRd(rdToAllocate.get());
                        operationalAdjacency = populator.createOperationalAdjacency(input);
                        int label = operationalAdjacency.getLabel().intValue();
                        vpnManager.addExtraRoute(vpnName, adj.getIpAddress(), nh, rdToAllocate.get(), currVpnIntf.getVpnInstanceName(), l3vni, origin, currVpnIntf.getName(), operationalAdjacency, encapType, prefixListForRefreshFib, writeConfigTxn);
                        LOG.info("addNewAdjToVpnInterface: Added extra route ip {} nh {} rd {} vpnname {} label {}" + " Interface {} on dpn {}", adj.getIpAddress(), nh, rdToAllocate.get(), vpnName, label, currVpnIntf.getName(), dpnId);
                    } else {
                        LOG.error("addNewAdjToVpnInterface: No rds to allocate extraroute vpn {} prefix {}", vpnName, prefix);
                        return;
                    }
                    // Keeping the MPLS check for now.
                    if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
                        final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
                        List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
                        vpnsToImportRoute.forEach(vpn -> {
                            if (vpn.getVrfId() != null) {
                                vpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(vpn.getVpnId(), vpnId, prefix, vpnUtil.getVpnName(vpn.getVpnId()), nh, dpnId).ifPresent(rds -> vpnManager.addExtraRoute(vpnUtil.getVpnName(vpn.getVpnId()), adj.getIpAddress(), nh, rds, currVpnIntf.getVpnInstanceName(), l3vni, RouteOrigin.SELF_IMPORTED, currVpnIntf.getName(), opAdjacency, encapType, prefixListForRefreshFib, writeConfigTxn));
                            }
                        });
                    }
                } finally {
                    lock.unlock();
                }
            } else if (adj.isPhysNetworkFunc()) {
                // PNF adjacency.
                LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
                InstanceIdentifier<VpnInterface> vpnIfaceConfigidentifier = VpnUtil.getVpnInterfaceIdentifier(currVpnIntf.getName());
                Optional<VpnInterface> vpnIntefaceConfig = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfaceConfigidentifier);
                Prefixes pnfPrefix = VpnUtil.getPrefixToInterface(Uint64.ZERO, currVpnIntf.getName(), prefix, Prefixes.PrefixCue.PhysNetFunc);
                if (vpnIntefaceConfig.isPresent()) {
                    pnfPrefix = VpnUtil.getPrefixToInterface(Uint64.ZERO, currVpnIntf.getName(), prefix, vpnIntefaceConfig.get().getNetworkId(), vpnIntefaceConfig.get().getNetworkType(), vpnIntefaceConfig.get().getSegmentationId().toJava(), Prefixes.PrefixCue.PhysNetFunc);
                }
                String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
                writeOperTxn.mergeParentStructureMerge(VpnUtil.getPrefixToInterfaceIdentifier(vpnUtil.getVpnId(adj.getSubnetId().getValue()), prefix), pnfPrefix);
                fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(), adj.getIpAddress(), emptyList(), null, /* EncapType */
                Uint32.ZERO, /* label */
                Uint32.ZERO, /*l3vni*/
                null, /* gw-mac */
                parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
                input.setRd(adj.getVrfId());
            }
            if (operationalAdjacency == null) {
                operationalAdjacency = populator.createOperationalAdjacency(input);
            }
            adjacencies.add(operationalAdjacency);
            AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
            VpnInterfaceOpDataEntry newVpnIntf = VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.getLportTag().toJava(), currVpnIntf.getGatewayMacAddress(), currVpnIntf.getGatewayIpAddress());
            writeOperTxn.mergeParentStructureMerge(identifier, newVpnIntf);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("addNewAdjToVpnInterface: Failed to read data store for interface {} dpn {} vpn {} rd {} ip " + "{}", interfaceName, dpnId, configVpnName, primaryRd, adj.getIpAddress());
    }
}
Also used : ArrayList(java.util.ArrayList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) Optional(java.util.Optional) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface)

Example 14 with Adjacencies

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

the class VpnInterfaceManager method updateVpnInstanceAdjChange.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private List<ListenableFuture<?>> updateVpnInstanceAdjChange(VpnInterface original, VpnInterface update, String vpnInterfaceName, List<ListenableFuture<?>> futures) {
    final Adjacencies origAdjs = original.augmentation(Adjacencies.class);
    final List<Adjacency> oldAdjs = origAdjs != null && origAdjs.getAdjacency() != null ? new ArrayList<>(origAdjs.getAdjacency().values()) : new ArrayList<>();
    final Adjacencies updateAdjs = update.augmentation(Adjacencies.class);
    final List<Adjacency> newAdjs = updateAdjs != null && updateAdjs.getAdjacency() != null ? new ArrayList<>(updateAdjs.getAdjacency().values()) : new ArrayList<>();
    final Uint64 dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
    for (VpnInstanceNames vpnInterfaceVpnInstance : update.nonnullVpnInstanceNames().values()) {
        String newVpnName = vpnInterfaceVpnInstance.getVpnName();
        List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
        List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
        String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
        if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
            // TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
            // set of prefix used as entry in prefix-to-interface datastore
            // is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
            // in bucket actions on bgp-vpn delete
            Set<String> prefixListForRefreshFib = new HashSet<>();
            ListenableFuture<?> configTxFuture = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
                InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterfaceName, newVpnName);
                LOG.info("VPN Interface update event-intfName {} onto vpnName {} running config-driven", update.getName(), newVpnName);
                // handle both addition and removal of adjacencies
                // currently, new adjacency may be an extra route
                boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(newVpnName);
                if (!oldAdjs.equals(newAdjs)) {
                    for (Adjacency adj : copyNewAdjs) {
                        if (copyOldAdjs.contains(adj)) {
                            copyOldAdjs.remove(adj);
                        } else {
                            // add new adjacency
                            if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
                                try {
                                    addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, confTx, prefixListForRefreshFib);
                                } catch (RuntimeException e) {
                                    LOG.error("Failed to add adjacency {} to vpn interface {} with" + " dpnId {}", adj, vpnInterfaceName, dpnId, e);
                                }
                            }
                            LOG.info("update: new Adjacency {} with nextHop {} label {} subnet {} " + " added to vpn interface {} on vpn {} dpnId {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName, dpnId);
                        }
                    }
                    for (Adjacency adj : copyOldAdjs) {
                        if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
                            if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency && !adj.isPhysNetworkFunc()) {
                                delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
                                // remove FIB entry
                                String vpnRd = vpnUtil.getVpnRd(newVpnName);
                                LOG.debug("update: remove prefix {} from the FIB and BGP entry " + "for the Vpn-Rd {} ", adj.getIpAddress(), vpnRd);
                                // remove BGP entry
                                fibManager.removeFibEntry(vpnRd, adj.getIpAddress(), null, confTx);
                                if (vpnRd != null && !vpnRd.equalsIgnoreCase(newVpnName)) {
                                    bgpManager.withdrawPrefix(vpnRd, adj.getIpAddress());
                                }
                            } else {
                                delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
                            }
                        }
                        LOG.info("update: Adjacency {} with nextHop {} label {} subnet {} removed from" + " vpn interface {} on vpn {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName);
                    }
                }
            })));
            Futures.addCallback(configTxFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
            futures.add(configTxFuture);
            for (ListenableFuture<?> future : futures) {
                LoggingFutures.addErrorLogging(future, LOG, "update: failed for interface {} on vpn {}", update.getName(), update.getVpnInstanceNames());
            }
        } else {
            LOG.error("update: Ignoring update of vpnInterface {}, as newVpnInstance {} with primaryRd {}" + " is already marked for deletion", vpnInterfaceName, newVpnName, primaryRd);
        }
    }
    return futures;
}
Also used : ArrayList(java.util.ArrayList) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) Uint64(org.opendaylight.yangtools.yang.common.Uint64) HashSet(java.util.HashSet)

Example 15 with Adjacencies

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

the class VpnInterfaceManager method updateVpnInterfaceOnTepAdd.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateVpnInterfaceOnTepAdd(VpnInterfaceOpDataEntry vpnInterface, StateTunnelList stateTunnelList, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn) {
    String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
    Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern();
    AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
    Map<AdjacencyKey, Adjacency> keyAdjacencyMap = adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency() : Collections.<AdjacencyKey, Adjacency>emptyMap();
    if (keyAdjacencyMap.isEmpty()) {
        LOG.trace("updateVpnInterfaceOnTepAdd: Adjacencies are empty for vpnInterface {} on dpn {}", vpnInterface, srcDpnId);
        return;
    }
    String prefix = null;
    List<Adjacency> value = new ArrayList<>();
    boolean isFibNextHopAddReqd = false;
    String vpnName = vpnInterface.getVpnInstanceName();
    Uint32 vpnId = vpnUtil.getVpnId(vpnName);
    String primaryRd = vpnUtil.getPrimaryRd(vpnName);
    LOG.info("updateVpnInterfaceOnTepAdd: AdjacencyList for interface {} on dpn {} vpn {} is {}", vpnInterface.getName(), vpnInterface.getDpnId(), vpnInterface.getVpnInstanceName(), keyAdjacencyMap);
    for (Adjacency adj : keyAdjacencyMap.values()) {
        String rd = adj.getVrfId();
        rd = rd != null ? rd : vpnName;
        prefix = adj.getIpAddress();
        Uint32 label = adj.getLabel();
        List<String> nhList = Collections.singletonList(srcTepIp);
        List<String> nextHopList = adj.getNextHopIpList();
        // Secondary adj nexthop is already pointing to primary adj IP address.
        if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            value.add(new AdjacencyBuilder(adj).setNextHopIpList(nhList).build());
            if (nextHopList != null && !nextHopList.isEmpty()) {
            /* everything right already */
            } else {
                isFibNextHopAddReqd = true;
            }
        } else {
            Optional<VrfEntry> vrfEntryOptional = FibHelper.getVrfEntry(dataBroker, primaryRd, prefix);
            if (!vrfEntryOptional.isPresent()) {
                continue;
            }
            nhList = FibHelper.getNextHopListFromRoutePaths(vrfEntryOptional.get());
            if (!nhList.contains(srcTepIp)) {
                nhList.add(srcTepIp);
                isFibNextHopAddReqd = true;
            }
            value.add(adj);
        }
        if (isFibNextHopAddReqd) {
            updateLabelMapper(label, nhList);
            LOG.info("updateVpnInterfaceOnTepAdd: Updated label mapper : label {} dpn {} prefix {} nexthoplist {}" + " vpn {} vpnid {} rd {} interface {}", label, srcDpnId, prefix, nhList, vpnInterface.getVpnInstanceName(), vpnId, rd, vpnInterface.getName());
            // Update the VRF entry with nextHop
            fibManager.updateRoutePathForFibEntry(primaryRd, prefix, srcTepIp, label, true, writeConfigTxn);
            // Get the list of VPN's importing this route(prefix) .
            // Then update the VRF entry with nhList
            List<VpnInstanceOpDataEntry> vpnsToImportRoute = vpnUtil.getVpnsImportingMyRoute(vpnName);
            for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
                String vpnRd = vpn.getVrfId();
                if (vpnRd != null) {
                    fibManager.updateRoutePathForFibEntry(vpnRd, prefix, srcTepIp, label, true, writeConfigTxn);
                    LOG.info("updateVpnInterfaceOnTepAdd: Exported route with rd {} prefix {} nhList {} label {}" + " interface {} dpn {} from vpn {} to VPN {} vpnRd {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName, vpn.getVpnInstanceName(), vpnRd);
                }
            }
            // since there is a nexthop change.
            try {
                if (!rd.equalsIgnoreCase(vpnName)) {
                    bgpManager.advertisePrefix(rd, null, /*macAddress*/
                    prefix, nhList, VrfEntry.EncapType.Mplsgre, label, Uint32.ZERO, /*evi*/
                    Uint32.ZERO, /*l2vni*/
                    null);
                }
                LOG.info("updateVpnInterfaceOnTepAdd: Advertised rd {} prefix {} nhList {} label {}" + " for interface {} on dpn {} vpn {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName);
            } catch (Exception ex) {
                LOG.error("updateVpnInterfaceOnTepAdd: Exception when advertising prefix {} nh {} label {}" + " on rd {} for interface {} on dpn {} vpn {}", prefix, nhList, label, rd, vpnInterface.getName(), srcDpnId, vpnName, ex);
            }
        }
    }
    AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
    VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface).withKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName)).addAugmentation(aug).build();
    InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
    writeOperTxn.mergeParentStructurePut(interfaceId, opInterface);
    LOG.info("updateVpnInterfaceOnTepAdd: interface {} updated successully on tep add on dpn {} vpn {}", vpnInterface.getName(), srcDpnId, vpnName);
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) VpnInterfaceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

ArrayList (java.util.ArrayList)31 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency)28 ExecutionException (java.util.concurrent.ExecutionException)27 AdjacenciesOp (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp)22 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)22 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey)20 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)19 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies)18 VpnInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)15 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)14 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)14 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)13 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)12 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)11 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)9 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder)9 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)9 List (java.util.List)8 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)8