From: Nitin Saxena <nsaxena16@gmail.com>
To: Ankur Dwivedi <adwivedi@marvell.com>
Cc: dev@dpdk.org, jerinj@marvell.com, vladimir.medvedkin@intel.com,
ndabilpuram@marvell.com, pbhagavatula@marvell.com,
skori@marvell.com, rkudurumalla@marvell.com
Subject: Re: [PATCH v1 02/12] node: add IP4 lookup FIB node
Date: Wed, 16 Apr 2025 13:02:11 +0530 [thread overview]
Message-ID: <CAG6-93x0TTnbE9sR81W4xRMmT1TPSG25OUK80ftEYf_65KqDJg@mail.gmail.com> (raw)
In-Reply-To: <20250415121052.1497155-3-adwivedi@marvell.com>
Hi Ankur,
Please see my comments inline below
Thanks,
Nitin
On Tue, Apr 15, 2025 at 5:41 PM Ankur Dwivedi <adwivedi@marvell.com> wrote:
>
> Adds a lookup FIB node for IP4.
>
> Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
> ---
> lib/node/ip4_lookup_fib.c | 127 ++++++++++++++++++++++++++++++++++++++
> lib/node/meson.build | 3 +-
> 2 files changed, 129 insertions(+), 1 deletion(-)
> create mode 100644 lib/node/ip4_lookup_fib.c
>
> diff --git a/lib/node/ip4_lookup_fib.c b/lib/node/ip4_lookup_fib.c
> new file mode 100644
> index 0000000000..9c71610718
> --- /dev/null
> +++ b/lib/node/ip4_lookup_fib.c
> @@ -0,0 +1,127 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(C) 2025 Marvell.
> + */
> +
> +#include <rte_errno.h>
> +#include <rte_ether.h>
> +#include <rte_fib.h>
> +#include <rte_graph.h>
> +#include <rte_graph_worker.h>
> +#include <rte_ip.h>
> +
> +#include "rte_node_ip4_api.h"
> +
> +#include "node_private.h"
> +
> +/* IP4 Lookup global data struct */
> +struct ip4_lookup_fib_node_main {
> + struct rte_fib *fib[RTE_MAX_NUMA_NODES];
> +};
> +
> +struct ip4_lookup_fib_node_ctx {
> + /* Socket's FIB */
> + struct rte_fib *fib;
> + /* Dynamic offset to mbuf priv1 */
> + int mbuf_priv1_off;
> +};
> +
> +static struct ip4_lookup_fib_node_main ip4_lookup_fib_nm;
> +
> +#define FIB_MAX_ROUTES (1 << 16)
> +#define FIB_NUM_TBL8 (1 << 15)
> +#define FIB_DEFAULT_NH 999
These macros may not be required if we expose public setup_api() with
arguments. See below
> +
> +#define IP4_LOOKUP_NODE_FIB(ctx) \
> + (((struct ip4_lookup_fib_node_ctx *)ctx)->fib)
> +
> +#define IP4_LOOKUP_NODE_PRIV1_OFF(ctx) \
> + (((struct ip4_lookup_fib_node_ctx *)ctx)->mbuf_priv1_off)
> +
> +static int
> +setup_fib(unsigned int socket)
Should we add public API to allow applications to control MAX_ROUTES?
In a typical stack multiple fibs can be set up for each VRF (~~ port_id).
A public API:
int rte_ip4_lookup_fib_setup(int fib_index, int port_id, uint32_t
max_routes) where
For now we can assume fib_index == 0, is global fib table (can be
extended to VRF later). Socket_id can be determined from port_Id
> +{
> + struct ip4_lookup_fib_node_main *nm = &ip4_lookup_fib_nm;
> + struct rte_fib_conf conf;
> + char s[RTE_FIB_NAMESIZE];
> +
> + /* One fib per socket */
> + if (nm->fib[socket])
> + return 0;
> +
> + conf.type = RTE_FIB_DIR24_8;
> + conf.default_nh = FIB_DEFAULT_NH;
FIB_DEFAULT_NH can be defined in such a way, fast path can decode
next_edge from return of rte_fib_lookup_bulk()
Like
union {
struct u64;
struct {
uint32_t next_hop_id;
uint16_t next_edge;
uint16_t. reserved;
};
} rte_ip4_lookup_fib_nexthop_t;
FIB_DEFAULT_NH should be set as
rte_ip4_lookup_fib_nexthop_t default_next_hop = {.next_edge =
IP4_FIB_LOOKUP_NEXT_DROP}
This way in fast path a return from fib_bulk() can be directly used to
send packet to pkt_drop node
> + conf.max_routes = FIB_MAX_ROUTES;
> + conf.rib_ext_sz = 0;
> + conf.dir24_8.nh_sz = RTE_FIB_DIR24_8_4B;
> + conf.dir24_8.num_tbl8 = FIB_NUM_TBL8;
> + conf.flags = 0;
> + snprintf(s, sizeof(s), "IPV4_LOOKUP_FIB_%d", socket);
> + nm->fib[socket] = rte_fib_create(s, socket, &conf);
> + if (nm->fib[socket] == NULL)
> + return -rte_errno;
> +
> + return 0;
> +}
> +
> +static int
> +ip4_lookup_fib_node_init(const struct rte_graph *graph, struct rte_node *node)
> +{
> + static uint8_t init_once;
> + unsigned int socket;
> + uint16_t lcore_id;
> + int rc;
> +
> + RTE_BUILD_BUG_ON(sizeof(struct ip4_lookup_fib_node_ctx) > RTE_NODE_CTX_SZ);
> +
> + if (!init_once) {
> + node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
> + &node_mbuf_priv1_dynfield_desc);
> + if (node_mbuf_priv1_dynfield_offset < 0)
> + return -rte_errno;
You may need to rebase this patch on top of
https://patches.dpdk.org/project/dpdk/patch/20250409135554.2180390-2-nsaxena@marvell.com/
for using global mbuf field
> +
> + /* Setup FIB for all sockets */
> + RTE_LCORE_FOREACH(lcore_id)
Instead can be use rte_socket_count() which allow to loop for socket
instead of port? Ideally we may need to add fib for virtual interfaces
or VRF (later)
> + {
> + socket = rte_lcore_to_socket_id(lcore_id);
> + rc = setup_fib(socket);
> + if (rc) {
> + node_err("ip4_lookup_fib",
> + "Failed to setup fib for sock %u, rc=%d",
> + socket, rc);
> + return rc;
> + }
> + }
> + init_once = 1;
> + }
> +
> + /* Update socket's FIB and mbuf dyn priv1 offset in node ctx */
> + IP4_LOOKUP_NODE_FIB(node->ctx) = ip4_lookup_fib_nm.fib[graph->socket];
> + IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;
> +
> + node_dbg("ip4_lookup_fib", "Initialized ip4_lookup_fib node");
> +
> + return 0;
> +}
> +
> +static struct rte_node_xstats ip4_lookup_fib_xstats = {
> + .nb_xstats = 1,
> + .xstat_desc = {
> + [0] = "ip4_lookup_fib_error",
> + },
> +};
> +
> +static struct rte_node_register ip4_lookup_fib_node = {
> + .name = "ip4_lookup_fib",
> +
> + .init = ip4_lookup_fib_node_init,
> + .xstats = &ip4_lookup_fib_xstats,
> +
> + .nb_edges = RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP + 1,
> + .next_nodes = {
> + [RTE_NODE_IP4_LOOKUP_NEXT_IP4_LOCAL] = "ip4_local",
> + [RTE_NODE_IP4_LOOKUP_NEXT_REWRITE] = "ip4_rewrite",
> + [RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP] = "pkt_drop",
> + },
> +};
> +
> +RTE_NODE_REGISTER(ip4_lookup_fib_node);
> diff --git a/lib/node/meson.build b/lib/node/meson.build
> index 0bed97a96c..d2011c8f56 100644
> --- a/lib/node/meson.build
> +++ b/lib/node/meson.build
> @@ -13,6 +13,7 @@ sources = files(
> 'ethdev_tx.c',
> 'ip4_local.c',
> 'ip4_lookup.c',
> + 'ip4_lookup_fib.c',
> 'ip4_reassembly.c',
> 'ip4_rewrite.c',
> 'ip6_lookup.c',
> @@ -34,4 +35,4 @@ headers = files(
>
> # Strict-aliasing rules are violated by uint8_t[] to context size casts.
> cflags += '-fno-strict-aliasing'
> -deps += ['graph', 'mbuf', 'lpm', 'ethdev', 'mempool', 'cryptodev', 'ip_frag']
> +deps += ['graph', 'mbuf', 'lpm', 'ethdev', 'mempool', 'cryptodev', 'ip_frag', 'fib']
> --
> 2.25.1
>
next prev parent reply other threads:[~2025-04-16 7:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-15 12:10 [PATCH v1 00/12] add lookup fib nodes in graph library Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 01/12] fib: move macro to header file Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 02/12] node: add IP4 lookup FIB node Ankur Dwivedi
2025-04-16 7:32 ` Nitin Saxena [this message]
2025-04-16 10:26 ` [EXTERNAL] " Ankur Dwivedi
2025-04-16 9:34 ` Medvedkin, Vladimir
2025-04-16 10:07 ` [EXTERNAL] " Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 03/12] node: add IP4 FIB route add Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 04/12] node: add process callback for IP4 FIB Ankur Dwivedi
2025-04-16 7:54 ` Nitin Saxena
2025-04-16 12:54 ` Medvedkin, Vladimir
2025-04-18 7:38 ` [EXTERNAL] " Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 05/12] node: add next node in packet classification Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 06/12] app/graph: add IP4 lookup mode command Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 07/12] fib: move macro to header file Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 08/12] node: add IP6 lookup FIB node Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 09/12] node: add IP6 FIB route add Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 10/12] node: add process callback for IP6 FIB Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 11/12] node: add next node in packet classification Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 12/12] app/graph: add IP6 lookup mode command Ankur Dwivedi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAG6-93x0TTnbE9sR81W4xRMmT1TPSG25OUK80ftEYf_65KqDJg@mail.gmail.com \
--to=nsaxena16@gmail.com \
--cc=adwivedi@marvell.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=ndabilpuram@marvell.com \
--cc=pbhagavatula@marvell.com \
--cc=rkudurumalla@marvell.com \
--cc=skori@marvell.com \
--cc=vladimir.medvedkin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).