Skip to content

feat(ernic): emulator frame counts as an oracle for xtcp2; egress follows the lowest metric - #347

Merged
randomizedcoder merged 26 commits into
mainfrom
feat/ernic-verification
Nov 26, 2026
Merged

randomizedcoder merged 26 commits into
mainfrom
feat/ernic-verification

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

Round 2 of rocm-ernic verification: the emulator's own frame counts become an external oracle for xtcp2, plus an egress-metric fix found along the way. Design and findings: docs/design-rocm-ernic-tests.md.

Fix

  • Egress follows the lowest metric. With two routes for the same prefix, localnet.insertRoute kept the one listed last. The kernel lists them by ascending metric (fib_find_alias, fib6_add_rt2node), so that was the highest-metric route. It now keeps the lowest metric, and on a tie the first route listed. Golden row egress_metric (netns golden-metric-a, m1 metric 100 / m2 metric 200).

Oracle

  • ernic-run-many stops every server cleanly, so each prints its Fault <site>: eligible N, fired M report. --pcap IFNAME records a fabric interface.
  • The capture runner powers the VM off before it deletes the stage, keeps the server logs in <transcript>.ernic/, and runs the new ernic-oracle.
  • ernic-oracle checks each fault report against the guest's NIC counters. It also checks each NIC's frames against the tcp_info_segs_out / segs_in xtcp2 recorded: exactly equal, no offset, on all four NICs.
  • To make that exact, two sources of extra frames were removed:
    • Go's 15 s keepalive, which probed after the poll. New -keepalive flag on tcp_client / tcp_server.
    • The fabric bridge's IGMPv3 report, which multicast snooping triggers (mcast_snooping 0). This was the old stray ionic1 frame. no_noise is strict again.
  • ionic1 can drop a SYN, and tcp_client's 1 s dial timeout then redialed before the kernel's 1 s SYN retransmit, losing the closed socket's segs_out (2 of 12 captures). The ernic clients now use -dialTimeout 30s.

Deterministic loss on one flow

  • ionic2/ionic3 (netns golden-ernic-c/d, own bridge) carry one cubic 4 MiB echo. ionic2 drops a fixed sequence (frames 501, 1002–1004, 1505–1512).
  • Rows seq_fired (exactly 12), seq_egress, seq_retrans, seq_segs_out, seq_no_rto, seq_no_noise, seq_quiescent.
  • goldenrec.DefaultFaultNetns gains golden-ernic-c/d.
  • Fixture 7_3_1 recaptured.

Other

  • DefaultUplinks ordering pinned by TestDefaultUplinksMetric and documented. It trusts the kernel's order and is evaluated once at startup (TODO in the doc).
  • Dropped from the plan: retrans_covers_drops / bytes_retrans_mss. Echo traffic means some drops are pure ACKs, which are never resent.
  • Open TODOs (doc Status):
    • netem loss_seen: once, one whole dctcp flow got through netem's 2 % loss untouched.
    • A keepalive probe in flight on an idle golden-cc-a socket made one diff mismatch (pre-existing).

Red (test commits before each fix)

--- FAIL: TestLookupEgressMetric/lowest_wins_dump_order
--- FAIL: TestLookupEgressMetric/equal_prio_first
--- FAIL: TestLookupEgressMetric/multipath_lower
ROW clean_stop positive FAIL ... reports=0
ROW pcap_unknown negative FAIL ... rc=2 err=usage: ...
ROW pcap_no_fabric negative FAIL ... rc=2 err=usage: ...
checks.ernic-oracle: error: Path 'nix/ernic/oracle.nix' does not exist
tools/tcp_client/options_test.go:57:101: c.keepalive undefined
tools/tcp_server/options_test.go:197:10: undefined: listenConfig
ROW segs_out_match positive FAIL ... rc=2 out=usage: ...
ROW bridge_no_snooping corner FAIL ... matches=0
--- FAIL: TestDiff/fault_ernic_c
--- FAIL: TestDiff/fault_ernic_d

Verification

  • go test ./...
  • nix checks: gofmt, go-vet, nix-fmt, lint-baseline, golangci ×3, redteam-lint, golden-records, test-fuzz-all, ernic-pin/nics/run-many/oracle, upstream-pins
  • Golden captures:
    • Before the SYN fix, 5: all 47 rows PASS; diff clean pairwise except the keepalive-probe TODO.
    • After it, 8 with a pcap: 7 all PASS with the oracle exact, and 1 hit the netem loss_seen TODO.
  • Fleet shape-diff: only bbr_info_bw_hi and sk_mem_info_optmem are populated on the fleet and not in the fixture; the rest is NIC identity a VM can't reproduce.

🤖 Generated with Claude Code

randomizedcoder and others added 26 commits November 25, 2026 21:02
The emulator's fault counts as an exact witness for the guest counters
and xtcp2's TCP segment counters, the egress-by-metric fix, the two
capture flakes and the uplink corner cases, each with its test table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TestLookupEgressMetric: two default routes; the kernel lists same-prefix
routes in ascending metric order and its lookup takes the first, but the
snapshot keeps the last one listed, so the egress names the highest
metric. Fails: lowest_wins_dump_order, equal_prio_first, multipath_lower.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
routeEntry keeps the route metric, and insertRoute replaces a same-prefix
entry only with a strictly lower metric. With two default routes the
egress interface was the highest-metric one (the last the kernel lists);
it is now the one the kernel uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TestDefaultUplinksMetric: kernel metric order, IPv4 before IPv6,
lines out of metric order kept as listed, equal metrics, the
no-default fallback and a NIC with both defaults. The route fixtures
take a metric. These pass on main by design: they record that
DefaultUplinks trusts the kernel's listing order, which its comment
now says, along with being evaluated once at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fake server now shuts down like rocm-ernic: TERM, a short wait,
then the fault report. clean_stop fails: run-many SIGKILLs the group
as soon as the fabric leader exits, before either report is written.
pcap_unknown and pcap_no_fabric fail: there is no --pcap yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fabric's TERM trap now waits for every server, so each finishes its
clean shutdown and prints its fault report before the caller's deadline
SIGKILLs the group. --pcap IFNAME runs tcpdump on a fabric bridge or
TAP, writing DIR/IFNAME.pcap; any other name is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The emulator's fault report (eligible, fired) against the guest's NIC
counters from the console: matches, a disagreeing drop count, a missing
report or counters line, a site with no frames, everything dropped,
other sites in the same log, journal prefixes, u64 and non-numbers.
Red: nix/ernic/oracle.nix does not exist yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parses each server's clean-shutdown fault report and the guest's
GOLDEN_ERNIC_COUNTERS console line: for an eth_tx drop fault,
eligible == tx + tx_dropped and fired == tx_dropped; for an eth_rx
drop fault, eligible == rx + fired. Counts compare exactly with bc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flag rows (off, not a duration, zero) and socket rows: the dialer's and
the listener's accepted connections have SO_KEEPALIVE on by Go's
default, set by a positive value and off for any negative one. Red:
there is no -keepalive, dialerFor or listenConfig yet.

The golden capture needs this: Go's 15 s keepalive probes on the idle
ionic connections reach the emulator after xtcp2's last poll, so its
frame counts and xtcp2's segment counts differ by 2 per connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dialer's and the listener's KeepAlive: 0 keeps Go's default (on,
15 s idle), a negative value turns it off. dialerFor and listenConfig
build them from the parsed flags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he capture

- The guest prints its final ionic counters (GOLDEN_ERNIC_COUNTERS) and
  takes both ionic links down, so nothing more reaches the emulator.
- The runner powers the VM off and waits for ernic-run-many, keeps the
  server logs next to the transcript, prints every ROW line, and runs
  ernic-oracle: ionic0's eth_tx and ionic1's eth_rx counts against the
  guest's. Its EXIT trap no longer deletes the logs before the servers
  stop.
- ERNIC_PCAP=<bridge or TAP> records that interface's frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
golden-metric-a reaches 192.0.2.80 only through two default routes, m1
at metric 100 and m2 at 200 (the higher added first). Row egress_metric
expects m1. With the localnet fix it passes (capture 1); before it, the
snapshot kept the last route listed, m2 (TestLookupEgressMetric red).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ric bridge (red)

ernic-oracle rows: the emulator's tx frames equal the senders'
tcp_info_segs_out, the frames delivered to the receiving NIC equal the
receivers' tcp_info_segs_in, and either falling short fails. Red: no
--segs-out / --segs-in yet.

ernic-run-many row bridge_no_snooping: a capture's pcap showed the
fabric bridge's one IGMPv3 report (group 224.0.0.106, all-snoopers),
flooded to both TAPs; the bridge joins that group on open when
snooping is on (net/bridge/br_device.c, br_dev_open). Red: bridges are
created with snooping on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ernic-oracle --segs-out/--segs-in: the emulator's eth_tx frames equal
  the senders' tcp_info_segs_out, and ionic1's delivered frames equal the
  receivers' tcp_info_segs_in, exactly (TSO/GSO/GRO off).
- The ernic workload clients and servers turn TCP keepalive off: Go's
  15 s default sent probes after xtcp2's last poll (2 frames per flow).
- The fabric bridge runs with mcast_snooping 0: with snooping on, the
  bridge joins 224.0.0.106 when it comes up and floods an IGMPv3 report
  to both TAPs (the stray frame on ionic1; net/bridge/br_device.c).
- The oracle check's result variable no longer shadows $out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GOLDEN_ERNIC_COUNTERS adds ionic0_segs_out and ionic1_segs_in, summed
  from the captured records.
- New row quiescent: the ionic counters are unchanged 1 s after the read.
- no_noise again requires 0 frames on ionic0 and ionic1 before the
  transfers.
- loss_seen's detail reports netem's own drop count per veth0, so a
  failure tells netem dropping nothing from TCP seeing no loss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lt rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ionic2 (golden-ernic-c, 10.0.5.15) and ionic3 (golden-ernic-d,
  10.0.5.16) on their own fabric bridge, PCI slots 0x1b and 0x1c.
- ionic2 drops eth_tx frames 501, 1002-1004 and 1505-1512 (sequence
  "0x500,1x1,0x500,1x3,0x500,1x8,0x60000"; counts are decimal).
- Rows seq_fired, seq_egress, seq_retrans, seq_segs_out, seq_no_noise,
  seq_quiescent; ernic-oracle checks ionic2's fault report and both NICs'
  frames against segs_out/segs_in.
- Both pairs' counters go on one GOLDEN_ERNIC_COUNTERS line (the oracle
  reads the last).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tures)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…etric

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A disagreement in oracle_segs_out then tells frames sent after the poll
from frames no live socket counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…resent

ionic1 drops every 64th frame, and in 2 of 12 captures that was a SYN.
tcp_client's default 1 s dial timeout closed the socket just as the
kernel's first SYN retransmit came due (TCP_TIMEOUT_INIT), and dialed
again; the closed socket's segs_out went with it, so oracle_segs_out was
1 or 2 short. The pcap showed the lone SYN (port 55522) and the redial
1 s later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idation runs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder
randomizedcoder merged commit 0ec774a into main Nov 26, 2026
1 check passed
@randomizedcoder
randomizedcoder deleted the feat/ernic-verification branch November 26, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant