Skip to content

Commit

Permalink
run tcp_connect_one_stack test
Browse files Browse the repository at this point in the history
  • Loading branch information
yomimono committed Oct 12, 2015
1 parent b78923b commit 9ee63f3
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions lib_test/test_connect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,46 +79,49 @@ module Test_connect (B : Vnetif_backends.Backend) = struct
log_s c "wrote hello world" >>= fun () ->
V.Stackv4.TCPV4.close flow >>= fun () ->
Lwt_unix.sleep 1.0 >>= fun () -> (* record some traffic after close *)
Lwt.return_unit) ] >>= fun () ->
Lwt.return_unit) ]
>>= fun () ->

Lwt.return_unit

let test_tcp_connect_one_stack () =
or_error "console" Console.connect "console" >>= fun c ->
V.create_stack c backend server_ip netmask [gw] >>= fun s1 ->
let timeout = 15.0 in
Lwt.pick [
(Lwt_unix.sleep timeout >>= fun () ->
fail "connect test timedout after %f seconds" timeout) ;

(V.Stackv4.listen_tcpv4 s1 ~port:80 (fun f -> accept c f test_string);
V.Stackv4.listen s1) ;

(Lwt_unix.sleep 1.0 >>= fun () ->
or_error "connect" (V.Stackv4.TCPV4.create_connection (V.Stackv4.tcpv4 s1)) (server_ip, 80) >>= fun flow ->
C.log_s c "Connected to other end...%!" >>= fun () ->
V.Stackv4.TCPV4.write flow (Cstruct.of_string test_string) >>= (function
| `Ok () -> C.log_s c "wrote hello world%!"
| `Error _ -> fail "client tried to write, got error%!"
| `Eof -> fail "client tried to write, got eof%!") >>= fun () ->
V.Stackv4.TCPV4.close flow >>= fun () ->
Lwt.return_unit) ] >>= fun () ->
Lwt.return_unit

let record_pcap =
V.record_pcap backend

end

let tcp_connect_one_stack backend =
or_error "console" Console.connect "console" >>= fun c ->
create_stack c backend server_ip netmask [gw] >>= fun s1 ->
let timeout = 15.0 in
Lwt.pick [
(Lwt_unix.sleep timeout >>= fun () ->
fail "connect test timedout after %f seconds" timeout) ;

(S.listen_tcpv4 s1 ~port:80 (fun f -> accept c f test_string);
S.listen s1) ;

(Lwt_unix.sleep 1.0 >>= fun () ->
or_error "connect" (S.T.create_connection (S.tcpv4 s1)) (server_ip, 80) >>= fun flow ->
C.log_s c "Connected to other end...%!" >>= fun () ->
S.T.write flow (Cstruct.of_string test_string) >>= (function
| `Ok () -> C.log_s c "wrote hello world%!"
| `Error _ -> fail "client tried to write, got error%!"
| `Eof -> fail "client tried to write, got eof%!") >>= fun () ->
S.T.close flow >>= fun () ->
Lwt.return_unit) ] >>= fun () ->
Lwt.return_unit

let test_tcp_connect_two_stacks_basic () =
let module Test = Test_connect(Vnetif_backends.Basic) in
Test.record_pcap
"tests/pcap/tcp_connect_two_stacks_basic.pcap"
Test.test_tcp_connect_two_stacks

let test_tcp_connect_one_stack_basic () =
let backend = S.B.create ~use_async_readers:true ~yield:(fun() -> Lwt_main.yield () ) () in (* use_async_readers must be true with tcpip *)
tcp_connect_one_stack backend
let module Test = Test_connect(Vnetif_backends.Basic) in
Test.record_pcap
"tests/pcap/tcp_connect_one_stack_basic.pcap"
Test.test_tcp_connect_one_stack

let test_tcp_connect_two_stacks_trailing_bytes () =
let module Test = Test_connect(Vnetif_backends.Trailing_bytes) in
Expand Down

0 comments on commit 9ee63f3

Please sign in to comment.