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.
32 #include <rte_malloc.h>
33 #include <rte_mempool.h>
35 #include <rte_ethdev.h>
41 #define MAX_ITERATIONS 100
42 #define DEFAULT_RULES_COUNT 4000000
43 #define DEFAULT_ITERATION 100000
45 struct rte_flow *flow;
46 static uint8_t flow_group;
48 static uint64_t flow_items;
49 static uint64_t flow_actions;
50 static uint64_t flow_attrs;
52 static volatile bool force_quit;
53 static bool dump_iterations;
54 static bool delete_flag;
55 static bool dump_socket_mem_flag;
56 static bool enable_fwd;
58 static struct rte_mempool *mbuf_mp;
59 static uint32_t nb_lcores;
60 static uint32_t flows_count;
61 static uint32_t iterations_number;
62 static uint32_t hairpin_queues_num; /* total hairpin q number - default: 0 */
63 static uint32_t nb_lcores;
65 #define MAX_PKT_BURST 32
66 #define LCORE_MODE_PKT 1
67 #define LCORE_MODE_STATS 2
68 #define MAX_STREAMS 64
81 struct stream streams[MAX_STREAMS];
86 struct rte_mbuf *pkts[MAX_PKT_BURST];
87 } __rte_cache_aligned;
89 static struct lcore_info lcore_infos[MAX_LCORES];
94 printf("\nusage: %s\n", progname);
95 printf("\nControl configurations:\n");
96 printf(" --flows-count=N: to set the number of needed"
97 " flows to insert, default is 4,000,000\n");
98 printf(" --dump-iterations: To print rates for each"
100 printf(" --deletion-rate: Enable deletion rate"
102 printf(" --dump-socket-mem: To dump all socket memory\n");
103 printf(" --enable-fwd: To enable packets forwarding"
104 " after insertion\n");
106 printf("To set flow attributes:\n");
107 printf(" --ingress: set ingress attribute in flows\n");
108 printf(" --egress: set egress attribute in flows\n");
109 printf(" --transfer: set transfer attribute in flows\n");
110 printf(" --group=N: set group for all flows,"
113 printf("To set flow items:\n");
114 printf(" --ether: add ether layer in flow items\n");
115 printf(" --vlan: add vlan layer in flow items\n");
116 printf(" --ipv4: add ipv4 layer in flow items\n");
117 printf(" --ipv6: add ipv6 layer in flow items\n");
118 printf(" --tcp: add tcp layer in flow items\n");
119 printf(" --udp: add udp layer in flow items\n");
120 printf(" --vxlan: add vxlan layer in flow items\n");
121 printf(" --vxlan-gpe: add vxlan-gpe layer in flow items\n");
122 printf(" --gre: add gre layer in flow items\n");
123 printf(" --geneve: add geneve layer in flow items\n");
124 printf(" --gtp: add gtp layer in flow items\n");
125 printf(" --meta: add meta layer in flow items\n");
126 printf(" --tag: add tag layer in flow items\n");
128 printf("To set flow actions:\n");
129 printf(" --port-id: add port-id action in flow actions\n");
130 printf(" --rss: add rss action in flow actions\n");
131 printf(" --queue: add queue action in flow actions\n");
132 printf(" --jump: add jump action in flow actions\n");
133 printf(" --mark: add mark action in flow actions\n");
134 printf(" --count: add count action in flow actions\n");
135 printf(" --set-meta: add set meta action in flow actions\n");
136 printf(" --set-tag: add set tag action in flow actions\n");
137 printf(" --drop: add drop action in flow actions\n");
138 printf(" --hairpin-queue=N: add hairpin-queue action in flow actions\n");
139 printf(" --hairpin-rss=N: add hairping-rss action in flow actions\n");
143 args_parse(int argc, char **argv)
150 static const struct option_dict {
157 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH),
158 .bitmap = &flow_items
162 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV4),
163 .bitmap = &flow_items
167 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV6),
168 .bitmap = &flow_items
172 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VLAN),
173 .bitmap = &flow_items
177 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TCP),
178 .bitmap = &flow_items
182 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_UDP),
183 .bitmap = &flow_items
187 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN),
188 .bitmap = &flow_items
192 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN_GPE),
193 .bitmap = &flow_items
197 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GRE),
198 .bitmap = &flow_items
202 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GENEVE),
203 .bitmap = &flow_items
207 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GTP),
208 .bitmap = &flow_items
212 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_META),
213 .bitmap = &flow_items
217 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TAG),
218 .bitmap = &flow_items
223 .bitmap = &flow_attrs
228 .bitmap = &flow_attrs
233 .bitmap = &flow_attrs
237 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_PORT_ID),
238 .bitmap = &flow_actions
242 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_RSS),
243 .bitmap = &flow_actions
247 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_QUEUE),
248 .bitmap = &flow_actions
252 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_JUMP),
253 .bitmap = &flow_actions
257 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_MARK),
258 .bitmap = &flow_actions
262 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_COUNT),
263 .bitmap = &flow_actions
267 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_META),
268 .bitmap = &flow_actions
272 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_TAG),
273 .bitmap = &flow_actions
277 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP),
278 .bitmap = &flow_actions
282 static const struct option lgopts[] = {
285 { "flows-count", 1, 0, 0 },
286 { "dump-iterations", 0, 0, 0 },
287 { "deletion-rate", 0, 0, 0 },
288 { "dump-socket-mem", 0, 0, 0 },
289 { "enable-fwd", 0, 0, 0 },
291 { "ingress", 0, 0, 0 },
292 { "egress", 0, 0, 0 },
293 { "transfer", 0, 0, 0 },
294 { "group", 1, 0, 0 },
296 { "ether", 0, 0, 0 },
302 { "vxlan", 0, 0, 0 },
303 { "vxlan-gpe", 0, 0, 0 },
305 { "geneve", 0, 0, 0 },
310 { "port-id", 0, 0, 0 },
312 { "queue", 0, 0, 0 },
315 { "count", 0, 0, 0 },
316 { "set-meta", 0, 0, 0 },
317 { "set-tag", 0, 0, 0 },
319 { "hairpin-queue", 1, 0, 0 },
320 { "hairpin-rss", 1, 0, 0 },
326 hairpin_queues_num = 0;
329 printf(":: Flow -> ");
330 while ((opt = getopt_long(argc, argvopt, "",
331 lgopts, &opt_idx)) != EOF) {
334 if (strcmp(lgopts[opt_idx].name, "help") == 0) {
336 rte_exit(EXIT_SUCCESS, "Displayed help\n");
339 if (strcmp(lgopts[opt_idx].name, "group") == 0) {
344 rte_exit(EXIT_SUCCESS,
345 "flow group should be >= 0\n");
346 printf("group %d ", flow_group);
349 for (i = 0; i < RTE_DIM(flow_options); i++)
350 if (strcmp(lgopts[opt_idx].name,
351 flow_options[i].str) == 0) {
352 *flow_options[i].bitmap |=
353 flow_options[i].mask;
354 printf("%s / ", flow_options[i].str);
357 if (strcmp(lgopts[opt_idx].name,
358 "hairpin-rss") == 0) {
361 hairpin_queues_num = n;
363 rte_exit(EXIT_SUCCESS,
364 "Hairpin queues should be > 0\n");
366 flow_actions |= HAIRPIN_RSS_ACTION;
367 printf("hairpin-rss / ");
369 if (strcmp(lgopts[opt_idx].name,
370 "hairpin-queue") == 0) {
373 hairpin_queues_num = n;
375 rte_exit(EXIT_SUCCESS,
376 "Hairpin queues should be > 0\n");
378 flow_actions |= HAIRPIN_QUEUE_ACTION;
379 printf("hairpin-queue / ");
383 if (strcmp(lgopts[opt_idx].name,
384 "flows-count") == 0) {
386 if (n > (int) iterations_number)
389 printf("\n\nflows_count should be > %d\n",
391 rte_exit(EXIT_SUCCESS, " ");
394 if (strcmp(lgopts[opt_idx].name,
395 "dump-iterations") == 0)
396 dump_iterations = true;
397 if (strcmp(lgopts[opt_idx].name,
398 "deletion-rate") == 0)
400 if (strcmp(lgopts[opt_idx].name,
401 "dump-socket-mem") == 0)
402 dump_socket_mem_flag = true;
403 if (strcmp(lgopts[opt_idx].name,
408 fprintf(stderr, "Invalid option: %s\n", argv[optind]);
410 rte_exit(EXIT_SUCCESS, "Invalid option\n");
414 printf("end_flow\n");
417 /* Dump the socket memory statistics on console */
419 dump_socket_mem(FILE *f)
421 struct rte_malloc_socket_stats socket_stats;
426 unsigned int n_alloc = 0;
427 unsigned int n_free = 0;
428 bool active_nodes = false;
431 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
432 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
433 !socket_stats.heap_totalsz_bytes)
436 total += socket_stats.heap_totalsz_bytes;
437 alloc += socket_stats.heap_allocsz_bytes;
438 free += socket_stats.heap_freesz_bytes;
439 n_alloc += socket_stats.alloc_count;
440 n_free += socket_stats.free_count;
441 if (dump_socket_mem_flag) {
442 fprintf(f, "::::::::::::::::::::::::::::::::::::::::");
444 "\nSocket %u:\nsize(M) total: %.6lf\nalloc:"
445 " %.6lf(%.3lf%%)\nfree: %.6lf"
447 "\ncount alloc: %u\nfree: %u\n",
449 socket_stats.heap_totalsz_bytes / 1.0e6,
450 socket_stats.heap_allocsz_bytes / 1.0e6,
451 (double)socket_stats.heap_allocsz_bytes * 100 /
452 (double)socket_stats.heap_totalsz_bytes,
453 socket_stats.heap_freesz_bytes / 1.0e6,
454 socket_stats.greatest_free_size / 1.0e6,
455 socket_stats.alloc_count,
456 socket_stats.free_count);
457 fprintf(f, "::::::::::::::::::::::::::::::::::::::::");
460 if (dump_socket_mem_flag && active_nodes) {
462 "\nTotal: size(M)\ntotal: %.6lf"
463 "\nalloc: %.6lf(%.3lf%%)\nfree: %.6lf"
464 "\ncount alloc: %u\nfree: %u\n",
465 total / 1.0e6, alloc / 1.0e6,
466 (double)alloc * 100 / (double)total, free / 1.0e6,
468 fprintf(f, "::::::::::::::::::::::::::::::::::::::::\n");
474 print_flow_error(struct rte_flow_error error)
476 printf("Flow can't be created %d message: %s\n",
478 error.message ? error.message : "(no stated reason)");
482 destroy_flows(int port_id, struct rte_flow **flow_list)
484 struct rte_flow_error error;
485 clock_t start_iter, end_iter;
486 double cpu_time_used = 0;
488 double cpu_time_per_iter[MAX_ITERATIONS];
493 for (i = 0; i < MAX_ITERATIONS; i++)
494 cpu_time_per_iter[i] = -1;
496 if (iterations_number > flows_count)
497 iterations_number = flows_count;
500 printf("Flows Deletion on port = %d\n", port_id);
501 start_iter = clock();
502 for (i = 0; i < flows_count; i++) {
503 if (flow_list[i] == 0)
506 memset(&error, 0x33, sizeof(error));
507 if (rte_flow_destroy(port_id, flow_list[i], &error)) {
508 print_flow_error(error);
509 rte_exit(EXIT_FAILURE, "Error in deleting flow");
512 if (i && !((i + 1) % iterations_number)) {
513 /* Save the deletion rate of each iter */
515 delta = (double) (end_iter - start_iter);
516 iter_id = ((i + 1) / iterations_number) - 1;
517 cpu_time_per_iter[iter_id] =
518 delta / CLOCKS_PER_SEC;
519 cpu_time_used += cpu_time_per_iter[iter_id];
520 start_iter = clock();
524 /* Deletion rate per iteration */
526 for (i = 0; i < MAX_ITERATIONS; i++) {
527 if (cpu_time_per_iter[i] == -1)
529 delta = (double)(iterations_number /
530 cpu_time_per_iter[i]);
531 flows_rate = delta / 1000;
532 printf(":: Iteration #%d: %d flows "
533 "in %f sec[ Rate = %f K/Sec ]\n",
534 i, iterations_number,
535 cpu_time_per_iter[i], flows_rate);
538 /* Deletion rate for all flows */
539 flows_rate = ((double) (flows_count / cpu_time_used) / 1000);
540 printf("\n:: Total flow deletion rate -> %f K/Sec\n",
542 printf(":: The time for deleting %d in flows %f seconds\n",
543 flows_count, cpu_time_used);
549 struct rte_flow **flow_list;
550 struct rte_flow_error error;
551 clock_t start_iter, end_iter;
552 double cpu_time_used;
554 double cpu_time_per_iter[MAX_ITERATIONS];
562 nr_ports = rte_eth_dev_count_avail();
564 for (i = 0; i < MAX_ITERATIONS; i++)
565 cpu_time_per_iter[i] = -1;
567 if (iterations_number > flows_count)
568 iterations_number = flows_count;
570 printf(":: Flows Count per port: %d\n", flows_count);
572 flow_list = rte_zmalloc("flow_list",
573 (sizeof(struct rte_flow *) * flows_count) + 1, 0);
574 if (flow_list == NULL)
575 rte_exit(EXIT_FAILURE, "No Memory available!");
577 for (port_id = 0; port_id < nr_ports; port_id++) {
580 if (flow_group > 0) {
582 * Create global rule to jump into flow_group,
583 * this way the app will avoid the default rules.
586 * group 0 eth / end actions jump group <flow_group>
589 flow = generate_flow(port_id, 0, flow_attrs,
590 FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH),
591 FLOW_ITEM_MASK(RTE_FLOW_ACTION_TYPE_JUMP),
592 flow_group, 0, 0, &error);
595 print_flow_error(error);
596 rte_exit(EXIT_FAILURE, "error in creating flow");
598 flow_list[flow_index++] = flow;
602 printf("Flows insertion on port = %d\n", port_id);
603 start_iter = clock();
604 for (i = 0; i < flows_count; i++) {
605 flow = generate_flow(port_id, flow_group,
606 flow_attrs, flow_items, flow_actions,
607 JUMP_ACTION_TABLE, i,
608 hairpin_queues_num, &error);
614 print_flow_error(error);
615 rte_exit(EXIT_FAILURE, "error in creating flow");
618 flow_list[flow_index++] = flow;
620 if (i && !((i + 1) % iterations_number)) {
621 /* Save the insertion rate of each iter */
623 delta = (double) (end_iter - start_iter);
624 iter_id = ((i + 1) / iterations_number) - 1;
625 cpu_time_per_iter[iter_id] =
626 delta / CLOCKS_PER_SEC;
627 cpu_time_used += cpu_time_per_iter[iter_id];
628 start_iter = clock();
632 /* Iteration rate per iteration */
634 for (i = 0; i < MAX_ITERATIONS; i++) {
635 if (cpu_time_per_iter[i] == -1)
637 delta = (double)(iterations_number /
638 cpu_time_per_iter[i]);
639 flows_rate = delta / 1000;
640 printf(":: Iteration #%d: %d flows "
641 "in %f sec[ Rate = %f K/Sec ]\n",
642 i, iterations_number,
643 cpu_time_per_iter[i], flows_rate);
646 /* Insertion rate for all flows */
647 flows_rate = ((double) (flows_count / cpu_time_used) / 1000);
648 printf("\n:: Total flow insertion rate -> %f K/Sec\n",
650 printf(":: The time for creating %d in flows %f seconds\n",
651 flows_count, cpu_time_used);
654 destroy_flows(port_id, flow_list);
659 signal_handler(int signum)
661 if (signum == SIGINT || signum == SIGTERM) {
662 printf("\n\nSignal %d received, preparing to exit...\n",
664 printf("Error: Stats are wrong due to sudden signal!\n\n");
669 static inline uint16_t
670 do_rx(struct lcore_info *li, uint16_t rx_port, uint16_t rx_queue)
673 cnt = rte_eth_rx_burst(rx_port, rx_queue, li->pkts, MAX_PKT_BURST);
679 do_tx(struct lcore_info *li, uint16_t cnt, uint16_t tx_port,
685 nr_tx = rte_eth_tx_burst(tx_port, tx_queue, li->pkts, cnt);
686 li->tx_pkts += nr_tx;
687 li->tx_drops += cnt - nr_tx;
689 for (i = nr_tx; i < cnt; i++)
690 rte_pktmbuf_free(li->pkts[i]);
694 * Method to convert numbers into pretty numbers that easy
695 * to read. The design here is to add comma after each three
696 * digits and set all of this inside buffer.
698 * For example if n = 1799321, the output will be
699 * 1,799,321 after this method which is easier to read.
702 pretty_number(uint64_t n, char *buf)
709 sprintf(p[i], "%03d", (int)(n % 1000));
714 sprintf(p[i++], "%d", (int)n);
717 off += sprintf(buf + off, "%s,", p[i]);
718 buf[strlen(buf) - 1] = '\0';
724 packet_per_second_stats(void)
726 struct lcore_info *old;
727 struct lcore_info *li, *oli;
731 old = rte_zmalloc("old",
732 sizeof(struct lcore_info) * MAX_LCORES, 0);
734 rte_exit(EXIT_FAILURE, "No Memory available!");
736 memcpy(old, lcore_infos,
737 sizeof(struct lcore_info) * MAX_LCORES);
739 while (!force_quit) {
740 uint64_t total_tx_pkts = 0;
741 uint64_t total_rx_pkts = 0;
742 uint64_t total_tx_drops = 0;
743 uint64_t tx_delta, rx_delta, drops_delta;
745 int nr_valid_core = 0;
750 char go_up_nr_lines[16];
752 sprintf(go_up_nr_lines, "%c[%dA\r", 27, nr_lines);
753 printf("%s\r", go_up_nr_lines);
756 printf("\n%6s %16s %16s %16s\n", "core", "tx", "tx drops", "rx");
757 printf("%6s %16s %16s %16s\n", "------", "----------------",
758 "----------------", "----------------");
760 for (i = 0; i < MAX_LCORES; i++) {
761 li = &lcore_infos[i];
763 if (li->mode != LCORE_MODE_PKT)
766 tx_delta = li->tx_pkts - oli->tx_pkts;
767 rx_delta = li->rx_pkts - oli->rx_pkts;
768 drops_delta = li->tx_drops - oli->tx_drops;
769 printf("%6d %16s %16s %16s\n", i,
770 pretty_number(tx_delta, buf[0]),
771 pretty_number(drops_delta, buf[1]),
772 pretty_number(rx_delta, buf[2]));
774 total_tx_pkts += tx_delta;
775 total_rx_pkts += rx_delta;
776 total_tx_drops += drops_delta;
782 if (nr_valid_core > 1) {
783 printf("%6s %16s %16s %16s\n", "total",
784 pretty_number(total_tx_pkts, buf[0]),
785 pretty_number(total_tx_drops, buf[1]),
786 pretty_number(total_rx_pkts, buf[2]));
790 memcpy(old, lcore_infos,
791 sizeof(struct lcore_info) * MAX_LCORES);
796 start_forwarding(void *data __rte_unused)
798 int lcore = rte_lcore_id();
801 struct lcore_info *li = &lcore_infos[lcore];
806 if (li->mode == LCORE_MODE_STATS) {
807 printf(":: started stats on lcore %u\n", lcore);
808 packet_per_second_stats();
813 for (stream_id = 0; stream_id < MAX_STREAMS; stream_id++) {
814 if (li->streams[stream_id].rx_port == -1)
818 li->streams[stream_id].rx_port,
819 li->streams[stream_id].rx_queue);
822 li->streams[stream_id].tx_port,
823 li->streams[stream_id].tx_queue);
829 init_lcore_info(void)
837 int streams_per_core;
838 int unassigned_streams;
840 nr_port = rte_eth_dev_count_avail();
842 /* First logical core is reserved for stats printing */
843 lcore = rte_get_next_lcore(-1, 0, 0);
844 lcore_infos[lcore].mode = LCORE_MODE_STATS;
847 * Initialize all cores
848 * All cores at first must have -1 value in all streams
849 * This means that this stream is not used, or not set
852 for (i = 0; i < MAX_LCORES; i++)
853 for (j = 0; j < MAX_STREAMS; j++) {
854 lcore_infos[i].streams[j].tx_port = -1;
855 lcore_infos[i].streams[j].rx_port = -1;
856 lcore_infos[i].streams[j].tx_queue = -1;
857 lcore_infos[i].streams[j].rx_queue = -1;
858 lcore_infos[i].streams_nb = 0;
862 * Calculate the total streams count.
863 * Also distribute those streams count between the available
864 * logical cores except first core, since it's reserved for
867 nb_fwd_streams = nr_port * RXQ_NUM;
868 if ((int)(nb_lcores - 1) >= nb_fwd_streams)
869 for (i = 0; i < (int)(nb_lcores - 1); i++) {
870 lcore = rte_get_next_lcore(lcore, 0, 0);
871 lcore_infos[lcore].streams_nb = 1;
874 streams_per_core = nb_fwd_streams / (nb_lcores - 1);
875 unassigned_streams = nb_fwd_streams % (nb_lcores - 1);
876 for (i = 0; i < (int)(nb_lcores - 1); i++) {
877 lcore = rte_get_next_lcore(lcore, 0, 0);
878 lcore_infos[lcore].streams_nb = streams_per_core;
879 if (unassigned_streams) {
880 lcore_infos[lcore].streams_nb++;
881 unassigned_streams--;
887 * Set the streams for the cores according to each logical
889 * The streams is built on the design of what received should
890 * forward as well, this means that if you received packets on
891 * port 0 queue 0 then the same queue should forward the
892 * packets, using the same logical core.
894 lcore = rte_get_next_lcore(-1, 0, 0);
895 for (port = 0; port < nr_port; port++) {
896 /* Create FWD stream */
897 for (queue = 0; queue < RXQ_NUM; queue++) {
898 if (!lcore_infos[lcore].streams_nb ||
899 !(stream_id % lcore_infos[lcore].streams_nb)) {
900 lcore = rte_get_next_lcore(lcore, 0, 0);
901 lcore_infos[lcore].mode = LCORE_MODE_PKT;
904 lcore_infos[lcore].streams[stream_id].rx_queue = queue;
905 lcore_infos[lcore].streams[stream_id].tx_queue = queue;
906 lcore_infos[lcore].streams[stream_id].rx_port = port;
907 lcore_infos[lcore].streams[stream_id].tx_port = port;
912 /* Print all streams */
913 printf(":: Stream -> core id[N]: (rx_port, rx_queue)->(tx_port, tx_queue)\n");
914 for (i = 0; i < MAX_LCORES; i++)
915 for (j = 0; j < MAX_STREAMS; j++) {
916 /* No streams for this core */
917 if (lcore_infos[i].streams[j].tx_port == -1)
919 printf("Stream -> core id[%d]: (%d,%d)->(%d,%d)\n",
921 lcore_infos[i].streams[j].rx_port,
922 lcore_infos[i].streams[j].rx_queue,
923 lcore_infos[i].streams[j].tx_port,
924 lcore_infos[i].streams[j].tx_queue);
933 uint16_t hairpin_queue;
937 struct rte_eth_hairpin_conf hairpin_conf = {
940 struct rte_eth_conf port_conf = {
946 struct rte_eth_txconf txq_conf;
947 struct rte_eth_rxconf rxq_conf;
948 struct rte_eth_dev_info dev_info;
951 if (hairpin_queues_num != 0)
952 nr_queues = RXQ_NUM + hairpin_queues_num;
954 nr_ports = rte_eth_dev_count_avail();
956 rte_exit(EXIT_FAILURE, "Error: no port detected\n");
958 mbuf_mp = rte_pktmbuf_pool_create("mbuf_pool",
959 TOTAL_MBUF_NUM, MBUF_CACHE_SIZE,
963 rte_exit(EXIT_FAILURE, "Error: can't init mbuf pool\n");
965 for (port_id = 0; port_id < nr_ports; port_id++) {
966 ret = rte_eth_dev_info_get(port_id, &dev_info);
968 rte_exit(EXIT_FAILURE,
969 "Error during getting device"
970 " (port %u) info: %s\n",
971 port_id, strerror(-ret));
973 port_conf.txmode.offloads &= dev_info.tx_offload_capa;
974 port_conf.rxmode.offloads &= dev_info.rx_offload_capa;
976 printf(":: initializing port: %d\n", port_id);
978 ret = rte_eth_dev_configure(port_id, nr_queues,
979 nr_queues, &port_conf);
981 rte_exit(EXIT_FAILURE,
982 ":: cannot configure device: err=%d, port=%u\n",
985 rxq_conf = dev_info.default_rxconf;
986 for (std_queue = 0; std_queue < RXQ_NUM; std_queue++) {
987 ret = rte_eth_rx_queue_setup(port_id, std_queue, NR_RXD,
988 rte_eth_dev_socket_id(port_id),
992 rte_exit(EXIT_FAILURE,
993 ":: Rx queue setup failed: err=%d, port=%u\n",
997 txq_conf = dev_info.default_txconf;
998 for (std_queue = 0; std_queue < TXQ_NUM; std_queue++) {
999 ret = rte_eth_tx_queue_setup(port_id, std_queue, NR_TXD,
1000 rte_eth_dev_socket_id(port_id),
1003 rte_exit(EXIT_FAILURE,
1004 ":: Tx queue setup failed: err=%d, port=%u\n",
1008 /* Catch all packets from traffic generator. */
1009 ret = rte_eth_promiscuous_enable(port_id);
1011 rte_exit(EXIT_FAILURE,
1012 ":: promiscuous mode enable failed: err=%s, port=%u\n",
1013 rte_strerror(-ret), port_id);
1015 if (hairpin_queues_num != 0) {
1017 * Configure peer which represents hairpin Tx.
1018 * Hairpin queue numbers start after standard queues
1019 * (RXQ_NUM and TXQ_NUM).
1021 for (hairpin_queue = RXQ_NUM, std_queue = 0;
1022 hairpin_queue < nr_queues;
1023 hairpin_queue++, std_queue++) {
1024 hairpin_conf.peers[0].port = port_id;
1025 hairpin_conf.peers[0].queue =
1026 std_queue + TXQ_NUM;
1027 ret = rte_eth_rx_hairpin_queue_setup(
1028 port_id, hairpin_queue,
1029 NR_RXD, &hairpin_conf);
1031 rte_exit(EXIT_FAILURE,
1032 ":: Hairpin rx queue setup failed: err=%d, port=%u\n",
1036 for (hairpin_queue = TXQ_NUM, std_queue = 0;
1037 hairpin_queue < nr_queues;
1038 hairpin_queue++, std_queue++) {
1039 hairpin_conf.peers[0].port = port_id;
1040 hairpin_conf.peers[0].queue =
1041 std_queue + RXQ_NUM;
1042 ret = rte_eth_tx_hairpin_queue_setup(
1043 port_id, hairpin_queue,
1044 NR_TXD, &hairpin_conf);
1046 rte_exit(EXIT_FAILURE,
1047 ":: Hairpin tx queue setup failed: err=%d, port=%u\n",
1052 ret = rte_eth_dev_start(port_id);
1054 rte_exit(EXIT_FAILURE,
1055 "rte_eth_dev_start:err=%d, port=%u\n",
1058 printf(":: initializing port: %d done\n", port_id);
1063 main(int argc, char **argv)
1067 struct rte_flow_error error;
1068 int64_t alloc, last_alloc;
1070 ret = rte_eal_init(argc, argv);
1072 rte_exit(EXIT_FAILURE, "EAL init failed\n");
1075 dump_iterations = false;
1076 flows_count = DEFAULT_RULES_COUNT;
1077 iterations_number = DEFAULT_ITERATION;
1078 delete_flag = false;
1079 dump_socket_mem_flag = false;
1082 signal(SIGINT, signal_handler);
1083 signal(SIGTERM, signal_handler);
1088 args_parse(argc, argv);
1092 nb_lcores = rte_lcore_count();
1094 rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
1096 last_alloc = (int64_t)dump_socket_mem(stdout);
1098 alloc = (int64_t)dump_socket_mem(stdout);
1101 fprintf(stdout, ":: Memory allocation change(M): %.6lf\n",
1102 (alloc - last_alloc) / 1.0e6);
1106 rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MASTER);
1109 RTE_ETH_FOREACH_DEV(port) {
1110 rte_flow_flush(port, &error);
1111 rte_eth_dev_stop(port);
1112 rte_eth_dev_close(port);