xref: /freebsd/tests/sys/netinet6/output6.sh (revision e17f5b1d)
1#!/usr/bin/env atf-sh
2#-
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2020 Alexander V. Chernikov
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD$
29#
30
31. $(atf_get_srcdir)/../common/vnet.subr
32
33atf_test_case "output6_tcp_setup_success" "cleanup"
34output6_tcp_setup_success_head()
35{
36
37	atf_set descr 'Test valid IPv6 TCP output'
38	atf_set require.user root
39}
40
41output6_tcp_setup_success_body()
42{
43
44	vnet_init
45
46	net_src="2001:db8:0:0:1::"
47	net_dst="2001:db8:0:0:1::"
48	ip_src="${net_src}1"
49	ip_dst=${net_dst}4242
50	plen=64
51	text="testtesttst"
52	port=4242
53
54	script_name=`dirname $0`/../common/net_receiver.py
55	script_name=`realpath ${script_name}`
56	jname="v6t-output6_tcp_setup_success"
57
58	epair=$(vnet_mkepair)
59
60	vnet_mkjail ${jname}a ${epair}a
61	jexec ${jname}a ifconfig ${epair}a up
62	jexec ${jname}a ifconfig ${epair}a inet6 ${ip_src}/${plen}
63
64	vnet_mkjail ${jname}b ${epair}b
65	jexec ${jname}b ifconfig ${epair}b up
66
67	jexec ${jname}b ifconfig ${epair}b inet6 ${ip_dst}/${plen}
68
69	# wait for DAD to complete
70	while [ `jexec ${jname}b ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
71		sleep 0.1
72	done
73	while [ `jexec ${jname}a ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
74		sleep 0.1
75	done
76
77	# run listener
78	args="--family inet6 --ports ${port} --match_str ${text}"
79	echo jexec ${jname}b ${script_name} ${args}
80	jexec ${jname}b ${script_name} --test_name "test_listen_tcp" ${args} &
81	cmd_pid=$!
82
83	# wait for the script init
84	counter=0
85	while [ `jexec ${jname}b sockstat -6qlp ${port} | wc -l` != "1" ]; do
86		sleep 0.01
87		counter=$((counter+1))
88		if [ ${counter} -ge 50 ]; then break; fi
89	done
90	if [ `jexec ${jname}b sockstat -6qlp ${port} | wc -l` != "1" ]; then
91		echo "App setup failed"
92		exit 1
93	fi
94
95	# run sender
96	echo -n "${text}" | jexec ${jname}a nc -N ${ip_dst} ${port}
97	exit_code=$?
98	if [ $exit_code -ne 0 ]; then atf_fail "sender exit code $exit_code" ; fi
99
100	wait ${cmd_pid}
101	exit_code=$?
102	if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
103}
104
105output6_tcp_setup_success_cleanup()
106{
107	vnet_cleanup
108}
109
110
111atf_test_case "output6_udp_setup_success" "cleanup"
112output6_udp_setup_success_head()
113{
114
115	atf_set descr 'Test valid IPv6 UDP output'
116	atf_set require.user root
117}
118
119output6_udp_setup_success_body()
120{
121
122	vnet_init
123
124	net_src="2001:db8:0:0:1::"
125	net_dst="2001:db8:0:0:1::"
126	ip_src="${net_src}1"
127	ip_dst=${net_dst}4242
128	plen=64
129	text="testtesttst"
130	port=4242
131
132	script_name=`dirname $0`/../common/net_receiver.py
133	script_name=`realpath ${script_name}`
134	jname="v6t-output6_udp_setup_success"
135
136	epair=$(vnet_mkepair)
137
138	vnet_mkjail ${jname}a ${epair}a
139	jexec ${jname}a ifconfig ${epair}a up
140	jexec ${jname}a ifconfig ${epair}a inet6 ${ip_src}/${plen}
141
142	vnet_mkjail ${jname}b ${epair}b
143	jexec ${jname}b ifconfig ${epair}b up
144	jexec ${jname}b ifconfig ${epair}b inet6 ${ip_dst}/${plen}
145
146	# wait for DAD to complete
147	while [ `jexec ${jname}b ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
148		sleep 0.1
149	done
150	while [ `jexec ${jname}a ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
151		sleep 0.1
152	done
153
154	# run listener
155	args="--family inet6 --ports ${port} --match_str ${text}"
156	echo jexec ${jname}b ${script_name} ${args}
157	jexec ${jname}b ${script_name} --test_name "test_listen_udp" ${args} &
158	cmd_pid=$!
159
160	# wait for the script init
161	counter=0
162	while [ `jexec ${jname}b sockstat -6qlp ${port} | wc -l` != "1" ]; do
163		sleep 0.1
164		counterc=$((counter+1))
165		if [ ${counter} -ge 50 ]; then break; fi
166	done
167	if [ `jexec ${jname}b sockstat -6qlp ${port} | wc -l` != "1" ]; then
168		echo "App setup failed"
169		exit 1
170	fi
171
172	# run sender
173	# TODO: switch from nc to some alternative to avoid 1-second delay
174	echo -n "${text}" | jexec ${jname}a nc -uNw1 ${ip_dst} ${port}
175	exit_code=$?
176	if [ $exit_code -ne 0 ]; then atf_fail "sender exit code $exit_code" ; fi
177
178	wait ${cmd_pid}
179	exit_code=$?
180	if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
181}
182
183output6_udp_setup_success_cleanup()
184{
185	vnet_cleanup
186}
187
188atf_test_case "output6_raw_success" "cleanup"
189output6_raw_success_head()
190{
191
192	atf_set descr 'Test valid IPv6 raw output'
193	atf_set require.user root
194}
195
196output6_raw_success_body()
197{
198
199	vnet_init
200
201	net_src="2001:db8:0:0:1::"
202	net_dst="2001:db8:0:0:1::"
203	ip_src="${net_src}1"
204	ip_dst=${net_dst}4242
205	plen=64
206
207	script_name=`dirname $0`/../common/net_receiver.py
208	script_name=`realpath ${script_name}`
209	jname="v6t-output6_raw_success"
210
211	epair=$(vnet_mkepair)
212
213	vnet_mkjail ${jname}a ${epair}a
214	jexec ${jname}a ifconfig ${epair}a up
215	jexec ${jname}a ifconfig ${epair}a inet6 ${ip_src}/${plen}
216
217	vnet_mkjail ${jname}b ${epair}b
218	jexec ${jname}b ifconfig ${epair}b up
219
220	jexec ${jname}b ifconfig ${epair}b inet6 ${ip_dst}/${plen}
221
222	# wait for DAD to complete
223	while [ `jexec ${jname}b ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
224		sleep 0.1
225	done
226	while [ `jexec ${jname}a ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
227		sleep 0.1
228	done
229
230	atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -nc1 ${ip_dst}
231}
232
233output6_raw_success_cleanup()
234{
235	vnet_cleanup
236}
237
238# Multipath tests are done the following way:
239#               epair0/LL
240# jailA lo/GU <           > lo/GU jailB
241#               epair1/LL
242# jailA has 2 routes towards /64 prefix on jailB loopback, via 2 epairs
243# jailB has 1 route towards /64 prefix on jailA loopback, via epair0
244#
245# jailA initiates connections/sends packets towards IPs on jailB loopback.
246# Script then compares amount of packets sent via epair0 and epair1
247
248mpath_check()
249{
250	if [ "`sysctl -i -n net.route.multipath`" != 1 ]; then
251		atf_skip "This test requires ROUTE_MPATH enabled"
252	fi
253}
254
255atf_test_case "output6_tcp_flowid_mpath_success" "cleanup"
256output6_tcp_flowid_mpath_success_head()
257{
258
259	atf_set descr 'Test valid IPv6 TCP output flowid generation'
260	atf_set require.user root
261}
262
263output6_tcp_flowid_mpath_success_body()
264{
265	vnet_init
266	mpath_check
267
268	net_src="2001:db8:0:1"
269	net_dst="2001:db8:0:2"
270	ip_src="${net_src}::1"
271	ip_dst="${net_dst}::1"
272	plen=64
273	text="testtesttst"
274
275	script_name=`dirname $0`/../common/net_receiver.py
276	script_name=`realpath ${script_name}`
277	jname="v6t-output6_tcp_flowid_mpath_success"
278
279	epair0=$(vnet_mkepair)
280	epair1=$(vnet_mkepair)
281	lo_src=$(vnet_mkloopback)
282	lo_dst=$(vnet_mkloopback)
283
284	vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
285	jls -N
286	# enable link-local IPv6
287	jexec ${jname}a ndp -i ${epair0}a -- -disabled
288	jexec ${jname}a ifconfig ${epair0}a up
289	jexec ${jname}a ndp -i ${epair1}a -- -disabled
290	jexec ${jname}a ifconfig ${epair1}a up
291	jexec ${jname}a ifconfig ${lo_src} up
292
293	vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
294	jls -N
295	jexec ${jname}b ndp -i ${epair0}b -- -disabled
296	jexec ${jname}b ifconfig ${epair0}b up
297	jexec ${jname}b ndp -i ${epair1}b -- -disabled
298	jexec ${jname}b ifconfig ${epair1}b up
299	jexec ${jname}b ifconfig ${lo_dst} up
300
301	# DST ips/ports to test
302	ips="d3:c4:eb:40 2b:ff:dd:52 b1:d4:44:0e 41:2c:4d:43 66:4a:b4:be 8b:da:ac:f7 ca:d1:c4:f0 b1:31:da:d7 0c:ac:45:7a 44:9c:ce:71"
303	ports="53540 49743 43067 9131 16734 5150 14379 40292 20634 51302 3387 24387 9282 14275 42103 26881 42461 29520 45714 11096"
304
305	jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
306
307	jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
308	for i in ${ips}; do
309		jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
310	done
311
312	# wait for DAD to complete
313	while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
314		sleep 0.1
315	done
316	while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
317		sleep 0.1
318	done
319
320	# Add routes
321	# A -> towards B via epair0a LL
322	ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
323	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
324	# A -> towards B via epair1a LL
325	ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
326	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
327
328	# B towards A via epair0b LL
329	ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
330	jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
331
332	# Base setup verification
333	atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -c1 ${ip_dst}
334
335	# run listener
336	num_ports=`echo ${ports} | wc -w`
337	num_ips=`echo ${ips} | wc -w`
338	count_examples=$((num_ports*num_ips))
339	listener_ports=`echo ${ports} | tr ' ' '\n' | sort -n | tr '\n' ',' | sed -e 's?,$??'`
340	args="--family inet6 --ports ${listener_ports} --count ${count_examples} --match_str ${text}"
341	echo jexec ${jname}b ${script_name} ${args}
342	jexec ${jname}b ${script_name} --test_name "test_listen_tcp" ${args} &
343	cmd_pid=$!
344
345	# wait for the app init
346	counter=0
347	init=0
348	while [ ${counter} -le 50 ]; do
349		_ports=`jexec ${jname}b sockstat -6ql | awk "\\\$3 == ${cmd_pid} {print \\\$6}"|awk -F: "{print \\\$2}" | sort -n | tr '\n' ','`
350		if [ "${_ports}" = "${listener_ports}," ]; then
351			init=1
352			break;
353		fi
354	done
355	if [ ${init} -eq 0 ]; then
356		jexec ${jname}b sockstat -6ql | awk "\$3 == ${cmd_pid}"
357		echo "App setup failed"
358		exit 1
359	fi
360	echo "App setup done"
361
362	# run sender
363	for _ip in ${ips}; do
364		ip="${net_dst}:${_ip}"
365		for port in ${ports}; do
366			echo -n "${text}" | jexec ${jname}a nc -nN ${ip} ${port}
367			exit_code=$?
368			if [ $exit_code -ne 0 ]; then atf_fail "sender exit code $exit_code" ; fi
369		done
370	done
371
372	wait ${cmd_pid}
373	exit_code=$?
374	if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
375
376	pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
377	pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
378	if [ ${pkt_0} -le 10 ]; then
379		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
380		exit 1
381	fi
382	if [ ${pkt_1} -le 10 ]; then
383		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
384		exit 1
385	fi
386	echo "TCP Balancing: 1: ${pkt_0} 2: ${pkt_1}"
387}
388
389output6_tcp_flowid_mpath_success_cleanup()
390{
391	vnet_cleanup
392}
393
394atf_test_case "output6_udp_flowid_mpath_success" "cleanup"
395output6_udp_flowid_mpath_success_head()
396{
397
398	atf_set descr 'Test valid IPv6 UDP output flowid generation'
399	atf_set require.user root
400}
401
402output6_udp_flowid_mpath_success_body()
403{
404
405	vnet_init
406	mpath_check
407
408	# Note this test will spawn around ~100 nc processes
409
410	net_src="2001:db8:0:1"
411	net_dst="2001:db8:0:2"
412	ip_src="${net_src}::1"
413	ip_dst="${net_dst}::1"
414	plen=64
415	text="testtesttst"
416
417	script_name=`dirname $0`/../common/net_receiver.py
418	script_name=`realpath ${script_name}`
419	jname="v6t-output6_udp_flowid_mpath_success"
420
421	epair0=$(vnet_mkepair)
422	epair1=$(vnet_mkepair)
423	lo_src=$(vnet_mkloopback)
424	lo_dst=$(vnet_mkloopback)
425
426	vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
427	jls -N
428	# enable link-local IPv6
429	jexec ${jname}a ndp -i ${epair0}a -- -disabled
430	jexec ${jname}a ifconfig ${epair0}a up
431	jexec ${jname}a ndp -i ${epair1}a -- -disabled
432	jexec ${jname}a ifconfig ${epair1}a up
433	jexec ${jname}a ifconfig ${lo_src} up
434
435	vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
436	jls -N
437	jexec ${jname}b ndp -i ${epair0}b -- -disabled
438	jexec ${jname}b ifconfig ${epair0}b up
439	jexec ${jname}b ndp -i ${epair1}b -- -disabled
440	jexec ${jname}b ifconfig ${epair1}b up
441	jexec ${jname}b ifconfig ${lo_dst} up
442
443	# DST ips/ports to test
444	ips="d3:c4:eb:40 2b:ff:dd:52 b1:d4:44:0e 41:2c:4d:43 66:4a:b4:be 8b:da:ac:f7 ca:d1:c4:f0 b1:31:da:d7 0c:ac:45:7a 44:9c:ce:71"
445	ports="53540 49743 43067 9131 16734 5150 14379 40292 20634 51302 3387 24387 9282 14275 42103 26881 42461 29520 45714 11096"
446
447	jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
448
449	jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
450	for i in ${ips}; do
451		jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
452	done
453
454
455	# wait for DAD to complete
456	while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
457		sleep 0.1
458	done
459	while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
460		sleep 0.1
461	done
462
463	# Add routes
464	# A -> towards B via epair0a LL
465	ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
466	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
467	# A -> towards B via epair1a LL
468	ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
469	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
470
471	# B towards A via epair0b LL
472	ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
473	jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
474
475	# Base setup verification
476	atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -c1 ${ip_dst}
477
478	# run listener
479	num_ports=`echo ${ports} | wc -w`
480	num_ips=`echo ${ips} | wc -w`
481	count_examples=$((num_ports*num_ips))
482	listener_ports=`echo ${ports} | tr ' ' '\n' | sort -n | tr '\n' ',' | sed -e 's?,$??'`
483	args="--family inet6 --ports ${listener_ports} --count ${count_examples} --match_str ${text}"
484	echo jexec ${jname}b ${script_name} ${args}
485	jexec ${jname}b ${script_name} --test_name "test_listen_udp" ${args} &
486	cmd_pid=$!
487
488	# wait for the app init
489	counter=0
490	init=0
491	while [ ${counter} -le 50 ]; do
492		_ports=`jexec ${jname}b sockstat -6ql | awk "\\\$3 == ${cmd_pid} {print \\\$6}"|awk -F: "{print \\\$2}" | sort -n | tr '\n' ','`
493		if [ "${_ports}" = "${listener_ports}," ]; then
494			init=1
495			break;
496		fi
497	done
498	if [ ${init} -eq 0 ]; then
499		jexec ${jname}b sockstat -6ql | awk "\$3 == ${cmd_pid}"
500		echo "App setup failed"
501		exit 1
502	fi
503	echo "App setup done"
504
505	# run sender
506	for _ip in ${ips}; do
507		ip="${net_dst}:${_ip}"
508		for port in ${ports}; do
509			# XXX: switch to something that allows immediate exit
510			echo -n "${text}" | jexec ${jname}a nc -nuNw1 ${ip} ${port} &
511			sleep 0.01
512		done
513	done
514
515	wait ${cmd_pid}
516	exit_code=$?
517	if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
518
519	pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
520	pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
521	if [ ${pkt_0} -le 10 ]; then
522		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
523		exit 1
524	fi
525	if [ ${pkt_1} -le 10 ]; then
526		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
527		exit 1
528	fi
529	echo "UDP BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
530}
531
532output6_udp_flowid_mpath_success_cleanup()
533{
534	vnet_cleanup
535}
536
537atf_test_case "output6_raw_flowid_mpath_success" "cleanup"
538output6_raw_flowid_mpath_success_head()
539{
540
541	atf_set descr 'Test valid IPv6 raw output flowid generation'
542	atf_set require.user root
543}
544
545output6_raw_flowid_mpath_success_body()
546{
547
548	vnet_init
549	mpath_check
550
551	net_src="2001:db8:0:1"
552	net_dst="2001:db8:0:2"
553	ip_src="${net_src}::1"
554	ip_dst="${net_dst}::1"
555	plen=64
556	text="testtesttst"
557
558	jname="v6t-output6_raw_flowid_mpath_success"
559
560	epair0=$(vnet_mkepair)
561	epair1=$(vnet_mkepair)
562	lo_src=$(vnet_mkloopback)
563	lo_dst=$(vnet_mkloopback)
564
565	vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
566	jls -N
567	# enable link-local IPv6
568	jexec ${jname}a ndp -i ${epair0}a -- -disabled
569	jexec ${jname}a ifconfig ${epair0}a up
570	jexec ${jname}a ndp -i ${epair1}a -- -disabled
571	jexec ${jname}a ifconfig ${epair1}a up
572	jexec ${jname}a ifconfig ${lo_src} up
573
574	vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
575	jls -N
576	jexec ${jname}b ndp -i ${epair0}b -- -disabled
577	jexec ${jname}b ifconfig ${epair0}b up
578	jexec ${jname}b ndp -i ${epair1}b -- -disabled
579	jexec ${jname}b ifconfig ${epair1}b up
580	jexec ${jname}b ifconfig ${lo_dst} up
581
582	# DST ips to test
583	ips="9d:33:f2:7f 48:06:9a:0b cf:96:d5:78 76:da:8e:28 d4:66:38:1e ec:43:da:7c bb:f8:93:2f d3:c4:eb:40"
584	ips="${ips} c7:31:0e:ae 8d:ed:35:2e c0:e0:22:31 82:1c:4e:28 c1:00:60:3e 6a:4f:3b:6c 8e:a7:e9:57 2b:ff:dd:52"
585	ips="${ips} 88:44:79:5d 80:62:83:11 c8:e4:17:a6 e7:2a:45:d7 5a:92:0e:04 70:fc:6a:ee ce:24:4c:68 41:2c:4d:43"
586	ips="${ips} 57:2b:5e:a7 f9:e0:69:c6 cb:b9:e6:ed 28:88:5d:fa d6:19:ac:1d dc:de:37:d8 fe:39:55:c7 b1:31:da:d7"
587
588	jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
589
590	jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
591	for i in ${ips}; do
592		jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
593	done
594
595	# wait for DAD to complete
596	while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
597		sleep 0.1
598	done
599	while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
600		sleep 0.1
601	done
602
603	# Add routes
604	# A -> towards B via epair0a LL
605	ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
606	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
607	# A -> towards B via epair1a LL
608	ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
609	jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
610
611	# B towards A via epair0b LL
612	ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
613	jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
614
615	# Base setup verification
616	atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -nc1 ${ip_dst}
617
618	# run sender
619	valid_message='1 packets transmitted, 1 packets received'
620	for _ip in ${ips}; do
621		ip="${net_dst}:${_ip}"
622		atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -nc1 ${ip}
623	done
624
625	pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
626	pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
627
628	jexec ${jname}a netstat -bWf link -I ${epair0}a
629	jexec ${jname}a netstat -bWf link -I ${epair1}a
630	if [ ${pkt_0} -le 10 ]; then
631		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
632		exit 1
633	fi
634	if [ ${pkt_1} -le 10 ]; then
635		echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
636		exit 1
637	fi
638	echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
639}
640
641output6_raw_flowid_mpath_success_cleanup()
642{
643	vnet_cleanup
644}
645
646atf_init_test_cases()
647{
648	atf_add_test_case "output6_tcp_setup_success"
649	atf_add_test_case "output6_udp_setup_success"
650	atf_add_test_case "output6_raw_success"
651	atf_add_test_case "output6_tcp_flowid_mpath_success"
652	atf_add_test_case "output6_udp_flowid_mpath_success"
653	atf_add_test_case "output6_raw_flowid_mpath_success"
654}
655
656# end
657
658
659