1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
4 * This file contain the application main file
5 * This application provides the user the ability to test the
6 * insertion rate for specific rte_flow rule under stress state ~4M rule/
8 * Then it will also provide packet per second measurement after installing
9 * all rules, the user may send traffic to test the PPS that match the rules
10 * after all rules are installed, to check performance or functionality after
13 * The flows insertion will go for all ports first, then it will print the
14 * results, after that the application will go into forwarding packets mode
15 * it will start receiving traffic if any and then forwarding it back and
16 * gives packet per second measurement.
30 #include <rte_malloc.h>
31 #include <rte_mempool.h>
33 #include <rte_ethdev.h>
38 static struct rte_mempool *mbuf_mp;
39 static uint32_t nb_lcores;
44 printf("\nusage: %s\n", progname);
48 args_parse(int argc, char **argv)
53 static struct option lgopts[] = {
60 while ((opt = getopt_long(argc, argvopt, "",
61 lgopts, &opt_idx)) != EOF) {
64 if (strcmp(lgopts[opt_idx].name, "help") == 0) {
66 rte_exit(EXIT_SUCCESS, "Displayed help\n");
70 fprintf(stderr, "Invalid option: %s\n", argv[optind]);
72 rte_exit(EXIT_SUCCESS, "Invalid option\n");
85 struct rte_eth_conf port_conf = {
91 struct rte_eth_txconf txq_conf;
92 struct rte_eth_rxconf rxq_conf;
93 struct rte_eth_dev_info dev_info;
95 nr_ports = rte_eth_dev_count_avail();
97 rte_exit(EXIT_FAILURE, "Error: no port detected\n");
99 mbuf_mp = rte_pktmbuf_pool_create("mbuf_pool",
100 TOTAL_MBUF_NUM, MBUF_CACHE_SIZE,
104 rte_exit(EXIT_FAILURE, "Error: can't init mbuf pool\n");
106 for (port_id = 0; port_id < nr_ports; port_id++) {
107 ret = rte_eth_dev_info_get(port_id, &dev_info);
109 rte_exit(EXIT_FAILURE,
110 "Error during getting device"
111 " (port %u) info: %s\n",
112 port_id, strerror(-ret));
114 port_conf.txmode.offloads &= dev_info.tx_offload_capa;
115 port_conf.rxmode.offloads &= dev_info.rx_offload_capa;
117 printf(":: initializing port: %d\n", port_id);
119 ret = rte_eth_dev_configure(port_id, RXQ_NUM,
120 TXQ_NUM, &port_conf);
122 rte_exit(EXIT_FAILURE,
123 ":: cannot configure device: err=%d, port=%u\n",
126 rxq_conf = dev_info.default_rxconf;
127 for (std_queue = 0; std_queue < RXQ_NUM; std_queue++) {
128 ret = rte_eth_rx_queue_setup(port_id, std_queue, NR_RXD,
129 rte_eth_dev_socket_id(port_id),
133 rte_exit(EXIT_FAILURE,
134 ":: Rx queue setup failed: err=%d, port=%u\n",
138 txq_conf = dev_info.default_txconf;
139 for (std_queue = 0; std_queue < TXQ_NUM; std_queue++) {
140 ret = rte_eth_tx_queue_setup(port_id, std_queue, NR_TXD,
141 rte_eth_dev_socket_id(port_id),
144 rte_exit(EXIT_FAILURE,
145 ":: Tx queue setup failed: err=%d, port=%u\n",
149 /* Catch all packets from traffic generator. */
150 ret = rte_eth_promiscuous_enable(port_id);
152 rte_exit(EXIT_FAILURE,
153 ":: promiscuous mode enable failed: err=%s, port=%u\n",
154 rte_strerror(-ret), port_id);
156 ret = rte_eth_dev_start(port_id);
158 rte_exit(EXIT_FAILURE,
159 "rte_eth_dev_start:err=%d, port=%u\n",
162 printf(":: initializing port: %d done\n", port_id);
167 main(int argc, char **argv)
171 struct rte_flow_error error;
173 ret = rte_eal_init(argc, argv);
175 rte_exit(EXIT_FAILURE, "EAL init failed\n");
180 args_parse(argc, argv);
184 nb_lcores = rte_lcore_count();
186 rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
188 RTE_ETH_FOREACH_DEV(port) {
189 rte_flow_flush(port, &error);
190 rte_eth_dev_stop(port);
191 rte_eth_dev_close(port);