@@ -11,9 +11,12 @@ module Log = (val Logs.src_log src : Logs.LOG)
1111exception Test_failure of string
1212
1313let get_ips c =
14- (* TODO: Check logic *)
1514 Client.Ipv. configured_ips c
16- |> List. map Ipaddr.Prefix. netmask
15+ |> List. map Ipaddr.Prefix. address
16+
17+ (* TODO: invocations of with_stack seem to remember the MAC -> IP bindings, so there's
18+ unexpected state somewhere. Work around this by using unique UUIDs. *)
19+ let uuid_gen = Uuidm. v4_gen (Random. get_state () )
1720
1821(* Open multiple connections and verify that the connection succeeds and MAC and IP changes *)
1922let test_connect n () =
@@ -22,30 +25,33 @@ let test_connect n () =
2225 match x, used_ips, used_macs with
2326 | 0 , _ , _ -> Lwt. return_unit
2427 | x , used_ips , used_macs ->
25- let uuid = ( Uuidm. v4_gen ( Random. get_state () ) () ) in
28+ let uuid = uuid_gen ( ) in
2629 with_stack ~uuid ~pcap: " test_connect.pcap" (fun _ client_stack ->
2730 (* Same IP should not appear twice *)
2831 let ips = get_ips (Client. ip client_stack.t) in
29- assert (List. length ips == 1 );
30- let ip = List. hd ips in
31- assert ((List. mem ip used_ips) == false );
32+ List. iter (fun ip ->
33+ if List. mem ip used_ips then begin
34+ Log. err (fun f -> f " IP %s is a duplicate" (Ipaddr. to_string ip));
35+ assert (false )
36+ end
37+ ) ips;
3238
3339 (* Same MAC should not appear twice *)
3440 let mac = (VMNET. mac client_stack.netif) in
3541 assert ((List. mem mac used_macs) == false );
3642
37- Lwt. return (ip , mac)
38- ) >> = fun (ip , mac ) ->
39- Log. info (fun f -> f " Stack %d got IP %s and MAC %s" x (Ipaddr. to_string ip ) (Macaddr. to_string mac));
40- loop (x - 1 ) ([ip] @ used_ips) ([mac] @ used_macs)
43+ Lwt. return (ips , mac)
44+ ) >> = fun (ips , mac ) ->
45+ Log. info (fun f -> f " Stack %d got IPs %s and MAC %s" x (String. concat " , " ( List. map Ipaddr. to_string ips) ) (Macaddr. to_string mac));
46+ loop (x - 1 ) (ips @ used_ips) ([mac] @ used_macs)
4147 in
4248 loop n [] []
4349 end
4450
4551(* Connect twice with the same UUID and verify that MAC and IP are the same *)
4652let test_reconnect () =
4753 Host.Main. run begin
48- let uuid = ( Uuidm. v4_gen ( Random. get_state () ) () ) in
54+ let uuid = uuid_gen ( ) in
4955 Log. info (fun f -> f " Using UUID %s" (Uuidm. to_string uuid));
5056 with_stack ~uuid ~pcap: " test_reconnect.pcap" (fun _ client_stack ->
5157 let ips = get_ips (Client. ip client_stack.t) in
@@ -69,7 +75,7 @@ let test_reconnect () =
6975(* Connect with random UUID and request an unused IP *)
7076let test_connect_preferred_ipv4 preferred_ip () =
7177 Host.Main. run begin
72- let uuid = ( Uuidm. v4_gen ( Random. get_state () ) () ) in
78+ let uuid = uuid_gen ( ) in
7379 Log. info (fun f -> f " Using UUID %s, requesting IP %s" (Uuidm. to_string uuid) (Ipaddr.V4. to_string preferred_ip));
7480 with_stack ~uuid ~preferred_ip ~pcap: " test_connect_preferred_ipv4.pcap" (fun _ client_stack ->
7581 let ips = get_ips (Client. ip client_stack.t) in
@@ -106,7 +112,7 @@ let test_connect_preferred_ipv4 preferred_ip () =
106112 | e -> raise e) >> = fun () ->
107113 (* Try to reconnect with a different UUID, but request a used IP (this should fail) *)
108114 Lwt. catch (fun () ->
109- let uuid = ( Uuidm. v4_gen ( Random. get_state () ) () ) in
115+ let uuid = uuid_gen ( ) in
110116 with_stack ~uuid ~preferred_ip ~pcap: " test_connect_preferred_ipv4.4.pcap" (fun _ client_stack ->
111117 let ips = get_ips (Client. ip client_stack.t) in
112118 let ip = List. hd ips in
0 commit comments