Commit 7ddd0b8
committed
feat(nat): Improve target prefix lookup for stateless NAT mapping
The idea behind the stateless NAT lookup is that, for a given IP and
port, we find the matching covering prefix (and associated port range)
in a LPM trie, and get the list of corresponding target ranges from the
LPM value. Then we retrieve the offset of the IP and port within the
prefix (LPM key), and look for the corresponding IP and port within the
target prefixes (LPM value).
To find the IP and port at the right offset, we need to iterate over all
target prefixes in the list and to compare the accumulated size with the
offset. This is not efficient; instead, we can use another data
structure to perform a faster lookup.
To that end, replace the list of prefixes with a DisjointRangesBTreeMap
that associates a target prefix to each portion of the original prefix.
Suggested-by: Manish Vachharajani <[email protected]>
Signed-off-by: Quentin Monnet <[email protected]>1 parent 532d480 commit 7ddd0b8
File tree
3 files changed
+347
-88
lines changed- lpm/src/prefix
- nat/src/stateless/setup
3 files changed
+347
-88
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
72 | 84 | | |
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
78 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
184 | 190 | | |
185 | 191 | | |
186 | 192 | | |
| |||
221 | 227 | | |
222 | 228 | | |
223 | 229 | | |
224 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
225 | 238 | | |
226 | 239 | | |
227 | 240 | | |
228 | 241 | | |
229 | 242 | | |
230 | | - | |
231 | | - | |
| 243 | + | |
| 244 | + | |
232 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
233 | 256 | | |
234 | 257 | | |
235 | 258 | | |
| |||
390 | 413 | | |
391 | 414 | | |
392 | 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 | + | |
393 | 460 | | |
394 | 461 | | |
395 | 462 | | |
| |||
0 commit comments