Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove mirage-profile dependency, also result #35

Merged
merged 8 commits into from
May 8, 2024
Merged
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: 0 additions & 1 deletion .github/workflows/main.yml → .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
matrix:
os:
- macos-latest
- windows-latest
ocaml-compiler:
- 4.13.x

Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Main workflow

on:
pull_request:
push:
schedule:
# Prime the caches every Monday
- cron: 0 1 * * MON

jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- windows-latest
ocaml-compiler:
- 4.13.x

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
opam-repositories: |
opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
default: https://github.com/ocaml/opam-repository.git
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- run: opam install . --deps-only --with-test

- run: opam exec -- dune build

- run: opam exec -- dune runtest
7 changes: 0 additions & 7 deletions .merlin

This file was deleted.

17 changes: 8 additions & 9 deletions mirage-vnetif-stack.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@ build: [
]

depends: [
"ocaml" {>= "4.06.0"}
"ocaml" {>= "4.08.0"}
"dune" {>= "1.9"}
"result" {>= "1.5"}
"lwt"
"mirage-time" {>= "2.0.0"}
"mirage-clock" {>= "3.0.0"}
"mirage-time" {>= "3.0.0"}
"mirage-clock" {>= "4.0.0"}
"mirage-net" {>= "3.0.0"}
"mirage-random"
"mirage-vnetif" {= version}
"tcpip" {>= "7.0.0"}
"tcpip" {>= "8.0.0"}
"ethernet"
"cstruct" {>="6.0.0"}
"ipaddr" {>= "5.0.0"}
"macaddr"
"mirage-profile"
"arp" {>= "3.0.0"}
"duration"
"logs"
"mirage-time-unix" {with-test}
"mirage-clock-unix" {with-test}
"mirage-random-test" {with-test}
"mirage-clock-unix" {with-test & >= "4.0.0"}
"mirage-crypto-rng" {with-test & >= "0.11.0"}
"alcotest" {>= "1.5.0" & with-test}
"alcotest-lwt" {with-test}
"alcotest-lwt" {>= "1.5.0" & with-test}
]
conflicts: [ "result" {< "1.5"} ]
tags: ["org:mirage"]
synopsis: "Vnetif implementation of mirage-stack for Mirage TCP/IP"
description: """
Expand Down
5 changes: 2 additions & 3 deletions mirage-vnetif.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ build: [
]

depends: [
"ocaml" {>= "4.06.0"}
"ocaml" {>= "4.08.0"}
"dune" {>= "1.9"}
"result" {>= "1.5"}
"lwt"
"mirage-net" {>= "3.0.0"}
"cstruct" {>="6.0.0"}
"ipaddr" {>= "3.0.0"}
"macaddr"
"mirage-profile"
"duration"
"logs"
]
conflicts: [ "result" {< "1.5"} ]
tags: ["org:mirage"]
synopsis: "Virtual network interface and software switch for Mirage"
description: """
Expand Down
6 changes: 3 additions & 3 deletions src/vnetif-stack/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
(public_name mirage-vnetif-stack)
(modules vnetif_stack)
(wrapped false)
(libraries cstruct lwt lwt.unix mirage-clock ipaddr macaddr mirage-profile
duration result mirage-time mirage-net mirage-random ethernet arp arp.mirage
logs tcpip.stack-direct tcpip.ipv4 tcpip.icmpv4 tcpip.tcp tcpip.udp
(libraries cstruct lwt lwt.unix mirage-clock ipaddr macaddr
duration mirage-time mirage-net mirage-random ethernet arp arp.mirage
logs tcpip.stack-direct tcpip.ipv4 tcpip.ipv6 tcpip.icmpv4 tcpip.tcp tcpip.udp tcpip
mirage-vnetif
))
24 changes: 14 additions & 10 deletions src/vnetif-stack/vnetif_stack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Lwt
open Lwt.Infix

module type Vnetif_stack =
sig
type backend
type buffer
type 'a io
type id
module V4 : Tcpip.Stack.V4
module V4V6 : Tcpip.Stack.V4V6
module Backend : Vnetif.BACKEND

(** Create a new IPv4 stack connected to an existing backend *)
val create_stack_ipv4 : cidr:Ipaddr.V4.Prefix.t ->
?gateway:Ipaddr.V4.t -> ?mtu:int -> ?monitor_fn:(buffer -> unit io) ->
?unlock_on_listen:Lwt_mutex.t ->
backend -> V4.t Lwt.t
backend -> V4V6.t Lwt.t
end

module Vnetif_stack (B : Vnetif.BACKEND)(R : Mirage_random.S)(Time : Mirage_time.S)(Mclock : Mirage_clock.MCLOCK):
Expand All @@ -44,21 +44,25 @@ struct
module V = Vnetif.Make(Backend)
module E = Ethernet.Make(V)
module A = Arp.Make(E)(Time)
module Ip = Static_ipv4.Make(R)(Mclock)(E)(A)
module Icmp = Icmpv4.Make(Ip)
module Ip4 = Static_ipv4.Make(R)(Mclock)(E)(A)
module Icmp = Icmpv4.Make(Ip4)
module Ip6 = Ipv6.Make(V)(E)(R)(Time)(Mclock)
module Ip = Tcpip_stack_direct.IPV4V6(Ip4)(Ip6)
module U = Udp.Make(Ip)(R)
module T = Tcp.Flow.Make(Ip)(Time)(Mclock)(R)
module V4 = Tcpip_stack_direct.Make(Time)(R)(V)(E)(A)(Ip)(Icmp)(U)(T)
module V4V6 = Tcpip_stack_direct.MakeV4V6(Time)(R)(V)(E)(A)(Ip)(Icmp)(U)(T)

let create_stack_ipv4 ~cidr ?gateway ?mtu ?monitor_fn ?unlock_on_listen backend =
V.connect ?size_limit:mtu ?monitor_fn ?unlock_on_listen backend >>= fun netif ->
E.connect netif >>= fun ethif ->
A.connect ethif >>= fun arp ->
Ip.connect ~cidr ?gateway ethif arp >>= fun ipv4 ->
Ip4.connect ~cidr ?gateway ethif arp >>= fun ipv4 ->
Icmp.connect ipv4 >>= fun icmp ->
U.connect ipv4 >>= fun udp ->
T.connect ipv4 >>= fun tcp ->
V4.connect netif ethif arp ipv4 icmp udp tcp
Ip6.connect ~no_init:true netif ethif >>= fun ipv6 ->
Ip.connect ~ipv4_only:true ~ipv6_only:false ipv4 ipv6 >>= fun ip ->
U.connect ip >>= fun udp ->
T.connect ip >>= fun tcp ->
V4V6.connect netif ethif arp ip icmp udp tcp
end

(*module Vnetif_stack_unix(B: Vnetif.BACKEND)(R : Mirage_random.S):
Expand Down
2 changes: 1 addition & 1 deletion src/vnetif/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
(modules basic_backend vnetif)
(wrapped false)
(libraries cstruct lwt lwt.unix ipaddr macaddr
duration result mirage-net logs mirage-profile
duration mirage-net logs
))
2 changes: 1 addition & 1 deletion src/vnetif/vnetif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module Make (B : BACKEND) = struct
| Some l -> Lwt_mutex.unlock l);

(* Block until woken up by disconnect *)
let task, waker = MProf.Trace.named_task "Netif.listen" in
let task, waker = Lwt.task () in
t.wake_on_disconnect <- (Some waker);
task >|= fun () ->
Ok ()
Expand Down
2 changes: 1 addition & 1 deletion test/vnetif-stack/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(test
(name test)
(package mirage-vnetif-stack)
(libraries lwt alcotest alcotest-lwt mirage-vnetif mirage-vnetif-stack mirage-random-test mirage-clock-unix mirage-time-unix)
(libraries lwt alcotest alcotest-lwt mirage-vnetif mirage-vnetif-stack mirage-crypto-rng mirage-crypto-rng.unix mirage-clock-unix mirage-time-unix)
(action
(run %{test} -v -e --color=always)))
20 changes: 10 additions & 10 deletions test/vnetif-stack/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
open Lwt.Infix

module Stack(B: Vnetif.BACKEND) = struct
module V = Vnetif_stack.Vnetif_stack(B)(Mirage_random_test)(Time)(Mclock)
module V = Vnetif_stack.Vnetif_stack(B)(Mirage_crypto_rng)(Time)(Mclock)
include V
end

Expand All @@ -30,12 +30,12 @@ let connect_test_lwt _ () =

let or_error name fn t =
fn t >>= function
| Error e -> Alcotest.failf "%s: %s" name (Format.asprintf "%a" Stack.V4.TCPV4.pp_error e)
| Error e -> Alcotest.failf "%s: %s" name (Format.asprintf "%a" Stack.V4V6.TCP.pp_error e)
| Ok t -> Lwt.return t
in

let accept client_l flow expected =
or_error "read" Stack.V4.TCPV4.read flow >>= function
or_error "read" Stack.V4V6.TCP.read flow >>= function
| `Eof -> Alcotest.failf "eof while reading from socket"
| `Data data ->
let recv_str = Cstruct.to_string data in
Expand All @@ -62,19 +62,19 @@ let connect_test_lwt _ () =

(* Server side *)
(Stack.create_stack_ipv4 ~cidr:server_cidr ~unlock_on_listen:listen_l backend >>= fun s1 ->
Stack.V4.TCPV4.listen (Stack.V4.tcpv4 s1) ~port:80 (fun f -> accept accept_l f test_msg);
Stack.V4.listen s1 >>= fun () ->
Stack.V4V6.TCP.listen (Stack.V4V6.tcp s1) ~port:80 (fun f -> accept accept_l f test_msg);
Stack.V4V6.listen s1 >>= fun () ->
Alcotest.failf "server: listen should never exit");

(* Client side *)
Lwt_mutex.lock listen_l >>= fun () -> (* wait for server to unlock with call to listen *)
Stack.create_stack_ipv4 ~cidr:client_cidr backend >>= fun s2 ->
or_error "connect" (Stack.V4.TCPV4.create_connection (Stack.V4.tcpv4 s2)) (Ipaddr.V4.Prefix.address server_cidr, 80) >>= fun flow ->
Stack.V4.TCPV4.write flow (Cstruct.of_string test_msg) >>= (function
or_error "connect" (Stack.V4V6.TCP.create_connection (Stack.V4V6.tcp s2)) Ipaddr.(V4 (V4.Prefix.address server_cidr), 80) >>= fun flow ->
Stack.V4V6.TCP.write flow (Cstruct.of_string test_msg) >>= (function
| Ok () -> Lwt.return_unit
| Error e -> Alcotest.failf "write: %s" (Format.asprintf "%a" Stack.V4.TCPV4.pp_write_error e))
| Error e -> Alcotest.failf "write: %s" (Format.asprintf "%a" Stack.V4V6.TCP.pp_write_error e))
>>= fun () ->
Stack.V4.TCPV4.close flow >>= fun () ->
Stack.V4V6.TCP.close flow >>= fun () ->
Lwt_mutex.lock accept_l (* wait for accept to unlock *)
]
)
Expand All @@ -86,7 +86,7 @@ let () =
Random.init rand_seed;
Printf.printf "Testing with rand_seed %d\n" rand_seed;

(*Mirage_random_test.initialize();*)
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);

Lwt_main.run @@
Alcotest_lwt.run "mirage-vnetif" [
Expand Down
Loading