xref: /linux/tools/testing/selftests/net/mptcp/mptcp_join.sh (revision 920c293af8d01942caa10300ad97eabf778e8598)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ret=0
5sin=""
6sinfail=""
7sout=""
8cin=""
9cinfail=""
10cinsent=""
11cout=""
12ksft_skip=4
13timeout_poll=30
14timeout_test=$((timeout_poll * 2 + 1))
15mptcp_connect=""
16capture=0
17checksum=0
18do_all_tests=1
19
20TEST_COUNT=0
21
22# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
23#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
24CBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
25			       48 0 0 0,
26			       84 0 0 240,
27			       21 0 3 64,
28			       48 0 0 54,
29			       84 0 0 240,
30			       21 6 7 48,
31			       48 0 0 0,
32			       84 0 0 240,
33			       21 0 4 96,
34			       48 0 0 74,
35			       84 0 0 240,
36			       21 0 1 48,
37			       6 0 0 65535,
38			       6 0 0 0"
39
40init()
41{
42	capout=$(mktemp)
43
44	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
45
46	ns1="ns1-$rndh"
47	ns2="ns2-$rndh"
48
49	for netns in "$ns1" "$ns2";do
50		ip netns add $netns || exit $ksft_skip
51		ip -net $netns link set lo up
52		ip netns exec $netns sysctl -q net.mptcp.enabled=1
53		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
54		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
55		if [ $checksum -eq 1 ]; then
56			ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
57		fi
58	done
59
60	#  ns1              ns2
61	# ns1eth1    ns2eth1
62	# ns1eth2    ns2eth2
63	# ns1eth3    ns2eth3
64	# ns1eth4    ns2eth4
65
66	for i in `seq 1 4`; do
67		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
68		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
69		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
70		ip -net "$ns1" link set ns1eth$i up
71
72		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
73		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
74		ip -net "$ns2" link set ns2eth$i up
75
76		# let $ns2 reach any $ns1 address from any interface
77		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
78	done
79}
80
81init_shapers()
82{
83	for i in `seq 1 4`; do
84		tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
85		tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
86	done
87}
88
89cleanup_partial()
90{
91	rm -f "$capout"
92
93	for netns in "$ns1" "$ns2"; do
94		ip netns del $netns
95		rm -f /tmp/$netns.{nstat,out}
96	done
97}
98
99cleanup()
100{
101	rm -f "$cin" "$cout" "$sinfail"
102	rm -f "$sin" "$sout" "$cinsent" "$cinfail"
103	cleanup_partial
104}
105
106reset()
107{
108	cleanup_partial
109	init
110}
111
112reset_with_cookies()
113{
114	reset
115
116	for netns in "$ns1" "$ns2";do
117		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
118	done
119}
120
121reset_with_add_addr_timeout()
122{
123	local ip="${1:-4}"
124	local tables
125
126	tables="iptables"
127	if [ $ip -eq 6 ]; then
128		tables="ip6tables"
129	fi
130
131	reset
132
133	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
134	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
135		-m tcp --tcp-option 30 \
136		-m bpf --bytecode \
137		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
138		-j DROP
139}
140
141reset_with_checksum()
142{
143	local ns1_enable=$1
144	local ns2_enable=$2
145
146	reset
147
148	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
149	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
150}
151
152reset_with_allow_join_id0()
153{
154	local ns1_enable=$1
155	local ns2_enable=$2
156
157	reset
158
159	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
160	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
161}
162
163ip -Version > /dev/null 2>&1
164if [ $? -ne 0 ];then
165	echo "SKIP: Could not run test without ip tool"
166	exit $ksft_skip
167fi
168
169iptables -V > /dev/null 2>&1
170if [ $? -ne 0 ];then
171	echo "SKIP: Could not run all tests without iptables tool"
172	exit $ksft_skip
173fi
174
175ip6tables -V > /dev/null 2>&1
176if [ $? -ne 0 ];then
177	echo "SKIP: Could not run all tests without ip6tables tool"
178	exit $ksft_skip
179fi
180
181print_file_err()
182{
183	ls -l "$1" 1>&2
184	echo "Trailing bytes are: "
185	tail -c 27 "$1"
186}
187
188check_transfer()
189{
190	in=$1
191	out=$2
192	what=$3
193
194	cmp "$in" "$out" > /dev/null 2>&1
195	if [ $? -ne 0 ] ;then
196		echo "[ FAIL ] $what does not match (in, out):"
197		print_file_err "$in"
198		print_file_err "$out"
199		ret=1
200
201		return 1
202	fi
203
204	return 0
205}
206
207do_ping()
208{
209	listener_ns="$1"
210	connector_ns="$2"
211	connect_addr="$3"
212
213	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
214	if [ $? -ne 0 ] ; then
215		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
216		ret=1
217	fi
218}
219
220link_failure()
221{
222	ns="$1"
223
224	if [ -z "$FAILING_LINKS" ]; then
225		l=$((RANDOM%4))
226		FAILING_LINKS=$((l+1))
227	fi
228
229	for l in $FAILING_LINKS; do
230		veth="ns1eth$l"
231		ip -net "$ns" link set "$veth" down
232	done
233}
234
235# $1: IP address
236is_v6()
237{
238	[ -z "${1##*:*}" ]
239}
240
241do_transfer()
242{
243	listener_ns="$1"
244	connector_ns="$2"
245	cl_proto="$3"
246	srv_proto="$4"
247	connect_addr="$5"
248	test_link_fail="$6"
249	addr_nr_ns1="$7"
250	addr_nr_ns2="$8"
251	speed="$9"
252	bkup="${10}"
253
254	port=$((10000+$TEST_COUNT))
255	TEST_COUNT=$((TEST_COUNT+1))
256
257	:> "$cout"
258	:> "$sout"
259	:> "$capout"
260
261	if [ $capture -eq 1 ]; then
262		if [ -z $SUDO_USER ] ; then
263			capuser=""
264		else
265			capuser="-Z $SUDO_USER"
266		fi
267
268		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
269
270		echo "Capturing traffic for test $TEST_COUNT into $capfile"
271		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
272		cappid=$!
273
274		sleep 1
275	fi
276
277	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
278		nstat -n
279	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
280		nstat -n
281
282	if [ $speed = "fast" ]; then
283		mptcp_connect="./mptcp_connect -j"
284	elif [ $speed = "slow" ]; then
285		mptcp_connect="./mptcp_connect -r 50"
286	elif [ $speed = "least" ]; then
287		mptcp_connect="./mptcp_connect -r 10"
288	fi
289
290	local local_addr
291	if is_v6 "${connect_addr}"; then
292		local_addr="::"
293	else
294		local_addr="0.0.0.0"
295	fi
296
297	if [ "$test_link_fail" -eq 2 ];then
298		timeout ${timeout_test} \
299			ip netns exec ${listener_ns} \
300				$mptcp_connect -t ${timeout_poll} -l -p $port -s ${cl_proto} \
301					${local_addr} < "$sinfail" > "$sout" &
302	else
303		timeout ${timeout_test} \
304			ip netns exec ${listener_ns} \
305				$mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
306					${local_addr} < "$sin" > "$sout" &
307	fi
308	spid=$!
309
310	sleep 1
311
312	if [ "$test_link_fail" -eq 0 ];then
313		timeout ${timeout_test} \
314			ip netns exec ${connector_ns} \
315				$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
316					$connect_addr < "$cin" > "$cout" &
317	else
318		( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
319			tee "$cinsent" | \
320			timeout ${timeout_test} \
321				ip netns exec ${connector_ns} \
322					$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
323						$connect_addr > "$cout" &
324	fi
325	cpid=$!
326
327	if [ $addr_nr_ns1 -gt 0 ]; then
328		let add_nr_ns1=addr_nr_ns1
329		counter=2
330		sleep 1
331		while [ $add_nr_ns1 -gt 0 ]; do
332			local addr
333			if is_v6 "${connect_addr}"; then
334				addr="dead:beef:$counter::1"
335			else
336				addr="10.0.$counter.1"
337			fi
338			ip netns exec $ns1 ./pm_nl_ctl add $addr flags signal
339			let counter+=1
340			let add_nr_ns1-=1
341		done
342		sleep 1
343	elif [ $addr_nr_ns1 -lt 0 ]; then
344		let rm_nr_ns1=-addr_nr_ns1
345		if [ $rm_nr_ns1 -lt 8 ]; then
346			counter=1
347			pos=1
348			dump=(`ip netns exec ${listener_ns} ./pm_nl_ctl dump`)
349			if [ ${#dump[@]} -gt 0 ]; then
350				sleep 1
351
352				while [ $counter -le $rm_nr_ns1 ]
353				do
354					id=${dump[$pos]}
355					ip netns exec ${listener_ns} ./pm_nl_ctl del $id
356					sleep 1
357					let counter+=1
358					let pos+=5
359				done
360			fi
361		elif [ $rm_nr_ns1 -eq 8 ]; then
362			sleep 1
363			ip netns exec ${listener_ns} ./pm_nl_ctl flush
364		elif [ $rm_nr_ns1 -eq 9 ]; then
365			sleep 1
366			ip netns exec ${listener_ns} ./pm_nl_ctl del 0 ${connect_addr}
367		fi
368	fi
369
370	flags="subflow"
371	if [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
372		flags="${flags},fullmesh"
373		addr_nr_ns2=${addr_nr_ns2:9}
374	fi
375
376	if [ $addr_nr_ns2 -gt 0 ]; then
377		let add_nr_ns2=addr_nr_ns2
378		counter=3
379		sleep 1
380		while [ $add_nr_ns2 -gt 0 ]; do
381			local addr
382			if is_v6 "${connect_addr}"; then
383				addr="dead:beef:$counter::2"
384			else
385				addr="10.0.$counter.2"
386			fi
387			ip netns exec $ns2 ./pm_nl_ctl add $addr flags $flags
388			let counter+=1
389			let add_nr_ns2-=1
390		done
391		sleep 1
392	elif [ $addr_nr_ns2 -lt 0 ]; then
393		let rm_nr_ns2=-addr_nr_ns2
394		if [ $rm_nr_ns2 -lt 8 ]; then
395			counter=1
396			pos=1
397			dump=(`ip netns exec ${connector_ns} ./pm_nl_ctl dump`)
398			if [ ${#dump[@]} -gt 0 ]; then
399				sleep 1
400
401				while [ $counter -le $rm_nr_ns2 ]
402				do
403					id=${dump[$pos]}
404					ip netns exec ${connector_ns} ./pm_nl_ctl del $id
405					sleep 1
406					let counter+=1
407					let pos+=5
408				done
409			fi
410		elif [ $rm_nr_ns2 -eq 8 ]; then
411			sleep 1
412			ip netns exec ${connector_ns} ./pm_nl_ctl flush
413		elif [ $rm_nr_ns2 -eq 9 ]; then
414			local addr
415			if is_v6 "${connect_addr}"; then
416				addr="dead:beef:1::2"
417			else
418				addr="10.0.1.2"
419			fi
420			sleep 1
421			ip netns exec ${connector_ns} ./pm_nl_ctl del 0 $addr
422		fi
423	fi
424
425	if [ ! -z $bkup ]; then
426		sleep 1
427		for netns in "$ns1" "$ns2"; do
428			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
429			if [ ${#dump[@]} -gt 0 ]; then
430				addr=${dump[${#dump[@]} - 1]}
431				backup="ip netns exec $netns ./pm_nl_ctl set $addr flags $bkup"
432				$backup
433			fi
434		done
435	fi
436
437	wait $cpid
438	retc=$?
439	wait $spid
440	rets=$?
441
442	if [ $capture -eq 1 ]; then
443	    sleep 1
444	    kill $cappid
445	fi
446
447	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
448		nstat | grep Tcp > /tmp/${listener_ns}.out
449	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
450		nstat | grep Tcp > /tmp/${connector_ns}.out
451
452	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
453		echo " client exit code $retc, server $rets" 1>&2
454		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
455		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
456		cat /tmp/${listener_ns}.out
457		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
458		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
459		cat /tmp/${connector_ns}.out
460
461		cat "$capout"
462		ret=1
463		return 1
464	fi
465
466	if [ "$test_link_fail" -eq 2 ];then
467		check_transfer $sinfail $cout "file received by client"
468	else
469		check_transfer $sin $cout "file received by client"
470	fi
471	retc=$?
472	if [ "$test_link_fail" -eq 0 ];then
473		check_transfer $cin $sout "file received by server"
474	else
475		check_transfer $cinsent $sout "file received by server"
476	fi
477	rets=$?
478
479	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
480		cat "$capout"
481		return 0
482	fi
483
484	cat "$capout"
485	return 1
486}
487
488make_file()
489{
490	name=$1
491	who=$2
492	size=$3
493
494	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
495	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
496
497	echo "Created $name (size $size KB) containing data sent by $who"
498}
499
500run_tests()
501{
502	listener_ns="$1"
503	connector_ns="$2"
504	connect_addr="$3"
505	test_linkfail="${4:-0}"
506	addr_nr_ns1="${5:-0}"
507	addr_nr_ns2="${6:-0}"
508	speed="${7:-fast}"
509	bkup="${8:-""}"
510	lret=0
511	oldin=""
512
513	# create the input file for the failure test when
514	# the first failure test run
515	if [ "$test_linkfail" -ne 0 -a -z "$cinfail" ]; then
516		# the client file must be considerably larger
517		# of the maximum expected cwin value, or the
518		# link utilization will be not predicable
519		size=$((RANDOM%2))
520		size=$((size+1))
521		size=$((size*8192))
522		size=$((size + ( $RANDOM % 8192) ))
523
524		cinfail=$(mktemp)
525		make_file "$cinfail" "client" $size
526	fi
527
528	if [ "$test_linkfail" -eq 2 -a -z "$sinfail" ]; then
529		size=$((RANDOM%16))
530		size=$((size+1))
531		size=$((size*2048))
532
533		sinfail=$(mktemp)
534		make_file "$sinfail" "server" $size
535	fi
536
537	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
538		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${bkup}
539	lret=$?
540}
541
542chk_csum_nr()
543{
544	local msg=${1:-""}
545	local count
546	local dump_stats
547
548	if [ ! -z "$msg" ]; then
549		printf "%02u" "$TEST_COUNT"
550	else
551		echo -n "  "
552	fi
553	printf " %-36s %s" "$msg" "sum"
554	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
555	[ -z "$count" ] && count=0
556	if [ "$count" != 0 ]; then
557		echo "[fail] got $count data checksum error[s] expected 0"
558		ret=1
559		dump_stats=1
560	else
561		echo -n "[ ok ]"
562	fi
563	echo -n " - csum  "
564	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
565	[ -z "$count" ] && count=0
566	if [ "$count" != 0 ]; then
567		echo "[fail] got $count data checksum error[s] expected 0"
568		ret=1
569		dump_stats=1
570	else
571		echo "[ ok ]"
572	fi
573	if [ "${dump_stats}" = 1 ]; then
574		echo Server ns stats
575		ip netns exec $ns1 nstat -as | grep MPTcp
576		echo Client ns stats
577		ip netns exec $ns2 nstat -as | grep MPTcp
578	fi
579}
580
581chk_join_nr()
582{
583	local msg="$1"
584	local syn_nr=$2
585	local syn_ack_nr=$3
586	local ack_nr=$4
587	local count
588	local dump_stats
589
590	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
591	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
592	[ -z "$count" ] && count=0
593	if [ "$count" != "$syn_nr" ]; then
594		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
595		ret=1
596		dump_stats=1
597	else
598		echo -n "[ ok ]"
599	fi
600
601	echo -n " - synack"
602	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
603	[ -z "$count" ] && count=0
604	if [ "$count" != "$syn_ack_nr" ]; then
605		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
606		ret=1
607		dump_stats=1
608	else
609		echo -n "[ ok ]"
610	fi
611
612	echo -n " - ack"
613	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
614	[ -z "$count" ] && count=0
615	if [ "$count" != "$ack_nr" ]; then
616		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
617		ret=1
618		dump_stats=1
619	else
620		echo "[ ok ]"
621	fi
622	if [ "${dump_stats}" = 1 ]; then
623		echo Server ns stats
624		ip netns exec $ns1 nstat -as | grep MPTcp
625		echo Client ns stats
626		ip netns exec $ns2 nstat -as | grep MPTcp
627	fi
628	if [ $checksum -eq 1 ]; then
629		chk_csum_nr
630	fi
631}
632
633# a negative value for 'stale_max' means no upper bound:
634# for bidirectional transfer, if one peer sleep for a while
635# - as these tests do - we can have a quite high number of
636# stale/recover conversions, proportional to
637# sleep duration/ MPTCP-level RTX interval.
638chk_stale_nr()
639{
640	local ns=$1
641	local stale_min=$2
642	local stale_max=$3
643	local stale_delta=$4
644	local dump_stats
645	local stale_nr
646	local recover_nr
647
648	printf "%-39s %-18s" " " "stale"
649	stale_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}'`
650	[ -z "$stale_nr" ] && stale_nr=0
651	recover_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}'`
652	[ -z "$recover_nr" ] && recover_nr=0
653
654	if [ $stale_nr -lt $stale_min ] ||
655	   [ $stale_max -gt 0 -a $stale_nr -gt $stale_max ] ||
656	   [ $((stale_nr - $recover_nr)) -ne $stale_delta ]; then
657		echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \
658		     " expected stale in range [$stale_min..$stale_max]," \
659		     " stale-recover delta $stale_delta "
660		ret=1
661		dump_stats=1
662	else
663		echo "[ ok ]"
664	fi
665
666	if [ "${dump_stats}" = 1 ]; then
667		echo $ns stats
668		ip netns exec $ns ip -s link show
669		ip netns exec $ns nstat -as | grep MPTcp
670	fi
671}
672
673chk_add_nr()
674{
675	local add_nr=$1
676	local echo_nr=$2
677	local port_nr=${3:-0}
678	local syn_nr=${4:-$port_nr}
679	local syn_ack_nr=${5:-$port_nr}
680	local ack_nr=${6:-$port_nr}
681	local mis_syn_nr=${7:-0}
682	local mis_ack_nr=${8:-0}
683	local count
684	local dump_stats
685
686	printf "%-39s %s" " " "add"
687	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
688	[ -z "$count" ] && count=0
689	if [ "$count" != "$add_nr" ]; then
690		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
691		ret=1
692		dump_stats=1
693	else
694		echo -n "[ ok ]"
695	fi
696
697	echo -n " - echo  "
698	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
699	[ -z "$count" ] && count=0
700	if [ "$count" != "$echo_nr" ]; then
701		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
702		ret=1
703		dump_stats=1
704	else
705		echo -n "[ ok ]"
706	fi
707
708	if [ $port_nr -gt 0 ]; then
709		echo -n " - pt "
710		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
711		[ -z "$count" ] && count=0
712		if [ "$count" != "$port_nr" ]; then
713			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
714			ret=1
715			dump_stats=1
716		else
717			echo "[ ok ]"
718		fi
719
720		printf "%-39s %s" " " "syn"
721		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
722			awk '{print $2}'`
723		[ -z "$count" ] && count=0
724		if [ "$count" != "$syn_nr" ]; then
725			echo "[fail] got $count JOIN[s] syn with a different \
726				port-number expected $syn_nr"
727			ret=1
728			dump_stats=1
729		else
730			echo -n "[ ok ]"
731		fi
732
733		echo -n " - synack"
734		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
735			awk '{print $2}'`
736		[ -z "$count" ] && count=0
737		if [ "$count" != "$syn_ack_nr" ]; then
738			echo "[fail] got $count JOIN[s] synack with a different \
739				port-number expected $syn_ack_nr"
740			ret=1
741			dump_stats=1
742		else
743			echo -n "[ ok ]"
744		fi
745
746		echo -n " - ack"
747		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
748			awk '{print $2}'`
749		[ -z "$count" ] && count=0
750		if [ "$count" != "$ack_nr" ]; then
751			echo "[fail] got $count JOIN[s] ack with a different \
752				port-number expected $ack_nr"
753			ret=1
754			dump_stats=1
755		else
756			echo "[ ok ]"
757		fi
758
759		printf "%-39s %s" " " "syn"
760		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
761			awk '{print $2}'`
762		[ -z "$count" ] && count=0
763		if [ "$count" != "$mis_syn_nr" ]; then
764			echo "[fail] got $count JOIN[s] syn with a mismatched \
765				port-number expected $mis_syn_nr"
766			ret=1
767			dump_stats=1
768		else
769			echo -n "[ ok ]"
770		fi
771
772		echo -n " - ack   "
773		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
774			awk '{print $2}'`
775		[ -z "$count" ] && count=0
776		if [ "$count" != "$mis_ack_nr" ]; then
777			echo "[fail] got $count JOIN[s] ack with a mismatched \
778				port-number expected $mis_ack_nr"
779			ret=1
780			dump_stats=1
781		else
782			echo "[ ok ]"
783		fi
784	else
785		echo ""
786	fi
787
788	if [ "${dump_stats}" = 1 ]; then
789		echo Server ns stats
790		ip netns exec $ns1 nstat -as | grep MPTcp
791		echo Client ns stats
792		ip netns exec $ns2 nstat -as | grep MPTcp
793	fi
794}
795
796chk_rm_nr()
797{
798	local rm_addr_nr=$1
799	local rm_subflow_nr=$2
800	local invert=${3:-""}
801	local count
802	local dump_stats
803	local addr_ns
804	local subflow_ns
805
806	if [ -z $invert ]; then
807		addr_ns=$ns1
808		subflow_ns=$ns2
809	elif [ $invert = "invert" ]; then
810		addr_ns=$ns2
811		subflow_ns=$ns1
812	fi
813
814	printf "%-39s %s" " " "rm "
815	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
816	[ -z "$count" ] && count=0
817	if [ "$count" != "$rm_addr_nr" ]; then
818		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
819		ret=1
820		dump_stats=1
821	else
822		echo -n "[ ok ]"
823	fi
824
825	echo -n " - sf    "
826	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
827	[ -z "$count" ] && count=0
828	if [ "$count" != "$rm_subflow_nr" ]; then
829		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
830		ret=1
831		dump_stats=1
832	else
833		echo "[ ok ]"
834	fi
835
836	if [ "${dump_stats}" = 1 ]; then
837		echo Server ns stats
838		ip netns exec $ns1 nstat -as | grep MPTcp
839		echo Client ns stats
840		ip netns exec $ns2 nstat -as | grep MPTcp
841	fi
842}
843
844chk_prio_nr()
845{
846	local mp_prio_nr_tx=$1
847	local mp_prio_nr_rx=$2
848	local count
849	local dump_stats
850
851	printf "%-39s %s" " " "ptx"
852	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
853	[ -z "$count" ] && count=0
854	if [ "$count" != "$mp_prio_nr_tx" ]; then
855		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
856		ret=1
857		dump_stats=1
858	else
859		echo -n "[ ok ]"
860	fi
861
862	echo -n " - prx   "
863	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
864	[ -z "$count" ] && count=0
865	if [ "$count" != "$mp_prio_nr_rx" ]; then
866		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
867		ret=1
868		dump_stats=1
869	else
870		echo "[ ok ]"
871	fi
872
873	if [ "${dump_stats}" = 1 ]; then
874		echo Server ns stats
875		ip netns exec $ns1 nstat -as | grep MPTcp
876		echo Client ns stats
877		ip netns exec $ns2 nstat -as | grep MPTcp
878	fi
879}
880
881chk_link_usage()
882{
883	local ns=$1
884	local link=$2
885	local out=$3
886	local expected_rate=$4
887	local tx_link=`ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes`
888	local tx_total=`ls -l $out | awk '{print $5}'`
889	local tx_rate=$((tx_link * 100 / $tx_total))
890	local tolerance=5
891
892	printf "%-39s %-18s" " " "link usage"
893	if [ $tx_rate -lt $((expected_rate - $tolerance)) -o \
894	     $tx_rate -gt $((expected_rate + $tolerance)) ]; then
895		echo "[fail] got $tx_rate% usage, expected $expected_rate%"
896		ret=1
897	else
898		echo "[ ok ]"
899	fi
900}
901
902subflows_tests()
903{
904	reset
905	run_tests $ns1 $ns2 10.0.1.1
906	chk_join_nr "no JOIN" "0" "0" "0"
907
908	# subflow limited by client
909	reset
910	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
911	run_tests $ns1 $ns2 10.0.1.1
912	chk_join_nr "single subflow, limited by client" 0 0 0
913
914	# subflow limited by server
915	reset
916	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
917	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
918	run_tests $ns1 $ns2 10.0.1.1
919	chk_join_nr "single subflow, limited by server" 1 1 0
920
921	# subflow
922	reset
923	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
924	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
925	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
926	run_tests $ns1 $ns2 10.0.1.1
927	chk_join_nr "single subflow" 1 1 1
928
929	# multiple subflows
930	reset
931	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
932	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
933	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
934	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
935	run_tests $ns1 $ns2 10.0.1.1
936	chk_join_nr "multiple subflows" 2 2 2
937
938	# multiple subflows limited by serverf
939	reset
940	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
941	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
942	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
943	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
944	run_tests $ns1 $ns2 10.0.1.1
945	chk_join_nr "multiple subflows, limited by server" 2 2 1
946
947	# single subflow, dev
948	reset
949	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
950	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
951	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow dev ns2eth3
952	run_tests $ns1 $ns2 10.0.1.1
953	chk_join_nr "single subflow, dev" 1 1 1
954}
955
956signal_address_tests()
957{
958	# add_address, unused
959	reset
960	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
961	run_tests $ns1 $ns2 10.0.1.1
962	chk_join_nr "unused signal address" 0 0 0
963	chk_add_nr 1 1
964
965	# accept and use add_addr
966	reset
967	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
968	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
969	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
970	run_tests $ns1 $ns2 10.0.1.1
971	chk_join_nr "signal address" 1 1 1
972	chk_add_nr 1 1
973
974	# accept and use add_addr with an additional subflow
975	# note: signal address in server ns and local addresses in client ns must
976	# belong to different subnets or one of the listed local address could be
977	# used for 'add_addr' subflow
978	reset
979	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
980	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
981	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
982	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
983	run_tests $ns1 $ns2 10.0.1.1
984	chk_join_nr "subflow and signal" 2 2 2
985	chk_add_nr 1 1
986
987	# accept and use add_addr with additional subflows
988	reset
989	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
990	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
991	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
992	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
993	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
994	run_tests $ns1 $ns2 10.0.1.1
995	chk_join_nr "multiple subflows and signal" 3 3 3
996	chk_add_nr 1 1
997
998	# signal addresses
999	reset
1000	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1001	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1002	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1003	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1004	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1005	run_tests $ns1 $ns2 10.0.1.1
1006	chk_join_nr "signal addresses" 3 3 3
1007	chk_add_nr 3 3
1008
1009	# signal invalid addresses
1010	reset
1011	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1012	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1013	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1014	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1015	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1016	run_tests $ns1 $ns2 10.0.1.1
1017	chk_join_nr "signal invalid addresses" 1 1 1
1018	chk_add_nr 3 3
1019}
1020
1021link_failure_tests()
1022{
1023	# accept and use add_addr with additional subflows and link loss
1024	reset
1025
1026	# without any b/w limit each veth could spool the packets and get
1027	# them acked at xmit time, so that the corresponding subflow will
1028	# have almost always no outstanding pkts, the scheduler will pick
1029	# always the first subflow and we will have hard time testing
1030	# active backup and link switch-over.
1031	# Let's set some arbitrary (low) virtual link limits.
1032	init_shapers
1033	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1034	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1035	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1036	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
1037	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
1038	run_tests $ns1 $ns2 10.0.1.1 1
1039	chk_join_nr "multiple flows, signal, link failure" 3 3 3
1040	chk_add_nr 1 1
1041	chk_stale_nr $ns2 1 5 1
1042
1043	# accept and use add_addr with additional subflows and link loss
1044	# for bidirectional transfer
1045	reset
1046	init_shapers
1047	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1048	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1049	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1050	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
1051	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
1052	run_tests $ns1 $ns2 10.0.1.1 2
1053	chk_join_nr "multi flows, signal, bidi, link fail" 3 3 3
1054	chk_add_nr 1 1
1055	chk_stale_nr $ns2 1 -1 1
1056
1057	# 2 subflows plus 1 backup subflow with a lossy link, backup
1058	# will never be used
1059	reset
1060	init_shapers
1061	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1062	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1063	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1064	export FAILING_LINKS="1"
1065	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1066	run_tests $ns1 $ns2 10.0.1.1 1
1067	chk_join_nr "backup subflow unused, link failure" 2 2 2
1068	chk_add_nr 1 1
1069	chk_link_usage $ns2 ns2eth3 $cinsent 0
1070
1071	# 2 lossy links after half transfer, backup will get half of
1072	# the traffic
1073	reset
1074	init_shapers
1075	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1076	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1077	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1078	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1079	export FAILING_LINKS="1 2"
1080	run_tests $ns1 $ns2 10.0.1.1 1
1081	chk_join_nr "backup flow used, multi links fail" 2 2 2
1082	chk_add_nr 1 1
1083	chk_stale_nr $ns2 2 4 2
1084	chk_link_usage $ns2 ns2eth3 $cinsent 50
1085
1086	# use a backup subflow with the first subflow on a lossy link
1087	# for bidirectional transfer
1088	reset
1089	init_shapers
1090	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1091	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1092	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1093	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1094	run_tests $ns1 $ns2 10.0.1.1 2
1095	chk_join_nr "backup flow used, bidi, link failure" 2 2 2
1096	chk_add_nr 1 1
1097	chk_stale_nr $ns2 1 -1 2
1098	chk_link_usage $ns2 ns2eth3 $cinsent 50
1099}
1100
1101add_addr_timeout_tests()
1102{
1103	# add_addr timeout
1104	reset_with_add_addr_timeout
1105	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1106	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1107	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1108	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1109	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
1110	chk_add_nr 4 0
1111
1112	# add_addr timeout IPv6
1113	reset_with_add_addr_timeout 6
1114	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1115	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1116	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1117	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1118	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
1119	chk_add_nr 4 0
1120
1121	# signal addresses timeout
1122	reset_with_add_addr_timeout
1123	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1124	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1125	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1126	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1127	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
1128	chk_join_nr "signal addresses, ADD_ADDR timeout" 2 2 2
1129	chk_add_nr 8 0
1130
1131	# signal invalid addresses timeout
1132	reset_with_add_addr_timeout
1133	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1134	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1135	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1136	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1137	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
1138	chk_join_nr "invalid address, ADD_ADDR timeout" 1 1 1
1139	chk_add_nr 8 0
1140}
1141
1142remove_tests()
1143{
1144	# single subflow, remove
1145	reset
1146	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1147	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1148	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1149	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
1150	chk_join_nr "remove single subflow" 1 1 1
1151	chk_rm_nr 1 1
1152
1153	# multiple subflows, remove
1154	reset
1155	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1156	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1157	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
1158	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1159	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
1160	chk_join_nr "remove multiple subflows" 2 2 2
1161	chk_rm_nr 2 2
1162
1163	# single address, remove
1164	reset
1165	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1166	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1167	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1168	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1169	chk_join_nr "remove single address" 1 1 1
1170	chk_add_nr 1 1
1171	chk_rm_nr 1 1 invert
1172
1173	# subflow and signal, remove
1174	reset
1175	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1176	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1177	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1178	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1179	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1180	chk_join_nr "remove subflow and signal" 2 2 2
1181	chk_add_nr 1 1
1182	chk_rm_nr 1 1
1183
1184	# subflows and signal, remove
1185	reset
1186	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1187	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1188	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1189	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1190	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1191	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
1192	chk_join_nr "remove subflows and signal" 3 3 3
1193	chk_add_nr 1 1
1194	chk_rm_nr 2 2
1195
1196	# addresses remove
1197	reset
1198	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1199	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1200	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1201	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1202	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1203	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1204	chk_join_nr "remove addresses" 3 3 3
1205	chk_add_nr 3 3
1206	chk_rm_nr 3 3 invert
1207
1208	# invalid addresses remove
1209	reset
1210	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1211	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1212	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1213	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1214	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1215	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1216	chk_join_nr "remove invalid addresses" 1 1 1
1217	chk_add_nr 3 3
1218	chk_rm_nr 3 1 invert
1219
1220	# subflows and signal, flush
1221	reset
1222	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1223	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1224	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1225	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1226	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1227	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1228	chk_join_nr "flush subflows and signal" 3 3 3
1229	chk_add_nr 1 1
1230	chk_rm_nr 2 2
1231
1232	# subflows flush
1233	reset
1234	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1235	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1236	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow id 150
1237	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1238	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1239	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1240	chk_join_nr "flush subflows" 3 3 3
1241	chk_rm_nr 3 3
1242
1243	# addresses flush
1244	reset
1245	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1246	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1247	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1248	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1249	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1250	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1251	chk_join_nr "flush addresses" 3 3 3
1252	chk_add_nr 3 3
1253	chk_rm_nr 3 3 invert
1254
1255	# invalid addresses flush
1256	reset
1257	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1258	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1259	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1260	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1261	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1262	run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
1263	chk_join_nr "flush invalid addresses" 1 1 1
1264	chk_add_nr 3 3
1265	chk_rm_nr 3 1 invert
1266
1267	# remove id 0 subflow
1268	reset
1269	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1270	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1271	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1272	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
1273	chk_join_nr "remove id 0 subflow" 1 1 1
1274	chk_rm_nr 1 1
1275
1276	# remove id 0 address
1277	reset
1278	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1279	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1280	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1281	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
1282	chk_join_nr "remove id 0 address" 1 1 1
1283	chk_add_nr 1 1
1284	chk_rm_nr 1 1 invert
1285}
1286
1287add_tests()
1288{
1289	# add single subflow
1290	reset
1291	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1292	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1293	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
1294	chk_join_nr "add single subflow" 1 1 1
1295
1296	# add signal address
1297	reset
1298	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1299	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1300	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
1301	chk_join_nr "add signal address" 1 1 1
1302	chk_add_nr 1 1
1303
1304	# add multiple subflows
1305	reset
1306	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1307	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1308	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
1309	chk_join_nr "add multiple subflows" 2 2 2
1310
1311	# add multiple subflows IPv6
1312	reset
1313	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1314	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1315	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
1316	chk_join_nr "add multiple subflows IPv6" 2 2 2
1317
1318	# add multiple addresses IPv6
1319	reset
1320	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1321	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1322	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
1323	chk_join_nr "add multiple addresses IPv6" 2 2 2
1324	chk_add_nr 2 2
1325}
1326
1327ipv6_tests()
1328{
1329	# subflow IPv6
1330	reset
1331	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1332	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1333	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
1334	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1335	chk_join_nr "single subflow IPv6" 1 1 1
1336
1337	# add_address, unused IPv6
1338	reset
1339	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1340	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1341	chk_join_nr "unused signal address IPv6" 0 0 0
1342	chk_add_nr 1 1
1343
1344	# signal address IPv6
1345	reset
1346	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1347	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1348	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1349	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1350	chk_join_nr "single address IPv6" 1 1 1
1351	chk_add_nr 1 1
1352
1353	# single address IPv6, remove
1354	reset
1355	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1356	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1357	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1358	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
1359	chk_join_nr "remove single address IPv6" 1 1 1
1360	chk_add_nr 1 1
1361	chk_rm_nr 1 1 invert
1362
1363	# subflow and signal IPv6, remove
1364	reset
1365	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1366	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1367	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1368	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
1369	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
1370	chk_join_nr "remove subflow and signal IPv6" 2 2 2
1371	chk_add_nr 1 1
1372	chk_rm_nr 1 1
1373}
1374
1375v4mapped_tests()
1376{
1377	# subflow IPv4-mapped to IPv4-mapped
1378	reset
1379	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1380	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1381	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1382	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1383	chk_join_nr "single subflow IPv4-mapped" 1 1 1
1384
1385	# signal address IPv4-mapped with IPv4-mapped sk
1386	reset
1387	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1388	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1389	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1390	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1391	chk_join_nr "signal address IPv4-mapped" 1 1 1
1392	chk_add_nr 1 1
1393
1394	# subflow v4-map-v6
1395	reset
1396	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1397	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1398	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1399	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1400	chk_join_nr "single subflow v4-map-v6" 1 1 1
1401
1402	# signal address v4-map-v6
1403	reset
1404	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1405	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1406	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1407	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1408	chk_join_nr "signal address v4-map-v6" 1 1 1
1409	chk_add_nr 1 1
1410
1411	# subflow v6-map-v4
1412	reset
1413	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1414	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1415	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1416	run_tests $ns1 $ns2 10.0.1.1
1417	chk_join_nr "single subflow v6-map-v4" 1 1 1
1418
1419	# signal address v6-map-v4
1420	reset
1421	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1422	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1423	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1424	run_tests $ns1 $ns2 10.0.1.1
1425	chk_join_nr "signal address v6-map-v4" 1 1 1
1426	chk_add_nr 1 1
1427
1428	# no subflow IPv6 to v4 address
1429	reset
1430	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1431	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1432	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::2 flags subflow
1433	run_tests $ns1 $ns2 10.0.1.1
1434	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1435
1436	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1437	reset
1438	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1439	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1440	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::10.0.3.2 flags subflow
1441	run_tests $ns1 $ns2 10.0.1.1
1442	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
1443
1444	# no subflow IPv4 to v6 address, no need to slow down too then
1445	reset
1446	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1447	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1448	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1449	run_tests $ns1 $ns2 dead:beef:1::1
1450	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
1451}
1452
1453backup_tests()
1454{
1455	# single subflow, backup
1456	reset
1457	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1458	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1459	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,backup
1460	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
1461	chk_join_nr "single subflow, backup" 1 1 1
1462	chk_prio_nr 0 1
1463
1464	# single address, backup
1465	reset
1466	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1467	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1468	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1469	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
1470	chk_join_nr "single address, backup" 1 1 1
1471	chk_add_nr 1 1
1472	chk_prio_nr 1 0
1473}
1474
1475add_addr_ports_tests()
1476{
1477	# signal address with port
1478	reset
1479	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1480	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1481	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1482	run_tests $ns1 $ns2 10.0.1.1
1483	chk_join_nr "signal address with port" 1 1 1
1484	chk_add_nr 1 1 1
1485
1486	# subflow and signal with port
1487	reset
1488	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1489	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1490	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1491	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1492	run_tests $ns1 $ns2 10.0.1.1
1493	chk_join_nr "subflow and signal with port" 2 2 2
1494	chk_add_nr 1 1 1
1495
1496	# single address with port, remove
1497	reset
1498	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1499	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1500	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1501	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1502	chk_join_nr "remove single address with port" 1 1 1
1503	chk_add_nr 1 1 1
1504	chk_rm_nr 1 1 invert
1505
1506	# subflow and signal with port, remove
1507	reset
1508	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1509	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1510	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1511	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1512	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1513	chk_join_nr "remove subflow and signal with port" 2 2 2
1514	chk_add_nr 1 1 1
1515	chk_rm_nr 1 1
1516
1517	# subflows and signal with port, flush
1518	reset
1519	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1520	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1521	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1522	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1523	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1524	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1525	chk_join_nr "flush subflows and signal with port" 3 3 3
1526	chk_add_nr 1 1
1527	chk_rm_nr 2 2
1528
1529	# multiple addresses with port
1530	reset
1531	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1532	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1533	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100
1534	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1535	run_tests $ns1 $ns2 10.0.1.1
1536	chk_join_nr "multiple addresses with port" 2 2 2
1537	chk_add_nr 2 2 2
1538
1539	# multiple addresses with ports
1540	reset
1541	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1542	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
1543	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101
1544	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1545	run_tests $ns1 $ns2 10.0.1.1
1546	chk_join_nr "multiple addresses with ports" 2 2 2
1547	chk_add_nr 2 2 2
1548}
1549
1550syncookies_tests()
1551{
1552	# single subflow, syncookies
1553	reset_with_cookies
1554	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1555	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1556	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1557	run_tests $ns1 $ns2 10.0.1.1
1558	chk_join_nr "single subflow with syn cookies" 1 1 1
1559
1560	# multiple subflows with syn cookies
1561	reset_with_cookies
1562	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1563	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1564	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1565	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
1566	run_tests $ns1 $ns2 10.0.1.1
1567	chk_join_nr "multiple subflows with syn cookies" 2 2 2
1568
1569	# multiple subflows limited by server
1570	reset_with_cookies
1571	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1572	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1573	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1574	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
1575	run_tests $ns1 $ns2 10.0.1.1
1576	chk_join_nr "subflows limited by server w cookies" 2 1 1
1577
1578	# test signal address with cookies
1579	reset_with_cookies
1580	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1581	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1582	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1583	run_tests $ns1 $ns2 10.0.1.1
1584	chk_join_nr "signal address with syn cookies" 1 1 1
1585	chk_add_nr 1 1
1586
1587	# test cookie with subflow and signal
1588	reset_with_cookies
1589	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1590	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1591	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1592	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1593	run_tests $ns1 $ns2 10.0.1.1
1594	chk_join_nr "subflow and signal w cookies" 2 2 2
1595	chk_add_nr 1 1
1596
1597	# accept and use add_addr with additional subflows
1598	reset_with_cookies
1599	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1600	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1601	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1602	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1603	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1604	run_tests $ns1 $ns2 10.0.1.1
1605	chk_join_nr "subflows and signal w. cookies" 3 3 3
1606	chk_add_nr 1 1
1607}
1608
1609checksum_tests()
1610{
1611	# checksum test 0 0
1612	reset_with_checksum 0 0
1613	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1614	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1615	run_tests $ns1 $ns2 10.0.1.1
1616	chk_csum_nr "checksum test 0 0"
1617
1618	# checksum test 1 1
1619	reset_with_checksum 1 1
1620	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1621	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1622	run_tests $ns1 $ns2 10.0.1.1
1623	chk_csum_nr "checksum test 1 1"
1624
1625	# checksum test 0 1
1626	reset_with_checksum 0 1
1627	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1628	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1629	run_tests $ns1 $ns2 10.0.1.1
1630	chk_csum_nr "checksum test 0 1"
1631
1632	# checksum test 1 0
1633	reset_with_checksum 1 0
1634	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1635	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1636	run_tests $ns1 $ns2 10.0.1.1
1637	chk_csum_nr "checksum test 1 0"
1638}
1639
1640deny_join_id0_tests()
1641{
1642	# subflow allow join id0 ns1
1643	reset_with_allow_join_id0 1 0
1644	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
1645	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1646	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1647	run_tests $ns1 $ns2 10.0.1.1
1648	chk_join_nr "single subflow allow join id0 ns1" 1 1 1
1649
1650	# subflow allow join id0 ns2
1651	reset_with_allow_join_id0 0 1
1652	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
1653	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1654	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1655	run_tests $ns1 $ns2 10.0.1.1
1656	chk_join_nr "single subflow allow join id0 ns2" 0 0 0
1657
1658	# signal address allow join id0 ns1
1659	# ADD_ADDRs are not affected by allow_join_id0 value.
1660	reset_with_allow_join_id0 1 0
1661	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
1662	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1663	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1664	run_tests $ns1 $ns2 10.0.1.1
1665	chk_join_nr "signal address allow join id0 ns1" 1 1 1
1666	chk_add_nr 1 1
1667
1668	# signal address allow join id0 ns2
1669	# ADD_ADDRs are not affected by allow_join_id0 value.
1670	reset_with_allow_join_id0 0 1
1671	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
1672	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1673	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1674	run_tests $ns1 $ns2 10.0.1.1
1675	chk_join_nr "signal address allow join id0 ns2" 1 1 1
1676	chk_add_nr 1 1
1677
1678	# subflow and address allow join id0 ns1
1679	reset_with_allow_join_id0 1 0
1680	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1681	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1682	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1683	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1684	run_tests $ns1 $ns2 10.0.1.1
1685	chk_join_nr "subflow and address allow join id0 1" 2 2 2
1686
1687	# subflow and address allow join id0 ns2
1688	reset_with_allow_join_id0 0 1
1689	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
1690	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
1691	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1692	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1693	run_tests $ns1 $ns2 10.0.1.1
1694	chk_join_nr "subflow and address allow join id0 2" 1 1 1
1695}
1696
1697fullmesh_tests()
1698{
1699	# fullmesh 1
1700	# 2 fullmesh addrs in ns2, added before the connection,
1701	# 1 non-fullmesh addr in ns1, added during the connection.
1702	reset
1703	ip netns exec $ns1 ./pm_nl_ctl limits 0 4
1704	ip netns exec $ns2 ./pm_nl_ctl limits 1 4
1705	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow,fullmesh
1706	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,fullmesh
1707	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
1708	chk_join_nr "fullmesh test 2x1" 4 4 4
1709	chk_add_nr 1 1
1710
1711	# fullmesh 2
1712	# 1 non-fullmesh addr in ns1, added before the connection,
1713	# 1 fullmesh addr in ns2, added during the connection.
1714	reset
1715	ip netns exec $ns1 ./pm_nl_ctl limits 1 3
1716	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1717	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1718	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow
1719	chk_join_nr "fullmesh test 1x1" 3 3 3
1720	chk_add_nr 1 1
1721
1722	# fullmesh 3
1723	# 1 non-fullmesh addr in ns1, added before the connection,
1724	# 2 fullmesh addrs in ns2, added during the connection.
1725	reset
1726	ip netns exec $ns1 ./pm_nl_ctl limits 2 5
1727	ip netns exec $ns2 ./pm_nl_ctl limits 1 5
1728	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1729	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
1730	chk_join_nr "fullmesh test 1x2" 5 5 5
1731	chk_add_nr 1 1
1732
1733	# fullmesh 4
1734	# 1 non-fullmesh addr in ns1, added before the connection,
1735	# 2 fullmesh addrs in ns2, added during the connection,
1736	# limit max_subflows to 4.
1737	reset
1738	ip netns exec $ns1 ./pm_nl_ctl limits 2 4
1739	ip netns exec $ns2 ./pm_nl_ctl limits 1 4
1740	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1741	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
1742	chk_join_nr "fullmesh test 1x2, limited" 4 4 4
1743	chk_add_nr 1 1
1744}
1745
1746all_tests()
1747{
1748	subflows_tests
1749	signal_address_tests
1750	link_failure_tests
1751	add_addr_timeout_tests
1752	remove_tests
1753	add_tests
1754	ipv6_tests
1755	v4mapped_tests
1756	backup_tests
1757	add_addr_ports_tests
1758	syncookies_tests
1759	checksum_tests
1760	deny_join_id0_tests
1761	fullmesh_tests
1762}
1763
1764usage()
1765{
1766	echo "mptcp_join usage:"
1767	echo "  -f subflows_tests"
1768	echo "  -s signal_address_tests"
1769	echo "  -l link_failure_tests"
1770	echo "  -t add_addr_timeout_tests"
1771	echo "  -r remove_tests"
1772	echo "  -a add_tests"
1773	echo "  -6 ipv6_tests"
1774	echo "  -4 v4mapped_tests"
1775	echo "  -b backup_tests"
1776	echo "  -p add_addr_ports_tests"
1777	echo "  -k syncookies_tests"
1778	echo "  -S checksum_tests"
1779	echo "  -d deny_join_id0_tests"
1780	echo "  -m fullmesh_tests"
1781	echo "  -c capture pcap files"
1782	echo "  -C enable data checksum"
1783	echo "  -h help"
1784}
1785
1786sin=$(mktemp)
1787sout=$(mktemp)
1788cin=$(mktemp)
1789cinsent=$(mktemp)
1790cout=$(mktemp)
1791init
1792make_file "$cin" "client" 1
1793make_file "$sin" "server" 1
1794trap cleanup EXIT
1795
1796for arg in "$@"; do
1797	# check for "capture/checksum" args before launching tests
1798	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"c"[0-9a-zA-Z]*$ ]]; then
1799		capture=1
1800	fi
1801	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"C"[0-9a-zA-Z]*$ ]]; then
1802		checksum=1
1803	fi
1804
1805	# exception for the capture/checksum options, the rest means: a part of the tests
1806	if [ "${arg}" != "-c" ] && [ "${arg}" != "-C" ]; then
1807		do_all_tests=0
1808	fi
1809done
1810
1811if [ $do_all_tests -eq 1 ]; then
1812	all_tests
1813	exit $ret
1814fi
1815
1816while getopts 'fsltra64bpkdmchCS' opt; do
1817	case $opt in
1818		f)
1819			subflows_tests
1820			;;
1821		s)
1822			signal_address_tests
1823			;;
1824		l)
1825			link_failure_tests
1826			;;
1827		t)
1828			add_addr_timeout_tests
1829			;;
1830		r)
1831			remove_tests
1832			;;
1833		a)
1834			add_tests
1835			;;
1836		6)
1837			ipv6_tests
1838			;;
1839		4)
1840			v4mapped_tests
1841			;;
1842		b)
1843			backup_tests
1844			;;
1845		p)
1846			add_addr_ports_tests
1847			;;
1848		k)
1849			syncookies_tests
1850			;;
1851		S)
1852			checksum_tests
1853			;;
1854		d)
1855			deny_join_id0_tests
1856			;;
1857		m)
1858			fullmesh_tests
1859			;;
1860		c)
1861			;;
1862		C)
1863			;;
1864		h | *)
1865			usage
1866			;;
1867	esac
1868done
1869
1870exit $ret
1871