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_cycles.h>
30 #if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32)
35 #include <rte_hash_crc.h>
36 #define DEFAULT_HASH_FUNC rte_hash_crc
38 #include <rte_jhash.h>
39 #define DEFAULT_HASH_FUNC rte_jhash
42 #define IPV6_ADDR_LEN 16
50 } __attribute__((__packed__));
52 union ipv4_5tuple_host {
65 #define XMM_NUM_IN_IPV6_5TUPLE 3
68 uint8_t ip_dst[IPV6_ADDR_LEN];
69 uint8_t ip_src[IPV6_ADDR_LEN];
73 } __attribute__((__packed__));
75 union ipv6_5tuple_host {
80 uint8_t ip_src[IPV6_ADDR_LEN];
81 uint8_t ip_dst[IPV6_ADDR_LEN];
86 xmm_t xmm[XMM_NUM_IN_IPV6_5TUPLE];
91 struct ipv4_l3fwd_em_route {
92 struct ipv4_5tuple key;
96 struct ipv6_l3fwd_em_route {
97 struct ipv6_5tuple key;
101 static struct ipv4_l3fwd_em_route ipv4_l3fwd_em_route_array[] = {
102 {{RTE_IPV4(101, 0, 0, 0), RTE_IPV4(100, 10, 0, 1), 101, 11, IPPROTO_TCP}, 0},
103 {{RTE_IPV4(201, 0, 0, 0), RTE_IPV4(200, 20, 0, 1), 102, 12, IPPROTO_TCP}, 1},
104 {{RTE_IPV4(111, 0, 0, 0), RTE_IPV4(100, 30, 0, 1), 101, 11, IPPROTO_TCP}, 2},
105 {{RTE_IPV4(211, 0, 0, 0), RTE_IPV4(200, 40, 0, 1), 102, 12, IPPROTO_TCP}, 3},
108 static struct ipv6_l3fwd_em_route ipv6_l3fwd_em_route_array[] = {
110 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
111 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
112 101, 11, IPPROTO_TCP}, 0},
115 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
116 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
117 102, 12, IPPROTO_TCP}, 1},
120 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
121 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
122 101, 11, IPPROTO_TCP}, 2},
125 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
126 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
127 102, 12, IPPROTO_TCP}, 3},
130 struct rte_hash *ipv4_l3fwd_em_lookup_struct[NB_SOCKETS];
131 struct rte_hash *ipv6_l3fwd_em_lookup_struct[NB_SOCKETS];
133 static inline uint32_t
134 ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len,
137 const union ipv4_5tuple_host *k;
143 p = (const uint32_t *)&k->port_src;
146 init_val = rte_hash_crc_4byte(t, init_val);
147 init_val = rte_hash_crc_4byte(k->ip_src, init_val);
148 init_val = rte_hash_crc_4byte(k->ip_dst, init_val);
149 init_val = rte_hash_crc_4byte(*p, init_val);
151 init_val = rte_jhash_1word(t, init_val);
152 init_val = rte_jhash_1word(k->ip_src, init_val);
153 init_val = rte_jhash_1word(k->ip_dst, init_val);
154 init_val = rte_jhash_1word(*p, init_val);
160 static inline uint32_t
161 ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
164 const union ipv6_5tuple_host *k;
168 const uint32_t *ip_src0, *ip_src1, *ip_src2, *ip_src3;
169 const uint32_t *ip_dst0, *ip_dst1, *ip_dst2, *ip_dst3;
174 p = (const uint32_t *)&k->port_src;
177 ip_src0 = (const uint32_t *) k->ip_src;
178 ip_src1 = (const uint32_t *)(k->ip_src+4);
179 ip_src2 = (const uint32_t *)(k->ip_src+8);
180 ip_src3 = (const uint32_t *)(k->ip_src+12);
181 ip_dst0 = (const uint32_t *) k->ip_dst;
182 ip_dst1 = (const uint32_t *)(k->ip_dst+4);
183 ip_dst2 = (const uint32_t *)(k->ip_dst+8);
184 ip_dst3 = (const uint32_t *)(k->ip_dst+12);
185 init_val = rte_hash_crc_4byte(t, init_val);
186 init_val = rte_hash_crc_4byte(*ip_src0, init_val);
187 init_val = rte_hash_crc_4byte(*ip_src1, init_val);
188 init_val = rte_hash_crc_4byte(*ip_src2, init_val);
189 init_val = rte_hash_crc_4byte(*ip_src3, init_val);
190 init_val = rte_hash_crc_4byte(*ip_dst0, init_val);
191 init_val = rte_hash_crc_4byte(*ip_dst1, init_val);
192 init_val = rte_hash_crc_4byte(*ip_dst2, init_val);
193 init_val = rte_hash_crc_4byte(*ip_dst3, init_val);
194 init_val = rte_hash_crc_4byte(*p, init_val);
196 init_val = rte_jhash_1word(t, init_val);
197 init_val = rte_jhash(k->ip_src,
198 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
199 init_val = rte_jhash(k->ip_dst,
200 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
201 init_val = rte_jhash_1word(*p, init_val);
206 #define IPV4_L3FWD_EM_NUM_ROUTES \
207 (sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
209 #define IPV6_L3FWD_EM_NUM_ROUTES \
210 (sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
212 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
213 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
215 static rte_xmm_t mask0;
216 static rte_xmm_t mask1;
217 static rte_xmm_t mask2;
219 #if defined(RTE_MACHINE_CPUFLAG_SSE2)
221 em_mask_key(void *key, xmm_t mask)
223 __m128i data = _mm_loadu_si128((__m128i *)(key));
225 return _mm_and_si128(data, mask);
227 #elif defined(RTE_MACHINE_CPUFLAG_NEON)
229 em_mask_key(void *key, xmm_t mask)
231 int32x4_t data = vld1q_s32((int32_t *)key);
233 return vandq_s32(data, mask);
235 #elif defined(RTE_MACHINE_CPUFLAG_ALTIVEC)
237 em_mask_key(void *key, xmm_t mask)
239 xmm_t data = vec_ld(0, (xmm_t *)(key));
241 return vec_and(data, mask);
244 #error No vector engine (SSE, NEON, ALTIVEC) available, check your toolchain
247 static inline uint16_t
248 em_get_ipv4_dst_port(void *ipv4_hdr, uint16_t portid, void *lookup_struct)
251 union ipv4_5tuple_host key;
252 struct rte_hash *ipv4_l3fwd_lookup_struct =
253 (struct rte_hash *)lookup_struct;
255 ipv4_hdr = (uint8_t *)ipv4_hdr +
256 offsetof(struct rte_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 +
278 offsetof(struct rte_ipv6_hdr, payload_len);
279 void *data0 = ipv6_hdr;
280 void *data1 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t);
281 void *data2 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t) + sizeof(xmm_t);
283 /* Get part of 5 tuple: src IP address lower 96 bits and protocol */
284 key.xmm[0] = em_mask_key(data0, mask1.x);
287 * Get part of 5 tuple: dst IP address lower 96 bits
288 * and src IP address higher 32 bits.
290 #if defined RTE_ARCH_X86
291 key.xmm[1] = _mm_loadu_si128(data1);
293 key.xmm[1] = *(xmm_t *)data1;
297 * Get part of 5 tuple: dst port and src port
298 * and dst IP address higher 32 bits.
300 key.xmm[2] = em_mask_key(data2, mask2.x);
302 /* Find destination port */
303 ret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);
304 return (ret < 0) ? portid : ipv6_l3fwd_out_if[ret];
307 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
308 #if defined(NO_HASH_MULTI_LOOKUP)
309 #include "l3fwd_em_sequential.h"
311 #include "l3fwd_em_hlm.h"
314 #include "l3fwd_em.h"
318 convert_ipv4_5tuple(struct ipv4_5tuple *key1,
319 union ipv4_5tuple_host *key2)
321 key2->ip_dst = rte_cpu_to_be_32(key1->ip_dst);
322 key2->ip_src = rte_cpu_to_be_32(key1->ip_src);
323 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
324 key2->port_src = rte_cpu_to_be_16(key1->port_src);
325 key2->proto = key1->proto;
331 convert_ipv6_5tuple(struct ipv6_5tuple *key1,
332 union ipv6_5tuple_host *key2)
336 for (i = 0; i < 16; i++) {
337 key2->ip_dst[i] = key1->ip_dst[i];
338 key2->ip_src[i] = key1->ip_src[i];
340 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
341 key2->port_src = rte_cpu_to_be_16(key1->port_src);
342 key2->proto = key1->proto;
348 #define BYTE_VALUE_MAX 256
349 #define ALL_32_BITS 0xffffffff
350 #define BIT_8_TO_15 0x0000ff00
353 populate_ipv4_few_flow_into_table(const struct rte_hash *h)
358 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
359 ALL_32_BITS, ALL_32_BITS} };
361 for (i = 0; i < IPV4_L3FWD_EM_NUM_ROUTES; i++) {
362 struct ipv4_l3fwd_em_route entry;
363 union ipv4_5tuple_host newkey;
365 entry = ipv4_l3fwd_em_route_array[i];
366 convert_ipv4_5tuple(&entry.key, &newkey);
367 ret = rte_hash_add_key(h, (void *) &newkey);
369 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
370 " to the l3fwd hash.\n", i);
372 ipv4_l3fwd_out_if[ret] = entry.if_out;
374 printf("Hash: Adding 0x%" PRIx64 " keys\n",
375 (uint64_t)IPV4_L3FWD_EM_NUM_ROUTES);
378 #define BIT_16_TO_23 0x00ff0000
380 populate_ipv6_few_flow_into_table(const struct rte_hash *h)
385 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
386 ALL_32_BITS, ALL_32_BITS} };
388 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
390 for (i = 0; i < IPV6_L3FWD_EM_NUM_ROUTES; i++) {
391 struct ipv6_l3fwd_em_route entry;
392 union ipv6_5tuple_host newkey;
394 entry = ipv6_l3fwd_em_route_array[i];
395 convert_ipv6_5tuple(&entry.key, &newkey);
396 ret = rte_hash_add_key(h, (void *) &newkey);
398 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
399 " to the l3fwd hash.\n", i);
401 ipv6_l3fwd_out_if[ret] = entry.if_out;
403 printf("Hash: Adding 0x%" PRIx64 "keys\n",
404 (uint64_t)IPV6_L3FWD_EM_NUM_ROUTES);
407 #define NUMBER_PORT_USED 4
409 populate_ipv4_many_flow_into_table(const struct rte_hash *h,
410 unsigned int nr_flow)
414 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
415 ALL_32_BITS, ALL_32_BITS} };
417 for (i = 0; i < nr_flow; i++) {
418 struct ipv4_l3fwd_em_route entry;
419 union ipv4_5tuple_host newkey;
421 uint8_t a = (uint8_t)
422 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
423 uint8_t b = (uint8_t)
424 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
425 uint8_t c = (uint8_t)
426 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
428 /* Create the ipv4 exact match flow */
429 memset(&entry, 0, sizeof(entry));
430 switch (i & (NUMBER_PORT_USED - 1)) {
432 entry = ipv4_l3fwd_em_route_array[0];
433 entry.key.ip_dst = RTE_IPV4(101, c, b, a);
436 entry = ipv4_l3fwd_em_route_array[1];
437 entry.key.ip_dst = RTE_IPV4(201, c, b, a);
440 entry = ipv4_l3fwd_em_route_array[2];
441 entry.key.ip_dst = RTE_IPV4(111, c, b, a);
444 entry = ipv4_l3fwd_em_route_array[3];
445 entry.key.ip_dst = RTE_IPV4(211, c, b, a);
448 convert_ipv4_5tuple(&entry.key, &newkey);
449 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
452 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
454 ipv4_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
457 printf("Hash: Adding 0x%x keys\n", nr_flow);
461 populate_ipv6_many_flow_into_table(const struct rte_hash *h,
462 unsigned int nr_flow)
466 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
467 ALL_32_BITS, ALL_32_BITS} };
468 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
470 for (i = 0; i < nr_flow; i++) {
471 struct ipv6_l3fwd_em_route entry;
472 union ipv6_5tuple_host newkey;
474 uint8_t a = (uint8_t)
475 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
476 uint8_t b = (uint8_t)
477 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
478 uint8_t c = (uint8_t)
479 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
481 /* Create the ipv6 exact match flow */
482 memset(&entry, 0, sizeof(entry));
483 switch (i & (NUMBER_PORT_USED - 1)) {
485 entry = ipv6_l3fwd_em_route_array[0];
488 entry = ipv6_l3fwd_em_route_array[1];
491 entry = ipv6_l3fwd_em_route_array[2];
494 entry = ipv6_l3fwd_em_route_array[3];
497 entry.key.ip_dst[13] = c;
498 entry.key.ip_dst[14] = b;
499 entry.key.ip_dst[15] = a;
500 convert_ipv6_5tuple(&entry.key, &newkey);
501 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
504 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
506 ipv6_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
509 printf("Hash: Adding 0x%x keys\n", nr_flow);
513 * 1. IP packets without extension;
514 * 2. L4 payload should be either TCP or UDP.
517 em_check_ptype(int portid)
520 int ptype_l3_ipv4_ext = 0;
521 int ptype_l3_ipv6_ext = 0;
522 int ptype_l4_tcp = 0;
523 int ptype_l4_udp = 0;
524 uint32_t ptype_mask = RTE_PTYPE_L3_MASK | RTE_PTYPE_L4_MASK;
526 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
530 uint32_t ptypes[ret];
532 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
533 for (i = 0; i < ret; ++i) {
535 case RTE_PTYPE_L3_IPV4_EXT:
536 ptype_l3_ipv4_ext = 1;
538 case RTE_PTYPE_L3_IPV6_EXT:
539 ptype_l3_ipv6_ext = 1;
541 case RTE_PTYPE_L4_TCP:
544 case RTE_PTYPE_L4_UDP:
550 if (ptype_l3_ipv4_ext == 0)
551 printf("port %d cannot parse RTE_PTYPE_L3_IPV4_EXT\n", portid);
552 if (ptype_l3_ipv6_ext == 0)
553 printf("port %d cannot parse RTE_PTYPE_L3_IPV6_EXT\n", portid);
554 if (!ptype_l3_ipv4_ext || !ptype_l3_ipv6_ext)
557 if (ptype_l4_tcp == 0)
558 printf("port %d cannot parse RTE_PTYPE_L4_TCP\n", portid);
559 if (ptype_l4_udp == 0)
560 printf("port %d cannot parse RTE_PTYPE_L4_UDP\n", portid);
561 if (ptype_l4_tcp && ptype_l4_udp)
568 em_parse_ptype(struct rte_mbuf *m)
570 struct rte_ether_hdr *eth_hdr;
571 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
575 struct rte_ipv4_hdr *ipv4_hdr;
576 struct rte_ipv6_hdr *ipv6_hdr;
578 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
579 ether_type = eth_hdr->ether_type;
580 l3 = (uint8_t *)eth_hdr + sizeof(struct rte_ether_hdr);
581 if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4)) {
582 ipv4_hdr = (struct rte_ipv4_hdr *)l3;
583 hdr_len = (ipv4_hdr->version_ihl & RTE_IPV4_HDR_IHL_MASK) *
584 RTE_IPV4_IHL_MULTIPLIER;
585 if (hdr_len == sizeof(struct rte_ipv4_hdr)) {
586 packet_type |= RTE_PTYPE_L3_IPV4;
587 if (ipv4_hdr->next_proto_id == IPPROTO_TCP)
588 packet_type |= RTE_PTYPE_L4_TCP;
589 else if (ipv4_hdr->next_proto_id == IPPROTO_UDP)
590 packet_type |= RTE_PTYPE_L4_UDP;
592 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
593 } else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6)) {
594 ipv6_hdr = (struct rte_ipv6_hdr *)l3;
595 if (ipv6_hdr->proto == IPPROTO_TCP)
596 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
597 else if (ipv6_hdr->proto == IPPROTO_UDP)
598 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
600 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
603 m->packet_type = packet_type;
607 em_cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
608 struct rte_mbuf *pkts[], uint16_t nb_pkts,
609 uint16_t max_pkts __rte_unused,
610 void *user_param __rte_unused)
614 for (i = 0; i < nb_pkts; ++i)
615 em_parse_ptype(pkts[i]);
620 /* main processing loop */
622 em_main_loop(__attribute__((unused)) void *dummy)
624 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
626 uint64_t prev_tsc, diff_tsc, cur_tsc;
630 struct lcore_conf *qconf;
631 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
632 US_PER_S * BURST_TX_DRAIN_US;
636 lcore_id = rte_lcore_id();
637 qconf = &lcore_conf[lcore_id];
639 if (qconf->n_rx_queue == 0) {
640 RTE_LOG(INFO, L3FWD, "lcore %u has nothing to do\n", lcore_id);
644 RTE_LOG(INFO, L3FWD, "entering main loop on lcore %u\n", lcore_id);
646 for (i = 0; i < qconf->n_rx_queue; i++) {
648 portid = qconf->rx_queue_list[i].port_id;
649 queueid = qconf->rx_queue_list[i].queue_id;
651 " -- lcoreid=%u portid=%u rxqueueid=%hhu\n",
652 lcore_id, portid, queueid);
655 while (!force_quit) {
657 cur_tsc = rte_rdtsc();
660 * TX burst queue drain
662 diff_tsc = cur_tsc - prev_tsc;
663 if (unlikely(diff_tsc > drain_tsc)) {
665 for (i = 0; i < qconf->n_tx_port; ++i) {
666 portid = qconf->tx_port_id[i];
667 if (qconf->tx_mbufs[portid].len == 0)
670 qconf->tx_mbufs[portid].len,
672 qconf->tx_mbufs[portid].len = 0;
679 * Read packet from RX queues
681 for (i = 0; i < qconf->n_rx_queue; ++i) {
682 portid = qconf->rx_queue_list[i].port_id;
683 queueid = qconf->rx_queue_list[i].queue_id;
684 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
689 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
690 l3fwd_em_send_packets(nb_rx, pkts_burst,
693 l3fwd_em_no_opt_send_packets(nb_rx, pkts_burst,
703 * Initialize exact match (hash) parameters.
706 setup_hash(const int socketid)
708 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
710 .entries = L3FWD_HASH_ENTRIES,
711 .key_len = sizeof(union ipv4_5tuple_host),
712 .hash_func = ipv4_hash_crc,
713 .hash_func_init_val = 0,
716 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
718 .entries = L3FWD_HASH_ENTRIES,
719 .key_len = sizeof(union ipv6_5tuple_host),
720 .hash_func = ipv6_hash_crc,
721 .hash_func_init_val = 0,
726 /* create ipv4 hash */
727 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
728 ipv4_l3fwd_hash_params.name = s;
729 ipv4_l3fwd_hash_params.socket_id = socketid;
730 ipv4_l3fwd_em_lookup_struct[socketid] =
731 rte_hash_create(&ipv4_l3fwd_hash_params);
732 if (ipv4_l3fwd_em_lookup_struct[socketid] == NULL)
733 rte_exit(EXIT_FAILURE,
734 "Unable to create the l3fwd hash on socket %d\n",
737 /* create ipv6 hash */
738 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
739 ipv6_l3fwd_hash_params.name = s;
740 ipv6_l3fwd_hash_params.socket_id = socketid;
741 ipv6_l3fwd_em_lookup_struct[socketid] =
742 rte_hash_create(&ipv6_l3fwd_hash_params);
743 if (ipv6_l3fwd_em_lookup_struct[socketid] == NULL)
744 rte_exit(EXIT_FAILURE,
745 "Unable to create the l3fwd hash on socket %d\n",
748 if (hash_entry_number != HASH_ENTRY_NUMBER_DEFAULT) {
749 /* For testing hash matching with a large number of flows we
750 * generate millions of IP 5-tuples with an incremented dst
751 * address to initialize the hash table. */
753 /* populate the ipv4 hash */
754 populate_ipv4_many_flow_into_table(
755 ipv4_l3fwd_em_lookup_struct[socketid],
758 /* populate the ipv6 hash */
759 populate_ipv6_many_flow_into_table(
760 ipv6_l3fwd_em_lookup_struct[socketid],
765 * Use data in ipv4/ipv6 l3fwd lookup table
766 * directly to initialize the hash table.
769 /* populate the ipv4 hash */
770 populate_ipv4_few_flow_into_table(
771 ipv4_l3fwd_em_lookup_struct[socketid]);
773 /* populate the ipv6 hash */
774 populate_ipv6_few_flow_into_table(
775 ipv6_l3fwd_em_lookup_struct[socketid]);
780 /* Return ipv4/ipv6 em fwd lookup struct. */
782 em_get_ipv4_l3fwd_lookup_struct(const int socketid)
784 return ipv4_l3fwd_em_lookup_struct[socketid];
788 em_get_ipv6_l3fwd_lookup_struct(const int socketid)
790 return ipv6_l3fwd_em_lookup_struct[socketid];