blob: e0298d28720cfae02a5d70c4fcd7ed3029e1dbf8 [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#
8# We use EoIP to build up virtual ethernet links between the machines, and
9# to run VLANs on that. We don't just use plain 'vlans' from NixOS tests as
10# we actually want to run 802.1q ourselves from the edge01 config.
11#
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 = [
34 ../modules/eoip.nix
35 ];
36
37 hscloud.eoip.interfaces."nnet" = {
38 parent = "eth1";
39 localV4 = "192.168.1.3";
40 remoteV4 = "192.168.1.2";
41 id = 100;
42 };
43 networking.interfaces."nnet" = {
44 virtual = true;
45 virtualType = "tap";
46 };
47 networking.vlans = {
48 "vl-globalmix" = { interface = "nnet"; id = 466; };
49 };
50 networking.interfaces."vl-globalmix" = {
51 ipv4.addresses = [{ address = "185.235.70.44"; prefixLength = 31; }];
52 ipv6.addresses = [{ address = "2001:67c:778:fd40::b9eb:462c"; prefixLength = 127; }];
53 };
54
55 services.bird2 = {
56 enable = true;
57 config = ''
58 log syslog all;
59 debug protocols { states, interfaces, events }
60 router id 185.235.70.44;
61
62 protocol device {
63 scan time 10;
64 };
65 protocol kernel kernel_v4 {
66 ipv4 {
67 import none;
68 export all;
69 };
70 }
71 protocol kernel kernel_v6 {
72 ipv6 {
73 import none;
74 export all;
75 };
76 }
77 ipv4 table globalmix4;
78 ipv6 table globalmix6;
79
80 protocol pipe pipe_globalmix4 {
81 table master4;
82 peer table globalmix4;
83 import all;
84 export none;
85 };
86 protocol pipe pipe_globalmix6 {
87 table master6;
88 peer table globalmix6;
89 import all;
90 export none;
91 };
92
93 protocol static static_globalmix_originate_v4 {
94 ipv4 {
95 table globalmix4;
96 import all;
97 };
98 route 8.8.8.0/24 blackhole;
99 }
100 protocol static static_globalmix_originate_v6 {
101 ipv6 {
102 table globalmix6;
103 import all;
104 };
105 route 2a00:1450:4016::/48 blackhole;
106 }
107 protocol bgp bgp_globalmix_v4 {
108 ipv4 {
109 table globalmix4;
110 export all;
111 import all;
112 };
113 local 185.235.70.44 as 62081;
114 neighbor 185.235.70.45 as 204880;
115 };
116 protocol bgp bgp_globalmix_v6 {
117 ipv6 {
118 table globalmix6;
119 export all;
120 import all;
121 };
122 local 2001:67c:778:fd40::b9eb:462c as 62081;
123 neighbor 2001:67c:778:fd40::b9eb:462d as 204880;
124 };
125 '';
126 };
127 networking.firewall.enable = false;
128 networking.useDHCP = false;
129 networking.interfaces.lo.ipv4.addresses = [ { address = "8.8.8.1"; prefixLength = 32; } ];
130 networking.interfaces.lo.ipv6.addresses = [ { address = "2a00:1450:4016:801::200e"; prefixLength = 128; } ];
131 environment.systemPackages = with pkgs; [
132 tcpdump htop dstat file
133 ];
134
135};
136
137
138test = import "${pkgsSrc}/nixos/tests/make-test-python.nix" ({ pkgs, libs, ... }: {
139 name = "test-edge01-waw-e2e";
140
141 nodes = {
142 dut = { config, pkgs, ... }: {
143 imports = [
144 ../edge01.waw.bgp.wtf.nix
145 ../modules/eoip.nix
146 ];
147 virtualisation.memorySize = 1024;
148 virtualisation.vlans = [
149 1 2
150 ];
151
152 hscloud.eoip.interfaces = {
153 "e1-nnet" = { parent = "eth1"; localV4 = "192.168.1.2"; remoteV4 = "192.168.1.3"; id = 100; };
154 "e2-customs" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.1"; id = 200; };
155 "e3-mgmt" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.111"; id = 300; }; # not connected
156 "e4-oob" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.112"; id = 400; }; # not connected
157 "e7-dcsw" = { parent = "eth2"; localV4 = "192.168.2.2"; remoteV4 = "192.168.2.113"; id = 500; }; # not connected
158 };
159 networking.interfaces = {
160 "e1-nnet" = { virtual = true; virtualType = "tap"; };
161 "e2-customs" = { virtual = true; virtualType = "tap"; };
162 "e3-mgmt" = { virtual = true; virtualType = "tap"; };
163 "e4-oob" = { virtual = true; virtualType = "tap"; };
164 "e7-dcsw" = { virtual = true; virtualType = "tap"; };
165 };
166 };
167
168 speaker = mkBGPSpeaker;
169
170 customs = { config, pkgs, ... }: {
171 imports = [
172 ../modules/eoip.nix
173 ];
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" = {
186 virtual = true;
187 virtualType = "tap";
188 ipv4.addresses = [{ address = "185.236.240.5"; prefixLength = 31; }];
189 ipv6.addresses = [{ address = "2a0d:eb00:2137:1::3"; prefixLength = 127; }];
190 };
191 hscloud.eoip.interfaces."edge" = {
192 parent = "eth2";
193 localV4 = "192.168.2.1";
194 remoteV4 = "192.168.2.2";
195 id = 200;
196 };
197 networking.bridges."lan".interfaces = [];
198 networking.interfaces."lan" = {
199 ipv4.addresses = [{ address = "10.8.1.2"; prefixLength = 23; }];
200 ipv6.addresses = [{ address = "2a0d:eb00:4242::1"; prefixLength = 64; }];
201 };
202 services.bird2 = {
203 enable = true;
204 config = ''
205 log syslog all;
206 debug protocols { states, interfaces, events }
207 router id 185.236.240.5;
208
209 protocol device {
210 scan time 10;
211 };
212 protocol kernel kernel_v4 {
213 ipv4 {
214 import none;
215 export all;
216 };
217 }
218 protocol kernel kernel_v6 {
219 ipv6 {
220 import none;
221 export all;
222 };
223 }
224
225 protocol ospf v3 ospf_hswaw {
226 ipv6 {
227 import all;
228 export all;
229 };
230 area 0.0.0.0 {
231 interface "edge" {
232 cost 10;
233 type bcast;
234 };
235 interface "lan" {
236 cost 10;
237 stub yes;
238 type bcast;
239 check link no;
240 };
241 };
242 }
243 '';
244 };
245 };
246 };
247
248 testScript = ''
249 start_all()
250
251 edge01.wait_for_unit("bird2.service")
252 # Wait for BGP to settle.
253 edge01.wait_until_succeeds("ping 185.235.70.44 -c 1 -w 2")
254 edge01.wait_until_succeeds("birdc show route for 8.8.8.1 table all | grep via")
255 edge01.wait_until_succeeds(
256 "birdc show route for 2a00:1450:4016:801::200e table all | grep via"
257 )
258 edge01.succeed("ping 8.8.8.1 -c 1 -w 2")
259
260 # ping from customs to globalmix must succeed.
261 customs.succeed("ping 8.8.8.1 -c 1 -w 2")
262 customs.succeed("ping 2a00:1450:4016:801::200e -c 1 -w 2")
263
264 # edge01 must announce exactly one v4 prefix.
265 bgpspeaker.succeed("birdc show route protocol bgp_globalmix_v4 | grep unicast")
266 bgpspeaker.fail(
267 "birdc show route protocol bgp_globalmix_v4 | grep unicast | grep -v 185.236.240.0/23"
268 )
269
270 # edge01 must announce exactly one v6 prefix.
271 bgpspeaker.succeed("birdc show route protocol bgp_globalmix_v6 | grep unicast")
272 bgpspeaker.fail(
273 "birdc show route protocol bgp_globalmix_v6 | grep unicast | grep -v 2a0d:eb00::/32"
274 )
275
276 # customer networks must be reachable from globalmix
277 bgpspeaker.succeed("ping 185.236.240.10 -c 1 -w 2")
278 bgpspeaker.succeed("ping 2a0d:eb00:8000::1 -c 1 -w 2")
279 bgpspeaker.succeed("ping 185.236.240.12 -c 1 -w 2")
280 bgpspeaker.succeed("ping 185.236.240.105 -c 1 -w 2")
281 bgpspeaker.succeed("ping 2a0d:eb00:8003::1 -c 1 -w 2")
282
283 # dhcp agent must be reachable
284 customs.succeed("ping 185.236.240.18 -c 1 -w 2")
285 '';
286});
287
288in test { inherit pkgs; inherit (pkgs) libs; }