1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <sys/queue.h>
18 #include <rte_common.h>
20 #include <rte_byteorder.h>
22 #include <rte_memory.h>
23 #include <rte_memcpy.h>
25 #include <rte_launch.h>
26 #include <rte_atomic.h>
27 #include <rte_cycles.h>
28 #include <rte_prefetch.h>
29 #include <rte_lcore.h>
30 #include <rte_per_lcore.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_interrupts.h>
33 #include <rte_random.h>
34 #include <rte_debug.h>
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_mempool.h>
42 #include <rte_string_fns.h>
43 #include <rte_cpuflags.h>
45 #include <cmdline_parse.h>
46 #include <cmdline_parse_etheraddr.h>
51 * Configurable number of RX/TX ring descriptors
53 #define RTE_TEST_RX_DESC_DEFAULT 1024
54 #define RTE_TEST_TX_DESC_DEFAULT 1024
56 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
57 #define MAX_RX_QUEUE_PER_PORT 128
59 #define MAX_LCORE_PARAMS 1024
61 /* Static global variables used within this file. */
62 static uint16_t nb_rxd
= RTE_TEST_RX_DESC_DEFAULT
;
63 static uint16_t nb_txd
= RTE_TEST_TX_DESC_DEFAULT
;
65 /**< Ports set in promiscuous mode off by default. */
66 static int promiscuous_on
;
68 /* Select Longest-Prefix or Exact match. */
69 static int l3fwd_lpm_on
;
70 static int l3fwd_em_on
;
72 /* Global variables. */
74 static int numa_on
= 1; /**< NUMA is enabled by default. */
75 static int parse_ptype
; /**< Parse packet type using rx callback, and */
76 /**< disabled by default */
77 static int per_port_pool
; /**< Use separate buffer pools per port; disabled */
80 volatile bool force_quit
;
82 /* ethernet addresses of ports */
83 uint64_t dest_eth_addr
[RTE_MAX_ETHPORTS
];
84 struct ether_addr ports_eth_addr
[RTE_MAX_ETHPORTS
];
86 xmm_t val_eth
[RTE_MAX_ETHPORTS
];
88 /* mask of enabled ports */
89 uint32_t enabled_port_mask
;
91 /* Used only in exact match mode. */
92 int ipv6
; /**< ipv6 is false by default. */
93 uint32_t hash_entry_number
= HASH_ENTRY_NUMBER_DEFAULT
;
95 struct lcore_conf lcore_conf
[RTE_MAX_LCORE
];
101 } __rte_cache_aligned
;
103 static struct lcore_params lcore_params_array
[MAX_LCORE_PARAMS
];
104 static struct lcore_params lcore_params_array_default
[] = {
116 static struct lcore_params
* lcore_params
= lcore_params_array_default
;
117 static uint16_t nb_lcore_params
= sizeof(lcore_params_array_default
) /
118 sizeof(lcore_params_array_default
[0]);
120 static struct rte_eth_conf port_conf
= {
122 .mq_mode
= ETH_MQ_RX_RSS
,
123 .max_rx_pkt_len
= ETHER_MAX_LEN
,
125 .offloads
= DEV_RX_OFFLOAD_CHECKSUM
,
130 .rss_hf
= ETH_RSS_IP
,
134 .mq_mode
= ETH_MQ_TX_NONE
,
138 static struct rte_mempool
*pktmbuf_pool
[RTE_MAX_ETHPORTS
][NB_SOCKETS
];
139 static uint8_t lkp_per_socket
[NB_SOCKETS
];
141 struct l3fwd_lkp_mode
{
143 int (*check_ptype
)(int);
144 rte_rx_callback_fn cb_parse_ptype
;
145 int (*main_loop
)(void *);
146 void* (*get_ipv4_lookup_struct
)(int);
147 void* (*get_ipv6_lookup_struct
)(int);
150 static struct l3fwd_lkp_mode l3fwd_lkp
;
152 static struct l3fwd_lkp_mode l3fwd_em_lkp
= {
154 .check_ptype
= em_check_ptype
,
155 .cb_parse_ptype
= em_cb_parse_ptype
,
156 .main_loop
= em_main_loop
,
157 .get_ipv4_lookup_struct
= em_get_ipv4_l3fwd_lookup_struct
,
158 .get_ipv6_lookup_struct
= em_get_ipv6_l3fwd_lookup_struct
,
161 static struct l3fwd_lkp_mode l3fwd_lpm_lkp
= {
163 .check_ptype
= lpm_check_ptype
,
164 .cb_parse_ptype
= lpm_cb_parse_ptype
,
165 .main_loop
= lpm_main_loop
,
166 .get_ipv4_lookup_struct
= lpm_get_ipv4_l3fwd_lookup_struct
,
167 .get_ipv6_lookup_struct
= lpm_get_ipv6_l3fwd_lookup_struct
,
171 * Setup lookup methods for forwarding.
172 * Currently exact-match and longest-prefix-match
173 * are supported ones.
176 setup_l3fwd_lookup_tables(void)
178 /* Setup HASH lookup functions. */
180 l3fwd_lkp
= l3fwd_em_lkp
;
181 /* Setup LPM lookup functions. */
183 l3fwd_lkp
= l3fwd_lpm_lkp
;
187 check_lcore_params(void)
189 uint8_t queue
, lcore
;
193 for (i
= 0; i
< nb_lcore_params
; ++i
) {
194 queue
= lcore_params
[i
].queue_id
;
195 if (queue
>= MAX_RX_QUEUE_PER_PORT
) {
196 printf("invalid queue number: %hhu\n", queue
);
199 lcore
= lcore_params
[i
].lcore_id
;
200 if (!rte_lcore_is_enabled(lcore
)) {
201 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore
);
204 if ((socketid
= rte_lcore_to_socket_id(lcore
) != 0) &&
206 printf("warning: lcore %hhu is on socket %d with numa off \n",
214 check_port_config(void)
219 for (i
= 0; i
< nb_lcore_params
; ++i
) {
220 portid
= lcore_params
[i
].port_id
;
221 if ((enabled_port_mask
& (1 << portid
)) == 0) {
222 printf("port %u is not enabled in port mask\n", portid
);
225 if (!rte_eth_dev_is_valid_port(portid
)) {
226 printf("port %u is not present on the board\n", portid
);
234 get_port_n_rx_queues(const uint16_t port
)
239 for (i
= 0; i
< nb_lcore_params
; ++i
) {
240 if (lcore_params
[i
].port_id
== port
) {
241 if (lcore_params
[i
].queue_id
== queue
+1)
242 queue
= lcore_params
[i
].queue_id
;
244 rte_exit(EXIT_FAILURE
, "queue ids of the port %d must be"
245 " in sequence and must start with 0\n",
246 lcore_params
[i
].port_id
);
249 return (uint8_t)(++queue
);
253 init_lcore_rx_queues(void)
255 uint16_t i
, nb_rx_queue
;
258 for (i
= 0; i
< nb_lcore_params
; ++i
) {
259 lcore
= lcore_params
[i
].lcore_id
;
260 nb_rx_queue
= lcore_conf
[lcore
].n_rx_queue
;
261 if (nb_rx_queue
>= MAX_RX_QUEUE_PER_LCORE
) {
262 printf("error: too many queues (%u) for lcore: %u\n",
263 (unsigned)nb_rx_queue
+ 1, (unsigned)lcore
);
266 lcore_conf
[lcore
].rx_queue_list
[nb_rx_queue
].port_id
=
267 lcore_params
[i
].port_id
;
268 lcore_conf
[lcore
].rx_queue_list
[nb_rx_queue
].queue_id
=
269 lcore_params
[i
].queue_id
;
270 lcore_conf
[lcore
].n_rx_queue
++;
278 print_usage(const char *prgname
)
280 fprintf(stderr
, "%s [EAL options] --"
285 " --config (port,queue,lcore)[,(port,queue,lcore)]"
286 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
287 " [--enable-jumbo [--max-pkt-len PKTLEN]]"
289 " [--hash-entry-num]"
292 " [--per-port-pool]\n\n"
294 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
295 " -P : Enable promiscuous mode\n"
296 " -E : Enable exact match\n"
297 " -L : Enable longest prefix match (default)\n"
298 " --config (port,queue,lcore): Rx queue configuration\n"
299 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
300 " --enable-jumbo: Enable jumbo frames\n"
301 " --max-pkt-len: Under the premise of enabling jumbo,\n"
302 " maximum packet length in decimal (64-9600)\n"
303 " --no-numa: Disable numa awareness\n"
304 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
305 " --ipv6: Set if running ipv6 packets\n"
306 " --parse-ptype: Set to use software to analyze packet type\n"
307 " --per-port-pool: Use separate buffer pool per port\n\n",
312 parse_max_pkt_len(const char *pktlen
)
317 /* parse decimal string */
318 len
= strtoul(pktlen
, &end
, 10);
319 if ((pktlen
[0] == '\0') || (end
== NULL
) || (*end
!= '\0'))
329 parse_portmask(const char *portmask
)
334 /* parse hexadecimal string */
335 pm
= strtoul(portmask
, &end
, 16);
336 if ((portmask
[0] == '\0') || (end
== NULL
) || (*end
!= '\0'))
346 parse_hash_entry_number(const char *hash_entry_num
)
349 unsigned long hash_en
;
350 /* parse hexadecimal string */
351 hash_en
= strtoul(hash_entry_num
, &end
, 16);
352 if ((hash_entry_num
[0] == '\0') || (end
== NULL
) || (*end
!= '\0'))
362 parse_config(const char *q_arg
)
365 const char *p
, *p0
= q_arg
;
373 unsigned long int_fld
[_NUM_FLD
];
374 char *str_fld
[_NUM_FLD
];
380 while ((p
= strchr(p0
,'(')) != NULL
) {
382 if((p0
= strchr(p
,')')) == NULL
)
386 if(size
>= sizeof(s
))
389 snprintf(s
, sizeof(s
), "%.*s", size
, p
);
390 if (rte_strsplit(s
, sizeof(s
), str_fld
, _NUM_FLD
, ',') != _NUM_FLD
)
392 for (i
= 0; i
< _NUM_FLD
; i
++){
394 int_fld
[i
] = strtoul(str_fld
[i
], &end
, 0);
395 if (errno
!= 0 || end
== str_fld
[i
] || int_fld
[i
] > 255)
398 if (nb_lcore_params
>= MAX_LCORE_PARAMS
) {
399 printf("exceeded max number of lcore params: %hu\n",
403 lcore_params_array
[nb_lcore_params
].port_id
=
404 (uint8_t)int_fld
[FLD_PORT
];
405 lcore_params_array
[nb_lcore_params
].queue_id
=
406 (uint8_t)int_fld
[FLD_QUEUE
];
407 lcore_params_array
[nb_lcore_params
].lcore_id
=
408 (uint8_t)int_fld
[FLD_LCORE
];
411 lcore_params
= lcore_params_array
;
416 parse_eth_dest(const char *optarg
)
420 uint8_t c
, *dest
, peer_addr
[6];
423 portid
= strtoul(optarg
, &port_end
, 10);
424 if (errno
!= 0 || port_end
== optarg
|| *port_end
++ != ',')
425 rte_exit(EXIT_FAILURE
,
426 "Invalid eth-dest: %s", optarg
);
427 if (portid
>= RTE_MAX_ETHPORTS
)
428 rte_exit(EXIT_FAILURE
,
429 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
430 portid
, RTE_MAX_ETHPORTS
);
432 if (cmdline_parse_etheraddr(NULL
, port_end
,
433 &peer_addr
, sizeof(peer_addr
)) < 0)
434 rte_exit(EXIT_FAILURE
,
435 "Invalid ethernet address: %s\n",
437 dest
= (uint8_t *)&dest_eth_addr
[portid
];
438 for (c
= 0; c
< 6; c
++)
439 dest
[c
] = peer_addr
[c
];
440 *(uint64_t *)(val_eth
+ portid
) = dest_eth_addr
[portid
];
443 #define MAX_JUMBO_PKT_LEN 9600
444 #define MEMPOOL_CACHE_SIZE 256
446 static const char short_options
[] =
448 "P" /* promiscuous */
449 "L" /* enable long prefix match */
450 "E" /* enable exact match */
453 #define CMD_LINE_OPT_CONFIG "config"
454 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
455 #define CMD_LINE_OPT_NO_NUMA "no-numa"
456 #define CMD_LINE_OPT_IPV6 "ipv6"
457 #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
458 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
459 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
460 #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool"
462 /* long options mapped to a short option */
464 /* first long only option value must be >= 256, so that we won't
465 * conflict with short options */
466 CMD_LINE_OPT_MIN_NUM
= 256,
467 CMD_LINE_OPT_CONFIG_NUM
,
468 CMD_LINE_OPT_ETH_DEST_NUM
,
469 CMD_LINE_OPT_NO_NUMA_NUM
,
470 CMD_LINE_OPT_IPV6_NUM
,
471 CMD_LINE_OPT_ENABLE_JUMBO_NUM
,
472 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM
,
473 CMD_LINE_OPT_PARSE_PTYPE_NUM
,
474 CMD_LINE_OPT_PARSE_PER_PORT_POOL
,
477 static const struct option lgopts
[] = {
478 {CMD_LINE_OPT_CONFIG
, 1, 0, CMD_LINE_OPT_CONFIG_NUM
},
479 {CMD_LINE_OPT_ETH_DEST
, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM
},
480 {CMD_LINE_OPT_NO_NUMA
, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM
},
481 {CMD_LINE_OPT_IPV6
, 0, 0, CMD_LINE_OPT_IPV6_NUM
},
482 {CMD_LINE_OPT_ENABLE_JUMBO
, 0, 0, CMD_LINE_OPT_ENABLE_JUMBO_NUM
},
483 {CMD_LINE_OPT_HASH_ENTRY_NUM
, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM
},
484 {CMD_LINE_OPT_PARSE_PTYPE
, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM
},
485 {CMD_LINE_OPT_PER_PORT_POOL
, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL
},
490 * This expression is used to calculate the number of mbufs needed
491 * depending on user input, taking into account memory for rx and
492 * tx hardware rings, cache per lcore and mtable per port per lcore.
493 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
496 #define NB_MBUF(nports) RTE_MAX( \
497 (nports*nb_rx_queue*nb_rxd + \
498 nports*nb_lcores*MAX_PKT_BURST + \
499 nports*n_tx_queue*nb_txd + \
500 nb_lcores*MEMPOOL_CACHE_SIZE), \
503 /* Parse the argument given in the command line of the application */
505 parse_args(int argc
, char **argv
)
510 char *prgname
= argv
[0];
514 /* Error or normal output strings. */
515 while ((opt
= getopt_long(argc
, argvopt
, short_options
,
516 lgopts
, &option_index
)) != EOF
) {
521 enabled_port_mask
= parse_portmask(optarg
);
522 if (enabled_port_mask
== 0) {
523 fprintf(stderr
, "Invalid portmask\n");
524 print_usage(prgname
);
542 case CMD_LINE_OPT_CONFIG_NUM
:
543 ret
= parse_config(optarg
);
545 fprintf(stderr
, "Invalid config\n");
546 print_usage(prgname
);
551 case CMD_LINE_OPT_ETH_DEST_NUM
:
552 parse_eth_dest(optarg
);
555 case CMD_LINE_OPT_NO_NUMA_NUM
:
559 case CMD_LINE_OPT_IPV6_NUM
:
563 case CMD_LINE_OPT_ENABLE_JUMBO_NUM
: {
564 const struct option lenopts
= {
565 "max-pkt-len", required_argument
, 0, 0
568 port_conf
.rxmode
.offloads
|= DEV_RX_OFFLOAD_JUMBO_FRAME
;
569 port_conf
.txmode
.offloads
|= DEV_TX_OFFLOAD_MULTI_SEGS
;
572 * if no max-pkt-len set, use the default
573 * value ETHER_MAX_LEN.
575 if (getopt_long(argc
, argvopt
, "",
576 &lenopts
, &option_index
) == 0) {
577 ret
= parse_max_pkt_len(optarg
);
578 if (ret
< 64 || ret
> MAX_JUMBO_PKT_LEN
) {
580 "invalid maximum packet length\n");
581 print_usage(prgname
);
584 port_conf
.rxmode
.max_rx_pkt_len
= ret
;
589 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM
:
590 ret
= parse_hash_entry_number(optarg
);
591 if ((ret
> 0) && (ret
<= L3FWD_HASH_ENTRIES
)) {
592 hash_entry_number
= ret
;
594 fprintf(stderr
, "invalid hash entry number\n");
595 print_usage(prgname
);
600 case CMD_LINE_OPT_PARSE_PTYPE_NUM
:
601 printf("soft parse-ptype is enabled\n");
605 case CMD_LINE_OPT_PARSE_PER_PORT_POOL
:
606 printf("per port buffer pool is enabled\n");
611 print_usage(prgname
);
616 /* If both LPM and EM are selected, return error. */
617 if (l3fwd_lpm_on
&& l3fwd_em_on
) {
618 fprintf(stderr
, "LPM and EM are mutually exclusive, select only one\n");
623 * Nothing is selected, pick longest-prefix match
626 if (!l3fwd_lpm_on
&& !l3fwd_em_on
) {
627 fprintf(stderr
, "LPM or EM none selected, default LPM on\n");
632 * ipv6 and hash flags are valid only for
633 * exact macth, reset them to default for
634 * longest-prefix match.
638 hash_entry_number
= HASH_ENTRY_NUMBER_DEFAULT
;
642 argv
[optind
-1] = prgname
;
645 optind
= 1; /* reset getopt lib */
650 print_ethaddr(const char *name
, const struct ether_addr
*eth_addr
)
652 char buf
[ETHER_ADDR_FMT_SIZE
];
653 ether_format_addr(buf
, ETHER_ADDR_FMT_SIZE
, eth_addr
);
654 printf("%s%s", name
, buf
);
658 init_mem(uint16_t portid
, unsigned int nb_mbuf
)
660 struct lcore_conf
*qconf
;
665 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
666 if (rte_lcore_is_enabled(lcore_id
) == 0)
670 socketid
= rte_lcore_to_socket_id(lcore_id
);
674 if (socketid
>= NB_SOCKETS
) {
675 rte_exit(EXIT_FAILURE
,
676 "Socket %d of lcore %u is out of range %d\n",
677 socketid
, lcore_id
, NB_SOCKETS
);
680 if (pktmbuf_pool
[portid
][socketid
] == NULL
) {
681 snprintf(s
, sizeof(s
), "mbuf_pool_%d:%d",
683 pktmbuf_pool
[portid
][socketid
] =
684 rte_pktmbuf_pool_create(s
, nb_mbuf
,
685 MEMPOOL_CACHE_SIZE
, 0,
686 RTE_MBUF_DEFAULT_BUF_SIZE
, socketid
);
687 if (pktmbuf_pool
[portid
][socketid
] == NULL
)
688 rte_exit(EXIT_FAILURE
,
689 "Cannot init mbuf pool on socket %d\n",
692 printf("Allocated mbuf pool on socket %d\n",
695 /* Setup either LPM or EM(f.e Hash). But, only once per
698 if (!lkp_per_socket
[socketid
]) {
699 l3fwd_lkp
.setup(socketid
);
700 lkp_per_socket
[socketid
] = 1;
703 qconf
= &lcore_conf
[lcore_id
];
704 qconf
->ipv4_lookup_struct
=
705 l3fwd_lkp
.get_ipv4_lookup_struct(socketid
);
706 qconf
->ipv6_lookup_struct
=
707 l3fwd_lkp
.get_ipv6_lookup_struct(socketid
);
712 /* Check the link status of all ports in up to 9s, and print them finally */
714 check_all_ports_link_status(uint32_t port_mask
)
716 #define CHECK_INTERVAL 100 /* 100ms */
717 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
719 uint8_t count
, all_ports_up
, print_flag
= 0;
720 struct rte_eth_link link
;
722 printf("\nChecking link status");
724 for (count
= 0; count
<= MAX_CHECK_TIME
; count
++) {
728 RTE_ETH_FOREACH_DEV(portid
) {
731 if ((port_mask
& (1 << portid
)) == 0)
733 memset(&link
, 0, sizeof(link
));
734 rte_eth_link_get_nowait(portid
, &link
);
735 /* print link status if flag set */
736 if (print_flag
== 1) {
737 if (link
.link_status
)
739 "Port%d Link Up. Speed %u Mbps -%s\n",
740 portid
, link
.link_speed
,
741 (link
.link_duplex
== ETH_LINK_FULL_DUPLEX
) ?
742 ("full-duplex") : ("half-duplex\n"));
744 printf("Port %d Link Down\n", portid
);
747 /* clear all_ports_up flag if any link down */
748 if (link
.link_status
== ETH_LINK_DOWN
) {
753 /* after finally printing all link status, get out */
757 if (all_ports_up
== 0) {
760 rte_delay_ms(CHECK_INTERVAL
);
763 /* set the print_flag if all ports up or timeout */
764 if (all_ports_up
== 1 || count
== (MAX_CHECK_TIME
- 1)) {
772 signal_handler(int signum
)
774 if (signum
== SIGINT
|| signum
== SIGTERM
) {
775 printf("\n\nSignal %d received, preparing to exit...\n",
782 prepare_ptype_parser(uint16_t portid
, uint16_t queueid
)
785 printf("Port %d: softly parse packet type info\n", portid
);
786 if (rte_eth_add_rx_callback(portid
, queueid
,
787 l3fwd_lkp
.cb_parse_ptype
,
791 printf("Failed to add rx callback: port=%d\n", portid
);
795 if (l3fwd_lkp
.check_ptype(portid
))
798 printf("port %d cannot parse packet type, please add --%s\n",
799 portid
, CMD_LINE_OPT_PARSE_PTYPE
);
804 main(int argc
, char **argv
)
806 struct lcore_conf
*qconf
;
807 struct rte_eth_dev_info dev_info
;
808 struct rte_eth_txconf
*txconf
;
811 uint16_t queueid
, portid
;
813 uint32_t n_tx_queue
, nb_lcores
;
814 uint8_t nb_rx_queue
, queue
, socketid
;
817 ret
= rte_eal_init(argc
, argv
);
819 rte_exit(EXIT_FAILURE
, "Invalid EAL parameters\n");
824 signal(SIGINT
, signal_handler
);
825 signal(SIGTERM
, signal_handler
);
827 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
828 for (portid
= 0; portid
< RTE_MAX_ETHPORTS
; portid
++) {
829 dest_eth_addr
[portid
] =
830 ETHER_LOCAL_ADMIN_ADDR
+ ((uint64_t)portid
<< 40);
831 *(uint64_t *)(val_eth
+ portid
) = dest_eth_addr
[portid
];
834 /* parse application arguments (after the EAL ones) */
835 ret
= parse_args(argc
, argv
);
837 rte_exit(EXIT_FAILURE
, "Invalid L3FWD parameters\n");
839 if (check_lcore_params() < 0)
840 rte_exit(EXIT_FAILURE
, "check_lcore_params failed\n");
842 ret
= init_lcore_rx_queues();
844 rte_exit(EXIT_FAILURE
, "init_lcore_rx_queues failed\n");
846 nb_ports
= rte_eth_dev_count_avail();
848 if (check_port_config() < 0)
849 rte_exit(EXIT_FAILURE
, "check_port_config failed\n");
851 nb_lcores
= rte_lcore_count();
853 /* Setup function pointers for lookup method. */
854 setup_l3fwd_lookup_tables();
856 /* initialize all ports */
857 RTE_ETH_FOREACH_DEV(portid
) {
858 struct rte_eth_conf local_port_conf
= port_conf
;
860 /* skip ports that are not enabled */
861 if ((enabled_port_mask
& (1 << portid
)) == 0) {
862 printf("\nSkipping disabled port %d\n", portid
);
867 printf("Initializing port %d ... ", portid
);
870 nb_rx_queue
= get_port_n_rx_queues(portid
);
871 n_tx_queue
= nb_lcores
;
872 if (n_tx_queue
> MAX_TX_QUEUE_PER_PORT
)
873 n_tx_queue
= MAX_TX_QUEUE_PER_PORT
;
874 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
875 nb_rx_queue
, (unsigned)n_tx_queue
);
877 rte_eth_dev_info_get(portid
, &dev_info
);
878 if (dev_info
.tx_offload_capa
& DEV_TX_OFFLOAD_MBUF_FAST_FREE
)
879 local_port_conf
.txmode
.offloads
|=
880 DEV_TX_OFFLOAD_MBUF_FAST_FREE
;
882 local_port_conf
.rx_adv_conf
.rss_conf
.rss_hf
&=
883 dev_info
.flow_type_rss_offloads
;
884 if (local_port_conf
.rx_adv_conf
.rss_conf
.rss_hf
!=
885 port_conf
.rx_adv_conf
.rss_conf
.rss_hf
) {
886 printf("Port %u modified RSS hash function based on hardware support,"
887 "requested:%#"PRIx64
" configured:%#"PRIx64
"\n",
889 port_conf
.rx_adv_conf
.rss_conf
.rss_hf
,
890 local_port_conf
.rx_adv_conf
.rss_conf
.rss_hf
);
893 ret
= rte_eth_dev_configure(portid
, nb_rx_queue
,
894 (uint16_t)n_tx_queue
, &local_port_conf
);
896 rte_exit(EXIT_FAILURE
,
897 "Cannot configure device: err=%d, port=%d\n",
900 ret
= rte_eth_dev_adjust_nb_rx_tx_desc(portid
, &nb_rxd
,
903 rte_exit(EXIT_FAILURE
,
904 "Cannot adjust number of descriptors: err=%d, "
905 "port=%d\n", ret
, portid
);
907 rte_eth_macaddr_get(portid
, &ports_eth_addr
[portid
]);
908 print_ethaddr(" Address:", &ports_eth_addr
[portid
]);
910 print_ethaddr("Destination:",
911 (const struct ether_addr
*)&dest_eth_addr
[portid
]);
915 * prepare src MACs for each port.
917 ether_addr_copy(&ports_eth_addr
[portid
],
918 (struct ether_addr
*)(val_eth
+ portid
) + 1);
921 if (!per_port_pool
) {
922 /* portid = 0; this is *not* signifying the first port,
923 * rather, it signifies that portid is ignored.
925 ret
= init_mem(0, NB_MBUF(nb_ports
));
927 ret
= init_mem(portid
, NB_MBUF(1));
930 rte_exit(EXIT_FAILURE
, "init_mem failed\n");
932 /* init one TX queue per couple (lcore,port) */
934 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
935 if (rte_lcore_is_enabled(lcore_id
) == 0)
940 (uint8_t)rte_lcore_to_socket_id(lcore_id
);
944 printf("txq=%u,%d,%d ", lcore_id
, queueid
, socketid
);
947 txconf
= &dev_info
.default_txconf
;
948 txconf
->offloads
= local_port_conf
.txmode
.offloads
;
949 ret
= rte_eth_tx_queue_setup(portid
, queueid
, nb_txd
,
952 rte_exit(EXIT_FAILURE
,
953 "rte_eth_tx_queue_setup: err=%d, "
954 "port=%d\n", ret
, portid
);
956 qconf
= &lcore_conf
[lcore_id
];
957 qconf
->tx_queue_id
[portid
] = queueid
;
960 qconf
->tx_port_id
[qconf
->n_tx_port
] = portid
;
966 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
967 if (rte_lcore_is_enabled(lcore_id
) == 0)
969 qconf
= &lcore_conf
[lcore_id
];
970 printf("\nInitializing rx queues on lcore %u ... ", lcore_id
);
973 for(queue
= 0; queue
< qconf
->n_rx_queue
; ++queue
) {
974 struct rte_eth_dev
*dev
;
975 struct rte_eth_conf
*conf
;
976 struct rte_eth_rxconf rxq_conf
;
978 portid
= qconf
->rx_queue_list
[queue
].port_id
;
979 queueid
= qconf
->rx_queue_list
[queue
].queue_id
;
980 dev
= &rte_eth_devices
[portid
];
981 conf
= &dev
->data
->dev_conf
;
985 (uint8_t)rte_lcore_to_socket_id(lcore_id
);
989 printf("rxq=%d,%d,%d ", portid
, queueid
, socketid
);
992 rte_eth_dev_info_get(portid
, &dev_info
);
993 rxq_conf
= dev_info
.default_rxconf
;
994 rxq_conf
.offloads
= conf
->rxmode
.offloads
;
996 ret
= rte_eth_rx_queue_setup(portid
, queueid
,
999 pktmbuf_pool
[0][socketid
]);
1001 ret
= rte_eth_rx_queue_setup(portid
, queueid
,
1004 pktmbuf_pool
[portid
][socketid
]);
1006 rte_exit(EXIT_FAILURE
,
1007 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
1015 RTE_ETH_FOREACH_DEV(portid
) {
1016 if ((enabled_port_mask
& (1 << portid
)) == 0) {
1020 ret
= rte_eth_dev_start(portid
);
1022 rte_exit(EXIT_FAILURE
,
1023 "rte_eth_dev_start: err=%d, port=%d\n",
1027 * If enabled, put device in promiscuous mode.
1028 * This allows IO forwarding mode to forward packets
1029 * to itself through 2 cross-connected ports of the
1033 rte_eth_promiscuous_enable(portid
);
1038 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
1039 if (rte_lcore_is_enabled(lcore_id
) == 0)
1041 qconf
= &lcore_conf
[lcore_id
];
1042 for (queue
= 0; queue
< qconf
->n_rx_queue
; ++queue
) {
1043 portid
= qconf
->rx_queue_list
[queue
].port_id
;
1044 queueid
= qconf
->rx_queue_list
[queue
].queue_id
;
1045 if (prepare_ptype_parser(portid
, queueid
) == 0)
1046 rte_exit(EXIT_FAILURE
, "ptype check fails\n");
1051 check_all_ports_link_status(enabled_port_mask
);
1054 /* launch per-lcore init on every lcore */
1055 rte_eal_mp_remote_launch(l3fwd_lkp
.main_loop
, NULL
, CALL_MASTER
);
1056 RTE_LCORE_FOREACH_SLAVE(lcore_id
) {
1057 if (rte_eal_wait_lcore(lcore_id
) < 0) {
1064 RTE_ETH_FOREACH_DEV(portid
) {
1065 if ((enabled_port_mask
& (1 << portid
)) == 0)
1067 printf("Closing port %d...", portid
);
1068 rte_eth_dev_stop(portid
);
1069 rte_eth_dev_close(portid
);