blob: 1d724e1cc02e2c500e7b0cb2292aaccc8892d09c [file] [log] [blame]
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02001# Smoke test edge01.waw in a multi-VM NixOS test.
2#
3# This brings up three VMs:
4# - dut/edge01
5# - bgpspeaker, which simulates bgp upstreams
6# - customs, which simulates customs.hackerspace.pl.
7#
Serge Bazanskicc769a52021-02-13 13:13:41 +01008# We use GRETap to build up virtual ethernet links between the machines, and to
9# run VLANs on that. We don't just use plain 'vlans' from NixOS tests as we
10# actually want to run 802.1q ourselves from the edge01 config.
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020011#
12# Everything else is pretty much straightforward. Bring up everything, ping
13# stuff. We don't really test much else than internet routing.
14#
15# To run this:
16# nix-build -A bgpwtf.machines.tests.edge01-waw
17#
18# To debug this:
19# nix-build -A bgpwtf.machines.tests.edge01-waw.driver && result/bin/nixos-test-driver
20# >>> start_all()
21
22{ hscloud, pkgsSrc, pkgs, lib, ... }:
23
24with lib;
25
26let
27
28mkBGPSpeaker = let
29in { config, pkgs, ... }: {
30 networking.hostName = "bgpspeaker";
31 virtualisation.memorySize = 1024;
32 virtualisation.vlans = [ 1 ];
33 imports = [
Serge Bazanskicc769a52021-02-13 13:13:41 +010034 ../modules/gretap.nix
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020035 ];
36
Serge Bazanskicc769a52021-02-13 13:13:41 +010037 hscloud.gretap.interfaces."nnet" = {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020038 parent = "eth1";
39 localV4 = "192.168.1.3";
40 remoteV4 = "192.168.1.2";
41 id = 100;
42 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020043 networking.vlans = {
44 "vl-globalmix" = { interface = "nnet"; id = 466; };
45 };
46 networking.interfaces."vl-globalmix" = {
47 ipv4.addresses = [{ address = "185.235.70.44"; prefixLength = 31; }];
48 ipv6.addresses = [{ address = "2001:67c:778:fd40::b9eb:462c"; prefixLength = 127; }];
49 };
50
51 services.bird2 = {
52 enable = true;
53 config = ''
54 log syslog all;
55 debug protocols { states, interfaces, events }
56 router id 185.235.70.44;
57
58 protocol device {
59 scan time 10;
60 };
61 protocol kernel kernel_v4 {
62 ipv4 {
63 import none;
64 export all;
65 };
66 }
67 protocol kernel kernel_v6 {
68 ipv6 {
69 import none;
70 export all;
71 };
72 }
73 ipv4 table globalmix4;
74 ipv6 table globalmix6;
75
76 protocol pipe pipe_globalmix4 {
77 table master4;
78 peer table globalmix4;
79 import all;
80 export none;
81 };
82 protocol pipe pipe_globalmix6 {
83 table master6;
84 peer table globalmix6;
85 import all;
86 export none;
87 };
88
89 protocol static static_globalmix_originate_v4 {
90 ipv4 {
91 table globalmix4;
92 import all;
93 };
94 route 8.8.8.0/24 blackhole;
95 }
96 protocol static static_globalmix_originate_v6 {
97 ipv6 {
98 table globalmix6;
99 import all;
100 };
101 route 2a00:1450:4016::/48 blackhole;
102 }
103 protocol bgp bgp_globalmix_v4 {
104 ipv4 {
105 table globalmix4;
106 export all;
107 import all;
108 };
109 local 185.235.70.44 as 62081;
110 neighbor 185.235.70.45 as 204880;
111 };
112 protocol bgp bgp_globalmix_v6 {
113 ipv6 {
114 table globalmix6;
115 export all;
116 import all;
117 };
118 local 2001:67c:778:fd40::b9eb:462c as 62081;
119 neighbor 2001:67c:778:fd40::b9eb:462d as 204880;
120 };
121 '';
122 };
123 networking.firewall.enable = false;
124 networking.useDHCP = false;
125 networking.interfaces.lo.ipv4.addresses = [ { address = "8.8.8.1"; prefixLength = 32; } ];
126 networking.interfaces.lo.ipv6.addresses = [ { address = "2a00:1450:4016:801::200e"; prefixLength = 128; } ];
127 environment.systemPackages = with pkgs; [
128 tcpdump htop dstat file
129 ];
130
131};
132
133
134test = import "${pkgsSrc}/nixos/tests/make-test-python.nix" ({ pkgs, libs, ... }: {
135 name = "test-edge01-waw-e2e";
136
137 nodes = {
138 dut = { config, pkgs, ... }: {
139 imports = [
140 ../edge01.waw.bgp.wtf.nix
Serge Bazanskicc769a52021-02-13 13:13:41 +0100141 ../modules/gretap.nix
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200142 ];
143 virtualisation.memorySize = 1024;
144 virtualisation.vlans = [
145 1 2
146 ];
147
Serge Bazanskicc769a52021-02-13 13:13:41 +0100148 hscloud.gretap.interfaces = {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200149 "e1-nnet" = { parent = "eth1"; localV4 = "192.168.1.2"; remoteV4 = "192.168.1.3"; id = 100; };
150 "e2-customs" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.1"; id = 200; };
151 "e3-mgmt" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.111"; id = 300; }; # not connected
152 "e4-oob" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.112"; id = 400; }; # not connected
153 "e7-dcsw" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.113"; id = 500; }; # not connected
154 };
Bartosz Stebelc7267982020-12-10 15:38:29 +0100155 hscloud.anchorvm = {
156 blkdev = "/anchor.img";
157 ram = 32;
158 };
159 systemd.services.anchorTestImg = {
160 requiredBy = [ "anchorvm.service" ];
161 serviceConfig = {
162 Type = "oneshot";
163 ExecStart = "${pkgs.coreutils}/bin/truncate -s 128m /anchor.img";
164 };
165 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200166 };
167
168 speaker = mkBGPSpeaker;
169
170 customs = { config, pkgs, ... }: {
171 imports = [
Serge Bazanskicc769a52021-02-13 13:13:41 +0100172 ../modules/gretap.nix
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200173 ];
174 environment.systemPackages = with pkgs; [
175 tcpdump htop dstat file dhcpcd
176 ];
177 virtualisation.memorySize = 1024;
178 virtualisation.vlans = [
179 2
180 ];
181 networking.firewall.enable = false;
182 networking.useDHCP = false;
183 networking.defaultGateway = "185.236.240.4";
184 networking.defaultGateway6 = "2a0d:eb00:2137:1::2";
185 networking.interfaces."edge" = {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200186 ipv4.addresses = [{ address = "185.236.240.5"; prefixLength = 31; }];
187 ipv6.addresses = [{ address = "2a0d:eb00:2137:1::3"; prefixLength = 127; }];
188 };
Serge Bazanskicc769a52021-02-13 13:13:41 +0100189 hscloud.gretap.interfaces."edge" = {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200190 parent = "eth2";
191 localV4 = "192.168.2.1";
192 remoteV4 = "192.168.2.2";
193 id = 200;
194 };
195 networking.bridges."lan".interfaces = [];
196 networking.interfaces."lan" = {
197 ipv4.addresses = [{ address = "10.8.1.2"; prefixLength = 23; }];
198 ipv6.addresses = [{ address = "2a0d:eb00:4242::1"; prefixLength = 64; }];
199 };
200 services.bird2 = {
201 enable = true;
202 config = ''
203 log syslog all;
204 debug protocols { states, interfaces, events }
205 router id 185.236.240.5;
206
207 protocol device {
208 scan time 10;
209 };
210 protocol kernel kernel_v4 {
211 ipv4 {
212 import none;
213 export all;
214 };
215 }
216 protocol kernel kernel_v6 {
217 ipv6 {
218 import none;
219 export all;
220 };
221 }
222
223 protocol ospf v3 ospf_hswaw {
224 ipv6 {
225 import all;
226 export all;
227 };
228 area 0.0.0.0 {
229 interface "edge" {
230 cost 10;
231 type bcast;
232 };
233 interface "lan" {
234 cost 10;
235 stub yes;
236 type bcast;
237 check link no;
238 };
239 };
240 }
241 '';
242 };
243 };
244 };
245
246 testScript = ''
247 start_all()
248
249 edge01.wait_for_unit("bird2.service")
250 # Wait for BGP to settle.
251 edge01.wait_until_succeeds("ping 185.235.70.44 -c 1 -w 2")
252 edge01.wait_until_succeeds("birdc show route for 8.8.8.1 table all | grep via")
253 edge01.wait_until_succeeds(
254 "birdc show route for 2a00:1450:4016:801::200e table all | grep via"
255 )
256 edge01.succeed("ping 8.8.8.1 -c 1 -w 2")
257
258 # ping from customs to globalmix must succeed.
259 customs.succeed("ping 8.8.8.1 -c 1 -w 2")
260 customs.succeed("ping 2a00:1450:4016:801::200e -c 1 -w 2")
261
262 # edge01 must announce exactly one v4 prefix.
263 bgpspeaker.succeed("birdc show route protocol bgp_globalmix_v4 | grep unicast")
264 bgpspeaker.fail(
265 "birdc show route protocol bgp_globalmix_v4 | grep unicast | grep -v 185.236.240.0/23"
266 )
267
268 # edge01 must announce exactly one v6 prefix.
269 bgpspeaker.succeed("birdc show route protocol bgp_globalmix_v6 | grep unicast")
270 bgpspeaker.fail(
271 "birdc show route protocol bgp_globalmix_v6 | grep unicast | grep -v 2a0d:eb00::/32"
272 )
273
274 # customer networks must be reachable from globalmix
275 bgpspeaker.succeed("ping 185.236.240.10 -c 1 -w 2")
276 bgpspeaker.succeed("ping 2a0d:eb00:8000::1 -c 1 -w 2")
277 bgpspeaker.succeed("ping 185.236.240.12 -c 1 -w 2")
278 bgpspeaker.succeed("ping 185.236.240.105 -c 1 -w 2")
279 bgpspeaker.succeed("ping 2a0d:eb00:8003::1 -c 1 -w 2")
280
281 # dhcp agent must be reachable
282 customs.succeed("ping 185.236.240.18 -c 1 -w 2")
283 '';
284});
285
286in test { inherit pkgs; inherit (pkgs) libs; }