Created
June 25, 2015 09:31
-
-
Save talex5/71ddeb255c2d9339d52b to your computer and use it in GitHub Desktop.
Mirage test that sends one byte to TCP endpoint (10.0.0.1/7001), with tracing on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Mirage | |
let main = foreign "Unikernel.Main" (stackv4 @-> job) | |
let stack console = | |
match get_mode () with | |
| `Xen -> direct_stackv4_with_default_ipv4 console tap0 | |
| `Unix -> assert false | |
let tracing = mprof_trace ~size:1000000 () | |
let () = | |
register "bench" ~tracing [ | |
main $ stack default_console; | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Lwt | |
let laptop_ip = Ipaddr.V4.of_string_exn "10.0.0.1" | |
let () = | |
let open Tcp in | |
[Pcb.info; Pcb.debug; State.debug] |> List.iter (fun log -> | |
Log.enable log; | |
Log.set_stats log false | |
) | |
let () = | |
Lwt.async_exception_hook := fun ex -> Printf.eprintf "Uncaught exception: %s\n%!" (Printexc.to_string ex) | |
module Main (S: V1_LWT.STACKV4) = struct | |
let buffer = Io_page.get 1 |> Io_page.to_cstruct | |
let start s = | |
let t = S.tcpv4 s in | |
match_lwt S.TCPV4.create_connection t (laptop_ip, 7001) with | |
| `Error _err -> failwith "TCP error 7001" | |
| `Ok flow -> | |
let payload = Cstruct.sub buffer 0 1 in | |
Cstruct.set_char payload 0 '!'; | |
match_lwt S.TCPV4.write flow payload with | |
| `Error _ | `Eof -> assert false | |
| `Ok () -> | |
S.TCPV4.close flow >>= fun () -> | |
OS.Time.sleep 10.0 | |
end |
Perfect, thanks; I was just recreating something from the snippet you put in the issue but I'll grab this and give it a try instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test, run netcat on 10.0.01 to accept the data (or change
laptop_ip
):Then run the unikernel. With mirage/mirage-tcpip#156, the output is: