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