1b08fbf24SPaolo Abeni#!/bin/bash
2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0
3b08fbf24SPaolo Abeni
4b08fbf24SPaolo Abeniret=0
5b08fbf24SPaolo Abenisin=""
6b08fbf24SPaolo Abenisout=""
7b08fbf24SPaolo Abenicin=""
88b819a84SFlorian Westphalcinsent=""
9b08fbf24SPaolo Abenicout=""
10b08fbf24SPaolo Abeniksft_skip=4
115888a61cSMatthieu Baertstimeout_poll=30
125888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1))
13dd72b0feSGeliang Tangmptcp_connect=""
14b08fbf24SPaolo Abenicapture=0
15af66d3e1SGeliang Tangchecksum=0
16a673321aSMat Martineaudo_all_tests=1
17b08fbf24SPaolo Abeni
18b08fbf24SPaolo AbeniTEST_COUNT=0
19b08fbf24SPaolo Abeni
208d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
218d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
228d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
238d014eaaSGeliang Tang			       48 0 0 0,
248d014eaaSGeliang Tang			       84 0 0 240,
258d014eaaSGeliang Tang			       21 0 3 64,
268d014eaaSGeliang Tang			       48 0 0 54,
278d014eaaSGeliang Tang			       84 0 0 240,
288d014eaaSGeliang Tang			       21 6 7 48,
298d014eaaSGeliang Tang			       48 0 0 0,
308d014eaaSGeliang Tang			       84 0 0 240,
318d014eaaSGeliang Tang			       21 0 4 96,
328d014eaaSGeliang Tang			       48 0 0 74,
338d014eaaSGeliang Tang			       84 0 0 240,
348d014eaaSGeliang Tang			       21 0 1 48,
358d014eaaSGeliang Tang			       6 0 0 65535,
368d014eaaSGeliang Tang			       6 0 0 0"
378d014eaaSGeliang Tang
38b08fbf24SPaolo Abeniinit()
39b08fbf24SPaolo Abeni{
40b08fbf24SPaolo Abeni	capout=$(mktemp)
41b08fbf24SPaolo Abeni
42b08fbf24SPaolo Abeni	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
43b08fbf24SPaolo Abeni
44b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
45b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
46b08fbf24SPaolo Abeni
47b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2";do
48b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
49b08fbf24SPaolo Abeni		ip -net $netns link set lo up
50b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
51b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
52b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
53af66d3e1SGeliang Tang		if [ $checksum -eq 1 ]; then
54af66d3e1SGeliang Tang			ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1
55af66d3e1SGeliang Tang		fi
56b08fbf24SPaolo Abeni	done
57b08fbf24SPaolo Abeni
58b08fbf24SPaolo Abeni	#  ns1              ns2
59b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
60b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
61b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
62b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
63b08fbf24SPaolo Abeni
64b08fbf24SPaolo Abeni	for i in `seq 1 4`; do
65b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
66b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
67b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
68b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
69b08fbf24SPaolo Abeni
70b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
71b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
72b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
73b08fbf24SPaolo Abeni
74b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
75b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
76b08fbf24SPaolo Abeni	done
77b08fbf24SPaolo Abeni}
78b08fbf24SPaolo Abeni
79b08fbf24SPaolo Abenicleanup_partial()
80b08fbf24SPaolo Abeni{
81b08fbf24SPaolo Abeni	rm -f "$capout"
82b08fbf24SPaolo Abeni
83b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
84b08fbf24SPaolo Abeni		ip netns del $netns
85c2a55e8fSMatthieu Baerts		rm -f /tmp/$netns.{nstat,out}
86b08fbf24SPaolo Abeni	done
87b08fbf24SPaolo Abeni}
88b08fbf24SPaolo Abeni
89b08fbf24SPaolo Abenicleanup()
90b08fbf24SPaolo Abeni{
91b08fbf24SPaolo Abeni	rm -f "$cin" "$cout"
928b819a84SFlorian Westphal	rm -f "$sin" "$sout" "$cinsent"
93b08fbf24SPaolo Abeni	cleanup_partial
94b08fbf24SPaolo Abeni}
95b08fbf24SPaolo Abeni
96b08fbf24SPaolo Abenireset()
97b08fbf24SPaolo Abeni{
98b08fbf24SPaolo Abeni	cleanup_partial
99b08fbf24SPaolo Abeni	init
100b08fbf24SPaolo Abeni}
101b08fbf24SPaolo Abeni
10200587187SFlorian Westphalreset_with_cookies()
10300587187SFlorian Westphal{
10400587187SFlorian Westphal	reset
10500587187SFlorian Westphal
10600587187SFlorian Westphal	for netns in "$ns1" "$ns2";do
10700587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
10800587187SFlorian Westphal	done
10900587187SFlorian Westphal}
11000587187SFlorian Westphal
1118d014eaaSGeliang Tangreset_with_add_addr_timeout()
1128d014eaaSGeliang Tang{
1138d014eaaSGeliang Tang	local ip="${1:-4}"
1148d014eaaSGeliang Tang	local tables
1158d014eaaSGeliang Tang
1168d014eaaSGeliang Tang	tables="iptables"
1178d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
1188d014eaaSGeliang Tang		tables="ip6tables"
1198d014eaaSGeliang Tang	fi
1208d014eaaSGeliang Tang
1218d014eaaSGeliang Tang	reset
1228d014eaaSGeliang Tang
1238d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
1248d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
1258d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
1268d014eaaSGeliang Tang		-m bpf --bytecode \
1278d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
1288d014eaaSGeliang Tang		-j DROP
1298d014eaaSGeliang Tang}
1308d014eaaSGeliang Tang
131af66d3e1SGeliang Tangreset_with_checksum()
132af66d3e1SGeliang Tang{
133af66d3e1SGeliang Tang	local ns1_enable=$1
134af66d3e1SGeliang Tang	local ns2_enable=$2
135af66d3e1SGeliang Tang
136af66d3e1SGeliang Tang	reset
137af66d3e1SGeliang Tang
138af66d3e1SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable
139af66d3e1SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable
140af66d3e1SGeliang Tang}
141af66d3e1SGeliang Tang
1420cddb4a6SGeliang Tangreset_with_allow_join_id0()
1430cddb4a6SGeliang Tang{
1440cddb4a6SGeliang Tang	local ns1_enable=$1
1450cddb4a6SGeliang Tang	local ns2_enable=$2
1460cddb4a6SGeliang Tang
1470cddb4a6SGeliang Tang	reset
1480cddb4a6SGeliang Tang
1490cddb4a6SGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable
1500cddb4a6SGeliang Tang	ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable
1510cddb4a6SGeliang Tang}
1520cddb4a6SGeliang Tang
153b08fbf24SPaolo Abeniip -Version > /dev/null 2>&1
154b08fbf24SPaolo Abeniif [ $? -ne 0 ];then
155b08fbf24SPaolo Abeni	echo "SKIP: Could not run test without ip tool"
156b08fbf24SPaolo Abeni	exit $ksft_skip
157b08fbf24SPaolo Abenifi
158b08fbf24SPaolo Abeni
1598d014eaaSGeliang Tangiptables -V > /dev/null 2>&1
1608d014eaaSGeliang Tangif [ $? -ne 0 ];then
1618d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without iptables tool"
1628d014eaaSGeliang Tang	exit $ksft_skip
1638d014eaaSGeliang Tangfi
1648d014eaaSGeliang Tang
1658d014eaaSGeliang Tangip6tables -V > /dev/null 2>&1
1668d014eaaSGeliang Tangif [ $? -ne 0 ];then
1678d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without ip6tables tool"
1688d014eaaSGeliang Tang	exit $ksft_skip
1698d014eaaSGeliang Tangfi
170b08fbf24SPaolo Abeni
1718b819a84SFlorian Westphalprint_file_err()
1728b819a84SFlorian Westphal{
1738b819a84SFlorian Westphal	ls -l "$1" 1>&2
1748b819a84SFlorian Westphal	echo "Trailing bytes are: "
1758b819a84SFlorian Westphal	tail -c 27 "$1"
1768b819a84SFlorian Westphal}
1778b819a84SFlorian Westphal
178b08fbf24SPaolo Abenicheck_transfer()
179b08fbf24SPaolo Abeni{
180b08fbf24SPaolo Abeni	in=$1
181b08fbf24SPaolo Abeni	out=$2
182b08fbf24SPaolo Abeni	what=$3
183b08fbf24SPaolo Abeni
184b08fbf24SPaolo Abeni	cmp "$in" "$out" > /dev/null 2>&1
185b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ;then
186b08fbf24SPaolo Abeni		echo "[ FAIL ] $what does not match (in, out):"
187b08fbf24SPaolo Abeni		print_file_err "$in"
188b08fbf24SPaolo Abeni		print_file_err "$out"
1898b819a84SFlorian Westphal		ret=1
190b08fbf24SPaolo Abeni
191b08fbf24SPaolo Abeni		return 1
192b08fbf24SPaolo Abeni	fi
193b08fbf24SPaolo Abeni
194b08fbf24SPaolo Abeni	return 0
195b08fbf24SPaolo Abeni}
196b08fbf24SPaolo Abeni
197b08fbf24SPaolo Abenido_ping()
198b08fbf24SPaolo Abeni{
199b08fbf24SPaolo Abeni	listener_ns="$1"
200b08fbf24SPaolo Abeni	connector_ns="$2"
201b08fbf24SPaolo Abeni	connect_addr="$3"
202b08fbf24SPaolo Abeni
203b08fbf24SPaolo Abeni	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
204b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ; then
205b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
206b08fbf24SPaolo Abeni		ret=1
207b08fbf24SPaolo Abeni	fi
208b08fbf24SPaolo Abeni}
209b08fbf24SPaolo Abeni
2108b819a84SFlorian Westphallink_failure()
2118b819a84SFlorian Westphal{
2128b819a84SFlorian Westphal	ns="$1"
2138b819a84SFlorian Westphal
2148b819a84SFlorian Westphal	l=$((RANDOM%4))
2158b819a84SFlorian Westphal	l=$((l+1))
2168b819a84SFlorian Westphal
2178b819a84SFlorian Westphal	veth="ns1eth$l"
2188b819a84SFlorian Westphal	ip -net "$ns" link set "$veth" down
2198b819a84SFlorian Westphal}
2208b819a84SFlorian Westphal
221523514edSGeliang Tang# $1: IP address
222523514edSGeliang Tangis_v6()
223523514edSGeliang Tang{
224523514edSGeliang Tang	[ -z "${1##*:*}" ]
225523514edSGeliang Tang}
226523514edSGeliang Tang
227b08fbf24SPaolo Abenido_transfer()
228b08fbf24SPaolo Abeni{
229b08fbf24SPaolo Abeni	listener_ns="$1"
230b08fbf24SPaolo Abeni	connector_ns="$2"
231b08fbf24SPaolo Abeni	cl_proto="$3"
232b08fbf24SPaolo Abeni	srv_proto="$4"
233b08fbf24SPaolo Abeni	connect_addr="$5"
2348b819a84SFlorian Westphal	test_link_fail="$6"
2352e8cbf45SGeliang Tang	addr_nr_ns1="$7"
2362e8cbf45SGeliang Tang	addr_nr_ns2="$8"
2378b819a84SFlorian Westphal	speed="$9"
238718eb44eSGeliang Tang	bkup="${10}"
239b08fbf24SPaolo Abeni
240b08fbf24SPaolo Abeni	port=$((10000+$TEST_COUNT))
241b08fbf24SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
242b08fbf24SPaolo Abeni
243b08fbf24SPaolo Abeni	:> "$cout"
244b08fbf24SPaolo Abeni	:> "$sout"
245b08fbf24SPaolo Abeni	:> "$capout"
246b08fbf24SPaolo Abeni
247b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
248b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
249b08fbf24SPaolo Abeni			capuser=""
250b08fbf24SPaolo Abeni		else
251b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
252b08fbf24SPaolo Abeni		fi
253b08fbf24SPaolo Abeni
25400587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
255b08fbf24SPaolo Abeni
256b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
257b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
258b08fbf24SPaolo Abeni		cappid=$!
259b08fbf24SPaolo Abeni
260b08fbf24SPaolo Abeni		sleep 1
261b08fbf24SPaolo Abeni	fi
262b08fbf24SPaolo Abeni
263c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
264c2a55e8fSMatthieu Baerts		nstat -n
265c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
266c2a55e8fSMatthieu Baerts		nstat -n
267c2a55e8fSMatthieu Baerts
2688d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
269dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -j"
2708da6229bSGeliang Tang	elif [ $speed = "slow" ]; then
2718da6229bSGeliang Tang		mptcp_connect="./mptcp_connect -r 50"
2728da6229bSGeliang Tang	elif [ $speed = "least" ]; then
2738da6229bSGeliang Tang		mptcp_connect="./mptcp_connect -r 10"
274dd72b0feSGeliang Tang	fi
275dd72b0feSGeliang Tang
276523514edSGeliang Tang	local local_addr
277523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
278523514edSGeliang Tang		local_addr="::"
279523514edSGeliang Tang	else
280523514edSGeliang Tang		local_addr="0.0.0.0"
281523514edSGeliang Tang	fi
282523514edSGeliang Tang
2835888a61cSMatthieu Baerts	timeout ${timeout_test} \
2845888a61cSMatthieu Baerts		ip netns exec ${listener_ns} \
2855888a61cSMatthieu Baerts			$mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
2865888a61cSMatthieu Baerts				${local_addr} < "$sin" > "$sout" &
287b08fbf24SPaolo Abeni	spid=$!
288b08fbf24SPaolo Abeni
289b08fbf24SPaolo Abeni	sleep 1
290b08fbf24SPaolo Abeni
2918b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
2925888a61cSMatthieu Baerts		timeout ${timeout_test} \
2935888a61cSMatthieu Baerts			ip netns exec ${connector_ns} \
2945888a61cSMatthieu Baerts				$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
2955888a61cSMatthieu Baerts					$connect_addr < "$cin" > "$cout" &
2968b819a84SFlorian Westphal	else
2975888a61cSMatthieu Baerts		( cat "$cin" ; sleep 2; link_failure $listener_ns ; cat "$cin" ) | \
2985888a61cSMatthieu Baerts			tee "$cinsent" | \
2995888a61cSMatthieu Baerts			timeout ${timeout_test} \
3005888a61cSMatthieu Baerts				ip netns exec ${connector_ns} \
3015888a61cSMatthieu Baerts					$mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
3025888a61cSMatthieu Baerts						$connect_addr > "$cout" &
3038b819a84SFlorian Westphal	fi
304b08fbf24SPaolo Abeni	cpid=$!
305b08fbf24SPaolo Abeni
3066208fd82SGeliang Tang	if [ $addr_nr_ns1 -gt 0 ]; then
3076208fd82SGeliang Tang		let add_nr_ns1=addr_nr_ns1
3086208fd82SGeliang Tang		counter=2
3096208fd82SGeliang Tang		sleep 1
3106208fd82SGeliang Tang		while [ $add_nr_ns1 -gt 0 ]; do
3116208fd82SGeliang Tang			local addr
3126208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3136208fd82SGeliang Tang				addr="dead:beef:$counter::1"
3146208fd82SGeliang Tang			else
3156208fd82SGeliang Tang				addr="10.0.$counter.1"
3166208fd82SGeliang Tang			fi
3176208fd82SGeliang Tang			ip netns exec $ns1 ./pm_nl_ctl add $addr flags signal
3186208fd82SGeliang Tang			let counter+=1
3196208fd82SGeliang Tang			let add_nr_ns1-=1
3206208fd82SGeliang Tang		done
3216208fd82SGeliang Tang		sleep 1
3226208fd82SGeliang Tang	elif [ $addr_nr_ns1 -lt 0 ]; then
3232e8cbf45SGeliang Tang		let rm_nr_ns1=-addr_nr_ns1
3246fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
325dd72b0feSGeliang Tang			counter=1
326f87744adSGeliang Tang			dump=(`ip netns exec ${listener_ns} ./pm_nl_ctl dump`)
327f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
328f87744adSGeliang Tang				id=${dump[1]}
329dd72b0feSGeliang Tang				sleep 1
330dd72b0feSGeliang Tang
331dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns1 ]
332dd72b0feSGeliang Tang				do
333f87744adSGeliang Tang					ip netns exec ${listener_ns} ./pm_nl_ctl del $id
334dd72b0feSGeliang Tang					sleep 1
335dd72b0feSGeliang Tang					let counter+=1
336f87744adSGeliang Tang					let id+=1
337dd72b0feSGeliang Tang				done
338f87744adSGeliang Tang			fi
3395e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 8 ]; then
3406fe4ccdcSGeliang Tang			sleep 1
3416fe4ccdcSGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl flush
3425e287fe7SGeliang Tang		elif [ $rm_nr_ns1 -eq 9 ]; then
3435e287fe7SGeliang Tang			sleep 1
3445e287fe7SGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl del 0 ${connect_addr}
3456fe4ccdcSGeliang Tang		fi
346dd72b0feSGeliang Tang	fi
347dd72b0feSGeliang Tang
3486208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
3496208fd82SGeliang Tang		let add_nr_ns2=addr_nr_ns2
3506208fd82SGeliang Tang		counter=3
3516208fd82SGeliang Tang		sleep 1
3526208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
3536208fd82SGeliang Tang			local addr
3546208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3556208fd82SGeliang Tang				addr="dead:beef:$counter::2"
3566208fd82SGeliang Tang			else
3576208fd82SGeliang Tang				addr="10.0.$counter.2"
3586208fd82SGeliang Tang			fi
3596208fd82SGeliang Tang			ip netns exec $ns2 ./pm_nl_ctl add $addr flags subflow
3606208fd82SGeliang Tang			let counter+=1
3616208fd82SGeliang Tang			let add_nr_ns2-=1
3626208fd82SGeliang Tang		done
3636208fd82SGeliang Tang		sleep 1
3646208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
3652e8cbf45SGeliang Tang		let rm_nr_ns2=-addr_nr_ns2
3666fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
367dd72b0feSGeliang Tang			counter=1
368f87744adSGeliang Tang			dump=(`ip netns exec ${connector_ns} ./pm_nl_ctl dump`)
369f87744adSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
370f87744adSGeliang Tang				id=${dump[1]}
371dd72b0feSGeliang Tang				sleep 1
372dd72b0feSGeliang Tang
373dd72b0feSGeliang Tang				while [ $counter -le $rm_nr_ns2 ]
374dd72b0feSGeliang Tang				do
375f87744adSGeliang Tang					ip netns exec ${connector_ns} ./pm_nl_ctl del $id
376dd72b0feSGeliang Tang					sleep 1
377dd72b0feSGeliang Tang					let counter+=1
378f87744adSGeliang Tang					let id+=1
379dd72b0feSGeliang Tang				done
380f87744adSGeliang Tang			fi
3815e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 8 ]; then
3826fe4ccdcSGeliang Tang			sleep 1
3836fe4ccdcSGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl flush
3845e287fe7SGeliang Tang		elif [ $rm_nr_ns2 -eq 9 ]; then
3855e287fe7SGeliang Tang			local addr
3865e287fe7SGeliang Tang			if is_v6 "${connect_addr}"; then
3875e287fe7SGeliang Tang				addr="dead:beef:1::2"
3885e287fe7SGeliang Tang			else
3895e287fe7SGeliang Tang				addr="10.0.1.2"
3905e287fe7SGeliang Tang			fi
3915e287fe7SGeliang Tang			sleep 1
3925e287fe7SGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl del 0 $addr
3936fe4ccdcSGeliang Tang		fi
394dd72b0feSGeliang Tang	fi
395dd72b0feSGeliang Tang
396718eb44eSGeliang Tang	if [ ! -z $bkup ]; then
397718eb44eSGeliang Tang		sleep 1
398718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
399718eb44eSGeliang Tang			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
400718eb44eSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
401718eb44eSGeliang Tang				addr=${dump[${#dump[@]} - 1]}
402718eb44eSGeliang Tang				backup="ip netns exec $netns ./pm_nl_ctl set $addr flags $bkup"
403718eb44eSGeliang Tang				$backup
404718eb44eSGeliang Tang			fi
405718eb44eSGeliang Tang		done
406718eb44eSGeliang Tang	fi
407718eb44eSGeliang Tang
408b08fbf24SPaolo Abeni	wait $cpid
409b08fbf24SPaolo Abeni	retc=$?
410b08fbf24SPaolo Abeni	wait $spid
411b08fbf24SPaolo Abeni	rets=$?
412b08fbf24SPaolo Abeni
413b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
414b08fbf24SPaolo Abeni	    sleep 1
415b08fbf24SPaolo Abeni	    kill $cappid
416b08fbf24SPaolo Abeni	fi
417b08fbf24SPaolo Abeni
418c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
419c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${listener_ns}.out
420c2a55e8fSMatthieu Baerts	NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
421c2a55e8fSMatthieu Baerts		nstat | grep Tcp > /tmp/${connector_ns}.out
422c2a55e8fSMatthieu Baerts
423b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
424b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
4258b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
426c2a55e8fSMatthieu Baerts		ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port"
427c2a55e8fSMatthieu Baerts		cat /tmp/${listener_ns}.out
4288b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
429c2a55e8fSMatthieu Baerts		ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port"
430c2a55e8fSMatthieu Baerts		cat /tmp/${connector_ns}.out
431b08fbf24SPaolo Abeni
432b08fbf24SPaolo Abeni		cat "$capout"
4338b819a84SFlorian Westphal		ret=1
434b08fbf24SPaolo Abeni		return 1
435b08fbf24SPaolo Abeni	fi
436b08fbf24SPaolo Abeni
437b08fbf24SPaolo Abeni	check_transfer $sin $cout "file received by client"
438b08fbf24SPaolo Abeni	retc=$?
4398b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
440b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
4418b819a84SFlorian Westphal	else
4428b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
4438b819a84SFlorian Westphal	fi
444b08fbf24SPaolo Abeni	rets=$?
445b08fbf24SPaolo Abeni
446b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
447b08fbf24SPaolo Abeni		cat "$capout"
448b08fbf24SPaolo Abeni		return 0
449b08fbf24SPaolo Abeni	fi
450b08fbf24SPaolo Abeni
451b08fbf24SPaolo Abeni	cat "$capout"
452b08fbf24SPaolo Abeni	return 1
453b08fbf24SPaolo Abeni}
454b08fbf24SPaolo Abeni
455b08fbf24SPaolo Abenimake_file()
456b08fbf24SPaolo Abeni{
457b08fbf24SPaolo Abeni	name=$1
458b08fbf24SPaolo Abeni	who=$2
4598b819a84SFlorian Westphal	size=$3
460b08fbf24SPaolo Abeni
4618b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
462b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
463b08fbf24SPaolo Abeni
4648b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
465b08fbf24SPaolo Abeni}
466b08fbf24SPaolo Abeni
467b08fbf24SPaolo Abenirun_tests()
468b08fbf24SPaolo Abeni{
469b08fbf24SPaolo Abeni	listener_ns="$1"
470b08fbf24SPaolo Abeni	connector_ns="$2"
471b08fbf24SPaolo Abeni	connect_addr="$3"
4728b819a84SFlorian Westphal	test_linkfail="${4:-0}"
4732e8cbf45SGeliang Tang	addr_nr_ns1="${5:-0}"
4742e8cbf45SGeliang Tang	addr_nr_ns2="${6:-0}"
4758b819a84SFlorian Westphal	speed="${7:-fast}"
476718eb44eSGeliang Tang	bkup="${8:-""}"
477b08fbf24SPaolo Abeni	lret=0
4788b819a84SFlorian Westphal	oldin=""
4798b819a84SFlorian Westphal
4808b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
4818b819a84SFlorian Westphal		size=$((RANDOM%1024))
4828b819a84SFlorian Westphal		size=$((size+1))
4838b819a84SFlorian Westphal		size=$((size*128))
4848b819a84SFlorian Westphal
4858b819a84SFlorian Westphal		oldin=$(mktemp)
4868b819a84SFlorian Westphal		cp "$cin" "$oldin"
4878b819a84SFlorian Westphal		make_file "$cin" "client" $size
4888b819a84SFlorian Westphal	fi
489b08fbf24SPaolo Abeni
4908d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
4912e8cbf45SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${bkup}
492b08fbf24SPaolo Abeni	lret=$?
4938b819a84SFlorian Westphal
4948b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
4958b819a84SFlorian Westphal		cp "$oldin" "$cin"
4968b819a84SFlorian Westphal		rm -f "$oldin"
4978b819a84SFlorian Westphal	fi
4988b819a84SFlorian Westphal
499b08fbf24SPaolo Abeni	if [ $lret -ne 0 ]; then
500b08fbf24SPaolo Abeni		ret=$lret
501b08fbf24SPaolo Abeni		return
502b08fbf24SPaolo Abeni	fi
503b08fbf24SPaolo Abeni}
504b08fbf24SPaolo Abeni
505af66d3e1SGeliang Tangchk_csum_nr()
506af66d3e1SGeliang Tang{
507af66d3e1SGeliang Tang	local msg=${1:-""}
508af66d3e1SGeliang Tang	local count
509af66d3e1SGeliang Tang	local dump_stats
510af66d3e1SGeliang Tang
511af66d3e1SGeliang Tang	if [ ! -z "$msg" ]; then
512af66d3e1SGeliang Tang		printf "%02u" "$TEST_COUNT"
513af66d3e1SGeliang Tang	else
514af66d3e1SGeliang Tang		echo -n "  "
515af66d3e1SGeliang Tang	fi
516af66d3e1SGeliang Tang	printf " %-36s %s" "$msg" "sum"
517af66d3e1SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
518af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
519af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
520af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
521af66d3e1SGeliang Tang		ret=1
522af66d3e1SGeliang Tang		dump_stats=1
523af66d3e1SGeliang Tang	else
524af66d3e1SGeliang Tang		echo -n "[ ok ]"
525af66d3e1SGeliang Tang	fi
526af66d3e1SGeliang Tang	echo -n " - csum  "
527af66d3e1SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}'`
528af66d3e1SGeliang Tang	[ -z "$count" ] && count=0
529af66d3e1SGeliang Tang	if [ "$count" != 0 ]; then
530af66d3e1SGeliang Tang		echo "[fail] got $count data checksum error[s] expected 0"
531af66d3e1SGeliang Tang		ret=1
532af66d3e1SGeliang Tang		dump_stats=1
533af66d3e1SGeliang Tang	else
534af66d3e1SGeliang Tang		echo "[ ok ]"
535af66d3e1SGeliang Tang	fi
536af66d3e1SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
537af66d3e1SGeliang Tang		echo Server ns stats
538af66d3e1SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
539af66d3e1SGeliang Tang		echo Client ns stats
540af66d3e1SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
541af66d3e1SGeliang Tang	fi
542af66d3e1SGeliang Tang}
543af66d3e1SGeliang Tang
544b08fbf24SPaolo Abenichk_join_nr()
545b08fbf24SPaolo Abeni{
546b08fbf24SPaolo Abeni	local msg="$1"
547b08fbf24SPaolo Abeni	local syn_nr=$2
548b08fbf24SPaolo Abeni	local syn_ack_nr=$3
549b08fbf24SPaolo Abeni	local ack_nr=$4
550b08fbf24SPaolo Abeni	local count
551b08fbf24SPaolo Abeni	local dump_stats
552b08fbf24SPaolo Abeni
55300587187SFlorian Westphal	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
554b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
555b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
556b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
557b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
558b08fbf24SPaolo Abeni		ret=1
559b08fbf24SPaolo Abeni		dump_stats=1
560b08fbf24SPaolo Abeni	else
561b08fbf24SPaolo Abeni		echo -n "[ ok ]"
562b08fbf24SPaolo Abeni	fi
563b08fbf24SPaolo Abeni
564b08fbf24SPaolo Abeni	echo -n " - synack"
565b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
566b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
567b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
568b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
569b08fbf24SPaolo Abeni		ret=1
570b08fbf24SPaolo Abeni		dump_stats=1
571b08fbf24SPaolo Abeni	else
572b08fbf24SPaolo Abeni		echo -n "[ ok ]"
573b08fbf24SPaolo Abeni	fi
574b08fbf24SPaolo Abeni
575b08fbf24SPaolo Abeni	echo -n " - ack"
576b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
577b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
578b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
579b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
580b08fbf24SPaolo Abeni		ret=1
581b08fbf24SPaolo Abeni		dump_stats=1
582b08fbf24SPaolo Abeni	else
583b08fbf24SPaolo Abeni		echo "[ ok ]"
584b08fbf24SPaolo Abeni	fi
585b08fbf24SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
586b08fbf24SPaolo Abeni		echo Server ns stats
587b08fbf24SPaolo Abeni		ip netns exec $ns1 nstat -as | grep MPTcp
588b08fbf24SPaolo Abeni		echo Client ns stats
589b08fbf24SPaolo Abeni		ip netns exec $ns2 nstat -as | grep MPTcp
590b08fbf24SPaolo Abeni	fi
591af66d3e1SGeliang Tang	if [ $checksum -eq 1 ]; then
592af66d3e1SGeliang Tang		chk_csum_nr
593af66d3e1SGeliang Tang	fi
594b08fbf24SPaolo Abeni}
595b08fbf24SPaolo Abeni
596be613160SGeliang Tangchk_add_nr()
597be613160SGeliang Tang{
598be613160SGeliang Tang	local add_nr=$1
599be613160SGeliang Tang	local echo_nr=$2
6008a127bf6SGeliang Tang	local port_nr=${3:-0}
6018a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
6028a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
6038a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
6048a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
6058a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
606be613160SGeliang Tang	local count
607be613160SGeliang Tang	local dump_stats
608be613160SGeliang Tang
609be613160SGeliang Tang	printf "%-39s %s" " " "add"
610be613160SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
611be613160SGeliang Tang	[ -z "$count" ] && count=0
612be613160SGeliang Tang	if [ "$count" != "$add_nr" ]; then
613be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
614be613160SGeliang Tang		ret=1
615be613160SGeliang Tang		dump_stats=1
616be613160SGeliang Tang	else
617be613160SGeliang Tang		echo -n "[ ok ]"
618be613160SGeliang Tang	fi
619be613160SGeliang Tang
620be613160SGeliang Tang	echo -n " - echo  "
621be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
622be613160SGeliang Tang	[ -z "$count" ] && count=0
623be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
624be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
625be613160SGeliang Tang		ret=1
626be613160SGeliang Tang		dump_stats=1
627be613160SGeliang Tang	else
6288a127bf6SGeliang Tang		echo -n "[ ok ]"
6298a127bf6SGeliang Tang	fi
6308a127bf6SGeliang Tang
6318a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
6328a127bf6SGeliang Tang		echo -n " - pt "
6338a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
6348a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6358a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
6368a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
6378a127bf6SGeliang Tang			ret=1
6388a127bf6SGeliang Tang			dump_stats=1
6398a127bf6SGeliang Tang		else
640be613160SGeliang Tang			echo "[ ok ]"
641be613160SGeliang Tang		fi
642be613160SGeliang Tang
6438a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
6448a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
6458a127bf6SGeliang Tang			awk '{print $2}'`
6468a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6478a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
6488a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
6498a127bf6SGeliang Tang				port-number expected $syn_nr"
6508a127bf6SGeliang Tang			ret=1
6518a127bf6SGeliang Tang			dump_stats=1
6528a127bf6SGeliang Tang		else
6538a127bf6SGeliang Tang			echo -n "[ ok ]"
6548a127bf6SGeliang Tang		fi
6558a127bf6SGeliang Tang
6568a127bf6SGeliang Tang		echo -n " - synack"
6578a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
6588a127bf6SGeliang Tang			awk '{print $2}'`
6598a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6608a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
6618a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
6628a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
6638a127bf6SGeliang Tang			ret=1
6648a127bf6SGeliang Tang			dump_stats=1
6658a127bf6SGeliang Tang		else
6668a127bf6SGeliang Tang			echo -n "[ ok ]"
6678a127bf6SGeliang Tang		fi
6688a127bf6SGeliang Tang
6698a127bf6SGeliang Tang		echo -n " - ack"
6708a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
6718a127bf6SGeliang Tang			awk '{print $2}'`
6728a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6738a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
6748a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
6758a127bf6SGeliang Tang				port-number expected $ack_nr"
6768a127bf6SGeliang Tang			ret=1
6778a127bf6SGeliang Tang			dump_stats=1
6788a127bf6SGeliang Tang		else
6798a127bf6SGeliang Tang			echo "[ ok ]"
6808a127bf6SGeliang Tang		fi
6818a127bf6SGeliang Tang
6828a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
6838a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
6848a127bf6SGeliang Tang			awk '{print $2}'`
6858a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6868a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
6878a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
6888a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
6898a127bf6SGeliang Tang			ret=1
6908a127bf6SGeliang Tang			dump_stats=1
6918a127bf6SGeliang Tang		else
6928a127bf6SGeliang Tang			echo -n "[ ok ]"
6938a127bf6SGeliang Tang		fi
6948a127bf6SGeliang Tang
6958a127bf6SGeliang Tang		echo -n " - ack   "
6968a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
6978a127bf6SGeliang Tang			awk '{print $2}'`
6988a127bf6SGeliang Tang		[ -z "$count" ] && count=0
6998a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
7008a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
7018a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
7028a127bf6SGeliang Tang			ret=1
7038a127bf6SGeliang Tang			dump_stats=1
7048a127bf6SGeliang Tang		else
7058a127bf6SGeliang Tang			echo "[ ok ]"
7068a127bf6SGeliang Tang		fi
7078a127bf6SGeliang Tang	else
7088a127bf6SGeliang Tang		echo ""
7098a127bf6SGeliang Tang	fi
7108a127bf6SGeliang Tang
711be613160SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
712be613160SGeliang Tang		echo Server ns stats
713be613160SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
714be613160SGeliang Tang		echo Client ns stats
715be613160SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
716be613160SGeliang Tang	fi
717be613160SGeliang Tang}
718be613160SGeliang Tang
719dd72b0feSGeliang Tangchk_rm_nr()
720dd72b0feSGeliang Tang{
721dd72b0feSGeliang Tang	local rm_addr_nr=$1
722dd72b0feSGeliang Tang	local rm_subflow_nr=$2
7237028ba8aSGeliang Tang	local invert=${3:-""}
724dd72b0feSGeliang Tang	local count
725dd72b0feSGeliang Tang	local dump_stats
7267028ba8aSGeliang Tang	local addr_ns
7277028ba8aSGeliang Tang	local subflow_ns
7287028ba8aSGeliang Tang
7297028ba8aSGeliang Tang	if [ -z $invert ]; then
7307028ba8aSGeliang Tang		addr_ns=$ns1
7317028ba8aSGeliang Tang		subflow_ns=$ns2
7327028ba8aSGeliang Tang	elif [ $invert = "invert" ]; then
7337028ba8aSGeliang Tang		addr_ns=$ns2
7347028ba8aSGeliang Tang		subflow_ns=$ns1
7357028ba8aSGeliang Tang	fi
736dd72b0feSGeliang Tang
737dd72b0feSGeliang Tang	printf "%-39s %s" " " "rm "
7387028ba8aSGeliang Tang	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
739dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
740dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
741dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
742dd72b0feSGeliang Tang		ret=1
743dd72b0feSGeliang Tang		dump_stats=1
744dd72b0feSGeliang Tang	else
745dd72b0feSGeliang Tang		echo -n "[ ok ]"
746dd72b0feSGeliang Tang	fi
747dd72b0feSGeliang Tang
748dd72b0feSGeliang Tang	echo -n " - sf    "
7497028ba8aSGeliang Tang	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
750dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
751dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
752dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
753dd72b0feSGeliang Tang		ret=1
754dd72b0feSGeliang Tang		dump_stats=1
755dd72b0feSGeliang Tang	else
756dd72b0feSGeliang Tang		echo "[ ok ]"
757dd72b0feSGeliang Tang	fi
758dd72b0feSGeliang Tang
759dd72b0feSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
760dd72b0feSGeliang Tang		echo Server ns stats
761dd72b0feSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
762dd72b0feSGeliang Tang		echo Client ns stats
763dd72b0feSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
764dd72b0feSGeliang Tang	fi
765dd72b0feSGeliang Tang}
766dd72b0feSGeliang Tang
767718eb44eSGeliang Tangchk_prio_nr()
768718eb44eSGeliang Tang{
769718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
770718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
771718eb44eSGeliang Tang	local count
772718eb44eSGeliang Tang	local dump_stats
773718eb44eSGeliang Tang
774718eb44eSGeliang Tang	printf "%-39s %s" " " "ptx"
775718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
776718eb44eSGeliang Tang	[ -z "$count" ] && count=0
777718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
778718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
779718eb44eSGeliang Tang		ret=1
780718eb44eSGeliang Tang		dump_stats=1
781718eb44eSGeliang Tang	else
782718eb44eSGeliang Tang		echo -n "[ ok ]"
783718eb44eSGeliang Tang	fi
784718eb44eSGeliang Tang
785718eb44eSGeliang Tang	echo -n " - prx   "
786718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
787718eb44eSGeliang Tang	[ -z "$count" ] && count=0
788718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
789718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
790718eb44eSGeliang Tang		ret=1
791718eb44eSGeliang Tang		dump_stats=1
792718eb44eSGeliang Tang	else
793718eb44eSGeliang Tang		echo "[ ok ]"
794718eb44eSGeliang Tang	fi
795718eb44eSGeliang Tang
796718eb44eSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
797718eb44eSGeliang Tang		echo Server ns stats
798718eb44eSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
799718eb44eSGeliang Tang		echo Client ns stats
800718eb44eSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
801718eb44eSGeliang Tang	fi
802718eb44eSGeliang Tang}
803718eb44eSGeliang Tang
8041002b89fSGeliang Tangsubflows_tests()
8051002b89fSGeliang Tang{
8061002b89fSGeliang Tang	reset
807b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
808b08fbf24SPaolo Abeni	chk_join_nr "no JOIN" "0" "0" "0"
809b08fbf24SPaolo Abeni
8101002b89fSGeliang Tang	# subflow limited by client
811b08fbf24SPaolo Abeni	reset
812b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
813b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
814b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by client" 0 0 0
815b08fbf24SPaolo Abeni
8161002b89fSGeliang Tang	# subflow limited by server
817b08fbf24SPaolo Abeni	reset
818b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
819b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
820b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
821b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by server" 1 1 0
822b08fbf24SPaolo Abeni
823b08fbf24SPaolo Abeni	# subflow
824b08fbf24SPaolo Abeni	reset
825b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
826b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
827b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
828b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
829b08fbf24SPaolo Abeni	chk_join_nr "single subflow" 1 1 1
830b08fbf24SPaolo Abeni
831b08fbf24SPaolo Abeni	# multiple subflows
832b08fbf24SPaolo Abeni	reset
833b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
834b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
835b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
836b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
837b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
838b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows" 2 2 2
839b08fbf24SPaolo Abeni
840b08fbf24SPaolo Abeni	# multiple subflows limited by serverf
841b08fbf24SPaolo Abeni	reset
842b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
843b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
844b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
845b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
846b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
847b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows, limited by server" 2 2 1
848c3eaa5f6SGeliang Tang
849c3eaa5f6SGeliang Tang	# single subflow, dev
850c3eaa5f6SGeliang Tang	reset
851c3eaa5f6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
852c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
853c3eaa5f6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow dev ns2eth3
854c3eaa5f6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
855c3eaa5f6SGeliang Tang	chk_join_nr "single subflow, dev" 1 1 1
8561002b89fSGeliang Tang}
857b08fbf24SPaolo Abeni
8581002b89fSGeliang Tangsignal_address_tests()
8591002b89fSGeliang Tang{
860b08fbf24SPaolo Abeni	# add_address, unused
861b08fbf24SPaolo Abeni	reset
862b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
863b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
864b08fbf24SPaolo Abeni	chk_join_nr "unused signal address" 0 0 0
865be613160SGeliang Tang	chk_add_nr 1 1
866b08fbf24SPaolo Abeni
867b08fbf24SPaolo Abeni	# accept and use add_addr
868b08fbf24SPaolo Abeni	reset
869b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
870b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
871b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
872b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
873b08fbf24SPaolo Abeni	chk_join_nr "signal address" 1 1 1
874be613160SGeliang Tang	chk_add_nr 1 1
875b08fbf24SPaolo Abeni
876b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
877b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
878b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
879b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
880b08fbf24SPaolo Abeni	reset
881b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
882b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
883b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
884b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
885b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
886b08fbf24SPaolo Abeni	chk_join_nr "subflow and signal" 2 2 2
887be613160SGeliang Tang	chk_add_nr 1 1
888b08fbf24SPaolo Abeni
889b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
890b08fbf24SPaolo Abeni	reset
891b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
892b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
893b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
894b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
895b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
896b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
897b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows and signal" 3 3 3
898be613160SGeliang Tang	chk_add_nr 1 1
899ef360019SGeliang Tang
900ef360019SGeliang Tang	# signal addresses
901ef360019SGeliang Tang	reset
902ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
903ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
904ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
905ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
906ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
907ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
908ef360019SGeliang Tang	chk_join_nr "signal addresses" 3 3 3
909ef360019SGeliang Tang	chk_add_nr 3 3
910ef360019SGeliang Tang
911ef360019SGeliang Tang	# signal invalid addresses
912ef360019SGeliang Tang	reset
913ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
914ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
915ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
916ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
917ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
918ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
919ef360019SGeliang Tang	chk_join_nr "signal invalid addresses" 1 1 1
920ef360019SGeliang Tang	chk_add_nr 3 3
9211002b89fSGeliang Tang}
922b08fbf24SPaolo Abeni
9231002b89fSGeliang Tanglink_failure_tests()
9241002b89fSGeliang Tang{
9258b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
9268b819a84SFlorian Westphal	reset
9278b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
9288b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
9298b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
9308b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
9318b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
9328b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 1
9338b819a84SFlorian Westphal	chk_join_nr "multiple flows, signal, link failure" 3 3 3
9348b819a84SFlorian Westphal	chk_add_nr 1 1
9351002b89fSGeliang Tang}
9368b819a84SFlorian Westphal
9371002b89fSGeliang Tangadd_addr_timeout_tests()
9381002b89fSGeliang Tang{
9398d014eaaSGeliang Tang	# add_addr timeout
9408d014eaaSGeliang Tang	reset_with_add_addr_timeout
9418d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
9428d014eaaSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
9438d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
9448b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
9458d014eaaSGeliang Tang	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
9468d014eaaSGeliang Tang	chk_add_nr 4 0
9478d014eaaSGeliang Tang
9481002b89fSGeliang Tang	# add_addr timeout IPv6
9491002b89fSGeliang Tang	reset_with_add_addr_timeout 6
9501002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
9511002b89fSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
9521002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
9531002b89fSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
9541002b89fSGeliang Tang	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
9551002b89fSGeliang Tang	chk_add_nr 4 0
9568da6229bSGeliang Tang
9578da6229bSGeliang Tang	# signal addresses timeout
9588da6229bSGeliang Tang	reset_with_add_addr_timeout
9598da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
9608da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
9618da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
9628da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
9638da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
9648da6229bSGeliang Tang	chk_join_nr "signal addresses, ADD_ADDR timeout" 2 2 2
9658da6229bSGeliang Tang	chk_add_nr 8 0
9668da6229bSGeliang Tang
9678da6229bSGeliang Tang	# signal invalid addresses timeout
9688da6229bSGeliang Tang	reset_with_add_addr_timeout
9698da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
9708da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
9718da6229bSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
9728da6229bSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
9738da6229bSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 least
9748da6229bSGeliang Tang	chk_join_nr "invalid address, ADD_ADDR timeout" 1 1 1
9758da6229bSGeliang Tang	chk_add_nr 8 0
9761002b89fSGeliang Tang}
9771002b89fSGeliang Tang
9781002b89fSGeliang Tangremove_tests()
9791002b89fSGeliang Tang{
980dd72b0feSGeliang Tang	# single subflow, remove
981dd72b0feSGeliang Tang	reset
982dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
983dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
984dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
9852e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
986dd72b0feSGeliang Tang	chk_join_nr "remove single subflow" 1 1 1
987dd72b0feSGeliang Tang	chk_rm_nr 1 1
988dd72b0feSGeliang Tang
989dd72b0feSGeliang Tang	# multiple subflows, remove
990dd72b0feSGeliang Tang	reset
991dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
992dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
993dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
994dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
9952e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
996dd72b0feSGeliang Tang	chk_join_nr "remove multiple subflows" 2 2 2
997dd72b0feSGeliang Tang	chk_rm_nr 2 2
998dd72b0feSGeliang Tang
999dd72b0feSGeliang Tang	# single address, remove
1000dd72b0feSGeliang Tang	reset
1001dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1002dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1003dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
10042e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
1005dd72b0feSGeliang Tang	chk_join_nr "remove single address" 1 1 1
1006dd72b0feSGeliang Tang	chk_add_nr 1 1
10077028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1008dd72b0feSGeliang Tang
1009dd72b0feSGeliang Tang	# subflow and signal, remove
1010dd72b0feSGeliang Tang	reset
1011dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1012dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1013dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1014dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
10152e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
1016dd72b0feSGeliang Tang	chk_join_nr "remove subflow and signal" 2 2 2
1017dd72b0feSGeliang Tang	chk_add_nr 1 1
1018dd72b0feSGeliang Tang	chk_rm_nr 1 1
1019dd72b0feSGeliang Tang
1020dd72b0feSGeliang Tang	# subflows and signal, remove
1021dd72b0feSGeliang Tang	reset
1022dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
1023dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1024dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
1025dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1026dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
10272e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
1028dd72b0feSGeliang Tang	chk_join_nr "remove subflows and signal" 3 3 3
1029dd72b0feSGeliang Tang	chk_add_nr 1 1
1030dd72b0feSGeliang Tang	chk_rm_nr 2 2
1031dd72b0feSGeliang Tang
1032ef360019SGeliang Tang	# addresses remove
1033ef360019SGeliang Tang	reset
1034ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1035ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1036ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1037ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1038ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1039ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1040ef360019SGeliang Tang	chk_join_nr "remove addresses" 3 3 3
1041ef360019SGeliang Tang	chk_add_nr 3 3
1042ef360019SGeliang Tang	chk_rm_nr 3 3 invert
1043ef360019SGeliang Tang
1044ef360019SGeliang Tang	# invalid addresses remove
1045ef360019SGeliang Tang	reset
1046ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1047ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1048ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1049ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1050ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1051ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -3 0 slow
1052ef360019SGeliang Tang	chk_join_nr "remove invalid addresses" 1 1 1
1053ef360019SGeliang Tang	chk_add_nr 3 3
1054ef360019SGeliang Tang	chk_rm_nr 3 1 invert
1055ef360019SGeliang Tang
10566fe4ccdcSGeliang Tang	# subflows and signal, flush
10576fe4ccdcSGeliang Tang	reset
10586fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
10596fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
10606fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
10616fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
10626fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
10632e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
10646fe4ccdcSGeliang Tang	chk_join_nr "flush subflows and signal" 3 3 3
10656fe4ccdcSGeliang Tang	chk_add_nr 1 1
10666fe4ccdcSGeliang Tang	chk_rm_nr 2 2
1067d2c4333aSGeliang Tang
1068d2c4333aSGeliang Tang	# subflows flush
1069d2c4333aSGeliang Tang	reset
1070d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1071d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1072d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow id 150
1073d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1074d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
1075d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1076d2c4333aSGeliang Tang	chk_join_nr "flush subflows" 3 3 3
1077d2c4333aSGeliang Tang	chk_rm_nr 3 3
1078d2c4333aSGeliang Tang
1079d2c4333aSGeliang Tang	# addresses flush
1080d2c4333aSGeliang Tang	reset
1081d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1082d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
1083d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1084d2c4333aSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
1085d2c4333aSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1086d2c4333aSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
1087d2c4333aSGeliang Tang	chk_join_nr "flush addresses" 3 3 3
1088d2c4333aSGeliang Tang	chk_add_nr 3 3
1089d2c4333aSGeliang Tang	chk_rm_nr 3 3 invert
1090ef360019SGeliang Tang
1091ef360019SGeliang Tang	# invalid addresses flush
1092ef360019SGeliang Tang	reset
1093ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
1094ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.12.1 flags signal
1095ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
1096ef360019SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.14.1 flags signal
1097ef360019SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
1098ef360019SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow
1099ef360019SGeliang Tang	chk_join_nr "flush invalid addresses" 1 1 1
1100ef360019SGeliang Tang	chk_add_nr 3 3
1101ef360019SGeliang Tang	chk_rm_nr 3 1 invert
11025e287fe7SGeliang Tang
11035e287fe7SGeliang Tang	# remove id 0 subflow
11045e287fe7SGeliang Tang	reset
11055e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11065e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
11075e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11085e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
11095e287fe7SGeliang Tang	chk_join_nr "remove id 0 subflow" 1 1 1
11105e287fe7SGeliang Tang	chk_rm_nr 1 1
11115e287fe7SGeliang Tang
11125e287fe7SGeliang Tang	# remove id 0 address
11135e287fe7SGeliang Tang	reset
11145e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11155e287fe7SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
11165e287fe7SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11175e287fe7SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
11185e287fe7SGeliang Tang	chk_join_nr "remove id 0 address" 1 1 1
11195e287fe7SGeliang Tang	chk_add_nr 1 1
11205e287fe7SGeliang Tang	chk_rm_nr 1 1 invert
11211002b89fSGeliang Tang}
11226fe4ccdcSGeliang Tang
11231002b89fSGeliang Tangadd_tests()
11241002b89fSGeliang Tang{
11256208fd82SGeliang Tang	# add single subflow
11266208fd82SGeliang Tang	reset
11276208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11286208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
11296208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
11306208fd82SGeliang Tang	chk_join_nr "add single subflow" 1 1 1
11316208fd82SGeliang Tang
11326208fd82SGeliang Tang	# add signal address
11336208fd82SGeliang Tang	reset
11346208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
11356208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11366208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
11376208fd82SGeliang Tang	chk_join_nr "add signal address" 1 1 1
11386208fd82SGeliang Tang	chk_add_nr 1 1
11396208fd82SGeliang Tang
11406208fd82SGeliang Tang	# add multiple subflows
11416208fd82SGeliang Tang	reset
11426208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11436208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
11446208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
11456208fd82SGeliang Tang	chk_join_nr "add multiple subflows" 2 2 2
11466208fd82SGeliang Tang
11476208fd82SGeliang Tang	# add multiple subflows IPv6
11486208fd82SGeliang Tang	reset
11496208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11506208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
11516208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
11526208fd82SGeliang Tang	chk_join_nr "add multiple subflows IPv6" 2 2 2
11536208fd82SGeliang Tang
11546208fd82SGeliang Tang	# add multiple addresses IPv6
11556208fd82SGeliang Tang	reset
11566208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11576208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11586208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
11596208fd82SGeliang Tang	chk_join_nr "add multiple addresses IPv6" 2 2 2
11606208fd82SGeliang Tang	chk_add_nr 2 2
11611002b89fSGeliang Tang}
11626208fd82SGeliang Tang
11631002b89fSGeliang Tangipv6_tests()
11641002b89fSGeliang Tang{
1165523514edSGeliang Tang	# subflow IPv6
1166523514edSGeliang Tang	reset
1167523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1168523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1169523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
1170523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1171523514edSGeliang Tang	chk_join_nr "single subflow IPv6" 1 1 1
1172523514edSGeliang Tang
1173523514edSGeliang Tang	# add_address, unused IPv6
1174523514edSGeliang Tang	reset
1175523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1176523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1177523514edSGeliang Tang	chk_join_nr "unused signal address IPv6" 0 0 0
1178523514edSGeliang Tang	chk_add_nr 1 1
1179523514edSGeliang Tang
1180523514edSGeliang Tang	# signal address IPv6
1181523514edSGeliang Tang	reset
1182523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1183523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1184523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1185523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
1186523514edSGeliang Tang	chk_join_nr "single address IPv6" 1 1 1
1187523514edSGeliang Tang	chk_add_nr 1 1
1188523514edSGeliang Tang
1189523514edSGeliang Tang	# single address IPv6, remove
1190523514edSGeliang Tang	reset
1191523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1192523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1193523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
11942e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
1195523514edSGeliang Tang	chk_join_nr "remove single address IPv6" 1 1 1
1196523514edSGeliang Tang	chk_add_nr 1 1
11977028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
1198523514edSGeliang Tang
1199523514edSGeliang Tang	# subflow and signal IPv6, remove
1200523514edSGeliang Tang	reset
1201523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
1202523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
1203523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
1204523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
12052e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
1206523514edSGeliang Tang	chk_join_nr "remove subflow and signal IPv6" 2 2 2
1207523514edSGeliang Tang	chk_add_nr 1 1
1208523514edSGeliang Tang	chk_rm_nr 1 1
12091002b89fSGeliang Tang}
1210523514edSGeliang Tang
12111002b89fSGeliang Tangv4mapped_tests()
12121002b89fSGeliang Tang{
1213a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
1214a6094788SGeliang Tang	reset
1215a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1216a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1217a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1218a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1219a6094788SGeliang Tang	chk_join_nr "single subflow IPv4-mapped" 1 1 1
1220a6094788SGeliang Tang
1221a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
1222a6094788SGeliang Tang	reset
1223a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1224a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1225a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1226a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1227a6094788SGeliang Tang	chk_join_nr "signal address IPv4-mapped" 1 1 1
1228a6094788SGeliang Tang	chk_add_nr 1 1
1229a6094788SGeliang Tang
1230a6094788SGeliang Tang	# subflow v4-map-v6
1231a6094788SGeliang Tang	reset
1232a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1233a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1234a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1235a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1236a6094788SGeliang Tang	chk_join_nr "single subflow v4-map-v6" 1 1 1
1237a6094788SGeliang Tang
1238a6094788SGeliang Tang	# signal address v4-map-v6
1239a6094788SGeliang Tang	reset
1240a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1241a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1242a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1243a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1244a6094788SGeliang Tang	chk_join_nr "signal address v4-map-v6" 1 1 1
1245a6094788SGeliang Tang	chk_add_nr 1 1
1246a6094788SGeliang Tang
1247a6094788SGeliang Tang	# subflow v6-map-v4
1248a6094788SGeliang Tang	reset
1249a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1250a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1251a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1252a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1253a6094788SGeliang Tang	chk_join_nr "single subflow v6-map-v4" 1 1 1
1254a6094788SGeliang Tang
1255a6094788SGeliang Tang	# signal address v6-map-v4
1256a6094788SGeliang Tang	reset
1257a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1258a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1259a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1260a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1261a6094788SGeliang Tang	chk_join_nr "signal address v6-map-v4" 1 1 1
1262a6094788SGeliang Tang	chk_add_nr 1 1
1263a6094788SGeliang Tang
1264a6094788SGeliang Tang	# no subflow IPv6 to v4 address
1265a6094788SGeliang Tang	reset
1266a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1267a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1268a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::2 flags subflow
1269a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1270a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1271a6094788SGeliang Tang
1272a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1273a6094788SGeliang Tang	reset
1274a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1275a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1276a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::10.0.3.2 flags subflow
1277a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1278a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
1279a6094788SGeliang Tang
1280a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
1281a6094788SGeliang Tang	reset
1282a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1283a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1284a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1285a6094788SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1
1286a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
12871002b89fSGeliang Tang}
1288a6094788SGeliang Tang
12891002b89fSGeliang Tangbackup_tests()
12901002b89fSGeliang Tang{
1291718eb44eSGeliang Tang	# single subflow, backup
1292718eb44eSGeliang Tang	reset
1293718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1294718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1295718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,backup
1296718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
1297718eb44eSGeliang Tang	chk_join_nr "single subflow, backup" 1 1 1
1298718eb44eSGeliang Tang	chk_prio_nr 0 1
1299718eb44eSGeliang Tang
1300718eb44eSGeliang Tang	# single address, backup
1301718eb44eSGeliang Tang	reset
1302718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1303718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1304718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1305718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
1306718eb44eSGeliang Tang	chk_join_nr "single address, backup" 1 1 1
1307718eb44eSGeliang Tang	chk_add_nr 1 1
1308718eb44eSGeliang Tang	chk_prio_nr 1 0
13091002b89fSGeliang Tang}
1310718eb44eSGeliang Tang
13111002b89fSGeliang Tangadd_addr_ports_tests()
13121002b89fSGeliang Tang{
13138a127bf6SGeliang Tang	# signal address with port
13148a127bf6SGeliang Tang	reset
13158a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13168a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
13178a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13188a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
13198a127bf6SGeliang Tang	chk_join_nr "signal address with port" 1 1 1
13208a127bf6SGeliang Tang	chk_add_nr 1 1 1
13218a127bf6SGeliang Tang
13228a127bf6SGeliang Tang	# subflow and signal with port
13238a127bf6SGeliang Tang	reset
13248a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13258a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13268a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
13278a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
13288a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
13298a127bf6SGeliang Tang	chk_join_nr "subflow and signal with port" 2 2 2
13308a127bf6SGeliang Tang	chk_add_nr 1 1 1
13318a127bf6SGeliang Tang
13328a127bf6SGeliang Tang	# single address with port, remove
13338a127bf6SGeliang Tang	reset
13348a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
13358a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13368a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
13378a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
13388a127bf6SGeliang Tang	chk_join_nr "remove single address with port" 1 1 1
13398a127bf6SGeliang Tang	chk_add_nr 1 1 1
13407028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
13418a127bf6SGeliang Tang
13428a127bf6SGeliang Tang	# subflow and signal with port, remove
13438a127bf6SGeliang Tang	reset
13448a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
13458a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13468a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
13478a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
13488a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
13498a127bf6SGeliang Tang	chk_join_nr "remove subflow and signal with port" 2 2 2
13508a127bf6SGeliang Tang	chk_add_nr 1 1 1
13518a127bf6SGeliang Tang	chk_rm_nr 1 1
13528a127bf6SGeliang Tang
13538a127bf6SGeliang Tang	# subflows and signal with port, flush
13548a127bf6SGeliang Tang	reset
13558a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
13568a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13578a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
13588a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
13598a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
13608a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
13618a127bf6SGeliang Tang	chk_join_nr "flush subflows and signal with port" 3 3 3
13628a127bf6SGeliang Tang	chk_add_nr 1 1
13638a127bf6SGeliang Tang	chk_rm_nr 2 2
13648a127bf6SGeliang Tang
13658a127bf6SGeliang Tang	# multiple addresses with port
13668a127bf6SGeliang Tang	reset
13678a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
13688a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13698a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100
13708a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
13718a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
13728a127bf6SGeliang Tang	chk_join_nr "multiple addresses with port" 2 2 2
13738a127bf6SGeliang Tang	chk_add_nr 2 2 2
13748a127bf6SGeliang Tang
13758a127bf6SGeliang Tang	# multiple addresses with ports
13768a127bf6SGeliang Tang	reset
13778a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
13788a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
13798a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101
13808a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
13818a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
13828a127bf6SGeliang Tang	chk_join_nr "multiple addresses with ports" 2 2 2
13838a127bf6SGeliang Tang	chk_add_nr 2 2 2
13841002b89fSGeliang Tang}
13858a127bf6SGeliang Tang
13861002b89fSGeliang Tangsyncookies_tests()
13871002b89fSGeliang Tang{
138800587187SFlorian Westphal	# single subflow, syncookies
138900587187SFlorian Westphal	reset_with_cookies
139000587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
139100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
139200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
139300587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
139400587187SFlorian Westphal	chk_join_nr "single subflow with syn cookies" 1 1 1
139500587187SFlorian Westphal
139600587187SFlorian Westphal	# multiple subflows with syn cookies
139700587187SFlorian Westphal	reset_with_cookies
139800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
139900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
140000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
140100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
140200587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
140300587187SFlorian Westphal	chk_join_nr "multiple subflows with syn cookies" 2 2 2
140400587187SFlorian Westphal
140500587187SFlorian Westphal	# multiple subflows limited by server
140600587187SFlorian Westphal	reset_with_cookies
140700587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
140800587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
140900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
141000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
141100587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
1412*a7da4416SJianguo Wu	chk_join_nr "subflows limited by server w cookies" 2 1 1
141300587187SFlorian Westphal
141400587187SFlorian Westphal	# test signal address with cookies
141500587187SFlorian Westphal	reset_with_cookies
141600587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
141700587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
141800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
141900587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
142000587187SFlorian Westphal	chk_join_nr "signal address with syn cookies" 1 1 1
1421be613160SGeliang Tang	chk_add_nr 1 1
142200587187SFlorian Westphal
142300587187SFlorian Westphal	# test cookie with subflow and signal
142400587187SFlorian Westphal	reset_with_cookies
142500587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
142600587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
142700587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
142800587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
142900587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
143000587187SFlorian Westphal	chk_join_nr "subflow and signal w cookies" 2 2 2
1431be613160SGeliang Tang	chk_add_nr 1 1
143200587187SFlorian Westphal
143300587187SFlorian Westphal	# accept and use add_addr with additional subflows
143400587187SFlorian Westphal	reset_with_cookies
143500587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
143600587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
143700587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
143800587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
143900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
144000587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
144100587187SFlorian Westphal	chk_join_nr "subflows and signal w. cookies" 3 3 3
1442be613160SGeliang Tang	chk_add_nr 1 1
14431002b89fSGeliang Tang}
14441002b89fSGeliang Tang
1445af66d3e1SGeliang Tangchecksum_tests()
1446af66d3e1SGeliang Tang{
1447af66d3e1SGeliang Tang	# checksum test 0 0
1448af66d3e1SGeliang Tang	reset_with_checksum 0 0
1449af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1450af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1451af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1452af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 0"
1453af66d3e1SGeliang Tang
1454af66d3e1SGeliang Tang	# checksum test 1 1
1455af66d3e1SGeliang Tang	reset_with_checksum 1 1
1456af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1457af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1458af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1459af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 1"
1460af66d3e1SGeliang Tang
1461af66d3e1SGeliang Tang	# checksum test 0 1
1462af66d3e1SGeliang Tang	reset_with_checksum 0 1
1463af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1464af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1465af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1466af66d3e1SGeliang Tang	chk_csum_nr "checksum test 0 1"
1467af66d3e1SGeliang Tang
1468af66d3e1SGeliang Tang	# checksum test 1 0
1469af66d3e1SGeliang Tang	reset_with_checksum 1 0
1470af66d3e1SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1471af66d3e1SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1472af66d3e1SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1473af66d3e1SGeliang Tang	chk_csum_nr "checksum test 1 0"
1474af66d3e1SGeliang Tang}
1475af66d3e1SGeliang Tang
14760cddb4a6SGeliang Tangdeny_join_id0_tests()
14770cddb4a6SGeliang Tang{
14780cddb4a6SGeliang Tang	# subflow allow join id0 ns1
14790cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
14800cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
14810cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14820cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
14830cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
14840cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns1" 1 1 1
14850cddb4a6SGeliang Tang
14860cddb4a6SGeliang Tang	# subflow allow join id0 ns2
14870cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
14880cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
14890cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14900cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
14910cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
14920cddb4a6SGeliang Tang	chk_join_nr "single subflow allow join id0 ns2" 0 0 0
14930cddb4a6SGeliang Tang
14940cddb4a6SGeliang Tang	# signal address allow join id0 ns1
14950cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
14960cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
14970cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
14980cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
14990cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
15000cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15010cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns1" 1 1 1
15020cddb4a6SGeliang Tang	chk_add_nr 1 1
15030cddb4a6SGeliang Tang
15040cddb4a6SGeliang Tang	# signal address allow join id0 ns2
15050cddb4a6SGeliang Tang	# ADD_ADDRs are not affected by allow_join_id0 value.
15060cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
15070cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 1 1
15080cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
15090cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
15100cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15110cddb4a6SGeliang Tang	chk_join_nr "signal address allow join id0 ns2" 1 1 1
15120cddb4a6SGeliang Tang	chk_add_nr 1 1
15130cddb4a6SGeliang Tang
15140cddb4a6SGeliang Tang	# subflow and address allow join id0 ns1
15150cddb4a6SGeliang Tang	reset_with_allow_join_id0 1 0
15160cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
15170cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
15180cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
15190cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15200cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15210cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 1" 2 2 2
15220cddb4a6SGeliang Tang
15230cddb4a6SGeliang Tang	# subflow and address allow join id0 ns2
15240cddb4a6SGeliang Tang	reset_with_allow_join_id0 0 1
15250cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
15260cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
15270cddb4a6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
15280cddb4a6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
15290cddb4a6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
15300cddb4a6SGeliang Tang	chk_join_nr "subflow and address allow join id0 2" 1 1 1
15310cddb4a6SGeliang Tang}
15320cddb4a6SGeliang Tang
15331002b89fSGeliang Tangall_tests()
15341002b89fSGeliang Tang{
15351002b89fSGeliang Tang	subflows_tests
15361002b89fSGeliang Tang	signal_address_tests
15371002b89fSGeliang Tang	link_failure_tests
15381002b89fSGeliang Tang	add_addr_timeout_tests
15391002b89fSGeliang Tang	remove_tests
15401002b89fSGeliang Tang	add_tests
15411002b89fSGeliang Tang	ipv6_tests
15421002b89fSGeliang Tang	v4mapped_tests
15431002b89fSGeliang Tang	backup_tests
15441002b89fSGeliang Tang	add_addr_ports_tests
15451002b89fSGeliang Tang	syncookies_tests
1546af66d3e1SGeliang Tang	checksum_tests
15470cddb4a6SGeliang Tang	deny_join_id0_tests
15481002b89fSGeliang Tang}
15491002b89fSGeliang Tang
15501002b89fSGeliang Tangusage()
15511002b89fSGeliang Tang{
15521002b89fSGeliang Tang	echo "mptcp_join usage:"
15531002b89fSGeliang Tang	echo "  -f subflows_tests"
15541002b89fSGeliang Tang	echo "  -s signal_address_tests"
15551002b89fSGeliang Tang	echo "  -l link_failure_tests"
15561002b89fSGeliang Tang	echo "  -t add_addr_timeout_tests"
15571002b89fSGeliang Tang	echo "  -r remove_tests"
15581002b89fSGeliang Tang	echo "  -a add_tests"
15591002b89fSGeliang Tang	echo "  -6 ipv6_tests"
15601002b89fSGeliang Tang	echo "  -4 v4mapped_tests"
15611002b89fSGeliang Tang	echo "  -b backup_tests"
15621002b89fSGeliang Tang	echo "  -p add_addr_ports_tests"
1563a673321aSMat Martineau	echo "  -k syncookies_tests"
1564af66d3e1SGeliang Tang	echo "  -S checksum_tests"
15650cddb4a6SGeliang Tang	echo "  -d deny_join_id0_tests"
1566a673321aSMat Martineau	echo "  -c capture pcap files"
1567af66d3e1SGeliang Tang	echo "  -C enable data checksum"
15681002b89fSGeliang Tang	echo "  -h help"
15691002b89fSGeliang Tang}
15701002b89fSGeliang Tang
15711002b89fSGeliang Tangsin=$(mktemp)
15721002b89fSGeliang Tangsout=$(mktemp)
15731002b89fSGeliang Tangcin=$(mktemp)
15741002b89fSGeliang Tangcinsent=$(mktemp)
15751002b89fSGeliang Tangcout=$(mktemp)
15761002b89fSGeliang Tanginit
15771002b89fSGeliang Tangmake_file "$cin" "client" 1
15781002b89fSGeliang Tangmake_file "$sin" "server" 1
15791002b89fSGeliang Tangtrap cleanup EXIT
15801002b89fSGeliang Tang
1581a673321aSMat Martineaufor arg in "$@"; do
1582af66d3e1SGeliang Tang	# check for "capture/checksum" args before launching tests
1583a673321aSMat Martineau	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"c"[0-9a-zA-Z]*$ ]]; then
1584a673321aSMat Martineau		capture=1
1585a673321aSMat Martineau	fi
1586af66d3e1SGeliang Tang	if [[ "${arg}" =~ ^"-"[0-9a-zA-Z]*"C"[0-9a-zA-Z]*$ ]]; then
1587af66d3e1SGeliang Tang		checksum=1
1588af66d3e1SGeliang Tang	fi
1589a673321aSMat Martineau
1590af66d3e1SGeliang Tang	# exception for the capture/checksum options, the rest means: a part of the tests
1591af66d3e1SGeliang Tang	if [ "${arg}" != "-c" ] && [ "${arg}" != "-C" ]; then
1592a673321aSMat Martineau		do_all_tests=0
1593a673321aSMat Martineau	fi
1594a673321aSMat Martineaudone
1595a673321aSMat Martineau
1596a673321aSMat Martineauif [ $do_all_tests -eq 1 ]; then
15971002b89fSGeliang Tang	all_tests
15981002b89fSGeliang Tang	exit $ret
15991002b89fSGeliang Tangfi
16001002b89fSGeliang Tang
16010cddb4a6SGeliang Tangwhile getopts 'fsltra64bpkdchCS' opt; do
16021002b89fSGeliang Tang	case $opt in
16031002b89fSGeliang Tang		f)
16041002b89fSGeliang Tang			subflows_tests
16051002b89fSGeliang Tang			;;
16061002b89fSGeliang Tang		s)
16071002b89fSGeliang Tang			signal_address_tests
16081002b89fSGeliang Tang			;;
16091002b89fSGeliang Tang		l)
16101002b89fSGeliang Tang			link_failure_tests
16111002b89fSGeliang Tang			;;
16121002b89fSGeliang Tang		t)
16131002b89fSGeliang Tang			add_addr_timeout_tests
16141002b89fSGeliang Tang			;;
16151002b89fSGeliang Tang		r)
16161002b89fSGeliang Tang			remove_tests
16171002b89fSGeliang Tang			;;
16181002b89fSGeliang Tang		a)
16191002b89fSGeliang Tang			add_tests
16201002b89fSGeliang Tang			;;
16211002b89fSGeliang Tang		6)
16221002b89fSGeliang Tang			ipv6_tests
16231002b89fSGeliang Tang			;;
16241002b89fSGeliang Tang		4)
16251002b89fSGeliang Tang			v4mapped_tests
16261002b89fSGeliang Tang			;;
16271002b89fSGeliang Tang		b)
16281002b89fSGeliang Tang			backup_tests
16291002b89fSGeliang Tang			;;
16301002b89fSGeliang Tang		p)
16311002b89fSGeliang Tang			add_addr_ports_tests
16321002b89fSGeliang Tang			;;
1633a673321aSMat Martineau		k)
16341002b89fSGeliang Tang			syncookies_tests
16351002b89fSGeliang Tang			;;
1636af66d3e1SGeliang Tang		S)
1637af66d3e1SGeliang Tang			checksum_tests
1638af66d3e1SGeliang Tang			;;
16390cddb4a6SGeliang Tang		d)
16400cddb4a6SGeliang Tang			deny_join_id0_tests
16410cddb4a6SGeliang Tang			;;
1642a673321aSMat Martineau		c)
1643a673321aSMat Martineau			;;
1644af66d3e1SGeliang Tang		C)
1645af66d3e1SGeliang Tang			;;
16461002b89fSGeliang Tang		h | *)
16471002b89fSGeliang Tang			usage
16481002b89fSGeliang Tang			;;
16491002b89fSGeliang Tang	esac
16501002b89fSGeliang Tangdone
165100587187SFlorian Westphal
1652b08fbf24SPaolo Abeniexit $ret
1653