Skip to content

Commit a8a30d4

Browse files
committed
fix issue with bridge IPvs and duplicate MACs
There is some unexpected hidden state somewhere which is causing with_stack called in test case with the same UUID as a previous case, to discover the same IP binding ("Reconnecting ...") Perhaps the DHCP server remembers the MAC? Signed-off-by: David Scott <[email protected]>
1 parent eb52bea commit a8a30d4

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/hostnet_test/test_bridge.ml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ module Log = (val Logs.src_log src : Logs.LOG)
1111
exception Test_failure of string
1212

1313
let 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 *)
1922
let 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 *)
4652
let 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 *)
7076
let 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

Comments
 (0)