about summary refs log tree commit diff
path: root/nixos/tests/babeld.nix
blob: d4df6f86d089d82253e274846585b1d7175508e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

import ./make-test-python.nix ({ pkgs, lib, ...} : {
  name = "babeld";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ hexa ];
  };

  nodes =
    { client = { pkgs, lib, ... }:
      {
        virtualisation.vlans = [ 10 ];

        networking = {
          useDHCP = false;
          interfaces."eth1" = {
            ipv4.addresses = lib.mkForce [ { address = "192.168.10.2"; prefixLength = 24; } ];
            ipv4.routes = lib.mkForce [ { address = "0.0.0.0"; prefixLength = 0; via = "192.168.10.1"; } ];
            ipv6.addresses = lib.mkForce [ { address = "2001:db8:10::2"; prefixLength = 64; } ];
            ipv6.routes = lib.mkForce [ { address = "::"; prefixLength = 0; via = "2001:db8:10::1"; } ];
          };
        };
      };

      local_router = { pkgs, lib, ... }:
      {
        virtualisation.vlans = [ 10 20 ];

        networking = {
          useDHCP = false;
          firewall.enable = false;

          interfaces."eth1" = {
            ipv4.addresses = lib.mkForce [ { address = "192.168.10.1"; prefixLength = 24; } ];
            ipv6.addresses = lib.mkForce [ { address = "2001:db8:10::1"; prefixLength = 64; } ];
          };

          interfaces."eth2" = {
            ipv4.addresses = lib.mkForce [ { address = "192.168.20.1"; prefixLength = 24; } ];
            ipv6.addresses = lib.mkForce [ { address = "2001:db8:20::1"; prefixLength = 64; } ];
          };
        };

        services.babeld = {
          enable = true;
          interfaces.eth2 = {
            hello-interval = 1;
            type = "wired";
          };
          extraConfig = ''
            local-port-readwrite 33123

            import-table 254 # main
            export-table 254 # main

            in ip 192.168.10.0/24 deny
            in ip 192.168.20.0/24 deny
            in ip 2001:db8:10::/64 deny
            in ip 2001:db8:20::/64 deny

            in ip 192.168.30.0/24 allow
            in ip 2001:db8:30::/64 allow

            in deny

            redistribute local proto 2
            redistribute local deny
          '';
        };
      };
      remote_router = { pkgs, lib, ... }:
      {
        virtualisation.vlans = [ 20 30 ];

        networking = {
          useDHCP = false;
          firewall.enable = false;

          interfaces."eth1" = {
            ipv4.addresses = lib.mkForce [ { address = "192.168.20.2"; prefixLength = 24; } ];
            ipv6.addresses = lib.mkForce [ { address = "2001:db8:20::2"; prefixLength = 64; } ];
          };

          interfaces."eth2" = {
            ipv4.addresses = lib.mkForce [ { address = "192.168.30.1"; prefixLength = 24; } ];
            ipv6.addresses = lib.mkForce [ { address = "2001:db8:30::1"; prefixLength = 64; } ];
          };
        };

        services.babeld = {
          enable = true;
          interfaces.eth1 = {
            hello-interval = 1;
            type = "wired";
          };
          extraConfig = ''
            local-port-readwrite 33123

            import-table 254 # main
            export-table 254 # main

            in ip 192.168.20.0/24 deny
            in ip 192.168.30.0/24 deny
            in ip 2001:db8:20::/64 deny
            in ip 2001:db8:30::/64 deny

            in ip 192.168.10.0/24 allow
            in ip 2001:db8:10::/64 allow

            in deny

            redistribute local proto 2
            redistribute local deny
          '';
        };

      };
    };

  testScript =
    ''
      start_all()

      client.wait_for_unit("network-online.target")
      local_router.wait_for_unit("network-online.target")
      remote_router.wait_for_unit("network-online.target")

      local_router.wait_for_unit("babeld.service")
      remote_router.wait_for_unit("babeld.service")

      local_router.wait_until_succeeds("ip route get 192.168.30.1")
      local_router.wait_until_succeeds("ip route get 2001:db8:30::1")

      remote_router.wait_until_succeeds("ip route get 192.168.10.1")
      remote_router.wait_until_succeeds("ip route get 2001:db8:10::1")

      client.succeed("ping -c1 192.168.30.1")
      client.succeed("ping -c1 2001:db8:30::1")

      remote_router.succeed("ping -c1 192.168.10.2")
      remote_router.succeed("ping -c1 2001:db8:10::2")
    '';
})