t_bridge.sh revision 1.14
1# $NetBSD: t_bridge.sh,v 1.14 2016/11/24 09:07:09 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 28libs1="-lrumpnet -lrumpnet_net -lrumpnet_netinet" 29libs2="-lrumpnet_bridge -lrumpnet_shmif -lrumpdev" 30libs6="-lrumpnet_netinet6" 31 32inetserver="rump_server ${libs1} ${libs2}" 33inet6server="rump_server ${libs1} ${libs6} ${libs2}" 34 35SOCK1=unix://commsock1 36SOCK2=unix://commsock2 37SOCK3=unix://commsock3 38IP1=10.0.0.1 39IP2=10.0.0.2 40IP61=fc00::1 41IP62=fc00::2 42IPBR1=10.0.0.11 43IPBR2=10.0.0.12 44IP6BR1=fc00::11 45IP6BR2=fc00::12 46 47TIMEOUT=5 48 49atf_test_case bridge_ipv4 cleanup 50atf_test_case bridge_ipv6 cleanup 51atf_test_case bridge_rtable cleanup 52atf_test_case bridge_member_ipv4 cleanup 53atf_test_case bridge_member_ipv6 cleanup 54 55bridge_ipv4_head() 56{ 57 atf_set "descr" "Does simple if_bridge tests" 58 atf_set "require.progs" "rump_server" 59} 60 61bridge_ipv6_head() 62{ 63 atf_set "descr" "Does simple if_bridge tests (IPv6)" 64 atf_set "require.progs" "rump_server" 65} 66 67bridge_rtable_head() 68{ 69 atf_set "descr" "Tests route table operations of if_bridge" 70 atf_set "require.progs" "rump_server" 71} 72 73bridge_member_ipv4_head() 74{ 75 atf_set "descr" "Tests if_bridge with members with an IP address" 76 atf_set "require.progs" "rump_server" 77} 78 79bridge_member_ipv6_head() 80{ 81 atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)" 82 atf_set "require.progs" "rump_server" 83} 84 85setup_endpoint() 86{ 87 sock=${1} 88 addr=${2} 89 bus=${3} 90 mode=${4} 91 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} 97 else 98 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00 99 fi 100 101 atf_check -s exit:0 rump.ifconfig shmif0 up 102 rump.ifconfig shmif0 103} 104 105test_endpoint() 106{ 107 sock=${1} 108 addr=${2} 109 bus=${3} 110 mode=${4} 111 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} 116 else 117 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr} 118 fi 119} 120 121show_endpoint() 122{ 123 sock=${1} 124 125 export RUMP_SERVER=${sock} 126 rump.ifconfig -v shmif0 127} 128 129test_setup() 130{ 131 test_endpoint $SOCK1 $IP1 bus1 ipv4 132 test_endpoint $SOCK3 $IP2 bus2 ipv4 133 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 137} 138 139test_setup6() 140{ 141 test_endpoint $SOCK1 $IP61 bus1 ipv6 142 test_endpoint $SOCK3 $IP62 bus2 ipv6 143 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 147} 148 149setup_bridge_server() 150{ 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 155 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 159} 160 161setup() 162{ 163 atf_check -s exit:0 ${inetserver} $SOCK1 164 atf_check -s exit:0 ${inetserver} $SOCK2 165 atf_check -s exit:0 ${inetserver} $SOCK3 166 167 setup_endpoint $SOCK1 $IP1 bus1 ipv4 168 setup_endpoint $SOCK3 $IP2 bus2 ipv4 169 setup_bridge_server 170} 171 172setup6() 173{ 174 atf_check -s exit:0 ${inet6server} $SOCK1 175 atf_check -s exit:0 ${inet6server} $SOCK2 176 atf_check -s exit:0 ${inet6server} $SOCK3 177 178 setup_endpoint $SOCK1 $IP61 bus1 ipv6 179 setup_endpoint $SOCK3 $IP62 bus2 ipv6 180 setup_bridge_server 181} 182 183setup_bridge() 184{ 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 188 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 193 unset LD_PRELOAD 194 rump.ifconfig shmif0 195 rump.ifconfig shmif1 196} 197 198setup_member_ip() 199{ 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 206 unset LD_PRELOAD 207 rump.ifconfig shmif0 208 rump.ifconfig shmif1 209} 210 211setup_member_ip6() 212{ 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 219 unset LD_PRELOAD 220 rump.ifconfig shmif0 221 rump.ifconfig shmif1 222} 223 224teardown_bridge() 225{ 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 232 unset LD_PRELOAD 233 rump.ifconfig shmif0 234 rump.ifconfig shmif1 235} 236 237test_setup_bridge() 238{ 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 244 unset LD_PRELOAD 245} 246 247cleanup() 248{ 249 env RUMP_SERVER=$SOCK1 rump.halt 250 env RUMP_SERVER=$SOCK2 rump.halt 251 env RUMP_SERVER=$SOCK3 rump.halt 252} 253 254dump_bus() 255{ 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 - 258} 259 260down_up_interfaces() 261{ 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 268} 269 270test_ping_failure() 271{ 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 276} 277 278test_ping_success() 279{ 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 284 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 289} 290 291test_ping6_failure() 292{ 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 297} 298 299test_ping6_success() 300{ 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 305 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 310} 311 312test_ping_member() 313{ 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 318 # Test for PR#48104 319 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2 320 rump.ifconfig -v shmif0 321 322 export RUMP_SERVER=$SOCK3 323 rump.ifconfig -v shmif0 324 # Test for PR#48104 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 329} 330 331test_ping6_member() 332{ 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 337 # Test for PR#48104 338 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2 339 rump.ifconfig -v shmif0 340 341 export RUMP_SERVER=$SOCK3 342 rump.ifconfig -v shmif0 343 # Test for PR#48104 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 348} 349 350get_number_of_caches() 351{ 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)) 355 unset LD_PRELOAD 356} 357 358test_brconfig_maxaddr() 359{ 360 addr1= addr3= n= 361 362 # Get MAC addresses of the endpoints. 363 addr1=$(get_macaddr $SOCK1 shmif0) 364 addr3=$(get_macaddr $SOCK3 shmif0) 365 366 # Refill the MAC addresses of the endpoints. 367 export RUMP_SERVER=$SOCK1 368 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 369 export RUMP_SERVER=$SOCK2 370 export LD_PRELOAD=/usr/lib/librumphijack.so 371 /sbin/brconfig bridge0 372 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 373 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 374 375 # Check the default # of caches is 100 376 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0 377 378 # Test two MAC addresses are cached 379 n=$(get_number_of_caches) 380 atf_check_equal $n 2 381 382 # Limit # of caches to one 383 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1 384 atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0 385 /sbin/brconfig bridge0 386 387 # Test just one address is cached 388 n=$(get_number_of_caches) 389 atf_check_equal $n 1 390 391 # Increase # of caches to two 392 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2 393 atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0 394 unset LD_PRELOAD 395 396 # Test we can cache two addresses again 397 export RUMP_SERVER=$SOCK1 398 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 399 export RUMP_SERVER=$SOCK2 400 export LD_PRELOAD=/usr/lib/librumphijack.so 401 /sbin/brconfig bridge0 402 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 403 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 404 unset LD_PRELOAD 405} 406 407bridge_ipv4_body() 408{ 409 setup 410 test_setup 411 412 # Enable once PR kern/49219 is fixed 413 #test_ping_failure 414 415 setup_bridge 416 sleep 1 417 test_setup_bridge 418 test_ping_success 419 420 teardown_bridge 421 test_ping_failure 422} 423 424bridge_ipv6_body() 425{ 426 setup6 427 test_setup6 428 429 test_ping6_failure 430 431 setup_bridge 432 sleep 1 433 test_setup_bridge 434 test_ping6_success 435 436 teardown_bridge 437 test_ping6_failure 438} 439 440bridge_rtable_body() 441{ 442 addr1= addr3= 443 444 setup 445 setup_bridge 446 447 # Get MAC addresses of the endpoints. 448 addr1=$(get_macaddr $SOCK1 shmif0) 449 addr3=$(get_macaddr $SOCK3 shmif0) 450 451 # Confirm there is no MAC address caches. 452 export RUMP_SERVER=$SOCK2 453 export LD_PRELOAD=/usr/lib/librumphijack.so 454 /sbin/brconfig bridge0 455 atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0 456 atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0 457 unset LD_PRELOAD 458 459 # Make the bridge learn the MAC addresses of the endpoints. 460 export RUMP_SERVER=$SOCK1 461 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 462 unset RUMP_SERVER 463 464 # Tests the addresses are in the cache. 465 export RUMP_SERVER=$SOCK2 466 export LD_PRELOAD=/usr/lib/librumphijack.so 467 /sbin/brconfig bridge0 468 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 469 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 470 471 # Tests brconfig deladdr 472 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1" 473 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 474 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3" 475 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 476 unset LD_PRELOAD 477 478 # Refill the MAC addresses of the endpoints. 479 export RUMP_SERVER=$SOCK1 480 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2 481 unset RUMP_SERVER 482 export RUMP_SERVER=$SOCK2 483 export LD_PRELOAD=/usr/lib/librumphijack.so 484 /sbin/brconfig bridge0 485 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0 486 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0 487 488 # Tests brconfig flush. 489 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush 490 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0 491 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0 492 unset LD_PRELOAD 493 494 # Tests brconfig timeout. 495 export RUMP_SERVER=$SOCK2 496 export LD_PRELOAD=/usr/lib/librumphijack.so 497 atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0 498 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10 499 atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0 500 unset LD_PRELOAD 501 502 # Tests brconfig maxaddr. 503 test_brconfig_maxaddr 504 505 # TODO: brconfig static/flushall/discover/learn 506 # TODO: cache expiration; it takes 5 minutes at least and we want to 507 # wait here so long. Should we have a sysctl to change the period? 508} 509 510bridge_member_ipv4_body() 511{ 512 setup 513 test_setup 514 515 # Enable once PR kern/49219 is fixed 516 #test_ping_failure 517 518 setup_bridge 519 sleep 1 520 test_setup_bridge 521 test_ping_success 522 523 setup_member_ip 524 test_ping_member 525 526 teardown_bridge 527 test_ping_failure 528} 529 530bridge_member_ipv6_body() 531{ 532 setup6 533 test_setup6 534 535 test_ping6_failure 536 537 setup_bridge 538 sleep 1 539 test_setup_bridge 540 test_ping6_success 541 542 setup_member_ip6 543 test_ping6_member 544 545 teardown_bridge 546 test_ping6_failure 547} 548 549bridge_ipv4_cleanup() 550{ 551 dump_bus 552 cleanup 553} 554 555bridge_ipv6_cleanup() 556{ 557 dump_bus 558 cleanup 559} 560 561bridge_rtable_cleanup() 562{ 563 dump_bus 564 cleanup 565} 566 567bridge_member_ipv4_cleanup() 568{ 569 dump_bus 570 cleanup 571} 572 573bridge_member_ipv6_cleanup() 574{ 575 dump_bus 576 cleanup 577} 578 579atf_init_test_cases() 580{ 581 atf_add_test_case bridge_ipv4 582 atf_add_test_case bridge_ipv6 583 atf_add_test_case bridge_rtable 584 atf_add_test_case bridge_member_ipv4 585 atf_add_test_case bridge_member_ipv6 586} 587