Skip to content
backkemPublic

About

A deterministic virtual IP network made of WebAssembly components: real protocols on real frames, WASI 0.3 sockets, the same bytes on every machine.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

wasmnet

A deterministic simulator for fleets of WebAssembly devices.
A whole IP network in one process: hosts, switches and routers as components, on virtual time.
Try it in your browser


Plug hosts into a switch, give the links a latency, and run. What comes out is what a real network would give you: ARP, SYN, SYN-ACK, GET / HTTP/1.1, in a capture Wireshark opens. Except that this network lives in one process, touches nothing on your machine, and does exactly the same thing every time.

The network is the largest part, not the whole. Underneath is a simulator for a fleet of devices: it creates, stops, crashes and limits them while the run goes on, lets a device that is granted it manage the others, and serves each one its time, its entropy and its wires from one seed. A network is what the components here build on that.

  • 🔁 Same seed, same bytes. Time is virtual and entropy is seeded. A run repeats exactly, captures and logs included, on every machine.
  • 📡 Real protocols on real frames. Ethernet, ARP and NDP, IPv4 and IPv6, TCP and UDP, DHCP, DNS, mDNS, HTTP. Every link writes a pcap.
  • 🧩 Ordinary programs. Apps are plain WASI 0.3 code on wasi:sockets. They do not know they are simulated.
  • 🧱 Nothing leaks. No TAP device, no host sockets, no wall clock. Components have no ambient authority, so the sandbox keeps the promise.
  • 🎛️ A fleet you can operate. Add, stop, restart, crash and limit devices mid-run, by hand or from a controller inside the simulation (wasmnet:infra). Every change is an event at a virtual instant, so it replays.
  • 🌐 In a tab too. The same simulator and devices run in a browser, live.
  http-get                                               http-server
     │ wasi:sockets@0.3                                       │ wasi:sockets@0.3
  netstack (smoltcp) ──100 µs──  switch  ──150 µs──  netstack (smoltcp)

Quick start

cargo install --locked wasmtime-cli@50.0.1 wasm-tools@1.261.0 wac-cli@0.12.0

cargo xtask build                           # the components and the composed nodes
cargo run -p wasmnet-host --example http    # two hosts, a switch, one GET

It prints what every device reported, stamped in virtual nanoseconds, and writes one pcap-ng per link to target/http/.

In ten lines

let host = Host::new()?;
let mut net = Network::new(&host, 42); // 42 is the seed
let sw = net.device("sw", &host.load("switch.wasm")?)?;
let web = net.device_with_config("web", &host.load("node-http-server.wasm")?, web_config)?;
let cli = net.device_with_config("cli", &host.load("node-http-get.wasm")?, cli_config)?;
net.link(web.port(0), sw.port(1))?.latency(150_000); // nanoseconds
net.link(cli.port(0), sw.port(2))?.latency(100_000);
net.run_until_quiescent()?;
let pcap = net.pcap(net.links()[0]); // open it in Wireshark

The full version is crates/wasmnet-host/examples/http.rs.

What's in the box

Path What it does
crates/wasmnet-host Runs a network on wasmtime: one store per device, deterministic WASI. Start here.
crates/wasmnet-core The simulator itself: devices and their lifecycle, virtual clock, event queue, patch panel, link model, pcap taps. No wasmtime.
crates/wasmnet-sites One network split over two simulators: the lockstep driver, its wire format, and the merge into what one simulator records.
crates/wasmnet-web The simulator for a browser, with web/: a TypeScript binding and the page behind the link above.
crates/wasmnet-artifacts A revision's components as files with hashes: their manifest, and fetching a pinned set from a directory or a registry.
crates/wasmnet-disk Disks for devices, opt-in: named ordered key-value stores behind wasi:keyvalue, with durability modes, faults, quotas and images, on every backend.
components/ netstack (smoltcp behind wasi:sockets@0.3), switch, router, wan-port. All of them by name.
components/apps/ DHCP, DNS and mDNS servers (host names and DNS-SD services), a DNS-SD browser, an HTTP server, client and load balancer, ping, traceroute, UDP echo.
compositions/ wac files that plug apps into a netstack to make a node.
wit/ The contracts. wasmnet:link is the wire; everything else stands on it.

The rules it keeps

  1. Determinism. Clocks, entropy and scheduling are host imports, served from virtual time and a seed.
  2. Packets are the truth. Devices talk only in Ethernet frames over wasmnet:link.
  3. The host is a dumb backplane. If it parses an IP header, it belongs in a component.
  4. Standards at the surface. Apps import wasi:sockets@0.3; what WASI lacks lives in the small wasmnet:sockets-ext.

Going deeper

  • docs/: how it works, with a reading order, and how to write a device or an app.
  • docs/design/configuration.md: every config key.
  • docs/known-issues.md: what we know is wrong today.
  • docs/design/artifacts.md: a revision's components as a set of files with hashes (cargo xtask artifacts), what makes them reproducible, and how another repository's build fetches and checks them instead of building them.
  • docs/stability.md: which parts of the API are the core, which move, and how to build its types so that a new field never breaks your build.
  • CONTRIBUTING.md: building, testing and the rules a change keeps.
cargo test --workspace     # wire, simulator, host, and end-to-end runs of real nodes
cargo xtask test-guest     # every component's own tests, executed inside wasmtime
cargo xtask web --test     # the browser page, in headless Chromium (needs Node 24 and a Chromium)

Status

Experimental, version 0.0.0: the Rust API and the WIT still move. A browser run is live and repeats itself, but is not byte-identical to a native one. Built on Rust 1.98.1 and wasmtime 50.0.1, both pinned (tools.toml has every tool version in one place).

License

MIT or Apache-2.0, at your option (LICENSE-MIT, LICENSE-APACHE). Vendored code keeps its own license: see third_party/README.md and wit/README.md.

About

A deterministic virtual IP network made of WebAssembly components: real protocols on real frames, WASI 0.3 sockets, the same bytes on every machine.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages