Home | History | Annotate | Line # | Download | only in if_bridge
t_bridge.sh revision 1.2
      1 #! /usr/bin/atf-sh
      2 #	$NetBSD: t_bridge.sh,v 1.2 2015/01/07 08:55:01 ozaki-r Exp $
      3 #
      4 # Copyright (c) 2014 The NetBSD Foundation, Inc.
      5 # All rights reserved.
      6 #
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 #
     16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26 # POSSIBILITY OF SUCH DAMAGE.
     27 #
     28 
     29 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_bridge -lrumpnet_shmif"
     30 inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_bridge -lrumpnet_shmif"
     31 
     32 SOCK1=unix://commsock1
     33 SOCK2=unix://commsock2
     34 SOCK3=unix://commsock3
     35 IP1=10.0.0.1
     36 IP2=10.0.0.2
     37 IP61=fc00::1
     38 IP62=fc00::2
     39 
     40 atf_test_case basic cleanup
     41 atf_test_case basic6 cleanup
     42 atf_test_case rtable cleanup
     43 
     44 basic_head()
     45 {
     46 	atf_set "descr" "Does simple if_bridge tests"
     47 	atf_set "require.progs" "rump_server"
     48 }
     49 
     50 basic6_head()
     51 {
     52 	atf_set "descr" "Does simple if_bridge tests (IPv6)"
     53 	atf_set "require.progs" "rump_server"
     54 }
     55 
     56 rtable_head()
     57 {
     58 	atf_set "descr" "Tests route table operations of if_bridge"
     59 	atf_set "require.progs" "rump_server"
     60 }
     61 
     62 setup_endpoint()
     63 {
     64 	sock=${1}
     65 	addr=${2}
     66 	bus=${3}
     67 	mode=${4}
     68 
     69 	export RUMP_SERVER=${sock}
     70 	atf_check -s exit:0 rump.ifconfig shmif0 create
     71 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
     72 	if [ $mode = "ipv6" ]; then
     73 		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
     74 	else
     75 		atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
     76 	fi
     77 
     78 	atf_check -s exit:0 rump.ifconfig shmif0 up
     79 	rump.ifconfig shmif0
     80 }
     81 
     82 test_endpoint()
     83 {
     84 	sock=${1}
     85 	addr=${2}
     86 	bus=${3}
     87 	mode=${4}
     88 
     89 	export RUMP_SERVER=${sock}
     90 	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
     91 	if [ $mode = "ipv6" ]; then
     92 		export LD_PRELOAD=/usr/lib/librumphijack.so
     93 		atf_check -s exit:0 -o ignore ping6 -n -c 1 ${addr}
     94 		unset LD_PRELOAD
     95 	else
     96 		atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 ${addr}
     97 	fi
     98 }
     99 
    100 show_endpoint()
    101 {
    102 	sock=${1}
    103 
    104 	export RUMP_SERVER=${sock}
    105 	rump.ifconfig -v shmif0
    106 }
    107 
    108 test_setup()
    109 {
    110 	test_endpoint $SOCK1 $IP1 bus1 ipv4
    111 	test_endpoint $SOCK3 $IP2 bus2 ipv4
    112 
    113 	export RUMP_SERVER=$SOCK2
    114 	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
    115 	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
    116 }
    117 
    118 test_setup6()
    119 {
    120 	test_endpoint $SOCK1 $IP61 bus1 ipv6
    121 	test_endpoint $SOCK3 $IP62 bus2 ipv6
    122 
    123 	export RUMP_SERVER=$SOCK2
    124 	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
    125 	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
    126 }
    127 
    128 setup_bridge_server()
    129 {
    130 	export RUMP_SERVER=$SOCK2
    131 	atf_check -s exit:0 rump.ifconfig shmif0 create
    132 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    133 	atf_check -s exit:0 rump.ifconfig shmif0 up
    134 
    135 	atf_check -s exit:0 rump.ifconfig shmif1 create
    136 	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
    137 	atf_check -s exit:0 rump.ifconfig shmif1 up
    138 }
    139 
    140 setup()
    141 {
    142 	atf_check -s exit:0 ${inetserver} $SOCK1
    143 	atf_check -s exit:0 ${inetserver} $SOCK2
    144 	atf_check -s exit:0 ${inetserver} $SOCK3
    145 
    146 	setup_endpoint $SOCK1 $IP1 bus1 ipv4
    147 	setup_endpoint $SOCK3 $IP2 bus2 ipv4
    148 	setup_bridge_server
    149 }
    150 
    151 setup6()
    152 {
    153 	atf_check -s exit:0 ${inet6server} $SOCK1
    154 	atf_check -s exit:0 ${inet6server} $SOCK2
    155 	atf_check -s exit:0 ${inet6server} $SOCK3
    156 
    157 	setup_endpoint $SOCK1 $IP61 bus1 ipv6
    158 	setup_endpoint $SOCK3 $IP62 bus2 ipv6
    159 	setup_bridge_server
    160 }
    161 
    162 setup_bridge()
    163 {
    164 	export RUMP_SERVER=$SOCK2
    165 	atf_check -s exit:0 rump.ifconfig bridge0 create
    166 	atf_check -s exit:0 rump.ifconfig bridge0 up
    167 
    168 	export LD_PRELOAD=/usr/lib/librumphijack.so
    169 	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
    170 	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
    171 	/sbin/brconfig bridge0
    172 	unset LD_PRELOAD
    173 	rump.ifconfig shmif0
    174 	rump.ifconfig shmif1
    175 }
    176 
    177 teardown_bridge()
    178 {
    179 	export RUMP_SERVER=$SOCK2
    180 	export LD_PRELOAD=/usr/lib/librumphijack.so
    181 	/sbin/brconfig bridge0
    182 	atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0
    183 	atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1
    184 	/sbin/brconfig bridge0
    185 	unset LD_PRELOAD
    186 	rump.ifconfig shmif0
    187 	rump.ifconfig shmif1
    188 }
    189 
    190 test_setup_bridge()
    191 {
    192 	export RUMP_SERVER=$SOCK2
    193 	export LD_PRELOAD=/usr/lib/librumphijack.so
    194 	atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0
    195 	atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0
    196 	/sbin/brconfig bridge0
    197 	unset LD_PRELOAD
    198 }
    199 
    200 cleanup()
    201 {
    202 	env RUMP_SERVER=$SOCK1 rump.halt
    203 	env RUMP_SERVER=$SOCK2 rump.halt
    204 	env RUMP_SERVER=$SOCK3 rump.halt
    205 }
    206 
    207 dump_bus()
    208 {
    209 	/usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
    210 	/usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
    211 }
    212 
    213 down_up_interfaces()
    214 {
    215 	export RUMP_SERVER=$SOCK1
    216 	rump.ifconfig shmif0 down
    217 	rump.ifconfig shmif0 up
    218 	export RUMP_SERVER=$SOCK3
    219 	rump.ifconfig shmif0 down
    220 	rump.ifconfig shmif0 up
    221 }
    222 
    223 test_ping_failure()
    224 {
    225 	export RUMP_SERVER=$SOCK1
    226 	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w 1 -c 1 $IP2
    227 	export RUMP_SERVER=$SOCK3
    228 	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w 1 -c 1 $IP1
    229 }
    230 
    231 test_ping_success()
    232 {
    233 	export RUMP_SERVER=$SOCK1
    234 	rump.ifconfig -v shmif0
    235 	atf_check -s exit:0 -o ignore rump.ping -q -n -w 1 -c 1 $IP2
    236 	rump.ifconfig -v shmif0
    237 
    238 	export RUMP_SERVER=$SOCK3
    239 	rump.ifconfig -v shmif0
    240 	atf_check -s exit:0 -o ignore rump.ping -q -n -w 1 -c 1 $IP1
    241 	rump.ifconfig -v shmif0
    242 }
    243 
    244 test_ping6_failure()
    245 {
    246 	export LD_PRELOAD=/usr/lib/librumphijack.so
    247 	export RUMP_SERVER=$SOCK1
    248 	atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 $IP62
    249 	export RUMP_SERVER=$SOCK3
    250 	atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 $IP61
    251 	unset LD_PRELOAD
    252 }
    253 
    254 test_ping6_success()
    255 {
    256 	export RUMP_SERVER=$SOCK1
    257 	rump.ifconfig -v shmif0
    258 	export LD_PRELOAD=/usr/lib/librumphijack.so
    259 	atf_check -s exit:0 -o ignore ping6 -q -n -c 1 $IP62
    260 	unset LD_PRELOAD
    261 	rump.ifconfig -v shmif0
    262 
    263 	export RUMP_SERVER=$SOCK3
    264 	rump.ifconfig -v shmif0
    265 	export LD_PRELOAD=/usr/lib/librumphijack.so
    266 	atf_check -s exit:0 -o ignore ping6 -q -n -c 1 $IP61
    267 	unset LD_PRELOAD
    268 	rump.ifconfig -v shmif0
    269 }
    270 
    271 basic_body()
    272 {
    273 	setup
    274 	test_setup
    275 
    276 	setup_bridge
    277 	test_setup_bridge
    278 
    279 	test_ping_success
    280 
    281 	teardown_bridge
    282 	test_ping_failure
    283 }
    284 
    285 basic6_body()
    286 {
    287 	setup6
    288 	test_setup6
    289 
    290 	# TODO: enable once ping6 implements timeout feature
    291 	#test_ping6_failure
    292 
    293 	setup_bridge
    294 	test_setup_bridge
    295 
    296 	test_ping6_success
    297 
    298 	teardown_bridge
    299 	# TODO: enable once ping6 implements timeout feature
    300 	#test_ping6_failure
    301 }
    302 
    303 rtable_body()
    304 {
    305 	addr1= addr3=
    306 
    307 	setup
    308 	setup_bridge
    309 
    310 	# Get MAC addresses of the endpoints.
    311 	export RUMP_SERVER=$SOCK1
    312 	addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
    313 	export RUMP_SERVER=$SOCK3
    314 	addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
    315 	unset RUMP_SERVER
    316 
    317 	# Confirm there is no MAC address caches.
    318 	export RUMP_SERVER=$SOCK2
    319 	export LD_PRELOAD=/usr/lib/librumphijack.so
    320 	/sbin/brconfig bridge0
    321 	atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
    322 	atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
    323 	unset LD_PRELOAD
    324 
    325 	# Make the bridge learn the MAC addresses of the endpoints.
    326 	export RUMP_SERVER=$SOCK1
    327 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP2
    328 	unset RUMP_SERVER
    329 
    330 	# Tests the addresses are in the cache.
    331 	export RUMP_SERVER=$SOCK2
    332 	export LD_PRELOAD=/usr/lib/librumphijack.so
    333 	/sbin/brconfig bridge0
    334 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    335 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    336 
    337 	# Tests brconfig deladdr
    338 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
    339 	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
    340 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
    341 	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
    342 	unset LD_PRELOAD
    343 
    344 	# Refill the MAC addresses of the endpoints.
    345 	export RUMP_SERVER=$SOCK1
    346 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP2
    347 	unset RUMP_SERVER
    348 	export RUMP_SERVER=$SOCK2
    349 	export LD_PRELOAD=/usr/lib/librumphijack.so
    350 	/sbin/brconfig bridge0
    351 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    352 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    353 
    354 	# Tests brconfig flush.
    355 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
    356 	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
    357 	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
    358 	unset LD_PRELOAD
    359 
    360 	# Tests brconfig timeout.
    361 	export RUMP_SERVER=$SOCK2
    362 	export LD_PRELOAD=/usr/lib/librumphijack.so
    363 	atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
    364 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10
    365 	atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0
    366 	unset LD_PRELOAD
    367 
    368 	# TODO: brconfig static/flushall/discover/learn
    369 	# TODO: cache expiration; it takes 5 minutes at least and we want to
    370 	#       wait here so long. Should we have a sysctl to change the period?
    371 }
    372 
    373 basic_cleanup()
    374 {
    375 	dump_bus
    376 	cleanup
    377 }
    378 
    379 basic6_cleanup()
    380 {
    381 	dump_bus
    382 	cleanup
    383 }
    384 
    385 rtable_cleanup()
    386 {
    387 	dump_bus
    388 	cleanup
    389 }
    390 
    391 atf_init_test_cases()
    392 {
    393 	atf_add_test_case basic
    394 	atf_add_test_case basic6
    395 	atf_add_test_case rtable
    396 }
    397