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, Forwarding Information Base or Access Control. */
63 enum L3FWD_LOOKUP_MODE {
70 static enum L3FWD_LOOKUP_MODE lookup_mode;
72 /* 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,
190 static struct l3fwd_lkp_mode l3fwd_acl_lkp = {
191 .read_config_files = read_config_files_acl,
193 .check_ptype = em_check_ptype,
194 .cb_parse_ptype = em_cb_parse_ptype,
195 .main_loop = acl_main_loop,
196 .get_ipv4_lookup_struct = acl_get_ipv4_l3fwd_lookup_struct,
197 .get_ipv6_lookup_struct = acl_get_ipv6_l3fwd_lookup_struct,
198 .free_routes = acl_free_routes,
202 * 198.18.0.0/16 are set aside for RFC2544 benchmarking (RFC5735).
203 * 198.18.{0-15}.0/24 = Port {0-15}
205 const struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
206 {RTE_IPV4(198, 18, 0, 0), 24, 0},
207 {RTE_IPV4(198, 18, 1, 0), 24, 1},
208 {RTE_IPV4(198, 18, 2, 0), 24, 2},
209 {RTE_IPV4(198, 18, 3, 0), 24, 3},
210 {RTE_IPV4(198, 18, 4, 0), 24, 4},
211 {RTE_IPV4(198, 18, 5, 0), 24, 5},
212 {RTE_IPV4(198, 18, 6, 0), 24, 6},
213 {RTE_IPV4(198, 18, 7, 0), 24, 7},
214 {RTE_IPV4(198, 18, 8, 0), 24, 8},
215 {RTE_IPV4(198, 18, 9, 0), 24, 9},
216 {RTE_IPV4(198, 18, 10, 0), 24, 10},
217 {RTE_IPV4(198, 18, 11, 0), 24, 11},
218 {RTE_IPV4(198, 18, 12, 0), 24, 12},
219 {RTE_IPV4(198, 18, 13, 0), 24, 13},
220 {RTE_IPV4(198, 18, 14, 0), 24, 14},
221 {RTE_IPV4(198, 18, 15, 0), 24, 15},
225 * 2001:200::/48 is IANA reserved range for IPv6 benchmarking (RFC5180).
226 * 2001:200:0:{0-f}::/64 = Port {0-15}
228 const struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {
229 {{32, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 0},
230 {{32, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 1},
231 {{32, 1, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 2},
232 {{32, 1, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 3},
233 {{32, 1, 2, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 4},
234 {{32, 1, 2, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 5},
235 {{32, 1, 2, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 6},
236 {{32, 1, 2, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 7},
237 {{32, 1, 2, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 8},
238 {{32, 1, 2, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 9},
239 {{32, 1, 2, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 10},
240 {{32, 1, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 11},
241 {{32, 1, 2, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 12},
242 {{32, 1, 2, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 13},
243 {{32, 1, 2, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 14},
244 {{32, 1, 2, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0}, 64, 15},
248 * API's called during initialization to setup ACL/EM/LPM rules.
251 l3fwd_set_rule_ipv4_name(const char *optarg)
253 parm_config.rule_ipv4_name = optarg;
257 l3fwd_set_rule_ipv6_name(const char *optarg)
259 parm_config.rule_ipv6_name = optarg;
263 l3fwd_set_alg(const char *optarg)
265 parm_config.alg = parse_acl_alg(optarg);
269 * Setup lookup methods for forwarding.
270 * Currently exact-match, longest-prefix-match and forwarding information
271 * base are the supported ones.
274 setup_l3fwd_lookup_tables(void)
276 /* Setup HASH lookup functions. */
277 if (lookup_mode == L3FWD_LOOKUP_EM)
278 l3fwd_lkp = l3fwd_em_lkp;
279 /* Setup FIB lookup functions. */
280 else if (lookup_mode == L3FWD_LOOKUP_FIB)
281 l3fwd_lkp = l3fwd_fib_lkp;
282 /* Setup ACL lookup functions. */
283 else if (lookup_mode == L3FWD_LOOKUP_ACL)
284 l3fwd_lkp = l3fwd_acl_lkp;
285 /* Setup LPM lookup functions. */
287 l3fwd_lkp = l3fwd_lpm_lkp;
291 check_lcore_params(void)
293 uint8_t queue, lcore;
297 for (i = 0; i < nb_lcore_params; ++i) {
298 queue = lcore_params[i].queue_id;
299 if (queue >= MAX_RX_QUEUE_PER_PORT) {
300 printf("invalid queue number: %hhu\n", queue);
303 lcore = lcore_params[i].lcore_id;
304 if (!rte_lcore_is_enabled(lcore)) {
305 printf("error: lcore %hhu is not enabled in lcore mask\n", lcore);
308 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
310 printf("warning: lcore %hhu is on socket %d with numa off \n",
318 check_port_config(void)
323 for (i = 0; i < nb_lcore_params; ++i) {
324 portid = lcore_params[i].port_id;
325 if ((enabled_port_mask & (1 << portid)) == 0) {
326 printf("port %u is not enabled in port mask\n", portid);
329 if (!rte_eth_dev_is_valid_port(portid)) {
330 printf("port %u is not present on the board\n", portid);
338 get_port_n_rx_queues(const uint16_t port)
343 for (i = 0; i < nb_lcore_params; ++i) {
344 if (lcore_params[i].port_id == port) {
345 if (lcore_params[i].queue_id == queue+1)
346 queue = lcore_params[i].queue_id;
348 rte_exit(EXIT_FAILURE, "queue ids of the port %d must be"
349 " in sequence and must start with 0\n",
350 lcore_params[i].port_id);
353 return (uint8_t)(++queue);
357 init_lcore_rx_queues(void)
359 uint16_t i, nb_rx_queue;
362 for (i = 0; i < nb_lcore_params; ++i) {
363 lcore = lcore_params[i].lcore_id;
364 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
365 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
366 printf("error: too many queues (%u) for lcore: %u\n",
367 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
370 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
371 lcore_params[i].port_id;
372 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
373 lcore_params[i].queue_id;
374 lcore_conf[lcore].n_rx_queue++;
382 print_usage(const char *prgname)
386 usage_acl_alg(alg, sizeof(alg));
387 fprintf(stderr, "%s [EAL options] --"
393 " --config (port,queue,lcore)[,(port,queue,lcore)]"
394 " [--rx-queue-size NPKTS]"
395 " [--tx-queue-size NPKTS]"
396 " [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
397 " [--max-pkt-len PKTLEN]"
399 " [--hash-entry-num]"
405 " [--event-vector [--event-vector-size SIZE] [--event-vector-tmo NS]]"
409 " -p PORTMASK: Hexadecimal bitmask of ports to configure\n"
410 " -P : Enable promiscuous mode\n"
411 " --lookup: Select the lookup method\n"
413 " Accepted: em (Exact Match), lpm (Longest Prefix Match), fib (Forwarding Information Base),\n"
414 " acl (Access Control List)\n"
415 " --config (port,queue,lcore): Rx queue configuration\n"
416 " --rx-queue-size NPKTS: Rx queue size in decimal\n"
418 " --tx-queue-size NPKTS: Tx queue size in decimal\n"
420 " --eth-dest=X,MM:MM:MM:MM:MM:MM: Ethernet destination for port X\n"
421 " --max-pkt-len PKTLEN: maximum packet length in decimal (64-9600)\n"
422 " --no-numa: Disable numa awareness\n"
423 " --hash-entry-num: Specify the hash entry number in hexadecimal to be setup\n"
424 " --ipv6: Set if running ipv6 packets\n"
425 " --parse-ptype: Set to use software to analyze packet type\n"
426 " --per-port-pool: Use separate buffer pool per port\n"
427 " --mode: Packet transfer mode for I/O, poll or eventdev\n"
428 " Default mode = poll\n"
429 " --eventq-sched: Event queue synchronization method\n"
430 " ordered, atomic or parallel.\n"
432 " Valid only if --mode=eventdev\n"
433 " --event-eth-rxqs: Number of ethernet RX queues per device.\n"
435 " Valid only if --mode=eventdev\n"
436 " --event-vector: Enable event vectorization.\n"
437 " --event-vector-size: Max vector size if event vectorization is enabled.\n"
438 " --event-vector-tmo: Max timeout to form vector in nanoseconds if event vectorization is enabled\n"
439 " -E : Enable exact match, legacy flag please use --lookup=em instead\n"
440 " -L : Enable longest prefix match, legacy flag please use --lookup=lpm instead\n"
441 " --rule_ipv4=FILE: Specify the ipv4 rules entries file.\n"
442 " Each rule occupies one line.\n"
443 " 2 kinds of rules are supported.\n"
444 " One is ACL entry at while line leads with character '%c',\n"
445 " another is route entry at while line leads with character '%c'.\n"
446 " --rule_ipv6=FILE: Specify the ipv6 rules entries file.\n"
447 " --alg: ACL classify method to use, one of: %s.\n\n",
448 prgname, RTE_TEST_RX_DESC_DEFAULT, RTE_TEST_TX_DESC_DEFAULT,
449 ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
453 parse_max_pkt_len(const char *pktlen)
458 /* parse decimal string */
459 len = strtoul(pktlen, &end, 10);
460 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
470 parse_portmask(const char *portmask)
475 /* parse hexadecimal string */
476 pm = strtoul(portmask, &end, 16);
477 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
484 parse_hash_entry_number(const char *hash_entry_num)
487 unsigned long hash_en;
488 /* parse hexadecimal string */
489 hash_en = strtoul(hash_entry_num, &end, 16);
490 if ((hash_entry_num[0] == '\0') || (end == NULL) || (*end != '\0'))
500 parse_config(const char *q_arg)
503 const char *p, *p0 = q_arg;
511 unsigned long int_fld[_NUM_FLD];
512 char *str_fld[_NUM_FLD];
518 while ((p = strchr(p0,'(')) != NULL) {
520 if((p0 = strchr(p,')')) == NULL)
524 if(size >= sizeof(s))
527 snprintf(s, sizeof(s), "%.*s", size, p);
528 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
530 for (i = 0; i < _NUM_FLD; i++){
532 int_fld[i] = strtoul(str_fld[i], &end, 0);
533 if (errno != 0 || end == str_fld[i] || int_fld[i] > 255)
536 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
537 printf("exceeded max number of lcore params: %hu\n",
541 lcore_params_array[nb_lcore_params].port_id =
542 (uint8_t)int_fld[FLD_PORT];
543 lcore_params_array[nb_lcore_params].queue_id =
544 (uint8_t)int_fld[FLD_QUEUE];
545 lcore_params_array[nb_lcore_params].lcore_id =
546 (uint8_t)int_fld[FLD_LCORE];
549 lcore_params = lcore_params_array;
554 parse_eth_dest(const char *optarg)
558 uint8_t c, *dest, peer_addr[6];
561 portid = strtoul(optarg, &port_end, 10);
562 if (errno != 0 || port_end == optarg || *port_end++ != ',')
563 rte_exit(EXIT_FAILURE,
564 "Invalid eth-dest: %s", optarg);
565 if (portid >= RTE_MAX_ETHPORTS)
566 rte_exit(EXIT_FAILURE,
567 "eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\n",
568 portid, RTE_MAX_ETHPORTS);
570 if (cmdline_parse_etheraddr(NULL, port_end,
571 &peer_addr, sizeof(peer_addr)) < 0)
572 rte_exit(EXIT_FAILURE,
573 "Invalid ethernet address: %s\n",
575 dest = (uint8_t *)&dest_eth_addr[portid];
576 for (c = 0; c < 6; c++)
577 dest[c] = peer_addr[c];
578 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
582 parse_mode(const char *optarg)
584 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
586 if (!strcmp(optarg, "poll"))
587 evt_rsrc->enabled = false;
588 else if (!strcmp(optarg, "eventdev"))
589 evt_rsrc->enabled = true;
593 parse_queue_size(const char *queue_size_arg, uint16_t *queue_size, int rx)
598 /* parse decimal string */
599 value = strtoul(queue_size_arg, &end, 10);
600 if ((queue_size_arg[0] == '\0') || (end == NULL) ||
601 (*end != '\0') || (value == 0)) {
603 rte_exit(EXIT_FAILURE, "Invalid rx-queue-size\n");
605 rte_exit(EXIT_FAILURE, "Invalid tx-queue-size\n");
610 if (value > UINT16_MAX) {
612 rte_exit(EXIT_FAILURE, "rx-queue-size %lu > %d\n",
615 rte_exit(EXIT_FAILURE, "tx-queue-size %lu > %d\n",
625 parse_eventq_sched(const char *optarg)
627 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
629 if (!strcmp(optarg, "ordered"))
630 evt_rsrc->sched_type = RTE_SCHED_TYPE_ORDERED;
631 if (!strcmp(optarg, "atomic"))
632 evt_rsrc->sched_type = RTE_SCHED_TYPE_ATOMIC;
633 if (!strcmp(optarg, "parallel"))
634 evt_rsrc->sched_type = RTE_SCHED_TYPE_PARALLEL;
638 parse_event_eth_rx_queues(const char *eth_rx_queues)
640 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
642 uint8_t num_eth_rx_queues;
644 /* parse decimal string */
645 num_eth_rx_queues = strtoul(eth_rx_queues, &end, 10);
646 if ((eth_rx_queues[0] == '\0') || (end == NULL) || (*end != '\0'))
649 if (num_eth_rx_queues == 0)
652 evt_rsrc->eth_rx_queues = num_eth_rx_queues;
656 parse_lookup(const char *optarg)
658 if (!strcmp(optarg, "em"))
659 lookup_mode = L3FWD_LOOKUP_EM;
660 else if (!strcmp(optarg, "lpm"))
661 lookup_mode = L3FWD_LOOKUP_LPM;
662 else if (!strcmp(optarg, "fib"))
663 lookup_mode = L3FWD_LOOKUP_FIB;
664 else if (!strcmp(optarg, "acl"))
665 lookup_mode = L3FWD_LOOKUP_ACL;
667 fprintf(stderr, "Invalid lookup option! Accepted options: acl, em, lpm, fib\n");
673 #define MAX_JUMBO_PKT_LEN 9600
675 static const char short_options[] =
677 "P" /* promiscuous */
678 "L" /* legacy enable long prefix match */
679 "E" /* legacy enable exact match */
682 #define CMD_LINE_OPT_CONFIG "config"
683 #define CMD_LINE_OPT_RX_QUEUE_SIZE "rx-queue-size"
684 #define CMD_LINE_OPT_TX_QUEUE_SIZE "tx-queue-size"
685 #define CMD_LINE_OPT_ETH_DEST "eth-dest"
686 #define CMD_LINE_OPT_NO_NUMA "no-numa"
687 #define CMD_LINE_OPT_IPV6 "ipv6"
688 #define CMD_LINE_OPT_MAX_PKT_LEN "max-pkt-len"
689 #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
690 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
691 #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool"
692 #define CMD_LINE_OPT_MODE "mode"
693 #define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sched"
694 #define CMD_LINE_OPT_EVENT_ETH_RX_QUEUES "event-eth-rxqs"
695 #define CMD_LINE_OPT_LOOKUP "lookup"
696 #define CMD_LINE_OPT_ENABLE_VECTOR "event-vector"
697 #define CMD_LINE_OPT_VECTOR_SIZE "event-vector-size"
698 #define CMD_LINE_OPT_VECTOR_TMO_NS "event-vector-tmo"
699 #define CMD_LINE_OPT_RULE_IPV4 "rule_ipv4"
700 #define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"
701 #define CMD_LINE_OPT_ALG "alg"
704 /* long options mapped to a short option */
706 /* first long only option value must be >= 256, so that we won't
707 * conflict with short options */
708 CMD_LINE_OPT_MIN_NUM = 256,
709 CMD_LINE_OPT_CONFIG_NUM,
710 CMD_LINE_OPT_RX_QUEUE_SIZE_NUM,
711 CMD_LINE_OPT_TX_QUEUE_SIZE_NUM,
712 CMD_LINE_OPT_ETH_DEST_NUM,
713 CMD_LINE_OPT_NO_NUMA_NUM,
714 CMD_LINE_OPT_IPV6_NUM,
715 CMD_LINE_OPT_MAX_PKT_LEN_NUM,
716 CMD_LINE_OPT_HASH_ENTRY_NUM_NUM,
717 CMD_LINE_OPT_PARSE_PTYPE_NUM,
718 CMD_LINE_OPT_RULE_IPV4_NUM,
719 CMD_LINE_OPT_RULE_IPV6_NUM,
720 CMD_LINE_OPT_ALG_NUM,
721 CMD_LINE_OPT_PARSE_PER_PORT_POOL,
722 CMD_LINE_OPT_MODE_NUM,
723 CMD_LINE_OPT_EVENTQ_SYNC_NUM,
724 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM,
725 CMD_LINE_OPT_LOOKUP_NUM,
726 CMD_LINE_OPT_ENABLE_VECTOR_NUM,
727 CMD_LINE_OPT_VECTOR_SIZE_NUM,
728 CMD_LINE_OPT_VECTOR_TMO_NS_NUM
731 static const struct option lgopts[] = {
732 {CMD_LINE_OPT_CONFIG, 1, 0, CMD_LINE_OPT_CONFIG_NUM},
733 {CMD_LINE_OPT_RX_QUEUE_SIZE, 1, 0, CMD_LINE_OPT_RX_QUEUE_SIZE_NUM},
734 {CMD_LINE_OPT_TX_QUEUE_SIZE, 1, 0, CMD_LINE_OPT_TX_QUEUE_SIZE_NUM},
735 {CMD_LINE_OPT_ETH_DEST, 1, 0, CMD_LINE_OPT_ETH_DEST_NUM},
736 {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM},
737 {CMD_LINE_OPT_IPV6, 0, 0, CMD_LINE_OPT_IPV6_NUM},
738 {CMD_LINE_OPT_MAX_PKT_LEN, 1, 0, CMD_LINE_OPT_MAX_PKT_LEN_NUM},
739 {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM},
740 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, CMD_LINE_OPT_PARSE_PTYPE_NUM},
741 {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL},
742 {CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM},
743 {CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM},
744 {CMD_LINE_OPT_EVENT_ETH_RX_QUEUES, 1, 0,
745 CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM},
746 {CMD_LINE_OPT_LOOKUP, 1, 0, CMD_LINE_OPT_LOOKUP_NUM},
747 {CMD_LINE_OPT_ENABLE_VECTOR, 0, 0, CMD_LINE_OPT_ENABLE_VECTOR_NUM},
748 {CMD_LINE_OPT_VECTOR_SIZE, 1, 0, CMD_LINE_OPT_VECTOR_SIZE_NUM},
749 {CMD_LINE_OPT_VECTOR_TMO_NS, 1, 0, CMD_LINE_OPT_VECTOR_TMO_NS_NUM},
750 {CMD_LINE_OPT_RULE_IPV4, 1, 0, CMD_LINE_OPT_RULE_IPV4_NUM},
751 {CMD_LINE_OPT_RULE_IPV6, 1, 0, CMD_LINE_OPT_RULE_IPV6_NUM},
752 {CMD_LINE_OPT_ALG, 1, 0, CMD_LINE_OPT_ALG_NUM},
757 * This expression is used to calculate the number of mbufs needed
758 * depending on user input, taking into account memory for rx and
759 * tx hardware rings, cache per lcore and mtable per port per lcore.
760 * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum
763 #define NB_MBUF(nports) RTE_MAX( \
764 (nports*nb_rx_queue*nb_rxd + \
765 nports*nb_lcores*MAX_PKT_BURST + \
766 nports*n_tx_queue*nb_txd + \
767 nb_lcores*MEMPOOL_CACHE_SIZE), \
770 /* Parse the argument given in the command line of the application */
772 parse_args(int argc, char **argv)
777 char *prgname = argv[0];
778 uint8_t lcore_params = 0;
779 uint8_t eventq_sched = 0;
780 uint8_t eth_rx_q = 0;
781 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
785 /* Error or normal output strings. */
786 while ((opt = getopt_long(argc, argvopt, short_options,
787 lgopts, &option_index)) != EOF) {
792 enabled_port_mask = parse_portmask(optarg);
793 if (enabled_port_mask == 0) {
794 fprintf(stderr, "Invalid portmask\n");
795 print_usage(prgname);
805 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
806 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
809 lookup_mode = L3FWD_LOOKUP_EM;
813 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
814 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
817 lookup_mode = L3FWD_LOOKUP_LPM;
821 case CMD_LINE_OPT_CONFIG_NUM:
822 ret = parse_config(optarg);
824 fprintf(stderr, "Invalid config\n");
825 print_usage(prgname);
831 case CMD_LINE_OPT_RX_QUEUE_SIZE_NUM:
832 parse_queue_size(optarg, &nb_rxd, 1);
835 case CMD_LINE_OPT_TX_QUEUE_SIZE_NUM:
836 parse_queue_size(optarg, &nb_txd, 0);
839 case CMD_LINE_OPT_ETH_DEST_NUM:
840 parse_eth_dest(optarg);
843 case CMD_LINE_OPT_NO_NUMA_NUM:
847 case CMD_LINE_OPT_IPV6_NUM:
851 case CMD_LINE_OPT_MAX_PKT_LEN_NUM:
852 max_pkt_len = parse_max_pkt_len(optarg);
855 case CMD_LINE_OPT_HASH_ENTRY_NUM_NUM:
856 ret = parse_hash_entry_number(optarg);
857 if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
858 hash_entry_number = ret;
860 fprintf(stderr, "invalid hash entry number\n");
861 print_usage(prgname);
866 case CMD_LINE_OPT_PARSE_PTYPE_NUM:
867 printf("soft parse-ptype is enabled\n");
871 case CMD_LINE_OPT_PARSE_PER_PORT_POOL:
872 printf("per port buffer pool is enabled\n");
876 case CMD_LINE_OPT_MODE_NUM:
880 case CMD_LINE_OPT_EVENTQ_SYNC_NUM:
881 parse_eventq_sched(optarg);
885 case CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM:
886 parse_event_eth_rx_queues(optarg);
890 case CMD_LINE_OPT_LOOKUP_NUM:
891 if (lookup_mode != L3FWD_LOOKUP_DEFAULT) {
892 fprintf(stderr, "Only one lookup mode is allowed at a time!\n");
895 ret = parse_lookup(optarg);
897 * If parse_lookup was passed an invalid lookup type
898 * then return -1. Error log included within
899 * parse_lookup for simplicity.
905 case CMD_LINE_OPT_ENABLE_VECTOR_NUM:
906 printf("event vectorization is enabled\n");
907 evt_rsrc->vector_enabled = 1;
909 case CMD_LINE_OPT_VECTOR_SIZE_NUM:
910 evt_rsrc->vector_size = strtol(optarg, NULL, 10);
912 case CMD_LINE_OPT_VECTOR_TMO_NS_NUM:
913 evt_rsrc->vector_tmo_ns = strtoull(optarg, NULL, 10);
915 case CMD_LINE_OPT_RULE_IPV4_NUM:
916 l3fwd_set_rule_ipv4_name(optarg);
918 case CMD_LINE_OPT_RULE_IPV6_NUM:
919 l3fwd_set_rule_ipv6_name(optarg);
921 case CMD_LINE_OPT_ALG_NUM:
922 l3fwd_set_alg(optarg);
925 print_usage(prgname);
930 if (evt_rsrc->enabled && lcore_params) {
931 fprintf(stderr, "lcore config is not valid when event mode is selected\n");
935 if (!evt_rsrc->enabled && eth_rx_q) {
936 fprintf(stderr, "eth_rx_queues is valid only when event mode is selected\n");
940 if (!evt_rsrc->enabled && eventq_sched) {
941 fprintf(stderr, "eventq_sched is valid only when event mode is selected\n");
945 if (evt_rsrc->vector_enabled && !evt_rsrc->vector_size) {
946 evt_rsrc->vector_size = VECTOR_SIZE_DEFAULT;
947 fprintf(stderr, "vector size set to default (%" PRIu16 ")\n",
948 evt_rsrc->vector_size);
951 if (evt_rsrc->vector_enabled && !evt_rsrc->vector_tmo_ns) {
952 evt_rsrc->vector_tmo_ns = VECTOR_TMO_NS_DEFAULT;
954 "vector timeout set to default (%" PRIu64 " ns)\n",
955 evt_rsrc->vector_tmo_ns);
959 * Nothing is selected, pick longest-prefix match
962 if (lookup_mode == L3FWD_LOOKUP_DEFAULT) {
963 fprintf(stderr, "Neither ACL, LPM, EM, or FIB selected, defaulting to LPM\n");
964 lookup_mode = L3FWD_LOOKUP_LPM;
968 * ipv6 and hash flags are valid only for
969 * exact match, reset them to default for
970 * longest-prefix match.
972 if (lookup_mode == L3FWD_LOOKUP_LPM) {
974 hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;
977 /* For ACL, update port config rss hash filter */
978 if (lookup_mode == L3FWD_LOOKUP_ACL) {
979 port_conf.rx_adv_conf.rss_conf.rss_hf |=
980 RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP | RTE_ETH_RSS_SCTP;
984 argv[optind-1] = prgname;
987 optind = 1; /* reset getopt lib */
992 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
994 char buf[RTE_ETHER_ADDR_FMT_SIZE];
995 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
996 printf("%s%s", name, buf);
1000 init_mem(uint16_t portid, unsigned int nb_mbuf)
1002 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
1003 struct lcore_conf *qconf;
1008 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1009 if (rte_lcore_is_enabled(lcore_id) == 0)
1013 socketid = rte_lcore_to_socket_id(lcore_id);
1017 if (socketid >= NB_SOCKETS) {
1018 rte_exit(EXIT_FAILURE,
1019 "Socket %d of lcore %u is out of range %d\n",
1020 socketid, lcore_id, NB_SOCKETS);
1023 if (pktmbuf_pool[portid][socketid] == NULL) {
1024 snprintf(s, sizeof(s), "mbuf_pool_%d:%d",
1026 pktmbuf_pool[portid][socketid] =
1027 rte_pktmbuf_pool_create(s, nb_mbuf,
1028 MEMPOOL_CACHE_SIZE, 0,
1029 RTE_MBUF_DEFAULT_BUF_SIZE, socketid);
1030 if (pktmbuf_pool[portid][socketid] == NULL)
1031 rte_exit(EXIT_FAILURE,
1032 "Cannot init mbuf pool on socket %d\n",
1035 printf("Allocated mbuf pool on socket %d\n",
1038 /* Setup ACL, LPM, EM(f.e Hash) or FIB. But, only once per
1041 if (!lkp_per_socket[socketid]) {
1042 l3fwd_lkp.setup(socketid);
1043 lkp_per_socket[socketid] = 1;
1047 if (evt_rsrc->vector_enabled && vector_pool[portid] == NULL) {
1048 unsigned int nb_vec;
1050 nb_vec = (nb_mbuf + evt_rsrc->vector_size - 1) /
1051 evt_rsrc->vector_size;
1052 snprintf(s, sizeof(s), "vector_pool_%d", portid);
1053 vector_pool[portid] = rte_event_vector_pool_create(
1054 s, nb_vec, 0, evt_rsrc->vector_size, socketid);
1055 if (vector_pool[portid] == NULL)
1056 rte_exit(EXIT_FAILURE,
1057 "Failed to create vector pool for port %d\n",
1060 printf("Allocated vector pool for port %d\n",
1064 qconf = &lcore_conf[lcore_id];
1065 qconf->ipv4_lookup_struct =
1066 l3fwd_lkp.get_ipv4_lookup_struct(socketid);
1067 qconf->ipv6_lookup_struct =
1068 l3fwd_lkp.get_ipv6_lookup_struct(socketid);
1073 /* Check the link status of all ports in up to 9s, and print them finally */
1075 check_all_ports_link_status(uint32_t port_mask)
1077 #define CHECK_INTERVAL 100 /* 100ms */
1078 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1080 uint8_t count, all_ports_up, print_flag = 0;
1081 struct rte_eth_link link;
1083 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
1085 printf("\nChecking link status");
1087 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1091 RTE_ETH_FOREACH_DEV(portid) {
1094 if ((port_mask & (1 << portid)) == 0)
1096 memset(&link, 0, sizeof(link));
1097 ret = rte_eth_link_get_nowait(portid, &link);
1100 if (print_flag == 1)
1101 printf("Port %u link get failed: %s\n",
1102 portid, rte_strerror(-ret));
1105 /* print link status if flag set */
1106 if (print_flag == 1) {
1107 rte_eth_link_to_str(link_status_text,
1108 sizeof(link_status_text), &link);
1109 printf("Port %d %s\n", portid,
1113 /* clear all_ports_up flag if any link down */
1114 if (link.link_status == RTE_ETH_LINK_DOWN) {
1119 /* after finally printing all link status, get out */
1120 if (print_flag == 1)
1123 if (all_ports_up == 0) {
1126 rte_delay_ms(CHECK_INTERVAL);
1129 /* set the print_flag if all ports up or timeout */
1130 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1138 signal_handler(int signum)
1140 if (signum == SIGINT || signum == SIGTERM) {
1141 printf("\n\nSignal %d received, preparing to exit...\n",
1148 prepare_ptype_parser(uint16_t portid, uint16_t queueid)
1151 printf("Port %d: softly parse packet type info\n", portid);
1152 if (rte_eth_add_rx_callback(portid, queueid,
1153 l3fwd_lkp.cb_parse_ptype,
1157 printf("Failed to add rx callback: port=%d\n", portid);
1161 if (l3fwd_lkp.check_ptype(portid))
1164 printf("port %d cannot parse packet type, please add --%s\n",
1165 portid, CMD_LINE_OPT_PARSE_PTYPE);
1170 eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
1172 uint32_t overhead_len;
1174 if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
1175 overhead_len = max_rx_pktlen - max_mtu;
1177 overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1179 return overhead_len;
1183 config_port_max_pkt_len(struct rte_eth_conf *conf,
1184 struct rte_eth_dev_info *dev_info)
1186 uint32_t overhead_len;
1188 if (max_pkt_len == 0)
1191 if (max_pkt_len < RTE_ETHER_MIN_LEN || max_pkt_len > MAX_JUMBO_PKT_LEN)
1194 overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
1196 conf->rxmode.mtu = max_pkt_len - overhead_len;
1198 if (conf->rxmode.mtu > RTE_ETHER_MTU)
1199 conf->txmode.offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
1205 l3fwd_poll_resource_setup(void)
1207 uint8_t nb_rx_queue, queue, socketid;
1208 struct rte_eth_dev_info dev_info;
1209 uint32_t n_tx_queue, nb_lcores;
1210 struct rte_eth_txconf *txconf;
1211 struct lcore_conf *qconf;
1212 uint16_t queueid, portid;
1213 unsigned int nb_ports;
1214 unsigned int lcore_id;
1217 if (check_lcore_params() < 0)
1218 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
1220 ret = init_lcore_rx_queues();
1222 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
1224 nb_ports = rte_eth_dev_count_avail();
1226 if (check_port_config() < 0)
1227 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
1229 nb_lcores = rte_lcore_count();
1231 /* initialize all ports */
1232 RTE_ETH_FOREACH_DEV(portid) {
1233 struct rte_eth_conf local_port_conf = port_conf;
1235 /* skip ports that are not enabled */
1236 if ((enabled_port_mask & (1 << portid)) == 0) {
1237 printf("\nSkipping disabled port %d\n", portid);
1242 printf("Initializing port %d ... ", portid );
1245 nb_rx_queue = get_port_n_rx_queues(portid);
1246 n_tx_queue = nb_lcores;
1247 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT)
1248 n_tx_queue = MAX_TX_QUEUE_PER_PORT;
1249 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
1250 nb_rx_queue, (unsigned)n_tx_queue );
1252 ret = rte_eth_dev_info_get(portid, &dev_info);
1254 rte_exit(EXIT_FAILURE,
1255 "Error during getting device (port %u) info: %s\n",
1256 portid, strerror(-ret));
1258 ret = config_port_max_pkt_len(&local_port_conf, &dev_info);
1260 rte_exit(EXIT_FAILURE,
1261 "Invalid max packet length: %u (port %u)\n",
1262 max_pkt_len, portid);
1264 if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
1265 local_port_conf.txmode.offloads |=
1266 RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1268 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
1269 dev_info.flow_type_rss_offloads;
1271 if (dev_info.max_rx_queues == 1)
1272 local_port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
1274 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
1275 port_conf.rx_adv_conf.rss_conf.rss_hf) {
1276 printf("Port %u modified RSS hash function based on hardware support,"
1277 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
1279 port_conf.rx_adv_conf.rss_conf.rss_hf,
1280 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
1283 ret = rte_eth_dev_configure(portid, nb_rx_queue,
1284 (uint16_t)n_tx_queue, &local_port_conf);
1286 rte_exit(EXIT_FAILURE,
1287 "Cannot configure device: err=%d, port=%d\n",
1290 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
1293 rte_exit(EXIT_FAILURE,
1294 "Cannot adjust number of descriptors: err=%d, "
1295 "port=%d\n", ret, portid);
1297 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
1299 rte_exit(EXIT_FAILURE,
1300 "Cannot get MAC address: err=%d, port=%d\n",
1303 print_ethaddr(" Address:", &ports_eth_addr[portid]);
1305 print_ethaddr("Destination:",
1306 (const struct rte_ether_addr *)&dest_eth_addr[portid]);
1310 * prepare src MACs for each port.
1312 rte_ether_addr_copy(&ports_eth_addr[portid],
1313 (struct rte_ether_addr *)(val_eth + portid) + 1);
1316 if (!per_port_pool) {
1317 /* portid = 0; this is *not* signifying the first port,
1318 * rather, it signifies that portid is ignored.
1320 ret = init_mem(0, NB_MBUF(nb_ports));
1322 ret = init_mem(portid, NB_MBUF(1));
1325 rte_exit(EXIT_FAILURE, "init_mem failed\n");
1327 /* init one TX queue per couple (lcore,port) */
1329 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1330 if (rte_lcore_is_enabled(lcore_id) == 0)
1335 (uint8_t)rte_lcore_to_socket_id(lcore_id);
1339 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
1342 txconf = &dev_info.default_txconf;
1343 txconf->offloads = local_port_conf.txmode.offloads;
1344 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
1347 rte_exit(EXIT_FAILURE,
1348 "rte_eth_tx_queue_setup: err=%d, "
1349 "port=%d\n", ret, portid);
1351 qconf = &lcore_conf[lcore_id];
1352 qconf->tx_queue_id[portid] = queueid;
1355 qconf->tx_port_id[qconf->n_tx_port] = portid;
1361 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1362 if (rte_lcore_is_enabled(lcore_id) == 0)
1364 qconf = &lcore_conf[lcore_id];
1365 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
1367 /* init RX queues */
1368 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
1369 struct rte_eth_rxconf rxq_conf;
1371 portid = qconf->rx_queue_list[queue].port_id;
1372 queueid = qconf->rx_queue_list[queue].queue_id;
1376 (uint8_t)rte_lcore_to_socket_id(lcore_id);
1380 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
1383 ret = rte_eth_dev_info_get(portid, &dev_info);
1385 rte_exit(EXIT_FAILURE,
1386 "Error during getting device (port %u) info: %s\n",
1387 portid, strerror(-ret));
1389 rxq_conf = dev_info.default_rxconf;
1390 rxq_conf.offloads = port_conf.rxmode.offloads;
1392 ret = rte_eth_rx_queue_setup(portid, queueid,
1395 pktmbuf_pool[0][socketid]);
1397 ret = rte_eth_rx_queue_setup(portid, queueid,
1400 pktmbuf_pool[portid][socketid]);
1402 rte_exit(EXIT_FAILURE,
1403 "rte_eth_rx_queue_setup: err=%d, port=%d\n",
1410 l3fwd_service_enable(uint32_t service_id)
1412 uint8_t min_service_count = UINT8_MAX;
1413 uint32_t slcore_array[RTE_MAX_LCORE];
1414 unsigned int slcore = 0;
1415 uint8_t service_count;
1416 int32_t slcore_count;
1418 if (!rte_service_lcore_count())
1421 slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE);
1422 if (slcore_count < 0)
1424 /* Get the core which has least number of services running. */
1425 while (slcore_count--) {
1426 /* Reset default mapping */
1427 if (rte_service_map_lcore_set(service_id,
1428 slcore_array[slcore_count], 0) != 0)
1430 service_count = rte_service_lcore_count_services(
1431 slcore_array[slcore_count]);
1432 if (service_count < min_service_count) {
1433 slcore = slcore_array[slcore_count];
1434 min_service_count = service_count;
1437 if (rte_service_map_lcore_set(service_id, slcore, 1))
1439 rte_service_lcore_start(slcore);
1445 l3fwd_event_service_setup(void)
1447 struct l3fwd_event_resources *evt_rsrc = l3fwd_get_eventdev_rsrc();
1448 struct rte_event_dev_info evdev_info;
1449 uint32_t service_id, caps;
1452 rte_event_dev_info_get(evt_rsrc->event_d_id, &evdev_info);
1453 if (!(evdev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED)) {
1454 ret = rte_event_dev_service_id_get(evt_rsrc->event_d_id,
1456 if (ret != -ESRCH && ret != 0)
1457 rte_exit(EXIT_FAILURE,
1458 "Error in starting eventdev service\n");
1459 l3fwd_service_enable(service_id);
1462 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) {
1463 ret = rte_event_eth_rx_adapter_caps_get(evt_rsrc->event_d_id,
1464 evt_rsrc->rx_adptr.rx_adptr[i], &caps);
1466 rte_exit(EXIT_FAILURE,
1467 "Failed to get Rx adapter[%d] caps\n",
1468 evt_rsrc->rx_adptr.rx_adptr[i]);
1469 ret = rte_event_eth_rx_adapter_service_id_get(
1470 evt_rsrc->event_d_id,
1472 if (ret != -ESRCH && ret != 0)
1473 rte_exit(EXIT_FAILURE,
1474 "Error in starting Rx adapter[%d] service\n",
1475 evt_rsrc->rx_adptr.rx_adptr[i]);
1476 l3fwd_service_enable(service_id);
1479 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) {
1480 ret = rte_event_eth_tx_adapter_caps_get(evt_rsrc->event_d_id,
1481 evt_rsrc->tx_adptr.tx_adptr[i], &caps);
1483 rte_exit(EXIT_FAILURE,
1484 "Failed to get Rx adapter[%d] caps\n",
1485 evt_rsrc->tx_adptr.tx_adptr[i]);
1486 ret = rte_event_eth_tx_adapter_service_id_get(
1487 evt_rsrc->event_d_id,
1489 if (ret != -ESRCH && ret != 0)
1490 rte_exit(EXIT_FAILURE,
1491 "Error in starting Rx adapter[%d] service\n",
1492 evt_rsrc->tx_adptr.tx_adptr[i]);
1493 l3fwd_service_enable(service_id);
1498 main(int argc, char **argv)
1500 struct l3fwd_event_resources *evt_rsrc;
1501 struct lcore_conf *qconf;
1502 uint16_t queueid, portid;
1503 unsigned int lcore_id;
1508 ret = rte_eal_init(argc, argv);
1510 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
1515 signal(SIGINT, signal_handler);
1516 signal(SIGTERM, signal_handler);
1518 /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
1519 for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
1520 dest_eth_addr[portid] =
1521 RTE_ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40);
1522 *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
1525 evt_rsrc = l3fwd_get_eventdev_rsrc();
1526 /* parse application arguments (after the EAL ones) */
1527 ret = parse_args(argc, argv);
1529 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
1531 /* Setup function pointers for lookup method. */
1532 setup_l3fwd_lookup_tables();
1534 /* Add the config file rules */
1535 l3fwd_lkp.read_config_files();
1537 evt_rsrc->per_port_pool = per_port_pool;
1538 evt_rsrc->pkt_pool = pktmbuf_pool;
1539 evt_rsrc->vec_pool = vector_pool;
1540 evt_rsrc->port_mask = enabled_port_mask;
1541 /* Configure eventdev parameters if user has requested */
1542 if (evt_rsrc->enabled) {
1543 l3fwd_event_resource_setup(&port_conf);
1544 if (lookup_mode == L3FWD_LOOKUP_EM)
1545 l3fwd_lkp.main_loop = evt_rsrc->ops.em_event_loop;
1546 else if (lookup_mode == L3FWD_LOOKUP_FIB)
1547 l3fwd_lkp.main_loop = evt_rsrc->ops.fib_event_loop;
1549 l3fwd_lkp.main_loop = evt_rsrc->ops.lpm_event_loop;
1550 l3fwd_event_service_setup();
1552 l3fwd_poll_resource_setup();
1555 RTE_ETH_FOREACH_DEV(portid) {
1556 if ((enabled_port_mask & (1 << portid)) == 0) {
1560 ret = rte_eth_dev_start(portid);
1562 rte_exit(EXIT_FAILURE,
1563 "rte_eth_dev_start: err=%d, port=%d\n",
1567 * If enabled, put device in promiscuous mode.
1568 * This allows IO forwarding mode to forward packets
1569 * to itself through 2 cross-connected ports of the
1572 if (promiscuous_on) {
1573 ret = rte_eth_promiscuous_enable(portid);
1575 rte_exit(EXIT_FAILURE,
1576 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
1577 rte_strerror(-ret), portid);
1583 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1584 if (rte_lcore_is_enabled(lcore_id) == 0)
1586 qconf = &lcore_conf[lcore_id];
1587 for (queue = 0; queue < qconf->n_rx_queue; ++queue) {
1588 portid = qconf->rx_queue_list[queue].port_id;
1589 queueid = qconf->rx_queue_list[queue].queue_id;
1590 if (prepare_ptype_parser(portid, queueid) == 0)
1591 rte_exit(EXIT_FAILURE, "ptype check fails\n");
1595 check_all_ports_link_status(enabled_port_mask);
1598 /* launch per-lcore init on every lcore */
1599 rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MAIN);
1600 if (evt_rsrc->enabled) {
1601 for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++)
1602 rte_event_eth_rx_adapter_stop(
1603 evt_rsrc->rx_adptr.rx_adptr[i]);
1604 for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++)
1605 rte_event_eth_tx_adapter_stop(
1606 evt_rsrc->tx_adptr.tx_adptr[i]);
1608 RTE_ETH_FOREACH_DEV(portid) {
1609 if ((enabled_port_mask & (1 << portid)) == 0)
1611 ret = rte_eth_dev_stop(portid);
1613 printf("rte_eth_dev_stop: err=%d, port=%u\n",
1617 rte_eal_mp_wait_lcore();
1618 RTE_ETH_FOREACH_DEV(portid) {
1619 if ((enabled_port_mask & (1 << portid)) == 0)
1621 rte_eth_dev_close(portid);
1624 rte_event_dev_stop(evt_rsrc->event_d_id);
1625 rte_event_dev_close(evt_rsrc->event_d_id);
1628 rte_eal_mp_wait_lcore();
1630 RTE_ETH_FOREACH_DEV(portid) {
1631 if ((enabled_port_mask & (1 << portid)) == 0)
1633 printf("Closing port %d...", portid);
1634 ret = rte_eth_dev_stop(portid);
1636 printf("rte_eth_dev_stop: err=%d, port=%u\n",
1638 rte_eth_dev_close(portid);
1643 /* clean up config file routes */
1644 l3fwd_lkp.free_routes();
1646 /* clean up the EAL */