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