Skip to content

bpf: fix flaky nat4_port_allocation_tcp/udp tests#45112

Draft
vipul-21 wants to merge 1 commit intocilium:mainfrom
vipul-21:singhvipul/bpf-test
Draft

bpf: fix flaky nat4_port_allocation_tcp/udp tests#45112
vipul-21 wants to merge 1 commit intocilium:mainfrom
vipul-21:singhvipul/bpf-test

Conversation

@vipul-21
Copy link
Copy Markdown
Contributor

@vipul-21 vipul-21 commented Apr 1, 2026

The SNAT port allocation stress tests were flaky due to two issues:

  1. The test used get_prandom_u32() for destination address selection in the callback, adding unnecessary run-to-run variance unrelated to the algorithm under test. Replace it with a seeded xorshift32 PRNG that produces a deterministic but non-trivial distribution, while the algorithm's own get_prandom_u32() for port selection on collision remains the sole source of randomness being tested.

  2. The 50% checkpoint assertion (retries_50percent[SNAT_COLLISION_RETRIES] < 15) was too tight. The algorithm's internal random port picks can occasionally produce slightly more early collisions than expected. Relax the threshold from 15 to 25 (still negligible: 0.019% of 131K iterations at the 50% mark).

Fixes: #42599

bpf: fix flaky nat4_port_allocation_tcp/udp tests

The SNAT port allocation stress tests were flaky due to two issues:

1. The test used get_prandom_u32() for destination address selection in
   the callback, adding unnecessary run-to-run variance unrelated to the
   algorithm under test. Replace it with a seeded xorshift32 PRNG that
   produces a deterministic but non-trivial distribution, while the
   algorithm's own get_prandom_u32() for port selection on collision
   remains the sole source of randomness being tested.

2. The 50% checkpoint assertion (retries_50percent[SNAT_COLLISION_RETRIES]
   < 15) was too tight. The algorithm's internal random port picks can
   occasionally produce slightly more early collisions than expected.
   Relax the threshold from 15 to 25 (still negligible: 0.019% of 131K
   iterations at the 50% mark).

Fixes: cilium#42599

Signed-off-by: Vipul Singh <singhvipul@microsoft.com>
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dont-merge/needs-release-note-label The author needs to describe the release impact of these changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: BPF Checks --TestBPF/bpf_nat_tests.o/nat4_port_allocation_tcp

1 participant