]> git.proxmox.com Git - pve-common.git/blob - test/etc_network_interfaces/t.create_network.pl
700eeef6bed1a4da3b27ecfd28bba766162723a6
[pve-common.git] / test / etc_network_interfaces / t.create_network.pl
1 save('proc_net_dev', <<'/proc/net/dev');
2 eth0:
3 eth1:
4 eth2:
5 eth3:
6 /proc/net/dev
7
8 r(load('brbase'));
9
10 #
11 # Variables used for the various interfaces:
12 #
13
14 my $ip = '192.168.0.2';
15 my $nm = '255.255.255.0';
16 my $gw = '192.168.0.1';
17 my $svcnodeip = '239.192.105.237';
18 my $physdev = 'eth0';
19 my $remoteip1 = '192.168.0.3';
20 my $remoteip2 = '192.168.0.4';
21
22 #
23 # Hunk for the default bridge of the 'brbase' configuration
24 #
25
26 my $vmbr0_part = <<"PART";
27 auto vmbr0
28 iface vmbr0 inet static
29 address 10.0.0.2
30 netmask 255.255.255.0
31 gateway 10.0.0.1
32 bridge-ports eth0
33 bridge-stp off
34 bridge-fd 0
35 PART
36 chomp $vmbr0_part;
37
38 #
39 # Configure eth1 statically, store its expected interfaces hunk in $eth1_part
40 # and test!
41 #
42
43 $config->{ifaces}->{eth1} = {
44 type => 'eth',
45 method => 'static',
46 address => $ip,
47 netmask => $nm,
48 gateway => $gw,
49 families => ['inet'],
50 autostart => 1
51 };
52
53 my $eth1_part = <<"PART";
54 auto eth1
55 iface eth1 inet static
56 address $ip
57 netmask $nm
58 gateway $gw
59 PART
60 chomp $eth1_part;
61
62 expect load('loopback') . <<"CHECK";
63 source-directory interfaces.d
64
65 iface eth0 inet manual
66
67 $eth1_part
68
69 iface eth2 inet manual
70
71 iface eth3 inet manual
72
73 $vmbr0_part
74
75 CHECK
76
77 #
78 # Add a bond for eth2 & 3 and check the new output
79 #
80
81 $config->{ifaces}->{bond0} = {
82 type => 'bond',
83 mtu => 1400,
84 slaves => 'eth2 eth3',
85 bond_mode => '802.3ad',
86 bond_xmit_hash_policy => 'layer3+4',
87 bond_miimon => 100,
88 method => 'manual',
89 families => ['inet'],
90 autostart => 1
91 };
92 my $bond0_part = <<"PART";
93 auto bond0
94 iface bond0 inet manual
95 bond-slaves eth2 eth3
96 bond-miimon 100
97 bond-mode 802.3ad
98 bond-xmit-hash-policy layer3+4
99 mtu 1400
100 PART
101 chomp $bond0_part;
102
103 expect load('loopback') . <<"CHECK";
104 source-directory interfaces.d
105
106 iface eth0 inet manual
107
108 $eth1_part
109
110 iface eth2 inet manual
111
112 iface eth3 inet manual
113
114 $bond0_part
115
116 $vmbr0_part
117
118 CHECK
119
120 #
121 # Add vxlan1 and 2
122 #
123
124 $config->{ifaces}->{vxlan1} = {
125 type => 'vxlan',
126 method => 'manual',
127 families => ['inet'],
128 'vxlan-id' => 1,
129 'vxlan-svcnodeip' => $svcnodeip,
130 'vxlan-physdev' => $physdev,
131 autostart => 1
132 };
133
134 $config->{ifaces}->{vxlan2} = {
135 type => 'vxlan',
136 method => 'manual',
137 families => ['inet'],
138 'vxlan-id' => 2,
139 'vxlan-local-tunnelip' => $ip,
140 autostart => 1
141 };
142
143 my $vxlan12_part = <<"PART";
144 auto vxlan1
145 iface vxlan1 inet manual
146 vxlan-id 1
147 vxlan-svcnodeip $svcnodeip
148 vxlan-physdev $physdev
149
150 auto vxlan2
151 iface vxlan2 inet manual
152 vxlan-id 2
153 vxlan-local-tunnelip $ip
154 PART
155 chomp $vxlan12_part;
156
157 expect load('loopback') . <<"CHECK";
158 source-directory interfaces.d
159
160 iface eth0 inet manual
161
162 $eth1_part
163
164 iface eth2 inet manual
165
166 iface eth3 inet manual
167
168 $bond0_part
169
170 $vmbr0_part
171
172 $vxlan12_part
173
174 CHECK
175
176 #
177 # Add vxlan3 and 3 bridges using vxlan1..3
178 #
179
180 $config->{ifaces}->{vmbr1} = {
181 mtu => 1400,
182 type => 'bridge',
183 method => 'manual',
184 families => ['inet'],
185 bridge_stp => 'off',
186 bridge_fd => 0,
187 bridge_ports => 'vxlan1',
188 bridge_vlan_aware => 'yes',
189 autostart => 1
190 };
191
192 $config->{ifaces}->{vmbr2} = {
193 type => 'bridge',
194 method => 'manual',
195 families => ['inet'],
196 bridge_stp => 'off',
197 bridge_fd => 0,
198 bridge_ports => 'vxlan2',
199 autostart => 1
200 };
201
202 $config->{ifaces}->{vmbr3} = {
203 type => 'bridge',
204 method => 'manual',
205 families => ['inet'],
206 bridge_stp => 'off',
207 bridge_fd => 0,
208 bridge_ports => 'vxlan3',
209 bridge_vlan_aware => 'yes',
210 bridge_vids => '2-10',
211 autostart => 1
212 };
213
214 my $vmbr123_part = <<"PART";
215 auto vmbr1
216 iface vmbr1 inet manual
217 bridge-ports vxlan1
218 bridge-stp off
219 bridge-fd 0
220 bridge-vlan-aware yes
221 bridge-vids 2-4094
222 mtu 1400
223
224 auto vmbr2
225 iface vmbr2 inet manual
226 bridge-ports vxlan2
227 bridge-stp off
228 bridge-fd 0
229
230 auto vmbr3
231 iface vmbr3 inet manual
232 bridge-ports vxlan3
233 bridge-stp off
234 bridge-fd 0
235 bridge-vlan-aware yes
236 bridge-vids 2-10
237 PART
238 chomp $vmbr123_part;
239
240 $config->{ifaces}->{vxlan3} = {
241 type => 'vxlan',
242 method => 'manual',
243 families => ['inet'],
244 'vxlan-id' => 3,
245 'vxlan-remoteip' => [$remoteip1, $remoteip2],
246 'bridge-access' => 3,
247 autostart => 1
248 };
249
250 my $vx = $config->{ifaces}->{vxlan2};
251 $vx->{'bridge-learning'} = 'off';
252 $vx->{'bridge-arp-nd-suppress'} = 'on';
253 $vx->{'bridge-unicast-flood'} = 'off';
254 $vx->{'bridge-multicast-flood'} = 'off';
255 my $vxlan123_part = $vxlan12_part ."\n" . <<"PART";
256 bridge-arp-nd-suppress on
257 bridge-learning off
258 bridge-multicast-flood off
259 bridge-unicast-flood off
260
261 auto vxlan3
262 iface vxlan3 inet manual
263 vxlan-id 3
264 vxlan-remoteip $remoteip1
265 vxlan-remoteip $remoteip2
266 bridge-access 3
267 PART
268 chomp $vxlan123_part;
269
270 expect load('loopback') . <<"CHECK";
271 source-directory interfaces.d
272
273 iface eth0 inet manual
274
275 $eth1_part
276
277 iface eth2 inet manual
278
279 iface eth3 inet manual
280
281 $bond0_part
282
283 $vmbr0_part
284
285 $vmbr123_part
286
287 $vxlan123_part
288
289 CHECK
290
291 #
292 # Now add vlans on all types of interfaces: vmbr1, bond0 and eth1
293 #
294
295 $config->{ifaces}->{'vmbr1.100'} = {
296 type => 'vlan',
297 mtu => 1300,
298 method => 'manual',
299 families => ['inet'],
300 autostart => 1
301 };
302
303 $config->{ifaces}->{'bond0.100'} = {
304 type => 'vlan',
305 mtu => 1300,
306 method => 'manual',
307 families => ['inet'],
308 'vlan-protocol' => '802.1ad',
309 autostart => 1
310 };
311
312 $config->{ifaces}->{'bond0.100.10'} = {
313 type => 'vlan',
314 mtu => 1300,
315 method => 'manual',
316 families => ['inet'],
317 autostart => 1
318 };
319
320 $config->{ifaces}->{'eth1.100'} = {
321 type => 'vlan',
322 mtu => 1400,
323 method => 'manual',
324 families => ['inet'],
325 autostart => 1
326 };
327
328 $config->{ifaces}->{'vmbr4'} = {
329 mtu => 1200,
330 type => 'bridge',
331 method => 'manual',
332 families => ['inet'],
333 bridge_stp => 'off',
334 bridge_fd => 0,
335 bridge_ports => 'bond0.100',
336 autostart => 1
337 };
338
339 $config->{ifaces}->{'vmbr5'} = {
340 mtu => 1100,
341 type => 'bridge',
342 method => 'manual',
343 families => ['inet'],
344 bridge_stp => 'off',
345 bridge_fd => 0,
346 bridge_ports => 'vmbr4.99',
347 autostart => 1
348 };
349
350 expect load('loopback') . <<"CHECK";
351 source-directory interfaces.d
352
353 iface eth0 inet manual
354
355 $eth1_part
356
357 iface eth2 inet manual
358
359 iface eth3 inet manual
360
361 auto eth1.100
362 iface eth1.100 inet manual
363 mtu 1400
364
365 $bond0_part
366
367 auto bond0.100
368 iface bond0.100 inet manual
369 mtu 1300
370 vlan-protocol 802.1ad
371
372 auto bond0.100.10
373 iface bond0.100.10 inet manual
374 mtu 1300
375
376 $vmbr0_part
377
378 $vmbr123_part
379
380 auto vmbr4
381 iface vmbr4 inet manual
382 bridge-ports bond0.100
383 bridge-stp off
384 bridge-fd 0
385 mtu 1200
386
387 auto vmbr5
388 iface vmbr5 inet manual
389 bridge-ports vmbr4.99
390 bridge-stp off
391 bridge-fd 0
392 mtu 1100
393
394 auto vmbr1.100
395 iface vmbr1.100 inet manual
396 mtu 1300
397
398 $vxlan123_part
399
400 CHECK
401
402 #
403 # Now check the new config for idempotency:
404 #
405
406 save('if', w());
407 r(load('if'));
408 expect load('if');
409
410 #
411 # Check a brbase with an ipv6 address on eth1
412 #
413
414 r(load('brbase'));
415
416 my $ip = 'fc05::2';
417 my $nm = '112';
418 my $gw = 'fc05::1';
419
420 $config->{ifaces}->{eth1} = {
421 type => 'eth',
422 method6 => 'static',
423 address6 => $ip,
424 netmask6 => $nm,
425 gateway6 => $gw,
426 families => ['inet6'],
427 autostart => 1
428 };
429
430 expect load('loopback') . <<"CHECK";
431 source-directory interfaces.d
432
433 iface eth0 inet manual
434
435 auto eth1
436 iface eth1 inet6 static
437 address $ip
438 netmask $nm
439 gateway $gw
440
441 iface eth2 inet manual
442
443 iface eth3 inet manual
444
445 auto vmbr0
446 iface vmbr0 inet static
447 address 10.0.0.2
448 netmask 255.255.255.0
449 gateway 10.0.0.1
450 bridge-ports eth0
451 bridge-stp off
452 bridge-fd 0
453
454 CHECK
455
456 save('if', w());
457 r(load('if'));
458 expect load('if');
459
460 1;