t_bridge.sh revision 1.7
1# $NetBSD: t_bridge.sh,v 1.7 2015/05/29 10:08:52 ozaki-r 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 28inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_bridge -lrumpnet_shmif" 29inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_bridge -lrumpnet_shmif" 30 31SOCK1=unix://commsock1 32SOCK2=unix://commsock2 33SOCK3=unix://commsock3 34IP1=10.0.0.1 35IP2=10.0.0.2 36IP61=fc00::1 37IP62=fc00::2 38 39TIMEOUT=5 40 41atf_test_case basic cleanup 42atf_test_case basic6 cleanup 43atf_test_case rtable cleanup 44 45basic_head() 46{ 47 atf_set "descr" "Does simple if_bridge tests" 48 atf_set "require.progs" "rump_server" 49} 50 51basic6_head() 52{ 53 atf_set "descr" "Does simple if_bridge tests (IPv6)" 54 atf_set "require.progs" "rump_server" 55} 56 57rtable_head() 58{ 59 atf_set "descr" "Tests route table operations of if_bridge" 60 atf_set "require.progs" "rump_server" 61} 62 63setup_endpoint() 64{ 65 sock=${1} 66 addr=${2} 67 bus=${3} 68 mode=${4} 69 70 export RUMP_SERVER=${sock} 71 atf_check -s exit:0 rump.ifconfig shmif0 create 72 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus} 73 if [ $mode = "ipv6" ]; then 74 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr} 75 else 76 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00 77 fi 78 79 atf_check -s exit:0 rump.ifconfig shmif0 up 80 rump.ifconfig shmif0 81} 82 83test_endpoint() 84{ 85 sock=${1} 86 addr=${2} 87 bus=${3} 88 mode=${4} 89 90 export RUMP_SERVER=${sock} 91 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 92 if [ $mode = "ipv6" ]; then 93 export LD_PRELOAD=/usr/lib/librumphijack.so 94 atf_check -s exit:0 -o ignore ping6 -n -c 1 -X $TIMEOUT ${addr} 95 unset LD_PRELOAD 96 else 97 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr} 98 fi 99} 100 101show_endpoint() 102{ 103 sock=${1} 104 105 export RUMP_SERVER=${sock} 106 rump.ifconfig -v shmif0 107} 108 109test_setup() 110{ 111 test_endpoint $SOCK1 $IP1 bus1 ipv4 112 test_endpoint $SOCK3 $IP2 bus2 ipv4 113 114 export RUMP_SERVER=$SOCK2 115 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 116 atf_check -s exit:0 -o match:shmif1 rump.ifconfig 117} 118 119test_setup6() 120{ 121 test_endpoint $SOCK1 $IP61 bus1 ipv6 122 test_endpoint $SOCK3 $IP62 bus2 ipv6 123 124 export RUMP_SERVER=$SOCK2 125 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 126 atf_check -s exit:0 -o match:shmif1 rump.ifconfig 127} 128 129setup_bridge_server() 130{ 131 export RUMP_SERVER=$SOCK2 132 atf_check -s exit:0 rump.ifconfig shmif0 create 133 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1 134 atf_check -s exit:0 rump.ifconfig shmif0 up 135 136 atf_check -s exit:0 rump.ifconfig shmif1 create 137 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2 138 atf_check -s exit:0 rump.ifconfig shmif1 up 139} 140 141setup() 142{ 143 atf_check -s exit:0 ${inetserver} $SOCK1 144 atf_check -s exit:0 ${inetserver} $SOCK2 145 atf_check -s exit:0 ${inetserver} $SOCK3 146 147 setup_endpoint $SOCK1 $IP1 bus1 ipv4 148 setup_endpoint $SOCK3 $IP2 bus2 ipv4 149 setup_bridge_server 150} 151 152setup6() 153{ 154 atf_check -s exit:0 ${inet6server} $SOCK1 155 atf_check -s exit:0 ${inet6server} $SOCK2 156 atf_check -s exit:0 ${inet6server} $SOCK3 157 158 setup_endpoint $SOCK1 $IP61 bus1 ipv6 159 setup_endpoint $SOCK3 $IP62 bus2 ipv6 160 setup_bridge_server 161} 162 163setup_bridge() 164{ 165 export RUMP_SERVER=$SOCK2 166 atf_check -s exit:0 rump.ifconfig bridge0 create 167 atf_check -s exit:0 rump.ifconfig bridge0 up 168 169 export LD_PRELOAD=/usr/lib/librumphijack.so 170 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0 171 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1 172 /sbin/brconfig bridge0 173 unset LD_PRELOAD 174 rump.ifconfig shmif0 175 rump.ifconfig shmif1 176} 177 178teardown_bridge() 179{ 180 export RUMP_SERVER=$SOCK2 181 export LD_PRELOAD=/usr/lib/librumphijack.so 182 /sbin/brconfig bridge0 183 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0 184 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1 185 /sbin/brconfig bridge0 186 unset LD_PRELOAD 187 rump.ifconfig shmif0 188 rump.ifconfig shmif1 189} 190 191test_setup_bridge() 192{ 193 export RUMP_SERVER=$SOCK2 194 export LD_PRELOAD=/usr/lib/librumphijack.so 195 atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0 196 atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0 197 /sbin/brconfig bridge0 198 unset LD_PRELOAD 199} 200 201cleanup() 202{ 203 env RUMP_SERVER=$SOCK1 rump.halt 204 env RUMP_SERVER=$SOCK2 rump.halt 205 env RUMP_SERVER=$SOCK3 rump.halt 206} 207 208dump_bus() 209{ 210 /usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r - 211 /usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r - 212} 213 214down_up_interfaces() 215{ 216 export RUMP_SERVER=$SOCK1 217 rump.ifconfig shmif0 down 218 rump.ifconfig shmif0 up 219 export RUMP_SERVER=$SOCK3 220 rump.ifconfig shmif0 down 221 rump.ifconfig shmif0 up 222} 223 224test_ping_failure() 225{ 226 export RUMP_SERVER=$SOCK1 227 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2 228 export RUMP_SERVER=$SOCK3 229 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1 230} 231 232test_ping_success() 233{ 234 export RUMP_SERVER=$SOCK1 235 rump.ifconfig -v shmif0 236 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2 237 rump.ifconfig -v shmif0 238 239 export RUMP_SERVER=$SOCK3 240 rump.ifconfig -v shmif0 241 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1 242 rump.ifconfig -v shmif0 243} 244 245test_ping6_failure() 246{ 247 export LD_PRELOAD=/usr/lib/librumphijack.so 248 export RUMP_SERVER=$SOCK1 249 atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62 250 export RUMP_SERVER=$SOCK3 251 atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61 252 unset LD_PRELOAD 253} 254 255test_ping6_success() 256{ 257 export RUMP_SERVER=$SOCK1 258 rump.ifconfig -v shmif0 259 export LD_PRELOAD=/usr/lib/librumphijack.so 260 atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62 261 unset LD_PRELOAD 262 rump.ifconfig -v shmif0 263 264 export RUMP_SERVER=$SOCK3 265 rump.ifconfig -v shmif0 266 export LD_PRELOAD=/usr/lib/librumphijack.so 267 atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61 268 unset LD_PRELOAD 269 rump.ifconfig -v shmif0 270} 271 272get_number_of_caches() 273{ 274 export RUMP_SERVER=$SOCK2 275 export LD_PRELOAD=/usr/lib/librumphijack.so 276 echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1)) 277 unset LD_PRELOAD 278} 279 280test_brconfig_maxaddr() 281{ 282 addr1= addr3= n= 283 284 # Get MAC addresses of the endpoints. 285 export RUMP_SERVER=$SOCK1 286 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 287 export RUMP_SERVER=$SOCK3 288 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 289 unset RUMP_SERVER 290 291 # Refill the MAC addresses of the endpoints. 292 export RUMP_SERVER=$SOCK1 293 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 294 export RUMP_SERVER=$SOCK2 295 export LD_PRELOAD=/usr/lib/librumphijack.so 296 /sbin/brconfig bridge0 297 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 298 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 299 300 # Check the default # of caches is 100 301 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0 302 303 # Test two MAC addresses are cached 304 n=$(get_number_of_caches) 305 atf_check_equal $n 2 306 307 # Limit # of caches to one 308 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1 309 atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0 310 /sbin/brconfig bridge0 311 312 # Test just one address is cached 313 n=$(get_number_of_caches) 314 atf_check_equal $n 1 315 316 # Increase # of caches to two 317 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2 318 atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0 319 unset LD_PRELOAD 320 321 # Test we can cache two addresses again 322 export RUMP_SERVER=$SOCK1 323 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 324 export RUMP_SERVER=$SOCK2 325 export LD_PRELOAD=/usr/lib/librumphijack.so 326 /sbin/brconfig bridge0 327 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 328 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 329 unset LD_PRELOAD 330} 331 332basic_body() 333{ 334 setup 335 test_setup 336 337 # Enable once PR kern/49219 is fixed 338 #test_ping_failure 339 340 setup_bridge 341 sleep 1 342 test_setup_bridge 343 test_ping_success 344 345 teardown_bridge 346 test_ping_failure 347} 348 349basic6_body() 350{ 351 setup6 352 test_setup6 353 354 test_ping6_failure 355 356 setup_bridge 357 sleep 1 358 test_setup_bridge 359 test_ping6_success 360 361 teardown_bridge 362 test_ping6_failure 363} 364 365rtable_body() 366{ 367 addr1= addr3= 368 369 setup 370 setup_bridge 371 372 # Get MAC addresses of the endpoints. 373 export RUMP_SERVER=$SOCK1 374 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 375 export RUMP_SERVER=$SOCK3 376 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 377 unset RUMP_SERVER 378 379 # Confirm there is no MAC address caches. 380 export RUMP_SERVER=$SOCK2 381 export LD_PRELOAD=/usr/lib/librumphijack.so 382 /sbin/brconfig bridge0 383 atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0 384 atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0 385 unset LD_PRELOAD 386 387 # Make the bridge learn the MAC addresses of the endpoints. 388 export RUMP_SERVER=$SOCK1 389 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 390 unset RUMP_SERVER 391 392 # Tests the addresses are in the cache. 393 export RUMP_SERVER=$SOCK2 394 export LD_PRELOAD=/usr/lib/librumphijack.so 395 /sbin/brconfig bridge0 396 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 397 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 398 399 # Tests brconfig deladdr 400 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1" 401 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 402 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3" 403 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 404 unset LD_PRELOAD 405 406 # Refill the MAC addresses of the endpoints. 407 export RUMP_SERVER=$SOCK1 408 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 409 unset RUMP_SERVER 410 export RUMP_SERVER=$SOCK2 411 export LD_PRELOAD=/usr/lib/librumphijack.so 412 /sbin/brconfig bridge0 413 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 414 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 415 416 # Tests brconfig flush. 417 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush 418 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 419 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 420 unset LD_PRELOAD 421 422 # Tests brconfig timeout. 423 export RUMP_SERVER=$SOCK2 424 export LD_PRELOAD=/usr/lib/librumphijack.so 425 atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0 426 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10 427 atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0 428 unset LD_PRELOAD 429 430 # Tests brconfig maxaddr. 431 test_brconfig_maxaddr 432 433 # TODO: brconfig static/flushall/discover/learn 434 # TODO: cache expiration; it takes 5 minutes at least and we want to 435 # wait here so long. Should we have a sysctl to change the period? 436} 437 438basic_cleanup() 439{ 440 dump_bus 441 cleanup 442} 443 444basic6_cleanup() 445{ 446 dump_bus 447 cleanup 448} 449 450rtable_cleanup() 451{ 452 dump_bus 453 cleanup 454} 455 456atf_init_test_cases() 457{ 458 atf_add_test_case basic 459 atf_add_test_case basic6 460 atf_add_test_case rtable 461} 462