etc/protocols - sync with NetBSD-8
[minix.git] / tests / net / if_bridge / t_bridge.sh
blob337f44511d9bfdf5236dbdd4fcc241a344d696eb
1 # $NetBSD: t_bridge.sh,v 1.11 2015/08/07 00:50:12 ozaki-r Exp $
3 # Copyright (c) 2014 The NetBSD Foundation, Inc.
4 # All rights reserved.
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.
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.
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_bridge -lrumpnet_shmif"
29 inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_bridge -lrumpnet_shmif"
31 SOCK1=unix://commsock1
32 SOCK2=unix://commsock2
33 SOCK3=unix://commsock3
34 IP1=10.0.0.1
35 IP2=10.0.0.2
36 IP61=fc00::1
37 IP62=fc00::2
38 IPBR1=10.0.0.11
39 IPBR2=10.0.0.12
40 IP6BR1=fc00::11
41 IP6BR2=fc00::12
43 TIMEOUT=5
45 atf_test_case basic cleanup
46 atf_test_case basic6 cleanup
47 atf_test_case rtable cleanup
48 atf_test_case member_ip cleanup
49 atf_test_case member_ip6 cleanup
51 basic_head()
53 atf_set "descr" "Does simple if_bridge tests"
54 atf_set "require.progs" "rump_server"
57 basic6_head()
59 atf_set "descr" "Does simple if_bridge tests (IPv6)"
60 atf_set "require.progs" "rump_server"
63 rtable_head()
65 atf_set "descr" "Tests route table operations of if_bridge"
66 atf_set "require.progs" "rump_server"
69 member_ip_head()
71 atf_set "descr" "Tests if_bridge with members with an IP address"
72 atf_set "require.progs" "rump_server"
75 member_ip6_head()
77 atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
78 atf_set "require.progs" "rump_server"
81 setup_endpoint()
83 sock=${1}
84 addr=${2}
85 bus=${3}
86 mode=${4}
88 export RUMP_SERVER=${sock}
89 atf_check -s exit:0 rump.ifconfig shmif0 create
90 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
91 if [ $mode = "ipv6" ]; then
92 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
93 else
94 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
97 atf_check -s exit:0 rump.ifconfig shmif0 up
98 rump.ifconfig shmif0
101 test_endpoint()
103 sock=${1}
104 addr=${2}
105 bus=${3}
106 mode=${4}
108 export RUMP_SERVER=${sock}
109 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
110 if [ $mode = "ipv6" ]; then
111 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
112 else
113 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
117 show_endpoint()
119 sock=${1}
121 export RUMP_SERVER=${sock}
122 rump.ifconfig -v shmif0
125 test_setup()
127 test_endpoint $SOCK1 $IP1 bus1 ipv4
128 test_endpoint $SOCK3 $IP2 bus2 ipv4
130 export RUMP_SERVER=$SOCK2
131 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
132 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
135 test_setup6()
137 test_endpoint $SOCK1 $IP61 bus1 ipv6
138 test_endpoint $SOCK3 $IP62 bus2 ipv6
140 export RUMP_SERVER=$SOCK2
141 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
142 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
145 setup_bridge_server()
147 export RUMP_SERVER=$SOCK2
148 atf_check -s exit:0 rump.ifconfig shmif0 create
149 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
150 atf_check -s exit:0 rump.ifconfig shmif0 up
152 atf_check -s exit:0 rump.ifconfig shmif1 create
153 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
154 atf_check -s exit:0 rump.ifconfig shmif1 up
157 setup()
159 atf_check -s exit:0 ${inetserver} $SOCK1
160 atf_check -s exit:0 ${inetserver} $SOCK2
161 atf_check -s exit:0 ${inetserver} $SOCK3
163 setup_endpoint $SOCK1 $IP1 bus1 ipv4
164 setup_endpoint $SOCK3 $IP2 bus2 ipv4
165 setup_bridge_server
168 setup6()
170 atf_check -s exit:0 ${inet6server} $SOCK1
171 atf_check -s exit:0 ${inet6server} $SOCK2
172 atf_check -s exit:0 ${inet6server} $SOCK3
174 setup_endpoint $SOCK1 $IP61 bus1 ipv6
175 setup_endpoint $SOCK3 $IP62 bus2 ipv6
176 setup_bridge_server
179 setup_bridge()
181 export RUMP_SERVER=$SOCK2
182 atf_check -s exit:0 rump.ifconfig bridge0 create
183 atf_check -s exit:0 rump.ifconfig bridge0 up
185 export LD_PRELOAD=/usr/lib/librumphijack.so
186 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
187 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
188 /sbin/brconfig bridge0
189 unset LD_PRELOAD
190 rump.ifconfig shmif0
191 rump.ifconfig shmif1
194 setup_member_ip()
196 export RUMP_SERVER=$SOCK2
197 export LD_PRELOAD=/usr/lib/librumphijack.so
198 atf_check -s exit:0 rump.ifconfig shmif0 $IPBR1/24
199 atf_check -s exit:0 rump.ifconfig shmif1 $IPBR2/24
200 atf_check -s exit:0 rump.ifconfig -w 10
201 /sbin/brconfig bridge0
202 unset LD_PRELOAD
203 rump.ifconfig shmif0
204 rump.ifconfig shmif1
207 setup_member_ip6()
209 export RUMP_SERVER=$SOCK2
210 export LD_PRELOAD=/usr/lib/librumphijack.so
211 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6BR1
212 atf_check -s exit:0 rump.ifconfig shmif1 inet6 $IP6BR2
213 atf_check -s exit:0 rump.ifconfig -w 10
214 /sbin/brconfig bridge0
215 unset LD_PRELOAD
216 rump.ifconfig shmif0
217 rump.ifconfig shmif1
220 teardown_bridge()
222 export RUMP_SERVER=$SOCK2
223 export LD_PRELOAD=/usr/lib/librumphijack.so
224 /sbin/brconfig bridge0
225 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0
226 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1
227 /sbin/brconfig bridge0
228 unset LD_PRELOAD
229 rump.ifconfig shmif0
230 rump.ifconfig shmif1
233 test_setup_bridge()
235 export RUMP_SERVER=$SOCK2
236 export LD_PRELOAD=/usr/lib/librumphijack.so
237 atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0
238 atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0
239 /sbin/brconfig bridge0
240 unset LD_PRELOAD
243 cleanup()
245 env RUMP_SERVER=$SOCK1 rump.halt
246 env RUMP_SERVER=$SOCK2 rump.halt
247 env RUMP_SERVER=$SOCK3 rump.halt
250 dump_bus()
252 /usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
253 /usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
256 down_up_interfaces()
258 export RUMP_SERVER=$SOCK1
259 rump.ifconfig shmif0 down
260 rump.ifconfig shmif0 up
261 export RUMP_SERVER=$SOCK3
262 rump.ifconfig shmif0 down
263 rump.ifconfig shmif0 up
266 test_ping_failure()
268 export RUMP_SERVER=$SOCK1
269 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
270 export RUMP_SERVER=$SOCK3
271 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
274 test_ping_success()
276 export RUMP_SERVER=$SOCK1
277 rump.ifconfig -v shmif0
278 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
279 rump.ifconfig -v shmif0
281 export RUMP_SERVER=$SOCK3
282 rump.ifconfig -v shmif0
283 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
284 rump.ifconfig -v shmif0
287 test_ping6_failure()
289 export RUMP_SERVER=$SOCK1
290 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
291 export RUMP_SERVER=$SOCK3
292 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
295 test_ping6_success()
297 export RUMP_SERVER=$SOCK1
298 rump.ifconfig -v shmif0
299 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
300 rump.ifconfig -v shmif0
302 export RUMP_SERVER=$SOCK3
303 rump.ifconfig -v shmif0
304 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
305 rump.ifconfig -v shmif0
308 test_ping_member()
310 export RUMP_SERVER=$SOCK1
311 rump.ifconfig -v shmif0
312 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
313 rump.ifconfig -v shmif0
314 # Test for PR#48104
315 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
316 rump.ifconfig -v shmif0
318 export RUMP_SERVER=$SOCK3
319 rump.ifconfig -v shmif0
320 # Test for PR#48104
321 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
322 rump.ifconfig -v shmif0
323 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
324 rump.ifconfig -v shmif0
327 test_ping6_member()
329 export RUMP_SERVER=$SOCK1
330 rump.ifconfig -v shmif0
331 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
332 rump.ifconfig -v shmif0
333 # Test for PR#48104
334 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
335 rump.ifconfig -v shmif0
337 export RUMP_SERVER=$SOCK3
338 rump.ifconfig -v shmif0
339 # Test for PR#48104
340 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
341 rump.ifconfig -v shmif0
342 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
343 rump.ifconfig -v shmif0
346 get_number_of_caches()
348 export RUMP_SERVER=$SOCK2
349 export LD_PRELOAD=/usr/lib/librumphijack.so
350 echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
351 unset LD_PRELOAD
354 test_brconfig_maxaddr()
356 addr1= addr3= n=
358 # Get MAC addresses of the endpoints.
359 export RUMP_SERVER=$SOCK1
360 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
361 export RUMP_SERVER=$SOCK3
362 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
363 unset RUMP_SERVER
365 # Refill the MAC addresses of the endpoints.
366 export RUMP_SERVER=$SOCK1
367 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
368 export RUMP_SERVER=$SOCK2
369 export LD_PRELOAD=/usr/lib/librumphijack.so
370 /sbin/brconfig bridge0
371 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
372 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
374 # Check the default # of caches is 100
375 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
377 # Test two MAC addresses are cached
378 n=$(get_number_of_caches)
379 atf_check_equal $n 2
381 # Limit # of caches to one
382 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
383 atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
384 /sbin/brconfig bridge0
386 # Test just one address is cached
387 n=$(get_number_of_caches)
388 atf_check_equal $n 1
390 # Increase # of caches to two
391 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
392 atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
393 unset LD_PRELOAD
395 # Test we can cache two addresses again
396 export RUMP_SERVER=$SOCK1
397 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
398 export RUMP_SERVER=$SOCK2
399 export LD_PRELOAD=/usr/lib/librumphijack.so
400 /sbin/brconfig bridge0
401 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
402 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
403 unset LD_PRELOAD
406 basic_body()
408 setup
409 test_setup
411 # Enable once PR kern/49219 is fixed
412 #test_ping_failure
414 setup_bridge
415 sleep 1
416 test_setup_bridge
417 test_ping_success
419 teardown_bridge
420 test_ping_failure
423 basic6_body()
425 setup6
426 test_setup6
428 test_ping6_failure
430 setup_bridge
431 sleep 1
432 test_setup_bridge
433 test_ping6_success
435 teardown_bridge
436 test_ping6_failure
439 rtable_body()
441 addr1= addr3=
443 setup
444 setup_bridge
446 # Get MAC addresses of the endpoints.
447 export RUMP_SERVER=$SOCK1
448 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
449 export RUMP_SERVER=$SOCK3
450 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
451 unset RUMP_SERVER
453 # Confirm there is no MAC address caches.
454 export RUMP_SERVER=$SOCK2
455 export LD_PRELOAD=/usr/lib/librumphijack.so
456 /sbin/brconfig bridge0
457 atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
458 atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
459 unset LD_PRELOAD
461 # Make the bridge learn the MAC addresses of the endpoints.
462 export RUMP_SERVER=$SOCK1
463 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
464 unset RUMP_SERVER
466 # Tests the addresses are in the cache.
467 export RUMP_SERVER=$SOCK2
468 export LD_PRELOAD=/usr/lib/librumphijack.so
469 /sbin/brconfig bridge0
470 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
471 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
473 # Tests brconfig deladdr
474 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
475 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
476 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
477 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
478 unset LD_PRELOAD
480 # Refill the MAC addresses of the endpoints.
481 export RUMP_SERVER=$SOCK1
482 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
483 unset RUMP_SERVER
484 export RUMP_SERVER=$SOCK2
485 export LD_PRELOAD=/usr/lib/librumphijack.so
486 /sbin/brconfig bridge0
487 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
488 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
490 # Tests brconfig flush.
491 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
492 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
493 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
494 unset LD_PRELOAD
496 # Tests brconfig timeout.
497 export RUMP_SERVER=$SOCK2
498 export LD_PRELOAD=/usr/lib/librumphijack.so
499 atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
500 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10
501 atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0
502 unset LD_PRELOAD
504 # Tests brconfig maxaddr.
505 test_brconfig_maxaddr
507 # TODO: brconfig static/flushall/discover/learn
508 # TODO: cache expiration; it takes 5 minutes at least and we want to
509 # wait here so long. Should we have a sysctl to change the period?
512 member_ip_body()
514 setup
515 test_setup
517 # Enable once PR kern/49219 is fixed
518 #test_ping_failure
520 setup_bridge
521 sleep 1
522 test_setup_bridge
523 test_ping_success
525 setup_member_ip
526 test_ping_member
528 teardown_bridge
529 test_ping_failure
532 member_ip6_body()
534 setup6
535 test_setup6
537 test_ping6_failure
539 setup_bridge
540 sleep 1
541 test_setup_bridge
542 test_ping6_success
544 setup_member_ip6
545 test_ping6_member
547 teardown_bridge
548 test_ping6_failure
551 basic_cleanup()
553 dump_bus
554 cleanup
557 basic6_cleanup()
559 dump_bus
560 cleanup
563 rtable_cleanup()
565 dump_bus
566 cleanup
569 member_ip_cleanup()
571 dump_bus
572 cleanup
575 member_ip6_cleanup()
577 dump_bus
578 cleanup
581 atf_init_test_cases()
583 atf_add_test_case basic
584 atf_add_test_case basic6
585 atf_add_test_case rtable
586 atf_add_test_case member_ip
587 atf_add_test_case member_ip6