forked from cisco-system-traffic-generator/trex-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp_sim.h
executable file
·3691 lines (2886 loc) · 102 KB
/
bp_sim.h
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 BP_SIM_H
#define BP_SIM_H
/*
Hanoch 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 <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include "mbuf.h"
#include <common/c_common.h>
#include <common/captureFile.h>
#include <common/Network/Packet/TcpHeader.h>
#include <common/Network/Packet/UdpHeader.h>
#include <common/Network/Packet/IcmpHeader.h>
#include <common/Network/Packet/IPHeader.h>
#include <common/Network/Packet/IPv6Header.h>
#include <common/Network/Packet/EthernetHeader.h>
#include <math.h>
#include <yaml-cpp/yaml.h>
#include "trex_defs.h"
#include "utl_ip.h"
#include "os_time.h"
#include "pal_utl.h"
#include "rx_check_header.h"
#include "rx_check.h"
#include "time_histogram.h"
#include "utl_cpuu.h"
#include "tuple_gen.h"
#include "utl_jitter.h"
#include "msg_manager.h"
#include "nat_check.h"
#include <common/cgen_map.h>
#include <arpa/inet.h>
#include "platform_cfg.h"
#include "trex_watchdog.h"
#include "trex_client_config.h"
#include "h_timer.h"
#include "tw_cfg.h"
#include "utl_dbl_human.h"
#include "utl_policer.h"
#include "trex_platform.h"
#include "trex_global.h"
#include "plat_support.h"
/* stateless includes */
#include "stl/trex_stl_dp_core.h"
#include "stl/trex_stl_fs.h"
#include "stl/trex_stl_tpg.h"
#include "hot_section.h"
/* astf includes */
#include "astf/trex_astf_dp_core.h"
class CGenNodePCAP;
#define FORCE_NO_INLINE __attribute__ ((noinline))
#define FORCE_INLINE __attribute__((always_inline))
/* reserve both 0xFF and 0xFE , router will -1 FF */
#define TTL_RESERVE_DUPLICATE 0xff
#define TOS_GO_TO_CPU 0x1
/*
* Length of string needed to hold the largest port (16-bit) address
*/
#define INET_PORTSTRLEN 5
/* VM commands */
class CMiniVMCmdBase {
public:
enum MV_FLAGS {
MIN_VM_V6=1 // IPv6 addressing
};
uint8_t m_cmd;
uint8_t m_flags;
uint16_t m_start_0;
uint16_t m_stop_1;
uint16_t m_add_pkt_len; /* request more length for mbuf packet the size */
};
class CMiniVMReplaceIP : public CMiniVMCmdBase {
public:
ipaddr_t m_server_ip;
};
class CMiniVMReplaceIPWithPort : public CMiniVMReplaceIP {
public:
uint16_t m_start_port;
uint16_t m_stop_port;
uint16_t m_client_port;
uint16_t m_server_port;
};
/* this command replace IP in 2 diffrent location and port
c = 10.1.1.2
o = 10.1.1.2
m = audio 102000
==>
c = xx.xx.xx.xx
o = xx.xx.xx.xx
m = audio yyyy
*/
class CMiniVMReplaceIP_IP_Port : public CMiniVMCmdBase {
public:
ipaddr_t m_ip;
uint16_t m_ip0_start;
uint16_t m_ip0_stop;
uint16_t m_ip1_start;
uint16_t m_ip1_stop;
uint16_t m_port;
uint16_t m_port_start;
uint16_t m_port_stop;
};
class CMiniVMReplaceIP_PORT_IP_IP_Port : public CMiniVMReplaceIP_IP_Port {
public:
ipaddr_t m_ip_via;
uint16_t m_port_via;
uint16_t m_ip_via_start;
uint16_t m_ip_via_stop;
};
class CMiniVMDynPyload : public CMiniVMCmdBase {
public:
void * m_ptr;
ipaddr_t m_ip;
} ;
class CMiniVMDHCPPayload : public CMiniVMCmdBase {
public:
CMiniVMDHCPPayload() {
m_flags = 0;
m_client_ip.v4 = 0;
}
inline const uint16_t get_dhcp_client_port() {
return m_dhcp_client_port;
}
inline const uint16_t get_client_ip_start_offset() {
return m_client_ip_offset;
}
inline const uint16_t get_client_ip_end_offset() {
return (m_client_ip_offset + sizeof(m_client_ip.v4));
}
inline const uint16_t get_client_mac_start_offset() {
return m_client_mac_offset;
}
inline const uint16_t get_client_mac_end_offset() {
return m_client_mac_offset + ETHER_ADDR_LEN;
}
inline const uint16_t get_offset_between_client_addresses() {
return get_client_mac_start_offset() - get_client_ip_end_offset();
}
public:
MacAddress m_client_mac;
ipaddr_t m_client_ip;
private:
const uint16_t m_client_mac_offset = 28;
const uint16_t m_client_ip_offset = 16;
const uint16_t m_dhcp_client_port = 68;
};
/* VM with SIMD commands for RTSP we can add SIP/FTP commands too */
typedef enum { VM_REPLACE_IP_OFFSET =0x12, /* fix ip at offset */
VM_REPLACE_IP_PORT_OFFSET, /* fix ip at offset and client port*/
VM_REPLACE_IP_PORT_RESPONSE_OFFSET, /* fix client port and server port */
VM_REPLACE_IP_IP_PORT,/* SMID command to replace IPV4 , IPV4, PORT in 3 diffrent location , see CMiniVMReplaceIP_IP_Port*/
VM_REPLACE_IPVIA_IP_IP_PORT,/* SMID command to replace ip,port IPV4 , IPV4, PORT in 3 diffrent location , see CMiniVMReplaceIP_PORT_IP_IP_Port*/
VM_DYN_PYLOAD,
VM_DHCP_PAYLOAD, /* command to replace Client Mac Address in a DHCP Payload (Request or ACK) based on the L2 Mac Address */
VM_EOP /* end of program */
} mini_vm_op_code_t;
/* work only on x86 littel */
#define MY_B(b) (((int)b)&0xff)
class CFlowPktInfo ;
class CMiniVM {
public:
CMiniVM(){
m_new_pkt_size=0;
}
int mini_vm_run(CMiniVMCmdBase * cmds[]);
int mini_vm_replace_ip(CMiniVMReplaceIP * cmd);
int mini_vm_replace_port_ip(CMiniVMReplaceIPWithPort * cmd);
int mini_vm_replace_ports(CMiniVMReplaceIPWithPort * cmd);
int mini_vm_replace_ip_ip_ports(CMiniVMReplaceIP_IP_Port * cmd);
int mini_vm_replace_ip_via_ip_ip_ports(CMiniVMReplaceIP_PORT_IP_IP_Port * cmd);
int mini_vm_dyn_payload( CMiniVMDynPyload * cmd);
int mini_vm_dhcp_payload(CMiniVMDHCPPayload* cmd);
private:
int append_with_end_of_line(uint16_t len){
//assert(m_new_pkt_size<=0);
if (m_new_pkt_size <0 ) {
memset(m_pyload_mbuf_ptr+len+m_new_pkt_size,0xa,(-m_new_pkt_size));
}
return (0);
}
public:
int16_t m_new_pkt_size; /* New packet size after transform by plugin */
CFlowPktInfo * m_pkt_info;
char * m_pyload_mbuf_ptr; /* pointer to the pyload pointer of new allocated packet from mbuf */
};
class CGenNode;
class CFlowYamlInfo;
class CFlowGenListPerThread ;
/* callback */
void on_node_first(uint8_t plugin_id,CGenNode * node,
CFlowYamlInfo * template_info,
CTupleTemplateGeneratorSmart * tuple_gen,
CFlowGenListPerThread * flow_gen
);
void on_node_last(uint8_t plugin_id,CGenNode * node);
rte_mbuf_t * on_node_generate_mbuf(uint8_t plugin_id,CGenNode * node,CFlowPktInfo * pkt_info);
class CPreviewMode ;
class CLatencyPktData {
public:
CLatencyPktData() {m_flow_seq = FLOW_STAT_PAYLOAD_INITIAL_FLOW_SEQ;}
inline uint32_t get_seq_num() {return m_seq_num;}
inline void inc_seq_num() {m_seq_num++;}
inline uint32_t get_flow_seq() {return m_flow_seq;}
void reset() {
m_seq_num = UINT32_MAX - 1; // catch wrap around issues early
m_flow_seq++;
if (m_flow_seq == FLOW_STAT_PAYLOAD_INITIAL_FLOW_SEQ)
m_flow_seq++;
}
private:
uint32_t m_seq_num; // seq num to put in packet for payload rules. Increased every packet.
uint16_t m_flow_seq; // Seq num of flow. Changed when we start new flow on this id.
};
/* represent the virtual interface
*/
/* counters per side */
class CVirtualIFPerSideStats {
public:
CVirtualIFPerSideStats(){
Clear();
m_template.Clear();
}
uint64_t m_tx_pkt;
uint64_t m_tx_rx_check_pkt;
uint64_t m_tx_bytes;
uint64_t m_tx_drop;
uint64_t m_tx_queue_full;
uint64_t m_tx_alloc_error;
uint64_t m_tx_redirect_error;
tx_per_flow_t m_tx_per_flow[MAX_FLOW_STATS + MAX_FLOW_STATS_PAYLOAD];
CLatencyPktData m_lat_data[MAX_FLOW_STATS_PAYLOAD];
CPerTxthreadTemplateInfo m_template;
public:
void Add(CVirtualIFPerSideStats * obj){
m_tx_pkt += obj->m_tx_pkt;
m_tx_rx_check_pkt +=obj->m_tx_rx_check_pkt;
m_tx_bytes += obj->m_tx_bytes;
m_tx_drop += obj->m_tx_drop;
m_tx_alloc_error += obj->m_tx_alloc_error;
m_tx_queue_full +=obj->m_tx_queue_full;
m_tx_redirect_error +=obj->m_tx_redirect_error;
m_template.Add(&obj->m_template);
}
void Clear(){
m_tx_pkt=0;
m_tx_rx_check_pkt=0;
m_tx_bytes=0;
m_tx_drop=0;
m_tx_alloc_error=0;
m_tx_queue_full=0;
m_tx_redirect_error=0;
m_template.Clear();
for (int i = 0; i < MAX_FLOW_STATS_PAYLOAD; i++) {
m_lat_data[i].reset();
}
for (int i = 0; i < sizeof(m_tx_per_flow) / sizeof(m_tx_per_flow[0]); i++) {
m_tx_per_flow[i].clear();
}
}
inline void Dump(FILE *fd);
};
void CVirtualIFPerSideStats::Dump(FILE *fd){
#define DP_B(f) if (f) printf(" %-40s : %lu \n",#f,f)
DP_B(m_tx_pkt);
DP_B(m_tx_rx_check_pkt);
DP_B(m_tx_bytes);
DP_B(m_tx_drop);
DP_B(m_tx_alloc_error);
DP_B(m_tx_queue_full);
DP_B(m_tx_redirect_error);
m_template.Dump(fd);
}
class CVirtualIF {
public:
CVirtualIF () {
m_preview_mode = NULL;
}
virtual ~CVirtualIF() {}
virtual int open_file(std::string file_name)=0;
virtual int close_file(void)=0;
/* read packet from the right queue , per direction, client/server */
virtual uint16_t rx_burst(pkt_dir_t dir,
struct rte_mbuf **rx_pkts,
uint16_t nb_pkts){
assert(0);
}
/* send one packet */
virtual int send_node(CGenNode * node)=0;
/* by default does the same */
virtual int send_node_service_mode(CGenNode *node) {
return send_node(node);
}
/* send one packet to a specific dir. flush all packets */
virtual void send_one_pkt(pkt_dir_t dir, rte_mbuf_t *m) {}
/* flush all pending packets into the stream */
virtual int flush_tx_queue(void)=0;
/* update the source and destination mac-addr of a given mbuf by global database */
virtual int update_mac_addr_from_global_cfg(pkt_dir_t dir, uint8_t * p)=0;
/* translate port_id to the correct dir on the core */
virtual pkt_dir_t port_id_to_dir(uint8_t port_id) {
return (CS_INVALID);
}
virtual void set_review_mode(CPreviewMode *preview_mode) {
m_preview_mode = preview_mode;
}
virtual CVirtualIFPerSideStats * get_stats() {
return m_stats;
}
virtual bool redirect_to_rx_core(pkt_dir_t dir,
rte_mbuf_t * m){
return(false);
}
/* set the time for simulation */
virtual void set_rx_burst_time(double time){
}
virtual void set_tunnel(CTunnelHandler* tunnel_handler, bool loopback=false) {}
virtual void delete_tunnel() {}
virtual CTunnelHandler* get_tunnel_handler() {
return nullptr;
}
/**
* Set back pointer to DP core. Provide an empty implementation for
* the base class, so that simulator interfaces won't have to implement this.
*
* @param dp_core
* Pointer to DP core.
*/
virtual void set_dp_core(TrexDpCore* dp_core) {}
protected:
CPreviewMode *m_preview_mode;
CVirtualIFPerSideStats m_stats[CS_NUM];
/* never add public fields to this class - it is being wrapped and delegated */
};
#define MAX_PYLOAD_PKT_CHANGE 4
/* info for the dynamic plugin */
struct CFlowYamlDpPkt {
CFlowYamlDpPkt(){
m_pkt_id=0xff;
m_pyld_offset=0;
m_type=0;
m_len=0;
m_pkt_mask=0xffffffff;
}
uint8_t m_pkt_id; /* number of packet */
uint8_t m_pyld_offset; /* 0-10 */
uint8_t m_type; /* 0 -random , 1 - inc */
uint8_t m_len; /* number of 32bit data 1,2,3,*/
uint32_t m_pkt_mask; /* 0xffffffff take all the packet */
public:
void Dump(FILE *fd);
};
struct CFlowYamlDynamicPyloadPlugin {
CFlowYamlDynamicPyloadPlugin(){
m_num=0;
int i;
for (i=0;i<MAX_PYLOAD_PKT_CHANGE;i++ ) {
m_pkt_ids[i]=0xff;
}
}
uint8_t m_num;/* number of pkts_id*/
uint8_t m_pkt_ids[MAX_PYLOAD_PKT_CHANGE]; /* -1 for not valid - fast mask */
CFlowYamlDpPkt m_program[MAX_PYLOAD_PKT_CHANGE];
public:
void Add(CFlowYamlDpPkt & fd);
void Dump(FILE *fd);
};
struct CVlanYamlInfo {
CVlanYamlInfo(){
m_enable=0;
m_vlan_per_port[0]=100;
m_vlan_per_port[1]=200;
}
bool m_enable;
uint16_t m_vlan_per_port[2];
public:
void Dump(FILE *fd);
};
struct CFlowYamlInfo {
CFlowYamlInfo();
std::string m_name;
std::string m_client_pool_name;
std::string m_server_pool_name;
double m_k_cps; //k CPS
double m_restart_time; /* restart time of this template */
dsec_t m_ipg_sec; // ipg in sec
dsec_t m_rtt_sec; // rtt in sec
uint32_t m_w;
uint32_t m_limit;
uint32_t m_flowcnt;
pool_index_t m_client_pool_idx;
pool_index_t m_server_pool_idx;
uint32_t m_server_addr;
uint8_t m_plugin_id; /* 0 - default , 1 - RTSP160 , 2- RTSP250 */
uint16_t m_ip_header_offset;
uint32_t m_max_ip_tunnels;
bool m_one_app_server;
bool m_one_app_server_was_set;
bool m_cap_mode;
bool m_cap_mode_was_set;
bool m_limit_was_set;
bool m_multi_flow_was_set;
bool m_keep_src_port;
std::vector<pkt_dir_t> m_flows_dirs;
CFlowYamlDynamicPyloadPlugin * m_dpPkt; /* plugin */
public:
void Dump(FILE *fd);
};
#define DP(f) if (f) printf(" %-40s: %llu \n",#f,(unsigned long long)f)
#define DP_name(n,f) if (f) printf(" %-40s: %llu \n",n,(unsigned long long)f)
#define DP_S(f,f_s) if (f) printf(" %-40s: %s \n",#f,f_s.c_str())
class CFlowPktInfo;
class CCapFileFlowInfo ;
#define SYNC_TIME_OUT ( 1.0/1000)
//#define SYNC_TIME_OUT ( 2000.0/1000)
/* this is a simple struct, do not add constructor and destractor here!
we are optimizing the allocation dealocation !!!
*/
struct CGenNodeBase {
public:
enum {
FLOW_PKT =0,
FLOW_FIF =1,
FLOW_DEFER_PORT_RELEASE =2,
FLOW_PKT_NAT =3,
FLOW_SYNC =4, /* called evey 1 msec */
STATELESS_PKT =5,
EXIT_SCHED =6,
COMMAND =7,
EXIT_PORT_SCHED =8,
PCAP_PKT =9,
GRAT_ARP =10,
TW_SYNC =11,
TW_SYNC1 =12,
TCP_RX_FLUSH =13, /* TCP rx flush */
TCP_TX_FIF =14, /* TCP FIF */
TCP_TW =15, /* TCP TW -- need to consolidate */
RX_MSG =16, /* message to Rx core */
STL_RX_FLUSH =17,
};
/* flags MASKS*/
enum {
NODE_FLAGS_DIR =1,
NODE_FLAGS_MBUF_CACHE =2,
NODE_FLAGS_SAMPLE_RX_CHECK =4,
NODE_FLAGS_LEARN_MODE =8, /* bits 3,4 MASK 0x18 wait for second direction packet */
NODE_FLAGS_LEARN_MSG_PROCESSED =0x10, /* got NAT msg */
NODE_FLAGS_LATENCY =0x20, /* got NAT msg */
NODE_FLAGS_INIT_START_FROM_SERVER_SIDE = 0x40,
NODE_FLAGS_ALL_FLOW_SAME_PORT_SIDE = 0x80,
NODE_FLAGS_INIT_START_FROM_SERVER_SIDE_SERVER_ADDR = 0x100, /* init packet start from server side with server addr */
NODE_FLAGS_SLOW_PATH = 0x200, /* used by the nodes to differ between fast path nodes and slow path nodes */
NODE_FLAGS_DEST_MAC_BROADCAST = 0x400 /* Used to set the L2 MAC destination address to broadcast */
};
public:
/*********************************************/
/* C1 must */
uint8_t m_type;
uint8_t m_thread_id; /* zero base */
uint8_t m_socket_id;
uint8_t m_pad2;
uint16_t m_src_port;
uint16_t m_flags; /* BIT 0 - DIR ,
BIT 1 - mbug_cache
BIT 2 - SAMPLE DUPLICATE */
double m_time; /* can't change this header - size 16 bytes*/
public:
bool operator <(const CGenNodeBase * rsh ) const {
return (m_time<rsh->m_time);
}
bool operator ==(const CGenNodeBase * rsh ) const {
return (m_time==rsh->m_time);
}
bool operator >(const CGenNodeBase * rsh ) const {
return (m_time>rsh->m_time);
}
public:
void set_socket_id(socket_id_t socket){
m_socket_id=socket;
}
socket_id_t get_socket_id(){
return ( m_socket_id );
}
inline void set_slow_path(bool enable) {
if (enable) {
m_flags |= NODE_FLAGS_SLOW_PATH;
} else {
m_flags &= ~NODE_FLAGS_SLOW_PATH;
}
}
inline bool get_is_slow_path() const {
return ( (m_flags & NODE_FLAGS_SLOW_PATH) ? true : false);
}
void free_base();
bool is_flow_node(){
if ((m_type == FLOW_PKT) || (m_type == FLOW_PKT_NAT)) {
return (true);
}else{
return (false);
}
}
};
struct CNodeTcp: public CGenNodeBase {
double sim_time;
rte_mbuf_t * mbuf;
uint8_t dir;
};
struct CGenNodeCommand : public CGenNodeBase {
public:
TrexCpToDpMsgBase *m_cmd;
uint8_t m_pad_end[104];
/* CACHE_LINE */
#ifdef __PPC64__
#ifdef TREX_SIM
uint64_t m_pad3[8];
#else
uint64_t m_pad3[16];
#endif
#else
uint64_t m_pad3[8];
#endif
public:
void free_command();
} __rte_cache_aligned;;
class CPerProfileCtx;
struct CGenNodeTXFIF : public CGenNodeBase {
public:
CPerProfileCtx * m_pctx;
double m_time_stop;
double m_time_established;
double m_terminate_duration;
bool m_set_nc;
uint8_t m_pad_end[79];
/* CACHE_LINE */
#ifdef __PPC64__
#ifdef TREX_SIM
uint64_t m_pad3[8];
#else
uint64_t m_pad3[16];
#endif
#else
uint64_t m_pad3[8];
#endif
} __rte_cache_aligned;;
struct CGenNode : public CGenNodeBase {
public:
uint32_t m_src_ip; /* client ip */
uint32_t m_dest_ip; /* server ip */
uint64_t m_flow_id; /* id that goes up for each flow */
/*c2*/
CFlowPktInfo * m_pkt_info;
CCapFileFlowInfo * m_flow_info;
CFlowYamlInfo * m_template_info;
void * m_plugin_info;
/* cache line -2 */
CHTimerObj m_tmr;
uint64_t m_tmr_pad[4];
/* cache line -3 */
CTupleGeneratorSmart *m_tuple_gen;
// cache line 1 - 64bytes waste of space !
uint32_t m_nat_external_ipv4; // NAT client IP
uint32_t m_nat_tcp_seq_diff_client; // support for firewalls that do TCP seq num randomization
uint32_t m_nat_tcp_seq_diff_server; // And some do seq num randomization for server->client also
uint16_t m_nat_external_port; // NAT client port
uint16_t m_nat_pad[1];
const ClientCfgBase *m_client_cfg;
uint32_t m_src_idx;
uint32_t m_dest_idx;
uint32_t m_end_of_cache_line[6];
public:
void free_gen_node();
public:
void Dump(FILE *fd);
static void DumpHeader(FILE *fd);
inline bool is_last_in_flow();
inline uint16_t get_template_id();
inline bool is_repeat_flow();
inline bool can_cache_mbuf(void);
/* is it possible to cache MBUF */
inline uint32_t update_next_pkt_in_flow_tw(void);
/* update the node time for accurate scheduler */
inline void update_next_pkt_in_flow_as(void);
inline uint32_t update_next_pkt_in_flow_both(void);
inline void reset_pkt_in_flow(void);
inline uint8_t get_plugin_id(void){
assert(m_template_info);
return ( m_template_info->m_plugin_id);
}
inline bool is_responder_pkt();
inline bool is_initiator_pkt();
inline bool is_eligible_from_server_side(){
return ( ( (m_src_ip&1) == 1)?true:false);
}
inline void set_dest_mac_broadcast(bool enable) {
if (enable) {
m_flags |= NODE_FLAGS_DEST_MAC_BROADCAST;
} else {
m_flags &=~ NODE_FLAGS_DEST_MAC_BROADCAST;
}
}
inline bool get_is_dest_mac_broadcast() {
return ((m_flags & NODE_FLAGS_DEST_MAC_BROADCAST) ? true : false);
}
inline void set_initiator_start_from_server_side_with_server_addr(bool enable){
if (enable) {
m_flags |= NODE_FLAGS_INIT_START_FROM_SERVER_SIDE_SERVER_ADDR;
}else{
m_flags &=~ NODE_FLAGS_INIT_START_FROM_SERVER_SIDE_SERVER_ADDR;
}
}
inline bool get_is_initiator_start_from_server_with_server_addr(){
return ( (m_flags &NODE_FLAGS_INIT_START_FROM_SERVER_SIDE_SERVER_ADDR)?true:false );
}
inline void set_initiator_start_from_server(bool enable){
if (enable) {
m_flags |= NODE_FLAGS_INIT_START_FROM_SERVER_SIDE;
}else{
m_flags &=~ NODE_FLAGS_INIT_START_FROM_SERVER_SIDE;
}
}
inline bool get_is_initiator_start_from_server(){
return ( (m_flags &NODE_FLAGS_INIT_START_FROM_SERVER_SIDE)?true:false );
}
inline void set_all_flow_from_same_dir(bool enable){
if (enable) {
m_flags |= NODE_FLAGS_ALL_FLOW_SAME_PORT_SIDE;
}else{
m_flags &=~ NODE_FLAGS_ALL_FLOW_SAME_PORT_SIDE;
}
}
inline bool get_is_all_flow_from_same_dir(void){
return ( (m_flags &NODE_FLAGS_ALL_FLOW_SAME_PORT_SIDE)?true:false );
}
/* direction for ip addr */
inline pkt_dir_t cur_pkt_ip_addr_dir();
/* direction for TCP/UDP port */
inline pkt_dir_t cur_pkt_port_addr_dir();
/* from which interface dir to get out */
inline pkt_dir_t cur_interface_dir();
inline void set_mbuf_cache_dir(pkt_dir_t dir){
if (dir) {
m_flags |=NODE_FLAGS_DIR;
}else{
m_flags &=~NODE_FLAGS_DIR;
}
}
inline pkt_dir_t get_mbuf_cache_dir(){
return ((pkt_dir_t)( m_flags &1));
}
inline void set_cache_mbuf(rte_mbuf_t * m){
m_plugin_info=(void *)m;
m_flags |= NODE_FLAGS_MBUF_CACHE;
}
inline rte_mbuf_t * get_cache_mbuf(){
if ( m_flags &NODE_FLAGS_MBUF_CACHE ) {
return ((rte_mbuf_t *)m_plugin_info);
}else{
return ((rte_mbuf_t *)0);
}
}
public:
inline void set_rx_check(){
m_flags |= NODE_FLAGS_SAMPLE_RX_CHECK;
}
inline bool is_rx_check_enabled(){
return ((m_flags & NODE_FLAGS_SAMPLE_RX_CHECK)?true:false);
}
public:
inline void set_nat_first_state(){
btSetMaskBit16(m_flags,4,3,1);
m_type=FLOW_PKT_NAT;
}
inline bool is_nat_first_state(){
return (btGetMaskBit16(m_flags,4,3)==1?true:false) ;
}
inline void set_nat_wait_state(){
btSetMaskBit16(m_flags,4,3,2);
}
inline bool is_nat_wait_state(){
return (btGetMaskBit16(m_flags,4,3)==2?true:false) ;
}
// We saw first TCP SYN. Waiting for SYN+ACK
inline void set_nat_wait_ack_state() {
btSetMaskBit16(m_flags, 4, 3, 3);
}
inline bool is_nat_wait_ack_state(){
return (btGetMaskBit16(m_flags,4,3) == 3) ? true : false;
}
inline void set_nat_learn_state(){
m_type=FLOW_PKT; /* normal operation .. repeat might work too */
}
public:
inline uint32_t get_short_fid(void){
return (((uint32_t)m_flow_id) & NAT_FLOW_ID_MASK_TCP_ACK);
}
inline uint8_t get_thread_id(void){
return (m_thread_id);
}
inline void set_nat_tcp_seq_diff_client(uint32_t diff) {
m_nat_tcp_seq_diff_client = diff;
}
inline uint32_t get_nat_tcp_seq_diff_client() {
return m_nat_tcp_seq_diff_client;
}
inline void set_nat_tcp_seq_diff_server(uint32_t diff) {
m_nat_tcp_seq_diff_server = diff;
}
inline uint32_t get_nat_tcp_seq_diff_server() {
return m_nat_tcp_seq_diff_server;
}
inline void set_nat_ipv4_addr(uint32_t ip){
m_nat_external_ipv4 =ip;
}
inline void set_nat_ipv4_port(uint16_t port){
m_nat_external_port = port;
}
inline uint32_t get_nat_ipv4_addr(){
return ( m_nat_external_ipv4 );
}
inline uint16_t get_nat_ipv4_port(){
return ( m_nat_external_port );
}
bool is_external_is_eq_to_internal_ip(){
/* this API is used to check TRex itself */
if ( (get_nat_ipv4_addr() == m_src_ip ) &&
(get_nat_ipv4_port()==m_src_port)) {
return (true);
}else{
return (false);
}
}
} __rte_cache_aligned;
#define DEFER_CLIENTS_NUM (16)
/* this class must be in the same size of CGenNode */
struct CGenNodeDeferPort {
/* this header must be the same as CGenNode */
uint8_t m_type;
uint8_t m_pad3;
uint16_t m_pad2;
uint32_t m_cnt;
double m_time;
uint32_t m_clients[DEFER_CLIENTS_NUM];
uint16_t m_ports[DEFER_CLIENTS_NUM];
pool_index_t m_pool_idx[DEFER_CLIENTS_NUM];
uint64_t m_pad4[6];
public:
void init(void){
m_type=CGenNode::FLOW_DEFER_PORT_RELEASE;
m_cnt=0;
}
/* return true if object is full */
bool add_client(pool_index_t pool_idx, uint32_t client,
uint16_t port){
m_clients[m_cnt]=client;
m_ports[m_cnt]=port;
m_pool_idx[m_cnt] = pool_idx;
m_cnt++;
if ( m_cnt == DEFER_CLIENTS_NUM ) {
return (true);
}
return (false);
}
} __rte_cache_aligned;