Home | History | Annotate | Line # | Download | only in if_lagg
t_lagg.sh revision 1.7
      1 #	$NetBSD: t_lagg.sh,v 1.7 2022/03/31 03:09:03 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 	for sock in $SOCK_HOST0 $SOCK_HOST1; do
    740 		export RUMP_SERVER=$sock
    741 		$atf_ifconfig lagg0 create
    742 		$atf_ifconfig lagg0 laggproto lacp laggport $iface0
    743 
    744 		$atf_ifconfig vlan0 create
    745 		$atf_ifconfig vlan0 vlan 10 vlanif lagg0
    746 		$atf_ifconfig vlan1 create
    747 		$atf_ifconfig vlan1 vlan 11 vlanif lagg0
    748 
    749 		$atf_ifconfig $iface0 up
    750 		$atf_ifconfig lagg0 up
    751 	done
    752 
    753 	export RUMP_SERVER=$SOCK_HOST0
    754 	wait_for_distributing lagg0
    755 	$atf_ifconfig vlan0 $af $host0addr0/$pfx
    756 	$atf_ifconfig vlan0 up
    757 	$atf_ifconfig vlan1 $af $host0addr1/$pfx
    758 	$atf_ifconfig vlan1 up
    759 
    760 	export RUMP_SERVER=$SOCK_HOST1
    761 	wait_for_distributing lagg0
    762 	$atf_ifconfig vlan0 $af $host1addr0/$pfx
    763 	$atf_ifconfig vlan0 up
    764 	$atf_ifconfig vlan1 $af $host1addr1/$pfx
    765 	$atf_ifconfig vlan1 up
    766 
    767 	export RUMP_SERVER=$SOCK_HOST0
    768 	$atf_ifconfig -w 10
    769 	export RUMP_SERVER=$SOCK_HOST1
    770 	$atf_ifconfig -w 10
    771 
    772 	export RUMP_SERVER=$SOCK_HOST0
    773 	$atf_ping $host1addr0
    774 	$atf_ping $host1addr1
    775 
    776 	$atf_ifconfig lagg0 laggport $iface1
    777 	$atf_ifconfig $iface1 up
    778 
    779 	export RUMP_SERVER=$SOCK_HOST1
    780 	$atf_ifconfig lagg0 laggport $iface1
    781 	$atf_ifconfig $iface1 up
    782 
    783 	export RUMP_SERVER=$SOCK_HOST0
    784 	wait_for_distributing lagg0 $iface1
    785 
    786 	export RUMP_SERVER=$SOCK_HOST1
    787 	wait_for_distributing lagg0 $iface1
    788 
    789 	$atf_ping $host0addr0
    790 	$atf_ping $host0addr1
    791 }
    792 
    793 atf_test_case lagg_lacp_vlan_ipv4 cleanup
    794 lagg_lacp_vlan_ipv4_head()
    795 {
    796 
    797 	atf_set "descr" "tests for IPv4 VLAN frames over LACP LAG"
    798 	atf_set "require.progs" "rump_server"
    799 }
    800 
    801 lagg_lacp_vlan_ipv4_body()
    802 {
    803 
    804 	lagg_lacp_vlan "inet" "ether"
    805 }
    806 
    807 lagg_lacp_vlan_ipv4_cleanup()
    808 {
    809 	$DEBUG && dump
    810 	cleanup
    811 }
    812 
    813 atf_test_case lagg_lacp_vlan_ipv6 cleanup
    814 lagg_lacp_vlan_ipv6_head()
    815 {
    816 
    817 	atf_set "descr" "tests for IPv6 VLAN frames over LACP LAG"
    818 	atf_set "require.progs" "rump_server"
    819 }
    820 
    821 lagg_lacp_vlan_ipv6_body()
    822 {
    823 
    824 	lagg_lacp_vlan "inet6" "ether"
    825 }
    826 
    827 lagg_lacp_vlan_ipv6_cleanup()
    828 {
    829 	$DEBUG && dump
    830 	cleanup
    831 }
    832 
    833 atf_test_case lagg_lacp_vlanl2tp_ipv4 cleanup
    834 lagg_lacp_vlanl2tp_ipv4_head()
    835 {
    836 
    837 	atf_set "descr" "tests for IPv4 VLAN frames over LACP L2TP LAG"
    838 	atf_set "require.progs" "rump_server"
    839 }
    840 
    841 lagg_lacp_vlanl2tp_ipv4_body()
    842 {
    843 
    844 	lagg_lacp_vlan "inet" "l2tp"
    845 }
    846 
    847 lagg_lacp_vlanl2tp_ipv4_cleanup()
    848 {
    849 
    850 	$DEBUG && dump
    851 	cleanup
    852 }
    853 
    854 atf_test_case lagg_lacp_vlanl2tp_ipv6 cleanup
    855 lagg_lacp_vlanl2tp_ipv6_head()
    856 {
    857 
    858 	atf_set "descr" "tests for IPv6 VLAN frames over LACP L2TP LAG"
    859 	atf_set "require.progs" "rump_server"
    860 }
    861 
    862 lagg_lacp_vlanl2tp_ipv6_body()
    863 {
    864 
    865 	lagg_lacp_vlan "inet6" "l2tp"
    866 }
    867 
    868 lagg_lacp_vlanl2tp_ipv6_cleanup()
    869 {
    870 
    871 	$DEBUG && dump
    872 	cleanup
    873 }
    874 
    875 atf_test_case lagg_lacp_portpri cleanup
    876 lagg_lacp_portpri_head()
    877 {
    878 
    879 	atf_set "descr" "tests for LACP port priority"
    880 	atf_set "require.progs" "rump_server"
    881 }
    882 
    883 lagg_lacp_portpri_body()
    884 {
    885 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    886 
    887 	rump_server_start $SOCK_HOST0 lagg
    888 	rump_server_start $SOCK_HOST1 lagg
    889 
    890 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
    891 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
    892 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
    893 
    894 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
    895 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
    896 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
    897 
    898 	export RUMP_SERVER=$SOCK_HOST0
    899 	$atf_ifconfig lagg0 create
    900 	$atf_ifconfig lagg0 laggproto lacp
    901 	$atf_ifconfig lagg0 lagglacp maxports 2
    902 
    903 	$atf_ifconfig shmif0 up
    904 	$atf_ifconfig shmif1 up
    905 	$atf_ifconfig shmif2 up
    906 
    907 	$atf_ifconfig lagg0 laggport shmif0 pri 1000
    908 	$atf_ifconfig lagg0 laggport shmif1 pri 2000
    909 	$atf_ifconfig lagg0 laggport shmif2 pri 3000
    910 	$atf_ifconfig lagg0 up
    911 
    912 	atf_check -s exit:0 -o match:'shmif0 pri=1000' rump.ifconfig lagg0
    913 	atf_check -s exit:0 -o match:'shmif1 pri=2000' rump.ifconfig lagg0
    914 	atf_check -s exit:0 -o match:'shmif2 pri=3000' rump.ifconfig lagg0
    915 
    916 	export RUMP_SERVER=$SOCK_HOST1
    917 	$atf_ifconfig lagg0 create
    918 	$atf_ifconfig lagg0 laggproto lacp
    919 
    920 	$atf_ifconfig shmif0 up
    921 	$atf_ifconfig shmif1 up
    922 	$atf_ifconfig shmif2 up
    923 
    924 	$atf_ifconfig lagg0 laggport shmif0 pri 300
    925 	$atf_ifconfig lagg0 laggport shmif1 pri 200
    926 	$atf_ifconfig lagg0 laggport shmif2 pri 100
    927 	$atf_ifconfig lagg0 up
    928 
    929 	atf_check -s exit:0 -o match:'shmif0 pri=300' rump.ifconfig lagg0
    930 	atf_check -s exit:0 -o match:'shmif1 pri=200' rump.ifconfig lagg0
    931 	atf_check -s exit:0 -o match:'shmif2 pri=100' rump.ifconfig lagg0
    932 
    933 	export RUMP_SERVER=$SOCK_HOST0
    934 	wait_for_distributing lagg0 shmif0
    935 	wait_for_distributing lagg0 shmif1
    936 	wait_state "STANDBY" lagg0 shmif2
    937 
    938 	$atf_ifconfig shmif0 down
    939 	wait_for_distributing lagg0 shmif2
    940 
    941 	$atf_ifconfig shmif0 up
    942 	wait_for_distributing lagg0 shmif0
    943 
    944 	$atf_ifconfig lagg0 laggportpri shmif0 5000
    945 	$atf_ifconfig lagg0 laggportpri shmif1 5000
    946 	$atf_ifconfig lagg0 laggportpri shmif2 5000
    947 
    948 	atf_check -s exit:0 -o match:'shmif0 pri=5000' rump.ifconfig lagg0
    949 	atf_check -s exit:0 -o match:'shmif1 pri=5000' rump.ifconfig lagg0
    950 	atf_check -s exit:0 -o match:'shmif2 pri=5000' rump.ifconfig lagg0
    951 
    952 	wait_state "STANDBY" lagg0 shmif0
    953 	wait_for_distributing lagg0 shmif1
    954 	wait_for_distributing lagg0 shmif2
    955 }
    956 
    957 lagg_lacp_portpri_cleanup()
    958 {
    959 
    960 	$DEBUG && dump
    961 	cleanup
    962 }
    963 
    964 lagg_failover()
    965 {
    966 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    967 
    968 	local af=$1
    969 	local l2proto=$2
    970 	local ping="rump.ping -c 1"
    971 	local rumplib=""
    972 	local pfx=24
    973 	local addr_host0=$IP4ADDR0
    974 	local addr_host1=$IP4ADDR1
    975 
    976 	case $af in
    977 	"inet")
    978 		# do nothing
    979 		;;
    980 	"inet6")
    981 		ping="rump.ping6 -c 1"
    982 		rumplib="netinet6"
    983 		pfx=64
    984 		addr_host0=$IP6ADDR0
    985 		addr_host1=$IP6ADDR1
    986 		;;
    987 	esac
    988 
    989 	case $l2proto in
    990 	"ether")
    991 		iface0="shmif0"
    992 		iface1="shmif1"
    993 		iface2="shmif2"
    994 		;;
    995 	"l2tp")
    996 		rumplib="$rumplib l2tp"
    997 		iface0="l2tp0"
    998 		iface1="l2tp1"
    999 		iface2="l2tp2"
   1000 		;;
   1001 	esac
   1002 
   1003 	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
   1004 
   1005 	rump_server_start $SOCK_HOST0 lagg $rumplib
   1006 	rump_server_start $SOCK_HOST1 lagg $rumplib
   1007 
   1008 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
   1009 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
   1010 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
   1011 
   1012 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
   1013 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
   1014 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
   1015 
   1016 	if [ x"$l2proto" = x"l2tp" ]; then
   1017 		setup_l2tp_ipv4tunnel
   1018 	fi
   1019 
   1020 	export RUMP_SERVER=$SOCK_HOST0
   1021 	$atf_ifconfig lagg0 create
   1022 	$atf_ifconfig lagg0 laggproto failover
   1023 
   1024 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1025 	$atf_ifconfig lagg0 laggport $iface1 pri 2000
   1026 	$atf_ifconfig lagg0 laggport $iface2 pri 3000
   1027 	$atf_ifconfig lagg0 $af $addr_host0/$pfx
   1028 
   1029 	export RUMP_SERVER=$SOCK_HOST1
   1030 	$atf_ifconfig lagg0 create
   1031 	$atf_ifconfig lagg0 laggproto failover
   1032 
   1033 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1034 	$atf_ifconfig lagg0 laggport $iface1 pri 3000
   1035 	$atf_ifconfig lagg0 laggport $iface2 pri 2000
   1036 	$atf_ifconfig lagg0 $af $addr_host1/$pfx
   1037 
   1038 	export RUMP_SERVER=$SOCK_HOST0
   1039 	$atf_ifconfig $iface0 up
   1040 	$atf_ifconfig $iface1 up
   1041 	$atf_ifconfig $iface2 up
   1042 	$atf_ifconfig lagg0 up
   1043 
   1044 	export RUMP_SERVER=$SOCK_HOST1
   1045 	$atf_ifconfig $iface0 up
   1046 	$atf_ifconfig $iface1 up
   1047 	$atf_ifconfig $iface2 up
   1048 	$atf_ifconfig lagg0 up
   1049 
   1050 	export RUMP_SERVER=$SOCK_HOST0
   1051 	$atf_ifconfig -w 10
   1052 	wait_for_distributing lagg0 $iface0
   1053 	wait_state "COLLECTING" lagg0 $iface0
   1054 	wait_state "COLLECTING" lagg0 $iface1
   1055 	wait_state "COLLECTING" lagg0 $iface2
   1056 
   1057 	export RUMP_SERVER=$SOCK_HOST1
   1058 	$atf_ifconfig -w 10
   1059 	wait_for_distributing lagg0 $iface0
   1060 	wait_state "COLLECTING" lagg0 $iface0
   1061 	wait_state "COLLECTING" lagg0 $iface1
   1062 	wait_state "COLLECTING" lagg0 $iface2
   1063 
   1064 	export RUMP_SERVER=$SOCK_HOST0
   1065 	$atf_ping $addr_host1
   1066 
   1067 	$atf_ifconfig $iface0 down
   1068 	wait_for_distributing lagg0 $iface1
   1069 	wait_state "COLLECTING" lagg0 $iface1
   1070 	wait_state "COLLECTING" lagg0 $iface2
   1071 
   1072 	export RUMP_SERVER=$SOCK_HOST1
   1073 	$atf_ifconfig $iface0 down
   1074 	wait_for_distributing lagg0 $iface2
   1075 	wait_state "COLLECTING" lagg0 $iface2
   1076 	wait_state "COLLECTING" lagg0 $iface1
   1077 
   1078 	export RUMP_SERVER=$SOCK_HOST0
   1079 	$atf_ping $addr_host1
   1080 
   1081 	$atf_ifconfig lagg0 laggfailover -rx-all
   1082 	atf_check -s exit:0 -o not-match:'$iface2.+COLLECTING' rump.ifconfig lagg0
   1083 
   1084 	export RUMP_SERVER=$SOCK_HOST1
   1085 	$atf_ifconfig lagg0 laggfailover -rx-all
   1086 	atf_check -s exit:0 -o not-match:'$iface1.+COLLECTING' rump.ifconfig lagg0
   1087 
   1088 	export RUMP_SERVER=$SOCK_HOST0
   1089 	atf_check -s not-exit:0 -o ignore -e ignore $ping -c 1 $addr_host1
   1090 }
   1091 
   1092 atf_test_case lagg_failover_ipv4 cleanup
   1093 lagg_failover_ipv4_head()
   1094 {
   1095 
   1096 	atf_set "descr" "tests for failover using IPv4"
   1097 	atf_set "require.progs" "rump_server"
   1098 }
   1099 
   1100 lagg_failover_ipv4_body()
   1101 {
   1102 
   1103 	lagg_failover "inet" "ether"
   1104 }
   1105 
   1106 lagg_failover_ipv4_cleanup()
   1107 {
   1108 
   1109 	$DEBUG && dump
   1110 	cleanup
   1111 }
   1112 
   1113 atf_test_case lagg_failover_ipv6 cleanup
   1114 lagg_failover_ipv6_head()
   1115 {
   1116 
   1117 	atf_set "descr" "tests for failover using IPv6"
   1118 	atf_set "require.progs" "rump_server"
   1119 }
   1120 
   1121 lagg_failover_ipv6_body()
   1122 {
   1123 
   1124 	lagg_failover "inet6" "ether"
   1125 }
   1126 
   1127 lagg_failover_ipv6_cleanup()
   1128 {
   1129 
   1130 	$DEBUG && dump
   1131 	cleanup
   1132 }
   1133 
   1134 atf_test_case lagg_failover_l2tp_ipv4 cleanup
   1135 lagg_failover_l2tp_ipv4_head()
   1136 {
   1137 
   1138 	atf_set "descr" "tests for failover over l2tp using IPv4"
   1139 	atf_set "require.progs" "rump_server"
   1140 }
   1141 
   1142 lagg_failover_l2tp_ipv4_body()
   1143 {
   1144 
   1145 	lagg_failover "inet" "l2tp"
   1146 }
   1147 
   1148 lagg_failover_l2tp_ipv4_cleanup()
   1149 {
   1150 	$DEBUG && dump
   1151 	cleanup
   1152 }
   1153 
   1154 atf_test_case lagg_failover_l2tp_ipv6 cleanup
   1155 lagg_failover_l2tp_ipv6_head()
   1156 {
   1157 
   1158 	atf_set "descr" "tests for failover over l2tp using IPv6"
   1159 	atf_set "require.progs" "rump_server"
   1160 }
   1161 
   1162 lagg_failover_l2tp_ipv6_body()
   1163 {
   1164 
   1165 	lagg_failover "inet6" "l2tp"
   1166 }
   1167 
   1168 lagg_failover_l2tp_ipv6_cleanup()
   1169 {
   1170 	$DEBUG && dump
   1171 	cleanup
   1172 }
   1173 
   1174 lagg_loadbalance()
   1175 {
   1176 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
   1177 
   1178 	local af=$1
   1179 	local l2proto=$2
   1180 	local ping="rump.ping -c 1"
   1181 	local rumplib=""
   1182 	local pfx=24
   1183 	local addr_host0=$IP4ADDR0
   1184 	local addr_host1=$IP4ADDR1
   1185 
   1186 	case $af in
   1187 	"inet")
   1188 		# do nothing
   1189 		;;
   1190 	"inet6")
   1191 		ping="rump.ping6 -c 1"
   1192 		rumplib="netinet6"
   1193 		pfx=64
   1194 		addr_host0=$IP6ADDR0
   1195 		addr_host1=$IP6ADDR1
   1196 		;;
   1197 	esac
   1198 
   1199 	case $l2proto in
   1200 	"ether")
   1201 		iface0=shmif0
   1202 		iface1=shmif1
   1203 		iface2=shmif2
   1204 		;;
   1205 	"l2tp")
   1206 		rumplib="$rumplib l2tp"
   1207 		iface0=l2tp0
   1208 		iface1=l2tp1
   1209 		iface2=l2tp2
   1210 		;;
   1211 	esac
   1212 
   1213 	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
   1214 
   1215 	rump_server_start $SOCK_HOST0 lagg $rumplib
   1216 	rump_server_start $SOCK_HOST1 lagg $rumplib
   1217 
   1218 	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
   1219 	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
   1220 	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
   1221 
   1222 	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
   1223 	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
   1224 	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
   1225 
   1226 	if [ x"$l2proto" = x"l2tp" ]; then
   1227 		setup_l2tp_ipv4tunnel
   1228 	fi
   1229 
   1230 	export RUMP_SERVER=$SOCK_HOST0
   1231 	$atf_ifconfig lagg0 create
   1232 	$atf_ifconfig lagg0 laggproto loadbalance
   1233 
   1234 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1235 	$atf_ifconfig lagg0 laggport $iface1 pri 2000
   1236 	$atf_ifconfig lagg0 laggport $iface2 pri 3000
   1237 	$atf_ifconfig lagg0 $af $addr_host0/$pfx
   1238 
   1239 	export RUMP_SERVER=$SOCK_HOST1
   1240 	$atf_ifconfig lagg0 create
   1241 	$atf_ifconfig lagg0 laggproto loadbalance
   1242 
   1243 	$atf_ifconfig lagg0 laggport $iface0 pri 1000
   1244 	$atf_ifconfig lagg0 laggport $iface1 pri 3000
   1245 	$atf_ifconfig lagg0 laggport $iface2 pri 2000
   1246 	$atf_ifconfig lagg0 $af $addr_host1/$pfx
   1247 
   1248 	export RUMP_SERVER=$SOCK_HOST0
   1249 	$atf_ifconfig $iface0 up
   1250 	$atf_ifconfig $iface1 up
   1251 	$atf_ifconfig $iface2 up
   1252 	$atf_ifconfig lagg0 up
   1253 
   1254 	export RUMP_SERVER=$SOCK_HOST1
   1255 	$atf_ifconfig $iface0 up
   1256 	$atf_ifconfig $iface1 up
   1257 	$atf_ifconfig $iface2 up
   1258 	$atf_ifconfig lagg0 up
   1259 
   1260 	export RUMP_SERVER=$SOCK_HOST0
   1261 	$atf_ifconfig -w 10
   1262 	wait_for_distributing lagg0 $iface0
   1263 	wait_state "COLLECTING" lagg0 $iface0
   1264 	wait_state "COLLECTING" lagg0 $iface1
   1265 	wait_state "COLLECTING" lagg0 $iface2
   1266 
   1267 	export RUMP_SERVER=$SOCK_HOST1
   1268 	$atf_ifconfig -w 10
   1269 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface0
   1270 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1271 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1272 
   1273 	export RUMP_SERVER=$SOCK_HOST0
   1274 	$atf_ping $addr_host1
   1275 
   1276 	$atf_ifconfig $iface0 down
   1277 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1278 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1279 
   1280 	export RUMP_SERVER=$SOCK_HOST1
   1281 	$atf_ifconfig $iface0 down
   1282 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
   1283 	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
   1284 
   1285 	export RUMP_SERVER=$SOCK_HOST0
   1286 	$atf_ping $addr_host1
   1287 }
   1288 
   1289 atf_test_case lagg_loadbalance_ipv4 cleanup
   1290 lagg_loadbalance_ipv4_head()
   1291 {
   1292 
   1293 	atf_set "descr" "tests for loadbalance using IPv4"
   1294 	atf_set "require.progs" "rump_server"
   1295 }
   1296 
   1297 lagg_loadbalance_ipv4_body()
   1298 {
   1299 
   1300 	lagg_loadbalance "inet" "ether"
   1301 }
   1302 
   1303 lagg_loadbalance_ipv4_cleanup()
   1304 {
   1305 
   1306 	$DEBUG && dump
   1307 	cleanup
   1308 }
   1309 
   1310 atf_test_case lagg_loadbalance_ipv6 cleanup
   1311 lagg_loadbalance_ipv6_head()
   1312 {
   1313 
   1314 	atf_set "descr" "tests for loadbalance using IPv6"
   1315 	atf_set "require.progs" "rump_server"
   1316 }
   1317 
   1318 lagg_loadbalance_ipv6_body()
   1319 {
   1320 
   1321 	lagg_loadbalance "inet6" "ether"
   1322 }
   1323 
   1324 lagg_loadbalance_ipv6_cleanup()
   1325 {
   1326 
   1327 	$DEBUG && dump
   1328 	cleanup
   1329 }
   1330 
   1331 atf_test_case lagg_loadbalance_l2tp_ipv4 cleanup
   1332 lagg_loadbalance_l2tp_ipv4_head()
   1333 {
   1334 
   1335 	atf_set "descr" "tests for loadbalance over l2tp using IPv4"
   1336 	atf_set "require.progs" "rump_server"
   1337 }
   1338 
   1339 lagg_loadbalance_l2tp_ipv4_body()
   1340 {
   1341 
   1342 	lagg_loadbalance "inet" "l2tp"
   1343 }
   1344 
   1345 lagg_loadbalance_l2tp_ipv4_cleanup()
   1346 {
   1347 
   1348 	$DEBUG && dump
   1349 	cleanup
   1350 }
   1351 
   1352 atf_test_case lagg_loadbalance_l2tp_ipv6 cleanup
   1353 lagg_loadbalance_l2tp_ipv4_head()
   1354 {
   1355 
   1356 	atf_set "descr" "tests for loadbalance over l2tp using IPv6"
   1357 	atf_set "require.progs" "rump_server"
   1358 }
   1359 
   1360 lagg_loadbalance_l2tp_ipv6_body()
   1361 {
   1362 
   1363 	lagg_loadbalance "inet6" "l2tp"
   1364 }
   1365 
   1366 lagg_loadbalance_l2tp_ipv6_cleanup()
   1367 {
   1368 
   1369 	$DEBUG && dump
   1370 	cleanup
   1371 }
   1372 
   1373 atf_init_test_cases()
   1374 {
   1375 
   1376 	atf_add_test_case lagg_ifconfig
   1377 	atf_add_test_case lagg_macaddr
   1378 	atf_add_test_case lagg_ipv6lla
   1379 	atf_add_test_case lagg_lacp_basic
   1380 	atf_add_test_case lagg_lacp_ipv4
   1381 	atf_add_test_case lagg_lacp_ipv6
   1382 	atf_add_test_case lagg_lacp_l2tp_ipv4
   1383 	atf_add_test_case lagg_lacp_l2tp_ipv6
   1384 	atf_add_test_case lagg_lacp_vlan_ipv4
   1385 	atf_add_test_case lagg_lacp_vlan_ipv6
   1386 	atf_add_test_case lagg_lacp_vlanl2tp_ipv4
   1387 	atf_add_test_case lagg_lacp_vlanl2tp_ipv6
   1388 	atf_add_test_case lagg_lacp_portpri
   1389 	atf_add_test_case lagg_failover_ipv4
   1390 	atf_add_test_case lagg_failover_ipv6
   1391 	atf_add_test_case lagg_failover_l2tp_ipv4
   1392 	atf_add_test_case lagg_failover_l2tp_ipv6
   1393 	atf_add_test_case lagg_loadbalance_ipv4
   1394 	atf_add_test_case lagg_loadbalance_ipv6
   1395 	atf_add_test_case lagg_loadbalance_l2tp_ipv4
   1396 	atf_add_test_case lagg_loadbalance_l2tp_ipv6
   1397 }
   1398