1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4b08fbf24SPaolo Abeniret=0
5b08fbf24SPaolo Abenisin=""
67d1e6f16SPaolo Abenisinfail=""
7b08fbf24SPaolo Abenisout=""
8b08fbf24SPaolo Abenicin=""
97d1e6f16SPaolo 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
817d1e6f16SPaolo Abeniinit_shapers()
827d1e6f16SPaolo Abeni{
837d1e6f16SPaolo Abeni	for i in `seq 1 4`; do
847d1e6f16SPaolo Abeni		tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
857d1e6f16SPaolo Abeni		tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
867d1e6f16SPaolo Abeni	done
877d1e6f16SPaolo Abeni}
887d1e6f16SPaolo 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{
1017d1e6f16SPaolo Abeni	rm -f "$cin" "$cout" "$sinfail"
1027d1e6f16SPaolo 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
2247d1e6f16SPaolo Abeni	if [ -z "$FAILING_LINKS" ]; then
2258b819a84SFlorian Westphal		l=$((RANDOM%4))
2267d1e6f16SPaolo Abeni		FAILING_LINKS=$((l+1))
2277d1e6f16SPaolo Abeni	fi
2288b819a84SFlorian Westphal
2297d1e6f16SPaolo Abeni	for l in $FAILING_LINKS; do
2308b819a84SFlorian Westphal		veth="ns1eth$l"
2318b819a84SFlorian Westphal		ip -net "$ns" link set "$veth" down
2327d1e6f16SPaolo 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
2977d1e6f16SPaolo Abeni	if [ "$test_link_fail" -eq 2 ];then
2987d1e6f16SPaolo Abeni		timeout ${timeout_test} \
2997d1e6f16SPaolo Abeni			ip netns exec ${listener_ns} \
3007c909a98SGeliang Tang				$mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
3017d1e6f16SPaolo Abeni					${local_addr} < "$sinfail" > "$sout" &
3027d1e6f16SPaolo 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" &
3077d1e6f16SPaolo 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
3187d1e6f16SPaolo 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
347f7713dd5SGeliang Tang			pos=1
348f87744adSGeliang Tang			dump=(`ip netns exec ${listener_ns} ./pm_nl_ctl dump`)
349f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
350dd72b0feSGeliang Tang				sleep 1
351dd72b0feSGeliang Tang
352dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns1 ]
353dd72b0feSGeliang Tang				do
354f7713dd5SGeliang Tang					id=${dump[$pos]}
355f87744adSGeliang Tang					ip netns exec ${listener_ns} ./pm_nl_ctl del $id
356dd72b0feSGeliang Tang					sleep 1
357dd72b0feSGeliang Tang					let counter+=1
358f7713dd5SGeliang Tang					let pos+=5
359dd72b0feSGeliang Tang				done
360f87744adSGeliang Tang			fi
3615e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 8 ]; then
3626fe4ccdcSGeliang Tang			sleep 1
3636fe4ccdcSGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl flush
3645e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 9 ]; then
3655e287fe7SGeliang Tang			sleep 1
3665e287fe7SGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl del 0 ${connect_addr}
3676fe4ccdcSGeliang Tang		fi
368dd72b0feSGeliang Tang	fi
369dd72b0feSGeliang Tang
3704f49d633SGeliang Tang	flags="subflow"
3714f49d633SGeliang Tang	if [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
3724f49d633SGeliang Tang		flags="${flags},fullmesh"
3734f49d633SGeliang Tang		addr_nr_ns2=${addr_nr_ns2:9}
3744f49d633SGeliang Tang	fi
3754f49d633SGeliang Tang
3766208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
3776208fd82SGeliang Tang		let add_nr_ns2=addr_nr_ns2
3786208fd82SGeliang Tang		counter=3
3796208fd82SGeliang Tang		sleep 1
3806208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
3816208fd82SGeliang Tang			local addr
3826208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3836208fd82SGeliang Tang				addr="dead:beef:$counter::2"
3846208fd82SGeliang Tang			else
3856208fd82SGeliang Tang				addr="10.0.$counter.2"
3866208fd82SGeliang Tang			fi
3874f49d633SGeliang Tang			ip netns exec $ns2 ./pm_nl_ctl add $addr flags $flags
3886208fd82SGeliang Tang			let counter+=1
3896208fd82SGeliang Tang			let add_nr_ns2-=1
3906208fd82SGeliang Tang		done
3916208fd82SGeliang Tang		sleep 1
3926208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
3932e8cbf45SGeliang Tang		let rm_nr_ns2=-addr_nr_ns2
3946fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
395dd72b0feSGeliang Tang			counter=1
396f7713dd5SGeliang Tang			pos=1
397f87744adSGeliang Tang			dump=(`ip netns exec ${connector_ns} ./pm_nl_ctl dump`)
398f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
399dd72b0feSGeliang Tang				sleep 1
400dd72b0feSGeliang Tang
401dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns2 ]
402dd72b0feSGeliang Tang				do
403f7713dd5SGeliang Tang					id=${dump[$pos]}
404f87744adSGeliang Tang					ip netns exec ${connector_ns} ./pm_nl_ctl del $id
405dd72b0feSGeliang Tang					sleep 1
406dd72b0feSGeliang Tang					let counter+=1
407f7713dd5SGeliang Tang					let pos+=5
408dd72b0feSGeliang Tang				done
409f87744adSGeliang Tang			fi
4105e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 8 ]; then
4116fe4ccdcSGeliang Tang			sleep 1
4126fe4ccdcSGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl flush
4135e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 9 ]; then
4145e287fe7SGeliang Tang			local addr
4155e287fe7SGeliang Tang			if is_v6 "${connect_addr}"; then
4165e287fe7SGeliang Tang				addr="dead:beef:1::2"
4175e287fe7SGeliang Tang			else
4185e287fe7SGeliang Tang				addr="10.0.1.2"
4195e287fe7SGeliang Tang			fi
4205e287fe7SGeliang Tang			sleep 1
4215e287fe7SGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl del 0 $addr
4226fe4ccdcSGeliang Tang		fi
423dd72b0feSGeliang Tang	fi
424dd72b0feSGeliang Tang
425718eb44eSGeliang Tang	if [ ! -z $bkup ]; then
426718eb44eSGeliang Tang		sleep 1
427718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
428718eb44eSGeliang Tang			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
429718eb44eSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
430718eb44eSGeliang Tang				addr=${dump[${#dump[@]} - 1]}
431718eb44eSGeliang Tang				backup="ip netns exec $netns ./pm_nl_ctl set $addr flags $bkup"
432718eb44eSGeliang Tang				$backup
433718eb44eSGeliang Tang			fi
434718eb44eSGeliang Tang		done
435718eb44eSGeliang Tang	fi
436718eb44eSGeliang Tang
437b08fbf24SPaolo Abeni	wait $cpid
438b08fbf24SPaolo Abeni	retc=$?
439b08fbf24SPaolo Abeni	wait $spid
440b08fbf24SPaolo Abeni	rets=$?
441b08fbf24SPaolo Abeni
442b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
443b08fbf24SPaolo Abeni	    sleep 1
444b08fbf24SPaolo Abeni	    kill $cappid
445b08fbf24SPaolo Abeni	fi
446b08fbf24SPaolo Abeni
447c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
448c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${listener_ns}.out
449c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
450c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${connector_ns}.out
451c2a55e8fSMatthieu Baerts
452b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
453b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
4548b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
455c2a55e8fSMatthieu Baerts		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
456c2a55e8fSMatthieu Baerts		cat /tmp/${listener_ns}.out
4578b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
458c2a55e8fSMatthieu Baerts		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
459c2a55e8fSMatthieu Baerts		cat /tmp/${connector_ns}.out
460b08fbf24SPaolo Abeni
461b08fbf24SPaolo Abeni		cat "$capout"
4628b819a84SFlorian Westphal		ret=1
463b08fbf24SPaolo Abeni		return 1
464b08fbf24SPaolo Abeni	fi
465b08fbf24SPaolo Abeni
4667d1e6f16SPaolo Abeni	if [ "$test_link_fail" -eq 2 ];then
4677d1e6f16SPaolo Abeni		check_transfer $sinfail $cout "file received by client"
4687d1e6f16SPaolo Abeni	else
469b08fbf24SPaolo Abeni		check_transfer $sin $cout "file received by client"
4707d1e6f16SPaolo Abeni	fi
471b08fbf24SPaolo Abeni	retc=$?
4728b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
473b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
4748b819a84SFlorian Westphal	else
4758b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
4768b819a84SFlorian Westphal	fi
477b08fbf24SPaolo Abeni	rets=$?
478b08fbf24SPaolo Abeni
479b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
480b08fbf24SPaolo Abeni		cat "$capout"
481b08fbf24SPaolo Abeni		return 0
482b08fbf24SPaolo Abeni	fi
483b08fbf24SPaolo Abeni
484b08fbf24SPaolo Abeni	cat "$capout"
485b08fbf24SPaolo Abeni	return 1
486b08fbf24SPaolo Abeni}
487b08fbf24SPaolo Abeni
488b08fbf24SPaolo Abenimake_file()
489b08fbf24SPaolo Abeni{
490b08fbf24SPaolo Abeni	name=$1
491b08fbf24SPaolo Abeni	who=$2
4928b819a84SFlorian Westphal	size=$3
493b08fbf24SPaolo Abeni
4948b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
495b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
496b08fbf24SPaolo Abeni
4978b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
498b08fbf24SPaolo Abeni}
499b08fbf24SPaolo Abeni
500b08fbf24SPaolo Abenirun_tests()
501b08fbf24SPaolo Abeni{
502b08fbf24SPaolo Abeni	listener_ns="$1"
503b08fbf24SPaolo Abeni	connector_ns="$2"
504b08fbf24SPaolo Abeni	connect_addr="$3"
5058b819a84SFlorian Westphal	test_linkfail="${4:-0}"
5062e8cbf45SGeliang Tang	addr_nr_ns1="${5:-0}"
5072e8cbf45SGeliang Tang	addr_nr_ns2="${6:-0}"
5088b819a84SFlorian Westphal	speed="${7:-fast}"
509718eb44eSGeliang Tang	bkup="${8:-""}"
510b08fbf24SPaolo Abeni	lret=0
5118b819a84SFlorian Westphal	oldin=""
5128b819a84SFlorian Westphal
5137d1e6f16SPaolo Abeni	# create the input file for the failure test when
5147d1e6f16SPaolo Abeni	# the first failure test run
5157d1e6f16SPaolo Abeni	if [ "$test_linkfail" -ne 0 -a -z "$cinfail" ]; then
5167d1e6f16SPaolo Abeni		# the client file must be considerably larger
5177d1e6f16SPaolo Abeni		# of the maximum expected cwin value, or the
5187d1e6f16SPaolo Abeni		# link utilization will be not predicable
5197d1e6f16SPaolo Abeni		size=$((RANDOM%2))
5208b819a84SFlorian Westphal		size=$((size+1))
5217d1e6f16SPaolo Abeni		size=$((size*8192))
5227d1e6f16SPaolo Abeni		size=$((size + ( $RANDOM % 8192) ))
5238b819a84SFlorian Westphal
5247d1e6f16SPaolo Abeni		cinfail=$(mktemp)
5257d1e6f16SPaolo Abeni		make_file "$cinfail" "client" $size
5267d1e6f16SPaolo Abeni	fi
5277d1e6f16SPaolo Abeni
5287d1e6f16SPaolo Abeni	if [ "$test_linkfail" -eq 2 -a -z "$sinfail" ]; then
5297d1e6f16SPaolo Abeni		size=$((RANDOM%16))
5307d1e6f16SPaolo Abeni		size=$((size+1))
5317d1e6f16SPaolo Abeni		size=$((size*2048))
5327d1e6f16SPaolo Abeni
5337d1e6f16SPaolo Abeni		sinfail=$(mktemp)
5347d1e6f16SPaolo Abeni		make_file "$sinfail" "server" $size
5358b819a84SFlorian Westphal	fi
536b08fbf24SPaolo Abeni
5378d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
5382e8cbf45SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${bkup}
539b08fbf24SPaolo Abeni	lret=$?
540b08fbf24SPaolo Abeni}
541b08fbf24SPaolo Abeni
542af66d3e1SGeliang Tangchk_csum_nr()
543af66d3e1SGeliang Tang{
544af66d3e1SGeliang Tang	local msg=${1:-""}
545af66d3e1SGeliang Tang	local count
546af66d3e1SGeliang Tang	local dump_stats
547af66d3e1SGeliang Tang
548af66d3e1SGeliang Tang	if [ ! -z "$msg" ]; then
549af66d3e1SGeliang Tang		printf "%02u" "$TEST_COUNT"
550af66d3e1SGeliang Tang	else
551af66d3e1SGeliang Tang		echo -n "  "
552af66d3e1SGeliang Tang	fi
553af66d3e1SGeliang Tang	printf " %-36s %s" "$msg" "sum"
554af66d3e1SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
555af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
556af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
557af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
558af66d3e1SGeliang Tang		ret=1
559af66d3e1SGeliang Tang		dump_stats=1
560af66d3e1SGeliang Tang	else
561af66d3e1SGeliang Tang		echo -n "[ ok ]"
562af66d3e1SGeliang Tang	fi
563af66d3e1SGeliang Tang	echo -n " - csum  "
564af66d3e1SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
565af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
566af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
567af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
568af66d3e1SGeliang Tang		ret=1
569af66d3e1SGeliang Tang		dump_stats=1
570af66d3e1SGeliang Tang	else
571af66d3e1SGeliang Tang		echo "[ ok ]"
572af66d3e1SGeliang Tang	fi
573af66d3e1SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
574af66d3e1SGeliang Tang		echo Server ns stats
575af66d3e1SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
576af66d3e1SGeliang Tang		echo Client ns stats
577af66d3e1SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
578af66d3e1SGeliang Tang	fi
579af66d3e1SGeliang Tang}
580af66d3e1SGeliang Tang
5816bb3ab49SGeliang Tangchk_fail_nr()
5826bb3ab49SGeliang Tang{
5836bb3ab49SGeliang Tang	local mp_fail_nr_tx=$1
5846bb3ab49SGeliang Tang	local mp_fail_nr_rx=$2
5856bb3ab49SGeliang Tang	local count
5866bb3ab49SGeliang Tang	local dump_stats
5876bb3ab49SGeliang Tang
5886bb3ab49SGeliang Tang	printf "%-39s %s" " " "ftx"
5896bb3ab49SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}'`
5906bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
5916bb3ab49SGeliang Tang	if [ "$count" != "$mp_fail_nr_tx" ]; then
5926bb3ab49SGeliang Tang		echo "[fail] got $count MP_FAIL[s] TX expected $mp_fail_nr_tx"
5936bb3ab49SGeliang Tang		ret=1
5946bb3ab49SGeliang Tang		dump_stats=1
5956bb3ab49SGeliang Tang	else
5966bb3ab49SGeliang Tang		echo -n "[ ok ]"
5976bb3ab49SGeliang Tang	fi
5986bb3ab49SGeliang Tang
5996bb3ab49SGeliang Tang	echo -n " - frx   "
6006bb3ab49SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}'`
6016bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
6026bb3ab49SGeliang Tang	if [ "$count" != "$mp_fail_nr_rx" ]; then
6036bb3ab49SGeliang Tang		echo "[fail] got $count MP_FAIL[s] RX expected $mp_fail_nr_rx"
6046bb3ab49SGeliang Tang		ret=1
6056bb3ab49SGeliang Tang		dump_stats=1
6066bb3ab49SGeliang Tang	else
6076bb3ab49SGeliang Tang		echo "[ ok ]"
6086bb3ab49SGeliang Tang	fi
6096bb3ab49SGeliang Tang
6106bb3ab49SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
6116bb3ab49SGeliang Tang		echo Server ns stats
6126bb3ab49SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
6136bb3ab49SGeliang Tang		echo Client ns stats
6146bb3ab49SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
6156bb3ab49SGeliang Tang	fi
6166bb3ab49SGeliang Tang}
6176bb3ab49SGeliang Tang
618b08fbf24SPaolo Abenichk_join_nr()
619b08fbf24SPaolo Abeni{
620b08fbf24SPaolo Abeni	local msg="$1"
621b08fbf24SPaolo Abeni	local syn_nr=$2
622b08fbf24SPaolo Abeni	local syn_ack_nr=$3
623b08fbf24SPaolo Abeni	local ack_nr=$4
624b08fbf24SPaolo Abeni	local count
625b08fbf24SPaolo Abeni	local dump_stats
626b08fbf24SPaolo Abeni
62700587187SFlorian Westphal	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
628b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
629b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
630b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
631b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
632b08fbf24SPaolo Abeni		ret=1
633b08fbf24SPaolo Abeni		dump_stats=1
634b08fbf24SPaolo Abeni	else
635b08fbf24SPaolo Abeni		echo -n "[ ok ]"
636b08fbf24SPaolo Abeni	fi
637b08fbf24SPaolo Abeni
638b08fbf24SPaolo Abeni	echo -n " - synack"
639b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
640b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
641b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
642b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
643b08fbf24SPaolo Abeni		ret=1
644b08fbf24SPaolo Abeni		dump_stats=1
645b08fbf24SPaolo Abeni	else
646b08fbf24SPaolo Abeni		echo -n "[ ok ]"
647b08fbf24SPaolo Abeni	fi
648b08fbf24SPaolo Abeni
649b08fbf24SPaolo Abeni	echo -n " - ack"
650b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
651b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
652b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
653b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
654b08fbf24SPaolo Abeni		ret=1
655b08fbf24SPaolo Abeni		dump_stats=1
656b08fbf24SPaolo Abeni	else
657b08fbf24SPaolo Abeni		echo "[ ok ]"
658b08fbf24SPaolo Abeni	fi
659b08fbf24SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
660b08fbf24SPaolo Abeni		echo Server ns stats
661b08fbf24SPaolo Abeni		ip netns exec $ns1 nstat -as | grep MPTcp
662b08fbf24SPaolo Abeni		echo Client ns stats
663b08fbf24SPaolo Abeni		ip netns exec $ns2 nstat -as | grep MPTcp
664b08fbf24SPaolo Abeni	fi
665af66d3e1SGeliang Tang	if [ $checksum -eq 1 ]; then
666af66d3e1SGeliang Tang		chk_csum_nr
6676bb3ab49SGeliang Tang		chk_fail_nr 0 0
668af66d3e1SGeliang Tang	fi
669b08fbf24SPaolo Abeni}
670b08fbf24SPaolo Abeni
6717d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound:
6727d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while
6737d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of
6747d1e6f16SPaolo Abeni# stale/recover conversions, proportional to
6757d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval.
6767d1e6f16SPaolo Abenichk_stale_nr()
6777d1e6f16SPaolo Abeni{
6787d1e6f16SPaolo Abeni	local ns=$1
6797d1e6f16SPaolo Abeni	local stale_min=$2
6807d1e6f16SPaolo Abeni	local stale_max=$3
6817d1e6f16SPaolo Abeni	local stale_delta=$4
6827d1e6f16SPaolo Abeni	local dump_stats
6837d1e6f16SPaolo Abeni	local stale_nr
6847d1e6f16SPaolo Abeni	local recover_nr
6857d1e6f16SPaolo Abeni
6867d1e6f16SPaolo Abeni	printf "%-39s %-18s" " " "stale"
6877d1e6f16SPaolo Abeni	stale_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}'`
6887d1e6f16SPaolo Abeni	[ -z "$stale_nr" ] && stale_nr=0
6897d1e6f16SPaolo Abeni	recover_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}'`
6907d1e6f16SPaolo Abeni	[ -z "$recover_nr" ] && recover_nr=0
6917d1e6f16SPaolo Abeni
6927d1e6f16SPaolo Abeni	if [ $stale_nr -lt $stale_min ] ||
6937d1e6f16SPaolo Abeni	   [ $stale_max -gt 0 -a $stale_nr -gt $stale_max ] ||
6947d1e6f16SPaolo Abeni	   [ $((stale_nr - $recover_nr)) -ne $stale_delta ]; then
6957d1e6f16SPaolo Abeni		echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \
6967d1e6f16SPaolo Abeni		     " expected stale in range [$stale_min..$stale_max]," \
6977d1e6f16SPaolo Abeni		     " stale-recover delta $stale_delta "
6987d1e6f16SPaolo Abeni		ret=1
6997d1e6f16SPaolo Abeni		dump_stats=1
7007d1e6f16SPaolo Abeni	else
7017d1e6f16SPaolo Abeni		echo "[ ok ]"
7027d1e6f16SPaolo Abeni	fi
7037d1e6f16SPaolo Abeni
7047d1e6f16SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
7057d1e6f16SPaolo Abeni		echo $ns stats
7067d1e6f16SPaolo Abeni		ip netns exec $ns ip -s link show
7077d1e6f16SPaolo Abeni		ip netns exec $ns nstat -as | grep MPTcp
7087d1e6f16SPaolo Abeni	fi
7097d1e6f16SPaolo Abeni}
7107d1e6f16SPaolo Abeni
711be613160SGeliang Tangchk_add_nr()
712be613160SGeliang Tang{
713be613160SGeliang Tang	local add_nr=$1
714be613160SGeliang Tang	local echo_nr=$2
7158a127bf6SGeliang Tang	local port_nr=${3:-0}
7168a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
7178a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
7188a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
7198a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
7208a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
721be613160SGeliang Tang	local count
722be613160SGeliang Tang	local dump_stats
723be613160SGeliang Tang
724be613160SGeliang Tang	printf "%-39s %s" " " "add"
725be613160SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
726be613160SGeliang Tang	[ -z "$count" ] && count=0
727be613160SGeliang Tang	if [ "$count" != "$add_nr" ]; then
728be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
729be613160SGeliang Tang		ret=1
730be613160SGeliang Tang		dump_stats=1
731be613160SGeliang Tang	else
732be613160SGeliang Tang		echo -n "[ ok ]"
733be613160SGeliang Tang	fi
734be613160SGeliang Tang
735be613160SGeliang Tang	echo -n " - echo  "
736be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
737be613160SGeliang Tang	[ -z "$count" ] && count=0
738be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
739be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
740be613160SGeliang Tang		ret=1
741be613160SGeliang Tang		dump_stats=1
742be613160SGeliang Tang	else
7438a127bf6SGeliang Tang		echo -n "[ ok ]"
7448a127bf6SGeliang Tang	fi
7458a127bf6SGeliang Tang
7468a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
7478a127bf6SGeliang Tang		echo -n " - pt "
7488a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
7498a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7508a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
7518a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
7528a127bf6SGeliang Tang			ret=1
7538a127bf6SGeliang Tang			dump_stats=1
7548a127bf6SGeliang Tang		else
755be613160SGeliang Tang			echo "[ ok ]"
756be613160SGeliang Tang		fi
757be613160SGeliang Tang
7588a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
7598a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
7608a127bf6SGeliang Tang			awk '{print $2}'`
7618a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7628a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
7638a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
7648a127bf6SGeliang Tang				port-number expected $syn_nr"
7658a127bf6SGeliang Tang			ret=1
7668a127bf6SGeliang Tang			dump_stats=1
7678a127bf6SGeliang Tang		else
7688a127bf6SGeliang Tang			echo -n "[ ok ]"
7698a127bf6SGeliang Tang		fi
7708a127bf6SGeliang Tang
7718a127bf6SGeliang Tang		echo -n " - synack"
7728a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
7738a127bf6SGeliang Tang			awk '{print $2}'`
7748a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7758a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
7768a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
7778a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
7788a127bf6SGeliang Tang			ret=1
7798a127bf6SGeliang Tang			dump_stats=1
7808a127bf6SGeliang Tang		else
7818a127bf6SGeliang Tang			echo -n "[ ok ]"
7828a127bf6SGeliang Tang		fi
7838a127bf6SGeliang Tang
7848a127bf6SGeliang Tang		echo -n " - ack"
7858a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
7868a127bf6SGeliang Tang			awk '{print $2}'`
7878a127bf6SGeliang Tang		[ -z "$count" ] && count=0
7888a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
7898a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
7908a127bf6SGeliang Tang				port-number expected $ack_nr"
7918a127bf6SGeliang Tang			ret=1
7928a127bf6SGeliang Tang			dump_stats=1
7938a127bf6SGeliang Tang		else
7948a127bf6SGeliang Tang			echo "[ ok ]"
7958a127bf6SGeliang Tang		fi
7968a127bf6SGeliang Tang
7978a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
7988a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
7998a127bf6SGeliang Tang			awk '{print $2}'`
8008a127bf6SGeliang Tang		[ -z "$count" ] && count=0
8018a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
8028a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
8038a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
8048a127bf6SGeliang Tang			ret=1
8058a127bf6SGeliang Tang			dump_stats=1
8068a127bf6SGeliang Tang		else
8078a127bf6SGeliang Tang			echo -n "[ ok ]"
8088a127bf6SGeliang Tang		fi
8098a127bf6SGeliang Tang
8108a127bf6SGeliang Tang		echo -n " - ack   "
8118a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
8128a127bf6SGeliang Tang			awk '{print $2}'`
8138a127bf6SGeliang Tang		[ -z "$count" ] && count=0
8148a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
8158a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
8168a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
8178a127bf6SGeliang Tang			ret=1
8188a127bf6SGeliang Tang			dump_stats=1
8198a127bf6SGeliang Tang		else
8208a127bf6SGeliang Tang			echo "[ ok ]"
8218a127bf6SGeliang Tang		fi
8228a127bf6SGeliang Tang	else
8238a127bf6SGeliang Tang		echo ""
8248a127bf6SGeliang Tang	fi
8258a127bf6SGeliang Tang
826be613160SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
827be613160SGeliang Tang		echo Server ns stats
828be613160SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
829be613160SGeliang Tang		echo Client ns stats
830be613160SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
831be613160SGeliang Tang	fi
832be613160SGeliang Tang}
833be613160SGeliang Tang
834dd72b0feSGeliang Tangchk_rm_nr()
835dd72b0feSGeliang Tang{
836dd72b0feSGeliang Tang	local rm_addr_nr=$1
837dd72b0feSGeliang Tang	local rm_subflow_nr=$2
8387028ba8aSGeliang Tang	local invert=${3:-""}
839dd72b0feSGeliang Tang	local count
840dd72b0feSGeliang Tang	local dump_stats
8417028ba8aSGeliang Tang	local addr_ns
8427028ba8aSGeliang Tang	local subflow_ns
8437028ba8aSGeliang Tang
8447028ba8aSGeliang Tang	if [ -z $invert ]; then
8457028ba8aSGeliang Tang		addr_ns=$ns1
8467028ba8aSGeliang Tang		subflow_ns=$ns2
8477028ba8aSGeliang Tang	elif [ $invert = "invert" ]; then
8487028ba8aSGeliang Tang		addr_ns=$ns2
8497028ba8aSGeliang Tang		subflow_ns=$ns1
8507028ba8aSGeliang Tang	fi
851dd72b0feSGeliang Tang
852dd72b0feSGeliang Tang	printf "%-39s %s" " " "rm "
8537028ba8aSGeliang Tang	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
854dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
855dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
856dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
857dd72b0feSGeliang Tang		ret=1
858dd72b0feSGeliang Tang		dump_stats=1
859dd72b0feSGeliang Tang	else
860dd72b0feSGeliang Tang		echo -n "[ ok ]"
861dd72b0feSGeliang Tang	fi
862dd72b0feSGeliang Tang
863dd72b0feSGeliang Tang	echo -n " - sf    "
8647028ba8aSGeliang Tang	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
865dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
866dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
867dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
868dd72b0feSGeliang Tang		ret=1
869dd72b0feSGeliang Tang		dump_stats=1
870dd72b0feSGeliang Tang	else
871dd72b0feSGeliang Tang		echo "[ ok ]"
872dd72b0feSGeliang Tang	fi
873dd72b0feSGeliang Tang
874dd72b0feSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
875dd72b0feSGeliang Tang		echo Server ns stats
876dd72b0feSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
877dd72b0feSGeliang Tang		echo Client ns stats
878dd72b0feSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
879dd72b0feSGeliang Tang	fi
880dd72b0feSGeliang Tang}
881dd72b0feSGeliang Tang
882718eb44eSGeliang Tangchk_prio_nr()
883718eb44eSGeliang Tang{
884718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
885718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
886718eb44eSGeliang Tang	local count
887718eb44eSGeliang Tang	local dump_stats
888718eb44eSGeliang Tang
889718eb44eSGeliang Tang	printf "%-39s %s" " " "ptx"
890718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
891718eb44eSGeliang Tang	[ -z "$count" ] && count=0
892718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
893718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
894718eb44eSGeliang Tang		ret=1
895718eb44eSGeliang Tang		dump_stats=1
896718eb44eSGeliang Tang	else
897718eb44eSGeliang Tang		echo -n "[ ok ]"
898718eb44eSGeliang Tang	fi
899718eb44eSGeliang Tang
900718eb44eSGeliang Tang	echo -n " - prx   "
901718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
902718eb44eSGeliang Tang	[ -z "$count" ] && count=0
903718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
904718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
905718eb44eSGeliang Tang		ret=1
906718eb44eSGeliang Tang		dump_stats=1
907718eb44eSGeliang Tang	else
908718eb44eSGeliang Tang		echo "[ ok ]"
909718eb44eSGeliang Tang	fi
910718eb44eSGeliang Tang
911718eb44eSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
912718eb44eSGeliang Tang		echo Server ns stats
913718eb44eSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
914718eb44eSGeliang Tang		echo Client ns stats
915718eb44eSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
916718eb44eSGeliang Tang	fi
917718eb44eSGeliang Tang}
918718eb44eSGeliang Tang
9197d1e6f16SPaolo Abenichk_link_usage()
9207d1e6f16SPaolo Abeni{
9217d1e6f16SPaolo Abeni	local ns=$1
9227d1e6f16SPaolo Abeni	local link=$2
9237d1e6f16SPaolo Abeni	local out=$3
9247d1e6f16SPaolo Abeni	local expected_rate=$4
9257d1e6f16SPaolo Abeni	local tx_link=`ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes`
9267d1e6f16SPaolo Abeni	local tx_total=`ls -l $out | awk '{print $5}'`
9277d1e6f16SPaolo Abeni	local tx_rate=$((tx_link * 100 / $tx_total))
9287d1e6f16SPaolo Abeni	local tolerance=5
9297d1e6f16SPaolo Abeni
9307d1e6f16SPaolo Abeni	printf "%-39s %-18s" " " "link usage"
9317d1e6f16SPaolo Abeni	if [ $tx_rate -lt $((expected_rate - $tolerance)) -o \
9327d1e6f16SPaolo Abeni	     $tx_rate -gt $((expected_rate + $tolerance)) ]; then
9337d1e6f16SPaolo Abeni		echo "[fail] got $tx_rate% usage, expected $expected_rate%"
9347d1e6f16SPaolo Abeni		ret=1
9357d1e6f16SPaolo Abeni	else
9367d1e6f16SPaolo Abeni		echo "[ ok ]"
9377d1e6f16SPaolo Abeni	fi
9387d1e6f16SPaolo Abeni}
9397d1e6f16SPaolo Abeni
9401002b89fSGeliang Tangsubflows_tests()
9411002b89fSGeliang Tang{
9421002b89fSGeliang Tang	reset
943b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
944b08fbf24SPaolo Abeni	chk_join_nr "no JOIN" "0" "0" "0"
945b08fbf24SPaolo Abeni
9461002b89fSGeliang Tang	# subflow limited by client
947b08fbf24SPaolo Abeni	reset
94872bcbc46SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 0
94972bcbc46SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 0
950b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
951b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
952b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by client" 0 0 0
953b08fbf24SPaolo Abeni
9541002b89fSGeliang Tang	# subflow limited by server
955b08fbf24SPaolo Abeni	reset
95672bcbc46SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 0
957b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
958b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
959b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
960b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by server" 1 1 0
961b08fbf24SPaolo Abeni
962b08fbf24SPaolo Abeni	# subflow
963b08fbf24SPaolo Abeni	reset
964b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
965b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
966b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
967b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
968b08fbf24SPaolo Abeni	chk_join_nr "single subflow" 1 1 1
969b08fbf24SPaolo Abeni
970b08fbf24SPaolo Abeni	# multiple subflows
971b08fbf24SPaolo Abeni	reset
972b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
973b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
974b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
975b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
976b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
977b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows" 2 2 2
978b08fbf24SPaolo Abeni
97972bcbc46SPaolo Abeni	# multiple subflows limited by server
980b08fbf24SPaolo Abeni	reset
981b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
982b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
983b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
984b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
985b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
986b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows, limited by server" 2 2 1
987c3eaa5f6SGeliang Tang
988c3eaa5f6SGeliang Tang	# single subflow, dev
989c3eaa5f6SGeliang Tang	reset
990c3eaa5f6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
991c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
992c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow dev ns2eth3
993c3eaa5f6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
994c3eaa5f6SGeliang Tang	chk_join_nr "single subflow, dev" 1 1 1
9951002b89fSGeliang Tang}
996b08fbf24SPaolo Abeni
9971002b89fSGeliang Tangsignal_address_tests()
9981002b89fSGeliang Tang{
999b08fbf24SPaolo Abeni	# add_address, unused
1000b08fbf24SPaolo Abeni	reset
1001b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1002b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1003b08fbf24SPaolo Abeni	chk_join_nr "unused signal address" 0 0 0
1004be613160SGeliang Tang	chk_add_nr 1 1
1005b08fbf24SPaolo Abeni
1006b08fbf24SPaolo Abeni	# accept and use add_addr
1007b08fbf24SPaolo Abeni	reset
1008b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1009b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1010b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1011b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1012b08fbf24SPaolo Abeni	chk_join_nr "signal address" 1 1 1
1013be613160SGeliang Tang	chk_add_nr 1 1
1014b08fbf24SPaolo Abeni
1015b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
1016b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
1017b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
1018b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
1019b08fbf24SPaolo Abeni	reset
1020b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1021b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1022b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1023b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1024b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1025b08fbf24SPaolo Abeni	chk_join_nr "subflow and signal" 2 2 2
1026be613160SGeliang Tang	chk_add_nr 1 1
1027b08fbf24SPaolo Abeni
1028b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
1029b08fbf24SPaolo Abeni	reset
1030b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1031b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1032b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1033b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1034b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1035b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1036b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows and signal" 3 3 3
1037be613160SGeliang Tang	chk_add_nr 1 1
1038ef360019SGeliang Tang
1039ef360019SGeliang Tang	# signal addresses
1040ef360019SGeliang Tang	reset
1041ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1042ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1043ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1044ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1045ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1046ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1047ef360019SGeliang Tang	chk_join_nr "signal addresses" 3 3 3
1048ef360019SGeliang Tang	chk_add_nr 3 3
1049ef360019SGeliang Tang
1050ef360019SGeliang Tang	# signal invalid addresses
1051ef360019SGeliang Tang	reset
1052ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1053ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1054ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1055ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1056ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1057ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1058ef360019SGeliang Tang	chk_join_nr "signal invalid addresses" 1 1 1
1059ef360019SGeliang Tang	chk_add_nr 3 3
106033c563adSYonglong Li
106133c563adSYonglong Li	# signal addresses race test
106233c563adSYonglong Li	reset
106333c563adSYonglong Li	ip netns exec $ns1 ./pm_nl_ctl limits 4 4
106433c563adSYonglong Li	ip netns exec $ns2 ./pm_nl_ctl limits 4 4
106533c563adSYonglong Li	ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags signal
106633c563adSYonglong Li	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
106733c563adSYonglong Li	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
106833c563adSYonglong Li	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
106933c563adSYonglong Li	ip netns exec $ns2 ./pm_nl_ctl add 10.0.1.2 flags signal
107033c563adSYonglong Li	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags signal
107133c563adSYonglong Li	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags signal
107233c563adSYonglong Li	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags signal
107333c563adSYonglong Li	run_tests $ns1 $ns2 10.0.1.1
1074*86e39e04SPaolo Abeni
1075*86e39e04SPaolo Abeni	# the server will not signal the address terminating
1076*86e39e04SPaolo Abeni	# the MPC subflow
1077*86e39e04SPaolo Abeni	chk_add_nr 3 3
10781002b89fSGeliang Tang}
1079b08fbf24SPaolo Abeni
10801002b89fSGeliang Tanglink_failure_tests()
10811002b89fSGeliang Tang{
10828b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
10838b819a84SFlorian Westphal	reset
10847d1e6f16SPaolo Abeni
10857d1e6f16SPaolo Abeni	# without any b/w limit each veth could spool the packets and get
10867d1e6f16SPaolo Abeni	# them acked at xmit time, so that the corresponding subflow will
10877d1e6f16SPaolo Abeni	# have almost always no outstanding pkts, the scheduler will pick
10887d1e6f16SPaolo Abeni	# always the first subflow and we will have hard time testing
10897d1e6f16SPaolo Abeni	# active backup and link switch-over.
10907d1e6f16SPaolo Abeni	# Let's set some arbitrary (low) virtual link limits.
10917d1e6f16SPaolo Abeni	init_shapers
10928b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
10937d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
10948b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
10957d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
10967d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
10978b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 1
10988b819a84SFlorian Westphal	chk_join_nr "multiple flows, signal, link failure" 3 3 3
10998b819a84SFlorian Westphal	chk_add_nr 1 1
11007d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 5 1
11017d1e6f16SPaolo Abeni
11027d1e6f16SPaolo Abeni	# accept and use add_addr with additional subflows and link loss
11037d1e6f16SPaolo Abeni	# for bidirectional transfer
11047d1e6f16SPaolo Abeni	reset
11057d1e6f16SPaolo Abeni	init_shapers
11067d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
11077d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
11087d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
11097d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow
11107d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 dev ns2eth4 flags subflow
11117d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
11127d1e6f16SPaolo Abeni	chk_join_nr "multi flows, signal, bidi, link fail" 3 3 3
11137d1e6f16SPaolo Abeni	chk_add_nr 1 1
11147d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 1
11157d1e6f16SPaolo Abeni
11167d1e6f16SPaolo Abeni	# 2 subflows plus 1 backup subflow with a lossy link, backup
11177d1e6f16SPaolo Abeni	# will never be used
11187d1e6f16SPaolo Abeni	reset
11197d1e6f16SPaolo Abeni	init_shapers
11207d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11217d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
11227d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
11237d1e6f16SPaolo Abeni	export FAILING_LINKS="1"
11247d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
11257d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
11267d1e6f16SPaolo Abeni	chk_join_nr "backup subflow unused, link failure" 2 2 2
11277d1e6f16SPaolo Abeni	chk_add_nr 1 1
11287d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 0
11297d1e6f16SPaolo Abeni
11307d1e6f16SPaolo Abeni	# 2 lossy links after half transfer, backup will get half of
11317d1e6f16SPaolo Abeni	# the traffic
11327d1e6f16SPaolo Abeni	reset
11337d1e6f16SPaolo Abeni	init_shapers
11347d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11357d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
11367d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
11377d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
11387d1e6f16SPaolo Abeni	export FAILING_LINKS="1 2"
11397d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
11407d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, multi links fail" 2 2 2
11417d1e6f16SPaolo Abeni	chk_add_nr 1 1
11427d1e6f16SPaolo Abeni	chk_stale_nr $ns2 2 4 2
11437d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
11447d1e6f16SPaolo Abeni
11457d1e6f16SPaolo Abeni	# use a backup subflow with the first subflow on a lossy link
11467d1e6f16SPaolo Abeni	# for bidirectional transfer
11477d1e6f16SPaolo Abeni	reset
11487d1e6f16SPaolo Abeni	init_shapers
11497d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11507d1e6f16SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags signal
11517d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
11527d1e6f16SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 dev ns2eth3 flags subflow,backup
11537d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
11547d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, bidi, link failure" 2 2 2
11557d1e6f16SPaolo Abeni	chk_add_nr 1 1
11567d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 2
11577d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
11581002b89fSGeliang Tang}
11598b819a84SFlorian Westphal
11601002b89fSGeliang Tangadd_addr_timeout_tests()
11611002b89fSGeliang Tang{
11628d014eaaSGeliang Tang	# add_addr timeout
11638d014eaaSGeliang Tang	reset_with_add_addr_timeout
11648d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11658d014eaaSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11668d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
11678b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
11688d014eaaSGeliang Tang	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
11698d014eaaSGeliang Tang	chk_add_nr 4 0
11708d014eaaSGeliang Tang
11711002b89fSGeliang Tang	# add_addr timeout IPv6
11721002b89fSGeliang Tang	reset_with_add_addr_timeout 6
11731002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11741002b89fSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11751002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
11761002b89fSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
11771002b89fSGeliang Tang	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
11781002b89fSGeliang Tang	chk_add_nr 4 0
11798da6229bSGeliang Tang
11808da6229bSGeliang Tang	# signal addresses timeout
11818da6229bSGeliang Tang	reset_with_add_addr_timeout
11828da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11838da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
11848da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
11858da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11868da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
11878da6229bSGeliang Tang	chk_join_nr "signal addresses, ADD_ADDR timeout" 2 2 2
11888da6229bSGeliang Tang	chk_add_nr 8 0
11898da6229bSGeliang Tang
11908da6229bSGeliang Tang	# signal invalid addresses timeout
11918da6229bSGeliang Tang	reset_with_add_addr_timeout
11928da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11938da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
11948da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
11958da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11968da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
11978da6229bSGeliang Tang	chk_join_nr "invalid address, ADD_ADDR timeout" 1 1 1
11988da6229bSGeliang Tang	chk_add_nr 8 0
11991002b89fSGeliang Tang}
12001002b89fSGeliang Tang
12011002b89fSGeliang Tangremove_tests()
12021002b89fSGeliang Tang{
1203dd72b0feSGeliang Tang	# single subflow, remove
1204dd72b0feSGeliang Tang	reset
1205dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1206dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1207dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12082e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
1209dd72b0feSGeliang Tang	chk_join_nr "remove single subflow" 1 1 1
1210dd72b0feSGeliang Tang	chk_rm_nr 1 1
1211dd72b0feSGeliang Tang
1212dd72b0feSGeliang Tang	# multiple subflows, remove
1213dd72b0feSGeliang Tang	reset
1214dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1215dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
1216dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
1217dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12182e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
1219dd72b0feSGeliang Tang	chk_join_nr "remove multiple subflows" 2 2 2
1220dd72b0feSGeliang Tang	chk_rm_nr 2 2
1221dd72b0feSGeliang Tang
1222dd72b0feSGeliang Tang	# single address, remove
1223dd72b0feSGeliang Tang	reset
1224dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1225dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1226dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
12272e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1228dd72b0feSGeliang Tang	chk_join_nr "remove single address" 1 1 1
1229dd72b0feSGeliang Tang	chk_add_nr 1 1
12307028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1231dd72b0feSGeliang Tang
1232dd72b0feSGeliang Tang	# subflow and signal, remove
1233dd72b0feSGeliang Tang	reset
1234dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1235dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1236dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1237dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12382e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1239dd72b0feSGeliang Tang	chk_join_nr "remove subflow and signal" 2 2 2
1240dd72b0feSGeliang Tang	chk_add_nr 1 1
1241dd72b0feSGeliang Tang	chk_rm_nr 1 1
1242dd72b0feSGeliang Tang
1243dd72b0feSGeliang Tang	# subflows and signal, remove
1244dd72b0feSGeliang Tang	reset
1245dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1246dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1247dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1248dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1249dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
12502e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
1251dd72b0feSGeliang Tang	chk_join_nr "remove subflows and signal" 3 3 3
1252dd72b0feSGeliang Tang	chk_add_nr 1 1
1253dd72b0feSGeliang Tang	chk_rm_nr 2 2
1254dd72b0feSGeliang Tang
1255ef360019SGeliang Tang	# addresses remove
1256ef360019SGeliang Tang	reset
1257ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1258ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1259ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1260ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1261ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1262ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1263ef360019SGeliang Tang	chk_join_nr "remove addresses" 3 3 3
1264ef360019SGeliang Tang	chk_add_nr 3 3
1265ef360019SGeliang Tang	chk_rm_nr 3 3 invert
1266ef360019SGeliang Tang
1267ef360019SGeliang Tang	# invalid addresses remove
1268ef360019SGeliang Tang	reset
1269ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1270ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1271ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1272ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1273ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1274ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1275ef360019SGeliang Tang	chk_join_nr "remove invalid addresses" 1 1 1
1276ef360019SGeliang Tang	chk_add_nr 3 3
1277ef360019SGeliang Tang	chk_rm_nr 3 1 invert
1278ef360019SGeliang Tang
12796fe4ccdcSGeliang Tang	# subflows and signal, flush
12806fe4ccdcSGeliang Tang	reset
12816fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
12826fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
12836fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
12846fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
12856fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
12862e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
12876fe4ccdcSGeliang Tang	chk_join_nr "flush subflows and signal" 3 3 3
12886fe4ccdcSGeliang Tang	chk_add_nr 1 1
12896fe4ccdcSGeliang Tang	chk_rm_nr 2 2
1290d2c4333aSGeliang Tang
1291d2c4333aSGeliang Tang	# subflows flush
1292d2c4333aSGeliang Tang	reset
1293d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1294d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1295d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow id 150
1296d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1297d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1298d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1299d2c4333aSGeliang Tang	chk_join_nr "flush subflows" 3 3 3
1300d2c4333aSGeliang Tang	chk_rm_nr 3 3
1301d2c4333aSGeliang Tang
1302d2c4333aSGeliang Tang	# addresses flush
1303d2c4333aSGeliang Tang	reset
1304d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1305d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1306d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1307d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1308d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1309d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1310d2c4333aSGeliang Tang	chk_join_nr "flush addresses" 3 3 3
1311d2c4333aSGeliang Tang	chk_add_nr 3 3
1312d2c4333aSGeliang Tang	chk_rm_nr 3 3 invert
1313ef360019SGeliang Tang
1314ef360019SGeliang Tang	# invalid addresses flush
1315ef360019SGeliang Tang	reset
1316ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1317ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1318ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1319ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1320ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1321ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
1322ef360019SGeliang Tang	chk_join_nr "flush invalid addresses" 1 1 1
1323ef360019SGeliang Tang	chk_add_nr 3 3
1324ef360019SGeliang Tang	chk_rm_nr 3 1 invert
13255e287fe7SGeliang Tang
13265e287fe7SGeliang Tang	# remove id 0 subflow
13275e287fe7SGeliang Tang	reset
13285e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13295e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
13305e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
13315e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
13325e287fe7SGeliang Tang	chk_join_nr "remove id 0 subflow" 1 1 1
13335e287fe7SGeliang Tang	chk_rm_nr 1 1
13345e287fe7SGeliang Tang
13355e287fe7SGeliang Tang	# remove id 0 address
13365e287fe7SGeliang Tang	reset
13375e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13385e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
13395e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
13405e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
13415e287fe7SGeliang Tang	chk_join_nr "remove id 0 address" 1 1 1
13425e287fe7SGeliang Tang	chk_add_nr 1 1
13435e287fe7SGeliang Tang	chk_rm_nr 1 1 invert
13441002b89fSGeliang Tang}
13456fe4ccdcSGeliang Tang
13461002b89fSGeliang Tangadd_tests()
13471002b89fSGeliang Tang{
13486208fd82SGeliang Tang	# add single subflow
13496208fd82SGeliang Tang	reset
13506208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13516208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
13526208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
13536208fd82SGeliang Tang	chk_join_nr "add single subflow" 1 1 1
13546208fd82SGeliang Tang
13556208fd82SGeliang Tang	# add signal address
13566208fd82SGeliang Tang	reset
13576208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13586208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
13596208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
13606208fd82SGeliang Tang	chk_join_nr "add signal address" 1 1 1
13616208fd82SGeliang Tang	chk_add_nr 1 1
13626208fd82SGeliang Tang
13636208fd82SGeliang Tang	# add multiple subflows
13646208fd82SGeliang Tang	reset
13656208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13666208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
13676208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
13686208fd82SGeliang Tang	chk_join_nr "add multiple subflows" 2 2 2
13696208fd82SGeliang Tang
13706208fd82SGeliang Tang	# add multiple subflows IPv6
13716208fd82SGeliang Tang	reset
13726208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13736208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
13746208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
13756208fd82SGeliang Tang	chk_join_nr "add multiple subflows IPv6" 2 2 2
13766208fd82SGeliang Tang
13776208fd82SGeliang Tang	# add multiple addresses IPv6
13786208fd82SGeliang Tang	reset
13796208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13806208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
13816208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
13826208fd82SGeliang Tang	chk_join_nr "add multiple addresses IPv6" 2 2 2
13836208fd82SGeliang Tang	chk_add_nr 2 2
13841002b89fSGeliang Tang}
13856208fd82SGeliang Tang
13861002b89fSGeliang Tangipv6_tests()
13871002b89fSGeliang Tang{
1388523514edSGeliang Tang	# subflow IPv6
1389523514edSGeliang Tang	reset
1390523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1391523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1392523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
1393523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1394523514edSGeliang Tang	chk_join_nr "single subflow IPv6" 1 1 1
1395523514edSGeliang Tang
1396523514edSGeliang Tang	# add_address, unused IPv6
1397523514edSGeliang Tang	reset
1398523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1399523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1400523514edSGeliang Tang	chk_join_nr "unused signal address IPv6" 0 0 0
1401523514edSGeliang Tang	chk_add_nr 1 1
1402523514edSGeliang Tang
1403523514edSGeliang Tang	# signal address IPv6
1404523514edSGeliang Tang	reset
1405523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1406523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1407523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1408523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1409523514edSGeliang Tang	chk_join_nr "single address IPv6" 1 1 1
1410523514edSGeliang Tang	chk_add_nr 1 1
1411523514edSGeliang Tang
1412523514edSGeliang Tang	# single address IPv6, remove
1413523514edSGeliang Tang	reset
1414523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1415523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1416523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14172e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
1418523514edSGeliang Tang	chk_join_nr "remove single address IPv6" 1 1 1
1419523514edSGeliang Tang	chk_add_nr 1 1
14207028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1421523514edSGeliang Tang
1422523514edSGeliang Tang	# subflow and signal IPv6, remove
1423523514edSGeliang Tang	reset
1424523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1425523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1426523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1427523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
14282e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
1429523514edSGeliang Tang	chk_join_nr "remove subflow and signal IPv6" 2 2 2
1430523514edSGeliang Tang	chk_add_nr 1 1
1431523514edSGeliang Tang	chk_rm_nr 1 1
14321002b89fSGeliang Tang}
1433523514edSGeliang Tang
14341002b89fSGeliang Tangv4mapped_tests()
14351002b89fSGeliang Tang{
1436a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
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 "::ffff:10.0.3.2" flags subflow
1441a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1442a6094788SGeliang Tang	chk_join_nr "single subflow IPv4-mapped" 1 1 1
1443a6094788SGeliang Tang
1444a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
1445a6094788SGeliang Tang	reset
1446a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1447a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1448a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1449a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1450a6094788SGeliang Tang	chk_join_nr "signal address IPv4-mapped" 1 1 1
1451a6094788SGeliang Tang	chk_add_nr 1 1
1452a6094788SGeliang Tang
1453a6094788SGeliang Tang	# subflow v4-map-v6
1454a6094788SGeliang Tang	reset
1455a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1456a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1457a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1458a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1459a6094788SGeliang Tang	chk_join_nr "single subflow v4-map-v6" 1 1 1
1460a6094788SGeliang Tang
1461a6094788SGeliang Tang	# signal address v4-map-v6
1462a6094788SGeliang Tang	reset
1463a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1464a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1465a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1466a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1467a6094788SGeliang Tang	chk_join_nr "signal address v4-map-v6" 1 1 1
1468a6094788SGeliang Tang	chk_add_nr 1 1
1469a6094788SGeliang Tang
1470a6094788SGeliang Tang	# subflow v6-map-v4
1471a6094788SGeliang Tang	reset
1472a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1473a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1474a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1475a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1476a6094788SGeliang Tang	chk_join_nr "single subflow v6-map-v4" 1 1 1
1477a6094788SGeliang Tang
1478a6094788SGeliang Tang	# signal address v6-map-v4
1479a6094788SGeliang Tang	reset
1480a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1481a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1482a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1483a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1484a6094788SGeliang Tang	chk_join_nr "signal address v6-map-v4" 1 1 1
1485a6094788SGeliang Tang	chk_add_nr 1 1
1486a6094788SGeliang Tang
1487a6094788SGeliang Tang	# no subflow IPv6 to v4 address
1488a6094788SGeliang Tang	reset
1489a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1490a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1491a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::2 flags subflow
1492a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1493a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1494a6094788SGeliang Tang
1495a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1496a6094788SGeliang Tang	reset
1497a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1498a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1499a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::10.0.3.2 flags subflow
1500a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1501a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
1502a6094788SGeliang Tang
1503a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
1504a6094788SGeliang Tang	reset
1505a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1506a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1507a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1508a6094788SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1
1509a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
15101002b89fSGeliang Tang}
1511a6094788SGeliang Tang
15121002b89fSGeliang Tangbackup_tests()
15131002b89fSGeliang Tang{
1514718eb44eSGeliang Tang	# single subflow, backup
1515718eb44eSGeliang Tang	reset
1516718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1517718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1518718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,backup
1519718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
1520718eb44eSGeliang Tang	chk_join_nr "single subflow, backup" 1 1 1
1521718eb44eSGeliang Tang	chk_prio_nr 0 1
1522718eb44eSGeliang Tang
1523718eb44eSGeliang Tang	# single address, backup
1524718eb44eSGeliang Tang	reset
1525718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1526718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1527718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1528718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
1529718eb44eSGeliang Tang	chk_join_nr "single address, backup" 1 1 1
1530718eb44eSGeliang Tang	chk_add_nr 1 1
1531718eb44eSGeliang Tang	chk_prio_nr 1 0
15321002b89fSGeliang Tang}
1533718eb44eSGeliang Tang
15341002b89fSGeliang Tangadd_addr_ports_tests()
15351002b89fSGeliang Tang{
15368a127bf6SGeliang Tang	# signal address with port
15378a127bf6SGeliang Tang	reset
15388a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
15398a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
15408a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15418a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15428a127bf6SGeliang Tang	chk_join_nr "signal address with port" 1 1 1
15438a127bf6SGeliang Tang	chk_add_nr 1 1 1
15448a127bf6SGeliang Tang
15458a127bf6SGeliang Tang	# subflow and signal with port
15468a127bf6SGeliang Tang	reset
15478a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15488a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
15498a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
15508a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15518a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15528a127bf6SGeliang Tang	chk_join_nr "subflow and signal with port" 2 2 2
15538a127bf6SGeliang Tang	chk_add_nr 1 1 1
15548a127bf6SGeliang Tang
15558a127bf6SGeliang Tang	# single address with port, remove
15568a127bf6SGeliang Tang	reset
15578a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
15588a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15598a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
15608a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
15618a127bf6SGeliang Tang	chk_join_nr "remove single address with port" 1 1 1
15628a127bf6SGeliang Tang	chk_add_nr 1 1 1
15637028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
15648a127bf6SGeliang Tang
15658a127bf6SGeliang Tang	# subflow and signal with port, remove
15668a127bf6SGeliang Tang	reset
15678a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
15688a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15698a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
15708a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15718a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
15728a127bf6SGeliang Tang	chk_join_nr "remove subflow and signal with port" 2 2 2
15738a127bf6SGeliang Tang	chk_add_nr 1 1 1
15748a127bf6SGeliang Tang	chk_rm_nr 1 1
15758a127bf6SGeliang Tang
15768a127bf6SGeliang Tang	# subflows and signal with port, flush
15778a127bf6SGeliang Tang	reset
15788a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
15798a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15808a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
15818a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15828a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
15838a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
15848a127bf6SGeliang Tang	chk_join_nr "flush subflows and signal with port" 3 3 3
15858a127bf6SGeliang Tang	chk_add_nr 1 1
15868a127bf6SGeliang Tang	chk_rm_nr 2 2
15878a127bf6SGeliang Tang
15888a127bf6SGeliang Tang	# multiple addresses with port
15898a127bf6SGeliang Tang	reset
15908a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
15918a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
15928a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100
15938a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
15948a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15958a127bf6SGeliang Tang	chk_join_nr "multiple addresses with port" 2 2 2
15968a127bf6SGeliang Tang	chk_add_nr 2 2 2
15978a127bf6SGeliang Tang
15988a127bf6SGeliang Tang	# multiple addresses with ports
15998a127bf6SGeliang Tang	reset
16008a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
16018a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
16028a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101
16038a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
16048a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
16058a127bf6SGeliang Tang	chk_join_nr "multiple addresses with ports" 2 2 2
16068a127bf6SGeliang Tang	chk_add_nr 2 2 2
16071002b89fSGeliang Tang}
16088a127bf6SGeliang Tang
16091002b89fSGeliang Tangsyncookies_tests()
16101002b89fSGeliang Tang{
161100587187SFlorian Westphal	# single subflow, syncookies
161200587187SFlorian Westphal	reset_with_cookies
161300587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
161400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
161500587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
161600587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
161700587187SFlorian Westphal	chk_join_nr "single subflow with syn cookies" 1 1 1
161800587187SFlorian Westphal
161900587187SFlorian Westphal	# multiple subflows with syn cookies
162000587187SFlorian Westphal	reset_with_cookies
162100587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
162200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
162300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
162400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
162500587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
162600587187SFlorian Westphal	chk_join_nr "multiple subflows with syn cookies" 2 2 2
162700587187SFlorian Westphal
162800587187SFlorian Westphal	# multiple subflows limited by server
162900587187SFlorian Westphal	reset_with_cookies
163000587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
163100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
163200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
163300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
163400587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
1635a7da4416SJianguo Wu	chk_join_nr "subflows limited by server w cookies" 2 1 1
163600587187SFlorian Westphal
163700587187SFlorian Westphal	# test signal address with cookies
163800587187SFlorian Westphal	reset_with_cookies
163900587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
164000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
164100587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
164200587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
164300587187SFlorian Westphal	chk_join_nr "signal address with syn cookies" 1 1 1
1644be613160SGeliang Tang	chk_add_nr 1 1
164500587187SFlorian Westphal
164600587187SFlorian Westphal	# test cookie with subflow and signal
164700587187SFlorian Westphal	reset_with_cookies
164800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
164900587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
165000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
165100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
165200587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
165300587187SFlorian Westphal	chk_join_nr "subflow and signal w cookies" 2 2 2
1654be613160SGeliang Tang	chk_add_nr 1 1
165500587187SFlorian Westphal
165600587187SFlorian Westphal	# accept and use add_addr with additional subflows
165700587187SFlorian Westphal	reset_with_cookies
165800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
165900587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
166000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
166100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
166200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
166300587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
166400587187SFlorian Westphal	chk_join_nr "subflows and signal w. cookies" 3 3 3
1665be613160SGeliang Tang	chk_add_nr 1 1
16661002b89fSGeliang Tang}
16671002b89fSGeliang Tang
1668af66d3e1SGeliang Tangchecksum_tests()
1669af66d3e1SGeliang Tang{
1670af66d3e1SGeliang Tang	# checksum test 0 0
1671af66d3e1SGeliang Tang	reset_with_checksum 0 0
1672af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1673af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1674af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1675af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 0"
1676af66d3e1SGeliang Tang
1677af66d3e1SGeliang Tang	# checksum test 1 1
1678af66d3e1SGeliang Tang	reset_with_checksum 1 1
1679af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1680af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1681af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1682af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 1"
1683af66d3e1SGeliang Tang
1684af66d3e1SGeliang Tang	# checksum test 0 1
1685af66d3e1SGeliang Tang	reset_with_checksum 0 1
1686af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1687af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1688af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1689af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 1"
1690af66d3e1SGeliang Tang
1691af66d3e1SGeliang Tang	# checksum test 1 0
1692af66d3e1SGeliang Tang	reset_with_checksum 1 0
1693af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1694af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1695af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1696af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 0"
1697af66d3e1SGeliang Tang}
1698af66d3e1SGeliang Tang
16990cddb4a6SGeliang Tangdeny_join_id0_tests()
17000cddb4a6SGeliang Tang{
17010cddb4a6SGeliang Tang	# subflow allow join id0 ns1
17020cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
17030cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
17040cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
17050cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
17060cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17070cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns1" 1 1 1
17080cddb4a6SGeliang Tang
17090cddb4a6SGeliang Tang	# subflow allow join id0 ns2
17100cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
17110cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
17120cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
17130cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
17140cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17150cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns2" 0 0 0
17160cddb4a6SGeliang Tang
17170cddb4a6SGeliang Tang	# signal address allow join id0 ns1
17180cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
17190cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
17200cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
17210cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
17220cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17230cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17240cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns1" 1 1 1
17250cddb4a6SGeliang Tang	chk_add_nr 1 1
17260cddb4a6SGeliang Tang
17270cddb4a6SGeliang Tang	# signal address allow join id0 ns2
17280cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
17290cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
17300cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
17310cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
17320cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17330cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17340cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns2" 1 1 1
17350cddb4a6SGeliang Tang	chk_add_nr 1 1
17360cddb4a6SGeliang Tang
17370cddb4a6SGeliang Tang	# subflow and address allow join id0 ns1
17380cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
17390cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
17400cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
17410cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17420cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
17430cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17440cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 1" 2 2 2
17450cddb4a6SGeliang Tang
17460cddb4a6SGeliang Tang	# subflow and address allow join id0 ns2
17470cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
17480cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
17490cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
17500cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17510cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
17520cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
17530cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 2" 1 1 1
17540cddb4a6SGeliang Tang}
17550cddb4a6SGeliang Tang
17564f49d633SGeliang Tangfullmesh_tests()
17574f49d633SGeliang Tang{
17584f49d633SGeliang Tang	# fullmesh 1
17594f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added before the connection,
17604f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added during the connection.
17614f49d633SGeliang Tang	reset
17624f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 4
17634f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 4
17644f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow,fullmesh
17654f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,fullmesh
17664f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
17674f49d633SGeliang Tang	chk_join_nr "fullmesh test 2x1" 4 4 4
17684f49d633SGeliang Tang	chk_add_nr 1 1
17694f49d633SGeliang Tang
17704f49d633SGeliang Tang	# fullmesh 2
17714f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
17724f49d633SGeliang Tang	# 1 fullmesh addr in ns2, added during the connection.
17734f49d633SGeliang Tang	reset
17744f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 3
17754f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
17764f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17774f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow
17784f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x1" 3 3 3
17794f49d633SGeliang Tang	chk_add_nr 1 1
17804f49d633SGeliang Tang
17814f49d633SGeliang Tang	# fullmesh 3
17824f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
17834f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection.
17844f49d633SGeliang Tang	reset
17854f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 5
17864f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 5
17874f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
17884f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
17894f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x2" 5 5 5
17904f49d633SGeliang Tang	chk_add_nr 1 1
17914f49d633SGeliang Tang
17924f49d633SGeliang Tang	# fullmesh 4
17934f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
17944f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection,
17954f49d633SGeliang Tang	# limit max_subflows to 4.
17964f49d633SGeliang Tang	reset
17974f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 4
17984f49d633SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 4
17994f49d633SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
18004f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
18014f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x2, limited" 4 4 4
18024f49d633SGeliang Tang	chk_add_nr 1 1
18034f49d633SGeliang Tang}
18044f49d633SGeliang Tang
18051002b89fSGeliang Tangall_tests()
18061002b89fSGeliang Tang{
18071002b89fSGeliang Tang	subflows_tests
18081002b89fSGeliang Tang	signal_address_tests
18091002b89fSGeliang Tang	link_failure_tests
18101002b89fSGeliang Tang	add_addr_timeout_tests
18111002b89fSGeliang Tang	remove_tests
18121002b89fSGeliang Tang	add_tests
18131002b89fSGeliang Tang	ipv6_tests
18141002b89fSGeliang Tang	v4mapped_tests
18151002b89fSGeliang Tang	backup_tests
18161002b89fSGeliang Tang	add_addr_ports_tests
18171002b89fSGeliang Tang	syncookies_tests
1818af66d3e1SGeliang Tang	checksum_tests
18190cddb4a6SGeliang Tang	deny_join_id0_tests
18204f49d633SGeliang Tang	fullmesh_tests
18211002b89fSGeliang Tang}
18221002b89fSGeliang Tang
18231002b89fSGeliang Tangusage()
18241002b89fSGeliang Tang{
18251002b89fSGeliang Tang	echo "mptcp_join usage:"
18261002b89fSGeliang Tang	echo "  -f subflows_tests"
18271002b89fSGeliang Tang	echo "  -s signal_address_tests"
18281002b89fSGeliang Tang	echo "  -l link_failure_tests"
18291002b89fSGeliang Tang	echo "  -t add_addr_timeout_tests"
18301002b89fSGeliang Tang	echo "  -r remove_tests"
18311002b89fSGeliang Tang	echo "  -a add_tests"
18321002b89fSGeliang Tang	echo "  -6 ipv6_tests"
18331002b89fSGeliang Tang	echo "  -4 v4mapped_tests"
18341002b89fSGeliang Tang	echo "  -b backup_tests"
18351002b89fSGeliang Tang	echo "  -p add_addr_ports_tests"
1836a673321aSMat Martineau	echo "  -k syncookies_tests"
1837af66d3e1SGeliang Tang	echo "  -S checksum_tests"
18380cddb4a6SGeliang Tang	echo "  -d deny_join_id0_tests"
18394f49d633SGeliang Tang	echo "  -m fullmesh_tests"
1840a673321aSMat Martineau	echo "  -c capture pcap files"
1841af66d3e1SGeliang Tang	echo "  -C enable data checksum"
18421002b89fSGeliang Tang	echo "  -h help"
18431002b89fSGeliang Tang}
18441002b89fSGeliang Tang
18451002b89fSGeliang Tangsin=$(mktemp)
18461002b89fSGeliang Tangsout=$(mktemp)
18471002b89fSGeliang Tangcin=$(mktemp)
18481002b89fSGeliang Tangcinsent=$(mktemp)
18491002b89fSGeliang Tangcout=$(mktemp)
18501002b89fSGeliang Tanginit
18511002b89fSGeliang Tangmake_file "$cin" "client" 1
18521002b89fSGeliang Tangmake_file "$sin" "server" 1
18531002b89fSGeliang Tangtrap cleanup EXIT
18541002b89fSGeliang Tang
1855a673321aSMat Martineaufor arg in "$@"; do
1856af66d3e1SGeliang Tang	# check for "capture/checksum" args before launching tests
1857a673321aSMat Martineau	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"c"[0-9a-zA-Z]*$ ]]; then
1858a673321aSMat Martineau		capture=1
1859a673321aSMat Martineau	fi
1860af66d3e1SGeliang Tang	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"C"[0-9a-zA-Z]*$ ]]; then
1861af66d3e1SGeliang Tang		checksum=1
1862af66d3e1SGeliang Tang	fi
1863a673321aSMat Martineau
1864af66d3e1SGeliang Tang	# exception for the capture/checksum options, the rest means: a part of the tests
1865af66d3e1SGeliang Tang	if [ "${arg}" != "-c" ] && [ "${arg}" != "-C" ]; then
1866a673321aSMat Martineau		do_all_tests=0
1867a673321aSMat Martineau	fi
1868a673321aSMat Martineaudone
1869a673321aSMat Martineau
1870a673321aSMat Martineauif [ $do_all_tests -eq 1 ]; then
18711002b89fSGeliang Tang	all_tests
18721002b89fSGeliang Tang	exit $ret
18731002b89fSGeliang Tangfi
18741002b89fSGeliang Tang
18754f49d633SGeliang Tangwhile getopts 'fsltra64bpkdmchCS' opt; do
18761002b89fSGeliang Tang	case $opt in
18771002b89fSGeliang Tang		f)
18781002b89fSGeliang Tang			subflows_tests
18791002b89fSGeliang Tang			;;
18801002b89fSGeliang Tang		s)
18811002b89fSGeliang Tang			signal_address_tests
18821002b89fSGeliang Tang			;;
18831002b89fSGeliang Tang		l)
18841002b89fSGeliang Tang			link_failure_tests
18851002b89fSGeliang Tang			;;
18861002b89fSGeliang Tang		t)
18871002b89fSGeliang Tang			add_addr_timeout_tests
18881002b89fSGeliang Tang			;;
18891002b89fSGeliang Tang		r)
18901002b89fSGeliang Tang			remove_tests
18911002b89fSGeliang Tang			;;
18921002b89fSGeliang Tang		a)
18931002b89fSGeliang Tang			add_tests
18941002b89fSGeliang Tang			;;
18951002b89fSGeliang Tang		6)
18961002b89fSGeliang Tang			ipv6_tests
18971002b89fSGeliang Tang			;;
18981002b89fSGeliang Tang		4)
18991002b89fSGeliang Tang			v4mapped_tests
19001002b89fSGeliang Tang			;;
19011002b89fSGeliang Tang		b)
19021002b89fSGeliang Tang			backup_tests
19031002b89fSGeliang Tang			;;
19041002b89fSGeliang Tang		p)
19051002b89fSGeliang Tang			add_addr_ports_tests
19061002b89fSGeliang Tang			;;
1907a673321aSMat Martineau		k)
19081002b89fSGeliang Tang			syncookies_tests
19091002b89fSGeliang Tang			;;
1910af66d3e1SGeliang Tang		S)
1911af66d3e1SGeliang Tang			checksum_tests
1912af66d3e1SGeliang Tang			;;
19130cddb4a6SGeliang Tang		d)
19140cddb4a6SGeliang Tang			deny_join_id0_tests
19150cddb4a6SGeliang Tang			;;
19164f49d633SGeliang Tang		m)
19174f49d633SGeliang Tang			fullmesh_tests
19184f49d633SGeliang Tang			;;
1919a673321aSMat Martineau		c)
1920a673321aSMat Martineau			;;
1921af66d3e1SGeliang Tang		C)
1922af66d3e1SGeliang Tang			;;
19231002b89fSGeliang Tang		h | *)
19241002b89fSGeliang Tang			usage
19251002b89fSGeliang Tang			;;
19261002b89fSGeliang Tang	esac
19271002b89fSGeliang Tangdone
192800587187SFlorian Westphal
1929b08fbf24SPaolo Abeniexit $ret
1930