4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/types.h>
40 #include <sys/queue.h>
45 #include <netinet/in.h>
47 #include <rte_debug.h>
48 #include <rte_ether.h>
49 #include <rte_ethdev.h>
50 #include <rte_cycles.h>
59 #if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32)
64 #include <rte_hash_crc.h>
65 #define DEFAULT_HASH_FUNC rte_hash_crc
67 #include <rte_jhash.h>
68 #define DEFAULT_HASH_FUNC rte_jhash
71 #define IPV6_ADDR_LEN 16
79 } __attribute__((__packed__));
81 union ipv4_5tuple_host {
94 #define XMM_NUM_IN_IPV6_5TUPLE 3
97 uint8_t ip_dst[IPV6_ADDR_LEN];
98 uint8_t ip_src[IPV6_ADDR_LEN];
102 } __attribute__((__packed__));
104 union ipv6_5tuple_host {
109 uint8_t ip_src[IPV6_ADDR_LEN];
110 uint8_t ip_dst[IPV6_ADDR_LEN];
115 xmm_t xmm[XMM_NUM_IN_IPV6_5TUPLE];
120 struct ipv4_l3fwd_em_route {
121 struct ipv4_5tuple key;
125 struct ipv6_l3fwd_em_route {
126 struct ipv6_5tuple key;
130 static struct ipv4_l3fwd_em_route ipv4_l3fwd_em_route_array[] = {
131 {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 101, 11, IPPROTO_TCP}, 0},
132 {{IPv4(201, 0, 0, 0), IPv4(200, 20, 0, 1), 102, 12, IPPROTO_TCP}, 1},
133 {{IPv4(111, 0, 0, 0), IPv4(100, 30, 0, 1), 101, 11, IPPROTO_TCP}, 2},
134 {{IPv4(211, 0, 0, 0), IPv4(200, 40, 0, 1), 102, 12, IPPROTO_TCP}, 3},
137 static struct ipv6_l3fwd_em_route ipv6_l3fwd_em_route_array[] = {
139 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
140 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
141 101, 11, IPPROTO_TCP}, 0},
144 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
145 {0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
146 102, 12, IPPROTO_TCP}, 1},
149 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
150 {0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
151 101, 11, IPPROTO_TCP}, 2},
154 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},
155 {0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
156 102, 12, IPPROTO_TCP}, 3},
159 struct rte_hash *ipv4_l3fwd_em_lookup_struct[NB_SOCKETS];
160 struct rte_hash *ipv6_l3fwd_em_lookup_struct[NB_SOCKETS];
162 static inline uint32_t
163 ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len,
166 const union ipv4_5tuple_host *k;
172 p = (const uint32_t *)&k->port_src;
175 init_val = rte_hash_crc_4byte(t, init_val);
176 init_val = rte_hash_crc_4byte(k->ip_src, init_val);
177 init_val = rte_hash_crc_4byte(k->ip_dst, init_val);
178 init_val = rte_hash_crc_4byte(*p, init_val);
180 init_val = rte_jhash_1word(t, init_val);
181 init_val = rte_jhash_1word(k->ip_src, init_val);
182 init_val = rte_jhash_1word(k->ip_dst, init_val);
183 init_val = rte_jhash_1word(*p, init_val);
189 static inline uint32_t
190 ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,
193 const union ipv6_5tuple_host *k;
197 const uint32_t *ip_src0, *ip_src1, *ip_src2, *ip_src3;
198 const uint32_t *ip_dst0, *ip_dst1, *ip_dst2, *ip_dst3;
203 p = (const uint32_t *)&k->port_src;
206 ip_src0 = (const uint32_t *) k->ip_src;
207 ip_src1 = (const uint32_t *)(k->ip_src+4);
208 ip_src2 = (const uint32_t *)(k->ip_src+8);
209 ip_src3 = (const uint32_t *)(k->ip_src+12);
210 ip_dst0 = (const uint32_t *) k->ip_dst;
211 ip_dst1 = (const uint32_t *)(k->ip_dst+4);
212 ip_dst2 = (const uint32_t *)(k->ip_dst+8);
213 ip_dst3 = (const uint32_t *)(k->ip_dst+12);
214 init_val = rte_hash_crc_4byte(t, init_val);
215 init_val = rte_hash_crc_4byte(*ip_src0, init_val);
216 init_val = rte_hash_crc_4byte(*ip_src1, init_val);
217 init_val = rte_hash_crc_4byte(*ip_src2, init_val);
218 init_val = rte_hash_crc_4byte(*ip_src3, init_val);
219 init_val = rte_hash_crc_4byte(*ip_dst0, init_val);
220 init_val = rte_hash_crc_4byte(*ip_dst1, init_val);
221 init_val = rte_hash_crc_4byte(*ip_dst2, init_val);
222 init_val = rte_hash_crc_4byte(*ip_dst3, init_val);
223 init_val = rte_hash_crc_4byte(*p, init_val);
225 init_val = rte_jhash_1word(t, init_val);
226 init_val = rte_jhash(k->ip_src,
227 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
228 init_val = rte_jhash(k->ip_dst,
229 sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);
230 init_val = rte_jhash_1word(*p, init_val);
235 #define IPV4_L3FWD_EM_NUM_ROUTES \
236 (sizeof(ipv4_l3fwd_em_route_array) / sizeof(ipv4_l3fwd_em_route_array[0]))
238 #define IPV6_L3FWD_EM_NUM_ROUTES \
239 (sizeof(ipv6_l3fwd_em_route_array) / sizeof(ipv6_l3fwd_em_route_array[0]))
241 static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
242 static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
244 static rte_xmm_t mask0;
245 static rte_xmm_t mask1;
246 static rte_xmm_t mask2;
248 #if defined(RTE_MACHINE_CPUFLAG_SSE2)
250 em_mask_key(void *key, xmm_t mask)
252 __m128i data = _mm_loadu_si128((__m128i *)(key));
254 return _mm_and_si128(data, mask);
256 #elif defined(RTE_MACHINE_CPUFLAG_NEON)
258 em_mask_key(void *key, xmm_t mask)
260 int32x4_t data = vld1q_s32((int32_t *)key);
262 return vandq_s32(data, mask);
264 #elif defined(RTE_MACHINE_CPUFLAG_ALTIVEC)
266 em_mask_key(void *key, xmm_t mask)
268 xmm_t data = vec_ld(0, (xmm_t *)(key));
270 return vec_and(data, mask);
273 #error No vector engine (SSE, NEON, ALTIVEC) available, check your toolchain
276 static inline uint16_t
277 em_get_ipv4_dst_port(void *ipv4_hdr, uint16_t portid, void *lookup_struct)
280 union ipv4_5tuple_host key;
281 struct rte_hash *ipv4_l3fwd_lookup_struct =
282 (struct rte_hash *)lookup_struct;
284 ipv4_hdr = (uint8_t *)ipv4_hdr + offsetof(struct ipv4_hdr, time_to_live);
287 * Get 5 tuple: dst port, src port, dst IP address,
288 * src IP address and protocol.
290 key.xmm = em_mask_key(ipv4_hdr, mask0.x);
292 /* Find destination port */
293 ret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);
294 return (ret < 0) ? portid : ipv4_l3fwd_out_if[ret];
297 static inline uint16_t
298 em_get_ipv6_dst_port(void *ipv6_hdr, uint16_t portid, void *lookup_struct)
301 union ipv6_5tuple_host key;
302 struct rte_hash *ipv6_l3fwd_lookup_struct =
303 (struct rte_hash *)lookup_struct;
305 ipv6_hdr = (uint8_t *)ipv6_hdr + offsetof(struct ipv6_hdr, payload_len);
306 void *data0 = ipv6_hdr;
307 void *data1 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t);
308 void *data2 = ((uint8_t *)ipv6_hdr) + sizeof(xmm_t) + sizeof(xmm_t);
310 /* Get part of 5 tuple: src IP address lower 96 bits and protocol */
311 key.xmm[0] = em_mask_key(data0, mask1.x);
314 * Get part of 5 tuple: dst IP address lower 96 bits
315 * and src IP address higher 32 bits.
317 key.xmm[1] = *(xmm_t *)data1;
320 * Get part of 5 tuple: dst port and src port
321 * and dst IP address higher 32 bits.
323 key.xmm[2] = em_mask_key(data2, mask2.x);
325 /* Find destination port */
326 ret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);
327 return (ret < 0) ? portid : ipv6_l3fwd_out_if[ret];
330 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
331 #if defined(NO_HASH_MULTI_LOOKUP)
332 #include "l3fwd_em_sequential.h"
334 #include "l3fwd_em_hlm.h"
337 #include "l3fwd_em.h"
341 convert_ipv4_5tuple(struct ipv4_5tuple *key1,
342 union ipv4_5tuple_host *key2)
344 key2->ip_dst = rte_cpu_to_be_32(key1->ip_dst);
345 key2->ip_src = rte_cpu_to_be_32(key1->ip_src);
346 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
347 key2->port_src = rte_cpu_to_be_16(key1->port_src);
348 key2->proto = key1->proto;
354 convert_ipv6_5tuple(struct ipv6_5tuple *key1,
355 union ipv6_5tuple_host *key2)
359 for (i = 0; i < 16; i++) {
360 key2->ip_dst[i] = key1->ip_dst[i];
361 key2->ip_src[i] = key1->ip_src[i];
363 key2->port_dst = rte_cpu_to_be_16(key1->port_dst);
364 key2->port_src = rte_cpu_to_be_16(key1->port_src);
365 key2->proto = key1->proto;
371 #define BYTE_VALUE_MAX 256
372 #define ALL_32_BITS 0xffffffff
373 #define BIT_8_TO_15 0x0000ff00
376 populate_ipv4_few_flow_into_table(const struct rte_hash *h)
381 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
382 ALL_32_BITS, ALL_32_BITS} };
384 for (i = 0; i < IPV4_L3FWD_EM_NUM_ROUTES; i++) {
385 struct ipv4_l3fwd_em_route entry;
386 union ipv4_5tuple_host newkey;
388 entry = ipv4_l3fwd_em_route_array[i];
389 convert_ipv4_5tuple(&entry.key, &newkey);
390 ret = rte_hash_add_key(h, (void *) &newkey);
392 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
393 " to the l3fwd hash.\n", i);
395 ipv4_l3fwd_out_if[ret] = entry.if_out;
397 printf("Hash: Adding 0x%" PRIx64 " keys\n",
398 (uint64_t)IPV4_L3FWD_EM_NUM_ROUTES);
401 #define BIT_16_TO_23 0x00ff0000
403 populate_ipv6_few_flow_into_table(const struct rte_hash *h)
408 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
409 ALL_32_BITS, ALL_32_BITS} };
411 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
413 for (i = 0; i < IPV6_L3FWD_EM_NUM_ROUTES; i++) {
414 struct ipv6_l3fwd_em_route entry;
415 union ipv6_5tuple_host newkey;
417 entry = ipv6_l3fwd_em_route_array[i];
418 convert_ipv6_5tuple(&entry.key, &newkey);
419 ret = rte_hash_add_key(h, (void *) &newkey);
421 rte_exit(EXIT_FAILURE, "Unable to add entry %" PRIu32
422 " to the l3fwd hash.\n", i);
424 ipv6_l3fwd_out_if[ret] = entry.if_out;
426 printf("Hash: Adding 0x%" PRIx64 "keys\n",
427 (uint64_t)IPV6_L3FWD_EM_NUM_ROUTES);
430 #define NUMBER_PORT_USED 4
432 populate_ipv4_many_flow_into_table(const struct rte_hash *h,
433 unsigned int nr_flow)
437 mask0 = (rte_xmm_t){.u32 = {BIT_8_TO_15, ALL_32_BITS,
438 ALL_32_BITS, ALL_32_BITS} };
440 for (i = 0; i < nr_flow; i++) {
441 struct ipv4_l3fwd_em_route entry;
442 union ipv4_5tuple_host newkey;
444 uint8_t a = (uint8_t)
445 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
446 uint8_t b = (uint8_t)
447 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
448 uint8_t c = (uint8_t)
449 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
451 /* Create the ipv4 exact match flow */
452 memset(&entry, 0, sizeof(entry));
453 switch (i & (NUMBER_PORT_USED - 1)) {
455 entry = ipv4_l3fwd_em_route_array[0];
456 entry.key.ip_dst = IPv4(101, c, b, a);
459 entry = ipv4_l3fwd_em_route_array[1];
460 entry.key.ip_dst = IPv4(201, c, b, a);
463 entry = ipv4_l3fwd_em_route_array[2];
464 entry.key.ip_dst = IPv4(111, c, b, a);
467 entry = ipv4_l3fwd_em_route_array[3];
468 entry.key.ip_dst = IPv4(211, c, b, a);
471 convert_ipv4_5tuple(&entry.key, &newkey);
472 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
475 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
477 ipv4_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
480 printf("Hash: Adding 0x%x keys\n", nr_flow);
484 populate_ipv6_many_flow_into_table(const struct rte_hash *h,
485 unsigned int nr_flow)
489 mask1 = (rte_xmm_t){.u32 = {BIT_16_TO_23, ALL_32_BITS,
490 ALL_32_BITS, ALL_32_BITS} };
491 mask2 = (rte_xmm_t){.u32 = {ALL_32_BITS, ALL_32_BITS, 0, 0} };
493 for (i = 0; i < nr_flow; i++) {
494 struct ipv6_l3fwd_em_route entry;
495 union ipv6_5tuple_host newkey;
497 uint8_t a = (uint8_t)
498 ((i/NUMBER_PORT_USED)%BYTE_VALUE_MAX);
499 uint8_t b = (uint8_t)
500 (((i/NUMBER_PORT_USED)/BYTE_VALUE_MAX)%BYTE_VALUE_MAX);
501 uint8_t c = (uint8_t)
502 ((i/NUMBER_PORT_USED)/(BYTE_VALUE_MAX*BYTE_VALUE_MAX));
504 /* Create the ipv6 exact match flow */
505 memset(&entry, 0, sizeof(entry));
506 switch (i & (NUMBER_PORT_USED - 1)) {
508 entry = ipv6_l3fwd_em_route_array[0];
511 entry = ipv6_l3fwd_em_route_array[1];
514 entry = ipv6_l3fwd_em_route_array[2];
517 entry = ipv6_l3fwd_em_route_array[3];
520 entry.key.ip_dst[13] = c;
521 entry.key.ip_dst[14] = b;
522 entry.key.ip_dst[15] = a;
523 convert_ipv6_5tuple(&entry.key, &newkey);
524 int32_t ret = rte_hash_add_key(h, (void *) &newkey);
527 rte_exit(EXIT_FAILURE, "Unable to add entry %u\n", i);
529 ipv6_l3fwd_out_if[ret] = (uint8_t) entry.if_out;
532 printf("Hash: Adding 0x%x keys\n", nr_flow);
536 * 1. IP packets without extension;
537 * 2. L4 payload should be either TCP or UDP.
540 em_check_ptype(int portid)
543 int ptype_l3_ipv4_ext = 0;
544 int ptype_l3_ipv6_ext = 0;
545 int ptype_l4_tcp = 0;
546 int ptype_l4_udp = 0;
547 uint32_t ptype_mask = RTE_PTYPE_L3_MASK | RTE_PTYPE_L4_MASK;
549 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
553 uint32_t ptypes[ret];
555 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
556 for (i = 0; i < ret; ++i) {
558 case RTE_PTYPE_L3_IPV4_EXT:
559 ptype_l3_ipv4_ext = 1;
561 case RTE_PTYPE_L3_IPV6_EXT:
562 ptype_l3_ipv6_ext = 1;
564 case RTE_PTYPE_L4_TCP:
567 case RTE_PTYPE_L4_UDP:
573 if (ptype_l3_ipv4_ext == 0)
574 printf("port %d cannot parse RTE_PTYPE_L3_IPV4_EXT\n", portid);
575 if (ptype_l3_ipv6_ext == 0)
576 printf("port %d cannot parse RTE_PTYPE_L3_IPV6_EXT\n", portid);
577 if (!ptype_l3_ipv4_ext || !ptype_l3_ipv6_ext)
580 if (ptype_l4_tcp == 0)
581 printf("port %d cannot parse RTE_PTYPE_L4_TCP\n", portid);
582 if (ptype_l4_udp == 0)
583 printf("port %d cannot parse RTE_PTYPE_L4_UDP\n", portid);
584 if (ptype_l4_tcp && ptype_l4_udp)
591 em_parse_ptype(struct rte_mbuf *m)
593 struct ether_hdr *eth_hdr;
594 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
598 struct ipv4_hdr *ipv4_hdr;
599 struct ipv6_hdr *ipv6_hdr;
601 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
602 ether_type = eth_hdr->ether_type;
603 l3 = (uint8_t *)eth_hdr + sizeof(struct ether_hdr);
604 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
605 ipv4_hdr = (struct ipv4_hdr *)l3;
606 hdr_len = (ipv4_hdr->version_ihl & IPV4_HDR_IHL_MASK) *
608 if (hdr_len == sizeof(struct ipv4_hdr)) {
609 packet_type |= RTE_PTYPE_L3_IPV4;
610 if (ipv4_hdr->next_proto_id == IPPROTO_TCP)
611 packet_type |= RTE_PTYPE_L4_TCP;
612 else if (ipv4_hdr->next_proto_id == IPPROTO_UDP)
613 packet_type |= RTE_PTYPE_L4_UDP;
615 packet_type |= RTE_PTYPE_L3_IPV4_EXT;
616 } else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) {
617 ipv6_hdr = (struct ipv6_hdr *)l3;
618 if (ipv6_hdr->proto == IPPROTO_TCP)
619 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
620 else if (ipv6_hdr->proto == IPPROTO_UDP)
621 packet_type |= RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
623 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
626 m->packet_type = packet_type;
630 em_cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
631 struct rte_mbuf *pkts[], uint16_t nb_pkts,
632 uint16_t max_pkts __rte_unused,
633 void *user_param __rte_unused)
637 for (i = 0; i < nb_pkts; ++i)
638 em_parse_ptype(pkts[i]);
643 /* main processing loop */
645 em_main_loop(__attribute__((unused)) void *dummy)
647 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
649 uint64_t prev_tsc, diff_tsc, cur_tsc;
653 struct lcore_conf *qconf;
654 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
655 US_PER_S * BURST_TX_DRAIN_US;
659 lcore_id = rte_lcore_id();
660 qconf = &lcore_conf[lcore_id];
662 if (qconf->n_rx_queue == 0) {
663 RTE_LOG(INFO, L3FWD, "lcore %u has nothing to do\n", lcore_id);
667 RTE_LOG(INFO, L3FWD, "entering main loop on lcore %u\n", lcore_id);
669 for (i = 0; i < qconf->n_rx_queue; i++) {
671 portid = qconf->rx_queue_list[i].port_id;
672 queueid = qconf->rx_queue_list[i].queue_id;
674 " -- lcoreid=%u portid=%u rxqueueid=%hhu\n",
675 lcore_id, portid, queueid);
678 while (!force_quit) {
680 cur_tsc = rte_rdtsc();
683 * TX burst queue drain
685 diff_tsc = cur_tsc - prev_tsc;
686 if (unlikely(diff_tsc > drain_tsc)) {
688 for (i = 0; i < qconf->n_tx_port; ++i) {
689 portid = qconf->tx_port_id[i];
690 if (qconf->tx_mbufs[portid].len == 0)
693 qconf->tx_mbufs[portid].len,
695 qconf->tx_mbufs[portid].len = 0;
702 * Read packet from RX queues
704 for (i = 0; i < qconf->n_rx_queue; ++i) {
705 portid = qconf->rx_queue_list[i].port_id;
706 queueid = qconf->rx_queue_list[i].queue_id;
707 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
712 #if defined RTE_ARCH_X86 || defined RTE_MACHINE_CPUFLAG_NEON
713 l3fwd_em_send_packets(nb_rx, pkts_burst,
716 l3fwd_em_no_opt_send_packets(nb_rx, pkts_burst,
726 * Initialize exact match (hash) parameters.
729 setup_hash(const int socketid)
731 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
733 .entries = L3FWD_HASH_ENTRIES,
734 .key_len = sizeof(union ipv4_5tuple_host),
735 .hash_func = ipv4_hash_crc,
736 .hash_func_init_val = 0,
739 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
741 .entries = L3FWD_HASH_ENTRIES,
742 .key_len = sizeof(union ipv6_5tuple_host),
743 .hash_func = ipv6_hash_crc,
744 .hash_func_init_val = 0,
749 /* create ipv4 hash */
750 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
751 ipv4_l3fwd_hash_params.name = s;
752 ipv4_l3fwd_hash_params.socket_id = socketid;
753 ipv4_l3fwd_em_lookup_struct[socketid] =
754 rte_hash_create(&ipv4_l3fwd_hash_params);
755 if (ipv4_l3fwd_em_lookup_struct[socketid] == NULL)
756 rte_exit(EXIT_FAILURE,
757 "Unable to create the l3fwd hash on socket %d\n",
760 /* create ipv6 hash */
761 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
762 ipv6_l3fwd_hash_params.name = s;
763 ipv6_l3fwd_hash_params.socket_id = socketid;
764 ipv6_l3fwd_em_lookup_struct[socketid] =
765 rte_hash_create(&ipv6_l3fwd_hash_params);
766 if (ipv6_l3fwd_em_lookup_struct[socketid] == NULL)
767 rte_exit(EXIT_FAILURE,
768 "Unable to create the l3fwd hash on socket %d\n",
771 if (hash_entry_number != HASH_ENTRY_NUMBER_DEFAULT) {
772 /* For testing hash matching with a large number of flows we
773 * generate millions of IP 5-tuples with an incremented dst
774 * address to initialize the hash table. */
776 /* populate the ipv4 hash */
777 populate_ipv4_many_flow_into_table(
778 ipv4_l3fwd_em_lookup_struct[socketid],
781 /* populate the ipv6 hash */
782 populate_ipv6_many_flow_into_table(
783 ipv6_l3fwd_em_lookup_struct[socketid],
788 * Use data in ipv4/ipv6 l3fwd lookup table
789 * directly to initialize the hash table.
792 /* populate the ipv4 hash */
793 populate_ipv4_few_flow_into_table(
794 ipv4_l3fwd_em_lookup_struct[socketid]);
796 /* populate the ipv6 hash */
797 populate_ipv6_few_flow_into_table(
798 ipv6_l3fwd_em_lookup_struct[socketid]);
803 /* Return ipv4/ipv6 em fwd lookup struct. */
805 em_get_ipv4_l3fwd_lookup_struct(const int socketid)
807 return ipv4_l3fwd_em_lookup_struct[socketid];
811 em_get_ipv6_l3fwd_lookup_struct(const int socketid)
813 return ipv6_l3fwd_em_lookup_struct[socketid];