1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4b08fbf24SPaolo Abeniret=0
5b08fbf24SPaolo Abenisin=""
6*7d1e6f16SPaolo Abenisinfail=""
7b08fbf24SPaolo Abenisout=""
8b08fbf24SPaolo Abenicin=""
9*7d1e6f16SPaolo Abenicinfail=""
108b819a84SFlorian Westphalcinsent=""
11b08fbf24SPaolo Abenicout=""
12b08fbf24SPaolo Abeniksft_skip=4
135888a61cSMatthieu Baertstimeout_poll=30
145888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1))
15dd72b0feSGeliang Tangmptcp_connect=""
16b08fbf24SPaolo Abenicapture=0
17af66d3e1SGeliang Tangchecksum=0
18a673321aSMat Martineaudo_all_tests=1
19b08fbf24SPaolo Abeni
20b08fbf24SPaolo AbeniTEST_COUNT=0
21b08fbf24SPaolo Abeni
228d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
238d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
248d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
258d014eaaSGeliang Tang			       48 0 0 0,
268d014eaaSGeliang Tang			       84 0 0 240,
278d014eaaSGeliang Tang			       21 0 3 64,
288d014eaaSGeliang Tang			       48 0 0 54,
298d014eaaSGeliang Tang			       84 0 0 240,
308d014eaaSGeliang Tang			       21 6 7 48,
318d014eaaSGeliang Tang			       48 0 0 0,
328d014eaaSGeliang Tang			       84 0 0 240,
338d014eaaSGeliang Tang			       21 0 4 96,
348d014eaaSGeliang Tang			       48 0 0 74,
358d014eaaSGeliang Tang			       84 0 0 240,
368d014eaaSGeliang Tang			       21 0 1 48,
378d014eaaSGeliang Tang			       6 0 0 65535,
388d014eaaSGeliang Tang			       6 0 0 0"
398d014eaaSGeliang Tang
40b08fbf24SPaolo Abeniinit()
41b08fbf24SPaolo Abeni{
42b08fbf24SPaolo Abeni	capout=$(mktemp)
43b08fbf24SPaolo Abeni
44b08fbf24SPaolo Abeni	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
45b08fbf24SPaolo Abeni
46b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
47b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
48b08fbf24SPaolo Abeni
49b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2";do
50b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
51b08fbf24SPaolo Abeni		ip -net $netns link set lo up
52b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
53b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
54b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
55af66d3e1SGeliang Tang		if [ $checksum -eq 1 ]; then
56af66d3e1SGeliang Tang			ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
57af66d3e1SGeliang Tang		fi
58b08fbf24SPaolo Abeni	done
59b08fbf24SPaolo Abeni
60b08fbf24SPaolo Abeni	#  ns1              ns2
61b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
62b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
63b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
64b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
65b08fbf24SPaolo Abeni
66b08fbf24SPaolo Abeni	for i in `seq 1 4`; do
67b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
68b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
69b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
70b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
71b08fbf24SPaolo Abeni
72b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
73b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
74b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
75b08fbf24SPaolo Abeni
76b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
77b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
78b08fbf24SPaolo Abeni	done
79b08fbf24SPaolo Abeni}
80b08fbf24SPaolo Abeni
81*7d1e6f16SPaolo Abeniinit_shapers()
82*7d1e6f16SPaolo Abeni{
83*7d1e6f16SPaolo Abeni	for i in `seq 1 4`; do
84*7d1e6f16SPaolo Abeni		tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
85*7d1e6f16SPaolo Abeni		tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
86*7d1e6f16SPaolo Abeni	done
87*7d1e6f16SPaolo Abeni}
88*7d1e6f16SPaolo Abeni
89b08fbf24SPaolo Abenicleanup_partial()
90b08fbf24SPaolo Abeni{
91b08fbf24SPaolo Abeni	rm -f "$capout"
92b08fbf24SPaolo Abeni
93b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
94b08fbf24SPaolo Abeni		ip netns del $netns
95c2a55e8fSMatthieu Baerts		rm -f /tmp/$netns.{nstat,out}
96b08fbf24SPaolo Abeni	done
97b08fbf24SPaolo Abeni}
98b08fbf24SPaolo Abeni
99b08fbf24SPaolo Abenicleanup()
100b08fbf24SPaolo Abeni{
101*7d1e6f16SPaolo Abeni	rm -f "$cin" "$cout" "$sinfail"
102*7d1e6f16SPaolo Abeni	rm -f "$sin" "$sout" "$cinsent" "$cinfail"
103b08fbf24SPaolo Abeni	cleanup_partial
104b08fbf24SPaolo Abeni}
105b08fbf24SPaolo Abeni
106b08fbf24SPaolo Abenireset()
107b08fbf24SPaolo Abeni{
108b08fbf24SPaolo Abeni	cleanup_partial
109b08fbf24SPaolo Abeni	init
110b08fbf24SPaolo Abeni}
111b08fbf24SPaolo Abeni
11200587187SFlorian Westphalreset_with_cookies()
11300587187SFlorian Westphal{
11400587187SFlorian Westphal	reset
11500587187SFlorian Westphal
11600587187SFlorian Westphal	for netns in "$ns1" "$ns2";do
11700587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
11800587187SFlorian Westphal	done
11900587187SFlorian Westphal}
12000587187SFlorian Westphal
1218d014eaaSGeliang Tangreset_with_add_addr_timeout()
1228d014eaaSGeliang Tang{
1238d014eaaSGeliang Tang	local ip="${1:-4}"
1248d014eaaSGeliang Tang	local tables
1258d014eaaSGeliang Tang
1268d014eaaSGeliang Tang	tables="iptables"
1278d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
1288d014eaaSGeliang Tang		tables="ip6tables"
1298d014eaaSGeliang Tang	fi
1308d014eaaSGeliang Tang
1318d014eaaSGeliang Tang	reset
1328d014eaaSGeliang Tang
1338d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
1348d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
1358d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
1368d014eaaSGeliang Tang		-m bpf --bytecode \
1378d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
1388d014eaaSGeliang Tang		-j DROP
1398d014eaaSGeliang Tang}
1408d014eaaSGeliang Tang
141af66d3e1SGeliang Tangreset_with_checksum()
142af66d3e1SGeliang Tang{
143af66d3e1SGeliang Tang	local ns1_enable=$1
144af66d3e1SGeliang Tang	local ns2_enable=$2
145af66d3e1SGeliang Tang
146af66d3e1SGeliang Tang	reset
147af66d3e1SGeliang Tang
148af66d3e1SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
149af66d3e1SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
150af66d3e1SGeliang Tang}
151af66d3e1SGeliang Tang
1520cddb4a6SGeliang Tangreset_with_allow_join_id0()
1530cddb4a6SGeliang Tang{
1540cddb4a6SGeliang Tang	local ns1_enable=$1
1550cddb4a6SGeliang Tang	local ns2_enable=$2
1560cddb4a6SGeliang Tang
1570cddb4a6SGeliang Tang	reset
1580cddb4a6SGeliang Tang
1590cddb4a6SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
1600cddb4a6SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
1610cddb4a6SGeliang Tang}
1620cddb4a6SGeliang Tang
163b08fbf24SPaolo Abeniip -Version > /dev/null 2>&1
164b08fbf24SPaolo Abeniif [ $? -ne 0 ];then
165b08fbf24SPaolo Abeni	echo "SKIP: Could not run test without ip tool"
166b08fbf24SPaolo Abeni	exit $ksft_skip
167b08fbf24SPaolo Abenifi
168b08fbf24SPaolo Abeni
1698d014eaaSGeliang Tangiptables -V > /dev/null 2>&1
1708d014eaaSGeliang Tangif [ $? -ne 0 ];then
1718d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without iptables tool"
1728d014eaaSGeliang Tang	exit $ksft_skip
1738d014eaaSGeliang Tangfi
1748d014eaaSGeliang Tang
1758d014eaaSGeliang Tangip6tables -V > /dev/null 2>&1
1768d014eaaSGeliang Tangif [ $? -ne 0 ];then
1778d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without ip6tables tool"
1788d014eaaSGeliang Tang	exit $ksft_skip
1798d014eaaSGeliang Tangfi
180b08fbf24SPaolo Abeni
1818b819a84SFlorian Westphalprint_file_err()
1828b819a84SFlorian Westphal{
1838b819a84SFlorian Westphal	ls -l "$1" 1>&2
1848b819a84SFlorian Westphal	echo "Trailing bytes are: "
1858b819a84SFlorian Westphal	tail -c 27 "$1"
1868b819a84SFlorian Westphal}
1878b819a84SFlorian Westphal
188b08fbf24SPaolo Abenicheck_transfer()
189b08fbf24SPaolo Abeni{
190b08fbf24SPaolo Abeni	in=$1
191b08fbf24SPaolo Abeni	out=$2
192b08fbf24SPaolo Abeni	what=$3
193b08fbf24SPaolo Abeni
194b08fbf24SPaolo Abeni	cmp "$in" "$out" > /dev/null 2>&1
195b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ;then
196b08fbf24SPaolo Abeni		echo "[ FAIL ] $what does not match (in, out):"
197b08fbf24SPaolo Abeni		print_file_err "$in"
198b08fbf24SPaolo Abeni		print_file_err "$out"
1998b819a84SFlorian Westphal		ret=1
200b08fbf24SPaolo Abeni
201b08fbf24SPaolo Abeni		return 1
202b08fbf24SPaolo Abeni	fi
203b08fbf24SPaolo Abeni
204b08fbf24SPaolo Abeni	return 0
205b08fbf24SPaolo Abeni}
206b08fbf24SPaolo Abeni
207b08fbf24SPaolo Abenido_ping()
208b08fbf24SPaolo Abeni{
209b08fbf24SPaolo Abeni	listener_ns="$1"
210b08fbf24SPaolo Abeni	connector_ns="$2"
211b08fbf24SPaolo Abeni	connect_addr="$3"
212b08fbf24SPaolo Abeni
213b08fbf24SPaolo Abeni	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
214b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ; then
215b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
216b08fbf24SPaolo Abeni		ret=1
217b08fbf24SPaolo Abeni	fi
218b08fbf24SPaolo Abeni}
219b08fbf24SPaolo Abeni
2208b819a84SFlorian Westphallink_failure()
2218b819a84SFlorian Westphal{
2228b819a84SFlorian Westphal	ns="$1"
2238b819a84SFlorian Westphal
224*7d1e6f16SPaolo Abeni	if [ -z "$FAILING_LINKS" ]; then
2258b819a84SFlorian Westphal		l=$((RANDOM%4))
226*7d1e6f16SPaolo Abeni		FAILING_LINKS=$((l+1))
227*7d1e6f16SPaolo Abeni	fi
2288b819a84SFlorian Westphal
229*7d1e6f16SPaolo Abeni	for l in $FAILING_LINKS; do
2308b819a84SFlorian Westphal		veth="ns1eth$l"
2318b819a84SFlorian Westphal		ip -net "$ns" link set "$veth" down
232*7d1e6f16SPaolo Abeni	done
2338b819a84SFlorian Westphal}
2348b819a84SFlorian Westphal
235523514edSGeliang Tang# $1: IP address
236523514edSGeliang Tangis_v6()
237523514edSGeliang Tang{
238523514edSGeliang Tang	[ -z "${1##*:*}" ]
239523514edSGeliang Tang}
240523514edSGeliang Tang
241b08fbf24SPaolo Abenido_transfer()
242b08fbf24SPaolo Abeni{
243b08fbf24SPaolo Abeni	listener_ns="$1"
244b08fbf24SPaolo Abeni	connector_ns="$2"
245b08fbf24SPaolo Abeni	cl_proto="$3"
246b08fbf24SPaolo Abeni	srv_proto="$4"
247b08fbf24SPaolo Abeni	connect_addr="$5"
2488b819a84SFlorian Westphal	test_link_fail="$6"
2492e8cbf45SGeliang Tang	addr_nr_ns1="$7"
2502e8cbf45SGeliang Tang	addr_nr_ns2="$8"
2518b819a84SFlorian Westphal	speed="$9"
252718eb44eSGeliang Tang	bkup="${10}"
253b08fbf24SPaolo Abeni
254b08fbf24SPaolo Abeni	port=$((10000+$TEST_COUNT))
255b08fbf24SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
256b08fbf24SPaolo Abeni
257b08fbf24SPaolo Abeni	:> "$cout"
258b08fbf24SPaolo Abeni	:> "$sout"
259b08fbf24SPaolo Abeni	:> "$capout"
260b08fbf24SPaolo Abeni
261b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
262b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
263b08fbf24SPaolo Abeni			capuser=""
264b08fbf24SPaolo Abeni		else
265b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
266b08fbf24SPaolo Abeni		fi
267b08fbf24SPaolo Abeni
26800587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
269b08fbf24SPaolo Abeni
270b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
271b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
272b08fbf24SPaolo Abeni		cappid=$!
273b08fbf24SPaolo Abeni
274b08fbf24SPaolo Abeni		sleep 1
275b08fbf24SPaolo Abeni	fi
276b08fbf24SPaolo Abeni
277c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
278c2a55e8fSMatthieu Baerts		nstat -n
279c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
280c2a55e8fSMatthieu Baerts		nstat -n
281c2a55e8fSMatthieu Baerts
2828d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
283dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -j"
2848da6229bSGeliang Tang	elif [ $speed = "slow" ]; then
2858da6229bSGeliang Tang		mptcp_connect="./mptcp_connect -r 50"
2868da6229bSGeliang Tang	elif [ $speed = "least" ]; then
2878da6229bSGeliang Tang		mptcp_connect="./mptcp_connect -r 10"
288dd72b0feSGeliang Tang	fi
289dd72b0feSGeliang Tang
290523514edSGeliang Tang	local local_addr
291523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
292523514edSGeliang Tang		local_addr="::"
293523514edSGeliang Tang	else
294523514edSGeliang Tang		local_addr="0.0.0.0"
295523514edSGeliang Tang	fi
296523514edSGeliang Tang
297*7d1e6f16SPaolo Abeni	if [ "$test_link_fail" -eq 2 ];then
298*7d1e6f16SPaolo Abeni		timeout ${timeout_test} \
299*7d1e6f16SPaolo Abeni			ip netns exec ${listener_ns} \
300*7d1e6f16SPaolo Abeni				$mptcp_connect -t ${timeout_poll} -l -p $port -s ${cl_proto} \
301*7d1e6f16SPaolo Abeni					${local_addr} < "$sinfail" > "$sout" &
302*7d1e6f16SPaolo Abeni	else
3035888a61cSMatthieu Baerts		timeout ${timeout_test} \
3045888a61cSMatthieu Baerts			ip netns exec ${listener_ns} \
3055888a61cSMatthieu Baerts				$mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
3065888a61cSMatthieu Baerts					${local_addr} < "$sin" > "$sout" &
307*7d1e6f16SPaolo Abeni	fi
308b08fbf24SPaolo Abeni	spid=$!
309b08fbf24SPaolo Abeni
310b08fbf24SPaolo Abeni	sleep 1
311b08fbf24SPaolo Abeni
3128b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
3135888a61cSMatthieu Baerts		timeout ${timeout_test} \
3145888a61cSMatthieu Baerts			ip netns exec ${connector_ns} \
3155888a61cSMatthieu Baerts				$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
3165888a61cSMatthieu Baerts					$connect_addr < "$cin" > "$cout" &
3178b819a84SFlorian Westphal	else
318*7d1e6f16SPaolo Abeni		( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
3195888a61cSMatthieu Baerts			tee "$cinsent" | \
3205888a61cSMatthieu Baerts			timeout ${timeout_test} \
3215888a61cSMatthieu Baerts				ip netns exec ${connector_ns} \
3225888a61cSMatthieu Baerts					$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
3235888a61cSMatthieu Baerts						$connect_addr > "$cout" &
3248b819a84SFlorian Westphal	fi
325b08fbf24SPaolo Abeni	cpid=$!
326b08fbf24SPaolo Abeni
3276208fd82SGeliang Tang	if [ $addr_nr_ns1 -gt 0 ]; then
3286208fd82SGeliang Tang		let add_nr_ns1=addr_nr_ns1
3296208fd82SGeliang Tang		counter=2
3306208fd82SGeliang Tang		sleep 1
3316208fd82SGeliang Tang		while [ $add_nr_ns1 -gt 0 ]; do
3326208fd82SGeliang Tang			local addr
3336208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3346208fd82SGeliang Tang				addr="dead:beef:$counter::1"
3356208fd82SGeliang Tang			else
3366208fd82SGeliang Tang				addr="10.0.$counter.1"
3376208fd82SGeliang Tang			fi
3386208fd82SGeliang Tang			ip netns exec $ns1 ./pm_nl_ctl add $addr flags signal
3396208fd82SGeliang Tang			let counter+=1
3406208fd82SGeliang Tang			let add_nr_ns1-=1
3416208fd82SGeliang Tang		done
3426208fd82SGeliang Tang		sleep 1
3436208fd82SGeliang Tang	elif [ $addr_nr_ns1 -lt 0 ]; then
3442e8cbf45SGeliang Tang		let rm_nr_ns1=-addr_nr_ns1
3456fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
346dd72b0feSGeliang Tang			counter=1
347f87744adSGeliang Tang			dump=(`ip netns exec ${listener_ns} ./pm_nl_ctl dump`)
348f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
349f87744adSGeliang Tang				id=${dump[1]}
350dd72b0feSGeliang Tang				sleep 1
351dd72b0feSGeliang Tang
352dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns1 ]
353dd72b0feSGeliang Tang				do
354f87744adSGeliang Tang					ip netns exec ${listener_ns} ./pm_nl_ctl del $id
355dd72b0feSGeliang Tang					sleep 1
356dd72b0feSGeliang Tang					let counter+=1
357f87744adSGeliang Tang					let id+=1
358dd72b0feSGeliang Tang				done
359f87744adSGeliang Tang			fi
3605e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 8 ]; then
3616fe4ccdcSGeliang Tang			sleep 1
3626fe4ccdcSGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl flush
3635e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 9 ]; then
3645e287fe7SGeliang Tang			sleep 1
3655e287fe7SGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl del 0 ${connect_addr}
3666fe4ccdcSGeliang Tang		fi
367dd72b0feSGeliang Tang	fi
368dd72b0feSGeliang Tang
3696208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
3706208fd82SGeliang Tang		let add_nr_ns2=addr_nr_ns2
3716208fd82SGeliang Tang		counter=3
3726208fd82SGeliang Tang		sleep 1
3736208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
3746208fd82SGeliang Tang			local addr
3756208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3766208fd82SGeliang Tang				addr="dead:beef:$counter::2"
3776208fd82SGeliang Tang			else
3786208fd82SGeliang Tang				addr="10.0.$counter.2"
3796208fd82SGeliang Tang			fi
3806208fd82SGeliang Tang			ip netns exec $ns2 ./pm_nl_ctl add $addr flags subflow
3816208fd82SGeliang Tang			let counter+=1
3826208fd82SGeliang Tang			let add_nr_ns2-=1
3836208fd82SGeliang Tang		done
3846208fd82SGeliang Tang		sleep 1
3856208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
3862e8cbf45SGeliang Tang		let rm_nr_ns2=-addr_nr_ns2
3876fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
388dd72b0feSGeliang Tang			counter=1
389f87744adSGeliang Tang			dump=(`ip netns exec ${connector_ns} ./pm_nl_ctl dump`)
390f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
391f87744adSGeliang Tang				id=${dump[1]}
392dd72b0feSGeliang Tang				sleep 1
393dd72b0feSGeliang Tang
394dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns2 ]
395dd72b0feSGeliang Tang				do
396f87744adSGeliang Tang					ip netns exec ${connector_ns} ./pm_nl_ctl del $id
397dd72b0feSGeliang Tang					sleep 1
398dd72b0feSGeliang Tang					let counter+=1
399f87744adSGeliang Tang					let id+=1
400dd72b0feSGeliang Tang				done
401f87744adSGeliang Tang			fi
4025e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 8 ]; then
4036fe4ccdcSGeliang Tang			sleep 1
4046fe4ccdcSGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl flush
4055e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 9 ]; then
4065e287fe7SGeliang Tang			local addr
4075e287fe7SGeliang Tang			if is_v6 "${connect_addr}"; then
4085e287fe7SGeliang Tang				addr="dead:beef:1::2"
4095e287fe7SGeliang Tang			else
4105e287fe7SGeliang Tang				addr="10.0.1.2"
4115e287fe7SGeliang Tang			fi
4125e287fe7SGeliang Tang			sleep 1
4135e287fe7SGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl del 0 $addr
4146fe4ccdcSGeliang Tang		fi
415dd72b0feSGeliang Tang	fi
416dd72b0feSGeliang Tang
417718eb44eSGeliang Tang	if [ ! -z $bkup ]; then
418718eb44eSGeliang Tang		sleep 1
419718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
420718eb44eSGeliang Tang			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
421718eb44eSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
422718eb44eSGeliang Tang				addr=${dump[${#dump[@]} - 1]}
423718eb44eSGeliang Tang				backup="ip netns exec $netns ./pm_nl_ctl set $addr flags $bkup"
424718eb44eSGeliang Tang				$backup
425718eb44eSGeliang Tang			fi
426718eb44eSGeliang Tang		done
427718eb44eSGeliang Tang	fi
428718eb44eSGeliang Tang
429b08fbf24SPaolo Abeni	wait $cpid
430b08fbf24SPaolo Abeni	retc=$?
431b08fbf24SPaolo Abeni	wait $spid
432b08fbf24SPaolo Abeni	rets=$?
433b08fbf24SPaolo Abeni
434b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
435b08fbf24SPaolo Abeni	    sleep 1
436b08fbf24SPaolo Abeni	    kill $cappid
437b08fbf24SPaolo Abeni	fi
438b08fbf24SPaolo Abeni
439c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
440c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${listener_ns}.out
441c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
442c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${connector_ns}.out
443c2a55e8fSMatthieu Baerts
444b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
445b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
4468b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
447c2a55e8fSMatthieu Baerts		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
448c2a55e8fSMatthieu Baerts		cat /tmp/${listener_ns}.out
4498b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
450c2a55e8fSMatthieu Baerts		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
451c2a55e8fSMatthieu Baerts		cat /tmp/${connector_ns}.out
452b08fbf24SPaolo Abeni
453b08fbf24SPaolo Abeni		cat "$capout"
4548b819a84SFlorian Westphal		ret=1
455b08fbf24SPaolo Abeni		return 1
456b08fbf24SPaolo Abeni	fi
457b08fbf24SPaolo Abeni
458*7d1e6f16SPaolo Abeni	if [ "$test_link_fail" -eq 2 ];then
459*7d1e6f16SPaolo Abeni		check_transfer $sinfail $cout "file received by client"
460*7d1e6f16SPaolo Abeni	else
461b08fbf24SPaolo Abeni		check_transfer $sin $cout "file received by client"
462*7d1e6f16SPaolo Abeni	fi
463b08fbf24SPaolo Abeni	retc=$?
4648b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
465b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
4668b819a84SFlorian Westphal	else
4678b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
4688b819a84SFlorian Westphal	fi
469b08fbf24SPaolo Abeni	rets=$?
470b08fbf24SPaolo Abeni
471b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
472b08fbf24SPaolo Abeni		cat "$capout"
473b08fbf24SPaolo Abeni		return 0
474b08fbf24SPaolo Abeni	fi
475b08fbf24SPaolo Abeni
476b08fbf24SPaolo Abeni	cat "$capout"
477b08fbf24SPaolo Abeni	return 1
478b08fbf24SPaolo Abeni}
479b08fbf24SPaolo Abeni
480b08fbf24SPaolo Abenimake_file()
481b08fbf24SPaolo Abeni{
482b08fbf24SPaolo Abeni	name=$1
483b08fbf24SPaolo Abeni	who=$2
4848b819a84SFlorian Westphal	size=$3
485b08fbf24SPaolo Abeni
4868b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
487b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
488b08fbf24SPaolo Abeni
4898b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
490b08fbf24SPaolo Abeni}
491b08fbf24SPaolo Abeni
492b08fbf24SPaolo Abenirun_tests()
493b08fbf24SPaolo Abeni{
494b08fbf24SPaolo Abeni	listener_ns="$1"
495b08fbf24SPaolo Abeni	connector_ns="$2"
496b08fbf24SPaolo Abeni	connect_addr="$3"
4978b819a84SFlorian Westphal	test_linkfail="${4:-0}"
4982e8cbf45SGeliang Tang	addr_nr_ns1="${5:-0}"
4992e8cbf45SGeliang Tang	addr_nr_ns2="${6:-0}"
5008b819a84SFlorian Westphal	speed="${7:-fast}"
501718eb44eSGeliang Tang	bkup="${8:-""}"
502b08fbf24SPaolo Abeni	lret=0
5038b819a84SFlorian Westphal	oldin=""
5048b819a84SFlorian Westphal
505*7d1e6f16SPaolo Abeni	# create the input file for the failure test when
506*7d1e6f16SPaolo Abeni	# the first failure test run
507*7d1e6f16SPaolo Abeni	if [ "$test_linkfail" -ne 0 -a -z "$cinfail" ]; then
508*7d1e6f16SPaolo Abeni		# the client file must be considerably larger
509*7d1e6f16SPaolo Abeni		# of the maximum expected cwin value, or the
510*7d1e6f16SPaolo Abeni		# link utilization will be not predicable
511*7d1e6f16SPaolo Abeni		size=$((RANDOM%2))
5128b819a84SFlorian Westphal		size=$((size+1))
513*7d1e6f16SPaolo Abeni		size=$((size*8192))
514*7d1e6f16SPaolo Abeni		size=$((size + ( $RANDOM % 8192) ))
5158b819a84SFlorian Westphal
516*7d1e6f16SPaolo Abeni		cinfail=$(mktemp)
517*7d1e6f16SPaolo Abeni		make_file "$cinfail" "client" $size
518*7d1e6f16SPaolo Abeni	fi
519*7d1e6f16SPaolo Abeni
520*7d1e6f16SPaolo Abeni	if [ "$test_linkfail" -eq 2 -a -z "$sinfail" ]; then
521*7d1e6f16SPaolo Abeni		size=$((RANDOM%16))
522*7d1e6f16SPaolo Abeni		size=$((size+1))
523*7d1e6f16SPaolo Abeni		size=$((size*2048))
524*7d1e6f16SPaolo Abeni
525*7d1e6f16SPaolo Abeni		sinfail=$(mktemp)
526*7d1e6f16SPaolo Abeni		make_file "$sinfail" "server" $size
5278b819a84SFlorian Westphal	fi
528b08fbf24SPaolo Abeni
5298d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
5302e8cbf45SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${bkup}
531b08fbf24SPaolo Abeni	lret=$?
532b08fbf24SPaolo Abeni}
533b08fbf24SPaolo Abeni
534af66d3e1SGeliang Tangchk_csum_nr()
535af66d3e1SGeliang Tang{
536af66d3e1SGeliang Tang	local msg=${1:-""}
537af66d3e1SGeliang Tang	local count
538af66d3e1SGeliang Tang	local dump_stats
539af66d3e1SGeliang Tang
540af66d3e1SGeliang Tang	if [ ! -z "$msg" ]; then
541af66d3e1SGeliang Tang		printf "%02u" "$TEST_COUNT"
542af66d3e1SGeliang Tang	else
543af66d3e1SGeliang Tang		echo -n "  "
544af66d3e1SGeliang Tang	fi
545af66d3e1SGeliang Tang	printf " %-36s %s" "$msg" "sum"
546af66d3e1SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
547af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
548af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
549af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
550af66d3e1SGeliang Tang		ret=1
551af66d3e1SGeliang Tang		dump_stats=1
552af66d3e1SGeliang Tang	else
553af66d3e1SGeliang Tang		echo -n "[ ok ]"
554af66d3e1SGeliang Tang	fi
555af66d3e1SGeliang Tang	echo -n " - csum  "
556af66d3e1SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
557af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
558af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
559af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
560af66d3e1SGeliang Tang		ret=1
561af66d3e1SGeliang Tang		dump_stats=1
562af66d3e1SGeliang Tang	else
563af66d3e1SGeliang Tang		echo "[ ok ]"
564af66d3e1SGeliang Tang	fi
565af66d3e1SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
566af66d3e1SGeliang Tang		echo Server ns stats
567af66d3e1SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
568af66d3e1SGeliang Tang		echo Client ns stats
569af66d3e1SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
570af66d3e1SGeliang Tang	fi
571af66d3e1SGeliang Tang}
572af66d3e1SGeliang Tang
573b08fbf24SPaolo Abenichk_join_nr()
574b08fbf24SPaolo Abeni{
575b08fbf24SPaolo Abeni	local msg="$1"
576b08fbf24SPaolo Abeni	local syn_nr=$2
577b08fbf24SPaolo Abeni	local syn_ack_nr=$3
578b08fbf24SPaolo Abeni	local ack_nr=$4
579b08fbf24SPaolo Abeni	local count
580b08fbf24SPaolo Abeni	local dump_stats
581b08fbf24SPaolo Abeni
58200587187SFlorian Westphal	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
583b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
584b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
585b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
586b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
587b08fbf24SPaolo Abeni		ret=1
588b08fbf24SPaolo Abeni		dump_stats=1
589b08fbf24SPaolo Abeni	else
590b08fbf24SPaolo Abeni		echo -n "[ ok ]"
591b08fbf24SPaolo Abeni	fi
592b08fbf24SPaolo Abeni
593b08fbf24SPaolo Abeni	echo -n " - synack"
594b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
595b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
596b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
597b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
598b08fbf24SPaolo Abeni		ret=1
599b08fbf24SPaolo Abeni		dump_stats=1
600b08fbf24SPaolo Abeni	else
601b08fbf24SPaolo Abeni		echo -n "[ ok ]"
602b08fbf24SPaolo Abeni	fi
603b08fbf24SPaolo Abeni
604b08fbf24SPaolo Abeni	echo -n " - ack"
605b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
606b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
607b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
608b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
609b08fbf24SPaolo Abeni		ret=1
610b08fbf24SPaolo Abeni		dump_stats=1
611b08fbf24SPaolo Abeni	else
612b08fbf24SPaolo Abeni		echo "[ ok ]"
613b08fbf24SPaolo Abeni	fi
614b08fbf24SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
615b08fbf24SPaolo Abeni		echo Server ns stats
616b08fbf24SPaolo Abeni		ip netns exec $ns1 nstat -as | grep MPTcp
617b08fbf24SPaolo Abeni		echo Client ns stats
618b08fbf24SPaolo Abeni		ip netns exec $ns2 nstat -as | grep MPTcp
619b08fbf24SPaolo Abeni	fi
620af66d3e1SGeliang Tang	if [ $checksum -eq 1 ]; then
621af66d3e1SGeliang Tang		chk_csum_nr
622af66d3e1SGeliang Tang	fi
623b08fbf24SPaolo Abeni}
624b08fbf24SPaolo Abeni
625*7d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound:
626*7d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while
627*7d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of
628*7d1e6f16SPaolo Abeni# stale/recover conversions, proportional to
629*7d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval.
630*7d1e6f16SPaolo Abenichk_stale_nr()
631*7d1e6f16SPaolo Abeni{
632*7d1e6f16SPaolo Abeni	local ns=$1
633*7d1e6f16SPaolo Abeni	local stale_min=$2
634*7d1e6f16SPaolo Abeni	local stale_max=$3
635*7d1e6f16SPaolo Abeni	local stale_delta=$4
636*7d1e6f16SPaolo Abeni	local dump_stats
637*7d1e6f16SPaolo Abeni	local stale_nr
638*7d1e6f16SPaolo Abeni	local recover_nr
639*7d1e6f16SPaolo Abeni
640*7d1e6f16SPaolo Abeni	printf "%-39s %-18s" " " "stale"
641*7d1e6f16SPaolo Abeni	stale_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}'`
642*7d1e6f16SPaolo Abeni	[ -z "$stale_nr" ] && stale_nr=0
643*7d1e6f16SPaolo Abeni	recover_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}'`
644*7d1e6f16SPaolo Abeni	[ -z "$recover_nr" ] && recover_nr=0
645*7d1e6f16SPaolo Abeni
646*7d1e6f16SPaolo Abeni	if [ $stale_nr -lt $stale_min ] ||
647*7d1e6f16SPaolo Abeni	   [ $stale_max -gt 0 -a $stale_nr -gt $stale_max ] ||
648*7d1e6f16SPaolo Abeni	   [ $((stale_nr - $recover_nr)) -ne $stale_delta ]; then
649*7d1e6f16SPaolo Abeni		echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \
650*7d1e6f16SPaolo Abeni		     " expected stale in range [$stale_min..$stale_max]," \
651*7d1e6f16SPaolo Abeni		     " stale-recover delta $stale_delta "
652*7d1e6f16SPaolo Abeni		ret=1
653*7d1e6f16SPaolo Abeni		dump_stats=1
654*7d1e6f16SPaolo Abeni	else
655*7d1e6f16SPaolo Abeni		echo "[ ok ]"
656*7d1e6f16SPaolo Abeni	fi
657*7d1e6f16SPaolo Abeni
658*7d1e6f16SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
659*7d1e6f16SPaolo Abeni		echo $ns stats
660*7d1e6f16SPaolo Abeni		ip netns exec $ns ip -s link show
661*7d1e6f16SPaolo Abeni		ip netns exec $ns nstat -as | grep MPTcp
662*7d1e6f16SPaolo Abeni	fi
663*7d1e6f16SPaolo Abeni}
664*7d1e6f16SPaolo Abeni
665be613160SGeliang Tangchk_add_nr()
666be613160SGeliang Tang{
667be613160SGeliang Tang	local add_nr=$1
668be613160SGeliang Tang	local echo_nr=$2
6698a127bf6SGeliang Tang	local port_nr=${3:-0}
6708a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
6718a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
6728a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
6738a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
6748a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
675be613160SGeliang Tang	local count
676be613160SGeliang Tang	local dump_stats
677be613160SGeliang Tang
678be613160SGeliang Tang	printf "%-39s %s" " " "add"
679be613160SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
680be613160SGeliang Tang	[ -z "$count" ] && count=0
681be613160SGeliang Tang	if [ "$count" != "$add_nr" ]; then
682be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
683be613160SGeliang Tang		ret=1
684be613160SGeliang Tang		dump_stats=1
685be613160SGeliang Tang	else
686be613160SGeliang Tang		echo -n "[ ok ]"
687be613160SGeliang Tang	fi
688be613160SGeliang Tang
689be613160SGeliang Tang	echo -n " - echo  "
690be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
691be613160SGeliang Tang	[ -z "$count" ] && count=0
692be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
693be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
694be613160SGeliang Tang		ret=1
695be613160SGeliang Tang		dump_stats=1
696be613160SGeliang Tang	else
6978a127bf6SGeliang Tang		echo -n "[ ok ]"
6988a127bf6SGeliang Tang	fi
6998a127bf6SGeliang Tang
7008a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
7018a127bf6SGeliang Tang		echo -n " - pt "
7028a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
7038a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7048a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
7058a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
7068a127bf6SGeliang Tang			ret=1
7078a127bf6SGeliang Tang			dump_stats=1
7088a127bf6SGeliang Tang		else
709be613160SGeliang Tang			echo "[ ok ]"
710be613160SGeliang Tang		fi
711be613160SGeliang Tang
7128a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
7138a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
7148a127bf6SGeliang Tang			awk '{print $2}'`
7158a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7168a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
7178a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
7188a127bf6SGeliang Tang				port-number expected $syn_nr"
7198a127bf6SGeliang Tang			ret=1
7208a127bf6SGeliang Tang			dump_stats=1
7218a127bf6SGeliang Tang		else
7228a127bf6SGeliang Tang			echo -n "[ ok ]"
7238a127bf6SGeliang Tang		fi
7248a127bf6SGeliang Tang
7258a127bf6SGeliang Tang		echo -n " - synack"
7268a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
7278a127bf6SGeliang Tang			awk '{print $2}'`
7288a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7298a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
7308a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
7318a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
7328a127bf6SGeliang Tang			ret=1
7338a127bf6SGeliang Tang			dump_stats=1
7348a127bf6SGeliang Tang		else
7358a127bf6SGeliang Tang			echo -n "[ ok ]"
7368a127bf6SGeliang Tang		fi
7378a127bf6SGeliang Tang
7388a127bf6SGeliang Tang		echo -n " - ack"
7398a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
7408a127bf6SGeliang Tang			awk '{print $2}'`
7418a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7428a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
7438a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
7448a127bf6SGeliang Tang				port-number expected $ack_nr"
7458a127bf6SGeliang Tang			ret=1
7468a127bf6SGeliang Tang			dump_stats=1
7478a127bf6SGeliang Tang		else
7488a127bf6SGeliang Tang			echo "[ ok ]"
7498a127bf6SGeliang Tang		fi
7508a127bf6SGeliang Tang
7518a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
7528a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
7538a127bf6SGeliang Tang			awk '{print $2}'`
7548a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7558a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
7568a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
7578a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
7588a127bf6SGeliang Tang			ret=1
7598a127bf6SGeliang Tang			dump_stats=1
7608a127bf6SGeliang Tang		else
7618a127bf6SGeliang Tang			echo -n "[ ok ]"
7628a127bf6SGeliang Tang		fi
7638a127bf6SGeliang Tang
7648a127bf6SGeliang Tang		echo -n " - ack   "
7658a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
7668a127bf6SGeliang Tang			awk '{print $2}'`
7678a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7688a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
7698a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
7708a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
7718a127bf6SGeliang Tang			ret=1
7728a127bf6SGeliang Tang			dump_stats=1
7738a127bf6SGeliang Tang		else
7748a127bf6SGeliang Tang			echo "[ ok ]"
7758a127bf6SGeliang Tang		fi
7768a127bf6SGeliang Tang	else
7778a127bf6SGeliang Tang		echo ""
7788a127bf6SGeliang Tang	fi
7798a127bf6SGeliang Tang
780be613160SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
781be613160SGeliang Tang		echo Server ns stats
782be613160SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
783be613160SGeliang Tang		echo Client ns stats
784be613160SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
785be613160SGeliang Tang	fi
786be613160SGeliang Tang}
787be613160SGeliang Tang
788dd72b0feSGeliang Tangchk_rm_nr()
789dd72b0feSGeliang Tang{
790dd72b0feSGeliang Tang	local rm_addr_nr=$1
791dd72b0feSGeliang Tang	local rm_subflow_nr=$2
7927028ba8aSGeliang Tang	local invert=${3:-""}
793dd72b0feSGeliang Tang	local count
794dd72b0feSGeliang Tang	local dump_stats
7957028ba8aSGeliang Tang	local addr_ns
7967028ba8aSGeliang Tang	local subflow_ns
7977028ba8aSGeliang Tang
7987028ba8aSGeliang Tang	if [ -z $invert ]; then
7997028ba8aSGeliang Tang		addr_ns=$ns1
8007028ba8aSGeliang Tang		subflow_ns=$ns2
8017028ba8aSGeliang Tang	elif [ $invert = "invert" ]; then
8027028ba8aSGeliang Tang		addr_ns=$ns2
8037028ba8aSGeliang Tang		subflow_ns=$ns1
8047028ba8aSGeliang Tang	fi
805dd72b0feSGeliang Tang
806dd72b0feSGeliang Tang	printf "%-39s %s" " " "rm "
8077028ba8aSGeliang Tang	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
808dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
809dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
810dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
811dd72b0feSGeliang Tang		ret=1
812dd72b0feSGeliang Tang		dump_stats=1
813dd72b0feSGeliang Tang	else
814dd72b0feSGeliang Tang		echo -n "[ ok ]"
815dd72b0feSGeliang Tang	fi
816dd72b0feSGeliang Tang
817dd72b0feSGeliang Tang	echo -n " - sf    "
8187028ba8aSGeliang Tang	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
819dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
820dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
821dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
822dd72b0feSGeliang Tang		ret=1
823dd72b0feSGeliang Tang		dump_stats=1
824dd72b0feSGeliang Tang	else
825dd72b0feSGeliang Tang		echo "[ ok ]"
826dd72b0feSGeliang Tang	fi
827dd72b0feSGeliang Tang
828dd72b0feSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
829dd72b0feSGeliang Tang		echo Server ns stats
830dd72b0feSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
831dd72b0feSGeliang Tang		echo Client ns stats
832dd72b0feSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
833dd72b0feSGeliang Tang	fi
834dd72b0feSGeliang Tang}
835dd72b0feSGeliang Tang
836718eb44eSGeliang Tangchk_prio_nr()
837718eb44eSGeliang Tang{
838718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
839718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
840718eb44eSGeliang Tang	local count
841718eb44eSGeliang Tang	local dump_stats
842718eb44eSGeliang Tang
843718eb44eSGeliang Tang	printf "%-39s %s" " " "ptx"
844718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
845718eb44eSGeliang Tang	[ -z "$count" ] && count=0
846718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
847718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
848718eb44eSGeliang Tang		ret=1
849718eb44eSGeliang Tang		dump_stats=1
850718eb44eSGeliang Tang	else
851718eb44eSGeliang Tang		echo -n "[ ok ]"
852718eb44eSGeliang Tang	fi
853718eb44eSGeliang Tang
854718eb44eSGeliang Tang	echo -n " - prx   "
855718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
856718eb44eSGeliang Tang	[ -z "$count" ] && count=0
857718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
858718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
859718eb44eSGeliang Tang		ret=1
860718eb44eSGeliang Tang		dump_stats=1
861718eb44eSGeliang Tang	else
862718eb44eSGeliang Tang		echo "[ ok ]"
863718eb44eSGeliang Tang	fi
864718eb44eSGeliang Tang
865718eb44eSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
866718eb44eSGeliang Tang		echo Server ns stats
867718eb44eSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
868718eb44eSGeliang Tang		echo Client ns stats
869718eb44eSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
870718eb44eSGeliang Tang	fi
871718eb44eSGeliang Tang}
872718eb44eSGeliang Tang
873*7d1e6f16SPaolo Abenichk_link_usage()
874*7d1e6f16SPaolo Abeni{
875*7d1e6f16SPaolo Abeni	local ns=$1
876*7d1e6f16SPaolo Abeni	local link=$2
877*7d1e6f16SPaolo Abeni	local out=$3
878*7d1e6f16SPaolo Abeni	local expected_rate=$4
879*7d1e6f16SPaolo Abeni	local tx_link=`ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes`
880*7d1e6f16SPaolo Abeni	local tx_total=`ls -l $out | awk '{print $5}'`
881*7d1e6f16SPaolo Abeni	local tx_rate=$((tx_link * 100 / $tx_total))
882*7d1e6f16SPaolo Abeni	local tolerance=5
883*7d1e6f16SPaolo Abeni
884*7d1e6f16SPaolo Abeni	printf "%-39s %-18s" " " "link usage"
885*7d1e6f16SPaolo Abeni	if [ $tx_rate -lt $((expected_rate - $tolerance)) -o \
886*7d1e6f16SPaolo Abeni	     $tx_rate -gt $((expected_rate + $tolerance)) ]; then
887*7d1e6f16SPaolo Abeni		echo "[fail] got $tx_rate% usage, expected $expected_rate%"
888*7d1e6f16SPaolo Abeni		ret=1
889*7d1e6f16SPaolo Abeni	else
890*7d1e6f16SPaolo Abeni		echo "[ ok ]"
891*7d1e6f16SPaolo Abeni	fi
892*7d1e6f16SPaolo Abeni}
893*7d1e6f16SPaolo Abeni
8941002b89fSGeliang Tangsubflows_tests()
8951002b89fSGeliang Tang{
8961002b89fSGeliang Tang	reset
897b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
898b08fbf24SPaolo Abeni	chk_join_nr "no JOIN" "0" "0" "0"
899b08fbf24SPaolo Abeni
9001002b89fSGeliang Tang	# subflow limited by client
901b08fbf24SPaolo Abeni	reset
902b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
903b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
904b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by client" 0 0 0
905b08fbf24SPaolo Abeni
9061002b89fSGeliang Tang	# subflow limited by server
907b08fbf24SPaolo Abeni	reset
908b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
909b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
910b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
911b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by server" 1 1 0
912b08fbf24SPaolo Abeni
913b08fbf24SPaolo Abeni	# subflow
914b08fbf24SPaolo Abeni	reset
915b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
916b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
917b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
918b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
919b08fbf24SPaolo Abeni	chk_join_nr "single subflow" 1 1 1
920b08fbf24SPaolo Abeni
921b08fbf24SPaolo Abeni	# multiple subflows
922b08fbf24SPaolo Abeni	reset
923b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
924b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
925b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
926b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
927b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
928b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows" 2 2 2
929b08fbf24SPaolo Abeni
930b08fbf24SPaolo Abeni	# multiple subflows limited by serverf
931b08fbf24SPaolo Abeni	reset
932b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
933b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
934b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
935b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
936b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
937b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows, limited by server" 2 2 1
938c3eaa5f6SGeliang Tang
939c3eaa5f6SGeliang Tang	# single subflow, dev
940c3eaa5f6SGeliang Tang	reset
941c3eaa5f6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
942c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
943c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow dev ns2eth3
944c3eaa5f6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
945c3eaa5f6SGeliang Tang	chk_join_nr "single subflow, dev" 1 1 1
9461002b89fSGeliang Tang}
947b08fbf24SPaolo Abeni
9481002b89fSGeliang Tangsignal_address_tests()
9491002b89fSGeliang Tang{
950b08fbf24SPaolo Abeni	# add_address, unused
951b08fbf24SPaolo Abeni	reset
952b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
953b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
954b08fbf24SPaolo Abeni	chk_join_nr "unused signal address" 0 0 0
955be613160SGeliang Tang	chk_add_nr 1 1
956b08fbf24SPaolo Abeni
957b08fbf24SPaolo Abeni	# accept and use add_addr
958b08fbf24SPaolo Abeni	reset
959b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
960b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
961b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
962b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
963b08fbf24SPaolo Abeni	chk_join_nr "signal address" 1 1 1
964be613160SGeliang Tang	chk_add_nr 1 1
965b08fbf24SPaolo Abeni
966b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
967b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
968b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
969b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
970b08fbf24SPaolo Abeni	reset
971b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
972b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
973b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
974b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
975b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
976b08fbf24SPaolo Abeni	chk_join_nr "subflow and signal" 2 2 2
977be613160SGeliang Tang	chk_add_nr 1 1
978b08fbf24SPaolo Abeni
979b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
980b08fbf24SPaolo Abeni	reset
981b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
982b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
983b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
984b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
985b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
986b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
987b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows and signal" 3 3 3
988be613160SGeliang Tang	chk_add_nr 1 1
989ef360019SGeliang Tang
990ef360019SGeliang Tang	# signal addresses
991ef360019SGeliang Tang	reset
992ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
993ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
994ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
995ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
996ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
997ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
998ef360019SGeliang Tang	chk_join_nr "signal addresses" 3 3 3
999ef360019SGeliang Tang	chk_add_nr 3 3
1000ef360019SGeliang Tang
1001ef360019SGeliang Tang	# signal invalid addresses
1002ef360019SGeliang Tang	reset
1003ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1004ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1005ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1006ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1007ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1008ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1009ef360019SGeliang Tang	chk_join_nr "signal invalid addresses" 1 1 1
1010ef360019SGeliang Tang	chk_add_nr 3 3
10111002b89fSGeliang Tang}
1012b08fbf24SPaolo Abeni
10131002b89fSGeliang Tanglink_failure_tests()
10141002b89fSGeliang Tang{
10158b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
10168b819a84SFlorian Westphal	reset
1017*7d1e6f16SPaolo Abeni
1018*7d1e6f16SPaolo Abeni	# without any b/w limit each veth could spool the packets and get
1019*7d1e6f16SPaolo Abeni	# them acked at xmit time, so that the corresponding subflow will
1020*7d1e6f16SPaolo Abeni	# have almost always no outstanding pkts, the scheduler will pick
1021*7d1e6f16SPaolo Abeni	# always the first subflow and we will have hard time testing
1022*7d1e6f16SPaolo Abeni	# active backup and link switch-over.
1023*7d1e6f16SPaolo Abeni	# Let's set some arbitrary (low) virtual link limits.
1024*7d1e6f16SPaolo Abeni	init_shapers
10258b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1026*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
10278b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1028*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
1029*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
10308b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 1
10318b819a84SFlorian Westphal	chk_join_nr "multiple flows, signal, link failure" 3 3 3
10328b819a84SFlorian Westphal	chk_add_nr 1 1
1033*7d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 5 1
1034*7d1e6f16SPaolo Abeni
1035*7d1e6f16SPaolo Abeni	# accept and use add_addr with additional subflows and link loss
1036*7d1e6f16SPaolo Abeni	# for bidirectional transfer
1037*7d1e6f16SPaolo Abeni	reset
1038*7d1e6f16SPaolo Abeni	init_shapers
1039*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1040*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1041*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1042*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
1043*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
1044*7d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
1045*7d1e6f16SPaolo Abeni	chk_join_nr "multi flows, signal, bidi, link fail" 3 3 3
1046*7d1e6f16SPaolo Abeni	chk_add_nr 1 1
1047*7d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 1
1048*7d1e6f16SPaolo Abeni
1049*7d1e6f16SPaolo Abeni	# 2 subflows plus 1 backup subflow with a lossy link, backup
1050*7d1e6f16SPaolo Abeni	# will never be used
1051*7d1e6f16SPaolo Abeni	reset
1052*7d1e6f16SPaolo Abeni	init_shapers
1053*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1054*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1055*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1056*7d1e6f16SPaolo Abeni	export FAILING_LINKS="1"
1057*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1058*7d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
1059*7d1e6f16SPaolo Abeni	chk_join_nr "backup subflow unused, link failure" 2 2 2
1060*7d1e6f16SPaolo Abeni	chk_add_nr 1 1
1061*7d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 0
1062*7d1e6f16SPaolo Abeni
1063*7d1e6f16SPaolo Abeni	# 2 lossy links after half transfer, backup will get half of
1064*7d1e6f16SPaolo Abeni	# the traffic
1065*7d1e6f16SPaolo Abeni	reset
1066*7d1e6f16SPaolo Abeni	init_shapers
1067*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1068*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1069*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1070*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1071*7d1e6f16SPaolo Abeni	export FAILING_LINKS="1 2"
1072*7d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
1073*7d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, multi links fail" 2 2 2
1074*7d1e6f16SPaolo Abeni	chk_add_nr 1 1
1075*7d1e6f16SPaolo Abeni	chk_stale_nr $ns2 2 4 2
1076*7d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
1077*7d1e6f16SPaolo Abeni
1078*7d1e6f16SPaolo Abeni	# use a backup subflow with the first subflow on a lossy link
1079*7d1e6f16SPaolo Abeni	# for bidirectional transfer
1080*7d1e6f16SPaolo Abeni	reset
1081*7d1e6f16SPaolo Abeni	init_shapers
1082*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1083*7d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
1084*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1085*7d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
1086*7d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
1087*7d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, bidi, link failure" 2 2 2
1088*7d1e6f16SPaolo Abeni	chk_add_nr 1 1
1089*7d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 2
1090*7d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
10911002b89fSGeliang Tang}
10928b819a84SFlorian Westphal
10931002b89fSGeliang Tangadd_addr_timeout_tests()
10941002b89fSGeliang Tang{
10958d014eaaSGeliang Tang	# add_addr timeout
10968d014eaaSGeliang Tang	reset_with_add_addr_timeout
10978d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
10988d014eaaSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
10998d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
11008b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
11018d014eaaSGeliang Tang	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
11028d014eaaSGeliang Tang	chk_add_nr 4 0
11038d014eaaSGeliang Tang
11041002b89fSGeliang Tang	# add_addr timeout IPv6
11051002b89fSGeliang Tang	reset_with_add_addr_timeout 6
11061002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11071002b89fSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11081002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
11091002b89fSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
11101002b89fSGeliang Tang	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
11111002b89fSGeliang Tang	chk_add_nr 4 0
11128da6229bSGeliang Tang
11138da6229bSGeliang Tang	# signal addresses timeout
11148da6229bSGeliang Tang	reset_with_add_addr_timeout
11158da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11168da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
11178da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
11188da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11198da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
11208da6229bSGeliang Tang	chk_join_nr "signal addresses, ADD_ADDR timeout" 2 2 2
11218da6229bSGeliang Tang	chk_add_nr 8 0
11228da6229bSGeliang Tang
11238da6229bSGeliang Tang	# signal invalid addresses timeout
11248da6229bSGeliang Tang	reset_with_add_addr_timeout
11258da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11268da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
11278da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
11288da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11298da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
11308da6229bSGeliang Tang	chk_join_nr "invalid address, ADD_ADDR timeout" 1 1 1
11318da6229bSGeliang Tang	chk_add_nr 8 0
11321002b89fSGeliang Tang}
11331002b89fSGeliang Tang
11341002b89fSGeliang Tangremove_tests()
11351002b89fSGeliang Tang{
1136dd72b0feSGeliang Tang	# single subflow, remove
1137dd72b0feSGeliang Tang	reset
1138dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1139dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1140dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11412e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
1142dd72b0feSGeliang Tang	chk_join_nr "remove single subflow" 1 1 1
1143dd72b0feSGeliang Tang	chk_rm_nr 1 1
1144dd72b0feSGeliang Tang
1145dd72b0feSGeliang Tang	# multiple subflows, remove
1146dd72b0feSGeliang Tang	reset
1147dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1148dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1149dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
1150dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11512e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
1152dd72b0feSGeliang Tang	chk_join_nr "remove multiple subflows" 2 2 2
1153dd72b0feSGeliang Tang	chk_rm_nr 2 2
1154dd72b0feSGeliang Tang
1155dd72b0feSGeliang Tang	# single address, remove
1156dd72b0feSGeliang Tang	reset
1157dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1158dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1159dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11602e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1161dd72b0feSGeliang Tang	chk_join_nr "remove single address" 1 1 1
1162dd72b0feSGeliang Tang	chk_add_nr 1 1
11637028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1164dd72b0feSGeliang Tang
1165dd72b0feSGeliang Tang	# subflow and signal, remove
1166dd72b0feSGeliang Tang	reset
1167dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1168dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1169dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1170dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11712e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1172dd72b0feSGeliang Tang	chk_join_nr "remove subflow and signal" 2 2 2
1173dd72b0feSGeliang Tang	chk_add_nr 1 1
1174dd72b0feSGeliang Tang	chk_rm_nr 1 1
1175dd72b0feSGeliang Tang
1176dd72b0feSGeliang Tang	# subflows and signal, remove
1177dd72b0feSGeliang Tang	reset
1178dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1179dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1180dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1181dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1182dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
11832e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
1184dd72b0feSGeliang Tang	chk_join_nr "remove subflows and signal" 3 3 3
1185dd72b0feSGeliang Tang	chk_add_nr 1 1
1186dd72b0feSGeliang Tang	chk_rm_nr 2 2
1187dd72b0feSGeliang Tang
1188ef360019SGeliang Tang	# addresses remove
1189ef360019SGeliang Tang	reset
1190ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1191ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1192ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1193ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1194ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1195ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1196ef360019SGeliang Tang	chk_join_nr "remove addresses" 3 3 3
1197ef360019SGeliang Tang	chk_add_nr 3 3
1198ef360019SGeliang Tang	chk_rm_nr 3 3 invert
1199ef360019SGeliang Tang
1200ef360019SGeliang Tang	# invalid addresses remove
1201ef360019SGeliang Tang	reset
1202ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1203ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1204ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1205ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1206ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1207ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1208ef360019SGeliang Tang	chk_join_nr "remove invalid addresses" 1 1 1
1209ef360019SGeliang Tang	chk_add_nr 3 3
1210ef360019SGeliang Tang	chk_rm_nr 3 1 invert
1211ef360019SGeliang Tang
12126fe4ccdcSGeliang Tang	# subflows and signal, flush
12136fe4ccdcSGeliang Tang	reset
12146fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
12156fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
12166fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
12176fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12186fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
12192e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
12206fe4ccdcSGeliang Tang	chk_join_nr "flush subflows and signal" 3 3 3
12216fe4ccdcSGeliang Tang	chk_add_nr 1 1
12226fe4ccdcSGeliang Tang	chk_rm_nr 2 2
1223d2c4333aSGeliang Tang
1224d2c4333aSGeliang Tang	# subflows flush
1225d2c4333aSGeliang Tang	reset
1226d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1227d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1228d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow id 150
1229d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1230d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1231d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1232d2c4333aSGeliang Tang	chk_join_nr "flush subflows" 3 3 3
1233d2c4333aSGeliang Tang	chk_rm_nr 3 3
1234d2c4333aSGeliang Tang
1235d2c4333aSGeliang Tang	# addresses flush
1236d2c4333aSGeliang Tang	reset
1237d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1238d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1239d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1240d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1241d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1242d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1243d2c4333aSGeliang Tang	chk_join_nr "flush addresses" 3 3 3
1244d2c4333aSGeliang Tang	chk_add_nr 3 3
1245d2c4333aSGeliang Tang	chk_rm_nr 3 3 invert
1246ef360019SGeliang Tang
1247ef360019SGeliang Tang	# invalid addresses flush
1248ef360019SGeliang Tang	reset
1249ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1250ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1251ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1252ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1253ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1254ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
1255ef360019SGeliang Tang	chk_join_nr "flush invalid addresses" 1 1 1
1256ef360019SGeliang Tang	chk_add_nr 3 3
1257ef360019SGeliang Tang	chk_rm_nr 3 1 invert
12585e287fe7SGeliang Tang
12595e287fe7SGeliang Tang	# remove id 0 subflow
12605e287fe7SGeliang Tang	reset
12615e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
12625e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
12635e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12645e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
12655e287fe7SGeliang Tang	chk_join_nr "remove id 0 subflow" 1 1 1
12665e287fe7SGeliang Tang	chk_rm_nr 1 1
12675e287fe7SGeliang Tang
12685e287fe7SGeliang Tang	# remove id 0 address
12695e287fe7SGeliang Tang	reset
12705e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
12715e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
12725e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
12735e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
12745e287fe7SGeliang Tang	chk_join_nr "remove id 0 address" 1 1 1
12755e287fe7SGeliang Tang	chk_add_nr 1 1
12765e287fe7SGeliang Tang	chk_rm_nr 1 1 invert
12771002b89fSGeliang Tang}
12786fe4ccdcSGeliang Tang
12791002b89fSGeliang Tangadd_tests()
12801002b89fSGeliang Tang{
12816208fd82SGeliang Tang	# add single subflow
12826208fd82SGeliang Tang	reset
12836208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
12846208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
12856208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
12866208fd82SGeliang Tang	chk_join_nr "add single subflow" 1 1 1
12876208fd82SGeliang Tang
12886208fd82SGeliang Tang	# add signal address
12896208fd82SGeliang Tang	reset
12906208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
12916208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
12926208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
12936208fd82SGeliang Tang	chk_join_nr "add signal address" 1 1 1
12946208fd82SGeliang Tang	chk_add_nr 1 1
12956208fd82SGeliang Tang
12966208fd82SGeliang Tang	# add multiple subflows
12976208fd82SGeliang Tang	reset
12986208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
12996208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
13006208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
13016208fd82SGeliang Tang	chk_join_nr "add multiple subflows" 2 2 2
13026208fd82SGeliang Tang
13036208fd82SGeliang Tang	# add multiple subflows IPv6
13046208fd82SGeliang Tang	reset
13056208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13066208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
13076208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
13086208fd82SGeliang Tang	chk_join_nr "add multiple subflows IPv6" 2 2 2
13096208fd82SGeliang Tang
13106208fd82SGeliang Tang	# add multiple addresses IPv6
13116208fd82SGeliang Tang	reset
13126208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13136208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
13146208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
13156208fd82SGeliang Tang	chk_join_nr "add multiple addresses IPv6" 2 2 2
13166208fd82SGeliang Tang	chk_add_nr 2 2
13171002b89fSGeliang Tang}
13186208fd82SGeliang Tang
13191002b89fSGeliang Tangipv6_tests()
13201002b89fSGeliang Tang{
1321523514edSGeliang Tang	# subflow IPv6
1322523514edSGeliang Tang	reset
1323523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1324523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1325523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
1326523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1327523514edSGeliang Tang	chk_join_nr "single subflow IPv6" 1 1 1
1328523514edSGeliang Tang
1329523514edSGeliang Tang	# add_address, unused IPv6
1330523514edSGeliang Tang	reset
1331523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1332523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1333523514edSGeliang Tang	chk_join_nr "unused signal address IPv6" 0 0 0
1334523514edSGeliang Tang	chk_add_nr 1 1
1335523514edSGeliang Tang
1336523514edSGeliang Tang	# signal address IPv6
1337523514edSGeliang Tang	reset
1338523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1339523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1340523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1341523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1342523514edSGeliang Tang	chk_join_nr "single address IPv6" 1 1 1
1343523514edSGeliang Tang	chk_add_nr 1 1
1344523514edSGeliang Tang
1345523514edSGeliang Tang	# single address IPv6, remove
1346523514edSGeliang Tang	reset
1347523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1348523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1349523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
13502e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
1351523514edSGeliang Tang	chk_join_nr "remove single address IPv6" 1 1 1
1352523514edSGeliang Tang	chk_add_nr 1 1
13537028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1354523514edSGeliang Tang
1355523514edSGeliang Tang	# subflow and signal IPv6, remove
1356523514edSGeliang Tang	reset
1357523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1358523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1359523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1360523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
13612e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
1362523514edSGeliang Tang	chk_join_nr "remove subflow and signal IPv6" 2 2 2
1363523514edSGeliang Tang	chk_add_nr 1 1
1364523514edSGeliang Tang	chk_rm_nr 1 1
13651002b89fSGeliang Tang}
1366523514edSGeliang Tang
13671002b89fSGeliang Tangv4mapped_tests()
13681002b89fSGeliang Tang{
1369a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
1370a6094788SGeliang Tang	reset
1371a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1372a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1373a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1374a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1375a6094788SGeliang Tang	chk_join_nr "single subflow IPv4-mapped" 1 1 1
1376a6094788SGeliang Tang
1377a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
1378a6094788SGeliang Tang	reset
1379a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1380a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1381a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1382a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1383a6094788SGeliang Tang	chk_join_nr "signal address IPv4-mapped" 1 1 1
1384a6094788SGeliang Tang	chk_add_nr 1 1
1385a6094788SGeliang Tang
1386a6094788SGeliang Tang	# subflow v4-map-v6
1387a6094788SGeliang Tang	reset
1388a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1389a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1390a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1391a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1392a6094788SGeliang Tang	chk_join_nr "single subflow v4-map-v6" 1 1 1
1393a6094788SGeliang Tang
1394a6094788SGeliang Tang	# signal address v4-map-v6
1395a6094788SGeliang Tang	reset
1396a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1397a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1398a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1399a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1400a6094788SGeliang Tang	chk_join_nr "signal address v4-map-v6" 1 1 1
1401a6094788SGeliang Tang	chk_add_nr 1 1
1402a6094788SGeliang Tang
1403a6094788SGeliang Tang	# subflow v6-map-v4
1404a6094788SGeliang Tang	reset
1405a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1406a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1407a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1408a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1409a6094788SGeliang Tang	chk_join_nr "single subflow v6-map-v4" 1 1 1
1410a6094788SGeliang Tang
1411a6094788SGeliang Tang	# signal address v6-map-v4
1412a6094788SGeliang Tang	reset
1413a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1414a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1415a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1416a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1417a6094788SGeliang Tang	chk_join_nr "signal address v6-map-v4" 1 1 1
1418a6094788SGeliang Tang	chk_add_nr 1 1
1419a6094788SGeliang Tang
1420a6094788SGeliang Tang	# no subflow IPv6 to v4 address
1421a6094788SGeliang Tang	reset
1422a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1423a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1424a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::2 flags subflow
1425a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1426a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1427a6094788SGeliang Tang
1428a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1429a6094788SGeliang Tang	reset
1430a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1431a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1432a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::10.0.3.2 flags subflow
1433a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1434a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
1435a6094788SGeliang Tang
1436a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
1437a6094788SGeliang Tang	reset
1438a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1439a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1440a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1441a6094788SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1
1442a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
14431002b89fSGeliang Tang}
1444a6094788SGeliang Tang
14451002b89fSGeliang Tangbackup_tests()
14461002b89fSGeliang Tang{
1447718eb44eSGeliang Tang	# single subflow, backup
1448718eb44eSGeliang Tang	reset
1449718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1450718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1451718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,backup
1452718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
1453718eb44eSGeliang Tang	chk_join_nr "single subflow, backup" 1 1 1
1454718eb44eSGeliang Tang	chk_prio_nr 0 1
1455718eb44eSGeliang Tang
1456718eb44eSGeliang Tang	# single address, backup
1457718eb44eSGeliang Tang	reset
1458718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1459718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1460718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1461718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
1462718eb44eSGeliang Tang	chk_join_nr "single address, backup" 1 1 1
1463718eb44eSGeliang Tang	chk_add_nr 1 1
1464718eb44eSGeliang Tang	chk_prio_nr 1 0
14651002b89fSGeliang Tang}
1466718eb44eSGeliang Tang
14671002b89fSGeliang Tangadd_addr_ports_tests()
14681002b89fSGeliang Tang{
14698a127bf6SGeliang Tang	# signal address with port
14708a127bf6SGeliang Tang	reset
14718a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
14728a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14738a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
14748a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
14758a127bf6SGeliang Tang	chk_join_nr "signal address with port" 1 1 1
14768a127bf6SGeliang Tang	chk_add_nr 1 1 1
14778a127bf6SGeliang Tang
14788a127bf6SGeliang Tang	# subflow and signal with port
14798a127bf6SGeliang Tang	reset
14808a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
14818a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
14828a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
14838a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
14848a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
14858a127bf6SGeliang Tang	chk_join_nr "subflow and signal with port" 2 2 2
14868a127bf6SGeliang Tang	chk_add_nr 1 1 1
14878a127bf6SGeliang Tang
14888a127bf6SGeliang Tang	# single address with port, remove
14898a127bf6SGeliang Tang	reset
14908a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
14918a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
14928a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14938a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
14948a127bf6SGeliang Tang	chk_join_nr "remove single address with port" 1 1 1
14958a127bf6SGeliang Tang	chk_add_nr 1 1 1
14967028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
14978a127bf6SGeliang Tang
14988a127bf6SGeliang Tang	# subflow and signal with port, remove
14998a127bf6SGeliang Tang	reset
15008a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
15018a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15028a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
15038a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15048a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
15058a127bf6SGeliang Tang	chk_join_nr "remove subflow and signal with port" 2 2 2
15068a127bf6SGeliang Tang	chk_add_nr 1 1 1
15078a127bf6SGeliang Tang	chk_rm_nr 1 1
15088a127bf6SGeliang Tang
15098a127bf6SGeliang Tang	# subflows and signal with port, flush
15108a127bf6SGeliang Tang	reset
15118a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
15128a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15138a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
15148a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15158a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
15168a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
15178a127bf6SGeliang Tang	chk_join_nr "flush subflows and signal with port" 3 3 3
15188a127bf6SGeliang Tang	chk_add_nr 1 1
15198a127bf6SGeliang Tang	chk_rm_nr 2 2
15208a127bf6SGeliang Tang
15218a127bf6SGeliang Tang	# multiple addresses with port
15228a127bf6SGeliang Tang	reset
15238a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
15248a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15258a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100
15268a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
15278a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15288a127bf6SGeliang Tang	chk_join_nr "multiple addresses with port" 2 2 2
15298a127bf6SGeliang Tang	chk_add_nr 2 2 2
15308a127bf6SGeliang Tang
15318a127bf6SGeliang Tang	# multiple addresses with ports
15328a127bf6SGeliang Tang	reset
15338a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
15348a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15358a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101
15368a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
15378a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15388a127bf6SGeliang Tang	chk_join_nr "multiple addresses with ports" 2 2 2
15398a127bf6SGeliang Tang	chk_add_nr 2 2 2
15401002b89fSGeliang Tang}
15418a127bf6SGeliang Tang
15421002b89fSGeliang Tangsyncookies_tests()
15431002b89fSGeliang Tang{
154400587187SFlorian Westphal	# single subflow, syncookies
154500587187SFlorian Westphal	reset_with_cookies
154600587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
154700587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
154800587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
154900587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
155000587187SFlorian Westphal	chk_join_nr "single subflow with syn cookies" 1 1 1
155100587187SFlorian Westphal
155200587187SFlorian Westphal	# multiple subflows with syn cookies
155300587187SFlorian Westphal	reset_with_cookies
155400587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
155500587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
155600587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
155700587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
155800587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
155900587187SFlorian Westphal	chk_join_nr "multiple subflows with syn cookies" 2 2 2
156000587187SFlorian Westphal
156100587187SFlorian Westphal	# multiple subflows limited by server
156200587187SFlorian Westphal	reset_with_cookies
156300587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
156400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
156500587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
156600587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
156700587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
1568a7da4416SJianguo Wu	chk_join_nr "subflows limited by server w cookies" 2 1 1
156900587187SFlorian Westphal
157000587187SFlorian Westphal	# test signal address with cookies
157100587187SFlorian Westphal	reset_with_cookies
157200587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
157300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
157400587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
157500587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
157600587187SFlorian Westphal	chk_join_nr "signal address with syn cookies" 1 1 1
1577be613160SGeliang Tang	chk_add_nr 1 1
157800587187SFlorian Westphal
157900587187SFlorian Westphal	# test cookie with subflow and signal
158000587187SFlorian Westphal	reset_with_cookies
158100587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
158200587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
158300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
158400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
158500587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
158600587187SFlorian Westphal	chk_join_nr "subflow and signal w cookies" 2 2 2
1587be613160SGeliang Tang	chk_add_nr 1 1
158800587187SFlorian Westphal
158900587187SFlorian Westphal	# accept and use add_addr with additional subflows
159000587187SFlorian Westphal	reset_with_cookies
159100587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
159200587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
159300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
159400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
159500587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
159600587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
159700587187SFlorian Westphal	chk_join_nr "subflows and signal w. cookies" 3 3 3
1598be613160SGeliang Tang	chk_add_nr 1 1
15991002b89fSGeliang Tang}
16001002b89fSGeliang Tang
1601af66d3e1SGeliang Tangchecksum_tests()
1602af66d3e1SGeliang Tang{
1603af66d3e1SGeliang Tang	# checksum test 0 0
1604af66d3e1SGeliang Tang	reset_with_checksum 0 0
1605af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1606af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1607af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1608af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 0"
1609af66d3e1SGeliang Tang
1610af66d3e1SGeliang Tang	# checksum test 1 1
1611af66d3e1SGeliang Tang	reset_with_checksum 1 1
1612af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1613af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1614af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1615af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 1"
1616af66d3e1SGeliang Tang
1617af66d3e1SGeliang Tang	# checksum test 0 1
1618af66d3e1SGeliang Tang	reset_with_checksum 0 1
1619af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1620af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1621af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1622af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 1"
1623af66d3e1SGeliang Tang
1624af66d3e1SGeliang Tang	# checksum test 1 0
1625af66d3e1SGeliang Tang	reset_with_checksum 1 0
1626af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1627af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1628af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1629af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 0"
1630af66d3e1SGeliang Tang}
1631af66d3e1SGeliang Tang
16320cddb4a6SGeliang Tangdeny_join_id0_tests()
16330cddb4a6SGeliang Tang{
16340cddb4a6SGeliang Tang	# subflow allow join id0 ns1
16350cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
16360cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
16370cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
16380cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
16390cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16400cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns1" 1 1 1
16410cddb4a6SGeliang Tang
16420cddb4a6SGeliang Tang	# subflow allow join id0 ns2
16430cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
16440cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
16450cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
16460cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
16470cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16480cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns2" 0 0 0
16490cddb4a6SGeliang Tang
16500cddb4a6SGeliang Tang	# signal address allow join id0 ns1
16510cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
16520cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
16530cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
16540cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
16550cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
16560cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16570cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns1" 1 1 1
16580cddb4a6SGeliang Tang	chk_add_nr 1 1
16590cddb4a6SGeliang Tang
16600cddb4a6SGeliang Tang	# signal address allow join id0 ns2
16610cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
16620cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
16630cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
16640cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
16650cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
16660cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16670cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns2" 1 1 1
16680cddb4a6SGeliang Tang	chk_add_nr 1 1
16690cddb4a6SGeliang Tang
16700cddb4a6SGeliang Tang	# subflow and address allow join id0 ns1
16710cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
16720cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
16730cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
16740cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
16750cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
16760cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16770cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 1" 2 2 2
16780cddb4a6SGeliang Tang
16790cddb4a6SGeliang Tang	# subflow and address allow join id0 ns2
16800cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
16810cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
16820cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
16830cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
16840cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
16850cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16860cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 2" 1 1 1
16870cddb4a6SGeliang Tang}
16880cddb4a6SGeliang Tang
16891002b89fSGeliang Tangall_tests()
16901002b89fSGeliang Tang{
16911002b89fSGeliang Tang	subflows_tests
16921002b89fSGeliang Tang	signal_address_tests
16931002b89fSGeliang Tang	link_failure_tests
16941002b89fSGeliang Tang	add_addr_timeout_tests
16951002b89fSGeliang Tang	remove_tests
16961002b89fSGeliang Tang	add_tests
16971002b89fSGeliang Tang	ipv6_tests
16981002b89fSGeliang Tang	v4mapped_tests
16991002b89fSGeliang Tang	backup_tests
17001002b89fSGeliang Tang	add_addr_ports_tests
17011002b89fSGeliang Tang	syncookies_tests
1702af66d3e1SGeliang Tang	checksum_tests
17030cddb4a6SGeliang Tang	deny_join_id0_tests
17041002b89fSGeliang Tang}
17051002b89fSGeliang Tang
17061002b89fSGeliang Tangusage()
17071002b89fSGeliang Tang{
17081002b89fSGeliang Tang	echo "mptcp_join usage:"
17091002b89fSGeliang Tang	echo "  -f subflows_tests"
17101002b89fSGeliang Tang	echo "  -s signal_address_tests"
17111002b89fSGeliang Tang	echo "  -l link_failure_tests"
17121002b89fSGeliang Tang	echo "  -t add_addr_timeout_tests"
17131002b89fSGeliang Tang	echo "  -r remove_tests"
17141002b89fSGeliang Tang	echo "  -a add_tests"
17151002b89fSGeliang Tang	echo "  -6 ipv6_tests"
17161002b89fSGeliang Tang	echo "  -4 v4mapped_tests"
17171002b89fSGeliang Tang	echo "  -b backup_tests"
17181002b89fSGeliang Tang	echo "  -p add_addr_ports_tests"
1719a673321aSMat Martineau	echo "  -k syncookies_tests"
1720af66d3e1SGeliang Tang	echo "  -S checksum_tests"
17210cddb4a6SGeliang Tang	echo "  -d deny_join_id0_tests"
1722a673321aSMat Martineau	echo "  -c capture pcap files"
1723af66d3e1SGeliang Tang	echo "  -C enable data checksum"
17241002b89fSGeliang Tang	echo "  -h help"
17251002b89fSGeliang Tang}
17261002b89fSGeliang Tang
17271002b89fSGeliang Tangsin=$(mktemp)
17281002b89fSGeliang Tangsout=$(mktemp)
17291002b89fSGeliang Tangcin=$(mktemp)
17301002b89fSGeliang Tangcinsent=$(mktemp)
17311002b89fSGeliang Tangcout=$(mktemp)
17321002b89fSGeliang Tanginit
17331002b89fSGeliang Tangmake_file "$cin" "client" 1
17341002b89fSGeliang Tangmake_file "$sin" "server" 1
17351002b89fSGeliang Tangtrap cleanup EXIT
17361002b89fSGeliang Tang
1737a673321aSMat Martineaufor arg in "$@"; do
1738af66d3e1SGeliang Tang	# check for "capture/checksum" args before launching tests
1739a673321aSMat Martineau	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"c"[0-9a-zA-Z]*$ ]]; then
1740a673321aSMat Martineau		capture=1
1741a673321aSMat Martineau	fi
1742af66d3e1SGeliang Tang	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"C"[0-9a-zA-Z]*$ ]]; then
1743af66d3e1SGeliang Tang		checksum=1
1744af66d3e1SGeliang Tang	fi
1745a673321aSMat Martineau
1746af66d3e1SGeliang Tang	# exception for the capture/checksum options, the rest means: a part of the tests
1747af66d3e1SGeliang Tang	if [ "${arg}" != "-c" ] && [ "${arg}" != "-C" ]; then
1748a673321aSMat Martineau		do_all_tests=0
1749a673321aSMat Martineau	fi
1750a673321aSMat Martineaudone
1751a673321aSMat Martineau
1752a673321aSMat Martineauif [ $do_all_tests -eq 1 ]; then
17531002b89fSGeliang Tang	all_tests
17541002b89fSGeliang Tang	exit $ret
17551002b89fSGeliang Tangfi
17561002b89fSGeliang Tang
17570cddb4a6SGeliang Tangwhile getopts 'fsltra64bpkdchCS' opt; do
17581002b89fSGeliang Tang	case $opt in
17591002b89fSGeliang Tang		f)
17601002b89fSGeliang Tang			subflows_tests
17611002b89fSGeliang Tang			;;
17621002b89fSGeliang Tang		s)
17631002b89fSGeliang Tang			signal_address_tests
17641002b89fSGeliang Tang			;;
17651002b89fSGeliang Tang		l)
17661002b89fSGeliang Tang			link_failure_tests
17671002b89fSGeliang Tang			;;
17681002b89fSGeliang Tang		t)
17691002b89fSGeliang Tang			add_addr_timeout_tests
17701002b89fSGeliang Tang			;;
17711002b89fSGeliang Tang		r)
17721002b89fSGeliang Tang			remove_tests
17731002b89fSGeliang Tang			;;
17741002b89fSGeliang Tang		a)
17751002b89fSGeliang Tang			add_tests
17761002b89fSGeliang Tang			;;
17771002b89fSGeliang Tang		6)
17781002b89fSGeliang Tang			ipv6_tests
17791002b89fSGeliang Tang			;;
17801002b89fSGeliang Tang		4)
17811002b89fSGeliang Tang			v4mapped_tests
17821002b89fSGeliang Tang			;;
17831002b89fSGeliang Tang		b)
17841002b89fSGeliang Tang			backup_tests
17851002b89fSGeliang Tang			;;
17861002b89fSGeliang Tang		p)
17871002b89fSGeliang Tang			add_addr_ports_tests
17881002b89fSGeliang Tang			;;
1789a673321aSMat Martineau		k)
17901002b89fSGeliang Tang			syncookies_tests
17911002b89fSGeliang Tang			;;
1792af66d3e1SGeliang Tang		S)
1793af66d3e1SGeliang Tang			checksum_tests
1794af66d3e1SGeliang Tang			;;
17950cddb4a6SGeliang Tang		d)
17960cddb4a6SGeliang Tang			deny_join_id0_tests
17970cddb4a6SGeliang Tang			;;
1798a673321aSMat Martineau		c)
1799a673321aSMat Martineau			;;
1800af66d3e1SGeliang Tang		C)
1801af66d3e1SGeliang Tang			;;
18021002b89fSGeliang Tang		h | *)
18031002b89fSGeliang Tang			usage
18041002b89fSGeliang Tang			;;
18051002b89fSGeliang Tang	esac
18061002b89fSGeliang Tangdone
180700587187SFlorian Westphal
1808b08fbf24SPaolo Abeniexit $ret
1809