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