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