xref: /netbsd/tests/net/if_lagg/t_lagg.sh (revision 870bb1d2)
1#	$NetBSD: t_lagg.sh,v 1.8 2022/03/31 03:26:33 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
28SOCK_HOST0=unix://commsock0
29SOCK_HOST1=unix://commsock1
30SOCK_HOST2=unix://commsock2
31BUS0=bus0
32BUS1=bus1
33BUS2=bus2
34IP4ADDR0=192.168.0.1
35IP4ADDR1=192.168.0.2
36IP4ADDR2=192.168.1.1
37IP4ADDR3=192.168.1.2
38IP6ADDR0=fc00::1
39IP6ADDR1=fc00::2
40IP6ADDR2=fc00:1::1
41IP6ADDR3=fc00:1::2
42WAITTIME=20
43
44DEBUG=${DEBUG:-false}
45
46wait_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}
72wait_for_distributing()
73{
74
75	wait_state "DISTRIBUTING" $*
76}
77
78expected_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
88setup_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
141atf_test_case lagg_ifconfig cleanup
142lagg_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
149lagg_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
215lagg_ifconfig_cleanup()
216{
217	$DEBG && dump
218	cleanup
219}
220
221atf_test_case lagg_macaddr cleanup
222lagg_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
228lagg_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
310lagg_macaddr_cleanup()
311{
312	$DEBUG && dump
313	cleanup
314}
315
316atf_test_case lagg_ipv6lla cleanup
317lagg_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
323lagg_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
354lagg_ipv6lla_cleanup()
355{
356	$DEBUG && dump
357	cleanup
358}
359
360atf_test_case lagg_mtu cleanup
361lagg_mtu_head()
362{
363	atf_set "descr" "tests for MTU"
364	atf_set "require.progs" "rump_server"
365}
366
367lagg_mtu_body()
368{
369	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
370	local mtu_1st=1450
371	local mtu_big=1460
372	local mtu_small=1440
373
374	rump_server_start $SOCK_HOST0 lagg
375
376	export RUMP_SERVER=$SOCK_HOST0
377	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
378	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
379	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
380	$atf_ifconfig lagg0 create
381	$atf_ifconfig lagg0 laggproto lacp
382
383	$atf_ifconfig shmif0 mtu $mtu_1st
384	$atf_ifconfig shmif1 mtu $mtu_big
385	$atf_ifconfig shmif2 mtu $mtu_small
386
387	atf_check -s exit:0 -o match:"mtu *1500" rump.ifconfig lagg0
388	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
389	atf_check -s exit:0 -o match:"mtu *$mtu_big" rump.ifconfig shmif1
390	atf_check -s exit:0 -o match:"mtu *$mtu_small" rump.ifconfig shmif2
391
392	# copy MTU from 1st port
393	$atf_ifconfig lagg0 laggport shmif0
394	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig lagg0
395	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
396
397	# copy MTU to added port
398	$atf_ifconfig lagg0 laggport shmif1
399	$atf_ifconfig lagg0 laggport shmif2
400	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig lagg0
401	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
402	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif1
403	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif2
404
405	# reset MTU after detaching from lagg0
406	$atf_ifconfig lagg0 -laggport shmif2
407	atf_check -s exit:0 -o match:"mtu *$mtu_small" rump.ifconfig shmif2
408
409	# change MTU of lagg0
410	$atf_ifconfig lagg0 mtu 1500
411	atf_check -s exit:0 -o match:"mtu *1500" rump.ifconfig lagg0
412	atf_check -s exit:0 -o match:"mtu *1500" rump.ifconfig shmif0
413	atf_check -s exit:0 -o match:"mtu *1500" rump.ifconfig shmif1
414
415	# reset MTU after detching from lagg0
416	$atf_ifconfig lagg0 -laggport shmif0
417	$atf_ifconfig lagg0 -laggport shmif1
418	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
419	atf_check -s exit:0 -o match:"mtu *$mtu_big" rump.ifconfig shmif1
420
421	# MTU should not be changed
422	atf_check -s exit:0 -o match:"mtu *1500" rump.ifconfig lagg0
423
424	# copy MTU from 1st port even when MTU of lagg0 is changhed
425	$atf_ifconfig lagg0 mtu 1400
426	atf_check -s exit:0 -o match:"mtu *1400" rump.ifconfig lagg0
427	$atf_ifconfig lagg0 laggport shmif0
428	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig lagg0
429	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
430
431	# MTU of lagg0 need not reset
432	$atf_ifconfig lagg0 -laggport shmif0
433	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig lagg0
434	atf_check -s exit:0 -o match:"mtu *$mtu_1st" rump.ifconfig shmif0
435}
436
437lagg_mtu_cleanup()
438{
439
440	$DEBUG && dump
441	cleanup
442}
443
444atf_test_case lagg_lacp_basic cleanup
445lagg_lacp_basic_head()
446{
447
448	atf_set "descr" "tests for LACP basic functions"
449	atf_set "require.progs" "rump_server"
450}
451
452lagg_lacp_basic_body()
453{
454	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
455
456	rump_server_start $SOCK_HOST0 lagg
457	rump_server_start $SOCK_HOST1 lagg
458	rump_server_start $SOCK_HOST2 lagg
459
460	export RUMP_SERVER=$SOCK_HOST0
461
462	# added running interface
463	$atf_ifconfig shmif0 create
464	$atf_ifconfig shmif0 linkstr $BUS0
465
466	$atf_ifconfig shmif1 create
467	$atf_ifconfig shmif1 linkstr $BUS1
468
469	$atf_ifconfig lagg0 create
470	$atf_ifconfig lagg0 laggproto lacp
471
472	$atf_ifconfig shmif0 up
473	$atf_ifconfig shmif1 up
474	$atf_ifconfig lagg0 up
475
476	$atf_ifconfig lagg0 laggport shmif0
477	$atf_ifconfig lagg0 laggport shmif1
478	$atf_ifconfig -w 10
479
480	$atf_ifconfig lagg0 -laggport shmif0
481	$atf_ifconfig lagg0 -laggport shmif1
482	$atf_ifconfig lagg0 down
483
484	# add the same interfaces again
485	$atf_ifconfig lagg0 up
486	$atf_ifconfig lagg0 laggport shmif0
487	$atf_ifconfig lagg0 laggport shmif1
488
489	# detach and re-attach protocol
490	$atf_ifconfig lagg0 laggproto none
491	$atf_ifconfig lagg0 laggproto lacp \
492	    laggport shmif0 laggport shmif1
493
494	$atf_ifconfig lagg0 -laggport shmif0 -laggport shmif1
495	$atf_ifconfig lagg0 destroy
496	$atf_ifconfig shmif0 destroy
497	$atf_ifconfig shmif1 destroy
498
499	# tests for a loopback condition
500	$atf_ifconfig shmif0 create
501	$atf_ifconfig shmif0 linkstr $BUS0
502	$atf_ifconfig shmif1 create
503	$atf_ifconfig shmif1 linkstr $BUS0
504	$atf_ifconfig lagg0 create
505	$atf_ifconfig lagg0 laggproto lacp \
506	    laggport shmif0 laggport shmif1
507	$atf_ifconfig shmif0 up
508	$atf_ifconfig shmif1 up
509	$atf_ifconfig lagg0 up
510
511	expected_inactive lagg0
512
513	$atf_ifconfig shmif0 down
514	$atf_ifconfig shmif0 destroy
515	$atf_ifconfig shmif1 down
516	$atf_ifconfig shmif1 destroy
517	$atf_ifconfig lagg0 down
518	$atf_ifconfig lagg0 destroy
519
520	export RUMP_SERVER=$SOCK_HOST0
521	$atf_ifconfig shmif0 create
522	$atf_ifconfig shmif0 linkstr $BUS0
523	$atf_ifconfig shmif0 up
524
525	$atf_ifconfig shmif1 create
526	$atf_ifconfig shmif1 linkstr $BUS1
527	$atf_ifconfig shmif1 up
528
529	$atf_ifconfig shmif2 create
530	$atf_ifconfig shmif2 linkstr $BUS2
531	$atf_ifconfig shmif2 up
532
533	$atf_ifconfig lagg0 create
534	$atf_ifconfig lagg0 laggproto lacp laggport shmif0 \
535	    laggport shmif1 laggport shmif2
536	$atf_ifconfig lagg0 up
537
538	export RUMP_SERVER=$SOCK_HOST1
539	$atf_ifconfig shmif0 create
540	$atf_ifconfig shmif0 linkstr $BUS0
541	$atf_ifconfig shmif0 up
542
543	$atf_ifconfig shmif1 create
544	$atf_ifconfig shmif1 linkstr $BUS1
545	$atf_ifconfig shmif1 up
546
547	$atf_ifconfig lagg0 create
548	$atf_ifconfig lagg0 laggproto lacp
549	$atf_ifconfig lagg1 create
550	$atf_ifconfig lagg1 laggproto lacp
551
552	$atf_ifconfig lagg0 laggport shmif0
553	$atf_ifconfig lagg0 up
554	wait_for_distributing lagg0 shmif0
555
556	$atf_ifconfig lagg1 laggport shmif1
557	$atf_ifconfig lagg1 up
558
559	export RUMP_SERVER=$SOCK_HOST2
560	$atf_ifconfig shmif0 create
561	$atf_ifconfig shmif0 linkstr $BUS2
562	$atf_ifconfig shmif0 up
563
564	$atf_ifconfig lagg0 create
565	$atf_ifconfig lagg0 laggproto lacp laggport shmif0
566	$atf_ifconfig lagg0 up
567
568	export RUMP_SERVER=$SOCK_HOST0
569	wait_for_distributing lagg0 shmif0
570	expected_inactive lagg0 shmif1
571	expected_inactive lagg0 shmif2
572}
573
574lagg_lacp_basic_cleanup()
575{
576
577	$DEBUG && dump
578	cleanup
579}
580
581lagg_lacp_ping()
582{
583	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
584
585	local af=$1
586	local l2proto=$2
587	local atf_ping="atf_check -s exit:0 -o ignore rump.ping -c 1"
588	local ping=rump.ping
589	local rumplib=""
590	local pfx=24
591	local addr_host0=$IP4ADDR0
592	local addr_host1=$IP4ADDR1
593
594	case $af in
595	"inet")
596		# do nothing
597		;;
598	"inet6")
599		atf_ping="atf_check -s exit:0 -o ignore rump.ping6 -c 1"
600		rumplib="netinet6"
601		pfx=64
602		addr_host0=$IP6ADDR0
603		addr_host1=$IP6ADDR1
604		;;
605	esac
606
607	case $l2proto in
608	"ether")
609		iface0=shmif0
610		iface1=shmif1
611		iface2=shmif2
612		;;
613	"l2tp")
614		rumplib="$rumplib l2tp"
615		iface0=l2tp0
616		iface1=l2tp1
617		iface2=l2tp2
618		;;
619	esac
620
621	rump_server_start $SOCK_HOST0 lagg $rumplib
622	rump_server_start $SOCK_HOST1 lagg $rumplib
623
624	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
625	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
626	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
627
628	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
629	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
630	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
631
632	if [ x"$l2proto" = x"l2tp" ];then
633		setup_l2tp_ipv4tunnel
634	fi
635
636	export RUMP_SERVER=$SOCK_HOST0
637	$atf_ifconfig lagg0 create
638	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
639	$atf_ifconfig lagg0 $af $addr_host0/$pfx
640	$atf_ifconfig $iface0 up
641	$atf_ifconfig lagg0 up
642
643	export RUMP_SERVER=$SOCK_HOST1
644	$atf_ifconfig lagg0 create
645	$atf_ifconfig lagg0 laggproto lacp laggport $iface0
646	$atf_ifconfig lagg0 $af $addr_host1/$pfx
647	$atf_ifconfig $iface0 up
648	$atf_ifconfig lagg0 up
649
650	export RUMP_SERVER=$SOCK_HOST0
651	wait_for_distributing lagg0
652	$atf_ifconfig -w 10
653
654	export RUMP_SERVER=$SOCK_HOST1
655	wait_for_distributing lagg0
656	$atf_ifconfig -w 10
657
658	$atf_ping $addr_host0
659
660	export RUMP_SERVER=$SOCK_HOST0
661	$atf_ifconfig $iface1 up
662	$atf_ifconfig lagg0 laggport $iface1 laggport $iface2
663	$atf_ifconfig $iface2 up
664
665	export RUMP_SERVER=$SOCK_HOST1
666	$atf_ifconfig $iface1 up
667	$atf_ifconfig lagg0 laggport $iface1 laggport $iface2
668	$atf_ifconfig $iface2 up
669
670	export RUMP_SERVER=$SOCK_HOST0
671	wait_for_distributing lagg0 $iface1
672	wait_for_distributing lagg0 $iface2
673
674	export RUMP_SERVER=$SOCK_HOST1
675	wait_for_distributing lagg0 $iface1
676	wait_for_distributing lagg0 $iface2
677
678	$atf_ping $addr_host0
679}
680
681atf_test_case lagg_lacp_ipv4 cleanup
682lagg_lacp_ipv4_head()
683{
684
685	atf_set "descr" "tests for IPv4 with LACP"
686	atf_set "require.progs" "rump_server"
687}
688
689lagg_lacp_ipv4_body()
690{
691
692	lagg_lacp_ping "inet" "ether"
693}
694
695lagg_lacp_ipv4_cleanup()
696{
697
698	$DEBUG && dump
699	cleanup
700}
701
702atf_test_case lagg_lacp_ipv6 cleanup
703lagg_lacp_ipv6_head()
704{
705
706	atf_set "descr" "tests for IPv6 with LACP"
707	atf_set "require.progs" "rump_server"
708}
709
710lagg_lacp_ipv6_body()
711{
712
713	lagg_lacp_ping "inet6" "ether"
714}
715
716lagg_lacp_ipv6_cleanup()
717{
718
719	$DEBUG && dump
720	cleanup
721}
722
723atf_test_case lagg_lacp_l2tp_ipv4 cleanup
724lagg_lacp_l2tp_ipv4_head()
725{
726
727	atf_set "descr" "tests for LACP over l2tp by using IPv4"
728	atf_set "require.progs" "rump_server"
729}
730
731lagg_lacp_l2tp_ipv4_body()
732{
733
734	lagg_lacp_ping "inet" "l2tp"
735}
736
737lagg_lacp_l2tp_ipv4_cleanup()
738{
739
740	$DEBUG && dump
741	cleanup
742}
743
744atf_test_case lagg_lacp_l2tp_ipv6 cleanup
745lagg_lacp_l2tp_ipv6_head()
746{
747
748	atf_set "descr" "tests for LACP over l2tp using IPv6"
749	atf_set "require.progs" "rump_server"
750}
751
752lagg_lacp_l2tp_ipv6_body()
753{
754
755	lagg_lacp_ping "inet6" "l2tp"
756}
757
758lagg_lacp_l2tp_ipv6_cleanup()
759{
760
761	$DEBUG && dump
762	cleanup
763}
764
765lagg_lacp_vlan()
766{
767	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
768
769	local af=$1
770	local l2proto=$2
771	local atf_ping="atf_check -s exit:0 -o ignore rump.ping -c 1"
772	local rumplib="vlan"
773	local pfx=24
774	local vlan0_addr_host0=$IP4ADDR0
775	local host0addr0=$IP4ADDR0
776	local host1addr0=$IP4ADDR1
777	local host0addr1=$IP4ADDR2
778	local host1addr1=$IP4ADDR3
779
780	case $af in
781	"inet")
782		# do nothing
783		;;
784	"inet6")
785		atf_ping="atf_check -s exit:0 -o ignore rump.ping6 -c 1"
786		rumplib="$rumplib netinet6"
787		pfx=64
788		host0addr0=$IP6ADDR0
789		host1addr0=$IP6ADDR1
790		host0addr1=$IP6ADDR2
791		host1addr1=$IP6ADDR3
792		;;
793	esac
794
795	case $l2proto in
796	"ether")
797		iface0=shmif0
798		iface1=shmif1
799		iface2=shmif2
800		;;
801	"l2tp")
802		rumplib="$rumplib l2tp"
803		iface0=l2tp0
804		iface1=l2tp1
805		iface2=l2tp2
806	esac
807
808	rump_server_start $SOCK_HOST0 lagg $rumplib
809	rump_server_start $SOCK_HOST1 lagg $rumplib
810
811	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
812	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
813	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
814
815	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
816	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
817	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
818
819	if [ x"$l2proto" = x"l2tp" ]; then
820		setup_l2tp_ipv4tunnel
821	fi
822
823	for sock in $SOCK_HOST0 $SOCK_HOST1; do
824		export RUMP_SERVER=$sock
825		$atf_ifconfig lagg0 create
826		$atf_ifconfig lagg0 laggproto lacp laggport $iface0
827
828		$atf_ifconfig vlan0 create
829		$atf_ifconfig vlan0 vlan 10 vlanif lagg0
830		$atf_ifconfig vlan1 create
831		$atf_ifconfig vlan1 vlan 11 vlanif lagg0
832
833		$atf_ifconfig $iface0 up
834		$atf_ifconfig lagg0 up
835	done
836
837	export RUMP_SERVER=$SOCK_HOST0
838	wait_for_distributing lagg0
839	$atf_ifconfig vlan0 $af $host0addr0/$pfx
840	$atf_ifconfig vlan0 up
841	$atf_ifconfig vlan1 $af $host0addr1/$pfx
842	$atf_ifconfig vlan1 up
843
844	export RUMP_SERVER=$SOCK_HOST1
845	wait_for_distributing lagg0
846	$atf_ifconfig vlan0 $af $host1addr0/$pfx
847	$atf_ifconfig vlan0 up
848	$atf_ifconfig vlan1 $af $host1addr1/$pfx
849	$atf_ifconfig vlan1 up
850
851	export RUMP_SERVER=$SOCK_HOST0
852	$atf_ifconfig -w 10
853	export RUMP_SERVER=$SOCK_HOST1
854	$atf_ifconfig -w 10
855
856	export RUMP_SERVER=$SOCK_HOST0
857	$atf_ping $host1addr0
858	$atf_ping $host1addr1
859
860	$atf_ifconfig lagg0 laggport $iface1
861	$atf_ifconfig $iface1 up
862
863	export RUMP_SERVER=$SOCK_HOST1
864	$atf_ifconfig lagg0 laggport $iface1
865	$atf_ifconfig $iface1 up
866
867	export RUMP_SERVER=$SOCK_HOST0
868	wait_for_distributing lagg0 $iface1
869
870	export RUMP_SERVER=$SOCK_HOST1
871	wait_for_distributing lagg0 $iface1
872
873	$atf_ping $host0addr0
874	$atf_ping $host0addr1
875}
876
877atf_test_case lagg_lacp_vlan_ipv4 cleanup
878lagg_lacp_vlan_ipv4_head()
879{
880
881	atf_set "descr" "tests for IPv4 VLAN frames over LACP LAG"
882	atf_set "require.progs" "rump_server"
883}
884
885lagg_lacp_vlan_ipv4_body()
886{
887
888	lagg_lacp_vlan "inet" "ether"
889}
890
891lagg_lacp_vlan_ipv4_cleanup()
892{
893	$DEBUG && dump
894	cleanup
895}
896
897atf_test_case lagg_lacp_vlan_ipv6 cleanup
898lagg_lacp_vlan_ipv6_head()
899{
900
901	atf_set "descr" "tests for IPv6 VLAN frames over LACP LAG"
902	atf_set "require.progs" "rump_server"
903}
904
905lagg_lacp_vlan_ipv6_body()
906{
907
908	lagg_lacp_vlan "inet6" "ether"
909}
910
911lagg_lacp_vlan_ipv6_cleanup()
912{
913	$DEBUG && dump
914	cleanup
915}
916
917atf_test_case lagg_lacp_vlanl2tp_ipv4 cleanup
918lagg_lacp_vlanl2tp_ipv4_head()
919{
920
921	atf_set "descr" "tests for IPv4 VLAN frames over LACP L2TP LAG"
922	atf_set "require.progs" "rump_server"
923}
924
925lagg_lacp_vlanl2tp_ipv4_body()
926{
927
928	lagg_lacp_vlan "inet" "l2tp"
929}
930
931lagg_lacp_vlanl2tp_ipv4_cleanup()
932{
933
934	$DEBUG && dump
935	cleanup
936}
937
938atf_test_case lagg_lacp_vlanl2tp_ipv6 cleanup
939lagg_lacp_vlanl2tp_ipv6_head()
940{
941
942	atf_set "descr" "tests for IPv6 VLAN frames over LACP L2TP LAG"
943	atf_set "require.progs" "rump_server"
944}
945
946lagg_lacp_vlanl2tp_ipv6_body()
947{
948
949	lagg_lacp_vlan "inet6" "l2tp"
950}
951
952lagg_lacp_vlanl2tp_ipv6_cleanup()
953{
954
955	$DEBUG && dump
956	cleanup
957}
958
959atf_test_case lagg_lacp_portpri cleanup
960lagg_lacp_portpri_head()
961{
962
963	atf_set "descr" "tests for LACP port priority"
964	atf_set "require.progs" "rump_server"
965}
966
967lagg_lacp_portpri_body()
968{
969	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
970
971	rump_server_start $SOCK_HOST0 lagg
972	rump_server_start $SOCK_HOST1 lagg
973
974	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
975	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
976	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
977
978	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
979	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
980	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
981
982	export RUMP_SERVER=$SOCK_HOST0
983	$atf_ifconfig lagg0 create
984	$atf_ifconfig lagg0 laggproto lacp
985	$atf_ifconfig lagg0 lagglacp maxports 2
986
987	$atf_ifconfig shmif0 up
988	$atf_ifconfig shmif1 up
989	$atf_ifconfig shmif2 up
990
991	$atf_ifconfig lagg0 laggport shmif0 pri 1000
992	$atf_ifconfig lagg0 laggport shmif1 pri 2000
993	$atf_ifconfig lagg0 laggport shmif2 pri 3000
994	$atf_ifconfig lagg0 up
995
996	atf_check -s exit:0 -o match:'shmif0 pri=1000' rump.ifconfig lagg0
997	atf_check -s exit:0 -o match:'shmif1 pri=2000' rump.ifconfig lagg0
998	atf_check -s exit:0 -o match:'shmif2 pri=3000' rump.ifconfig lagg0
999
1000	export RUMP_SERVER=$SOCK_HOST1
1001	$atf_ifconfig lagg0 create
1002	$atf_ifconfig lagg0 laggproto lacp
1003
1004	$atf_ifconfig shmif0 up
1005	$atf_ifconfig shmif1 up
1006	$atf_ifconfig shmif2 up
1007
1008	$atf_ifconfig lagg0 laggport shmif0 pri 300
1009	$atf_ifconfig lagg0 laggport shmif1 pri 200
1010	$atf_ifconfig lagg0 laggport shmif2 pri 100
1011	$atf_ifconfig lagg0 up
1012
1013	atf_check -s exit:0 -o match:'shmif0 pri=300' rump.ifconfig lagg0
1014	atf_check -s exit:0 -o match:'shmif1 pri=200' rump.ifconfig lagg0
1015	atf_check -s exit:0 -o match:'shmif2 pri=100' rump.ifconfig lagg0
1016
1017	export RUMP_SERVER=$SOCK_HOST0
1018	wait_for_distributing lagg0 shmif0
1019	wait_for_distributing lagg0 shmif1
1020	wait_state "STANDBY" lagg0 shmif2
1021
1022	$atf_ifconfig shmif0 down
1023	wait_for_distributing lagg0 shmif2
1024
1025	$atf_ifconfig shmif0 up
1026	wait_for_distributing lagg0 shmif0
1027
1028	$atf_ifconfig lagg0 laggportpri shmif0 5000
1029	$atf_ifconfig lagg0 laggportpri shmif1 5000
1030	$atf_ifconfig lagg0 laggportpri shmif2 5000
1031
1032	atf_check -s exit:0 -o match:'shmif0 pri=5000' rump.ifconfig lagg0
1033	atf_check -s exit:0 -o match:'shmif1 pri=5000' rump.ifconfig lagg0
1034	atf_check -s exit:0 -o match:'shmif2 pri=5000' rump.ifconfig lagg0
1035
1036	wait_state "STANDBY" lagg0 shmif0
1037	wait_for_distributing lagg0 shmif1
1038	wait_for_distributing lagg0 shmif2
1039}
1040
1041lagg_lacp_portpri_cleanup()
1042{
1043
1044	$DEBUG && dump
1045	cleanup
1046}
1047
1048lagg_failover()
1049{
1050	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
1051
1052	local af=$1
1053	local l2proto=$2
1054	local ping="rump.ping -c 1"
1055	local rumplib=""
1056	local pfx=24
1057	local addr_host0=$IP4ADDR0
1058	local addr_host1=$IP4ADDR1
1059
1060	case $af in
1061	"inet")
1062		# do nothing
1063		;;
1064	"inet6")
1065		ping="rump.ping6 -c 1"
1066		rumplib="netinet6"
1067		pfx=64
1068		addr_host0=$IP6ADDR0
1069		addr_host1=$IP6ADDR1
1070		;;
1071	esac
1072
1073	case $l2proto in
1074	"ether")
1075		iface0="shmif0"
1076		iface1="shmif1"
1077		iface2="shmif2"
1078		;;
1079	"l2tp")
1080		rumplib="$rumplib l2tp"
1081		iface0="l2tp0"
1082		iface1="l2tp1"
1083		iface2="l2tp2"
1084		;;
1085	esac
1086
1087	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
1088
1089	rump_server_start $SOCK_HOST0 lagg $rumplib
1090	rump_server_start $SOCK_HOST1 lagg $rumplib
1091
1092	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
1093	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
1094	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
1095
1096	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
1097	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
1098	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
1099
1100	if [ x"$l2proto" = x"l2tp" ]; then
1101		setup_l2tp_ipv4tunnel
1102	fi
1103
1104	export RUMP_SERVER=$SOCK_HOST0
1105	$atf_ifconfig lagg0 create
1106	$atf_ifconfig lagg0 laggproto failover
1107
1108	$atf_ifconfig lagg0 laggport $iface0 pri 1000
1109	$atf_ifconfig lagg0 laggport $iface1 pri 2000
1110	$atf_ifconfig lagg0 laggport $iface2 pri 3000
1111	$atf_ifconfig lagg0 $af $addr_host0/$pfx
1112
1113	export RUMP_SERVER=$SOCK_HOST1
1114	$atf_ifconfig lagg0 create
1115	$atf_ifconfig lagg0 laggproto failover
1116
1117	$atf_ifconfig lagg0 laggport $iface0 pri 1000
1118	$atf_ifconfig lagg0 laggport $iface1 pri 3000
1119	$atf_ifconfig lagg0 laggport $iface2 pri 2000
1120	$atf_ifconfig lagg0 $af $addr_host1/$pfx
1121
1122	export RUMP_SERVER=$SOCK_HOST0
1123	$atf_ifconfig $iface0 up
1124	$atf_ifconfig $iface1 up
1125	$atf_ifconfig $iface2 up
1126	$atf_ifconfig lagg0 up
1127
1128	export RUMP_SERVER=$SOCK_HOST1
1129	$atf_ifconfig $iface0 up
1130	$atf_ifconfig $iface1 up
1131	$atf_ifconfig $iface2 up
1132	$atf_ifconfig lagg0 up
1133
1134	export RUMP_SERVER=$SOCK_HOST0
1135	$atf_ifconfig -w 10
1136	wait_for_distributing lagg0 $iface0
1137	wait_state "COLLECTING" lagg0 $iface0
1138	wait_state "COLLECTING" lagg0 $iface1
1139	wait_state "COLLECTING" lagg0 $iface2
1140
1141	export RUMP_SERVER=$SOCK_HOST1
1142	$atf_ifconfig -w 10
1143	wait_for_distributing lagg0 $iface0
1144	wait_state "COLLECTING" lagg0 $iface0
1145	wait_state "COLLECTING" lagg0 $iface1
1146	wait_state "COLLECTING" lagg0 $iface2
1147
1148	export RUMP_SERVER=$SOCK_HOST0
1149	$atf_ping $addr_host1
1150
1151	$atf_ifconfig $iface0 down
1152	wait_for_distributing lagg0 $iface1
1153	wait_state "COLLECTING" lagg0 $iface1
1154	wait_state "COLLECTING" lagg0 $iface2
1155
1156	export RUMP_SERVER=$SOCK_HOST1
1157	$atf_ifconfig $iface0 down
1158	wait_for_distributing lagg0 $iface2
1159	wait_state "COLLECTING" lagg0 $iface2
1160	wait_state "COLLECTING" lagg0 $iface1
1161
1162	export RUMP_SERVER=$SOCK_HOST0
1163	$atf_ping $addr_host1
1164
1165	$atf_ifconfig lagg0 laggfailover -rx-all
1166	atf_check -s exit:0 -o not-match:'$iface2.+COLLECTING' rump.ifconfig lagg0
1167
1168	export RUMP_SERVER=$SOCK_HOST1
1169	$atf_ifconfig lagg0 laggfailover -rx-all
1170	atf_check -s exit:0 -o not-match:'$iface1.+COLLECTING' rump.ifconfig lagg0
1171
1172	export RUMP_SERVER=$SOCK_HOST0
1173	atf_check -s not-exit:0 -o ignore -e ignore $ping -c 1 $addr_host1
1174}
1175
1176atf_test_case lagg_failover_ipv4 cleanup
1177lagg_failover_ipv4_head()
1178{
1179
1180	atf_set "descr" "tests for failover using IPv4"
1181	atf_set "require.progs" "rump_server"
1182}
1183
1184lagg_failover_ipv4_body()
1185{
1186
1187	lagg_failover "inet" "ether"
1188}
1189
1190lagg_failover_ipv4_cleanup()
1191{
1192
1193	$DEBUG && dump
1194	cleanup
1195}
1196
1197atf_test_case lagg_failover_ipv6 cleanup
1198lagg_failover_ipv6_head()
1199{
1200
1201	atf_set "descr" "tests for failover using IPv6"
1202	atf_set "require.progs" "rump_server"
1203}
1204
1205lagg_failover_ipv6_body()
1206{
1207
1208	lagg_failover "inet6" "ether"
1209}
1210
1211lagg_failover_ipv6_cleanup()
1212{
1213
1214	$DEBUG && dump
1215	cleanup
1216}
1217
1218atf_test_case lagg_failover_l2tp_ipv4 cleanup
1219lagg_failover_l2tp_ipv4_head()
1220{
1221
1222	atf_set "descr" "tests for failover over l2tp using IPv4"
1223	atf_set "require.progs" "rump_server"
1224}
1225
1226lagg_failover_l2tp_ipv4_body()
1227{
1228
1229	lagg_failover "inet" "l2tp"
1230}
1231
1232lagg_failover_l2tp_ipv4_cleanup()
1233{
1234	$DEBUG && dump
1235	cleanup
1236}
1237
1238atf_test_case lagg_failover_l2tp_ipv6 cleanup
1239lagg_failover_l2tp_ipv6_head()
1240{
1241
1242	atf_set "descr" "tests for failover over l2tp using IPv6"
1243	atf_set "require.progs" "rump_server"
1244}
1245
1246lagg_failover_l2tp_ipv6_body()
1247{
1248
1249	lagg_failover "inet6" "l2tp"
1250}
1251
1252lagg_failover_l2tp_ipv6_cleanup()
1253{
1254	$DEBUG && dump
1255	cleanup
1256}
1257
1258lagg_loadbalance()
1259{
1260	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
1261
1262	local af=$1
1263	local l2proto=$2
1264	local ping="rump.ping -c 1"
1265	local rumplib=""
1266	local pfx=24
1267	local addr_host0=$IP4ADDR0
1268	local addr_host1=$IP4ADDR1
1269
1270	case $af in
1271	"inet")
1272		# do nothing
1273		;;
1274	"inet6")
1275		ping="rump.ping6 -c 1"
1276		rumplib="netinet6"
1277		pfx=64
1278		addr_host0=$IP6ADDR0
1279		addr_host1=$IP6ADDR1
1280		;;
1281	esac
1282
1283	case $l2proto in
1284	"ether")
1285		iface0=shmif0
1286		iface1=shmif1
1287		iface2=shmif2
1288		;;
1289	"l2tp")
1290		rumplib="$rumplib l2tp"
1291		iface0=l2tp0
1292		iface1=l2tp1
1293		iface2=l2tp2
1294		;;
1295	esac
1296
1297	local atf_ping="atf_check -s exit:0 -o ignore ${ping}"
1298
1299	rump_server_start $SOCK_HOST0 lagg $rumplib
1300	rump_server_start $SOCK_HOST1 lagg $rumplib
1301
1302	rump_server_add_iface $SOCK_HOST0 shmif0 $BUS0
1303	rump_server_add_iface $SOCK_HOST0 shmif1 $BUS1
1304	rump_server_add_iface $SOCK_HOST0 shmif2 $BUS2
1305
1306	rump_server_add_iface $SOCK_HOST1 shmif0 $BUS0
1307	rump_server_add_iface $SOCK_HOST1 shmif1 $BUS1
1308	rump_server_add_iface $SOCK_HOST1 shmif2 $BUS2
1309
1310	if [ x"$l2proto" = x"l2tp" ]; then
1311		setup_l2tp_ipv4tunnel
1312	fi
1313
1314	export RUMP_SERVER=$SOCK_HOST0
1315	$atf_ifconfig lagg0 create
1316	$atf_ifconfig lagg0 laggproto loadbalance
1317
1318	$atf_ifconfig lagg0 laggport $iface0 pri 1000
1319	$atf_ifconfig lagg0 laggport $iface1 pri 2000
1320	$atf_ifconfig lagg0 laggport $iface2 pri 3000
1321	$atf_ifconfig lagg0 $af $addr_host0/$pfx
1322
1323	export RUMP_SERVER=$SOCK_HOST1
1324	$atf_ifconfig lagg0 create
1325	$atf_ifconfig lagg0 laggproto loadbalance
1326
1327	$atf_ifconfig lagg0 laggport $iface0 pri 1000
1328	$atf_ifconfig lagg0 laggport $iface1 pri 3000
1329	$atf_ifconfig lagg0 laggport $iface2 pri 2000
1330	$atf_ifconfig lagg0 $af $addr_host1/$pfx
1331
1332	export RUMP_SERVER=$SOCK_HOST0
1333	$atf_ifconfig $iface0 up
1334	$atf_ifconfig $iface1 up
1335	$atf_ifconfig $iface2 up
1336	$atf_ifconfig lagg0 up
1337
1338	export RUMP_SERVER=$SOCK_HOST1
1339	$atf_ifconfig $iface0 up
1340	$atf_ifconfig $iface1 up
1341	$atf_ifconfig $iface2 up
1342	$atf_ifconfig lagg0 up
1343
1344	export RUMP_SERVER=$SOCK_HOST0
1345	$atf_ifconfig -w 10
1346	wait_for_distributing lagg0 $iface0
1347	wait_state "COLLECTING" lagg0 $iface0
1348	wait_state "COLLECTING" lagg0 $iface1
1349	wait_state "COLLECTING" lagg0 $iface2
1350
1351	export RUMP_SERVER=$SOCK_HOST1
1352	$atf_ifconfig -w 10
1353	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface0
1354	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
1355	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
1356
1357	export RUMP_SERVER=$SOCK_HOST0
1358	$atf_ping $addr_host1
1359
1360	$atf_ifconfig $iface0 down
1361	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
1362	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
1363
1364	export RUMP_SERVER=$SOCK_HOST1
1365	$atf_ifconfig $iface0 down
1366	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface1
1367	wait_state "COLLECTING,DISTRIBUTING" lagg0 $iface2
1368
1369	export RUMP_SERVER=$SOCK_HOST0
1370	$atf_ping $addr_host1
1371}
1372
1373atf_test_case lagg_loadbalance_ipv4 cleanup
1374lagg_loadbalance_ipv4_head()
1375{
1376
1377	atf_set "descr" "tests for loadbalance using IPv4"
1378	atf_set "require.progs" "rump_server"
1379}
1380
1381lagg_loadbalance_ipv4_body()
1382{
1383
1384	lagg_loadbalance "inet" "ether"
1385}
1386
1387lagg_loadbalance_ipv4_cleanup()
1388{
1389
1390	$DEBUG && dump
1391	cleanup
1392}
1393
1394atf_test_case lagg_loadbalance_ipv6 cleanup
1395lagg_loadbalance_ipv6_head()
1396{
1397
1398	atf_set "descr" "tests for loadbalance using IPv6"
1399	atf_set "require.progs" "rump_server"
1400}
1401
1402lagg_loadbalance_ipv6_body()
1403{
1404
1405	lagg_loadbalance "inet6" "ether"
1406}
1407
1408lagg_loadbalance_ipv6_cleanup()
1409{
1410
1411	$DEBUG && dump
1412	cleanup
1413}
1414
1415atf_test_case lagg_loadbalance_l2tp_ipv4 cleanup
1416lagg_loadbalance_l2tp_ipv4_head()
1417{
1418
1419	atf_set "descr" "tests for loadbalance over l2tp using IPv4"
1420	atf_set "require.progs" "rump_server"
1421}
1422
1423lagg_loadbalance_l2tp_ipv4_body()
1424{
1425
1426	lagg_loadbalance "inet" "l2tp"
1427}
1428
1429lagg_loadbalance_l2tp_ipv4_cleanup()
1430{
1431
1432	$DEBUG && dump
1433	cleanup
1434}
1435
1436atf_test_case lagg_loadbalance_l2tp_ipv6 cleanup
1437lagg_loadbalance_l2tp_ipv4_head()
1438{
1439
1440	atf_set "descr" "tests for loadbalance over l2tp using IPv6"
1441	atf_set "require.progs" "rump_server"
1442}
1443
1444lagg_loadbalance_l2tp_ipv6_body()
1445{
1446
1447	lagg_loadbalance "inet6" "l2tp"
1448}
1449
1450lagg_loadbalance_l2tp_ipv6_cleanup()
1451{
1452
1453	$DEBUG && dump
1454	cleanup
1455}
1456
1457atf_init_test_cases()
1458{
1459
1460	atf_add_test_case lagg_ifconfig
1461	atf_add_test_case lagg_macaddr
1462	atf_add_test_case lagg_ipv6lla
1463	atf_add_test_case lagg_mtu
1464	atf_add_test_case lagg_lacp_basic
1465	atf_add_test_case lagg_lacp_ipv4
1466	atf_add_test_case lagg_lacp_ipv6
1467	atf_add_test_case lagg_lacp_l2tp_ipv4
1468	atf_add_test_case lagg_lacp_l2tp_ipv6
1469	atf_add_test_case lagg_lacp_vlan_ipv4
1470	atf_add_test_case lagg_lacp_vlan_ipv6
1471	atf_add_test_case lagg_lacp_vlanl2tp_ipv4
1472	atf_add_test_case lagg_lacp_vlanl2tp_ipv6
1473	atf_add_test_case lagg_lacp_portpri
1474	atf_add_test_case lagg_failover_ipv4
1475	atf_add_test_case lagg_failover_ipv6
1476	atf_add_test_case lagg_failover_l2tp_ipv4
1477	atf_add_test_case lagg_failover_l2tp_ipv6
1478	atf_add_test_case lagg_loadbalance_ipv4
1479	atf_add_test_case lagg_loadbalance_ipv6
1480	atf_add_test_case lagg_loadbalance_l2tp_ipv4
1481	atf_add_test_case lagg_loadbalance_l2tp_ipv6
1482}
1483