Home | History | Annotate | Line # | Download | only in if_vlan
t_vlan.sh revision 1.2
      1 #	$NetBSD: t_vlan.sh,v 1.2 2017/06/14 02:32:29 ozaki-r Exp $
      2 #
      3 # Copyright (c) 2016 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 BUS=bus
     29 SOCK_LOCAL=unix://commsock1
     30 SOCK_REMOTE=unix://commsock2
     31 IP_LOCAL0=10.0.0.1
     32 IP_LOCAL1=10.0.1.1
     33 IP_REMOTE0=10.0.0.2
     34 IP_REMOTE1=10.0.1.2
     35 IP6_LOCAL0=fc00:0::1
     36 IP6_LOCAL1=fc00:1::1
     37 IP6_REMOTE0=fc00:0::2
     38 IP6_REMOTE1=fc00:1::2
     39 
     40 DEBUG=${DEBUG:-false}
     41 
     42 vlan_create_destroy_body_common()
     43 {
     44 	export RUMP_SERVER=${SOCK_LOCAL}
     45 
     46 	atf_check -s exit:0 rump.ifconfig vlan0 create
     47 	atf_check -s exit:0 rump.ifconfig vlan0 up
     48 	atf_check -s exit:0 rump.ifconfig vlan0 down
     49 	atf_check -s exit:0 rump.ifconfig vlan0 destroy
     50 
     51 	atf_check -s exit:0 rump.ifconfig shmif0 create
     52 	atf_check -s exit:0 rump.ifconfig vlan0 create
     53 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
     54 	atf_check -s exit:0 rump.ifconfig vlan0 up
     55 	atf_check -s exit:0 rump.ifconfig vlan0 destroy
     56 
     57 	# more than one vlan interface with a same parent interface
     58 	atf_check -s exit:0 rump.ifconfig shmif1 create
     59 	atf_check -s exit:0 rump.ifconfig vlan0 create
     60 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
     61 	atf_check -s exit:0 rump.ifconfig vlan1 create
     62 	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
     63 
     64 	# more than one interface with another parent interface
     65 	atf_check -s exit:0 rump.ifconfig vlan2 create
     66 	atf_check -s exit:0 rump.ifconfig vlan2 vlan 12 vlanif shmif1
     67 	atf_check -s exit:0 rump.ifconfig vlan3 create
     68 	atf_check -s exit:0 rump.ifconfig vlan3 vlan 13 vlanif shmif1
     69 	atf_check -s exit:0 rump.ifconfig shmif0 destroy
     70 	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan0
     71 	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan1
     72 	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan2
     73 	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan3
     74 	atf_check -s exit:0 rump.ifconfig vlan0 destroy
     75 	atf_check -s exit:0 rump.ifconfig vlan1 destroy
     76 	atf_check -s exit:0 rump.ifconfig vlan2 destroy
     77 	atf_check -s exit:0 rump.ifconfig vlan3 destroy
     78 
     79 }
     80 
     81 atf_test_case vlan_create_destroy cleanup
     82 vlan_create_destroy_head()
     83 {
     84 
     85 	atf_set "descr" "tests of creation and deletion of vlan interface"
     86 	atf_set "require.progs" "rump_server"
     87 }
     88 
     89 vlan_create_destroy_body()
     90 {
     91 	rump_server_start $SOCK_LOCAL vlan
     92 
     93 	vlan_create_destroy_body_common
     94 }
     95 
     96 
     97 vlan_create_destroy_cleanup()
     98 {
     99 
    100 	$DEBUG && dump
    101 	cleanup
    102 }
    103 
    104 atf_test_case vlan_create_destroy6 cleanup
    105 vlan_create_destroy6_head()
    106 {
    107 
    108 	atf_set "descr" "tests of creation and deletion of vlan interface with IPv6"
    109 	atf_set "require.progs" "rump_server"
    110 }
    111 
    112 vlan_create_destroy6_body()
    113 {
    114 
    115 	rump_server_start $SOCK_LOCAL vlan netinet6
    116 
    117 	vlan_create_destroy_body_common
    118 }
    119 
    120 vlan_create_destroy6_cleanup()
    121 {
    122 
    123 	$DEBUG && dump
    124 	cleanup
    125 }
    126 
    127 vlan_basic_body_common()
    128 {
    129 	local outfile=./out
    130 	local af=inet
    131 	local prefix=24
    132 	local local0=$IP_LOCAL0
    133 	local remote0=$IP_REMOTE0
    134 	local ping_cmd="rump.ping -n -w 1 -c 1"
    135 
    136 	if [ x"$1" = x"inet6" ]; then
    137 		af="inet6"
    138 		prefix=64
    139 		local0=$IP6_LOCAL0
    140 		remote0=$IP6_REMOTE0
    141 		ping_cmd="rump.ping6 -n -c 1"
    142 	fi
    143 
    144 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    145 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    146 
    147 	export RUMP_SERVER=$SOCK_LOCAL
    148 	atf_check -s exit:0 rump.ifconfig shmif0 up
    149 	export RUMP_SERVER=$SOCK_REMOTE
    150 	atf_check -s exit:0 rump.ifconfig shmif0 up
    151 
    152 	export RUMP_SERVER=$SOCK_LOCAL
    153 	atf_check -s exit:0 rump.ifconfig vlan0 create
    154 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    155 	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
    156 	atf_check -s exit:0 rump.ifconfig vlan0 up
    157 	atf_check -s exit:0 rump.ifconfig -w 10
    158 
    159 	export RUMP_SERVER=$SOCK_REMOTE
    160 	atf_check -s exit:0 rump.ifconfig vlan0 create
    161 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    162 	atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
    163 	atf_check -s exit:0 rump.ifconfig vlan0 up
    164 	atf_check -s exit:0 rump.ifconfig -w 10
    165 
    166 	extract_new_packets $BUS > $outfile
    167 
    168 	export RUMP_SERVER=$SOCK_LOCAL
    169 	atf_check -s exit:0 -o ignore $ping_cmd $remote0
    170 
    171 	extract_new_packets $BUS > $outfile
    172 	atf_check -s exit:0 -o match:'vlan 10' cat $outfile
    173 
    174 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    175 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 20 vlanif shmif0
    176 	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
    177 	atf_check -s exit:0 rump.ifconfig vlan0 up
    178 	atf_check -s exit:0 rump.ifconfig -w 10
    179 
    180 	extract_new_packets $BUS > $outfile
    181 	atf_check -s not-exit:0 -o ignore $ping_cmd $remote0
    182 
    183 	extract_new_packets $BUS > $outfile
    184 	atf_check -s exit:0 -o match:'vlan 20' cat $outfile
    185 }
    186 
    187 atf_test_case vlan_basic cleanup
    188 vlan_basic_head()
    189 {
    190 
    191 	atf_set "descr" "tests of communications over vlan interfaces"
    192 	atf_set "require.progs" "rump_server"
    193 }
    194 
    195 vlan_basic_body()
    196 {
    197 	rump_server_start $SOCK_LOCAL vlan
    198 	rump_server_start $SOCK_REMOTE vlan
    199 
    200 	vlan_basic_body_common inet
    201 
    202 }
    203 
    204 vlan_basic_cleanup()
    205 {
    206 
    207 	$DEBUG && dump
    208 	cleanup
    209 }
    210 
    211 atf_test_case vlan_basic6 cleanup
    212 vlan_basic6_head()
    213 {
    214 
    215 	atf_set "descr" "tests of communications over vlan interfaces using IPv6"
    216 	atf_set "require.progs" "rump_server"
    217 }
    218 
    219 vlan_basic6_body()
    220 {
    221 	rump_server_start $SOCK_LOCAL vlan netinet6
    222 	rump_server_start $SOCK_REMOTE vlan netinet6
    223 
    224 	vlan_basic_body_common inet6
    225 }
    226 
    227 vlan_basic6_cleanup()
    228 {
    229 
    230 	$DEBUG && dump
    231 	cleanup
    232 }
    233 
    234 vlanid_config_and_ping()
    235 {
    236 	local vlanid=$1
    237 	shift
    238 
    239 	export RUMP_SERVER=$SOCK_LOCAL
    240 	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
    241 	atf_check -s exit:0 rump.ifconfig vlan0 $IP_LOCAL0/24
    242 	atf_check -s exit:0 rump.ifconfig vlan0 up
    243 
    244 	export RUMP_SERVER=$SOCK_REMOTE
    245 	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
    246 	atf_check -s exit:0 rump.ifconfig vlan0 $IP_REMOTE0/24
    247 	atf_check -s exit:0 rump.ifconfig vlan0 up
    248 
    249 	export RUMP_SERVER=$SOCK_LOCAL
    250 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE0
    251 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    252 
    253 	export RUMP_SERVER=$SOCK_REMOTE
    254 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    255 }
    256 
    257 vlanid_config_and_ping6()
    258 {
    259 	local vlanid=$1
    260 	shift
    261 
    262 	export RUMP_SERVER=$SOCK_LOCAL
    263 	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
    264 	atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_LOCAL0/64
    265 	atf_check -s exit:0 rump.ifconfig vlan0 up
    266 
    267 	export RUMP_SERVER=$SOCK_REMOTE
    268 	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
    269 	atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_REMOTE0/64
    270 	atf_check -s exit:0 rump.ifconfig vlan0 up
    271 
    272 	export RUMP_SERVER=$SOCK_LOCAL
    273 	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 $IP6_REMOTE0
    274 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    275 
    276 	export RUMP_SERVER=$SOCK_REMOTE
    277 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    278 }
    279 
    280 vlan_vlanid_body_common()
    281 {
    282 	local af=inet
    283 	local prefix=24
    284 	local sysctl_param="net.inet.ip.dad_count=0"
    285 	local ping_cmd="rump.ping -n -w 1 -c 1"
    286 	local config_and_ping=vlanid_config_and_ping
    287 	local local0=$IP_LOCAL0
    288 	local local1=$IP_LOCAL1
    289 	local remote0=$IP_REMOTE0
    290 	local remote1=$IP_REMOTE1
    291 
    292 	if [ x"$1" = x"inet6" ]; then
    293 		af=inet6
    294 		prefix=64
    295 		sysctl_param="net.inet6.ip6.dad_count=0"
    296 		ping_cmd="rump.ping6 -n -c 1"
    297 		config_and_ping=vlanid_config_and_ping6
    298 		local0=$IP6_LOCAL0
    299 		local1=$IP6_LOCAL1
    300 		remote0=$IP6_REMOTE0
    301 		remote1=$IP6_REMOTE1
    302 	fi
    303 
    304 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    305 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    306 
    307 	export RUMP_SERVER=$SOCK_LOCAL
    308 	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
    309 	atf_check -s exit:0 rump.ifconfig shmif0 up
    310 	atf_check -s exit:0 rump.ifconfig vlan0 create
    311 
    312 	export RUMP_SERVER=$SOCK_REMOTE
    313 	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
    314 	atf_check -s exit:0 rump.ifconfig shmif0 up
    315 	atf_check -s exit:0 rump.ifconfig vlan0 create
    316 
    317 	export RUMP_SERVER=$SOCK_LOCAL
    318 	atf_check -s not-exit:0 -e ignore\
    319 	    rump.ifconfig vlan0 vlan -1 vlanif shmif0
    320 
    321 	$config_and_ping 0 # reserved vlan id
    322 	$config_and_ping 1
    323 	$config_and_ping 4094
    324 	$config_and_ping 4095 #reserved vlan id
    325 
    326 	export RUMP_SERVER=$SOCK_LOCAL
    327 	atf_check -s not-exit:0 -e ignore \
    328 	    rump.ifconfig vlan0 vlan 4096 vlanif shmif0
    329 
    330 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
    331 	atf_check -s not-exit:0 -e ignore \
    332 	    rump.ifconfig vlan0 vlan 2 vlanif shmif0
    333 
    334 	atf_check -s not-exit:0 -e ignore \
    335 	    rump.ifconfig vlan0 vlan 1 vlanif shmif1
    336 
    337 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    338 	atf_check -s not-exit:0 -e ignore \
    339 	    rump.ifconfig vlan0 $local0/$prefix
    340 
    341 	export RUMP_SERVER=$SOCK_LOCAL
    342 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    343 	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
    344 	atf_check -s exit:0 rump.ifconfig vlan0 up
    345 	atf_check -s exit:0 rump.ifconfig vlan1 create
    346 	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
    347 	atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix
    348 	atf_check -s exit:0 rump.ifconfig vlan1 up
    349 
    350 	export RUMP_SERVER=$SOCK_REMOTE
    351 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    352 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    353 	atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
    354 	atf_check -s exit:0 rump.ifconfig vlan0 up
    355 	atf_check -s exit:0 rump.ifconfig vlan1 create
    356 	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
    357 	atf_check -s exit:0 rump.ifconfig vlan1 $af $remote1/$prefix
    358 	atf_check -s exit:0 rump.ifconfig vlan1 up
    359 
    360 	export RUMP_SERVER=$SOCK_LOCAL
    361 	atf_check -s exit:0 -o ignore $ping_cmd $remote0
    362 	atf_check -s exit:0 -o ignore $ping_cmd $remote1
    363 }
    364 
    365 atf_test_case vlan_vlanid cleanup
    366 vlan_vlanid_head()
    367 {
    368 
    369 	atf_set "descr" "tests of configuration for vlan id"
    370 	atf_set "require.progs" "rump_server"
    371 }
    372 
    373 vlan_vlanid_body()
    374 {
    375 	rump_server_start $SOCK_LOCAL vlan
    376 	rump_server_start $SOCK_REMOTE vlan
    377 
    378 	vlan_vlanid_body_common inet
    379 }
    380 
    381 vlan_vlanid_cleanup()
    382 {
    383 
    384 	$DEBUG && dump
    385 	cleanup
    386 }
    387 
    388 atf_test_case vlan_vlanid6 cleanup
    389 vlan_vlanid6_head()
    390 {
    391 
    392 	atf_set "descr" "tests of configuration for vlan id using IPv6"
    393 	atf_set "require.progs" "rump_server"
    394 }
    395 
    396 
    397 vlan_vlanid6_body()
    398 {
    399 	rump_server_start $SOCK_LOCAL vlan netinet6
    400 	rump_server_start $SOCK_REMOTE vlan netinet6
    401 
    402 	vlan_vlanid_body_common inet6
    403 }
    404 
    405 vlan_vlanid6_cleanup()
    406 {
    407 
    408 	$DEBUG && dump
    409 	cleanup
    410 }
    411 
    412 vlan_configs_body_common()
    413 {
    414 	export RUMP_SERVER=${SOCK_LOCAL}
    415 
    416 	atf_check -s exit:0 rump.ifconfig shmif0 create
    417 	atf_check -s exit:0 rump.ifconfig shmif1 create
    418 	atf_check -s exit:0 rump.ifconfig vlan0 create
    419 
    420 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    421 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    422 
    423 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    424 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
    425 
    426 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    427 	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif1
    428 	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif2
    429 
    430 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    431 
    432 	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
    433 	atf_check -s exit:0 -e match:'Invalid argument' \
    434 	    rump.ifconfig vlan0 mtu 1497
    435 	atf_check -s exit:0 rump.ifconfig vlan0 mtu 1496
    436 	atf_check -s exit:0 rump.ifconfig vlan0 mtu 42
    437 	atf_check -s exit:0 -e match:'Invalid argument' \
    438 	    rump.ifconfig vlan0 mtu 41
    439 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
    440 }
    441 
    442 atf_test_case vlan_configs cleanup
    443 vlan_configs_head()
    444 {
    445 	atf_set "descr" "tests of configuration except vlan id"
    446 	atf_set "require.progs" "rump_server"
    447 }
    448 
    449 vlan_configs_body()
    450 {
    451 
    452 	rump_server_start $SOCK_LOCAL vlan
    453 
    454 	vlan_configs_body_common
    455 
    456 }
    457 
    458 vlan_configs_cleanup()
    459 {
    460 
    461 	$DEBUG && dump
    462 	cleanup
    463 }
    464 
    465 atf_test_case vlan_configs6 cleanup
    466 vlan_configs6_head()
    467 {
    468 	atf_set "descr" "tests of configuration except vlan id using IPv6"
    469 	atf_set "require.progs" "rump_server"
    470 }
    471 
    472 vlan_configs6_body()
    473 {
    474 	rump_server_start $SOCK_LOCAL vlan netinet6
    475 
    476 	vlan_configs_body_common
    477 }
    478 
    479 vlan_configs6_cleanup()
    480 {
    481 	$DEBUG && dump
    482 	cleanup
    483 }
    484 
    485 atf_init_test_cases()
    486 {
    487 
    488 	atf_add_test_case vlan_create_destroy
    489 	atf_add_test_case vlan_basic
    490 	atf_add_test_case vlan_vlanid
    491 	atf_add_test_case vlan_configs
    492 
    493 	atf_add_test_case vlan_create_destroy6
    494 	atf_add_test_case vlan_basic6
    495 	atf_add_test_case vlan_vlanid6
    496 	atf_add_test_case vlan_configs6
    497 }
    498