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_BATCHES_COUNT 100
42 #define DEFAULT_RULES_COUNT 4000000
43 #define DEFAULT_RULES_BATCH 100000
44 #define DEFAULT_GROUP 0
46 struct rte_flow *flow;
47 static uint8_t flow_group;
49 static uint64_t encap_data;
50 static uint64_t decap_data;
52 static uint64_t flow_items[MAX_ITEMS_NUM];
53 static uint64_t flow_actions[MAX_ACTIONS_NUM];
54 static uint64_t flow_attrs[MAX_ATTRS_NUM];
55 static uint8_t items_idx, actions_idx, attrs_idx;
57 static uint64_t ports_mask;
58 static volatile bool force_quit;
59 static bool dump_iterations;
60 static bool delete_flag;
61 static bool dump_socket_mem_flag;
62 static bool enable_fwd;
64 static struct rte_mempool *mbuf_mp;
65 static uint32_t nb_lcores;
66 static uint32_t rules_count;
67 static uint32_t rules_batch;
68 static uint32_t hairpin_queues_num; /* total hairpin q number - default: 0 */
69 static uint32_t nb_lcores;
71 #define MAX_PKT_BURST 32
72 #define LCORE_MODE_PKT 1
73 #define LCORE_MODE_STATS 2
74 #define MAX_STREAMS 64
86 struct stream streams[MAX_STREAMS];
91 struct rte_mbuf *pkts[MAX_PKT_BURST];
92 } __rte_cache_aligned;
94 static struct lcore_info lcore_infos[RTE_MAX_LCORE];
96 struct multi_cores_pool {
99 double cpu_time_used_insertion[MAX_PORTS][RTE_MAX_LCORE];
100 double cpu_time_used_deletion[MAX_PORTS][RTE_MAX_LCORE];
101 int64_t last_alloc[RTE_MAX_LCORE];
102 int64_t current_alloc[RTE_MAX_LCORE];
103 } __rte_cache_aligned;
105 static struct multi_cores_pool mc_pool = {
110 usage(char *progname)
112 printf("\nusage: %s\n", progname);
113 printf("\nControl configurations:\n");
114 printf(" --rules-count=N: to set the number of needed"
115 " rules to insert, default is %d\n", DEFAULT_RULES_COUNT);
116 printf(" --rules-batch=N: set number of batched rules,"
117 " default is %d\n", DEFAULT_RULES_BATCH);
118 printf(" --dump-iterations: To print rates for each"
120 printf(" --deletion-rate: Enable deletion rate"
122 printf(" --dump-socket-mem: To dump all socket memory\n");
123 printf(" --enable-fwd: To enable packets forwarding"
124 " after insertion\n");
125 printf(" --portmask=N: hexadecimal bitmask of ports used\n");
127 printf("To set flow attributes:\n");
128 printf(" --ingress: set ingress attribute in flows\n");
129 printf(" --egress: set egress attribute in flows\n");
130 printf(" --transfer: set transfer attribute in flows\n");
131 printf(" --group=N: set group for all flows,"
132 " default is %d\n", DEFAULT_GROUP);
133 printf(" --cores=N: to set the number of needed "
134 "cores to insert rte_flow rules, default is 1\n");
136 printf("To set flow items:\n");
137 printf(" --ether: add ether layer in flow items\n");
138 printf(" --vlan: add vlan layer in flow items\n");
139 printf(" --ipv4: add ipv4 layer in flow items\n");
140 printf(" --ipv6: add ipv6 layer in flow items\n");
141 printf(" --tcp: add tcp layer in flow items\n");
142 printf(" --udp: add udp layer in flow items\n");
143 printf(" --vxlan: add vxlan layer in flow items\n");
144 printf(" --vxlan-gpe: add vxlan-gpe layer in flow items\n");
145 printf(" --gre: add gre layer in flow items\n");
146 printf(" --geneve: add geneve layer in flow items\n");
147 printf(" --gtp: add gtp layer in flow items\n");
148 printf(" --meta: add meta layer in flow items\n");
149 printf(" --tag: add tag layer in flow items\n");
150 printf(" --icmpv4: add icmpv4 layer in flow items\n");
151 printf(" --icmpv6: add icmpv6 layer in flow items\n");
153 printf("To set flow actions:\n");
154 printf(" --port-id: add port-id action in flow actions\n");
155 printf(" --rss: add rss action in flow actions\n");
156 printf(" --queue: add queue action in flow actions\n");
157 printf(" --jump: add jump action in flow actions\n");
158 printf(" --mark: add mark action in flow actions\n");
159 printf(" --count: add count action in flow actions\n");
160 printf(" --set-meta: add set meta action in flow actions\n");
161 printf(" --set-tag: add set tag action in flow actions\n");
162 printf(" --drop: add drop action in flow actions\n");
163 printf(" --hairpin-queue=N: add hairpin-queue action in flow actions\n");
164 printf(" --hairpin-rss=N: add hairpin-rss action in flow actions\n");
165 printf(" --set-src-mac: add set src mac action to flow actions\n"
166 "Src mac to be set is random each flow\n");
167 printf(" --set-dst-mac: add set dst mac action to flow actions\n"
168 "Dst mac to be set is random each flow\n");
169 printf(" --set-src-ipv4: add set src ipv4 action to flow actions\n"
170 "Src ipv4 to be set is random each flow\n");
171 printf(" --set-dst-ipv4 add set dst ipv4 action to flow actions\n"
172 "Dst ipv4 to be set is random each flow\n");
173 printf(" --set-src-ipv6: add set src ipv6 action to flow actions\n"
174 "Src ipv6 to be set is random each flow\n");
175 printf(" --set-dst-ipv6: add set dst ipv6 action to flow actions\n"
176 "Dst ipv6 to be set is random each flow\n");
177 printf(" --set-src-tp: add set src tp action to flow actions\n"
178 "Src tp to be set is random each flow\n");
179 printf(" --set-dst-tp: add set dst tp action to flow actions\n"
180 "Dst tp to be set is random each flow\n");
181 printf(" --inc-tcp-ack: add inc tcp ack action to flow actions\n"
182 "tcp ack will be increments by 1\n");
183 printf(" --dec-tcp-ack: add dec tcp ack action to flow actions\n"
184 "tcp ack will be decrements by 1\n");
185 printf(" --inc-tcp-seq: add inc tcp seq action to flow actions\n"
186 "tcp seq will be increments by 1\n");
187 printf(" --dec-tcp-seq: add dec tcp seq action to flow actions\n"
188 "tcp seq will be decrements by 1\n");
189 printf(" --set-ttl: add set ttl action to flow actions\n"
190 "L3 ttl to be set is random each flow\n");
191 printf(" --dec-ttl: add dec ttl action to flow actions\n"
192 "L3 ttl will be decrements by 1\n");
193 printf(" --set-ipv4-dscp: add set ipv4 dscp action to flow actions\n"
194 "ipv4 dscp value to be set is random each flow\n");
195 printf(" --set-ipv6-dscp: add set ipv6 dscp action to flow actions\n"
196 "ipv6 dscp value to be set is random each flow\n");
197 printf(" --flag: add flag action to flow actions\n");
198 printf(" --raw-encap=<data>: add raw encap action to flow actions\n"
199 "Data is the data needed to be encaped\n"
200 "Example: raw-encap=ether,ipv4,udp,vxlan\n");
201 printf(" --raw-decap=<data>: add raw decap action to flow actions\n"
202 "Data is the data needed to be decaped\n"
203 "Example: raw-decap=ether,ipv4,udp,vxlan\n");
204 printf(" --vxlan-encap: add vxlan-encap action to flow actions\n"
205 "Encapped data is fixed with pattern: ether,ipv4,udp,vxlan\n"
206 "With fixed values\n");
207 printf(" --vxlan-decap: add vxlan_decap action to flow actions\n");
211 args_parse(int argc, char **argv)
221 static const struct option_dict {
230 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH),
231 .map = &flow_items[0],
232 .map_idx = &items_idx
236 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV4),
237 .map = &flow_items[0],
238 .map_idx = &items_idx
242 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV6),
243 .map = &flow_items[0],
244 .map_idx = &items_idx
248 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VLAN),
249 .map = &flow_items[0],
250 .map_idx = &items_idx
254 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TCP),
255 .map = &flow_items[0],
256 .map_idx = &items_idx
260 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_UDP),
261 .map = &flow_items[0],
262 .map_idx = &items_idx
266 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN),
267 .map = &flow_items[0],
268 .map_idx = &items_idx
272 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN_GPE),
273 .map = &flow_items[0],
274 .map_idx = &items_idx
278 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GRE),
279 .map = &flow_items[0],
280 .map_idx = &items_idx
284 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GENEVE),
285 .map = &flow_items[0],
286 .map_idx = &items_idx
290 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GTP),
291 .map = &flow_items[0],
292 .map_idx = &items_idx
296 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_META),
297 .map = &flow_items[0],
298 .map_idx = &items_idx
302 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TAG),
303 .map = &flow_items[0],
304 .map_idx = &items_idx
308 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP),
309 .map = &flow_items[0],
310 .map_idx = &items_idx
314 .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP6),
315 .map = &flow_items[0],
316 .map_idx = &items_idx
321 .map = &flow_attrs[0],
322 .map_idx = &attrs_idx
327 .map = &flow_attrs[0],
328 .map_idx = &attrs_idx
333 .map = &flow_attrs[0],
334 .map_idx = &attrs_idx
338 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_PORT_ID),
339 .map = &flow_actions[0],
340 .map_idx = &actions_idx
344 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_RSS),
345 .map = &flow_actions[0],
346 .map_idx = &actions_idx
350 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_QUEUE),
351 .map = &flow_actions[0],
352 .map_idx = &actions_idx
356 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_JUMP),
357 .map = &flow_actions[0],
358 .map_idx = &actions_idx
362 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_MARK),
363 .map = &flow_actions[0],
364 .map_idx = &actions_idx
368 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_COUNT),
369 .map = &flow_actions[0],
370 .map_idx = &actions_idx
374 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_META),
375 .map = &flow_actions[0],
376 .map_idx = &actions_idx
380 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_TAG),
381 .map = &flow_actions[0],
382 .map_idx = &actions_idx
386 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP),
387 .map = &flow_actions[0],
388 .map_idx = &actions_idx
391 .str = "set-src-mac",
392 .mask = FLOW_ACTION_MASK(
393 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
395 .map = &flow_actions[0],
396 .map_idx = &actions_idx
399 .str = "set-dst-mac",
400 .mask = FLOW_ACTION_MASK(
401 RTE_FLOW_ACTION_TYPE_SET_MAC_DST
403 .map = &flow_actions[0],
404 .map_idx = &actions_idx
407 .str = "set-src-ipv4",
408 .mask = FLOW_ACTION_MASK(
409 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC
411 .map = &flow_actions[0],
412 .map_idx = &actions_idx
415 .str = "set-dst-ipv4",
416 .mask = FLOW_ACTION_MASK(
417 RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
419 .map = &flow_actions[0],
420 .map_idx = &actions_idx
423 .str = "set-src-ipv6",
424 .mask = FLOW_ACTION_MASK(
425 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC
427 .map = &flow_actions[0],
428 .map_idx = &actions_idx
431 .str = "set-dst-ipv6",
432 .mask = FLOW_ACTION_MASK(
433 RTE_FLOW_ACTION_TYPE_SET_IPV6_DST
435 .map = &flow_actions[0],
436 .map_idx = &actions_idx
440 .mask = FLOW_ACTION_MASK(
441 RTE_FLOW_ACTION_TYPE_SET_TP_SRC
443 .map = &flow_actions[0],
444 .map_idx = &actions_idx
448 .mask = FLOW_ACTION_MASK(
449 RTE_FLOW_ACTION_TYPE_SET_TP_DST
451 .map = &flow_actions[0],
452 .map_idx = &actions_idx
455 .str = "inc-tcp-ack",
456 .mask = FLOW_ACTION_MASK(
457 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK
459 .map = &flow_actions[0],
460 .map_idx = &actions_idx
463 .str = "dec-tcp-ack",
464 .mask = FLOW_ACTION_MASK(
465 RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK
467 .map = &flow_actions[0],
468 .map_idx = &actions_idx
471 .str = "inc-tcp-seq",
472 .mask = FLOW_ACTION_MASK(
473 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ
475 .map = &flow_actions[0],
476 .map_idx = &actions_idx
479 .str = "dec-tcp-seq",
480 .mask = FLOW_ACTION_MASK(
481 RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ
483 .map = &flow_actions[0],
484 .map_idx = &actions_idx
488 .mask = FLOW_ACTION_MASK(
489 RTE_FLOW_ACTION_TYPE_SET_TTL
491 .map = &flow_actions[0],
492 .map_idx = &actions_idx
496 .mask = FLOW_ACTION_MASK(
497 RTE_FLOW_ACTION_TYPE_DEC_TTL
499 .map = &flow_actions[0],
500 .map_idx = &actions_idx
503 .str = "set-ipv4-dscp",
504 .mask = FLOW_ACTION_MASK(
505 RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP
507 .map = &flow_actions[0],
508 .map_idx = &actions_idx
511 .str = "set-ipv6-dscp",
512 .mask = FLOW_ACTION_MASK(
513 RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP
515 .map = &flow_actions[0],
516 .map_idx = &actions_idx
520 .mask = FLOW_ACTION_MASK(
521 RTE_FLOW_ACTION_TYPE_FLAG
523 .map = &flow_actions[0],
524 .map_idx = &actions_idx
527 .str = "vxlan-encap",
528 .mask = FLOW_ACTION_MASK(
529 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
531 .map = &flow_actions[0],
532 .map_idx = &actions_idx
535 .str = "vxlan-decap",
536 .mask = FLOW_ACTION_MASK(
537 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP
539 .map = &flow_actions[0],
540 .map_idx = &actions_idx
544 static const struct option lgopts[] = {
547 { "rules-count", 1, 0, 0 },
548 { "rules-batch", 1, 0, 0 },
549 { "dump-iterations", 0, 0, 0 },
550 { "deletion-rate", 0, 0, 0 },
551 { "dump-socket-mem", 0, 0, 0 },
552 { "enable-fwd", 0, 0, 0 },
553 { "portmask", 1, 0, 0 },
554 { "cores", 1, 0, 0 },
556 { "ingress", 0, 0, 0 },
557 { "egress", 0, 0, 0 },
558 { "transfer", 0, 0, 0 },
559 { "group", 1, 0, 0 },
561 { "ether", 0, 0, 0 },
567 { "vxlan", 0, 0, 0 },
568 { "vxlan-gpe", 0, 0, 0 },
570 { "geneve", 0, 0, 0 },
574 { "icmpv4", 0, 0, 0 },
575 { "icmpv6", 0, 0, 0 },
577 { "port-id", 0, 0, 0 },
579 { "queue", 0, 0, 0 },
582 { "count", 0, 0, 0 },
583 { "set-meta", 0, 0, 0 },
584 { "set-tag", 0, 0, 0 },
586 { "hairpin-queue", 1, 0, 0 },
587 { "hairpin-rss", 1, 0, 0 },
588 { "set-src-mac", 0, 0, 0 },
589 { "set-dst-mac", 0, 0, 0 },
590 { "set-src-ipv4", 0, 0, 0 },
591 { "set-dst-ipv4", 0, 0, 0 },
592 { "set-src-ipv6", 0, 0, 0 },
593 { "set-dst-ipv6", 0, 0, 0 },
594 { "set-src-tp", 0, 0, 0 },
595 { "set-dst-tp", 0, 0, 0 },
596 { "inc-tcp-ack", 0, 0, 0 },
597 { "dec-tcp-ack", 0, 0, 0 },
598 { "inc-tcp-seq", 0, 0, 0 },
599 { "dec-tcp-seq", 0, 0, 0 },
600 { "set-ttl", 0, 0, 0 },
601 { "dec-ttl", 0, 0, 0 },
602 { "set-ipv4-dscp", 0, 0, 0 },
603 { "set-ipv6-dscp", 0, 0, 0 },
605 { "raw-encap", 1, 0, 0 },
606 { "raw-decap", 1, 0, 0 },
607 { "vxlan-encap", 0, 0, 0 },
608 { "vxlan-decap", 0, 0, 0 },
611 RTE_ETH_FOREACH_DEV(i)
612 ports_mask |= 1 << i;
614 hairpin_queues_num = 0;
617 printf(":: Flow -> ");
618 while ((opt = getopt_long(argc, argvopt, "",
619 lgopts, &opt_idx)) != EOF) {
622 if (strcmp(lgopts[opt_idx].name, "help") == 0) {
624 rte_exit(EXIT_SUCCESS, "Displayed help\n");
627 if (strcmp(lgopts[opt_idx].name, "group") == 0) {
632 rte_exit(EXIT_SUCCESS,
633 "flow group should be >= 0\n");
634 printf("group %d / ", flow_group);
637 for (i = 0; i < RTE_DIM(flow_options); i++)
638 if (strcmp(lgopts[opt_idx].name,
639 flow_options[i].str) == 0) {
641 (*flow_options[i].map_idx)++] =
642 flow_options[i].mask;
643 printf("%s / ", flow_options[i].str);
646 if (strcmp(lgopts[opt_idx].name,
647 "hairpin-rss") == 0) {
650 hairpin_queues_num = n;
652 rte_exit(EXIT_SUCCESS,
653 "Hairpin queues should be > 0\n");
655 flow_actions[actions_idx++] =
657 printf("hairpin-rss / ");
659 if (strcmp(lgopts[opt_idx].name,
660 "hairpin-queue") == 0) {
663 hairpin_queues_num = n;
665 rte_exit(EXIT_SUCCESS,
666 "Hairpin queues should be > 0\n");
668 flow_actions[actions_idx++] =
669 HAIRPIN_QUEUE_ACTION;
670 printf("hairpin-queue / ");
673 if (strcmp(lgopts[opt_idx].name, "raw-encap") == 0) {
674 printf("raw-encap ");
675 flow_actions[actions_idx++] =
677 RTE_FLOW_ACTION_TYPE_RAW_ENCAP
680 token = strtok(optarg, ",");
681 while (token != NULL) {
682 for (i = 0; i < RTE_DIM(flow_options); i++) {
683 if (strcmp(flow_options[i].str, token) == 0) {
684 printf("%s,", token);
685 encap_data |= flow_options[i].mask;
688 /* Reached last item with no match */
689 if (i == (RTE_DIM(flow_options) - 1)) {
690 fprintf(stderr, "Invalid encap item: %s\n", token);
692 rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
695 token = strtok(NULL, ",");
699 if (strcmp(lgopts[opt_idx].name, "raw-decap") == 0) {
700 printf("raw-decap ");
701 flow_actions[actions_idx++] =
703 RTE_FLOW_ACTION_TYPE_RAW_DECAP
706 token = strtok(optarg, ",");
707 while (token != NULL) {
708 for (i = 0; i < RTE_DIM(flow_options); i++) {
709 if (strcmp(flow_options[i].str, token) == 0) {
710 printf("%s,", token);
711 encap_data |= flow_options[i].mask;
714 /* Reached last item with no match */
715 if (i == (RTE_DIM(flow_options) - 1)) {
716 fprintf(stderr, "Invalid decap item: %s\n", token);
718 rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
721 token = strtok(NULL, ",");
726 if (strcmp(lgopts[opt_idx].name,
727 "rules-batch") == 0) {
729 if (n >= DEFAULT_RULES_BATCH)
732 printf("\n\nrules_batch should be >= %d\n",
733 DEFAULT_RULES_BATCH);
734 rte_exit(EXIT_SUCCESS, " ");
737 if (strcmp(lgopts[opt_idx].name,
738 "rules-count") == 0) {
740 if (n >= (int) rules_batch)
743 printf("\n\nrules_count should be >= %d\n",
747 if (strcmp(lgopts[opt_idx].name,
748 "dump-iterations") == 0)
749 dump_iterations = true;
750 if (strcmp(lgopts[opt_idx].name,
751 "deletion-rate") == 0)
753 if (strcmp(lgopts[opt_idx].name,
754 "dump-socket-mem") == 0)
755 dump_socket_mem_flag = true;
756 if (strcmp(lgopts[opt_idx].name,
759 if (strcmp(lgopts[opt_idx].name,
761 /* parse hexadecimal string */
763 pm = strtoull(optarg, &end, 16);
764 if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
765 rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
768 if (strcmp(lgopts[opt_idx].name, "cores") == 0) {
770 if ((int) rte_lcore_count() <= n) {
771 printf("\nError: you need %d cores to run on multi-cores\n"
772 "Existing cores are: %d\n", n, rte_lcore_count());
773 rte_exit(EXIT_FAILURE, " ");
775 if (n <= RTE_MAX_LCORE && n > 0)
776 mc_pool.cores_count = n;
778 printf("Error: cores count must be > 0 "
779 " and < %d\n", RTE_MAX_LCORE);
780 rte_exit(EXIT_FAILURE, " ");
785 fprintf(stderr, "Invalid option: %s\n", argv[optind]);
787 rte_exit(EXIT_SUCCESS, "Invalid option\n");
791 printf("end_flow\n");
794 /* Dump the socket memory statistics on console */
796 dump_socket_mem(FILE *f)
798 struct rte_malloc_socket_stats socket_stats;
803 unsigned int n_alloc = 0;
804 unsigned int n_free = 0;
805 bool active_nodes = false;
808 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
809 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
810 !socket_stats.heap_totalsz_bytes)
813 total += socket_stats.heap_totalsz_bytes;
814 alloc += socket_stats.heap_allocsz_bytes;
815 free += socket_stats.heap_freesz_bytes;
816 n_alloc += socket_stats.alloc_count;
817 n_free += socket_stats.free_count;
818 if (dump_socket_mem_flag) {
819 fprintf(f, "::::::::::::::::::::::::::::::::::::::::");
821 "\nSocket %u:\nsize(M) total: %.6lf\nalloc:"
822 " %.6lf(%.3lf%%)\nfree: %.6lf"
824 "\ncount alloc: %u\nfree: %u\n",
826 socket_stats.heap_totalsz_bytes / 1.0e6,
827 socket_stats.heap_allocsz_bytes / 1.0e6,
828 (double)socket_stats.heap_allocsz_bytes * 100 /
829 (double)socket_stats.heap_totalsz_bytes,
830 socket_stats.heap_freesz_bytes / 1.0e6,
831 socket_stats.greatest_free_size / 1.0e6,
832 socket_stats.alloc_count,
833 socket_stats.free_count);
834 fprintf(f, "::::::::::::::::::::::::::::::::::::::::");
837 if (dump_socket_mem_flag && active_nodes) {
839 "\nTotal: size(M)\ntotal: %.6lf"
840 "\nalloc: %.6lf(%.3lf%%)\nfree: %.6lf"
841 "\ncount alloc: %u\nfree: %u\n",
842 total / 1.0e6, alloc / 1.0e6,
843 (double)alloc * 100 / (double)total, free / 1.0e6,
845 fprintf(f, "::::::::::::::::::::::::::::::::::::::::\n");
851 print_flow_error(struct rte_flow_error error)
853 printf("Flow can't be created %d message: %s\n",
855 error.message ? error.message : "(no stated reason)");
859 print_rules_batches(double *cpu_time_per_batch)
865 for (idx = 0; idx < MAX_BATCHES_COUNT; idx++) {
866 if (!cpu_time_per_batch[idx])
868 delta = (double)(rules_batch / cpu_time_per_batch[idx]);
869 rate = delta / 1000; /* Save rate in K unit. */
870 printf(":: Rules batch #%d: %d rules "
871 "in %f sec[ Rate = %f K Rule/Sec ]\n",
873 cpu_time_per_batch[idx], rate);
878 destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
880 struct rte_flow_error error;
881 clock_t start_batch, end_batch;
882 double cpu_time_used = 0;
883 double deletion_rate;
884 double cpu_time_per_batch[MAX_BATCHES_COUNT] = { 0 };
888 int rules_count_per_core;
890 rules_count_per_core = rules_count / mc_pool.cores_count;
892 start_batch = rte_rdtsc();
893 for (i = 0; i < (uint32_t) rules_count_per_core; i++) {
894 if (flows_list[i] == 0)
897 memset(&error, 0x33, sizeof(error));
898 if (rte_flow_destroy(port_id, flows_list[i], &error)) {
899 print_flow_error(error);
900 rte_exit(EXIT_FAILURE, "Error in deleting flow");
904 * Save the deletion rate for rules batch.
905 * Check if the deletion reached the rules
906 * patch counter, then save the deletion rate
909 if (!((i + 1) % rules_batch)) {
910 end_batch = rte_rdtsc();
911 delta = (double) (end_batch - start_batch);
912 rules_batch_idx = ((i + 1) / rules_batch) - 1;
913 cpu_time_per_batch[rules_batch_idx] = delta / rte_get_tsc_hz();
914 cpu_time_used += cpu_time_per_batch[rules_batch_idx];
915 start_batch = rte_rdtsc();
919 /* Print deletion rates for all batches */
921 print_rules_batches(cpu_time_per_batch);
923 /* Deletion rate for all rules */
924 deletion_rate = ((double) (rules_count_per_core / cpu_time_used) / 1000);
925 printf(":: Port %d :: Core %d :: Rules deletion rate -> %f K Rule/Sec\n",
926 port_id, core_id, deletion_rate);
927 printf(":: Port %d :: Core %d :: The time for deleting %d rules is %f seconds\n",
928 port_id, core_id, rules_count_per_core, cpu_time_used);
930 mc_pool.cpu_time_used_deletion[port_id][core_id] = cpu_time_used;
933 static struct rte_flow **
934 insert_flows(int port_id, uint8_t core_id)
936 struct rte_flow **flows_list;
937 struct rte_flow_error error;
938 clock_t start_batch, end_batch;
939 double cpu_time_used;
940 double insertion_rate;
941 double cpu_time_per_batch[MAX_BATCHES_COUNT] = { 0 };
944 uint32_t counter, start_counter = 0, end_counter;
945 uint64_t global_items[MAX_ITEMS_NUM] = { 0 };
946 uint64_t global_actions[MAX_ACTIONS_NUM] = { 0 };
948 int rules_count_per_core;
950 rules_count_per_core = rules_count / mc_pool.cores_count;
952 /* Set boundaries of rules for each core. */
954 start_counter = core_id * rules_count_per_core;
955 end_counter = (core_id + 1) * rules_count_per_core;
957 global_items[0] = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH);
958 global_actions[0] = FLOW_ITEM_MASK(RTE_FLOW_ACTION_TYPE_JUMP);
960 flows_list = rte_zmalloc("flows_list",
961 (sizeof(struct rte_flow *) * rules_count_per_core) + 1, 0);
962 if (flows_list == NULL)
963 rte_exit(EXIT_FAILURE, "No Memory available!");
967 if (flow_group > 0 && core_id == 0) {
969 * Create global rule to jump into flow_group,
970 * this way the app will avoid the default rules.
972 * This rule will be created only once.
975 * group 0 eth / end actions jump group <flow_group>
977 flow = generate_flow(port_id, 0, flow_attrs,
978 global_items, global_actions,
979 flow_group, 0, 0, 0, 0, core_id, &error);
982 print_flow_error(error);
983 rte_exit(EXIT_FAILURE, "error in creating flow");
985 flows_list[flow_index++] = flow;
988 start_batch = rte_rdtsc();
989 for (counter = start_counter; counter < end_counter; counter++) {
990 flow = generate_flow(port_id, flow_group,
991 flow_attrs, flow_items, flow_actions,
992 JUMP_ACTION_TABLE, counter,
994 encap_data, decap_data,
998 counter = end_counter;
1001 print_flow_error(error);
1002 rte_exit(EXIT_FAILURE, "error in creating flow");
1005 flows_list[flow_index++] = flow;
1008 * Save the insertion rate for rules batch.
1009 * Check if the insertion reached the rules
1010 * patch counter, then save the insertion rate
1013 if (!((counter + 1) % rules_batch)) {
1014 end_batch = rte_rdtsc();
1015 delta = (double) (end_batch - start_batch);
1016 rules_batch_idx = ((counter + 1) / rules_batch) - 1;
1017 cpu_time_per_batch[rules_batch_idx] = delta / rte_get_tsc_hz();
1018 cpu_time_used += cpu_time_per_batch[rules_batch_idx];
1019 start_batch = rte_rdtsc();
1023 /* Print insertion rates for all batches */
1024 if (dump_iterations)
1025 print_rules_batches(cpu_time_per_batch);
1027 printf(":: Port %d :: Core %d boundaries :: start @[%d] - end @[%d]\n",
1028 port_id, core_id, start_counter, end_counter - 1);
1030 /* Insertion rate for all rules in one core */
1031 insertion_rate = ((double) (rules_count_per_core / cpu_time_used) / 1000);
1032 printf(":: Port %d :: Core %d :: Rules insertion rate -> %f K Rule/Sec\n",
1033 port_id, core_id, insertion_rate);
1034 printf(":: Port %d :: Core %d :: The time for creating %d in rules %f seconds\n",
1035 port_id, core_id, rules_count_per_core, cpu_time_used);
1037 mc_pool.cpu_time_used_insertion[port_id][core_id] = cpu_time_used;
1042 flows_handler(uint8_t core_id)
1044 struct rte_flow **flows_list;
1048 nr_ports = rte_eth_dev_count_avail();
1050 if (rules_batch > rules_count)
1051 rules_batch = rules_count;
1053 printf(":: Rules Count per port: %d\n\n", rules_count);
1055 for (port_id = 0; port_id < nr_ports; port_id++) {
1056 /* If port outside portmask */
1057 if (!((ports_mask >> port_id) & 0x1))
1060 /* Insertion part. */
1061 mc_pool.last_alloc[core_id] = (int64_t)dump_socket_mem(stdout);
1062 flows_list = insert_flows(port_id, core_id);
1063 if (flows_list == NULL)
1064 rte_exit(EXIT_FAILURE, "Error: Insertion Failed!\n");
1065 mc_pool.current_alloc[core_id] = (int64_t)dump_socket_mem(stdout);
1067 /* Deletion part. */
1069 destroy_flows(port_id, core_id, flows_list);
1074 run_rte_flow_handler_cores(void *data __rte_unused)
1077 /* Latency: total count of rte rules divided
1078 * over max time used by thread between all
1081 * Throughput: total count of rte rules divided
1082 * over the average of the time cosumed by all
1085 double insertion_latency_time;
1086 double insertion_throughput_time;
1087 double deletion_latency_time;
1088 double deletion_throughput_time;
1089 double insertion_latency, insertion_throughput;
1090 double deletion_latency, deletion_throughput;
1091 int64_t last_alloc, current_alloc;
1092 int flow_size_in_bytes;
1093 int lcore_counter = 0;
1094 int lcore_id = rte_lcore_id();
1097 RTE_LCORE_FOREACH(i) {
1098 /* If core not needed return. */
1099 if (lcore_id == i) {
1100 printf(":: lcore %d mapped with index %d\n", lcore_id, lcore_counter);
1101 if (lcore_counter >= (int) mc_pool.cores_count)
1107 lcore_id = lcore_counter;
1109 if (lcore_id >= (int) mc_pool.cores_count)
1112 mc_pool.rules_count = rules_count;
1114 flows_handler(lcore_id);
1116 /* Only main core to print total results. */
1120 /* Make sure all cores finished insertion/deletion process. */
1121 rte_eal_mp_wait_lcore();
1123 /* Save first insertion/deletion rates from first thread.
1124 * Start comparing with all threads, if any thread used
1125 * time more than current saved, replace it.
1127 * Thus in the end we will have the max time used for
1128 * insertion/deletion by one thread.
1130 * As for memory consumption, save the min of all threads
1131 * of last alloc, and save the max for all threads for
1134 RTE_ETH_FOREACH_DEV(port) {
1135 last_alloc = mc_pool.last_alloc[0];
1136 current_alloc = mc_pool.current_alloc[0];
1138 insertion_latency_time = mc_pool.cpu_time_used_insertion[port][0];
1139 deletion_latency_time = mc_pool.cpu_time_used_deletion[port][0];
1140 insertion_throughput_time = mc_pool.cpu_time_used_insertion[port][0];
1141 deletion_throughput_time = mc_pool.cpu_time_used_deletion[port][0];
1142 i = mc_pool.cores_count;
1144 insertion_throughput_time += mc_pool.cpu_time_used_insertion[port][i];
1145 deletion_throughput_time += mc_pool.cpu_time_used_deletion[port][i];
1146 if (insertion_latency_time < mc_pool.cpu_time_used_insertion[port][i])
1147 insertion_latency_time = mc_pool.cpu_time_used_insertion[port][i];
1148 if (deletion_latency_time < mc_pool.cpu_time_used_deletion[port][i])
1149 deletion_latency_time = mc_pool.cpu_time_used_deletion[port][i];
1150 if (last_alloc > mc_pool.last_alloc[i])
1151 last_alloc = mc_pool.last_alloc[i];
1152 if (current_alloc < mc_pool.current_alloc[i])
1153 current_alloc = mc_pool.current_alloc[i];
1156 flow_size_in_bytes = (current_alloc - last_alloc) / mc_pool.rules_count;
1158 insertion_latency = ((double) (mc_pool.rules_count / insertion_latency_time) / 1000);
1159 deletion_latency = ((double) (mc_pool.rules_count / deletion_latency_time) / 1000);
1161 insertion_throughput_time /= mc_pool.cores_count;
1162 deletion_throughput_time /= mc_pool.cores_count;
1163 insertion_throughput = ((double) (mc_pool.rules_count / insertion_throughput_time) / 1000);
1164 deletion_throughput = ((double) (mc_pool.rules_count / deletion_throughput_time) / 1000);
1167 printf("\n:: [Latency | Insertion] All Cores :: Port %d :: ", port);
1168 printf("Total flows insertion rate -> %f K Rules/Sec\n",
1170 printf(":: [Latency | Insertion] All Cores :: Port %d :: ", port);
1171 printf("The time for creating %d rules is %f seconds\n",
1172 mc_pool.rules_count, insertion_latency_time);
1174 /* Throughput stats */
1175 printf(":: [Throughput | Insertion] All Cores :: Port %d :: ", port);
1176 printf("Total flows insertion rate -> %f K Rules/Sec\n",
1177 insertion_throughput);
1178 printf(":: [Throughput | Insertion] All Cores :: Port %d :: ", port);
1179 printf("The average time for creating %d rules is %f seconds\n",
1180 mc_pool.rules_count, insertion_throughput_time);
1184 printf(":: [Latency | Deletion] All Cores :: Port %d :: Total flows "
1185 "deletion rate -> %f K Rules/Sec\n",
1186 port, deletion_latency);
1187 printf(":: [Latency | Deletion] All Cores :: Port %d :: ", port);
1188 printf("The time for deleting %d rules is %f seconds\n",
1189 mc_pool.rules_count, deletion_latency_time);
1191 /* Throughput stats */
1192 printf(":: [Throughput | Deletion] All Cores :: Port %d :: Total flows "
1193 "deletion rate -> %f K Rules/Sec\n", port, deletion_throughput);
1194 printf(":: [Throughput | Deletion] All Cores :: Port %d :: ", port);
1195 printf("The average time for deleting %d rules is %f seconds\n",
1196 mc_pool.rules_count, deletion_throughput_time);
1198 printf("\n:: Port %d :: rte_flow size in DPDK layer: %d Bytes\n",
1199 port, flow_size_in_bytes);
1206 signal_handler(int signum)
1208 if (signum == SIGINT || signum == SIGTERM) {
1209 printf("\n\nSignal %d received, preparing to exit...\n",
1211 printf("Error: Stats are wrong due to sudden signal!\n\n");
1216 static inline uint16_t
1217 do_rx(struct lcore_info *li, uint16_t rx_port, uint16_t rx_queue)
1220 cnt = rte_eth_rx_burst(rx_port, rx_queue, li->pkts, MAX_PKT_BURST);
1226 do_tx(struct lcore_info *li, uint16_t cnt, uint16_t tx_port,
1232 nr_tx = rte_eth_tx_burst(tx_port, tx_queue, li->pkts, cnt);
1233 li->tx_pkts += nr_tx;
1234 li->tx_drops += cnt - nr_tx;
1236 for (i = nr_tx; i < cnt; i++)
1237 rte_pktmbuf_free(li->pkts[i]);
1241 * Method to convert numbers into pretty numbers that easy
1242 * to read. The design here is to add comma after each three
1243 * digits and set all of this inside buffer.
1245 * For example if n = 1799321, the output will be
1246 * 1,799,321 after this method which is easier to read.
1249 pretty_number(uint64_t n, char *buf)
1256 sprintf(p[i], "%03d", (int)(n % 1000));
1261 sprintf(p[i++], "%d", (int)n);
1264 off += sprintf(buf + off, "%s,", p[i]);
1265 buf[strlen(buf) - 1] = '\0';
1271 packet_per_second_stats(void)
1273 struct lcore_info *old;
1274 struct lcore_info *li, *oli;
1278 old = rte_zmalloc("old",
1279 sizeof(struct lcore_info) * RTE_MAX_LCORE, 0);
1281 rte_exit(EXIT_FAILURE, "No Memory available!");
1283 memcpy(old, lcore_infos,
1284 sizeof(struct lcore_info) * RTE_MAX_LCORE);
1286 while (!force_quit) {
1287 uint64_t total_tx_pkts = 0;
1288 uint64_t total_rx_pkts = 0;
1289 uint64_t total_tx_drops = 0;
1290 uint64_t tx_delta, rx_delta, drops_delta;
1292 int nr_valid_core = 0;
1297 char go_up_nr_lines[16];
1299 sprintf(go_up_nr_lines, "%c[%dA\r", 27, nr_lines);
1300 printf("%s\r", go_up_nr_lines);
1303 printf("\n%6s %16s %16s %16s\n", "core", "tx", "tx drops", "rx");
1304 printf("%6s %16s %16s %16s\n", "------", "----------------",
1305 "----------------", "----------------");
1307 for (i = 0; i < RTE_MAX_LCORE; i++) {
1308 li = &lcore_infos[i];
1310 if (li->mode != LCORE_MODE_PKT)
1313 tx_delta = li->tx_pkts - oli->tx_pkts;
1314 rx_delta = li->rx_pkts - oli->rx_pkts;
1315 drops_delta = li->tx_drops - oli->tx_drops;
1316 printf("%6d %16s %16s %16s\n", i,
1317 pretty_number(tx_delta, buf[0]),
1318 pretty_number(drops_delta, buf[1]),
1319 pretty_number(rx_delta, buf[2]));
1321 total_tx_pkts += tx_delta;
1322 total_rx_pkts += rx_delta;
1323 total_tx_drops += drops_delta;
1329 if (nr_valid_core > 1) {
1330 printf("%6s %16s %16s %16s\n", "total",
1331 pretty_number(total_tx_pkts, buf[0]),
1332 pretty_number(total_tx_drops, buf[1]),
1333 pretty_number(total_rx_pkts, buf[2]));
1337 memcpy(old, lcore_infos,
1338 sizeof(struct lcore_info) * RTE_MAX_LCORE);
1343 start_forwarding(void *data __rte_unused)
1345 int lcore = rte_lcore_id();
1348 struct lcore_info *li = &lcore_infos[lcore];
1353 if (li->mode == LCORE_MODE_STATS) {
1354 printf(":: started stats on lcore %u\n", lcore);
1355 packet_per_second_stats();
1360 for (stream_id = 0; stream_id < MAX_STREAMS; stream_id++) {
1361 if (li->streams[stream_id].rx_port == -1)
1365 li->streams[stream_id].rx_port,
1366 li->streams[stream_id].rx_queue);
1369 li->streams[stream_id].tx_port,
1370 li->streams[stream_id].tx_queue);
1376 init_lcore_info(void)
1384 int streams_per_core;
1385 int unassigned_streams;
1387 nr_port = rte_eth_dev_count_avail();
1389 /* First logical core is reserved for stats printing */
1390 lcore = rte_get_next_lcore(-1, 0, 0);
1391 lcore_infos[lcore].mode = LCORE_MODE_STATS;
1394 * Initialize all cores
1395 * All cores at first must have -1 value in all streams
1396 * This means that this stream is not used, or not set
1399 for (i = 0; i < RTE_MAX_LCORE; i++)
1400 for (j = 0; j < MAX_STREAMS; j++) {
1401 lcore_infos[i].streams[j].tx_port = -1;
1402 lcore_infos[i].streams[j].rx_port = -1;
1403 lcore_infos[i].streams[j].tx_queue = -1;
1404 lcore_infos[i].streams[j].rx_queue = -1;
1405 lcore_infos[i].streams_nb = 0;
1409 * Calculate the total streams count.
1410 * Also distribute those streams count between the available
1411 * logical cores except first core, since it's reserved for
1414 nb_fwd_streams = nr_port * RXQ_NUM;
1415 if ((int)(nb_lcores - 1) >= nb_fwd_streams)
1416 for (i = 0; i < (int)(nb_lcores - 1); i++) {
1417 lcore = rte_get_next_lcore(lcore, 0, 0);
1418 lcore_infos[lcore].streams_nb = 1;
1421 streams_per_core = nb_fwd_streams / (nb_lcores - 1);
1422 unassigned_streams = nb_fwd_streams % (nb_lcores - 1);
1423 for (i = 0; i < (int)(nb_lcores - 1); i++) {
1424 lcore = rte_get_next_lcore(lcore, 0, 0);
1425 lcore_infos[lcore].streams_nb = streams_per_core;
1426 if (unassigned_streams) {
1427 lcore_infos[lcore].streams_nb++;
1428 unassigned_streams--;
1434 * Set the streams for the cores according to each logical
1435 * core stream count.
1436 * The streams is built on the design of what received should
1437 * forward as well, this means that if you received packets on
1438 * port 0 queue 0 then the same queue should forward the
1439 * packets, using the same logical core.
1441 lcore = rte_get_next_lcore(-1, 0, 0);
1442 for (port = 0; port < nr_port; port++) {
1443 /* Create FWD stream */
1444 for (queue = 0; queue < RXQ_NUM; queue++) {
1445 if (!lcore_infos[lcore].streams_nb ||
1446 !(stream_id % lcore_infos[lcore].streams_nb)) {
1447 lcore = rte_get_next_lcore(lcore, 0, 0);
1448 lcore_infos[lcore].mode = LCORE_MODE_PKT;
1451 lcore_infos[lcore].streams[stream_id].rx_queue = queue;
1452 lcore_infos[lcore].streams[stream_id].tx_queue = queue;
1453 lcore_infos[lcore].streams[stream_id].rx_port = port;
1454 lcore_infos[lcore].streams[stream_id].tx_port = port;
1459 /* Print all streams */
1460 printf(":: Stream -> core id[N]: (rx_port, rx_queue)->(tx_port, tx_queue)\n");
1461 for (i = 0; i < RTE_MAX_LCORE; i++)
1462 for (j = 0; j < MAX_STREAMS; j++) {
1463 /* No streams for this core */
1464 if (lcore_infos[i].streams[j].tx_port == -1)
1466 printf("Stream -> core id[%d]: (%d,%d)->(%d,%d)\n",
1468 lcore_infos[i].streams[j].rx_port,
1469 lcore_infos[i].streams[j].rx_queue,
1470 lcore_infos[i].streams[j].tx_port,
1471 lcore_infos[i].streams[j].tx_queue);
1480 uint16_t hairpin_queue;
1484 struct rte_eth_hairpin_conf hairpin_conf = {
1487 struct rte_eth_conf port_conf = {
1493 struct rte_eth_txconf txq_conf;
1494 struct rte_eth_rxconf rxq_conf;
1495 struct rte_eth_dev_info dev_info;
1497 nr_queues = RXQ_NUM;
1498 if (hairpin_queues_num != 0)
1499 nr_queues = RXQ_NUM + hairpin_queues_num;
1501 nr_ports = rte_eth_dev_count_avail();
1503 rte_exit(EXIT_FAILURE, "Error: no port detected\n");
1505 mbuf_mp = rte_pktmbuf_pool_create("mbuf_pool",
1506 TOTAL_MBUF_NUM, MBUF_CACHE_SIZE,
1509 if (mbuf_mp == NULL)
1510 rte_exit(EXIT_FAILURE, "Error: can't init mbuf pool\n");
1512 for (port_id = 0; port_id < nr_ports; port_id++) {
1513 ret = rte_eth_dev_info_get(port_id, &dev_info);
1515 rte_exit(EXIT_FAILURE,
1516 "Error during getting device"
1517 " (port %u) info: %s\n",
1518 port_id, strerror(-ret));
1520 port_conf.txmode.offloads &= dev_info.tx_offload_capa;
1521 port_conf.rxmode.offloads &= dev_info.rx_offload_capa;
1523 printf(":: initializing port: %d\n", port_id);
1525 ret = rte_eth_dev_configure(port_id, nr_queues,
1526 nr_queues, &port_conf);
1528 rte_exit(EXIT_FAILURE,
1529 ":: cannot configure device: err=%d, port=%u\n",
1532 rxq_conf = dev_info.default_rxconf;
1533 for (std_queue = 0; std_queue < RXQ_NUM; std_queue++) {
1534 ret = rte_eth_rx_queue_setup(port_id, std_queue, NR_RXD,
1535 rte_eth_dev_socket_id(port_id),
1539 rte_exit(EXIT_FAILURE,
1540 ":: Rx queue setup failed: err=%d, port=%u\n",
1544 txq_conf = dev_info.default_txconf;
1545 for (std_queue = 0; std_queue < TXQ_NUM; std_queue++) {
1546 ret = rte_eth_tx_queue_setup(port_id, std_queue, NR_TXD,
1547 rte_eth_dev_socket_id(port_id),
1550 rte_exit(EXIT_FAILURE,
1551 ":: Tx queue setup failed: err=%d, port=%u\n",
1555 /* Catch all packets from traffic generator. */
1556 ret = rte_eth_promiscuous_enable(port_id);
1558 rte_exit(EXIT_FAILURE,
1559 ":: promiscuous mode enable failed: err=%s, port=%u\n",
1560 rte_strerror(-ret), port_id);
1562 if (hairpin_queues_num != 0) {
1564 * Configure peer which represents hairpin Tx.
1565 * Hairpin queue numbers start after standard queues
1566 * (RXQ_NUM and TXQ_NUM).
1568 for (hairpin_queue = RXQ_NUM, std_queue = 0;
1569 hairpin_queue < nr_queues;
1570 hairpin_queue++, std_queue++) {
1571 hairpin_conf.peers[0].port = port_id;
1572 hairpin_conf.peers[0].queue =
1573 std_queue + TXQ_NUM;
1574 ret = rte_eth_rx_hairpin_queue_setup(
1575 port_id, hairpin_queue,
1576 NR_RXD, &hairpin_conf);
1578 rte_exit(EXIT_FAILURE,
1579 ":: Hairpin rx queue setup failed: err=%d, port=%u\n",
1583 for (hairpin_queue = TXQ_NUM, std_queue = 0;
1584 hairpin_queue < nr_queues;
1585 hairpin_queue++, std_queue++) {
1586 hairpin_conf.peers[0].port = port_id;
1587 hairpin_conf.peers[0].queue =
1588 std_queue + RXQ_NUM;
1589 ret = rte_eth_tx_hairpin_queue_setup(
1590 port_id, hairpin_queue,
1591 NR_TXD, &hairpin_conf);
1593 rte_exit(EXIT_FAILURE,
1594 ":: Hairpin tx queue setup failed: err=%d, port=%u\n",
1599 ret = rte_eth_dev_start(port_id);
1601 rte_exit(EXIT_FAILURE,
1602 "rte_eth_dev_start:err=%d, port=%u\n",
1605 printf(":: initializing port: %d done\n", port_id);
1610 main(int argc, char **argv)
1614 struct rte_flow_error error;
1616 ret = rte_eal_init(argc, argv);
1618 rte_exit(EXIT_FAILURE, "EAL init failed\n");
1621 dump_iterations = false;
1622 rules_count = DEFAULT_RULES_COUNT;
1623 rules_batch = DEFAULT_RULES_BATCH;
1624 delete_flag = false;
1625 dump_socket_mem_flag = false;
1626 flow_group = DEFAULT_GROUP;
1628 signal(SIGINT, signal_handler);
1629 signal(SIGTERM, signal_handler);
1634 args_parse(argc, argv);
1638 nb_lcores = rte_lcore_count();
1640 rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
1643 printf(":: Flows Count per port: %d\n\n", rules_count);
1645 rte_eal_mp_remote_launch(run_rte_flow_handler_cores, NULL, CALL_MAIN);
1649 rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MAIN);
1652 RTE_ETH_FOREACH_DEV(port) {
1653 rte_flow_flush(port, &error);
1654 if (rte_eth_dev_stop(port) != 0)
1655 printf("Failed to stop device on port %u\n", port);
1656 rte_eth_dev_close(port);
1658 printf("\nBye ...\n");