Home | History | Annotate | Line # | Download | only in if_lagg
t_lagg.sh revision 1.6
      1 #	$NetBSD: t_lagg.sh,v 1.6 2021/11/08 06:24:11 yamaguchi Exp $
      2 #
      3 # Copyright (c) 2021 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 SOCK_HOST0=unix://commsock0
     29 SOCK_HOST1=unix://commsock1
     30 SOCK_HOST2=unix://commsock2
     31 BUS0=bus0
     32 BUS1=bus1
     33 BUS2=bus2
     34 IP4ADDR0=192.168.0.1
     35 IP4ADDR1=192.168.0.2
     36 IP4ADDR2=192.168.1.1
     37 IP4ADDR3=192.168.1.2
     38 IP6ADDR0=fc00::1
     39 IP6ADDR1=fc00::2
     40 IP6ADDR2=fc00:1::1
     41 IP6ADDR3=fc00:1::2
     42 WAITTIME=20
     43 
     44 DEBUG=${DEBUG:-false}
     45 
     46 wait_state()
     47 {
     48 	local state=$1
     49 	local if_lagg=$2
     50 	local if_port=$3
     51 
     52 	local n=$WAITTIME
     53 	local cmd_grep="grep -q ${state}"
     54 
     55 	if [ x"$if_port" != x"" ]; then
     56 		cmd_grep="grep $if_port | $cmd_grep"
     57 	fi
     58 
     59 	for i in $(seq $n); do
     60 		rump.ifconfig $if_lagg | eval $cmd_grep
     61 		if [ $? = 0 ] ; then
     62 			$DEBUG && echo "wait for $i seconds."
     63 			return 0
     64 		fi
     65 
     66 		sleep 1
     67 	done
     68 
     69 	$DEBUG && rump.ifconfig -v $if_lagg
     70 	atf_fail "Couldn't be ${state} for $n seconds."
     71 }
     72 wait_for_distributing()
     73 {
     74 
     75 	wait_state "DISTRIBUTING" $*
     76 }
     77 
     78 expected_inactive()
     79 {
     80 	local if_lagg=$1
     81 	local if_port=$2
     82 
     83 	sleep 3 # wait a little
     84 	atf_check -s exit:0 -o not-match:"${if_port}.*ACTIVE" \
     85 	    rump.ifconfig ${if_lagg}
     86 }
     87 
     88 setup_l2tp_ipv4tunnel()
     89 {
     90 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
     91 
     92 	local a_addr0=10.0.0.1
     93 	local a_addr1=10.0.0.2
     94 	local b_addr0=10.0.1.1
     95 	local b_addr1=10.0.1.2
     96 	local c_addr0=10.0.2.1
     97 	local c_addr1=10.0.2.2
     98 
     99 	local a_session0=1001
    100 	local a_session1=1002
    101 	local b_session0=1011
    102 	local b_session1=1012
    103 	local c_session0=1021
    104 	local c_session1=1022
    105 
    106 	rump_server_add_iface $SOCK_HOST0 l2tp0
    107 	rump_server_add_iface $SOCK_HOST0 l2tp1
    108 	rump_server_add_iface $SOCK_HOST0 l2tp2
    109 	rump_server_add_iface $SOCK_HOST1 l2tp0
    110 	rump_server_add_iface $SOCK_HOST1 l2tp1
    111 	rump_server_add_iface $SOCK_HOST1 l2tp2
    112 
    113 
    114 	export RUMP_SERVER=$SOCK_HOST0
    115 	$atf_ifconfig shmif0 $a_addr0/24
    116 	$atf_ifconfig l2tp0  tunnel  $a_addr0    $a_addr1
    117 	$atf_ifconfig l2tp0  session $a_session0 $a_session1
    118 
    119 	$atf_ifconfig shmif1 $b_addr0/24
    120 	$atf_ifconfig l2tp1  tunnel  $b_addr0    $b_addr1
    121 	$atf_ifconfig l2tp1  session $b_session0 $b_session1
    122 
    123 	$atf_ifconfig shmif2 $c_addr0/24
    124 	$atf_ifconfig l2tp2  tunnel  $c_addr0    $c_addr1
    125 	$atf_ifconfig l2tp2  session $c_session0 $c_session1
    126 
    127 	export RUMP_SERVER=$SOCK_HOST1
    128 	$atf_ifconfig shmif0 $a_addr1/24
    129 	$atf_ifconfig l2tp0  tunnel  $a_addr1    $a_addr0
    130 	$atf_ifconfig l2tp0  session $a_session1 $a_session0
    131 
    132 	$atf_ifconfig shmif1 $b_addr1/24
    133 	$atf_ifconfig l2tp1  tunnel  $b_addr1    $b_addr0
    134 	$atf_ifconfig l2tp1  session $b_session1 $b_session0
    135 
    136 	$atf_ifconfig shmif2 $c_addr1/24
    137 	$atf_ifconfig l2tp2  tunnel  $c_addr1    $c_addr0
    138 	$atf_ifconfig l2tp2  session $c_session1 $c_session0
    139 }
    140 
    141 atf_test_case lagg_ifconfig cleanup
    142 lagg_ifconfig_head()
    143 {
    144 
    145 	atf_set "descr" "tests for create, destroy, and ioctl of lagg(4)"
    146 	atf_set "require.progs" "rump_server"
    147 }
    148 
    149 lagg_ifconfig_body()
    150 {
    151 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    152 
    153 	rump_server_start $SOCK_HOST0 lagg
    154 
    155 	export RUMP_SERVER=$SOCK_HOST0
    156 	$atf_ifconfig lagg0 create
    157 	$atf_ifconfig lagg0 destroy
    158 
    159 	$atf_ifconfig lagg0 create
    160 	$atf_ifconfig shmif0 create
    161 
    162 	$atf_ifconfig lagg0 laggproto none
    163 	atf_check -s exit:0 -o match:'laggproto none' \
    164 	    rump.ifconfig lagg0
    165 
    166 	# cannot add a port while protocol is none
    167 	atf_check -s not-exit:0 -e ignore \
    168 	    rump.ifconfig lagg0 laggport shmif0
    169 
    170 	$atf_ifconfig lagg0 laggproto lacp
    171 	atf_check -s exit:0 -o match:'laggproto lacp' \
    172 	    rump.ifconfig lagg0
    173 
    174 	# add a port and an added port
    175 	$atf_ifconfig lagg0 laggport shmif0
    176 	atf_check -s not-exit:0 -e ignore \
    177 	    rump.ifconfig lagg0 laggport shmif0
    178 
    179 	# remove an added port and a removed port
    180 	$atf_ifconfig lagg0 -laggport shmif0
    181 	atf_check -s not-exit:0 -e ignore \
    182 	    rump.ifconfig lagg0 -laggport shmif0
    183 
    184 	# re-add a removed port
    185 	$atf_ifconfig lagg0 laggport shmif0
    186 
    187 	# detach protocol even if the I/F has ports
    188 	$atf_ifconfig lagg0 laggproto none
    189 
    190 	# destroy the interface while grouping ports
    191 	$atf_ifconfig lagg0 destroy
    192 
    193 	$atf_ifconfig lagg0 create
    194 	$atf_ifconfig shmif1 create
    195 
    196 	$atf_ifconfig lagg0 laggproto lacp
    197 	$atf_ifconfig lagg0 laggport shmif0
    198 	$atf_ifconfig lagg0 laggport shmif1
    199 
    200 	$atf_ifconfig lagg0 -laggport shmif0
    201 	$atf_ifconfig lagg0 laggport shmif0
    202 	$atf_ifconfig lagg0 -laggport shmif1
    203 	$atf_ifconfig lagg0 laggport shmif1
    204 
    205 	# destroy a LAGed port
    206 	atf_check -s exit:0 -o match:shmif0 rump.ifconfig lagg0
    207 	atf_check -s exit:0 -o match:shmif1 rump.ifconfig lagg0
    208 	$atf_ifconfig shmif0 destroy
    209 	$atf_ifconfig shmif1 destroy
    210 
    211 	$atf_ifconfig lagg0 laggproto none
    212 	atf_check -s exit:0 -o ignore rump.ifconfig lagg0
    213 }
    214 
    215 lagg_ifconfig_cleanup()
    216 {
    217 	$DEBG && dump
    218 	cleanup
    219 }
    220 
    221 atf_test_case lagg_macaddr cleanup
    222 lagg_macaddr_head()
    223 {
    224 	atf_set "descr" "tests for a MAC address to assign to lagg(4)"
    225 	atf_set "require.progs" "rump_server"
    226 }
    227 
    228 lagg_macaddr_body()
    229 {
    230 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    231 	local lnkaddr0="02:00:00:00:00:01" # 02: I/G = 0, G/L = 1
    232 
    233 	rump_server_start $SOCK_HOST0 lagg
    234 
    235 	export RUMP_SERVER=$SOCK_HOST0
    236 	$atf_ifconfig lagg0 create
    237 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    238 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    239 
    240 	maddr=$(get_macaddr $SOCK_HOST0 lagg0)
    241 	maddr0=$(get_macaddr $SOCK_HOST0 shmif0)
    242 	maddr1=$(get_macaddr $SOCK_HOST0 shmif1)
    243 
    244 	$atf_ifconfig lagg0 laggproto lacp
    245 
    246 	#
    247 	# Copy MAC address from shmif0 that is
    248 	# the first port to lagg.
    249 	# (laggport: (none) => shmif0)
    250 	#
    251 	$atf_ifconfig lagg0 laggport shmif0
    252 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig lagg0
    253 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig shmif0
    254 
    255 	#
    256 	# Copy MAC address assigned to lagg0 to shmif1
    257 	# (laggport: shmif0 => shmif0, shmif1)
    258 	#
    259 	$atf_ifconfig lagg0 laggport shmif1
    260 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig lagg0
    261 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig shmif1
    262 
    263 	#
    264 	# Change MAC address on the detaching
    265 	# the first port (shmif0) from lagg0
    266 	# (laggport: shmif0, shmif1 => shmif1)
    267 	#
    268 	$atf_ifconfig lagg0 -laggport shmif0
    269 	atf_check -s exit:0 -o match:$maddr1 rump.ifconfig lagg0
    270 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig shmif0
    271 	atf_check -s exit:0 -o match:$maddr1 rump.ifconfig shmif1
    272 
    273 	#
    274 	# Copy lagg0's MAC address to shmif0 even if
    275 	# lagg0 had used shmif0's MAC address
    276 	# (laggport: shmif1 => shmif1, shmif0)
    277 	#
    278 	$atf_ifconfig lagg0 laggport shmif0
    279 	atf_check -s exit:0 -o match:$maddr1 rump.ifconfig lagg0
    280 	atf_check -s exit:0 -o match:$maddr1 rump.ifconfig shmif0
    281 
    282 	#
    283 	# should not change MAC address of lagg0 on detaching
    284 	# shmif0 that copied mac address from lagg0
    285 	# (laggport: shmif1, shmif0 => shmif1)
    286 	#
    287 	$atf_ifconfig lagg0 -laggport shmif0
    288 	atf_check -s exit:0 -o match:$maddr1 rump.ifconfig lagg0
    289 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig shmif0
    290 
    291 	#
    292 	# Use the generated MAC address
    293 	# when all port detached from lagg0
    294 	# (laggport: shmif1 => (none))
    295 	$atf_ifconfig lagg0 -laggport shmif1
    296 	atf_check -s exit:0 -o match:$maddr rump.ifconfig lagg0
    297 
    298 	#
    299 	# Copy the active MAC address from shmif0 to lagg0
    300 	# when shmif0 has two MAC addresses
    301 	#
    302 	$atf_ifconfig shmif0 link $lnkaddr0
    303 	$atf_ifconfig lagg0 laggport shmif0
    304 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig lagg0
    305 	atf_check -s exit:0 -o not-match:$lnkaddr0 rump.ifconfig lagg0
    306 	atf_check -s exit:0 -o match:$maddr0 rump.ifconfig shmif0
    307 	atf_check -s exit:0 -o match:$lnkaddr0 rump.ifconfig shmif0
    308 }
    309 
    310 lagg_macaddr_cleanup()
    311 {
    312 	$DEBUG && dump
    313 	cleanup
    314 }
    315 
    316 atf_test_case lagg_ipv6lla cleanup
    317 lagg_ipv6lla_head()
    318 {
    319 	atf_set "descr" "tests for a IPV6 LLA to assign to lagg(4)"
    320 	atf_set "require.progs" "rump_server"
    321 }
    322 
    323 lagg_ipv6lla_body()
    324 {
    325 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    326 
    327 	rump_server_start $SOCK_HOST0 netinet6 lagg
    328 
    329 	export RUMP_SERVER=$SOCK_HOST0
    330 	$atf_ifconfig lagg0 create
    331 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    332 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    333 
    334 	$atf_ifconfig lagg0 laggproto lacp
    335 
    336 	$atf_ifconfig shmif0 up
    337 	atf_check -s exit:0 -o match:'inet6 fe80:' rump.ifconfig shmif0
    338 
    339 	$atf_ifconfig lagg0 laggproto lacp laggport shmif0
    340 	atf_check -s exit:0 -o not-match:'inet6 fe80:' rump.ifconfig shmif0
    341 
    342 	$atf_ifconfig lagg0 laggport shmif1
    343 	$atf_ifconfig shmif1 up
    344 	atf_check -s exit:0 -o not-match:'inet6 fe80:' rump.ifconfig shmif1
    345 
    346 	$atf_ifconfig lagg0 -laggport shmif0
    347 	atf_check -s exit:0 -o match:'inet6 fe80:' rump.ifconfig shmif0
    348 
    349 	$atf_ifconfig shmif1 down
    350 	$atf_ifconfig lagg0 -laggport shmif1
    351 	atf_check -s exit:0 -o not-match:'inet fe80:' rump.ifconfig shmif1
    352 }
    353 
    354 lagg_ipv6lla_cleanup()
    355 {
    356 	$DEBUG && dump
    357 	cleanup
    358 }
    359 
    360 atf_test_case lagg_lacp_basic cleanup
    361 lagg_lacp_basic_head()
    362 {
    363 
    364 	atf_set "descr" "tests for LACP basic functions"
    365 	atf_set "require.progs" "rump_server"
    366 }
    367 
    368 lagg_lacp_basic_body()
    369 {
    370 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    371 
    372 	rump_server_start $SOCK_HOST0 lagg
    373 	rump_server_start $SOCK_HOST1 lagg
    374 	rump_server_start $SOCK_HOST2 lagg
    375 
    376 	export RUMP_SERVER=$SOCK_HOST0
    377 
    378 	# added running interface
    379 	$atf_ifconfig shmif0 create
    380 	$atf_ifconfig shmif0 linkstr $BUS0
    381 
    382 	$atf_ifconfig shmif1 create
    383 	$atf_ifconfig shmif1 linkstr $BUS1
    384 
    385 	$atf_ifconfig lagg0 create
    386 	$atf_ifconfig lagg0 laggproto lacp
    387 
    388 	$atf_ifconfig shmif0 up
    389 	$atf_ifconfig shmif1 up
    390 	$atf_ifconfig lagg0 up
    391 
    392 	$atf_ifconfig lagg0 laggport shmif0
    393 	$atf_ifconfig lagg0 laggport shmif1
    394 	$atf_ifconfig -w 10
    395 
    396 	$atf_ifconfig lagg0 -laggport shmif0
    397 	$atf_ifconfig lagg0 -laggport shmif1
    398 	$atf_ifconfig lagg0 down
    399 
    400 	# add the same interfaces again
    401 	$atf_ifconfig lagg0 up
    402 	$atf_ifconfig lagg0 laggport shmif0
    403 	$atf_ifconfig lagg0 laggport shmif1
    404 
    405 	# detach and re-attach protocol
    406 	$atf_ifconfig lagg0 laggproto none
    407 	$atf_ifconfig lagg0 laggproto lacp \
    408 	    laggport shmif0 laggport shmif1
    409 
    410 	$atf_ifconfig lagg0 -laggport shmif0 -laggport shmif1
    411 	$atf_ifconfig lagg0 destroy
    412 	$atf_ifconfig shmif0 destroy
    413 	$atf_ifconfig shmif1 destroy
    414 
    415 	# tests for a loopback condition
    416 	$atf_ifconfig shmif0 create
    417 	$atf_ifconfig shmif0 linkstr $BUS0
    418 	$atf_ifconfig shmif1 create
    419 	$atf_ifconfig shmif1 linkstr $BUS0
    420 	$atf_ifconfig lagg0 create
    421 	$atf_ifconfig lagg0 laggproto lacp \
    422 	    laggport shmif0 laggport shmif1
    423 	$atf_ifconfig shmif0 up
    424 	$atf_ifconfig shmif1 up
    425 	$atf_ifconfig lagg0 up
    426 
    427 	expected_inactive lagg0
    428 
    429 	$atf_ifconfig shmif0 down
    430 	$atf_ifconfig shmif0 destroy
    431 	$atf_ifconfig shmif1 down
    432 	$atf_ifconfig shmif1 destroy
    433 	$atf_ifconfig lagg0 down
    434 	$atf_ifconfig lagg0 destroy
    435 
    436 	export RUMP_SERVER=$SOCK_HOST0
    437 	$atf_ifconfig shmif0 create
    438 	$atf_ifconfig shmif0 linkstr $BUS0
    439 	$atf_ifconfig shmif0 up
    440 
    441 	$atf_ifconfig shmif1 create
    442 	$atf_ifconfig shmif1 linkstr $BUS1
    443 	$atf_ifconfig shmif1 up
    444 
    445 	$atf_ifconfig shmif2 create
    446 	$atf_ifconfig shmif2 linkstr $BUS2
    447 	$atf_ifconfig shmif2 up
    448 
    449 	$atf_ifconfig lagg0 create
    450 	$atf_ifconfig lagg0 laggproto lacp laggport shmif0 \
    451 	    laggport shmif1 laggport shmif2
    452 	$atf_ifconfig lagg0 up
    453 
    454 	export RUMP_SERVER=$SOCK_HOST1
    455 	$atf_ifconfig shmif0 create
    456 	$atf_ifconfig shmif0 linkstr $BUS0
    457 	$atf_ifconfig shmif0 up
    458 
    459 	$atf_ifconfig shmif1 create
    460 	$atf_ifconfig shmif1 linkstr $BUS1
    461 	$atf_ifconfig shmif1 up
    462 
    463 	$atf_ifconfig lagg0 create
    464 	$atf_ifconfig lagg0 laggproto lacp
    465 	$atf_ifconfig lagg1 create
    466 	$atf_ifconfig lagg1 laggproto lacp
    467 
    468 	$atf_ifconfig lagg0 laggport shmif0
    469 	$atf_ifconfig lagg0 up
    470 	wait_for_distributing lagg0 shmif0
    471 
    472 	$atf_ifconfig lagg1 laggport shmif1
    473 	$atf_ifconfig lagg1 up
    474 
    475 	export RUMP_SERVER=$SOCK_HOST2
    476 	$atf_ifconfig shmif0 create
    477 	$atf_ifconfig shmif0 linkstr $BUS2
    478 	$atf_ifconfig shmif0 up
    479 
    480 	$atf_ifconfig lagg0 create
    481 	$atf_ifconfig lagg0 laggproto lacp laggport shmif0
    482 	$atf_ifconfig lagg0 up
    483 
    484 	export RUMP_SERVER=$SOCK_HOST0
    485 	wait_for_distributing lagg0 shmif0
    486 	expected_inactive lagg0 shmif1
    487 	expected_inactive lagg0 shmif2
    488 }
    489 
    490 lagg_lacp_basic_cleanup()
    491 {
    492 
    493 	$DEBUG && dump
    494 	cleanup
    495 }
    496 
    497 lagg_lacp_ping()
    498 {
    499 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    500 
    501 	local af=$1
    502 	local l2proto=$2
    503 	local atf_ping="atf_check -s exit:0 -o ignore rump.ping -c 1"
    504 	local ping=rump.ping
    505 	local rumplib=""
    506 	local pfx=24
    507 	local addr_host0=$IP4ADDR0
    508 	local addr_host1=$IP4ADDR1
    509 
    510 	case $af in
    511 	"inet")
    512 		# do nothing
    513 		;;
    514 	"inet6")
    515 		atf_ping="atf_check -s exit:0 -o ignore rump.ping6 -c 1"
    516 		rumplib="netinet6"
    517 		pfx=64
    518 		addr_host0=$IP6ADDR0
    519 		addr_host1=$IP6ADDR1
    520 		;;
    521 	esac
    522 
    523 	case $l2proto in
    524 	"ether")
    525 		iface0=shmif0
    526 		iface1=shmif1
    527 		iface2=shmif2
    528 		;;
    529 	"l2tp")
    530 		rumplib="$rumplib l2tp"
    531 		iface0=l2tp0
    532 		iface1=l2tp1
    533 		iface2=l2tp2
    534 		;;
    535 	esac
    536 
    537 	rump_server_start $SOCK_HOST0 lagg $rumplib
    538 	rump_server_start $SOCK_HOST1 lagg $rumplib
    539 
    540 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    541 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    542 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
    543 
    544 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
    545 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
    546 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
    547 
    548 	if [ x"$l2proto" = x"l2tp" ];then
    549 		setup_l2tp_ipv4tunnel
    550 	fi
    551 
    552 	export RUMP_SERVER=$SOCK_HOST0
    553 	$atf_ifconfig lagg0 create
    554 	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
    555 	$atf_ifconfig lagg0 $af $addr_host0/$pfx
    556 	$atf_ifconfig $iface0 up
    557 	$atf_ifconfig lagg0 up
    558 
    559 	export RUMP_SERVER=$SOCK_HOST1
    560 	$atf_ifconfig lagg0 create
    561 	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
    562 	$atf_ifconfig lagg0 $af $addr_host1/$pfx
    563 	$atf_ifconfig $iface0 up
    564 	$atf_ifconfig lagg0 up
    565 
    566 	export RUMP_SERVER=$SOCK_HOST0
    567 	wait_for_distributing lagg0
    568 	$atf_ifconfig -w 10
    569 
    570 	export RUMP_SERVER=$SOCK_HOST1
    571 	wait_for_distributing lagg0
    572 	$atf_ifconfig -w 10
    573 
    574 	$atf_ping $addr_host0
    575 
    576 	export RUMP_SERVER=$SOCK_HOST0
    577 	$atf_ifconfig $iface1 up
    578 	$atf_ifconfig lagg0 laggport $iface1 laggport $iface2
    579 	$atf_ifconfig $iface2 up
    580 
    581 	export RUMP_SERVER=$SOCK_HOST1
    582 	$atf_ifconfig $iface1 up
    583 	$atf_ifconfig lagg0 laggport $iface1 laggport $iface2
    584 	$atf_ifconfig $iface2 up
    585 
    586 	export RUMP_SERVER=$SOCK_HOST0
    587 	wait_for_distributing lagg0 $iface1
    588 	wait_for_distributing lagg0 $iface2
    589 
    590 	export RUMP_SERVER=$SOCK_HOST1
    591 	wait_for_distributing lagg0 $iface1
    592 	wait_for_distributing lagg0 $iface2
    593 
    594 	$atf_ping $addr_host0
    595 }
    596 
    597 atf_test_case lagg_lacp_ipv4 cleanup
    598 lagg_lacp_ipv4_head()
    599 {
    600 
    601 	atf_set "descr" "tests for IPv4 with LACP"
    602 	atf_set "require.progs" "rump_server"
    603 }
    604 
    605 lagg_lacp_ipv4_body()
    606 {
    607 
    608 	lagg_lacp_ping "inet" "ether"
    609 }
    610 
    611 lagg_lacp_ipv4_cleanup()
    612 {
    613 
    614 	$DEBUG && dump
    615 	cleanup
    616 }
    617 
    618 atf_test_case lagg_lacp_ipv6 cleanup
    619 lagg_lacp_ipv6_head()
    620 {
    621 
    622 	atf_set "descr" "tests for IPv6 with LACP"
    623 	atf_set "require.progs" "rump_server"
    624 }
    625 
    626 lagg_lacp_ipv6_body()
    627 {
    628 
    629 	lagg_lacp_ping "inet6" "ether"
    630 }
    631 
    632 lagg_lacp_ipv6_cleanup()
    633 {
    634 
    635 	$DEBUG && dump
    636 	cleanup
    637 }
    638 
    639 atf_test_case lagg_lacp_l2tp_ipv4 cleanup
    640 lagg_lacp_l2tp_ipv4_head()
    641 {
    642 
    643 	atf_set "descr" "tests for LACP over l2tp by using IPv4"
    644 	atf_set "require.progs" "rump_server"
    645 }
    646 
    647 lagg_lacp_l2tp_ipv4_body()
    648 {
    649 
    650 	lagg_lacp_ping "inet" "l2tp"
    651 }
    652 
    653 lagg_lacp_l2tp_ipv4_cleanup()
    654 {
    655 
    656 	$DEBUG && dump
    657 	cleanup
    658 }
    659 
    660 atf_test_case lagg_lacp_l2tp_ipv6 cleanup
    661 lagg_lacp_l2tp_ipv6_head()
    662 {
    663 
    664 	atf_set "descr" "tests for LACP over l2tp using IPv6"
    665 	atf_set "require.progs" "rump_server"
    666 }
    667 
    668 lagg_lacp_l2tp_ipv6_body()
    669 {
    670 
    671 	lagg_lacp_ping "inet6" "l2tp"
    672 }
    673 
    674 lagg_lacp_l2tp_ipv6_cleanup()
    675 {
    676 
    677 	$DEBUG && dump
    678 	cleanup
    679 }
    680 
    681 lagg_lacp_vlan()
    682 {
    683 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    684 
    685 	local af=$1
    686 	local l2proto=$2
    687 	local atf_ping="atf_check -s exit:0 -o ignore rump.ping -c 1"
    688 	local rumplib="vlan"
    689 	local pfx=24
    690 	local vlan0_addr_host0=$IP4ADDR0
    691 	local host0addr0=$IP4ADDR0
    692 	local host1addr0=$IP4ADDR1
    693 	local host0addr1=$IP4ADDR2
    694 	local host1addr1=$IP4ADDR3
    695 
    696 	case $af in
    697 	"inet")
    698 		# do nothing
    699 		;;
    700 	"inet6")
    701 		atf_ping="atf_check -s exit:0 -o ignore rump.ping6 -c 1"
    702 		rumplib="$rumplib netinet6"
    703 		pfx=64
    704 		host0addr0=$IP6ADDR0
    705 		host1addr0=$IP6ADDR1
    706 		host0addr1=$IP6ADDR2
    707 		host1addr1=$IP6ADDR3
    708 		;;
    709 	esac
    710 
    711 	case $l2proto in
    712 	"ether")
    713 		iface0=shmif0
    714 		iface1=shmif1
    715 		iface2=shmif2
    716 		;;
    717 	"l2tp")
    718 		rumplib="$rumplib l2tp"
    719 		iface0=l2tp0
    720 		iface1=l2tp1
    721 		iface2=l2tp2
    722 	esac
    723 
    724 	rump_server_start $SOCK_HOST0 lagg $rumplib
    725 	rump_server_start $SOCK_HOST1 lagg $rumplib
    726 
    727 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    728 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    729 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
    730 
    731 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
    732 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
    733 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
    734 
    735 	if [ x"$l2proto" = x"l2tp" ]; then
    736 		setup_l2tp_ipv4tunnel
    737 	fi
    738 
    739 	export RUMP_SERVER=$SOCK_HOST0
    740 	$atf_ifconfig lagg0 create
    741 	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
    742 	$atf_ifconfig $iface0 up
    743 	$atf_ifconfig lagg0 up
    744 
    745 	export RUMP_SERVER=$SOCK_HOST1
    746 	$atf_ifconfig lagg0 create
    747 	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
    748 	$atf_ifconfig $iface0 up
    749 	$atf_ifconfig lagg0 up
    750 
    751 	export RUMP_SERVER=$SOCK_HOST0
    752 	wait_for_distributing lagg0
    753 
    754 	$atf_ifconfig vlan0 create
    755 	$atf_ifconfig vlan0 vlan 10 vlanif lagg0
    756 	$atf_ifconfig vlan0 $af $host0addr0/$pfx
    757 	$atf_ifconfig vlan0 up
    758 
    759 	$atf_ifconfig vlan1 create
    760 	$atf_ifconfig vlan1 vlan 11 vlanif lagg0
    761 	$atf_ifconfig vlan1 $af $host0addr1/$pfx
    762 	$atf_ifconfig vlan1 up
    763 
    764 	export RUMP_SERVER=$SOCK_HOST1
    765 	$atf_ifconfig vlan0 create
    766 	$atf_ifconfig vlan0 vlan 10 vlanif lagg0
    767 	$atf_ifconfig vlan0 $af $host1addr0/$pfx
    768 	$atf_ifconfig vlan0 up
    769 
    770 	$atf_ifconfig vlan1 create
    771 	$atf_ifconfig vlan1 vlan 11 vlanif lagg0
    772 	$atf_ifconfig vlan1 $af $host1addr1/$pfx
    773 	$atf_ifconfig vlan1 up
    774 
    775 	export RUMP_SERVER=$SOCK_HOST0
    776 	$atf_ifconfig -w 10
    777 	export RUMP_SERVER=$SOCK_HOST1
    778 	$atf_ifconfig -w 10
    779 
    780 	export RUMP_SERVER=$SOCK_HOST0
    781 	$atf_ping $host1addr0
    782 	$atf_ping $host1addr1
    783 
    784 	$atf_ifconfig lagg0 laggport $iface1
    785 	$atf_ifconfig $iface1 up
    786 
    787 	export RUMP_SERVER=$SOCK_HOST1
    788 	$atf_ifconfig lagg0 laggport $iface1
    789 	$atf_ifconfig $iface1 up
    790 
    791 	export RUMP_SERVER=$SOCK_HOST0
    792 	wait_for_distributing lagg0 $iface1
    793 
    794 	export RUMP_SERVER=$SOCK_HOST1
    795 	wait_for_distributing lagg0 $iface1
    796 
    797 	$atf_ping $host0addr0
    798 	$atf_ping $host0addr1
    799 }
    800 
    801 atf_test_case lagg_lacp_vlan_ipv4 cleanup
    802 lagg_lacp_vlan_ipv4_head()
    803 {
    804 
    805 	atf_set "descr" "tests for IPv4 VLAN frames over LACP LAG"
    806 	atf_set "require.progs" "rump_server"
    807 }
    808 
    809 lagg_lacp_vlan_ipv4_body()
    810 {
    811 
    812 	lagg_lacp_vlan "inet" "ether"
    813 }
    814 
    815 lagg_lacp_vlan_ipv4_cleanup()
    816 {
    817 	$DEBUG && dump
    818 	cleanup
    819 }
    820 
    821 atf_test_case lagg_lacp_vlan_ipv6 cleanup
    822 lagg_lacp_vlan_ipv6_head()
    823 {
    824 
    825 	atf_set "descr" "tests for IPv6 VLAN frames over LACP LAG"
    826 	atf_set "require.progs" "rump_server"
    827 }
    828 
    829 lagg_lacp_vlan_ipv6_body()
    830 {
    831 
    832 	lagg_lacp_vlan "inet6" "ether"
    833 }
    834 
    835 lagg_lacp_vlan_ipv6_cleanup()
    836 {
    837 	$DEBUG && dump
    838 	cleanup
    839 }
    840 
    841 atf_test_case lagg_lacp_vlanl2tp_ipv4 cleanup
    842 lagg_lacp_vlanl2tp_ipv4_head()
    843 {
    844 
    845 	atf_set "descr" "tests for IPv4 VLAN frames over LACP L2TP LAG"
    846 	atf_set "require.progs" "rump_server"
    847 }
    848 
    849 lagg_lacp_vlanl2tp_ipv4_body()
    850 {
    851 
    852 	lagg_lacp_vlan "inet" "l2tp"
    853 }
    854 
    855 lagg_lacp_vlanl2tp_ipv4_cleanup()
    856 {
    857 
    858 	$DEBUG && dump
    859 	cleanup
    860 }
    861 
    862 atf_test_case lagg_lacp_vlanl2tp_ipv6 cleanup
    863 lagg_lacp_vlanl2tp_ipv6_head()
    864 {
    865 
    866 	atf_set "descr" "tests for IPv6 VLAN frames over LACP L2TP LAG"
    867 	atf_set "require.progs" "rump_server"
    868 }
    869 
    870 lagg_lacp_vlanl2tp_ipv6_body()
    871 {
    872 
    873 	lagg_lacp_vlan "inet6" "l2tp"
    874 }
    875 
    876 lagg_lacp_vlanl2tp_ipv6_cleanup()
    877 {
    878 
    879 	$DEBUG && dump
    880 	cleanup
    881 }
    882 
    883 atf_test_case lagg_lacp_portpri cleanup
    884 lagg_lacp_portpri_head()
    885 {
    886 
    887 	atf_set "descr" "tests for LACP port priority"
    888 	atf_set "require.progs" "rump_server"
    889 }
    890 
    891 lagg_lacp_portpri_body()
    892 {
    893 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    894 
    895 	rump_server_start $SOCK_HOST0 lagg
    896 	rump_server_start $SOCK_HOST1 lagg
    897 
    898 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    899 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    900 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
    901 
    902 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
    903 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
    904 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
    905 
    906 	export RUMP_SERVER=$SOCK_HOST0
    907 	$atf_ifconfig lagg0 create
    908 	$atf_ifconfig lagg0 laggproto lacp
    909 	$atf_ifconfig lagg0 lagglacp maxports 2
    910 
    911 	$atf_ifconfig shmif0 up
    912 	$atf_ifconfig shmif1 up
    913 	$atf_ifconfig shmif2 up
    914 
    915 	$atf_ifconfig lagg0 laggport shmif0 pri 1000
    916 	$atf_ifconfig lagg0 laggport shmif1 pri 2000
    917 	$atf_ifconfig lagg0 laggport shmif2 pri 3000
    918 	$atf_ifconfig lagg0 up
    919 
    920 	atf_check -s exit:0 -o match:'shmif0 pri=1000' rump.ifconfig lagg0
    921 	atf_check -s exit:0 -o match:'shmif1 pri=2000' rump.ifconfig lagg0
    922 	atf_check -s exit:0 -o match:'shmif2 pri=3000' rump.ifconfig lagg0
    923 
    924 	export RUMP_SERVER=$SOCK_HOST1
    925 	$atf_ifconfig lagg0 create
    926 	$atf_ifconfig lagg0 laggproto lacp
    927 
    928 	$atf_ifconfig shmif0 up
    929 	$atf_ifconfig shmif1 up
    930 	$atf_ifconfig shmif2 up
    931 
    932 	$atf_ifconfig lagg0 laggport shmif0 pri 300
    933 	$atf_ifconfig lagg0 laggport shmif1 pri 200
    934 	$atf_ifconfig lagg0 laggport shmif2 pri 100
    935 	$atf_ifconfig lagg0 up
    936 
    937 	atf_check -s exit:0 -o match:'shmif0 pri=300' rump.ifconfig lagg0
    938 	atf_check -s exit:0 -o match:'shmif1 pri=200' rump.ifconfig lagg0
    939 	atf_check -s exit:0 -o match:'shmif2 pri=100' rump.ifconfig lagg0
    940 
    941 	export RUMP_SERVER=$SOCK_HOST0
    942 	wait_for_distributing lagg0 shmif0
    943 	wait_for_distributing lagg0 shmif1
    944 	wait_state "STANDBY" lagg0 shmif2
    945 
    946 	$atf_ifconfig shmif0 down
    947 	wait_for_distributing lagg0 shmif2
    948 
    949 	$atf_ifconfig shmif0 up
    950 	wait_for_distributing lagg0 shmif0
    951 
    952 	$atf_ifconfig lagg0 laggportpri shmif0 5000
    953 	$atf_ifconfig lagg0 laggportpri shmif1 5000
    954 	$atf_ifconfig lagg0 laggportpri shmif2 5000
    955 
    956 	atf_check -s exit:0 -o match:'shmif0 pri=5000' rump.ifconfig lagg0
    957 	atf_check -s exit:0 -o match:'shmif1 pri=5000' rump.ifconfig lagg0
    958 	atf_check -s exit:0 -o match:'shmif2 pri=5000' rump.ifconfig lagg0
    959 
    960 	wait_state "STANDBY" lagg0 shmif0
    961 	wait_for_distributing lagg0 shmif1
    962 	wait_for_distributing lagg0 shmif2
    963 }
    964 
    965 lagg_lacp_portpri_cleanup()
    966 {
    967 
    968 	$DEBUG && dump
    969 	cleanup
    970 }
    971 
    972 lagg_failover()
    973 {
    974 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    975 
    976 	local af=$1
    977 	local l2proto=$2
    978 	local ping="rump.ping -c 1"
    979 	local rumplib=""
    980 	local pfx=24
    981 	local addr_host0=$IP4ADDR0
    982 	local addr_host1=$IP4ADDR1
    983 
    984 	case $af in
    985 	"inet")
    986 		# do nothing
    987 		;;
    988 	"inet6")
    989 		ping="rump.ping6 -c 1"
    990 		rumplib="netinet6"
    991 		pfx=64
    992 		addr_host0=$IP6ADDR0
    993 		addr_host1=$IP6ADDR1
    994 		;;
    995 	esac
    996 
    997 	case $l2proto in
    998 	"ether")
    999 		iface0="shmif0"
   1000 		iface1="shmif1"
   1001 		iface2="shmif2"
   1002 		;;
   1003 	"l2tp")
   1004 		rumplib="$rumplib l2tp"
   1005 		iface0="l2tp0"
   1006 		iface1="l2tp1"
   1007 		iface2="l2tp2"
   1008 		;;
   1009 	esac
   1010 
   1011 	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
   1012 
   1013 	rump_server_start $SOCK_HOST0 lagg $rumplib
   1014 	rump_server_start $SOCK_HOST1 lagg $rumplib
   1015 
   1016 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
   1017 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
   1018 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
   1019 
   1020 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
   1021 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
   1022 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
   1023 
   1024 	if [ x"$l2proto" = x"l2tp" ]; then
   1025 		setup_l2tp_ipv4tunnel
   1026 	fi
   1027 
   1028 	export RUMP_SERVER=$SOCK_HOST0
   1029 	$atf_ifconfig lagg0 create
   1030 	$atf_ifconfig lagg0 laggproto failover
   1031 
   1032 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1033 	$atf_ifconfig lagg0 laggport $iface1 pri 2000
   1034 	$atf_ifconfig lagg0 laggport $iface2 pri 3000
   1035 	$atf_ifconfig lagg0 $af $addr_host0/$pfx
   1036 
   1037 	export RUMP_SERVER=$SOCK_HOST1
   1038 	$atf_ifconfig lagg0 create
   1039 	$atf_ifconfig lagg0 laggproto failover
   1040 
   1041 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1042 	$atf_ifconfig lagg0 laggport $iface1 pri 3000
   1043 	$atf_ifconfig lagg0 laggport $iface2 pri 2000
   1044 	$atf_ifconfig lagg0 $af $addr_host1/$pfx
   1045 
   1046 	export RUMP_SERVER=$SOCK_HOST0
   1047 	$atf_ifconfig $iface0 up
   1048 	$atf_ifconfig $iface1 up
   1049 	$atf_ifconfig $iface2 up
   1050 	$atf_ifconfig lagg0 up
   1051 
   1052 	export RUMP_SERVER=$SOCK_HOST1
   1053 	$atf_ifconfig $iface0 up
   1054 	$atf_ifconfig $iface1 up
   1055 	$atf_ifconfig $iface2 up
   1056 	$atf_ifconfig lagg0 up
   1057 
   1058 	export RUMP_SERVER=$SOCK_HOST0
   1059 	$atf_ifconfig -w 10
   1060 	wait_for_distributing lagg0 $iface0
   1061 	wait_state "COLLECTING" lagg0 $iface0
   1062 	wait_state "COLLECTING" lagg0 $iface1
   1063 	wait_state "COLLECTING" lagg0 $iface2
   1064 
   1065 	export RUMP_SERVER=$SOCK_HOST1
   1066 	$atf_ifconfig -w 10
   1067 	wait_for_distributing lagg0 $iface0
   1068 	wait_state "COLLECTING" lagg0 $iface0
   1069 	wait_state "COLLECTING" lagg0 $iface1
   1070 	wait_state "COLLECTING" lagg0 $iface2
   1071 
   1072 	export RUMP_SERVER=$SOCK_HOST0
   1073 	$atf_ping $addr_host1
   1074 
   1075 	$atf_ifconfig $iface0 down
   1076 	wait_for_distributing lagg0 $iface1
   1077 	wait_state "COLLECTING" lagg0 $iface1
   1078 	wait_state "COLLECTING" lagg0 $iface2
   1079 
   1080 	export RUMP_SERVER=$SOCK_HOST1
   1081 	$atf_ifconfig $iface0 down
   1082 	wait_for_distributing lagg0 $iface2
   1083 	wait_state "COLLECTING" lagg0 $iface2
   1084 	wait_state "COLLECTING" lagg0 $iface1
   1085 
   1086 	export RUMP_SERVER=$SOCK_HOST0
   1087 	$atf_ping $addr_host1
   1088 
   1089 	$atf_ifconfig lagg0 laggfailover -rx-all
   1090 	atf_check -s exit:0 -o not-match:'$iface2.+COLLECTING' rump.ifconfig lagg0
   1091 
   1092 	export RUMP_SERVER=$SOCK_HOST1
   1093 	$atf_ifconfig lagg0 laggfailover -rx-all
   1094 	atf_check -s exit:0 -o not-match:'$iface1.+COLLECTING' rump.ifconfig lagg0
   1095 
   1096 	export RUMP_SERVER=$SOCK_HOST0
   1097 	atf_check -s not-exit:0 -o ignore -e ignore $ping -c 1 $addr_host1
   1098 }
   1099 
   1100 atf_test_case lagg_failover_ipv4 cleanup
   1101 lagg_failover_ipv4_head()
   1102 {
   1103 
   1104 	atf_set "descr" "tests for failover using IPv4"
   1105 	atf_set "require.progs" "rump_server"
   1106 }
   1107 
   1108 lagg_failover_ipv4_body()
   1109 {
   1110 
   1111 	lagg_failover "inet" "ether"
   1112 }
   1113 
   1114 lagg_failover_ipv4_cleanup()
   1115 {
   1116 
   1117 	$DEBUG && dump
   1118 	cleanup
   1119 }
   1120 
   1121 atf_test_case lagg_failover_ipv6 cleanup
   1122 lagg_failover_ipv6_head()
   1123 {
   1124 
   1125 	atf_set "descr" "tests for failover using IPv6"
   1126 	atf_set "require.progs" "rump_server"
   1127 }
   1128 
   1129 lagg_failover_ipv6_body()
   1130 {
   1131 
   1132 	lagg_failover "inet6" "ether"
   1133 }
   1134 
   1135 lagg_failover_ipv6_cleanup()
   1136 {
   1137 
   1138 	$DEBUG && dump
   1139 	cleanup
   1140 }
   1141 
   1142 atf_test_case lagg_failover_l2tp_ipv4 cleanup
   1143 lagg_failover_l2tp_ipv4_head()
   1144 {
   1145 
   1146 	atf_set "descr" "tests for failover over l2tp using IPv4"
   1147 	atf_set "require.progs" "rump_server"
   1148 }
   1149 
   1150 lagg_failover_l2tp_ipv4_body()
   1151 {
   1152 
   1153 	lagg_failover "inet" "l2tp"
   1154 }
   1155 
   1156 lagg_failover_l2tp_ipv4_cleanup()
   1157 {
   1158 	$DEBUG && dump
   1159 	cleanup
   1160 }
   1161 
   1162 atf_test_case lagg_failover_l2tp_ipv6 cleanup
   1163 lagg_failover_l2tp_ipv6_head()
   1164 {
   1165 
   1166 	atf_set "descr" "tests for failover over l2tp using IPv6"
   1167 	atf_set "require.progs" "rump_server"
   1168 }
   1169 
   1170 lagg_failover_l2tp_ipv6_body()
   1171 {
   1172 
   1173 	lagg_failover "inet6" "l2tp"
   1174 }
   1175 
   1176 lagg_failover_l2tp_ipv6_cleanup()
   1177 {
   1178 	$DEBUG && dump
   1179 	cleanup
   1180 }
   1181 
   1182 lagg_loadbalance()
   1183 {
   1184 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
   1185 
   1186 	local af=$1
   1187 	local l2proto=$2
   1188 	local ping="rump.ping -c 1"
   1189 	local rumplib=""
   1190 	local pfx=24
   1191 	local addr_host0=$IP4ADDR0
   1192 	local addr_host1=$IP4ADDR1
   1193 
   1194 	case $af in
   1195 	"inet")
   1196 		# do nothing
   1197 		;;
   1198 	"inet6")
   1199 		ping="rump.ping6 -c 1"
   1200 		rumplib="netinet6"
   1201 		pfx=64
   1202 		addr_host0=$IP6ADDR0
   1203 		addr_host1=$IP6ADDR1
   1204 		;;
   1205 	esac
   1206 
   1207 	case $l2proto in
   1208 	"ether")
   1209 		iface0=shmif0
   1210 		iface1=shmif1
   1211 		iface2=shmif2
   1212 		;;
   1213 	"l2tp")
   1214 		rumplib="$rumplib l2tp"
   1215 		iface0=l2tp0
   1216 		iface1=l2tp1
   1217 		iface2=l2tp2
   1218 		;;
   1219 	esac
   1220 
   1221 	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
   1222 
   1223 	rump_server_start $SOCK_HOST0 lagg $rumplib
   1224 	rump_server_start $SOCK_HOST1 lagg $rumplib
   1225 
   1226 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
   1227 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
   1228 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
   1229 
   1230 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
   1231 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
   1232 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
   1233 
   1234 	if [ x"$l2proto" = x"l2tp" ]; then
   1235 		setup_l2tp_ipv4tunnel
   1236 	fi
   1237 
   1238 	export RUMP_SERVER=$SOCK_HOST0
   1239 	$atf_ifconfig lagg0 create
   1240 	$atf_ifconfig lagg0 laggproto loadbalance
   1241 
   1242 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1243 	$atf_ifconfig lagg0 laggport $iface1 pri 2000
   1244 	$atf_ifconfig lagg0 laggport $iface2 pri 3000
   1245 	$atf_ifconfig lagg0 $af $addr_host0/$pfx
   1246 
   1247 	export RUMP_SERVER=$SOCK_HOST1
   1248 	$atf_ifconfig lagg0 create
   1249 	$atf_ifconfig lagg0 laggproto loadbalance
   1250 
   1251 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1252 	$atf_ifconfig lagg0 laggport $iface1 pri 3000
   1253 	$atf_ifconfig lagg0 laggport $iface2 pri 2000
   1254 	$atf_ifconfig lagg0 $af $addr_host1/$pfx
   1255 
   1256 	export RUMP_SERVER=$SOCK_HOST0
   1257 	$atf_ifconfig $iface0 up
   1258 	$atf_ifconfig $iface1 up
   1259 	$atf_ifconfig $iface2 up
   1260 	$atf_ifconfig lagg0 up
   1261 
   1262 	export RUMP_SERVER=$SOCK_HOST1
   1263 	$atf_ifconfig $iface0 up
   1264 	$atf_ifconfig $iface1 up
   1265 	$atf_ifconfig $iface2 up
   1266 	$atf_ifconfig lagg0 up
   1267 
   1268 	export RUMP_SERVER=$SOCK_HOST0
   1269 	$atf_ifconfig -w 10
   1270 	wait_for_distributing lagg0 $iface0
   1271 	wait_state "COLLECTING" lagg0 $iface0
   1272 	wait_state "COLLECTING" lagg0 $iface1
   1273 	wait_state "COLLECTING" lagg0 $iface2
   1274 
   1275 	export RUMP_SERVER=$SOCK_HOST1
   1276 	$atf_ifconfig -w 10
   1277 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface0
   1278 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1279 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1280 
   1281 	export RUMP_SERVER=$SOCK_HOST0
   1282 	$atf_ping $addr_host1
   1283 
   1284 	$atf_ifconfig $iface0 down
   1285 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1286 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1287 
   1288 	export RUMP_SERVER=$SOCK_HOST1
   1289 	$atf_ifconfig $iface0 down
   1290 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1291 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1292 
   1293 	export RUMP_SERVER=$SOCK_HOST0
   1294 	$atf_ping $addr_host1
   1295 }
   1296 
   1297 atf_test_case lagg_loadbalance_ipv4 cleanup
   1298 lagg_loadbalance_ipv4_head()
   1299 {
   1300 
   1301 	atf_set "descr" "tests for loadbalance using IPv4"
   1302 	atf_set "require.progs" "rump_server"
   1303 }
   1304 
   1305 lagg_loadbalance_ipv4_body()
   1306 {
   1307 
   1308 	lagg_loadbalance "inet" "ether"
   1309 }
   1310 
   1311 lagg_loadbalance_ipv4_cleanup()
   1312 {
   1313 
   1314 	$DEBUG && dump
   1315 	cleanup
   1316 }
   1317 
   1318 atf_test_case lagg_loadbalance_ipv6 cleanup
   1319 lagg_loadbalance_ipv6_head()
   1320 {
   1321 
   1322 	atf_set "descr" "tests for loadbalance using IPv6"
   1323 	atf_set "require.progs" "rump_server"
   1324 }
   1325 
   1326 lagg_loadbalance_ipv6_body()
   1327 {
   1328 
   1329 	lagg_loadbalance "inet6" "ether"
   1330 }
   1331 
   1332 lagg_loadbalance_ipv6_cleanup()
   1333 {
   1334 
   1335 	$DEBUG && dump
   1336 	cleanup
   1337 }
   1338 
   1339 atf_test_case lagg_loadbalance_l2tp_ipv4 cleanup
   1340 lagg_loadbalance_l2tp_ipv4_head()
   1341 {
   1342 
   1343 	atf_set "descr" "tests for loadbalance over l2tp using IPv4"
   1344 	atf_set "require.progs" "rump_server"
   1345 }
   1346 
   1347 lagg_loadbalance_l2tp_ipv4_body()
   1348 {
   1349 
   1350 	lagg_loadbalance "inet" "l2tp"
   1351 }
   1352 
   1353 lagg_loadbalance_l2tp_ipv4_cleanup()
   1354 {
   1355 
   1356 	$DEBUG && dump
   1357 	cleanup
   1358 }
   1359 
   1360 atf_test_case lagg_loadbalance_l2tp_ipv6 cleanup
   1361 lagg_loadbalance_l2tp_ipv4_head()
   1362 {
   1363 
   1364 	atf_set "descr" "tests for loadbalance over l2tp using IPv6"
   1365 	atf_set "require.progs" "rump_server"
   1366 }
   1367 
   1368 lagg_loadbalance_l2tp_ipv6_body()
   1369 {
   1370 
   1371 	lagg_loadbalance "inet6" "l2tp"
   1372 }
   1373 
   1374 lagg_loadbalance_l2tp_ipv6_cleanup()
   1375 {
   1376 
   1377 	$DEBUG && dump
   1378 	cleanup
   1379 }
   1380 
   1381 atf_init_test_cases()
   1382 {
   1383 
   1384 	atf_add_test_case lagg_ifconfig
   1385 	atf_add_test_case lagg_macaddr
   1386 	atf_add_test_case lagg_ipv6lla
   1387 	atf_add_test_case lagg_lacp_basic
   1388 	atf_add_test_case lagg_lacp_ipv4
   1389 	atf_add_test_case lagg_lacp_ipv6
   1390 	atf_add_test_case lagg_lacp_l2tp_ipv4
   1391 	atf_add_test_case lagg_lacp_l2tp_ipv6
   1392 	atf_add_test_case lagg_lacp_vlan_ipv4
   1393 	atf_add_test_case lagg_lacp_vlan_ipv6
   1394 	atf_add_test_case lagg_lacp_vlanl2tp_ipv4
   1395 	atf_add_test_case lagg_lacp_vlanl2tp_ipv6
   1396 	atf_add_test_case lagg_lacp_portpri
   1397 	atf_add_test_case lagg_failover_ipv4
   1398 	atf_add_test_case lagg_failover_ipv6
   1399 	atf_add_test_case lagg_failover_l2tp_ipv4
   1400 	atf_add_test_case lagg_failover_l2tp_ipv6
   1401 	atf_add_test_case lagg_loadbalance_ipv4
   1402 	atf_add_test_case lagg_loadbalance_ipv6
   1403 	atf_add_test_case lagg_loadbalance_l2tp_ipv4
   1404 	atf_add_test_case lagg_loadbalance_l2tp_ipv6
   1405 }
   1406