feat(docs): Add Methodology
[csit.git] / docs / content / methodology / network_address_translation.md
1 ---
2 bookToc: false
3 title: "Network Address Translation"
4 weight: 7
5 ---
6
7 # Network Address Translation
8
9 ## NAT44 Prefix Bindings
10
11 NAT44 prefix bindings should be representative to target applications,
12 where a number of private IPv4 addresses from the range defined by
13 RFC1918 is mapped to a smaller set of public IPv4 addresses from the
14 public range.
15
16 Following quantities are used to describe inside to outside IP address
17 and port bindings scenarios:
18
19 - Inside-addresses, number of inside source addresses
20   (representing inside hosts).
21 - Ports-per-inside-address, number of TCP/UDP source
22   ports per inside source address.
23 - Outside-addresses, number of outside (public) source addresses
24   allocated to NAT44.
25 - Ports-per-outside-address, number of TCP/UDP source
26   ports per outside source address. The maximal number of
27   ports-per-outside-address usable for NAT is 64 512
28   (in non-reserved port range 1024-65535, RFC4787).
29 - Sharing-ratio, equal to inside-addresses divided by outside-addresses.
30
31 CSIT NAT44 tests are designed to take into account the maximum number of
32 ports (sessions) required per inside host (inside-address) and at the
33 same time to maximize the use of outside-address range by using all
34 available outside ports. With this in mind, the following scheme of
35 NAT44 sharing ratios has been devised for use in CSIT:
36
37  **ports-per-inside-address** | **sharing-ratio**
38 -----------------------------:|------------------:
39  63                           | 1024
40  126                          | 512
41  252                          | 256
42  504                          | 128
43
44 Initial CSIT NAT44 tests, including associated TG/TRex traffic profiles,
45 are based on ports-per-inside-address set to 63 and the sharing ratio of
46 1024. This approach is currently used for all NAT44 tests including
47 NAT44det (NAT44 deterministic used for Carrier Grade NAT applications)
48 and NAT44ed (Endpoint Dependent).
49
50 Private address ranges to be used in tests:
51
52 - 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
53
54   - Total of 2^16 (65 536) of usable IPv4 addresses.
55   - Used in tests for up to 65 536 inside addresses (inside hosts).
56
57 - 172.16.0.0 - 172.31.255.255  (172.16/12 prefix)
58
59   - Total of 2^20 (1 048 576) of usable IPv4 addresses.
60   - Used in tests for up to 1 048 576 inside addresses (inside hosts).
61
62 ### NAT44 Session Scale
63
64 NAT44 session scale tested is govern by the following logic:
65
66 - Number of inside-addresses(hosts) H[i] = (H[i-1] x 2^2) with H(0)=1 024,
67   i = 1,2,3, ...
68
69   - H[i] = 1 024, 4 096, 16 384, 65 536, 262 144, ...
70
71 - Number of sessions S[i] = H[i] * ports-per-inside-address
72
73   - ports-per-inside-address = 63
74
75  **i** | **hosts** | **sessions**
76 ------:|----------:|-------------:
77  0     | 1 024     | 64 512
78  1     | 4 096     | 258 048
79  2     | 16 384    | 1 032 192
80  3     | 65 536    | 4 128 768
81  4     | 262 144   | 16 515 072
82
83 ### NAT44 Deterministic
84
85 NAT44det performance tests are using TRex STL (Stateless) API and traffic
86 profiles, similar to all other stateless packet forwarding tests like
87 ip4, ip6 and l2, sending UDP packets in both directions
88 inside-to-outside and outside-to-inside.
89
90 The inside-to-outside traffic uses single destination address (20.0.0.0)
91 and port (1024).
92 The inside-to-outside traffic covers whole inside address and port range,
93 the outside-to-inside traffic covers whole outside address and port range.
94
95 NAT44det translation entries are created during the ramp-up phase,
96 followed by verification that all entries are present,
97 before proceeding to the main measurements of the test.
98 This ensures session setup does not impact the forwarding performance test.
99
100 Associated CSIT test cases use the following naming scheme to indicate
101 NAT44det scenario tested:
102
103 - ethip4udp-nat44det-h{H}-p{P}-s{S}-[mrr|ndrpdr|soak]
104
105   - {H}, number of inside hosts, H = 1024, 4096, 16384, 65536, 262144.
106   - {P}, number of ports per inside host, P = 63.
107   - {S}, number of sessions, S = 64512, 258048, 1032192, 4128768,
108     16515072.
109   - [mrr|ndrpdr|soak], MRR, NDRPDR or SOAK test.
110
111 ### NAT44 Endpoint-Dependent
112
113 In order to excercise NAT44ed ability to translate based on both
114 source and destination address and port, the inside-to-outside traffic
115 varies also destination address and port. Destination port is the same
116 as source port, destination address has the same offset as the source address,
117 but applied to different subnet (starting with 20.0.0.0).
118
119 As the mapping is not deterministic (for security reasons),
120 we cannot easily use stateless bidirectional traffic profiles.
121 Inside address and port range is fully covered,
122 but we do not know which outside-to-inside source address and port to use
123 to hit an open session.
124
125 Therefore, NAT44ed is benchmarked using following methodologies:
126
127 - Unidirectional throughput using *stateless* traffic profile.
128 - Connections-per-second (CPS) using *stateful* traffic profile.
129 - Bidirectional throughput (TPUT, see below) using *stateful* traffic profile.
130
131 Unidirectional NAT44ed throughput tests are using TRex STL (Stateless)
132 APIs and traffic profiles, but with packets sent only in
133 inside-to-outside direction.
134 Similarly to NAT44det, NAT44ed unidirectional throughput tests include
135 a ramp-up phase to establish and verify the presence of required NAT44ed
136 binding entries. As the sessions have finite duration, the test code
137 keeps inserting ramp-up trials during the search, if it detects a risk
138 of sessions timing out. Any zero loss trial visits all sessions,
139 so it acts also as a ramp-up.
140
141 Stateful NAT44ed tests are using TRex ASTF (Advanced Stateful) APIs and
142 traffic profiles, with packets sent in both directions. Tests are run
143 with both UDP and TCP sessions.
144 As NAT44ed CPS (connections-per-second) stateful tests
145 measure (also) session opening performance,
146 they use state reset instead of ramp-up trial.
147 NAT44ed TPUT (bidirectional throughput) tests prepend ramp-up trials
148 as in the unidirectional tests,
149 so the test results describe performance without translation entry
150 creation overhead.
151
152 Associated CSIT test cases use the following naming scheme to indicate
153 NAT44det case tested:
154
155 - Stateless: ethip4udp-nat44ed-h{H}-p{P}-s{S}-udir-[mrr|ndrpdr|soak]
156
157   - {H}, number of inside hosts, H = 1024, 4096, 16384, 65536, 262144.
158   - {P}, number of ports per inside host, P = 63.
159   - {S}, number of sessions, S = 64512, 258048, 1032192, 4128768,
160     16515072.
161   - udir-[mrr|ndrpdr|soak], unidirectional stateless tests MRR, NDRPDR
162     or SOAK.
163
164 - Stateful: ethip4[udp|tcp]-nat44ed-h{H}-p{P}-s{S}-[cps|tput]-[mrr|ndrpdr|soak]
165
166   - [udp|tcp], UDP or TCP sessions
167   - {H}, number of inside hosts, H = 1024, 4096, 16384, 65536, 262144.
168   - {P}, number of ports per inside host, P = 63.
169   - {S}, number of sessions, S = 64512, 258048, 1032192, 4128768,
170     16515072.
171   - [cps|tput], connections-per-second session establishment rate or
172     packets-per-second average rate, or packets-per-second rate
173     without session establishment.
174   - [mrr|ndrpdr|soak], bidirectional stateful tests MRR, NDRPDR, or SOAK.
175
176 ## Stateful traffic profiles
177
178 There are several important details which distinguish ASTF profiles
179 from stateless profiles.
180
181 ### General considerations
182
183 #### Protocols
184
185 ASTF profiles are limited to either UDP or TCP protocol.
186
187 #### Programs
188
189 Each template in the profile defines two "programs", one for the client side
190 and one for the server side.
191
192 Each program specifies when that side has to wait until enough data is received
193 (counted in packets for UDP and in bytes for TCP)
194 and when to send additional data. Together, the two programs
195 define a single transaction. Due to packet loss, transaction may take longer,
196 use more packets (retransmission) or never finish in its entirety.
197
198 #### Instances
199
200 A client instance is created according to TPS parameter for the trial,
201 and sends the first packet of the transaction (in some cases more packets).
202 Each client instance uses a different source address (see sequencing below)
203 and some source port. The destination address also comes from a range,
204 but destination port has to be constant for a given program.
205
206 TRex uses an opaque way to chose source ports, but as session counting shows,
207 next client with the same source address uses a different source port.
208
209 Server instance is created when the first packet arrives to the server side.
210 Source address and port of the first packet are used as destination address
211 and port for the server responses. This is the ability we need
212 when outside surface is not predictable.
213
214 When a program reaches its end, the instance is deleted.
215 This creates possible issues with server instances. If the server instance
216 does not read all the data client has sent, late data packets
217 can cause a second copy of server instance to be created,
218 which breaks assumptions on how many packet a transaction should have.
219
220 The need for server instances to read all the data reduces the overall
221 bandwidth TRex is able to create in ASTF mode.
222
223 Note that client instances are not created on packets,
224 so it is safe to end client program without reading all server data
225 (unless the definition of transaction success requires that).
226
227 #### Sequencing
228
229 ASTF profiles offer two modes for choosing source and destination IP addresses
230 for client programs: seqential and pseudorandom.
231 In current tests we are using sequential addressing only (if destination
232 address varies at all).
233
234 For client destination UDP/TCP port, we use a single constant value.
235 (TRex can support multiple program pairs in the same traffic profile,
236 distinguished by the port number.)
237
238 #### Transaction overlap
239
240 If a transaction takes longer to finish, compared to period implied by TPS,
241 TRex will have multiple client or server instances active at a time.
242
243 During calibration testing we have found this increases CPU utilization,
244 and for high TPS it can lead to TRex's Rx or Tx buffers becoming full.
245 This generally leads to duration stretching, and/or packet loss on TRex.
246
247 Currently used transactions were chosen to be short, so risk of bad behavior
248 is decreased. But in MRR tests, where load is computed based on NIC ability,
249 not TRex ability, anomalous behavior is still possible
250 (e.g. MRR values being way lower than NDR).
251
252 #### Delays
253
254 TRex supports adding constant delays to ASTF programs.
255 This can be useful, for example if we want to separate connection establishment
256 from data transfer.
257
258 But as TRex tracks delayed instances as active, this still results
259 in higher CPU utilization and reduced performance issues
260 (as other overlaping transactions). So the current tests do not use any delays.
261
262 #### Keepalives
263
264 Both UDP and TCP protocol implementations in TRex programs support keepalive
265 duration. That means there is a configurable period of keepalive time,
266 and TRex sends keepalive packets automatically (outside the program)
267 for the time the program is active (started, not ended yet)
268 but not sending any packets.
269
270 For TCP this is generally not a big deal, as the other side usually
271 retransmits faster. But for UDP it means a packet loss may leave
272 the receiving program running.
273
274 In order to avoid keepalive packets, keepalive value is set to a high number.
275 Here, "high number" means that even at maximum scale and minimum TPS,
276 there are still no keepalive packets sent within the corresponding
277 (computed) trial duration. This number is kept the same also for
278 smaller scale traffic profiles, to simplify maintenance.
279
280 #### Transaction success
281
282 The transaction is considered successful at Layer-7 (L7) level
283 when both program instances close. At this point, various L7 counters
284 (unofficial name) are updated on TRex.
285
286 We found that proper close and L7 counter update can be CPU intensive,
287 whereas lower-level counters (ipackets, opackets) called L2 counters
288 can keep up with higher loads.
289
290 For some tests, we do not need to confirm the whole transaction was successful.
291 CPS (connections per second) tests are a typical example.
292 We care only for NAT44ed creating a session (needs one packet
293 in inside-to-outside direction per session) and being able to use it
294 (needs one packet in outside-to-inside direction).
295
296 Similarly in TPUT tests (packet throuput, counting both control
297 and data packets), we care about NAT44ed ability to forward packets,
298 we do not care whether aplications (TRex) can fully process them at that rate.
299
300 Therefore each type of tests has its own formula (usually just one counter
301 already provided by TRex) to count "successful enough" transactions
302 and attempted transactions. Currently, all tests relying on L7 counters
303 use size-limited profiles, so they know what the count of attempted
304 transactions should be, but due to duration stretching
305 TRex might have been unable to send that many packets.
306 For search purposes, unattempted transactions are treated the same
307 as attempted but failed transactions.
308
309 Sometimes even the number of transactions as tracked by search algorithm
310 does not match the transactions as defined by ASTF programs.
311 See TCP TPUT profile below.
312
313 ### UDP CPS
314
315 This profile uses a minimalistic transaction to verify NAT44ed session has been
316 created and it allows outside-to-inside traffic.
317
318 Client instance sends one packet and ends.
319 Server instance sends one packet upon creation and ends.
320
321 In principle, packet size is configurable,
322 but currently used tests apply only one value (100 bytes frame).
323
324 Transaction counts as attempted when opackets counter increases on client side.
325 Transaction counts as successful when ipackets counter increases on client side.
326
327 ### TCP CPS
328
329 This profile uses a minimalistic transaction to verify NAT44ed session has been
330 created and it allows outside-to-inside traffic.
331
332 Client initiates TCP connection. Client waits until connection is confirmed
333 (by reading zero data bytes). Client ends.
334 Server accepts the connection. Server waits for indirect confirmation
335 from client (by waiting for client to initiate close). Server ends.
336
337 Without packet loss, the whole transaction takes 7 packets to finish
338 (4 and 3 per direction).
339 From NAT44ed point of view, only the first two are needed to verify
340 the session got created.
341
342 Packet size is not configurable, but currently used tests report
343 frame size as 64 bytes.
344
345 Transaction counts as attempted when tcps_connattempt counter increases
346 on client side.
347 Transaction counts as successful when tcps_connects counter increases
348 on client side.
349
350 ### UDP TPUT
351
352 This profile uses a small transaction of "request-response" type,
353 with several packets simulating data payload.
354
355 Client sends 5 packets and closes immediately.
356 Server reads all 5 packets (needed to avoid late packets creating new
357 server instances), then sends 5 packets and closes.
358 The value 5 was chosen to mirror what TCP TPUT (see below) choses.
359
360 Packet size is configurable, currently we have tests for 100,
361 1518 and 9000 bytes frame (to match size of TCP TPUT data frames, see below).
362
363 As this is a packet oriented test, we do not track the whole
364 10 packet transaction. Similarly to stateless tests, we treat each packet
365 as a "transaction" for search algorthm packet loss ratio purposes.
366 Therefore a "transaction" is attempted when opacket counter on client
367 or server side is increased. Transaction is successful if ipacket counter
368 on client or server side is increased.
369
370 If one of 5 client packets is lost, server instance will get stuck
371 in the reading phase. This probably decreases TRex performance,
372 but it leads to more stable results then alternatives.
373
374 ### TCP TPUT
375
376 This profile uses a small transaction of "request-response" type,
377 with some data amount to be transferred both ways.
378
379 In CSIT release 22.06, TRex behavior changed, so we needed to edit
380 the traffic profile. Let us describe the pre-22.06 profile first.
381
382 Client connects, sends 5 data packets worth of data,
383 receives 5 data packets worth of data and closes its side of the connection.
384 Server accepts connection, reads 5 data packets worth of data,
385 sends 5 data packets worth of data and closes its side of the connection.
386 As usual in TCP, sending side waits for ACK from the receiving side
387 before proceeding with next step of its program.
388
389 Server read is needed to avoid premature close and second server instance.
390 Client read is not stricly needed, but ACKs allow TRex to close
391 the server instance quickly, thus saving CPU and improving performance.
392
393 The number 5 of data packets was chosen so TRex is able to send them
394 in a single burst, even with 9000 byte frame size (TRex has a hard limit
395 on initial window size).
396 That leads to 16 packets (9 of them in c2s direction) to be exchanged
397 if no loss occurs.
398 The size of data packets is controlled by the traffic profile setting
399 the appropriate maximum segment size. Due to TRex restrictions,
400 the minimal size for IPv4 data frame achievable by this method is 70 bytes,
401 which is more than our usual minimum of 64 bytes.
402 For that reason, the data frame sizes available for testing are 100 bytes
403 (that allows room for eventually adding IPv6 ASTF tests),
404 1518 bytes and 9000 bytes. There is no control over control packet sizes.
405
406 Exactly as in UDP TPUT, ipackets and opackets counters are used for counting
407 "transactions" (in fact packets).
408
409 If packet loss occurs, there can be large transaction overlap, even if most
410 ASTF programs finish eventually. This can lead to big duration stretching
411 and somehow uneven rate of packets sent. This makes it hard to interpret
412 MRR results (frequently MRR is below NDR for this reason),
413 but NDR and PDR results tend to be stable enough.
414
415 In 22.06, the "ACK from the receiving side" behavior changed,
416 the receiving side started sending ACK sometimes
417 also before receiving the full set of 5 data packets.
418 If the previous profile is understood as a "single challenge, single response"
419 where challenge (and also response) is sent as a burst of 5 data packets,
420 the new profile uses "bursts" of 1 packet instead, but issues
421 the challenge-response part 5 times sequentially
422 (waiting for receiving the response before sending next challenge).
423 This new profile happens to have the same overall packet count
424 (when no re-transmissions are needed).
425 Although it is possibly more taxing for TRex CPU,
426 the results are comparable to the old traffic profile.
427
428 ## Ip4base tests
429
430 Contrary to stateless traffic profiles, we do not have a simple limit
431 that would guarantee TRex is able to send traffic at specified load.
432 For that reason, we have added tests where "nat44ed" is replaced by "ip4base".
433 Instead of NAT44ed processing, the tests set minimalistic IPv4 routes,
434 so that packets are forwarded in both inside-to-outside and outside-to-inside
435 directions.
436
437 The packets arrive to server end of TRex with different source address&port
438 than in NAT44ed tests (no translation to outside values is done with ip4base),
439 but those are not specified in the stateful traffic profiles.
440 The server end (as always) uses the received address&port as destination
441 for outside-to-inside traffic. Therefore the same stateful traffic profile
442 works for both NAT44ed and ip4base test (of the same scale).
443
444 The NAT44ed results are displayed together with corresponding ip4base results.
445 If they are similar, TRex is probably the bottleneck.
446 If NAT44ed result is visibly smaller, it describes the real VPP performance.