feat(docs): Fix images and ToC
[csit.git] / docs / content / methodology / trex_traffic_generator.md
1 ---
2 title: "TRex Traffic Generator"
3 weight: 5
4 ---
5
6 # TRex Traffic Generator
7
8 ## Usage
9
10 [TRex traffic generator](https://trex-tgn.cisco.com) is used for majority of
11 CSIT performance tests. TRex is used in multiple types of performance tests,
12 see [Data Plane Throughtput]({{< ref "data_plane_throughput/data_plane_throughput/#Data Plane Throughtput" >}})
13 for more detail.
14
15 ## Traffic modes
16
17 TRex is primarily used in two (mutually incompatible) modes.
18
19 ### Stateless mode
20
21 Sometimes abbreviated as STL.
22 A mode with high performance, which is unable to react to incoming traffic.
23 We use this mode whenever it is possible.
24 Typical test where this mode is not applicable is NAT44ED,
25 as DUT does not assign deterministic outside address+port combinations,
26 so we are unable to create traffic that does not lose packets
27 in out2in direction.
28
29 Measurement results are based on simple L2 counters
30 (opackets, ipackets) for each traffic direction.
31
32 ### Stateful mode
33
34 A mode capable of reacting to incoming traffic.
35 Contrary to the stateless mode, only UDP and TCP is supported
36 (carried over IPv4 or IPv6 packets).
37 Performance is limited, as TRex needs to do more CPU processing.
38 TRex suports two subtypes of stateful traffic,
39 CSIT uses ASTF (Advanced STateFul mode).
40
41 This mode is suitable for NAT44ED tests, as clients send packets from inside,
42 and servers react to it, so they see the outside address and port to respond to.
43 Also, they do not send traffic before NAT44ED has created the corresponding
44 translation entry.
45
46 When possible, L2 counters (opackets, ipackets) are used.
47 Some tests need L7 counters, which track protocol state (e.g. TCP),
48 but those values are less than reliable on high loads.
49
50 ## Traffic Continuity
51
52 Generated traffic is either continuous, or limited (by number of transactions).
53 Both modes support both continuities in principle.
54
55 ### Continuous traffic
56
57 Traffic is started without any data size goal.
58 Traffic is ended based on time duration, as hinted by search algorithm.
59 This is useful when DUT behavior does not depend on the traffic duration.
60 The default for stateless mode.
61
62 ### Limited traffic
63
64 Traffic has defined data size goal (given as number of transactions),
65 duration is computed based on this goal.
66 Traffic is ended when the size goal is reached,
67 or when the computed duration is reached.
68 This is useful when DUT behavior depends on traffic size,
69 e.g. target number of NAT translation entries, each to be hit exactly once
70 per direction.
71 This is used mainly for stateful mode.
72
73 ## Traffic synchronicity
74
75 Traffic can be generated synchronously (test waits for duration)
76 or asynchronously (test operates during traffic and stops traffic explicitly).
77
78 ### Synchronous traffic
79
80 Trial measurement is driven by given (or precomputed) duration,
81 no activity from test driver during the traffic.
82 Used for most trials.
83
84 ### Asynchronous traffic
85
86 Traffic is started, but then the test driver is free to perform
87 other actions, before stopping the traffic explicitly.
88 This is used mainly by reconf tests, but also by some trials
89 used for runtime telemetry.
90
91 ## Trafic profiles
92
93 TRex supports several ways to define the traffic.
94 CSIT uses small Python modules based on Scapy as definitions.
95 Details of traffic profiles depend on modes (STL or ASTF),
96 but some are common for both modes.
97
98 Search algorithms are intentionally unaware of the traffic mode used,
99 so CSIT defines some terms to use instead of mode-specific TRex terms.
100
101 ### Transactions
102
103 TRex traffic profile defines a small number of behaviors,
104 in CSIT called transaction templates. Traffic profiles also instruct
105 TRex how to create a large number of transactions based on the templates.
106
107 Continuous traffic loops over the generated transactions.
108 Limited traffic usually executes each transaction once
109 (typically as constant number of loops over source addresses,
110 each loop with different source ports).
111
112 Currently, ASTF profiles define one transaction template each.
113 Number of packets expected per one transaction varies based on profile details,
114 as does the criterion for when a transaction is considered successful.
115
116 Stateless transactions are just one packet (sent from one TG port,
117 successful if received on the other TG port).
118 Thus unidirectional stateless profiles define one transaction template,
119 bidirectional stateless profiles define two transaction templates.
120
121 ### TPS multiplier
122
123 TRex aims to open transaction specified by the profile at a steady rate.
124 While TRex allows the transaction template to define its intended "cps" value,
125 CSIT does not specify it, so the default value of 1 is applied,
126 meaning TRex will open one transaction per second (and transaction template)
127 by default. But CSIT invocation uses "multiplier" (mult) argument
128 when starting the traffic, that multiplies the cps value,
129 meaning it acts as TPS (transactions per second) input.
130
131 With a slight abuse of nomenclature, bidirectional stateless tests
132 set "packets per transaction" value to 2, just to keep the TPS semantics
133 as a unidirectional input value.
134
135 ### Duration stretching
136
137 TRex can be IO-bound, CPU-bound, or have any other reason
138 why it is not able to generate the traffic at the requested TPS.
139 Some conditions are detected, leading to TRex failure,
140 for example when the bandwidth does not fit into the line capacity.
141 But many reasons are not detected.
142
143 Unfortunately, TRex frequently reacts by not honoring the duration
144 in synchronous mode, taking longer to send the traffic,
145 leading to lower then requested load offered to DUT.
146 This usualy breaks assumptions used in search algorithms,
147 so it has to be avoided.
148
149 For stateless traffic, the behavior is quite deterministic,
150 so the workaround is to apply a fictional TPS limit (max_rate)
151 to search algorithms, usually depending only on the NIC used.
152
153 For stateful traffic the behavior is not deterministic enough,
154 for example the limit for TCP traffic depends on DUT packet loss.
155 In CSIT we decided to use logic similar to asynchronous traffic.
156 The traffic driver sleeps for a time, then stops the traffic explicitly.
157 The library that parses counters into measurement results
158 than usually treats unsent packets/transactions as lost/failed.
159
160 We have added a IP4base tests for every NAT44ED test,
161 so that users can compare results.
162 If the results are very similar, it is probable TRex was the bottleneck.
163
164 ### Startup delay
165
166 By investigating TRex behavior, it was found that TRex does not start
167 the traffic in ASTF mode immediately. There is a delay of zero traffic,
168 after which the traffic rate ramps up to the defined TPS value.
169
170 It is possible to poll for counters during the traffic
171 (fist nonzero means traffic has started),
172 but that was found to influence the NDR results.
173
174 Thus "sleep and stop" stategy is used, which needs a correction
175 to the computed duration so traffic is stopped after the intended
176 duration of real traffic. Luckily, it turns out this correction
177 is not dependend on traffic profile nor CPU used by TRex,
178 so a fixed constant (0.112 seconds) works well.
179 Unfortunately, the constant may depend on TRex version,
180 or execution environment (e.g. TRex in AWS).
181
182 The result computations need a precise enough duration of the real traffic,
183 luckily server side of TRex has precise enough counter for that.
184
185 It is unknown whether stateless traffic profiles also exhibit a startup delay.
186 Unfortunately, stateless mode does not have similarly precise duration counter,
187 so some results (mostly MRR) are affected by less precise duration measurement
188 in Python part of CSIT code.
189
190 ## Measuring Latency
191
192 If measurement of latency is requested, two more packet streams are
193 created (one for each direction) with TRex flow_stats parameter set to
194 STLFlowLatencyStats. In that case, returned statistics will also include
195 min/avg/max latency values and encoded HDRHistogram data.