Search in sources :

Example 41 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.

the class EvpnVrfEntryHandler method createRemoteFibEntry.

private void createRemoteFibEntry(final Uint64 remoteDpnId, final Uint32 vpnId, final VrfTablesKey vrfTableKey, final VrfEntry vrfEntry, boolean isNatPrefix, WriteTransaction tx) {
    String rd = vrfTableKey.getRouteDistinguisher();
    List<SubTransaction> subTxns = new ArrayList<>();
    LOG.debug("createremotefibentry: adding route {} for rd {} with transaction {}", vrfEntry.getDestPrefix(), rd, tx);
    List<NexthopManager.AdjacencyResult> tunnelInterfaceList = resolveAdjacency(remoteDpnId, vpnId, vrfEntry, rd);
    if (tunnelInterfaceList.isEmpty()) {
        LOG.error("Could not get interface for route-paths: {} in vpn {}", vrfEntry.getRoutePaths(), rd);
        LOG.warn("Failed to add Route: {} in vpn: {}", vrfEntry.getDestPrefix(), rd);
        return;
    }
    for (NexthopManager.AdjacencyResult adjacencyResult : tunnelInterfaceList) {
        List<ActionInfo> actionInfos = new ArrayList<>();
        Uint64 tunnelId = Uint64.ZERO;
        String prefix = adjacencyResult.getPrefix();
        Prefixes prefixInfo = getFibUtil().getPrefixToInterface(vpnId, prefix);
        String interfaceName = prefixInfo.getVpnInterfaceName();
        if (RouteOrigin.BGP.getValue().equals(vrfEntry.getOrigin()) || isNatPrefix) {
            tunnelId = Uint64.valueOf(vrfEntry.getL3vni().longValue());
        } else if (FibUtil.isVxlanNetwork(prefixInfo.getNetworkType())) {
            tunnelId = Uint64.valueOf(prefixInfo.getSegmentationId().longValue());
        } else {
            try {
                StateTunnelList stateTunnelList = getFibUtil().getTunnelState(interfaceName);
                if (stateTunnelList == null || stateTunnelList.getOperState() != TunnelOperStatus.Up) {
                    LOG.trace("Tunnel is not up for interface {}", interfaceName);
                    return;
                }
                tunnelId = Uint64.valueOf(stateTunnelList.getIfIndex().intValue());
            } catch (ReadFailedException e) {
                LOG.error("createRemoteFibEntry: error in fetching tunnel state for interface {}", interfaceName, e);
                continue;
            }
        }
        LOG.debug("adding set tunnel id action for label {}", tunnelId);
        String macAddress = null;
        String vpnName = getFibUtil().getVpnNameFromId(vpnId);
        if (vpnName == null) {
            LOG.debug("Failed to get VPN name for vpnId {}", vpnId);
            return;
        }
        if (interfaceName != null) {
            macAddress = getFibUtil().getMacAddressFromPrefix(interfaceName, vpnName, prefix);
            actionInfos.add(new ActionSetFieldEthernetDestination(new MacAddress(macAddress)));
        }
        actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
        List<ActionInfo> egressActions = nexthopManager.getEgressActionsForInterface(adjacencyResult.getInterfaceName(), actionInfos.size(), true, vpnId, vrfEntry.getDestPrefix());
        if (egressActions.isEmpty()) {
            LOG.error("Failed to retrieve egress action for prefix {} route-paths {} interface {}." + " Aborting remote FIB entry creation..", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), adjacencyResult.getInterfaceName());
            return;
        }
        actionInfos.addAll(egressActions);
        List<InstructionInfo> instructions = new ArrayList<>();
        instructions.add(new InstructionApplyActions(actionInfos));
        makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, subTxns);
    }
    LOG.debug("Successfully added FIB entry for prefix {} in rd {}", vrfEntry.getDestPrefix(), rd);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) ArrayList(java.util.ArrayList) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 42 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.

the class EvpnVrfEntryHandler method createRemoteEvpnFlows.

// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
private void createRemoteEvpnFlows(String rd, VrfEntry vrfEntry, VpnInstanceOpDataEntry vpnInstance, List<Uint64> localDpnId, VrfTablesKey vrfTableKey, boolean isNatPrefix) {
    LOG.info("Creating remote EVPN flows for prefix {} rd {} route-paths {} evi {}", vrfEntry.getDestPrefix(), rd, vrfEntry.getRoutePaths(), vrfEntry.getL3vni());
    Map<VpnToDpnListKey, VpnToDpnList> keyVpnToDpnListMap = vpnInstance.nonnullVpnToDpnList();
    if (keyVpnToDpnListMap != null) {
        jobCoordinator.enqueueJob("FIB" + rd + vrfEntry.getDestPrefix(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, tx -> {
            for (VpnToDpnList vpnDpn : keyVpnToDpnListMap.values()) {
                if (!localDpnId.contains(vpnDpn.getDpnId())) {
                    if (vpnDpn.getDpnState() == VpnToDpnList.DpnState.Active) {
                        createRemoteFibEntry(vpnDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, isNatPrefix, TransactionAdapter.toWriteTransaction(tx));
                    }
                }
            }
        })));
    }
}
Also used : VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) VpnToDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey)

Example 43 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.

the class VpnInterfaceManager method advertiseAdjacenciesForVpnToBgp.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void advertiseAdjacenciesForVpnToBgp(final String rd, Uint64 dpnId, final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String vpnName, String interfaceName) {
    if (rd == null) {
        LOG.error("advertiseAdjacenciesForVpnFromBgp: Unable to recover rd for interface {} on dpn {} in vpn {}", interfaceName, dpnId, vpnName);
        return;
    } else {
        if (rd.equals(vpnName)) {
            LOG.info("advertiseAdjacenciesForVpnFromBgp: Ignoring BGP advertisement for interface {} on dpn {}" + " as it is in internal vpn{} with rd {}", interfaceName, dpnId, vpnName, rd);
            return;
        }
    }
    LOG.info("advertiseAdjacenciesForVpnToBgp: Advertising interface {} on dpn {} in vpn {} with rd {} ", interfaceName, dpnId, vpnName, rd);
    String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
    if (nextHopIp == null) {
        LOG.error("advertiseAdjacenciesForVpnToBgp: NextHop for interface {} on dpn {} is null," + " returning from advertising route with rd {} vpn {} to bgp", interfaceName, dpnId, rd, vpnName);
        return;
    }
    try {
        // Read NextHops
        InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
        Optional<AdjacenciesOp> adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
        if (adjacencies.isPresent()) {
            Map<AdjacencyKey, Adjacency> nextHopsMap = adjacencies.get().getAdjacency();
            if (nextHopsMap != null && !nextHopsMap.isEmpty()) {
                LOG.debug("advertiseAdjacenciesForVpnToBgp:  NextHops are {} for interface {} on dpn {} for vpn {}" + " rd {}", nextHopsMap, interfaceName, dpnId, vpnName, rd);
                VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(rd);
                Uint32 l3vni = vpnInstanceOpData.getL3vni();
                VrfEntry.EncapType encapType = VpnUtil.isL3VpnOverVxLan(l3vni) ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
                for (Adjacency nextHop : nextHopsMap.values()) {
                    if (nextHop.getAdjacencyType() == AdjacencyType.ExtraRoute) {
                        continue;
                    }
                    String gatewayMac = null;
                    Uint32 label = Uint32.ZERO;
                    if (VpnUtil.isL3VpnOverVxLan(l3vni)) {
                        final VpnPortipToPort gwPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnInstanceOpData.getVpnInstanceName(), nextHop.getIpAddress());
                        gatewayMac = arpResponderHandler.getGatewayMacAddressForInterface(gwPort, interfaceName).get();
                    } else {
                        label = nextHop.getLabel();
                    }
                    try {
                        LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Adding Fib Entry rd {} prefix {}" + " nexthop {} label {}", rd, nextHop.getIpAddress(), nextHopIp, label);
                        bgpManager.advertisePrefix(rd, nextHop.getMacAddress(), nextHop.getIpAddress(), nextHopIp, encapType, label, l3vni, Uint32.ZERO, /*l2vni*/
                        gatewayMac);
                        LOG.info("VPN ADVERTISE: advertiseAdjacenciesForVpnToBgp: Added Fib Entry rd {} prefix {}" + " nexthop {} label {} for interface {} on dpn {} for vpn {}", rd, nextHop.getIpAddress(), nextHopIp, label, interfaceName, dpnId, vpnName);
                    } catch (Exception e) {
                        LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to advertise prefix {} in vpn {}" + " with rd {} for interface {} on dpn {}", nextHop.getIpAddress(), vpnName, rd, interfaceName, dpnId, e);
                    }
                }
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("advertiseAdjacenciesForVpnToBgp: Failed to read data store for interface {} dpn {} nexthop {}" + "vpn {} rd {}", interfaceName, dpnId, nextHopIp, vpnName, rd);
    }
}
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) ExecutionException(java.util.concurrent.ExecutionException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) 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) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 44 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route 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 45 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route 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)

Aggregations

ArrayList (java.util.ArrayList)82 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)57 ExecutionException (java.util.concurrent.ExecutionException)55 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)55 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)51 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)45 Test (org.junit.Test)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)43 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)40 BigInteger (java.math.BigInteger)33 List (java.util.List)33 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 Singleton (javax.inject.Singleton)32 Inject (javax.inject.Inject)30 RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)30 Collections (java.util.Collections)29 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)29 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)29