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

mirage-time is variant now #125

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion charrua-client.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ depends: [
"macaddr" {>= "4.0.0"}
"mirage-random" {>= "2.0.0"}
"mirage-clock" {>= "3.0.0"}
"mirage-time" {>= "2.0.0"}
"mirage-time" {>= "4.0.0"}
"mirage-net" {>= "3.0.0"}
"duration"
"logs"
Expand Down
8 changes: 4 additions & 4 deletions client/lwt/dhcp_client_lwt.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let src = Logs.Src.create "dhcp_client_lwt"
module Log = (val Logs.src_log src : Logs.LOG)

module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S) = struct
module Make(Random : Mirage_random.S)(Net : Mirage_net.S) = struct
open Lwt.Infix

type lease = Dhcp_wire.pkt
Expand All @@ -25,7 +25,7 @@ module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S)
let c = ref client in

let rec do_renew c t =
Time.sleep_ns @@ Duration.of_sec t >>= fun () ->
Mirage_time.sleep_ns @@ Duration.of_sec t >>= fun () ->
match Dhcp_client.renew c with
| `Noop -> Log.debug (fun f -> f "Can't renew this lease; won't try"); Lwt.return_unit
| `Response (c, pkt) ->
Expand All @@ -44,7 +44,7 @@ module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S)
Log.err (fun f -> f "Failed to write initial lease discovery request: %a" Net.pp_error e);
Lwt.return_unit
| Ok () ->
Time.sleep_ns sleep_interval >>= fun () ->
Mirage_time.sleep_ns sleep_interval >>= fun () ->
match Dhcp_client.lease !c with
| Some _lease -> Lwt.return_unit
| None ->
Expand Down Expand Up @@ -81,7 +81,7 @@ module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S)
c := s;
match renew with
| true ->
Time.sleep_ns @@ Duration.of_sec 1800 >>= fun () ->
Mirage_time.sleep_ns @@ Duration.of_sec 1800 >>= fun () ->
do_renew !c 1800
| false ->
push None;
Expand Down
2 changes: 1 addition & 1 deletion client/lwt/dhcp_client_lwt.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S) : sig
module Make(Random : Mirage_random.S)(Net : Mirage_net.S) : sig
type lease = Dhcp_wire.pkt

type t = lease Lwt_stream.t
Expand Down
4 changes: 2 additions & 2 deletions client/mirage/dhcp_client_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ let config_of_lease lease =
| [] -> Some (network, None)
| hd::_ -> Some (network, Some hd)

module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S) = struct
module Make(Random : Mirage_random.S)(Net : Mirage_net.S) = struct
open Lwt.Infix

type t = (Ipaddr.V4.Prefix.t * Ipaddr.V4.t option) Lwt_stream.t

let connect ?(requests : Dhcp_wire.option_code list option) net =
let module Lwt_client = Dhcp_client_lwt.Make(Random)(Time)(Net) in
let module Lwt_client = Dhcp_client_lwt.Make(Random)(Net) in
Lwt_client.connect ~renew:false ?requests net >>= fun lease_stream ->
Lwt.return @@ Lwt_stream.filter_map config_of_lease lease_stream
end
2 changes: 1 addition & 1 deletion client/mirage/dhcp_client_mirage.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Network : Mirage_net.S) : sig
module Make(Random : Mirage_random.S)(Network : Mirage_net.S) : sig
type t = (Ipaddr.V4.Prefix.t * Ipaddr.V4.t option) Lwt_stream.t
val connect : ?requests:Dhcp_wire.option_code list
-> Network.t -> t Lwt.t
Expand Down
4 changes: 2 additions & 2 deletions client/mirage/dhcp_ipv4.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
open Lwt.Infix

module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) = struct
module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) = struct
(* for now, just wrap a static ipv4 *)
module DHCP = Dhcp_client_mirage.Make(R)(Time)(Network)
module DHCP = Dhcp_client_mirage.Make(R)(Network)
include Static_ipv4.Make(R)(C)(E)(Arp)
let connect net ethernet arp =
DHCP.connect net >>= fun dhcp ->
Expand Down
2 changes: 1 addition & 1 deletion client/mirage/dhcp_ipv4.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) : sig
module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) : sig
include Tcpip.Ip.S with type ipaddr = Ipaddr.V4.t
val connect : Network.t -> E.t -> Arp.t -> t Lwt.t
(** Connect to an ipv4 device using information from a DHCP lease. *)
Expand Down
8 changes: 1 addition & 7 deletions test/client/lwt/test_client_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ module No_random = struct
let generate ?g:_ n = Cstruct.create n
end

module No_time = struct
let sleep_ns n =
Format.printf "Ignoring request to wait %f seconds\n" (Duration.to_f n);
Lwt.pause ()
end

module No_net = struct
type error = Mirage_net.Net.error
let pp_error = Mirage_net.Net.pp_error
Expand Down Expand Up @@ -42,7 +36,7 @@ end

let keep_trying () =
Lwt_main.run @@ (
let module Client = Dhcp_client_lwt.Make(No_random)(No_time)(No_net) in
let module Client = Dhcp_client_lwt.Make(No_random)(No_net) in
let net = No_net.connect ~mac:(Macaddr.of_string_exn "c0:ff:ee:c0:ff:ee") () in
let test =
Client.connect net >>= Lwt_stream.get >|= function
Expand Down