at 22.05-pre 3.1 kB view raw
1import ./make-test-python.nix ( 2 { 3 nodes = { 4 router = {config, pkgs, ...}: { 5 config = { 6 # This machine simulates a router with IPv6 forwarding and a static IPv6 address. 7 boot.kernel.sysctl = { 8 "net.ipv6.conf.all.forwarding" = true; 9 }; 10 networking.interfaces.eth1 = { 11 ipv6.addresses = [ { address = "fd00:dead:beef:dead::1"; prefixLength = 64; } ]; 12 }; 13 services.corerad = { 14 enable = true; 15 # Serve router advertisements to the client machine with prefix information matching 16 # any IPv6 /64 prefixes configured on this interface. 17 # 18 # This configuration is identical to the example in the CoreRAD NixOS module. 19 settings = { 20 interfaces = [ 21 { 22 name = "eth0"; 23 monitor = true; 24 } 25 { 26 name = "eth1"; 27 advertise = true; 28 prefix = [{ prefix = "::/64"; }]; 29 } 30 ]; 31 debug = { 32 address = "localhost:9430"; 33 prometheus = true; 34 }; 35 }; 36 }; 37 }; 38 }; 39 client = {config, pkgs, ...}: { 40 # Use IPv6 SLAAC from router advertisements, and install rdisc6 so we can 41 # trigger one immediately. 42 config = { 43 boot.kernel.sysctl = { 44 "net.ipv6.conf.all.autoconf" = true; 45 }; 46 environment.systemPackages = with pkgs; [ 47 ndisc6 48 ]; 49 }; 50 }; 51 }; 52 53 testScript = '' 54 start_all() 55 56 with subtest("Wait for CoreRAD and network ready"): 57 # Ensure networking is online and CoreRAD is ready. 58 router.wait_for_unit("network-online.target") 59 client.wait_for_unit("network-online.target") 60 router.wait_for_unit("corerad.service") 61 62 # Ensure the client can reach the router. 63 client.wait_until_succeeds("ping -c 1 fd00:dead:beef:dead::1") 64 65 with subtest("Verify SLAAC on client"): 66 # Trigger a router solicitation and verify a SLAAC address is assigned from 67 # the prefix configured on the router. 68 client.wait_until_succeeds("rdisc6 -1 -r 10 eth1") 69 client.wait_until_succeeds( 70 "ip -6 addr show dev eth1 | grep -q 'fd00:dead:beef:dead:'" 71 ) 72 73 addrs = client.succeed("ip -6 addr show dev eth1") 74 75 assert ( 76 "fd00:dead:beef:dead:" in addrs 77 ), "SLAAC prefix was not found in client addresses after router advertisement" 78 assert ( 79 "/64 scope global temporary" in addrs 80 ), "SLAAC temporary address was not configured on client after router advertisement" 81 82 with subtest("Verify HTTP debug server is configured"): 83 out = router.succeed("curl -f localhost:9430/metrics") 84 85 assert ( 86 "corerad_build_info" in out 87 ), "Build info metric was not found in Prometheus output" 88 ''; 89 })