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.
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 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
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
53 atf_set
"descr" "Does simple if_bridge tests"
54 atf_set
"require.progs" "rump_server"
59 atf_set
"descr" "Does simple if_bridge tests (IPv6)"
60 atf_set
"require.progs" "rump_server"
65 atf_set
"descr" "Tests route table operations of if_bridge"
66 atf_set
"require.progs" "rump_server"
71 atf_set
"descr" "Tests if_bridge with members with an IP address"
72 atf_set
"require.progs" "rump_server"
77 atf_set
"descr" "Tests if_bridge with members with an IP address (IPv6)"
78 atf_set
"require.progs" "rump_server"
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}
94 atf_check
-s exit:0 rump.ifconfig shmif0 inet
${addr} netmask
0xffffff00
97 atf_check
-s exit:0 rump.ifconfig shmif0 up
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}
113 atf_check
-s exit:0 -o ignore rump.
ping -n -w $TIMEOUT -c 1 ${addr}
121 export RUMP_SERVER
=${sock}
122 rump.ifconfig
-v shmif0
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
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
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
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
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
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
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
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
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
245 env RUMP_SERVER
=$SOCK1 rump.halt
246 env RUMP_SERVER
=$SOCK2 rump.halt
247 env RUMP_SERVER
=$SOCK3 rump.halt
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 -
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
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
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
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
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
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
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
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
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
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
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))
354 test_brconfig_maxaddr
()
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;}')
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
)
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
)
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
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
411 # Enable once PR kern/49219 is fixed
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;}')
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
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
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
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
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
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
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?
517 # Enable once PR kern/49219 is fixed
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