Home | History | Annotate | Line # | Download | only in if_bridge
t_rtable.sh revision 1.1
      1 #	$NetBSD: t_rtable.sh,v 1.1 2017/03/11 04:24:52 ozaki-r Exp $
      2 #
      3 # Copyright (c) 2017 Internet Initiative Japan 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 
     28 SOCK1=unix://commsock1
     29 SOCK2=unix://commsock2
     30 SOCK3=unix://commsock3
     31 IP1=10.0.0.1
     32 IP2=10.0.0.2
     33 
     34 DEBUG=${DEBUG:-false}
     35 TIMEOUT=5
     36 
     37 setup_endpoint()
     38 {
     39 	local sock=${1}
     40 	local addr=${2}
     41 	local bus=${3}
     42 	local mode=${4}
     43 
     44 	rump_server_add_iface $sock shmif0 $bus
     45 	export RUMP_SERVER=${sock}
     46 	if [ $mode = "ipv6" ]; then
     47 		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
     48 	else
     49 		atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
     50 	fi
     51 
     52 	atf_check -s exit:0 rump.ifconfig shmif0 up
     53 	$DEBUG && rump.ifconfig shmif0
     54 }
     55 
     56 setup_bridge_server()
     57 {
     58 
     59 	rump_server_add_iface $SOCK2 shmif0 bus1
     60 	rump_server_add_iface $SOCK2 shmif1 bus2
     61 	export RUMP_SERVER=$SOCK2
     62 	atf_check -s exit:0 rump.ifconfig shmif0 up
     63 	atf_check -s exit:0 rump.ifconfig shmif1 up
     64 }
     65 
     66 setup()
     67 {
     68 
     69 	rump_server_start $SOCK1 bridge
     70 	rump_server_start $SOCK2 bridge
     71 	rump_server_start $SOCK3 bridge
     72 
     73 	setup_endpoint $SOCK1 $IP1 bus1 ipv4
     74 	setup_endpoint $SOCK3 $IP2 bus2 ipv4
     75 	setup_bridge_server
     76 }
     77 
     78 setup_bridge()
     79 {
     80 
     81 	export RUMP_SERVER=$SOCK2
     82 	atf_check -s exit:0 rump.ifconfig bridge0 create
     83 	atf_check -s exit:0 rump.ifconfig bridge0 up
     84 
     85 	export LD_PRELOAD=/usr/lib/librumphijack.so
     86 	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
     87 	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
     88 	/sbin/brconfig bridge0
     89 	unset LD_PRELOAD
     90 	rump.ifconfig shmif0
     91 	rump.ifconfig shmif1
     92 }
     93 
     94 get_number_of_caches()
     95 {
     96 
     97 	export RUMP_SERVER=$SOCK2
     98 	export LD_PRELOAD=/usr/lib/librumphijack.so
     99 	echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
    100 	unset LD_PRELOAD
    101 }
    102 
    103 
    104 atf_test_case bridge_rtable_basic cleanup
    105 bridge_rtable_basic_head()
    106 {
    107 
    108 	atf_set "descr" "Tests basic opearaions of bridge's learning table"
    109 	atf_set "require.progs" "rump_server"
    110 }
    111 
    112 bridge_rtable_basic_body()
    113 {
    114 	local addr1= addr3=
    115 
    116 	setup
    117 	setup_bridge
    118 
    119 	# Get MAC addresses of the endpoints.
    120 	addr1=$(get_macaddr $SOCK1 shmif0)
    121 	addr3=$(get_macaddr $SOCK3 shmif0)
    122 
    123 	# Confirm there is no MAC address caches.
    124 	export RUMP_SERVER=$SOCK2
    125 	export LD_PRELOAD=/usr/lib/librumphijack.so
    126 	$DEBUG && /sbin/brconfig bridge0
    127 	atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
    128 	atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
    129 	unset LD_PRELOAD
    130 
    131 	# Make the bridge learn the MAC addresses of the endpoints.
    132 	export RUMP_SERVER=$SOCK1
    133 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
    134 	unset RUMP_SERVER
    135 
    136 	# Tests the addresses are in the cache.
    137 	export RUMP_SERVER=$SOCK2
    138 	export LD_PRELOAD=/usr/lib/librumphijack.so
    139 	$DEBUG && /sbin/brconfig bridge0
    140 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    141 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    142 
    143 	# Tests brconfig deladdr
    144 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
    145 	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
    146 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
    147 	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
    148 	unset LD_PRELOAD
    149 
    150 	rump_server_destroy_ifaces
    151 }
    152 
    153 bridge_rtable_basic_cleanup()
    154 {
    155 
    156 	$DEBUG && dump
    157 	cleanup
    158 }
    159 
    160 
    161 atf_test_case bridge_rtable_flush cleanup
    162 bridge_rtable_flush_head()
    163 {
    164 
    165 	atf_set "descr" "Tests brconfig flush"
    166 	atf_set "require.progs" "rump_server"
    167 }
    168 
    169 bridge_rtable_flush_body()
    170 {
    171 	local addr1= addr3=
    172 
    173 	setup
    174 	setup_bridge
    175 
    176 	# Get MAC addresses of the endpoints.
    177 	addr1=$(get_macaddr $SOCK1 shmif0)
    178 	addr3=$(get_macaddr $SOCK3 shmif0)
    179 
    180 	# Make the bridge learn the MAC addresses of the endpoints.
    181 	export RUMP_SERVER=$SOCK1
    182 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
    183 	unset RUMP_SERVER
    184 
    185 	# Tests the addresses are in the cache.
    186 	export RUMP_SERVER=$SOCK2
    187 	export LD_PRELOAD=/usr/lib/librumphijack.so
    188 	$DEBUG && /sbin/brconfig bridge0
    189 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    190 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    191 
    192 	# Tests brconfig flush.
    193 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
    194 	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
    195 	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
    196 	unset LD_PRELOAD
    197 
    198 	rump_server_destroy_ifaces
    199 }
    200 
    201 bridge_rtable_flush_cleanup()
    202 {
    203 
    204 	$DEBUG && dump
    205 	cleanup
    206 }
    207 
    208 
    209 atf_test_case bridge_rtable_timeout cleanup
    210 bridge_rtable_timeout_head()
    211 {
    212 
    213 	atf_set "descr" "Tests cache timeout of bridge's learning table"
    214 	atf_set "require.progs" "rump_server"
    215 }
    216 
    217 bridge_rtable_timeout_body()
    218 {
    219 	local addr1= addr3=
    220 	local timeout=5
    221 
    222 	setup
    223 	setup_bridge
    224 
    225 	# Get MAC addresses of the endpoints.
    226 	addr1=$(get_macaddr $SOCK1 shmif0)
    227 	addr3=$(get_macaddr $SOCK3 shmif0)
    228 
    229 	# Tests brconfig timeout.
    230 	export RUMP_SERVER=$SOCK2
    231 	export LD_PRELOAD=/usr/lib/librumphijack.so
    232 	atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
    233 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout $timeout
    234 	atf_check -s exit:0 -o match:"timeout: $timeout" /sbin/brconfig bridge0
    235 	unset LD_PRELOAD
    236 
    237 	# Make the bridge learn the MAC addresses of the endpoints.
    238 	export RUMP_SERVER=$SOCK1
    239 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
    240 	unset RUMP_SERVER
    241 
    242 	# Tests the addresses are in the cache.
    243 	export RUMP_SERVER=$SOCK2
    244 	export LD_PRELOAD=/usr/lib/librumphijack.so
    245 	$DEBUG && /sbin/brconfig bridge0
    246 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    247 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    248 
    249 	# TODO: cache expiration
    250 	# The initial timeout value of a cache is changed to $timeout and
    251 	# after $timeout elapsed the cache is ready to be sweeped. However,
    252 	# the GC of rtable runs every 5 minutes and the cache remains until
    253 	# then. Should we have a sysctl to change the period?
    254 
    255 	#sleep $(($timeout + 2))
    256 	#
    257 	## Tests the addresses are not in the cache.
    258 	#export RUMP_SERVER=$SOCK2
    259 	#export LD_PRELOAD=/usr/lib/librumphijack.so
    260 	#$DEBUG && /sbin/brconfig bridge0
    261 	#atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
    262 	#atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
    263 
    264 	rump_server_destroy_ifaces
    265 }
    266 
    267 bridge_rtable_timeout_cleanup()
    268 {
    269 
    270 	$DEBUG && dump
    271 	cleanup
    272 }
    273 
    274 
    275 atf_test_case bridge_rtable_maxaddr cleanup
    276 bridge_rtable_maxaddr_head()
    277 {
    278 
    279 	atf_set "descr" "Tests brconfig maxaddr"
    280 	atf_set "require.progs" "rump_server"
    281 }
    282 
    283 bridge_rtable_maxaddr_body()
    284 {
    285 	local addr1= addr3=
    286 
    287 	setup
    288 	setup_bridge
    289 
    290 	# Get MAC addresses of the endpoints.
    291 	addr1=$(get_macaddr $SOCK1 shmif0)
    292 	addr3=$(get_macaddr $SOCK3 shmif0)
    293 
    294 	# Fill the MAC addresses of the endpoints.
    295 	export RUMP_SERVER=$SOCK1
    296 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
    297 	export RUMP_SERVER=$SOCK2
    298 	export LD_PRELOAD=/usr/lib/librumphijack.so
    299 	/sbin/brconfig bridge0
    300 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    301 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    302 
    303 	# Check the default # of caches is 100
    304 	atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
    305 
    306 	# Test two MAC addresses are cached
    307 	n=$(get_number_of_caches)
    308 	atf_check_equal $n 2
    309 
    310 	# Limit # of caches to one
    311 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
    312 	atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
    313 	/sbin/brconfig bridge0
    314 
    315 	# Test just one address is cached
    316 	n=$(get_number_of_caches)
    317 	atf_check_equal $n 1
    318 
    319 	# Increase # of caches to two
    320 	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
    321 	atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
    322 	unset LD_PRELOAD
    323 
    324 	# Test we can cache two addresses again
    325 	export RUMP_SERVER=$SOCK1
    326 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
    327 	export RUMP_SERVER=$SOCK2
    328 	export LD_PRELOAD=/usr/lib/librumphijack.so
    329 	/sbin/brconfig bridge0
    330 	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
    331 	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
    332 	unset LD_PRELOAD
    333 
    334 	rump_server_destroy_ifaces
    335 }
    336 
    337 bridge_rtable_maxaddr_cleanup()
    338 {
    339 
    340 	$DEBUG && dump
    341 	cleanup
    342 }
    343 
    344 
    345 atf_init_test_cases()
    346 {
    347 
    348 	atf_add_test_case bridge_rtable_basic
    349 	atf_add_test_case bridge_rtable_flush
    350 	atf_add_test_case bridge_rtable_timeout
    351 	atf_add_test_case bridge_rtable_maxaddr
    352 	# TODO: brconfig static/flushall/discover/learn
    353 }
    354