-
Notifications
You must be signed in to change notification settings - Fork 120
/
cli-functions.c
2209 lines (2019 loc) · 72.2 KB
/
cli-functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-
* Copyright(c) <2020-2024>, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/* Created 2018 by Keith Wiles @ intel.com */
#include "cli-functions.h"
#include <stdio.h>
#include <termios.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <rte_version.h>
#include <rte_atomic.h>
#include <rte_devargs.h>
#include <rte_ether.h>
#include <rte_string_fns.h>
#include <pg_strings.h>
#include <rte_hexdump.h>
#include <rte_cycles.h>
#include <rte_malloc.h>
#include <lua_config.h>
#include "pktgen.h"
#include <cli.h>
#include <cli_map.h>
#include <plugin.h>
#include "copyright_info.h"
#include "pktgen-cmds.h"
#include "pktgen-main.h"
#include "lpktgenlib.h"
#include "pktgen-display.h"
#include "pktgen-random.h"
#include "pktgen-log.h"
#include "pg_ether.h"
#if defined(RTE_LIBRTE_PMD_BOND) || defined(RTE_NET_BOND)
#include <rte_eth_bond.h>
#include <rte_eth_bond_8023ad.h>
#endif
#include <hmap.h>
static inline uint16_t
valid_gtpu_teid(port_info_t *info __rte_unused, char *val)
{
uint16_t gtpu_teid;
gtpu_teid = atoi(val);
return gtpu_teid;
}
/**********************************************************/
static const char *title_help[] = {
" *** Pktgen Help information ***",
"",
NULL,
};
static const char *status_help[] = {
"",
" Flags: P----------------- - Promiscuous mode enabled",
" E - ICMP Echo enabled",
" B - Bonding enabled LACP 802.3ad",
" I - Process packets on input enabled",
" * - Using TAP interface for this port can be [-rt*]",
" C - Capture received packets",
" ------ - Modes Single, pcap, sequence, latency, random, Rate",
" ------ - Modes VLAN, VxLAN, MPLS, QnQ, GRE IPv4, GRE ETH",
"Notes: <state> - Use enable|disable or on|off to set the state.",
" <portlist> - a list of ports (no spaces) as 2,4,6-9,12 or 3-5,8 or 5 or the word "
"'all'",
" Colors best seen on a black background for now",
CLI_HELP_PAUSE,
NULL};
#define SMMI "%|start|minimum|maximum|increment|min|max|inc"
// clang-format off
static struct cli_map range_map[] = {
{20, "range %P dst mac " SMMI " %m"},
{21, "range %P src mac " SMMI " %m"},
{22, "range %P dst mac %m %m %m %m"},
{23, "range %P src mac %m %m %m %m"},
{30, "range %P dst ip " SMMI " %4"},
{31, "range %P src ip " SMMI " %4"},
{32, "range %P dst ip %4 %4 %4 %4"},
{33, "range %P src ip %4 %4 %4 %4"},
{34, "range %P dst ip " SMMI " %6"},
{35, "range %P src ip " SMMI " %6"},
{36, "range %P dst ip %6 %6 %6 %6"},
{37, "range %P src ip %6 %6 %6 %6"},
{40, "range %P proto %|tcp|udp"},
{41, "range %P type %|ipv4|ipv6"},
{42, "range %P tcp %|flag|flags %s"},
{44, "range %P tcp seq %d %d %d %d"},
{45, "range %P tcp ack %d %d %d %d"},
{46, "range %P tcp seq " SMMI " %d"},
{47, "range %P tcp ack " SMMI " %d"},
{50, "range %P dst port " SMMI " %d"},
{51, "range %P src port " SMMI " %d"},
{52, "range %P dst port %d %d %d %d"},
{53, "range %P src port %d %d %d %d"},
{55, "range %P ttl " SMMI " %b"},
{56, "range %P ttl %b %b %b %b"},
{60, "range %P vlan " SMMI " %d"},
{61, "range %P vlan %d %d %d %d"},
{70, "range %P size " SMMI " %d"},
{71, "range %P size %d %d %d %d"},
{80, "range %P mpls entry %h"},
{85, "range %P qinq index %d %d"},
{90, "range %P gre key %d"},
{91, "range %P gre_key %d"},
{100, "range %P gtpu " SMMI " %d"},
{101, "range %P gtpu %d %d %d %d"},
{160, "range %P cos " SMMI " %d"},
{161, "range %P cos %d %d %d %d"},
{170, "range %P tos " SMMI " %d"},
{171, "range %P tos %d %d %d %d"},
{172, "range %P hop_limits " SMMI " %b"},
{173, "range %P hop_limits %d %d %d %d"},
{174, "range %P traffic_class " SMMI " %d"},
{175, "range %P traffic_class %d %d %d %d"},
{-1, NULL}
};
// clang-format on
static const char *range_help[] = {
"",
" -- Setup the packet range values --",
" note: SMMI = start|min|max|inc (start, minimum, maximum, increment)",
"",
"range <portlist> src|dst mac <SMMI> <etheraddr> - Set destination/source MAC address",
" e.g: range 0 src mac start 00:00:00:00:00:00",
" range 0 dst mac max 00:12:34:56:78:90",
" or range 0 src mac 00:00:00:00:00:00 00:00:00:00:00:00 00:12:34:56:78:90 "
"00:00:00:01:01:01",
"range <portlist> src|dst ip <SMMI> <ipaddr> - Set source IP start address",
" e.g: range 0 dst ip start 0.0.0.0",
" range 0 dst ip min 0.0.0.0",
" range 0 dst ip max 1.2.3.4",
" range 0 dst ip inc 0.0.1.0",
" or range 0 dst ip 0.0.0.0 0.0.0.0 1.2.3.4 0.0.1.0",
"range <portlist> type ipv4|ipv6 - Set the range packet type to IPv4 or IPv6",
"range <portlist> proto tcp|udp - Set the IP protocol type",
"range <portlist> tcp flags <string> - Set comma delimited TCP flags: "
"cwr,ece,urg,ack,psh,rst,syn,fin,clr",
"range <portlist> tcp seq <SMMI> <value> - Set the TCP sequence number",
" or range <portlist> tcp seq <start> <min> <max> <inc>",
"range <portlist> tcp ack <SMMI> <value> - Set the TCP acknowledge number",
" or range <portlist> tcp ack <start> <min> <max> <inc>",
"range <portlist> src|dst port <SMMI> <value> - Set UDP/TCP source/dest port number",
" or range <portlist> src|dst port <start> <min> <max> <inc>",
"range <portlist> vlan <SMMI> <value> - Set vlan id start address",
" or range <portlist> vlan <start> <min> <max> <inc>",
"range <portlist> size <SMMI> <value> - Set pkt size start address",
" or range <portlist> size <start> <min> <max> <inc>",
"range <portlist> teid <SMMI> <value> - Set TEID value",
" or range <portlist> teid <start> <min> <max> <inc>",
"range <portlist> mpls entry <hex-value> - Set MPLS entry value",
"range <portlist> qinq index <val1> <val2> - Set QinQ index values",
"range <portlist> gre key <value> - Set GRE key value",
"range <portlist> cos <SMMI> <value> - Set cos value",
"range <portlist> tos <SMMI> <value> - Set tos value",
"range <portlist> ttl <SMMI> <value> - Set TTL",
"range <portlist> hop_limits <SMMI> <value> - Set Hop Limits",
"range <portlist> traffic_class <SMMI> <value> - Set Traffic Class value",
CLI_HELP_PAUSE,
NULL};
static int
range_cmd(int argc, char **argv)
{
struct cli_map *m;
portlist_t portlist;
struct pg_ipaddr ip;
struct rte_ether_addr mac[4];
char *what, *p;
const char *val;
m = cli_mapping(range_map, argc, argv);
if (!m)
return cli_cmd_error("Range command error", "Range", argc, argv);
portlist_parse(argv[1], pktgen.nb_ports, &portlist);
what = argv[4];
val = (const char *)argv[5];
switch (m->index) {
case 20:
if (pg_ether_aton(val, &mac[0]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", val);
break;
}
foreach_port(portlist, range_set_dest_mac(pinfo, what, &mac[0]));
break;
case 21:
if (pg_ether_aton(val, &mac[0]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", val);
break;
}
foreach_port(portlist, range_set_src_mac(pinfo, what, &mac[0]));
break;
case 22:
if (pg_ether_aton(argv[4], &mac[0]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[4]);
break;
}
if (pg_ether_aton(argv[5], &mac[1]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[5]);
break;
}
if (pg_ether_aton(argv[6], &mac[2]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[6]);
break;
}
if (pg_ether_aton(argv[7], &mac[3]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[7]);
break;
}
foreach_port(portlist, range_set_dest_mac(pinfo, "start", &mac[0]);
range_set_dest_mac(pinfo, "min", &mac[1]);
range_set_dest_mac(pinfo, "max", &mac[2]);
range_set_dest_mac(pinfo, "inc", &mac[3]));
break;
case 23:
if (pg_ether_aton(argv[4], &mac[0]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[4]);
break;
}
if (pg_ether_aton(argv[5], &mac[1]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[5]);
break;
}
if (pg_ether_aton(argv[6], &mac[2]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[6]);
break;
}
if (pg_ether_aton(argv[7], &mac[3]) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[7]);
break;
}
foreach_port(portlist, range_set_src_mac(pinfo, "start", &mac[0]);
range_set_src_mac(pinfo, "min", &mac[1]);
range_set_src_mac(pinfo, "max", &mac[2]);
range_set_src_mac(pinfo, "inc", &mac[3]));
break;
case 30:
/* Remove the /XX mask value is supplied */
p = strchr(argv[4], '/');
if (p)
*p = '\0';
_atoip(val, 0, &ip, sizeof(ip));
foreach_port(portlist, range_set_dst_ip(pinfo, what, &ip));
break;
case 31:
/* Remove the /XX mask value is supplied */
p = strchr(argv[4], '/');
if (p)
*p = '\0';
_atoip(argv[5], 0, &ip, sizeof(ip));
foreach_port(portlist, range_set_src_ip(pinfo, what, &ip));
break;
case 32:
// clang-format off
foreach_port(portlist, _atoip(argv[4], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"start", &ip);
_atoip(argv[5], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"min", &ip);
_atoip(argv[6], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"max", &ip);
_atoip(argv[7], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"inc", &ip));
// clang-format on
break;
case 33:
// clang-format off
foreach_port(portlist, _atoip(argv[4], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"start", &ip);
_atoip(argv[5], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"min", &ip);
_atoip(argv[6], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"max", &ip);
_atoip(argv[7], PG_IPADDR_V4, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"inc", &ip));
// clang-format on
break;
case 34:
/* Remove the /XX mask value is supplied */
p = strchr(argv[4], '/');
if (p)
*p = '\0';
_atoip(val, 0, &ip, sizeof(ip));
foreach_port(portlist, range_set_dst_ip(pinfo, what, &ip));
break;
case 35:
/* Remove the /XX mask value is supplied */
p = strchr(argv[4], '/');
if (p)
*p = '\0';
_atoip(argv[5], 0, &ip, sizeof(ip));
foreach_port(portlist, range_set_src_ip(pinfo, what, &ip));
break;
case 36:
// clang-format off
foreach_port(portlist, _atoip(argv[4], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"start", &ip);
_atoip(argv[5], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"min", &ip);
_atoip(argv[6], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"max", &ip);
_atoip(argv[7], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_dst_ip(pinfo, (char *)(uintptr_t)"inc", &ip));
// clang-format on
break;
case 37:
// clang-format off
foreach_port(portlist, _atoip(argv[4], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"start", &ip);
_atoip(argv[5], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"min", &ip);
_atoip(argv[6], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"max", &ip);
_atoip(argv[7], PG_IPADDR_V6, &ip, sizeof(ip));
range_set_src_ip(pinfo, (char *)(uintptr_t)"inc", &ip));
// clang-format on
break;
case 40:
foreach_port(portlist, range_set_proto(pinfo, argv[3]));
break;
case 41:
foreach_port(portlist, range_set_pkt_type(pinfo, argv[3]));
break;
case 42:
foreach_port(portlist, range_set_tcp_flags(pinfo, argv[4]));
break;
case 44:
// clang-format off
foreach_port(portlist, range_set_tcp_seq(pinfo, (char *)(uintptr_t)"start", atoi(argv[4]));
range_set_tcp_seq(pinfo, (char *)(uintptr_t)"min", atoi(argv[5]));
range_set_tcp_seq(pinfo, (char *)(uintptr_t)"max", atoi(argv[6]));
range_set_tcp_seq(pinfo, (char *)(uintptr_t)"inc", atoi(argv[7])));
// clang-format on
break;
case 45:
// clang-format off
foreach_port(portlist, range_set_tcp_ack(pinfo, (char *)(uintptr_t)"start", atoi(argv[4]));
range_set_tcp_ack(pinfo, (char *)(uintptr_t)"min", atoi(argv[5]));
range_set_tcp_ack(pinfo, (char *)(uintptr_t)"max", atoi(argv[6]));
range_set_tcp_ack(pinfo, (char *)(uintptr_t)"inc", atoi(argv[7])));
// clang-format on
break;
case 46:
foreach_port(portlist, range_set_tcp_seq(pinfo, what, atoi(val)));
break;
case 47:
foreach_port(portlist, range_set_tcp_ack(pinfo, what, atoi(val)));
break;
case 50:
foreach_port(portlist, range_set_dst_port(pinfo, what, atoi(val)));
break;
case 51:
foreach_port(portlist, range_set_src_port(pinfo, what, atoi(val)));
break;
case 52:
// clang-format off
foreach_port(portlist, range_set_dst_port(pinfo, (char *)(uintptr_t)"start", atoi(argv[4]));
range_set_dst_port(pinfo, (char *)(uintptr_t)"min", atoi(argv[5]));
range_set_dst_port(pinfo, (char *)(uintptr_t)"max", atoi(argv[6]));
range_set_dst_port(pinfo, (char *)(uintptr_t)"inc", atoi(argv[7])));
// clang-format on
break;
case 53:
// clang-format off
foreach_port(portlist, range_set_src_port(pinfo, (char *)(uintptr_t)"start", atoi(argv[4]));
range_set_src_port(pinfo, (char *)(uintptr_t)"min", atoi(argv[5]));
range_set_src_port(pinfo, (char *)(uintptr_t)"max", atoi(argv[6]));
range_set_src_port(pinfo, (char *)(uintptr_t)"inc", atoi(argv[7])));
// clang-format on
break;
case 55:
foreach_port(portlist, range_set_ttl(pinfo, argv[3], atoi(argv[4])));
break;
case 56:
// clang-format off
foreach_port(portlist, range_set_ttl(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_ttl(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_ttl(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_ttl(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])));
// clang-format on
break;
case 60:
foreach_port(portlist, range_set_vlan_id(pinfo, argv[3], atoi(what)));
break;
case 61:
// clang-format off
foreach_port(portlist, range_set_vlan_id(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_vlan_id(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_vlan_id(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_vlan_id(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])));
// clang-format on
break;
case 70:
foreach_port(portlist,
range_set_pkt_size(pinfo, argv[3],
strcmp("inc", argv[3]) ? atoi(argv[4]) : atoi(argv[3])));
break;
case 71:
// clang-format off
foreach_port(portlist, range_set_pkt_size(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_pkt_size(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_pkt_size(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_pkt_size(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])););
// clang-format on
break;
case 80:
foreach_port(portlist, range_set_mpls_entry(pinfo, strtoul(what, NULL, 16)));
break;
case 85:
foreach_port(portlist, range_set_qinqids(pinfo, atoi(what), atoi(val)));
break;
case 90:
case 91:
foreach_port(portlist, range_set_gre_key(pinfo, strtoul(what, NULL, 10)));
break;
case 100:
foreach_port(portlist,
range_set_gtpu_teid(pinfo, argv[3],
strcmp("inc", argv[3]) ? valid_gtpu_teid(pinfo, what)
: atoi(what)));
break;
case 101:
// clang-format off
foreach_port(
portlist,
range_set_gtpu_teid(pinfo, (char *)(uintptr_t)"start", valid_gtpu_teid(pinfo, argv[3]));
range_set_gtpu_teid(pinfo, (char *)(uintptr_t)"min", valid_gtpu_teid(pinfo, argv[4]));
range_set_gtpu_teid(pinfo, (char *)(uintptr_t)"max", valid_gtpu_teid(pinfo, argv[5]));
range_set_gtpu_teid(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])););
// clang-format on
break;
case 160:
foreach_port(portlist, range_set_cos_id(pinfo, argv[3], atoi(what)));
break;
case 161:
// clang-format off
foreach_port(portlist, range_set_cos_id(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_cos_id(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_cos_id(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_cos_id(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])););
// clang-format on
break;
case 170:
foreach_port(portlist, range_set_tos_id(pinfo, argv[3], atoi(what)));
break;
case 171:
// clang-format off
foreach_port(portlist, range_set_tos_id(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_tos_id(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_tos_id(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_tos_id(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])));
// clang-format on
break;
case 172:
foreach_port(portlist, range_set_hop_limits(pinfo, argv[3], atoi(what)));
break;
case 173:
// clang-format off
foreach_port(portlist,
range_set_hop_limits(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_hop_limits(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_hop_limits(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_hop_limits(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])));
// clang-format on
break;
case 174:
foreach_port(portlist, range_set_traffic_class(pinfo, argv[3], atoi(what)));
break;
case 175:
// clang-format off
foreach_port(portlist,
range_set_traffic_class(pinfo, (char *)(uintptr_t)"start", atoi(argv[3]));
range_set_traffic_class(pinfo, (char *)(uintptr_t)"min", atoi(argv[4]));
range_set_traffic_class(pinfo, (char *)(uintptr_t)"max", atoi(argv[5]));
range_set_traffic_class(pinfo, (char *)(uintptr_t)"inc", atoi(argv[6])));
// clang-format on
break;
default:
return cli_cmd_error("Range command error", "Range", argc, argv);
}
pktgen_update_display();
return 0;
}
#define set_types \
"count|" /* 0 */ \
"size|" /* 1 */ \
"rate|" /* 2 */ \
"burst|" /* 3 */ \
"tx_cycles|" /* 4 */ \
"sport|" /* 5 */ \
"dport|" /* 6 */ \
"prime|" /* 7 */ \
"dump|" /* 8 */ \
"vlan|" /* 9 */ \
"vlanid|" /* 10 */ \
"seq_cnt|" /* 11 */ \
"seqCnt|" /* 12 */ \
"seqcnt|" /* 13 */ \
"ttl|" /* 14 */ \
"txburst|" /* 15 */ \
"rxburst" /* 16 */
// clang-format off
static struct cli_map set_map[] = {
{10, "set %P %|" set_types " %d"},
{11, "set %P jitter %D"},
{20, "set %P type %|arp|ipv4|ipv6|ip4|ip6|vlan"},
{21, "set %P proto %|udp|tcp|icmp"},
{22, "set %P src mac %m"},
{23, "set %P dst mac %m"},
{24, "set %P pattern %|abc|none|user|zero"},
{25, "set %P user pattern %s"},
{30, "set %P src ip %4"},
{31, "set %P dst ip %4"},
{32, "set %P src ip %6"},
{33, "set %P dst ip %6"},
{34, "set %P tcp %|flag|flags %s"},
{36, "set %P tcp seq %d"},
{37, "set %P tcp ack %d"},
{40, "set ports_per_page %d"},
{50, "set %P qinqids %d %d"},
{60, "set %P rnd %d %d %s"},
{70, "set %P cos %d"},
{80, "set %P tos %d"},
{90, "set %P vxlan %h %d %d"},
{100, "set %P latsampler %|simple|poisson %d %d %s"},
{-1, NULL}
};
// clang format on
static const char *set_help[] = {
"",
" note: <portlist> - a list of ports (no spaces) e.g. 2,4,6-9,12 or the word "
"'all'",
"set <portlist> count <value> - number of packets to transmit",
"set <portlist> size <value> - size of the packet to transmit",
"set <portlist> rate <percent> - Packet rate in percentage",
"set <portlist> txburst|burst <value> - number of packets in a TX burst",
"set <portlist> rxburst <value> - number of packets in a RX burst",
"set <portlist> tx_cycles <value> - DEBUG to set the number of cycles per TX burst",
"set <portlist> sport <value> - Source port number for UDP/TCP",
"set <portlist> dport <value> - Destination port number for UDP/TCP",
"set <portlist> ttl <value> - Set the TTL value for the single port more",
"set <portlist> seq_cnt|seqcnt|seqCnt <value>",
" - Set the number of packet in the sequence to send [0-16]",
"set <portlist> prime <value> - Set the number of packets to send on prime command",
"set <portlist> dump <value> - Dump the next 1-32 received packets to the screen",
" Dumped packets are in the log, use 'page log' to view",
"set <portlist> vlan|vlanid <value> - Set the VLAN ID value for the portlist",
"set <portlist> jitter <value> - Set the jitter threshold in micro-seconds",
"set <portlist> src|dst mac <addr> - Set MAC addresses 00:11:22:33:44:55 or 0011:2233:4455 "
"format",
"set <portlist> type ipv4|ipv6|vlan|arp - Set the packet type to IPv4 or IPv6 or VLAN",
"set <portlist> proto udp|tcp|icmp - Set the packet protocol to UDP or TCP or ICMP per port",
"set <portlist> pattern <type> - Set the fill pattern type",
" type - abc - Default pattern of abc string",
" none - No fill pattern, maybe random data",
" zero - Fill of zero bytes",
" user - User supplied string of max 16 bytes",
"set <portlist> user pattern <string> - A 16 byte string, must set 'pattern user' command",
"set <portlist> [src|dst] ip ipaddr - Set IP addresses, Source must include network mask e.g. "
"10.1.2.3/24",
"set <portlist> tcp flags <string> - Set comma delimited TCP flags: cwr,ece,urg,ack,psh,rst,syn,fin,clr",
"set <portlist> tcp seq <sequence> - Set the TCP sequence number",
"set <portlist> tcp ack <acknowledge> - Set the TCP acknowledge number",
"set <portlist> qinqids <id1> <id2> - Set the Q-in-Q ID's for the portlist",
"set <portlist> rnd <idx> <off> <mask> - Set random mask for all transmitted packets from "
"portlist",
" idx: random mask index slot",
" off: offset in bytes to apply mask value",
" mask: up to 32 bit long mask specification (empty to disable):",
" 0: bit will be 0",
" 1: bit will be 1",
" .: bit will be ignored (original value is retained)",
" X: bit will get random value",
"set <portlist> cos <value> - Set the CoS value for the portlist",
"set <portlist> tos <value> - Set the ToS value for the portlist",
"set <portlist> vxlan <flags> <group id> <vxlan_id> - Set the vxlan values",
"set <portlist> latsampler [simple|poisson] <num-samples> <rate> <outfile> - Set latency "
"sampler parameters",
" num-samples: number of samples.",
" rate: sampling rate i.e., samples per second.",
" outfile: path to output file to dump all sampled latencies",
"set ports_per_page <value> - Set ports per page value 1 - 6",
CLI_HELP_PAUSE,
NULL};
static int
set_cmd(int argc, char **argv)
{
portlist_t portlist;
struct rte_ether_addr mac;
char *what, *p;
int value, n;
struct cli_map *m;
struct pg_ipaddr ip;
uint16_t id1, id2;
uint32_t u1, u2;
int ip_ver;
m = cli_mapping(set_map, argc, argv);
if (!m)
return cli_cmd_error("Set command is invalid", "Set", argc, argv);
portlist_parse(argv[1], pktgen.nb_ports, &portlist);
what = argv[2];
value = atoi(argv[3]);
switch (m->index) {
case 10:
n = cli_map_list_search(m->fmt, argv[2], 2);
foreach_port(portlist, _do(switch (n) {
case 0:
single_set_tx_count(pinfo, value);
break;
case 1:
single_set_pkt_size(pinfo, atoi(argv[3]));
break;
case 2:
single_set_tx_rate(pinfo, argv[3]);
break;
case 3:
single_set_tx_burst(pinfo, value);
break;
case 4:
debug_set_tx_cycles(pinfo, value);
break;
case 5:
single_set_port_value(pinfo, what[0], value);
break;
case 6:
single_set_port_value(pinfo, what[0], value);
break;
case 7:
pktgen_set_port_prime(pinfo, value);
break;
case 8:
debug_set_port_dump(pinfo, value);
break;
case 9: /* vlanid and vlan are valid */
case 10:
single_set_vlan_id(pinfo, value);
break;
case 11:
/* FALLTHRU */
case 12:
/* FALLTHRU */
case 13:
pktgen_set_port_seqCnt(pinfo, value);
break;
case 14:
single_set_ttl_value(pinfo, value);
break;
case 15:
single_set_tx_burst(pinfo, value);
break;
case 16:
single_set_rx_burst(pinfo, value);
break;
default:
return cli_cmd_error("Set command is invalid", "Set", argc, argv);
}));
break;
case 11:
foreach_port(portlist, single_set_jitter(pinfo, strtoull(argv[3], NULL, 0)));
break;
case 20:
foreach_port(portlist, single_set_pkt_type(pinfo, argv[3]));
break;
case 21:
foreach_port(portlist, single_set_proto(pinfo, argv[3]));
break;
case 22:
if (pg_ether_aton(argv[4], &mac) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[4]);
break;
}
foreach_port(portlist, single_set_src_mac(pinfo, &mac));
break;
case 23:
if (pg_ether_aton(argv[4], &mac) == NULL) {
cli_printf("Failed to parse MAC address from (%s)\n", argv[4]);
break;
}
foreach_port(portlist, single_set_dst_mac(pinfo, &mac));
break;
case 24:
foreach_port(portlist, pattern_set_type(pinfo, argv[3]));
break;
case 25:
foreach_port(portlist, pattern_set_user_pattern(pinfo, argv[4]));
break;
case 30:
p = strchr(argv[4], '/');
if (!p)
cli_printf("src IP address should contain subnet value, default /32 for IPv4\n");
ip_ver = _atoip(argv[4], PG_IPADDR_V4 | PG_IPADDR_NETWORK, &ip, sizeof(ip));
foreach_port(portlist, single_set_ipaddr(pinfo, 's', &ip, ip_ver));
break;
case 31:
/* Remove the /XX mask value if supplied */
p = strchr(argv[4], '/');
if (p) {
cli_printf("Subnet mask not required, removing subnet mask value\n");
*p = '\0';
}
ip_ver = _atoip(argv[4], PG_IPADDR_V4, &ip, sizeof(ip));
foreach_port(portlist, single_set_ipaddr(pinfo, 'd', &ip, ip_ver));
break;
case 32:
p = strchr(argv[4], '/');
if (!p)
cli_printf("src IP address should contain subnet value, default /128 for IPv6\n");
ip_ver = _atoip(argv[4], PG_IPADDR_V6 | PG_IPADDR_NETWORK, &ip, sizeof(ip));
foreach_port(portlist, single_set_ipaddr(pinfo, 's', &ip, ip_ver));
break;
case 33:
/* Remove the /XX mask value if supplied */
p = strchr(argv[4], '/');
if (p) {
cli_printf("Subnet mask not required, removing subnet mask value\n");
*p = '\0';
}
ip_ver = _atoip(argv[4], PG_IPADDR_V6, &ip, sizeof(ip));
foreach_port(portlist, single_set_ipaddr(pinfo, 'd', &ip, ip_ver));
break;
case 34:
foreach_port(portlist, single_set_tcp_flags(pinfo, argv[4]));
break;
case 36:
foreach_port(portlist, single_set_tcp_seq(pinfo, atoi(argv[4])));
break;
case 37:
foreach_port(portlist, single_set_tcp_ack(pinfo, atoi(argv[4])));
break;
case 40:
pktgen_set_page_size(atoi(argv[2]));
break;
case 50:
id1 = strtol(argv[3], NULL, 0);
id2 = strtol(argv[4], NULL, 0);
foreach_port(portlist, single_set_qinqids(pinfo, id1, id2));
break;
case 60: {
char mask[34] = {0}, *m;
char cb;
id1 = strtol(argv[3], NULL, 0);
id2 = strtol(argv[4], NULL, 0);
m = argv[5];
if (strcmp(m, "off")) {
int idx;
/* Filter invalid characters from provided mask. This way the user can
* more easily enter long bitmasks, using for example '_' as a separator
* every 8 bits. */
for (n = 0, idx = 0; (idx < 32) && ((cb = m[n]) != '\0'); n++)
if ((cb == '0') || (cb == '1') || (cb == '.') || (cb == 'X') || (cb == 'x'))
mask[idx++] = cb;
}
foreach_port(portlist, enable_random(pinfo, pktgen_set_random_bitfield(pinfo->rnd_bitfields,
id1, id2, mask)
? ENABLE_STATE
: DISABLE_STATE));
} break;
case 70:
id1 = strtol(argv[3], NULL, 0);
foreach_port(portlist, single_set_cos(pinfo, id1));
break;
case 80:
id1 = strtol(argv[3], NULL, 0);
foreach_port(portlist, single_set_tos(pinfo, id1));
break;
case 90:
id1 = strtol(argv[3], NULL, 0);
id2 = strtol(argv[4], NULL, 0);
u1 = strtol(argv[5], NULL, 0);
foreach_port(portlist, single_set_vxlan(pinfo, id1, id2, u1));
break;
case 100:
u1 = strtol(argv[4], NULL, 0);
u2 = strtol(argv[5], NULL, 0);
foreach_port(portlist, single_set_latsampler_params(pinfo, argv[3], u1, u2, argv[6]));
break;
default:
return cli_cmd_error("Command invalid", "Set", argc, argv);
}
pktgen_update_display();
return 0;
}
// clang-format off
static struct cli_map pcap_map[] = {
{10, "pcap %D"},
{20, "pcap show"},
{21, "pcap show all"},
{30, "pcap filter %P %s"},
{-1, NULL}
};
// clang-format on
static const char *pcap_help[] = {
"",
"pcap show - Show PCAP information",
"pcap <index> - Move the PCAP file index to the given packet number,\n "
" 0 - rewind, -1 - end of file",
"pcap filter <portlist> <string> - PCAP filter string to filter packets on receive",
CLI_HELP_PAUSE,
NULL};
static int
pcap_cmd(int argc, char **argv)
{
struct cli_map *m;
pcap_info_t *pcap;
uint32_t max_cnt;
uint32_t value;
portlist_t portlist;
port_info_t *pinfo;
m = cli_mapping(pcap_map, argc, argv);
if (!m)
return cli_cmd_error("PCAP command invalid", "PCAP", argc, argv);
pinfo = l2p_get_port_pinfo(pktgen.curr_port);
switch (m->index) {
case 10:
pcap = l2p_get_pcap(pinfo->pid);
value = strtoul(argv[1], NULL, 10);
if (pcap) {
max_cnt = pcap->pkt_count;
if (value >= max_cnt)
pcap->pkt_index = max_cnt - RTE_MIN(PCAP_PAGE_SIZE, (int)max_cnt);
else
pcap->pkt_index = value;
pktgen.flags |= PRINT_LABELS_FLAG;
} else
pktgen_log_error(" ** PCAP file is not loaded on port %d", pktgen.curr_port);
break;
case 20:
pcap = l2p_get_pcap(pinfo->pid);
if (pcap)
pktgen_pcap_info(pcap, pktgen.curr_port, 1);
else
pktgen_log_error(" ** PCAP file is not loaded on port %d", pktgen.curr_port);
break;
case 21:
for (int pid = 0; pid < pktgen.nb_ports; pid++) {
pcap = l2p_get_pcap(pid);
if (pcap)
pktgen_pcap_info(pcap, pid, 1);
}
break;
case 30:
portlist_parse(argv[2], pktgen.nb_ports, &portlist);
foreach_port(portlist, pcap_filter(pinfo, argv[3]));
break;
default:
return cli_cmd_error("PCAP command invalid", "PCAP", argc, argv);
}
pktgen_update_display();
return 0;
}
// clang-format off
static struct cli_map start_map[] = {
{10, "start %P"},
{20, "stop %P"},
{40, "start %P prime"},
{50, "start %P arp %|request|gratuitous|req|grat"},
{60, "start %P latsampler"},
{70, "stop %P latsampler"},
{-1, NULL}
};
// clang-format on
static const char *start_help[] = {
"",
"start <portlist> - Start transmitting packets",
"stop <portlist> - Stop transmitting packets",
"stp - Stop all ports from transmitting",
"str - Start all ports transmitting",
"start <portlist> prime - Transmit packets on each port listed. See set prime "
"command above",
"start <portlist> arp <type> - Send a ARP type packet",
" type - request | gratuitous | req | grat",
"start <portlist> latsampler - Start latency sampler, make sure to set sampling "
"parameters before starting",
"stop <portlist> latsampler - Stop latency sampler, dumps to file if specified",
CLI_HELP_PAUSE,
NULL};
static int
start_stop_cmd(int argc, char **argv)
{
struct cli_map *m;
portlist_t portlist;
m = cli_mapping(start_map, argc, argv);
if (!m)
return cli_cmd_error("Start/Stop command invalid", "Start", argc, argv);
portlist_parse(argv[1], pktgen.nb_ports, &portlist);
switch (m->index) {
case 10:
foreach_port(portlist, pktgen_start_transmitting(pinfo));
break;
case 20:
foreach_port(portlist, pktgen_stop_transmitting(pinfo));
break;
case 40:
foreach_port(portlist, pktgen_prime_ports(pinfo));
break;
case 50:
if (argv[3][0] == 'g')
foreach_port(portlist, pktgen_send_arp_requests(pinfo, GRATUITOUS_ARP));
else
foreach_port(portlist, pktgen_send_arp_requests(pinfo, 0));
break;
case 60:
foreach_port(portlist, pktgen_start_latency_sampler(pinfo));
break;
case 70:
foreach_port(portlist, pktgen_stop_latency_sampler(pinfo));
break;
default:
return cli_cmd_error("Start/Stop command invalid", "Start", argc, argv);
}
pktgen_update_display();
return 0;
}
// clang-format off
static struct cli_map theme_map[] = {
{0, "theme"},
{10, "theme %|on|off"},
{20, "theme %s %s %s %s"},
{30, "theme save %s"},
{-1, NULL}
};
// clang-format on
static const char *theme_help[] = {
"",
"theme <item> <fg> <bg> <attr> - Set color for item with fg/bg color and attribute value",
"theme show - List the item strings, colors and attributes to the "
"items",
"theme save <filename> - Save the current color theme to a file",
CLI_HELP_PAUSE,
NULL};
static int
theme_cmd(int argc, char **argv)
{
struct cli_map *m;
m = cli_mapping(theme_map, argc, argv);
if (!m)
return cli_cmd_error("Theme command invalid", "Theme", argc, argv);
switch (m->index) {
case 0:
pktgen_theme_show();
break;
case 10:
pktgen_theme_state(argv[1]);
pktgen_clear_display();
break;
case 20:
pktgen_set_theme_item(argv[1], argv[2], argv[3], argv[4]);
break;
case 30:
pktgen_theme_save(argv[2]);
break;
default:
return cli_help_show_group("Theme");
}