1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2021 Intel Corporation
11 #include <sys/queue.h>
18 #include <rte_common.h>
20 #include <rte_byteorder.h>
22 #include <rte_malloc.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
26 #include <rte_launch.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_mempool.h>
41 #include <rte_string_fns.h>
42 #include <rte_cpuflags.h>
44 #include <cmdline_parse.h>
45 #include <cmdline_parse_etheraddr.h>
48 #include "l3fwd_event.h"
49 #include "l3fwd_route.h"
51 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_LCORE
52 #define MAX_RX_QUEUE_PER_PORT 128
54 #define MAX_LCORE_PARAMS 1024
56 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
57 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
59 /**< Ports set in promiscuous mode off by default. */
60 static int promiscuous_on;
62 /* Select Longest-Prefix, Exact match or Forwarding Information Base. */
63 enum L3FWD_LOOKUP_MODE {
69 static enum L3FWD_LOOKUP_MODE lookup_mode;
71 /* Global variables. */
73 static int numa_on = 1; /**< NUMA is enabled by default. */
74 static int parse_ptype; /**< Parse packet type using rx callback, and */
75 /**< disabled by default */
76 static int per_port_pool; /**< Use separate buffer pools per port; disabled */
79 volatile bool force_quit;
81 /* ethernet addresses of ports */
82 uint64_t dest_eth_addr[RTE_MAX_ETHPORTS];
83 struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
85 xmm_t val_eth[RTE_MAX_ETHPORTS];
87 /* mask of enabled ports */
88 uint32_t enabled_port_mask;
90 /* Used only in exact match mode. */
91 int ipv6; /**< ipv6 is false by default. */
92 uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
94 struct lcore_conf lcore_conf[RTE_MAX_LCORE];
96 struct parm_cfg parm_config;
102 } __rte_cache_aligned;
104 static struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
105 static struct lcore_params lcore_params_array_default[] = {
117 static struct lcore_params * lcore_params = lcore_params_array_default;
118 static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
119 sizeof(lcore_params_array_default[0]);
121 static struct rte_eth_conf port_conf = {
123 .mq_mode = RTE_ETH_MQ_RX_RSS,
125 .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM,
130 .rss_hf = RTE_ETH_RSS_IP,
134 .mq_mode = RTE_ETH_MQ_TX_NONE,
138 static uint32_t max_pkt_len;
140 static struct rte_mempool *pktmbuf_pool[RTE_MAX_ETHPORTS][NB_SOCKETS];
141 static struct rte_mempool *vector_pool[RTE_MAX_ETHPORTS];
142 static uint8_t lkp_per_socket[NB_SOCKETS];
144 struct l3fwd_lkp_mode {
145 void (*read_config_files)(void);
147 int (*check_ptype)(int);
148 rte_rx_callback_fn cb_parse_ptype;
149 int (*main_loop)(void *);
150 void* (*get_ipv4_lookup_struct)(int);
151 void* (*get_ipv6_lookup_struct)(int);
152 void (*free_routes)(void);
155 static struct l3fwd_lkp_mode l3fwd_lkp;
157 static struct l3fwd_lkp_mode l3fwd_em_lkp = {
158 .read_config_files = read_config_files_em,
160 .check_ptype = em_check_ptype,
161 .cb_parse_ptype = em_cb_parse_ptype,
162 .main_loop = em_main_loop,
163 .get_ipv4_lookup_struct = em_get_ipv4_l3fwd_lookup_struct,
164 .get_ipv6_lookup_struct = em_get_ipv6_l3fwd_lookup_struct,
165 .free_routes = em_free_routes,
168 static struct l3fwd_lkp_mode l3fwd_lpm_lkp = {
169 .read_config_files = read_config_files_lpm,
171 .check_ptype = lpm_check_ptype,
172 .cb_parse_ptype = lpm_cb_parse_ptype,
173 .main_loop = lpm_main_loop,
174 .get_ipv4_lookup_struct = lpm_get_ipv4_l3fwd_lookup_struct,
175 .get_ipv6_lookup_struct = lpm_get_ipv6_l3fwd_lookup_struct,
176 .free_routes = lpm_free_routes,
179 static struct l3fwd_lkp_mode l3fwd_fib_lkp = {
180 .read_config_files = read_config_files_lpm,
182 .check_ptype = lpm_check_ptype,
183 .cb_parse_ptype = lpm_cb_parse_ptype,
184 .main_loop = fib_main_loop,
185 .get_ipv4_lookup_struct = fib_get_ipv4_l3fwd_lookup_struct,
186 .get_ipv6_lookup_struct = fib_get_ipv6_l3fwd_lookup_struct,
187 .free_routes = lpm_free_routes,
191 * 198.18.0.0/16 are set aside for RFC2544 benchmarking (RFC5735).
192 * 198.18.{0-15}.0/24 = Port {0-15}
194 const struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
195 {RTE_IPV4(198, 18, 0, 0), 24, 0},
196 {RTE_IPV4(198, 18, 1, 0), 24, 1},
197 {RTE_IPV4(198, 18, 2, 0), 24, 2},
198 {RTE_IPV4(198, 18, 3, 0), 24, 3},
199 {RTE_IPV4(198, 18, 4, 0), 24, 4},
200 {RTE_IPV4(198, 18, 5, 0), 24, 5},
201 {RTE_IPV4(198, 18, 6, 0), 24, 6},
202 {RTE_IPV4(198, 18, 7, 0), 24, 7},
203 {RTE_IPV4(198, 18, 8, 0), 24, 8},
204 {RTE_IPV4(198, 18, 9, 0), 24, 9},
205 {RTE_IPV4(198, 18, 10, 0), 24, 10},
206 {RTE_IPV4(198, 18, 11, 0), 24, 11},
207 {RTE_IPV4(198, 18, 12, 0), 24, 12},
208 {RTE_IPV4(198, 18, 13, 0), 24, 13},
209 {RTE_IPV4(198, 18, 14, 0), 24, 14},
210 {RTE_IPV4(198, 18, 15, 0), 24, 15},
214 * 2001:200::/48 is IANA reserved range for IPv6 benchmarking (RFC5180).
215 * 2001:200:0:{0-f}::/64 = Port {0-15}
217 const struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {
218 {{32, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 0},
219 {{32, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 1},
220 {{32, 1, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 2},
221 {{32, 1, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 3},
222 {{32, 1, 2, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 4},
223 {{32, 1, 2, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 5},
224 {{32, 1, 2, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 6},
225 {{32, 1, 2, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 7},
226 {{32, 1, 2, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 8},
227 {{32, 1, 2, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 9},
228 {{32, 1, 2, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 10},
229 {{32, 1, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 11},
230 {{32, 1, 2, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 12},
231 {{32, 1, 2, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 13},
232 {{32, 1, 2, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 14},
233 {{32, 1, 2, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 15},
237 * API's called during initialization to setup ACL/EM/LPM rules.
240 l3fwd_set_rule_ipv4_name(const char *optarg)
242 parm_config.rule_ipv4_name = optarg;
246 l3fwd_set_rule_ipv6_name(const char *optarg)
248 parm_config.rule_ipv6_name = optarg;
252 * Setup lookup methods for forwarding.
253 * Currently exact-match, longest-prefix-match and forwarding information
254 * base are the supported ones.
257 setup_l3fwd_lookup_tables(void)
259 /* Setup HASH lookup functions. */
260 if (lookup_mode == L3FWD_LOOKUP_EM)
261 l3fwd_lkp = l3fwd_em_lkp;
262 /* Setup FIB lookup functions. */
263 else if (lookup_mode == L3FWD_LOOKUP_FIB)
264 l3fwd_lkp = l3fwd_fib_lkp;
265 /* Setup LPM lookup functions. */
267 l3fwd_lkp = l3fwd_lpm_lkp;
271 check_lcore_params(void)
273 uint8_t queue, lcore;
277 for (i = 0; i < nb_lcore_params; ++i) {
278 queue = lcore_params[i].queue_id;
279 if (queue >= MAX_RX_QUEUE_PER_PORT) {
280 printf("invalid queue number: %hhu\n", queue);
283 lcore = lcore_params[i].lcore_id;
284 if (!rte_lcore_is_enabled(lcore)) {
285 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
288 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
290 printf("warning: lcore %hhu is on socket %d with numa off \n",
298 check_port_config(void)
303 for (i = 0; i < nb_lcore_params; ++i) {
304 portid = lcore_params[i].port_id;
305 if ((enabled_port_mask & (1 << portid)) == 0) {
306 printf("port %u is not enabled in port mask\n", portid);
309 if (!rte_eth_dev_is_valid_port(portid)) {
310 printf("port %u is not present on the board\n", portid);
318 get_port_n_rx_queues(const uint16_t port)
323 for (i = 0; i < nb_lcore_params; ++i) {
324 if (lcore_params[i].port_id == port) {
325 if (lcore_params[i].queue_id == queue+1)
326 queue = lcore_params[i].queue_id;
328 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be"
329 " in sequence and must start with 0\n",
330 lcore_params[i].port_id);
333 return (uint8_t)(++queue);
337 init_lcore_rx_queues(void)
339 uint16_t i, nb_rx_queue;
342 for (i = 0; i < nb_lcore_params; ++i) {
343 lcore = lcore_params[i].lcore_id;
344 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
345 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
346 printf("error: too many queues (%u) for lcore: %u\n",
347 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
350 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
351 lcore_params[i].port_id;
352 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
353 lcore_params[i].queue_id;
354 lcore_conf[lcore].n_rx_queue++;
362 print_usage(const char *prgname)
364 fprintf(stderr, "%s [EAL options] --"
370 " --config (port,queue,lcore)[,(port,queue,lcore)]"
371 " [--rx-queue-size NPKTS]"
372 " [--tx-queue-size NPKTS]"
373 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
374 " [--max-pkt-len PKTLEN]"
376 " [--hash-entry-num]"
382 " [--event-vector [--event-vector-size SIZE] [--event-vector-tmo NS]]"
386 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
387 " -P : Enable promiscuous mode\n"
388 " --lookup: Select the lookup method\n"
390 " Accepted: em (Exact Match), lpm (Longest Prefix Match), fib (Forwarding Information Base)\n"
391 " --config (port,queue,lcore): Rx queue configuration\n"
392 " --rx-queue-size NPKTS: Rx queue size in decimal\n"
394 " --tx-queue-size NPKTS: Tx queue size in decimal\n"
396 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
397 " --max-pkt-len PKTLEN: maximum packet length in decimal (64-9600)\n"
398 " --no-numa: Disable numa awareness\n"
399 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
400 " --ipv6: Set if running ipv6 packets\n"
401 " --parse-ptype: Set to use software to analyze packet type\n"
402 " --per-port-pool: Use separate buffer pool per port\n"
403 " --mode: Packet transfer mode for I/O, poll or eventdev\n"
404 " Default mode = poll\n"
405 " --eventq-sched: Event queue synchronization method\n"
406 " ordered, atomic or parallel.\n"
408 " Valid only if --mode=eventdev\n"
409 " --event-eth-rxqs: Number of ethernet RX queues per device.\n"
411 " Valid only if --mode=eventdev\n"
412 " --event-vector: Enable event vectorization.\n"
413 " --event-vector-size: Max vector size if event vectorization is enabled.\n"
414 " --event-vector-tmo: Max timeout to form vector in nanoseconds if event vectorization is enabled\n"
415 " -E : Enable exact match, legacy flag please use --lookup=em instead\n"
416 " -L : Enable longest prefix match, legacy flag please use --lookup=lpm instead\n"
417 " --rule_ipv4=FILE: Specify the ipv4 rules entries file.\n"
418 " Each rule occupies one line.\n"
419 " --rule_ipv6=FILE: Specify the ipv6 rules entries file.\n\n",
420 prgname, RTE_TEST_RX_DESC_DEFAULT, RTE_TEST_TX_DESC_DEFAULT);
424 parse_max_pkt_len(const char *pktlen)
429 /* parse decimal string */
430 len = strtoul(pktlen, &end, 10);
431 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
441 parse_portmask(const char *portmask)
446 /* parse hexadecimal string */
447 pm = strtoul(portmask, &end, 16);
448 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
455 parse_hash_entry_number(const char *hash_entry_num)
458 unsigned long hash_en;
459 /* parse hexadecimal string */
460 hash_en = strtoul(hash_entry_num, &end, 16);
461 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
471 parse_config(const char *q_arg)
474 const char *p, *p0 = q_arg;
482 unsigned long int_fld[_NUM_FLD];
483 char *str_fld[_NUM_FLD];
489 while ((p = strchr(p0,'(')) != NULL) {
491 if((p0 = strchr(p,')')) == NULL)
495 if(size >= sizeof(s))
498 snprintf(s, sizeof(s), "%.*s", size, p);
499 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
501 for (i = 0; i < _NUM_FLD; i++){
503 int_fld[i] = strtoul(str_fld[i], &end, 0);
504 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
507 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
508 printf("exceeded max number of lcore params: %hu\n",
512 lcore_params_array[nb_lcore_params].port_id =
513 (uint8_t)int_fld[FLD_PORT];
514 lcore_params_array[nb_lcore_params].queue_id =
515 (uint8_t)int_fld[FLD_QUEUE];
516 lcore_params_array[nb_lcore_params].lcore_id =
517 (uint8_t)int_fld[FLD_LCORE];
520 lcore_params = lcore_params_array;
525 parse_eth_dest(const char *optarg)
529 uint8_t c, *dest, peer_addr[6];
532 portid = strtoul(optarg, &port_end, 10);
533 if (errno != 0 || port_end == optarg || *port_end++ != ',')
534 rte_exit(EXIT_FAILURE,
535 "Invalid eth-dest: %s", optarg);
536 if (portid >= RTE_MAX_ETHPORTS)
537 rte_exit(EXIT_FAILURE,
538 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
539 portid, RTE_MAX_ETHPORTS);
541 if (cmdline_parse_etheraddr(NULL, port_end,
542 &peer_addr, sizeof(peer_addr)) < 0)
543 rte_exit(EXIT_FAILURE,
544 "Invalid ethernet address: %s\n",
546 dest = (uint8_t *)&dest_eth_addr[portid];
547 for (c = 0; c < 6; c++)
548 dest[c] = peer_addr[c];
549 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
553 parse_mode(const char *optarg)
555 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
557 if (!strcmp(optarg, "poll"))
558 evt_rsrc->enabled = false;
559 else if (!strcmp(optarg, "eventdev"))
560 evt_rsrc->enabled = true;
564 parse_queue_size(const char *queue_size_arg, uint16_t *queue_size, int rx)
569 /* parse decimal string */
570 value = strtoul(queue_size_arg, &end, 10);
571 if ((queue_size_arg[0] == '\0') || (end == NULL) ||
572 (*end != '\0') || (value == 0)) {
574 rte_exit(EXIT_FAILURE, "Invalid rx-queue-size\n");
576 rte_exit(EXIT_FAILURE, "Invalid tx-queue-size\n");
581 if (value > UINT16_MAX) {
583 rte_exit(EXIT_FAILURE, "rx-queue-size %lu > %d\n",
586 rte_exit(EXIT_FAILURE, "tx-queue-size %lu > %d\n",
596 parse_eventq_sched(const char *optarg)
598 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
600 if (!strcmp(optarg, "ordered"))
601 evt_rsrc->sched_type = RTE_SCHED_TYPE_ORDERED;
602 if (!strcmp(optarg, "atomic"))
603 evt_rsrc->sched_type = RTE_SCHED_TYPE_ATOMIC;
604 if (!strcmp(optarg, "parallel"))
605 evt_rsrc->sched_type = RTE_SCHED_TYPE_PARALLEL;
609 parse_event_eth_rx_queues(const char *eth_rx_queues)
611 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
613 uint8_t num_eth_rx_queues;
615 /* parse decimal string */
616 num_eth_rx_queues = strtoul(eth_rx_queues, &end, 10);
617 if ((eth_rx_queues[0] == '\0') || (end == NULL) || (*end != '\0'))
620 if (num_eth_rx_queues == 0)
623 evt_rsrc->eth_rx_queues = num_eth_rx_queues;
627 parse_lookup(const char *optarg)
629 if (!strcmp(optarg, "em"))
630 lookup_mode = L3FWD_LOOKUP_EM;
631 else if (!strcmp(optarg, "lpm"))
632 lookup_mode = L3FWD_LOOKUP_LPM;
633 else if (!strcmp(optarg, "fib"))
634 lookup_mode = L3FWD_LOOKUP_FIB;
636 fprintf(stderr, "Invalid lookup option! Accepted options: em, lpm, fib\n");
642 #define MAX_JUMBO_PKT_LEN 9600
644 static const char short_options[] =
646 "P" /* promiscuous */
647 "L" /* legacy enable long prefix match */
648 "E" /* legacy enable exact match */
651 #define CMD_LINE_OPT_CONFIG "config"
652 #define CMD_LINE_OPT_RX_QUEUE_SIZE "rx-queue-size"
653 #define CMD_LINE_OPT_TX_QUEUE_SIZE "tx-queue-size"
654 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
655 #define CMD_LINE_OPT_NO_NUMA "no-numa"
656 #define CMD_LINE_OPT_IPV6 "ipv6"
657 #define CMD_LINE_OPT_MAX_PKT_LEN "max-pkt-len"
658 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
659 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
660 #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool"
661 #define CMD_LINE_OPT_MODE "mode"
662 #define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sched"
663 #define CMD_LINE_OPT_EVENT_ETH_RX_QUEUES "event-eth-rxqs"
664 #define CMD_LINE_OPT_LOOKUP "lookup"
665 #define CMD_LINE_OPT_ENABLE_VECTOR "event-vector"
666 #define CMD_LINE_OPT_VECTOR_SIZE "event-vector-size"
667 #define CMD_LINE_OPT_VECTOR_TMO_NS "event-vector-tmo"
668 #define CMD_LINE_OPT_RULE_IPV4 "rule_ipv4"
669 #define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"
672 /* long options mapped to a short option */
674 /* first long only option value must be >= 256, so that we won't
675 * conflict with short options */
676 CMD_LINE_OPT_MIN_NUM = 256,
677 CMD_LINE_OPT_CONFIG_NUM,
678 CMD_LINE_OPT_RX_QUEUE_SIZE_NUM,
679 CMD_LINE_OPT_TX_QUEUE_SIZE_NUM,
680 CMD_LINE_OPT_ETH_DEST_NUM,
681 CMD_LINE_OPT_NO_NUMA_NUM,
682 CMD_LINE_OPT_IPV6_NUM,
683 CMD_LINE_OPT_MAX_PKT_LEN_NUM,
684 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM,
685 CMD_LINE_OPT_PARSE_PTYPE_NUM,
686 CMD_LINE_OPT_RULE_IPV4_NUM,
687 CMD_LINE_OPT_RULE_IPV6_NUM,
688 CMD_LINE_OPT_PARSE_PER_PORT_POOL,
689 CMD_LINE_OPT_MODE_NUM,
690 CMD_LINE_OPT_EVENTQ_SYNC_NUM,
691 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM,
692 CMD_LINE_OPT_LOOKUP_NUM,
693 CMD_LINE_OPT_ENABLE_VECTOR_NUM,
694 CMD_LINE_OPT_VECTOR_SIZE_NUM,
695 CMD_LINE_OPT_VECTOR_TMO_NS_NUM
698 static const struct option lgopts[] = {
699 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
700 {CMD_LINE_OPT_RX_QUEUE_SIZE, 1, 0, CMD_LINE_OPT_RX_QUEUE_SIZE_NUM},
701 {CMD_LINE_OPT_TX_QUEUE_SIZE, 1, 0, CMD_LINE_OPT_TX_QUEUE_SIZE_NUM},
702 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM},
703 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM},
704 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM},
705 {CMD_LINE_OPT_MAX_PKT_LEN, 1, 0, CMD_LINE_OPT_MAX_PKT_LEN_NUM},
706 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM},
707 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM},
708 {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL},
709 {CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM},
710 {CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM},
711 {CMD_LINE_OPT_EVENT_ETH_RX_QUEUES, 1, 0,
712 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM},
713 {CMD_LINE_OPT_LOOKUP, 1, 0, CMD_LINE_OPT_LOOKUP_NUM},
714 {CMD_LINE_OPT_ENABLE_VECTOR, 0, 0, CMD_LINE_OPT_ENABLE_VECTOR_NUM},
715 {CMD_LINE_OPT_VECTOR_SIZE, 1, 0, CMD_LINE_OPT_VECTOR_SIZE_NUM},
716 {CMD_LINE_OPT_VECTOR_TMO_NS, 1, 0, CMD_LINE_OPT_VECTOR_TMO_NS_NUM},
717 {CMD_LINE_OPT_RULE_IPV4, 1, 0, CMD_LINE_OPT_RULE_IPV4_NUM},
718 {CMD_LINE_OPT_RULE_IPV6, 1, 0, CMD_LINE_OPT_RULE_IPV6_NUM},
723 * This expression is used to calculate the number of mbufs needed
724 * depending on user input, taking into account memory for rx and
725 * tx hardware rings, cache per lcore and mtable per port per lcore.
726 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
729 #define NB_MBUF(nports) RTE_MAX( \
730 (nports*nb_rx_queue*nb_rxd + \
731 nports*nb_lcores*MAX_PKT_BURST + \
732 nports*n_tx_queue*nb_txd + \
733 nb_lcores*MEMPOOL_CACHE_SIZE), \
736 /* Parse the argument given in the command line of the application */
738 parse_args(int argc, char **argv)
743 char *prgname = argv[0];
744 uint8_t lcore_params = 0;
745 uint8_t eventq_sched = 0;
746 uint8_t eth_rx_q = 0;
747 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
751 /* Error or normal output strings. */
752 while ((opt = getopt_long(argc, argvopt, short_options,
753 lgopts, &option_index)) != EOF) {
758 enabled_port_mask = parse_portmask(optarg);
759 if (enabled_port_mask == 0) {
760 fprintf(stderr, "Invalid portmask\n");
761 print_usage(prgname);
771 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
772 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
775 lookup_mode = L3FWD_LOOKUP_EM;
779 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
780 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
783 lookup_mode = L3FWD_LOOKUP_LPM;
787 case CMD_LINE_OPT_CONFIG_NUM:
788 ret = parse_config(optarg);
790 fprintf(stderr, "Invalid config\n");
791 print_usage(prgname);
797 case CMD_LINE_OPT_RX_QUEUE_SIZE_NUM:
798 parse_queue_size(optarg, &nb_rxd, 1);
801 case CMD_LINE_OPT_TX_QUEUE_SIZE_NUM:
802 parse_queue_size(optarg, &nb_txd, 0);
805 case CMD_LINE_OPT_ETH_DEST_NUM:
806 parse_eth_dest(optarg);
809 case CMD_LINE_OPT_NO_NUMA_NUM:
813 case CMD_LINE_OPT_IPV6_NUM:
817 case CMD_LINE_OPT_MAX_PKT_LEN_NUM:
818 max_pkt_len = parse_max_pkt_len(optarg);
821 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM:
822 ret = parse_hash_entry_number(optarg);
823 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
824 hash_entry_number = ret;
826 fprintf(stderr, "invalid hash entry number\n");
827 print_usage(prgname);
832 case CMD_LINE_OPT_PARSE_PTYPE_NUM:
833 printf("soft parse-ptype is enabled\n");
837 case CMD_LINE_OPT_PARSE_PER_PORT_POOL:
838 printf("per port buffer pool is enabled\n");
842 case CMD_LINE_OPT_MODE_NUM:
846 case CMD_LINE_OPT_EVENTQ_SYNC_NUM:
847 parse_eventq_sched(optarg);
851 case CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM:
852 parse_event_eth_rx_queues(optarg);
856 case CMD_LINE_OPT_LOOKUP_NUM:
857 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
858 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
861 ret = parse_lookup(optarg);
863 * If parse_lookup was passed an invalid lookup type
864 * then return -1. Error log included within
865 * parse_lookup for simplicity.
871 case CMD_LINE_OPT_ENABLE_VECTOR_NUM:
872 printf("event vectorization is enabled\n");
873 evt_rsrc->vector_enabled = 1;
875 case CMD_LINE_OPT_VECTOR_SIZE_NUM:
876 evt_rsrc->vector_size = strtol(optarg, NULL, 10);
878 case CMD_LINE_OPT_VECTOR_TMO_NS_NUM:
879 evt_rsrc->vector_tmo_ns = strtoull(optarg, NULL, 10);
881 case CMD_LINE_OPT_RULE_IPV4_NUM:
882 l3fwd_set_rule_ipv4_name(optarg);
884 case CMD_LINE_OPT_RULE_IPV6_NUM:
885 l3fwd_set_rule_ipv6_name(optarg);
888 print_usage(prgname);
893 if (evt_rsrc->enabled && lcore_params) {
894 fprintf(stderr, "lcore config is not valid when event mode is selected\n");
898 if (!evt_rsrc->enabled && eth_rx_q) {
899 fprintf(stderr, "eth_rx_queues is valid only when event mode is selected\n");
903 if (!evt_rsrc->enabled && eventq_sched) {
904 fprintf(stderr, "eventq_sched is valid only when event mode is selected\n");
908 if (evt_rsrc->vector_enabled && !evt_rsrc->vector_size) {
909 evt_rsrc->vector_size = VECTOR_SIZE_DEFAULT;
910 fprintf(stderr, "vector size set to default (%" PRIu16 ")\n",
911 evt_rsrc->vector_size);
914 if (evt_rsrc->vector_enabled && !evt_rsrc->vector_tmo_ns) {
915 evt_rsrc->vector_tmo_ns = VECTOR_TMO_NS_DEFAULT;
917 "vector timeout set to default (%" PRIu64 " ns)\n",
918 evt_rsrc->vector_tmo_ns);
922 * Nothing is selected, pick longest-prefix match
925 if (lookup_mode == L3FWD_LOOKUP_DEFAULT) {
926 fprintf(stderr, "Neither LPM, EM, or FIB selected, defaulting to LPM\n");
927 lookup_mode = L3FWD_LOOKUP_LPM;
931 * ipv6 and hash flags are valid only for
932 * exact match, reset them to default for
933 * longest-prefix match.
935 if (lookup_mode == L3FWD_LOOKUP_LPM) {
937 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
941 argv[optind-1] = prgname;
944 optind = 1; /* reset getopt lib */
949 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
951 char buf[RTE_ETHER_ADDR_FMT_SIZE];
952 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
953 printf("%s%s", name, buf);
957 init_mem(uint16_t portid, unsigned int nb_mbuf)
959 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
960 struct lcore_conf *qconf;
965 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
966 if (rte_lcore_is_enabled(lcore_id) == 0)
970 socketid = rte_lcore_to_socket_id(lcore_id);
974 if (socketid >= NB_SOCKETS) {
975 rte_exit(EXIT_FAILURE,
976 "Socket %d of lcore %u is out of range %d\n",
977 socketid, lcore_id, NB_SOCKETS);
980 if (pktmbuf_pool[portid][socketid] == NULL) {
981 snprintf(s, sizeof(s), "mbuf_pool_%d:%d",
983 pktmbuf_pool[portid][socketid] =
984 rte_pktmbuf_pool_create(s, nb_mbuf,
985 MEMPOOL_CACHE_SIZE, 0,
986 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
987 if (pktmbuf_pool[portid][socketid] == NULL)
988 rte_exit(EXIT_FAILURE,
989 "Cannot init mbuf pool on socket %d\n",
992 printf("Allocated mbuf pool on socket %d\n",
995 /* Setup LPM, EM(f.e Hash) or FIB. But, only once per
998 if (!lkp_per_socket[socketid]) {
999 l3fwd_lkp.setup(socketid);
1000 lkp_per_socket[socketid] = 1;
1004 if (evt_rsrc->vector_enabled && vector_pool[portid] == NULL) {
1005 unsigned int nb_vec;
1007 nb_vec = (nb_mbuf + evt_rsrc->vector_size - 1) /
1008 evt_rsrc->vector_size;
1009 snprintf(s, sizeof(s), "vector_pool_%d", portid);
1010 vector_pool[portid] = rte_event_vector_pool_create(
1011 s, nb_vec, 0, evt_rsrc->vector_size, socketid);
1012 if (vector_pool[portid] == NULL)
1013 rte_exit(EXIT_FAILURE,
1014 "Failed to create vector pool for port %d\n",
1017 printf("Allocated vector pool for port %d\n",
1021 qconf = &lcore_conf[lcore_id];
1022 qconf->ipv4_lookup_struct =
1023 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
1024 qconf->ipv6_lookup_struct =
1025 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
1030 /* Check the link status of all ports in up to 9s, and print them finally */
1032 check_all_ports_link_status(uint32_t port_mask)
1034 #define CHECK_INTERVAL 100 /* 100ms */
1035 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1037 uint8_t count, all_ports_up, print_flag = 0;
1038 struct rte_eth_link link;
1040 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
1042 printf("\nChecking link status");
1044 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1048 RTE_ETH_FOREACH_DEV(portid) {
1051 if ((port_mask & (1 << portid)) == 0)
1053 memset(&link, 0, sizeof(link));
1054 ret = rte_eth_link_get_nowait(portid, &link);
1057 if (print_flag == 1)
1058 printf("Port %u link get failed: %s\n",
1059 portid, rte_strerror(-ret));
1062 /* print link status if flag set */
1063 if (print_flag == 1) {
1064 rte_eth_link_to_str(link_status_text,
1065 sizeof(link_status_text), &link);
1066 printf("Port %d %s\n", portid,
1070 /* clear all_ports_up flag if any link down */
1071 if (link.link_status == RTE_ETH_LINK_DOWN) {
1076 /* after finally printing all link status, get out */
1077 if (print_flag == 1)
1080 if (all_ports_up == 0) {
1083 rte_delay_ms(CHECK_INTERVAL);
1086 /* set the print_flag if all ports up or timeout */
1087 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1095 signal_handler(int signum)
1097 if (signum == SIGINT || signum == SIGTERM) {
1098 printf("\n\nSignal %d received, preparing to exit...\n",
1105 prepare_ptype_parser(uint16_t portid, uint16_t queueid)
1108 printf("Port %d: softly parse packet type info\n", portid);
1109 if (rte_eth_add_rx_callback(portid, queueid,
1110 l3fwd_lkp.cb_parse_ptype,
1114 printf("Failed to add rx callback: port=%d\n", portid);
1118 if (l3fwd_lkp.check_ptype(portid))
1121 printf("port %d cannot parse packet type, please add --%s\n",
1122 portid, CMD_LINE_OPT_PARSE_PTYPE);
1127 eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
1129 uint32_t overhead_len;
1131 if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
1132 overhead_len = max_rx_pktlen - max_mtu;
1134 overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1136 return overhead_len;
1140 config_port_max_pkt_len(struct rte_eth_conf *conf,
1141 struct rte_eth_dev_info *dev_info)
1143 uint32_t overhead_len;
1145 if (max_pkt_len == 0)
1148 if (max_pkt_len < RTE_ETHER_MIN_LEN || max_pkt_len > MAX_JUMBO_PKT_LEN)
1151 overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
1153 conf->rxmode.mtu = max_pkt_len - overhead_len;
1155 if (conf->rxmode.mtu > RTE_ETHER_MTU)
1156 conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
1162 l3fwd_poll_resource_setup(void)
1164 uint8_t nb_rx_queue, queue, socketid;
1165 struct rte_eth_dev_info dev_info;
1166 uint32_t n_tx_queue, nb_lcores;
1167 struct rte_eth_txconf *txconf;
1168 struct lcore_conf *qconf;
1169 uint16_t queueid, portid;
1170 unsigned int nb_ports;
1171 unsigned int lcore_id;
1174 if (check_lcore_params() < 0)
1175 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
1177 ret = init_lcore_rx_queues();
1179 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
1181 nb_ports = rte_eth_dev_count_avail();
1183 if (check_port_config() < 0)
1184 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
1186 nb_lcores = rte_lcore_count();
1188 /* initialize all ports */
1189 RTE_ETH_FOREACH_DEV(portid) {
1190 struct rte_eth_conf local_port_conf = port_conf;
1192 /* skip ports that are not enabled */
1193 if ((enabled_port_mask & (1 << portid)) == 0) {
1194 printf("\nSkipping disabled port %d\n", portid);
1199 printf("Initializing port %d ... ", portid );
1202 nb_rx_queue = get_port_n_rx_queues(portid);
1203 n_tx_queue = nb_lcores;
1204 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
1205 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
1206 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
1207 nb_rx_queue, (unsigned)n_tx_queue );
1209 ret = rte_eth_dev_info_get(portid, &dev_info);
1211 rte_exit(EXIT_FAILURE,
1212 "Error during getting device (port %u) info: %s\n",
1213 portid, strerror(-ret));
1215 ret = config_port_max_pkt_len(&local_port_conf, &dev_info);
1217 rte_exit(EXIT_FAILURE,
1218 "Invalid max packet length: %u (port %u)\n",
1219 max_pkt_len, portid);
1221 if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
1222 local_port_conf.txmode.offloads |=
1223 RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1225 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
1226 dev_info.flow_type_rss_offloads;
1228 if (dev_info.max_rx_queues == 1)
1229 local_port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
1231 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
1232 port_conf.rx_adv_conf.rss_conf.rss_hf) {
1233 printf("Port %u modified RSS hash function based on hardware support,"
1234 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
1236 port_conf.rx_adv_conf.rss_conf.rss_hf,
1237 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
1240 ret = rte_eth_dev_configure(portid, nb_rx_queue,
1241 (uint16_t)n_tx_queue, &local_port_conf);
1243 rte_exit(EXIT_FAILURE,
1244 "Cannot configure device: err=%d, port=%d\n",
1247 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
1250 rte_exit(EXIT_FAILURE,
1251 "Cannot adjust number of descriptors: err=%d, "
1252 "port=%d\n", ret, portid);
1254 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
1256 rte_exit(EXIT_FAILURE,
1257 "Cannot get MAC address: err=%d, port=%d\n",
1260 print_ethaddr(" Address:", &ports_eth_addr[portid]);
1262 print_ethaddr("Destination:",
1263 (const struct rte_ether_addr *)&dest_eth_addr[portid]);
1267 * prepare src MACs for each port.
1269 rte_ether_addr_copy(&ports_eth_addr[portid],
1270 (struct rte_ether_addr *)(val_eth + portid) + 1);
1273 if (!per_port_pool) {
1274 /* portid = 0; this is *not* signifying the first port,
1275 * rather, it signifies that portid is ignored.
1277 ret = init_mem(0, NB_MBUF(nb_ports));
1279 ret = init_mem(portid, NB_MBUF(1));
1282 rte_exit(EXIT_FAILURE, "init_mem failed\n");
1284 /* init one TX queue per couple (lcore,port) */
1286 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1287 if (rte_lcore_is_enabled(lcore_id) == 0)
1292 (uint8_t)rte_lcore_to_socket_id(lcore_id);
1296 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
1299 txconf = &dev_info.default_txconf;
1300 txconf->offloads = local_port_conf.txmode.offloads;
1301 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
1304 rte_exit(EXIT_FAILURE,
1305 "rte_eth_tx_queue_setup: err=%d, "
1306 "port=%d\n", ret, portid);
1308 qconf = &lcore_conf[lcore_id];
1309 qconf->tx_queue_id[portid] = queueid;
1312 qconf->tx_port_id[qconf->n_tx_port] = portid;
1318 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1319 if (rte_lcore_is_enabled(lcore_id) == 0)
1321 qconf = &lcore_conf[lcore_id];
1322 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
1324 /* init RX queues */
1325 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
1326 struct rte_eth_rxconf rxq_conf;
1328 portid = qconf->rx_queue_list[queue].port_id;
1329 queueid = qconf->rx_queue_list[queue].queue_id;
1333 (uint8_t)rte_lcore_to_socket_id(lcore_id);
1337 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
1340 ret = rte_eth_dev_info_get(portid, &dev_info);
1342 rte_exit(EXIT_FAILURE,
1343 "Error during getting device (port %u) info: %s\n",
1344 portid, strerror(-ret));
1346 rxq_conf = dev_info.default_rxconf;
1347 rxq_conf.offloads = port_conf.rxmode.offloads;
1349 ret = rte_eth_rx_queue_setup(portid, queueid,
1352 pktmbuf_pool[0][socketid]);
1354 ret = rte_eth_rx_queue_setup(portid, queueid,
1357 pktmbuf_pool[portid][socketid]);
1359 rte_exit(EXIT_FAILURE,
1360 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
1367 l3fwd_service_enable(uint32_t service_id)
1369 uint8_t min_service_count = UINT8_MAX;
1370 uint32_t slcore_array[RTE_MAX_LCORE];
1371 unsigned int slcore = 0;
1372 uint8_t service_count;
1373 int32_t slcore_count;
1375 if (!rte_service_lcore_count())
1378 slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE);
1379 if (slcore_count < 0)
1381 /* Get the core which has least number of services running. */
1382 while (slcore_count--) {
1383 /* Reset default mapping */
1384 if (rte_service_map_lcore_set(service_id,
1385 slcore_array[slcore_count], 0) != 0)
1387 service_count = rte_service_lcore_count_services(
1388 slcore_array[slcore_count]);
1389 if (service_count < min_service_count) {
1390 slcore = slcore_array[slcore_count];
1391 min_service_count = service_count;
1394 if (rte_service_map_lcore_set(service_id, slcore, 1))
1396 rte_service_lcore_start(slcore);
1402 l3fwd_event_service_setup(void)
1404 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
1405 struct rte_event_dev_info evdev_info;
1406 uint32_t service_id, caps;
1409 rte_event_dev_info_get(evt_rsrc->event_d_id, &evdev_info);
1410 if (!(evdev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED)) {
1411 ret = rte_event_dev_service_id_get(evt_rsrc->event_d_id,
1413 if (ret != -ESRCH && ret != 0)
1414 rte_exit(EXIT_FAILURE,
1415 "Error in starting eventdev service\n");
1416 l3fwd_service_enable(service_id);
1419 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) {
1420 ret = rte_event_eth_rx_adapter_caps_get(evt_rsrc->event_d_id,
1421 evt_rsrc->rx_adptr.rx_adptr[i], &caps);
1423 rte_exit(EXIT_FAILURE,
1424 "Failed to get Rx adapter[%d] caps\n",
1425 evt_rsrc->rx_adptr.rx_adptr[i]);
1426 ret = rte_event_eth_rx_adapter_service_id_get(
1427 evt_rsrc->event_d_id,
1429 if (ret != -ESRCH && ret != 0)
1430 rte_exit(EXIT_FAILURE,
1431 "Error in starting Rx adapter[%d] service\n",
1432 evt_rsrc->rx_adptr.rx_adptr[i]);
1433 l3fwd_service_enable(service_id);
1436 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) {
1437 ret = rte_event_eth_tx_adapter_caps_get(evt_rsrc->event_d_id,
1438 evt_rsrc->tx_adptr.tx_adptr[i], &caps);
1440 rte_exit(EXIT_FAILURE,
1441 "Failed to get Rx adapter[%d] caps\n",
1442 evt_rsrc->tx_adptr.tx_adptr[i]);
1443 ret = rte_event_eth_tx_adapter_service_id_get(
1444 evt_rsrc->event_d_id,
1446 if (ret != -ESRCH && ret != 0)
1447 rte_exit(EXIT_FAILURE,
1448 "Error in starting Rx adapter[%d] service\n",
1449 evt_rsrc->tx_adptr.tx_adptr[i]);
1450 l3fwd_service_enable(service_id);
1455 main(int argc, char **argv)
1457 struct l3fwd_event_resources *evt_rsrc;
1458 struct lcore_conf *qconf;
1459 uint16_t queueid, portid;
1460 unsigned int lcore_id;
1465 ret = rte_eal_init(argc, argv);
1467 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
1472 signal(SIGINT, signal_handler);
1473 signal(SIGTERM, signal_handler);
1475 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
1476 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
1477 dest_eth_addr[portid] =
1478 RTE_ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
1479 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
1482 evt_rsrc = l3fwd_get_eventdev_rsrc();
1483 /* parse application arguments (after the EAL ones) */
1484 ret = parse_args(argc, argv);
1486 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
1488 /* Setup function pointers for lookup method. */
1489 setup_l3fwd_lookup_tables();
1491 /* Add the config file rules */
1492 l3fwd_lkp.read_config_files();
1494 evt_rsrc->per_port_pool = per_port_pool;
1495 evt_rsrc->pkt_pool = pktmbuf_pool;
1496 evt_rsrc->vec_pool = vector_pool;
1497 evt_rsrc->port_mask = enabled_port_mask;
1498 /* Configure eventdev parameters if user has requested */
1499 if (evt_rsrc->enabled) {
1500 l3fwd_event_resource_setup(&port_conf);
1501 if (lookup_mode == L3FWD_LOOKUP_EM)
1502 l3fwd_lkp.main_loop = evt_rsrc->ops.em_event_loop;
1503 else if (lookup_mode == L3FWD_LOOKUP_FIB)
1504 l3fwd_lkp.main_loop = evt_rsrc->ops.fib_event_loop;
1506 l3fwd_lkp.main_loop = evt_rsrc->ops.lpm_event_loop;
1507 l3fwd_event_service_setup();
1509 l3fwd_poll_resource_setup();
1512 RTE_ETH_FOREACH_DEV(portid) {
1513 if ((enabled_port_mask & (1 << portid)) == 0) {
1517 ret = rte_eth_dev_start(portid);
1519 rte_exit(EXIT_FAILURE,
1520 "rte_eth_dev_start: err=%d, port=%d\n",
1524 * If enabled, put device in promiscuous mode.
1525 * This allows IO forwarding mode to forward packets
1526 * to itself through 2 cross-connected ports of the
1529 if (promiscuous_on) {
1530 ret = rte_eth_promiscuous_enable(portid);
1532 rte_exit(EXIT_FAILURE,
1533 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
1534 rte_strerror(-ret), portid);
1540 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1541 if (rte_lcore_is_enabled(lcore_id) == 0)
1543 qconf = &lcore_conf[lcore_id];
1544 for (queue = 0; queue < qconf->n_rx_queue; ++queue) {
1545 portid = qconf->rx_queue_list[queue].port_id;
1546 queueid = qconf->rx_queue_list[queue].queue_id;
1547 if (prepare_ptype_parser(portid, queueid) == 0)
1548 rte_exit(EXIT_FAILURE, "ptype check fails\n");
1552 check_all_ports_link_status(enabled_port_mask);
1555 /* launch per-lcore init on every lcore */
1556 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MAIN);
1557 if (evt_rsrc->enabled) {
1558 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++)
1559 rte_event_eth_rx_adapter_stop(
1560 evt_rsrc->rx_adptr.rx_adptr[i]);
1561 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++)
1562 rte_event_eth_tx_adapter_stop(
1563 evt_rsrc->tx_adptr.tx_adptr[i]);
1565 RTE_ETH_FOREACH_DEV(portid) {
1566 if ((enabled_port_mask & (1 << portid)) == 0)
1568 ret = rte_eth_dev_stop(portid);
1570 printf("rte_eth_dev_stop: err=%d, port=%u\n",
1574 rte_eal_mp_wait_lcore();
1575 RTE_ETH_FOREACH_DEV(portid) {
1576 if ((enabled_port_mask & (1 << portid)) == 0)
1578 rte_eth_dev_close(portid);
1581 rte_event_dev_stop(evt_rsrc->event_d_id);
1582 rte_event_dev_close(evt_rsrc->event_d_id);
1585 rte_eal_mp_wait_lcore();
1587 RTE_ETH_FOREACH_DEV(portid) {
1588 if ((enabled_port_mask & (1 << portid)) == 0)
1590 printf("Closing port %d...", portid);
1591 ret = rte_eth_dev_stop(portid);
1593 printf("rte_eth_dev_stop: err=%d, port=%u\n",
1595 rte_eth_dev_close(portid);
1600 /* clean up config file routes */
1601 l3fwd_lkp.free_routes();
1603 /* clean up the EAL */