Skip to content
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
6 changes: 3 additions & 3 deletions conduit_server_manual/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ module Main (C:CONSOLE) (S:STACKV4) = struct
let start console s =

C.log_s console (sprintf "IP address: %s\n"
(Ipaddr.V4.to_string (S.IPV4.get_ipv4 (S.ipv4 s))))
(String.concat ", " (List.map Ipaddr.V4.to_string (S.IPV4.get_ip (S.ipv4 s)))))
>>= fun () ->

lwt ctx = CON.init () in
lwt ctx = CON.init ~stack:s () in

let http_callback conn_id req body =
let path = Uri.path (H.Server.Request.uri req) in
C.log_s console (sprintf "Got request for %s\n" path)
C.log_s console (sprintf "Got request for %s\n" path)
>>= fun () ->
H.Server.respond_string ~status:`OK ~body:"hello mirage world!\n" ()
in
Expand Down
10 changes: 5 additions & 5 deletions ethifv4/config.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
open Mirage

let main = foreign "Unikernel.Main" (console @-> network @-> job)
let main = foreign "Unikernel.Main" (console @-> network @-> clock @-> job)

(* TODO: workaround a bug in the command-line tool by adding Clock
for Unix (this is pulled in as an implicit dependency in Xen) *)
let unix_libs =
match get_mode () with
match get_mode () with
| `Xen -> []
| _ -> ["mirage-clock-unix"]
| _ -> ["mirage-clock-unix"]

let () =
add_to_ocamlfind_libraries
([ "tcpip.ethif"; "tcpip.tcpv4"; "tcpip.udpv4"; "tcpip.dhcpv4" ]
([ "tcpip.ethif"; "tcpip.tcp"; "tcpip.udp"; "tcpip.dhcpv4" ]
@ unix_libs);
register "ethifv4" [
main $ default_console $ tap0
main $ default_console $ tap0 $ default_clock
]
15 changes: 8 additions & 7 deletions ethifv4/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ 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) = struct
module Main (C: CONSOLE) (N: NETWORK) (Clock : V1.CLOCK) = struct

module E = Ethif.Make(N)
module I = Ipv4.Make(E)
module U = Udpv4.Make(I)
module T = Tcpv4.Flow.Make(I)(OS.Time)(Clock)(Random)
module U = Udp.Make(I)
module T = Tcp.Flow.Make(I)(OS.Time)(Clock)(Random)
module D = Dhcp_clientv4.Make(C)(OS.Time)(Random)(U)

let or_error c name fn t =
Expand All @@ -20,18 +20,18 @@ module Main (C: CONSOLE) (N: NETWORK) = struct
| `Error e -> fail (Failure ("Error starting " ^ name))
| `Ok t -> return t

let start c net =
let start c net _ =
or_error c "Ethif" E.connect net
>>= fun e ->

or_error c "Ipv4" I.connect e
>>= fun i ->

I.set_ipv4 i (Ipaddr.V4.of_string_exn "10.0.0.2")
I.set_ip i (Ipaddr.V4.of_string_exn "10.0.0.2")
>>= fun () ->
I.set_ipv4_netmask i (Ipaddr.V4.of_string_exn "255.255.255.0")
I.set_ip_netmask i (Ipaddr.V4.of_string_exn "255.255.255.0")
>>= fun () ->
I.set_ipv4_gateways i [Ipaddr.V4.of_string_exn "10.0.0.1"]
I.set_ip_gateways i [Ipaddr.V4.of_string_exn "10.0.0.1"]
>>= fun () ->
or_error c "UDPv4" U.connect i
>>= fun udp ->
Expand All @@ -42,6 +42,7 @@ module Main (C: CONSOLE) (N: NETWORK) = struct

N.listen net (
E.input
~arpv4:(I.input_arpv4 i)
~ipv4:(
I.input
~tcp:(
Expand Down
2 changes: 1 addition & 1 deletion kv_ro/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let disk =
match mode, get_mode () with
| `Fat , _ -> fat_ro "t"
| `Crunch, `Xen -> crunch "t"
| `Crunch, `Unix -> direct_kv_ro "t"
| `Crunch, (`Unix | `MacOSX) -> direct_kv_ro "t"

let main =
foreign "Unikernel.Main" (console @-> kv_ro @-> kv_ro @-> job)
Expand Down
1 change: 1 addition & 0 deletions ping/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ open Mirage
let main = foreign "Unikernel.Main" (console @-> network @-> job)

let () =
add_to_opam_packages [ "tcpip" ];
add_to_ocamlfind_libraries [ "tcpip.ethif"; "tcpip.ipv4" ];
register "ping" [ main $ default_console $ tap0 ]
11 changes: 6 additions & 5 deletions ping/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ module Main (C:CONSOLE) (N:NETWORK) = struct
or_error c "Ethif" E.connect n >>= fun e ->
or_error c "Ipv4" I.connect e >>= fun i ->

I.set_ipv4 i (Ipaddr.V4.of_string_exn ipaddr) >>= fun () ->
I.set_ipv4_netmask i (Ipaddr.V4.of_string_exn netmask) >>= fun () ->
I.set_ipv4_gateways i (List.map Ipaddr.V4.of_string_exn gateways)
I.set_ip i (Ipaddr.V4.of_string_exn ipaddr) >>= fun () ->
I.set_ip_netmask i (Ipaddr.V4.of_string_exn netmask) >>= fun () ->
I.set_ip_gateways i (List.map Ipaddr.V4.of_string_exn gateways)
>>= fun () ->

let handler s = fun ~src ~dst data ->
C.log_s c (yellow "%s > %s TCP"
(Ipaddr.V4.to_string src) (Ipaddr.V4.to_string dst))
C.log_s c (yellow "%s > %s %s"
(Ipaddr.V4.to_string src) (Ipaddr.V4.to_string dst) s)
in
N.listen n
(E.input
~arpv4:(I.input_arpv4 i)
~ipv4:(I.input
~tcp:(handler "TCP")
~udp:(handler "UDP")
Expand Down
8 changes: 8 additions & 0 deletions ping6/config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
open Mirage

let main = foreign "Unikernel.Main" (console @-> network @-> clock @-> job)

let () =
add_to_opam_packages [ "tcpip" ];
add_to_ocamlfind_libraries [ "tcpip.ethif"; "tcpip.ipv6" ];
register "ping" [ main $ default_console $ tap0 $ default_clock ]
51 changes: 51 additions & 0 deletions ping6/unikernel.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
open Lwt
open V1_LWT

let red fmt = Printf.sprintf ("\027[31m"^^fmt^^"\027[m")
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")

let ipaddr = "fc00::2"
let gateways = ["fc00::1"]

module Main (C:CONSOLE) (N:NETWORK) (Clock : V1.CLOCK) = struct

module E = Ethif.Make(N)
module I = Ipv6.Make(E)(OS.Time)(Clock)

let or_error c name fn t =
fn t
>>= function
| `Error e -> fail (Failure ("Error starting " ^ name))
| `Ok t -> return t

let start c n _ =
C.log c (green "starting...");
or_error c "Ethif" E.connect n >>= fun e ->
or_error c "Ipv6" I.connect e >>= fun i ->

I.set_ip i (Ipaddr.V6.of_string_exn ipaddr) >>= fun () ->
I.set_ip_gateways i (List.map Ipaddr.V6.of_string_exn gateways) >>= fun () ->

let handler s = fun ~src ~dst data ->
C.log_s c (yellow "%s > %s %s"
(Ipaddr.V6.to_string src) (Ipaddr.V6.to_string dst) s)
in
N.listen n
(E.input
~arpv4:(fun _ -> return (C.log c (red "ARP4")))
~ipv4:(fun _ -> return (C.log c (red "IP4")))
~ipv6:(I.input
~tcp:(handler "TCP")
~udp:(handler "UDP")
~default:(fun ~proto ~src ~dst data ->
C.log_s c (red "%d DEFAULT" proto))
i
)
e)
>>= fun () ->
C.log c (green "done!");
return ()

end
10 changes: 5 additions & 5 deletions stackv4/unikernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module Main (C:CONSOLE) (S:STACKV4) = struct

let start console s =

C.log_s console
(sprintf "IP address: %s\n"
(Ipaddr.V4.to_string (S.IPV4.get_ipv4 (S.ipv4 s))))
C.log_s console
(sprintf "IP address: %s\n"
(String.concat ", " (List.map Ipaddr.V4.to_string (S.IPV4.get_ip (S.ipv4 s)))))
>>= fun () ->

S.listen_udpv4 s 53 (
Expand All @@ -28,15 +28,15 @@ module Main (C:CONSOLE) (S:STACKV4) = struct
fun flow ->
let dst, dst_port = T.get_dest flow in
C.log_s console
(green "new tcp from %s %d"
(green "new tcp from %s %d"
(Ipaddr.V4.to_string dst) dst_port
)
>>= fun () ->
T.read flow
>>= function
| `Ok b ->
C.log_s console
(yellow "read: %d\n%s"
(yellow "read: %d\n%s"
(Cstruct.len b) (Cstruct.to_string b)
)
>>= fun () ->
Expand Down
2 changes: 1 addition & 1 deletion xen/static_website+ip/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let main =
foreign "Dispatch.Main" (console @-> kv_ro @-> network @-> job)

let () =
add_to_ocamlfind_libraries ["mirage-http";"tcpip.ethif"; "tcpip.tcpv4"; "tcpip.udpv4"; "tcpip.dhcpv4" ];
add_to_ocamlfind_libraries ["mirage-http";"tcpip.ethif"; "tcpip.tcp"; "tcpip.udp"; "tcpip.dhcpv4" ];
add_to_opam_packages ["mirage-http"];
register "www" [
main $ default_console $ fs $ tap0
Expand Down
23 changes: 12 additions & 11 deletions xen/static_website+ip/dispatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ module Main (C:CONSOLE) (FS:KV_RO) (N:NETWORK) = struct

module E = Ethif.Make(N)
module I = Ipv4.Make(E)
module U = Udpv4.Make(I)
module T = Tcpv4.Flow.Make(I)(OS.Time)(Clock)(Random)
module U = Udp.Make(I)
module T = Tcp.Flow.Make(I)(OS.Time)(Clock)(Random)
module CH = Channel.Make(T)
module H = HTTP.Make(CH)

let or_error c name fn t =
fn t
>>= function
| `Error e -> fail (Failure ("Error starting " ^ name))
| `Ok t -> return t
| `Ok t -> return t

let start c fs net =

Expand All @@ -32,21 +32,21 @@ module Main (C:CONSOLE) (FS:KV_RO) (N:NETWORK) = struct
let fields = Re_str.(split (regexp_string " ") cmd_line) in
let bits =
List.map (fun x ->
match Re_str.(split (regexp_string "=") x) with
| [a;b] -> (a,b)
match Re_str.(split (regexp_string "=") x) with
| [a;b] -> (a,b)
| _ -> raise (Failure "malformed cmdline")) fields
in
let get x = List.assoc x bits in
let ip = Ipaddr.V4.of_string_exn (get "ip") in
let netmask = Ipaddr.V4.of_string_exn (get "netmask") in
let gateway = Ipaddr.V4.of_string_exn (get "gateway") in
C.log_s c (sprintf "ip=%s netmask=%s gateway=%s"
C.log_s c (sprintf "ip=%s netmask=%s gateway=%s"
(Ipaddr.V4.to_string ip)
(Ipaddr.V4.to_string netmask)
(Ipaddr.V4.to_string gateway)) >>= fun () ->
I.set_ipv4 i ip >>= fun () ->
I.set_ipv4_netmask i netmask >>= fun () ->
I.set_ipv4_gateways i [gateway] >>= fun () ->
(Ipaddr.V4.to_string gateway)) >>= fun () ->
I.set_ip i ip >>= fun () ->
I.set_ip_netmask i netmask >>= fun () ->
I.set_ip_gateways i [gateway] >>= fun () ->
or_error c "UDPv4" U.connect i >>= fun udp ->
or_error c "TCPv4" T.connect i >>= fun tcp ->

Expand Down Expand Up @@ -74,7 +74,7 @@ module Main (C:CONSOLE) (FS:KV_RO) (N:NETWORK) = struct

(* dispatch non-file URLs *)
let rec dispatcher = function
| [] | [""] -> dispatcher ["index.html"]
| [] | [""] -> dispatcher ["index.html"]
| segments ->
let path = String.concat "/" segments in
try_lwt
Expand Down Expand Up @@ -110,6 +110,7 @@ module Main (C:CONSOLE) (FS:KV_RO) (N:NETWORK) = struct

N.listen net (
E.input
~arpv4:(I.input_arpv4 i)
~ipv4:(
I.input
~tcp:(
Expand Down