Page
Library
Module
Module type
Parameter
Class
Class type
Source
mnet, a pure OCaml TCP/IP stack for unikernelsmnet implements IPv4, IPv6, TCP, and UDP protocols for mkernel-based unikernels running on Solo5 and Unikraft. It replaces mirage-tcpip with a direct-style API powered by Miou and OCaml 5 effects.
The library also provides TLS (via ocaml-tls), DNS resolution (via ocaml-dns), and the Happy Eyeballs connection algorithm (via [happy-eyeballs][happy-eyeballs]).
connect, listen, accept, read, write, close)sendto/recvfrommnet requires OCaml 5. It is also necessary to launch unikernels via virtualisation (KVM, BHyve, VMM). Your processor must therefore be configured to allow virtualisation (VT-x, AMD-V).
opam pin add mnet https://github.com/robur-coop/mnet.git
opam install mnet mnet-tls mnet-dns mnet-happy-eyeballsEvery unikernel starts by creating a network stack via Mkernel.run. The stack needs a random number generator and an CIDRv4 (the IPv4 address of the unikernel). It is also possible to assign an IPv6 address to the unikernel. The DHCP protocol has not yet been implemented.
let ( let@ ) finally fn = Fun.protect ~finally fn
module RNG = Mirage_crypto_rng.Fortuna
let rng () = Mirage_crypto_rng_mkernel.initialize (module RNG)
let rng = Mkernel.map rng Mkernel.[]
let () =
Mkernel.(run [ rng; Mnet.stack ~name:"service" ~gateway cidr ])
@@ fun rng (stack, tcp, udp) () ->
let@ () = fun () -> Mnet.kill stack in
let@ () = fun () -> Mirage_crypto_rng_mkernel.kill rng in
(* use [tcp] and [udp] here *)
()The name parameter corresponds to the Solo5 network device. To launch the unikernel, you must allocate a virtual Ethernet interface (a tap interface) and you can launch the unikernel in this way:
$ sudo ip link add name br0 type bridge
$ sudo ip addr add 10.0.0.1/24 dev br0
$ sudo ip tuntap add name tap0 mode tap
$ sudo ip link set tap0 master br0
$ solo5-hvt --net:service=tap0 -- unikernel.hvt --ipv4=10.0.0.2/24Package | Description |
|---|---|
| Core TCP/IP stack (IPv4, IPv6, TCP, UDP) |
| TLS support via ocaml-tls |
| DNS client via ocaml-dns |
| Happy Eyeballs connection algorithm (RFC 8305) |
mnet provides end-to-end tests that compile and run real unikernels. This requires:
kvm group on Linux)mnet pinned in opamgit clone https://github.com/robur-coop/mnet
cd mnet
opam pin add -y .
sudo true
dune runtest --profile=unikernels