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 .offloads = (DEV_RX_OFFLOAD_CRC_STRIP |
124 DEV_RX_OFFLOAD_CHECKSUM),
129 .rss_hf = ETH_RSS_IP,
133 .mq_mode = ETH_MQ_TX_NONE,
137 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
139 struct l3fwd_lkp_mode {
141 int (*check_ptype)(int);
142 rte_rx_callback_fn cb_parse_ptype;
143 int (*main_loop)(void *);
144 void* (*get_ipv4_lookup_struct)(int);
145 void* (*get_ipv6_lookup_struct)(int);
148 static struct l3fwd_lkp_mode l3fwd_lkp;
150 static struct l3fwd_lkp_mode l3fwd_em_lkp = {
152 .check_ptype = em_check_ptype,
153 .cb_parse_ptype = em_cb_parse_ptype,
154 .main_loop = em_main_loop,
155 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct,
156 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct,
159 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = {
161 .check_ptype = lpm_check_ptype,
162 .cb_parse_ptype = lpm_cb_parse_ptype,
163 .main_loop = lpm_main_loop,
164 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct,
165 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct,
169 * Setup lookup methods for forwarding.
170 * Currently exact-match and longest-prefix-match
171 * are supported ones.
174 setup_l3fwd_lookup_tables(void)
176 /* Setup HASH lookup functions. */
178 l3fwd_lkp = l3fwd_em_lkp;
179 /* Setup LPM lookup functions. */
181 l3fwd_lkp = l3fwd_lpm_lkp;
185 check_lcore_params(void)
187 uint8_t queue, lcore;
191 for (i = 0; i < nb_lcore_params; ++i) {
192 queue = lcore_params[i].queue_id;
193 if (queue >= MAX_RX_QUEUE_PER_PORT) {
194 printf("invalid queue number: %hhu\n", queue);
197 lcore = lcore_params[i].lcore_id;
198 if (!rte_lcore_is_enabled(lcore)) {
199 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
202 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
204 printf("warning: lcore %hhu is on socket %d with numa off \n",
212 check_port_config(void)
217 for (i = 0; i < nb_lcore_params; ++i) {
218 portid = lcore_params[i].port_id;
219 if ((enabled_port_mask & (1 << portid)) == 0) {
220 printf("port %u is not enabled in port mask\n", portid);
223 if (!rte_eth_dev_is_valid_port(portid)) {
224 printf("port %u is not present on the board\n", portid);
232 get_port_n_rx_queues(const uint16_t port)
237 for (i = 0; i < nb_lcore_params; ++i) {
238 if (lcore_params[i].port_id == port) {
239 if (lcore_params[i].queue_id == queue+1)
240 queue = lcore_params[i].queue_id;
242 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be"
243 " in sequence and must start with 0\n",
244 lcore_params[i].port_id);
247 return (uint8_t)(++queue);
251 init_lcore_rx_queues(void)
253 uint16_t i, nb_rx_queue;
256 for (i = 0; i < nb_lcore_params; ++i) {
257 lcore = lcore_params[i].lcore_id;
258 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
259 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
260 printf("error: too many queues (%u) for lcore: %u\n",
261 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
264 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
265 lcore_params[i].port_id;
266 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
267 lcore_params[i].queue_id;
268 lcore_conf[lcore].n_rx_queue++;
276 print_usage(const char *prgname)
278 fprintf(stderr, "%s [EAL options] --"
283 " --config (port,queue,lcore)[,(port,queue,lcore)]"
284 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
285 " [--enable-jumbo [--max-pkt-len PKTLEN]]"
287 " [--hash-entry-num]"
289 " [--parse-ptype]\n\n"
291 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
292 " -P : Enable promiscuous mode\n"
293 " -E : Enable exact match\n"
294 " -L : Enable longest prefix match (default)\n"
295 " --config (port,queue,lcore): Rx queue configuration\n"
296 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
297 " --enable-jumbo: Enable jumbo frames\n"
298 " --max-pkt-len: Under the premise of enabling jumbo,\n"
299 " maximum packet length in decimal (64-9600)\n"
300 " --no-numa: Disable numa awareness\n"
301 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
302 " --ipv6: Set if running ipv6 packets\n"
303 " --parse-ptype: Set to use software to analyze packet type\n\n",
308 parse_max_pkt_len(const char *pktlen)
313 /* parse decimal string */
314 len = strtoul(pktlen, &end, 10);
315 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
325 parse_portmask(const char *portmask)
330 /* parse hexadecimal string */
331 pm = strtoul(portmask, &end, 16);
332 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
342 parse_hash_entry_number(const char *hash_entry_num)
345 unsigned long hash_en;
346 /* parse hexadecimal string */
347 hash_en = strtoul(hash_entry_num, &end, 16);
348 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
358 parse_config(const char *q_arg)
361 const char *p, *p0 = q_arg;
369 unsigned long int_fld[_NUM_FLD];
370 char *str_fld[_NUM_FLD];
376 while ((p = strchr(p0,'(')) != NULL) {
378 if((p0 = strchr(p,')')) == NULL)
382 if(size >= sizeof(s))
385 snprintf(s, sizeof(s), "%.*s", size, p);
386 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
388 for (i = 0; i < _NUM_FLD; i++){
390 int_fld[i] = strtoul(str_fld[i], &end, 0);
391 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
394 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
395 printf("exceeded max number of lcore params: %hu\n",
399 lcore_params_array[nb_lcore_params].port_id =
400 (uint8_t)int_fld[FLD_PORT];
401 lcore_params_array[nb_lcore_params].queue_id =
402 (uint8_t)int_fld[FLD_QUEUE];
403 lcore_params_array[nb_lcore_params].lcore_id =
404 (uint8_t)int_fld[FLD_LCORE];
407 lcore_params = lcore_params_array;
412 parse_eth_dest(const char *optarg)
416 uint8_t c, *dest, peer_addr[6];
419 portid = strtoul(optarg, &port_end, 10);
420 if (errno != 0 || port_end == optarg || *port_end++ != ',')
421 rte_exit(EXIT_FAILURE,
422 "Invalid eth-dest: %s", optarg);
423 if (portid >= RTE_MAX_ETHPORTS)
424 rte_exit(EXIT_FAILURE,
425 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
426 portid, RTE_MAX_ETHPORTS);
428 if (cmdline_parse_etheraddr(NULL, port_end,
429 &peer_addr, sizeof(peer_addr)) < 0)
430 rte_exit(EXIT_FAILURE,
431 "Invalid ethernet address: %s\n",
433 dest = (uint8_t *)&dest_eth_addr[portid];
434 for (c = 0; c < 6; c++)
435 dest[c] = peer_addr[c];
436 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
439 #define MAX_JUMBO_PKT_LEN 9600
440 #define MEMPOOL_CACHE_SIZE 256
442 static const char short_options[] =
444 "P" /* promiscuous */
445 "L" /* enable long prefix match */
446 "E" /* enable exact match */
449 #define CMD_LINE_OPT_CONFIG "config"
450 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
451 #define CMD_LINE_OPT_NO_NUMA "no-numa"
452 #define CMD_LINE_OPT_IPV6 "ipv6"
453 #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
454 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
455 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
457 /* long options mapped to a short option */
459 /* first long only option value must be >= 256, so that we won't
460 * conflict with short options */
461 CMD_LINE_OPT_MIN_NUM = 256,
462 CMD_LINE_OPT_CONFIG_NUM,
463 CMD_LINE_OPT_ETH_DEST_NUM,
464 CMD_LINE_OPT_NO_NUMA_NUM,
465 CMD_LINE_OPT_IPV6_NUM,
466 CMD_LINE_OPT_ENABLE_JUMBO_NUM,
467 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM,
468 CMD_LINE_OPT_PARSE_PTYPE_NUM,
471 static const struct option lgopts[] = {
472 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
473 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM},
474 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM},
475 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM},
476 {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, CMD_LINE_OPT_ENABLE_JUMBO_NUM},
477 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM},
478 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM},
483 * This expression is used to calculate the number of mbufs needed
484 * depending on user input, taking into account memory for rx and
485 * tx hardware rings, cache per lcore and mtable per port per lcore.
486 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
489 #define NB_MBUF RTE_MAX( \
490 (nb_ports*nb_rx_queue*nb_rxd + \
491 nb_ports*nb_lcores*MAX_PKT_BURST + \
492 nb_ports*n_tx_queue*nb_txd + \
493 nb_lcores*MEMPOOL_CACHE_SIZE), \
496 /* Parse the argument given in the command line of the application */
498 parse_args(int argc, char **argv)
503 char *prgname = argv[0];
507 /* Error or normal output strings. */
508 while ((opt = getopt_long(argc, argvopt, short_options,
509 lgopts, &option_index)) != EOF) {
514 enabled_port_mask = parse_portmask(optarg);
515 if (enabled_port_mask == 0) {
516 fprintf(stderr, "Invalid portmask\n");
517 print_usage(prgname);
535 case CMD_LINE_OPT_CONFIG_NUM:
536 ret = parse_config(optarg);
538 fprintf(stderr, "Invalid config\n");
539 print_usage(prgname);
544 case CMD_LINE_OPT_ETH_DEST_NUM:
545 parse_eth_dest(optarg);
548 case CMD_LINE_OPT_NO_NUMA_NUM:
552 case CMD_LINE_OPT_IPV6_NUM:
556 case CMD_LINE_OPT_ENABLE_JUMBO_NUM: {
557 const struct option lenopts = {
558 "max-pkt-len", required_argument, 0, 0
561 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
562 port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
565 * if no max-pkt-len set, use the default
566 * value ETHER_MAX_LEN.
568 if (getopt_long(argc, argvopt, "",
569 &lenopts, &option_index) == 0) {
570 ret = parse_max_pkt_len(optarg);
571 if (ret < 64 || ret > MAX_JUMBO_PKT_LEN) {
573 "invalid maximum packet length\n");
574 print_usage(prgname);
577 port_conf.rxmode.max_rx_pkt_len = ret;
582 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM:
583 ret = parse_hash_entry_number(optarg);
584 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
585 hash_entry_number = ret;
587 fprintf(stderr, "invalid hash entry number\n");
588 print_usage(prgname);
593 case CMD_LINE_OPT_PARSE_PTYPE_NUM:
594 printf("soft parse-ptype is enabled\n");
599 print_usage(prgname);
604 /* If both LPM and EM are selected, return error. */
605 if (l3fwd_lpm_on && l3fwd_em_on) {
606 fprintf(stderr, "LPM and EM are mutually exclusive, select only one\n");
611 * Nothing is selected, pick longest-prefix match
614 if (!l3fwd_lpm_on && !l3fwd_em_on) {
615 fprintf(stderr, "LPM or EM none selected, default LPM on\n");
620 * ipv6 and hash flags are valid only for
621 * exact macth, reset them to default for
622 * longest-prefix match.
626 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
630 argv[optind-1] = prgname;
633 optind = 1; /* reset getopt lib */
638 print_ethaddr(const char *name, const struct ether_addr *eth_addr)
640 char buf[ETHER_ADDR_FMT_SIZE];
641 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
642 printf("%s%s", name, buf);
646 init_mem(unsigned nb_mbuf)
648 struct lcore_conf *qconf;
653 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
654 if (rte_lcore_is_enabled(lcore_id) == 0)
658 socketid = rte_lcore_to_socket_id(lcore_id);
662 if (socketid >= NB_SOCKETS) {
663 rte_exit(EXIT_FAILURE,
664 "Socket %d of lcore %u is out of range %d\n",
665 socketid, lcore_id, NB_SOCKETS);
668 if (pktmbuf_pool[socketid] == NULL) {
669 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
670 pktmbuf_pool[socketid] =
671 rte_pktmbuf_pool_create(s, nb_mbuf,
672 MEMPOOL_CACHE_SIZE, 0,
673 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
674 if (pktmbuf_pool[socketid] == NULL)
675 rte_exit(EXIT_FAILURE,
676 "Cannot init mbuf pool on socket %d\n",
679 printf("Allocated mbuf pool on socket %d\n",
682 /* Setup either LPM or EM(f.e Hash). */
683 l3fwd_lkp.setup(socketid);
685 qconf = &lcore_conf[lcore_id];
686 qconf->ipv4_lookup_struct =
687 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
688 qconf->ipv6_lookup_struct =
689 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
694 /* Check the link status of all ports in up to 9s, and print them finally */
696 check_all_ports_link_status(uint32_t port_mask)
698 #define CHECK_INTERVAL 100 /* 100ms */
699 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
701 uint8_t count, all_ports_up, print_flag = 0;
702 struct rte_eth_link link;
704 printf("\nChecking link status");
706 for (count = 0; count <= MAX_CHECK_TIME; count++) {
710 RTE_ETH_FOREACH_DEV(portid) {
713 if ((port_mask & (1 << portid)) == 0)
715 memset(&link, 0, sizeof(link));
716 rte_eth_link_get_nowait(portid, &link);
717 /* print link status if flag set */
718 if (print_flag == 1) {
719 if (link.link_status)
721 "Port%d Link Up. Speed %u Mbps -%s\n",
722 portid, link.link_speed,
723 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
724 ("full-duplex") : ("half-duplex\n"));
726 printf("Port %d Link Down\n", portid);
729 /* clear all_ports_up flag if any link down */
730 if (link.link_status == ETH_LINK_DOWN) {
735 /* after finally printing all link status, get out */
739 if (all_ports_up == 0) {
742 rte_delay_ms(CHECK_INTERVAL);
745 /* set the print_flag if all ports up or timeout */
746 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
754 signal_handler(int signum)
756 if (signum == SIGINT || signum == SIGTERM) {
757 printf("\n\nSignal %d received, preparing to exit...\n",
764 prepare_ptype_parser(uint16_t portid, uint16_t queueid)
767 printf("Port %d: softly parse packet type info\n", portid);
768 if (rte_eth_add_rx_callback(portid, queueid,
769 l3fwd_lkp.cb_parse_ptype,
773 printf("Failed to add rx callback: port=%d\n", portid);
777 if (l3fwd_lkp.check_ptype(portid))
780 printf("port %d cannot parse packet type, please add --%s\n",
781 portid, CMD_LINE_OPT_PARSE_PTYPE);
786 main(int argc, char **argv)
788 struct lcore_conf *qconf;
789 struct rte_eth_dev_info dev_info;
790 struct rte_eth_txconf *txconf;
793 uint16_t queueid, portid;
795 uint32_t n_tx_queue, nb_lcores;
796 uint8_t nb_rx_queue, queue, socketid;
799 ret = rte_eal_init(argc, argv);
801 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
806 signal(SIGINT, signal_handler);
807 signal(SIGTERM, signal_handler);
809 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
810 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
811 dest_eth_addr[portid] =
812 ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
813 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
816 /* parse application arguments (after the EAL ones) */
817 ret = parse_args(argc, argv);
819 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
821 if (check_lcore_params() < 0)
822 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
824 ret = init_lcore_rx_queues();
826 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
828 nb_ports = rte_eth_dev_count_avail();
830 if (check_port_config() < 0)
831 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
833 nb_lcores = rte_lcore_count();
835 /* Setup function pointers for lookup method. */
836 setup_l3fwd_lookup_tables();
838 /* initialize all ports */
839 RTE_ETH_FOREACH_DEV(portid) {
840 struct rte_eth_conf local_port_conf = port_conf;
842 /* skip ports that are not enabled */
843 if ((enabled_port_mask & (1 << portid)) == 0) {
844 printf("\nSkipping disabled port %d\n", portid);
849 printf("Initializing port %d ... ", portid );
852 nb_rx_queue = get_port_n_rx_queues(portid);
853 n_tx_queue = nb_lcores;
854 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
855 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
856 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
857 nb_rx_queue, (unsigned)n_tx_queue );
859 rte_eth_dev_info_get(portid, &dev_info);
860 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
861 local_port_conf.txmode.offloads |=
862 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
864 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
865 dev_info.flow_type_rss_offloads;
866 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
867 port_conf.rx_adv_conf.rss_conf.rss_hf) {
868 printf("Port %u modified RSS hash function based on hardware support,"
869 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
871 port_conf.rx_adv_conf.rss_conf.rss_hf,
872 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
875 ret = rte_eth_dev_configure(portid, nb_rx_queue,
876 (uint16_t)n_tx_queue, &local_port_conf);
878 rte_exit(EXIT_FAILURE,
879 "Cannot configure device: err=%d, port=%d\n",
882 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
885 rte_exit(EXIT_FAILURE,
886 "Cannot adjust number of descriptors: err=%d, "
887 "port=%d\n", ret, portid);
889 rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
890 print_ethaddr(" Address:", &ports_eth_addr[portid]);
892 print_ethaddr("Destination:",
893 (const struct ether_addr *)&dest_eth_addr[portid]);
897 * prepare src MACs for each port.
899 ether_addr_copy(&ports_eth_addr[portid],
900 (struct ether_addr *)(val_eth + portid) + 1);
903 ret = init_mem(NB_MBUF);
905 rte_exit(EXIT_FAILURE, "init_mem failed\n");
907 /* init one TX queue per couple (lcore,port) */
909 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
910 if (rte_lcore_is_enabled(lcore_id) == 0)
915 (uint8_t)rte_lcore_to_socket_id(lcore_id);
919 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
922 txconf = &dev_info.default_txconf;
923 txconf->offloads = local_port_conf.txmode.offloads;
924 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
927 rte_exit(EXIT_FAILURE,
928 "rte_eth_tx_queue_setup: err=%d, "
929 "port=%d\n", ret, portid);
931 qconf = &lcore_conf[lcore_id];
932 qconf->tx_queue_id[portid] = queueid;
935 qconf->tx_port_id[qconf->n_tx_port] = portid;
941 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
942 if (rte_lcore_is_enabled(lcore_id) == 0)
944 qconf = &lcore_conf[lcore_id];
945 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
948 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
949 struct rte_eth_dev *dev;
950 struct rte_eth_conf *conf;
951 struct rte_eth_rxconf rxq_conf;
953 portid = qconf->rx_queue_list[queue].port_id;
954 queueid = qconf->rx_queue_list[queue].queue_id;
955 dev = &rte_eth_devices[portid];
956 conf = &dev->data->dev_conf;
960 (uint8_t)rte_lcore_to_socket_id(lcore_id);
964 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
967 rte_eth_dev_info_get(portid, &dev_info);
968 rxq_conf = dev_info.default_rxconf;
969 rxq_conf.offloads = conf->rxmode.offloads;
970 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
973 pktmbuf_pool[socketid]);
975 rte_exit(EXIT_FAILURE,
976 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
984 RTE_ETH_FOREACH_DEV(portid) {
985 if ((enabled_port_mask & (1 << portid)) == 0) {
989 ret = rte_eth_dev_start(portid);
991 rte_exit(EXIT_FAILURE,
992 "rte_eth_dev_start: err=%d, port=%d\n",
996 * If enabled, put device in promiscuous mode.
997 * This allows IO forwarding mode to forward packets
998 * to itself through 2 cross-connected ports of the
1002 rte_eth_promiscuous_enable(portid);
1007 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1008 if (rte_lcore_is_enabled(lcore_id) == 0)
1010 qconf = &lcore_conf[lcore_id];
1011 for (queue = 0; queue < qconf->n_rx_queue; ++queue) {
1012 portid = qconf->rx_queue_list[queue].port_id;
1013 queueid = qconf->rx_queue_list[queue].queue_id;
1014 if (prepare_ptype_parser(portid, queueid) == 0)
1015 rte_exit(EXIT_FAILURE, "ptype check fails\n");
1020 check_all_ports_link_status(enabled_port_mask);
1023 /* launch per-lcore init on every lcore */
1024 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER);
1025 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
1026 if (rte_eal_wait_lcore(lcore_id) < 0) {
1033 RTE_ETH_FOREACH_DEV(portid) {
1034 if ((enabled_port_mask & (1 << portid)) == 0)
1036 printf("Closing port %d...", portid);
1037 rte_eth_dev_stop(portid);
1038 rte_eth_dev_close(portid);