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>
47 #include <rte_common.h>
49 #include <rte_byteorder.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
55 #include <rte_per_lcore.h>
56 #include <rte_launch.h>
57 #include <rte_atomic.h>
58 #include <rte_cycles.h>
59 #include <rte_prefetch.h>
60 #include <rte_lcore.h>
61 #include <rte_per_lcore.h>
62 #include <rte_branch_prediction.h>
63 #include <rte_interrupts.h>
65 #include <rte_random.h>
66 #include <rte_debug.h>
67 #include <rte_ether.h>
68 #include <rte_ethdev.h>
70 #include <rte_mempool.h>
75 #include <rte_string_fns.h>
76 #include <rte_cpuflags.h>
78 #include <cmdline_parse.h>
79 #include <cmdline_parse_etheraddr.h>
84 * Configurable number of RX/TX ring descriptors
86 #define RTE_TEST_RX_DESC_DEFAULT 128
87 #define RTE_TEST_TX_DESC_DEFAULT 512
89 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
90 #define MAX_RX_QUEUE_PER_PORT 128
92 #define MAX_LCORE_PARAMS 1024
94 /* Static global variables used within this file. */
95 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
96 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
98 /**< Ports set in promiscuous mode off by default. */
99 static int promiscuous_on;
101 /* Select Longest-Prefix or Exact match. */
102 static int l3fwd_lpm_on;
103 static int l3fwd_em_on;
105 static int numa_on = 1; /**< NUMA is enabled by default. */
107 /* Global variables. */
109 volatile bool force_quit;
111 /* ethernet addresses of ports */
112 uint64_t dest_eth_addr[RTE_MAX_ETHPORTS];
113 struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
115 __m128i val_eth[RTE_MAX_ETHPORTS];
117 /* mask of enabled ports */
118 uint32_t enabled_port_mask;
120 /* Used only in exact match mode. */
121 int ipv6; /**< ipv6 is false by default. */
122 uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
124 struct lcore_conf lcore_conf[RTE_MAX_LCORE];
126 struct lcore_params {
130 } __rte_cache_aligned;
132 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
133 static struct lcore_params lcore_params_array_default[] = {
145 static struct lcore_params * lcore_params = lcore_params_array_default;
146 static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
147 sizeof(lcore_params_array_default[0]);
149 static struct rte_eth_conf port_conf = {
151 .mq_mode = ETH_MQ_RX_RSS,
152 .max_rx_pkt_len = ETHER_MAX_LEN,
154 .header_split = 0, /**< Header Split disabled */
155 .hw_ip_checksum = 1, /**< IP checksum offload enabled */
156 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
157 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
158 .hw_strip_crc = 0, /**< CRC stripped by hardware */
163 .rss_hf = ETH_RSS_IP,
167 .mq_mode = ETH_MQ_TX_NONE,
171 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
173 struct l3fwd_lkp_mode {
175 int (*main_loop)(void *);
176 void* (*get_ipv4_lookup_struct)(int);
177 void* (*get_ipv6_lookup_struct)(int);
180 static struct l3fwd_lkp_mode l3fwd_lkp;
182 static struct l3fwd_lkp_mode l3fwd_em_lkp = {
184 .main_loop = em_main_loop,
185 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct,
186 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct,
189 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = {
191 .main_loop = lpm_main_loop,
192 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct,
193 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct,
197 * Setup lookup methods for forwarding.
198 * Currently exact-match and longest-prefix-match
199 * are supported ones.
202 setup_l3fwd_lookup_tables(void)
204 /* Setup HASH lookup functions. */
206 l3fwd_lkp = l3fwd_em_lkp;
207 /* Setup LPM lookup functions. */
209 l3fwd_lkp = l3fwd_lpm_lkp;
213 check_lcore_params(void)
215 uint8_t queue, lcore;
219 for (i = 0; i < nb_lcore_params; ++i) {
220 queue = lcore_params[i].queue_id;
221 if (queue >= MAX_RX_QUEUE_PER_PORT) {
222 printf("invalid queue number: %hhu\n", queue);
225 lcore = lcore_params[i].lcore_id;
226 if (!rte_lcore_is_enabled(lcore)) {
227 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
230 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
232 printf("warning: lcore %hhu is on socket %d with numa off \n",
240 check_port_config(const unsigned nb_ports)
245 for (i = 0; i < nb_lcore_params; ++i) {
246 portid = lcore_params[i].port_id;
247 if ((enabled_port_mask & (1 << portid)) == 0) {
248 printf("port %u is not enabled in port mask\n", portid);
251 if (portid >= nb_ports) {
252 printf("port %u is not present on the board\n", portid);
260 get_port_n_rx_queues(const uint8_t port)
265 for (i = 0; i < nb_lcore_params; ++i) {
266 if (lcore_params[i].port_id == port &&
267 lcore_params[i].queue_id > queue)
268 queue = lcore_params[i].queue_id;
270 return (uint8_t)(++queue);
274 init_lcore_rx_queues(void)
276 uint16_t i, nb_rx_queue;
279 for (i = 0; i < nb_lcore_params; ++i) {
280 lcore = lcore_params[i].lcore_id;
281 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
282 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
283 printf("error: too many queues (%u) for lcore: %u\n",
284 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
287 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
288 lcore_params[i].port_id;
289 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
290 lcore_params[i].queue_id;
291 lcore_conf[lcore].n_rx_queue++;
299 print_usage(const char *prgname)
301 printf ("%s [EAL options] -- -p PORTMASK -P"
302 " [--config (port,queue,lcore)[,(port,queue,lcore]]"
303 " [--enable-jumbo [--max-pkt-len PKTLEN]]\n"
304 " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
305 " -P : enable promiscuous mode\n"
306 " -E : enable exact match\n"
307 " -L : enable longest prefix match\n"
308 " --config (port,queue,lcore): rx queues configuration\n"
309 " --eth-dest=X,MM:MM:MM:MM:MM:MM: optional, ethernet destination for port X\n"
310 " --no-numa: optional, disable numa awareness\n"
311 " --ipv6: optional, specify it if running ipv6 packets\n"
312 " --enable-jumbo: enable jumbo frame"
313 " which max packet len is PKTLEN in decimal (64-9600)\n"
314 " --hash-entry-num: specify the hash entry number in hexadecimal to be setup\n",
319 parse_max_pkt_len(const char *pktlen)
324 /* parse decimal string */
325 len = strtoul(pktlen, &end, 10);
326 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
336 parse_portmask(const char *portmask)
341 /* parse hexadecimal string */
342 pm = strtoul(portmask, &end, 16);
343 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
353 parse_hash_entry_number(const char *hash_entry_num)
356 unsigned long hash_en;
357 /* parse hexadecimal string */
358 hash_en = strtoul(hash_entry_num, &end, 16);
359 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
369 parse_config(const char *q_arg)
372 const char *p, *p0 = q_arg;
380 unsigned long int_fld[_NUM_FLD];
381 char *str_fld[_NUM_FLD];
387 while ((p = strchr(p0,'(')) != NULL) {
389 if((p0 = strchr(p,')')) == NULL)
393 if(size >= sizeof(s))
396 snprintf(s, sizeof(s), "%.*s", size, p);
397 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
399 for (i = 0; i < _NUM_FLD; i++){
401 int_fld[i] = strtoul(str_fld[i], &end, 0);
402 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
405 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
406 printf("exceeded max number of lcore params: %hu\n",
410 lcore_params_array[nb_lcore_params].port_id =
411 (uint8_t)int_fld[FLD_PORT];
412 lcore_params_array[nb_lcore_params].queue_id =
413 (uint8_t)int_fld[FLD_QUEUE];
414 lcore_params_array[nb_lcore_params].lcore_id =
415 (uint8_t)int_fld[FLD_LCORE];
418 lcore_params = lcore_params_array;
423 parse_eth_dest(const char *optarg)
427 uint8_t c, *dest, peer_addr[6];
430 portid = strtoul(optarg, &port_end, 10);
431 if (errno != 0 || port_end == optarg || *port_end++ != ',')
432 rte_exit(EXIT_FAILURE,
433 "Invalid eth-dest: %s", optarg);
434 if (portid >= RTE_MAX_ETHPORTS)
435 rte_exit(EXIT_FAILURE,
436 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
437 portid, RTE_MAX_ETHPORTS);
439 if (cmdline_parse_etheraddr(NULL, port_end,
440 &peer_addr, sizeof(peer_addr)) < 0)
441 rte_exit(EXIT_FAILURE,
442 "Invalid ethernet address: %s\n",
444 dest = (uint8_t *)&dest_eth_addr[portid];
445 for (c = 0; c < 6; c++)
446 dest[c] = peer_addr[c];
447 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
450 #define MAX_JUMBO_PKT_LEN 9600
451 #define MEMPOOL_CACHE_SIZE 256
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"
461 * This expression is used to calculate the number of mbufs needed
462 * depending on user input, taking into account memory for rx and
463 * tx hardware rings, cache per lcore and mtable per port per lcore.
464 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
467 #define NB_MBUF RTE_MAX( \
468 (nb_ports*nb_rx_queue*RTE_TEST_RX_DESC_DEFAULT + \
469 nb_ports*nb_lcores*MAX_PKT_BURST + \
470 nb_ports*n_tx_queue*RTE_TEST_TX_DESC_DEFAULT + \
471 nb_lcores*MEMPOOL_CACHE_SIZE), \
474 /* Parse the argument given in the command line of the application */
476 parse_args(int argc, char **argv)
481 char *prgname = argv[0];
482 static struct option lgopts[] = {
483 {CMD_LINE_OPT_CONFIG, 1, 0, 0},
484 {CMD_LINE_OPT_ETH_DEST, 1, 0, 0},
485 {CMD_LINE_OPT_NO_NUMA, 0, 0, 0},
486 {CMD_LINE_OPT_IPV6, 0, 0, 0},
487 {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0},
488 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0},
494 /* Error or normal output strings. */
495 const char *str1 = "L3FWD: Invalid portmask";
496 const char *str2 = "L3FWD: Promiscuous mode selected";
497 const char *str3 = "L3FWD: Exact match selected";
498 const char *str4 = "L3FWD: Longest-prefix match selected";
499 const char *str5 = "L3FWD: Invalid config";
500 const char *str6 = "L3FWD: NUMA is disabled";
501 const char *str7 = "L3FWD: IPV6 is specified";
503 "L3FWD: Jumbo frame is enabled - disabling simple TX path";
504 const char *str9 = "L3FWD: Invalid packet length";
505 const char *str10 = "L3FWD: Set jumbo frame max packet len to ";
506 const char *str11 = "L3FWD: Invalid hash entry number";
508 "L3FWD: LPM and EM are mutually exclusive, select only one";
509 const char *str13 = "L3FWD: LPM or EM none selected, default LPM on";
511 while ((opt = getopt_long(argc, argvopt, "p:PLE",
512 lgopts, &option_index)) != EOF) {
517 enabled_port_mask = parse_portmask(optarg);
518 if (enabled_port_mask == 0) {
519 printf("%s\n", str1);
520 print_usage(prgname);
525 printf("%s\n", str2);
530 printf("%s\n", str3);
535 printf("%s\n", str4);
541 if (!strncmp(lgopts[option_index].name,
543 sizeof(CMD_LINE_OPT_CONFIG))) {
545 ret = parse_config(optarg);
547 printf("%s\n", str5);
548 print_usage(prgname);
553 if (!strncmp(lgopts[option_index].name,
554 CMD_LINE_OPT_ETH_DEST,
555 sizeof(CMD_LINE_OPT_ETH_DEST))) {
556 parse_eth_dest(optarg);
559 if (!strncmp(lgopts[option_index].name,
560 CMD_LINE_OPT_NO_NUMA,
561 sizeof(CMD_LINE_OPT_NO_NUMA))) {
562 printf("%s\n", str6);
566 if (!strncmp(lgopts[option_index].name,
568 sizeof(CMD_LINE_OPT_IPV6))) {
573 if (!strncmp(lgopts[option_index].name,
574 CMD_LINE_OPT_ENABLE_JUMBO,
575 sizeof(CMD_LINE_OPT_ENABLE_JUMBO))) {
576 struct option lenopts = {
577 "max-pkt-len", required_argument, 0, 0
580 printf("%s\n", str8);
581 port_conf.rxmode.jumbo_frame = 1;
584 * if no max-pkt-len set, use the default
585 * value ETHER_MAX_LEN.
587 if (0 == getopt_long(argc, argvopt, "",
588 &lenopts, &option_index)) {
589 ret = parse_max_pkt_len(optarg);
591 (ret > MAX_JUMBO_PKT_LEN)) {
592 printf("%s\n", str9);
593 print_usage(prgname);
596 port_conf.rxmode.max_rx_pkt_len = ret;
598 printf("%s %u\n", str10,
599 (unsigned int)port_conf.rxmode.max_rx_pkt_len);
602 if (!strncmp(lgopts[option_index].name,
603 CMD_LINE_OPT_HASH_ENTRY_NUM,
604 sizeof(CMD_LINE_OPT_HASH_ENTRY_NUM))) {
606 ret = parse_hash_entry_number(optarg);
607 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
608 hash_entry_number = ret;
610 printf("%s\n", str11);
611 print_usage(prgname);
618 print_usage(prgname);
623 /* If both LPM and EM are selected, return error. */
624 if (l3fwd_lpm_on && l3fwd_em_on) {
625 printf("%s\n", str12);
630 * Nothing is selected, pick longest-prefix match
633 if (!l3fwd_lpm_on && !l3fwd_em_on) {
635 printf("%s\n", str13);
639 * ipv6 and hash flags are valid only for
640 * exact macth, reset them to default for
641 * longest-prefix match.
645 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
649 argv[optind-1] = prgname;
652 optind = 0; /* reset getopt lib */
657 print_ethaddr(const char *name, const struct ether_addr *eth_addr)
659 char buf[ETHER_ADDR_FMT_SIZE];
660 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
661 printf("%s%s", name, buf);
665 init_mem(unsigned nb_mbuf)
667 struct lcore_conf *qconf;
672 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
673 if (rte_lcore_is_enabled(lcore_id) == 0)
677 socketid = rte_lcore_to_socket_id(lcore_id);
681 if (socketid >= NB_SOCKETS) {
682 rte_exit(EXIT_FAILURE,
683 "Socket %d of lcore %u is out of range %d\n",
684 socketid, lcore_id, NB_SOCKETS);
687 if (pktmbuf_pool[socketid] == NULL) {
688 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
689 pktmbuf_pool[socketid] =
690 rte_pktmbuf_pool_create(s, nb_mbuf,
691 MEMPOOL_CACHE_SIZE, 0,
692 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
693 if (pktmbuf_pool[socketid] == NULL)
694 rte_exit(EXIT_FAILURE,
695 "Cannot init mbuf pool on socket %d\n",
698 printf("Allocated mbuf pool on socket %d\n",
701 /* Setup either LPM or EM(f.e Hash). */
702 l3fwd_lkp.setup(socketid);
704 qconf = &lcore_conf[lcore_id];
705 qconf->ipv4_lookup_struct =
706 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
707 qconf->ipv6_lookup_struct =
708 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
713 /* Check the link status of all ports in up to 9s, and print them finally */
715 check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
717 #define CHECK_INTERVAL 100 /* 100ms */
718 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
719 uint8_t portid, 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 for (portid = 0; portid < port_num; 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)
738 printf("Port %d Link Up - speed %u "
739 "Mbps - %s\n", (uint8_t)portid,
740 (unsigned)link.link_speed,
741 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
742 ("full-duplex") : ("half-duplex\n"));
744 printf("Port %d Link Down\n",
748 /* clear all_ports_up flag if any link down */
749 if (link.link_status == 0) {
754 /* after finally printing all link status, get out */
758 if (all_ports_up == 0) {
761 rte_delay_ms(CHECK_INTERVAL);
764 /* set the print_flag if all ports up or timeout */
765 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
773 signal_handler(int signum)
775 if (signum == SIGINT || signum == SIGTERM) {
776 printf("\n\nSignal %d received, preparing to exit...\n",
783 main(int argc, char **argv)
785 struct lcore_conf *qconf;
786 struct rte_eth_dev_info dev_info;
787 struct rte_eth_txconf *txconf;
792 uint32_t n_tx_queue, nb_lcores;
793 uint8_t portid, nb_rx_queue, queue, socketid;
796 ret = rte_eal_init(argc, argv);
798 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
803 signal(SIGINT, signal_handler);
804 signal(SIGTERM, signal_handler);
806 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
807 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
808 dest_eth_addr[portid] =
809 ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
810 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
813 /* parse application arguments (after the EAL ones) */
814 ret = parse_args(argc, argv);
816 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
818 if (check_lcore_params() < 0)
819 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
821 ret = init_lcore_rx_queues();
823 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
825 nb_ports = rte_eth_dev_count();
826 if (nb_ports > RTE_MAX_ETHPORTS)
827 nb_ports = RTE_MAX_ETHPORTS;
829 if (check_port_config(nb_ports) < 0)
830 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
832 nb_lcores = rte_lcore_count();
834 /* Setup function pointers for lookup method. */
835 setup_l3fwd_lookup_tables();
837 /* initialize all ports */
838 for (portid = 0; portid < nb_ports; portid++) {
839 /* skip ports that are not enabled */
840 if ((enabled_port_mask & (1 << portid)) == 0) {
841 printf("\nSkipping disabled port %d\n", portid);
846 printf("Initializing port %d ... ", portid );
849 nb_rx_queue = get_port_n_rx_queues(portid);
850 n_tx_queue = nb_lcores;
851 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
852 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
853 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
854 nb_rx_queue, (unsigned)n_tx_queue );
855 ret = rte_eth_dev_configure(portid, nb_rx_queue,
856 (uint16_t)n_tx_queue, &port_conf);
858 rte_exit(EXIT_FAILURE,
859 "Cannot configure device: err=%d, port=%d\n",
862 rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
863 print_ethaddr(" Address:", &ports_eth_addr[portid]);
865 print_ethaddr("Destination:",
866 (const struct ether_addr *)&dest_eth_addr[portid]);
870 * prepare src MACs for each port.
872 ether_addr_copy(&ports_eth_addr[portid],
873 (struct ether_addr *)(val_eth + portid) + 1);
876 ret = init_mem(NB_MBUF);
878 rte_exit(EXIT_FAILURE, "init_mem failed\n");
880 /* init one TX queue per couple (lcore,port) */
882 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
883 if (rte_lcore_is_enabled(lcore_id) == 0)
888 (uint8_t)rte_lcore_to_socket_id(lcore_id);
892 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
895 rte_eth_dev_info_get(portid, &dev_info);
896 txconf = &dev_info.default_txconf;
897 if (port_conf.rxmode.jumbo_frame)
898 txconf->txq_flags = 0;
899 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
902 rte_exit(EXIT_FAILURE,
903 "rte_eth_tx_queue_setup: err=%d, "
904 "port=%d\n", ret, portid);
906 qconf = &lcore_conf[lcore_id];
907 qconf->tx_queue_id[portid] = queueid;
913 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
914 if (rte_lcore_is_enabled(lcore_id) == 0)
916 qconf = &lcore_conf[lcore_id];
917 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
920 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
921 portid = qconf->rx_queue_list[queue].port_id;
922 queueid = qconf->rx_queue_list[queue].queue_id;
926 (uint8_t)rte_lcore_to_socket_id(lcore_id);
930 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
933 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
936 pktmbuf_pool[socketid]);
938 rte_exit(EXIT_FAILURE,
939 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
947 for (portid = 0; portid < nb_ports; portid++) {
948 if ((enabled_port_mask & (1 << portid)) == 0) {
952 ret = rte_eth_dev_start(portid);
954 rte_exit(EXIT_FAILURE,
955 "rte_eth_dev_start: err=%d, port=%d\n",
959 * If enabled, put device in promiscuous mode.
960 * This allows IO forwarding mode to forward packets
961 * to itself through 2 cross-connected ports of the
965 rte_eth_promiscuous_enable(portid);
968 check_all_ports_link_status((uint8_t)nb_ports, enabled_port_mask);
971 /* launch per-lcore init on every lcore */
972 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER);
973 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
974 if (rte_eal_wait_lcore(lcore_id) < 0) {
981 for (portid = 0; portid < nb_ports; portid++) {
982 if ((enabled_port_mask & (1 << portid)) == 0)
984 printf("Closing port %d...", portid);
985 rte_eth_dev_stop(portid);
986 rte_eth_dev_close(portid);