]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/if_bridge/t_bridge.sh
MFC r305358,r305449,r305451,r306367,r306397,r309474:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / if_bridge / t_bridge.sh
1 #       $NetBSD: t_bridge.sh,v 1.13 2016/08/10 22:37:07 kre Exp $
2 #
3 # Copyright (c) 2014 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 libs1="-lrumpnet -lrumpnet_net -lrumpnet_netinet"
29 libs2="-lrumpnet_bridge -lrumpnet_shmif -lrumpdev"
30 libs6="-lrumpnet_netinet6"
31
32 inetserver="rump_server ${libs1} ${libs2}"
33 inet6server="rump_server ${libs1} ${libs6} ${libs2}"
34
35 SOCK1=unix://commsock1
36 SOCK2=unix://commsock2
37 SOCK3=unix://commsock3
38 IP1=10.0.0.1
39 IP2=10.0.0.2
40 IP61=fc00::1
41 IP62=fc00::2
42 IPBR1=10.0.0.11
43 IPBR2=10.0.0.12
44 IP6BR1=fc00::11
45 IP6BR2=fc00::12
46
47 TIMEOUT=5
48
49 atf_test_case bridge_ipv4 cleanup
50 atf_test_case bridge_ipv6 cleanup
51 atf_test_case bridge_rtable cleanup
52 atf_test_case bridge_member_ipv4 cleanup
53 atf_test_case bridge_member_ipv6 cleanup
54
55 bridge_ipv4_head()
56 {
57         atf_set "descr" "Does simple if_bridge tests"
58         atf_set "require.progs" "rump_server"
59 }
60
61 bridge_ipv6_head()
62 {
63         atf_set "descr" "Does simple if_bridge tests (IPv6)"
64         atf_set "require.progs" "rump_server"
65 }
66
67 bridge_rtable_head()
68 {
69         atf_set "descr" "Tests route table operations of if_bridge"
70         atf_set "require.progs" "rump_server"
71 }
72
73 bridge_member_ipv4_head()
74 {
75         atf_set "descr" "Tests if_bridge with members with an IP address"
76         atf_set "require.progs" "rump_server"
77 }
78
79 bridge_member_ipv6_head()
80 {
81         atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
82         atf_set "require.progs" "rump_server"
83 }
84
85 setup_endpoint()
86 {
87         sock=${1}
88         addr=${2}
89         bus=${3}
90         mode=${4}
91
92         export RUMP_SERVER=${sock}
93         atf_check -s exit:0 rump.ifconfig shmif0 create
94         atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
95         if [ $mode = "ipv6" ]; then
96                 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
97         else
98                 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
99         fi
100
101         atf_check -s exit:0 rump.ifconfig shmif0 up
102         rump.ifconfig shmif0
103 }
104
105 test_endpoint()
106 {
107         sock=${1}
108         addr=${2}
109         bus=${3}
110         mode=${4}
111
112         export RUMP_SERVER=${sock}
113         atf_check -s exit:0 -o match:shmif0 rump.ifconfig
114         if [ $mode = "ipv6" ]; then
115                 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
116         else
117                 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
118         fi
119 }
120
121 show_endpoint()
122 {
123         sock=${1}
124
125         export RUMP_SERVER=${sock}
126         rump.ifconfig -v shmif0
127 }
128
129 test_setup()
130 {
131         test_endpoint $SOCK1 $IP1 bus1 ipv4
132         test_endpoint $SOCK3 $IP2 bus2 ipv4
133
134         export RUMP_SERVER=$SOCK2
135         atf_check -s exit:0 -o match:shmif0 rump.ifconfig
136         atf_check -s exit:0 -o match:shmif1 rump.ifconfig
137 }
138
139 test_setup6()
140 {
141         test_endpoint $SOCK1 $IP61 bus1 ipv6
142         test_endpoint $SOCK3 $IP62 bus2 ipv6
143
144         export RUMP_SERVER=$SOCK2
145         atf_check -s exit:0 -o match:shmif0 rump.ifconfig
146         atf_check -s exit:0 -o match:shmif1 rump.ifconfig
147 }
148
149 setup_bridge_server()
150 {
151         export RUMP_SERVER=$SOCK2
152         atf_check -s exit:0 rump.ifconfig shmif0 create
153         atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
154         atf_check -s exit:0 rump.ifconfig shmif0 up
155
156         atf_check -s exit:0 rump.ifconfig shmif1 create
157         atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
158         atf_check -s exit:0 rump.ifconfig shmif1 up
159 }
160
161 setup()
162 {
163         atf_check -s exit:0 ${inetserver} $SOCK1
164         atf_check -s exit:0 ${inetserver} $SOCK2
165         atf_check -s exit:0 ${inetserver} $SOCK3
166
167         setup_endpoint $SOCK1 $IP1 bus1 ipv4
168         setup_endpoint $SOCK3 $IP2 bus2 ipv4
169         setup_bridge_server
170 }
171
172 setup6()
173 {
174         atf_check -s exit:0 ${inet6server} $SOCK1
175         atf_check -s exit:0 ${inet6server} $SOCK2
176         atf_check -s exit:0 ${inet6server} $SOCK3
177
178         setup_endpoint $SOCK1 $IP61 bus1 ipv6
179         setup_endpoint $SOCK3 $IP62 bus2 ipv6
180         setup_bridge_server
181 }
182
183 setup_bridge()
184 {
185         export RUMP_SERVER=$SOCK2
186         atf_check -s exit:0 rump.ifconfig bridge0 create
187         atf_check -s exit:0 rump.ifconfig bridge0 up
188
189         export LD_PRELOAD=/usr/lib/librumphijack.so
190         atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
191         atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
192         /sbin/brconfig bridge0
193         unset LD_PRELOAD
194         rump.ifconfig shmif0
195         rump.ifconfig shmif1
196 }
197
198 setup_member_ip()
199 {
200         export RUMP_SERVER=$SOCK2
201         export LD_PRELOAD=/usr/lib/librumphijack.so
202         atf_check -s exit:0 rump.ifconfig shmif0 $IPBR1/24
203         atf_check -s exit:0 rump.ifconfig shmif1 $IPBR2/24
204         atf_check -s exit:0 rump.ifconfig -w 10
205         /sbin/brconfig bridge0
206         unset LD_PRELOAD
207         rump.ifconfig shmif0
208         rump.ifconfig shmif1
209 }
210
211 setup_member_ip6()
212 {
213         export RUMP_SERVER=$SOCK2
214         export LD_PRELOAD=/usr/lib/librumphijack.so
215         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6BR1
216         atf_check -s exit:0 rump.ifconfig shmif1 inet6 $IP6BR2
217         atf_check -s exit:0 rump.ifconfig -w 10
218         /sbin/brconfig bridge0
219         unset LD_PRELOAD
220         rump.ifconfig shmif0
221         rump.ifconfig shmif1
222 }
223
224 teardown_bridge()
225 {
226         export RUMP_SERVER=$SOCK2
227         export LD_PRELOAD=/usr/lib/librumphijack.so
228         /sbin/brconfig bridge0
229         atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0
230         atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1
231         /sbin/brconfig bridge0
232         unset LD_PRELOAD
233         rump.ifconfig shmif0
234         rump.ifconfig shmif1
235 }
236
237 test_setup_bridge()
238 {
239         export RUMP_SERVER=$SOCK2
240         export LD_PRELOAD=/usr/lib/librumphijack.so
241         atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0
242         atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0
243         /sbin/brconfig bridge0
244         unset LD_PRELOAD
245 }
246
247 cleanup()
248 {
249         env RUMP_SERVER=$SOCK1 rump.halt
250         env RUMP_SERVER=$SOCK2 rump.halt
251         env RUMP_SERVER=$SOCK3 rump.halt
252 }
253
254 dump_bus()
255 {
256         /usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
257         /usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
258 }
259
260 down_up_interfaces()
261 {
262         export RUMP_SERVER=$SOCK1
263         rump.ifconfig shmif0 down
264         rump.ifconfig shmif0 up
265         export RUMP_SERVER=$SOCK3
266         rump.ifconfig shmif0 down
267         rump.ifconfig shmif0 up
268 }
269
270 test_ping_failure()
271 {
272         export RUMP_SERVER=$SOCK1
273         atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
274         export RUMP_SERVER=$SOCK3
275         atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
276 }
277
278 test_ping_success()
279 {
280         export RUMP_SERVER=$SOCK1
281         rump.ifconfig -v shmif0
282         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
283         rump.ifconfig -v shmif0
284
285         export RUMP_SERVER=$SOCK3
286         rump.ifconfig -v shmif0
287         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
288         rump.ifconfig -v shmif0
289 }
290
291 test_ping6_failure()
292 {
293         export RUMP_SERVER=$SOCK1
294         atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
295         export RUMP_SERVER=$SOCK3
296         atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
297 }
298
299 test_ping6_success()
300 {
301         export RUMP_SERVER=$SOCK1
302         rump.ifconfig -v shmif0
303         atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
304         rump.ifconfig -v shmif0
305
306         export RUMP_SERVER=$SOCK3
307         rump.ifconfig -v shmif0
308         atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
309         rump.ifconfig -v shmif0
310 }
311
312 test_ping_member()
313 {
314         export RUMP_SERVER=$SOCK1
315         rump.ifconfig -v shmif0
316         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
317         rump.ifconfig -v shmif0
318         # Test for PR#48104
319         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
320         rump.ifconfig -v shmif0
321
322         export RUMP_SERVER=$SOCK3
323         rump.ifconfig -v shmif0
324         # Test for PR#48104
325         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
326         rump.ifconfig -v shmif0
327         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
328         rump.ifconfig -v shmif0
329 }
330
331 test_ping6_member()
332 {
333         export RUMP_SERVER=$SOCK1
334         rump.ifconfig -v shmif0
335         atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
336         rump.ifconfig -v shmif0
337         # Test for PR#48104
338         atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
339         rump.ifconfig -v shmif0
340
341         export RUMP_SERVER=$SOCK3
342         rump.ifconfig -v shmif0
343         # Test for PR#48104
344         atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
345         rump.ifconfig -v shmif0
346         atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
347         rump.ifconfig -v shmif0
348 }
349
350 get_number_of_caches()
351 {
352         export RUMP_SERVER=$SOCK2
353         export LD_PRELOAD=/usr/lib/librumphijack.so
354         echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
355         unset LD_PRELOAD
356 }
357
358 test_brconfig_maxaddr()
359 {
360         addr1= addr3= n=
361
362         # Get MAC addresses of the endpoints.
363         export RUMP_SERVER=$SOCK1
364         addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
365         export RUMP_SERVER=$SOCK3
366         addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
367         unset RUMP_SERVER
368
369         # Refill the MAC addresses of the endpoints.
370         export RUMP_SERVER=$SOCK1
371         atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
372         export RUMP_SERVER=$SOCK2
373         export LD_PRELOAD=/usr/lib/librumphijack.so
374         /sbin/brconfig bridge0
375         atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
376         atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
377
378         # Check the default # of caches is 100
379         atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
380
381         # Test two MAC addresses are cached
382         n=$(get_number_of_caches)
383         atf_check_equal $n 2
384
385         # Limit # of caches to one
386         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
387         atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
388         /sbin/brconfig bridge0
389
390         # Test just one address is cached
391         n=$(get_number_of_caches)
392         atf_check_equal $n 1
393
394         # Increase # of caches to two
395         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
396         atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
397         unset LD_PRELOAD
398
399         # Test we can cache two addresses again
400         export RUMP_SERVER=$SOCK1
401         atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
402         export RUMP_SERVER=$SOCK2
403         export LD_PRELOAD=/usr/lib/librumphijack.so
404         /sbin/brconfig bridge0
405         atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
406         atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
407         unset LD_PRELOAD
408 }
409
410 bridge_ipv4_body()
411 {
412         setup
413         test_setup
414
415         # Enable once PR kern/49219 is fixed
416         #test_ping_failure
417
418         setup_bridge
419         sleep 1
420         test_setup_bridge
421         test_ping_success
422
423         teardown_bridge
424         test_ping_failure
425 }
426
427 bridge_ipv6_body()
428 {
429         setup6
430         test_setup6
431
432         test_ping6_failure
433
434         setup_bridge
435         sleep 1
436         test_setup_bridge
437         test_ping6_success
438
439         teardown_bridge
440         test_ping6_failure
441 }
442
443 bridge_rtable_body()
444 {
445         addr1= addr3=
446
447         setup
448         setup_bridge
449
450         # Get MAC addresses of the endpoints.
451         export RUMP_SERVER=$SOCK1
452         addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
453         export RUMP_SERVER=$SOCK3
454         addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
455         unset RUMP_SERVER
456
457         # Confirm there is no MAC address caches.
458         export RUMP_SERVER=$SOCK2
459         export LD_PRELOAD=/usr/lib/librumphijack.so
460         /sbin/brconfig bridge0
461         atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
462         atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
463         unset LD_PRELOAD
464
465         # Make the bridge learn the MAC addresses of the endpoints.
466         export RUMP_SERVER=$SOCK1
467         atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
468         unset RUMP_SERVER
469
470         # Tests the addresses are in the cache.
471         export RUMP_SERVER=$SOCK2
472         export LD_PRELOAD=/usr/lib/librumphijack.so
473         /sbin/brconfig bridge0
474         atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
475         atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
476
477         # Tests brconfig deladdr
478         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
479         atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
480         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
481         atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
482         unset LD_PRELOAD
483
484         # Refill the MAC addresses of the endpoints.
485         export RUMP_SERVER=$SOCK1
486         atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
487         unset RUMP_SERVER
488         export RUMP_SERVER=$SOCK2
489         export LD_PRELOAD=/usr/lib/librumphijack.so
490         /sbin/brconfig bridge0
491         atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
492         atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
493
494         # Tests brconfig flush.
495         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
496         atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
497         atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
498         unset LD_PRELOAD
499
500         # Tests brconfig timeout.
501         export RUMP_SERVER=$SOCK2
502         export LD_PRELOAD=/usr/lib/librumphijack.so
503         atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
504         atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10
505         atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0
506         unset LD_PRELOAD
507
508         # Tests brconfig maxaddr.
509         test_brconfig_maxaddr
510
511         # TODO: brconfig static/flushall/discover/learn
512         # TODO: cache expiration; it takes 5 minutes at least and we want to
513         #       wait here so long. Should we have a sysctl to change the period?
514 }
515
516 bridge_member_ipv4_body()
517 {
518         setup
519         test_setup
520
521         # Enable once PR kern/49219 is fixed
522         #test_ping_failure
523
524         setup_bridge
525         sleep 1
526         test_setup_bridge
527         test_ping_success
528
529         setup_member_ip
530         test_ping_member
531
532         teardown_bridge
533         test_ping_failure
534 }
535
536 bridge_member_ipv6_body()
537 {
538         setup6
539         test_setup6
540
541         test_ping6_failure
542
543         setup_bridge
544         sleep 1
545         test_setup_bridge
546         test_ping6_success
547
548         setup_member_ip6
549         test_ping6_member
550
551         teardown_bridge
552         test_ping6_failure
553 }
554
555 bridge_ipv4_cleanup()
556 {
557         dump_bus
558         cleanup
559 }
560
561 bridge_ipv6_cleanup()
562 {
563         dump_bus
564         cleanup
565 }
566
567 bridge_rtable_cleanup()
568 {
569         dump_bus
570         cleanup
571 }
572
573 bridge_member_ipv4_cleanup()
574 {
575         dump_bus
576         cleanup
577 }
578
579 bridge_member_ipv6_cleanup()
580 {
581         dump_bus
582         cleanup
583 }
584
585 atf_init_test_cases()
586 {
587         atf_add_test_case bridge_ipv4
588         atf_add_test_case bridge_ipv6
589         atf_add_test_case bridge_rtable
590         atf_add_test_case bridge_member_ipv4
591         atf_add_test_case bridge_member_ipv6
592 }