1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4d8d08302SMatthieu Baerts# Double quotes to prevent globbing and word splitting is recommended in new
5d8d08302SMatthieu Baerts# code but we accept it, especially because there were too many before having
6d8d08302SMatthieu Baerts# address all other issues detected by shellcheck.
7d8d08302SMatthieu Baerts#shellcheck disable=SC2086
8d8d08302SMatthieu Baerts
9b08fbf24SPaolo Abeniret=0
10b08fbf24SPaolo Abenisin=""
117d1e6f16SPaolo Abenisinfail=""
12b08fbf24SPaolo Abenisout=""
13b08fbf24SPaolo Abenicin=""
147d1e6f16SPaolo Abenicinfail=""
158b819a84SFlorian Westphalcinsent=""
16b08fbf24SPaolo Abenicout=""
171e777bd8SMatthieu Baertscapout=""
181e777bd8SMatthieu Baertsns1=""
191e777bd8SMatthieu Baertsns2=""
20b08fbf24SPaolo Abeniksft_skip=4
215888a61cSMatthieu Baertstimeout_poll=30
225888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1))
23b08fbf24SPaolo Abenicapture=0
24af66d3e1SGeliang Tangchecksum=0
2534aa6e3bSGeliang Tangip_mptcp=0
268117dac3SGeliang Tangcheck_invert=0
273c082695SGeliang Tangvalidate_checksum=0
2893827ad5SMatthieu Baertsinit=0
29a3735625SGeliang Tangevts_ns1=""
30a3735625SGeliang Tangevts_ns2=""
31a3735625SGeliang Tangevts_ns1_pid=0
32a3735625SGeliang Tangevts_ns2_pid=0
33b08fbf24SPaolo Abeni
343afd0280SMatthieu Baertsdeclare -A all_tests
35c7d49c03SMatthieu Baertsdeclare -a only_tests_ids
36c7d49c03SMatthieu Baertsdeclare -a only_tests_names
3739aab882SMatthieu Baertsdeclare -A failed_tests
38b08fbf24SPaolo AbeniTEST_COUNT=0
39c7d49c03SMatthieu BaertsTEST_NAME=""
409a0a9367SGeliang Tangnr_blank=40
41b08fbf24SPaolo Abeni
42e59300ceSMatthieu Baertsexport FAILING_LINKS=""
43e59300ceSMatthieu Baerts
448d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
458d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
468d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
478d014eaaSGeliang Tang			       48 0 0 0,
488d014eaaSGeliang Tang			       84 0 0 240,
498d014eaaSGeliang Tang			       21 0 3 64,
508d014eaaSGeliang Tang			       48 0 0 54,
518d014eaaSGeliang Tang			       84 0 0 240,
528d014eaaSGeliang Tang			       21 6 7 48,
538d014eaaSGeliang Tang			       48 0 0 0,
548d014eaaSGeliang Tang			       84 0 0 240,
558d014eaaSGeliang Tang			       21 0 4 96,
568d014eaaSGeliang Tang			       48 0 0 74,
578d014eaaSGeliang Tang			       84 0 0 240,
588d014eaaSGeliang Tang			       21 0 1 48,
598d014eaaSGeliang Tang			       6 0 0 65535,
608d014eaaSGeliang Tang			       6 0 0 0"
618d014eaaSGeliang Tang
6293827ad5SMatthieu Baertsinit_partial()
63b08fbf24SPaolo Abeni{
64b08fbf24SPaolo Abeni	capout=$(mktemp)
65b08fbf24SPaolo Abeni
66787eb1e4SMatthieu Baerts	local sec rndh
67787eb1e4SMatthieu Baerts	sec=$(date +%s)
68787eb1e4SMatthieu Baerts	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
69b08fbf24SPaolo Abeni
70b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
71b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
72b08fbf24SPaolo Abeni
731e777bd8SMatthieu Baerts	local netns
74b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
75b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
76b08fbf24SPaolo Abeni		ip -net $netns link set lo up
77b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
785ac1d2d6SMat Martineau		ip netns exec $netns sysctl -q net.mptcp.pm_type=0
79b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
80b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
81af66d3e1SGeliang Tang		if [ $checksum -eq 1 ]; then
82af66d3e1SGeliang Tang			ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
83af66d3e1SGeliang Tang		fi
84b08fbf24SPaolo Abeni	done
85b08fbf24SPaolo Abeni
868117dac3SGeliang Tang	check_invert=0
873c082695SGeliang Tang	validate_checksum=$checksum
88e59300ceSMatthieu Baerts	FAILING_LINKS=""
898117dac3SGeliang Tang
90b08fbf24SPaolo Abeni	#  ns1         ns2
91b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
92b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
93b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
94b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
95b08fbf24SPaolo Abeni
961e777bd8SMatthieu Baerts	local i
974bfadd71SMatthieu Baerts	for i in $(seq 1 4); do
98b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
99b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
100b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
101b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
102b08fbf24SPaolo Abeni
103b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
104b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
105b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
106b08fbf24SPaolo Abeni
107b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
108b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
1099846921dSPaolo Abeni		ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i
110b08fbf24SPaolo Abeni	done
111b08fbf24SPaolo Abeni}
112b08fbf24SPaolo Abeni
1137d1e6f16SPaolo Abeniinit_shapers()
1147d1e6f16SPaolo Abeni{
1151e777bd8SMatthieu Baerts	local i
1164bfadd71SMatthieu Baerts	for i in $(seq 1 4); do
1177d1e6f16SPaolo Abeni		tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
1187d1e6f16SPaolo Abeni		tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
1197d1e6f16SPaolo Abeni	done
1207d1e6f16SPaolo Abeni}
1217d1e6f16SPaolo Abeni
122b08fbf24SPaolo Abenicleanup_partial()
123b08fbf24SPaolo Abeni{
124b08fbf24SPaolo Abeni	rm -f "$capout"
125b08fbf24SPaolo Abeni
1261e777bd8SMatthieu Baerts	local netns
127b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
128b08fbf24SPaolo Abeni		ip netns del $netns
129c2a55e8fSMatthieu Baerts		rm -f /tmp/$netns.{nstat,out}
130b08fbf24SPaolo Abeni	done
131b08fbf24SPaolo Abeni}
132b08fbf24SPaolo Abeni
13387154755SMatthieu Baertscheck_tools()
13487154755SMatthieu Baerts{
13587154755SMatthieu Baerts	if ! ip -Version &> /dev/null; then
13687154755SMatthieu Baerts		echo "SKIP: Could not run test without ip tool"
13787154755SMatthieu Baerts		exit $ksft_skip
13887154755SMatthieu Baerts	fi
13987154755SMatthieu Baerts
14087154755SMatthieu Baerts	if ! iptables -V &> /dev/null; then
14187154755SMatthieu Baerts		echo "SKIP: Could not run all tests without iptables tool"
14287154755SMatthieu Baerts		exit $ksft_skip
14387154755SMatthieu Baerts	fi
14487154755SMatthieu Baerts
14587154755SMatthieu Baerts	if ! ip6tables -V &> /dev/null; then
14687154755SMatthieu Baerts		echo "SKIP: Could not run all tests without ip6tables tool"
14787154755SMatthieu Baerts		exit $ksft_skip
14887154755SMatthieu Baerts	fi
14987154755SMatthieu Baerts}
15087154755SMatthieu Baerts
15193827ad5SMatthieu Baertsinit() {
15293827ad5SMatthieu Baerts	init=1
15393827ad5SMatthieu Baerts
15487154755SMatthieu Baerts	check_tools
15587154755SMatthieu Baerts
15693827ad5SMatthieu Baerts	sin=$(mktemp)
15793827ad5SMatthieu Baerts	sout=$(mktemp)
15893827ad5SMatthieu Baerts	cin=$(mktemp)
15993827ad5SMatthieu Baerts	cinsent=$(mktemp)
16093827ad5SMatthieu Baerts	cout=$(mktemp)
161a3735625SGeliang Tang	evts_ns1=$(mktemp)
162a3735625SGeliang Tang	evts_ns2=$(mktemp)
16393827ad5SMatthieu Baerts
16493827ad5SMatthieu Baerts	trap cleanup EXIT
16593827ad5SMatthieu Baerts
16693827ad5SMatthieu Baerts	make_file "$cin" "client" 1
16793827ad5SMatthieu Baerts	make_file "$sin" "server" 1
16893827ad5SMatthieu Baerts}
16993827ad5SMatthieu Baerts
170b08fbf24SPaolo Abenicleanup()
171b08fbf24SPaolo Abeni{
1727d1e6f16SPaolo Abeni	rm -f "$cin" "$cout" "$sinfail"
1737d1e6f16SPaolo Abeni	rm -f "$sin" "$sout" "$cinsent" "$cinfail"
174a3735625SGeliang Tang	rm -rf $evts_ns1 $evts_ns2
175b08fbf24SPaolo Abeni	cleanup_partial
176b08fbf24SPaolo Abeni}
177b08fbf24SPaolo Abeni
178ae7bd9ccSMatthieu Baertsskip_test()
179ae7bd9ccSMatthieu Baerts{
180c7d49c03SMatthieu Baerts	if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then
181ae7bd9ccSMatthieu Baerts		return 1
182ae7bd9ccSMatthieu Baerts	fi
183ae7bd9ccSMatthieu Baerts
184ae7bd9ccSMatthieu Baerts	local i
185c7d49c03SMatthieu Baerts	for i in "${only_tests_ids[@]}"; do
186ae7bd9ccSMatthieu Baerts		if [ "${TEST_COUNT}" -eq "${i}" ]; then
187ae7bd9ccSMatthieu Baerts			return 1
188ae7bd9ccSMatthieu Baerts		fi
189ae7bd9ccSMatthieu Baerts	done
190c7d49c03SMatthieu Baerts	for i in "${only_tests_names[@]}"; do
191c7d49c03SMatthieu Baerts		if [ "${TEST_NAME}" = "${i}" ]; then
192c7d49c03SMatthieu Baerts			return 1
193c7d49c03SMatthieu Baerts		fi
194c7d49c03SMatthieu Baerts	done
195ae7bd9ccSMatthieu Baerts
196ae7bd9ccSMatthieu Baerts	return 0
197ae7bd9ccSMatthieu Baerts}
198ae7bd9ccSMatthieu Baerts
199c7d49c03SMatthieu Baerts# $1: test name
200b08fbf24SPaolo Abenireset()
201b08fbf24SPaolo Abeni{
202c7d49c03SMatthieu Baerts	TEST_NAME="${1}"
203c7d49c03SMatthieu Baerts
204ae7bd9ccSMatthieu Baerts	TEST_COUNT=$((TEST_COUNT+1))
205ae7bd9ccSMatthieu Baerts
206ae7bd9ccSMatthieu Baerts	if skip_test; then
207ae7bd9ccSMatthieu Baerts		return 1
208ae7bd9ccSMatthieu Baerts	fi
209ae7bd9ccSMatthieu Baerts
21093827ad5SMatthieu Baerts	if [ "${init}" != "1" ]; then
211b08fbf24SPaolo Abeni		init
21293827ad5SMatthieu Baerts	else
21393827ad5SMatthieu Baerts		cleanup_partial
21493827ad5SMatthieu Baerts	fi
21593827ad5SMatthieu Baerts
21693827ad5SMatthieu Baerts	init_partial
217ae7bd9ccSMatthieu Baerts
218ae7bd9ccSMatthieu Baerts	return 0
219b08fbf24SPaolo Abeni}
220b08fbf24SPaolo Abeni
221c7d49c03SMatthieu Baerts# $1: test name
22200587187SFlorian Westphalreset_with_cookies()
22300587187SFlorian Westphal{
224c7d49c03SMatthieu Baerts	reset "${1}" || return 1
22500587187SFlorian Westphal
2261e777bd8SMatthieu Baerts	local netns
22700587187SFlorian Westphal	for netns in "$ns1" "$ns2"; do
22800587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
22900587187SFlorian Westphal	done
23000587187SFlorian Westphal}
23100587187SFlorian Westphal
232c7d49c03SMatthieu Baerts# $1: test name
2338d014eaaSGeliang Tangreset_with_add_addr_timeout()
2348d014eaaSGeliang Tang{
235c7d49c03SMatthieu Baerts	local ip="${2:-4}"
2368d014eaaSGeliang Tang	local tables
2378d014eaaSGeliang Tang
238c7d49c03SMatthieu Baerts	reset "${1}" || return 1
239c7d49c03SMatthieu Baerts
2408d014eaaSGeliang Tang	tables="iptables"
2418d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
2428d014eaaSGeliang Tang		tables="ip6tables"
2438d014eaaSGeliang Tang	fi
2448d014eaaSGeliang Tang
2458d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
2468d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
2478d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
2488d014eaaSGeliang Tang		-m bpf --bytecode \
2498d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
2508d014eaaSGeliang Tang		-j DROP
2518d014eaaSGeliang Tang}
2528d014eaaSGeliang Tang
253c7d49c03SMatthieu Baerts# $1: test name
254af66d3e1SGeliang Tangreset_with_checksum()
255af66d3e1SGeliang Tang{
256af66d3e1SGeliang Tang	local ns1_enable=$1
257af66d3e1SGeliang Tang	local ns2_enable=$2
258af66d3e1SGeliang Tang
259c7d49c03SMatthieu Baerts	reset "checksum test ${1} ${2}" || return 1
260af66d3e1SGeliang Tang
261af66d3e1SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
262af66d3e1SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
2633c082695SGeliang Tang
2643c082695SGeliang Tang	validate_checksum=1
265af66d3e1SGeliang Tang}
266af66d3e1SGeliang Tang
2670cddb4a6SGeliang Tangreset_with_allow_join_id0()
2680cddb4a6SGeliang Tang{
269c7d49c03SMatthieu Baerts	local ns1_enable=$2
270c7d49c03SMatthieu Baerts	local ns2_enable=$3
2710cddb4a6SGeliang Tang
272c7d49c03SMatthieu Baerts	reset "${1}" || return 1
2730cddb4a6SGeliang Tang
2740cddb4a6SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
2750cddb4a6SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
2760cddb4a6SGeliang Tang}
2770cddb4a6SGeliang Tang
278b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet
279b6e074e1SGeliang Tang#
280b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets
281b6e074e1SGeliang Tang# carrying enough data.
282b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still
283b6e074e1SGeliang Tang# considered as valid at the TCP level.
284b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been
285b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted:
286b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options.
287b6e074e1SGeliang Tang#
288b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets
289b6e074e1SGeliang Tang# not carrying enough data:
290b6e074e1SGeliang Tang#
291b6e074e1SGeliang Tang#     tc action pedit offset 162 out of bounds
292b6e074e1SGeliang Tang#
293b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data.
294b6e074e1SGeliang Tangreset_with_fail()
295b6e074e1SGeliang Tang{
296b6e074e1SGeliang Tang	reset "${1}" || return 1
297b6e074e1SGeliang Tang
298b6e074e1SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1
299b6e074e1SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1
300b6e074e1SGeliang Tang
301b6e074e1SGeliang Tang	check_invert=1
302b6e074e1SGeliang Tang	validate_checksum=1
303b6e074e1SGeliang Tang	local i="$2"
304b6e074e1SGeliang Tang	local ip="${3:-4}"
305b6e074e1SGeliang Tang	local tables
306b6e074e1SGeliang Tang
307b6e074e1SGeliang Tang	tables="iptables"
308b6e074e1SGeliang Tang	if [ $ip -eq 6 ]; then
309b6e074e1SGeliang Tang		tables="ip6tables"
310b6e074e1SGeliang Tang	fi
311b6e074e1SGeliang Tang
312b6e074e1SGeliang Tang	ip netns exec $ns2 $tables \
313b6e074e1SGeliang Tang		-t mangle \
314b6e074e1SGeliang Tang		-A OUTPUT \
315b6e074e1SGeliang Tang		-o ns2eth$i \
316b6e074e1SGeliang Tang		-p tcp \
317b6e074e1SGeliang Tang		-m length --length 150:9999 \
318b6e074e1SGeliang Tang		-m statistic --mode nth --packet 1 --every 99999 \
319b6e074e1SGeliang Tang		-j MARK --set-mark 42 || exit 1
320b6e074e1SGeliang Tang
321b6e074e1SGeliang Tang	tc -n $ns2 qdisc add dev ns2eth$i clsact || exit 1
322b6e074e1SGeliang Tang	tc -n $ns2 filter add dev ns2eth$i egress \
323b6e074e1SGeliang Tang		protocol ip prio 1000 \
324b6e074e1SGeliang Tang		handle 42 fw \
325b6e074e1SGeliang Tang		action pedit munge offset 148 u8 invert \
326b6e074e1SGeliang Tang		pipe csum tcp \
327b6e074e1SGeliang Tang		index 100 || exit 1
328b6e074e1SGeliang Tang}
329b6e074e1SGeliang Tang
330a3735625SGeliang Tangreset_with_events()
331a3735625SGeliang Tang{
332a3735625SGeliang Tang	reset "${1}" || return 1
333a3735625SGeliang Tang
334a3735625SGeliang Tang	:> "$evts_ns1"
335a3735625SGeliang Tang	:> "$evts_ns2"
336a3735625SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
337a3735625SGeliang Tang	evts_ns1_pid=$!
338a3735625SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
339a3735625SGeliang Tang	evts_ns2_pid=$!
340a3735625SGeliang Tang}
341a3735625SGeliang Tang
34239aab882SMatthieu Baertsfail_test()
34339aab882SMatthieu Baerts{
34439aab882SMatthieu Baerts	ret=1
34539aab882SMatthieu Baerts	failed_tests[${TEST_COUNT}]="${TEST_NAME}"
34639aab882SMatthieu Baerts}
34739aab882SMatthieu Baerts
34839aab882SMatthieu Baertsget_failed_tests_ids()
34939aab882SMatthieu Baerts{
35039aab882SMatthieu Baerts	# sorted
35139aab882SMatthieu Baerts	local i
35239aab882SMatthieu Baerts	for i in "${!failed_tests[@]}"; do
35339aab882SMatthieu Baerts		echo "${i}"
35439aab882SMatthieu Baerts	done | sort -n
35539aab882SMatthieu Baerts}
35639aab882SMatthieu Baerts
3578b819a84SFlorian Westphalprint_file_err()
3588b819a84SFlorian Westphal{
3598b819a84SFlorian Westphal	ls -l "$1" 1>&2
3608b819a84SFlorian Westphal	echo "Trailing bytes are: "
3618b819a84SFlorian Westphal	tail -c 27 "$1"
3628b819a84SFlorian Westphal}
3638b819a84SFlorian Westphal
364b08fbf24SPaolo Abenicheck_transfer()
365b08fbf24SPaolo Abeni{
3661e777bd8SMatthieu Baerts	local in=$1
3671e777bd8SMatthieu Baerts	local out=$2
3681e777bd8SMatthieu Baerts	local what=$3
3696bf41020SPaolo Abeni	local bytes=$4
370d8d08302SMatthieu Baerts	local i a b
371b08fbf24SPaolo Abeni
3721e777bd8SMatthieu Baerts	local line
3736bf41020SPaolo Abeni	if [ -n "$bytes" ]; then
3746bf41020SPaolo Abeni		# when truncating we must check the size explicitly
3756bf41020SPaolo Abeni		local out_size=$(wc -c $out | awk '{print $1}')
3766bf41020SPaolo Abeni		if [ $out_size -ne $bytes ]; then
3776bf41020SPaolo Abeni			echo "[ FAIL ] $what output file has wrong size ($out_size, $bytes)"
3786bf41020SPaolo Abeni			fail_test
3796bf41020SPaolo Abeni			return 1
3806bf41020SPaolo Abeni		fi
3816bf41020SPaolo Abeni		bytes="--bytes=${bytes}"
3826bf41020SPaolo Abeni	fi
3836bf41020SPaolo Abeni	cmp -l "$in" "$out" ${bytes} | while read -r i a b; do
384d8d08302SMatthieu Baerts		local sum=$((0${a} + 0${b}))
3858117dac3SGeliang Tang		if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
386b08fbf24SPaolo Abeni			echo "[ FAIL ] $what does not match (in, out):"
387b08fbf24SPaolo Abeni			print_file_err "$in"
388b08fbf24SPaolo Abeni			print_file_err "$out"
38939aab882SMatthieu Baerts			fail_test
390b08fbf24SPaolo Abeni
391b08fbf24SPaolo Abeni			return 1
3928117dac3SGeliang Tang		else
393d8d08302SMatthieu Baerts			echo "$what has inverted byte at ${i}"
394b08fbf24SPaolo Abeni		fi
3958117dac3SGeliang Tang	done
396b08fbf24SPaolo Abeni
397b08fbf24SPaolo Abeni	return 0
398b08fbf24SPaolo Abeni}
399b08fbf24SPaolo Abeni
400b08fbf24SPaolo Abenido_ping()
401b08fbf24SPaolo Abeni{
4021e777bd8SMatthieu Baerts	local listener_ns="$1"
4031e777bd8SMatthieu Baerts	local connector_ns="$2"
4041e777bd8SMatthieu Baerts	local connect_addr="$3"
405b08fbf24SPaolo Abeni
406d8d08302SMatthieu Baerts	if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then
407b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
40839aab882SMatthieu Baerts		fail_test
409b08fbf24SPaolo Abeni	fi
410b08fbf24SPaolo Abeni}
411b08fbf24SPaolo Abeni
4128b819a84SFlorian Westphallink_failure()
4138b819a84SFlorian Westphal{
4141e777bd8SMatthieu Baerts	local ns="$1"
4158b819a84SFlorian Westphal
4167d1e6f16SPaolo Abeni	if [ -z "$FAILING_LINKS" ]; then
4178b819a84SFlorian Westphal		l=$((RANDOM%4))
4187d1e6f16SPaolo Abeni		FAILING_LINKS=$((l+1))
4197d1e6f16SPaolo Abeni	fi
4208b819a84SFlorian Westphal
4211e777bd8SMatthieu Baerts	local l
4227d1e6f16SPaolo Abeni	for l in $FAILING_LINKS; do
4231e777bd8SMatthieu Baerts		local veth="ns1eth$l"
4248b819a84SFlorian Westphal		ip -net "$ns" link set "$veth" down
4257d1e6f16SPaolo Abeni	done
4268b819a84SFlorian Westphal}
4278b819a84SFlorian Westphal
428523514edSGeliang Tang# $1: IP address
429523514edSGeliang Tangis_v6()
430523514edSGeliang Tang{
431523514edSGeliang Tang	[ -z "${1##*:*}" ]
432523514edSGeliang Tang}
433523514edSGeliang Tang
434327b9a94SPaolo Abeni# $1: ns, $2: port
435327b9a94SPaolo Abeniwait_local_port_listen()
436327b9a94SPaolo Abeni{
437327b9a94SPaolo Abeni	local listener_ns="${1}"
438327b9a94SPaolo Abeni	local port="${2}"
439327b9a94SPaolo Abeni
4401e777bd8SMatthieu Baerts	local port_hex
441327b9a94SPaolo Abeni	port_hex="$(printf "%04X" "${port}")"
4421e777bd8SMatthieu Baerts
4431e777bd8SMatthieu Baerts	local i
444327b9a94SPaolo Abeni	for i in $(seq 10); do
445327b9a94SPaolo Abeni		ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
446327b9a94SPaolo Abeni			awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
447327b9a94SPaolo Abeni			break
448327b9a94SPaolo Abeni		sleep 0.1
449327b9a94SPaolo Abeni	done
450327b9a94SPaolo Abeni}
451327b9a94SPaolo Abeni
452327b9a94SPaolo Abenirm_addr_count()
453327b9a94SPaolo Abeni{
4541e777bd8SMatthieu Baerts	local ns=${1}
455327b9a94SPaolo Abeni
456327b9a94SPaolo Abeni	ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'
457327b9a94SPaolo Abeni}
458327b9a94SPaolo Abeni
459327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns
460327b9a94SPaolo Abeniwait_rm_addr()
461327b9a94SPaolo Abeni{
462327b9a94SPaolo Abeni	local ns="${1}"
463327b9a94SPaolo Abeni	local old_cnt="${2}"
464327b9a94SPaolo Abeni	local cnt
465327b9a94SPaolo Abeni
4661e777bd8SMatthieu Baerts	local i
467327b9a94SPaolo Abeni	for i in $(seq 10); do
468327b9a94SPaolo Abeni		cnt=$(rm_addr_count ${ns})
469327b9a94SPaolo Abeni		[ "$cnt" = "${old_cnt}" ] || break
470327b9a94SPaolo Abeni		sleep 0.1
471327b9a94SPaolo Abeni	done
472327b9a94SPaolo Abeni}
473327b9a94SPaolo Abeni
47469c6ce7bSPaolo Abeniwait_mpj()
47569c6ce7bSPaolo Abeni{
47669c6ce7bSPaolo Abeni	local ns="${1}"
47769c6ce7bSPaolo Abeni	local cnt old_cnt
47869c6ce7bSPaolo Abeni
47969c6ce7bSPaolo Abeni	old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
48069c6ce7bSPaolo Abeni
48169c6ce7bSPaolo Abeni	local i
48269c6ce7bSPaolo Abeni	for i in $(seq 10); do
48369c6ce7bSPaolo Abeni		cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
48469c6ce7bSPaolo Abeni		[ "$cnt" = "${old_cnt}" ] || break
48569c6ce7bSPaolo Abeni		sleep 0.1
48669c6ce7bSPaolo Abeni	done
48769c6ce7bSPaolo Abeni}
48869c6ce7bSPaolo Abeni
48997040cf9SGeliang Tangkill_wait()
49097040cf9SGeliang Tang{
49197040cf9SGeliang Tang	kill $1 > /dev/null 2>&1
49297040cf9SGeliang Tang	wait $1 2>/dev/null
49397040cf9SGeliang Tang}
49497040cf9SGeliang Tang
495a3735625SGeliang Tangkill_events_pids()
496a3735625SGeliang Tang{
497a3735625SGeliang Tang	kill_wait $evts_ns1_pid
498a3735625SGeliang Tang	kill_wait $evts_ns2_pid
499a3735625SGeliang Tang}
500a3735625SGeliang Tang
501*070d6dafSMatthieu Baertskill_tests_wait()
502*070d6dafSMatthieu Baerts{
503*070d6dafSMatthieu Baerts	kill -SIGUSR1 $(ip netns pids $ns2) $(ip netns pids $ns1)
504*070d6dafSMatthieu Baerts	wait
505*070d6dafSMatthieu Baerts}
506*070d6dafSMatthieu Baerts
50734aa6e3bSGeliang Tangpm_nl_set_limits()
50834aa6e3bSGeliang Tang{
50934aa6e3bSGeliang Tang	local ns=$1
51034aa6e3bSGeliang Tang	local addrs=$2
51134aa6e3bSGeliang Tang	local subflows=$3
51234aa6e3bSGeliang Tang
51334aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
51434aa6e3bSGeliang Tang		ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
51534aa6e3bSGeliang Tang	else
51634aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
51734aa6e3bSGeliang Tang	fi
51834aa6e3bSGeliang Tang}
51934aa6e3bSGeliang Tang
52034aa6e3bSGeliang Tangpm_nl_add_endpoint()
52134aa6e3bSGeliang Tang{
52234aa6e3bSGeliang Tang	local ns=$1
52334aa6e3bSGeliang Tang	local addr=$2
5241e777bd8SMatthieu Baerts	local flags _flags
5251e777bd8SMatthieu Baerts	local port _port
5261e777bd8SMatthieu Baerts	local dev _dev
5271e777bd8SMatthieu Baerts	local id _id
52834aa6e3bSGeliang Tang	local nr=2
52934aa6e3bSGeliang Tang
5301e777bd8SMatthieu Baerts	local p
531d8d08302SMatthieu Baerts	for p in "${@}"
53234aa6e3bSGeliang Tang	do
53334aa6e3bSGeliang Tang		if [ $p = "flags" ]; then
53434aa6e3bSGeliang Tang			eval _flags=\$"$nr"
535d8d08302SMatthieu Baerts			[ -n "$_flags" ]; flags="flags $_flags"
53634aa6e3bSGeliang Tang		fi
53734aa6e3bSGeliang Tang		if [ $p = "dev" ]; then
53834aa6e3bSGeliang Tang			eval _dev=\$"$nr"
539d8d08302SMatthieu Baerts			[ -n "$_dev" ]; dev="dev $_dev"
54034aa6e3bSGeliang Tang		fi
54134aa6e3bSGeliang Tang		if [ $p = "id" ]; then
54234aa6e3bSGeliang Tang			eval _id=\$"$nr"
543d8d08302SMatthieu Baerts			[ -n "$_id" ]; id="id $_id"
54434aa6e3bSGeliang Tang		fi
54534aa6e3bSGeliang Tang		if [ $p = "port" ]; then
54634aa6e3bSGeliang Tang			eval _port=\$"$nr"
547d8d08302SMatthieu Baerts			[ -n "$_port" ]; port="port $_port"
54834aa6e3bSGeliang Tang		fi
54934aa6e3bSGeliang Tang
550d8d08302SMatthieu Baerts		nr=$((nr + 1))
55134aa6e3bSGeliang Tang	done
55234aa6e3bSGeliang Tang
55334aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
55434aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
55534aa6e3bSGeliang Tang	else
55634aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
55734aa6e3bSGeliang Tang	fi
55834aa6e3bSGeliang Tang}
55934aa6e3bSGeliang Tang
56034aa6e3bSGeliang Tangpm_nl_del_endpoint()
56134aa6e3bSGeliang Tang{
56234aa6e3bSGeliang Tang	local ns=$1
56334aa6e3bSGeliang Tang	local id=$2
56434aa6e3bSGeliang Tang	local addr=$3
56534aa6e3bSGeliang Tang
56634aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
56734aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint delete id $id $addr
56834aa6e3bSGeliang Tang	else
56934aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl del $id $addr
57034aa6e3bSGeliang Tang	fi
57134aa6e3bSGeliang Tang}
57234aa6e3bSGeliang Tang
57334aa6e3bSGeliang Tangpm_nl_flush_endpoint()
57434aa6e3bSGeliang Tang{
57534aa6e3bSGeliang Tang	local ns=$1
57634aa6e3bSGeliang Tang
57734aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
57834aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint flush
57934aa6e3bSGeliang Tang	else
58034aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl flush
58134aa6e3bSGeliang Tang	fi
58234aa6e3bSGeliang Tang}
58334aa6e3bSGeliang Tang
584dda61b3dSGeliang Tangpm_nl_show_endpoints()
585dda61b3dSGeliang Tang{
586dda61b3dSGeliang Tang	local ns=$1
587dda61b3dSGeliang Tang
588dda61b3dSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
589dda61b3dSGeliang Tang		ip -n $ns mptcp endpoint show
590dda61b3dSGeliang Tang	else
591dda61b3dSGeliang Tang		ip netns exec $ns ./pm_nl_ctl dump
592dda61b3dSGeliang Tang	fi
593dda61b3dSGeliang Tang}
594dda61b3dSGeliang Tang
595f0140386SGeliang Tangpm_nl_change_endpoint()
596f0140386SGeliang Tang{
597f0140386SGeliang Tang	local ns=$1
598bccefb76SGeliang Tang	local id=$2
599bccefb76SGeliang Tang	local flags=$3
600f0140386SGeliang Tang
601f0140386SGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
602f0140386SGeliang Tang		ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
603f0140386SGeliang Tang	else
604bccefb76SGeliang Tang		ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
605f0140386SGeliang Tang	fi
606f0140386SGeliang Tang}
607f0140386SGeliang Tang
60869c6ce7bSPaolo Abenipm_nl_check_endpoint()
60969c6ce7bSPaolo Abeni{
61069c6ce7bSPaolo Abeni	local line expected_line
611c7d49c03SMatthieu Baerts	local need_title=$1
61269c6ce7bSPaolo Abeni	local msg="$2"
61369c6ce7bSPaolo Abeni	local ns=$3
61469c6ce7bSPaolo Abeni	local addr=$4
61569c6ce7bSPaolo Abeni	local _flags=""
61669c6ce7bSPaolo Abeni	local flags
61769c6ce7bSPaolo Abeni	local _port
61869c6ce7bSPaolo Abeni	local port
61969c6ce7bSPaolo Abeni	local dev
62069c6ce7bSPaolo Abeni	local _id
62169c6ce7bSPaolo Abeni	local id
62269c6ce7bSPaolo Abeni
623c7d49c03SMatthieu Baerts	if [ "${need_title}" = 1 ]; then
624c7d49c03SMatthieu Baerts		printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}"
62569c6ce7bSPaolo Abeni	else
62669c6ce7bSPaolo Abeni		printf "%-${nr_blank}s %s" " " "${msg}"
62769c6ce7bSPaolo Abeni	fi
62869c6ce7bSPaolo Abeni
62969c6ce7bSPaolo Abeni	shift 4
63069c6ce7bSPaolo Abeni	while [ -n "$1" ]; do
63169c6ce7bSPaolo Abeni		if [ $1 = "flags" ]; then
63269c6ce7bSPaolo Abeni			_flags=$2
633d8d08302SMatthieu Baerts			[ -n "$_flags" ]; flags="flags $_flags"
63469c6ce7bSPaolo Abeni			shift
63569c6ce7bSPaolo Abeni		elif [ $1 = "dev" ]; then
636d8d08302SMatthieu Baerts			[ -n "$2" ]; dev="dev $1"
63769c6ce7bSPaolo Abeni			shift
63869c6ce7bSPaolo Abeni		elif [ $1 = "id" ]; then
63969c6ce7bSPaolo Abeni			_id=$2
640d8d08302SMatthieu Baerts			[ -n "$_id" ]; id="id $_id"
64169c6ce7bSPaolo Abeni			shift
64269c6ce7bSPaolo Abeni		elif [ $1 = "port" ]; then
64369c6ce7bSPaolo Abeni			_port=$2
644d8d08302SMatthieu Baerts			[ -n "$_port" ]; port=" port $_port"
64569c6ce7bSPaolo Abeni			shift
64669c6ce7bSPaolo Abeni		fi
64769c6ce7bSPaolo Abeni
64869c6ce7bSPaolo Abeni		shift
64969c6ce7bSPaolo Abeni	done
65069c6ce7bSPaolo Abeni
65169c6ce7bSPaolo Abeni	if [ -z "$id" ]; then
65269c6ce7bSPaolo Abeni		echo "[skip] bad test - missing endpoint id"
65369c6ce7bSPaolo Abeni		return
65469c6ce7bSPaolo Abeni	fi
65569c6ce7bSPaolo Abeni
65669c6ce7bSPaolo Abeni	if [ $ip_mptcp -eq 1 ]; then
65769c6ce7bSPaolo Abeni		line=$(ip -n $ns mptcp endpoint show $id)
65869c6ce7bSPaolo Abeni		# the dump order is: address id flags port dev
65969c6ce7bSPaolo Abeni		expected_line="$addr"
66069c6ce7bSPaolo Abeni		[ -n "$addr" ] && expected_line="$expected_line $addr"
66169c6ce7bSPaolo Abeni		expected_line="$expected_line $id"
66269c6ce7bSPaolo Abeni		[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
66369c6ce7bSPaolo Abeni		[ -n "$dev" ] && expected_line="$expected_line $dev"
66469c6ce7bSPaolo Abeni		[ -n "$port" ] && expected_line="$expected_line $port"
66569c6ce7bSPaolo Abeni	else
66669c6ce7bSPaolo Abeni		line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
66769c6ce7bSPaolo Abeni		# the dump order is: id flags dev address port
66869c6ce7bSPaolo Abeni		expected_line="$id"
66969c6ce7bSPaolo Abeni		[ -n "$flags" ] && expected_line="$expected_line $flags"
67069c6ce7bSPaolo Abeni		[ -n "$dev" ] && expected_line="$expected_line $dev"
67169c6ce7bSPaolo Abeni		[ -n "$addr" ] && expected_line="$expected_line $addr"
67269c6ce7bSPaolo Abeni		[ -n "$_port" ] && expected_line="$expected_line $_port"
67369c6ce7bSPaolo Abeni	fi
67469c6ce7bSPaolo Abeni	if [ "$line" = "$expected_line" ]; then
67569c6ce7bSPaolo Abeni		echo "[ ok ]"
67669c6ce7bSPaolo Abeni	else
67769c6ce7bSPaolo Abeni		echo "[fail] expected '$expected_line' found '$line'"
67839aab882SMatthieu Baerts		fail_test
67969c6ce7bSPaolo Abeni	fi
68069c6ce7bSPaolo Abeni}
68169c6ce7bSPaolo Abeni
6823469d72fSMatthieu Baertsfilter_tcp_from()
6833469d72fSMatthieu Baerts{
6843469d72fSMatthieu Baerts	local ns="${1}"
6853469d72fSMatthieu Baerts	local src="${2}"
6863469d72fSMatthieu Baerts	local target="${3}"
6873469d72fSMatthieu Baerts
6883469d72fSMatthieu Baerts	ip netns exec "${ns}" iptables -A INPUT -s "${src}" -p tcp -j "${target}"
6893469d72fSMatthieu Baerts}
6903469d72fSMatthieu Baerts
691b08fbf24SPaolo Abenido_transfer()
692b08fbf24SPaolo Abeni{
6931e777bd8SMatthieu Baerts	local listener_ns="$1"
6941e777bd8SMatthieu Baerts	local connector_ns="$2"
6951e777bd8SMatthieu Baerts	local cl_proto="$3"
6961e777bd8SMatthieu Baerts	local srv_proto="$4"
6971e777bd8SMatthieu Baerts	local connect_addr="$5"
6981e777bd8SMatthieu Baerts	local test_link_fail="$6"
6991e777bd8SMatthieu Baerts	local addr_nr_ns1="$7"
7001e777bd8SMatthieu Baerts	local addr_nr_ns2="$8"
7011e777bd8SMatthieu Baerts	local speed="$9"
7021e777bd8SMatthieu Baerts	local sflags="${10}"
703b08fbf24SPaolo Abeni
7041e777bd8SMatthieu Baerts	local port=$((10000 + TEST_COUNT - 1))
7051e777bd8SMatthieu Baerts	local cappid
70697040cf9SGeliang Tang	local userspace_pm=0
707b08fbf24SPaolo Abeni
708b08fbf24SPaolo Abeni	:> "$cout"
709b08fbf24SPaolo Abeni	:> "$sout"
710b08fbf24SPaolo Abeni	:> "$capout"
711b08fbf24SPaolo Abeni
712b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
7131e777bd8SMatthieu Baerts		local capuser
714b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
715b08fbf24SPaolo Abeni			capuser=""
716b08fbf24SPaolo Abeni		else
717b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
718b08fbf24SPaolo Abeni		fi
719b08fbf24SPaolo Abeni
72000587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
721b08fbf24SPaolo Abeni
722b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
723b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
724b08fbf24SPaolo Abeni		cappid=$!
725b08fbf24SPaolo Abeni
726b08fbf24SPaolo Abeni		sleep 1
727b08fbf24SPaolo Abeni	fi
728b08fbf24SPaolo Abeni
729c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
730c2a55e8fSMatthieu Baerts		nstat -n
731c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
732c2a55e8fSMatthieu Baerts		nstat -n
733c2a55e8fSMatthieu Baerts
734cbfafac4SGeliang Tang	local extra_args
7358d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
736cbfafac4SGeliang Tang		extra_args="-j"
7378da6229bSGeliang Tang	elif [ $speed = "slow" ]; then
738cbfafac4SGeliang Tang		extra_args="-r 50"
739cbfafac4SGeliang Tang	elif [[ $speed = "speed_"* ]]; then
740cbfafac4SGeliang Tang		extra_args="-r ${speed:6}"
741dd72b0feSGeliang Tang	fi
742dd72b0feSGeliang Tang
74397040cf9SGeliang Tang	if [[ "${addr_nr_ns1}" = "userspace_"* ]]; then
74497040cf9SGeliang Tang		userspace_pm=1
74597040cf9SGeliang Tang		addr_nr_ns1=${addr_nr_ns1:10}
74697040cf9SGeliang Tang	fi
74797040cf9SGeliang Tang
748a1c3bdd9SGeliang Tang	local flags="subflow"
7496bf41020SPaolo Abeni	local extra_cl_args=""
7506bf41020SPaolo Abeni	local extra_srv_args=""
7516bf41020SPaolo Abeni	local trunc_size=""
75201542c9bSGeliang Tang	if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then
7536bf41020SPaolo Abeni		if [ ${test_link_fail} -le 1 ]; then
7546bf41020SPaolo Abeni			echo "fastclose tests need test_link_fail argument"
7556bf41020SPaolo Abeni			fail_test
7566bf41020SPaolo Abeni			return 1
7576bf41020SPaolo Abeni		fi
7586bf41020SPaolo Abeni
75901542c9bSGeliang Tang		# disconnect
7606bf41020SPaolo Abeni		trunc_size=${test_link_fail}
7616bf41020SPaolo Abeni		local side=${addr_nr_ns2:10}
7626bf41020SPaolo Abeni
7636bf41020SPaolo Abeni		if [ ${side} = "client" ]; then
7646bf41020SPaolo Abeni			extra_cl_args="-f ${test_link_fail}"
7656bf41020SPaolo Abeni			extra_srv_args="-f -1"
7666bf41020SPaolo Abeni		elif [ ${side} = "server" ]; then
7676bf41020SPaolo Abeni			extra_srv_args="-f ${test_link_fail}"
7686bf41020SPaolo Abeni			extra_cl_args="-f -1"
7696bf41020SPaolo Abeni		else
7706bf41020SPaolo Abeni			echo "wrong/unknown fastclose spec ${side}"
7716bf41020SPaolo Abeni			fail_test
7726bf41020SPaolo Abeni			return 1
7736bf41020SPaolo Abeni		fi
77401542c9bSGeliang Tang		addr_nr_ns2=0
7755e986ec4SGeliang Tang	elif [[ "${addr_nr_ns2}" = "userspace_"* ]]; then
7765e986ec4SGeliang Tang		userspace_pm=1
7775e986ec4SGeliang Tang		addr_nr_ns2=${addr_nr_ns2:10}
778a1c3bdd9SGeliang Tang	elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
779a1c3bdd9SGeliang Tang		flags="${flags},fullmesh"
780a1c3bdd9SGeliang Tang		addr_nr_ns2=${addr_nr_ns2:9}
78101542c9bSGeliang Tang	fi
78201542c9bSGeliang Tang
783523514edSGeliang Tang	local local_addr
784523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
785523514edSGeliang Tang		local_addr="::"
786523514edSGeliang Tang	else
787523514edSGeliang Tang		local_addr="0.0.0.0"
788523514edSGeliang Tang	fi
789523514edSGeliang Tang
7906bf41020SPaolo Abeni	extra_srv_args="$extra_args $extra_srv_args"
79134b572b7SGeliang Tang	if [ "$test_link_fail" -gt 1 ];then
7927d1e6f16SPaolo Abeni		timeout ${timeout_test} \
7937d1e6f16SPaolo Abeni			ip netns exec ${listener_ns} \
794cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
7956bf41020SPaolo Abeni					$extra_srv_args ${local_addr} < "$sinfail" > "$sout" &
7967d1e6f16SPaolo Abeni	else
7975888a61cSMatthieu Baerts		timeout ${timeout_test} \
7985888a61cSMatthieu Baerts			ip netns exec ${listener_ns} \
799cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
8006bf41020SPaolo Abeni					$extra_srv_args ${local_addr} < "$sin" > "$sout" &
8017d1e6f16SPaolo Abeni	fi
8021e777bd8SMatthieu Baerts	local spid=$!
803b08fbf24SPaolo Abeni
804327b9a94SPaolo Abeni	wait_local_port_listen "${listener_ns}" "${port}"
805b08fbf24SPaolo Abeni
8066bf41020SPaolo Abeni	extra_cl_args="$extra_args $extra_cl_args"
8078b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
8085888a61cSMatthieu Baerts		timeout ${timeout_test} \
8095888a61cSMatthieu Baerts			ip netns exec ${connector_ns} \
810cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
8116bf41020SPaolo Abeni					$extra_cl_args $connect_addr < "$cin" > "$cout" &
81234b572b7SGeliang Tang	elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then
8137d1e6f16SPaolo Abeni		( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
8145888a61cSMatthieu Baerts			tee "$cinsent" | \
8155888a61cSMatthieu Baerts			timeout ${timeout_test} \
8165888a61cSMatthieu Baerts				ip netns exec ${connector_ns} \
817cbfafac4SGeliang Tang					./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
8186bf41020SPaolo Abeni						$extra_cl_args $connect_addr > "$cout" &
81934b572b7SGeliang Tang	else
820d8d08302SMatthieu Baerts		tee "$cinsent" < "$cinfail" | \
82134b572b7SGeliang Tang			timeout ${timeout_test} \
82234b572b7SGeliang Tang				ip netns exec ${connector_ns} \
82334b572b7SGeliang Tang					./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
8246bf41020SPaolo Abeni						$extra_cl_args $connect_addr > "$cout" &
8258b819a84SFlorian Westphal	fi
8261e777bd8SMatthieu Baerts	local cpid=$!
827b08fbf24SPaolo Abeni
828327b9a94SPaolo Abeni	# let the mptcp subflow be established in background before
829327b9a94SPaolo Abeni	# do endpoint manipulation
830d8d08302SMatthieu Baerts	if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then
831d8d08302SMatthieu Baerts		sleep 1
832d8d08302SMatthieu Baerts	fi
833327b9a94SPaolo Abeni
8346208fd82SGeliang Tang	if [ $addr_nr_ns1 -gt 0 ]; then
8351e777bd8SMatthieu Baerts		local counter=2
836d8d08302SMatthieu Baerts		local add_nr_ns1=${addr_nr_ns1}
83797040cf9SGeliang Tang		local id=10
83897040cf9SGeliang Tang		local tk
8396208fd82SGeliang Tang		while [ $add_nr_ns1 -gt 0 ]; do
8406208fd82SGeliang Tang			local addr
8416208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
8426208fd82SGeliang Tang				addr="dead:beef:$counter::1"
8436208fd82SGeliang Tang			else
8446208fd82SGeliang Tang				addr="10.0.$counter.1"
8456208fd82SGeliang Tang			fi
84697040cf9SGeliang Tang			if [ $userspace_pm -eq 0 ]; then
84734aa6e3bSGeliang Tang				pm_nl_add_endpoint $ns1 $addr flags signal
84897040cf9SGeliang Tang			else
8497dff74f5SGeliang Tang				tk=$(grep "type:1," "$evts_ns1" |
8507dff74f5SGeliang Tang				     sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
85197040cf9SGeliang Tang				ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id
85297040cf9SGeliang Tang				sleep 1
85397040cf9SGeliang Tang				ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id
85497040cf9SGeliang Tang			fi
85597040cf9SGeliang Tang
856d8d08302SMatthieu Baerts			counter=$((counter + 1))
857d8d08302SMatthieu Baerts			add_nr_ns1=$((add_nr_ns1 - 1))
85897040cf9SGeliang Tang			id=$((id + 1))
8596208fd82SGeliang Tang		done
8606208fd82SGeliang Tang	elif [ $addr_nr_ns1 -lt 0 ]; then
861d8d08302SMatthieu Baerts		local rm_nr_ns1=$((-addr_nr_ns1))
8626fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
8631e777bd8SMatthieu Baerts			local counter=0
8641e777bd8SMatthieu Baerts			local line
865d8d08302SMatthieu Baerts			pm_nl_show_endpoints ${listener_ns} | while read -r line; do
866d8d08302SMatthieu Baerts				# shellcheck disable=SC2206 # we do want to split per word
867dda61b3dSGeliang Tang				local arr=($line)
868dda61b3dSGeliang Tang				local nr=0
869dda61b3dSGeliang Tang
8701e777bd8SMatthieu Baerts				local i
871d8d08302SMatthieu Baerts				for i in "${arr[@]}"; do
872dda61b3dSGeliang Tang					if [ $i = "id" ]; then
873dda61b3dSGeliang Tang						if [ $counter -eq $rm_nr_ns1 ]; then
874dda61b3dSGeliang Tang							break
875dda61b3dSGeliang Tang						fi
876dda61b3dSGeliang Tang						id=${arr[$nr+1]}
877327b9a94SPaolo Abeni						rm_addr=$(rm_addr_count ${connector_ns})
87834aa6e3bSGeliang Tang						pm_nl_del_endpoint ${listener_ns} $id
879327b9a94SPaolo Abeni						wait_rm_addr ${connector_ns} ${rm_addr}
880d8d08302SMatthieu Baerts						counter=$((counter + 1))
881f87744adSGeliang Tang					fi
882d8d08302SMatthieu Baerts					nr=$((nr + 1))
883dda61b3dSGeliang Tang				done
884dda61b3dSGeliang Tang			done
8855e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 8 ]; then
88634aa6e3bSGeliang Tang			pm_nl_flush_endpoint ${listener_ns}
8875e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 9 ]; then
88834aa6e3bSGeliang Tang			pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr}
8896fe4ccdcSGeliang Tang		fi
890dd72b0feSGeliang Tang	fi
891dd72b0feSGeliang Tang
892327b9a94SPaolo Abeni	# if newly added endpoints must be deleted, give the background msk
893327b9a94SPaolo Abeni	# some time to created them
894d8d08302SMatthieu Baerts	[ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1
895327b9a94SPaolo Abeni
8966208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
897d8d08302SMatthieu Baerts		local add_nr_ns2=${addr_nr_ns2}
8981e777bd8SMatthieu Baerts		local counter=3
8995e986ec4SGeliang Tang		local id=20
9005e986ec4SGeliang Tang		local tk da dp sp
9016208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
9026208fd82SGeliang Tang			local addr
9036208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
9046208fd82SGeliang Tang				addr="dead:beef:$counter::2"
9056208fd82SGeliang Tang			else
9066208fd82SGeliang Tang				addr="10.0.$counter.2"
9076208fd82SGeliang Tang			fi
9085e986ec4SGeliang Tang			if [ $userspace_pm -eq 0 ]; then
90934aa6e3bSGeliang Tang				pm_nl_add_endpoint $ns2 $addr flags $flags
9105e986ec4SGeliang Tang			else
9115e986ec4SGeliang Tang				tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
9125e986ec4SGeliang Tang				da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2")
9135e986ec4SGeliang Tang				dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2")
9145e986ec4SGeliang Tang				ip netns exec ${connector_ns} ./pm_nl_ctl csf lip $addr lid $id \
9155e986ec4SGeliang Tang									rip $da rport $dp token $tk
9165e986ec4SGeliang Tang				sleep 1
9175e986ec4SGeliang Tang				sp=$(grep "type:10" "$evts_ns2" |
9185e986ec4SGeliang Tang				     sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
9195e986ec4SGeliang Tang				ip netns exec ${connector_ns} ./pm_nl_ctl dsf lip $addr lport $sp \
9205e986ec4SGeliang Tang									rip $da rport $dp token $tk
9215e986ec4SGeliang Tang			fi
922d8d08302SMatthieu Baerts			counter=$((counter + 1))
923d8d08302SMatthieu Baerts			add_nr_ns2=$((add_nr_ns2 - 1))
9245e986ec4SGeliang Tang			id=$((id + 1))
9256208fd82SGeliang Tang		done
9266208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
927d8d08302SMatthieu Baerts		local rm_nr_ns2=$((-addr_nr_ns2))
9286fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
9291e777bd8SMatthieu Baerts			local counter=0
9301e777bd8SMatthieu Baerts			local line
931d8d08302SMatthieu Baerts			pm_nl_show_endpoints ${connector_ns} | while read -r line; do
932d8d08302SMatthieu Baerts				# shellcheck disable=SC2206 # we do want to split per word
933dda61b3dSGeliang Tang				local arr=($line)
934dda61b3dSGeliang Tang				local nr=0
935dda61b3dSGeliang Tang
9361e777bd8SMatthieu Baerts				local i
937d8d08302SMatthieu Baerts				for i in "${arr[@]}"; do
938dda61b3dSGeliang Tang					if [ $i = "id" ]; then
939dda61b3dSGeliang Tang						if [ $counter -eq $rm_nr_ns2 ]; then
940dda61b3dSGeliang Tang							break
941dda61b3dSGeliang Tang						fi
9421e777bd8SMatthieu Baerts						local id rm_addr
943dda61b3dSGeliang Tang						# rm_addr are serialized, allow the previous one to
944dda61b3dSGeliang Tang						# complete
945dda61b3dSGeliang Tang						id=${arr[$nr+1]}
946327b9a94SPaolo Abeni						rm_addr=$(rm_addr_count ${listener_ns})
94734aa6e3bSGeliang Tang						pm_nl_del_endpoint ${connector_ns} $id
948327b9a94SPaolo Abeni						wait_rm_addr ${listener_ns} ${rm_addr}
949d8d08302SMatthieu Baerts						counter=$((counter + 1))
950f87744adSGeliang Tang					fi
951d8d08302SMatthieu Baerts					nr=$((nr + 1))
952dda61b3dSGeliang Tang				done
953dda61b3dSGeliang Tang			done
9545e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 8 ]; then
95534aa6e3bSGeliang Tang			pm_nl_flush_endpoint ${connector_ns}
9565e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 9 ]; then
9575e287fe7SGeliang Tang			local addr
9585e287fe7SGeliang Tang			if is_v6 "${connect_addr}"; then
9595e287fe7SGeliang Tang				addr="dead:beef:1::2"
9605e287fe7SGeliang Tang			else
9615e287fe7SGeliang Tang				addr="10.0.1.2"
9625e287fe7SGeliang Tang			fi
96334aa6e3bSGeliang Tang			pm_nl_del_endpoint ${connector_ns} 0 $addr
9646fe4ccdcSGeliang Tang		fi
965dd72b0feSGeliang Tang	fi
966dd72b0feSGeliang Tang
967d8d08302SMatthieu Baerts	if [ -n "${sflags}" ]; then
968718eb44eSGeliang Tang		sleep 1
9691e777bd8SMatthieu Baerts
9701e777bd8SMatthieu Baerts		local netns
971718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
9721e777bd8SMatthieu Baerts			local line
973d8d08302SMatthieu Baerts			pm_nl_show_endpoints $netns | while read -r line; do
974d8d08302SMatthieu Baerts				# shellcheck disable=SC2206 # we do want to split per word
97533397b83SGeliang Tang				local arr=($line)
976bccefb76SGeliang Tang				local nr=0
977f0140386SGeliang Tang				local id
97833397b83SGeliang Tang
9791e777bd8SMatthieu Baerts				local i
980d8d08302SMatthieu Baerts				for i in "${arr[@]}"; do
981bccefb76SGeliang Tang					if [ $i = "id" ]; then
982bccefb76SGeliang Tang						id=${arr[$nr+1]}
983718eb44eSGeliang Tang					fi
984d8d08302SMatthieu Baerts					nr=$((nr + 1))
98533397b83SGeliang Tang				done
986bccefb76SGeliang Tang				pm_nl_change_endpoint $netns $id $sflags
98733397b83SGeliang Tang			done
988718eb44eSGeliang Tang		done
989718eb44eSGeliang Tang	fi
990718eb44eSGeliang Tang
991b08fbf24SPaolo Abeni	wait $cpid
9921e777bd8SMatthieu Baerts	local retc=$?
993b08fbf24SPaolo Abeni	wait $spid
9941e777bd8SMatthieu Baerts	local rets=$?
995b08fbf24SPaolo Abeni
996b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
997b08fbf24SPaolo Abeni	    sleep 1
998b08fbf24SPaolo Abeni	    kill $cappid
999b08fbf24SPaolo Abeni	fi
1000b08fbf24SPaolo Abeni
1001c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
1002c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${listener_ns}.out
1003c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
1004c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${connector_ns}.out
1005c2a55e8fSMatthieu Baerts
1006b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
1007b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
10088b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
1009c2a55e8fSMatthieu Baerts		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
1010c2a55e8fSMatthieu Baerts		cat /tmp/${listener_ns}.out
10118b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
1012c2a55e8fSMatthieu Baerts		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
1013c2a55e8fSMatthieu Baerts		cat /tmp/${connector_ns}.out
1014b08fbf24SPaolo Abeni
1015b08fbf24SPaolo Abeni		cat "$capout"
101639aab882SMatthieu Baerts		fail_test
1017b08fbf24SPaolo Abeni		return 1
1018b08fbf24SPaolo Abeni	fi
1019b08fbf24SPaolo Abeni
102034b572b7SGeliang Tang	if [ "$test_link_fail" -gt 1 ];then
10216bf41020SPaolo Abeni		check_transfer $sinfail $cout "file received by client" $trunc_size
10227d1e6f16SPaolo Abeni	else
10236bf41020SPaolo Abeni		check_transfer $sin $cout "file received by client" $trunc_size
10247d1e6f16SPaolo Abeni	fi
1025b08fbf24SPaolo Abeni	retc=$?
10268b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
10276bf41020SPaolo Abeni		check_transfer $cin $sout "file received by server" $trunc_size
10288b819a84SFlorian Westphal	else
10296bf41020SPaolo Abeni		check_transfer $cinsent $sout "file received by server" $trunc_size
10308b819a84SFlorian Westphal	fi
1031b08fbf24SPaolo Abeni	rets=$?
1032b08fbf24SPaolo Abeni
1033b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
1034b08fbf24SPaolo Abeni		cat "$capout"
1035b08fbf24SPaolo Abeni		return 0
1036b08fbf24SPaolo Abeni	fi
1037b08fbf24SPaolo Abeni
1038b08fbf24SPaolo Abeni	cat "$capout"
1039b08fbf24SPaolo Abeni	return 1
1040b08fbf24SPaolo Abeni}
1041b08fbf24SPaolo Abeni
1042b08fbf24SPaolo Abenimake_file()
1043b08fbf24SPaolo Abeni{
10441e777bd8SMatthieu Baerts	local name=$1
10451e777bd8SMatthieu Baerts	local who=$2
10461e777bd8SMatthieu Baerts	local size=$3
1047b08fbf24SPaolo Abeni
10488b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
1049b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
1050b08fbf24SPaolo Abeni
10518b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
1052b08fbf24SPaolo Abeni}
1053b08fbf24SPaolo Abeni
1054b08fbf24SPaolo Abenirun_tests()
1055b08fbf24SPaolo Abeni{
10561e777bd8SMatthieu Baerts	local listener_ns="$1"
10571e777bd8SMatthieu Baerts	local connector_ns="$2"
10581e777bd8SMatthieu Baerts	local connect_addr="$3"
10591e777bd8SMatthieu Baerts	local test_linkfail="${4:-0}"
10601e777bd8SMatthieu Baerts	local addr_nr_ns1="${5:-0}"
10611e777bd8SMatthieu Baerts	local addr_nr_ns2="${6:-0}"
10621e777bd8SMatthieu Baerts	local speed="${7:-fast}"
10631e777bd8SMatthieu Baerts	local sflags="${8:-""}"
10641e777bd8SMatthieu Baerts
10651e777bd8SMatthieu Baerts	local size
10668b819a84SFlorian Westphal
106734b572b7SGeliang Tang	# The values above 2 are reused to make test files
106834b572b7SGeliang Tang	# with the given sizes (KB)
106934b572b7SGeliang Tang	if [ "$test_linkfail" -gt 2 ]; then
107034b572b7SGeliang Tang		size=$test_linkfail
107134b572b7SGeliang Tang
107234b572b7SGeliang Tang		if [ -z "$cinfail" ]; then
107334b572b7SGeliang Tang			cinfail=$(mktemp)
107434b572b7SGeliang Tang		fi
107534b572b7SGeliang Tang		make_file "$cinfail" "client" $size
10767d1e6f16SPaolo Abeni	# create the input file for the failure test when
10777d1e6f16SPaolo Abeni	# the first failure test run
1078d8d08302SMatthieu Baerts	elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then
10797d1e6f16SPaolo Abeni		# the client file must be considerably larger
10807d1e6f16SPaolo Abeni		# of the maximum expected cwin value, or the
10817d1e6f16SPaolo Abeni		# link utilization will be not predicable
10827d1e6f16SPaolo Abeni		size=$((RANDOM%2))
10838b819a84SFlorian Westphal		size=$((size+1))
10847d1e6f16SPaolo Abeni		size=$((size*8192))
1085d8d08302SMatthieu Baerts		size=$((size + ( RANDOM % 8192) ))
10868b819a84SFlorian Westphal
10877d1e6f16SPaolo Abeni		cinfail=$(mktemp)
10887d1e6f16SPaolo Abeni		make_file "$cinfail" "client" $size
10897d1e6f16SPaolo Abeni	fi
10907d1e6f16SPaolo Abeni
109134b572b7SGeliang Tang	if [ "$test_linkfail" -gt 2 ]; then
109234b572b7SGeliang Tang		size=$test_linkfail
109334b572b7SGeliang Tang
109434b572b7SGeliang Tang		if [ -z "$sinfail" ]; then
109534b572b7SGeliang Tang			sinfail=$(mktemp)
109634b572b7SGeliang Tang		fi
109734b572b7SGeliang Tang		make_file "$sinfail" "server" $size
1098d8d08302SMatthieu Baerts	elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then
10997d1e6f16SPaolo Abeni		size=$((RANDOM%16))
11007d1e6f16SPaolo Abeni		size=$((size+1))
11017d1e6f16SPaolo Abeni		size=$((size*2048))
11027d1e6f16SPaolo Abeni
11037d1e6f16SPaolo Abeni		sinfail=$(mktemp)
11047d1e6f16SPaolo Abeni		make_file "$sinfail" "server" $size
11058b819a84SFlorian Westphal	fi
1106b08fbf24SPaolo Abeni
11078d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
11086a0653b9SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${sflags}
1109b08fbf24SPaolo Abeni}
1110b08fbf24SPaolo Abeni
1111327b9a94SPaolo Abenidump_stats()
1112327b9a94SPaolo Abeni{
1113327b9a94SPaolo Abeni	echo Server ns stats
1114327b9a94SPaolo Abeni	ip netns exec $ns1 nstat -as | grep Tcp
1115327b9a94SPaolo Abeni	echo Client ns stats
1116327b9a94SPaolo Abeni	ip netns exec $ns2 nstat -as | grep Tcp
1117327b9a94SPaolo Abeni}
1118327b9a94SPaolo Abeni
1119af66d3e1SGeliang Tangchk_csum_nr()
1120af66d3e1SGeliang Tang{
11213c082695SGeliang Tang	local csum_ns1=${1:-0}
11223c082695SGeliang Tang	local csum_ns2=${2:-0}
1123af66d3e1SGeliang Tang	local count
1124af66d3e1SGeliang Tang	local dump_stats
112553f368bfSGeliang Tang	local extra_msg=""
112626516e10SGeliang Tang	local allow_multi_errors_ns1=0
112726516e10SGeliang Tang	local allow_multi_errors_ns2=0
112826516e10SGeliang Tang
112926516e10SGeliang Tang	if [[ "${csum_ns1}" = "+"* ]]; then
113026516e10SGeliang Tang		allow_multi_errors_ns1=1
113126516e10SGeliang Tang		csum_ns1=${csum_ns1:1}
113226516e10SGeliang Tang	fi
113326516e10SGeliang Tang	if [[ "${csum_ns2}" = "+"* ]]; then
113426516e10SGeliang Tang		allow_multi_errors_ns2=1
113526516e10SGeliang Tang		csum_ns2=${csum_ns2:1}
113626516e10SGeliang Tang	fi
1137af66d3e1SGeliang Tang
11383c082695SGeliang Tang	printf "%-${nr_blank}s %s" " " "sum"
11394bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}')
1140af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
114153f368bfSGeliang Tang	if [ "$count" != "$csum_ns1" ]; then
114253f368bfSGeliang Tang		extra_msg="$extra_msg ns1=$count"
114353f368bfSGeliang Tang	fi
1144d8d08302SMatthieu Baerts	if { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } ||
1145d8d08302SMatthieu Baerts	   { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then
114626516e10SGeliang Tang		echo "[fail] got $count data checksum error[s] expected $csum_ns1"
114739aab882SMatthieu Baerts		fail_test
1148af66d3e1SGeliang Tang		dump_stats=1
1149af66d3e1SGeliang Tang	else
1150af66d3e1SGeliang Tang		echo -n "[ ok ]"
1151af66d3e1SGeliang Tang	fi
1152af66d3e1SGeliang Tang	echo -n " - csum  "
11534bfadd71SMatthieu Baerts	count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}')
1154af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
115553f368bfSGeliang Tang	if [ "$count" != "$csum_ns2" ]; then
115653f368bfSGeliang Tang		extra_msg="$extra_msg ns2=$count"
115753f368bfSGeliang Tang	fi
1158d8d08302SMatthieu Baerts	if { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } ||
1159d8d08302SMatthieu Baerts	   { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then
116026516e10SGeliang Tang		echo "[fail] got $count data checksum error[s] expected $csum_ns2"
116139aab882SMatthieu Baerts		fail_test
1162af66d3e1SGeliang Tang		dump_stats=1
1163af66d3e1SGeliang Tang	else
116453f368bfSGeliang Tang		echo -n "[ ok ]"
1165af66d3e1SGeliang Tang	fi
1166327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
116753f368bfSGeliang Tang
116853f368bfSGeliang Tang	echo "$extra_msg"
1169af66d3e1SGeliang Tang}
1170af66d3e1SGeliang Tang
11716bb3ab49SGeliang Tangchk_fail_nr()
11726bb3ab49SGeliang Tang{
117326516e10SGeliang Tang	local fail_tx=$1
117426516e10SGeliang Tang	local fail_rx=$2
11751f7d325fSGeliang Tang	local ns_invert=${3:-""}
11766bb3ab49SGeliang Tang	local count
11776bb3ab49SGeliang Tang	local dump_stats
11781f7d325fSGeliang Tang	local ns_tx=$ns1
11791f7d325fSGeliang Tang	local ns_rx=$ns2
11801f7d325fSGeliang Tang	local extra_msg=""
11811f7d325fSGeliang Tang	local allow_tx_lost=0
11821f7d325fSGeliang Tang	local allow_rx_lost=0
11831f7d325fSGeliang Tang
11841f7d325fSGeliang Tang	if [[ $ns_invert = "invert" ]]; then
11851f7d325fSGeliang Tang		ns_tx=$ns2
11861f7d325fSGeliang Tang		ns_rx=$ns1
11871f7d325fSGeliang Tang		extra_msg=" invert"
11881f7d325fSGeliang Tang	fi
11891f7d325fSGeliang Tang
11901f7d325fSGeliang Tang	if [[ "${fail_tx}" = "-"* ]]; then
11911f7d325fSGeliang Tang		allow_tx_lost=1
11921f7d325fSGeliang Tang		fail_tx=${fail_tx:1}
11931f7d325fSGeliang Tang	fi
11941f7d325fSGeliang Tang	if [[ "${fail_rx}" = "-"* ]]; then
11951f7d325fSGeliang Tang		allow_rx_lost=1
11961f7d325fSGeliang Tang		fail_rx=${fail_rx:1}
11971f7d325fSGeliang Tang	fi
11986bb3ab49SGeliang Tang
11999a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "ftx"
12001f7d325fSGeliang Tang	count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}')
12016bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
120226516e10SGeliang Tang	if [ "$count" != "$fail_tx" ]; then
12031f7d325fSGeliang Tang		extra_msg="$extra_msg,tx=$count"
12041f7d325fSGeliang Tang	fi
12051f7d325fSGeliang Tang	if { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } ||
12061f7d325fSGeliang Tang	   { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then
120726516e10SGeliang Tang		echo "[fail] got $count MP_FAIL[s] TX expected $fail_tx"
120839aab882SMatthieu Baerts		fail_test
12096bb3ab49SGeliang Tang		dump_stats=1
12106bb3ab49SGeliang Tang	else
12116bb3ab49SGeliang Tang		echo -n "[ ok ]"
12126bb3ab49SGeliang Tang	fi
12136bb3ab49SGeliang Tang
121426516e10SGeliang Tang	echo -n " - failrx"
12151f7d325fSGeliang Tang	count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}')
12166bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
121726516e10SGeliang Tang	if [ "$count" != "$fail_rx" ]; then
12181f7d325fSGeliang Tang		extra_msg="$extra_msg,rx=$count"
12191f7d325fSGeliang Tang	fi
12201f7d325fSGeliang Tang	if { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } ||
12211f7d325fSGeliang Tang	   { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then
122226516e10SGeliang Tang		echo "[fail] got $count MP_FAIL[s] RX expected $fail_rx"
122339aab882SMatthieu Baerts		fail_test
12246bb3ab49SGeliang Tang		dump_stats=1
12256bb3ab49SGeliang Tang	else
12261f7d325fSGeliang Tang		echo -n "[ ok ]"
12276bb3ab49SGeliang Tang	fi
12286bb3ab49SGeliang Tang
1229327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
12301f7d325fSGeliang Tang
12311f7d325fSGeliang Tang	echo "$extra_msg"
12326bb3ab49SGeliang Tang}
12336bb3ab49SGeliang Tang
1234e8e947efSGeliang Tangchk_fclose_nr()
1235e8e947efSGeliang Tang{
1236e8e947efSGeliang Tang	local fclose_tx=$1
1237e8e947efSGeliang Tang	local fclose_rx=$2
12386bf41020SPaolo Abeni	local ns_invert=$3
1239e8e947efSGeliang Tang	local count
1240e8e947efSGeliang Tang	local dump_stats
12416bf41020SPaolo Abeni	local ns_tx=$ns2
12426bf41020SPaolo Abeni	local ns_rx=$ns1
12436bf41020SPaolo Abeni	local extra_msg="   "
12446bf41020SPaolo Abeni
12456bf41020SPaolo Abeni	if [[ $ns_invert = "invert" ]]; then
12466bf41020SPaolo Abeni		ns_tx=$ns1
12476bf41020SPaolo Abeni		ns_rx=$ns2
12486bf41020SPaolo Abeni		extra_msg=${extra_msg}"invert"
12496bf41020SPaolo Abeni	fi
1250e8e947efSGeliang Tang
1251e8e947efSGeliang Tang	printf "%-${nr_blank}s %s" " " "ctx"
12526bf41020SPaolo Abeni	count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFastcloseTx | awk '{print $2}')
1253e8e947efSGeliang Tang	[ -z "$count" ] && count=0
12546bf41020SPaolo Abeni	[ "$count" != "$fclose_tx" ] && extra_msg="$extra_msg,tx=$count"
1255e8e947efSGeliang Tang	if [ "$count" != "$fclose_tx" ]; then
1256e8e947efSGeliang Tang		echo "[fail] got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
125739aab882SMatthieu Baerts		fail_test
1258e8e947efSGeliang Tang		dump_stats=1
1259e8e947efSGeliang Tang	else
1260e8e947efSGeliang Tang		echo -n "[ ok ]"
1261e8e947efSGeliang Tang	fi
1262e8e947efSGeliang Tang
1263e8e947efSGeliang Tang	echo -n " - fclzrx"
12646bf41020SPaolo Abeni	count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFastcloseRx | awk '{print $2}')
1265e8e947efSGeliang Tang	[ -z "$count" ] && count=0
12666bf41020SPaolo Abeni	[ "$count" != "$fclose_rx" ] && extra_msg="$extra_msg,rx=$count"
1267e8e947efSGeliang Tang	if [ "$count" != "$fclose_rx" ]; then
1268e8e947efSGeliang Tang		echo "[fail] got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
126939aab882SMatthieu Baerts		fail_test
1270e8e947efSGeliang Tang		dump_stats=1
1271e8e947efSGeliang Tang	else
12726bf41020SPaolo Abeni		echo -n "[ ok ]"
1273e8e947efSGeliang Tang	fi
1274e8e947efSGeliang Tang
1275e8e947efSGeliang Tang	[ "${dump_stats}" = 1 ] && dump_stats
12766bf41020SPaolo Abeni
12776bf41020SPaolo Abeni	echo "$extra_msg"
1278e8e947efSGeliang Tang}
1279e8e947efSGeliang Tang
1280922fd2b3SGeliang Tangchk_rst_nr()
1281922fd2b3SGeliang Tang{
1282922fd2b3SGeliang Tang	local rst_tx=$1
1283922fd2b3SGeliang Tang	local rst_rx=$2
1284922fd2b3SGeliang Tang	local ns_invert=${3:-""}
1285922fd2b3SGeliang Tang	local count
1286922fd2b3SGeliang Tang	local dump_stats
1287922fd2b3SGeliang Tang	local ns_tx=$ns1
1288922fd2b3SGeliang Tang	local ns_rx=$ns2
1289922fd2b3SGeliang Tang	local extra_msg=""
1290922fd2b3SGeliang Tang
1291922fd2b3SGeliang Tang	if [[ $ns_invert = "invert" ]]; then
1292922fd2b3SGeliang Tang		ns_tx=$ns2
1293922fd2b3SGeliang Tang		ns_rx=$ns1
1294922fd2b3SGeliang Tang		extra_msg="   invert"
1295922fd2b3SGeliang Tang	fi
1296922fd2b3SGeliang Tang
1297922fd2b3SGeliang Tang	printf "%-${nr_blank}s %s" " " "rtx"
1298922fd2b3SGeliang Tang	count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPRstTx | awk '{print $2}')
1299922fd2b3SGeliang Tang	[ -z "$count" ] && count=0
13006bf41020SPaolo Abeni	if [ $count -lt $rst_tx ]; then
1301922fd2b3SGeliang Tang		echo "[fail] got $count MP_RST[s] TX expected $rst_tx"
130239aab882SMatthieu Baerts		fail_test
1303922fd2b3SGeliang Tang		dump_stats=1
1304922fd2b3SGeliang Tang	else
1305922fd2b3SGeliang Tang		echo -n "[ ok ]"
1306922fd2b3SGeliang Tang	fi
1307922fd2b3SGeliang Tang
1308922fd2b3SGeliang Tang	echo -n " - rstrx "
1309922fd2b3SGeliang Tang	count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPRstRx | awk '{print $2}')
1310922fd2b3SGeliang Tang	[ -z "$count" ] && count=0
13116bf41020SPaolo Abeni	if [ "$count" -lt "$rst_rx" ]; then
1312922fd2b3SGeliang Tang		echo "[fail] got $count MP_RST[s] RX expected $rst_rx"
131339aab882SMatthieu Baerts		fail_test
1314922fd2b3SGeliang Tang		dump_stats=1
1315922fd2b3SGeliang Tang	else
1316922fd2b3SGeliang Tang		echo -n "[ ok ]"
1317922fd2b3SGeliang Tang	fi
1318922fd2b3SGeliang Tang
1319922fd2b3SGeliang Tang	[ "${dump_stats}" = 1 ] && dump_stats
1320922fd2b3SGeliang Tang
1321922fd2b3SGeliang Tang	echo "$extra_msg"
1322922fd2b3SGeliang Tang}
1323922fd2b3SGeliang Tang
13248bd03be3SGeliang Tangchk_infi_nr()
13258bd03be3SGeliang Tang{
13268bd03be3SGeliang Tang	local infi_tx=$1
13278bd03be3SGeliang Tang	local infi_rx=$2
13288bd03be3SGeliang Tang	local count
13298bd03be3SGeliang Tang	local dump_stats
13308bd03be3SGeliang Tang
13318bd03be3SGeliang Tang	printf "%-${nr_blank}s %s" " " "itx"
13328bd03be3SGeliang Tang	count=$(ip netns exec $ns2 nstat -as | grep InfiniteMapTx | awk '{print $2}')
13338bd03be3SGeliang Tang	[ -z "$count" ] && count=0
13348bd03be3SGeliang Tang	if [ "$count" != "$infi_tx" ]; then
13358bd03be3SGeliang Tang		echo "[fail] got $count infinite map[s] TX expected $infi_tx"
13368bd03be3SGeliang Tang		fail_test
13378bd03be3SGeliang Tang		dump_stats=1
13388bd03be3SGeliang Tang	else
13398bd03be3SGeliang Tang		echo -n "[ ok ]"
13408bd03be3SGeliang Tang	fi
13418bd03be3SGeliang Tang
13428bd03be3SGeliang Tang	echo -n " - infirx"
13438bd03be3SGeliang Tang	count=$(ip netns exec $ns1 nstat -as | grep InfiniteMapRx | awk '{print $2}')
13448bd03be3SGeliang Tang	[ -z "$count" ] && count=0
13458bd03be3SGeliang Tang	if [ "$count" != "$infi_rx" ]; then
13468bd03be3SGeliang Tang		echo "[fail] got $count infinite map[s] RX expected $infi_rx"
13478bd03be3SGeliang Tang		fail_test
13488bd03be3SGeliang Tang		dump_stats=1
13498bd03be3SGeliang Tang	else
13508bd03be3SGeliang Tang		echo "[ ok ]"
13518bd03be3SGeliang Tang	fi
13528bd03be3SGeliang Tang
13538bd03be3SGeliang Tang	[ "${dump_stats}" = 1 ] && dump_stats
13548bd03be3SGeliang Tang}
13558bd03be3SGeliang Tang
1356b08fbf24SPaolo Abenichk_join_nr()
1357b08fbf24SPaolo Abeni{
1358c7d49c03SMatthieu Baerts	local syn_nr=$1
1359c7d49c03SMatthieu Baerts	local syn_ack_nr=$2
1360c7d49c03SMatthieu Baerts	local ack_nr=$3
1361c7d49c03SMatthieu Baerts	local csum_ns1=${4:-0}
1362c7d49c03SMatthieu Baerts	local csum_ns2=${5:-0}
1363c7d49c03SMatthieu Baerts	local fail_nr=${6:-0}
1364c7d49c03SMatthieu Baerts	local rst_nr=${7:-0}
13658bd03be3SGeliang Tang	local infi_nr=${8:-0}
13668bd03be3SGeliang Tang	local corrupted_pkts=${9:-0}
1367b08fbf24SPaolo Abeni	local count
1368b08fbf24SPaolo Abeni	local dump_stats
1369e35f885bSPaolo Abeni	local with_cookie
1370c7d49c03SMatthieu Baerts	local title="${TEST_NAME}"
1371b08fbf24SPaolo Abeni
1372c7d49c03SMatthieu Baerts	if [ "${corrupted_pkts}" -gt 0 ]; then
1373c7d49c03SMatthieu Baerts		title+=": ${corrupted_pkts} corrupted pkts"
1374c7d49c03SMatthieu Baerts	fi
1375c7d49c03SMatthieu Baerts
1376c7d49c03SMatthieu Baerts	printf "%03u %-36s %s" "${TEST_COUNT}" "${title}" "syn"
13774bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}')
1378b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1379b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
1380b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
138139aab882SMatthieu Baerts		fail_test
1382b08fbf24SPaolo Abeni		dump_stats=1
1383b08fbf24SPaolo Abeni	else
1384b08fbf24SPaolo Abeni		echo -n "[ ok ]"
1385b08fbf24SPaolo Abeni	fi
1386b08fbf24SPaolo Abeni
1387b08fbf24SPaolo Abeni	echo -n " - synack"
13884bfadd71SMatthieu Baerts	with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies)
13894bfadd71SMatthieu Baerts	count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}')
1390b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1391b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
1392e35f885bSPaolo Abeni		# simult connections exceeding the limit with cookie enabled could go up to
1393e35f885bSPaolo Abeni		# synack validation as the conn limit can be enforced reliably only after
1394e35f885bSPaolo Abeni		# the subflow creation
1395e35f885bSPaolo Abeni		if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then
1396e35f885bSPaolo Abeni			echo -n "[ ok ]"
1397e35f885bSPaolo Abeni		else
1398b08fbf24SPaolo Abeni			echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
139939aab882SMatthieu Baerts			fail_test
1400b08fbf24SPaolo Abeni			dump_stats=1
1401e35f885bSPaolo Abeni		fi
1402b08fbf24SPaolo Abeni	else
1403b08fbf24SPaolo Abeni		echo -n "[ ok ]"
1404b08fbf24SPaolo Abeni	fi
1405b08fbf24SPaolo Abeni
1406b08fbf24SPaolo Abeni	echo -n " - ack"
14074bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}')
1408b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1409b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
1410b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
141139aab882SMatthieu Baerts		fail_test
1412b08fbf24SPaolo Abeni		dump_stats=1
1413b08fbf24SPaolo Abeni	else
1414b08fbf24SPaolo Abeni		echo "[ ok ]"
1415b08fbf24SPaolo Abeni	fi
1416327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1417b6e074e1SGeliang Tang	if [ $validate_checksum -eq 1 ]; then
14183c082695SGeliang Tang		chk_csum_nr $csum_ns1 $csum_ns2
141926516e10SGeliang Tang		chk_fail_nr $fail_nr $fail_nr
142026516e10SGeliang Tang		chk_rst_nr $rst_nr $rst_nr
14218bd03be3SGeliang Tang		chk_infi_nr $infi_nr $infi_nr
1422af66d3e1SGeliang Tang	fi
1423b08fbf24SPaolo Abeni}
1424b08fbf24SPaolo Abeni
14257d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound:
14267d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while
14277d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of
14287d1e6f16SPaolo Abeni# stale/recover conversions, proportional to
14297d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval.
14307d1e6f16SPaolo Abenichk_stale_nr()
14317d1e6f16SPaolo Abeni{
14327d1e6f16SPaolo Abeni	local ns=$1
14337d1e6f16SPaolo Abeni	local stale_min=$2
14347d1e6f16SPaolo Abeni	local stale_max=$3
14357d1e6f16SPaolo Abeni	local stale_delta=$4
14367d1e6f16SPaolo Abeni	local dump_stats
14377d1e6f16SPaolo Abeni	local stale_nr
14387d1e6f16SPaolo Abeni	local recover_nr
14397d1e6f16SPaolo Abeni
14409a0a9367SGeliang Tang	printf "%-${nr_blank}s %-18s" " " "stale"
14414bfadd71SMatthieu Baerts	stale_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}')
14427d1e6f16SPaolo Abeni	[ -z "$stale_nr" ] && stale_nr=0
14434bfadd71SMatthieu Baerts	recover_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}')
14447d1e6f16SPaolo Abeni	[ -z "$recover_nr" ] && recover_nr=0
14457d1e6f16SPaolo Abeni
14467d1e6f16SPaolo Abeni	if [ $stale_nr -lt $stale_min ] ||
1447d8d08302SMatthieu Baerts	   { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } ||
1448d8d08302SMatthieu Baerts	   [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then
14497d1e6f16SPaolo Abeni		echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \
14507d1e6f16SPaolo Abeni		     " expected stale in range [$stale_min..$stale_max]," \
14517d1e6f16SPaolo Abeni		     " stale-recover delta $stale_delta "
145239aab882SMatthieu Baerts		fail_test
14537d1e6f16SPaolo Abeni		dump_stats=1
14547d1e6f16SPaolo Abeni	else
14557d1e6f16SPaolo Abeni		echo "[ ok ]"
14567d1e6f16SPaolo Abeni	fi
14577d1e6f16SPaolo Abeni
14587d1e6f16SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
14597d1e6f16SPaolo Abeni		echo $ns stats
14607d1e6f16SPaolo Abeni		ip netns exec $ns ip -s link show
14617d1e6f16SPaolo Abeni		ip netns exec $ns nstat -as | grep MPTcp
14627d1e6f16SPaolo Abeni	fi
14637d1e6f16SPaolo Abeni}
14647d1e6f16SPaolo Abeni
1465be613160SGeliang Tangchk_add_nr()
1466be613160SGeliang Tang{
1467be613160SGeliang Tang	local add_nr=$1
1468be613160SGeliang Tang	local echo_nr=$2
14698a127bf6SGeliang Tang	local port_nr=${3:-0}
14708a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
14718a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
14728a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
14738a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
14748a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
1475be613160SGeliang Tang	local count
1476be613160SGeliang Tang	local dump_stats
14776ef84b15SPaolo Abeni	local timeout
14786ef84b15SPaolo Abeni
14794bfadd71SMatthieu Baerts	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
1480be613160SGeliang Tang
14819a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "add"
14824bfadd71SMatthieu Baerts	count=$(ip netns exec $ns2 nstat -as MPTcpExtAddAddr | grep MPTcpExtAddAddr | awk '{print $2}')
1483be613160SGeliang Tang	[ -z "$count" ] && count=0
14846ef84b15SPaolo Abeni
14856ef84b15SPaolo Abeni	# if the test configured a short timeout tolerate greater then expected
14866ef84b15SPaolo Abeni	# add addrs options, due to retransmissions
1487d8d08302SMatthieu Baerts	if [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then
1488be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
148939aab882SMatthieu Baerts		fail_test
1490be613160SGeliang Tang		dump_stats=1
1491be613160SGeliang Tang	else
1492be613160SGeliang Tang		echo -n "[ ok ]"
1493be613160SGeliang Tang	fi
1494be613160SGeliang Tang
1495be613160SGeliang Tang	echo -n " - echo  "
14964bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}')
1497be613160SGeliang Tang	[ -z "$count" ] && count=0
1498be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
1499be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
150039aab882SMatthieu Baerts		fail_test
1501be613160SGeliang Tang		dump_stats=1
1502be613160SGeliang Tang	else
15038a127bf6SGeliang Tang		echo -n "[ ok ]"
15048a127bf6SGeliang Tang	fi
15058a127bf6SGeliang Tang
15068a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
15078a127bf6SGeliang Tang		echo -n " - pt "
15084bfadd71SMatthieu Baerts		count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}')
15098a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15108a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
15118a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
151239aab882SMatthieu Baerts			fail_test
15138a127bf6SGeliang Tang			dump_stats=1
15148a127bf6SGeliang Tang		else
1515be613160SGeliang Tang			echo "[ ok ]"
1516be613160SGeliang Tang		fi
1517be613160SGeliang Tang
15189a0a9367SGeliang Tang		printf "%-${nr_blank}s %s" " " "syn"
15194bfadd71SMatthieu Baerts		count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
15204bfadd71SMatthieu Baerts			awk '{print $2}')
15218a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15228a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
15238a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
15248a127bf6SGeliang Tang				port-number expected $syn_nr"
152539aab882SMatthieu Baerts			fail_test
15268a127bf6SGeliang Tang			dump_stats=1
15278a127bf6SGeliang Tang		else
15288a127bf6SGeliang Tang			echo -n "[ ok ]"
15298a127bf6SGeliang Tang		fi
15308a127bf6SGeliang Tang
15318a127bf6SGeliang Tang		echo -n " - synack"
15324bfadd71SMatthieu Baerts		count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
15334bfadd71SMatthieu Baerts			awk '{print $2}')
15348a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15358a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
15368a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
15378a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
153839aab882SMatthieu Baerts			fail_test
15398a127bf6SGeliang Tang			dump_stats=1
15408a127bf6SGeliang Tang		else
15418a127bf6SGeliang Tang			echo -n "[ ok ]"
15428a127bf6SGeliang Tang		fi
15438a127bf6SGeliang Tang
15448a127bf6SGeliang Tang		echo -n " - ack"
15454bfadd71SMatthieu Baerts		count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
15464bfadd71SMatthieu Baerts			awk '{print $2}')
15478a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15488a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
15498a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
15508a127bf6SGeliang Tang				port-number expected $ack_nr"
155139aab882SMatthieu Baerts			fail_test
15528a127bf6SGeliang Tang			dump_stats=1
15538a127bf6SGeliang Tang		else
15548a127bf6SGeliang Tang			echo "[ ok ]"
15558a127bf6SGeliang Tang		fi
15568a127bf6SGeliang Tang
15579a0a9367SGeliang Tang		printf "%-${nr_blank}s %s" " " "syn"
15584bfadd71SMatthieu Baerts		count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
15594bfadd71SMatthieu Baerts			awk '{print $2}')
15608a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15618a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
15628a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
15638a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
156439aab882SMatthieu Baerts			fail_test
15658a127bf6SGeliang Tang			dump_stats=1
15668a127bf6SGeliang Tang		else
15678a127bf6SGeliang Tang			echo -n "[ ok ]"
15688a127bf6SGeliang Tang		fi
15698a127bf6SGeliang Tang
15708a127bf6SGeliang Tang		echo -n " - ack   "
15714bfadd71SMatthieu Baerts		count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
15724bfadd71SMatthieu Baerts			awk '{print $2}')
15738a127bf6SGeliang Tang		[ -z "$count" ] && count=0
15748a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
15758a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
15768a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
157739aab882SMatthieu Baerts			fail_test
15788a127bf6SGeliang Tang			dump_stats=1
15798a127bf6SGeliang Tang		else
15808a127bf6SGeliang Tang			echo "[ ok ]"
15818a127bf6SGeliang Tang		fi
15828a127bf6SGeliang Tang	else
15838a127bf6SGeliang Tang		echo ""
15848a127bf6SGeliang Tang	fi
15858a127bf6SGeliang Tang
1586327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1587be613160SGeliang Tang}
1588be613160SGeliang Tang
1589dd72b0feSGeliang Tangchk_rm_nr()
1590dd72b0feSGeliang Tang{
1591dd72b0feSGeliang Tang	local rm_addr_nr=$1
1592dd72b0feSGeliang Tang	local rm_subflow_nr=$2
15936fa0174aSPaolo Abeni	local invert
15946fa0174aSPaolo Abeni	local simult
1595dd72b0feSGeliang Tang	local count
1596dd72b0feSGeliang Tang	local dump_stats
15977d9bf018SGeliang Tang	local addr_ns=$ns1
15987d9bf018SGeliang Tang	local subflow_ns=$ns2
15997d9bf018SGeliang Tang	local extra_msg=""
16007028ba8aSGeliang Tang
16016fa0174aSPaolo Abeni	shift 2
16026fa0174aSPaolo Abeni	while [ -n "$1" ]; do
16036fa0174aSPaolo Abeni		[ "$1" = "invert" ] && invert=true
16046fa0174aSPaolo Abeni		[ "$1" = "simult" ] && simult=true
16056fa0174aSPaolo Abeni		shift
16066fa0174aSPaolo Abeni	done
16076fa0174aSPaolo Abeni
16086fa0174aSPaolo Abeni	if [ -z $invert ]; then
16096fa0174aSPaolo Abeni		addr_ns=$ns1
16106fa0174aSPaolo Abeni		subflow_ns=$ns2
16116fa0174aSPaolo Abeni	elif [ $invert = "true" ]; then
16127028ba8aSGeliang Tang		addr_ns=$ns2
16137028ba8aSGeliang Tang		subflow_ns=$ns1
16147d9bf018SGeliang Tang		extra_msg="   invert"
16157028ba8aSGeliang Tang	fi
1616dd72b0feSGeliang Tang
16179a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "rm "
16184bfadd71SMatthieu Baerts	count=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}')
1619dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
1620dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
1621dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
162239aab882SMatthieu Baerts		fail_test
1623dd72b0feSGeliang Tang		dump_stats=1
1624dd72b0feSGeliang Tang	else
1625dd72b0feSGeliang Tang		echo -n "[ ok ]"
1626dd72b0feSGeliang Tang	fi
1627dd72b0feSGeliang Tang
16287d9bf018SGeliang Tang	echo -n " - rmsf  "
16294bfadd71SMatthieu Baerts	count=$(ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}')
1630dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
16316fa0174aSPaolo Abeni	if [ -n "$simult" ]; then
1632d8d08302SMatthieu Baerts		local cnt suffix
1633d8d08302SMatthieu Baerts
1634d8d08302SMatthieu Baerts		cnt=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}')
16356fa0174aSPaolo Abeni
16366fa0174aSPaolo Abeni		# in case of simult flush, the subflow removal count on each side is
16376fa0174aSPaolo Abeni		# unreliable
16386fa0174aSPaolo Abeni		[ -z "$cnt" ] && cnt=0
16396fa0174aSPaolo Abeni		count=$((count + cnt))
16406fa0174aSPaolo Abeni		[ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
16416fa0174aSPaolo Abeni		if [ $count -ge "$rm_subflow_nr" ] && \
16426fa0174aSPaolo Abeni		   [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
16436fa0174aSPaolo Abeni			echo "[ ok ] $suffix"
16446fa0174aSPaolo Abeni		else
16456fa0174aSPaolo Abeni			echo "[fail] got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]"
164639aab882SMatthieu Baerts			fail_test
16476fa0174aSPaolo Abeni			dump_stats=1
16486fa0174aSPaolo Abeni		fi
16496fa0174aSPaolo Abeni		return
16506fa0174aSPaolo Abeni	fi
1651dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
1652dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
165339aab882SMatthieu Baerts		fail_test
1654dd72b0feSGeliang Tang		dump_stats=1
1655dd72b0feSGeliang Tang	else
16567d9bf018SGeliang Tang		echo -n "[ ok ]"
1657dd72b0feSGeliang Tang	fi
1658dd72b0feSGeliang Tang
1659327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
16607d9bf018SGeliang Tang
16617d9bf018SGeliang Tang	echo "$extra_msg"
1662dd72b0feSGeliang Tang}
1663dd72b0feSGeliang Tang
1664718eb44eSGeliang Tangchk_prio_nr()
1665718eb44eSGeliang Tang{
1666718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
1667718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
1668718eb44eSGeliang Tang	local count
1669718eb44eSGeliang Tang	local dump_stats
1670718eb44eSGeliang Tang
16719a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "ptx"
16724bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
1673718eb44eSGeliang Tang	[ -z "$count" ] && count=0
1674718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
1675718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
167639aab882SMatthieu Baerts		fail_test
1677718eb44eSGeliang Tang		dump_stats=1
1678718eb44eSGeliang Tang	else
1679718eb44eSGeliang Tang		echo -n "[ ok ]"
1680718eb44eSGeliang Tang	fi
1681718eb44eSGeliang Tang
1682718eb44eSGeliang Tang	echo -n " - prx   "
16834bfadd71SMatthieu Baerts	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
1684718eb44eSGeliang Tang	[ -z "$count" ] && count=0
1685718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
1686718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
168739aab882SMatthieu Baerts		fail_test
1688718eb44eSGeliang Tang		dump_stats=1
1689718eb44eSGeliang Tang	else
1690718eb44eSGeliang Tang		echo "[ ok ]"
1691718eb44eSGeliang Tang	fi
1692718eb44eSGeliang Tang
1693327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1694718eb44eSGeliang Tang}
1695718eb44eSGeliang Tang
1696e274f715SPaolo Abenichk_subflow_nr()
1697e274f715SPaolo Abeni{
1698e274f715SPaolo Abeni	local need_title="$1"
1699e274f715SPaolo Abeni	local msg="$2"
1700e274f715SPaolo Abeni	local subflow_nr=$3
1701e274f715SPaolo Abeni	local cnt1
1702e274f715SPaolo Abeni	local cnt2
1703a635a8c3SPaolo Abeni	local dump_stats
1704e274f715SPaolo Abeni
1705e274f715SPaolo Abeni	if [ -n "${need_title}" ]; then
1706e274f715SPaolo Abeni		printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}"
1707e274f715SPaolo Abeni	else
1708e274f715SPaolo Abeni		printf "%-${nr_blank}s %s" " " "${msg}"
1709e274f715SPaolo Abeni	fi
1710e274f715SPaolo Abeni
1711e274f715SPaolo Abeni	cnt1=$(ss -N $ns1 -tOni | grep -c token)
1712e274f715SPaolo Abeni	cnt2=$(ss -N $ns2 -tOni | grep -c token)
1713e274f715SPaolo Abeni	if [ "$cnt1" != "$subflow_nr" -o "$cnt2" != "$subflow_nr" ]; then
1714e274f715SPaolo Abeni		echo "[fail] got $cnt1:$cnt2 subflows expected $subflow_nr"
1715e274f715SPaolo Abeni		fail_test
1716e274f715SPaolo Abeni		dump_stats=1
1717e274f715SPaolo Abeni	else
1718e274f715SPaolo Abeni		echo "[ ok ]"
1719e274f715SPaolo Abeni	fi
1720e274f715SPaolo Abeni
1721a635a8c3SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
1722a635a8c3SPaolo Abeni		ss -N $ns1 -tOni
1723a635a8c3SPaolo Abeni		ss -N $ns1 -tOni | grep token
1724a635a8c3SPaolo Abeni		ip -n $ns1 mptcp endpoint
1725a635a8c3SPaolo Abeni		dump_stats
1726a635a8c3SPaolo Abeni	fi
1727e274f715SPaolo Abeni}
1728e274f715SPaolo Abeni
17297d1e6f16SPaolo Abenichk_link_usage()
17307d1e6f16SPaolo Abeni{
17317d1e6f16SPaolo Abeni	local ns=$1
17327d1e6f16SPaolo Abeni	local link=$2
17337d1e6f16SPaolo Abeni	local out=$3
17347d1e6f16SPaolo Abeni	local expected_rate=$4
17354bfadd71SMatthieu Baerts
17364bfadd71SMatthieu Baerts	local tx_link tx_total
17374bfadd71SMatthieu Baerts	tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes)
1738d8d08302SMatthieu Baerts	tx_total=$(stat --format=%s $out)
1739d8d08302SMatthieu Baerts	local tx_rate=$((tx_link * 100 / tx_total))
17407d1e6f16SPaolo Abeni	local tolerance=5
17417d1e6f16SPaolo Abeni
17429a0a9367SGeliang Tang	printf "%-${nr_blank}s %-18s" " " "link usage"
1743d8d08302SMatthieu Baerts	if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \
1744d8d08302SMatthieu Baerts	   [ $tx_rate -gt $((expected_rate + tolerance)) ]; then
17457d1e6f16SPaolo Abeni		echo "[fail] got $tx_rate% usage, expected $expected_rate%"
174639aab882SMatthieu Baerts		fail_test
17477d1e6f16SPaolo Abeni	else
17487d1e6f16SPaolo Abeni		echo "[ ok ]"
17497d1e6f16SPaolo Abeni	fi
17507d1e6f16SPaolo Abeni}
17517d1e6f16SPaolo Abeni
1752f98c2bcaSMat Martineauwait_attempt_fail()
175346e967d1SPaolo Abeni{
175446e967d1SPaolo Abeni	local timeout_ms=$((timeout_poll * 1000))
175546e967d1SPaolo Abeni	local time=0
175646e967d1SPaolo Abeni	local ns=$1
175746e967d1SPaolo Abeni
175846e967d1SPaolo Abeni	while [ $time -lt $timeout_ms ]; do
17591e777bd8SMatthieu Baerts		local cnt
17601e777bd8SMatthieu Baerts
17611e777bd8SMatthieu Baerts		cnt=$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFails | awk '{print $2}')
176246e967d1SPaolo Abeni
176346e967d1SPaolo Abeni		[ "$cnt" = 1 ] && return 1
176446e967d1SPaolo Abeni		time=$((time + 100))
176546e967d1SPaolo Abeni		sleep 0.1
176646e967d1SPaolo Abeni	done
176746e967d1SPaolo Abeni	return 1
176846e967d1SPaolo Abeni}
176946e967d1SPaolo Abeni
17705ac1d2d6SMat Martineauset_userspace_pm()
17715ac1d2d6SMat Martineau{
17725ac1d2d6SMat Martineau	local ns=$1
17735ac1d2d6SMat Martineau
17745ac1d2d6SMat Martineau	ip netns exec $ns sysctl -q net.mptcp.pm_type=1
17755ac1d2d6SMat Martineau}
17765ac1d2d6SMat Martineau
17771002b89fSGeliang Tangsubflows_tests()
17781002b89fSGeliang Tang{
1779c7d49c03SMatthieu Baerts	if reset "no JOIN"; then
1780b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1781c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
1782ae7bd9ccSMatthieu Baerts	fi
1783b08fbf24SPaolo Abeni
17841002b89fSGeliang Tang	# subflow limited by client
1785c7d49c03SMatthieu Baerts	if reset "single subflow, limited by client"; then
178634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 0
178734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 0
178834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1789b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1790c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
1791ae7bd9ccSMatthieu Baerts	fi
1792b08fbf24SPaolo Abeni
17931002b89fSGeliang Tang	# subflow limited by server
1794c7d49c03SMatthieu Baerts	if reset "single subflow, limited by server"; then
179534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 0
179634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
179734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1798b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1799c7d49c03SMatthieu Baerts		chk_join_nr 1 1 0
1800ae7bd9ccSMatthieu Baerts	fi
1801b08fbf24SPaolo Abeni
1802b08fbf24SPaolo Abeni	# subflow
1803c7d49c03SMatthieu Baerts	if reset "single subflow"; then
180434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
180534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
180634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1807b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1808c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1809ae7bd9ccSMatthieu Baerts	fi
1810b08fbf24SPaolo Abeni
1811b08fbf24SPaolo Abeni	# multiple subflows
1812c7d49c03SMatthieu Baerts	if reset "multiple subflows"; then
181334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
181434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
181534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
181634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1817b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1818c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
1819ae7bd9ccSMatthieu Baerts	fi
1820b08fbf24SPaolo Abeni
182172bcbc46SPaolo Abeni	# multiple subflows limited by server
1822c7d49c03SMatthieu Baerts	if reset "multiple subflows, limited by server"; then
182334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
182434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
182534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
182634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1827b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1828c7d49c03SMatthieu Baerts		chk_join_nr 2 2 1
1829ae7bd9ccSMatthieu Baerts	fi
1830c3eaa5f6SGeliang Tang
1831c3eaa5f6SGeliang Tang	# single subflow, dev
1832c7d49c03SMatthieu Baerts	if reset "single subflow, dev"; then
183334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
183434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
183534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3
1836c3eaa5f6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
1837c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1838ae7bd9ccSMatthieu Baerts	fi
18391002b89fSGeliang Tang}
1840b08fbf24SPaolo Abeni
184146e967d1SPaolo Abenisubflows_error_tests()
184246e967d1SPaolo Abeni{
184346e967d1SPaolo Abeni	# If a single subflow is configured, and matches the MPC src
184446e967d1SPaolo Abeni	# address, no additional subflow should be created
1845c7d49c03SMatthieu Baerts	if reset "no MPC reuse with single endpoint"; then
184634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
184734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
184834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
184946e967d1SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1850c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
1851ae7bd9ccSMatthieu Baerts	fi
185246e967d1SPaolo Abeni
185346e967d1SPaolo Abeni	# multiple subflows, with subflow creation error
1854c7d49c03SMatthieu Baerts	if reset "multi subflows, with failing subflow"; then
185534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
185634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
185734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
185834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
18593469d72fSMatthieu Baerts		filter_tcp_from $ns1 10.0.3.2 REJECT
186046e967d1SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1861c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1862ae7bd9ccSMatthieu Baerts	fi
186346e967d1SPaolo Abeni
186446e967d1SPaolo Abeni	# multiple subflows, with subflow timeout on MPJ
1865c7d49c03SMatthieu Baerts	if reset "multi subflows, with subflow timeout"; then
186634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
186734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
186834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
186934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
18703469d72fSMatthieu Baerts		filter_tcp_from $ns1 10.0.3.2 DROP
187146e967d1SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1872c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1873ae7bd9ccSMatthieu Baerts	fi
187446e967d1SPaolo Abeni
187546e967d1SPaolo Abeni	# multiple subflows, check that the endpoint corresponding to
187646e967d1SPaolo Abeni	# closed subflow (due to reset) is not reused if additional
187746e967d1SPaolo Abeni	# subflows are added later
1878c7d49c03SMatthieu Baerts	if reset "multi subflows, fair usage on close"; then
187934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
188034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
188134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
18823469d72fSMatthieu Baerts		filter_tcp_from $ns1 10.0.3.2 REJECT
188346e967d1SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow &
188446e967d1SPaolo Abeni
188546e967d1SPaolo Abeni		# mpj subflow will be in TW after the reset
1886f98c2bcaSMat Martineau		wait_attempt_fail $ns2
188734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
188846e967d1SPaolo Abeni		wait
188946e967d1SPaolo Abeni
189046e967d1SPaolo Abeni		# additional subflow could be created only if the PM select
189146e967d1SPaolo Abeni		# the later endpoint, skipping the already used one
1892c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1893ae7bd9ccSMatthieu Baerts	fi
189446e967d1SPaolo Abeni}
189546e967d1SPaolo Abeni
18961002b89fSGeliang Tangsignal_address_tests()
18971002b89fSGeliang Tang{
1898b08fbf24SPaolo Abeni	# add_address, unused
1899c7d49c03SMatthieu Baerts	if reset "unused signal address"; then
190034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
1901b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1902c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
1903be613160SGeliang Tang		chk_add_nr 1 1
1904ae7bd9ccSMatthieu Baerts	fi
1905b08fbf24SPaolo Abeni
1906b08fbf24SPaolo Abeni	# accept and use add_addr
1907c7d49c03SMatthieu Baerts	if reset "signal address"; then
190834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
190934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
191034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
1911b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1912c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1913be613160SGeliang Tang		chk_add_nr 1 1
1914ae7bd9ccSMatthieu Baerts	fi
1915b08fbf24SPaolo Abeni
1916b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
1917b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
1918b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
1919b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
1920c7d49c03SMatthieu Baerts	if reset "subflow and signal"; then
192134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
192234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
192334aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
192434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1925b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1926c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
1927be613160SGeliang Tang		chk_add_nr 1 1
1928ae7bd9ccSMatthieu Baerts	fi
1929b08fbf24SPaolo Abeni
1930b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
1931c7d49c03SMatthieu Baerts	if reset "multiple subflows and signal"; then
193234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
193334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
193434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
193534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
193634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
1937b08fbf24SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1
1938c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
1939be613160SGeliang Tang		chk_add_nr 1 1
1940ae7bd9ccSMatthieu Baerts	fi
1941ef360019SGeliang Tang
1942ef360019SGeliang Tang	# signal addresses
1943c7d49c03SMatthieu Baerts	if reset "signal addresses"; then
194434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
194534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
194634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
194734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
194834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
1949ef360019SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
1950c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
1951ef360019SGeliang Tang		chk_add_nr 3 3
1952ae7bd9ccSMatthieu Baerts	fi
1953ef360019SGeliang Tang
1954ef360019SGeliang Tang	# signal invalid addresses
1955c7d49c03SMatthieu Baerts	if reset "signal invalid addresses"; then
195634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
195734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
195834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
195934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
196034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
1961ef360019SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
1962c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
1963ef360019SGeliang Tang		chk_add_nr 3 3
1964ae7bd9ccSMatthieu Baerts	fi
196533c563adSYonglong Li
196633c563adSYonglong Li	# signal addresses race test
1967c7d49c03SMatthieu Baerts	if reset "signal addresses race test"; then
196834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 4 4
196934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 4 4
197034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.1.1 flags signal
197134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
197234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
197334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
197434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.1.2 flags signal
197534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
197634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags signal
197734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags signal
19786ef84b15SPaolo Abeni
19796ef84b15SPaolo Abeni		# the peer could possibly miss some addr notification, allow retransmission
19806ef84b15SPaolo Abeni		ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
19816ef84b15SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1982c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
198386e39e04SPaolo Abeni
198486e39e04SPaolo Abeni		# the server will not signal the address terminating
198586e39e04SPaolo Abeni		# the MPC subflow
198686e39e04SPaolo Abeni		chk_add_nr 3 3
1987ae7bd9ccSMatthieu Baerts	fi
19881002b89fSGeliang Tang}
1989b08fbf24SPaolo Abeni
19901002b89fSGeliang Tanglink_failure_tests()
19911002b89fSGeliang Tang{
19928b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
1993c7d49c03SMatthieu Baerts	if reset "multiple flows, signal, link failure"; then
19947d1e6f16SPaolo Abeni		# without any b/w limit each veth could spool the packets and get
19957d1e6f16SPaolo Abeni		# them acked at xmit time, so that the corresponding subflow will
19967d1e6f16SPaolo Abeni		# have almost always no outstanding pkts, the scheduler will pick
19977d1e6f16SPaolo Abeni		# always the first subflow and we will have hard time testing
19987d1e6f16SPaolo Abeni		# active backup and link switch-over.
19997d1e6f16SPaolo Abeni		# Let's set some arbitrary (low) virtual link limits.
20007d1e6f16SPaolo Abeni		init_shapers
200134aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
200234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
200334aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
200434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
200534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
20068b819a84SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1 1
2007c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
20088b819a84SFlorian Westphal		chk_add_nr 1 1
20097d1e6f16SPaolo Abeni		chk_stale_nr $ns2 1 5 1
2010ae7bd9ccSMatthieu Baerts	fi
20117d1e6f16SPaolo Abeni
20127d1e6f16SPaolo Abeni	# accept and use add_addr with additional subflows and link loss
20137d1e6f16SPaolo Abeni	# for bidirectional transfer
2014c7d49c03SMatthieu Baerts	if reset "multi flows, signal, bidi, link fail"; then
20157d1e6f16SPaolo Abeni		init_shapers
201634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
201734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
201834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
201934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
202034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
20217d1e6f16SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 2
2022c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
20237d1e6f16SPaolo Abeni		chk_add_nr 1 1
20247d1e6f16SPaolo Abeni		chk_stale_nr $ns2 1 -1 1
2025ae7bd9ccSMatthieu Baerts	fi
20267d1e6f16SPaolo Abeni
20277d1e6f16SPaolo Abeni	# 2 subflows plus 1 backup subflow with a lossy link, backup
20287d1e6f16SPaolo Abeni	# will never be used
2029c7d49c03SMatthieu Baerts	if reset "backup subflow unused, link failure"; then
20307d1e6f16SPaolo Abeni		init_shapers
203134aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
203234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
203334aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
2034e59300ceSMatthieu Baerts		FAILING_LINKS="1"
203534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
20367d1e6f16SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 1
2037c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
20387d1e6f16SPaolo Abeni		chk_add_nr 1 1
20397d1e6f16SPaolo Abeni		chk_link_usage $ns2 ns2eth3 $cinsent 0
2040ae7bd9ccSMatthieu Baerts	fi
20417d1e6f16SPaolo Abeni
20427d1e6f16SPaolo Abeni	# 2 lossy links after half transfer, backup will get half of
20437d1e6f16SPaolo Abeni	# the traffic
2044c7d49c03SMatthieu Baerts	if reset "backup flow used, multi links fail"; then
20457d1e6f16SPaolo Abeni		init_shapers
204634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
204734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
204834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
204934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
2050e59300ceSMatthieu Baerts		FAILING_LINKS="1 2"
20517d1e6f16SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 1
2052c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
20537d1e6f16SPaolo Abeni		chk_add_nr 1 1
20547d1e6f16SPaolo Abeni		chk_stale_nr $ns2 2 4 2
20557d1e6f16SPaolo Abeni		chk_link_usage $ns2 ns2eth3 $cinsent 50
2056ae7bd9ccSMatthieu Baerts	fi
20577d1e6f16SPaolo Abeni
20587d1e6f16SPaolo Abeni	# use a backup subflow with the first subflow on a lossy link
20597d1e6f16SPaolo Abeni	# for bidirectional transfer
2060c7d49c03SMatthieu Baerts	if reset "backup flow used, bidi, link failure"; then
20617d1e6f16SPaolo Abeni		init_shapers
206234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
206334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
206434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
206534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
2066e59300ceSMatthieu Baerts		FAILING_LINKS="1 2"
20677d1e6f16SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 2
2068c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
20697d1e6f16SPaolo Abeni		chk_add_nr 1 1
20707d1e6f16SPaolo Abeni		chk_stale_nr $ns2 1 -1 2
20717d1e6f16SPaolo Abeni		chk_link_usage $ns2 ns2eth3 $cinsent 50
2072ae7bd9ccSMatthieu Baerts	fi
20731002b89fSGeliang Tang}
20748b819a84SFlorian Westphal
20751002b89fSGeliang Tangadd_addr_timeout_tests()
20761002b89fSGeliang Tang{
20778d014eaaSGeliang Tang	# add_addr timeout
2078c7d49c03SMatthieu Baerts	if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then
207934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
208034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
208134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
20828b819a84SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
2083c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
20848d014eaaSGeliang Tang		chk_add_nr 4 0
2085ae7bd9ccSMatthieu Baerts	fi
20868d014eaaSGeliang Tang
20871002b89fSGeliang Tang	# add_addr timeout IPv6
2088c7d49c03SMatthieu Baerts	if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then
208934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
209034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
209134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
20921002b89fSGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
2093c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
20941002b89fSGeliang Tang		chk_add_nr 4 0
2095ae7bd9ccSMatthieu Baerts	fi
20968da6229bSGeliang Tang
20978da6229bSGeliang Tang	# signal addresses timeout
2098c7d49c03SMatthieu Baerts	if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then
209934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
210034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
210134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
210234aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
2103cbfafac4SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10
2104c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
21058da6229bSGeliang Tang		chk_add_nr 8 0
2106ae7bd9ccSMatthieu Baerts	fi
21078da6229bSGeliang Tang
21088da6229bSGeliang Tang	# signal invalid addresses timeout
2109c7d49c03SMatthieu Baerts	if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then
211034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
211134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
211234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
211334aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
2114cbfafac4SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10
2115c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
21168da6229bSGeliang Tang		chk_add_nr 8 0
2117ae7bd9ccSMatthieu Baerts	fi
21181002b89fSGeliang Tang}
21191002b89fSGeliang Tang
21201002b89fSGeliang Tangremove_tests()
21211002b89fSGeliang Tang{
2122dd72b0feSGeliang Tang	# single subflow, remove
2123c7d49c03SMatthieu Baerts	if reset "remove single subflow"; then
212434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
212534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
212634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
21272e8cbf45SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
2128c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2129dd72b0feSGeliang Tang		chk_rm_nr 1 1
2130ae7bd9ccSMatthieu Baerts	fi
2131dd72b0feSGeliang Tang
2132dd72b0feSGeliang Tang	# multiple subflows, remove
2133c7d49c03SMatthieu Baerts	if reset "remove multiple subflows"; then
213434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
213534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
213634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
213734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
21382e8cbf45SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
2139c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2140dd72b0feSGeliang Tang		chk_rm_nr 2 2
2141ae7bd9ccSMatthieu Baerts	fi
2142dd72b0feSGeliang Tang
2143dd72b0feSGeliang Tang	# single address, remove
2144c7d49c03SMatthieu Baerts	if reset "remove single address"; then
214534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
214634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
214734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
21482e8cbf45SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
2149c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2150dd72b0feSGeliang Tang		chk_add_nr 1 1
21517028ba8aSGeliang Tang		chk_rm_nr 1 1 invert
2152ae7bd9ccSMatthieu Baerts	fi
2153dd72b0feSGeliang Tang
2154dd72b0feSGeliang Tang	# subflow and signal, remove
2155c7d49c03SMatthieu Baerts	if reset "remove subflow and signal"; then
215634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
215734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
215834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
215934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
21602e8cbf45SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
2161c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2162dd72b0feSGeliang Tang		chk_add_nr 1 1
2163dd72b0feSGeliang Tang		chk_rm_nr 1 1
2164ae7bd9ccSMatthieu Baerts	fi
2165dd72b0feSGeliang Tang
2166dd72b0feSGeliang Tang	# subflows and signal, remove
2167c7d49c03SMatthieu Baerts	if reset "remove subflows and signal"; then
216834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
216934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
217034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
217134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
217234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
217322b29557SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 speed_10
2174c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
2175dd72b0feSGeliang Tang		chk_add_nr 1 1
2176dd72b0feSGeliang Tang		chk_rm_nr 2 2
2177ae7bd9ccSMatthieu Baerts	fi
2178dd72b0feSGeliang Tang
2179ef360019SGeliang Tang	# addresses remove
2180c7d49c03SMatthieu Baerts	if reset "remove addresses"; then
218134aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
218234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
218334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
218434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
218534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
218622b29557SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10
2187c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
2188ef360019SGeliang Tang		chk_add_nr 3 3
2189ef360019SGeliang Tang		chk_rm_nr 3 3 invert
2190ae7bd9ccSMatthieu Baerts	fi
2191ef360019SGeliang Tang
2192ef360019SGeliang Tang	# invalid addresses remove
2193c7d49c03SMatthieu Baerts	if reset "remove invalid addresses"; then
219434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
219534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
219634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
219734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
219834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
219922b29557SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10
2200c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2201ef360019SGeliang Tang		chk_add_nr 3 3
2202ef360019SGeliang Tang		chk_rm_nr 3 1 invert
2203ae7bd9ccSMatthieu Baerts	fi
2204ef360019SGeliang Tang
22056fe4ccdcSGeliang Tang	# subflows and signal, flush
2206c7d49c03SMatthieu Baerts	if reset "flush subflows and signal"; then
220734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
220834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
220934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
221034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
221134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
22122e8cbf45SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
2213c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
22146fe4ccdcSGeliang Tang		chk_add_nr 1 1
22156fa0174aSPaolo Abeni		chk_rm_nr 1 3 invert simult
2216ae7bd9ccSMatthieu Baerts	fi
2217d2c4333aSGeliang Tang
2218d2c4333aSGeliang Tang	# subflows flush
2219c7d49c03SMatthieu Baerts	if reset "flush subflows"; then
222034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
222134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
222234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150
222334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
222434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2225d2c4333aSGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
2226c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
22276fa0174aSPaolo Abeni		chk_rm_nr 0 3 simult
2228ae7bd9ccSMatthieu Baerts	fi
2229d2c4333aSGeliang Tang
2230d2c4333aSGeliang Tang	# addresses flush
2231c7d49c03SMatthieu Baerts	if reset "flush addresses"; then
223234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
223334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
223434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
223534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
223634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
2237d2c4333aSGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
2238c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
2239d2c4333aSGeliang Tang		chk_add_nr 3 3
22406fa0174aSPaolo Abeni		chk_rm_nr 3 3 invert simult
2241ae7bd9ccSMatthieu Baerts	fi
2242ef360019SGeliang Tang
2243ef360019SGeliang Tang	# invalid addresses flush
2244c7d49c03SMatthieu Baerts	if reset "flush invalid addresses"; then
224534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 3 3
224634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
224734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
224834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
224934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 3 3
2250ef360019SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
2251c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2252ef360019SGeliang Tang		chk_add_nr 3 3
2253ef360019SGeliang Tang		chk_rm_nr 3 1 invert
2254ae7bd9ccSMatthieu Baerts	fi
22555e287fe7SGeliang Tang
22565e287fe7SGeliang Tang	# remove id 0 subflow
2257c7d49c03SMatthieu Baerts	if reset "remove id 0 subflow"; then
225834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
225934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
226034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
22615e287fe7SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
2262c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
22635e287fe7SGeliang Tang		chk_rm_nr 1 1
2264ae7bd9ccSMatthieu Baerts	fi
22655e287fe7SGeliang Tang
22665e287fe7SGeliang Tang	# remove id 0 address
2267c7d49c03SMatthieu Baerts	if reset "remove id 0 address"; then
226834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
226934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
227034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
22715e287fe7SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
2272c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
22735e287fe7SGeliang Tang		chk_add_nr 1 1
22745e287fe7SGeliang Tang		chk_rm_nr 1 1 invert
2275ae7bd9ccSMatthieu Baerts	fi
22761002b89fSGeliang Tang}
22776fe4ccdcSGeliang Tang
22781002b89fSGeliang Tangadd_tests()
22791002b89fSGeliang Tang{
22806208fd82SGeliang Tang	# add single subflow
2281c7d49c03SMatthieu Baerts	if reset "add single subflow"; then
228234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
228334aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
22846208fd82SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
2285c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2286ae7bd9ccSMatthieu Baerts	fi
22876208fd82SGeliang Tang
22886208fd82SGeliang Tang	# add signal address
2289c7d49c03SMatthieu Baerts	if reset "add signal address"; then
229034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
229134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
22926208fd82SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
2293c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
22946208fd82SGeliang Tang		chk_add_nr 1 1
2295ae7bd9ccSMatthieu Baerts	fi
22966208fd82SGeliang Tang
22976208fd82SGeliang Tang	# add multiple subflows
2298c7d49c03SMatthieu Baerts	if reset "add multiple subflows"; then
229934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
230034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
23016208fd82SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
2302c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2303ae7bd9ccSMatthieu Baerts	fi
23046208fd82SGeliang Tang
23056208fd82SGeliang Tang	# add multiple subflows IPv6
2306c7d49c03SMatthieu Baerts	if reset "add multiple subflows IPv6"; then
230734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
230834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
23096208fd82SGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
2310c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2311ae7bd9ccSMatthieu Baerts	fi
23126208fd82SGeliang Tang
23136208fd82SGeliang Tang	# add multiple addresses IPv6
2314c7d49c03SMatthieu Baerts	if reset "add multiple addresses IPv6"; then
231534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
231634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
23176208fd82SGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
2318c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
23196208fd82SGeliang Tang		chk_add_nr 2 2
2320ae7bd9ccSMatthieu Baerts	fi
23211002b89fSGeliang Tang}
23226208fd82SGeliang Tang
23231002b89fSGeliang Tangipv6_tests()
23241002b89fSGeliang Tang{
2325523514edSGeliang Tang	# subflow IPv6
2326c7d49c03SMatthieu Baerts	if reset "single subflow IPv6"; then
232734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
232834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
232934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
2330523514edSGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
2331c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2332ae7bd9ccSMatthieu Baerts	fi
2333523514edSGeliang Tang
2334523514edSGeliang Tang	# add_address, unused IPv6
2335c7d49c03SMatthieu Baerts	if reset "unused signal address IPv6"; then
233634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
2337523514edSGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
2338c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2339523514edSGeliang Tang		chk_add_nr 1 1
2340ae7bd9ccSMatthieu Baerts	fi
2341523514edSGeliang Tang
2342523514edSGeliang Tang	# signal address IPv6
2343c7d49c03SMatthieu Baerts	if reset "single address IPv6"; then
234434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
234534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
234634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
2347523514edSGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
2348c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2349523514edSGeliang Tang		chk_add_nr 1 1
2350ae7bd9ccSMatthieu Baerts	fi
2351523514edSGeliang Tang
2352523514edSGeliang Tang	# single address IPv6, remove
2353c7d49c03SMatthieu Baerts	if reset "remove single address IPv6"; then
235434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
235534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
235634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
23572e8cbf45SGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
2358c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2359523514edSGeliang Tang		chk_add_nr 1 1
23607028ba8aSGeliang Tang		chk_rm_nr 1 1 invert
2361ae7bd9ccSMatthieu Baerts	fi
2362523514edSGeliang Tang
2363523514edSGeliang Tang	# subflow and signal IPv6, remove
2364c7d49c03SMatthieu Baerts	if reset "remove subflow and signal IPv6"; then
236534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
236634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
236734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
236834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
23692e8cbf45SGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
2370c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2371523514edSGeliang Tang		chk_add_nr 1 1
2372523514edSGeliang Tang		chk_rm_nr 1 1
2373ae7bd9ccSMatthieu Baerts	fi
23741002b89fSGeliang Tang}
2375523514edSGeliang Tang
23761002b89fSGeliang Tangv4mapped_tests()
23771002b89fSGeliang Tang{
2378a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
2379c7d49c03SMatthieu Baerts	if reset "single subflow IPv4-mapped"; then
238034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
238134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
238234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
2383a6094788SGeliang Tang		run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2384c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2385ae7bd9ccSMatthieu Baerts	fi
2386a6094788SGeliang Tang
2387a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
2388c7d49c03SMatthieu Baerts	if reset "signal address IPv4-mapped"; then
238934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
239034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
239134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
2392a6094788SGeliang Tang		run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2393c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2394a6094788SGeliang Tang		chk_add_nr 1 1
2395ae7bd9ccSMatthieu Baerts	fi
2396a6094788SGeliang Tang
2397a6094788SGeliang Tang	# subflow v4-map-v6
2398c7d49c03SMatthieu Baerts	if reset "single subflow v4-map-v6"; then
239934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
240034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
240134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2402a6094788SGeliang Tang		run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2403c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2404ae7bd9ccSMatthieu Baerts	fi
2405a6094788SGeliang Tang
2406a6094788SGeliang Tang	# signal address v4-map-v6
2407c7d49c03SMatthieu Baerts	if reset "signal address v4-map-v6"; then
240834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
240934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
241034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2411a6094788SGeliang Tang		run_tests $ns1 $ns2 "::ffff:10.0.1.1"
2412c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2413a6094788SGeliang Tang		chk_add_nr 1 1
2414ae7bd9ccSMatthieu Baerts	fi
2415a6094788SGeliang Tang
2416a6094788SGeliang Tang	# subflow v6-map-v4
2417c7d49c03SMatthieu Baerts	if reset "single subflow v6-map-v4"; then
241834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
241934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
242034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
2421a6094788SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2422c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2423ae7bd9ccSMatthieu Baerts	fi
2424a6094788SGeliang Tang
2425a6094788SGeliang Tang	# signal address v6-map-v4
2426c7d49c03SMatthieu Baerts	if reset "signal address v6-map-v4"; then
242734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
242834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
242934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
2430a6094788SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2431c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2432a6094788SGeliang Tang		chk_add_nr 1 1
2433ae7bd9ccSMatthieu Baerts	fi
2434a6094788SGeliang Tang
2435a6094788SGeliang Tang	# no subflow IPv6 to v4 address
2436c7d49c03SMatthieu Baerts	if reset "no JOIN with diff families v4-v6"; then
243734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
243834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
243934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow
2440a6094788SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2441c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2442ae7bd9ccSMatthieu Baerts	fi
2443a6094788SGeliang Tang
2444a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
2445c7d49c03SMatthieu Baerts	if reset "no JOIN with diff families v4-v6-2"; then
244634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
244734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
244834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow
2449a6094788SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2450c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2451ae7bd9ccSMatthieu Baerts	fi
2452a6094788SGeliang Tang
2453a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
2454c7d49c03SMatthieu Baerts	if reset "no JOIN with diff families v6-v4"; then
245534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
245634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
245734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2458a6094788SGeliang Tang		run_tests $ns1 $ns2 dead:beef:1::1
2459c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2460ae7bd9ccSMatthieu Baerts	fi
24611002b89fSGeliang Tang}
2462a6094788SGeliang Tang
24631002b89fSGeliang Tangbackup_tests()
24641002b89fSGeliang Tang{
2465718eb44eSGeliang Tang	# single subflow, backup
2466c7d49c03SMatthieu Baerts	if reset "single subflow, backup"; then
246734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
246834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
246934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup
2470718eb44eSGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
2471c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2472718eb44eSGeliang Tang		chk_prio_nr 0 1
2473ae7bd9ccSMatthieu Baerts	fi
2474718eb44eSGeliang Tang
2475718eb44eSGeliang Tang	# single address, backup
2476c7d49c03SMatthieu Baerts	if reset "single address, backup"; then
247734aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
247834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
247934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
2480718eb44eSGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
2481c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2482718eb44eSGeliang Tang		chk_add_nr 1 1
2483d045b9ebSPaolo Abeni		chk_prio_nr 1 1
2484ae7bd9ccSMatthieu Baerts	fi
248533397b83SGeliang Tang
248633397b83SGeliang Tang	# single address with port, backup
2487c7d49c03SMatthieu Baerts	if reset "single address with port, backup"; then
248834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
248934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
249034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
249133397b83SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
2492c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
249333397b83SGeliang Tang		chk_add_nr 1 1
2494d045b9ebSPaolo Abeni		chk_prio_nr 1 1
2495ae7bd9ccSMatthieu Baerts	fi
2496914f6a59SPaolo Abeni
2497914f6a59SPaolo Abeni	if reset "mpc backup"; then
2498914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup
2499914f6a59SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
2500914f6a59SPaolo Abeni		chk_join_nr 0 0 0
2501914f6a59SPaolo Abeni		chk_prio_nr 0 1
2502914f6a59SPaolo Abeni	fi
2503914f6a59SPaolo Abeni
2504914f6a59SPaolo Abeni	if reset "mpc backup both sides"; then
2505914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup
2506914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup
2507914f6a59SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
2508914f6a59SPaolo Abeni		chk_join_nr 0 0 0
2509914f6a59SPaolo Abeni		chk_prio_nr 1 1
2510914f6a59SPaolo Abeni	fi
2511914f6a59SPaolo Abeni
2512914f6a59SPaolo Abeni	if reset "mpc switch to backup"; then
2513914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
2514914f6a59SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
2515914f6a59SPaolo Abeni		chk_join_nr 0 0 0
2516914f6a59SPaolo Abeni		chk_prio_nr 0 1
2517914f6a59SPaolo Abeni	fi
2518914f6a59SPaolo Abeni
2519914f6a59SPaolo Abeni	if reset "mpc switch to backup both sides"; then
2520914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow
2521914f6a59SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
2522914f6a59SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
2523914f6a59SPaolo Abeni		chk_join_nr 0 0 0
2524914f6a59SPaolo Abeni		chk_prio_nr 1 1
2525914f6a59SPaolo Abeni	fi
25261002b89fSGeliang Tang}
2527718eb44eSGeliang Tang
2528178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
2529178d0232SGeliang TangLISTENER_CLOSED=16  #MPTCP_EVENT_LISTENER_CLOSED
2530178d0232SGeliang Tang
2531178d0232SGeliang TangAF_INET=2
2532178d0232SGeliang TangAF_INET6=10
2533178d0232SGeliang Tang
2534178d0232SGeliang Tangverify_listener_events()
2535178d0232SGeliang Tang{
2536178d0232SGeliang Tang	local evt=$1
2537178d0232SGeliang Tang	local e_type=$2
2538178d0232SGeliang Tang	local e_family=$3
2539178d0232SGeliang Tang	local e_saddr=$4
2540178d0232SGeliang Tang	local e_sport=$5
2541178d0232SGeliang Tang	local type
2542178d0232SGeliang Tang	local family
2543178d0232SGeliang Tang	local saddr
2544178d0232SGeliang Tang	local sport
2545178d0232SGeliang Tang
2546178d0232SGeliang Tang	if [ $e_type = $LISTENER_CREATED ]; then
2547178d0232SGeliang Tang		stdbuf -o0 -e0 printf "\t\t\t\t\t CREATE_LISTENER %s:%s"\
2548178d0232SGeliang Tang			$e_saddr $e_sport
2549178d0232SGeliang Tang	elif [ $e_type = $LISTENER_CLOSED ]; then
2550178d0232SGeliang Tang		stdbuf -o0 -e0 printf "\t\t\t\t\t CLOSE_LISTENER %s:%s "\
2551178d0232SGeliang Tang			$e_saddr $e_sport
2552178d0232SGeliang Tang	fi
2553178d0232SGeliang Tang
2554178d0232SGeliang Tang	type=$(grep "type:$e_type," $evt |
2555178d0232SGeliang Tang	       sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
2556178d0232SGeliang Tang	family=$(grep "type:$e_type," $evt |
2557178d0232SGeliang Tang		 sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
2558178d0232SGeliang Tang	sport=$(grep "type:$e_type," $evt |
2559178d0232SGeliang Tang		sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
2560178d0232SGeliang Tang	if [ $family ] && [ $family = $AF_INET6 ]; then
2561178d0232SGeliang Tang		saddr=$(grep "type:$e_type," $evt |
2562178d0232SGeliang Tang			sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
2563178d0232SGeliang Tang	else
2564178d0232SGeliang Tang		saddr=$(grep "type:$e_type," $evt |
2565178d0232SGeliang Tang			sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
2566178d0232SGeliang Tang	fi
2567178d0232SGeliang Tang
2568178d0232SGeliang Tang	if [ $type ] && [ $type = $e_type ] &&
2569178d0232SGeliang Tang	   [ $family ] && [ $family = $e_family ] &&
2570178d0232SGeliang Tang	   [ $saddr ] && [ $saddr = $e_saddr ] &&
2571178d0232SGeliang Tang	   [ $sport ] && [ $sport = $e_sport ]; then
2572178d0232SGeliang Tang		stdbuf -o0 -e0 printf "[ ok ]\n"
2573178d0232SGeliang Tang		return 0
2574178d0232SGeliang Tang	fi
2575178d0232SGeliang Tang	fail_test
2576178d0232SGeliang Tang	stdbuf -o0 -e0 printf "[fail]\n"
2577178d0232SGeliang Tang}
2578178d0232SGeliang Tang
25791002b89fSGeliang Tangadd_addr_ports_tests()
25801002b89fSGeliang Tang{
25818a127bf6SGeliang Tang	# signal address with port
2582c7d49c03SMatthieu Baerts	if reset "signal address with port"; then
258334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
258434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
258534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
25868a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2587c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
25888a127bf6SGeliang Tang		chk_add_nr 1 1 1
2589ae7bd9ccSMatthieu Baerts	fi
25908a127bf6SGeliang Tang
25918a127bf6SGeliang Tang	# subflow and signal with port
2592c7d49c03SMatthieu Baerts	if reset "subflow and signal with port"; then
259334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
259434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
259534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
259634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
25978a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2598c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
25998a127bf6SGeliang Tang		chk_add_nr 1 1 1
2600ae7bd9ccSMatthieu Baerts	fi
26018a127bf6SGeliang Tang
26028a127bf6SGeliang Tang	# single address with port, remove
2603178d0232SGeliang Tang	# pm listener events
2604178d0232SGeliang Tang	if reset_with_events "remove single address with port"; then
260534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
260634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
260734aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
26088a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
2609c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
26108a127bf6SGeliang Tang		chk_add_nr 1 1 1
26117028ba8aSGeliang Tang		chk_rm_nr 1 1 invert
2612178d0232SGeliang Tang
2613178d0232SGeliang Tang		verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100
2614178d0232SGeliang Tang		verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100
2615178d0232SGeliang Tang		kill_events_pids
2616ae7bd9ccSMatthieu Baerts	fi
26178a127bf6SGeliang Tang
26188a127bf6SGeliang Tang	# subflow and signal with port, remove
2619c7d49c03SMatthieu Baerts	if reset "remove subflow and signal with port"; then
262034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
262134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
262234aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
262334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
26248a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
2625c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
26268a127bf6SGeliang Tang		chk_add_nr 1 1 1
26278a127bf6SGeliang Tang		chk_rm_nr 1 1
2628ae7bd9ccSMatthieu Baerts	fi
26298a127bf6SGeliang Tang
26308a127bf6SGeliang Tang	# subflows and signal with port, flush
2631c7d49c03SMatthieu Baerts	if reset "flush subflows and signal with port"; then
263234aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
263334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
263434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
263534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
263634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2637327b9a94SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 0 -8 -2 slow
2638c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
26398a127bf6SGeliang Tang		chk_add_nr 1 1
26406fa0174aSPaolo Abeni		chk_rm_nr 1 3 invert simult
2641ae7bd9ccSMatthieu Baerts	fi
26428a127bf6SGeliang Tang
26438a127bf6SGeliang Tang	# multiple addresses with port
2644c7d49c03SMatthieu Baerts	if reset "multiple addresses with port"; then
264534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
264634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
264734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100
264834aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
26498a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2650c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
26518a127bf6SGeliang Tang		chk_add_nr 2 2 2
2652ae7bd9ccSMatthieu Baerts	fi
26538a127bf6SGeliang Tang
26548a127bf6SGeliang Tang	# multiple addresses with ports
2655c7d49c03SMatthieu Baerts	if reset "multiple addresses with ports"; then
265634aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
265734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
265834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101
265934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
26608a127bf6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2661c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
26628a127bf6SGeliang Tang		chk_add_nr 2 2 2
2663ae7bd9ccSMatthieu Baerts	fi
26641002b89fSGeliang Tang}
26658a127bf6SGeliang Tang
26661002b89fSGeliang Tangsyncookies_tests()
26671002b89fSGeliang Tang{
266800587187SFlorian Westphal	# single subflow, syncookies
2669c7d49c03SMatthieu Baerts	if reset_with_cookies "single subflow with syn cookies"; then
267034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
267134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
267234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
267300587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2674c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2675ae7bd9ccSMatthieu Baerts	fi
267600587187SFlorian Westphal
267700587187SFlorian Westphal	# multiple subflows with syn cookies
2678c7d49c03SMatthieu Baerts	if reset_with_cookies "multiple subflows with syn cookies"; then
267934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
268034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
268134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
268234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
268300587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2684c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2685ae7bd9ccSMatthieu Baerts	fi
268600587187SFlorian Westphal
268700587187SFlorian Westphal	# multiple subflows limited by server
2688c7d49c03SMatthieu Baerts	if reset_with_cookies "subflows limited by server w cookies"; then
268934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
269034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 2
269134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
269234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
269300587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2694c7d49c03SMatthieu Baerts		chk_join_nr 2 1 1
2695ae7bd9ccSMatthieu Baerts	fi
269600587187SFlorian Westphal
269700587187SFlorian Westphal	# test signal address with cookies
2698c7d49c03SMatthieu Baerts	if reset_with_cookies "signal address with syn cookies"; then
269934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
270034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
270134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
270200587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2703c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2704be613160SGeliang Tang		chk_add_nr 1 1
2705ae7bd9ccSMatthieu Baerts	fi
270600587187SFlorian Westphal
270700587187SFlorian Westphal	# test cookie with subflow and signal
2708c7d49c03SMatthieu Baerts	if reset_with_cookies "subflow and signal w cookies"; then
270934aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
271034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 2
271134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 2
271234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
271300587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2714c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2715be613160SGeliang Tang		chk_add_nr 1 1
2716ae7bd9ccSMatthieu Baerts	fi
271700587187SFlorian Westphal
271800587187SFlorian Westphal	# accept and use add_addr with additional subflows
2719c7d49c03SMatthieu Baerts	if reset_with_cookies "subflows and signal w. cookies"; then
272034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 3
272134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
272234aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
272334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
272434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
272500587187SFlorian Westphal		run_tests $ns1 $ns2 10.0.1.1
2726c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
2727be613160SGeliang Tang		chk_add_nr 1 1
2728ae7bd9ccSMatthieu Baerts	fi
27291002b89fSGeliang Tang}
27301002b89fSGeliang Tang
2731af66d3e1SGeliang Tangchecksum_tests()
2732af66d3e1SGeliang Tang{
2733af66d3e1SGeliang Tang	# checksum test 0 0
2734ae7bd9ccSMatthieu Baerts	if reset_with_checksum 0 0; then
273534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
273634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
2737af66d3e1SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2738c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2739ae7bd9ccSMatthieu Baerts	fi
2740af66d3e1SGeliang Tang
2741af66d3e1SGeliang Tang	# checksum test 1 1
2742ae7bd9ccSMatthieu Baerts	if reset_with_checksum 1 1; then
274334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
274434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
2745af66d3e1SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2746c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2747ae7bd9ccSMatthieu Baerts	fi
2748af66d3e1SGeliang Tang
2749af66d3e1SGeliang Tang	# checksum test 0 1
2750ae7bd9ccSMatthieu Baerts	if reset_with_checksum 0 1; then
275134aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
275234aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
2753af66d3e1SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2754c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2755ae7bd9ccSMatthieu Baerts	fi
2756af66d3e1SGeliang Tang
2757af66d3e1SGeliang Tang	# checksum test 1 0
2758ae7bd9ccSMatthieu Baerts	if reset_with_checksum 1 0; then
275934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 1
276034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 0 1
2761af66d3e1SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2762c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2763ae7bd9ccSMatthieu Baerts	fi
2764af66d3e1SGeliang Tang}
2765af66d3e1SGeliang Tang
27660cddb4a6SGeliang Tangdeny_join_id0_tests()
27670cddb4a6SGeliang Tang{
27680cddb4a6SGeliang Tang	# subflow allow join id0 ns1
2769c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then
277034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 1 1
277134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
277234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
27730cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2774c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2775ae7bd9ccSMatthieu Baerts	fi
27760cddb4a6SGeliang Tang
27770cddb4a6SGeliang Tang	# subflow allow join id0 ns2
2778c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then
277934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 1 1
278034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
278134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
27820cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2783c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
2784ae7bd9ccSMatthieu Baerts	fi
27850cddb4a6SGeliang Tang
27860cddb4a6SGeliang Tang	# signal address allow join id0 ns1
27870cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
2788c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then
278934aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 1 1
279034aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
279134aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
27920cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2793c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
27940cddb4a6SGeliang Tang		chk_add_nr 1 1
2795ae7bd9ccSMatthieu Baerts	fi
27960cddb4a6SGeliang Tang
27970cddb4a6SGeliang Tang	# signal address allow join id0 ns2
27980cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
2799c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then
280034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 1 1
280134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 1
280234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
28030cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2804c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
28050cddb4a6SGeliang Tang		chk_add_nr 1 1
2806ae7bd9ccSMatthieu Baerts	fi
28070cddb4a6SGeliang Tang
28080cddb4a6SGeliang Tang	# subflow and address allow join id0 ns1
2809c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then
281034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
281134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
281234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
281334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
28140cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2815c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
2816ae7bd9ccSMatthieu Baerts	fi
28170cddb4a6SGeliang Tang
28180cddb4a6SGeliang Tang	# subflow and address allow join id0 ns2
2819c7d49c03SMatthieu Baerts	if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then
282034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 2
282134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 2 2
282234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
282334aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
28240cddb4a6SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1
2825c7d49c03SMatthieu Baerts		chk_join_nr 1 1 1
2826ae7bd9ccSMatthieu Baerts	fi
28270cddb4a6SGeliang Tang}
28280cddb4a6SGeliang Tang
28294f49d633SGeliang Tangfullmesh_tests()
28304f49d633SGeliang Tang{
28314f49d633SGeliang Tang	# fullmesh 1
28324f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added before the connection,
28334f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added during the connection.
2834c7d49c03SMatthieu Baerts	if reset "fullmesh test 2x1"; then
283534aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 0 4
283634aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 4
283734aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh
283834aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh
28394f49d633SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
2840c7d49c03SMatthieu Baerts		chk_join_nr 4 4 4
28414f49d633SGeliang Tang		chk_add_nr 1 1
2842ae7bd9ccSMatthieu Baerts	fi
28434f49d633SGeliang Tang
28444f49d633SGeliang Tang	# fullmesh 2
28454f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
28464f49d633SGeliang Tang	# 1 fullmesh addr in ns2, added during the connection.
2847c7d49c03SMatthieu Baerts	if reset "fullmesh test 1x1"; then
284834aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 1 3
284934aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 3
285034aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
28514f49d633SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow
2852c7d49c03SMatthieu Baerts		chk_join_nr 3 3 3
28534f49d633SGeliang Tang		chk_add_nr 1 1
2854ae7bd9ccSMatthieu Baerts	fi
28554f49d633SGeliang Tang
28564f49d633SGeliang Tang	# fullmesh 3
28574f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
28584f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection.
2859c7d49c03SMatthieu Baerts	if reset "fullmesh test 1x2"; then
286034aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 5
286134aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 5
286234aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
28634f49d633SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
2864c7d49c03SMatthieu Baerts		chk_join_nr 5 5 5
28654f49d633SGeliang Tang		chk_add_nr 1 1
2866ae7bd9ccSMatthieu Baerts	fi
28674f49d633SGeliang Tang
28684f49d633SGeliang Tang	# fullmesh 4
28694f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
28704f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection,
28714f49d633SGeliang Tang	# limit max_subflows to 4.
2872c7d49c03SMatthieu Baerts	if reset "fullmesh test 1x2, limited"; then
287334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 2 4
287434aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 1 4
287534aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
28764f49d633SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
2877c7d49c03SMatthieu Baerts		chk_join_nr 4 4 4
28784f49d633SGeliang Tang		chk_add_nr 1 1
2879ae7bd9ccSMatthieu Baerts	fi
28806a0653b9SGeliang Tang
28816a0653b9SGeliang Tang	# set fullmesh flag
2882c7d49c03SMatthieu Baerts	if reset "set fullmesh flag test"; then
288334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 4 4
288434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
288534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 4 4
28866a0653b9SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow fullmesh
2887c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
28886a0653b9SGeliang Tang		chk_rm_nr 0 1
2889ae7bd9ccSMatthieu Baerts	fi
28906a0653b9SGeliang Tang
28916a0653b9SGeliang Tang	# set nofullmesh flag
2892c7d49c03SMatthieu Baerts	if reset "set nofullmesh flag test"; then
289334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 4 4
289434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh
289534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 4 4
28966a0653b9SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow nofullmesh
2897c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
28986a0653b9SGeliang Tang		chk_rm_nr 0 1
2899ae7bd9ccSMatthieu Baerts	fi
29006a0653b9SGeliang Tang
29016a0653b9SGeliang Tang	# set backup,fullmesh flags
2902c7d49c03SMatthieu Baerts	if reset "set backup,fullmesh flags test"; then
290334aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 4 4
290434aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
290534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 4 4
29066a0653b9SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow backup,fullmesh
2907c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
29086a0653b9SGeliang Tang		chk_prio_nr 0 1
29096a0653b9SGeliang Tang		chk_rm_nr 0 1
2910ae7bd9ccSMatthieu Baerts	fi
29116a0653b9SGeliang Tang
29126a0653b9SGeliang Tang	# set nobackup,nofullmesh flags
2913c7d49c03SMatthieu Baerts	if reset "set nobackup,nofullmesh flags test"; then
291434aa6e3bSGeliang Tang		pm_nl_set_limits $ns1 4 4
291534aa6e3bSGeliang Tang		pm_nl_set_limits $ns2 4 4
291634aa6e3bSGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh
29176a0653b9SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup,nofullmesh
2918c7d49c03SMatthieu Baerts		chk_join_nr 2 2 2
29196a0653b9SGeliang Tang		chk_prio_nr 0 1
29206a0653b9SGeliang Tang		chk_rm_nr 0 1
2921ae7bd9ccSMatthieu Baerts	fi
29224f49d633SGeliang Tang}
29234f49d633SGeliang Tang
292401542c9bSGeliang Tangfastclose_tests()
292501542c9bSGeliang Tang{
2926c7d49c03SMatthieu Baerts	if reset "fastclose test"; then
29276bf41020SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_client
2928c7d49c03SMatthieu Baerts		chk_join_nr 0 0 0
292901542c9bSGeliang Tang		chk_fclose_nr 1 1
293001542c9bSGeliang Tang		chk_rst_nr 1 1 invert
2931ae7bd9ccSMatthieu Baerts	fi
29326bf41020SPaolo Abeni
29336bf41020SPaolo Abeni	if reset "fastclose server test"; then
29346bf41020SPaolo Abeni		run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_server
29356bf41020SPaolo Abeni		chk_join_nr 0 0 0
29366bf41020SPaolo Abeni		chk_fclose_nr 1 1 invert
29376bf41020SPaolo Abeni		chk_rst_nr 1 1
29386bf41020SPaolo Abeni	fi
293901542c9bSGeliang Tang}
294001542c9bSGeliang Tang
2941b6e074e1SGeliang Tangpedit_action_pkts()
2942b6e074e1SGeliang Tang{
2943b6e074e1SGeliang Tang	tc -n $ns2 -j -s action show action pedit index 100 | \
2944c43ce398SGeliang Tang		grep "packets" | \
2945b6e074e1SGeliang Tang		sed 's/.*"packets":\([0-9]\+\),.*/\1/'
2946b6e074e1SGeliang Tang}
2947b6e074e1SGeliang Tang
2948b6e074e1SGeliang Tangfail_tests()
2949b6e074e1SGeliang Tang{
2950b6e074e1SGeliang Tang	# single subflow
2951b6e074e1SGeliang Tang	if reset_with_fail "Infinite map" 1; then
2952b6e074e1SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 128
2953b6e074e1SGeliang Tang		chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)"
29541f7d325fSGeliang Tang		chk_fail_nr 1 -1 invert
2955b6e074e1SGeliang Tang	fi
29562ba18161SGeliang Tang
29572ba18161SGeliang Tang	# multiple subflows
29582ba18161SGeliang Tang	if reset_with_fail "MP_FAIL MP_RST" 2; then
29592ba18161SGeliang Tang		tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5
29602ba18161SGeliang Tang		pm_nl_set_limits $ns1 0 1
29612ba18161SGeliang Tang		pm_nl_set_limits $ns2 0 1
29622ba18161SGeliang Tang		pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow
29632ba18161SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 1024
29642ba18161SGeliang Tang		chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)"
29652ba18161SGeliang Tang	fi
2966b6e074e1SGeliang Tang}
2967b6e074e1SGeliang Tang
29685ac1d2d6SMat Martineauuserspace_tests()
29695ac1d2d6SMat Martineau{
29705ac1d2d6SMat Martineau	# userspace pm type prevents add_addr
29715ac1d2d6SMat Martineau	if reset "userspace pm type prevents add_addr"; then
29725ac1d2d6SMat Martineau		set_userspace_pm $ns1
29735ac1d2d6SMat Martineau		pm_nl_set_limits $ns1 0 2
29745ac1d2d6SMat Martineau		pm_nl_set_limits $ns2 0 2
29755ac1d2d6SMat Martineau		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
29765ac1d2d6SMat Martineau		run_tests $ns1 $ns2 10.0.1.1
29775ac1d2d6SMat Martineau		chk_join_nr 0 0 0
29785ac1d2d6SMat Martineau		chk_add_nr 0 0
29795ac1d2d6SMat Martineau	fi
29805ac1d2d6SMat Martineau
2981b3b71bf9SMat Martineau	# userspace pm type does not echo add_addr without daemon
2982b3b71bf9SMat Martineau	if reset "userspace pm no echo w/o daemon"; then
2983b3b71bf9SMat Martineau		set_userspace_pm $ns2
2984b3b71bf9SMat Martineau		pm_nl_set_limits $ns1 0 2
2985b3b71bf9SMat Martineau		pm_nl_set_limits $ns2 0 2
2986b3b71bf9SMat Martineau		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
2987b3b71bf9SMat Martineau		run_tests $ns1 $ns2 10.0.1.1
2988b3b71bf9SMat Martineau		chk_join_nr 0 0 0
2989b3b71bf9SMat Martineau		chk_add_nr 1 0
2990b3b71bf9SMat Martineau	fi
2991b3b71bf9SMat Martineau
29925ac1d2d6SMat Martineau	# userspace pm type rejects join
29935ac1d2d6SMat Martineau	if reset "userspace pm type rejects join"; then
29945ac1d2d6SMat Martineau		set_userspace_pm $ns1
29955ac1d2d6SMat Martineau		pm_nl_set_limits $ns1 1 1
29965ac1d2d6SMat Martineau		pm_nl_set_limits $ns2 1 1
29975ac1d2d6SMat Martineau		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
29985ac1d2d6SMat Martineau		run_tests $ns1 $ns2 10.0.1.1
29995ac1d2d6SMat Martineau		chk_join_nr 1 1 0
30005ac1d2d6SMat Martineau	fi
30015ac1d2d6SMat Martineau
30025ac1d2d6SMat Martineau	# userspace pm type does not send join
30035ac1d2d6SMat Martineau	if reset "userspace pm type does not send join"; then
30045ac1d2d6SMat Martineau		set_userspace_pm $ns2
30055ac1d2d6SMat Martineau		pm_nl_set_limits $ns1 1 1
30065ac1d2d6SMat Martineau		pm_nl_set_limits $ns2 1 1
30075ac1d2d6SMat Martineau		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
30085ac1d2d6SMat Martineau		run_tests $ns1 $ns2 10.0.1.1
30095ac1d2d6SMat Martineau		chk_join_nr 0 0 0
30105ac1d2d6SMat Martineau	fi
30115ac1d2d6SMat Martineau
30125ac1d2d6SMat Martineau	# userspace pm type prevents mp_prio
30135ac1d2d6SMat Martineau	if reset "userspace pm type prevents mp_prio"; then
30145ac1d2d6SMat Martineau		set_userspace_pm $ns1
30155ac1d2d6SMat Martineau		pm_nl_set_limits $ns1 1 1
30165ac1d2d6SMat Martineau		pm_nl_set_limits $ns2 1 1
30175ac1d2d6SMat Martineau		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
30185ac1d2d6SMat Martineau		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
30195ac1d2d6SMat Martineau		chk_join_nr 1 1 0
30205ac1d2d6SMat Martineau		chk_prio_nr 0 0
30215ac1d2d6SMat Martineau	fi
30225ac1d2d6SMat Martineau
30235ac1d2d6SMat Martineau	# userspace pm type prevents rm_addr
30245ac1d2d6SMat Martineau	if reset "userspace pm type prevents rm_addr"; then
30255ac1d2d6SMat Martineau		set_userspace_pm $ns1
30265ac1d2d6SMat Martineau		set_userspace_pm $ns2
30275ac1d2d6SMat Martineau		pm_nl_set_limits $ns1 0 1
30285ac1d2d6SMat Martineau		pm_nl_set_limits $ns2 0 1
30295ac1d2d6SMat Martineau		pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
30305ac1d2d6SMat Martineau		run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
30315ac1d2d6SMat Martineau		chk_join_nr 0 0 0
30325ac1d2d6SMat Martineau		chk_rm_nr 0 0
30335ac1d2d6SMat Martineau	fi
303497040cf9SGeliang Tang
303597040cf9SGeliang Tang	# userspace pm add & remove address
3036a3735625SGeliang Tang	if reset_with_events "userspace pm add & remove address"; then
303797040cf9SGeliang Tang		set_userspace_pm $ns1
303897040cf9SGeliang Tang		pm_nl_set_limits $ns2 1 1
303997040cf9SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow
304097040cf9SGeliang Tang		chk_join_nr 1 1 1
304197040cf9SGeliang Tang		chk_add_nr 1 1
304297040cf9SGeliang Tang		chk_rm_nr 1 1 invert
3043a3735625SGeliang Tang		kill_events_pids
304497040cf9SGeliang Tang	fi
30455e986ec4SGeliang Tang
30465e986ec4SGeliang Tang	# userspace pm create destroy subflow
3047a3735625SGeliang Tang	if reset_with_events "userspace pm create destroy subflow"; then
30485e986ec4SGeliang Tang		set_userspace_pm $ns2
30495e986ec4SGeliang Tang		pm_nl_set_limits $ns1 0 1
30505e986ec4SGeliang Tang		run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow
30515e986ec4SGeliang Tang		chk_join_nr 1 1 1
30525e986ec4SGeliang Tang		chk_rm_nr 0 1
3053a3735625SGeliang Tang		kill_events_pids
30545e986ec4SGeliang Tang	fi
30555ac1d2d6SMat Martineau}
30565ac1d2d6SMat Martineau
3057e274f715SPaolo Abeniendpoint_tests()
305869c6ce7bSPaolo Abeni{
305969c6ce7bSPaolo Abeni	# userspace pm type prevents add_addr
3060c7d49c03SMatthieu Baerts	if reset "implicit EP"; then
306169c6ce7bSPaolo Abeni		pm_nl_set_limits $ns1 2 2
306269c6ce7bSPaolo Abeni		pm_nl_set_limits $ns2 2 2
306369c6ce7bSPaolo Abeni		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
3064*070d6dafSMatthieu Baerts		run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2>/dev/null &
306569c6ce7bSPaolo Abeni
306669c6ce7bSPaolo Abeni		wait_mpj $ns1
3067c7d49c03SMatthieu Baerts		pm_nl_check_endpoint 1 "creation" \
306869c6ce7bSPaolo Abeni			$ns2 10.0.2.2 id 1 flags implicit
306969c6ce7bSPaolo Abeni
307069c6ce7bSPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.2.2 id 33
3071c7d49c03SMatthieu Baerts		pm_nl_check_endpoint 0 "ID change is prevented" \
307269c6ce7bSPaolo Abeni			$ns2 10.0.2.2 id 1 flags implicit
307369c6ce7bSPaolo Abeni
307469c6ce7bSPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
3075c7d49c03SMatthieu Baerts		pm_nl_check_endpoint 0 "modif is allowed" \
307669c6ce7bSPaolo Abeni			$ns2 10.0.2.2 id 1 flags signal
3077*070d6dafSMatthieu Baerts		kill_tests_wait
3078ae7bd9ccSMatthieu Baerts	fi
3079e274f715SPaolo Abeni
3080e274f715SPaolo Abeni	if reset "delete and re-add"; then
3081e274f715SPaolo Abeni		pm_nl_set_limits $ns1 1 1
3082e274f715SPaolo Abeni		pm_nl_set_limits $ns2 1 1
3083e274f715SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow
3084*070d6dafSMatthieu Baerts		run_tests $ns1 $ns2 10.0.1.1 4 0 0 speed_20 2>/dev/null &
3085e274f715SPaolo Abeni
3086e274f715SPaolo Abeni		wait_mpj $ns2
3087e274f715SPaolo Abeni		pm_nl_del_endpoint $ns2 2 10.0.2.2
3088e274f715SPaolo Abeni		sleep 0.5
3089e274f715SPaolo Abeni		chk_subflow_nr needtitle "after delete" 1
3090e274f715SPaolo Abeni
3091e274f715SPaolo Abeni		pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow
3092e274f715SPaolo Abeni		wait_mpj $ns2
3093e274f715SPaolo Abeni		chk_subflow_nr "" "after re-add" 2
3094*070d6dafSMatthieu Baerts		kill_tests_wait
3095e274f715SPaolo Abeni	fi
309669c6ce7bSPaolo Abeni}
309769c6ce7bSPaolo Abeni
309822514d52SMatthieu Baerts# [$1: error message]
30991002b89fSGeliang Tangusage()
31001002b89fSGeliang Tang{
310122514d52SMatthieu Baerts	if [ -n "${1}" ]; then
310222514d52SMatthieu Baerts		echo "${1}"
310322514d52SMatthieu Baerts		ret=1
310422514d52SMatthieu Baerts	fi
310522514d52SMatthieu Baerts
31061002b89fSGeliang Tang	echo "mptcp_join usage:"
31073afd0280SMatthieu Baerts
31083afd0280SMatthieu Baerts	local key
31093afd0280SMatthieu Baerts	for key in "${!all_tests[@]}"; do
31103afd0280SMatthieu Baerts		echo "  -${key} ${all_tests[${key}]}"
31113afd0280SMatthieu Baerts	done
31123afd0280SMatthieu Baerts
3113a673321aSMat Martineau	echo "  -c capture pcap files"
3114af66d3e1SGeliang Tang	echo "  -C enable data checksum"
3115621bd393SGeliang Tang	echo "  -i use ip mptcp"
31161002b89fSGeliang Tang	echo "  -h help"
311722514d52SMatthieu Baerts
3118c7d49c03SMatthieu Baerts	echo "[test ids|names]"
3119ae7bd9ccSMatthieu Baerts
312022514d52SMatthieu Baerts	exit ${ret}
31211002b89fSGeliang Tang}
31221002b89fSGeliang Tang
3123a673321aSMat Martineau
31243afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one
31253afd0280SMatthieu Baertsall_tests_sorted=(
31263afd0280SMatthieu Baerts	f@subflows_tests
31273afd0280SMatthieu Baerts	e@subflows_error_tests
31283afd0280SMatthieu Baerts	s@signal_address_tests
31293afd0280SMatthieu Baerts	l@link_failure_tests
31303afd0280SMatthieu Baerts	t@add_addr_timeout_tests
31313afd0280SMatthieu Baerts	r@remove_tests
31323afd0280SMatthieu Baerts	a@add_tests
31333afd0280SMatthieu Baerts	6@ipv6_tests
31343afd0280SMatthieu Baerts	4@v4mapped_tests
31353afd0280SMatthieu Baerts	b@backup_tests
31363afd0280SMatthieu Baerts	p@add_addr_ports_tests
31373afd0280SMatthieu Baerts	k@syncookies_tests
31383afd0280SMatthieu Baerts	S@checksum_tests
31393afd0280SMatthieu Baerts	d@deny_join_id0_tests
31403afd0280SMatthieu Baerts	m@fullmesh_tests
31413afd0280SMatthieu Baerts	z@fastclose_tests
3142b6e074e1SGeliang Tang	F@fail_tests
31435ac1d2d6SMat Martineau	u@userspace_tests
3144e274f715SPaolo Abeni	I@endpoint_tests
31453afd0280SMatthieu Baerts)
31463afd0280SMatthieu Baerts
31473afd0280SMatthieu Baertsall_tests_args=""
31483afd0280SMatthieu Baertsall_tests_names=()
31493afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do
31503afd0280SMatthieu Baerts	key="${subtests%@*}"
31513afd0280SMatthieu Baerts	value="${subtests#*@}"
31523afd0280SMatthieu Baerts
31533afd0280SMatthieu Baerts	all_tests_args+="${key}"
31543afd0280SMatthieu Baerts	all_tests_names+=("${value}")
31553afd0280SMatthieu Baerts	all_tests[${key}]="${value}"
31563afd0280SMatthieu Baertsdone
31573afd0280SMatthieu Baerts
3158826d7bdcSMatthieu Baertstests=()
31593afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do
31601002b89fSGeliang Tang	case $opt in
31613afd0280SMatthieu Baerts		["${all_tests_args}"])
31623afd0280SMatthieu Baerts			tests+=("${all_tests[${opt}]}")
316369c6ce7bSPaolo Abeni			;;
3164a673321aSMat Martineau		c)
3165826d7bdcSMatthieu Baerts			capture=1
3166a673321aSMat Martineau			;;
3167af66d3e1SGeliang Tang		C)
3168826d7bdcSMatthieu Baerts			checksum=1
3169af66d3e1SGeliang Tang			;;
3170621bd393SGeliang Tang		i)
3171826d7bdcSMatthieu Baerts			ip_mptcp=1
3172621bd393SGeliang Tang			;;
317322514d52SMatthieu Baerts		h)
31741002b89fSGeliang Tang			usage
31751002b89fSGeliang Tang			;;
317622514d52SMatthieu Baerts		*)
317722514d52SMatthieu Baerts			usage "Unknown option: -${opt}"
317822514d52SMatthieu Baerts			;;
31791002b89fSGeliang Tang	esac
31801002b89fSGeliang Tangdone
318100587187SFlorian Westphal
3182ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1))
3183ae7bd9ccSMatthieu Baerts
3184ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do
3185ae7bd9ccSMatthieu Baerts	if [[ "${arg}" =~ ^[0-9]+$ ]]; then
3186c7d49c03SMatthieu Baerts		only_tests_ids+=("${arg}")
3187ae7bd9ccSMatthieu Baerts	else
3188c7d49c03SMatthieu Baerts		only_tests_names+=("${arg}")
3189ae7bd9ccSMatthieu Baerts	fi
3190ae7bd9ccSMatthieu Baertsdone
3191ae7bd9ccSMatthieu Baerts
3192826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then
31933afd0280SMatthieu Baerts	tests=("${all_tests_names[@]}")
31943afd0280SMatthieu Baertsfi
31953afd0280SMatthieu Baerts
3196826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do
3197826d7bdcSMatthieu Baerts	"${subtests}"
3198826d7bdcSMatthieu Baertsdone
3199826d7bdcSMatthieu Baerts
320039aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then
320139aab882SMatthieu Baerts	echo
320239aab882SMatthieu Baerts	echo "${#failed_tests[@]} failure(s) has(ve) been detected:"
320339aab882SMatthieu Baerts	for i in $(get_failed_tests_ids); do
320439aab882SMatthieu Baerts		echo -e "\t- ${i}: ${failed_tests[${i}]}"
320539aab882SMatthieu Baerts	done
320639aab882SMatthieu Baerts	echo
320739aab882SMatthieu Baertsfi
320839aab882SMatthieu Baerts
3209b08fbf24SPaolo Abeniexit $ret
3210