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