Skip to content

Commit 74b4dbf

Browse files
nix: two-VM pair test, Homa traffic between microVMs
- mkVm.nix: optional pairNode adds eth1 on a QEMU socket link (node0 listens, node1 connects; no root/tap/bridge), static IPs, cp_node node<N> hosts, firewall off, and runs the pair script - pair.nix: server (demo_server1 + cp_node Homa/TCP servers) and client (ping, echo 100 B..1 MB, cp_node w4 over Homa then TCP); both rmmod and gate on dmesg; TCP ready/done ports via socat so a Homa failure still ends both VMs promptly - lib-pair.nix: start node0, wait for its listen socket (ss, no probe connection), run node1, verdict from both consoles - homa-pair-test: 7.3 <-> 7.3 PASS, ~35 s cached; a client with no live peer fails at PING - README: two-VM section with real output; plan phase 1 done Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e96c257 commit 74b4dbf

7 files changed

Lines changed: 384 additions & 8 deletions

File tree

‎nix/README.md‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,53 @@ VERDICT: PASS
101101

102102
The whole run takes about 15 seconds once the kernel is in the store.
103103

104+
### 5. Homa between two VMs
105+
106+
```sh
107+
nix run .#homa-pair-test
108+
```
109+
110+
This boots two VMs, `node0` and `node1`, joined by a private Ethernet link. The link is a
111+
QEMU socket connection, so it needs no root, tap or bridge. Homa then runs over that link
112+
between two separate kernels:
113+
114+
```
115+
--- node0 (server)
116+
HOMA_PAIR_SERVER_START host=node0 kernel=7.3.0
117+
HOMA_PAIR_SERVER_INSMOD_OK
118+
HOMA_PAIR_SERVER_SERVERS_OK
119+
HOMA_PAIR_SERVER_READY
120+
HOMA_PAIR_SERVER_CLIENT_REPORT PASS
121+
HOMA_PAIR_SERVER_RMMOD_OK
122+
HOMA_PAIR_SERVER_DMESG_OK
123+
HOMA_PAIR_SERVER_PASS
124+
--- node1 (client)
125+
HOMA_PAIR_START host=node1 kernel=7.3.0
126+
HOMA_PAIR_INSMOD_OK
127+
HOMA_PAIR_PING_OK
128+
HOMA_PAIR_PEER_READY_OK
129+
HOMA_PAIR_ECHO responses=6 (want 6) data+grant packets=1256
130+
HOMA_PAIR_ECHO_OK
131+
HOMA_PAIR_CPNODE_homa ... homa_w4 clients: 0.24 Kops/sec, 0.17 Gbps out, 0.17 Gbps in, RTT (us) P50 4977.72 P99 16528.36 ...
132+
HOMA_PAIR_CPNODE_HOMA_OK
133+
HOMA_PAIR_CPNODE_tcp ... tcp_w4 clients: 0.12 Kops/sec, 0.05 Gbps out, 0.05 Gbps in, RTT (us) P50 218.30 P99 41996.96 ...
134+
HOMA_PAIR_CPNODE_TCP_OK
135+
HOMA_PAIR_RMMOD_OK
136+
HOMA_PAIR_DMESG_OK
137+
HOMA_PAIR_PASS
138+
VERDICT: PASS
139+
```
140+
141+
The client does the following, in order:
142+
1. pings `node0`;
143+
2. runs echo RPCs from 100 B to 1 MB across the link;
144+
3. drives a few seconds of Homa's `cp_node` workload `w4`;
145+
4. drives the same workload over TCP for comparison.
146+
147+
Then both VMs unload the module and check dmesg. A run takes about 35 seconds once
148+
cached. The link is emulated and the VMs share host CPUs, so the rates show that traffic
149+
flows, not how fast Homa is.
150+
104151
---
105152

106153
## Testing against different kernels
@@ -146,6 +193,7 @@ nix run .#homa-microvm-test # default kernel: insmod, echo, GRO/RPS, rm
146193
nix run .#homa-microvm-test-<s> # ... on one kernel
147194
nix run .#homa-microvm-test-debug # ... under a KASAN/KMEMLEAK kernel (slow)
148195
nix run .#homa-microvm[-<s>] # interactive guest
196+
nix run .#homa-pair-test # two VMs: echo + cp_node (Homa, TCP) across a link
149197

150198
nix build .#homa-image[-debug] # OCI user-space image (docker load < result)
151199

@@ -181,7 +229,7 @@ default each run makes a fresh `mktemp -d` and prints its path.
181229
| `userspace.nix` | `util/` tools and the `test/` unit harness |
182230
| `devshell.nix` + `shell-functions/` | the dev shell |
183231
| `oci.nix` | user-space OCI image |
184-
| `microvms/` | per-kernel microVM guests, the in-guest smoke test, and the orchestrator |
232+
| `microvms/` | per-kernel microVM guests, the in-guest smoke and pair tests, and the orchestrators |
185233
| `analysis/` | tiered static analysis (quick/standard/deep) |
186234
| `fuzz/` | libFuzzer harnesses for wire (de)serialization |
187235

‎nix/microvms/PLAN-pairs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Two guests built by the existing `mkVm.nix`, each with a second NIC:
5656

5757
| # | Deliverable | New targets | Done when |
5858
|---|---|---|---|
59-
| 1 | Pair harness, same kernel | `homa-pair-test` (default kernel), `homa-pair` (interactive: both VMs, root shells) | Echo + cp_node pass on 7.3 ↔ 7.3 |
59+
| 1 ✅ | Pair harness, same kernel | `homa-pair-test` (default kernel) | **Done:** echo + cp_node Homa/TCP pass on 7.3 ↔ 7.3, about 35 s cached; a client with a dead link fails at `PING`. The interactive pair (`homa-pair`) moves to phase 3 |
6060
| 2 | Cross-kernel pairs | `homa-pair-test-<A>-<B>` for supported kernels (6.12 ↔ 7.3 both ways) | Mixed-kernel wire compatibility proven both directions |
6161
| 3 | One command for everything | `homa-vm-matrix`: every single-VM test plus every pair, run in parallel, printing a table (kernel(s), verdict, RPC counts, cp_node rates) | `nix run .#homa-vm-matrix` is the demo |
6262
| 4 | Lossy and slow links | `homa-pair-test-netem`: `tc netem loss 1% delay 1ms` on eth1 | Echo still completes, and the RESEND/retransmit counters in `/proc/net/homa_metrics` move |

‎nix/microvms/constants.nix‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,31 @@
1919
bootTimeoutDebug = 1200; # KASAN guests boot slowly
2020

2121
stateVersion = "24.11";
22+
23+
# Two-VM pair test (pair.nix, lib-pair.nix; uds-rdma-proxy pattern). The guests share a
24+
# private L2 link on eth1: a QEMU socket netdev that node0 listens on and node1 connects
25+
# to, so no root, tap or bridge is needed. Hostnames follow cp_node's "node<N>" naming.
26+
pair = {
27+
nodes = {
28+
server = { hostname = "node0"; ip = "10.88.0.1"; mac = "52:54:00:88:00:01"; role = "listen"; };
29+
client = { hostname = "node1"; ip = "10.88.0.2"; mac = "52:54:00:88:00:02"; role = "connect"; };
30+
};
31+
prefixLength = 24;
32+
socketPort = 23700; # host 127.0.0.1 port for the QEMU socket link
33+
34+
# Guest TCP ports for coordination (not Homa traffic).
35+
readyPort = 5998; # server listens once its Homa servers are up
36+
donePort = 5999; # client sends its verdict here when finished
37+
cpNodeHomaPort = 4100; # demo_server1 already owns Homa port 4000
38+
39+
# cp_node load phase: a few seconds of workload w4 at a modest rate (the socket link
40+
# runs at roughly 1-2 Gb/s; this shows traffic flows, not Homa's performance).
41+
workload = "w4";
42+
gbps = "0.2";
43+
loadSeconds = 6;
44+
45+
serverTimeout = 120; # client waits this long for the server's ready port
46+
clientTimeout = 300; # server waits this long for the client's report
47+
runTimeout = 420; # host: whole pair run
48+
};
2249
}

‎nix/microvms/default.nix‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
let
3232
constants = import ./constants.nix { inherit lib; };
3333

34-
mkGuest = { kernelPackages, withSanitizers ? false, autoTest ? false }: import ./mkVm.nix {
34+
mkGuest = { kernelPackages, withSanitizers ? false, autoTest ? false, pairNode ? null }: import ./mkVm.nix {
3535
inherit pkgs lib microvm nixpkgs buildSystem constants homaUtils
36-
kernelPackages withSanitizers autoTest;
36+
kernelPackages withSanitizers autoTest pairNode;
3737
homaModule = buildModule { inherit kernelPackages; };
3838
homaModuleDebug = buildModule { inherit kernelPackages; enableDebug = true; };
3939
};
@@ -43,6 +43,13 @@ let
4343
runner = mkGuest { inherit kernelPackages withSanitizers; autoTest = true; };
4444
};
4545

46+
# Two-VM pair test: node0 (server) on serverKp, node1 (client) on clientKp.
47+
mkPairTest = { serverKp, clientKp, label }: import ./lib-pair.nix {
48+
inherit pkgs lib constants label;
49+
serverRunner = mkGuest { kernelPackages = serverKp; autoTest = true; pairNode = "server"; };
50+
clientRunner = mkGuest { kernelPackages = clientKp; autoTest = true; pairNode = "client"; };
51+
};
52+
4653
defaultKp = kernelConfig.kernelPackages;
4754

4855
perKernel = lib.concatMapAttrs
@@ -62,5 +69,6 @@ in
6269
label = "-debug";
6370
withSanitizers = true;
6471
};
72+
homa-pair-test = mkPairTest { serverKp = defaultKp; clientKp = defaultKp; label = ""; };
6573
} // perKernel;
6674
}

‎nix/microvms/lib-pair.nix‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# nix/microvms/lib-pair.nix
2+
#
3+
# Orchestrator for the two-VM pair test (PLAN-pairs.md, uds-rdma-proxy pattern, console
4+
# markers as in lib.nix). Both guests drive themselves (pair.nix) and power off when done,
5+
# so the host only has to:
6+
# 1. start node0 (server), whose QEMU listens on the socket link;
7+
# 2. wait until that port is listening (checked with ss, because a probe connection would
8+
# take the link's only accept);
9+
# 3. start node1 (client), which connects;
10+
# 4. wait for both qemu processes to exit, then grep both consoles:
11+
# node1: HOMA_PAIR_PASS node0: HOMA_PAIR_SERVER_PASS
12+
# Logs go to $HOMA_VM_LOGDIR (default: a fresh mktemp -d), printed at the start.
13+
14+
{ pkgs
15+
, lib
16+
, constants
17+
, serverRunner # declaredRunner for the pairNode = "server" guest
18+
, clientRunner # declaredRunner for the pairNode = "client" guest
19+
, label ? "" # "", "-7_3", "-6_12-7_3", ...
20+
}:
21+
22+
let
23+
pair = constants.pair;
24+
in
25+
pkgs.writeShellApplication {
26+
name = "homa-pair-test${label}";
27+
runtimeInputs = with pkgs; [ coreutils gnugrep iproute2 procps ];
28+
text = ''
29+
logdir="''${HOMA_VM_LOGDIR:-$(mktemp -d)}"
30+
mkdir -p "$logdir"
31+
slog="$logdir/node0${label}.log"
32+
clog="$logdir/node1${label}.log"
33+
port=${toString pair.socketPort}
34+
echo "console logs: $slog $clog"
35+
36+
if ss -Hltn "sport = :$port" | grep -q .; then
37+
echo "port $port is already in use (another pair test running?)"
38+
echo "VERDICT: FAIL"
39+
exit 1
40+
fi
41+
42+
timeout --kill-after=10s ${toString pair.runTimeout}s \
43+
${serverRunner}/bin/microvm-run > "$slog" 2>&1 &
44+
spid=$!
45+
46+
for _ in $(seq 60); do
47+
ss -Hltn "sport = :$port" | grep -q . && break
48+
kill -0 "$spid" 2>/dev/null || break
49+
sleep 0.5
50+
done
51+
if ! ss -Hltn "sport = :$port" | grep -q .; then
52+
echo "node0 never listened on 127.0.0.1:$port"
53+
tail -n 30 "$slog"
54+
kill "$spid" 2>/dev/null || true
55+
echo "VERDICT: FAIL"
56+
exit 1
57+
fi
58+
59+
cstatus=0
60+
timeout --kill-after=10s ${toString pair.runTimeout}s \
61+
${clientRunner}/bin/microvm-run > "$clog" 2>&1 || cstatus=$?
62+
[ "$cstatus" = 124 ] && echo "node1 timed out"
63+
64+
# The server powers off after the client's report; give it a moment, then stop it.
65+
for _ in $(seq 60); do
66+
kill -0 "$spid" 2>/dev/null || break
67+
sleep 1
68+
done
69+
kill "$spid" 2>/dev/null || true
70+
wait "$spid" 2>/dev/null || true
71+
72+
# Lines look like "[ 13.44] homa-pair-client[522]: HOMA_PAIR_ECHO_OK"; -a because the
73+
# logs also hold terminal escape sequences.
74+
show() { grep -aE '\]: HOMA_PAIR_' "$1" | sed -E 's/^.*\]: //' | tr -d '\r' || true; }
75+
echo "--- node0 (server)"
76+
show "$slog"
77+
echo "--- node1 (client)"
78+
show "$clog"
79+
80+
verdict=PASS
81+
grep -aqE '\]: HOMA_PAIR_SERVER_PASS' "$slog" || verdict=FAIL
82+
grep -aqE '\]: HOMA_PAIR_PASS' "$clog" || verdict=FAIL
83+
if [ "$verdict" = FAIL ]; then
84+
for f in "$slog" "$clog"; do
85+
if ! grep -aqE '\]: HOMA_PAIR_(SERVER_)?(PASS|FAIL)' "$f"; then
86+
echo "--- $(basename "$f") never reported; last console lines:"
87+
tail -n 30 "$f"
88+
fi
89+
done
90+
fi
91+
echo "VERDICT: $verdict"
92+
[ "$verdict" = PASS ]
93+
'';
94+
}

‎nix/microvms/mkVm.nix‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# kernel).
1515
#
1616
# kernelPackages selects the guest kernel (one VM per kernel.nix matrix entry, xtcp2-style).
17+
#
18+
# pairNode = "server" | "client" makes the guest one half of the two-VM pair test: a second
19+
# NIC (eth1) on a QEMU socket link to the other guest, a static IP, cp_node's node<N>
20+
# hostnames, and pair.nix's script in place of the smoke test.
1721

1822
{ pkgs
1923
, lib
@@ -27,6 +31,7 @@
2731
, homaUtils # user-space tools (demo_server1/demo_client1 for the smoke test)
2832
, withSanitizers ? false
2933
, autoTest ? false
34+
, pairNode ? null # null | "server" | "client"
3035
}:
3136

3237
let
@@ -54,6 +59,13 @@ let
5459

5560
smoke = import ./smoke.nix { inherit pkgs homaKoPath homaUtils withSanitizers; };
5661

62+
pair = constants.pair;
63+
isPair = pairNode != null;
64+
node = pair.nodes.${pairNode};
65+
pairScripts = import ./pair.nix { inherit pkgs homaKoPath homaUtils pair; };
66+
testScript = if isPair then pairScripts.${pairNode} else smoke;
67+
testExe = lib.getExe testScript;
68+
5769
guest = nixpkgs.lib.nixosSystem {
5870
system = buildSystem;
5971
modules = [
@@ -63,6 +75,9 @@ let
6375
boot.kernelParams = [
6476
"console=ttyS0,115200"
6577
"systemd.show_status=true"
78+
] ++ lib.optionals isPair [
79+
# Stable names: the user NIC is eth0 and the pair link eth1.
80+
"net.ifnames=0"
6681
] ++ lib.optionals withSanitizers [ "kmemleak=on" "kasan_multi_shot" ];
6782
boot.initrd.availableKernelModules = [ "9p" "9pnet" "9pnet_virtio" "virtio_pci" ];
6883

@@ -89,25 +104,45 @@ let
89104
id = "eth0";
90105
mac = "52:54:00:00:00:01";
91106
}];
107+
108+
# Pair link (eth1): point-to-point QEMU socket, node0 listens and node1 connects.
109+
qemu.extraArgs = lib.optionals isPair [
110+
"-netdev"
111+
"socket,id=homapair,${node.role}=127.0.0.1:${toString pair.socketPort}"
112+
"-device"
113+
"virtio-net-pci,netdev=homapair,mac=${node.mac}"
114+
];
115+
};
116+
117+
networking.interfaces = lib.mkIf isPair {
118+
eth1 = {
119+
useDHCP = false;
120+
ipv4.addresses = [{ address = node.ip; inherit (pair) prefixLength; }];
121+
};
92122
};
123+
networking.hosts = lib.mkIf isPair (lib.mapAttrs'
124+
(_: n: lib.nameValuePair n.ip [ n.hostname ])
125+
pair.nodes);
126+
# The NixOS firewall would drop Homa (IP protocol 146) and the coordination ports.
127+
networking.firewall.enable = !isPair;
93128

94129
# Interactive use: passwordless root autologin on the console.
95130
services.getty.autologinUser = "root";
96131
users.users.root.password = "";
97132

98-
networking.hostName = constants.hostname;
133+
networking.hostName = if isPair then node.hostname else constants.hostname;
99134

100-
environment.systemPackages = [ pkgs.kmod pkgs.iproute2 pkgs.coreutils homaUtils smoke ];
135+
environment.systemPackages = [ pkgs.kmod pkgs.iproute2 pkgs.coreutils homaUtils testScript ];
101136
environment.variables.HOMA_KO = homaKoPath;
102137

103-
systemd.services.homa-smoke = lib.mkIf autoTest {
138+
systemd.services.homa-test = lib.mkIf autoTest {
104139
wantedBy = [ "multi-user.target" ];
105140
after = [ "multi-user.target" ];
106141
serviceConfig = {
107142
Type = "oneshot";
108143
StandardOutput = "journal+console";
109144
StandardError = "journal+console";
110-
ExecStart = "${smoke}/bin/homa-smoke";
145+
ExecStart = testExe;
111146
# Pass or fail, end the run so the host sees qemu exit.
112147
ExecStopPost = "${pkgs.systemd}/bin/systemctl poweroff --no-block";
113148
};

0 commit comments

Comments
 (0)