vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / frr.nix
bloba975d4b402a1a37c3eab3db9678470ea638c1af3
1 # This test runs FRR and checks if OSPF routing works.
3 # Network topology:
4 #   [ client ]--net1--[ router1 ]--net2--[ router2 ]--net3--[ server ]
6 # All interfaces are in OSPF Area 0.
8 import ./make-test-python.nix ({ pkgs, ... }:
9   let
11     ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
13     ospfConf1 = ''
14       router ospf
15         network 192.168.0.0/16 area 0
16     '';
18     ospfConf2 = ''
19       interface eth2
20         ip ospf hello-interval 1
21         ip ospf dead-interval 5
22       !
23       router ospf
24         network 192.168.0.0/16 area 0
25     '';
27   in
28     {
29       name = "frr";
31       meta = with pkgs.lib.maintainers; {
32         maintainers = [ ];
33       };
35       nodes = {
37         client =
38           { nodes, ... }:
39           {
40             virtualisation.vlans = [ 1 ];
41             services.frr = {
42               config = ''
43                 ip route 192.168.0.0/16 ${ifAddr nodes.router1 "eth1"}
44               '';
45             };
46           };
48         router1 =
49           { ... }:
50           {
51             virtualisation.vlans = [ 1 2 ];
52             boot.kernel.sysctl."net.ipv4.ip_forward" = "1";
53             networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospfigp -j ACCEPT";
54             services.frr = {
55               ospfd.enable = true;
56               config = ospfConf1;
57             };
59             specialisation.ospf.configuration = {
60               services.frr.config = ospfConf2;
61             };
62           };
64         router2 =
65           { ... }:
66           {
67             virtualisation.vlans = [ 3 2 ];
68             boot.kernel.sysctl."net.ipv4.ip_forward" = "1";
69             networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospfigp -j ACCEPT";
70             services.frr = {
71               ospfd.enable = true;
72               config = ospfConf2;
73             };
74           };
76         server =
77           { nodes, ... }:
78           {
79             virtualisation.vlans = [ 3 ];
80             services.frr = {
81               config = ''
82                 ip route 192.168.0.0/16 ${ifAddr nodes.router2 "eth1"}
83               '';
84             };
85           };
86       };
88       testScript =
89         { nodes, ... }:
90         ''
91           start_all()
93           # Wait for the networking to start on all machines
94           for machine in client, router1, router2, server:
95               machine.wait_for_unit("network.target")
97           with subtest("Wait for FRR"):
98               for gw in client, router1, router2, server:
99                   gw.wait_for_unit("frr")
101           router1.succeed("${nodes.router1.config.system.build.toplevel}/specialisation/ospf/bin/switch-to-configuration test >&2")
103           with subtest("Wait for OSPF to form adjacencies"):
104               for gw in router1, router2:
105                   gw.wait_until_succeeds("vtysh -c 'show ip ospf neighbor' | grep Full")
106                   gw.wait_until_succeeds("vtysh -c 'show ip route' | grep '^O>'")
108           with subtest("Test ICMP"):
109               client.wait_until_succeeds("ping -4 -c 3 server >&2")
110         '';
111     })