DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ankur Dwivedi <adwivedi@marvell.com>
To: <dev@dpdk.org>
Cc: <jerinj@marvell.com>, <vladimir.medvedkin@intel.com>,
	<ndabilpuram@marvell.com>, <pbhagavatula@marvell.com>,
	<skori@marvell.com>, <rkudurumalla@marvell.com>,
	<nsaxena@marvell.com>, Ankur Dwivedi <adwivedi@marvell.com>
Subject: [PATCH v2 02/13] node: add IP4 lookup FIB node
Date: Fri, 9 May 2025 12:14:37 +0530	[thread overview]
Message-ID: <20250509064448.724019-3-adwivedi@marvell.com> (raw)
In-Reply-To: <20250509064448.724019-1-adwivedi@marvell.com>

Adds a lookup FIB node for IP4.
Adds a public function to do fib configuration from application.

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
---
 lib/node/ip4_lookup_fib.c   | 141 ++++++++++++++++++++++++++++++++++++
 lib/node/meson.build        |   3 +-
 lib/node/rte_node_ip4_api.h |  15 ++++
 3 files changed, 158 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..977d97b713
--- /dev/null
+++ b/lib/node/ip4_lookup_fib.c
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2025 Marvell.
+ */
+
+#include <eal_export.h>
+#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_DEFAULT_MAX_ROUTES (UINT16_MAX)
+#define FIB_DEFAULT_NUM_TBL8   (UINT16_MAX / 2)
+#define FIB_DEFAULT_NH (RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP << 16)
+
+#define IP4_LOOKUP_NODE_FIB(ctx) \
+	(((struct ip4_lookup_fib_node_ctx *)ctx)->fib)
+
+#define IP4_LOOKUP_FIB_NODE_PRIV1_OFF(ctx) \
+	(((struct ip4_lookup_fib_node_ctx *)ctx)->mbuf_priv1_off)
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_node_ip4_fib_create, 25.07)
+int
+rte_node_ip4_fib_create(int socket, struct rte_fib_conf *conf)
+{
+	struct ip4_lookup_fib_node_main *nm = &ip4_lookup_fib_nm;
+	char s[RTE_FIB_NAMESIZE];
+
+	/* One fib per socket */
+	if (nm->fib[socket])
+		return 0;
+
+	conf->default_nh = FIB_DEFAULT_NH;
+	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
+setup_fib(int socket)
+{
+	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;
+	conf.max_routes = FIB_DEFAULT_MAX_ROUTES;
+	conf.rib_ext_sz = 0;
+	conf.dir24_8.nh_sz = RTE_FIB_DIR24_8_4B;
+	conf.dir24_8.num_tbl8 = FIB_DEFAULT_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;
+	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;
+
+		init_once = 1;
+	}
+
+	rc = setup_fib(graph->socket);
+	if (rc) {
+		node_err("ip4_lookup_fib", "Failed to setup fib for sock %u, rc=%d",
+				graph->socket, rc);
+		return rc;
+	}
+
+	/* 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_FIB_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']
diff --git a/lib/node/rte_node_ip4_api.h b/lib/node/rte_node_ip4_api.h
index 950751a525..1dac7a4936 100644
--- a/lib/node/rte_node_ip4_api.h
+++ b/lib/node/rte_node_ip4_api.h
@@ -18,6 +18,7 @@
 #include <rte_common.h>
 #include <rte_compat.h>
 
+#include <rte_fib.h>
 #include <rte_graph.h>
 
 #ifdef __cplusplus
@@ -117,6 +118,20 @@ int rte_node_ip4_rewrite_add(uint16_t next_hop, uint8_t *rewrite_data,
 __rte_experimental
 int rte_node_ip4_reassembly_configure(struct rte_node_ip4_reassembly_cfg *cfg, uint16_t cnt);
 
+/**
+ * Create ipv4 FIB.
+ *
+ * @param socket
+ *   NUMA socket for FIB memory allocation.
+ * @param conf
+ *   Structure containing FIB configuration.
+ *
+ * @return
+ *   0 on success, negative otherwise.
+ */
+__rte_experimental
+int rte_node_ip4_fib_create(int socket, struct rte_fib_conf *conf);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.25.1


  parent reply	other threads:[~2025-05-09  6:45 UTC|newest]

Thread overview: 36+ 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
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-19 18:14       ` Vladimir Medvedkin
2025-04-23  9:46         ` 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
2025-05-09  6:44 ` [PATCH v2 00/13] add lookup fib nodes in graph library Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 01/13] fib: move macro to header file Ankur Dwivedi
2025-05-09  6:44   ` Ankur Dwivedi [this message]
2025-05-09  6:44   ` [PATCH v2 03/13] node: add IP4 FIB route add Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 04/13] node: add process callback for IP4 FIB Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 05/13] node: move next nodes to public header file Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 06/13] node: add next node in packet classification Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 07/13] app/graph: add IP4 lookup mode command Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 08/13] fib: move macro to header file Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 09/13] node: add IP6 lookup FIB node Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 10/13] node: add IP6 FIB route add Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 11/13] node: add process callback for IP6 FIB Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 12/13] node: add next node in packet classification Ankur Dwivedi
2025-05-09  6:44   ` [PATCH v2 13/13] 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=20250509064448.724019-3-adwivedi@marvell.com \
    --to=adwivedi@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=nsaxena@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).