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 hairpinq;
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 },
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) {
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) {
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, hairpinq, &error);
613 print_flow_error(error);
614 rte_exit(EXIT_FAILURE, "error in creating flow");
617 flow_list[flow_index++] = flow;
619 if (i && !((i + 1) % iterations_number)) {
620 /* Save the insertion rate of each iter */
622 delta = (double) (end_iter - start_iter);
623 iter_id = ((i + 1) / iterations_number) - 1;
624 cpu_time_per_iter[iter_id] =
625 delta / CLOCKS_PER_SEC;
626 cpu_time_used += cpu_time_per_iter[iter_id];
627 start_iter = clock();
631 /* Iteration rate per iteration */
633 for (i = 0; i < MAX_ITERATIONS; i++) {
634 if (cpu_time_per_iter[i] == -1)
636 delta = (double)(iterations_number /
637 cpu_time_per_iter[i]);
638 flows_rate = delta / 1000;
639 printf(":: Iteration #%d: %d flows "
640 "in %f sec[ Rate = %f K/Sec ]\n",
641 i, iterations_number,
642 cpu_time_per_iter[i], flows_rate);
645 /* Insertion rate for all flows */
646 flows_rate = ((double) (flows_count / cpu_time_used) / 1000);
647 printf("\n:: Total flow insertion rate -> %f K/Sec\n",
649 printf(":: The time for creating %d in flows %f seconds\n",
650 flows_count, cpu_time_used);
653 destroy_flows(port_id, flow_list);
658 signal_handler(int signum)
660 if (signum == SIGINT || signum == SIGTERM) {
661 printf("\n\nSignal %d received, preparing to exit...\n",
663 printf("Error: Stats are wrong due to sudden signal!\n\n");
668 static inline uint16_t
669 do_rx(struct lcore_info *li, uint16_t rx_port, uint16_t rx_queue)
672 cnt = rte_eth_rx_burst(rx_port, rx_queue, li->pkts, MAX_PKT_BURST);
678 do_tx(struct lcore_info *li, uint16_t cnt, uint16_t tx_port,
684 nr_tx = rte_eth_tx_burst(tx_port, tx_queue, li->pkts, cnt);
685 li->tx_pkts += nr_tx;
686 li->tx_drops += cnt - nr_tx;
688 for (i = nr_tx; i < cnt; i++)
689 rte_pktmbuf_free(li->pkts[i]);
693 * Method to convert numbers into pretty numbers that easy
694 * to read. The design here is to add comma after each three
695 * digits and set all of this inside buffer.
697 * For example if n = 1799321, the output will be
698 * 1,799,321 after this method which is easier to read.
701 pretty_number(uint64_t n, char *buf)
708 sprintf(p[i], "%03d", (int)(n % 1000));
713 sprintf(p[i++], "%d", (int)n);
716 off += sprintf(buf + off, "%s,", p[i]);
717 buf[strlen(buf) - 1] = '\0';
723 packet_per_second_stats(void)
725 struct lcore_info *old;
726 struct lcore_info *li, *oli;
730 old = rte_zmalloc("old",
731 sizeof(struct lcore_info) * MAX_LCORES, 0);
733 rte_exit(EXIT_FAILURE, "No Memory available!");
735 memcpy(old, lcore_infos,
736 sizeof(struct lcore_info) * MAX_LCORES);
738 while (!force_quit) {
739 uint64_t total_tx_pkts = 0;
740 uint64_t total_rx_pkts = 0;
741 uint64_t total_tx_drops = 0;
742 uint64_t tx_delta, rx_delta, drops_delta;
744 int nr_valid_core = 0;
749 char go_up_nr_lines[16];
751 sprintf(go_up_nr_lines, "%c[%dA\r", 27, nr_lines);
752 printf("%s\r", go_up_nr_lines);
755 printf("\n%6s %16s %16s %16s\n", "core", "tx", "tx drops", "rx");
756 printf("%6s %16s %16s %16s\n", "------", "----------------",
757 "----------------", "----------------");
759 for (i = 0; i < MAX_LCORES; i++) {
760 li = &lcore_infos[i];
762 if (li->mode != LCORE_MODE_PKT)
765 tx_delta = li->tx_pkts - oli->tx_pkts;
766 rx_delta = li->rx_pkts - oli->rx_pkts;
767 drops_delta = li->tx_drops - oli->tx_drops;
768 printf("%6d %16s %16s %16s\n", i,
769 pretty_number(tx_delta, buf[0]),
770 pretty_number(drops_delta, buf[1]),
771 pretty_number(rx_delta, buf[2]));
773 total_tx_pkts += tx_delta;
774 total_rx_pkts += rx_delta;
775 total_tx_drops += drops_delta;
781 if (nr_valid_core > 1) {
782 printf("%6s %16s %16s %16s\n", "total",
783 pretty_number(total_tx_pkts, buf[0]),
784 pretty_number(total_tx_drops, buf[1]),
785 pretty_number(total_rx_pkts, buf[2]));
789 memcpy(old, lcore_infos,
790 sizeof(struct lcore_info) * MAX_LCORES);
795 start_forwarding(void *data __rte_unused)
797 int lcore = rte_lcore_id();
800 struct lcore_info *li = &lcore_infos[lcore];
805 if (li->mode == LCORE_MODE_STATS) {
806 printf(":: started stats on lcore %u\n", lcore);
807 packet_per_second_stats();
812 for (stream_id = 0; stream_id < MAX_STREAMS; stream_id++) {
813 if (li->streams[stream_id].rx_port == -1)
817 li->streams[stream_id].rx_port,
818 li->streams[stream_id].rx_queue);
821 li->streams[stream_id].tx_port,
822 li->streams[stream_id].tx_queue);
828 init_lcore_info(void)
836 int streams_per_core;
837 int unassigned_streams;
839 nr_port = rte_eth_dev_count_avail();
841 /* First logical core is reserved for stats printing */
842 lcore = rte_get_next_lcore(-1, 0, 0);
843 lcore_infos[lcore].mode = LCORE_MODE_STATS;
846 * Initialize all cores
847 * All cores at first must have -1 value in all streams
848 * This means that this stream is not used, or not set
851 for (i = 0; i < MAX_LCORES; i++)
852 for (j = 0; j < MAX_STREAMS; j++) {
853 lcore_infos[i].streams[j].tx_port = -1;
854 lcore_infos[i].streams[j].rx_port = -1;
855 lcore_infos[i].streams[j].tx_queue = -1;
856 lcore_infos[i].streams[j].rx_queue = -1;
857 lcore_infos[i].streams_nb = 0;
861 * Calculate the total streams count.
862 * Also distribute those streams count between the available
863 * logical cores except first core, since it's reserved for
866 nb_fwd_streams = nr_port * RXQ_NUM;
867 if ((int)(nb_lcores - 1) >= nb_fwd_streams)
868 for (i = 0; i < (int)(nb_lcores - 1); i++) {
869 lcore = rte_get_next_lcore(lcore, 0, 0);
870 lcore_infos[lcore].streams_nb = 1;
873 streams_per_core = nb_fwd_streams / (nb_lcores - 1);
874 unassigned_streams = nb_fwd_streams % (nb_lcores - 1);
875 for (i = 0; i < (int)(nb_lcores - 1); i++) {
876 lcore = rte_get_next_lcore(lcore, 0, 0);
877 lcore_infos[lcore].streams_nb = streams_per_core;
878 if (unassigned_streams) {
879 lcore_infos[lcore].streams_nb++;
880 unassigned_streams--;
886 * Set the streams for the cores according to each logical
888 * The streams is built on the design of what received should
889 * forward as well, this means that if you received packets on
890 * port 0 queue 0 then the same queue should forward the
891 * packets, using the same logical core.
893 lcore = rte_get_next_lcore(-1, 0, 0);
894 for (port = 0; port < nr_port; port++) {
895 /* Create FWD stream */
896 for (queue = 0; queue < RXQ_NUM; queue++) {
897 if (!lcore_infos[lcore].streams_nb ||
898 !(stream_id % lcore_infos[lcore].streams_nb)) {
899 lcore = rte_get_next_lcore(lcore, 0, 0);
900 lcore_infos[lcore].mode = LCORE_MODE_PKT;
903 lcore_infos[lcore].streams[stream_id].rx_queue = queue;
904 lcore_infos[lcore].streams[stream_id].tx_queue = queue;
905 lcore_infos[lcore].streams[stream_id].rx_port = port;
906 lcore_infos[lcore].streams[stream_id].tx_port = port;
911 /* Print all streams */
912 printf(":: Stream -> core id[N]: (rx_port, rx_queue)->(tx_port, tx_queue)\n");
913 for (i = 0; i < MAX_LCORES; i++)
914 for (j = 0; j < MAX_STREAMS; j++) {
915 /* No streams for this core */
916 if (lcore_infos[i].streams[j].tx_port == -1)
918 printf("Stream -> core id[%d]: (%d,%d)->(%d,%d)\n",
920 lcore_infos[i].streams[j].rx_port,
921 lcore_infos[i].streams[j].rx_queue,
922 lcore_infos[i].streams[j].tx_port,
923 lcore_infos[i].streams[j].tx_queue);
936 struct rte_eth_hairpin_conf hairpin_conf = {
939 struct rte_eth_conf port_conf = {
945 struct rte_eth_txconf txq_conf;
946 struct rte_eth_rxconf rxq_conf;
947 struct rte_eth_dev_info dev_info;
951 nr_queues = RXQ_NUM + hairpinq;
953 nr_ports = rte_eth_dev_count_avail();
955 rte_exit(EXIT_FAILURE, "Error: no port detected\n");
957 mbuf_mp = rte_pktmbuf_pool_create("mbuf_pool",
958 TOTAL_MBUF_NUM, MBUF_CACHE_SIZE,
962 rte_exit(EXIT_FAILURE, "Error: can't init mbuf pool\n");
964 for (port_id = 0; port_id < nr_ports; port_id++) {
965 ret = rte_eth_dev_info_get(port_id, &dev_info);
967 rte_exit(EXIT_FAILURE,
968 "Error during getting device"
969 " (port %u) info: %s\n",
970 port_id, strerror(-ret));
972 port_conf.txmode.offloads &= dev_info.tx_offload_capa;
973 port_conf.rxmode.offloads &= dev_info.rx_offload_capa;
975 printf(":: initializing port: %d\n", port_id);
977 ret = rte_eth_dev_configure(port_id, nr_queues,
978 nr_queues, &port_conf);
980 rte_exit(EXIT_FAILURE,
981 ":: cannot configure device: err=%d, port=%u\n",
984 rxq_conf = dev_info.default_rxconf;
985 for (std_queue = 0; std_queue < RXQ_NUM; std_queue++) {
986 ret = rte_eth_rx_queue_setup(port_id, std_queue, NR_RXD,
987 rte_eth_dev_socket_id(port_id),
991 rte_exit(EXIT_FAILURE,
992 ":: Rx queue setup failed: err=%d, port=%u\n",
996 txq_conf = dev_info.default_txconf;
997 for (std_queue = 0; std_queue < TXQ_NUM; std_queue++) {
998 ret = rte_eth_tx_queue_setup(port_id, std_queue, NR_TXD,
999 rte_eth_dev_socket_id(port_id),
1002 rte_exit(EXIT_FAILURE,
1003 ":: Tx queue setup failed: err=%d, port=%u\n",
1007 /* Catch all packets from traffic generator. */
1008 ret = rte_eth_promiscuous_enable(port_id);
1010 rte_exit(EXIT_FAILURE,
1011 ":: promiscuous mode enable failed: err=%s, port=%u\n",
1012 rte_strerror(-ret), port_id);
1014 if (hairpinq != 0) {
1015 for (hairpin_q = RXQ_NUM, std_queue = 0;
1016 std_queue < nr_queues;
1017 hairpin_q++, std_queue++) {
1018 hairpin_conf.peers[0].port = port_id;
1019 hairpin_conf.peers[0].queue =
1020 std_queue + TXQ_NUM;
1021 ret = rte_eth_rx_hairpin_queue_setup(
1023 NR_RXD, &hairpin_conf);
1025 rte_exit(EXIT_FAILURE,
1026 ":: Hairpin rx queue setup failed: err=%d, port=%u\n",
1030 for (hairpin_q = TXQ_NUM, std_queue = 0;
1031 std_queue < nr_queues;
1032 hairpin_q++, std_queue++) {
1033 hairpin_conf.peers[0].port = port_id;
1034 hairpin_conf.peers[0].queue =
1035 std_queue + RXQ_NUM;
1036 ret = rte_eth_tx_hairpin_queue_setup(
1038 NR_TXD, &hairpin_conf);
1040 rte_exit(EXIT_FAILURE,
1041 ":: Hairpin tx queue setup failed: err=%d, port=%u\n",
1046 ret = rte_eth_dev_start(port_id);
1048 rte_exit(EXIT_FAILURE,
1049 "rte_eth_dev_start:err=%d, port=%u\n",
1052 printf(":: initializing port: %d done\n", port_id);
1057 main(int argc, char **argv)
1061 struct rte_flow_error error;
1062 int64_t alloc, last_alloc;
1064 ret = rte_eal_init(argc, argv);
1066 rte_exit(EXIT_FAILURE, "EAL init failed\n");
1069 dump_iterations = false;
1070 flows_count = DEFAULT_RULES_COUNT;
1071 iterations_number = DEFAULT_ITERATION;
1072 delete_flag = false;
1073 dump_socket_mem_flag = false;
1076 signal(SIGINT, signal_handler);
1077 signal(SIGTERM, signal_handler);
1082 args_parse(argc, argv);
1086 nb_lcores = rte_lcore_count();
1088 rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
1090 last_alloc = (int64_t)dump_socket_mem(stdout);
1092 alloc = (int64_t)dump_socket_mem(stdout);
1095 fprintf(stdout, ":: Memory allocation change(M): %.6lf\n",
1096 (alloc - last_alloc) / 1.0e6);
1100 rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MASTER);
1103 RTE_ETH_FOREACH_DEV(port) {
1104 rte_flow_flush(port, &error);
1105 rte_eth_dev_stop(port);
1106 rte_eth_dev_close(port);