Search in sources :

Example 16 with RoutePaths

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths in project netvirt by opendaylight.

the class ShowFibCommand method printVrfTable.

private void printVrfTable(VrfTables vrfTable, PrintStream console, boolean isIpv4, boolean isIpv6, boolean isL2vpn, String inputPrefixOrSubnet) {
    List<VrfEntry> vrfEntries = vrfTable.getVrfEntry();
    if (vrfEntries == null) {
        LOG.warn("Null vrfEntries found for VPN with rd={}", vrfTable.getRouteDistinguisher());
        return;
    }
    for (VrfEntry vrfEntry : vrfEntries) {
        boolean showIt = false;
        if (isIpv4 && isIpv6 && isL2vpn) {
            showIt = true;
        }
        if (!showIt && isIpv4) {
            LOG.debug("is ipv4 address family=> vrfEntry.getDestPrefix() = {}", vrfEntry.getDestPrefix());
            showIt = FibHelper.isIpv4Prefix(vrfEntry.getDestPrefix());
        }
        if (!showIt && isIpv6) {
            LOG.debug("is ipv6 address family=> vrfEntry.getDestPrefix() = {}", vrfEntry.getDestPrefix());
            showIt = FibHelper.isIpv6Prefix(vrfEntry.getDestPrefix());
        }
        if (!showIt && isL2vpn) {
            if (vrfEntry.getEncapType() != null && !EncapType.Mplsgre.equals(vrfEntry.getEncapType())) {
                LOG.debug("is l2vpn address family=> vrfEntry.getEncapType() = {}", vrfEntry.getEncapType());
                showIt = true;
            }
        }
        if (!showIt && inputPrefixOrSubnet != null) {
            showIt = FibHelper.isBelongingPrefix(vrfEntry.getDestPrefix(), inputPrefixOrSubnet);
        }
        if (!showIt) {
            continue;
        }
        List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
        if (routePaths == null || routePaths.isEmpty()) {
            console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), "local", routePaths == null ? "<not set>" : "<empty>", vrfEntry.getOrigin()));
            continue;
        }
        for (RoutePaths routePath : routePaths) {
            console.println(String.format(TABULAR_FORMAT, vrfTable.getRouteDistinguisher(), vrfEntry.getDestPrefix(), routePath.getNexthopAddress(), routePath.getLabel(), vrfEntry.getOrigin()));
        }
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths)

Example 17 with RoutePaths

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths in project netvirt by opendaylight.

the class BaseVrfEntryHandler method resolveAdjacency.

@Nonnull
protected List<AdjacencyResult> resolveAdjacency(final BigInteger remoteDpnId, final long vpnId, final VrfEntry vrfEntry, String rd) {
    List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
    FibHelper.sortIpAddress(routePaths);
    List<AdjacencyResult> adjacencyList = new ArrayList<>();
    List<String> prefixIpList;
    LOG.trace("resolveAdjacency called with remotedDpnId {}, vpnId{}, VrfEntry {}", remoteDpnId, vpnId, vrfEntry);
    try {
        if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
            List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
            List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, fibUtil.getVpnNameFromId(vpnId), usedRds, vrfEntry.getDestPrefix());
            if (vpnExtraRoutes.isEmpty()) {
                Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
                // We don't want to provide an adjacencyList for an extra-route-prefix.
                if (prefixInfo == null) {
                    LOG.debug("The extra route {} in rd {} for vpn {} has been removed from all the next hops", vrfEntry.getDestPrefix(), rd, vpnId);
                    return adjacencyList;
                }
                prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
            } else {
                List<String> prefixIpListLocal = new ArrayList<>();
                vpnExtraRoutes.stream().forEach(route -> {
                    route.getNexthopIpList().stream().forEach(extraRouteIp -> {
                        String ipPrefix;
                        if (isIpv4Address(extraRouteIp)) {
                            ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
                        } else {
                            ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
                        }
                        prefixIpListLocal.add(ipPrefix);
                    });
                });
                prefixIpList = prefixIpListLocal;
            }
        } else {
            prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
        }
        for (String prefixIp : prefixIpList) {
            if (routePaths == null || routePaths.isEmpty()) {
                LOG.trace("Processing Destination IP {} without NextHop IP", prefixIp);
                AdjacencyResult adjacencyResult = nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, null);
                addAdjacencyResultToList(adjacencyList, adjacencyResult);
                continue;
            }
            adjacencyList.addAll(routePaths.stream().map(routePath -> {
                LOG.debug("NextHop IP for destination {} is {}", prefixIp, routePath.getNexthopAddress());
                return nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, routePath.getNexthopAddress());
            }).filter(adjacencyResult -> adjacencyResult != null && !adjacencyList.contains(adjacencyResult)).distinct().collect(toList()));
        }
    } catch (NullPointerException e) {
        LOG.trace("", e);
    }
    return adjacencyList;
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) VpnToExtraroutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnToExtraroutes) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) InetAddress(java.net.InetAddress) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.Vpn) Optional(com.google.common.base.Optional) BigInteger(java.math.BigInteger) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) VpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.VpnKey) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) List(java.util.List) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) TunnelTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) ActionMoveSourceDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp) NWUtil.isIpv4Address(org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) ActionSetIcmpType(org.opendaylight.genius.mdsalutil.actions.ActionSetIcmpType) ExtraRoutesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutesKey) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) ExtraRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutes) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) RoutesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.RoutesKey) Nonnull(javax.annotation.Nonnull) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) MatchIpProtocol(org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol) Logger(org.slf4j.Logger) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) ActionMoveSourceDestinationEth(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth) Collectors.toList(java.util.stream.Collectors.toList) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) ExtraRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) Nonnull(javax.annotation.Nonnull)

Aggregations

RoutePaths (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths)16 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)9 ArrayList (java.util.ArrayList)7 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)7 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)6 BigInteger (java.math.BigInteger)5 Optional (com.google.common.base.Optional)4 Collections (java.util.Collections)4 List (java.util.List)4 Inject (javax.inject.Inject)4 Singleton (javax.inject.Singleton)4 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)4 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)4 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)4 VpnExtraRouteHelper (org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper)4 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)4 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)4