1 # $NetBSD: t_bridge.sh,v 1.13 2016/08/10 22:37:07 kre Exp $
3 # Copyright (c) 2014 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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 libs1="-lrumpnet -lrumpnet_net -lrumpnet_netinet"
29 libs2="-lrumpnet_bridge -lrumpnet_shmif -lrumpdev"
30 libs6="-lrumpnet_netinet6"
32 inetserver="rump_server ${libs1} ${libs2}"
33 inet6server="rump_server ${libs1} ${libs6} ${libs2}"
35 SOCK1=unix://commsock1
36 SOCK2=unix://commsock2
37 SOCK3=unix://commsock3
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
57 atf_set "descr" "Does simple if_bridge tests"
58 atf_set "require.progs" "rump_server"
63 atf_set "descr" "Does simple if_bridge tests (IPv6)"
64 atf_set "require.progs" "rump_server"
69 atf_set "descr" "Tests route table operations of if_bridge"
70 atf_set "require.progs" "rump_server"
73 bridge_member_ipv4_head()
75 atf_set "descr" "Tests if_bridge with members with an IP address"
76 atf_set "require.progs" "rump_server"
79 bridge_member_ipv6_head()
81 atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
82 atf_set "require.progs" "rump_server"
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}
98 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
101 atf_check -s exit:0 rump.ifconfig shmif0 up
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}
117 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
125 export RUMP_SERVER=${sock}
126 rump.ifconfig -v shmif0
131 test_endpoint $SOCK1 $IP1 bus1 ipv4
132 test_endpoint $SOCK3 $IP2 bus2 ipv4
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
141 test_endpoint $SOCK1 $IP61 bus1 ipv6
142 test_endpoint $SOCK3 $IP62 bus2 ipv6
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
149 setup_bridge_server()
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
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
163 atf_check -s exit:0 ${inetserver} $SOCK1
164 atf_check -s exit:0 ${inetserver} $SOCK2
165 atf_check -s exit:0 ${inetserver} $SOCK3
167 setup_endpoint $SOCK1 $IP1 bus1 ipv4
168 setup_endpoint $SOCK3 $IP2 bus2 ipv4
174 atf_check -s exit:0 ${inet6server} $SOCK1
175 atf_check -s exit:0 ${inet6server} $SOCK2
176 atf_check -s exit:0 ${inet6server} $SOCK3
178 setup_endpoint $SOCK1 $IP61 bus1 ipv6
179 setup_endpoint $SOCK3 $IP62 bus2 ipv6
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
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
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
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
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
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
249 env RUMP_SERVER=$SOCK1 rump.halt
250 env RUMP_SERVER=$SOCK2 rump.halt
251 env RUMP_SERVER=$SOCK3 rump.halt
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 -
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
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
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
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
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
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
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
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
319 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
320 rump.ifconfig -v shmif0
322 export RUMP_SERVER=$SOCK3
323 rump.ifconfig -v shmif0
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
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
338 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
339 rump.ifconfig -v shmif0
341 export RUMP_SERVER=$SOCK3
342 rump.ifconfig -v shmif0
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
350 get_number_of_caches()
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))
358 test_brconfig_maxaddr()
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;}')
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
378 # Check the default # of caches is 100
379 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
381 # Test two MAC addresses are cached
382 n=$(get_number_of_caches)
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
390 # Test just one address is cached
391 n=$(get_number_of_caches)
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
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
415 # Enable once PR kern/49219 is fixed
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;}')
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
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
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
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
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
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
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
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
508 # Tests brconfig maxaddr.
509 test_brconfig_maxaddr
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?
516 bridge_member_ipv4_body()
521 # Enable once PR kern/49219 is fixed
536 bridge_member_ipv6_body()
555 bridge_ipv4_cleanup()
561 bridge_ipv6_cleanup()
567 bridge_rtable_cleanup()
573 bridge_member_ipv4_cleanup()
579 bridge_member_ipv6_cleanup()
585 atf_init_test_cases()
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