]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/netinet6/output6.sh
Make the tests work without COMPAT_FREEBSD12 in kernel.
[FreeBSD/FreeBSD.git] / tests / sys / netinet6 / output6.sh
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
33 atf_test_case "output6_tcp_setup_success" "cleanup"
34 output6_tcp_setup_success_head()
35 {
36
37         atf_set descr 'Test valid IPv6 TCP output'
38         atf_set require.user root
39 }
40
41 output6_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
105 output6_tcp_setup_success_cleanup()
106 {
107         vnet_cleanup
108 }
109
110
111 atf_test_case "output6_udp_setup_success" "cleanup"
112 output6_udp_setup_success_head()
113 {
114
115         atf_set descr 'Test valid IPv6 UDP output'
116         atf_set require.user root
117 }
118
119 output6_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
183 output6_udp_setup_success_cleanup()
184 {
185         vnet_cleanup
186 }
187
188 atf_test_case "output6_raw_success" "cleanup"
189 output6_raw_success_head()
190 {
191
192         atf_set descr 'Test valid IPv6 raw output'
193         atf_set require.user root
194 }
195
196 output6_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
233 output6_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
248 mpath_check()
249 {
250         if [ `sysctl -iW net.route.multipath | wc -l` != "1" ]; then
251                 atf_skip "This test requires ROUTE_MPATH enabled"
252         fi
253 }
254
255 mpath_enable()
256 {
257         jexec $1 sysctl net.route.multipath=1
258         if [ $? != 0 ]; then
259                 atf_fail "Setting multipath in jail $1 failed".
260         fi
261 }
262
263
264 atf_test_case "output6_tcp_flowid_mpath_success" "cleanup"
265 output6_tcp_flowid_mpath_success_head()
266 {
267
268         atf_set descr 'Test valid IPv6 TCP output flowid generation'
269         atf_set require.user root
270 }
271
272 output6_tcp_flowid_mpath_success_body()
273 {
274         vnet_init
275         mpath_check
276
277         net_src="2001:db8:0:1"
278         net_dst="2001:db8:0:2"
279         ip_src="${net_src}::1"
280         ip_dst="${net_dst}::1"
281         plen=64
282         text="testtesttst"
283
284         script_name=`dirname $0`/../common/net_receiver.py
285         script_name=`realpath ${script_name}`
286         jname="v6t-output6_tcp_flowid_mpath_success"
287
288         epair0=$(vnet_mkepair)
289         epair1=$(vnet_mkepair)
290         lo_src=$(vnet_mkloopback)
291         lo_dst=$(vnet_mkloopback)
292
293         vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
294         mpath_enable ${jname}a
295         jls -N
296         # enable link-local IPv6
297         jexec ${jname}a ndp -i ${epair0}a -- -disabled
298         jexec ${jname}a ifconfig ${epair0}a up
299         jexec ${jname}a ndp -i ${epair1}a -- -disabled
300         jexec ${jname}a ifconfig ${epair1}a up
301         jexec ${jname}a ifconfig ${lo_src} up
302
303         vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
304         jls -N
305         jexec ${jname}b ndp -i ${epair0}b -- -disabled
306         jexec ${jname}b ifconfig ${epair0}b up
307         jexec ${jname}b ndp -i ${epair1}b -- -disabled
308         jexec ${jname}b ifconfig ${epair1}b up
309         jexec ${jname}b ifconfig ${lo_dst} up
310
311         # DST ips/ports to test
312         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"
313         ports="53540 49743 43067 9131 16734 5150 14379 40292 20634 51302 3387 24387 9282 14275 42103 26881 42461 29520 45714 11096"
314
315         jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
316
317         jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
318         for i in ${ips}; do
319                 jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
320         done
321
322         # wait for DAD to complete
323         while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
324                 sleep 0.1
325         done
326         while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
327                 sleep 0.1
328         done
329
330         # Add routes
331         # A -> towards B via epair0a LL
332         ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
333         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
334         # A -> towards B via epair1a LL
335         ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
336         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
337
338         # B towards A via epair0b LL
339         ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
340         jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
341         
342         # Base setup verification
343         atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -c1 ${ip_dst}
344
345         # run listener
346         num_ports=`echo ${ports} | wc -w`
347         num_ips=`echo ${ips} | wc -w`
348         count_examples=$((num_ports*num_ips))
349         listener_ports=`echo ${ports} | tr ' ' '\n' | sort -n | tr '\n' ',' | sed -e 's?,$??'`
350         args="--family inet6 --ports ${listener_ports} --count ${count_examples} --match_str ${text}"
351         echo jexec ${jname}b ${script_name} ${args}
352         jexec ${jname}b ${script_name} --test_name "test_listen_tcp" ${args} &
353         cmd_pid=$!
354
355         # wait for the app init
356         counter=0
357         init=0
358         while [ ${counter} -le 50 ]; do
359                 _ports=`jexec ${jname}b sockstat -6ql | awk "\\\$3 == ${cmd_pid} {print \\\$6}"|awk -F: "{print \\\$2}" | sort -n | tr '\n' ','`
360                 if [ "${_ports}" = "${listener_ports}," ]; then
361                         init=1
362                         break;
363                 fi
364         done
365         if [ ${init} -eq 0 ]; then
366                 jexec ${jname}b sockstat -6ql | awk "\$3 == ${cmd_pid}"
367                 echo "App setup failed"
368                 exit 1
369         fi
370         echo "App setup done"
371
372         # run sender
373         for _ip in ${ips}; do
374                 ip="${net_dst}:${_ip}"
375                 for port in ${ports}; do
376                         echo -n "${text}" | jexec ${jname}a nc -nN ${ip} ${port}
377                         exit_code=$?
378                         if [ $exit_code -ne 0 ]; then atf_fail "sender exit code $exit_code" ; fi
379                 done
380         done
381
382         wait ${cmd_pid}
383         exit_code=$?
384         if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
385
386         pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
387         pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
388         if [ ${pkt_0} -le 10 ]; then
389                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
390         fi
391         if [ ${pkt_1} -le 10 ]; then
392                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
393         fi
394         echo "TCP Balancing: 1: ${pkt_0} 2: ${pkt_1}"
395 }
396
397 output6_tcp_flowid_mpath_success_cleanup()
398 {
399         vnet_cleanup
400 }
401
402 atf_test_case "output6_udp_flowid_mpath_success" "cleanup"
403 output6_udp_flowid_mpath_success_head()
404 {
405
406         atf_set descr 'Test valid IPv6 UDP output flowid generation'
407         atf_set require.user root
408 }
409
410 output6_udp_flowid_mpath_success_body()
411 {
412
413         vnet_init
414         mpath_check
415
416         # Note this test will spawn around ~100 nc processes
417
418         net_src="2001:db8:0:1"
419         net_dst="2001:db8:0:2"
420         ip_src="${net_src}::1"
421         ip_dst="${net_dst}::1"
422         plen=64
423         text="testtesttst"
424
425         script_name=`dirname $0`/../common/net_receiver.py
426         script_name=`realpath ${script_name}`
427         jname="v6t-output6_udp_flowid_mpath_success"
428
429         epair0=$(vnet_mkepair)
430         epair1=$(vnet_mkepair)
431         lo_src=$(vnet_mkloopback)
432         lo_dst=$(vnet_mkloopback)
433
434         vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
435         mpath_enable ${jname}a
436         jls -N
437         # enable link-local IPv6
438         jexec ${jname}a ndp -i ${epair0}a -- -disabled
439         jexec ${jname}a ifconfig ${epair0}a up
440         jexec ${jname}a ndp -i ${epair1}a -- -disabled
441         jexec ${jname}a ifconfig ${epair1}a up
442         jexec ${jname}a ifconfig ${lo_src} up
443
444         vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
445         jls -N
446         jexec ${jname}b ndp -i ${epair0}b -- -disabled
447         jexec ${jname}b ifconfig ${epair0}b up
448         jexec ${jname}b ndp -i ${epair1}b -- -disabled
449         jexec ${jname}b ifconfig ${epair1}b up
450         jexec ${jname}b ifconfig ${lo_dst} up
451
452         # DST ips/ports to test
453         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"
454         ports="53540 49743 43067 9131 16734 5150 14379 40292 20634 51302 3387 24387 9282 14275 42103 26881 42461 29520 45714 11096"
455
456         jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
457
458         jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
459         for i in ${ips}; do
460                 jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
461         done
462
463         
464         # wait for DAD to complete
465         while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
466                 sleep 0.1
467         done
468         while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
469                 sleep 0.1
470         done
471
472         # Add routes
473         # A -> towards B via epair0a LL
474         ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
475         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
476         # A -> towards B via epair1a LL
477         ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
478         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
479
480         # B towards A via epair0b LL
481         ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
482         jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
483         
484         # Base setup verification
485         atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -c1 ${ip_dst}
486
487         # run listener
488         num_ports=`echo ${ports} | wc -w`
489         num_ips=`echo ${ips} | wc -w`
490         count_examples=$((num_ports*num_ips))
491         listener_ports=`echo ${ports} | tr ' ' '\n' | sort -n | tr '\n' ',' | sed -e 's?,$??'`
492         args="--family inet6 --ports ${listener_ports} --count ${count_examples} --match_str ${text}"
493         echo jexec ${jname}b ${script_name} ${args}
494         jexec ${jname}b ${script_name} --test_name "test_listen_udp" ${args} &
495         cmd_pid=$!
496
497         # wait for the app init
498         counter=0
499         init=0
500         while [ ${counter} -le 50 ]; do
501                 _ports=`jexec ${jname}b sockstat -6ql | awk "\\\$3 == ${cmd_pid} {print \\\$6}"|awk -F: "{print \\\$2}" | sort -n | tr '\n' ','`
502                 if [ "${_ports}" = "${listener_ports}," ]; then
503                         init=1
504                         break;
505                 fi
506         done
507         if [ ${init} -eq 0 ]; then
508                 jexec ${jname}b sockstat -6ql | awk "\$3 == ${cmd_pid}"
509                 echo "App setup failed"
510                 exit 1
511         fi
512         echo "App setup done"
513
514         # run sender
515         for _ip in ${ips}; do
516                 ip="${net_dst}:${_ip}"
517                 for port in ${ports}; do
518                         # XXX: switch to something that allows immediate exit
519                         echo -n "${text}" | jexec ${jname}a nc -nuNw1 ${ip} ${port} &
520                         sleep 0.01
521                 done
522         done
523
524         wait ${cmd_pid}
525         exit_code=$?
526         if [ $exit_code -ne 0 ]; then atf_fail "receiver exit code $exit_code" ; fi
527
528         pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
529         pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
530         if [ ${pkt_0} -le 10 ]; then
531                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
532         fi
533         if [ ${pkt_1} -le 10 ]; then
534                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
535         fi
536         echo "UDP BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
537 }
538
539 output6_udp_flowid_mpath_success_cleanup()
540 {
541         vnet_cleanup
542 }
543
544 atf_test_case "output6_raw_flowid_mpath_success" "cleanup"
545 output6_raw_flowid_mpath_success_head()
546 {
547
548         atf_set descr 'Test valid IPv6 raw output flowid generation'
549         atf_set require.user root
550 }
551
552 output6_raw_flowid_mpath_success_body()
553 {
554
555         vnet_init
556         mpath_check
557
558         net_src="2001:db8:0:1"
559         net_dst="2001:db8:0:2"
560         ip_src="${net_src}::1"
561         ip_dst="${net_dst}::1"
562         plen=64
563         text="testtesttst"
564
565         jname="v6t-output6_raw_flowid_mpath_success"
566
567         epair0=$(vnet_mkepair)
568         epair1=$(vnet_mkepair)
569         lo_src=$(vnet_mkloopback)
570         lo_dst=$(vnet_mkloopback)
571
572         vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
573         mpath_enable ${jname}a
574         jls -N
575         # enable link-local IPv6
576         jexec ${jname}a ndp -i ${epair0}a -- -disabled
577         jexec ${jname}a ifconfig ${epair0}a up
578         jexec ${jname}a ndp -i ${epair1}a -- -disabled
579         jexec ${jname}a ifconfig ${epair1}a up
580         jexec ${jname}a ifconfig ${lo_src} up
581
582         vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
583         jls -N
584         jexec ${jname}b ndp -i ${epair0}b -- -disabled
585         jexec ${jname}b ifconfig ${epair0}b up
586         jexec ${jname}b ndp -i ${epair1}b -- -disabled
587         jexec ${jname}b ifconfig ${epair1}b up
588         jexec ${jname}b ifconfig ${lo_dst} up
589
590         # DST ips to test
591         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"
592         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"
593         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"
594         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"
595
596         jexec ${jname}a ifconfig ${lo_src} inet6 ${ip_src}/128
597
598         jexec ${jname}b ifconfig ${lo_dst} inet6 ${ip_dst}/128
599         for i in ${ips}; do
600                 jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:${i}/128
601         done
602
603         # wait for DAD to complete
604         while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
605                 sleep 0.1
606         done
607         while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
608                 sleep 0.1
609         done
610
611         # Add routes
612         # A -> towards B via epair0a LL
613         ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
614         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair0}a
615         # A -> towards B via epair1a LL
616         ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
617         jexec ${jname}a route add -6 -net ${net_dst}::/${plen} ${ll}%${epair1}a
618
619         # B towards A via epair0b LL
620         ll=`jexec ${jname}a ifconfig ${epair1}a inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
621         jexec ${jname}b route add -6 -net ${net_src}::/${plen} ${ll}%${epair1}b
622         
623         # Base setup verification
624         atf_check -o match:'1 packets transmitted, 1 packets received' jexec ${jname}a ping6 -nc1 ${ip_dst}
625
626         # run sender
627         valid_message='1 packets transmitted, 1 packets received'
628         for _ip in ${ips}; do
629                 ip="${net_dst}:${_ip}"
630                 atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -nc1 ${ip}
631         done
632
633         pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
634         pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
635
636         jexec ${jname}a netstat -bWf link -I ${epair0}a
637         jexec ${jname}a netstat -bWf link -I ${epair1}a
638         if [ ${pkt_0} -le 10 ]; then
639                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
640         fi
641         if [ ${pkt_1} -le 10 ]; then
642                 atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
643         fi
644         echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
645 }
646
647 output6_raw_flowid_mpath_success_cleanup()
648 {
649         vnet_cleanup
650 }
651
652 atf_init_test_cases()
653 {
654         atf_add_test_case "output6_tcp_setup_success"
655         atf_add_test_case "output6_udp_setup_success"
656         atf_add_test_case "output6_raw_success"
657         atf_add_test_case "output6_tcp_flowid_mpath_success"
658         atf_add_test_case "output6_udp_flowid_mpath_success"
659         atf_add_test_case "output6_raw_flowid_mpath_success"
660 }
661
662 # end
663
664