DPDK patches and discussions
 help / color / mirror / Atom feed
From: Medvedkin Vladimir <medvedkinv@gmail.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, thomas@monjalon.net,
	cristian.dumitrescu@intel.com,
	Medvedkin Vladimir <medvedkinv@gmail.com>
Subject: [dpdk-dev] [PATCH v4 4/4] Add support for lpm and rib bulk lookup
Date: Fri, 27 Apr 2018 01:03:34 +0300	[thread overview]
Message-ID: <1524780214-23196-5-git-send-email-medvedkinv@gmail.com> (raw)
In-Reply-To: <1524780214-23196-1-git-send-email-medvedkinv@gmail.com>

Signed-off-by: Medvedkin Vladimir <medvedkinv@gmail.com>
---
 examples/l3fwd/l3fwd_lpm.c | 132 +++++++++++++++++++++++++++++++++++++++++++++
 examples/l3fwd/meson.build |   2 +-
 2 files changed, 133 insertions(+), 1 deletion(-)

diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index a747126..9ad1ddc 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -24,9 +24,12 @@
 #include <rte_tcp.h>
 #include <rte_udp.h>
 #include <rte_lpm.h>
+#include <rte_rib.h>
 #include <rte_lpm6.h>
 
 #include "l3fwd.h"
+#define BULK_LOOKUP
+#define USE_RIB
 
 struct ipv4_l3fwd_lpm_route {
 	uint32_t ip;
@@ -72,7 +75,11 @@ struct ipv6_l3fwd_lpm_route {
 #define IPV6_L3FWD_LPM_MAX_RULES         1024
 #define IPV6_L3FWD_LPM_NUMBER_TBL8S (1 << 16)
 
+#if  defined(BULK_LOOKUP) && defined(USE_RIB)
+struct rte_rib *ipv4_l3fwd_lpm_lookup_struct[NB_SOCKETS];
+#else
 struct rte_lpm *ipv4_l3fwd_lpm_lookup_struct[NB_SOCKETS];
+#endif
 struct rte_lpm6 *ipv6_l3fwd_lpm_lookup_struct[NB_SOCKETS];
 
 static inline uint16_t
@@ -168,6 +175,104 @@ struct ipv6_l3fwd_lpm_route {
 #include "l3fwd_lpm.h"
 #endif
 
+static __rte_always_inline int
+l3fwd_rib_handle_pkt(struct rte_mbuf *m, uint32_t *dst_ip)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+		/* Handle IPv4 headers.*/
+		ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
+				sizeof(struct ether_hdr));
+#ifdef DO_RFC_1812_CHECKS
+		/* Check to make sure the packet is valid (RFC1812) */
+		if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0)
+			return -1;
+		/* Update time to live and header checksum */
+		--(ipv4_hdr->time_to_live);
+		++(ipv4_hdr->hdr_checksum);
+#endif
+		*dst_ip = rte_be_to_cpu_32(ipv4_hdr->dst_addr);
+	} else
+		return -1;
+
+	return 0;
+}
+
+static inline void
+l3fwd_rib_send_packets(int nb_rx, struct rte_mbuf **pkts_burst,
+			uint16_t portid, struct lcore_conf *qconf)
+{
+	struct rte_mbuf *send_pkts[MAX_PKT_BURST];
+#ifdef USE_RIB
+	uint64_t next_hops[MAX_PKT_BURST];
+#else
+	uint32_t next_hops[MAX_PKT_BURST];
+#endif
+	uint32_t dst_ips[MAX_PKT_BURST];
+#ifdef USE_RIB
+	struct rte_rib *rib = qconf->ipv4_lookup_struct;
+#else
+	struct rte_lpm *rib = qconf->ipv4_lookup_struct;
+#endif
+	struct ether_hdr *eth_hdr;
+        int32_t j, k = 0;
+	int ret;
+	uint16_t dst_port;
+
+	for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)
+		rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));
+
+	for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
+		rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
+			j + PREFETCH_OFFSET], void *));
+
+		ret = l3fwd_rib_handle_pkt(pkts_burst[j], &dst_ips[k]);
+		if (ret != 0) {
+			rte_pktmbuf_free(pkts_burst[j]);
+			continue;
+		}
+		send_pkts[k++] = pkts_burst[j];
+        }
+
+        for (; j < nb_rx; j++) {
+		ret = l3fwd_rib_handle_pkt(pkts_burst[j], &dst_ips[k]);
+		if (ret != 0) {
+			rte_pktmbuf_free(pkts_burst[j]);
+			continue;
+		}
+		send_pkts[k++] = pkts_burst[j];
+	}
+
+#ifdef USE_RIB
+	ret = rte_rib_fib_lookup_bulk(rib, dst_ips, next_hops, k);
+#else
+	ret = rte_lpm_lookup_bulk(rib, dst_ips, next_hops, k);
+#endif
+	if (ret != 0) {
+		for (j = 0; j < k; j++)
+			rte_pktmbuf_free(send_pkts[j]);
+	} else {
+		for (j = 0; j < k; j++) {
+#ifdef USE_RIB
+			dst_port = next_hops[j];
+#else
+			dst_port = next_hops[j] & 0x00FFFFFF;
+#endif
+			if (dst_port >= RTE_MAX_ETHPORTS ||
+				(enabled_port_mask & 1 << dst_port) == 0) {
+				dst_port = portid;
+			}
+			eth_hdr = rte_pktmbuf_mtod(send_pkts[j], struct ether_hdr *);
+			/* dst addr */
+			*(uint64_t *)&eth_hdr->d_addr = dest_eth_addr[dst_port];
+			/* src addr */
+			ether_addr_copy(&ports_eth_addr[dst_port], &eth_hdr->s_addr);
+			send_single_packet(qconf, send_pkts[j], dst_port);
+		}
+	}
+}
+
 /* main processing loop */
 int
 lpm_main_loop(__attribute__((unused)) void *dummy)
@@ -237,6 +342,10 @@ struct ipv6_l3fwd_lpm_route {
 			if (nb_rx == 0)
 				continue;
 
+#if defined(BULK_LOOKUP)
+			l3fwd_rib_send_packets(nb_rx, pkts_burst,
+						portid, qconf);
+#else
 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON \
 			 || defined RTE_ARCH_PPC_64
 			l3fwd_lpm_send_packets(nb_rx, pkts_burst,
@@ -245,6 +354,7 @@ struct ipv6_l3fwd_lpm_route {
 			l3fwd_lpm_no_opt_send_packets(nb_rx, pkts_burst,
 							portid, qconf);
 #endif /* X86 */
+#endif /* BULK_LOOKUP*/
 		}
 	}
 
@@ -255,18 +365,36 @@ struct ipv6_l3fwd_lpm_route {
 setup_lpm(const int socketid)
 {
 	struct rte_lpm6_config config;
+#if defined(BULK_LOOKUP) && defined(USE_RIB)
+	struct rte_rib_conf config_ipv4;
+#else
 	struct rte_lpm_config config_ipv4;
+#endif
 	unsigned i;
 	int ret;
 	char s[64];
 
 	/* create the LPM table */
+#if defined(BULK_LOOKUP) && defined(USE_RIB)
+	config_ipv4.type = RTE_RIB_DIR24_8;
+	config_ipv4.max_nodes = IPV4_L3FWD_LPM_MAX_RULES;
+	config_ipv4.node_sz = sizeof(struct rte_rib_node);
+	config_ipv4.fib_conf.dir24_8.def_nh = 0;
+	config_ipv4.fib_conf.dir24_8.nh_sz = RTE_DIR24_8_4B;
+	config_ipv4.fib_conf.dir24_8.num_tbl8 = IPV4_L3FWD_LPM_NUMBER_TBL8S;
+#else
 	config_ipv4.max_rules = IPV4_L3FWD_LPM_MAX_RULES;
 	config_ipv4.number_tbl8s = IPV4_L3FWD_LPM_NUMBER_TBL8S;
 	config_ipv4.flags = 0;
+#endif
 	snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
+
 	ipv4_l3fwd_lpm_lookup_struct[socketid] =
+#if defined(BULK_LOOKUP) && defined(USE_RIB)
+			rte_rib_create(s, socketid, &config_ipv4);
+#else
 			rte_lpm_create(s, socketid, &config_ipv4);
+#endif
 	if (ipv4_l3fwd_lpm_lookup_struct[socketid] == NULL)
 		rte_exit(EXIT_FAILURE,
 			"Unable to create the l3fwd LPM table on socket %d\n",
@@ -280,7 +408,11 @@ struct ipv6_l3fwd_lpm_route {
 				enabled_port_mask) == 0)
 			continue;
 
+#if defined(BULK_LOOKUP) && defined(USE_RIB)
+		ret = rte_rib_add(ipv4_l3fwd_lpm_lookup_struct[socketid],
+#else
 		ret = rte_lpm_add(ipv4_l3fwd_lpm_lookup_struct[socketid],
+#endif
 			ipv4_l3fwd_lpm_route_array[i].ip,
 			ipv4_l3fwd_lpm_route_array[i].depth,
 			ipv4_l3fwd_lpm_route_array[i].if_out);
diff --git a/examples/l3fwd/meson.build b/examples/l3fwd/meson.build
index cbef07f..f742fb1 100644
--- a/examples/l3fwd/meson.build
+++ b/examples/l3fwd/meson.build
@@ -6,7 +6,7 @@
 # To build this example as a standalone application with an already-installed
 # DPDK instance, use 'make'
 
-deps += ['hash', 'lpm']
+deps += ['hash', 'lpm', 'rib']
 allow_experimental_apis = true
 sources = files(
 	'l3fwd_em.c', 'l3fwd_lpm.c', 'main.c'
-- 
1.8.3.1

  parent reply	other threads:[~2018-04-26 22:03 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 22:03 [dpdk-dev] [PATCH v4 0/4] lib/rib: Add Routing Information Base library Medvedkin Vladimir
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 1/4] Add RIB library Medvedkin Vladimir
2018-04-26 22:17   ` Stephen Hemminger
2018-04-26 22:18   ` Stephen Hemminger
2018-04-26 22:19   ` Stephen Hemminger
2018-04-26 22:19   ` Stephen Hemminger
2018-04-26 22:20   ` Stephen Hemminger
2018-04-27  6:45     ` Vladimir Medvedkin
2018-06-29 13:54   ` Bruce Richardson
2018-06-29 14:02   ` Bruce Richardson
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 2/4] Add dir24_8 implementation for rib library Medvedkin Vladimir
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 3/4] Add autotests for RIB library Medvedkin Vladimir
2018-06-29 14:13   ` Bruce Richardson
2018-06-29 15:07   ` Bruce Richardson
2018-06-29 15:31   ` Bruce Richardson
2018-04-26 22:03 ` Medvedkin Vladimir [this message]
2018-04-26 22:24 ` [dpdk-dev] [PATCH v4 0/4] lib/rib: Add Routing Information Base library Stephen Hemminger
2018-04-26 22:27   ` Thomas Monjalon
2018-04-26 22:42     ` Stephen Hemminger
2018-04-26 22:49     ` Stephen Hemminger
2018-04-27  8:27   ` Vladimir Medvedkin
2018-06-29 15:48 ` Bruce Richardson
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 00/12] lib: add RIB and FIB liraries Vladimir Medvedkin
2019-09-12  7:37   ` Morten Brørup
2019-09-12  9:47     ` Medvedkin, Vladimir
2019-09-12 12:00       ` Morten Brørup
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 " Vladimir Medvedkin
2019-11-05 23:14     ` Thomas Monjalon
2019-11-06  5:50       ` David Marchand
2019-11-06  7:50         ` Thomas Monjalon
2019-11-06 11:53           ` Medvedkin, Vladimir
2019-11-06 11:59             ` Thomas Monjalon
2019-11-06 14:37               ` Aaron Conole
2019-11-06 11:50         ` Medvedkin, Vladimir
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 01/12] rib: add RIB library Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 02/12] test/rib: add RIB library autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 03/12] rib: add ipv6 support for RIB Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 04/12] test/rib: add ipv6 support for RIB autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 05/12] fib: add FIB library Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 06/12] fib: add FIB ipv6 support Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 07/12] fib: add DIR24-8 dataplane algorithm Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 08/12] fib: add dataplane algorithm for ipv6 Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 09/12] test/fib: add FIB library autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 10/12] test/fib: add ipv6 support for FIB autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 11/12] test/fib: add FIB library performance autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 12/12] test/fib: add FIB library ipv6 " Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 01/12] rib: add RIB library Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 02/12] test/rib: add RIB library autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 03/12] rib: add ipv6 support for RIB Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 04/12] test/rib: add ipv6 support for RIB autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 05/12] fib: add FIB library Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 06/12] fib: add FIB ipv6 support Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 07/12] fib: add DIR24-8 dataplane algorithm Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 08/12] fib: add dataplane algorithm for ipv6 Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 09/12] test/fib: add FIB library autotests Vladimir Medvedkin
2019-09-12 14:07   ` Aaron Conole
2019-10-01 17:12     ` Medvedkin, Vladimir
2019-10-24 15:55       ` Thomas Monjalon
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 10/12] test/fib: add ipv6 support for FIB autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 11/12] test/fib: add FIB library performance autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 12/12] test/fib: add FIB library ipv6 " Vladimir Medvedkin

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=1524780214-23196-5-git-send-email-medvedkinv@gmail.com \
    --to=medvedkinv@gmail.com \
    --cc=bruce.richardson@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /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).