Repository navigation
Expand file tree
/
Copy pathtrex_global.h
More file actions
1189 lines (959 loc) · 33.4 KB
/
Copy pathtrex_global.h
File metadata and controls
1189 lines (959 loc) · 33.4 KB
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
#ifndef TREX_GLOBAL_H
#define TREX_GLOBAL_H
/*
Hanoh Haim
Cisco Systems, Inc.
*/
/*
Copyright (c) 2015-2016 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdint.h>
#include <stdio.h>
#include "mbuf.h"
#include <common/bitMan.h>
#include "platform_cfg.h"
#include "utl_json.h"
#include <json/json.h>
#include "pal_utl.h"
#include "trex_platform.h"
#include "trex_modes.h"
#include "hot_section.h"
#include <algorithm>
#define CONST_NB_MBUF 16380
/* this is the first small part of the packet that we manipulate */
#define _FIRST_PKT_SIZE 64
#define CONST_SMALL_MBUF_SIZE (_FIRST_PKT_SIZE + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
#define _64_MBUF_SIZE 64
#define _128_MBUF_SIZE 128
#define _256_MBUF_SIZE 256
#define _512_MBUF_SIZE 512
#define _1024_MBUF_SIZE 1024
#define _2048_MBUF_SIZE 2048
#define _4096_MBUF_SIZE 4096
#define MAX_PKT_ALIGN_BUF_9K (9*1024+64)
#define NUM_OF_POOLS 7
#define MBUF_PKT_PREFIX ( sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM )
#define CONST_128_MBUF_SIZE (128 + MBUF_PKT_PREFIX )
#define CONST_256_MBUF_SIZE (256 + MBUF_PKT_PREFIX )
#define CONST_512_MBUF_SIZE (512 + MBUF_PKT_PREFIX)
#define CONST_1024_MBUF_SIZE (1024 + MBUF_PKT_PREFIX)
#define CONST_2048_MBUF_SIZE (2048 + MBUF_PKT_PREFIX)
#define CONST_4096_MBUF_SIZE (4096 + MBUF_PKT_PREFIX)
#define CONST_9k_MBUF_SIZE (MAX_PKT_ALIGN_BUF_9K + MBUF_PKT_PREFIX)
#define TW_BUCKETS (CGlobalInfo::m_options.get_tw_buckets())
#define TW_BUCKETS_LEVEL1_DIV (16)
#define TW_LEVELS (CGlobalInfo::m_options.get_tw_levels())
#define BUCKET_TIME_SEC (CGlobalInfo::m_options.get_tw_bucket_time_in_sec())
#define BUCKET_TIME_SEC_LEVEL1 (CGlobalInfo::m_options.get_tw_bucket_level1_time_in_sec())
#define TCP_RX_FLUSH_ACCURATE_SEC (2.0/1000000.0)
#define TCP_RX_FLUSH_SEC (20.0/1000000.0)
#define STL_RX_FLUSH_SEC (20.0/1000000.0)
#define STL_RX_DELAY_TICKS (0.5/STL_RX_FLUSH_SEC)
#define LOWEND_LIMIT_FLOWNODES (1 << 16)
#define LOWEND_LIMIT_ACTIVEFLOWS (LOWEND_LIMIT_FLOWNODES / 2)
#define LOWEND_SHORT_SLEEP_SEC (100.0 / 1e6)
#define LOWEND_LONG_SLEEP_SEC (1.0 / 1e3)
#define LOWEND_MEMPOOL_LIMIT_MB (20 * 1e6)
typedef enum {
SERVICE_OFF,
SERVICE_FILTERED,
SERVICE_ON,
} service_status;
class CGenNode;
class CPreviewMode {
public:
enum {
VLAN_MODE_NONE = 0,
VLAN_MODE_NORMAL = 1,
VLAN_MODE_LOAD_BALANCE = 2,
MPLS_MODE_NORMAL = 4,
EoMPLS_MODE_NORMAL = 5,
EoMPLS_WITH_VLAN_MODE = 6,
};
CPreviewMode(){
clean();
}
void clean(){
m_fl
10BC8
ags = 0;
m_flags1=0;
setCores(1);
set_vlan_mode(VLAN_MODE_NONE);
set_zmq_publish_enable(true);
}
void setFileWrite(bool enable){
btSetMaskBit32(m_flags,0,0,enable?1:0);
}
bool getFileWrite(){
return (btGetMaskBit32(m_flags,0,0) ? true:false);
}
void setDisableMbufCache(bool enable){
btSetMaskBit32(m_flags,2,2,enable?1:0);
}
bool isMbufCacheDisabled(){
return (btGetMaskBit32(m_flags,2,2) ? true:false);
}
void set_disable_hw_flow_stat(bool enable) {
btSetMaskBit32(m_flags, 3, 3, enable ? 1 : 0);
}
bool get_disable_hw_flow_stat() {
return (btGetMaskBit32(m_flags, 3, 3) ? true:false);
}
void set_disable_flow_control_setting(bool enable){
btSetMaskBit32(m_flags,4,4,enable?1:0);
}
bool get_is_disable_flow_control_setting(){
return (btGetMaskBit32(m_flags,4,4) ? true:false);
}
/* learn & verify mode */
void set_learn_and_verify_mode_enable(bool enable){
btSetMaskBit32(m_flags,5,5,enable?1:0);
}
bool get_learn_and_verify_mode_enable(){
return (btGetMaskBit32(m_flags,5,5) ? true:false);
}
/* IPv6 enable/disable */
void set_ipv6_mode_enable(bool enable){
btSetMaskBit32(m_flags,7,7,enable?1:0);
}
bool get_ipv6_mode_enable(){
return (btGetMaskBit32(m_flags,7,7) ? true:false);
}
void setVMode(uint8_t vmode){
btSetMaskBit32(m_flags,10,8,vmode);
}
uint8_t getVMode(){
return (btGetMaskBit32(m_flags,10,8) );
}
void setRealTime(bool enable){
btSetMaskBit32(m_flags,11,11,enable?1:0);
}
bool getRealTime(){
return (btGetMaskBit32(m_flags,11,11) ? true:false);
}
void setClientServerFlip(bool enable){
btSetMaskBit32(m_flags,12,12,enable?1:0);
}
bool getClientServerFlip(){
return (btGetMaskBit32(m_flags,12,12) ? true:false);
}
void setSingleCore(bool enable){
btSetMaskBit32(m_flags,13,13,enable?1:0);
}
bool getSingleCore(){
return (btGetMaskBit32(m_flags,13,13) ? true:false);
}
/* -p */
void setClientServerFlowFlip(bool enable){
btSetMaskBit32(m_flags,14,14,enable?1:0);
}
bool getClientServerFlowFlip(){
return (btGetMaskBit32(m_flags,14,14) ? true:false);
}
void setNoCleanFlowClose(bool enable){
btSetMaskBit32(m_flags,15,15,enable?1:0);
}
bool getNoCleanFlowClose(){
return (btGetMaskBit32(m_flags,15,15) ? true:false);
}
void setCores(uint8_t cores){
btSetMaskBit32(m_flags,24,16,cores);
}
uint8_t getCores(){
return (btGetMaskBit32(m_flags,24,16) );
}
bool getIsOneCore(){
return (getCores()==1?true:false);
}
void setOnlyLatency(bool enable){
btSetMaskBit32(m_flags,25,25,enable?1:0);
}
bool getOnlyLatency(){
return (btGetMaskBit32(m_flags,25,25) ? true:false);
}
void set_pcap_mode_enable(bool enable){
btSetMaskBit32(m_flags,26,26,enable?1:0);
}
bool get_pcap_mode_enable(){
return (btGetMaskBit32(m_flags,26,26) ? true:false);
}
void set_zmq_publish_enable(bool enable){
btSetMaskBit32(m_flags,27,27,enable?1:0);
}
bool get_zmq_publish_enable(){
return (btGetMaskBit32(m_flags,27,27) ? true:false);
}
uint8_t get_vlan_mode() {
return (btGetMaskBit32(m_flags, 30, 28));
}
void set_vlan_mode(uint8_t mode) {
btSetMaskBit32(m_flags, 30, 28, mode);
}
void set_vlan_mode_verify(uint8_t mode);
bool get_is_rx_check_enable(){
return (btGetMaskBit32(m_flags,31,31) ? true:false);
}
void set_rx_check_enable(bool enable){
btSetMaskBit32(m_flags,31,31,enable?1:0);
}
bool get_is_slowpath_features_on() {
return (btGetMaskBit32(m_flags1, 0, 0) ? true : false);
}
void set_slowpath_features_on(bool enable) {
btSetMaskBit32(m_flags1, 0, 0, enable ? 1 : 0);
}
bool get_is_client_cfg_enable() {
return (btGetMaskBit32(m_flags1, 1, 1) ? true : false);
}
void set_client_cfg_enable(bool enable){
btSetMaskBit32(m_flags1, 1, 1, enable ? 1 : 0);
if (enable) {
set_slowpath_features_on(enable);
}
}
// m_flags1 - bit 2 is free
void set_no_keyboard(bool enable){
btSetMaskBit32(m_flags1,5,5,enable?1:0);
}
bool get_no_keyboard(){
return (btGetMaskBit32(m_flags1,5,5) ? true:false);
}
/* -e */
void setClientServerFlowFlipAddr(bool enable){
btSetMaskBit32(m_flags1,3,3,enable?1:0);
}
bool getClientServerFlowFlipAddr(){
return (btGetMaskBit32(m_flags1,3,3) ? true:false);
}
/* split mac is enabled */
void setWDDisable(bool wd_disable){
btSetMaskBit32(m_flags1,6,6,wd_disable?1:0);
}
bool getWDDisable(){
return (btGetMaskBit32(m_flags1,6,6) ? true:false);
}
void setCoreDumpEnable(bool enable) {
btSetMaskBit32(m_flags1, 7, 7, (enable ? 1 : 0) );
}
bool getCoreDumpEnable(){
return (btGetMaskBit32(m_flags1, 7, 7) ? true : false);
}
void setChecksumOffloadEnable(bool enable) {
btSetMaskBit32(m_flags1, 8, 8, (enable ? 1 : 0) );
}
bool getChecksumOffloadEnable(){
return (btGetMaskBit32(m_flags1, 8, 8) ? true : false);
}
void setCloseEnable(bool enable) {
btSetMaskBit32(m_flags1, 9, 9, (enable ? 1 : 0) );
}
bool getCloseEnable(){
return (btGetMaskBit32(m_flags1, 9, 9) ? true : false);
}
void set_rt_prio_mode(bool enable) {
btSetMaskBit32(m_flags1, 10, 10, (enable ? 1 : 0) );
}
bool get_rt_prio_mode() {
return (btGetMaskBit32(m_flags1, 10, 10) ? true : false);
}
void set_mlx5_so_mode(bool enable) {
btSetMaskBit32(m_flags1, 11, 11, (enable ? 1 : 0) );
}
bool get_mlx5_so_mode() {
return (btGetMaskBit32(m_flags1, 11, 11) ? true : false);
}
void set_mlx4_so_mode(bool enable) {
btSetMaskBit32(m_flags1, 12, 12, (enable ? 1 : 0) );
}
bool get_mlx4_so_mode() {
return (btGetMaskBit32(m_flags1, 12, 12) ? true : false);
}
void setChecksumOffloadDisable(bool enable) {
btSetMaskBit32(m_flags1, 13, 13, (enable ? 1 : 0) );
}
bool getChecksumOffloadDisable(){
return (btGetMaskBit32(m_flags1, 13, 13) ? true : false);
}
void set_dev_tso_support(bool enable) {
btSetMaskBit32(m_flags1, 15, 15, (enable ? 1 : 0) );
}
bool get_dev_tso_support() {
return (btGetMaskBit32(m_flags1, 15, 15) ? true : false);
}
void setTsoOffloadDisable(bool enable){
btSetMaskBit32(m_flags1, 16, 16, (enable ? 1 : 0) );
}
bool getTsoOffloadDisable() {
return (btGetMaskBit32(m_flags1, 16, 16) ? true : false
8
);
10BC8
}
void set_ntacc_so_mode(bool enable) {
btSetMaskBit32(m_flags1, 17, 17, (enable ? 1 : 0) );
}
bool get_ntacc_so_mode() {
return (btGetMaskBit32(m_flags1, 17, 17) ? true : false);
}
void set_termio_disabled(bool enable) {
btSetMaskBit32(m_flags1, 18, 18, (enable ? 1 : 0) );
}
bool get_is_termio_disabled() {
return (btGetMaskBit32(m_flags1, 18, 18) ? true : false);
}
void setLroOffloadDisable(bool enable){
btSetMaskBit32(m_flags1, 19, 19, (enable ? 1 : 0) );
}
bool getLroOffloadDisable() {
return (btGetMaskBit32(m_flags1, 19, 19) ? true : false);
}
void setPromMode(bool enable){
btSetMaskBit32(m_flags1, 20, 20, (enable ? 1 : 0) );
}
bool getPromMode() {
return (btGetMaskBit32(m_flags1, 20, 20) ? true : false);
}
void setEmulDebug(bool enable){
btSetMaskBit32(m_flags1, 21, 21, (enable ? 1 : 0) );
}
bool getEmulDebug() {
return (btGetMaskBit32(m_flags1, 21, 21) ? true : false);
}
uint8_t get_mac_ip_overide_mode() {
return btGetMaskBit32(m_flags1, 23, 22);
}
void set_mac_ip_overide_mode(uint8_t mode) {
btSetMaskBit32(m_flags1, 23, 22, mode);
if ( mode ) {
set_slowpath_features_on(mode);
}
}
void set_bnxt_so_mode(bool enable) {
btSetMaskBit32(m_flags1, 20, 20, (enable ? 1 : 0) );
}
bool get_bnxt_so_mode() {
return (btGetMaskBit32(m_flags1, 20, 20) ? true : false);
}
void setLatencyIEEE1588Disable(bool enable) {
btSetMaskBit32(m_flags1, 24, 24, (enable ? 1 : 0) );
}
bool getLatencyIEEE1588Disable(){
return (btGetMaskBit32(m_flags1, 24, 24) ? true : false);
}
void set_dev_lro_support(bool enable) {
btSetMaskBit32(m_flags1, 25, 25, (enable ? 1 : 0) );
}
bool get_dev_lro_support() {
return (btGetMaskBit32(m_flags1, 25, 25) ? true : false);
}
void set_latency_diag(bool enable) {
btSetMaskBit32(m_flags1, 26, 26, (enable ? 1 : 0) );
}
bool get_latency_diag() {
return (btGetMaskBit32(m_flags1, 26, 26) ? true : false);
}
void set_defer_start_queues(bool enable) {
btSetMaskBit32(m_flags1, 27, 27, (enable ? 1 : 0) );
}
bool get_defer_start_queues() {
return (btGetMaskBit32(m_flags1, 27, 27) ? true : false);
}
void set_mana_so_mode(bool enable) {
btSetMaskBit32(m_flags1, 28, 28, (enable ? 1 : 0) );
}
bool get_mana_so_mode() {
return (btGetMaskBit32(m_flags1, 28, 28) ? true : false);
}
public:
void Dump(FILE *fd);
private:
uint32_t m_flags;
uint32_t m_flags1;
};
typedef struct mac_align_t_ {
uint8_t dest[6];
uint8_t src[6];
uint8_t is_set;
uint8_t pad[3];
} mac_align_t ;
struct CMacAddrCfg {
public:
CMacAddrCfg () {
reset();
}
void reset () {
memset(u.m_data, 0, sizeof(u.m_data));
u.m_mac.dest[3] = 1;
u.m_mac.is_set = 0;
}
union {
mac_align_t m_mac;
uint8_t m_data[16];
} u;
} __rte_cache_aligned;
typedef struct tunnel_cfg_data_t{
uint16_t m_vlan;
mpls_tag_t m_mpls;
tunnel_cfg_data_t() {
m_vlan = 0;
m_mpls = {0};
}
} tunnel_cfg_data_t;
class CPerPortIPCfg {
public:
uint32_t get_ip() {return m_ip;}
uint32_t get_mask() {return m_mask;}
uint32_t get_def_gw() {return m_def_gw;}
uint32_t get_vlan() {return m_tunnel_cfg_data.m_vlan;}
mpls_tag_t get_mpls() {return m_tunnel_cfg_data.m_mpls;}
tunnel_cfg_data_t get_tunnel_cfg_data() {return m_tunnel_cfg_data;}
bool get_vxlan_fs() {return m_vxlan_fs;}
void set_ip(uint32_t val) {m_ip = val;}
void set_mask(uint32_t val) {m_mask = val;}
void set_def_gw(uint32_t val) {m_def_gw = val;}
void set_vlan(uint16_t val) {m_tunnel_cfg_data.m_vlan = val;}
void set_mpls(mpls_tag_t val) {m_tunnel_cfg_data.m_mpls = val;}
void set_tunnel_cfg_data(tunnel_cfg_data_t val) {m_tunnel_cfg_data = val;}
void set_vxlan_fs(bool val) {m_vxlan_fs = val;}
private:
uint32_t m_def_gw;
uint32_t m_ip;
uint32_t m_mask;
tunnel_cfg_data_t m_tunnel_cfg_data;
bool m_vxlan_fs = false;
};
class CParserOption {
public:
/* Runtime flags */
enum {
RUN_FLAGS_RXCHECK_CONST_TS =1,
};
enum trex_astf_mode_e {
OP_ASTF_MODE_NONE =0,
OP_ASTF_MODE_SERVR_ONLY =1,
OP_ASTF_MODE_CLIENT_MASK=2
};
enum trex_learn_mode_e {
LEARN_MODE_DISABLED=0,
LEARN_MODE_TCP_ACK=1,
LEARN_MODE_IP_OPTION=2,
LEARN_MODE_TCP_ACK_NO_SERVER_SEQ_RAND=3,
LEARN_MODE_MAX=LEARN_MODE_TCP_ACK_NO_SERVER_SEQ_RAND,
// This is used to check if 1 or 3 exist
LEARN_MODE_TCP=100
};
public:
void reset() {
preview.clean();
m_tw_buckets = 1024;
m_tw_levels = 3;
m_active_flows = 0;
m_factor = 1.0;
m_mbuf_factor = 1.0;
m_duration = 0.0;
m_platform_factor = 1.0;
m_vlan_port[0] = 100;
m_vlan_port[1] = 100;
memset(m_src_ipv6, 0, sizeof(m_src_ipv6));
memset(m_dst_ipv6, 0, sizeof(m_dst_ipv6));
m_ip_cfg->set_ip(0);
m_ip_cfg->set_mask(0);
m_ip_cfg->set_def_gw(0);
m_ip_cfg->set_vlan(0);
m_ip_cfg->set_vxlan_fs(false);
m_latency_rate = 0;
m_latency_mask = 0xffffffff;
m_latency_prev = 0;
m_rx_check_sample = 0;
m_rx_check_hops = 0;
m_wait_before_traffic = 1;
m_zmq_port = 4500;
m_telnet_port = 4501;
m_ezmq_ch_port = 4511;
m_expected_portd = 4; /* should be at least the number of ports found in the system but could be less. includes dummy ports */
m_io_mode = 1;
m_run_flags = 0;
m_l_pkt_mode = 0;
m_learn_mode = 0;
m_debug_pkt_proto = 0;
m_arp_ref_per = 120; // in seconds
m_arp_req_limit = 10;
m_rx_thread_enabled = false;
cfg_file = "";
client_cfg_file = "";
platform_cfg_file = "";
out_file = "";
prefix = "";
rpc_logfile_name = "";
set_tw_bucket_time_in_usec(20.0);
// we read every 0.5 second. We want to catch the counter when it approach the maximum (where it will stuck,
// and we will start losing packets).
x710_fdir_reset_threshold = 0xffffffff - 1000000000/8/64*40;
m_astf_mode =OP_ASTF_MODE_NONE;
m_astf_client_mask=0;
m_is_lowend = false;
m_lowend_core = 0;
m_is_sleepy_scheduler = false;
m_is_queuefull_retry = true;
m_is_vdev = false;
m_is_devs_in_vdev = false;
m_pdevs_in_vdev.clear();
m_is_bird_enabled = false;
m_ezmq_ch_enabled = false;
m_emzq_ch_tcp = false;
m_emzq_ipc_file_path = "/tmp/emu";
m_cmds_ipc_file_path = "/tmp/cmds";
m_stack_type = "legacy";
m_dummy_count=0;
m_reta_mask=0;
m_hdrh = false;
m_tx_ring_size = 0;
m_astf_best_effort_mode = false;
m_tunnel_loopback = false;
m_tunnel_enabled = false;
m_rx_dp_ring_size = 0;
}
CParserOption(){
reset();
}
/* IMPORTANT! Every new cold member in this class must be added at the bottom, otherwise performance issue may occur */
CPreviewMode preview;
uint16_t m_tw_buckets;
uint16_t m_tw_levels;
uint32_t m_active_flows;
float m_factor;
float m_mbuf_factor;
float m_duration;
float m_platform_factor;
uint16_t m_vlan_port[2]; /* vlan value */
uint16_t m_src_ipv6[6]; /* Most signficant 96-bits */
uint16_t m_dst_ipv6[6]; /* Most signficant 96-bits */
CPerPortIPCfg m_ip_cfg[TREX_MAX_PORTS];
uint32_t m_latency_rate; /* pkt/sec for each thread/port zero disable */
uint32_t m_latency_mask;
uint32_t m_latency_prev;
uint32_t m_wait_before_traffic;
uint16_t m_rx_check_sample; /* the sample rate of flows */
uint16_t m_rx_check_hops;
uint16_t m_zmq_port;
uint16_t m_telnet_port;
uint16_t m_ezmq_ch_port;
uint16_t m_expected_portd;
uint16_t m_io_mode; //0,1,2 0 disable, 1- normal , 2 - short
uint16_t m_run_flags;
uint8_t m_l_pkt_mode;
uint8_t m_learn_mode;
uint16_t m_debug_pkt_proto;
uint16_t m_arp_ref_per;
uint16_t m_arp_req_limit; // limit the initial ARP req for GW address
uint8_t m_dummy_count;
uint8_t m_reta_mask;
bool m_rx_thread_enabled;
trex_astf_mode_e m_astf_mode;
uint32_t m_astf_client_mask;
bool m_is_lowend;
bool m_is_sleepy_scheduler; // sleep or busy wait on scheduler
bool m_is_queuefull_retry; // retry on queue full
bool m_is_vdev;
bool m_is_devs_in_vdev;
std::vector<std::string> m_pdevs_in_vdev;
bool m_hdrh; /* enable HDR histograms for latency */
bool m_is_bird_enabled;
bool m_ezmq_ch_enabled;
bool m_tunnel_enabled;
bool m_emzq_ch_tcp;
std::string m_emzq_ipc_file_path;
std::string m_cmds_ipc_file_path;
std::string m_stack_type;
std::string cfg_file;
std::string astf_cfg_file;
std::string client_cfg_file;
std::string platform_cfg_file;
std::string out_file;
std::string prefix;
std::string rpc_logfile_name;
bool m_dummy_port_map[TREX_MAX_PORTS];
CMacAddrCfg m_mac_addr[TREX_MAX_PORTS];
double m_tw_bucket_time_sec;
double m_tw_bucket_time_sec_level1;
uint32_t x710_fdir_reset_threshold;
uint32_t m_lowend_core;
uint16_t m_tx_ring_size;
bool m_astf_best_effort_mode;
bool m_tunnel_loopback;
uint16_t m_rx_dp_ring_size; // Size of rings between Dp and Rx.
public:
uint8_t * get_src_mac_addr(int if_index){
return (m_mac_addr[if_index].u.m_mac.src);
}
uint8_t * get_dst_src_mac_addr(int if_index){
return (m_mac_addr[if_index].u.m_mac.dest);
}
uint32_t get_expected_ports(){
return (m_expected_portd);
}
/* how many dual ports supported */
uint32_t get_expected_dual_ports(void){
return (m_expected_portd>>1);
}
uint32_t get_number_of_dp_cores_needed() {
return ( (m_expected_portd>>1) * preview.getCores());
}
bool is_latency_enabled() {
return ( (m_latency_rate == 0) ? false : true);
}
bool is_rx_enabled() {
return m_rx_thread_enabled;
}
void set_rx_enabled() {
m_rx_thread_enabled = true;
}
uint32_t get_x710_fdir_reset_threshold() {
return (x710_fdir_reset_threshold);
}
void set_x710_fdir_reset_threshold(uint32_t val) {
x710_fdir_reset_threshold = val;
}
inline double get_tw_bucket_time_in_sec(void){
return (m_tw_bucket_time_sec);
}
inline double get_tw_bucket_level1_time_in_sec(void){
return (m_tw_bucket_time_sec_level1);
}
void set_tw_bucket_time_in_usec(double usec){
m_tw_bucket_time_sec= (usec/1000000.0);
m_tw_bucket_time_sec_level1 = (m_tw_bucket_time_sec*(double)m_tw_buckets)/((double)TW_BUCKETS_LEVEL1_DIV);
}
void set_tw_buckets(uint16_t buckets){
m_tw_buckets=buckets;
}
inline uint16_t get_tw_buckets(void){
return (m_tw_buckets);
}
void set_tw_levels(uint16_t levels){
m_tw_levels=levels;
}
inline uint16_t get_tw_levels(void){
return (m_tw_levels);
}
inline void set_rxcheck_const_ts(){
m_run_flags |= RUN_FLAGS_RXCHECK_CONST_TS;
}
inline void clear_rxcheck_const_ts(){
m_run_flags &=~ RUN_FLAGS_RXCHECK_CONST_TS;
}
inline bool is_rxcheck_const_ts(){
return ( (m_run_flags &RUN_FLAGS_RXCHECK_CONST_TS)?true:false );
}
inline uint8_t get_l_pkt_mode(){
return (m_l_pkt_mode);
}
void dump(FILE *fd);
bool is_valid_opt_val(int val, int min, int max, const std::string &opt_name);
void verify();
};
class CGlobalMemory {
public:
CGlobalMemory(){
CPlatformMemoryYamlInfo info;
m_num_cores=1;
m_pool_cache_size=32;
}
void set(const CPlatformMemoryYamlInfo &info,float mul);
uint32_t get_2k_num_blocks(){
return ( m_mbuf[MBUF_2048]);
}
uint32_t get_each_core_dp_flows(){
return ( m_mbuf[MBUF_DP_FLOWS]/m_num_cores );
}
void set_number_of_dp_cors(uint32_t cores){
m_num_cores = cores;
}
void set_pool_cache_size(uint32_t pool_cache){
m_pool_cache_size=pool_cache;
}
void Dump(FILE *fd);
public:
uint32_t m_mbuf[MBUF_ELM_SIZE]; // relative to traffic norm to 2x10G ports
uint32_t m_num_cores;
uint32_t m_pool_cache_size;
};
class CRteMemPool {
public:
inline rte_mbuf_t * HOT_FUNC _rte_pktmbuf_alloc(rte_mempool_t * mp ){
rte_mbuf_t * m=rte_pktmbuf_alloc(mp);
if ( likely(m) ) {
return (m);
}
// hack for failure when using lots of 4k mbufs. See TRex-393
// real solution should be to always use 2K mbufs, and concatenate if needed
if (mp == m_mbuf_pool_4096) {
return _rte_pktmbuf_alloc(m_mbuf_pool_9k);
}
dump_in_case_of_error(stderr, mp);
assert(0);
}
inline rte_mbuf_t * HOT_FUNC _rte_pktmbuf_alloc_no_assert(rte_mempool_t * mp ){
rte_mbuf_t * m=rte_pktmbuf_alloc(mp);
if ( likely(m) ) {
return (m);
}
// hack for failure when using lots of 4k mbufs. See TRex-393
// real solution should be to always use 2K mbufs, and concatenate if needed
if (mp == m_mbuf_pool_4096) {
return _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_9k);
} else {
return m;
}
}
inline rte_mempool_t HOT_FUNC * pktmbuf_get_pool(uint16_t size){
rte_mempool_t * p;
if ( size <= _128_MBUF_SIZE) {
p = m_mbuf_pool_128;
}else if ( size <= _256_MBUF_SIZE) {
p = m_mbuf_pool_256;
}else if (size <= _512_MBUF_SIZE) {
p = m_mbuf_pool_512;
}else if (size <= _1024_MBUF_SIZE) {
p = m_mbuf_pool_1024;
}else if (size <= _2048_MBUF_SIZE) {
p = m_mbuf_pool_2048;
}else if (size <= _4096_MBUF_SIZE) {
p = m_mbuf_pool_4096;
}else{
assert(size<=MAX_PKT_ALIGN_BUF_9K);
p = m_mbuf_pool_9k;
}
return (p);
}
inline HOT_FUNC rte_mbuf_t * pktmbuf_alloc(uint16_t size){
rte_mbuf_t * m;
if ( size <= _128_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_128);
}else if ( size <= _256_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_256);
}else if (size <= _512_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_512);
}else if (size <= _1024_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_1024);
}else if (size <= _2048_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_2048);
}else if (size <= _4096_MBUF_SIZE) {
m = _rte_pktmbuf_alloc(m_mbuf_pool_4096);
}else{
assert(size<=MAX_PKT_ALIGN_BUF_9K);
m = _rte_pktmbuf_alloc(m_mbuf_pool_9k);
}
return (m);
}
inline HOT_FUNC rte_mbuf_t * pktmbuf_alloc_no_assert(uint16_t size){
rte_mbuf_t * m;
if ( size <= _128_MBUF_SIZE) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_128);
if ( m ) { return m; }
}
if ( size <= _256_MBUF_SIZE ) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_256);
if ( m ) { return m; }
}
if ( size <= _512_MBUF_SIZE ) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_512);
if ( m ) { return m; }
}
if ( size <= _1024_MBUF_SIZE ) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_1024);
if ( m ) { return m; }
}
if ( size <= _2048_MBUF_SIZE ) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_2048);
if ( m ) { return m; }
}
if ( size <= _4096_MBUF_SIZE ) {
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_4096);
if ( m ) { return m; }
} else {
assert(size<=MAX_PKT_ALIGN_BUF_9K);
m = _rte_pktmbuf_alloc_no_assert(m_mbuf_pool_9k);
if ( m ) { return m; }
}
return NULL;
}
inline rte_mbuf_t * HOT_FUNC pktmbuf_alloc_small(){
return ( _rte_pktmbuf_alloc(m_small_mbuf_pool) );
}
inline rte_mbuf_t * HOT_FUNC pktmbuf_alloc_small_no_assert(){
return ( _rte_pktmbuf_alloc_no_assert(m_small_mbuf_pool) );
}
bool dump_one(FILE *fd, const char *name, rte_mempool_t *pool);
void dump(FILE *fd);
void dump_in_case_of_error(FILE *fd, rte_mempool_t * mp);
void dump_as_json(Json::Value &json);
private:
void add_to_json(Json::Value &json, std::string name, rte_mempool_t * pool);
public:
rte_mempool_t * m_small_mbuf_pool; /* pool for start packets */
rte_mempool_t * m_mbuf_pool_128;
rte_mempool_t * m_mbuf_pool_256;
rte_mempool_t * m_mbuf_pool_512;
rte_mempool_t * m_mbuf_pool_1024;
rte_mempool_t * m_mbuf_pool_2048;
rte_mempool_t * m_mbuf_pool_4096;
rte_mempool_t * m_mbuf_pool_9k;
rte_mempool_t * m_mbuf_global_nodes;
uint32_t m_pool_id;
};
class CGlobalInfo {
public:
static void init_pools(uint32_t rx_buffers, uint32_t rx_pool, bool is_hugepages = true);
/* for simulation */
static void free_pools();
static inline rte_mbuf_t * HOT_FUNC pktmbuf_alloc_small(socket_id_t socket){
return ( m_mem_pool[socket].pktmbuf_alloc_small() );
}
static inline rte_mbuf_t * HOT_FUNC pktmbuf_alloc_small_no_assert(socket_id_t socket){