Skip to content

Commit

Permalink
Merge pull request #149 from MagnusS/iperf-cleanup
Browse files Browse the repository at this point in the history
Iperf and vnetif improvements
  • Loading branch information
samoht committed Jun 9, 2015
2 parents a6d7e26 + e5cdaa8 commit ac7e93e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib_test/test_iperf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ module Test_iperf ( B : Vnetif_backends.Backend ) = struct
write_and_check flow a >>= fun () ->
V.Stackv4.TCPV4.close flow
in
OS.Time.sleep 1. >>= fun () ->
C.log_s c (Printf.sprintf "Iperf client: Attempting connection.%!") >>= fun () ->
tcp_connect (V.Stackv4.tcpv4 s) (dest_ip, dport) >>= fun flow ->
iperftx flow >>= fun () ->
Expand Down Expand Up @@ -134,13 +133,12 @@ module Test_iperf ( B : Vnetif_backends.Backend ) = struct
fail "iperf test timed out after %f seconds" timeout) ;

(server_ready >>= fun () ->
Lwt_unix.sleep 1.0 >>= fun() ->
Lwt_unix.sleep 0.1 >>= fun() -> (* Give server 0.1 s to call listen *)
C.log_s c (Printf.sprintf "I am client with IP %s, trying to connect to server @ %s:%d" (Ipaddr.V4.to_string client_ip) (Ipaddr.V4.to_string server_ip) port) >>= fun () ->
V.create_stack c backend client_ip netmask [gw] >>= fun client_s ->
iperfclient c client_s server_ip port) ;

(Lwt_unix.sleep 1.0 >>= fun () ->
C.log_s c (Printf.sprintf "I am server with IP %s, expecting connections on port %d" (Ipaddr.V4.to_string server_ip) port) >>= fun () ->
(C.log_s c (Printf.sprintf "I am server with IP %s, expecting connections on port %d" (Ipaddr.V4.to_string server_ip) port) >>= fun () ->
V.create_stack c backend server_ip netmask [gw] >>= fun server_s ->
V.Stackv4.listen_tcpv4 server_s ~port (iperf c server_s server_done_u);
Lwt.wakeup server_ready_u ();
Expand Down
11 changes: 6 additions & 5 deletions lib_test/vnetif_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ sig
val create_backend_listener : backend -> (buffer -> unit io) -> id
(** Disable a listener function *)
val disable_backend_listener : backend -> id -> unit
(** Create a pcap recorder that listens to traffic on the specified backend and writes pcap data to an output_channel*)
val create_pcap_recorder : backend -> Lwt_io.output_channel -> id Lwt.t
(** Records pcap data from the backend while running the specified function. Disables the pcap recorder when the function exits. *)
val record_pcap : backend -> string -> (unit -> unit Lwt.t) -> unit Lwt.t
end
Expand Down Expand Up @@ -96,7 +94,6 @@ module VNETIF_STACK ( B : Vnetif_backends.Backend) : VNETIF_STACK = struct
Pcap.LE.set_pcap_header_version_major header_buf Pcap.major_version;
Pcap.LE.set_pcap_header_version_minor header_buf Pcap.minor_version;
Lwt_io.write channel (Cstruct.to_string header_buf) >>= fun () ->
Lwt_io.flush channel >>= fun () ->
let pcap_record channel buffer =
let pcap_buf = Cstruct.create Pcap.sizeof_pcap_packet in
let time = Unix.gettimeofday () in
Expand All @@ -105,8 +102,12 @@ module VNETIF_STACK ( B : Vnetif_backends.Backend) : VNETIF_STACK = struct
Pcap.LE.set_pcap_packet_ts_sec pcap_buf (Int32.of_float time);
let frac = (time -. (float_of_int (truncate time))) *. 1000000.0 in
Pcap.LE.set_pcap_packet_ts_usec pcap_buf (Int32.of_float frac);
Lwt_io.write channel ((Cstruct.to_string pcap_buf) ^ (Cstruct.to_string buffer)) >>= fun () ->
Lwt_io.flush channel (* always flush *)
(try
Lwt_io.write channel ((Cstruct.to_string pcap_buf) ^ (Cstruct.to_string buffer))
with
Lwt_io.Channel_closed msg -> Printf.printf "Warning: Pcap output channel already closed: %s.\n" msg; Lwt.return_unit)
>>= fun () ->
Lwt.return_unit
in
let recorder_id = create_backend_listener backend (pcap_record channel) in
Lwt.return recorder_id
Expand Down

0 comments on commit ac7e93e

Please sign in to comment.