Skip to content

Commit

Permalink
remove time as functor argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed May 7, 2024
1 parent 33b9ddf commit 220520e
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 59 deletions.
5 changes: 2 additions & 3 deletions src/ipv6/ipv6.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ open Lwt.Infix
module Make (N : Mirage_net.S)
(E : Ethernet.S)
(R : Mirage_random.S)
(T : Mirage_time.S)
(C : Mirage_clock.MCLOCK) = struct
type ipaddr = Ipaddr.V6.t
type callback = src:ipaddr -> dst:ipaddr -> Cstruct.t -> unit Lwt.t
Expand Down Expand Up @@ -56,7 +55,7 @@ module Make (N : Mirage_net.S)
| Some u, _ -> Lwt.wakeup_later u (); None
in
Lwt_list.iter_s (output_ign t) outs (* MCP: replace with propagation *) >>= fun () ->
T.sleep_ns (Duration.of_sec 1) >>= fun () ->
Mirage_time.sleep_ns (Duration.of_sec 1) >>= fun () ->
loop u
in
loop (Some u)
Expand Down Expand Up @@ -155,7 +154,7 @@ module Make (N : Mirage_net.S)
~ipv4:(fun _ -> Lwt.return_unit)
~ipv6:(input t ~tcp:noop ~udp:noop ~default:(fun ~proto:_ -> noop))
in
let timeout = T.sleep_ns (Duration.of_sec 3) in
let timeout = Mirage_time.sleep_ns (Duration.of_sec 3) in
Lwt.pick [
(* MCP: replace this error swallowing with proper propagation *)
(Lwt_list.iter_s (output_ign t) outs >>= fun () ->
Expand Down
1 change: 0 additions & 1 deletion src/ipv6/ipv6.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
module Make (N : Mirage_net.S)
(E : Ethernet.S)
(R : Mirage_random.S)
(T : Mirage_time.S)
(Clock : Mirage_clock.MCLOCK) : sig
include Tcpip.Ip.S with type ipaddr = Ipaddr.V6.t
val connect :
Expand Down
1 change: 0 additions & 1 deletion src/stack-direct/tcpip_stack_direct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ module IPV4V6 (Ipv4 : Tcpip.Ip.S with type ipaddr = Ipaddr.V4.t) (Ipv6 : Tcpip.I
end

module MakeV4V6
(Time : Mirage_time.S)
(Random : Mirage_random.S)
(Netif : Mirage_net.S)
(Eth : Ethernet.S)
Expand Down
1 change: 0 additions & 1 deletion src/stack-direct/tcpip_stack_direct.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module IPV4V6 (Ipv4 : Tcpip.Ip.S with type ipaddr = Ipaddr.V4.t) (Ipv6 : Tcpip.I
end

module MakeV4V6
(Time : Mirage_time.S)
(Random : Mirage_random.S)
(Netif : Mirage_net.S)
(Ethernet : Ethernet.S)
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/ack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ end


(* Delayed ACKs *)
module Delayed (Time:Mirage_time.S) : M = struct
module Delayed : M = struct

module TT = Tcptimer.Make(Time)
module TT = Tcptimer.Make

type delayed_r = {
send_ack: Sequence.t Lwt_mvar.t;
Expand Down
2 changes: 1 addition & 1 deletion src/tcp/ack.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ end

module Immediate : M

module Delayed(T:Mirage_time.S) : M
module Delayed : M
14 changes: 7 additions & 7 deletions src/tcp/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ open Lwt.Infix
let src = Logs.Src.create "tcp.pcb" ~doc:"Mirage TCP PCB module"
module Log = (val Logs.src_log src : Logs.LOG)

module Make(Ip: Tcpip.Ip.S)(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK)(Random:Mirage_random.S) =
module Make(Ip: Tcpip.Ip.S)(Clock:Mirage_clock.MCLOCK)(Random:Mirage_random.S) =
struct

module ACK = Ack.Immediate
module RXS = Segment.Rx(Time)(ACK)
module TXS = Segment.Tx(Time)(Clock)
module UTX = User_buffer.Tx(Time)(Clock)
module RXS = Segment.Rx(ACK)
module TXS = Segment.Tx(Clock)
module UTX = User_buffer.Tx(Clock)
module WIRE = Wire.Make(Ip)
module STATE = State.Make(Time)
module KEEPALIVE = Keepalive.Make(Time)(Clock)
module STATE = State.Make
module KEEPALIVE = Keepalive.Make(Clock)

type error = [ Tcpip.Tcp.error | WIRE.error]

Expand Down Expand Up @@ -678,7 +678,7 @@ struct
let rxtime = match count with
| 0 -> 3 | 1 -> 6 | 2 -> 12 | 3 -> 24 | _ -> 48
in
Time.sleep_ns (Duration.of_sec rxtime) >>= fun () ->
Mirage_time.sleep_ns (Duration.of_sec rxtime) >>= fun () ->
match hashtbl_find t.connects id with
| None -> Lwt.return_unit
| Some (wakener, isn, _) ->
Expand Down
1 change: 0 additions & 1 deletion src/tcp/flow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*)

module Make (IP:Tcpip.Ip.S)
(TM:Mirage_time.S)
(C:Mirage_clock.MCLOCK)
(R:Mirage_random.S) : sig
include Tcpip.Tcp.S with type ipaddr = IP.ipaddr
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/keepalive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let next ~configuration ~ns state =
end
end

module Make(T:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) = struct
module Make(Clock:Mirage_clock.MCLOCK) = struct
type t = {
configuration: Tcpip.Tcp.Keepalive.t;
callback: ([ `SendProbe | `Close ] -> unit Lwt.t);
Expand All @@ -64,7 +64,7 @@ let next ~configuration ~ns state =
let ns = Int64.sub (Clock.elapsed_ns ()) t.start in
match next ~configuration:t.configuration ~ns t.state with
| `Wait ns, state ->
T.sleep_ns ns >>= fun () ->
Mirage_time.sleep_ns ns >>= fun () ->
t.state <- state;
restart t
| `SendProbe, state ->
Expand Down
2 changes: 1 addition & 1 deletion src/tcp/keepalive.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ val next: configuration:Tcpip.Tcp.Keepalive.t -> ns:int64 -> state -> action * s
that we last received a packet [ns] nanoseconds ago and the new state
of the connection *)

module Make(T:Mirage_time.S)(Clock:Mirage_clock.MCLOCK): sig
module Make(Clock:Mirage_clock.MCLOCK): sig
type t
(** A keep-alive timer *)

Expand Down
10 changes: 5 additions & 5 deletions src/tcp/segment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ let rec reset_seq segs =
It also looks for control messages and dispatches them to
the Rtx queue to ack messages or close channels.
*)
module Rx(Time:Mirage_time.S)(ACK: Ack.M) = struct
module Rx(ACK: Ack.M) = struct
open Tcp_packet
module StateTick = State.Make(Time)
module StateTick = State.Make

(* Individual received TCP segment
TODO: this will change when IP fragments work *)
Expand Down Expand Up @@ -235,10 +235,10 @@ type tx_flags = (* At most one of Syn/Fin/Rst/Psh allowed *)
| Rst
| Psh

module Tx (Time:Mirage_time.S) (Clock:Mirage_clock.MCLOCK) = struct
module Tx (Clock:Mirage_clock.MCLOCK) = struct

module StateTick = State.Make(Time)
module TT = Tcptimer.Make(Time)
module StateTick = State.Make
module TT = Tcptimer.Make
module TX = Window.Make(Clock)

type ('a, 'b) xmit =
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/segment.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
the Rtx queue to ack messages or close channels.
*)

module Rx (T:Mirage_time.S)(ACK:Ack.M) : sig
module Rx (ACK:Ack.M) : sig

type segment = { header: Tcp_packet.t; payload: Cstruct.t }
(** Individual received TCP segment *)
Expand Down Expand Up @@ -57,7 +57,7 @@ type tx_flags = No_flags | Syn | Fin | Rst | Psh
(** Either Syn/Fin/Rst allowed, but not combinations *)

(** Pre-transmission queue *)
module Tx (Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) : sig
module Tx (Clock:Mirage_clock.MCLOCK) : sig

type ('a, 'b) xmit = flags:tx_flags -> wnd:Window.t -> options:Options.t list ->
seq:Sequence.t -> Cstruct.t -> ('a, 'b) result Lwt.t
Expand Down
6 changes: 3 additions & 3 deletions src/tcp/state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ let pp_tcpstate fmt = function

let pp fmt t = pf fmt "{ %a }" pp_tcpstate t.state

module Make(Time:Mirage_time.S) = struct
module Make = struct

let fin_wait_2_time = (* 60 *) Duration.of_sec 10
let time_wait_time = (* 30 *) Duration.of_sec 2

let rec finwait2timer t count timeout =
Log.debug (fun fmt -> fmt "finwait2timer %Lu" timeout);
Time.sleep_ns timeout >>= fun () ->
Mirage_time.sleep_ns timeout >>= fun () ->
match t.state with
| Fin_wait_2 i ->
Log.debug (fun f -> f "finwait2timer: Fin_wait_2");
Expand All @@ -116,7 +116,7 @@ module Make(Time:Mirage_time.S) = struct

let timewait t twomsl =
Log.debug (fun fmt -> fmt "timewait %Lu" twomsl);
Time.sleep_ns twomsl >>= fun () ->
Mirage_time.sleep_ns twomsl >>= fun () ->
t.state <- Closed;
Log.debug (fun fmt -> fmt "timewait on_close");
t.on_close ();
Expand Down
2 changes: 1 addition & 1 deletion src/tcp/state.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ val on_close : t -> unit

val pp: Format.formatter -> t -> unit

module Make(Time : Mirage_time.S) : sig
module Make : sig
val fin_wait_2_time : int64
val time_wait_time : int64
val finwait2timer : t -> int -> int64 -> unit Lwt.t
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/tcptimer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type t = {
mutable running: bool;
}

module Make(Time:Mirage_time.S) = struct
module Make = struct
let t ~period_ns ~expire =
let running = false in
{period_ns; expire; running}
Expand All @@ -42,7 +42,7 @@ module Make(Time:Mirage_time.S) = struct
Stats.incr_timer ();
let rec aux t s =
Log.debug (fun f -> f "timerloop: sleeping for %Lu ns" t.period_ns);
Time.sleep_ns t.period_ns >>= fun () ->
Mirage_time.sleep_ns t.period_ns >>= fun () ->
t.expire s >>= function
| Stoptimer ->
Stats.decr_timer ();
Expand Down
2 changes: 1 addition & 1 deletion src/tcp/tcptimer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type tr =
| Continue of Sequence.t
| ContinueSetPeriod of (time * Sequence.t)

module Make(T:Mirage_time.S) : sig
module Make : sig
val t : period_ns: time -> expire: (Sequence.t -> tr Lwt.t) -> t

val start : t -> ?p:time -> Sequence.t -> unit Lwt.t
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/user_buffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ end
to decide how to throttle or breakup its data production with this
information.
*)
module Tx(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) = struct
module Tx(Clock:Mirage_clock.MCLOCK) = struct

module TXS = Segment.Tx(Time)(Clock)
module TXS = Segment.Tx(Clock)

type t = {
wnd: Window.t;
Expand Down
4 changes: 2 additions & 2 deletions src/tcp/user_buffer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ module Rx : sig
val monitor: t -> int32 Lwt_mvar.t -> unit
end

module Tx(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) : sig
module Tx(Clock:Mirage_clock.MCLOCK) : sig

type t

module TXS : sig
type t = Segment.Tx(Time)(Clock).t
type t = Segment.Tx(Clock).t
val output : ?flags:Segment.tx_flags -> ?options:Options.t list -> t ->
Cstruct.t -> unit Lwt.t
end
Expand Down
2 changes: 1 addition & 1 deletion tcpip.opam
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ depends: [
"mirage-net" {>= "3.0.0"}
"mirage-clock" {>= "3.0.0"}
"mirage-random" {>= "2.0.0" & < "4.0.0"}
"mirage-time" {>= "2.0.0"}
"mirage-time" {>= "4.0.0"}
"ipaddr" {>= "5.0.0"}
"macaddr" {>="4.0.0"}
"macaddr-cstruct"
Expand Down
2 changes: 1 addition & 1 deletion test/low_level.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module VNETIF_STACK = Vnetif_common.VNETIF_STACK(Vnetif_backends.Basic)
module Time = Vnetif_common.Time
module V = Vnetif.Make(Vnetif_backends.Basic)
module E = Ethernet.Make(V)
module A = Arp.Make(E)(Time)
module A = Arp.Make(E)
module I = Static_ipv4.Make(Mirage_crypto_rng)(Vnetif_common.Clock)(E)(A)
module Wire = Tcp.Wire
module WIRE = Wire.Make(I)
Expand Down
4 changes: 2 additions & 2 deletions test/static_arp.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Lwt.Infix

module Make(E : Ethernet.S)(Time : Mirage_time.S) = struct
module A = Arp.Make(E)(Time)
module Make(E : Ethernet.S) = struct
module A = Arp.Make(E)
(* generally repurpose A, but substitute input and query, and add functions
for adding/deleting entries *)
type error = A.error
Expand Down
14 changes: 4 additions & 10 deletions test/test_deadlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@ module TCPIP =
struct
module RANDOM = Mirage_crypto_rng

module TIME =
struct
type 'a io = 'a Lwt.t
let sleep_ns nanos = Lwt_unix.sleep (Int64.to_float nanos /. 1e9)
end

module MCLOCK = Mclock

module M =
struct
module B = Basic_backend.Make
module NETIF = Vnetif.Make(B)
module ETHIF = Ethernet.Make(NETIF)
module ARPV4 = Arp.Make(ETHIF)(TIME)
module ARPV4 = Arp.Make(ETHIF)
module IPV4 = Static_ipv4.Make(RANDOM)(MCLOCK)(ETHIF)(ARPV4)
module IPV6 = Ipv6.Make(NETIF)(ETHIF)(RANDOM)(TIME)(MCLOCK)
module IPV6 = Ipv6.Make(NETIF)(ETHIF)(RANDOM)(MCLOCK)
module IP = Tcpip_stack_direct.IPV4V6(IPV4)(IPV6)
module ICMPV4 = Icmpv4.Make(IPV4)
module UDP = Udp.Make(IP)(RANDOM)
module TCP = Tcp.Flow.Make(IP)(TIME)(MCLOCK)(RANDOM)
module TCPIP = Tcpip_stack_direct.MakeV4V6(TIME)(RANDOM)(NETIF)(ETHIF)(ARPV4)(IP)(ICMPV4)(UDP)(TCP)
module TCP = Tcp.Flow.Make(IP)(MCLOCK)(RANDOM)
module TCPIP = Tcpip_stack_direct.MakeV4V6(RANDOM)(NETIF)(ETHIF)(ARPV4)(IP)(ICMPV4)(UDP)(TCP)
end
open M

Expand Down
2 changes: 1 addition & 1 deletion test/test_icmpv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Time = Vnetif_common.Time
module B = Basic_backend.Make
module V = Vnetif.Make(B)
module E = Ethernet.Make(V)
module Static_arp = Static_arp.Make(E)(Time)
module Static_arp = Static_arp.Make(E)

open Lwt.Infix

Expand Down
2 changes: 1 addition & 1 deletion test/test_ipv6.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module B = Vnetif_backends.Basic
module V = Vnetif.Make(B)
module E = Ethernet.Make(V)

module Ipv6 = Ipv6.Make(V)(E)(Mirage_crypto_rng)(Time)(Mclock)
module Ipv6 = Ipv6.Make(V)(E)(Mirage_crypto_rng)(Mclock)
module Udp = Udp.Make(Ipv6)(Mirage_crypto_rng)
open Lwt.Infix

Expand Down
2 changes: 1 addition & 1 deletion test/test_udp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Time = Vnetif_common.Time
module B = Basic_backend.Make
module V = Vnetif.Make(B)
module E = Ethernet.Make(V)
module Static_arp = Static_arp.Make(E)(Time)
module Static_arp = Static_arp.Make(E)
module Ip = Static_ipv4.Make(Mirage_crypto_rng)(Mclock)(E)(Static_arp)
module Udp = Udp.Make(Ip)(Mirage_crypto_rng)

Expand Down
8 changes: 4 additions & 4 deletions test/vnetif_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ end
module V = Vnetif.Make(B)
module E = Ethernet.Make(V)

module A = Arp.Make(E)(Time)
module A = Arp.Make(E)
module Ip4 = Static_ipv4.Make(Mirage_crypto_rng)(Clock)(E)(A)
module Icmp4 = Icmpv4.Make(Ip4)
module Ip6 = Ipv6.Make(V)(E)(Mirage_crypto_rng)(Time)(Clock)
module Ip6 = Ipv6.Make(V)(E)(Mirage_crypto_rng)(Clock)
module Ip46 = Tcpip_stack_direct.IPV4V6(Ip4)(Ip6)
module U = Udp.Make(Ip46)(Mirage_crypto_rng)
module T = Tcp.Flow.Make(Ip46)(Time)(Clock)(Mirage_crypto_rng)
module T = Tcp.Flow.Make(Ip46)(Clock)(Mirage_crypto_rng)

module Stack =
Tcpip_stack_direct.MakeV4V6(Time)(Mirage_crypto_rng)(V)(E)(A)(Ip46)(Icmp4)(U)(T)
Tcpip_stack_direct.MakeV4V6(Mirage_crypto_rng)(V)(E)(A)(Ip46)(Icmp4)(U)(T)

let create_backend () =
B.create ()
Expand Down

0 comments on commit 220520e

Please sign in to comment.