Network quality harnesses #
Ordinary cargo test runs the socket-delay/outage scenarios in
tests/network_quality.rs. They forward real TCP relay connections and check exact
stream delivery through delay and disconnection. They do not model UDP loss or NAT.
The opt-in Linux tests change networking only inside fresh user/network namespaces.
The NAT harness also isolates mounts before creating named network namespaces or
changing firewall rules. They require Linux user namespaces, network/mount namespace
creation, ip, tc (netem test), and iptables with conntrack/NAT support (NAT test).
They require no change to host firewall rules. Container restrictions may prevent
these capabilities even when the tools are installed.
Run the real UDP-loss test:
cargo test --test network_quality netem_udp_loss_preserves_streams -- --ignored --nocapture
It configures loopback with 20 ms delay and seeded 2% packet loss (seed 42), then
transfers 512 KB through an ICE/DTLS/SCTP connection. No relay is configured.
Run the NAT matrix:
cargo test --test nat_quality nat_topology_matrix -- --ignored --nocapture
An explicitly requested test fails with an availability message if namespace creation is denied; it does not count unavailable capabilities as a passing test. NAT failures retain service/receiver logs in the printed temporary artifact path. Successful runs remove their temporary files.
NAT topologies and assertions #
A WAN bridge connects a public WebSocket relay and two independent STUN binding server ports to the peer networks. Both endpoints start on the WebSocket relay. The same unidirectional application stream starts before path selection and completes with a byte-for-byte 512 KB payload and an application receipt.
| Scenario | Network behavior | Expected result |
|---|---|---|
| Host to host | Two publicly reachable peers on the WAN | Relay followed by direct ICE |
| Endpoint independent | Separate routers with static 1:1 SNAT/DNAT and unrestricted inbound filtering | Relay followed by direct ICE |
| Symmetric | Separate routers randomize source ports per destination tuple and allow only conntrack-established inbound traffic | Keep a usable relay path while direct attempts fail |
Before establishing Hori connections, each peer probes both STUN destinations
using the same UDP socket. The harness checks equal external mappings for host
and endpoint-independent cases and different mappings for symmetric NAT. This
checks the configured mapping behavior rather than relying solely on a topology
label. The symmetric model uses Linux SNAT --random-fully with disjoint source-port
ranges for each STUN destination and for peer traffic, so the mapping assertion
does not depend on a random collision. It models endpoint dependent mapping and
filtering, rather than a specific commercial router.
The endpoint-independent case is static full-cone behavior. It does not cover port-restricted cone filtering or mapping expiration. This initial matrix also does not cover IPv6 NAT, carrier-grade double NAT, simultaneous uplink switches, or loss-induced stream head-of-line comparisons.
Provenance and validation limits #
Scenarios follow the local iroh sources in
reference/iroh/iroh/tests/patchbay/nat.rs, relay.rs, degrade.rs, and
switch-uplink.rs. They reimplement scenarios for WebRTC/ICE and Hori's relay;
iroh's QUIC-specific assertions are not copied unchanged. STUN responses use the
RFC 5389 IPv4 XOR-MAPPED-ADDRESS binding format and run only in the test topology.
The development container denies user/network namespace creation. These tests compile, their shell syntax is checked, and their explicit unavailable-environment failure path is tested. The NAT topology and netem packet-loss scenarios still need execution on a capable Linux machine before being treated as validated.