1# This test does a basic functionality check for all bird variants and demonstrates a use
2# of the preCheckConfig option.
3
4{
5 system ? builtins.currentSystem,
6 pkgs ? import ../.. {
7 inherit system;
8 config = { };
9 },
10}:
11
12let
13 inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
14 inherit (pkgs.lib) optionalString;
15
16 makeBirdHost =
17 hostId:
18 { pkgs, ... }:
19 {
20 virtualisation.vlans = [ 1 ];
21
22 environment.systemPackages = with pkgs; [ jq ];
23
24 networking = {
25 useNetworkd = true;
26 useDHCP = false;
27 firewall.enable = false;
28 };
29
30 systemd.network.networks."01-eth1" = {
31 name = "eth1";
32 networkConfig.Address = "10.0.0.${hostId}/24";
33 };
34
35 services.bird = {
36 enable = true;
37
38 config = ''
39 log syslog all;
40
41 debug protocols all;
42
43 router id 10.0.0.${hostId};
44
45 protocol device {
46 }
47
48 protocol kernel kernel4 {
49 ipv4 {
50 import none;
51 export all;
52 };
53 }
54
55 protocol static static4 {
56 ipv4;
57 include "static4.conf";
58 }
59
60 protocol ospf v2 ospf4 {
61 ipv4 {
62 export all;
63 };
64 area 0 {
65 interface "eth1" {
66 hello 5;
67 wait 5;
68 };
69 };
70 }
71
72 protocol kernel kernel6 {
73 ipv6 {
74 import none;
75 export all;
76 };
77 }
78
79 protocol static static6 {
80 ipv6;
81 include "static6.conf";
82 }
83
84 protocol ospf v3 ospf6 {
85 ipv6 {
86 export all;
87 };
88 area 0 {
89 interface "eth1" {
90 hello 5;
91 wait 5;
92 };
93 };
94 }
95 '';
96
97 preCheckConfig = ''
98 echo "route 1.2.3.4/32 blackhole;" > static4.conf
99 echo "route fd00::/128 blackhole;" > static6.conf
100 '';
101 };
102
103 systemd.tmpfiles.rules = [
104 "f /etc/bird/static4.conf - - - - route 10.10.0.${hostId}/32 blackhole;"
105 "f /etc/bird/static6.conf - - - - route fdff::${hostId}/128 blackhole;"
106 ];
107 };
108in
109makeTest {
110 name = "bird";
111
112 nodes.host1 = makeBirdHost "1";
113 nodes.host2 = makeBirdHost "2";
114
115 testScript = ''
116 start_all()
117
118 host1.wait_for_unit("bird.service")
119 host2.wait_for_unit("bird.service")
120 host1.succeed("systemctl reload bird.service")
121
122 with subtest("Waiting for advertised IPv4 routes"):
123 host1.wait_until_succeeds("ip --json r | jq -e 'map(select(.dst == \"10.10.0.2\")) | any'")
124 host2.wait_until_succeeds("ip --json r | jq -e 'map(select(.dst == \"10.10.0.1\")) | any'")
125 with subtest("Waiting for advertised IPv6 routes"):
126 host1.wait_until_succeeds("ip --json -6 r | jq -e 'map(select(.dst == \"fdff::2\")) | any'")
127 host2.wait_until_succeeds("ip --json -6 r | jq -e 'map(select(.dst == \"fdff::1\")) | any'")
128
129 with subtest("Check fake routes in preCheckConfig do not exists"):
130 host1.fail("ip --json r | jq -e 'map(select(.dst == \"1.2.3.4\")) | any'")
131 host2.fail("ip --json r | jq -e 'map(select(.dst == \"1.2.3.4\")) | any'")
132
133 host1.fail("ip --json -6 r | jq -e 'map(select(.dst == \"fd00::\")) | any'")
134 host2.fail("ip --json -6 r | jq -e 'map(select(.dst == \"fd00::\")) | any'")
135 '';
136}