1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <sys/queue.h>
16 #include <netinet/in.h>
18 #include <rte_debug.h>
19 #include <rte_ether.h>
20 #include <rte_ethdev.h>
21 #include <rte_mempool.h>
22 #include <rte_cycles.h>
31 #if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32)
36 #include <rte_hash_crc.h>
37 #define DEFAULT_HASH_FUNC rte_hash_crc
39 #include <rte_jhash.h>
40 #define DEFAULT_HASH_FUNC rte_jhash
43 #define IPV6_ADDR_LEN 16
51 } __attribute__((__packed__));
53 union ipv4_5tuple_host {
66 #define XMM_NUM_IN_IPV6_5TUPLE 3
69 uint8_t ip_dst[IPV6_ADDR_LEN];
70 uint8_t ip_src[IPV6_ADDR_LEN];
74 } __attribute__((__packed__));
76 union ipv6_5tuple_host {
81 uint8_t ip_src[IPV6_ADDR_LEN];
82 uint8_t ip_dst[IPV6_ADDR_LEN];
87 xmm_t xmm[XMM_NUM_IN_IPV6_5TUPLE];
92 struct ipv4_l3fwd_em_route {
93 struct ipv4_5tuple key;
97 struct ipv6_l3fwd_em_route {
98 struct ipv6_5tuple key;
102 static struct ipv4_l3fwd_em_route ipv4_l3fwd_em_route_array[] = {
103 {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 101, 11, IPPROTO_TCP}, 0},
104 {{IPv4(201, 0, 0, 0), IPv4(200, 20, 0, 1), 102, 12, IPPROTO_TCP}, 1},
105 {{IPv4(111, 0, 0, 0), IPv4(100, 30, 0, 1), 101, 11, IPPROTO_TCP}, 2},
106 {{IPv4(211, 0, 0, 0), IPv4(200, 40, 0, 1), 102, 12, IPPROTO_TCP}, 3},
109 static struct ipv6_l3fwd_em_route ipv6_l3fwd_em_route_array[] = {
111 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
112 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
113 101, 11, IPPROTO_TCP}, 0},
116 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
117 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
118 102, 12, IPPROTO_TCP}, 1},
121 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
122 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
123 101, 11, IPPROTO_TCP}, 2},
126 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
127 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
128 102, 12, IPPROTO_TCP}, 3},
131 struct rte_hash *ipv4_l3fwd_em_lookup_struct[NB_SOCKETS];
132 struct rte_hash *ipv6_l3fwd_em_lookup_struct[NB_SOCKETS];
134 static inline uint32_t
135 ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len,
138 const union ipv4_5tuple_host *k;
144 p = (const uint32_t *)&k->port_src;
147 init_val = rte_hash_crc_4byte(t, init_val);
148 init_val = rte_hash_crc_4byte(k->ip_src, init_val);
149 init_val = rte_hash_crc_4byte(k->ip_dst, init_val);
150 init_val = rte_hash_crc_4byte(*p, init_val);
152 init_val = rte_jhash_1word(t, init_val);
153 init_val = rte_jhash_1word(k->ip_src, init_val);
154 init_val = rte_jhash_1word(k->ip_dst, init_val);
155 init_val = rte_jhash_1word(*p, init_val);
161 static inline uint32_t
162 ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
165 const union ipv6_5tuple_host *k;
169 const uint32_t *ip_src0, *ip_src1, *ip_src2, *ip_src3;
170 const uint32_t *ip_dst0, *ip_dst1, *ip_dst2, *ip_dst3;
175 p = (const uint32_t *)&k->port_src;
178 ip_src0 = (const uint32_t *) k->ip_src;
179 ip_src1 = (const uint32_t *)(k->ip_src+4);
180 ip_src2 = (const uint32_t *)(k->ip_src+8);
181 ip_src3 = (const uint32_t *)(k->ip_src+12);
182 ip_dst0 = (const uint32_t *) k->ip_dst;
183 ip_dst1 = (const uint32_t *)(k->ip_dst+4);
184 ip_dst2 = (const uint32_t *)(k->ip_dst+8);
185 ip_dst3 = (const uint32_t *)(k->ip_dst+12);
186 init_val = rte_hash_crc_4byte(t, init_val);
187 init_val = rte_hash_crc_4byte(*ip_src0, init_val);
188 init_val = rte_hash_crc_4byte(*ip_src1, init_val);
189 init_val = rte_hash_crc_4byte(*ip_src2, init_val);
190 init_val = rte_hash_crc_4byte(*ip_src3, init_val);
191 init_val = rte_hash_crc_4byte(*ip_dst0, init_val);
192 init_val = rte_hash_crc_4byte(*ip_dst1, init_val);
193 init_val = rte_hash_crc_4byte(*ip_dst2, init_val);
194 init_val = rte_hash_crc_4byte(*ip_dst3, init_val);
195 init_val = rte_hash_crc_4byte(*p, init_val);
197 init_val = rte_jhash_1word(t, init_val);
198 init_val = rte_jhash(k->ip_src,
199 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
200 init_val = rte_jhash(k->ip_dst,
201 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
202 init_val = rte_jhash_1word(*p, init_val);
207 #define IPV4_L3FWD_EM_NUM_ROUTES \
208 (sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
210 #define IPV6_L3FWD_EM_NUM_ROUTES \
211 (sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
213 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
214 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
216 static rte_xmm_t mask0;
217 static rte_xmm_t mask1;
218 static rte_xmm_t mask2;
220 #if defined(RTE_MACHINE_CPUFLAG_SSE2)
222 em_mask_key(void *key, xmm_t mask)
224 __m128i data = _mm_loadu_si128((__m128i *)(key));
226 return _mm_and_si128(data, mask);
228 #elif defined(RTE_MACHINE_CPUFLAG_NEON)
230 em_mask_key(void *key, xmm_t mask)
232 int32x4_t data = vld1q_s32((int32_t *)key);
234 return vandq_s32(data, mask);
236 #elif defined(RTE_MACHINE_CPUFLAG_ALTIVEC)
238 em_mask_key(void *key, xmm_t mask)
240 xmm_t data = vec_ld(0, (xmm_t *)(key));
242 return vec_and(data, mask);
245 #error No vector engine (SSE, NEON, ALTIVEC) available, check your toolchain
248 static inline uint16_t
249 em_get_ipv4_dst_port(void *ipv4_hdr, uint16_t portid, void *lookup_struct)
252 union ipv4_5tuple_host key;
253 struct rte_hash *ipv4_l3fwd_lookup_struct =
254 (struct rte_hash *)lookup_struct;
256 ipv4_hdr = (uint8_t *)ipv4_hdr + offsetof(struct ipv4_hdr, time_to_live);
259 * Get 5 tuple: dst port, src port, dst IP address,
260 * src IP address and protocol.
262 key.xmm = em_mask_key(ipv4_hdr, mask0.x);
264 /* Find destination port */
265 ret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);
266 return (ret < 0) ? portid : ipv4_l3fwd_out_if[ret];
269 static inline uint16_t
270 em_get_ipv6_dst_port(void *ipv6_hdr, uint16_t portid, void *lookup_struct)
273 union ipv6_5tuple_host key;
274 struct rte_hash *ipv6_l3fwd_lookup_struct =
275 (struct rte_hash *)lookup_struct;
277 ipv6_hdr = (uint8_t *)ipv6_hdr + offsetof(struct ipv6_hdr, payload_len);
278 void *data0 = ipv6_hdr;
279 void *data1 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t);
280 void *data2 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t) + sizeof(xmm_t);
282 /* Get part of 5 tuple: src IP address lower 96 bits and protocol */
283 key.xmm[0] = em_mask_key(data0, mask1.x);
286 * Get part of 5 tuple: dst IP address lower 96 bits
287 * and src IP address higher 32 bits.
289 key.xmm[1] = *(xmm_t *)data1;
292 * Get part of 5 tuple: dst port and src port
293 * and dst IP address higher 32 bits.
295 key.xmm[2] = em_mask_key(data2, mask2.x);
297 /* Find destination port */
298 ret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);
299 return (ret < 0) ? portid : ipv6_l3fwd_out_if[ret];
302 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
303 #if defined(NO_HASH_MULTI_LOOKUP)
304 #include "l3fwd_em_sequential.h"
306 #include "l3fwd_em_hlm.h"
309 #include "l3fwd_em.h"
313 convert_ipv4_5tuple(struct ipv4_5tuple *key1,
314 union ipv4_5tuple_host *key2)
316 key2->ip_dst = rte_cpu_to_be_32(key1->ip_dst);
317 key2->ip_src = rte_cpu_to_be_32(key1->ip_src);
318 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
319 key2->port_src = rte_cpu_to_be_16(key1->port_src);
320 key2->proto = key1->proto;
326 convert_ipv6_5tuple(struct ipv6_5tuple *key1,
327 union ipv6_5tuple_host *key2)
331 for (i = 0; i < 16; i++) {
332 key2->ip_dst[i] = key1->ip_dst[i];
333 key2->ip_src[i] = key1->ip_src[i];
335 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
336 key2->port_src = rte_cpu_to_be_16(key1->port_src);
337 key2->proto = key1->proto;
343 #define BYTE_VALUE_MAX 256
344 #define ALL_32_BITS 0xffffffff
345 #define BIT_8_TO_15 0x0000ff00
348 populate_ipv4_few_flow_into_table(const struct rte_hash *h)
353 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
354 ALL_32_BITS, ALL_32_BITS} };
356 for (i = 0; i < IPV4_L3FWD_EM_NUM_ROUTES; i++) {
357 struct ipv4_l3fwd_em_route entry;
358 union ipv4_5tuple_host newkey;
360 entry = ipv4_l3fwd_em_route_array[i];
361 convert_ipv4_5tuple(&entry.key, &newkey);
362 ret = rte_hash_add_key(h, (void *) &newkey);
364 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
365 " to the l3fwd hash.\n", i);
367 ipv4_l3fwd_out_if[ret] = entry.if_out;
369 printf("Hash: Adding 0x%" PRIx64 " keys\n",
370 (uint64_t)IPV4_L3FWD_EM_NUM_ROUTES);
373 #define BIT_16_TO_23 0x00ff0000
375 populate_ipv6_few_flow_into_table(const struct rte_hash *h)
380 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
381 ALL_32_BITS, ALL_32_BITS} };
383 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
385 for (i = 0; i < IPV6_L3FWD_EM_NUM_ROUTES; i++) {
386 struct ipv6_l3fwd_em_route entry;
387 union ipv6_5tuple_host newkey;
389 entry = ipv6_l3fwd_em_route_array[i];
390 convert_ipv6_5tuple(&entry.key, &newkey);
391 ret = rte_hash_add_key(h, (void *) &newkey);
393 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
394 " to the l3fwd hash.\n", i);
396 ipv6_l3fwd_out_if[ret] = entry.if_out;
398 printf("Hash: Adding 0x%" PRIx64 "keys\n",
399 (uint64_t)IPV6_L3FWD_EM_NUM_ROUTES);
402 #define NUMBER_PORT_USED 4
404 populate_ipv4_many_flow_into_table(const struct rte_hash *h,
405 unsigned int nr_flow)
409 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
410 ALL_32_BITS, ALL_32_BITS} };
412 for (i = 0; i < nr_flow; i++) {
413 struct ipv4_l3fwd_em_route entry;
414 union ipv4_5tuple_host newkey;
416 uint8_t a = (uint8_t)
417 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
418 uint8_t b = (uint8_t)
419 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
420 uint8_t c = (uint8_t)
421 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
423 /* Create the ipv4 exact match flow */
424 memset(&entry, 0, sizeof(entry));
425 switch (i & (NUMBER_PORT_USED - 1)) {
427 entry = ipv4_l3fwd_em_route_array[0];
428 entry.key.ip_dst = IPv4(101, c, b, a);
431 entry = ipv4_l3fwd_em_route_array[1];
432 entry.key.ip_dst = IPv4(201, c, b, a);
435 entry = ipv4_l3fwd_em_route_array[2];
436 entry.key.ip_dst = IPv4(111, c, b, a);
439 entry = ipv4_l3fwd_em_route_array[3];
440 entry.key.ip_dst = IPv4(211, c, b, a);
443 convert_ipv4_5tuple(&entry.key, &newkey);
444 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
447 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
449 ipv4_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
452 printf("Hash: Adding 0x%x keys\n", nr_flow);
456 populate_ipv6_many_flow_into_table(const struct rte_hash *h,
457 unsigned int nr_flow)
461 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
462 ALL_32_BITS, ALL_32_BITS} };
463 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
465 for (i = 0; i < nr_flow; i++) {
466 struct ipv6_l3fwd_em_route entry;
467 union ipv6_5tuple_host newkey;
469 uint8_t a = (uint8_t)
470 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
471 uint8_t b = (uint8_t)
472 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
473 uint8_t c = (uint8_t)
474 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
476 /* Create the ipv6 exact match flow */
477 memset(&entry, 0, sizeof(entry));
478 switch (i & (NUMBER_PORT_USED - 1)) {
480 entry = ipv6_l3fwd_em_route_array[0];
483 entry = ipv6_l3fwd_em_route_array[1];
486 entry = ipv6_l3fwd_em_route_array[2];
489 entry = ipv6_l3fwd_em_route_array[3];
492 entry.key.ip_dst[13] = c;
493 entry.key.ip_dst[14] = b;
494 entry.key.ip_dst[15] = a;
495 convert_ipv6_5tuple(&entry.key, &newkey);
496 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
499 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
501 ipv6_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
504 printf("Hash: Adding 0x%x keys\n", nr_flow);
508 * 1. IP packets without extension;
509 * 2. L4 payload should be either TCP or UDP.
512 em_check_ptype(int portid)
515 int ptype_l3_ipv4_ext = 0;
516 int ptype_l3_ipv6_ext = 0;
517 int ptype_l4_tcp = 0;
518 int ptype_l4_udp = 0;
519 uint32_t ptype_mask = RTE_PTYPE_L3_MASK | RTE_PTYPE_L4_MASK;
521 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
525 uint32_t ptypes[ret];
527 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
528 for (i = 0; i < ret; ++i) {
530 case RTE_PTYPE_L3_IPV4_EXT:
531 ptype_l3_ipv4_ext = 1;
533 case RTE_PTYPE_L3_IPV6_EXT:
534 ptype_l3_ipv6_ext = 1;
536 case RTE_PTYPE_L4_TCP:
539 case RTE_PTYPE_L4_UDP:
545 if (ptype_l3_ipv4_ext == 0)
546 printf("port %d cannot parse RTE_PTYPE_L3_IPV4_EXT\n", portid);
547 if (ptype_l3_ipv6_ext == 0)
548 printf("port %d cannot parse RTE_PTYPE_L3_IPV6_EXT\n", portid);
549 if (!ptype_l3_ipv4_ext || !ptype_l3_ipv6_ext)
552 if (ptype_l4_tcp == 0)
553 printf("port %d cannot parse RTE_PTYPE_L4_TCP\n", portid);
554 if (ptype_l4_udp == 0)
555 printf("port %d cannot parse RTE_PTYPE_L4_UDP\n", portid);
556 if (ptype_l4_tcp && ptype_l4_udp)
563 em_parse_ptype(struct rte_mbuf *m)
565 struct ether_hdr *eth_hdr;
566 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
570 struct ipv4_hdr *ipv4_hdr;
571 struct ipv6_hdr *ipv6_hdr;
573 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
574 ether_type = eth_hdr->ether_type;
575 l3 = (uint8_t *)eth_hdr + sizeof(struct ether_hdr);
576 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
577 ipv4_hdr = (struct ipv4_hdr *)l3;
578 hdr_len = (ipv4_hdr->version_ihl & IPV4_HDR_IHL_MASK) *
580 if (hdr_len == sizeof(struct ipv4_hdr)) {
581 packet_type |= RTE_PTYPE_L3_IPV4;
582 if (ipv4_hdr->next_proto_id == IPPROTO_TCP)
583 packet_type |= RTE_PTYPE_L4_TCP;
584 else if (ipv4_hdr->next_proto_id == IPPROTO_UDP)
585 packet_type |= RTE_PTYPE_L4_UDP;
587 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
588 } else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) {
589 ipv6_hdr = (struct ipv6_hdr *)l3;
590 if (ipv6_hdr->proto == IPPROTO_TCP)
591 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
592 else if (ipv6_hdr->proto == IPPROTO_UDP)
593 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
595 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
598 m->packet_type = packet_type;
602 em_cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
603 struct rte_mbuf *pkts[], uint16_t nb_pkts,
604 uint16_t max_pkts __rte_unused,
605 void *user_param __rte_unused)
609 for (i = 0; i < nb_pkts; ++i)
610 em_parse_ptype(pkts[i]);
615 /* main processing loop */
617 em_main_loop(__attribute__((unused)) void *dummy)
619 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
621 uint64_t prev_tsc, diff_tsc, cur_tsc;
625 struct lcore_conf *qconf;
626 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
627 US_PER_S * BURST_TX_DRAIN_US;
631 lcore_id = rte_lcore_id();
632 qconf = &lcore_conf[lcore_id];
634 if (qconf->n_rx_queue == 0) {
635 RTE_LOG(INFO, L3FWD, "lcore %u has nothing to do\n", lcore_id);
639 RTE_LOG(INFO, L3FWD, "entering main loop on lcore %u\n", lcore_id);
641 for (i = 0; i < qconf->n_rx_queue; i++) {
643 portid = qconf->rx_queue_list[i].port_id;
644 queueid = qconf->rx_queue_list[i].queue_id;
646 " -- lcoreid=%u portid=%u rxqueueid=%hhu\n",
647 lcore_id, portid, queueid);
650 while (!force_quit) {
652 cur_tsc = rte_rdtsc();
655 * TX burst queue drain
657 diff_tsc = cur_tsc - prev_tsc;
658 if (unlikely(diff_tsc > drain_tsc)) {
660 for (i = 0; i < qconf->n_tx_port; ++i) {
661 portid = qconf->tx_port_id[i];
662 if (qconf->tx_mbufs[portid].len == 0)
665 qconf->tx_mbufs[portid].len,
667 qconf->tx_mbufs[portid].len = 0;
674 * Read packet from RX queues
676 for (i = 0; i < qconf->n_rx_queue; ++i) {
677 portid = qconf->rx_queue_list[i].port_id;
678 queueid = qconf->rx_queue_list[i].queue_id;
679 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
684 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
685 l3fwd_em_send_packets(nb_rx, pkts_burst,
688 l3fwd_em_no_opt_send_packets(nb_rx, pkts_burst,
698 * Initialize exact match (hash) parameters.
701 setup_hash(const int socketid)
703 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
705 .entries = L3FWD_HASH_ENTRIES,
706 .key_len = sizeof(union ipv4_5tuple_host),
707 .hash_func = ipv4_hash_crc,
708 .hash_func_init_val = 0,
711 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
713 .entries = L3FWD_HASH_ENTRIES,
714 .key_len = sizeof(union ipv6_5tuple_host),
715 .hash_func = ipv6_hash_crc,
716 .hash_func_init_val = 0,
721 /* create ipv4 hash */
722 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
723 ipv4_l3fwd_hash_params.name = s;
724 ipv4_l3fwd_hash_params.socket_id = socketid;
725 ipv4_l3fwd_em_lookup_struct[socketid] =
726 rte_hash_create(&ipv4_l3fwd_hash_params);
727 if (ipv4_l3fwd_em_lookup_struct[socketid] == NULL)
728 rte_exit(EXIT_FAILURE,
729 "Unable to create the l3fwd hash on socket %d\n",
732 /* create ipv6 hash */
733 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
734 ipv6_l3fwd_hash_params.name = s;
735 ipv6_l3fwd_hash_params.socket_id = socketid;
736 ipv6_l3fwd_em_lookup_struct[socketid] =
737 rte_hash_create(&ipv6_l3fwd_hash_params);
738 if (ipv6_l3fwd_em_lookup_struct[socketid] == NULL)
739 rte_exit(EXIT_FAILURE,
740 "Unable to create the l3fwd hash on socket %d\n",
743 if (hash_entry_number != HASH_ENTRY_NUMBER_DEFAULT) {
744 /* For testing hash matching with a large number of flows we
745 * generate millions of IP 5-tuples with an incremented dst
746 * address to initialize the hash table. */
748 /* populate the ipv4 hash */
749 populate_ipv4_many_flow_into_table(
750 ipv4_l3fwd_em_lookup_struct[socketid],
753 /* populate the ipv6 hash */
754 populate_ipv6_many_flow_into_table(
755 ipv6_l3fwd_em_lookup_struct[socketid],
760 * Use data in ipv4/ipv6 l3fwd lookup table
761 * directly to initialize the hash table.
764 /* populate the ipv4 hash */
765 populate_ipv4_few_flow_into_table(
766 ipv4_l3fwd_em_lookup_struct[socketid]);
768 /* populate the ipv6 hash */
769 populate_ipv6_few_flow_into_table(
770 ipv6_l3fwd_em_lookup_struct[socketid]);
775 /* Return ipv4/ipv6 em fwd lookup struct. */
777 em_get_ipv4_l3fwd_lookup_struct(const int socketid)
779 return ipv4_l3fwd_em_lookup_struct[socketid];
783 em_get_ipv6_l3fwd_lookup_struct(const int socketid)
785 return ipv6_l3fwd_em_lookup_struct[socketid];