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 static int numa_on = 1; /**< NUMA is enabled by default. */
73 static int parse_ptype; /**< Parse packet type using rx callback, and */
74 /**< disabled by default */
76 /* Global variables. */
78 volatile bool force_quit;
80 /* ethernet addresses of ports */
81 uint64_t dest_eth_addr[RTE_MAX_ETHPORTS];
82 struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
84 xmm_t val_eth[RTE_MAX_ETHPORTS];
86 /* mask of enabled ports */
87 uint32_t enabled_port_mask;
89 /* Used only in exact match mode. */
90 int ipv6; /**< ipv6 is false by default. */
91 uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
93 struct lcore_conf lcore_conf[RTE_MAX_LCORE];
99 } __rte_cache_aligned;
101 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
102 static struct lcore_params lcore_params_array_default[] = {
114 static struct lcore_params * lcore_params = lcore_params_array_default;
115 static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
116 sizeof(lcore_params_array_default[0]);
118 static struct rte_eth_conf port_conf = {
120 .mq_mode = ETH_MQ_RX_RSS,
121 .max_rx_pkt_len = ETHER_MAX_LEN,
123 .ignore_offload_bitfield = 1,
124 .offloads = (DEV_RX_OFFLOAD_CRC_STRIP |
125 DEV_RX_OFFLOAD_CHECKSUM),
130 .rss_hf = ETH_RSS_IP,
134 .mq_mode = ETH_MQ_TX_NONE,
138 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
140 struct l3fwd_lkp_mode {
142 int (*check_ptype)(int);
143 rte_rx_callback_fn cb_parse_ptype;
144 int (*main_loop)(void *);
145 void* (*get_ipv4_lookup_struct)(int);
146 void* (*get_ipv6_lookup_struct)(int);
149 static struct l3fwd_lkp_mode l3fwd_lkp;
151 static struct l3fwd_lkp_mode l3fwd_em_lkp = {
153 .check_ptype = em_check_ptype,
154 .cb_parse_ptype = em_cb_parse_ptype,
155 .main_loop = em_main_loop,
156 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct,
157 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct,
160 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = {
162 .check_ptype = lpm_check_ptype,
163 .cb_parse_ptype = lpm_cb_parse_ptype,
164 .main_loop = lpm_main_loop,
165 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct,
166 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct,
170 * Setup lookup methods for forwarding.
171 * Currently exact-match and longest-prefix-match
172 * are supported ones.
175 setup_l3fwd_lookup_tables(void)
177 /* Setup HASH lookup functions. */
179 l3fwd_lkp = l3fwd_em_lkp;
180 /* Setup LPM lookup functions. */
182 l3fwd_lkp = l3fwd_lpm_lkp;
186 check_lcore_params(void)
188 uint8_t queue, lcore;
192 for (i = 0; i < nb_lcore_params; ++i) {
193 queue = lcore_params[i].queue_id;
194 if (queue >= MAX_RX_QUEUE_PER_PORT) {
195 printf("invalid queue number: %hhu\n", queue);
198 lcore = lcore_params[i].lcore_id;
199 if (!rte_lcore_is_enabled(lcore)) {
200 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
203 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
205 printf("warning: lcore %hhu is on socket %d with numa off \n",
213 check_port_config(const unsigned nb_ports)
218 for (i = 0; i < nb_lcore_params; ++i) {
219 portid = lcore_params[i].port_id;
220 if ((enabled_port_mask & (1 << portid)) == 0) {
221 printf("port %u is not enabled in port mask\n", portid);
224 if (portid >= nb_ports) {
225 printf("port %u is not present on the board\n", portid);
233 get_port_n_rx_queues(const uint16_t port)
238 for (i = 0; i < nb_lcore_params; ++i) {
239 if (lcore_params[i].port_id == port) {
240 if (lcore_params[i].queue_id == queue+1)
241 queue = lcore_params[i].queue_id;
243 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be"
244 " in sequence and must start with 0\n",
245 lcore_params[i].port_id);
248 return (uint8_t)(++queue);
252 init_lcore_rx_queues(void)
254 uint16_t i, nb_rx_queue;
257 for (i = 0; i < nb_lcore_params; ++i) {
258 lcore = lcore_params[i].lcore_id;
259 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
260 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
261 printf("error: too many queues (%u) for lcore: %u\n",
262 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
265 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
266 lcore_params[i].port_id;
267 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
268 lcore_params[i].queue_id;
269 lcore_conf[lcore].n_rx_queue++;
277 print_usage(const char *prgname)
279 fprintf(stderr, "%s [EAL options] --"
284 " --config (port,queue,lcore)[,(port,queue,lcore)]"
285 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
286 " [--enable-jumbo [--max-pkt-len PKTLEN]]"
288 " [--hash-entry-num]"
290 " [--parse-ptype]\n\n"
292 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
293 " -P : Enable promiscuous mode\n"
294 " -E : Enable exact match\n"
295 " -L : Enable longest prefix match (default)\n"
296 " --config (port,queue,lcore): Rx queue configuration\n"
297 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
298 " --enable-jumbo: Enable jumbo frames\n"
299 " --max-pkt-len: Under the premise of enabling jumbo,\n"
300 " maximum packet length in decimal (64-9600)\n"
301 " --no-numa: Disable numa awareness\n"
302 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
303 " --ipv6: Set if running ipv6 packets\n"
304 " --parse-ptype: Set to use software to analyze packet type\n\n",
309 parse_max_pkt_len(const char *pktlen)
314 /* parse decimal string */
315 len = strtoul(pktlen, &end, 10);
316 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
326 parse_portmask(const char *portmask)
331 /* parse hexadecimal string */
332 pm = strtoul(portmask, &end, 16);
333 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
343 parse_hash_entry_number(const char *hash_entry_num)
346 unsigned long hash_en;
347 /* parse hexadecimal string */
348 hash_en = strtoul(hash_entry_num, &end, 16);
349 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
359 parse_config(const char *q_arg)
362 const char *p, *p0 = q_arg;
370 unsigned long int_fld[_NUM_FLD];
371 char *str_fld[_NUM_FLD];
377 while ((p = strchr(p0,'(')) != NULL) {
379 if((p0 = strchr(p,')')) == NULL)
383 if(size >= sizeof(s))
386 snprintf(s, sizeof(s), "%.*s", size, p);
387 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
389 for (i = 0; i < _NUM_FLD; i++){
391 int_fld[i] = strtoul(str_fld[i], &end, 0);
392 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
395 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
396 printf("exceeded max number of lcore params: %hu\n",
400 lcore_params_array[nb_lcore_params].port_id =
401 (uint8_t)int_fld[FLD_PORT];
402 lcore_params_array[nb_lcore_params].queue_id =
403 (uint8_t)int_fld[FLD_QUEUE];
404 lcore_params_array[nb_lcore_params].lcore_id =
405 (uint8_t)int_fld[FLD_LCORE];
408 lcore_params = lcore_params_array;
413 parse_eth_dest(const char *optarg)
417 uint8_t c, *dest, peer_addr[6];
420 portid = strtoul(optarg, &port_end, 10);
421 if (errno != 0 || port_end == optarg || *port_end++ != ',')
422 rte_exit(EXIT_FAILURE,
423 "Invalid eth-dest: %s", optarg);
424 if (portid >= RTE_MAX_ETHPORTS)
425 rte_exit(EXIT_FAILURE,
426 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
427 portid, RTE_MAX_ETHPORTS);
429 if (cmdline_parse_etheraddr(NULL, port_end,
430 &peer_addr, sizeof(peer_addr)) < 0)
431 rte_exit(EXIT_FAILURE,
432 "Invalid ethernet address: %s\n",
434 dest = (uint8_t *)&dest_eth_addr[portid];
435 for (c = 0; c < 6; c++)
436 dest[c] = peer_addr[c];
437 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
440 #define MAX_JUMBO_PKT_LEN 9600
441 #define MEMPOOL_CACHE_SIZE 256
443 static const char short_options[] =
445 "P" /* promiscuous */
446 "L" /* enable long prefix match */
447 "E" /* enable exact match */
450 #define CMD_LINE_OPT_CONFIG "config"
451 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
452 #define CMD_LINE_OPT_NO_NUMA "no-numa"
453 #define CMD_LINE_OPT_IPV6 "ipv6"
454 #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
455 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
456 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
458 /* long options mapped to a short option */
460 /* first long only option value must be >= 256, so that we won't
461 * conflict with short options */
462 CMD_LINE_OPT_MIN_NUM = 256,
463 CMD_LINE_OPT_CONFIG_NUM,
464 CMD_LINE_OPT_ETH_DEST_NUM,
465 CMD_LINE_OPT_NO_NUMA_NUM,
466 CMD_LINE_OPT_IPV6_NUM,
467 CMD_LINE_OPT_ENABLE_JUMBO_NUM,
468 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM,
469 CMD_LINE_OPT_PARSE_PTYPE_NUM,
472 static const struct option lgopts[] = {
473 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
474 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM},
475 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM},
476 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM},
477 {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, CMD_LINE_OPT_ENABLE_JUMBO_NUM},
478 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM},
479 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM},
484 * This expression is used to calculate the number of mbufs needed
485 * depending on user input, taking into account memory for rx and
486 * tx hardware rings, cache per lcore and mtable per port per lcore.
487 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
490 #define NB_MBUF RTE_MAX( \
491 (nb_ports*nb_rx_queue*nb_rxd + \
492 nb_ports*nb_lcores*MAX_PKT_BURST + \
493 nb_ports*n_tx_queue*nb_txd + \
494 nb_lcores*MEMPOOL_CACHE_SIZE), \
497 /* Parse the argument given in the command line of the application */
499 parse_args(int argc, char **argv)
504 char *prgname = argv[0];
508 /* Error or normal output strings. */
509 while ((opt = getopt_long(argc, argvopt, short_options,
510 lgopts, &option_index)) != EOF) {
515 enabled_port_mask = parse_portmask(optarg);
516 if (enabled_port_mask == 0) {
517 fprintf(stderr, "Invalid portmask\n");
518 print_usage(prgname);
536 case CMD_LINE_OPT_CONFIG_NUM:
537 ret = parse_config(optarg);
539 fprintf(stderr, "Invalid config\n");
540 print_usage(prgname);
545 case CMD_LINE_OPT_ETH_DEST_NUM:
546 parse_eth_dest(optarg);
549 case CMD_LINE_OPT_NO_NUMA_NUM:
553 case CMD_LINE_OPT_IPV6_NUM:
557 case CMD_LINE_OPT_ENABLE_JUMBO_NUM: {
558 const struct option lenopts = {
559 "max-pkt-len", required_argument, 0, 0
562 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
563 port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
566 * if no max-pkt-len set, use the default
567 * value ETHER_MAX_LEN.
569 if (getopt_long(argc, argvopt, "",
570 &lenopts, &option_index) == 0) {
571 ret = parse_max_pkt_len(optarg);
572 if (ret < 64 || ret > MAX_JUMBO_PKT_LEN) {
574 "invalid maximum packet length\n");
575 print_usage(prgname);
578 port_conf.rxmode.max_rx_pkt_len = ret;
583 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM:
584 ret = parse_hash_entry_number(optarg);
585 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
586 hash_entry_number = ret;
588 fprintf(stderr, "invalid hash entry number\n");
589 print_usage(prgname);
594 case CMD_LINE_OPT_PARSE_PTYPE_NUM:
595 printf("soft parse-ptype is enabled\n");
600 print_usage(prgname);
605 /* If both LPM and EM are selected, return error. */
606 if (l3fwd_lpm_on && l3fwd_em_on) {
607 fprintf(stderr, "LPM and EM are mutually exclusive, select only one\n");
612 * Nothing is selected, pick longest-prefix match
615 if (!l3fwd_lpm_on && !l3fwd_em_on) {
616 fprintf(stderr, "LPM or EM none selected, default LPM on\n");
621 * ipv6 and hash flags are valid only for
622 * exact macth, reset them to default for
623 * longest-prefix match.
627 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
631 argv[optind-1] = prgname;
634 optind = 1; /* reset getopt lib */
639 print_ethaddr(const char *name, const struct ether_addr *eth_addr)
641 char buf[ETHER_ADDR_FMT_SIZE];
642 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
643 printf("%s%s", name, buf);
647 init_mem(unsigned nb_mbuf)
649 struct lcore_conf *qconf;
654 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
655 if (rte_lcore_is_enabled(lcore_id) == 0)
659 socketid = rte_lcore_to_socket_id(lcore_id);
663 if (socketid >= NB_SOCKETS) {
664 rte_exit(EXIT_FAILURE,
665 "Socket %d of lcore %u is out of range %d\n",
666 socketid, lcore_id, NB_SOCKETS);
669 if (pktmbuf_pool[socketid] == NULL) {
670 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
671 pktmbuf_pool[socketid] =
672 rte_pktmbuf_pool_create(s, nb_mbuf,
673 MEMPOOL_CACHE_SIZE, 0,
674 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
675 if (pktmbuf_pool[socketid] == NULL)
676 rte_exit(EXIT_FAILURE,
677 "Cannot init mbuf pool on socket %d\n",
680 printf("Allocated mbuf pool on socket %d\n",
683 /* Setup either LPM or EM(f.e Hash). */
684 l3fwd_lkp.setup(socketid);
686 qconf = &lcore_conf[lcore_id];
687 qconf->ipv4_lookup_struct =
688 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
689 qconf->ipv6_lookup_struct =
690 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
695 /* Check the link status of all ports in up to 9s, and print them finally */
697 check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
699 #define CHECK_INTERVAL 100 /* 100ms */
700 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
702 uint8_t count, all_ports_up, print_flag = 0;
703 struct rte_eth_link link;
705 printf("\nChecking link status");
707 for (count = 0; count <= MAX_CHECK_TIME; count++) {
711 for (portid = 0; portid < port_num; portid++) {
714 if ((port_mask & (1 << portid)) == 0)
716 memset(&link, 0, sizeof(link));
717 rte_eth_link_get_nowait(portid, &link);
718 /* print link status if flag set */
719 if (print_flag == 1) {
720 if (link.link_status)
722 "Port%d Link Up. Speed %u Mbps -%s\n",
723 portid, link.link_speed,
724 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
725 ("full-duplex") : ("half-duplex\n"));
727 printf("Port %d Link Down\n", portid);
730 /* clear all_ports_up flag if any link down */
731 if (link.link_status == ETH_LINK_DOWN) {
736 /* after finally printing all link status, get out */
740 if (all_ports_up == 0) {
743 rte_delay_ms(CHECK_INTERVAL);
746 /* set the print_flag if all ports up or timeout */
747 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
755 signal_handler(int signum)
757 if (signum == SIGINT || signum == SIGTERM) {
758 printf("\n\nSignal %d received, preparing to exit...\n",
765 prepare_ptype_parser(uint16_t portid, uint16_t queueid)
768 printf("Port %d: softly parse packet type info\n", portid);
769 if (rte_eth_add_rx_callback(portid, queueid,
770 l3fwd_lkp.cb_parse_ptype,
774 printf("Failed to add rx callback: port=%d\n", portid);
778 if (l3fwd_lkp.check_ptype(portid))
781 printf("port %d cannot parse packet type, please add --%s\n",
782 portid, CMD_LINE_OPT_PARSE_PTYPE);
787 main(int argc, char **argv)
789 struct lcore_conf *qconf;
790 struct rte_eth_dev_info dev_info;
791 struct rte_eth_txconf *txconf;
794 uint16_t queueid, portid;
796 uint32_t n_tx_queue, nb_lcores;
797 uint8_t nb_rx_queue, queue, socketid;
800 ret = rte_eal_init(argc, argv);
802 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
807 signal(SIGINT, signal_handler);
808 signal(SIGTERM, signal_handler);
810 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
811 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
812 dest_eth_addr[portid] =
813 ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
814 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
817 /* parse application arguments (after the EAL ones) */
818 ret = parse_args(argc, argv);
820 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
822 if (check_lcore_params() < 0)
823 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
825 ret = init_lcore_rx_queues();
827 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
829 nb_ports = rte_eth_dev_count();
831 if (check_port_config(nb_ports) < 0)
832 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
834 nb_lcores = rte_lcore_count();
836 /* Setup function pointers for lookup method. */
837 setup_l3fwd_lookup_tables();
839 /* initialize all ports */
840 for (portid = 0; portid < nb_ports; portid++) {
841 struct rte_eth_conf local_port_conf = port_conf;
843 /* skip ports that are not enabled */
844 if ((enabled_port_mask & (1 << portid)) == 0) {
845 printf("\nSkipping disabled port %d\n", portid);
850 printf("Initializing port %d ... ", portid );
853 nb_rx_queue = get_port_n_rx_queues(portid);
854 n_tx_queue = nb_lcores;
855 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
856 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
857 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
858 nb_rx_queue, (unsigned)n_tx_queue );
860 rte_eth_dev_info_get(portid, &dev_info);
861 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
862 local_port_conf.txmode.offloads |=
863 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
864 ret = rte_eth_dev_configure(portid, nb_rx_queue,
865 (uint16_t)n_tx_queue, &local_port_conf);
867 rte_exit(EXIT_FAILURE,
868 "Cannot configure device: err=%d, port=%d\n",
871 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
874 rte_exit(EXIT_FAILURE,
875 "Cannot adjust number of descriptors: err=%d, "
876 "port=%d\n", ret, portid);
878 rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
879 print_ethaddr(" Address:", &ports_eth_addr[portid]);
881 print_ethaddr("Destination:",
882 (const struct ether_addr *)&dest_eth_addr[portid]);
886 * prepare src MACs for each port.
888 ether_addr_copy(&ports_eth_addr[portid],
889 (struct ether_addr *)(val_eth + portid) + 1);
892 ret = init_mem(NB_MBUF);
894 rte_exit(EXIT_FAILURE, "init_mem failed\n");
896 /* init one TX queue per couple (lcore,port) */
898 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
899 if (rte_lcore_is_enabled(lcore_id) == 0)
904 (uint8_t)rte_lcore_to_socket_id(lcore_id);
908 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
911 txconf = &dev_info.default_txconf;
912 txconf->txq_flags = ETH_TXQ_FLAGS_IGNORE;
913 txconf->offloads = local_port_conf.txmode.offloads;
914 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
917 rte_exit(EXIT_FAILURE,
918 "rte_eth_tx_queue_setup: err=%d, "
919 "port=%d\n", ret, portid);
921 qconf = &lcore_conf[lcore_id];
922 qconf->tx_queue_id[portid] = queueid;
925 qconf->tx_port_id[qconf->n_tx_port] = portid;
931 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
932 if (rte_lcore_is_enabled(lcore_id) == 0)
934 qconf = &lcore_conf[lcore_id];
935 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
938 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
939 struct rte_eth_dev *dev;
940 struct rte_eth_conf *conf;
941 struct rte_eth_rxconf rxq_conf;
943 portid = qconf->rx_queue_list[queue].port_id;
944 queueid = qconf->rx_queue_list[queue].queue_id;
945 dev = &rte_eth_devices[portid];
946 conf = &dev->data->dev_conf;
950 (uint8_t)rte_lcore_to_socket_id(lcore_id);
954 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
957 rte_eth_dev_info_get(portid, &dev_info);
958 rxq_conf = dev_info.default_rxconf;
959 rxq_conf.offloads = conf->rxmode.offloads;
960 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
963 pktmbuf_pool[socketid]);
965 rte_exit(EXIT_FAILURE,
966 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
974 for (portid = 0; portid < nb_ports; portid++) {
975 if ((enabled_port_mask & (1 << portid)) == 0) {
979 ret = rte_eth_dev_start(portid);
981 rte_exit(EXIT_FAILURE,
982 "rte_eth_dev_start: err=%d, port=%d\n",
986 * If enabled, put device in promiscuous mode.
987 * This allows IO forwarding mode to forward packets
988 * to itself through 2 cross-connected ports of the
992 rte_eth_promiscuous_enable(portid);
997 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
998 if (rte_lcore_is_enabled(lcore_id) == 0)
1000 qconf = &lcore_conf[lcore_id];
1001 for (queue = 0; queue < qconf->n_rx_queue; ++queue) {
1002 portid = qconf->rx_queue_list[queue].port_id;
1003 queueid = qconf->rx_queue_list[queue].queue_id;
1004 if (prepare_ptype_parser(portid, queueid) == 0)
1005 rte_exit(EXIT_FAILURE, "ptype check fails\n");
1010 check_all_ports_link_status(nb_ports, enabled_port_mask);
1013 /* launch per-lcore init on every lcore */
1014 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER);
1015 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1016 if (rte_eal_wait_lcore(lcore_id) < 0) {
1023 for (portid = 0; portid < nb_ports; portid++) {
1024 if ((enabled_port_mask & (1 << portid)) == 0)
1026 printf("Closing port %d...", portid);
1027 rte_eth_dev_stop(portid);
1028 rte_eth_dev_close(portid);