Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

### Fixes

- **Golden records: netem loses every bulk flow's segments.** TCP built multi-segment (GSO) packets on the bulk veths even with ethtool tso/gso off, and netem drew loss once per packet, so one flow in about 20 captures saw no loss and failed `loss_seen`. The bulk veths now use `gso_max_segs 1`. A failed capture keeps its records in `<transcript>.failed/`, and new rows check per-flow netem drops (`netem_per_flow`, `bulk_tap_complete`) ([design](docs/design-rocm-ernic-tests.md#round-4-loss_seen-found-a-failed-capture-keeps-its-records)).
- **Egress follows the lowest route metric.** With two routes for the same prefix, `enrich_socket_dest_egress_ifname` named the one listed last, which the kernel lists by ascending metric, so it was the highest-metric route. That is the one the kernel uses last. The lowest metric now wins, and on a tie the first route listed, as in the kernel's lookup.
- **Congestion names are matched whole.** `inet_diag_cong_enum` came from the first three letters, so `dctcp-reno` (DCTCP's fallback when ECN isn't negotiated) read as DCTCP and any name starting `cub` as CUBIC. Names now match exactly: `dctcp-reno` and look-alikes are UNSPECIFIED with their name kept, `bbr1` is BBR1, and `prague` gets its enum. A 2-letter name (`nv`, `lp`) without NLA padding is accepted (the minimum was 4 bytes). The in-tree names are now constants, so decoding them no longer allocates.
- **`nsid` 0 is no longer ambiguous.** The kernel's first namespace id is 0, which read the same as "no id" and as `-populateNsid` off; Docker gives its containers ids 0, 1, 2… in creation order, so one container per host had the ambiguous 0. New column `nsid_assigned` (proto tag 33, a free slot, so no record epoch bump) is true exactly when `nsid` holds an assigned id: filter on it, not on `nsid != 0`. Existing ClickHouse deployments add it with `build/containers/clickhouse/sql/migrations/nsid-assigned.sql`; rows from older daemons read false. The CSV/TSV default columns gain it after `nsid`, shifting the later columns by one. Golden records compare `nsid` again, numbered like the other ids.
Expand Down
20 changes: 19 additions & 1 deletion docs/design-rocm-ernic-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Any column that comes out exactly equal also gets a goldenrec unit row (`pkg/gol

# Round 3: close the two golden flakes, strict diff on the sequence flow

Status: done (2026-11-27). Round 2 left three TODOs (Status, above). This round closes the keepalive flake, adds exact netem rows that tell an xtcp2 bug from a flow that saw no loss, fixes a dctcp ECN fallback the hunt found, and makes the sequence flow exact. The netem `loss_seen` flake is not closed: it recurred once in 20 captures with the kernel agreeing, cause unknown (Round 3 status, TODO). The uplink TODO stays open.
Status: done (2026-11-27). Round 2 left three TODOs (Status, above). This round closes the keepalive flake, adds exact netem rows that tell an xtcp2 bug from a flow that saw no loss, fixes a dctcp ECN fallback the hunt found, and makes the sequence flow exact. The netem `loss_seen` flake is not closed: it recurred once in 20 captures with the kernel agreeing, cause unknown (Round 3 status, TODO; found and fixed in round 4). The uplink TODO stays open (fixed in round 4).

## Phase 0: kernel findings

Expand Down Expand Up @@ -231,3 +231,21 @@ Tests (table-driven, red first): tcp_server discard (discard reads all, echo def
- **Captures:** five. In four, all 52 guest rows passed and the oracle was exact on all four NICs, at host load 7 to 24. The first failed only `netem_kernel_agrees`, on formatting (the query helper strips spaces, so the lists now use commas); its values agreed. A sixth timed out at host load 61 (`GOLDEN_DONE not seen within 600 s`) and is not counted. The fixture is recaptured. Then 15 more for the netem hunt, at host load 5 to 19: 14 passed all 52 rows, capture 14 failed `loss_seen` only (above), and `xtcp2-golden diff` against the fixture was clean for 13 of the 14 that kept records, capture 19 being the dctcp fallback. One more with the ECN fix and the new detail passed all 53 rows.
- **Uplinks:** unchanged, still TODO (round 2 Status).
- **Checks:** the list passes but for three failures this branch does not cause. `deadnix` (unused bindings in nix/ernic/oracle.nix and run-many.nix) and `go-sec` (tools/ipfeed-fixture) fail on main 7e1e4c3f9 too (TODO). `test-go-race` failed once in `TestOnDemandRace/ttl-edge` (pkg/linkmonitor) at host load near 120; it passed three of three with `-race` afterwards.

# Round 4: `loss_seen` found, a failed capture keeps its records

Status: done (2026-11-27). The uplink TODO is fixed separately (uplinks follow a route change on `locality_refresh_interval`).

## Round 4 status

- **A failed capture keeps its records.** When a row fails, the guest still writes the manifest, adds a `FAILED` file naming the rows, prints `GOLDEN_DUMPING` and emits the dump, then fails. The runner decodes it into `<transcript>.failed/`, never into the output dir, so a failed run can't overwrite the fixture. Forced row failure: exit 2, with `FAILED`, the manifest, `records.jsonl`/`parquet` and `uname` in `.failed/`, and no output dir. Forced shell-trap error: exit 2, no `.failed/`, as before.
- **Per-flow netem evidence.** tcpdump on golden-bulk-a's veth0 sees what left netem, so per client port, netem drops = `segs_out` - packets tapped. New rows `bulk_tap_complete` (tcpdump dropped none) and `netem_per_flow` (netem dropped from every bulk flow both ways). On a `loss_seen` failure, `bulk-a.pcap.gz` and `netem-diag.txt` (`tc -s qdisc`, `ip -s link`, `ethtool -k`, `ss -tienmO`, `nstat`) go out with the records.
- **`loss_seen` root cause: netem drew loss per skb, not per segment.** Turning tso/gso off on the veth with ethtool doesn't stop TCP from building GSO skbs: `sk_setup_caps` always adds `NETIF_F_GSO`, and with it the software GSO features (net/core/sock.c:2680-2684). netem segments a GSO skb only to corrupt it (net/sched/sch_netem.c:519). A loss draw drops the whole skb and counts one drop (net/sched/sch_netem.c:490-493), while the byte/packet stats count segments (`qdisc_pkt_segs`, include/net/sch_generic.h:977). A flow sending large skbs got few loss draws, so the chance it saw none was 0.98 to the power of its skb count, not of its segment count. The old-code hunt showed it directly: one flow with 223 drops one way and 8 the other. The fix is `ip link set veth0 gso_max_segs 1` on the bulk veths (`IFLA_GSO_MAX_SEGS`, net/core/rtnetlink.c:3332-3336); `tcp_tso_segs` clamps to `sk_gso_max_segs` (net/ipv4/tcp_output.c:2350), so every skb is one segment.
- **The round 3 baseline gap was the same cause.** netem's sent + dropped against the namespace's OutSegs + RetransSegs was about 120 apart; with one segment per skb it is about 12 (16733 vs 16722, 16432 vs 16419).
- **ECN fallback in the root netns (fixed).** The ernic dctcp client runs in the root netns, not golden-bulk-a, and in one old-code capture a dropped SYN turned it into dctcp-reno. `tcp_ecn_fallback` is per netns, so the workload now sets it to 0 there too.
- **`seq_retrans` and DSACK (fixed).** One capture under load had `total_retrans` 13 for 12 drops, with `tcpi_dsack_dups` 1: a spurious retransmit (a TLP) the receiver reported as a duplicate. The row now checks `total_retrans - dsack_dups` == 12.
- **Hunt, old code (17 captures, stopped once the cause was found):** no `loss_seen` failure. One `seq_retrans` (DSACK, above), one ernic dctcp-reno (above), one listener-drop diff (below), and three that timed out at host load 57 to 81 (environmental, not counted).
- **Hunt, with the fix (20 captures, host load 9 to 27):** all 55 rows passed in all 20. Every flow saw netem drops both ways, 60 to 128 per flow, about 2 % of its segments (before: as few as 8). `xtcp2-golden diff` against the fixture was clean in 19; the 20th is the listener flake below.
- **golden-opts-b IPv6 listener drops (TODO):** `sk_mem_info_drops` on the IPv6 port-4000 listener is 1 in the fixture but 0 in some captures, and once the client showed a `total_rto` instead. Seen twice: once in each hunt.
- **Checks:** `deadnix` (nix/ernic/oracle.nix, run-many.nix) and `go-sec` (tools/ipfeed-fixture) still fail on main 14d7e1c38 too (TODO, not this branch).

42 changes: 34 additions & 8 deletions nix/microvms/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,38 @@ rec {
fi
wait "$vm_pid" 2>/dev/null || true
}
# extract_dump DIR: unpack the guest's XTCP2_GOLDEN_DUMP block into
# DIR. Strip journal+console's `[TIME] ident[PID]: ` prefix before
# decoding, as mkNlmonCaptureRunner does.
extract_dump() {
mkdir -p "$1"
awk '/XTCP2_GOLDEN_DUMP_START/{flag=1;next} /XTCP2_GOLDEN_DUMP_END/{flag=0} flag' "$LOG" \
| sed -E 's/^\[[^]]*\] [A-Za-z0-9_.@-]+\[[0-9]+\]: //' \
| tr -d '\r\n ' \
| base64 -d 2>/dev/null \
| gzip -dc 2>/dev/null \
| tar x -C "$1" 2>/dev/null || true
}
# keep_failed: a guest whose rows failed still dumps its records
# (GOLDEN_DUMPING, then the block, then GOLDEN_ERR). Keep them, with
# FAILED and any netem evidence, next to the transcript, never in
# OUT_DIR, so a failed run can't replace the fixture. Only the
# scrubbed copy is kept, as for a passing run.
keep_failed() {
grep -q 'GOLDEN_DUMPING' "$LOG" 2>/dev/null || return 0
for _ in $(seq 1 60); do
if grep -q 'XTCP2_GOLDEN_DUMP_END' "$LOG" 2>/dev/null; then break; fi
sleep 1
done
local failed="''${LOG%.log}.failed"
extract_dump "$failed"
if [ -s "$failed/raw.parquet" ]; then
xtcp2-golden scrub "$failed/raw.parquet" "$failed/records.parquet" || true
xtcp2-golden normalize "$failed/records.parquet" > "$failed/records.jsonl" 2>/dev/null || true
rm -f "$failed/raw.parquet"
fi
echo "the failed capture's records: $failed"
}
# The guest's ROW lines, without the journal prefix.
print_rows() {
grep -a 'ROW ' "$LOG" | sed -E 's/^\[[^]]*\] [A-Za-z0-9_.@-]+\[[0-9]+\]: //' | tr -d '\r' || true
Expand Down Expand Up @@ -1348,6 +1380,7 @@ rec {
print_rows
echo "FATAL: the guest reported:"
grep -E 'GOLDEN_ERR' "$LOG" || true
keep_failed
exit 2
fi
sleep 5
Expand All @@ -1361,14 +1394,7 @@ rec {
print_rows
grep -E 'GOLDEN_WORKLOAD_READY|GOLDEN_ROWS' "$LOG" | sed -E 's/^\[[^]]*\] [A-Za-z0-9_.@-]+\[[0-9]+\]: //' || true

# Strip journal+console's `[TIME] ident[PID]: ` prefix before
# decoding, as mkNlmonCaptureRunner does.
awk '/XTCP2_GOLDEN_DUMP_START/{flag=1;next} /XTCP2_GOLDEN_DUMP_END/{flag=0} flag' "$LOG" \
| sed -E 's/^\[[^]]*\] [A-Za-z0-9_.@-]+\[[0-9]+\]: //' \
| tr -d '\r\n ' \
| base64 -d 2>/dev/null \
| gzip -dc 2>/dev/null \
| tar x -C "$STAGE" 2>/dev/null || true
extract_dump "$STAGE"
for f in raw.parquet manifest.json uname; do
if [ ! -s "$STAGE/$f" ]; then
echo "FATAL: the guest's block has no $f"
Expand Down
3 changes: 3 additions & 0 deletions nix/microvms/mkVm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,7 @@ let
kmod
procps
systemd
tcpdump
util-linux
];
text = ''
Expand All @@ -2517,6 +2518,7 @@ let
curl
docker
duckdb
ethtool
gawk
gnugrep
gnutar
Expand All @@ -2525,6 +2527,7 @@ let
jq
rclone
systemd
tcpdump
util-linux
];
text = ''
Expand Down
66 changes: 59 additions & 7 deletions nix/microvms/scripts/golden-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ host=$(q "SELECT count(*) FROM $P WHERE container_name = '' AND netns <> 'golden
# The nsid rows: nsid_assigned says whether nsid is set, so the kernel's
# first id (0) reads apart from no id at all.
row_failed=0
failed_rows=()
row() {
if [ "$3" = 1 ]; then
echo "ROW $1 $2 PASS $4"
else
echo "ROW $1 $2 FAIL $4"
row_failed=1
failed_rows+=("$1")
fi
}
zeros=0
Expand Down Expand Up @@ -199,7 +201,48 @@ mibs=""
for ns in golden-bulk-a golden-bulk-b; do
mibs="$mibs $ns=RetransSegs$(nstat_of "$ns" TcpRetransSegs)/OutSegs$(nstat_of "$ns" TcpOutSegs)"
done
row loss_seen negative "$ok" "$n bulk clients with retransmits, of $(wc -w <<<"$BULK_CC"); per client, retransmits/state/segs_out/bytes_acked: ${per_cc:-none}; netem sent/dropped:$netem_drops; kernel per port, retrans/cong/segs_out/rtt: $(ss_bulk detail " "); servers by client port: $(ss_bulk detail " " server);$mibs"
# netem's drops per flow, from the workload's tap on golden-bulk-a's veth0
# (/run/xtcp2-golden-bulk-tap: PORT=CLIENT_TAPPED/SERVER_TAPPED): a
# client's segs_out minus the packets tapped from it, and the same for its
# server. A flow that never went through netem shows 0/0.
segs_by_port() {
ip netns exec "$1" ss -HtinO state established "$2" |
awk -v key="$3" '{ p = $key; sub(/.*:/, "", p); if (match($0, /segs_out:[0-9]+/)) print p, substr($0, RSTART + 9, RLENGTH - 9) }'
}
netem_per_flow() {
awk 'ARGIND == 1 { c[$1] = $2; next } ARGIND == 2 { s[$1] = $2; next }
{ n = split($0, a, ","); for (i = 1; i <= n; i++) { split(a[i], kv, "="); split(kv[2], t, "/")
printf "%s%s=%d/%d", sep, kv[1], c[kv[1]] - t[1], s[kv[1]] - t[2]; sep = " " } }
END { print "" }' \
<(segs_by_port golden-bulk-a '( dport = :4000 )' 3) <(segs_by_port golden-bulk-b '( sport = :4000 )' 4) /run/xtcp2-golden-bulk-tap
}
tapped=$(cat /run/xtcp2-golden-bulk-tap 2>/dev/null || true)
tap_dropped=$(cat /run/xtcp2-golden-bulk-tap-dropped 2>/dev/null || echo "?")
loss_ok=$ok
row loss_seen negative "$ok" "$n bulk clients with retransmits, of $(wc -w <<<"$BULK_CC"); per client, retransmits/state/segs_out/bytes_acked: ${per_cc:-none}; netem sent/dropped:$netem_drops; kernel per port, retrans/cong/segs_out/rtt: $(ss_bulk detail " "); servers by client port: $(ss_bulk detail " " server);$mibs; netem drops per client port, client/server: $(netem_per_flow); tapped: ${tapped:-none}"
ok=0
[ -n "$tapped" ] && [ "$tap_dropped" = 0 ] && ok=1
row bulk_tap_complete positive "$ok" "the bulk tap on golden-bulk-a: kernel drops $tap_dropped, flows ${tapped:-none}"
per_flow=$(netem_per_flow)
ok=0
[ -n "$tapped" ] && awk '{ for (i = 1; i <= NF; i++) { split($i, kv, "="); split(kv[2], d, "/"); if (d[1] <= 0 || d[2] <= 0) exit 1 } }' <<<"$per_flow" && ok=1
row netem_per_flow positive "$ok" "netem dropped from every bulk flow both ways, per client port client/server: ${per_flow:-none}; netem sent/dropped:$netem_drops"
# When loss_seen fails, the dump carries what the kernel and netem saw and
# the tap's packets for the flows without retransmits (headers only).
if [ "$loss_ok" != 1 ]; then
for bns in golden-bulk-a golden-bulk-b; do
echo "== $bns"
ip netns exec "$bns" tc -s qdisc show dev veth0 || true
ip -n "$bns" -s link show veth0 || true
ip netns exec "$bns" ethtool -k veth0 || true
ip netns exec "$bns" ss -tienmO || true
ip netns exec "$bns" nstat -asz || true
done >"$OUT/netem-diag.txt" 2>&1
noloss=$(ss_bulk | tr , '\n' | awk -F= '$2 == 0 { printf "%sport %s", sep, $1; sep = " or " }')
if [ -n "$noloss" ] && tcpdump -r /run/xtcp2-golden-bulk-a.pcap -w "$OUT/bulk-a-noloss.pcap" "$noloss" 2>/dev/null; then
gzip -n "$OUT/bulk-a-noloss.pcap" || true
fi
fi
# The dctcp bulk client keeps dctcp: a SYN lost to netem must not make it
# fall back to dctcp-reno (tcp_ecn_fallback=0 in golden-bulk-a, the
# workload). Only when BULK_CC has dctcp.
Expand Down Expand Up @@ -293,16 +336,18 @@ if [ -n "${ERNIC_SEQ_DROPS:-}" ]; then
ok=0
[ "$dropped" -eq "$ERNIC_SEQ_DROPS" ] && ok=1
row seq_fired boundary "$ok" "ionic2 tx_dropped $dropped, want the sequence's $ERNIC_SEQ_DROPS"
got=$(q "SELECT count(*) || ':' || coalesce(string_agg(DISTINCT enrich_socket_dest_egress_ifname, ','), '') || ':' || coalesce(max(tcp_info_total_retrans), 0) || ':' || coalesce(max(tcp_info_total_rto), 0) || ':' || coalesce(max(tcp_info_segs_out), 0) FROM $P WHERE $C")
IFS=: read -r n egress retrans rto segs_out <<<"$got"
got=$(q "SELECT count(*) || ':' || coalesce(string_agg(DISTINCT enrich_socket_dest_egress_ifname, ','), '') || ':' || coalesce(max(tcp_info_total_retrans), 0) || ':' || coalesce(max(tcp_info_total_rto), 0) || ':' || coalesce(max(tcp_info_segs_out), 0) || ':' || coalesce(max(tcp_info_dsack_dups), 0) FROM $P WHERE $C")
IFS=: read -r n egress retrans rto segs_out dsack <<<"$got"
ok=0
[ "$n" = 1 ] && [ "$egress" = ionic2 ] && ok=1
row seq_egress negative "$ok" "the sequence flow's client and egress: $n:$egress, want 1:ionic2 (not uplink ionic0)"
# The flow is one-way, so every dropped frame is a data segment and is
# retransmitted exactly once.
# retransmitted exactly once. A retransmit of a segment that was not lost
# (a tail loss probe under host load) comes back as a DSACK
# (tcpi_dsack_dups), so those are not counted.
ok=0
[ "$retrans" -eq "$ERNIC_SEQ_DROPS" ] && ok=1
row seq_retrans positive "$ok" "the sequence flow's total_retrans $retrans (total_rto $rto), want the sequence's $ERNIC_SEQ_DROPS"
[ "$((retrans - dsack))" -eq "$ERNIC_SEQ_DROPS" ] && ok=1
row seq_retrans positive "$ok" "the sequence flow's total_retrans $retrans less dsack_dups $dsack (total_rto $rto), want the sequence's $ERNIC_SEQ_DROPS"
# The server sends only ACKs, over NICs without faults: nothing to resend.
got=$(q "SELECT count(*) || ':' || coalesce(max(tcp_info_total_retrans), 0) FROM $P WHERE netns = 'golden-ernic-d' AND inet_diag_msg_socket_source_port = 4000 AND inet_diag_msg_state = 1")
IFS=: read -r n sretrans <<<"$got"
Expand Down Expand Up @@ -392,7 +437,12 @@ got=$(q "SELECT string_agg(DISTINCT uplink1_nic_fw_version, ',') FROM $P")
ok=0
[ "$got" = "xtcp2-golden-1.0" ] && ok=1
row fw_from_profile corner "$ok" "uplink1 firmware, from the NIC profile's [identity]: $got"
[ "$row_failed" = 0 ] || fail "rows failed"
# A failed row still dumps the records, with FAILED listing the rows, so
# the host runner keeps them next to the transcript (never in the fixture
# directory); GOLDEN_ERR follows the dump.
if [ "$row_failed" != 0 ]; then
printf '%s\n' "${failed_rows[@]}" >"$OUT/FAILED"
fi

version=$(q "SELECT any_value(daemon_version) FROM $P")

Expand All @@ -413,8 +463,10 @@ jq -n \
rm -f "$OUT"/ss-golden-* "$OUT"/nsid-golden-*

echo "GOLDEN_ROWS $rows"
echo "GOLDEN_DUMPING"
echo "XTCP2_GOLDEN_DUMP_START"
tar c -C "$OUT" . | gzip -n | base64 -w0
echo
echo "XTCP2_GOLDEN_DUMP_END"
[ "$row_failed" = 0 ] || fail "rows failed: ${failed_rows[*]}"
echo "GOLDEN_DONE"
Loading