Skip to content
Closed
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ script: bash -ex .travis-opam.sh
sudo: required
env:
global:
- EXTRA_REMOTES="https://github.com/mirage/mirage-dev.git"
- EXTRA_REMOTES="https://github.com/hannesm/mirage-dev.git#random"
- TESTS=false
- PINS="lwt.dev:https://github.com/mirage/lwt.git#tracing mirage-profile:https://github.com/mirage/mirage-profile.git"
matrix:
Expand Down
4 changes: 2 additions & 2 deletions ethifv4/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let main =
let packages = ["tcpip"] in
foreign
~libraries ~packages
"Unikernel.Main" (console @-> network @-> mclock @-> time @-> job)
"Unikernel.Main" (console @-> network @-> mclock @-> time @-> random @-> job)

let () =
register "ethifv4" [
main $ default_console $ tap0 $ default_monotonic_clock $ default_time
main $ default_console $ tap0 $ default_monotonic_clock $ default_time $ stdlib_random
]
8 changes: 4 additions & 4 deletions ethifv4/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ let green fmt = Printf.sprintf ("\027[32m"^^fmt^^"\027[m")
let yellow fmt = Printf.sprintf ("\027[33m"^^fmt^^"\027[m")
let blue fmt = Printf.sprintf ("\027[36m"^^fmt^^"\027[m")

module Main (C: CONSOLE) (N: NETWORK) (Clock : V1.MCLOCK) (Time: TIME) = struct
module Main (C: CONSOLE) (N: NETWORK) (Clock : V1.MCLOCK) (Time: TIME) (R : RANDOM) = struct

module E = Ethif.Make(N)
module A = Arpv4.Make(E)(Clock)(Time)
module I = Ipv4.Make(E)(A)
module U = Udp.Make(I)
module T = Tcp.Flow.Make(I)(Time)(Clock)(Random)
module D = Dhcp_clientv4.Make(Time)(Random)(U)
module T = Tcp.Flow.Make(I)(Time)(Clock)(R)
module D = Dhcp_clientv4.Make(Time)(R)(U)

let or_error _c name fn t =
fn t
>>= function
| `Error _e -> Lwt.fail (Failure ("Error starting " ^ name))
| `Ok t -> Lwt.return t

let start c net clock _time =
let start c net clock _time _r =
or_error c "Ethif" E.connect net
>>= fun e ->
or_error c "Arpv4" (A.connect e) clock
Expand Down
38 changes: 22 additions & 16 deletions lwt/src/config.ml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
open Mirage

let (name, main) =
try match Sys.getenv "TARGET" with
| "heads1" -> ("heads1", "Unikernels.Heads1")
| "heads2" -> ("heads2", "Unikernels.Heads2")
| "heads3" -> ("heads3", "Unikernels.Heads3")
let libraries = ["duration"; "randomconv"]
and packages = ["duration"; "randomconv"]

| "timeout1" -> ("timeout1", "Unikernels.Timeout1")
| "timeout2" -> ("timeout2", "Unikernels.Timeout2")
let () =
try match Sys.getenv "TARGET" with
| "heads1" ->
let main = foreign ~libraries ~packages "Unikernels.Heads1" (console @-> job) in
register "heads1" [ main $ default_console ]
| "heads2" ->
let main = foreign ~libraries ~packages "Unikernels.Heads2" (console @-> job) in
register "heads2" [ main $ default_console ]
| "heads3" ->
let main = foreign ~libraries ~packages "Unikernels.Heads3" (console @-> job) in
register "heads3" [ main $ default_console ]

| "echo_server1" -> ("echo_server1", "Unikernels.Echo_server1")
| "timeout1" ->
let main = foreign ~libraries ~packages "Unikernels.Timeout1" (console @-> random @-> job) in
register "timeout1" [ main $ default_console $ stdlib_random ]
| "timeout2" ->
let main = foreign ~libraries ~packages "Unikernels.Timeout2" (console @-> random @-> job) in
register "timeout2" [ main $ default_console $ stdlib_random ]

| "echo_server1" ->
let main = foreign ~libraries ~packages "Unikernels.Echo_server1" (console @-> random @-> job) in
register "echo_server1" [ main $ default_console $ stdlib_random ]
with Not_found -> failwith "Must specify target"

let () =
let main =
foreign
~libraries:["duration"] ~packages:["duration"]
main (console @-> job)
in
register name [ main $ default_console ]
22 changes: 10 additions & 12 deletions lwt/src/unikernels.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Heads3 (C: V1_LWT.CONSOLE) = struct

end

module Timeout1 (C: V1_LWT.CONSOLE) = struct
module Timeout1 (C: V1_LWT.CONSOLE) (R: V1_LWT.RANDOM) = struct

let timeout delay t =
Time.sleep_ns delay >>= fun () ->
Expand All @@ -48,16 +48,15 @@ module Timeout1 (C: V1_LWT.CONSOLE) = struct
| Lwt.Return v -> Lwt.return (Some v)
| Lwt.Fail ex -> Lwt.fail ex

let start c =
Random.self_init ();
let t = Time.sleep_ns (Duration.of_ms (Random.int 3000)) >|= fun () -> "Heads" in
let start c _r =
let t = Time.sleep_ns (Duration.of_ms (Randomconv.int ~bound:3000 R.generate)) >|= fun () -> "Heads" in
timeout (Duration.of_sec 2) t >>= function
| None -> C.log_s c "Cancelled"
| Some v -> C.log_s c (Printf.sprintf "Returned %S" v)

end

module Timeout2 (C: V1_LWT.CONSOLE) = struct
module Timeout2 (C: V1_LWT.CONSOLE) (R: V1_LWT.RANDOM) = struct

let timeout delay t =
let tmout = Time.sleep_ns delay in
Expand All @@ -66,22 +65,21 @@ module Timeout2 (C: V1_LWT.CONSOLE) = struct
(t >|= fun v -> Some v);
]

let start c =
Random.self_init ();
let t = Time.sleep_ns (Duration.of_ms (Random.int 3000)) >|= fun () -> "Heads" in
let start c _r =
let t = Time.sleep_ns (Duration.of_ms (Randomconv.int ~bound:3000 R.generate)) >|= fun () -> "Heads" in
timeout (Duration.of_sec 2) t >>= function
| None -> C.log_s c "Cancelled"
| Some v -> C.log_s c (Printf.sprintf "Returned %S" v)

end

module Echo_server1 (C: V1_LWT.CONSOLE) = struct
module Echo_server1 (C: V1_LWT.CONSOLE) (R: V1_LWT.RANDOM) = struct

let read_line () =
OS.Time.sleep_ns (Duration.of_ms (Random.int 2500)) >|= fun () ->
String.make (Random.int 20) 'a'
OS.Time.sleep_ns (Duration.of_ms (Randomconv.int ~bound:2500 R.generate)) >|= fun () ->
String.make (Randomconv.int ~bound:20 R.generate) 'a'

let start c =
let start c _r =
let rec echo_server = function
| 0 -> Lwt.return ()
| n ->
Expand Down