diff --git a/.travis.yml b/.travis.yml index fc89119d8..96069f29c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,10 @@ sudo: false env: global: - POST_INSTALL_HOOK="sh ./.travis-ci.sh" - - EXTRA_REMOTES="https://github.com/mirage/mirage-dev.git" + - EXTRA_REMOTES="https://github.com/hannesm/mirage-dev.git#easy" - PACKAGE=tcpip matrix: - - DISTRO=alpine OCAML_VERSION=4.05 EXTRA_ENV="MIRAGE_MODE=xen" - - DISTRO=alpine OCAML_VERSION=4.06 EXTRA_ENV="MIRAGE_MODE=hvt" + - DISTRO=alpine OCAML_VERSION=4.06 EXTRA_ENV="MIRAGE_MODE=xen" - DISTRO=alpine OCAML_VERSION=4.07 EXTRA_ENV="MIRAGE_MODE=unix" - DISTRO=alpine OCAML_VERSION=4.08 EXTRA_ENV="MIRAGE_MODE=qubes" - DISTRO=alpine OCAML_VERSION=4.09 EXTRA_ENV="MIRAGE_MODE=virtio" diff --git a/examples/unikernel/services.ml b/examples/unikernel/services.ml index 9f2256e22..bc4aa47c3 100644 --- a/examples/unikernel/services.ml +++ b/examples/unikernel/services.ml @@ -1,6 +1,6 @@ open Lwt.Infix -module Main (S: Mirage_types_lwt.STACKV4) = struct +module Main (S: Mirage_stack.V4) = struct let report_and_close flow pp e message = let ip, port = S.TCPV4.dst flow in Logs.warn diff --git a/src/icmp/dune b/src/icmp/dune index 7d60a071b..e44427007 100644 --- a/src/icmp/dune +++ b/src/icmp/dune @@ -1,7 +1,6 @@ (library (name tcpip_icmpv4) (public_name tcpip.icmpv4) - (libraries mirage-protocols-lwt rresult logs tcpip mirage-profile tcpip.udp) - (preprocess - (pps ppx_cstruct)) + (libraries mirage-protocols rresult logs tcpip mirage-profile tcpip.udp) + (preprocess (pps ppx_cstruct)) (wrapped false)) diff --git a/src/icmp/icmpv4.ml b/src/icmp/icmpv4.ml index 4d0e3c628..c62c42074 100644 --- a/src/icmp/icmpv4.ml +++ b/src/icmp/icmpv4.ml @@ -3,10 +3,8 @@ open Lwt.Infix let src = Logs.Src.create "icmpv4" ~doc:"Mirage ICMPv4" module Log = (val Logs.src_log src : Logs.LOG) -module Make(IP : Mirage_protocols_lwt.IPV4) = struct +module Make(IP : Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t) = struct - type buffer = Cstruct.t - type 'a io = 'a Lwt.t type ipaddr = Ipaddr.V4.t type t = { diff --git a/src/icmp/icmpv4.mli b/src/icmp/icmpv4.mli index b7bea2b7c..2886c07c7 100644 --- a/src/icmp/icmpv4.mli +++ b/src/icmp/icmpv4.mli @@ -1,5 +1,5 @@ -module Make ( I:Mirage_protocols_lwt.IPV4 ) : sig - include Mirage_protocols_lwt.ICMPV4 +module Make (I:Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t) : sig + include Mirage_protocols.ICMP with type ipaddr = Ipaddr.V4.t - val connect : I.t -> t io + val connect : I.t -> t Lwt.t end diff --git a/src/ipv4/dune b/src/ipv4/dune index 363385bce..b59bf9cb7 100644 --- a/src/ipv4/dune +++ b/src/ipv4/dune @@ -1,8 +1,7 @@ (library (name tcpip_ipv4) (public_name tcpip.ipv4) - (libraries logs mirage-protocols-lwt ipaddr cstruct rresult tcpip + (libraries logs mirage-protocols ipaddr cstruct rresult tcpip tcpip.udp mirage-random mirage-clock randomconv lru) - (preprocess - (pps ppx_cstruct)) + (preprocess (pps ppx_cstruct)) (wrapped false)) diff --git a/src/ipv4/routing.ml b/src/ipv4/routing.ml index bbbf92fe4..466b37921 100644 --- a/src/ipv4/routing.ml +++ b/src/ipv4/routing.ml @@ -12,7 +12,7 @@ let mac_of_multicast ip = type routing_error = [ `Local | `Gateway ] -module Make(Log : Logs.LOG) (A : Mirage_protocols_lwt.ARP) = struct +module Make(Log : Logs.LOG) (A : Mirage_protocols.ARP) = struct open Lwt.Infix diff --git a/src/ipv4/static_ipv4.ml b/src/ipv4/static_ipv4.ml index 2919b05af..aea24ca64 100644 --- a/src/ipv4/static_ipv4.ml +++ b/src/ipv4/static_ipv4.ml @@ -19,7 +19,7 @@ open Lwt.Infix let src = Logs.Src.create "ipv4" ~doc:"Mirage IPv4" module Log = (val Logs.src_log src : Logs.LOG) -module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_protocols_lwt.ETHERNET) (Arpv4 : Mirage_protocols_lwt.ARP) = struct +module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_protocols.ETHERNET) (Arpv4 : Mirage_protocols.ARP) = struct module Routing = Routing.Make(Log)(Arpv4) (** IO operation errors *) @@ -28,17 +28,14 @@ module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot | #Mirage_protocols.Ip.error as e -> Mirage_protocols.Ip.pp_error ppf e | `Ethif e -> Ethernet.pp_error ppf e - type 'a io = 'a Lwt.t - type buffer = Cstruct.t type ipaddr = Ipaddr.V4.t - type callback = src:ipaddr -> dst:ipaddr -> buffer -> unit Lwt.t + type callback = src:ipaddr -> dst:ipaddr -> Cstruct.t -> unit Lwt.t let pp_ipaddr = Ipaddr.V4.pp type t = { ethif : Ethernet.t; arp : Arpv4.t; - clock : C.t; mutable ip: Ipaddr.V4.t; network: Ipaddr.V4.Prefix.t; mutable gateway: Ipaddr.V4.t option; @@ -149,7 +146,7 @@ module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot Log.debug (fun m -> m "dropping zero length IPv4 frame %a" Ipv4_packet.pp packet) ; Lwt.return_unit end else - let ts = C.elapsed_ns t.clock in + let ts = C.elapsed_ns () in match Fragments.process t.cache ts packet payload with | None -> Lwt.return_unit | Some (packet, payload) -> @@ -159,22 +156,12 @@ module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (Ethernet: Mirage_prot | Some `UDP -> udp ~src ~dst payload | Some `ICMP | None -> default ~proto:packet.proto ~src ~dst payload - let connect - ?(ip=Ipaddr.V4.any) - ?(network=Ipaddr.V4.Prefix.make 0 Ipaddr.V4.any) - ?(gateway=None) clock ethif arp = - match Ipaddr.V4.Prefix.mem ip network with - | false -> - Log.warn (fun f -> f "IPv4: ip %a is not in the prefix %a" - Ipaddr.V4.pp ip Ipaddr.V4.Prefix.pp network); - Lwt.fail_with "given IP is not in the network provided" - | true -> - Arpv4.set_ips arp [ip] >>= fun () -> - (* TODO currently hardcoded to 256KB, should be configurable - and maybe limited per-src/dst-ip as well? *) - let cache = Fragments.Cache.create ~random:true (1024 * 256) in - let t = { ethif; arp; ip; clock; network; gateway ; cache } in - Lwt.return t + let connect ~ip:(network, ip) ?gateway ethif arp = + Arpv4.set_ips arp [ip] >>= fun () -> + (* TODO currently hardcoded to 256KB, should be configurable + and maybe limited per-src/dst-ip as well? *) + let cache = Fragments.Cache.create ~random:true (1024 * 256) in + Lwt.return { ethif; arp; ip; network; gateway ; cache } let disconnect _ = Lwt.return_unit diff --git a/src/ipv4/static_ipv4.mli b/src/ipv4/static_ipv4.mli index 9b452cadb..702dafab2 100644 --- a/src/ipv4/static_ipv4.mli +++ b/src/ipv4/static_ipv4.mli @@ -14,16 +14,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make (R: Mirage_random.C) (C: Mirage_clock.MCLOCK) (E: Mirage_protocols_lwt.ETHERNET) (A: Mirage_protocols_lwt.ARP) : sig - include Mirage_protocols_lwt.IPV4 - val connect : - ?ip:Ipaddr.V4.t -> - ?network:Ipaddr.V4.Prefix.t -> - ?gateway:Ipaddr.V4.t option -> - C.t -> E.t -> A.t -> t Lwt.t - (** Connect to an ipv4 device. - Default ip is {!Ipaddr.V4.any} - Default network is {!Ipaddr.V4.any}/0 - Default gateway is None. *) +module Make (R: Mirage_random.S) (C: Mirage_clock.MCLOCK) (E: Mirage_protocols.ETHERNET) (A: Mirage_protocols.ARP) : sig + include Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t + val connect : ip:(Ipaddr.V4.Prefix.t * Ipaddr.V4.t) -> ?gateway:Ipaddr.V4.t -> + E.t -> A.t -> t Lwt.t + (** Connect to an ipv4 device. *) end diff --git a/src/ipv6/dune b/src/ipv6/dune index 228785386..9aa0cb4ec 100644 --- a/src/ipv6/dune +++ b/src/ipv6/dune @@ -1,9 +1,8 @@ (library (name tcpip_ipv6) (public_name tcpip.ipv6) - (libraries logs mirage-protocols-lwt mirage-time-lwt macaddr-cstruct - mirage-clock-lwt duration ipaddr cstruct rresult mirage-random tcpip + (libraries logs mirage-protocols mirage-time macaddr-cstruct + mirage-clock duration ipaddr cstruct rresult mirage-random tcpip randomconv) - (preprocess - (pps ppx_cstruct)) + (preprocess (pps ppx_cstruct)) (wrapped false)) diff --git a/src/ipv6/ipv6.ml b/src/ipv6/ipv6.ml index b1e2fedec..a57d51a95 100644 --- a/src/ipv6/ipv6.ml +++ b/src/ipv6/ipv6.ml @@ -21,20 +21,17 @@ module I = Ipaddr open Lwt.Infix -module Make (E : Mirage_protocols_lwt.ETHERNET) - (R : Mirage_random.C) - (T : Mirage_time_lwt.S) - (C : Mirage_clock_lwt.MCLOCK) = struct - type 'a io = 'a Lwt.t - type buffer = Cstruct.t +module Make (E : Mirage_protocols.ETHERNET) + (R : Mirage_random.S) + (T : Mirage_time.S) + (C : Mirage_clock.MCLOCK) = struct type ipaddr = Ipaddr.V6.t - type callback = src:ipaddr -> dst:ipaddr -> buffer -> unit Lwt.t + type callback = src:ipaddr -> dst:ipaddr -> Cstruct.t -> unit Lwt.t let pp_ipaddr = Ipaddr.V6.pp type t = { ethif : E.t; - clock : C.t; mutable ctx : Ndpv6.context } type error = [ Mirage_protocols.Ip.error | `Ethif of E.error ] @@ -50,7 +47,7 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) let start_ticking t = let rec loop () = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in let ctx, outs = Ndpv6.tick ~now t.ctx in t.ctx <- ctx; Lwt_list.iter_s (output_ign t) outs (* MCP: replace with propagation *) >>= fun () -> @@ -61,7 +58,7 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) let mtu t = E.mtu t.ethif - Ipv6_wire.sizeof_ipv6 let write t ?fragment:_ ?ttl:_ ?src:_ dst proto ?(size = 0) headerf bufs = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in (* TODO fragmentation! *) let payload = Cstruct.concat bufs in let size' = size + Cstruct.len payload in @@ -92,7 +89,7 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) Lwt_list.fold_left_s fail_any (Ok ()) outs let input t ~tcp ~udp ~default buf = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in let _, outs, actions = Ndpv6.handle ~now ~random:R.generate t.ctx buf in Lwt_list.iter_s (function | `Tcp (src, dst, buf) -> tcp ~src ~dst buf @@ -108,7 +105,7 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) let src t ~dst = Ndpv6.select_source t.ctx dst let set_ip t ip = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in let ctx, outs = Ndpv6.add_ip ~now t.ctx ip in t.ctx <- ctx; (* MCP: replace the below *) @@ -118,13 +115,13 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) Ndpv6.get_ip t.ctx let set_ip_gateways t ips = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in let ctx = Ndpv6.add_routers ~now t.ctx ips in t.ctx <- ctx; Lwt.return_unit let set_ip_netmask t pfx = - let now = C.elapsed_ns t.clock in + let now = C.elapsed_ns () in let ctx = Ndpv6.add_prefix ~now t.ctx pfx in t.ctx <- ctx; Lwt.return_unit @@ -145,11 +142,11 @@ module Make (E : Mirage_protocols_lwt.ETHERNET) | Some x -> f x >>= g | None -> g () - let connect ?ip ?netmask ?gateways ethif clock = + let connect ?ip ?netmask ?gateways ethif = Log.info (fun f -> f "IP6: Starting"); - let now = C.elapsed_ns clock in + let now = C.elapsed_ns () in let ctx, outs = Ndpv6.local ~now ~random:R.generate (E.mac ethif) in - let t = {ctx; clock; ethif} in + let t = {ctx; ethif} in (* MCP: replace this error swallowing with proper propagation *) Lwt_list.iter_s (output_ign t) outs >>= fun () -> (ip, Lwt_list.iter_s (set_ip t)) >>=? fun () -> diff --git a/src/ipv6/ipv6.mli b/src/ipv6/ipv6.mli index 59dcc541f..f548a0387 100644 --- a/src/ipv6/ipv6.mli +++ b/src/ipv6/ipv6.mli @@ -14,14 +14,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make (E : Mirage_protocols_lwt.ETHERNET) - (R : Mirage_random.C) - (T : Mirage_time_lwt.S) - (Clock : Mirage_clock_lwt.MCLOCK) : sig - include Mirage_protocols_lwt.IPV6 +module Make (E : Mirage_protocols.ETHERNET) + (R : Mirage_random.S) + (T : Mirage_time.S) + (Clock : Mirage_clock.MCLOCK) : sig + include Mirage_protocols.IP with type ipaddr = Ipaddr.V6.t val connect : ?ip:Ipaddr.V6.t list -> ?netmask:Ipaddr.V6.Prefix.t list -> ?gateways:Ipaddr.V6.t list -> - E.t -> Clock.t -> t Lwt.t + E.t -> t Lwt.t end diff --git a/src/stack-direct/dune b/src/stack-direct/dune index b64796956..6d8e46b50 100644 --- a/src/stack-direct/dune +++ b/src/stack-direct/dune @@ -1,5 +1,5 @@ (library (name tcpip_stack_direct) (public_name tcpip.stack-direct) - (libraries logs ipaddr lwt result fmt mirage-time-lwt mirage-random - mirage-protocols-lwt mirage-stack-lwt mirage-net-lwt ethernet)) + (libraries logs ipaddr lwt result fmt mirage-time mirage-random + mirage-protocols mirage-stack mirage-net ethernet)) diff --git a/src/stack-direct/tcpip_stack_direct.ml b/src/stack-direct/tcpip_stack_direct.ml index d4ffc023c..cce23aade 100644 --- a/src/stack-direct/tcpip_stack_direct.ml +++ b/src/stack-direct/tcpip_stack_direct.ml @@ -20,28 +20,24 @@ let src = Logs.Src.create "tcpip-stack-direct" ~doc:"Pure OCaml TCP/IP stack" module Log = (val Logs.src_log src : Logs.LOG) type direct_ipv4_input = src:Ipaddr.V4.t -> dst:Ipaddr.V4.t -> Cstruct.t -> unit Lwt.t -module type UDPV4_DIRECT = Mirage_protocols_lwt.UDPV4 - with type ipinput = direct_ipv4_input +module type UDPV4_DIRECT = Mirage_protocols.UDP + with type ipaddr = Ipaddr.V4.t + and type ipinput = direct_ipv4_input -module type TCPV4_DIRECT = Mirage_protocols_lwt.TCPV4 - with type ipinput = direct_ipv4_input +module type TCPV4_DIRECT = Mirage_protocols.TCP + with type ipaddr = Ipaddr.V4.t + and type ipinput = direct_ipv4_input module Make (Time : Mirage_time.S) - (Random : Mirage_random.C) - (Netif : Mirage_net_lwt.S) - (Ethernet : Mirage_protocols_lwt.ETHERNET) - (Arpv4 : Mirage_protocols_lwt.ARP) - (Ipv4 : Mirage_protocols_lwt.IPV4) - (Icmpv4 : Mirage_protocols_lwt.ICMPV4) + (Random : Mirage_random.S) + (Netif : Mirage_net.S) + (Ethernet : Mirage_protocols.ETHERNET) + (Arpv4 : Mirage_protocols.ARP) + (Ipv4 : Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t) + (Icmpv4 : Mirage_protocols.ICMP with type ipaddr = Ipaddr.V4.t) (Udpv4 : UDPV4_DIRECT) (Tcpv4 : TCPV4_DIRECT) = struct - type +'a io = 'a Lwt.t - type buffer = Cstruct.t - type ipv4addr = Ipaddr.V4.t - type tcpv4 = Tcpv4.t - type udpv4 = Udpv4.t - type ipv4 = Ipv4.t module UDPV4 = Udpv4 module TCPV4 = Tcpv4 diff --git a/src/stack-direct/tcpip_stack_direct.mli b/src/stack-direct/tcpip_stack_direct.mli index ed327692e..aec9acd08 100644 --- a/src/stack-direct/tcpip_stack_direct.mli +++ b/src/stack-direct/tcpip_stack_direct.mli @@ -15,27 +15,27 @@ *) type direct_ipv4_input = src:Ipaddr.V4.t -> dst:Ipaddr.V4.t -> Cstruct.t -> unit Lwt.t -module type UDPV4_DIRECT = Mirage_protocols_lwt.UDPV4 - with type ipinput = direct_ipv4_input -module type TCPV4_DIRECT = Mirage_protocols_lwt.TCPV4 - with type ipinput = direct_ipv4_input +module type UDPV4_DIRECT = Mirage_protocols.UDP + with type ipaddr = Ipaddr.V4.t + and type ipinput = direct_ipv4_input + +module type TCPV4_DIRECT = Mirage_protocols.TCP + with type ipaddr = Ipaddr.V4.t + and type ipinput = direct_ipv4_input module Make (Time : Mirage_time.S) - (Random : Mirage_random.C) - (Netif : Mirage_net_lwt.S) - (Ethernet : Mirage_protocols_lwt.ETHERNET) - (Arpv4 : Mirage_protocols_lwt.ARP) - (Ipv4 : Mirage_protocols_lwt.IPV4) - (Icmpv4 : Mirage_protocols_lwt.ICMPV4) + (Random : Mirage_random.S) + (Netif : Mirage_net.S) + (Ethernet : Mirage_protocols.ETHERNET) + (Arpv4 : Mirage_protocols.ARP) + (Ipv4 : Mirage_protocols.IP with type ipaddr = Ipaddr.V4.t) + (Icmpv4 : Mirage_protocols.ICMP with type ipaddr = Ipaddr.V4.t) (Udpv4 : UDPV4_DIRECT) (Tcpv4 : TCPV4_DIRECT) : sig - include Mirage_stack_lwt.V4 - with type udpv4 = Udpv4.t - and type tcpv4 = Tcpv4.t - and type ipv4 = Ipv4.t - and module IPV4 = Ipv4 + include Mirage_stack.V4 + with module IPV4 = Ipv4 and module TCPV4 = Tcpv4 and module UDPV4 = Udpv4 diff --git a/src/stack-unix/dune b/src/stack-unix/dune index 4f4f9ae84..f1dc1e1e8 100644 --- a/src/stack-unix/dune +++ b/src/stack-unix/dune @@ -4,21 +4,21 @@ (modules icmpv4_socket) (wrapped false) (libraries lwt.unix ipaddr.unix cstruct-lwt tcpip.icmpv4 - tcpip.ipv4 tcpip.ipv6 mirage-protocols-lwt)) + tcpip.ipv4 tcpip.ipv6 mirage-protocols)) (library (name udpv4_socket) (public_name tcpip.udpv4-socket) (modules udpv4_socket) (wrapped false) - (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols-lwt)) + (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols)) (library (name udpv6_socket) (public_name tcpip.udpv6-socket) (modules udpv6_socket) (wrapped false) - (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols-lwt)) + (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols)) (library (name tcp_socket_options) @@ -34,7 +34,7 @@ (modules tcpv4_socket tcp_socket) (wrapped false) (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols - mirage-protocols-lwt tcp_socket_options)) + tcp_socket_options)) (library (name tcpv6_socket) @@ -42,7 +42,7 @@ (modules tcpv6_socket) (wrapped false) (libraries lwt.unix ipaddr.unix cstruct-lwt fmt mirage-protocols - mirage-protocols-lwt tcpv4_socket tcp_socket_options)) + tcpv4_socket tcp_socket_options)) (library (name tcpip_stack_socket) @@ -51,4 +51,4 @@ (wrapped false) (libraries lwt.unix cstruct-lwt ipaddr.unix logs tcpip.tcpv4-socket tcpip.udpv4-socket tcpip.ipv4 tcpip.ipv6 tcpip.icmpv4 - mirage-protocols-lwt mirage-stack-lwt)) + mirage-protocols mirage-stack)) diff --git a/src/stack-unix/icmpv4_socket.ml b/src/stack-unix/icmpv4_socket.ml index 766913fde..82b7fa222 100644 --- a/src/stack-unix/icmpv4_socket.ml +++ b/src/stack-unix/icmpv4_socket.ml @@ -1,8 +1,6 @@ open Lwt.Infix type ipaddr = Ipaddr.V4.t -type buffer = Cstruct.t -type 'a io = 'a Lwt.t type t = unit diff --git a/src/stack-unix/icmpv4_socket.mli b/src/stack-unix/icmpv4_socket.mli index a9336d55b..bd3247313 100644 --- a/src/stack-unix/icmpv4_socket.mli +++ b/src/stack-unix/icmpv4_socket.mli @@ -1,8 +1,8 @@ -include Mirage_protocols_lwt.ICMPV4 +include Mirage_protocols.ICMP with type ipaddr = Ipaddr.V4.t -val connect : unit -> t io +val connect : unit -> t Lwt.t -val listen : t -> ipaddr -> (buffer -> unit io) -> unit io +val listen : t -> ipaddr -> (Cstruct.t -> unit Lwt.t) -> unit Lwt.t (** [listen t addr fn] attempts to create an unprivileged listener on IP address [addr]. When a packet is received, the callback [fn] will be called in a fresh background diff --git a/src/stack-unix/tcpip_stack_socket.ml b/src/stack-unix/tcpip_stack_socket.ml index 38de74bff..94b909e79 100644 --- a/src/stack-unix/tcpip_stack_socket.ml +++ b/src/stack-unix/tcpip_stack_socket.ml @@ -21,27 +21,19 @@ module Log = (val Logs.src_log src : Logs.LOG) type socket_ipv4_input = unit Lwt.t -module type UDPV4_SOCKET = Mirage_protocols_lwt.UDP +module type UDPV4_SOCKET = Mirage_protocols.UDP with type ipinput = socket_ipv4_input -module type TCPV4_SOCKET = Mirage_protocols_lwt.TCP +module type TCPV4_SOCKET = Mirage_protocols.TCP with type ipinput = socket_ipv4_input module Tcpv4 = Tcpv4_socket module Udpv4 = Udpv4_socket -type +'a io = 'a Lwt.t -type buffer = Cstruct.t -type ipv4addr = Ipaddr.V4.t - module TCPV4 = Tcpv4_socket module UDPV4 = Udpv4_socket module IPV4 = Ipv4_socket -type udpv4 = Udpv4_socket.t -type tcpv4 = Tcpv4_socket.t -type ipv4 = Ipaddr.V4.t option - type t = { udpv4 : Udpv4.t; tcpv4 : Tcpv4.t; diff --git a/src/stack-unix/tcpip_stack_socket.mli b/src/stack-unix/tcpip_stack_socket.mli index 604f374fd..23968e956 100644 --- a/src/stack-unix/tcpip_stack_socket.mli +++ b/src/stack-unix/tcpip_stack_socket.mli @@ -14,11 +14,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -include Mirage_stack_lwt.V4 - with type tcpv4 = Tcpv4_socket.t - and type udpv4 = Udpv4_socket.t - and type ipv4 = Ipaddr.V4.t option - and module UDPV4 = Udpv4_socket +include Mirage_stack.V4 + with module UDPV4 = Udpv4_socket and module TCPV4 = Tcpv4_socket and module IPV4 = Ipv4_socket val connect : Ipaddr.V4.t list -> Udpv4_socket.t -> Tcpv4_socket.t -> t Lwt.t diff --git a/src/stack-unix/tcpv4_socket.ml b/src/stack-unix/tcpv4_socket.ml index 28664a146..9f150c9e1 100644 --- a/src/stack-unix/tcpv4_socket.ml +++ b/src/stack-unix/tcpv4_socket.ml @@ -16,11 +16,9 @@ open Lwt -type buffer = Cstruct.t type ipaddr = Ipaddr.V4.t type flow = Lwt_unix.file_descr -type +'a io = 'a Lwt.t -type ipinput = unit io +type ipinput = unit Lwt.t type t = { interface: Unix.inet_addr option; (* source ip to bind to *) diff --git a/src/stack-unix/tcpv4_socket.mli b/src/stack-unix/tcpv4_socket.mli index 52eab7e2d..2ea3dc8d2 100644 --- a/src/stack-unix/tcpv4_socket.mli +++ b/src/stack-unix/tcpv4_socket.mli @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -include Mirage_protocols_lwt.TCP +include Mirage_protocols.TCP with type ipaddr = Ipaddr.V4.t and type ipinput = unit Lwt.t and type flow = Lwt_unix.file_descr diff --git a/src/stack-unix/tcpv6_socket.ml b/src/stack-unix/tcpv6_socket.ml index 9be50ef44..45f40c440 100644 --- a/src/stack-unix/tcpv6_socket.ml +++ b/src/stack-unix/tcpv6_socket.ml @@ -15,13 +15,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -open Lwt +open Lwt.Infix -type buffer = Cstruct.t type ipaddr = Ipaddr.V6.t type flow = Lwt_unix.file_descr -type +'a io = 'a Lwt.t -type ipinput = unit io +type ipinput = unit Lwt.t type t = { interface: Unix.inet_addr option; (* source ip to bind to *) @@ -33,7 +31,7 @@ let connect addr = | None -> { interface=None } | Some ip -> { interface=Some (Ipaddr_unix.V6.to_inet_addr ip) } in - return t + Lwt.return t let dst fd = match Lwt_unix.getpeername fd with @@ -55,9 +53,9 @@ let create_connection ?keepalive _t (dst,dst_port) = | None -> () | Some { Mirage_protocols.Keepalive.after; interval; probes } -> Tcp_socket_options.enable_keepalive ~fd ~after ~interval ~probes ); - return (Ok fd)) + Lwt.return (Ok fd)) (fun exn -> Lwt.catch (fun () -> Lwt_unix.close fd) (fun _ -> Lwt.return_unit) >>= fun () -> - return (Error (`Exn exn))) + Lwt.return (Error (`Exn exn))) include Tcp_socket diff --git a/src/stack-unix/tcpv6_socket.mli b/src/stack-unix/tcpv6_socket.mli index a5307f305..ae483bfc3 100644 --- a/src/stack-unix/tcpv6_socket.mli +++ b/src/stack-unix/tcpv6_socket.mli @@ -15,11 +15,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -include Mirage_protocols_lwt.TCP +include Mirage_protocols.TCP with type ipaddr = Ipaddr.V6.t and type ipinput = unit Lwt.t and type flow = Lwt_unix.file_descr and type error = [ Mirage_protocols.Tcp.error | `Exn of exn ] and type write_error = [ Mirage_protocols.Tcp.write_error | `Exn of exn ] -val connect : Ipaddr.V6.t option -> t io +val connect : Ipaddr.V6.t option -> t Lwt.t diff --git a/src/stack-unix/udpv4_socket.ml b/src/stack-unix/udpv4_socket.ml index 4c14f3e41..6c9dfbc42 100644 --- a/src/stack-unix/udpv4_socket.ml +++ b/src/stack-unix/udpv4_socket.ml @@ -14,15 +14,13 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -open Lwt +open Lwt.Infix -type buffer = Cstruct.t type ipaddr = Ipaddr.V4.t type flow = Lwt_unix.file_descr -type +'a io = 'a Lwt.t type ip = Ipaddr.V4.t option (* source ip and port *) type ipinput = unit Lwt.t -type callback = src:ipaddr -> dst:ipaddr -> src_port:int -> buffer -> unit io +type callback = src:ipaddr -> dst:ipaddr -> src_port:int -> Cstruct.t -> unit Lwt.t type t = { interface: Unix.inet_addr; (* source ip to bind to *) @@ -53,10 +51,9 @@ let connect (id:ip) = | None -> Ipaddr_unix.V4.to_inet_addr Ipaddr.V4.any | Some ip -> Ipaddr_unix.V4.to_inet_addr ip in { interface; listen_fds } - in return t + in Lwt.return t -let disconnect _ = - return_unit +let disconnect _ = Lwt.return_unit let id { interface; _ } = Some (Ipaddr_unix.V4.of_inet_addr_exn interface) @@ -72,8 +69,8 @@ let write ?src_port ?ttl:_ttl ~dst ~dst_port t buf = let rec write_to_fd fd buf = Lwt_cstruct.sendto fd buf [] (ADDR_INET ((Ipaddr_unix.V4.to_inet_addr dst), dst_port)) >>= function - | n when n = Cstruct.len buf -> return @@ Ok () - | 0 -> return @@ Error `Sendto_failed + | n when n = Cstruct.len buf -> Lwt.return @@ Ok () + | 0 -> Lwt.return @@ Error `Sendto_failed | n -> write_to_fd fd (Cstruct.sub buf n (Cstruct.len buf - n)) (* keep trying *) in ( match src_port with diff --git a/src/tcp/ack.ml b/src/tcp/ack.ml index ff33a91fb..d12b99dda 100644 --- a/src/tcp/ack.ml +++ b/src/tcp/ack.ml @@ -61,7 +61,7 @@ end (* Delayed ACKs *) -module Delayed (Time:Mirage_time_lwt.S) : M = struct +module Delayed (Time:Mirage_time.S) : M = struct module TT = Tcptimer.Make(Time) diff --git a/src/tcp/ack.mli b/src/tcp/ack.mli index 0c8260c82..5204cf913 100644 --- a/src/tcp/ack.mli +++ b/src/tcp/ack.mli @@ -26,4 +26,4 @@ end module Immediate : M -module Delayed(T:Mirage_time_lwt.S) : M +module Delayed(T:Mirage_time.S) : M diff --git a/src/tcp/dune b/src/tcp/dune index b3d1fef29..997de9caf 100644 --- a/src/tcp/dune +++ b/src/tcp/dune @@ -1,8 +1,7 @@ (library (name tcp) (public_name tcpip.tcp) - (libraries logs mirage-protocols-lwt ipaddr cstruct lwt-dllist rresult - mirage-profile tcpip duration randomconv fmt mirage-time-lwt + (libraries logs mirage-protocols ipaddr cstruct lwt-dllist rresult + mirage-profile tcpip duration randomconv fmt mirage-time mirage-clock mirage-random) - (preprocess - (pps ppx_cstruct))) + (preprocess (pps ppx_cstruct))) diff --git a/src/tcp/flow.ml b/src/tcp/flow.ml index 027931951..2e79b3420 100644 --- a/src/tcp/flow.ml +++ b/src/tcp/flow.ml @@ -20,7 +20,7 @@ open Lwt.Infix let src = Logs.Src.create "pcb" ~doc:"Mirage TCP PCB module" module Log = (val Logs.src_log src : Logs.LOG) -module Make(Ip:Mirage_protocols_lwt.IP)(Time:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK)(Random:Mirage_random.C) = +module Make(Ip:Mirage_protocols.IP)(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK)(Random:Mirage_random.S) = struct module RXS = Segment.Rx(Time) @@ -71,7 +71,6 @@ struct type t = { ip : Ip.t; - clock : Clock.t; mutable localport : int; channels: (WIRE.t, connection) Hashtbl.t; (* server connections the process of connecting - SYN-ACK sent @@ -353,7 +352,7 @@ struct let on_close () = clearpcb t id tx_isn in let state = State.t ~on_close in let txq, _tx_t = - TXS.create ~clock:t.clock ~xmit:(Tx.xmit_pcb t.ip id) ~wnd ~state ~rx_ack ~tx_ack ~tx_wnd_update + TXS.create ~xmit:(Tx.xmit_pcb t.ip id) ~wnd ~state ~rx_ack ~tx_ack ~tx_wnd_update in (* The user application transmit buffer *) let utx = UTX.create ~wnd ~txq ~max_size:16384l in @@ -369,7 +368,7 @@ struct Log.warn (fun f -> f "using keep-alives can cause excessive memory consumption: https://github.com/mirage/mirage-tcpip/issues/367"); emitted_keepalive_warning := true end; - Some (KEEPALIVE.create config (keepalive_cb t id wnd state urx) t.clock) in + Some (KEEPALIVE.create config (keepalive_cb t id wnd state urx)) in (* Construct basic PCB in Syn_received state *) let pcb = { state; rxq; txq; wnd; id; ack; urx; utx; keepalive } in (* Compose the overall thread from the various tx/rx threads @@ -720,14 +719,14 @@ struct | Ok (fl, _) -> Lwt.return (Ok fl) (* Construct the main TCP thread *) - let connect ip clock = + let connect ip = let localport = 1024 + (Randomconv.int ~bound:(0xFFFF - 1024) Random.generate) in let listens = Hashtbl.create 1 in let connects = Hashtbl.create 1 in let channels = Hashtbl.create 7 in - Lwt.return { clock; ip; localport; channels; listens; connects } + Lwt.return { ip; localport; channels; listens; connects } let disconnect _ = Lwt.return_unit end diff --git a/src/tcp/flow.mli b/src/tcp/flow.mli index 521ce26c7..8d8a6221e 100644 --- a/src/tcp/flow.mli +++ b/src/tcp/flow.mli @@ -14,12 +14,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make (IP:Mirage_protocols_lwt.IP) - (TM:Mirage_time_lwt.S) +module Make (IP:Mirage_protocols.IP) + (TM:Mirage_time.S) (C:Mirage_clock.MCLOCK) - (R:Mirage_random.C) : sig - include Mirage_protocols_lwt.TCP + (R:Mirage_random.S) : sig + include Mirage_protocols.TCP with type ipaddr = IP.ipaddr and type ipinput = src:IP.ipaddr -> dst:IP.ipaddr -> Cstruct.t -> unit Lwt.t - val connect : IP.t -> C.t -> t Lwt.t + val connect : IP.t -> t Lwt.t end diff --git a/src/tcp/keepalive.ml b/src/tcp/keepalive.ml index 71c967d63..43e6bf701 100644 --- a/src/tcp/keepalive.ml +++ b/src/tcp/keepalive.ml @@ -49,11 +49,10 @@ let next ~configuration ~ns state = end end - module Make(T:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK) = struct + module Make(T:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) = struct type t = { configuration: Mirage_protocols.Keepalive.t; callback: ([ `SendProbe | `Close ] -> unit Lwt.t); - clock: Clock.t; mutable state: state; mutable timer: unit Lwt.t; mutable start: int64; @@ -62,7 +61,7 @@ let next ~configuration ~ns state = let rec restart t = let open Lwt.Infix in - let ns = Int64.sub (Clock.elapsed_ns t.clock) t.start in + 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 () -> @@ -76,16 +75,16 @@ let next ~configuration ~ns state = t.callback `Close >>= fun () -> Lwt.return_unit - let create configuration callback clock = + let create configuration callback = let state = alive in let timer = Lwt.return_unit in - let start = Clock.elapsed_ns clock in - let t = { configuration; callback; clock; state; timer; start } in + let start = Clock.elapsed_ns () in + let t = { configuration; callback; state; timer; start } in t.timer <- restart t; t let refresh t = - t.start <- Clock.elapsed_ns t.clock; + t.start <- Clock.elapsed_ns (); t.state <- alive; Lwt.cancel t.timer; t.timer <- restart t diff --git a/src/tcp/keepalive.mli b/src/tcp/keepalive.mli index 73871fa97..d638ae791 100644 --- a/src/tcp/keepalive.mli +++ b/src/tcp/keepalive.mli @@ -44,11 +44,11 @@ val next: configuration:Mirage_protocols.Keepalive.t -> ns:int64 -> state -> act that we last received a packet [ns] nanoseconds ago and the new state of the connection *) -module Make(T:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK): sig +module Make(T:Mirage_time.S)(Clock:Mirage_clock.MCLOCK): sig type t (** A keep-alive timer *) - val create: Mirage_protocols.Keepalive.t -> ([ `SendProbe | `Close] -> unit Lwt.t) -> Clock.t -> t + val create: Mirage_protocols.Keepalive.t -> ([ `SendProbe | `Close] -> unit Lwt.t) -> t (** [create configuration f clock] returns a keep-alive timer which will call [f] in future depending on both the [configuration] and any calls to [refresh] *) diff --git a/src/tcp/segment.ml b/src/tcp/segment.ml index 3807f0113..8e1a6ecad 100644 --- a/src/tcp/segment.ml +++ b/src/tcp/segment.ml @@ -55,7 +55,7 @@ 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_lwt.S) = struct +module Rx(Time:Mirage_time.S) = struct open Tcp_packet module StateTick = State.Make(Time) @@ -232,7 +232,7 @@ type tx_flags = (* At most one of Syn/Fin/Rst/Psh allowed *) | Rst | Psh -module Tx (Time:Mirage_time_lwt.S) (Clock:Mirage_clock.MCLOCK) = struct +module Tx (Time:Mirage_time.S) (Clock:Mirage_clock.MCLOCK) = struct module StateTick = State.Make(Time) module TT = Tcptimer.Make(Time) @@ -266,7 +266,6 @@ module Tx (Time:Mirage_time_lwt.S) (Clock:Mirage_clock.MCLOCK) = struct with this queue *) tx_wnd_update: int Lwt_mvar.t; (* Received updates to the transmit window *) rexmit_timer: Tcptimer.t; (* Retransmission timer for this connection *) - clock: Clock.t; (* whom to ask for the time *) mutable dup_acks: int; (* dup ack count for re-xmits *) } @@ -350,7 +349,7 @@ module Tx (Time:Mirage_time_lwt.S) (Clock:Mirage_clock.MCLOCK) = struct let rec tx_ack_t () = let serviceack dupack ack_len seq win = let partleft = clearsegs q ack_len q.segs in - TX.tx_ack q.clock q.wnd (Sequence.sub seq partleft) win; + TX.tx_ack q.wnd (Sequence.sub seq partleft) win; match dupack || Window.fast_rec q.wnd with | true -> q.dup_acks <- q.dup_acks + 1; @@ -403,14 +402,14 @@ module Tx (Time:Mirage_time_lwt.S) (Clock:Mirage_clock.MCLOCK) = struct in tx_ack_t () - let create ~clock ~xmit ~wnd ~state ~rx_ack ~tx_ack ~tx_wnd_update = + let create ~xmit ~wnd ~state ~rx_ack ~tx_ack ~tx_wnd_update = let segs = Lwt_dllist.create () in let dup_acks = 0 in let expire = ontimer xmit state segs wnd in let period_ns = Window.rto wnd in let rexmit_timer = TT.t ~period_ns ~expire in let q = - { clock; xmit; wnd; state; rx_ack; segs; tx_wnd_update; + { xmit; wnd; state; rx_ack; segs; tx_wnd_update; rexmit_timer; dup_acks } in let t = rto_t q tx_ack in @@ -430,7 +429,7 @@ module Tx (Time:Mirage_time_lwt.S) (Clock:Mirage_clock.MCLOCK) = struct let seq = Window.tx_nxt wnd in let seg = { data; flags; seq } in let seq_len = len seg in - TX.tx_advance q.clock q.wnd seq_len; + TX.tx_advance q.wnd seq_len; (* Queue up segment just sent for retransmission if needed *) let q_rexmit () = match Sequence.(gt seq_len zero) with diff --git a/src/tcp/segment.mli b/src/tcp/segment.mli index 5b067edeb..605904343 100644 --- a/src/tcp/segment.mli +++ b/src/tcp/segment.mli @@ -24,7 +24,7 @@ the Rtx queue to ack messages or close channels. *) -module Rx (T:Mirage_time_lwt.S) : sig +module Rx (T:Mirage_time.S) : sig type segment = { header: Tcp_packet.t; payload: Cstruct.t } (** Individual received TCP segment *) @@ -56,7 +56,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_lwt.S)(Clock:Mirage_clock.MCLOCK) : sig +module Tx (Time:Mirage_time.S)(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 @@ -65,7 +65,7 @@ module Tx (Time:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK) : sig (** Queue of pre-transmission segments *) val create: - clock:Clock.t -> xmit:('a, 'b) xmit -> wnd:Window.t -> state:State.t -> + xmit:('a, 'b) xmit -> wnd:Window.t -> state:State.t -> rx_ack:Sequence.t Lwt_mvar.t -> tx_ack:(Sequence.t * int) Lwt_mvar.t -> tx_wnd_update:int Lwt_mvar.t -> t * unit Lwt.t diff --git a/src/tcp/state.ml b/src/tcp/state.ml index a8da439b5..0b486cd52 100644 --- a/src/tcp/state.ml +++ b/src/tcp/state.ml @@ -89,7 +89,7 @@ let pp_tcpstate fmt = function let pp fmt t = pf fmt "{ %a }" pp_tcpstate t.state -module Make(Time:Mirage_time_lwt.S) = struct +module Make(Time:Mirage_time.S) = struct let fin_wait_2_time = (* 60 *) Duration.of_sec 10 let time_wait_time = (* 30 *) Duration.of_sec 2 diff --git a/src/tcp/state.mli b/src/tcp/state.mli index 2ccfd0350..2d3a89238 100644 --- a/src/tcp/state.mli +++ b/src/tcp/state.mli @@ -54,7 +54,7 @@ val t : on_close:close_cb -> t val pp: Format.formatter -> t -> unit -module Make(Time : Mirage_time_lwt.S) : sig +module Make(Time : Mirage_time.S) : sig val fin_wait_2_time : int64 val time_wait_time : int64 val finwait2timer : t -> int -> int64 -> unit Lwt.t diff --git a/src/tcp/tcptimer.ml b/src/tcp/tcptimer.ml index 5af4a863e..3899474af 100644 --- a/src/tcp/tcptimer.ml +++ b/src/tcp/tcptimer.ml @@ -32,7 +32,7 @@ type t = { mutable running: bool; } -module Make(Time:Mirage_time_lwt.S) = struct +module Make(Time:Mirage_time.S) = struct let t ~period_ns ~expire = let running = false in {period_ns; expire; running} diff --git a/src/tcp/tcptimer.mli b/src/tcp/tcptimer.mli index 547263c6e..25e3d8bb6 100644 --- a/src/tcp/tcptimer.mli +++ b/src/tcp/tcptimer.mli @@ -23,7 +23,7 @@ type tr = | Continue of Sequence.t | ContinueSetPeriod of (time * Sequence.t) -module Make(T:Mirage_time_lwt.S) : sig +module Make(T:Mirage_time.S) : sig val t : period_ns: time -> expire: (Sequence.t -> tr Lwt.t) -> t val start : t -> ?p:time -> Sequence.t -> unit Lwt.t diff --git a/src/tcp/user_buffer.ml b/src/tcp/user_buffer.ml index 94ecee67e..8675be495 100644 --- a/src/tcp/user_buffer.ml +++ b/src/tcp/user_buffer.ml @@ -111,7 +111,7 @@ end to decide how to throttle or breakup its data production with this information. *) -module Tx(Time:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK) = struct +module Tx(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) = struct module TXS = Segment.Tx(Time)(Clock) diff --git a/src/tcp/user_buffer.mli b/src/tcp/user_buffer.mli index 9d6b3825b..63f984d35 100644 --- a/src/tcp/user_buffer.mli +++ b/src/tcp/user_buffer.mli @@ -26,7 +26,7 @@ module Rx : sig val monitor: t -> int32 Lwt_mvar.t -> unit end -module Tx(Time:Mirage_time_lwt.S)(Clock:Mirage_clock.MCLOCK) : sig +module Tx(Time:Mirage_time.S)(Clock:Mirage_clock.MCLOCK) : sig type t diff --git a/src/tcp/window.ml b/src/tcp/window.ml index c26bbae6a..862a7195b 100644 --- a/src/tcp/window.ml +++ b/src/tcp/window.ml @@ -155,16 +155,16 @@ let tx_mss t = module Make(Clock:Mirage_clock.MCLOCK) = struct (* Advance transmitted packet sequence number *) - let tx_advance clock t b = + let tx_advance t b = if not t.rtt_timer_on && not t.fast_recovery then begin t.rtt_timer_on <- true; t.rtt_timer_seq <- t.tx_nxt; - t.rtt_timer_starttime <- Clock.elapsed_ns clock; + t.rtt_timer_starttime <- Clock.elapsed_ns (); end; t.tx_nxt <- Sequence.add t.tx_nxt b (* An ACK was received - use it to adjust cwnd *) - let tx_ack clock t r win = + let tx_ack t r win = set_tx_wnd t win; if t.fast_recovery then begin if Sequence.gt r t.snd_una then @@ -182,7 +182,7 @@ module Make(Clock:Mirage_clock.MCLOCK) = struct t.snd_una <- r; if t.rtt_timer_on && Sequence.gt r t.rtt_timer_seq then begin t.rtt_timer_on <- false; - let rtt_m = Int64.sub (Clock.elapsed_ns clock) t.rtt_timer_starttime in + let rtt_m = Int64.sub (Clock.elapsed_ns ()) t.rtt_timer_starttime in if t.rtt_timer_reset then begin t.rtt_timer_reset <- false; t.rttvar <- Int64.div rtt_m 2L; diff --git a/src/tcp/window.mli b/src/tcp/window.mli index 1f902df4b..eecaabc98 100644 --- a/src/tcp/window.mli +++ b/src/tcp/window.mli @@ -29,8 +29,8 @@ val rx_nxt : t -> Sequence.t val rx_nxt_inseq : t -> Sequence.t module Make(C:Mirage_clock.MCLOCK) : sig - val tx_advance : C.t -> t -> Sequence.t -> unit - val tx_ack: C.t -> t -> Sequence.t -> int -> unit + val tx_advance : t -> Sequence.t -> unit + val tx_ack: t -> Sequence.t -> int -> unit end val tx_nxt : t -> Sequence.t diff --git a/src/tcp/wire.ml b/src/tcp/wire.ml index 5d31f7a45..83ffcf4f1 100644 --- a/src/tcp/wire.ml +++ b/src/tcp/wire.ml @@ -20,7 +20,7 @@ module Log = (val Logs.src_log src : Logs.LOG) let count_tcp_to_ip = MProf.Counter.make ~name:"tcp-to-ip" -module Make (Ip:Mirage_protocols_lwt.IP) = struct +module Make (Ip:Mirage_protocols.IP) = struct type error = Mirage_protocols.Ip.error diff --git a/src/tcp/wire.mli b/src/tcp/wire.mli index 254ac05bb..726deb427 100644 --- a/src/tcp/wire.mli +++ b/src/tcp/wire.mli @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make (Ip:Mirage_protocols_lwt.IP) : sig +module Make (Ip:Mirage_protocols.IP) : sig type error = Mirage_protocols.Ip.error (** The type for TCP wire errors. *) diff --git a/src/udp/dune b/src/udp/dune index c482d48ef..8ed39f677 100644 --- a/src/udp/dune +++ b/src/udp/dune @@ -1,7 +1,6 @@ (library (name tcpip_udpv4) (public_name tcpip.udp) - (libraries mirage-protocols-lwt mirage-random rresult logs tcpip randomconv) - (preprocess - (pps ppx_cstruct)) + (libraries mirage-protocols mirage-random rresult logs tcpip randomconv) + (preprocess (pps ppx_cstruct)) (wrapped false)) diff --git a/src/udp/udp.ml b/src/udp/udp.ml index d00ab8b23..1d4c12977 100644 --- a/src/udp/udp.ml +++ b/src/udp/udp.ml @@ -19,12 +19,10 @@ open Lwt.Infix let src = Logs.Src.create "udp" ~doc:"Mirage UDP" module Log = (val Logs.src_log src : Logs.LOG) -module Make(Ip: Mirage_protocols_lwt.IP)(Random:Mirage_random.C) = struct +module Make(Ip: Mirage_protocols.IP)(Random:Mirage_random.S) = struct - type 'a io = 'a Lwt.t - type buffer = Cstruct.t type ipaddr = Ip.ipaddr - type ipinput = src:ipaddr -> dst:ipaddr -> buffer -> unit io + type ipinput = src:ipaddr -> dst:ipaddr -> Cstruct.t -> unit Lwt.t type callback = src:ipaddr -> dst:ipaddr -> src_port:int -> Cstruct.t -> unit Lwt.t type error = [ `Ip of Ip.error ] diff --git a/src/udp/udp.mli b/src/udp/udp.mli index 1dab3f6eb..21249cec0 100644 --- a/src/udp/udp.mli +++ b/src/udp/udp.mli @@ -15,8 +15,8 @@ *) -module Make (IP:Mirage_protocols_lwt.IP)(R:Mirage_random.C) : sig - include Mirage_protocols_lwt.UDP +module Make (IP:Mirage_protocols.IP)(R:Mirage_random.S) : sig + include Mirage_protocols.UDP with type ipaddr = IP.ipaddr and type ipinput = src:IP.ipaddr -> dst:IP.ipaddr -> Cstruct.t -> unit Lwt.t val connect : IP.t -> t Lwt.t diff --git a/tcpip.opam b/tcpip.opam index a473eef40..fa3e7c2f6 100644 --- a/tcpip.opam +++ b/tcpip.opam @@ -21,35 +21,33 @@ build: [ depopts: ["mirage-xen-ocaml"] depends: [ "dune" {>= "1.0"} - "ocaml" {>= "4.03.0"} + "ocaml" {>= "4.06.0"} "rresult" {>= "0.5.0"} "cstruct" {>= "3.2.0"} "cstruct-lwt" - "mirage-net-lwt" {>= "2.0.0"} - "mirage-clock" {>= "1.2.0"} - "mirage-random" {>= "1.0.0"} - "mirage-clock-lwt" {>= "1.2.0"} - "mirage-stack-lwt" {>= "1.3.0"} - "mirage-protocols" {>= "3.1.0"} - "mirage-protocols-lwt" {>= "3.1.0"} - "mirage-time-lwt" {>= "1.0.0"} + "mirage-net" {>= "3.0.0"} + "mirage-clock" {>= "3.0.0"} + "mirage-random" {>= "2.0.0"} + "mirage-stack" {>= "2.0.0"} + "mirage-protocols" {>= "4.0.0"} + "mirage-time" {>= "2.0.0"} "ipaddr" {>= "4.0.0"} "macaddr" {>="4.0.0"} "macaddr-cstruct" "mirage-profile" {>= "0.5"} "fmt" - "lwt" {>= "3.0.0"} + "lwt" {>= "4.0.0"} "lwt-dllist" "logs" {>= "0.6.0"} "duration" "randomconv" "ethernet" {>= "2.0.0"} - "mirage-flow" {with-test & >= "1.2.0"} - "mirage-vnetif" {with-test & >= "0.4.0"} + "mirage-flow" {with-test & >= "2.0.0"} + "mirage-vnetif" {with-test & >= "0.5.0"} "alcotest" {with-test & >="0.7.0"} "pcap-format" {with-test} - "mirage-clock-unix" {with-test & >= "1.2.0"} - "mirage-random-test" {with-test} + "mirage-clock-unix" {with-test & >= "3.0.0"} + "mirage-random-test" {with-test & >= "0.1.0"} "arp-mirage" {with-test & >= "2.0.0"} "lru" {>= "0.3.0"} ] diff --git a/test/dune b/test/dune index f70e1ad1e..8a1ee2b3b 100644 --- a/test/dune +++ b/test/dune @@ -2,8 +2,8 @@ (names test) (libraries alcotest mirage-random-test lwt.unix logs logs.fmt mirage-profile mirage-flow mirage-vnetif mirage-clock-unix - pcap-format duration mirage-random rresult mirage-protocols-lwt - mirage-stack-lwt arp arp-mirage ethernet tcpip.ipv4 tcpip.tcp tcpip.udp + pcap-format duration mirage-random rresult mirage-protocols + mirage-stack arp arp-mirage ethernet tcpip.ipv4 tcpip.tcp tcpip.udp tcpip.stack-direct tcpip.icmpv4 tcpip.udpv4-socket tcpip.tcpv4-socket tcpip.icmpv4-socket tcpip.stack-socket tcpip.ipv6)) diff --git a/test/static_arp.ml b/test/static_arp.ml index 7efc9ad58..5c0003253 100644 --- a/test/static_arp.ml +++ b/test/static_arp.ml @@ -1,19 +1,14 @@ open Lwt.Infix -module Make(E : Mirage_protocols_lwt.ETHERNET)(Time : Mirage_time_lwt.S) = struct +module Make(E : Mirage_protocols.ETHERNET)(Time : Mirage_time.S) = struct module A = Arp.Make(E)(Time) (* generally repurpose A, but substitute input and query, and add functions for adding/deleting entries *) type error = Mirage_protocols.Arp.error - type 'a io = 'a Lwt.t - type buffer = Cstruct.t - type macaddr = Macaddr.t - type ipaddr = Ipaddr.V4.t - type repr = string type t = { base : A.t; - table : (Ipaddr.V4.t, macaddr) Hashtbl.t; + table : (Ipaddr.V4.t, Macaddr.t) Hashtbl.t; } let pp_error = Mirage_protocols.Arp.pp_error @@ -22,16 +17,11 @@ module Make(E : Mirage_protocols_lwt.ETHERNET)(Time : Mirage_time_lwt.S) = struc let set_ips t = A.set_ips t.base let get_ips t = A.get_ips t.base - let to_repr t = - let print ip entry acc = - let key = Ipaddr.V4.to_string ip in - let entry = Macaddr.to_string entry in - Printf.sprintf "%sIP %s : MAC %s\n" acc key entry + let pp ppf t = + let print ip entry = + Fmt.pf ppf "IP %a : MAC %a" Ipaddr.V4.pp ip Macaddr.pp entry in - Lwt.return (Hashtbl.fold print t.table "") - - let pp fmt repr = - Format.fprintf fmt "%s" repr + Hashtbl.iter print t.table let connect e = A.connect e >>= fun base -> Lwt.return ({ base; table = (Hashtbl.create 7) }) diff --git a/test/test_connect.ml b/test/test_connect.ml index 3085f4dc3..bb9e2f7c4 100644 --- a/test/test_connect.ml +++ b/test/test_connect.ml @@ -25,10 +25,10 @@ module Log = (val Logs.src_log src : Logs.LOG) module Test_connect (B : Vnetif_backends.Backend) = struct module V = VNETIF_STACK (B) - let netmask = 24 - let gw = Some (Ipaddr.V4.of_string_exn "10.0.0.1") + let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" let client_ip = Ipaddr.V4.of_string_exn "10.0.0.101" let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" + let network = Ipaddr.V4.Prefix.make 24 client_ip let test_string = "Hello world from Mirage 123456789...." let backend = V.create_backend () @@ -62,17 +62,18 @@ module Test_connect (B : Vnetif_backends.Backend) = struct (Lwt_unix.sleep timeout >>= fun () -> failf "connect test timedout after %f seconds" timeout) ; - (V.create_stack backend server_ip netmask gw >>= fun s1 -> + (V.create_stack ~ip:(network, server_ip) ~gateway backend >>= fun s1 -> V.Stackv4.listen_tcpv4 s1 ~port:80 (fun f -> accept f test_string); V.Stackv4.listen s1) ; (Lwt_unix.sleep 0.1 >>= fun () -> - V.create_stack backend client_ip netmask gw >>= fun s2 -> + V.create_stack ~ip:(network, client_ip) ~gateway backend >>= fun s2 -> Lwt.pick [ V.Stackv4.listen s2; (let conn = V.Stackv4.TCPV4.create_connection (V.Stackv4.tcpv4 s2) in or_error "connect" conn (server_ip, 80) >>= fun flow -> Log.debug (fun f -> f "Connected to other end..."); + V.Stackv4.TCPV4.write flow (Cstruct.of_string test_string) >>= function | Error `Closed -> err_write_eof () | Error e -> err_write e diff --git a/test/test_deadlock.ml b/test/test_deadlock.ml index b3f0995ca..3437ad514 100644 --- a/test/test_deadlock.ml +++ b/test/test_deadlock.ml @@ -38,16 +38,15 @@ struct let server_ip = Ipaddr.V4.of_string_exn "192.168.10.10" let client_ip = Ipaddr.V4.of_string_exn "192.168.10.20" - let network = Ipaddr.V4.Prefix.of_string_exn "192.168.10.255/24" + let network = Ipaddr.V4.Prefix.make 24 server_ip - let make ~ip ~network ?gateway netif = - MCLOCK.connect () >>= fun clock -> + let make ~ip ?gateway netif = ETHIF.connect netif >>= fun ethif -> ARPV4.connect ethif >>= fun arpv4 -> - IPV4.connect ~ip ~network ?gateway clock ethif arpv4 >>= fun ipv4 -> + IPV4.connect ~ip:(network, ip) ?gateway ethif arpv4 >>= fun ipv4 -> ICMPV4.connect ipv4 >>= fun icmpv4 -> UDPV4.connect ipv4 >>= fun udpv4 -> - TCPV4.connect ipv4 clock >>= fun tcpv4 -> + TCPV4.connect ipv4 >>= fun tcpv4 -> TCPIP.connect netif ethif arpv4 ipv4 icmpv4 udpv4 tcpv4 >>= fun tcpip -> Lwt.return tcpip @@ -56,8 +55,8 @@ struct let tcpip t = t let make role netif = match role with - | `Server -> make ~ip:server_ip ~network netif - | `Client -> make ~ip:client_ip ~network netif + | `Server -> make ~ip:server_ip netif + | `Client -> make ~ip:client_ip netif type conn = M.NETIF.t diff --git a/test/test_icmpv4.ml b/test/test_icmpv4.ml index 98b9b1672..ebad83011 100644 --- a/test/test_icmpv4.ml +++ b/test/test_icmpv4.ml @@ -49,12 +49,10 @@ let get_stack ?(backend = B.create ~use_async_readers:true ~yield:(fun() -> Lwt_main.yield ()) ()) ip = let network = Ipaddr.V4.Prefix.make 24 listener_address in - let gateway = None in - Mclock.connect () >>= fun clock -> V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> Static_arp.connect ethif >>= fun arp -> - Ip.connect ~ip ~network ~gateway clock ethif arp >>= fun ip -> + Ip.connect ~ip:(network, ip) ethif arp >>= fun ip -> Icmp.connect ip >>= fun icmp -> Udp.connect ip >>= fun udp -> Lwt.return { backend; netif; ethif; arp; ip; icmp; udp } diff --git a/test/test_iperf.ml b/test/test_iperf.ml index fc322bdd6..5cb76fbf5 100644 --- a/test/test_iperf.ml +++ b/test/test_iperf.ml @@ -24,10 +24,9 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct module V = VNETIF_STACK (B) - let netmask = 24 - let gw = Some (Ipaddr.V4.of_string_exn "10.0.0.1") - let client_ip = Ipaddr.V4.of_string_exn "10.0.0.101" - let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" + let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" + let client_ip = Ipaddr.V4.Prefix.of_address_string_exn "10.0.0.101/24" + let server_ip = Ipaddr.V4.Prefix.of_address_string_exn "10.0.0.100/24" type stats = { mutable bytes: int64; @@ -45,8 +44,8 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct } let default_network ?(backend = B.create ()) () = - V.create_stack backend client_ip netmask gw >>= fun client -> - V.create_stack backend server_ip netmask gw >>= fun server -> + V.create_stack ~ip:client_ip ~gateway backend >>= fun client -> + V.create_stack ~ip:server_ip ~gateway backend >>= fun server -> Lwt.return {backend; server; client} let msg = @@ -118,11 +117,11 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct st.bin_packets <- 0L; Lwt.return_unit - let iperf clock _s server_done_u flow = + let iperf _s server_done_u flow = (* debug is too much for us here *) Logs.set_level ~all:true (Some Logs.Info); Logs.info (fun f -> f "Iperf server: Received connection."); - let t0 = Clock.elapsed_ns clock in + let t0 = Clock.elapsed_ns () in let st = { bytes=0L; packets=0L; bin_bytes=0L; bin_packets=0L; start_time = t0; last_time = t0 @@ -130,7 +129,7 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct let rec iperf_h flow = V.Stackv4.TCPV4.read flow >|= Rresult.R.get_ok >>= function | `Eof -> - let ts_now = Clock.elapsed_ns clock in + let ts_now = Clock.elapsed_ns () in st.bin_bytes <- st.bytes; st.bin_packets <- st.packets; st.last_time <- st.start_time; @@ -145,7 +144,7 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct st.packets <- (Int64.add st.packets 1L); st.bin_bytes <- (Int64.add st.bin_bytes (Int64.of_int l)); st.bin_packets <- (Int64.add st.bin_packets 1L); - let ts_now = Clock.elapsed_ns clock in + let ts_now = Clock.elapsed_ns () in (if (Int64.sub ts_now st.last_time >= 1L) then print_data st ts_now else @@ -180,8 +179,7 @@ module Test_iperf (B : Vnetif_backends.Backend) = struct (Logs.info (fun f -> f "I am server with IP %a, expecting connections on port %d" Ipaddr.V4.pp (V.Stackv4.IPV4.get_ip (V.Stackv4.ipv4 server_s) |> List.hd) port); - Mclock.connect () >>= fun clock -> - V.Stackv4.listen_tcpv4 server_s ~port (iperf clock server_s server_done_u); + V.Stackv4.listen_tcpv4 server_s ~port (iperf server_s server_done_u); Lwt.wakeup server_ready_u (); V.Stackv4.listen server_s) ] >>= fun () -> diff --git a/test/test_ipv6.ml b/test/test_ipv6.ml index 045c5c81c..57211068b 100644 --- a/test/test_ipv6.ml +++ b/test/test_ipv6.ml @@ -28,10 +28,9 @@ let get_stack backend address = let ip = [address] in let netmask = [Ipaddr.V6.Prefix.make 24 address] in let gateways = [] in - Mclock.connect () >>= fun clock -> V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> - Ipv6.connect ~ip ~netmask ~gateways ethif clock >>= fun ip -> + Ipv6.connect ~ip ~netmask ~gateways ethif >>= fun ip -> Udp.connect ip >>= fun udp -> Lwt.return { backend; netif; ethif; ip; udp } diff --git a/test/test_keepalive.ml b/test/test_keepalive.ml index d0330383b..834ed4c29 100644 --- a/test/test_keepalive.ml +++ b/test/test_keepalive.ml @@ -74,10 +74,10 @@ module Log = (val Logs.src_log src : Logs.LOG) module Test_connect = struct module V = VNETIF_STACK (Vnetif_backends.On_off_switch) - let netmask = 24 - let gw = Some (Ipaddr.V4.of_string_exn "10.0.0.1") + let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" let client_ip = Ipaddr.V4.of_string_exn "10.0.0.101" let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" + let network = Ipaddr.V4.Prefix.make 24 client_ip let backend = V.create_backend () let err_read_eof () = failf "accept got EOF while reading" @@ -101,12 +101,12 @@ module Test_connect = struct (Lwt_unix.sleep timeout >>= fun () -> failf "connect test timedout after %f seconds" timeout) ; - (V.create_stack backend server_ip netmask gw >>= fun s1 -> + (V.create_stack ~ip:(network, server_ip) ~gateway backend >>= fun s1 -> V.Stackv4.listen_tcpv4 s1 ~port:80 (fun f -> accept f); V.Stackv4.listen s1) ; (Lwt_unix.sleep 0.1 >>= fun () -> - V.create_stack backend client_ip netmask gw >>= fun s2 -> + V.create_stack ~ip:(network, client_ip) ~gateway backend >>= fun s2 -> Lwt.pick [ V.Stackv4.listen s2; let keepalive = { Mirage_protocols.Keepalive.after = 0L; interval = Duration.of_sec 1; probes = 3 } in diff --git a/test/test_mtus.ml b/test/test_mtus.ml index 45ed68db6..fef469ee5 100644 --- a/test/test_mtus.ml +++ b/test/test_mtus.ml @@ -1,16 +1,8 @@ open Lwt.Infix -module Server = struct - let ip = Ipaddr.V4.of_string_exn "192.168.1.254" - let netmask = 24 - let gateway = None -end - -module Client = struct - let ip = Ipaddr.V4.of_string_exn "192.168.1.10" - let netmask = 24 - let gateway = None -end +let server_ip = Ipaddr.V4.of_string_exn "192.168.1.254" +let client_ip = Ipaddr.V4.of_string_exn "192.168.1.10" +let network = Ipaddr.V4.Prefix.make 24 server_ip let server_port = 7 @@ -42,8 +34,8 @@ let read_one flow = let get_stacks ?client_mtu ?server_mtu backend = let or_default = function | None -> default_mtu | Some n -> n in let client_mtu, server_mtu = or_default client_mtu, or_default server_mtu in - Client.(Stack.create_stack backend ~mtu:client_mtu ip netmask gateway) >>= fun client -> - Server.(Stack.create_stack backend ~mtu:server_mtu ip netmask gateway) >>= fun server -> + Stack.create_stack ~ip:(network, client_ip) ~mtu:client_mtu backend >>= fun client -> + Stack.create_stack ~ip:(network, server_ip) ~mtu:server_mtu backend >>= fun server -> let max_mtu = max client_mtu server_mtu in Backend.set_mtu max_mtu; Lwt.return (server, client) @@ -53,7 +45,7 @@ let start_server ~f server = Stack.Stackv4.listen server let start_client client = - Stack.Stackv4.TCPV4.create_connection (Stack.Stackv4.tcpv4 client) (Server.ip, server_port) >>= function + Stack.Stackv4.TCPV4.create_connection (Stack.Stackv4.tcpv4 client) (server_ip, server_port) >>= function | Ok connection -> Lwt.return connection | Error e -> err_fail e diff --git a/test/test_rfc5961.ml b/test/test_rfc5961.ml index 7f6a8ca27..14b628858 100644 --- a/test/test_rfc5961.ml +++ b/test/test_rfc5961.ml @@ -37,8 +37,8 @@ module Sequence = Tcp.Sequence let sut_ip = Ipaddr.V4.of_string_exn "10.0.0.101" let server_ip = Ipaddr.V4.of_string_exn "10.0.0.100" -let netmask = 24 -let gateway = Some (Ipaddr.V4.of_string_exn "10.0.0.1") +let network = Ipaddr.V4.Prefix.make 24 server_ip +let gateway = Ipaddr.V4.of_string_exn "10.0.0.1" let header_size = Ethernet_wire.sizeof_ethernet @@ -47,14 +47,13 @@ let options = [] let window = 5120 let create_sut_stack backend = - VNETIF_STACK.create_stack backend sut_ip netmask gateway + VNETIF_STACK.create_stack ~ip:(network, sut_ip) ~gateway backend let create_raw_stack ip backend = - Mclock.connect () >>= fun clock -> V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> A.connect ethif >>= fun arpv4 -> - I.connect ~ip ~network:(Ipaddr.V4.Prefix.make netmask ip) ~gateway clock ethif arpv4 >>= fun ip -> + I.connect ~ip:(network, ip) ~gateway ethif arpv4 >>= fun ip -> Lwt.return (netif, ethif, arpv4, ip) type 'state fsm_result = diff --git a/test/test_tcp_window.ml b/test/test_tcp_window.ml index 0b23e5d01..996670249 100644 --- a/test/test_tcp_window.ml +++ b/test/test_tcp_window.ml @@ -1,22 +1,13 @@ -open Lwt.Infix - let now = ref 0L module Clock = struct - (* Mirage_device.S *) - type error = string - type t = unit - type 'a io = 'a Lwt.t - let disconnect _ = Lwt.return_unit - let connect () = Lwt.return_unit - (* Mirage_clock.MCLOCK *) let period_ns () = None let elapsed_ns () = !now (* Test-related function: advance by 1 ns *) let tick () = now := Int64.add !now 1L - let tick_for () duration = now := Int64.add !now duration + let tick_for duration = now := Int64.add !now duration end module Timed_window = Tcp.Window.Make(Clock) @@ -35,7 +26,7 @@ let fresh_window () = Alcotest.(check int64) "initial rto is 2/3 second" (Duration.of_ms 667) @@ Tcp.Window.rto window; Lwt.return_unit -let increase_congestion_window clock window goal = +let increase_congestion_window window goal = (* simulate a successful slow start, which primes the congestion window to be relatively large *) let receive_window = Tcp.Window.ack_win window in let rec successful_transmission goal = @@ -44,14 +35,14 @@ let increase_congestion_window clock window goal = | true -> max_send | false -> let sz = Tcp.Sequence.add max_send @@ Tcp.Window.tx_nxt window in - let clock = Clock.tick clock in - Timed_window.tx_advance clock window @@ Tcp.Window.tx_nxt window; - let clock = Clock.tick clock in + Clock.tick (); + Timed_window.tx_advance window @@ Tcp.Window.tx_nxt window; + Clock.tick (); (* need to acknowledge the full size of the data *) - Timed_window.tx_ack clock window sz receive_window; + Timed_window.tx_ack window sz receive_window; successful_transmission goal in - (clock, successful_transmission goal) + successful_transmission goal let n_segments window n = Int32.mul n @@ Int32.of_int @@ Tcp.Window.tx_mss window |> Tcp.Sequence.of_int32 @@ -59,37 +50,36 @@ let n_segments window n = (* attempt to ensure that fast recovery is working as described in rfc5681 *) let recover_fast () = let window = default_window () in - Clock.connect () >>= fun clock -> let receive_window = Tcp.Window.ack_win window in Alcotest.(check bool) "don't start in fast recovery" false @@ Tcp.Window.fast_rec window; (* get a large congestion window to avoid confounding factors *) let cwnd_goal = 262140l in - let clock, _ = increase_congestion_window clock window (Tcp.Sequence.of_int32 cwnd_goal) in + let _ = increase_congestion_window window (Tcp.Sequence.of_int32 cwnd_goal) in let available_to_send = Tcp.Window.tx_available window in let big_enough x = Int32.compare x cwnd_goal > 0 in Alcotest.(check bool) "congestion window is big enough" true @@ big_enough available_to_send; (* get ready to send another burst of data *) let seq = Tcp.Window.tx_nxt window in - let clock = Clock.tick clock in + Clock.tick (); (* say that we sent the full amount of data *) let sz = Tcp.Sequence.(add (of_int32 available_to_send) seq) in - Timed_window.tx_advance clock window @@ sz; + Timed_window.tx_advance window sz; (* but receive an ack indicating that we missed a segment *) let nonfull_ack = Tcp.Sequence.add seq @@ n_segments window 4l in (* 1st ack *) - let clock = Clock.tick clock in - Timed_window.tx_ack clock window nonfull_ack receive_window; + Clock.tick (); + Timed_window.tx_ack window nonfull_ack receive_window; (* 1st duplicate ack *) - let clock = Clock.tick clock in - Timed_window.tx_ack clock window nonfull_ack receive_window; + Clock.tick (); + Timed_window.tx_ack window nonfull_ack receive_window; (* 2nd duplicate ack *) - let clock = Clock.tick clock in - Timed_window.tx_ack clock window nonfull_ack receive_window; + Clock.tick (); + Timed_window.tx_ack window nonfull_ack receive_window; (* 3rd duplicate ack *) - let clock = Clock.tick clock in - Timed_window.tx_ack clock window nonfull_ack receive_window; + Clock.tick (); + Timed_window.tx_ack window nonfull_ack receive_window; (* request that we go into fast retransmission *) Tcp.Window.alert_fast_rexmit window @@ n_segments window 4l; @@ -104,22 +94,21 @@ let rto_calculation () = (* RFC 2988 2.1 *) Alcotest.(check int64) "initial rto is 2/3 second" (Duration.of_ms 667) @@ Tcp.Window.rto window; let receive_window = Tcp.Window.ack_win window in - Clock.connect () >>= fun clock -> - Timed_window.tx_advance clock window (Tcp.Window.tx_nxt window); - let clock = Clock.tick_for clock (Duration.of_ms 400) in + Timed_window.tx_advance window (Tcp.Window.tx_nxt window); + Clock.tick_for (Duration.of_ms 400); let max_size = Tcp.Window.tx_available window |> Tcp.Sequence.of_int32 in let sz = Tcp.Sequence.add max_size @@ (Tcp.Window.tx_nxt window) in - Timed_window.tx_ack clock window sz receive_window; + Timed_window.tx_ack window sz receive_window; (* RFC 2988 2.2 *) Alcotest.(check int64) "After one RTT measurement, the calculated rto is 400 + (4 * 200) = 1200ms" (Duration.of_ms 1200) @@ Tcp.Window.rto window; (* RFC 2988 2.3 *) - Timed_window.tx_advance clock window (Tcp.Window.tx_nxt window); + Timed_window.tx_advance window (Tcp.Window.tx_nxt window); let receive_window = Tcp.Window.ack_win window in - let clock = Clock.tick_for clock (Duration.of_ms 300) in + Clock.tick_for (Duration.of_ms 300); let max_size = Tcp.Window.tx_available window |> Tcp.Sequence.of_int32 in let sz = Tcp.Sequence.add max_size @@ (Tcp.Window.tx_nxt window) in - Timed_window.tx_ack clock window sz receive_window; + Timed_window.tx_ack window sz receive_window; Alcotest.(check int64) "After subsequent RTT measurement, the calculated rto is 1087.5ms" (Duration.of_us 1087500) @@ Tcp.Window.rto window; Lwt.return_unit diff --git a/test/test_udp.ml b/test/test_udp.ml index d1b4d7b95..1760a6b7a 100644 --- a/test/test_udp.ml +++ b/test/test_udp.ml @@ -9,7 +9,6 @@ module Ip = Static_ipv4.Make(Mirage_random_test)(Mclock)(E)(Static_arp) module Udp = Udp.Make(Ip)(Mirage_random_test) type stack = { - clock : Mclock.t; backend : B.t; netif : V.t; ethif : E.t; @@ -22,14 +21,12 @@ let get_stack ?(backend = B.create ~use_async_readers:true ~yield:(fun() -> Lwt_main.yield ()) ()) ip = let open Lwt.Infix in let network = Ipaddr.V4.Prefix.make 24 ip in - let gateway = None in - Mclock.connect () >>= fun clock -> V.connect backend >>= fun netif -> E.connect netif >>= fun ethif -> Static_arp.connect ethif >>= fun arp -> - Ip.connect ~ip ~network ~gateway clock ethif arp >>= fun ip -> + Ip.connect ~ip:(network, ip) ethif arp >>= fun ip -> Udp.connect ip >>= fun udp -> - Lwt.return { clock; backend; netif; ethif; arp; ip; udp } + Lwt.return { backend; netif; ethif; arp; ip; udp } let fails msg f args = match f args with diff --git a/test/vnetif_common.ml b/test/vnetif_common.ml index d92643c81..50dc78efe 100644 --- a/test/vnetif_common.ml +++ b/test/vnetif_common.ml @@ -33,14 +33,14 @@ sig type buffer type 'a io type id - module Stackv4 : Mirage_stack_lwt.V4 + module Stackv4 : Mirage_stack.V4 (** Create a new backend *) val create_backend : unit -> backend (** Create a new stack connected to an existing backend *) - val create_stack : backend -> ?mtu:int -> Ipaddr.V4.t -> int -> - Ipaddr.V4.t option -> Stackv4.t Lwt.t + val create_stack : ?mtu:int -> ip:(Ipaddr.V4.Prefix.t * Ipaddr.V4.t) -> + ?gateway:Ipaddr.V4.t -> backend -> Stackv4.t Lwt.t (** [create_stack backend ?mtu ip netmask gateway] adds a listener function to the backend *) @@ -75,17 +75,15 @@ struct let create_backend () = B.create () - let create_stack backend ?mtu ip netmask gw = + let create_stack ?mtu ~ip ?gateway backend = let size_limit = match mtu with None -> None | Some x -> Some x in - let network = Ipaddr.V4.Prefix.make netmask ip in - Clock.connect () >>= fun clock -> V.connect ?size_limit backend >>= fun netif -> E.connect netif >>= fun ethif -> A.connect ethif >>= fun arpv4 -> - Ip.connect ~ip ~network ~gateway:gw clock ethif arpv4 >>= fun ipv4 -> + Ip.connect ~ip ?gateway ethif arpv4 >>= fun ipv4 -> Icmp.connect ipv4 >>= fun icmpv4 -> U.connect ipv4 >>= fun udpv4 -> - T.connect ipv4 clock >>= fun tcpv4 -> + T.connect ipv4 >>= fun tcpv4 -> Stackv4.connect netif ethif arpv4 ipv4 icmpv4 udpv4 tcpv4 let create_backend_listener backend listenf =