t_bridge.sh revision 1.9
1# $NetBSD: t_bridge.sh,v 1.9 2015/06/10 03:29:37 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 38IPBR1=10.0.0.11 39IPBR2=10.0.0.12 40IP6BR1=fc00::11 41IP6BR2=fc00::12 42 43TIMEOUT=5 44 45atf_test_case basic cleanup 46atf_test_case basic6 cleanup 47atf_test_case rtable cleanup 48atf_test_case member_ip cleanup 49atf_test_case member_ip6 cleanup 50 51basic_head() 52{ 53 atf_set "descr" "Does simple if_bridge tests" 54 atf_set "require.progs" "rump_server" 55} 56 57basic6_head() 58{ 59 atf_set "descr" "Does simple if_bridge tests (IPv6)" 60 atf_set "require.progs" "rump_server" 61} 62 63rtable_head() 64{ 65 atf_set "descr" "Tests route table operations of if_bridge" 66 atf_set "require.progs" "rump_server" 67} 68 69member_ip_head() 70{ 71 atf_set "descr" "Tests if_bridge with members with an IP address" 72 atf_set "require.progs" "rump_server" 73} 74 75member_ip6_head() 76{ 77 atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)" 78 atf_set "require.progs" "rump_server" 79} 80 81setup_endpoint() 82{ 83 sock=${1} 84 addr=${2} 85 bus=${3} 86 mode=${4} 87 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 95 fi 96 97 atf_check -s exit:0 rump.ifconfig shmif0 up 98 rump.ifconfig shmif0 99} 100 101test_endpoint() 102{ 103 sock=${1} 104 addr=${2} 105 bus=${3} 106 mode=${4} 107 108 export RUMP_SERVER=${sock} 109 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 110 if [ $mode = "ipv6" ]; then 111 export LD_PRELOAD=/usr/lib/librumphijack.so 112 atf_check -s exit:0 -o ignore ping6 -n -c 1 -X $TIMEOUT ${addr} 113 unset LD_PRELOAD 114 else 115 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr} 116 fi 117} 118 119show_endpoint() 120{ 121 sock=${1} 122 123 export RUMP_SERVER=${sock} 124 rump.ifconfig -v shmif0 125} 126 127test_setup() 128{ 129 test_endpoint $SOCK1 $IP1 bus1 ipv4 130 test_endpoint $SOCK3 $IP2 bus2 ipv4 131 132 export RUMP_SERVER=$SOCK2 133 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 134 atf_check -s exit:0 -o match:shmif1 rump.ifconfig 135} 136 137test_setup6() 138{ 139 test_endpoint $SOCK1 $IP61 bus1 ipv6 140 test_endpoint $SOCK3 $IP62 bus2 ipv6 141 142 export RUMP_SERVER=$SOCK2 143 atf_check -s exit:0 -o match:shmif0 rump.ifconfig 144 atf_check -s exit:0 -o match:shmif1 rump.ifconfig 145} 146 147setup_bridge_server() 148{ 149 export RUMP_SERVER=$SOCK2 150 atf_check -s exit:0 rump.ifconfig shmif0 create 151 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1 152 atf_check -s exit:0 rump.ifconfig shmif0 up 153 154 atf_check -s exit:0 rump.ifconfig shmif1 create 155 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2 156 atf_check -s exit:0 rump.ifconfig shmif1 up 157} 158 159setup() 160{ 161 atf_check -s exit:0 ${inetserver} $SOCK1 162 atf_check -s exit:0 ${inetserver} $SOCK2 163 atf_check -s exit:0 ${inetserver} $SOCK3 164 165 setup_endpoint $SOCK1 $IP1 bus1 ipv4 166 setup_endpoint $SOCK3 $IP2 bus2 ipv4 167 setup_bridge_server 168} 169 170setup6() 171{ 172 atf_check -s exit:0 ${inet6server} $SOCK1 173 atf_check -s exit:0 ${inet6server} $SOCK2 174 atf_check -s exit:0 ${inet6server} $SOCK3 175 176 setup_endpoint $SOCK1 $IP61 bus1 ipv6 177 setup_endpoint $SOCK3 $IP62 bus2 ipv6 178 setup_bridge_server 179} 180 181setup_bridge() 182{ 183 export RUMP_SERVER=$SOCK2 184 atf_check -s exit:0 rump.ifconfig bridge0 create 185 atf_check -s exit:0 rump.ifconfig bridge0 up 186 187 export LD_PRELOAD=/usr/lib/librumphijack.so 188 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0 189 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1 190 /sbin/brconfig bridge0 191 unset LD_PRELOAD 192 rump.ifconfig shmif0 193 rump.ifconfig shmif1 194} 195 196setup_member_ip() 197{ 198 export RUMP_SERVER=$SOCK2 199 export LD_PRELOAD=/usr/lib/librumphijack.so 200 atf_check -s exit:0 rump.ifconfig shmif0 $IPBR1/24 201 atf_check -s exit:0 rump.ifconfig shmif1 $IPBR2/24 202 atf_check -s exit:0 rump.ifconfig -w 10 203 /sbin/brconfig bridge0 204 unset LD_PRELOAD 205 rump.ifconfig shmif0 206 rump.ifconfig shmif1 207} 208 209setup_member_ip6() 210{ 211 export RUMP_SERVER=$SOCK2 212 export LD_PRELOAD=/usr/lib/librumphijack.so 213 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6BR1 214 atf_check -s exit:0 rump.ifconfig shmif1 inet6 $IP6BR2 215 atf_check -s exit:0 rump.ifconfig -w 10 216 /sbin/brconfig bridge0 217 unset LD_PRELOAD 218 rump.ifconfig shmif0 219 rump.ifconfig shmif1 220} 221 222teardown_bridge() 223{ 224 export RUMP_SERVER=$SOCK2 225 export LD_PRELOAD=/usr/lib/librumphijack.so 226 /sbin/brconfig bridge0 227 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0 228 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1 229 /sbin/brconfig bridge0 230 unset LD_PRELOAD 231 rump.ifconfig shmif0 232 rump.ifconfig shmif1 233} 234 235test_setup_bridge() 236{ 237 export RUMP_SERVER=$SOCK2 238 export LD_PRELOAD=/usr/lib/librumphijack.so 239 atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0 240 atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0 241 /sbin/brconfig bridge0 242 unset LD_PRELOAD 243} 244 245cleanup() 246{ 247 env RUMP_SERVER=$SOCK1 rump.halt 248 env RUMP_SERVER=$SOCK2 rump.halt 249 env RUMP_SERVER=$SOCK3 rump.halt 250} 251 252dump_bus() 253{ 254 /usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r - 255 /usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r - 256} 257 258down_up_interfaces() 259{ 260 export RUMP_SERVER=$SOCK1 261 rump.ifconfig shmif0 down 262 rump.ifconfig shmif0 up 263 export RUMP_SERVER=$SOCK3 264 rump.ifconfig shmif0 down 265 rump.ifconfig shmif0 up 266} 267 268test_ping_failure() 269{ 270 export RUMP_SERVER=$SOCK1 271 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2 272 export RUMP_SERVER=$SOCK3 273 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1 274} 275 276test_ping_success() 277{ 278 export RUMP_SERVER=$SOCK1 279 rump.ifconfig -v shmif0 280 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2 281 rump.ifconfig -v shmif0 282 283 export RUMP_SERVER=$SOCK3 284 rump.ifconfig -v shmif0 285 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1 286 rump.ifconfig -v shmif0 287} 288 289test_ping6_failure() 290{ 291 export LD_PRELOAD=/usr/lib/librumphijack.so 292 export RUMP_SERVER=$SOCK1 293 atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62 294 export RUMP_SERVER=$SOCK3 295 atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61 296 unset LD_PRELOAD 297} 298 299test_ping6_success() 300{ 301 export RUMP_SERVER=$SOCK1 302 rump.ifconfig -v shmif0 303 export LD_PRELOAD=/usr/lib/librumphijack.so 304 atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62 305 unset LD_PRELOAD 306 rump.ifconfig -v shmif0 307 308 export RUMP_SERVER=$SOCK3 309 rump.ifconfig -v shmif0 310 export LD_PRELOAD=/usr/lib/librumphijack.so 311 atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61 312 unset LD_PRELOAD 313 rump.ifconfig -v shmif0 314} 315 316test_ping_member() 317{ 318 export RUMP_SERVER=$SOCK1 319 rump.ifconfig -v shmif0 320 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1 321 rump.ifconfig -v shmif0 322 # It's known to fail. See PR#48104 323 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2 324 rump.ifconfig -v shmif0 325 326 export RUMP_SERVER=$SOCK3 327 rump.ifconfig -v shmif0 328 # It's known to fail. See PR#48104 329 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1 330 rump.ifconfig -v shmif0 331 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2 332 rump.ifconfig -v shmif0 333} 334 335test_ping6_member() 336{ 337 export LD_PRELOAD=/usr/lib/librumphijack.so 338 339 export RUMP_SERVER=$SOCK1 340 rump.ifconfig -v shmif0 341 atf_check -s exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1 342 rump.ifconfig -v shmif0 343 # It's known to fail. See PR#48104 344 atf_check -s not-exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2 345 rump.ifconfig -v shmif0 346 347 export RUMP_SERVER=$SOCK3 348 rump.ifconfig -v shmif0 349 # It's known to fail. See PR#48104 350 atf_check -s not-exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1 351 rump.ifconfig -v shmif0 352 # FIXME: it doesn't work for some reason 353 atf_check -s exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2 354 rump.ifconfig -v shmif0 355 356 unset LD_PRELOAD 357} 358 359get_number_of_caches() 360{ 361 export RUMP_SERVER=$SOCK2 362 export LD_PRELOAD=/usr/lib/librumphijack.so 363 echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1)) 364 unset LD_PRELOAD 365} 366 367test_brconfig_maxaddr() 368{ 369 addr1= addr3= n= 370 371 # Get MAC addresses of the endpoints. 372 export RUMP_SERVER=$SOCK1 373 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 374 export RUMP_SERVER=$SOCK3 375 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 376 unset RUMP_SERVER 377 378 # Refill the MAC addresses of the endpoints. 379 export RUMP_SERVER=$SOCK1 380 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 381 export RUMP_SERVER=$SOCK2 382 export LD_PRELOAD=/usr/lib/librumphijack.so 383 /sbin/brconfig bridge0 384 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 385 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 386 387 # Check the default # of caches is 100 388 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0 389 390 # Test two MAC addresses are cached 391 n=$(get_number_of_caches) 392 atf_check_equal $n 2 393 394 # Limit # of caches to one 395 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1 396 atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0 397 /sbin/brconfig bridge0 398 399 # Test just one address is cached 400 n=$(get_number_of_caches) 401 atf_check_equal $n 1 402 403 # Increase # of caches to two 404 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2 405 atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0 406 unset LD_PRELOAD 407 408 # Test we can cache two addresses again 409 export RUMP_SERVER=$SOCK1 410 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 411 export RUMP_SERVER=$SOCK2 412 export LD_PRELOAD=/usr/lib/librumphijack.so 413 /sbin/brconfig bridge0 414 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 415 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 416 unset LD_PRELOAD 417} 418 419basic_body() 420{ 421 setup 422 test_setup 423 424 # Enable once PR kern/49219 is fixed 425 #test_ping_failure 426 427 setup_bridge 428 sleep 1 429 test_setup_bridge 430 test_ping_success 431 432 teardown_bridge 433 test_ping_failure 434} 435 436basic6_body() 437{ 438 setup6 439 test_setup6 440 441 test_ping6_failure 442 443 setup_bridge 444 sleep 1 445 test_setup_bridge 446 test_ping6_success 447 448 teardown_bridge 449 test_ping6_failure 450} 451 452rtable_body() 453{ 454 addr1= addr3= 455 456 setup 457 setup_bridge 458 459 # Get MAC addresses of the endpoints. 460 export RUMP_SERVER=$SOCK1 461 addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 462 export RUMP_SERVER=$SOCK3 463 addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}') 464 unset RUMP_SERVER 465 466 # Confirm there is no MAC address caches. 467 export RUMP_SERVER=$SOCK2 468 export LD_PRELOAD=/usr/lib/librumphijack.so 469 /sbin/brconfig bridge0 470 atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0 471 atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0 472 unset LD_PRELOAD 473 474 # Make the bridge learn the MAC addresses of the endpoints. 475 export RUMP_SERVER=$SOCK1 476 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 477 unset RUMP_SERVER 478 479 # Tests the addresses are in the cache. 480 export RUMP_SERVER=$SOCK2 481 export LD_PRELOAD=/usr/lib/librumphijack.so 482 /sbin/brconfig bridge0 483 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 484 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 485 486 # Tests brconfig deladdr 487 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1" 488 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 489 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3" 490 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 491 unset LD_PRELOAD 492 493 # Refill the MAC addresses of the endpoints. 494 export RUMP_SERVER=$SOCK1 495 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 496 unset RUMP_SERVER 497 export RUMP_SERVER=$SOCK2 498 export LD_PRELOAD=/usr/lib/librumphijack.so 499 /sbin/brconfig bridge0 500 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 501 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 502 503 # Tests brconfig flush. 504 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush 505 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 506 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 507 unset LD_PRELOAD 508 509 # Tests brconfig timeout. 510 export RUMP_SERVER=$SOCK2 511 export LD_PRELOAD=/usr/lib/librumphijack.so 512 atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0 513 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10 514 atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0 515 unset LD_PRELOAD 516 517 # Tests brconfig maxaddr. 518 test_brconfig_maxaddr 519 520 # TODO: brconfig static/flushall/discover/learn 521 # TODO: cache expiration; it takes 5 minutes at least and we want to 522 # wait here so long. Should we have a sysctl to change the period? 523} 524 525member_ip_body() 526{ 527 setup 528 test_setup 529 530 # Enable once PR kern/49219 is fixed 531 #test_ping_failure 532 533 setup_bridge 534 sleep 1 535 test_setup_bridge 536 test_ping_success 537 538 setup_member_ip 539 test_ping_member 540 541 teardown_bridge 542 test_ping_failure 543} 544 545member_ip6_body() 546{ 547 setup6 548 test_setup6 549 550 test_ping6_failure 551 552 setup_bridge 553 sleep 1 554 test_setup_bridge 555 test_ping6_success 556 557 setup_member_ip6 558 test_ping6_member 559 560 teardown_bridge 561 test_ping6_failure 562} 563 564basic_cleanup() 565{ 566 dump_bus 567 cleanup 568} 569 570basic6_cleanup() 571{ 572 dump_bus 573 cleanup 574} 575 576rtable_cleanup() 577{ 578 dump_bus 579 cleanup 580} 581 582member_ip_cleanup() 583{ 584 dump_bus 585 cleanup 586} 587 588member_ip6_cleanup() 589{ 590 dump_bus 591 cleanup 592} 593 594atf_init_test_cases() 595{ 596 atf_add_test_case basic 597 atf_add_test_case basic6 598 atf_add_test_case rtable 599 atf_add_test_case member_ip 600 atf_add_test_case member_ip6 601} 602