1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4b08fbf24SPaolo Abeniret=0
5b08fbf24SPaolo Abenisin=""
67d1e6f16SPaolo Abenisinfail=""
7b08fbf24SPaolo Abenisout=""
8b08fbf24SPaolo Abenicin=""
97d1e6f16SPaolo Abenicinfail=""
108b819a84SFlorian Westphalcinsent=""
11b08fbf24SPaolo Abenicout=""
12b08fbf24SPaolo Abeniksft_skip=4
135888a61cSMatthieu Baertstimeout_poll=30
145888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1))
15b08fbf24SPaolo Abenicapture=0
16af66d3e1SGeliang Tangchecksum=0
1734aa6e3bSGeliang Tangip_mptcp=0
188117dac3SGeliang Tangcheck_invert=0
193c082695SGeliang Tangvalidate_checksum=0
2093827ad5SMatthieu Baertsinit=0
21b08fbf24SPaolo Abeni
22*3afd0280SMatthieu Baertsdeclare -A all_tests
23b08fbf24SPaolo AbeniTEST_COUNT=0
249a0a9367SGeliang Tangnr_blank=40
25b08fbf24SPaolo Abeni
268d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
278d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
288d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
298d014eaaSGeliang Tang			       48 0 0 0,
308d014eaaSGeliang Tang			       84 0 0 240,
318d014eaaSGeliang Tang			       21 0 3 64,
328d014eaaSGeliang Tang			       48 0 0 54,
338d014eaaSGeliang Tang			       84 0 0 240,
348d014eaaSGeliang Tang			       21 6 7 48,
358d014eaaSGeliang Tang			       48 0 0 0,
368d014eaaSGeliang Tang			       84 0 0 240,
378d014eaaSGeliang Tang			       21 0 4 96,
388d014eaaSGeliang Tang			       48 0 0 74,
398d014eaaSGeliang Tang			       84 0 0 240,
408d014eaaSGeliang Tang			       21 0 1 48,
418d014eaaSGeliang Tang			       6 0 0 65535,
428d014eaaSGeliang Tang			       6 0 0 0"
438d014eaaSGeliang Tang
4493827ad5SMatthieu Baertsinit_partial()
45b08fbf24SPaolo Abeni{
46b08fbf24SPaolo Abeni	capout=$(mktemp)
47b08fbf24SPaolo Abeni
480a40e273SMatthieu Baerts	rndh=$(mktemp -u XXXXXX)
49b08fbf24SPaolo Abeni
50b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
51b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
52b08fbf24SPaolo Abeni
53b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2";do
54b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
55b08fbf24SPaolo Abeni		ip -net $netns link set lo up
56b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
57b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
58b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
59af66d3e1SGeliang Tang		if [ $checksum -eq 1 ]; then
60af66d3e1SGeliang Tang			ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
61af66d3e1SGeliang Tang		fi
62b08fbf24SPaolo Abeni	done
63b08fbf24SPaolo Abeni
648117dac3SGeliang Tang	check_invert=0
653c082695SGeliang Tang	validate_checksum=$checksum
668117dac3SGeliang Tang
67b08fbf24SPaolo Abeni	#  ns1              ns2
68b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
69b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
70b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
71b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
72b08fbf24SPaolo Abeni
73b08fbf24SPaolo Abeni	for i in `seq 1 4`; do
74b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
75b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
76b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
77b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
78b08fbf24SPaolo Abeni
79b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
80b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
81b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
82b08fbf24SPaolo Abeni
83b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
84b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
859846921dSPaolo Abeni		ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i
86b08fbf24SPaolo Abeni	done
87b08fbf24SPaolo Abeni}
88b08fbf24SPaolo Abeni
897d1e6f16SPaolo Abeniinit_shapers()
907d1e6f16SPaolo Abeni{
917d1e6f16SPaolo Abeni	for i in `seq 1 4`; do
927d1e6f16SPaolo Abeni		tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1
937d1e6f16SPaolo Abeni		tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1
947d1e6f16SPaolo Abeni	done
957d1e6f16SPaolo Abeni}
967d1e6f16SPaolo Abeni
97b08fbf24SPaolo Abenicleanup_partial()
98b08fbf24SPaolo Abeni{
99b08fbf24SPaolo Abeni	rm -f "$capout"
100b08fbf24SPaolo Abeni
101b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
102b08fbf24SPaolo Abeni		ip netns del $netns
103c2a55e8fSMatthieu Baerts		rm -f /tmp/$netns.{nstat,out}
104b08fbf24SPaolo Abeni	done
105b08fbf24SPaolo Abeni}
106b08fbf24SPaolo Abeni
10787154755SMatthieu Baertscheck_tools()
10887154755SMatthieu Baerts{
10987154755SMatthieu Baerts	if ! ip -Version &> /dev/null; then
11087154755SMatthieu Baerts		echo "SKIP: Could not run test without ip tool"
11187154755SMatthieu Baerts		exit $ksft_skip
11287154755SMatthieu Baerts	fi
11387154755SMatthieu Baerts
11487154755SMatthieu Baerts	if ! iptables -V &> /dev/null; then
11587154755SMatthieu Baerts		echo "SKIP: Could not run all tests without iptables tool"
11687154755SMatthieu Baerts		exit $ksft_skip
11787154755SMatthieu Baerts	fi
11887154755SMatthieu Baerts
11987154755SMatthieu Baerts	if ! ip6tables -V &> /dev/null; then
12087154755SMatthieu Baerts		echo "SKIP: Could not run all tests without ip6tables tool"
12187154755SMatthieu Baerts		exit $ksft_skip
12287154755SMatthieu Baerts	fi
12387154755SMatthieu Baerts}
12487154755SMatthieu Baerts
12593827ad5SMatthieu Baertsinit() {
12693827ad5SMatthieu Baerts	init=1
12793827ad5SMatthieu Baerts
12887154755SMatthieu Baerts	check_tools
12987154755SMatthieu Baerts
13093827ad5SMatthieu Baerts	sin=$(mktemp)
13193827ad5SMatthieu Baerts	sout=$(mktemp)
13293827ad5SMatthieu Baerts	cin=$(mktemp)
13393827ad5SMatthieu Baerts	cinsent=$(mktemp)
13493827ad5SMatthieu Baerts	cout=$(mktemp)
13593827ad5SMatthieu Baerts
13693827ad5SMatthieu Baerts	trap cleanup EXIT
13793827ad5SMatthieu Baerts
13893827ad5SMatthieu Baerts	make_file "$cin" "client" 1
13993827ad5SMatthieu Baerts	make_file "$sin" "server" 1
14093827ad5SMatthieu Baerts}
14193827ad5SMatthieu Baerts
142b08fbf24SPaolo Abenicleanup()
143b08fbf24SPaolo Abeni{
1447d1e6f16SPaolo Abeni	rm -f "$cin" "$cout" "$sinfail"
1457d1e6f16SPaolo Abeni	rm -f "$sin" "$sout" "$cinsent" "$cinfail"
146b08fbf24SPaolo Abeni	cleanup_partial
147b08fbf24SPaolo Abeni}
148b08fbf24SPaolo Abeni
149b08fbf24SPaolo Abenireset()
150b08fbf24SPaolo Abeni{
15193827ad5SMatthieu Baerts	if [ "${init}" != "1" ]; then
152b08fbf24SPaolo Abeni		init
15393827ad5SMatthieu Baerts	else
15493827ad5SMatthieu Baerts		cleanup_partial
15593827ad5SMatthieu Baerts	fi
15693827ad5SMatthieu Baerts
15793827ad5SMatthieu Baerts	init_partial
158b08fbf24SPaolo Abeni}
159b08fbf24SPaolo Abeni
16000587187SFlorian Westphalreset_with_cookies()
16100587187SFlorian Westphal{
16200587187SFlorian Westphal	reset
16300587187SFlorian Westphal
16400587187SFlorian Westphal	for netns in "$ns1" "$ns2";do
16500587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
16600587187SFlorian Westphal	done
16700587187SFlorian Westphal}
16800587187SFlorian Westphal
1698d014eaaSGeliang Tangreset_with_add_addr_timeout()
1708d014eaaSGeliang Tang{
1718d014eaaSGeliang Tang	local ip="${1:-4}"
1728d014eaaSGeliang Tang	local tables
1738d014eaaSGeliang Tang
1748d014eaaSGeliang Tang	tables="iptables"
1758d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
1768d014eaaSGeliang Tang		tables="ip6tables"
1778d014eaaSGeliang Tang	fi
1788d014eaaSGeliang Tang
1798d014eaaSGeliang Tang	reset
1808d014eaaSGeliang Tang
1818d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
1828d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
1838d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
1848d014eaaSGeliang Tang		-m bpf --bytecode \
1858d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
1868d014eaaSGeliang Tang		-j DROP
1878d014eaaSGeliang Tang}
1888d014eaaSGeliang Tang
189af66d3e1SGeliang Tangreset_with_checksum()
190af66d3e1SGeliang Tang{
191af66d3e1SGeliang Tang	local ns1_enable=$1
192af66d3e1SGeliang Tang	local ns2_enable=$2
193af66d3e1SGeliang Tang
194af66d3e1SGeliang Tang	reset
195af66d3e1SGeliang Tang
196af66d3e1SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
197af66d3e1SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
1983c082695SGeliang Tang
1993c082695SGeliang Tang	validate_checksum=1
200af66d3e1SGeliang Tang}
201af66d3e1SGeliang Tang
2020cddb4a6SGeliang Tangreset_with_allow_join_id0()
2030cddb4a6SGeliang Tang{
2040cddb4a6SGeliang Tang	local ns1_enable=$1
2050cddb4a6SGeliang Tang	local ns2_enable=$2
2060cddb4a6SGeliang Tang
2070cddb4a6SGeliang Tang	reset
2080cddb4a6SGeliang Tang
2090cddb4a6SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
2100cddb4a6SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
2110cddb4a6SGeliang Tang}
2120cddb4a6SGeliang Tang
2138b819a84SFlorian Westphalprint_file_err()
2148b819a84SFlorian Westphal{
2158b819a84SFlorian Westphal	ls -l "$1" 1>&2
2168b819a84SFlorian Westphal	echo "Trailing bytes are: "
2178b819a84SFlorian Westphal	tail -c 27 "$1"
2188b819a84SFlorian Westphal}
2198b819a84SFlorian Westphal
220b08fbf24SPaolo Abenicheck_transfer()
221b08fbf24SPaolo Abeni{
222b08fbf24SPaolo Abeni	in=$1
223b08fbf24SPaolo Abeni	out=$2
224b08fbf24SPaolo Abeni	what=$3
225b08fbf24SPaolo Abeni
2268117dac3SGeliang Tang	cmp -l "$in" "$out" | while read line; do
2278117dac3SGeliang Tang		local arr=($line)
2288117dac3SGeliang Tang
2298117dac3SGeliang Tang		let sum=0${arr[1]}+0${arr[2]}
2308117dac3SGeliang Tang		if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
231b08fbf24SPaolo Abeni			echo "[ FAIL ] $what does not match (in, out):"
232b08fbf24SPaolo Abeni			print_file_err "$in"
233b08fbf24SPaolo Abeni			print_file_err "$out"
2348b819a84SFlorian Westphal			ret=1
235b08fbf24SPaolo Abeni
236b08fbf24SPaolo Abeni			return 1
2378117dac3SGeliang Tang		else
2388117dac3SGeliang Tang			echo "$what has inverted byte at ${arr[0]}"
239b08fbf24SPaolo Abeni		fi
2408117dac3SGeliang Tang	done
241b08fbf24SPaolo Abeni
242b08fbf24SPaolo Abeni	return 0
243b08fbf24SPaolo Abeni}
244b08fbf24SPaolo Abeni
245b08fbf24SPaolo Abenido_ping()
246b08fbf24SPaolo Abeni{
247b08fbf24SPaolo Abeni	listener_ns="$1"
248b08fbf24SPaolo Abeni	connector_ns="$2"
249b08fbf24SPaolo Abeni	connect_addr="$3"
250b08fbf24SPaolo Abeni
251b08fbf24SPaolo Abeni	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
252b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ; then
253b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
254b08fbf24SPaolo Abeni		ret=1
255b08fbf24SPaolo Abeni	fi
256b08fbf24SPaolo Abeni}
257b08fbf24SPaolo Abeni
2588b819a84SFlorian Westphallink_failure()
2598b819a84SFlorian Westphal{
2608b819a84SFlorian Westphal	ns="$1"
2618b819a84SFlorian Westphal
2627d1e6f16SPaolo Abeni	if [ -z "$FAILING_LINKS" ]; then
2638b819a84SFlorian Westphal		l=$((RANDOM%4))
2647d1e6f16SPaolo Abeni		FAILING_LINKS=$((l+1))
2657d1e6f16SPaolo Abeni	fi
2668b819a84SFlorian Westphal
2677d1e6f16SPaolo Abeni	for l in $FAILING_LINKS; do
2688b819a84SFlorian Westphal		veth="ns1eth$l"
2698b819a84SFlorian Westphal		ip -net "$ns" link set "$veth" down
2707d1e6f16SPaolo Abeni	done
2718b819a84SFlorian Westphal}
2728b819a84SFlorian Westphal
273523514edSGeliang Tang# $1: IP address
274523514edSGeliang Tangis_v6()
275523514edSGeliang Tang{
276523514edSGeliang Tang	[ -z "${1##*:*}" ]
277523514edSGeliang Tang}
278523514edSGeliang Tang
279327b9a94SPaolo Abeni# $1: ns, $2: port
280327b9a94SPaolo Abeniwait_local_port_listen()
281327b9a94SPaolo Abeni{
282327b9a94SPaolo Abeni	local listener_ns="${1}"
283327b9a94SPaolo Abeni	local port="${2}"
284327b9a94SPaolo Abeni
285327b9a94SPaolo Abeni	local port_hex i
286327b9a94SPaolo Abeni
287327b9a94SPaolo Abeni	port_hex="$(printf "%04X" "${port}")"
288327b9a94SPaolo Abeni	for i in $(seq 10); do
289327b9a94SPaolo Abeni		ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
290327b9a94SPaolo Abeni			awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
291327b9a94SPaolo Abeni			break
292327b9a94SPaolo Abeni		sleep 0.1
293327b9a94SPaolo Abeni	done
294327b9a94SPaolo Abeni}
295327b9a94SPaolo Abeni
296327b9a94SPaolo Abenirm_addr_count()
297327b9a94SPaolo Abeni{
298327b9a94SPaolo Abeni	ns=${1}
299327b9a94SPaolo Abeni
300327b9a94SPaolo Abeni	ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'
301327b9a94SPaolo Abeni}
302327b9a94SPaolo Abeni
303327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns
304327b9a94SPaolo Abeniwait_rm_addr()
305327b9a94SPaolo Abeni{
306327b9a94SPaolo Abeni	local ns="${1}"
307327b9a94SPaolo Abeni	local old_cnt="${2}"
308327b9a94SPaolo Abeni	local cnt
309327b9a94SPaolo Abeni	local i
310327b9a94SPaolo Abeni
311327b9a94SPaolo Abeni	for i in $(seq 10); do
312327b9a94SPaolo Abeni		cnt=$(rm_addr_count ${ns})
313327b9a94SPaolo Abeni		[ "$cnt" = "${old_cnt}" ] || break
314327b9a94SPaolo Abeni		sleep 0.1
315327b9a94SPaolo Abeni	done
316327b9a94SPaolo Abeni}
317327b9a94SPaolo Abeni
31869c6ce7bSPaolo Abeniwait_mpj()
31969c6ce7bSPaolo Abeni{
32069c6ce7bSPaolo Abeni	local ns="${1}"
32169c6ce7bSPaolo Abeni	local cnt old_cnt
32269c6ce7bSPaolo Abeni
32369c6ce7bSPaolo Abeni	old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
32469c6ce7bSPaolo Abeni
32569c6ce7bSPaolo Abeni	local i
32669c6ce7bSPaolo Abeni	for i in $(seq 10); do
32769c6ce7bSPaolo Abeni		cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}')
32869c6ce7bSPaolo Abeni		[ "$cnt" = "${old_cnt}" ] || break
32969c6ce7bSPaolo Abeni		sleep 0.1
33069c6ce7bSPaolo Abeni	done
33169c6ce7bSPaolo Abeni}
33269c6ce7bSPaolo Abeni
33334aa6e3bSGeliang Tangpm_nl_set_limits()
33434aa6e3bSGeliang Tang{
33534aa6e3bSGeliang Tang	local ns=$1
33634aa6e3bSGeliang Tang	local addrs=$2
33734aa6e3bSGeliang Tang	local subflows=$3
33834aa6e3bSGeliang Tang
33934aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
34034aa6e3bSGeliang Tang		ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
34134aa6e3bSGeliang Tang	else
34234aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
34334aa6e3bSGeliang Tang	fi
34434aa6e3bSGeliang Tang}
34534aa6e3bSGeliang Tang
34634aa6e3bSGeliang Tangpm_nl_add_endpoint()
34734aa6e3bSGeliang Tang{
34834aa6e3bSGeliang Tang	local ns=$1
34934aa6e3bSGeliang Tang	local addr=$2
35034aa6e3bSGeliang Tang	local flags
35134aa6e3bSGeliang Tang	local port
35234aa6e3bSGeliang Tang	local dev
35334aa6e3bSGeliang Tang	local id
35434aa6e3bSGeliang Tang	local nr=2
35534aa6e3bSGeliang Tang
35634aa6e3bSGeliang Tang	for p in $@
35734aa6e3bSGeliang Tang	do
35834aa6e3bSGeliang Tang		if [ $p = "flags" ]; then
35934aa6e3bSGeliang Tang			eval _flags=\$"$nr"
36034aa6e3bSGeliang Tang			[ ! -z $_flags ]; flags="flags $_flags"
36134aa6e3bSGeliang Tang		fi
36234aa6e3bSGeliang Tang		if [ $p = "dev" ]; then
36334aa6e3bSGeliang Tang			eval _dev=\$"$nr"
36434aa6e3bSGeliang Tang			[ ! -z $_dev ]; dev="dev $_dev"
36534aa6e3bSGeliang Tang		fi
36634aa6e3bSGeliang Tang		if [ $p = "id" ]; then
36734aa6e3bSGeliang Tang			eval _id=\$"$nr"
36834aa6e3bSGeliang Tang			[ ! -z $_id ]; id="id $_id"
36934aa6e3bSGeliang Tang		fi
37034aa6e3bSGeliang Tang		if [ $p = "port" ]; then
37134aa6e3bSGeliang Tang			eval _port=\$"$nr"
37234aa6e3bSGeliang Tang			[ ! -z $_port ]; port="port $_port"
37334aa6e3bSGeliang Tang		fi
37434aa6e3bSGeliang Tang
37534aa6e3bSGeliang Tang		let nr+=1
37634aa6e3bSGeliang Tang	done
37734aa6e3bSGeliang Tang
37834aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
37934aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
38034aa6e3bSGeliang Tang	else
38134aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
38234aa6e3bSGeliang Tang	fi
38334aa6e3bSGeliang Tang}
38434aa6e3bSGeliang Tang
38534aa6e3bSGeliang Tangpm_nl_del_endpoint()
38634aa6e3bSGeliang Tang{
38734aa6e3bSGeliang Tang	local ns=$1
38834aa6e3bSGeliang Tang	local id=$2
38934aa6e3bSGeliang Tang	local addr=$3
39034aa6e3bSGeliang Tang
39134aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
39234aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint delete id $id $addr
39334aa6e3bSGeliang Tang	else
39434aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl del $id $addr
39534aa6e3bSGeliang Tang	fi
39634aa6e3bSGeliang Tang}
39734aa6e3bSGeliang Tang
39834aa6e3bSGeliang Tangpm_nl_flush_endpoint()
39934aa6e3bSGeliang Tang{
40034aa6e3bSGeliang Tang	local ns=$1
40134aa6e3bSGeliang Tang
40234aa6e3bSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
40334aa6e3bSGeliang Tang		ip -n $ns mptcp endpoint flush
40434aa6e3bSGeliang Tang	else
40534aa6e3bSGeliang Tang		ip netns exec $ns ./pm_nl_ctl flush
40634aa6e3bSGeliang Tang	fi
40734aa6e3bSGeliang Tang}
40834aa6e3bSGeliang Tang
409dda61b3dSGeliang Tangpm_nl_show_endpoints()
410dda61b3dSGeliang Tang{
411dda61b3dSGeliang Tang	local ns=$1
412dda61b3dSGeliang Tang
413dda61b3dSGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
414dda61b3dSGeliang Tang		ip -n $ns mptcp endpoint show
415dda61b3dSGeliang Tang	else
416dda61b3dSGeliang Tang		ip netns exec $ns ./pm_nl_ctl dump
417dda61b3dSGeliang Tang	fi
418dda61b3dSGeliang Tang}
419dda61b3dSGeliang Tang
420f0140386SGeliang Tangpm_nl_change_endpoint()
421f0140386SGeliang Tang{
422f0140386SGeliang Tang	local ns=$1
423bccefb76SGeliang Tang	local id=$2
424bccefb76SGeliang Tang	local flags=$3
425f0140386SGeliang Tang
426f0140386SGeliang Tang	if [ $ip_mptcp -eq 1 ]; then
427f0140386SGeliang Tang		ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
428f0140386SGeliang Tang	else
429bccefb76SGeliang Tang		ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
430f0140386SGeliang Tang	fi
431f0140386SGeliang Tang}
432f0140386SGeliang Tang
43369c6ce7bSPaolo Abenipm_nl_check_endpoint()
43469c6ce7bSPaolo Abeni{
43569c6ce7bSPaolo Abeni	local line expected_line
43669c6ce7bSPaolo Abeni	local title="$1"
43769c6ce7bSPaolo Abeni	local msg="$2"
43869c6ce7bSPaolo Abeni	local ns=$3
43969c6ce7bSPaolo Abeni	local addr=$4
44069c6ce7bSPaolo Abeni	local _flags=""
44169c6ce7bSPaolo Abeni	local flags
44269c6ce7bSPaolo Abeni	local _port
44369c6ce7bSPaolo Abeni	local port
44469c6ce7bSPaolo Abeni	local dev
44569c6ce7bSPaolo Abeni	local _id
44669c6ce7bSPaolo Abeni	local id
44769c6ce7bSPaolo Abeni
44869c6ce7bSPaolo Abeni	if [ -n "${title}" ]; then
44969c6ce7bSPaolo Abeni		printf "%03u %-36s %s" "${TEST_COUNT}" "${title}" "${msg}"
45069c6ce7bSPaolo Abeni	else
45169c6ce7bSPaolo Abeni		printf "%-${nr_blank}s %s" " " "${msg}"
45269c6ce7bSPaolo Abeni	fi
45369c6ce7bSPaolo Abeni
45469c6ce7bSPaolo Abeni	shift 4
45569c6ce7bSPaolo Abeni	while [ -n "$1" ]; do
45669c6ce7bSPaolo Abeni		if [ $1 = "flags" ]; then
45769c6ce7bSPaolo Abeni			_flags=$2
45869c6ce7bSPaolo Abeni			[ ! -z $_flags ]; flags="flags $_flags"
45969c6ce7bSPaolo Abeni			shift
46069c6ce7bSPaolo Abeni		elif [ $1 = "dev" ]; then
46169c6ce7bSPaolo Abeni			[ ! -z $2 ]; dev="dev $1"
46269c6ce7bSPaolo Abeni			shift
46369c6ce7bSPaolo Abeni		elif [ $1 = "id" ]; then
46469c6ce7bSPaolo Abeni			_id=$2
46569c6ce7bSPaolo Abeni			[ ! -z $_id ]; id="id $_id"
46669c6ce7bSPaolo Abeni			shift
46769c6ce7bSPaolo Abeni		elif [ $1 = "port" ]; then
46869c6ce7bSPaolo Abeni			_port=$2
46969c6ce7bSPaolo Abeni			[ ! -z $_port ]; port=" port $_port"
47069c6ce7bSPaolo Abeni			shift
47169c6ce7bSPaolo Abeni		fi
47269c6ce7bSPaolo Abeni
47369c6ce7bSPaolo Abeni		shift
47469c6ce7bSPaolo Abeni	done
47569c6ce7bSPaolo Abeni
47669c6ce7bSPaolo Abeni	if [ -z "$id" ]; then
47769c6ce7bSPaolo Abeni		echo "[skip] bad test - missing endpoint id"
47869c6ce7bSPaolo Abeni		return
47969c6ce7bSPaolo Abeni	fi
48069c6ce7bSPaolo Abeni
48169c6ce7bSPaolo Abeni	if [ $ip_mptcp -eq 1 ]; then
48269c6ce7bSPaolo Abeni		line=$(ip -n $ns mptcp endpoint show $id)
48369c6ce7bSPaolo Abeni		# the dump order is: address id flags port dev
48469c6ce7bSPaolo Abeni		expected_line="$addr"
48569c6ce7bSPaolo Abeni		[ -n "$addr" ] && expected_line="$expected_line $addr"
48669c6ce7bSPaolo Abeni		expected_line="$expected_line $id"
48769c6ce7bSPaolo Abeni		[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
48869c6ce7bSPaolo Abeni		[ -n "$dev" ] && expected_line="$expected_line $dev"
48969c6ce7bSPaolo Abeni		[ -n "$port" ] && expected_line="$expected_line $port"
49069c6ce7bSPaolo Abeni	else
49169c6ce7bSPaolo Abeni		line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
49269c6ce7bSPaolo Abeni		# the dump order is: id flags dev address port
49369c6ce7bSPaolo Abeni		expected_line="$id"
49469c6ce7bSPaolo Abeni		[ -n "$flags" ] && expected_line="$expected_line $flags"
49569c6ce7bSPaolo Abeni		[ -n "$dev" ] && expected_line="$expected_line $dev"
49669c6ce7bSPaolo Abeni		[ -n "$addr" ] && expected_line="$expected_line $addr"
49769c6ce7bSPaolo Abeni		[ -n "$_port" ] && expected_line="$expected_line $_port"
49869c6ce7bSPaolo Abeni	fi
49969c6ce7bSPaolo Abeni	if [ "$line" = "$expected_line" ]; then
50069c6ce7bSPaolo Abeni		echo "[ ok ]"
50169c6ce7bSPaolo Abeni	else
50269c6ce7bSPaolo Abeni		echo "[fail] expected '$expected_line' found '$line'"
50369c6ce7bSPaolo Abeni		ret=1
50469c6ce7bSPaolo Abeni	fi
50569c6ce7bSPaolo Abeni}
50669c6ce7bSPaolo Abeni
507b08fbf24SPaolo Abenido_transfer()
508b08fbf24SPaolo Abeni{
509b08fbf24SPaolo Abeni	listener_ns="$1"
510b08fbf24SPaolo Abeni	connector_ns="$2"
511b08fbf24SPaolo Abeni	cl_proto="$3"
512b08fbf24SPaolo Abeni	srv_proto="$4"
513b08fbf24SPaolo Abeni	connect_addr="$5"
5148b819a84SFlorian Westphal	test_link_fail="$6"
5152e8cbf45SGeliang Tang	addr_nr_ns1="$7"
5162e8cbf45SGeliang Tang	addr_nr_ns2="$8"
5178b819a84SFlorian Westphal	speed="$9"
5186a0653b9SGeliang Tang	sflags="${10}"
519b08fbf24SPaolo Abeni
520b08fbf24SPaolo Abeni	port=$((10000+$TEST_COUNT))
521b08fbf24SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
522b08fbf24SPaolo Abeni
523b08fbf24SPaolo Abeni	:> "$cout"
524b08fbf24SPaolo Abeni	:> "$sout"
525b08fbf24SPaolo Abeni	:> "$capout"
526b08fbf24SPaolo Abeni
527b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
528b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
529b08fbf24SPaolo Abeni			capuser=""
530b08fbf24SPaolo Abeni		else
531b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
532b08fbf24SPaolo Abeni		fi
533b08fbf24SPaolo Abeni
53400587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
535b08fbf24SPaolo Abeni
536b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
537b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
538b08fbf24SPaolo Abeni		cappid=$!
539b08fbf24SPaolo Abeni
540b08fbf24SPaolo Abeni		sleep 1
541b08fbf24SPaolo Abeni	fi
542b08fbf24SPaolo Abeni
543c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
544c2a55e8fSMatthieu Baerts		nstat -n
545c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
546c2a55e8fSMatthieu Baerts		nstat -n
547c2a55e8fSMatthieu Baerts
548cbfafac4SGeliang Tang	local extra_args
5498d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
550cbfafac4SGeliang Tang		extra_args="-j"
5518da6229bSGeliang Tang	elif [ $speed = "slow" ]; then
552cbfafac4SGeliang Tang		extra_args="-r 50"
553cbfafac4SGeliang Tang	elif [[ $speed = "speed_"* ]]; then
554cbfafac4SGeliang Tang		extra_args="-r ${speed:6}"
555dd72b0feSGeliang Tang	fi
556dd72b0feSGeliang Tang
55701542c9bSGeliang Tang	if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then
55801542c9bSGeliang Tang		# disconnect
55901542c9bSGeliang Tang		extra_args="$extra_args -I ${addr_nr_ns2:10}"
56001542c9bSGeliang Tang		addr_nr_ns2=0
56101542c9bSGeliang Tang	fi
56201542c9bSGeliang Tang
563523514edSGeliang Tang	local local_addr
564523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
565523514edSGeliang Tang		local_addr="::"
566523514edSGeliang Tang	else
567523514edSGeliang Tang		local_addr="0.0.0.0"
568523514edSGeliang Tang	fi
569523514edSGeliang Tang
57034b572b7SGeliang Tang	if [ "$test_link_fail" -gt 1 ];then
5717d1e6f16SPaolo Abeni		timeout ${timeout_test} \
5727d1e6f16SPaolo Abeni			ip netns exec ${listener_ns} \
573cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
574cbfafac4SGeliang Tang					$extra_args ${local_addr} < "$sinfail" > "$sout" &
5757d1e6f16SPaolo Abeni	else
5765888a61cSMatthieu Baerts		timeout ${timeout_test} \
5775888a61cSMatthieu Baerts			ip netns exec ${listener_ns} \
578cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
579cbfafac4SGeliang Tang					$extra_args ${local_addr} < "$sin" > "$sout" &
5807d1e6f16SPaolo Abeni	fi
581b08fbf24SPaolo Abeni	spid=$!
582b08fbf24SPaolo Abeni
583327b9a94SPaolo Abeni	wait_local_port_listen "${listener_ns}" "${port}"
584b08fbf24SPaolo Abeni
5858b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
5865888a61cSMatthieu Baerts		timeout ${timeout_test} \
5875888a61cSMatthieu Baerts			ip netns exec ${connector_ns} \
588cbfafac4SGeliang Tang				./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
589cbfafac4SGeliang Tang					$extra_args $connect_addr < "$cin" > "$cout" &
59034b572b7SGeliang Tang	elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then
5917d1e6f16SPaolo Abeni		( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
5925888a61cSMatthieu Baerts			tee "$cinsent" | \
5935888a61cSMatthieu Baerts			timeout ${timeout_test} \
5945888a61cSMatthieu Baerts				ip netns exec ${connector_ns} \
595cbfafac4SGeliang Tang					./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
596cbfafac4SGeliang Tang						$extra_args $connect_addr > "$cout" &
59734b572b7SGeliang Tang	else
59834b572b7SGeliang Tang		cat "$cinfail" | tee "$cinsent" | \
59934b572b7SGeliang Tang			timeout ${timeout_test} \
60034b572b7SGeliang Tang				ip netns exec ${connector_ns} \
60134b572b7SGeliang Tang					./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
60234b572b7SGeliang Tang						$extra_args $connect_addr > "$cout" &
6038b819a84SFlorian Westphal	fi
604b08fbf24SPaolo Abeni	cpid=$!
605b08fbf24SPaolo Abeni
606327b9a94SPaolo Abeni	# let the mptcp subflow be established in background before
607327b9a94SPaolo Abeni	# do endpoint manipulation
608327b9a94SPaolo Abeni	[ $addr_nr_ns1 = "0" -a $addr_nr_ns2 = "0" ] || sleep 1
609327b9a94SPaolo Abeni
6106208fd82SGeliang Tang	if [ $addr_nr_ns1 -gt 0 ]; then
6116208fd82SGeliang Tang		let add_nr_ns1=addr_nr_ns1
6126208fd82SGeliang Tang		counter=2
6136208fd82SGeliang Tang		while [ $add_nr_ns1 -gt 0 ]; do
6146208fd82SGeliang Tang			local addr
6156208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
6166208fd82SGeliang Tang				addr="dead:beef:$counter::1"
6176208fd82SGeliang Tang			else
6186208fd82SGeliang Tang				addr="10.0.$counter.1"
6196208fd82SGeliang Tang			fi
62034aa6e3bSGeliang Tang			pm_nl_add_endpoint $ns1 $addr flags signal
6216208fd82SGeliang Tang			let counter+=1
6226208fd82SGeliang Tang			let add_nr_ns1-=1
6236208fd82SGeliang Tang		done
6246208fd82SGeliang Tang	elif [ $addr_nr_ns1 -lt 0 ]; then
6252e8cbf45SGeliang Tang		let rm_nr_ns1=-addr_nr_ns1
6266fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
627dda61b3dSGeliang Tang			counter=0
628dda61b3dSGeliang Tang			pm_nl_show_endpoints ${listener_ns} | while read line; do
629dda61b3dSGeliang Tang				local arr=($line)
630dda61b3dSGeliang Tang				local nr=0
631dda61b3dSGeliang Tang
632dda61b3dSGeliang Tang				for i in ${arr[@]}; do
633dda61b3dSGeliang Tang					if [ $i = "id" ]; then
634dda61b3dSGeliang Tang						if [ $counter -eq $rm_nr_ns1 ]; then
635dda61b3dSGeliang Tang							break
636dda61b3dSGeliang Tang						fi
637dda61b3dSGeliang Tang						id=${arr[$nr+1]}
638327b9a94SPaolo Abeni						rm_addr=$(rm_addr_count ${connector_ns})
63934aa6e3bSGeliang Tang						pm_nl_del_endpoint ${listener_ns} $id
640327b9a94SPaolo Abeni						wait_rm_addr ${connector_ns} ${rm_addr}
641dd72b0feSGeliang Tang						let counter+=1
642f87744adSGeliang Tang					fi
643dda61b3dSGeliang Tang					let nr+=1
644dda61b3dSGeliang Tang				done
645dda61b3dSGeliang Tang			done
6465e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 8 ]; then
64734aa6e3bSGeliang Tang			pm_nl_flush_endpoint ${listener_ns}
6485e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 9 ]; then
64934aa6e3bSGeliang Tang			pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr}
6506fe4ccdcSGeliang Tang		fi
651dd72b0feSGeliang Tang	fi
652dd72b0feSGeliang Tang
6534f49d633SGeliang Tang	flags="subflow"
6544f49d633SGeliang Tang	if [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
6554f49d633SGeliang Tang		flags="${flags},fullmesh"
6564f49d633SGeliang Tang		addr_nr_ns2=${addr_nr_ns2:9}
6574f49d633SGeliang Tang	fi
6584f49d633SGeliang Tang
659327b9a94SPaolo Abeni	# if newly added endpoints must be deleted, give the background msk
660327b9a94SPaolo Abeni	# some time to created them
661327b9a94SPaolo Abeni	[ $addr_nr_ns1 -gt 0 -a $addr_nr_ns2 -lt 0 ] && sleep 1
662327b9a94SPaolo Abeni
6636208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
6646208fd82SGeliang Tang		let add_nr_ns2=addr_nr_ns2
6656208fd82SGeliang Tang		counter=3
6666208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
6676208fd82SGeliang Tang			local addr
6686208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
6696208fd82SGeliang Tang				addr="dead:beef:$counter::2"
6706208fd82SGeliang Tang			else
6716208fd82SGeliang Tang				addr="10.0.$counter.2"
6726208fd82SGeliang Tang			fi
67334aa6e3bSGeliang Tang			pm_nl_add_endpoint $ns2 $addr flags $flags
6746208fd82SGeliang Tang			let counter+=1
6756208fd82SGeliang Tang			let add_nr_ns2-=1
6766208fd82SGeliang Tang		done
6776208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
6782e8cbf45SGeliang Tang		let rm_nr_ns2=-addr_nr_ns2
6796fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
680dda61b3dSGeliang Tang			counter=0
681dda61b3dSGeliang Tang			pm_nl_show_endpoints ${connector_ns} | while read line; do
682dda61b3dSGeliang Tang				local arr=($line)
683dda61b3dSGeliang Tang				local nr=0
684dda61b3dSGeliang Tang
685dda61b3dSGeliang Tang				for i in ${arr[@]}; do
686dda61b3dSGeliang Tang					if [ $i = "id" ]; then
687dda61b3dSGeliang Tang						if [ $counter -eq $rm_nr_ns2 ]; then
688dda61b3dSGeliang Tang							break
689dda61b3dSGeliang Tang						fi
690dda61b3dSGeliang Tang						# rm_addr are serialized, allow the previous one to
691dda61b3dSGeliang Tang						# complete
692dda61b3dSGeliang Tang						id=${arr[$nr+1]}
693327b9a94SPaolo Abeni						rm_addr=$(rm_addr_count ${listener_ns})
69434aa6e3bSGeliang Tang						pm_nl_del_endpoint ${connector_ns} $id
695327b9a94SPaolo Abeni						wait_rm_addr ${listener_ns} ${rm_addr}
696dd72b0feSGeliang Tang						let counter+=1
697f87744adSGeliang Tang					fi
698dda61b3dSGeliang Tang					let nr+=1
699dda61b3dSGeliang Tang				done
700dda61b3dSGeliang Tang			done
7015e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 8 ]; then
70234aa6e3bSGeliang Tang			pm_nl_flush_endpoint ${connector_ns}
7035e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 9 ]; then
7045e287fe7SGeliang Tang			local addr
7055e287fe7SGeliang Tang			if is_v6 "${connect_addr}"; then
7065e287fe7SGeliang Tang				addr="dead:beef:1::2"
7075e287fe7SGeliang Tang			else
7085e287fe7SGeliang Tang				addr="10.0.1.2"
7095e287fe7SGeliang Tang			fi
71034aa6e3bSGeliang Tang			pm_nl_del_endpoint ${connector_ns} 0 $addr
7116fe4ccdcSGeliang Tang		fi
712dd72b0feSGeliang Tang	fi
713dd72b0feSGeliang Tang
7146a0653b9SGeliang Tang	if [ ! -z $sflags ]; then
715718eb44eSGeliang Tang		sleep 1
716718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
717dda61b3dSGeliang Tang			pm_nl_show_endpoints $netns | while read line; do
71833397b83SGeliang Tang				local arr=($line)
719bccefb76SGeliang Tang				local nr=0
720f0140386SGeliang Tang				local id
72133397b83SGeliang Tang
72233397b83SGeliang Tang				for i in ${arr[@]}; do
723bccefb76SGeliang Tang					if [ $i = "id" ]; then
724bccefb76SGeliang Tang						id=${arr[$nr+1]}
725718eb44eSGeliang Tang					fi
726bccefb76SGeliang Tang					let nr+=1
72733397b83SGeliang Tang				done
728bccefb76SGeliang Tang				pm_nl_change_endpoint $netns $id $sflags
72933397b83SGeliang Tang			done
730718eb44eSGeliang Tang		done
731718eb44eSGeliang Tang	fi
732718eb44eSGeliang Tang
733b08fbf24SPaolo Abeni	wait $cpid
734b08fbf24SPaolo Abeni	retc=$?
735b08fbf24SPaolo Abeni	wait $spid
736b08fbf24SPaolo Abeni	rets=$?
737b08fbf24SPaolo Abeni
738b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
739b08fbf24SPaolo Abeni	    sleep 1
740b08fbf24SPaolo Abeni	    kill $cappid
741b08fbf24SPaolo Abeni	fi
742b08fbf24SPaolo Abeni
743c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
744c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${listener_ns}.out
745c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
746c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${connector_ns}.out
747c2a55e8fSMatthieu Baerts
748b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
749b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
7508b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
751c2a55e8fSMatthieu Baerts		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
752c2a55e8fSMatthieu Baerts		cat /tmp/${listener_ns}.out
7538b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
754c2a55e8fSMatthieu Baerts		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
755c2a55e8fSMatthieu Baerts		cat /tmp/${connector_ns}.out
756b08fbf24SPaolo Abeni
757b08fbf24SPaolo Abeni		cat "$capout"
7588b819a84SFlorian Westphal		ret=1
759b08fbf24SPaolo Abeni		return 1
760b08fbf24SPaolo Abeni	fi
761b08fbf24SPaolo Abeni
76234b572b7SGeliang Tang	if [ "$test_link_fail" -gt 1 ];then
7637d1e6f16SPaolo Abeni		check_transfer $sinfail $cout "file received by client"
7647d1e6f16SPaolo Abeni	else
765b08fbf24SPaolo Abeni		check_transfer $sin $cout "file received by client"
7667d1e6f16SPaolo Abeni	fi
767b08fbf24SPaolo Abeni	retc=$?
7688b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
769b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
7708b819a84SFlorian Westphal	else
7718b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
7728b819a84SFlorian Westphal	fi
773b08fbf24SPaolo Abeni	rets=$?
774b08fbf24SPaolo Abeni
775b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
776b08fbf24SPaolo Abeni		cat "$capout"
777b08fbf24SPaolo Abeni		return 0
778b08fbf24SPaolo Abeni	fi
779b08fbf24SPaolo Abeni
780b08fbf24SPaolo Abeni	cat "$capout"
781b08fbf24SPaolo Abeni	return 1
782b08fbf24SPaolo Abeni}
783b08fbf24SPaolo Abeni
784b08fbf24SPaolo Abenimake_file()
785b08fbf24SPaolo Abeni{
786b08fbf24SPaolo Abeni	name=$1
787b08fbf24SPaolo Abeni	who=$2
7888b819a84SFlorian Westphal	size=$3
789b08fbf24SPaolo Abeni
7908b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
791b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
792b08fbf24SPaolo Abeni
7938b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
794b08fbf24SPaolo Abeni}
795b08fbf24SPaolo Abeni
796b08fbf24SPaolo Abenirun_tests()
797b08fbf24SPaolo Abeni{
798b08fbf24SPaolo Abeni	listener_ns="$1"
799b08fbf24SPaolo Abeni	connector_ns="$2"
800b08fbf24SPaolo Abeni	connect_addr="$3"
8018b819a84SFlorian Westphal	test_linkfail="${4:-0}"
8022e8cbf45SGeliang Tang	addr_nr_ns1="${5:-0}"
8032e8cbf45SGeliang Tang	addr_nr_ns2="${6:-0}"
8048b819a84SFlorian Westphal	speed="${7:-fast}"
8056a0653b9SGeliang Tang	sflags="${8:-""}"
8068b819a84SFlorian Westphal
80734b572b7SGeliang Tang	# The values above 2 are reused to make test files
80834b572b7SGeliang Tang	# with the given sizes (KB)
80934b572b7SGeliang Tang	if [ "$test_linkfail" -gt 2 ]; then
81034b572b7SGeliang Tang		size=$test_linkfail
81134b572b7SGeliang Tang
81234b572b7SGeliang Tang		if [ -z "$cinfail" ]; then
81334b572b7SGeliang Tang			cinfail=$(mktemp)
81434b572b7SGeliang Tang		fi
81534b572b7SGeliang Tang		make_file "$cinfail" "client" $size
8167d1e6f16SPaolo Abeni	# create the input file for the failure test when
8177d1e6f16SPaolo Abeni	# the first failure test run
81834b572b7SGeliang Tang	elif [ "$test_linkfail" -ne 0 -a -z "$cinfail" ]; then
8197d1e6f16SPaolo Abeni		# the client file must be considerably larger
8207d1e6f16SPaolo Abeni		# of the maximum expected cwin value, or the
8217d1e6f16SPaolo Abeni		# link utilization will be not predicable
8227d1e6f16SPaolo Abeni		size=$((RANDOM%2))
8238b819a84SFlorian Westphal		size=$((size+1))
8247d1e6f16SPaolo Abeni		size=$((size*8192))
8257d1e6f16SPaolo Abeni		size=$((size + ( $RANDOM % 8192) ))
8268b819a84SFlorian Westphal
8277d1e6f16SPaolo Abeni		cinfail=$(mktemp)
8287d1e6f16SPaolo Abeni		make_file "$cinfail" "client" $size
8297d1e6f16SPaolo Abeni	fi
8307d1e6f16SPaolo Abeni
83134b572b7SGeliang Tang	if [ "$test_linkfail" -gt 2 ]; then
83234b572b7SGeliang Tang		size=$test_linkfail
83334b572b7SGeliang Tang
83434b572b7SGeliang Tang		if [ -z "$sinfail" ]; then
83534b572b7SGeliang Tang			sinfail=$(mktemp)
83634b572b7SGeliang Tang		fi
83734b572b7SGeliang Tang		make_file "$sinfail" "server" $size
83834b572b7SGeliang Tang	elif [ "$test_linkfail" -eq 2 -a -z "$sinfail" ]; then
8397d1e6f16SPaolo Abeni		size=$((RANDOM%16))
8407d1e6f16SPaolo Abeni		size=$((size+1))
8417d1e6f16SPaolo Abeni		size=$((size*2048))
8427d1e6f16SPaolo Abeni
8437d1e6f16SPaolo Abeni		sinfail=$(mktemp)
8447d1e6f16SPaolo Abeni		make_file "$sinfail" "server" $size
8458b819a84SFlorian Westphal	fi
846b08fbf24SPaolo Abeni
8478d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
8486a0653b9SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${sflags}
849b08fbf24SPaolo Abeni}
850b08fbf24SPaolo Abeni
851327b9a94SPaolo Abenidump_stats()
852327b9a94SPaolo Abeni{
853327b9a94SPaolo Abeni	echo Server ns stats
854327b9a94SPaolo Abeni	ip netns exec $ns1 nstat -as | grep Tcp
855327b9a94SPaolo Abeni	echo Client ns stats
856327b9a94SPaolo Abeni	ip netns exec $ns2 nstat -as | grep Tcp
857327b9a94SPaolo Abeni}
858327b9a94SPaolo Abeni
859af66d3e1SGeliang Tangchk_csum_nr()
860af66d3e1SGeliang Tang{
8613c082695SGeliang Tang	local csum_ns1=${1:-0}
8623c082695SGeliang Tang	local csum_ns2=${2:-0}
863af66d3e1SGeliang Tang	local count
864af66d3e1SGeliang Tang	local dump_stats
86526516e10SGeliang Tang	local allow_multi_errors_ns1=0
86626516e10SGeliang Tang	local allow_multi_errors_ns2=0
86726516e10SGeliang Tang
86826516e10SGeliang Tang	if [[ "${csum_ns1}" = "+"* ]]; then
86926516e10SGeliang Tang		allow_multi_errors_ns1=1
87026516e10SGeliang Tang		csum_ns1=${csum_ns1:1}
87126516e10SGeliang Tang	fi
87226516e10SGeliang Tang	if [[ "${csum_ns2}" = "+"* ]]; then
87326516e10SGeliang Tang		allow_multi_errors_ns2=1
87426516e10SGeliang Tang		csum_ns2=${csum_ns2:1}
87526516e10SGeliang Tang	fi
876af66d3e1SGeliang Tang
8773c082695SGeliang Tang	printf "%-${nr_blank}s %s" " " "sum"
878af66d3e1SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
879af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
88026516e10SGeliang Tang	if [ "$count" != $csum_ns1 -a $allow_multi_errors_ns1 -eq 0 ] ||
88126516e10SGeliang Tang	   [ "$count" -lt $csum_ns1 -a $allow_multi_errors_ns1 -eq 1 ]; then
88226516e10SGeliang Tang		echo "[fail] got $count data checksum error[s] expected $csum_ns1"
883af66d3e1SGeliang Tang		ret=1
884af66d3e1SGeliang Tang		dump_stats=1
885af66d3e1SGeliang Tang	else
886af66d3e1SGeliang Tang		echo -n "[ ok ]"
887af66d3e1SGeliang Tang	fi
888af66d3e1SGeliang Tang	echo -n " - csum  "
889af66d3e1SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
890af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
89126516e10SGeliang Tang	if [ "$count" != $csum_ns2 -a $allow_multi_errors_ns2 -eq 0 ] ||
89226516e10SGeliang Tang	   [ "$count" -lt $csum_ns2 -a $allow_multi_errors_ns2 -eq 1 ]; then
89326516e10SGeliang Tang		echo "[fail] got $count data checksum error[s] expected $csum_ns2"
894af66d3e1SGeliang Tang		ret=1
895af66d3e1SGeliang Tang		dump_stats=1
896af66d3e1SGeliang Tang	else
897af66d3e1SGeliang Tang		echo "[ ok ]"
898af66d3e1SGeliang Tang	fi
899327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
900af66d3e1SGeliang Tang}
901af66d3e1SGeliang Tang
9026bb3ab49SGeliang Tangchk_fail_nr()
9036bb3ab49SGeliang Tang{
90426516e10SGeliang Tang	local fail_tx=$1
90526516e10SGeliang Tang	local fail_rx=$2
9066bb3ab49SGeliang Tang	local count
9076bb3ab49SGeliang Tang	local dump_stats
9086bb3ab49SGeliang Tang
9099a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "ftx"
9106bb3ab49SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}'`
9116bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
91226516e10SGeliang Tang	if [ "$count" != "$fail_tx" ]; then
91326516e10SGeliang Tang		echo "[fail] got $count MP_FAIL[s] TX expected $fail_tx"
9146bb3ab49SGeliang Tang		ret=1
9156bb3ab49SGeliang Tang		dump_stats=1
9166bb3ab49SGeliang Tang	else
9176bb3ab49SGeliang Tang		echo -n "[ ok ]"
9186bb3ab49SGeliang Tang	fi
9196bb3ab49SGeliang Tang
92026516e10SGeliang Tang	echo -n " - failrx"
9216bb3ab49SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}'`
9226bb3ab49SGeliang Tang	[ -z "$count" ] && count=0
92326516e10SGeliang Tang	if [ "$count" != "$fail_rx" ]; then
92426516e10SGeliang Tang		echo "[fail] got $count MP_FAIL[s] RX expected $fail_rx"
9256bb3ab49SGeliang Tang		ret=1
9266bb3ab49SGeliang Tang		dump_stats=1
9276bb3ab49SGeliang Tang	else
9286bb3ab49SGeliang Tang		echo "[ ok ]"
9296bb3ab49SGeliang Tang	fi
9306bb3ab49SGeliang Tang
931327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
9326bb3ab49SGeliang Tang}
9336bb3ab49SGeliang Tang
934e8e947efSGeliang Tangchk_fclose_nr()
935e8e947efSGeliang Tang{
936e8e947efSGeliang Tang	local fclose_tx=$1
937e8e947efSGeliang Tang	local fclose_rx=$2
938e8e947efSGeliang Tang	local count
939e8e947efSGeliang Tang	local dump_stats
940e8e947efSGeliang Tang
941e8e947efSGeliang Tang	printf "%-${nr_blank}s %s" " " "ctx"
942e8e947efSGeliang Tang	count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPFastcloseTx | awk '{print $2}')
943e8e947efSGeliang Tang	[ -z "$count" ] && count=0
944e8e947efSGeliang Tang	if [ "$count" != "$fclose_tx" ]; then
945e8e947efSGeliang Tang		echo "[fail] got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
946e8e947efSGeliang Tang		ret=1
947e8e947efSGeliang Tang		dump_stats=1
948e8e947efSGeliang Tang	else
949e8e947efSGeliang Tang		echo -n "[ ok ]"
950e8e947efSGeliang Tang	fi
951e8e947efSGeliang Tang
952e8e947efSGeliang Tang	echo -n " - fclzrx"
953e8e947efSGeliang Tang	count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPFastcloseRx | awk '{print $2}')
954e8e947efSGeliang Tang	[ -z "$count" ] && count=0
955e8e947efSGeliang Tang	if [ "$count" != "$fclose_rx" ]; then
956e8e947efSGeliang Tang		echo "[fail] got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
957e8e947efSGeliang Tang		ret=1
958e8e947efSGeliang Tang		dump_stats=1
959e8e947efSGeliang Tang	else
960e8e947efSGeliang Tang		echo "[ ok ]"
961e8e947efSGeliang Tang	fi
962e8e947efSGeliang Tang
963e8e947efSGeliang Tang	[ "${dump_stats}" = 1 ] && dump_stats
964e8e947efSGeliang Tang}
965e8e947efSGeliang Tang
966922fd2b3SGeliang Tangchk_rst_nr()
967922fd2b3SGeliang Tang{
968922fd2b3SGeliang Tang	local rst_tx=$1
969922fd2b3SGeliang Tang	local rst_rx=$2
970922fd2b3SGeliang Tang	local ns_invert=${3:-""}
971922fd2b3SGeliang Tang	local count
972922fd2b3SGeliang Tang	local dump_stats
973922fd2b3SGeliang Tang	local ns_tx=$ns1
974922fd2b3SGeliang Tang	local ns_rx=$ns2
975922fd2b3SGeliang Tang	local extra_msg=""
976922fd2b3SGeliang Tang
977922fd2b3SGeliang Tang	if [[ $ns_invert = "invert" ]]; then
978922fd2b3SGeliang Tang		ns_tx=$ns2
979922fd2b3SGeliang Tang		ns_rx=$ns1
980922fd2b3SGeliang Tang		extra_msg="   invert"
981922fd2b3SGeliang Tang	fi
982922fd2b3SGeliang Tang
983922fd2b3SGeliang Tang	printf "%-${nr_blank}s %s" " " "rtx"
984922fd2b3SGeliang Tang	count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPRstTx | awk '{print $2}')
985922fd2b3SGeliang Tang	[ -z "$count" ] && count=0
986922fd2b3SGeliang Tang	if [ "$count" != "$rst_tx" ]; then
987922fd2b3SGeliang Tang		echo "[fail] got $count MP_RST[s] TX expected $rst_tx"
988922fd2b3SGeliang Tang		ret=1
989922fd2b3SGeliang Tang		dump_stats=1
990922fd2b3SGeliang Tang	else
991922fd2b3SGeliang Tang		echo -n "[ ok ]"
992922fd2b3SGeliang Tang	fi
993922fd2b3SGeliang Tang
994922fd2b3SGeliang Tang	echo -n " - rstrx "
995922fd2b3SGeliang Tang	count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPRstRx | awk '{print $2}')
996922fd2b3SGeliang Tang	[ -z "$count" ] && count=0
997922fd2b3SGeliang Tang	if [ "$count" != "$rst_rx" ]; then
998922fd2b3SGeliang Tang		echo "[fail] got $count MP_RST[s] RX expected $rst_rx"
999922fd2b3SGeliang Tang		ret=1
1000922fd2b3SGeliang Tang		dump_stats=1
1001922fd2b3SGeliang Tang	else
1002922fd2b3SGeliang Tang		echo -n "[ ok ]"
1003922fd2b3SGeliang Tang	fi
1004922fd2b3SGeliang Tang
1005922fd2b3SGeliang Tang	[ "${dump_stats}" = 1 ] && dump_stats
1006922fd2b3SGeliang Tang
1007922fd2b3SGeliang Tang	echo "$extra_msg"
1008922fd2b3SGeliang Tang}
1009922fd2b3SGeliang Tang
1010b08fbf24SPaolo Abenichk_join_nr()
1011b08fbf24SPaolo Abeni{
1012b08fbf24SPaolo Abeni	local msg="$1"
1013b08fbf24SPaolo Abeni	local syn_nr=$2
1014b08fbf24SPaolo Abeni	local syn_ack_nr=$3
1015b08fbf24SPaolo Abeni	local ack_nr=$4
101626516e10SGeliang Tang	local csum_ns1=${5:-0}
101726516e10SGeliang Tang	local csum_ns2=${6:-0}
101826516e10SGeliang Tang	local fail_nr=${7:-0}
101926516e10SGeliang Tang	local rst_nr=${8:-0}
1020b08fbf24SPaolo Abeni	local count
1021b08fbf24SPaolo Abeni	local dump_stats
1022e35f885bSPaolo Abeni	local with_cookie
1023b08fbf24SPaolo Abeni
10249a0a9367SGeliang Tang	printf "%03u %-36s %s" "$TEST_COUNT" "$msg" "syn"
1025b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
1026b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1027b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
1028b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
1029b08fbf24SPaolo Abeni		ret=1
1030b08fbf24SPaolo Abeni		dump_stats=1
1031b08fbf24SPaolo Abeni	else
1032b08fbf24SPaolo Abeni		echo -n "[ ok ]"
1033b08fbf24SPaolo Abeni	fi
1034b08fbf24SPaolo Abeni
1035b08fbf24SPaolo Abeni	echo -n " - synack"
1036e35f885bSPaolo Abeni	with_cookie=`ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies`
1037b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
1038b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1039b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
1040e35f885bSPaolo Abeni		# simult connections exceeding the limit with cookie enabled could go up to
1041e35f885bSPaolo Abeni		# synack validation as the conn limit can be enforced reliably only after
1042e35f885bSPaolo Abeni		# the subflow creation
1043e35f885bSPaolo Abeni		if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then
1044e35f885bSPaolo Abeni			echo -n "[ ok ]"
1045e35f885bSPaolo Abeni		else
1046b08fbf24SPaolo Abeni			echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
1047b08fbf24SPaolo Abeni			ret=1
1048b08fbf24SPaolo Abeni			dump_stats=1
1049e35f885bSPaolo Abeni		fi
1050b08fbf24SPaolo Abeni	else
1051b08fbf24SPaolo Abeni		echo -n "[ ok ]"
1052b08fbf24SPaolo Abeni	fi
1053b08fbf24SPaolo Abeni
1054b08fbf24SPaolo Abeni	echo -n " - ack"
1055b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
1056b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
1057b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
1058b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
1059b08fbf24SPaolo Abeni		ret=1
1060b08fbf24SPaolo Abeni		dump_stats=1
1061b08fbf24SPaolo Abeni	else
1062b08fbf24SPaolo Abeni		echo "[ ok ]"
1063b08fbf24SPaolo Abeni	fi
1064327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1065af66d3e1SGeliang Tang	if [ $checksum -eq 1 ]; then
10663c082695SGeliang Tang		chk_csum_nr $csum_ns1 $csum_ns2
106726516e10SGeliang Tang		chk_fail_nr $fail_nr $fail_nr
106826516e10SGeliang Tang		chk_rst_nr $rst_nr $rst_nr
1069af66d3e1SGeliang Tang	fi
1070b08fbf24SPaolo Abeni}
1071b08fbf24SPaolo Abeni
10727d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound:
10737d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while
10747d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of
10757d1e6f16SPaolo Abeni# stale/recover conversions, proportional to
10767d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval.
10777d1e6f16SPaolo Abenichk_stale_nr()
10787d1e6f16SPaolo Abeni{
10797d1e6f16SPaolo Abeni	local ns=$1
10807d1e6f16SPaolo Abeni	local stale_min=$2
10817d1e6f16SPaolo Abeni	local stale_max=$3
10827d1e6f16SPaolo Abeni	local stale_delta=$4
10837d1e6f16SPaolo Abeni	local dump_stats
10847d1e6f16SPaolo Abeni	local stale_nr
10857d1e6f16SPaolo Abeni	local recover_nr
10867d1e6f16SPaolo Abeni
10879a0a9367SGeliang Tang	printf "%-${nr_blank}s %-18s" " " "stale"
10887d1e6f16SPaolo Abeni	stale_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}'`
10897d1e6f16SPaolo Abeni	[ -z "$stale_nr" ] && stale_nr=0
10907d1e6f16SPaolo Abeni	recover_nr=`ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}'`
10917d1e6f16SPaolo Abeni	[ -z "$recover_nr" ] && recover_nr=0
10927d1e6f16SPaolo Abeni
10937d1e6f16SPaolo Abeni	if [ $stale_nr -lt $stale_min ] ||
10947d1e6f16SPaolo Abeni	   [ $stale_max -gt 0 -a $stale_nr -gt $stale_max ] ||
10957d1e6f16SPaolo Abeni	   [ $((stale_nr - $recover_nr)) -ne $stale_delta ]; then
10967d1e6f16SPaolo Abeni		echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \
10977d1e6f16SPaolo Abeni		     " expected stale in range [$stale_min..$stale_max]," \
10987d1e6f16SPaolo Abeni		     " stale-recover delta $stale_delta "
10997d1e6f16SPaolo Abeni		ret=1
11007d1e6f16SPaolo Abeni		dump_stats=1
11017d1e6f16SPaolo Abeni	else
11027d1e6f16SPaolo Abeni		echo "[ ok ]"
11037d1e6f16SPaolo Abeni	fi
11047d1e6f16SPaolo Abeni
11057d1e6f16SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
11067d1e6f16SPaolo Abeni		echo $ns stats
11077d1e6f16SPaolo Abeni		ip netns exec $ns ip -s link show
11087d1e6f16SPaolo Abeni		ip netns exec $ns nstat -as | grep MPTcp
11097d1e6f16SPaolo Abeni	fi
11107d1e6f16SPaolo Abeni}
11117d1e6f16SPaolo Abeni
1112be613160SGeliang Tangchk_add_nr()
1113be613160SGeliang Tang{
1114be613160SGeliang Tang	local add_nr=$1
1115be613160SGeliang Tang	local echo_nr=$2
11168a127bf6SGeliang Tang	local port_nr=${3:-0}
11178a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
11188a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
11198a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
11208a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
11218a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
1122be613160SGeliang Tang	local count
1123be613160SGeliang Tang	local dump_stats
11246ef84b15SPaolo Abeni	local timeout
11256ef84b15SPaolo Abeni
11266ef84b15SPaolo Abeni	timeout=`ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout`
1127be613160SGeliang Tang
11289a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "add"
11296ef84b15SPaolo Abeni	count=`ip netns exec $ns2 nstat -as MPTcpExtAddAddr | grep MPTcpExtAddAddr | awk '{print $2}'`
1130be613160SGeliang Tang	[ -z "$count" ] && count=0
11316ef84b15SPaolo Abeni
11326ef84b15SPaolo Abeni	# if the test configured a short timeout tolerate greater then expected
11336ef84b15SPaolo Abeni	# add addrs options, due to retransmissions
11346ef84b15SPaolo Abeni	if [ "$count" != "$add_nr" ] && [ "$timeout" -gt 1 -o "$count" -lt "$add_nr" ]; then
1135be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
1136be613160SGeliang Tang		ret=1
1137be613160SGeliang Tang		dump_stats=1
1138be613160SGeliang Tang	else
1139be613160SGeliang Tang		echo -n "[ ok ]"
1140be613160SGeliang Tang	fi
1141be613160SGeliang Tang
1142be613160SGeliang Tang	echo -n " - echo  "
1143be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
1144be613160SGeliang Tang	[ -z "$count" ] && count=0
1145be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
1146be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
1147be613160SGeliang Tang		ret=1
1148be613160SGeliang Tang		dump_stats=1
1149be613160SGeliang Tang	else
11508a127bf6SGeliang Tang		echo -n "[ ok ]"
11518a127bf6SGeliang Tang	fi
11528a127bf6SGeliang Tang
11538a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
11548a127bf6SGeliang Tang		echo -n " - pt "
11558a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
11568a127bf6SGeliang Tang		[ -z "$count" ] && count=0
11578a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
11588a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
11598a127bf6SGeliang Tang			ret=1
11608a127bf6SGeliang Tang			dump_stats=1
11618a127bf6SGeliang Tang		else
1162be613160SGeliang Tang			echo "[ ok ]"
1163be613160SGeliang Tang		fi
1164be613160SGeliang Tang
11659a0a9367SGeliang Tang		printf "%-${nr_blank}s %s" " " "syn"
11668a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
11678a127bf6SGeliang Tang			awk '{print $2}'`
11688a127bf6SGeliang Tang		[ -z "$count" ] && count=0
11698a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
11708a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
11718a127bf6SGeliang Tang				port-number expected $syn_nr"
11728a127bf6SGeliang Tang			ret=1
11738a127bf6SGeliang Tang			dump_stats=1
11748a127bf6SGeliang Tang		else
11758a127bf6SGeliang Tang			echo -n "[ ok ]"
11768a127bf6SGeliang Tang		fi
11778a127bf6SGeliang Tang
11788a127bf6SGeliang Tang		echo -n " - synack"
11798a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
11808a127bf6SGeliang Tang			awk '{print $2}'`
11818a127bf6SGeliang Tang		[ -z "$count" ] && count=0
11828a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
11838a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
11848a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
11858a127bf6SGeliang Tang			ret=1
11868a127bf6SGeliang Tang			dump_stats=1
11878a127bf6SGeliang Tang		else
11888a127bf6SGeliang Tang			echo -n "[ ok ]"
11898a127bf6SGeliang Tang		fi
11908a127bf6SGeliang Tang
11918a127bf6SGeliang Tang		echo -n " - ack"
11928a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
11938a127bf6SGeliang Tang			awk '{print $2}'`
11948a127bf6SGeliang Tang		[ -z "$count" ] && count=0
11958a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
11968a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
11978a127bf6SGeliang Tang				port-number expected $ack_nr"
11988a127bf6SGeliang Tang			ret=1
11998a127bf6SGeliang Tang			dump_stats=1
12008a127bf6SGeliang Tang		else
12018a127bf6SGeliang Tang			echo "[ ok ]"
12028a127bf6SGeliang Tang		fi
12038a127bf6SGeliang Tang
12049a0a9367SGeliang Tang		printf "%-${nr_blank}s %s" " " "syn"
12058a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
12068a127bf6SGeliang Tang			awk '{print $2}'`
12078a127bf6SGeliang Tang		[ -z "$count" ] && count=0
12088a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
12098a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
12108a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
12118a127bf6SGeliang Tang			ret=1
12128a127bf6SGeliang Tang			dump_stats=1
12138a127bf6SGeliang Tang		else
12148a127bf6SGeliang Tang			echo -n "[ ok ]"
12158a127bf6SGeliang Tang		fi
12168a127bf6SGeliang Tang
12178a127bf6SGeliang Tang		echo -n " - ack   "
12188a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
12198a127bf6SGeliang Tang			awk '{print $2}'`
12208a127bf6SGeliang Tang		[ -z "$count" ] && count=0
12218a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
12228a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
12238a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
12248a127bf6SGeliang Tang			ret=1
12258a127bf6SGeliang Tang			dump_stats=1
12268a127bf6SGeliang Tang		else
12278a127bf6SGeliang Tang			echo "[ ok ]"
12288a127bf6SGeliang Tang		fi
12298a127bf6SGeliang Tang	else
12308a127bf6SGeliang Tang		echo ""
12318a127bf6SGeliang Tang	fi
12328a127bf6SGeliang Tang
1233327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1234be613160SGeliang Tang}
1235be613160SGeliang Tang
1236dd72b0feSGeliang Tangchk_rm_nr()
1237dd72b0feSGeliang Tang{
1238dd72b0feSGeliang Tang	local rm_addr_nr=$1
1239dd72b0feSGeliang Tang	local rm_subflow_nr=$2
12406fa0174aSPaolo Abeni	local invert
12416fa0174aSPaolo Abeni	local simult
1242dd72b0feSGeliang Tang	local count
1243dd72b0feSGeliang Tang	local dump_stats
12447d9bf018SGeliang Tang	local addr_ns=$ns1
12457d9bf018SGeliang Tang	local subflow_ns=$ns2
12467d9bf018SGeliang Tang	local extra_msg=""
12477028ba8aSGeliang Tang
12486fa0174aSPaolo Abeni	shift 2
12496fa0174aSPaolo Abeni	while [ -n "$1" ]; do
12506fa0174aSPaolo Abeni		[ "$1" = "invert" ] && invert=true
12516fa0174aSPaolo Abeni		[ "$1" = "simult" ] && simult=true
12526fa0174aSPaolo Abeni		shift
12536fa0174aSPaolo Abeni	done
12546fa0174aSPaolo Abeni
12556fa0174aSPaolo Abeni	if [ -z $invert ]; then
12566fa0174aSPaolo Abeni		addr_ns=$ns1
12576fa0174aSPaolo Abeni		subflow_ns=$ns2
12586fa0174aSPaolo Abeni	elif [ $invert = "true" ]; then
12597028ba8aSGeliang Tang		addr_ns=$ns2
12607028ba8aSGeliang Tang		subflow_ns=$ns1
12617d9bf018SGeliang Tang		extra_msg="   invert"
12627028ba8aSGeliang Tang	fi
1263dd72b0feSGeliang Tang
12649a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "rm "
12657028ba8aSGeliang Tang	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
1266dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
1267dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
1268dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
1269dd72b0feSGeliang Tang		ret=1
1270dd72b0feSGeliang Tang		dump_stats=1
1271dd72b0feSGeliang Tang	else
1272dd72b0feSGeliang Tang		echo -n "[ ok ]"
1273dd72b0feSGeliang Tang	fi
1274dd72b0feSGeliang Tang
12757d9bf018SGeliang Tang	echo -n " - rmsf  "
12767028ba8aSGeliang Tang	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
1277dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
12786fa0174aSPaolo Abeni	if [ -n "$simult" ]; then
12796fa0174aSPaolo Abeni		local cnt=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}')
12806fa0174aSPaolo Abeni		local suffix
12816fa0174aSPaolo Abeni
12826fa0174aSPaolo Abeni		# in case of simult flush, the subflow removal count on each side is
12836fa0174aSPaolo Abeni		# unreliable
12846fa0174aSPaolo Abeni		[ -z "$cnt" ] && cnt=0
12856fa0174aSPaolo Abeni		count=$((count + cnt))
12866fa0174aSPaolo Abeni		[ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
12876fa0174aSPaolo Abeni		if [ $count -ge "$rm_subflow_nr" ] && \
12886fa0174aSPaolo Abeni		   [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
12896fa0174aSPaolo Abeni			echo "[ ok ] $suffix"
12906fa0174aSPaolo Abeni		else
12916fa0174aSPaolo Abeni			echo "[fail] got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]"
12926fa0174aSPaolo Abeni			ret=1
12936fa0174aSPaolo Abeni			dump_stats=1
12946fa0174aSPaolo Abeni		fi
12956fa0174aSPaolo Abeni		return
12966fa0174aSPaolo Abeni	fi
1297dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
1298dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
1299dd72b0feSGeliang Tang		ret=1
1300dd72b0feSGeliang Tang		dump_stats=1
1301dd72b0feSGeliang Tang	else
13027d9bf018SGeliang Tang		echo -n "[ ok ]"
1303dd72b0feSGeliang Tang	fi
1304dd72b0feSGeliang Tang
1305327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
13067d9bf018SGeliang Tang
13077d9bf018SGeliang Tang	echo "$extra_msg"
1308dd72b0feSGeliang Tang}
1309dd72b0feSGeliang Tang
1310718eb44eSGeliang Tangchk_prio_nr()
1311718eb44eSGeliang Tang{
1312718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
1313718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
1314718eb44eSGeliang Tang	local count
1315718eb44eSGeliang Tang	local dump_stats
1316718eb44eSGeliang Tang
13179a0a9367SGeliang Tang	printf "%-${nr_blank}s %s" " " "ptx"
1318718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
1319718eb44eSGeliang Tang	[ -z "$count" ] && count=0
1320718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
1321718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
1322718eb44eSGeliang Tang		ret=1
1323718eb44eSGeliang Tang		dump_stats=1
1324718eb44eSGeliang Tang	else
1325718eb44eSGeliang Tang		echo -n "[ ok ]"
1326718eb44eSGeliang Tang	fi
1327718eb44eSGeliang Tang
1328718eb44eSGeliang Tang	echo -n " - prx   "
1329718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
1330718eb44eSGeliang Tang	[ -z "$count" ] && count=0
1331718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
1332718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
1333718eb44eSGeliang Tang		ret=1
1334718eb44eSGeliang Tang		dump_stats=1
1335718eb44eSGeliang Tang	else
1336718eb44eSGeliang Tang		echo "[ ok ]"
1337718eb44eSGeliang Tang	fi
1338718eb44eSGeliang Tang
1339327b9a94SPaolo Abeni	[ "${dump_stats}" = 1 ] && dump_stats
1340718eb44eSGeliang Tang}
1341718eb44eSGeliang Tang
13427d1e6f16SPaolo Abenichk_link_usage()
13437d1e6f16SPaolo Abeni{
13447d1e6f16SPaolo Abeni	local ns=$1
13457d1e6f16SPaolo Abeni	local link=$2
13467d1e6f16SPaolo Abeni	local out=$3
13477d1e6f16SPaolo Abeni	local expected_rate=$4
13487d1e6f16SPaolo Abeni	local tx_link=`ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes`
13497d1e6f16SPaolo Abeni	local tx_total=`ls -l $out | awk '{print $5}'`
13507d1e6f16SPaolo Abeni	local tx_rate=$((tx_link * 100 / $tx_total))
13517d1e6f16SPaolo Abeni	local tolerance=5
13527d1e6f16SPaolo Abeni
13539a0a9367SGeliang Tang	printf "%-${nr_blank}s %-18s" " " "link usage"
13547d1e6f16SPaolo Abeni	if [ $tx_rate -lt $((expected_rate - $tolerance)) -o \
13557d1e6f16SPaolo Abeni	     $tx_rate -gt $((expected_rate + $tolerance)) ]; then
13567d1e6f16SPaolo Abeni		echo "[fail] got $tx_rate% usage, expected $expected_rate%"
13577d1e6f16SPaolo Abeni		ret=1
13587d1e6f16SPaolo Abeni	else
13597d1e6f16SPaolo Abeni		echo "[ ok ]"
13607d1e6f16SPaolo Abeni	fi
13617d1e6f16SPaolo Abeni}
13627d1e6f16SPaolo Abeni
1363f98c2bcaSMat Martineauwait_attempt_fail()
136446e967d1SPaolo Abeni{
136546e967d1SPaolo Abeni	local timeout_ms=$((timeout_poll * 1000))
136646e967d1SPaolo Abeni	local time=0
136746e967d1SPaolo Abeni	local ns=$1
136846e967d1SPaolo Abeni
136946e967d1SPaolo Abeni	while [ $time -lt $timeout_ms ]; do
13705b31dda7SPaolo Abeni		local cnt=$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFails | awk '{print $2}')
137146e967d1SPaolo Abeni
137246e967d1SPaolo Abeni		[ "$cnt" = 1 ] && return 1
137346e967d1SPaolo Abeni		time=$((time + 100))
137446e967d1SPaolo Abeni		sleep 0.1
137546e967d1SPaolo Abeni	done
137646e967d1SPaolo Abeni	return 1
137746e967d1SPaolo Abeni}
137846e967d1SPaolo Abeni
13791002b89fSGeliang Tangsubflows_tests()
13801002b89fSGeliang Tang{
13811002b89fSGeliang Tang	reset
1382b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1383b08fbf24SPaolo Abeni	chk_join_nr "no JOIN" "0" "0" "0"
1384b08fbf24SPaolo Abeni
13851002b89fSGeliang Tang	# subflow limited by client
1386b08fbf24SPaolo Abeni	reset
138734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 0
138834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 0
138934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1390b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1391b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by client" 0 0 0
1392b08fbf24SPaolo Abeni
13931002b89fSGeliang Tang	# subflow limited by server
1394b08fbf24SPaolo Abeni	reset
139534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 0
139634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
139734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1398b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1399b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by server" 1 1 0
1400b08fbf24SPaolo Abeni
1401b08fbf24SPaolo Abeni	# subflow
1402b08fbf24SPaolo Abeni	reset
140334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
140434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
140534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1406b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1407b08fbf24SPaolo Abeni	chk_join_nr "single subflow" 1 1 1
1408b08fbf24SPaolo Abeni
1409b08fbf24SPaolo Abeni	# multiple subflows
1410b08fbf24SPaolo Abeni	reset
141134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
141234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
141334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
141434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1415b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1416b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows" 2 2 2
1417b08fbf24SPaolo Abeni
141872bcbc46SPaolo Abeni	# multiple subflows limited by server
1419b08fbf24SPaolo Abeni	reset
142034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
142134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
142234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
142334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
1424b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1425b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows, limited by server" 2 2 1
1426c3eaa5f6SGeliang Tang
1427c3eaa5f6SGeliang Tang	# single subflow, dev
1428c3eaa5f6SGeliang Tang	reset
142934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
143034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
143134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3
1432c3eaa5f6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1433c3eaa5f6SGeliang Tang	chk_join_nr "single subflow, dev" 1 1 1
14341002b89fSGeliang Tang}
1435b08fbf24SPaolo Abeni
143646e967d1SPaolo Abenisubflows_error_tests()
143746e967d1SPaolo Abeni{
143846e967d1SPaolo Abeni	# If a single subflow is configured, and matches the MPC src
143946e967d1SPaolo Abeni	# address, no additional subflow should be created
144046e967d1SPaolo Abeni	reset
144134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
144234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
144334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow
144446e967d1SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
144546e967d1SPaolo Abeni	chk_join_nr "no MPC reuse with single endpoint" 0 0 0
144646e967d1SPaolo Abeni
144746e967d1SPaolo Abeni	# multiple subflows, with subflow creation error
144846e967d1SPaolo Abeni	reset
144934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
145034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
145134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
145234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
145346e967d1SPaolo Abeni	ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j REJECT
145446e967d1SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
145546e967d1SPaolo Abeni	chk_join_nr "multi subflows, with failing subflow" 1 1 1
145646e967d1SPaolo Abeni
145746e967d1SPaolo Abeni	# multiple subflows, with subflow timeout on MPJ
145846e967d1SPaolo Abeni	reset
145934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
146034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
146134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
146234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
146346e967d1SPaolo Abeni	ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j DROP
146446e967d1SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
146546e967d1SPaolo Abeni	chk_join_nr "multi subflows, with subflow timeout" 1 1 1
146646e967d1SPaolo Abeni
146746e967d1SPaolo Abeni	# multiple subflows, check that the endpoint corresponding to
146846e967d1SPaolo Abeni	# closed subflow (due to reset) is not reused if additional
146946e967d1SPaolo Abeni	# subflows are added later
147046e967d1SPaolo Abeni	reset
147134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
147234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
147334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
147446e967d1SPaolo Abeni	ip netns exec $ns1 iptables -A INPUT -s 10.0.3.2 -p tcp -j REJECT
147546e967d1SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow &
147646e967d1SPaolo Abeni
147746e967d1SPaolo Abeni	# updates in the child shell do not have any effect here, we
147846e967d1SPaolo Abeni	# need to bump the test counter for the above case
147946e967d1SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
148046e967d1SPaolo Abeni
148146e967d1SPaolo Abeni	# mpj subflow will be in TW after the reset
1482f98c2bcaSMat Martineau	wait_attempt_fail $ns2
148334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
148446e967d1SPaolo Abeni	wait
148546e967d1SPaolo Abeni
148646e967d1SPaolo Abeni	# additional subflow could be created only if the PM select
148746e967d1SPaolo Abeni	# the later endpoint, skipping the already used one
148846e967d1SPaolo Abeni	chk_join_nr "multi subflows, fair usage on close" 1 1 1
148946e967d1SPaolo Abeni}
149046e967d1SPaolo Abeni
14911002b89fSGeliang Tangsignal_address_tests()
14921002b89fSGeliang Tang{
1493b08fbf24SPaolo Abeni	# add_address, unused
1494b08fbf24SPaolo Abeni	reset
149534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
1496b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1497b08fbf24SPaolo Abeni	chk_join_nr "unused signal address" 0 0 0
1498be613160SGeliang Tang	chk_add_nr 1 1
1499b08fbf24SPaolo Abeni
1500b08fbf24SPaolo Abeni	# accept and use add_addr
1501b08fbf24SPaolo Abeni	reset
150234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
150334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
150434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
1505b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1506b08fbf24SPaolo Abeni	chk_join_nr "signal address" 1 1 1
1507be613160SGeliang Tang	chk_add_nr 1 1
1508b08fbf24SPaolo Abeni
1509b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
1510b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
1511b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
1512b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
1513b08fbf24SPaolo Abeni	reset
151434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
151534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
151634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
151734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1518b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1519b08fbf24SPaolo Abeni	chk_join_nr "subflow and signal" 2 2 2
1520be613160SGeliang Tang	chk_add_nr 1 1
1521b08fbf24SPaolo Abeni
1522b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
1523b08fbf24SPaolo Abeni	reset
152434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
152534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
152634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
152734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
152834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
1529b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
1530b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows and signal" 3 3 3
1531be613160SGeliang Tang	chk_add_nr 1 1
1532ef360019SGeliang Tang
1533ef360019SGeliang Tang	# signal addresses
1534ef360019SGeliang Tang	reset
153534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
153634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
153734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
153834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
153934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1540ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1541ef360019SGeliang Tang	chk_join_nr "signal addresses" 3 3 3
1542ef360019SGeliang Tang	chk_add_nr 3 3
1543ef360019SGeliang Tang
1544ef360019SGeliang Tang	# signal invalid addresses
1545ef360019SGeliang Tang	reset
154634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
154734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
154834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
154934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
155034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1551ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1552ef360019SGeliang Tang	chk_join_nr "signal invalid addresses" 1 1 1
1553ef360019SGeliang Tang	chk_add_nr 3 3
155433c563adSYonglong Li
155533c563adSYonglong Li	# signal addresses race test
155633c563adSYonglong Li	reset
155734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 4 4
155834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 4 4
155934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.1.1 flags signal
156034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
156134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
156234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
156334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.1.2 flags signal
156434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
156534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags signal
156634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags signal
15676ef84b15SPaolo Abeni
15686ef84b15SPaolo Abeni	# the peer could possibly miss some addr notification, allow retransmission
15696ef84b15SPaolo Abeni	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
15706ef84b15SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
1571857898ebSMatthieu Baerts	chk_join_nr "signal addresses race test" 3 3 3
157286e39e04SPaolo Abeni
157386e39e04SPaolo Abeni	# the server will not signal the address terminating
157486e39e04SPaolo Abeni	# the MPC subflow
157586e39e04SPaolo Abeni	chk_add_nr 3 3
15761002b89fSGeliang Tang}
1577b08fbf24SPaolo Abeni
15781002b89fSGeliang Tanglink_failure_tests()
15791002b89fSGeliang Tang{
15808b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
15818b819a84SFlorian Westphal	reset
15827d1e6f16SPaolo Abeni
15837d1e6f16SPaolo Abeni	# without any b/w limit each veth could spool the packets and get
15847d1e6f16SPaolo Abeni	# them acked at xmit time, so that the corresponding subflow will
15857d1e6f16SPaolo Abeni	# have almost always no outstanding pkts, the scheduler will pick
15867d1e6f16SPaolo Abeni	# always the first subflow and we will have hard time testing
15877d1e6f16SPaolo Abeni	# active backup and link switch-over.
15887d1e6f16SPaolo Abeni	# Let's set some arbitrary (low) virtual link limits.
15897d1e6f16SPaolo Abeni	init_shapers
159034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
159134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
159234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
159334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
159434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
15958b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 1
15968b819a84SFlorian Westphal	chk_join_nr "multiple flows, signal, link failure" 3 3 3
15978b819a84SFlorian Westphal	chk_add_nr 1 1
15987d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 5 1
15997d1e6f16SPaolo Abeni
16007d1e6f16SPaolo Abeni	# accept and use add_addr with additional subflows and link loss
16017d1e6f16SPaolo Abeni	# for bidirectional transfer
16027d1e6f16SPaolo Abeni	reset
16037d1e6f16SPaolo Abeni	init_shapers
160434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
160534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
160634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
160734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow
160834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow
16097d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
16107d1e6f16SPaolo Abeni	chk_join_nr "multi flows, signal, bidi, link fail" 3 3 3
16117d1e6f16SPaolo Abeni	chk_add_nr 1 1
16127d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 1
16137d1e6f16SPaolo Abeni
16147d1e6f16SPaolo Abeni	# 2 subflows plus 1 backup subflow with a lossy link, backup
16157d1e6f16SPaolo Abeni	# will never be used
16167d1e6f16SPaolo Abeni	reset
16177d1e6f16SPaolo Abeni	init_shapers
161834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
161934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
162034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
16217d1e6f16SPaolo Abeni	export FAILING_LINKS="1"
162234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
16237d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
16247d1e6f16SPaolo Abeni	chk_join_nr "backup subflow unused, link failure" 2 2 2
16257d1e6f16SPaolo Abeni	chk_add_nr 1 1
16267d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 0
16277d1e6f16SPaolo Abeni
16287d1e6f16SPaolo Abeni	# 2 lossy links after half transfer, backup will get half of
16297d1e6f16SPaolo Abeni	# the traffic
16307d1e6f16SPaolo Abeni	reset
16317d1e6f16SPaolo Abeni	init_shapers
163234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
163334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
163434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
163534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
16367d1e6f16SPaolo Abeni	export FAILING_LINKS="1 2"
16377d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 1
16387d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, multi links fail" 2 2 2
16397d1e6f16SPaolo Abeni	chk_add_nr 1 1
16407d1e6f16SPaolo Abeni	chk_stale_nr $ns2 2 4 2
16417d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
16427d1e6f16SPaolo Abeni
16437d1e6f16SPaolo Abeni	# use a backup subflow with the first subflow on a lossy link
16447d1e6f16SPaolo Abeni	# for bidirectional transfer
16457d1e6f16SPaolo Abeni	reset
16467d1e6f16SPaolo Abeni	init_shapers
164734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
164834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal
164934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
165034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup
16517d1e6f16SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 2
16527d1e6f16SPaolo Abeni	chk_join_nr "backup flow used, bidi, link failure" 2 2 2
16537d1e6f16SPaolo Abeni	chk_add_nr 1 1
16547d1e6f16SPaolo Abeni	chk_stale_nr $ns2 1 -1 2
16557d1e6f16SPaolo Abeni	chk_link_usage $ns2 ns2eth3 $cinsent 50
16561002b89fSGeliang Tang}
16578b819a84SFlorian Westphal
16581002b89fSGeliang Tangadd_addr_timeout_tests()
16591002b89fSGeliang Tang{
16608d014eaaSGeliang Tang	# add_addr timeout
16618d014eaaSGeliang Tang	reset_with_add_addr_timeout
166234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
166334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
166434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
16658b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
16668d014eaaSGeliang Tang	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
16678d014eaaSGeliang Tang	chk_add_nr 4 0
16688d014eaaSGeliang Tang
16691002b89fSGeliang Tang	# add_addr timeout IPv6
16701002b89fSGeliang Tang	reset_with_add_addr_timeout 6
167134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
167234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
167334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
16741002b89fSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
16751002b89fSGeliang Tang	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
16761002b89fSGeliang Tang	chk_add_nr 4 0
16778da6229bSGeliang Tang
16788da6229bSGeliang Tang	# signal addresses timeout
16798da6229bSGeliang Tang	reset_with_add_addr_timeout
168034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
168134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
168234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
168334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
1684cbfafac4SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10
16858da6229bSGeliang Tang	chk_join_nr "signal addresses, ADD_ADDR timeout" 2 2 2
16868da6229bSGeliang Tang	chk_add_nr 8 0
16878da6229bSGeliang Tang
16888da6229bSGeliang Tang	# signal invalid addresses timeout
16898da6229bSGeliang Tang	reset_with_add_addr_timeout
169034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
169134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
169234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
169334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
1694cbfafac4SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10
16958da6229bSGeliang Tang	chk_join_nr "invalid address, ADD_ADDR timeout" 1 1 1
16968da6229bSGeliang Tang	chk_add_nr 8 0
16971002b89fSGeliang Tang}
16981002b89fSGeliang Tang
16991002b89fSGeliang Tangremove_tests()
17001002b89fSGeliang Tang{
1701dd72b0feSGeliang Tang	# single subflow, remove
1702dd72b0feSGeliang Tang	reset
170334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
170434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
170534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
17062e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
1707dd72b0feSGeliang Tang	chk_join_nr "remove single subflow" 1 1 1
1708dd72b0feSGeliang Tang	chk_rm_nr 1 1
1709dd72b0feSGeliang Tang
1710dd72b0feSGeliang Tang	# multiple subflows, remove
1711dd72b0feSGeliang Tang	reset
171234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
171334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
171434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
171534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
17162e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
1717dd72b0feSGeliang Tang	chk_join_nr "remove multiple subflows" 2 2 2
1718dd72b0feSGeliang Tang	chk_rm_nr 2 2
1719dd72b0feSGeliang Tang
1720dd72b0feSGeliang Tang	# single address, remove
1721dd72b0feSGeliang Tang	reset
172234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
172334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
172434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
17252e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1726dd72b0feSGeliang Tang	chk_join_nr "remove single address" 1 1 1
1727dd72b0feSGeliang Tang	chk_add_nr 1 1
17287028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1729dd72b0feSGeliang Tang
1730dd72b0feSGeliang Tang	# subflow and signal, remove
1731dd72b0feSGeliang Tang	reset
173234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
173334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
173434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
173534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
17362e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1737dd72b0feSGeliang Tang	chk_join_nr "remove subflow and signal" 2 2 2
1738dd72b0feSGeliang Tang	chk_add_nr 1 1
1739dd72b0feSGeliang Tang	chk_rm_nr 1 1
1740dd72b0feSGeliang Tang
1741dd72b0feSGeliang Tang	# subflows and signal, remove
1742dd72b0feSGeliang Tang	reset
174334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
174434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
174534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
174634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
174734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
17482e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
1749dd72b0feSGeliang Tang	chk_join_nr "remove subflows and signal" 3 3 3
1750dd72b0feSGeliang Tang	chk_add_nr 1 1
1751dd72b0feSGeliang Tang	chk_rm_nr 2 2
1752dd72b0feSGeliang Tang
1753ef360019SGeliang Tang	# addresses remove
1754ef360019SGeliang Tang	reset
175534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
175634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
175734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
175834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
175934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1760ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1761ef360019SGeliang Tang	chk_join_nr "remove addresses" 3 3 3
1762ef360019SGeliang Tang	chk_add_nr 3 3
1763ef360019SGeliang Tang	chk_rm_nr 3 3 invert
1764ef360019SGeliang Tang
1765ef360019SGeliang Tang	# invalid addresses remove
1766ef360019SGeliang Tang	reset
176734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
176834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
176934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
177034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
177134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1772ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1773ef360019SGeliang Tang	chk_join_nr "remove invalid addresses" 1 1 1
1774ef360019SGeliang Tang	chk_add_nr 3 3
1775ef360019SGeliang Tang	chk_rm_nr 3 1 invert
1776ef360019SGeliang Tang
17776fe4ccdcSGeliang Tang	# subflows and signal, flush
17786fe4ccdcSGeliang Tang	reset
177934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
178034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
178134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
178234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
178334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
17842e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
17856fe4ccdcSGeliang Tang	chk_join_nr "flush subflows and signal" 3 3 3
17866fe4ccdcSGeliang Tang	chk_add_nr 1 1
17876fa0174aSPaolo Abeni	chk_rm_nr 1 3 invert simult
1788d2c4333aSGeliang Tang
1789d2c4333aSGeliang Tang	# subflows flush
1790d2c4333aSGeliang Tang	reset
179134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
179234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
179334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150
179434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
179534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
1796d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1797d2c4333aSGeliang Tang	chk_join_nr "flush subflows" 3 3 3
17986fa0174aSPaolo Abeni	chk_rm_nr 0 3 simult
1799d2c4333aSGeliang Tang
1800d2c4333aSGeliang Tang	# addresses flush
1801d2c4333aSGeliang Tang	reset
180234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
180334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250
180434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
180534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.4.1 flags signal
180634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1807d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1808d2c4333aSGeliang Tang	chk_join_nr "flush addresses" 3 3 3
1809d2c4333aSGeliang Tang	chk_add_nr 3 3
18106fa0174aSPaolo Abeni	chk_rm_nr 3 3 invert simult
1811ef360019SGeliang Tang
1812ef360019SGeliang Tang	# invalid addresses flush
1813ef360019SGeliang Tang	reset
181434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 3 3
181534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.12.1 flags signal
181634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal
181734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.14.1 flags signal
181834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 3 3
1819ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
1820ef360019SGeliang Tang	chk_join_nr "flush invalid addresses" 1 1 1
1821ef360019SGeliang Tang	chk_add_nr 3 3
1822ef360019SGeliang Tang	chk_rm_nr 3 1 invert
18235e287fe7SGeliang Tang
18245e287fe7SGeliang Tang	# remove id 0 subflow
18255e287fe7SGeliang Tang	reset
182634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
182734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
182834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
18295e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
18305e287fe7SGeliang Tang	chk_join_nr "remove id 0 subflow" 1 1 1
18315e287fe7SGeliang Tang	chk_rm_nr 1 1
18325e287fe7SGeliang Tang
18335e287fe7SGeliang Tang	# remove id 0 address
18345e287fe7SGeliang Tang	reset
183534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
183634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
183734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
18385e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
18395e287fe7SGeliang Tang	chk_join_nr "remove id 0 address" 1 1 1
18405e287fe7SGeliang Tang	chk_add_nr 1 1
18415e287fe7SGeliang Tang	chk_rm_nr 1 1 invert
18421002b89fSGeliang Tang}
18436fe4ccdcSGeliang Tang
18441002b89fSGeliang Tangadd_tests()
18451002b89fSGeliang Tang{
18466208fd82SGeliang Tang	# add single subflow
18476208fd82SGeliang Tang	reset
184834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
184934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
18506208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
18516208fd82SGeliang Tang	chk_join_nr "add single subflow" 1 1 1
18526208fd82SGeliang Tang
18536208fd82SGeliang Tang	# add signal address
18546208fd82SGeliang Tang	reset
185534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
185634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
18576208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
18586208fd82SGeliang Tang	chk_join_nr "add signal address" 1 1 1
18596208fd82SGeliang Tang	chk_add_nr 1 1
18606208fd82SGeliang Tang
18616208fd82SGeliang Tang	# add multiple subflows
18626208fd82SGeliang Tang	reset
186334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
186434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
18656208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
18666208fd82SGeliang Tang	chk_join_nr "add multiple subflows" 2 2 2
18676208fd82SGeliang Tang
18686208fd82SGeliang Tang	# add multiple subflows IPv6
18696208fd82SGeliang Tang	reset
187034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
187134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
18726208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
18736208fd82SGeliang Tang	chk_join_nr "add multiple subflows IPv6" 2 2 2
18746208fd82SGeliang Tang
18756208fd82SGeliang Tang	# add multiple addresses IPv6
18766208fd82SGeliang Tang	reset
187734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
187834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
18796208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
18806208fd82SGeliang Tang	chk_join_nr "add multiple addresses IPv6" 2 2 2
18816208fd82SGeliang Tang	chk_add_nr 2 2
18821002b89fSGeliang Tang}
18836208fd82SGeliang Tang
18841002b89fSGeliang Tangipv6_tests()
18851002b89fSGeliang Tang{
1886523514edSGeliang Tang	# subflow IPv6
1887523514edSGeliang Tang	reset
188834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
188934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
189034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
1891523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1892523514edSGeliang Tang	chk_join_nr "single subflow IPv6" 1 1 1
1893523514edSGeliang Tang
1894523514edSGeliang Tang	# add_address, unused IPv6
1895523514edSGeliang Tang	reset
189634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
1897523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1898523514edSGeliang Tang	chk_join_nr "unused signal address IPv6" 0 0 0
1899523514edSGeliang Tang	chk_add_nr 1 1
1900523514edSGeliang Tang
1901523514edSGeliang Tang	# signal address IPv6
1902523514edSGeliang Tang	reset
190334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
190434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
190534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
1906523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1907523514edSGeliang Tang	chk_join_nr "single address IPv6" 1 1 1
1908523514edSGeliang Tang	chk_add_nr 1 1
1909523514edSGeliang Tang
1910523514edSGeliang Tang	# single address IPv6, remove
1911523514edSGeliang Tang	reset
191234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
191334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
191434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
19152e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
1916523514edSGeliang Tang	chk_join_nr "remove single address IPv6" 1 1 1
1917523514edSGeliang Tang	chk_add_nr 1 1
19187028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1919523514edSGeliang Tang
1920523514edSGeliang Tang	# subflow and signal IPv6, remove
1921523514edSGeliang Tang	reset
192234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
192334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal
192434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
192534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow
19262e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
1927523514edSGeliang Tang	chk_join_nr "remove subflow and signal IPv6" 2 2 2
1928523514edSGeliang Tang	chk_add_nr 1 1
1929523514edSGeliang Tang	chk_rm_nr 1 1
19301002b89fSGeliang Tang}
1931523514edSGeliang Tang
19321002b89fSGeliang Tangv4mapped_tests()
19331002b89fSGeliang Tang{
1934a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
1935a6094788SGeliang Tang	reset
193634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
193734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
193834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
1939a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1940a6094788SGeliang Tang	chk_join_nr "single subflow IPv4-mapped" 1 1 1
1941a6094788SGeliang Tang
1942a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
1943a6094788SGeliang Tang	reset
194434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
194534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
194634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
1947a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1948a6094788SGeliang Tang	chk_join_nr "signal address IPv4-mapped" 1 1 1
1949a6094788SGeliang Tang	chk_add_nr 1 1
1950a6094788SGeliang Tang
1951a6094788SGeliang Tang	# subflow v4-map-v6
1952a6094788SGeliang Tang	reset
195334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
195434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
195534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
1956a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1957a6094788SGeliang Tang	chk_join_nr "single subflow v4-map-v6" 1 1 1
1958a6094788SGeliang Tang
1959a6094788SGeliang Tang	# signal address v4-map-v6
1960a6094788SGeliang Tang	reset
196134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
196234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
196334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
1964a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1965a6094788SGeliang Tang	chk_join_nr "signal address v4-map-v6" 1 1 1
1966a6094788SGeliang Tang	chk_add_nr 1 1
1967a6094788SGeliang Tang
1968a6094788SGeliang Tang	# subflow v6-map-v4
1969a6094788SGeliang Tang	reset
197034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
197134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
197234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow
1973a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1974a6094788SGeliang Tang	chk_join_nr "single subflow v6-map-v4" 1 1 1
1975a6094788SGeliang Tang
1976a6094788SGeliang Tang	# signal address v6-map-v4
1977a6094788SGeliang Tang	reset
197834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
197934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
198034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal
1981a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1982a6094788SGeliang Tang	chk_join_nr "signal address v6-map-v4" 1 1 1
1983a6094788SGeliang Tang	chk_add_nr 1 1
1984a6094788SGeliang Tang
1985a6094788SGeliang Tang	# no subflow IPv6 to v4 address
1986a6094788SGeliang Tang	reset
198734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
198834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
198934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow
1990a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1991a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1992a6094788SGeliang Tang
1993a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1994a6094788SGeliang Tang	reset
199534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
199634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
199734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow
1998a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1999a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
2000a6094788SGeliang Tang
2001a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
2002a6094788SGeliang Tang	reset
200334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
200434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
200534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
2006a6094788SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1
2007a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
20081002b89fSGeliang Tang}
2009a6094788SGeliang Tang
20101002b89fSGeliang Tangbackup_tests()
20111002b89fSGeliang Tang{
2012718eb44eSGeliang Tang	# single subflow, backup
2013718eb44eSGeliang Tang	reset
201434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
201534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
201634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup
2017718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
2018718eb44eSGeliang Tang	chk_join_nr "single subflow, backup" 1 1 1
2019718eb44eSGeliang Tang	chk_prio_nr 0 1
2020718eb44eSGeliang Tang
2021718eb44eSGeliang Tang	# single address, backup
2022718eb44eSGeliang Tang	reset
202334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
202434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
202534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
2026718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
2027718eb44eSGeliang Tang	chk_join_nr "single address, backup" 1 1 1
2028718eb44eSGeliang Tang	chk_add_nr 1 1
2029d045b9ebSPaolo Abeni	chk_prio_nr 1 1
203033397b83SGeliang Tang
203133397b83SGeliang Tang	# single address with port, backup
203233397b83SGeliang Tang	reset
203334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
203434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
203534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
203633397b83SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
203733397b83SGeliang Tang	chk_join_nr "single address with port, backup" 1 1 1
203833397b83SGeliang Tang	chk_add_nr 1 1
2039d045b9ebSPaolo Abeni	chk_prio_nr 1 1
20401002b89fSGeliang Tang}
2041718eb44eSGeliang Tang
20421002b89fSGeliang Tangadd_addr_ports_tests()
20431002b89fSGeliang Tang{
20448a127bf6SGeliang Tang	# signal address with port
20458a127bf6SGeliang Tang	reset
204634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
204734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
204834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
20498a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
20508a127bf6SGeliang Tang	chk_join_nr "signal address with port" 1 1 1
20518a127bf6SGeliang Tang	chk_add_nr 1 1 1
20528a127bf6SGeliang Tang
20538a127bf6SGeliang Tang	# subflow and signal with port
20548a127bf6SGeliang Tang	reset
205534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
205634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
205734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
205834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
20598a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
20608a127bf6SGeliang Tang	chk_join_nr "subflow and signal with port" 2 2 2
20618a127bf6SGeliang Tang	chk_add_nr 1 1 1
20628a127bf6SGeliang Tang
20638a127bf6SGeliang Tang	# single address with port, remove
20648a127bf6SGeliang Tang	reset
206534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
206634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
206734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
20688a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
20698a127bf6SGeliang Tang	chk_join_nr "remove single address with port" 1 1 1
20708a127bf6SGeliang Tang	chk_add_nr 1 1 1
20717028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
20728a127bf6SGeliang Tang
20738a127bf6SGeliang Tang	# subflow and signal with port, remove
20748a127bf6SGeliang Tang	reset
207534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
207634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
207734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
207834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
20798a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
20808a127bf6SGeliang Tang	chk_join_nr "remove subflow and signal with port" 2 2 2
20818a127bf6SGeliang Tang	chk_add_nr 1 1 1
20828a127bf6SGeliang Tang	chk_rm_nr 1 1
20838a127bf6SGeliang Tang
20848a127bf6SGeliang Tang	# subflows and signal with port, flush
20858a127bf6SGeliang Tang	reset
208634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
208734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
208834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
208934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
209034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
2091327b9a94SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 -8 -2 slow
20928a127bf6SGeliang Tang	chk_join_nr "flush subflows and signal with port" 3 3 3
20938a127bf6SGeliang Tang	chk_add_nr 1 1
20946fa0174aSPaolo Abeni	chk_rm_nr 1 3 invert simult
20958a127bf6SGeliang Tang
20968a127bf6SGeliang Tang	# multiple addresses with port
20978a127bf6SGeliang Tang	reset
209834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
209934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
210034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100
210134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
21028a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
21038a127bf6SGeliang Tang	chk_join_nr "multiple addresses with port" 2 2 2
21048a127bf6SGeliang Tang	chk_add_nr 2 2 2
21058a127bf6SGeliang Tang
21068a127bf6SGeliang Tang	# multiple addresses with ports
21078a127bf6SGeliang Tang	reset
210834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
210934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100
211034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101
211134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
21128a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
21138a127bf6SGeliang Tang	chk_join_nr "multiple addresses with ports" 2 2 2
21148a127bf6SGeliang Tang	chk_add_nr 2 2 2
21151002b89fSGeliang Tang}
21168a127bf6SGeliang Tang
21171002b89fSGeliang Tangsyncookies_tests()
21181002b89fSGeliang Tang{
211900587187SFlorian Westphal	# single subflow, syncookies
212000587187SFlorian Westphal	reset_with_cookies
212134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
212234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
212334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
212400587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
212500587187SFlorian Westphal	chk_join_nr "single subflow with syn cookies" 1 1 1
212600587187SFlorian Westphal
212700587187SFlorian Westphal	# multiple subflows with syn cookies
212800587187SFlorian Westphal	reset_with_cookies
212934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
213034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
213134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
213234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
213300587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
213400587187SFlorian Westphal	chk_join_nr "multiple subflows with syn cookies" 2 2 2
213500587187SFlorian Westphal
213600587187SFlorian Westphal	# multiple subflows limited by server
213700587187SFlorian Westphal	reset_with_cookies
213834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
213934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 2
214034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
214134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
214200587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
2143a7da4416SJianguo Wu	chk_join_nr "subflows limited by server w cookies" 2 1 1
214400587187SFlorian Westphal
214500587187SFlorian Westphal	# test signal address with cookies
214600587187SFlorian Westphal	reset_with_cookies
214734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
214834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
214934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
215000587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
215100587187SFlorian Westphal	chk_join_nr "signal address with syn cookies" 1 1 1
2152be613160SGeliang Tang	chk_add_nr 1 1
215300587187SFlorian Westphal
215400587187SFlorian Westphal	# test cookie with subflow and signal
215500587187SFlorian Westphal	reset_with_cookies
215634aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
215734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 2
215834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 2
215934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
216000587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
216100587187SFlorian Westphal	chk_join_nr "subflow and signal w cookies" 2 2 2
2162be613160SGeliang Tang	chk_add_nr 1 1
216300587187SFlorian Westphal
216400587187SFlorian Westphal	# accept and use add_addr with additional subflows
216500587187SFlorian Westphal	reset_with_cookies
216634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 3
216734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
216834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
216934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
217034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow
217100587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
217200587187SFlorian Westphal	chk_join_nr "subflows and signal w. cookies" 3 3 3
2173be613160SGeliang Tang	chk_add_nr 1 1
21741002b89fSGeliang Tang}
21751002b89fSGeliang Tang
2176af66d3e1SGeliang Tangchecksum_tests()
2177af66d3e1SGeliang Tang{
2178af66d3e1SGeliang Tang	# checksum test 0 0
2179af66d3e1SGeliang Tang	reset_with_checksum 0 0
218034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
218134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
2182af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
21833c082695SGeliang Tang	chk_join_nr "checksum test 0 0" 0 0 0
2184af66d3e1SGeliang Tang
2185af66d3e1SGeliang Tang	# checksum test 1 1
2186af66d3e1SGeliang Tang	reset_with_checksum 1 1
218734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
218834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
2189af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
21903c082695SGeliang Tang	chk_join_nr "checksum test 1 1" 0 0 0
2191af66d3e1SGeliang Tang
2192af66d3e1SGeliang Tang	# checksum test 0 1
2193af66d3e1SGeliang Tang	reset_with_checksum 0 1
219434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
219534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
2196af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
21973c082695SGeliang Tang	chk_join_nr "checksum test 0 1" 0 0 0
2198af66d3e1SGeliang Tang
2199af66d3e1SGeliang Tang	# checksum test 1 0
2200af66d3e1SGeliang Tang	reset_with_checksum 1 0
220134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 1
220234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 0 1
2203af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22043c082695SGeliang Tang	chk_join_nr "checksum test 1 0" 0 0 0
2205af66d3e1SGeliang Tang}
2206af66d3e1SGeliang Tang
22070cddb4a6SGeliang Tangdeny_join_id0_tests()
22080cddb4a6SGeliang Tang{
22090cddb4a6SGeliang Tang	# subflow allow join id0 ns1
22100cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
221134aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 1 1
221234aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
221334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
22140cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22150cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns1" 1 1 1
22160cddb4a6SGeliang Tang
22170cddb4a6SGeliang Tang	# subflow allow join id0 ns2
22180cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
221934aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 1 1
222034aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
222134aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
22220cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22230cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns2" 0 0 0
22240cddb4a6SGeliang Tang
22250cddb4a6SGeliang Tang	# signal address allow join id0 ns1
22260cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
22270cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
222834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 1 1
222934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
223034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
22310cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22320cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns1" 1 1 1
22330cddb4a6SGeliang Tang	chk_add_nr 1 1
22340cddb4a6SGeliang Tang
22350cddb4a6SGeliang Tang	# signal address allow join id0 ns2
22360cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
22370cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
223834aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 1 1
223934aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 1
224034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
22410cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22420cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns2" 1 1 1
22430cddb4a6SGeliang Tang	chk_add_nr 1 1
22440cddb4a6SGeliang Tang
22450cddb4a6SGeliang Tang	# subflow and address allow join id0 ns1
22460cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
224734aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
224834aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
224934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
225034aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
22510cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22520cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 1" 2 2 2
22530cddb4a6SGeliang Tang
22540cddb4a6SGeliang Tang	# subflow and address allow join id0 ns2
22550cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
225634aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 2
225734aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 2 2
225834aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
225934aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
22600cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
22610cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 2" 1 1 1
22620cddb4a6SGeliang Tang}
22630cddb4a6SGeliang Tang
22644f49d633SGeliang Tangfullmesh_tests()
22654f49d633SGeliang Tang{
22664f49d633SGeliang Tang	# fullmesh 1
22674f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added before the connection,
22684f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added during the connection.
22694f49d633SGeliang Tang	reset
227034aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 0 4
227134aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 4
227234aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh
227334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh
22744f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
22754f49d633SGeliang Tang	chk_join_nr "fullmesh test 2x1" 4 4 4
22764f49d633SGeliang Tang	chk_add_nr 1 1
22774f49d633SGeliang Tang
22784f49d633SGeliang Tang	# fullmesh 2
22794f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
22804f49d633SGeliang Tang	# 1 fullmesh addr in ns2, added during the connection.
22814f49d633SGeliang Tang	reset
228234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 1 3
228334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 3
228434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
22854f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow
22864f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x1" 3 3 3
22874f49d633SGeliang Tang	chk_add_nr 1 1
22884f49d633SGeliang Tang
22894f49d633SGeliang Tang	# fullmesh 3
22904f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
22914f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection.
22924f49d633SGeliang Tang	reset
229334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 5
229434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 5
229534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
22964f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
22974f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x2" 5 5 5
22984f49d633SGeliang Tang	chk_add_nr 1 1
22994f49d633SGeliang Tang
23004f49d633SGeliang Tang	# fullmesh 4
23014f49d633SGeliang Tang	# 1 non-fullmesh addr in ns1, added before the connection,
23024f49d633SGeliang Tang	# 2 fullmesh addrs in ns2, added during the connection,
23034f49d633SGeliang Tang	# limit max_subflows to 4.
23044f49d633SGeliang Tang	reset
230534aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 2 4
230634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 1 4
230734aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
23084f49d633SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow
23094f49d633SGeliang Tang	chk_join_nr "fullmesh test 1x2, limited" 4 4 4
23104f49d633SGeliang Tang	chk_add_nr 1 1
23116a0653b9SGeliang Tang
23126a0653b9SGeliang Tang	# set fullmesh flag
23136a0653b9SGeliang Tang	reset
231434aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 4 4
231534aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
231634aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 4 4
23176a0653b9SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow fullmesh
23186a0653b9SGeliang Tang	chk_join_nr "set fullmesh flag test" 2 2 2
23196a0653b9SGeliang Tang	chk_rm_nr 0 1
23206a0653b9SGeliang Tang
23216a0653b9SGeliang Tang	# set nofullmesh flag
23226a0653b9SGeliang Tang	reset
232334aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 4 4
232434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh
232534aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 4 4
23266a0653b9SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow nofullmesh
23276a0653b9SGeliang Tang	chk_join_nr "set nofullmesh flag test" 2 2 2
23286a0653b9SGeliang Tang	chk_rm_nr 0 1
23296a0653b9SGeliang Tang
23306a0653b9SGeliang Tang	# set backup,fullmesh flags
23316a0653b9SGeliang Tang	reset
233234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 4 4
233334aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow
233434aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 4 4
23356a0653b9SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow backup,fullmesh
23366a0653b9SGeliang Tang	chk_join_nr "set backup,fullmesh flags test" 2 2 2
23376a0653b9SGeliang Tang	chk_prio_nr 0 1
23386a0653b9SGeliang Tang	chk_rm_nr 0 1
23396a0653b9SGeliang Tang
23406a0653b9SGeliang Tang	# set nobackup,nofullmesh flags
23416a0653b9SGeliang Tang	reset
234234aa6e3bSGeliang Tang	pm_nl_set_limits $ns1 4 4
234334aa6e3bSGeliang Tang	pm_nl_set_limits $ns2 4 4
234434aa6e3bSGeliang Tang	pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh
23456a0653b9SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup,nofullmesh
23466a0653b9SGeliang Tang	chk_join_nr "set nobackup,nofullmesh flags test" 2 2 2
23476a0653b9SGeliang Tang	chk_prio_nr 0 1
23486a0653b9SGeliang Tang	chk_rm_nr 0 1
23494f49d633SGeliang Tang}
23504f49d633SGeliang Tang
235101542c9bSGeliang Tangfastclose_tests()
235201542c9bSGeliang Tang{
235301542c9bSGeliang Tang	reset
235401542c9bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_2
235501542c9bSGeliang Tang	chk_join_nr "fastclose test" 0 0 0
235601542c9bSGeliang Tang	chk_fclose_nr 1 1
235701542c9bSGeliang Tang	chk_rst_nr 1 1 invert
235801542c9bSGeliang Tang}
235901542c9bSGeliang Tang
236069c6ce7bSPaolo Abeniimplicit_tests()
236169c6ce7bSPaolo Abeni{
236269c6ce7bSPaolo Abeni	# userspace pm type prevents add_addr
236369c6ce7bSPaolo Abeni	reset
236469c6ce7bSPaolo Abeni	pm_nl_set_limits $ns1 2 2
236569c6ce7bSPaolo Abeni	pm_nl_set_limits $ns2 2 2
236669c6ce7bSPaolo Abeni	pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
236769c6ce7bSPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow &
236869c6ce7bSPaolo Abeni
236969c6ce7bSPaolo Abeni	wait_mpj $ns1
237069c6ce7bSPaolo Abeni	TEST_COUNT=$((TEST_COUNT + 1))
237169c6ce7bSPaolo Abeni	pm_nl_check_endpoint "implicit EP" "creation" \
237269c6ce7bSPaolo Abeni		$ns2 10.0.2.2 id 1 flags implicit
237369c6ce7bSPaolo Abeni
237469c6ce7bSPaolo Abeni	pm_nl_add_endpoint $ns2 10.0.2.2 id 33
237569c6ce7bSPaolo Abeni	pm_nl_check_endpoint "" "ID change is prevented" \
237669c6ce7bSPaolo Abeni		$ns2 10.0.2.2 id 1 flags implicit
237769c6ce7bSPaolo Abeni
237869c6ce7bSPaolo Abeni	pm_nl_add_endpoint $ns2 10.0.2.2 flags signal
237969c6ce7bSPaolo Abeni	pm_nl_check_endpoint "" "modif is allowed" \
238069c6ce7bSPaolo Abeni		$ns2 10.0.2.2 id 1 flags signal
238169c6ce7bSPaolo Abeni	wait
238269c6ce7bSPaolo Abeni}
238369c6ce7bSPaolo Abeni
238422514d52SMatthieu Baerts# [$1: error message]
23851002b89fSGeliang Tangusage()
23861002b89fSGeliang Tang{
238722514d52SMatthieu Baerts	if [ -n "${1}" ]; then
238822514d52SMatthieu Baerts		echo "${1}"
238922514d52SMatthieu Baerts		ret=1
239022514d52SMatthieu Baerts	fi
239122514d52SMatthieu Baerts
23921002b89fSGeliang Tang	echo "mptcp_join usage:"
2393*3afd0280SMatthieu Baerts
2394*3afd0280SMatthieu Baerts	local key
2395*3afd0280SMatthieu Baerts	for key in "${!all_tests[@]}"; do
2396*3afd0280SMatthieu Baerts		echo "  -${key} ${all_tests[${key}]}"
2397*3afd0280SMatthieu Baerts	done
2398*3afd0280SMatthieu Baerts
2399a673321aSMat Martineau	echo "  -c capture pcap files"
2400af66d3e1SGeliang Tang	echo "  -C enable data checksum"
2401621bd393SGeliang Tang	echo "  -i use ip mptcp"
24021002b89fSGeliang Tang	echo "  -h help"
240322514d52SMatthieu Baerts
240422514d52SMatthieu Baerts	exit ${ret}
24051002b89fSGeliang Tang}
24061002b89fSGeliang Tang
2407a673321aSMat Martineau
2408*3afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one
2409*3afd0280SMatthieu Baertsall_tests_sorted=(
2410*3afd0280SMatthieu Baerts	f@subflows_tests
2411*3afd0280SMatthieu Baerts	e@subflows_error_tests
2412*3afd0280SMatthieu Baerts	s@signal_address_tests
2413*3afd0280SMatthieu Baerts	l@link_failure_tests
2414*3afd0280SMatthieu Baerts	t@add_addr_timeout_tests
2415*3afd0280SMatthieu Baerts	r@remove_tests
2416*3afd0280SMatthieu Baerts	a@add_tests
2417*3afd0280SMatthieu Baerts	6@ipv6_tests
2418*3afd0280SMatthieu Baerts	4@v4mapped_tests
2419*3afd0280SMatthieu Baerts	b@backup_tests
2420*3afd0280SMatthieu Baerts	p@add_addr_ports_tests
2421*3afd0280SMatthieu Baerts	k@syncookies_tests
2422*3afd0280SMatthieu Baerts	S@checksum_tests
2423*3afd0280SMatthieu Baerts	d@deny_join_id0_tests
2424*3afd0280SMatthieu Baerts	m@fullmesh_tests
2425*3afd0280SMatthieu Baerts	z@fastclose_tests
2426*3afd0280SMatthieu Baerts	I@implicit_tests
2427*3afd0280SMatthieu Baerts)
2428*3afd0280SMatthieu Baerts
2429*3afd0280SMatthieu Baertsall_tests_args=""
2430*3afd0280SMatthieu Baertsall_tests_names=()
2431*3afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do
2432*3afd0280SMatthieu Baerts	key="${subtests%@*}"
2433*3afd0280SMatthieu Baerts	value="${subtests#*@}"
2434*3afd0280SMatthieu Baerts
2435*3afd0280SMatthieu Baerts	all_tests_args+="${key}"
2436*3afd0280SMatthieu Baerts	all_tests_names+=("${value}")
2437*3afd0280SMatthieu Baerts	all_tests[${key}]="${value}"
2438*3afd0280SMatthieu Baertsdone
2439*3afd0280SMatthieu Baerts
2440826d7bdcSMatthieu Baertstests=()
2441*3afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do
24421002b89fSGeliang Tang	case $opt in
2443*3afd0280SMatthieu Baerts		["${all_tests_args}"])
2444*3afd0280SMatthieu Baerts			tests+=("${all_tests[${opt}]}")
244569c6ce7bSPaolo Abeni			;;
2446a673321aSMat Martineau		c)
2447826d7bdcSMatthieu Baerts			capture=1
2448a673321aSMat Martineau			;;
2449af66d3e1SGeliang Tang		C)
2450826d7bdcSMatthieu Baerts			checksum=1
2451af66d3e1SGeliang Tang			;;
2452621bd393SGeliang Tang		i)
2453826d7bdcSMatthieu Baerts			ip_mptcp=1
2454621bd393SGeliang Tang			;;
245522514d52SMatthieu Baerts		h)
24561002b89fSGeliang Tang			usage
24571002b89fSGeliang Tang			;;
245822514d52SMatthieu Baerts		*)
245922514d52SMatthieu Baerts			usage "Unknown option: -${opt}"
246022514d52SMatthieu Baerts			;;
24611002b89fSGeliang Tang	esac
24621002b89fSGeliang Tangdone
246300587187SFlorian Westphal
2464826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then
2465*3afd0280SMatthieu Baerts	tests=("${all_tests_names[@]}")
2466*3afd0280SMatthieu Baertsfi
2467*3afd0280SMatthieu Baerts
2468826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do
2469826d7bdcSMatthieu Baerts	"${subtests}"
2470826d7bdcSMatthieu Baertsdone
2471826d7bdcSMatthieu Baerts
2472b08fbf24SPaolo Abeniexit $ret
2473