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
11b08fbf24SPaolo Abenitimeout=30
12dd72b0feSGeliang Tangmptcp_connect=""
13b08fbf24SPaolo Abenicapture=0
14b08fbf24SPaolo Abeni
15b08fbf24SPaolo AbeniTEST_COUNT=0
16b08fbf24SPaolo Abeni
178d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) ||
188d014eaaSGeliang Tang#				  (ip6 && (ip6[74] & 0xf0) == 0x30)'"
198d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14,
208d014eaaSGeliang Tang			       48 0 0 0,
218d014eaaSGeliang Tang			       84 0 0 240,
228d014eaaSGeliang Tang			       21 0 3 64,
238d014eaaSGeliang Tang			       48 0 0 54,
248d014eaaSGeliang Tang			       84 0 0 240,
258d014eaaSGeliang Tang			       21 6 7 48,
268d014eaaSGeliang Tang			       48 0 0 0,
278d014eaaSGeliang Tang			       84 0 0 240,
288d014eaaSGeliang Tang			       21 0 4 96,
298d014eaaSGeliang Tang			       48 0 0 74,
308d014eaaSGeliang Tang			       84 0 0 240,
318d014eaaSGeliang Tang			       21 0 1 48,
328d014eaaSGeliang Tang			       6 0 0 65535,
338d014eaaSGeliang Tang			       6 0 0 0"
348d014eaaSGeliang Tang
35b08fbf24SPaolo Abeniinit()
36b08fbf24SPaolo Abeni{
37b08fbf24SPaolo Abeni	capout=$(mktemp)
38b08fbf24SPaolo Abeni
39b08fbf24SPaolo Abeni	rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
40b08fbf24SPaolo Abeni
41b08fbf24SPaolo Abeni	ns1="ns1-$rndh"
42b08fbf24SPaolo Abeni	ns2="ns2-$rndh"
43b08fbf24SPaolo Abeni
44b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2";do
45b08fbf24SPaolo Abeni		ip netns add $netns || exit $ksft_skip
46b08fbf24SPaolo Abeni		ip -net $netns link set lo up
47b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.mptcp.enabled=1
48b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0
49b08fbf24SPaolo Abeni		ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
50b08fbf24SPaolo Abeni	done
51b08fbf24SPaolo Abeni
52b08fbf24SPaolo Abeni	#  ns1              ns2
53b08fbf24SPaolo Abeni	# ns1eth1    ns2eth1
54b08fbf24SPaolo Abeni	# ns1eth2    ns2eth2
55b08fbf24SPaolo Abeni	# ns1eth3    ns2eth3
56b08fbf24SPaolo Abeni	# ns1eth4    ns2eth4
57b08fbf24SPaolo Abeni
58b08fbf24SPaolo Abeni	for i in `seq 1 4`; do
59b08fbf24SPaolo Abeni		ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
60b08fbf24SPaolo Abeni		ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
61b08fbf24SPaolo Abeni		ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad
62b08fbf24SPaolo Abeni		ip -net "$ns1" link set ns1eth$i up
63b08fbf24SPaolo Abeni
64b08fbf24SPaolo Abeni		ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i
65b08fbf24SPaolo Abeni		ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad
66b08fbf24SPaolo Abeni		ip -net "$ns2" link set ns2eth$i up
67b08fbf24SPaolo Abeni
68b08fbf24SPaolo Abeni		# let $ns2 reach any $ns1 address from any interface
69b08fbf24SPaolo Abeni		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
70b08fbf24SPaolo Abeni	done
71b08fbf24SPaolo Abeni}
72b08fbf24SPaolo Abeni
73b08fbf24SPaolo Abenicleanup_partial()
74b08fbf24SPaolo Abeni{
75b08fbf24SPaolo Abeni	rm -f "$capout"
76b08fbf24SPaolo Abeni
77b08fbf24SPaolo Abeni	for netns in "$ns1" "$ns2"; do
78b08fbf24SPaolo Abeni		ip netns del $netns
79b08fbf24SPaolo Abeni	done
80b08fbf24SPaolo Abeni}
81b08fbf24SPaolo Abeni
82b08fbf24SPaolo Abenicleanup()
83b08fbf24SPaolo Abeni{
84b08fbf24SPaolo Abeni	rm -f "$cin" "$cout"
858b819a84SFlorian Westphal	rm -f "$sin" "$sout" "$cinsent"
86b08fbf24SPaolo Abeni	cleanup_partial
87b08fbf24SPaolo Abeni}
88b08fbf24SPaolo Abeni
89b08fbf24SPaolo Abenireset()
90b08fbf24SPaolo Abeni{
91b08fbf24SPaolo Abeni	cleanup_partial
92b08fbf24SPaolo Abeni	init
93b08fbf24SPaolo Abeni}
94b08fbf24SPaolo Abeni
9500587187SFlorian Westphalreset_with_cookies()
9600587187SFlorian Westphal{
9700587187SFlorian Westphal	reset
9800587187SFlorian Westphal
9900587187SFlorian Westphal	for netns in "$ns1" "$ns2";do
10000587187SFlorian Westphal		ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2
10100587187SFlorian Westphal	done
10200587187SFlorian Westphal}
10300587187SFlorian Westphal
1048d014eaaSGeliang Tangreset_with_add_addr_timeout()
1058d014eaaSGeliang Tang{
1068d014eaaSGeliang Tang	local ip="${1:-4}"
1078d014eaaSGeliang Tang	local tables
1088d014eaaSGeliang Tang
1098d014eaaSGeliang Tang	tables="iptables"
1108d014eaaSGeliang Tang	if [ $ip -eq 6 ]; then
1118d014eaaSGeliang Tang		tables="ip6tables"
1128d014eaaSGeliang Tang	fi
1138d014eaaSGeliang Tang
1148d014eaaSGeliang Tang	reset
1158d014eaaSGeliang Tang
1168d014eaaSGeliang Tang	ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1
1178d014eaaSGeliang Tang	ip netns exec $ns2 $tables -A OUTPUT -p tcp \
1188d014eaaSGeliang Tang		-m tcp --tcp-option 30 \
1198d014eaaSGeliang Tang		-m bpf --bytecode \
1208d014eaaSGeliang Tang		"$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \
1218d014eaaSGeliang Tang		-j DROP
1228d014eaaSGeliang Tang}
1238d014eaaSGeliang Tang
124b08fbf24SPaolo Abenifor arg in "$@"; do
125b08fbf24SPaolo Abeni	if [ "$arg" = "-c" ]; then
126b08fbf24SPaolo Abeni		capture=1
127b08fbf24SPaolo Abeni	fi
128b08fbf24SPaolo Abenidone
129b08fbf24SPaolo Abeni
130b08fbf24SPaolo Abeniip -Version > /dev/null 2>&1
131b08fbf24SPaolo Abeniif [ $? -ne 0 ];then
132b08fbf24SPaolo Abeni	echo "SKIP: Could not run test without ip tool"
133b08fbf24SPaolo Abeni	exit $ksft_skip
134b08fbf24SPaolo Abenifi
135b08fbf24SPaolo Abeni
1368d014eaaSGeliang Tangiptables -V > /dev/null 2>&1
1378d014eaaSGeliang Tangif [ $? -ne 0 ];then
1388d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without iptables tool"
1398d014eaaSGeliang Tang	exit $ksft_skip
1408d014eaaSGeliang Tangfi
1418d014eaaSGeliang Tang
1428d014eaaSGeliang Tangip6tables -V > /dev/null 2>&1
1438d014eaaSGeliang Tangif [ $? -ne 0 ];then
1448d014eaaSGeliang Tang	echo "SKIP: Could not run all tests without ip6tables tool"
1458d014eaaSGeliang Tang	exit $ksft_skip
1468d014eaaSGeliang Tangfi
147b08fbf24SPaolo Abeni
1488b819a84SFlorian Westphalprint_file_err()
1498b819a84SFlorian Westphal{
1508b819a84SFlorian Westphal	ls -l "$1" 1>&2
1518b819a84SFlorian Westphal	echo "Trailing bytes are: "
1528b819a84SFlorian Westphal	tail -c 27 "$1"
1538b819a84SFlorian Westphal}
1548b819a84SFlorian Westphal
155b08fbf24SPaolo Abenicheck_transfer()
156b08fbf24SPaolo Abeni{
157b08fbf24SPaolo Abeni	in=$1
158b08fbf24SPaolo Abeni	out=$2
159b08fbf24SPaolo Abeni	what=$3
160b08fbf24SPaolo Abeni
161b08fbf24SPaolo Abeni	cmp "$in" "$out" > /dev/null 2>&1
162b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ;then
163b08fbf24SPaolo Abeni		echo "[ FAIL ] $what does not match (in, out):"
164b08fbf24SPaolo Abeni		print_file_err "$in"
165b08fbf24SPaolo Abeni		print_file_err "$out"
1668b819a84SFlorian Westphal		ret=1
167b08fbf24SPaolo Abeni
168b08fbf24SPaolo Abeni		return 1
169b08fbf24SPaolo Abeni	fi
170b08fbf24SPaolo Abeni
171b08fbf24SPaolo Abeni	return 0
172b08fbf24SPaolo Abeni}
173b08fbf24SPaolo Abeni
174b08fbf24SPaolo Abenido_ping()
175b08fbf24SPaolo Abeni{
176b08fbf24SPaolo Abeni	listener_ns="$1"
177b08fbf24SPaolo Abeni	connector_ns="$2"
178b08fbf24SPaolo Abeni	connect_addr="$3"
179b08fbf24SPaolo Abeni
180b08fbf24SPaolo Abeni	ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null
181b08fbf24SPaolo Abeni	if [ $? -ne 0 ] ; then
182b08fbf24SPaolo Abeni		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
183b08fbf24SPaolo Abeni		ret=1
184b08fbf24SPaolo Abeni	fi
185b08fbf24SPaolo Abeni}
186b08fbf24SPaolo Abeni
1878b819a84SFlorian Westphallink_failure()
1888b819a84SFlorian Westphal{
1898b819a84SFlorian Westphal	ns="$1"
1908b819a84SFlorian Westphal
1918b819a84SFlorian Westphal	l=$((RANDOM%4))
1928b819a84SFlorian Westphal	l=$((l+1))
1938b819a84SFlorian Westphal
1948b819a84SFlorian Westphal	veth="ns1eth$l"
1958b819a84SFlorian Westphal	ip -net "$ns" link set "$veth" down
1968b819a84SFlorian Westphal}
1978b819a84SFlorian Westphal
198523514edSGeliang Tang# $1: IP address
199523514edSGeliang Tangis_v6()
200523514edSGeliang Tang{
201523514edSGeliang Tang	[ -z "${1##*:*}" ]
202523514edSGeliang Tang}
203523514edSGeliang Tang
204b08fbf24SPaolo Abenido_transfer()
205b08fbf24SPaolo Abeni{
206b08fbf24SPaolo Abeni	listener_ns="$1"
207b08fbf24SPaolo Abeni	connector_ns="$2"
208b08fbf24SPaolo Abeni	cl_proto="$3"
209b08fbf24SPaolo Abeni	srv_proto="$4"
210b08fbf24SPaolo Abeni	connect_addr="$5"
2118b819a84SFlorian Westphal	test_link_fail="$6"
2122e8cbf45SGeliang Tang	addr_nr_ns1="$7"
2132e8cbf45SGeliang Tang	addr_nr_ns2="$8"
2148b819a84SFlorian Westphal	speed="$9"
215718eb44eSGeliang Tang	bkup="${10}"
216b08fbf24SPaolo Abeni
217b08fbf24SPaolo Abeni	port=$((10000+$TEST_COUNT))
218b08fbf24SPaolo Abeni	TEST_COUNT=$((TEST_COUNT+1))
219b08fbf24SPaolo Abeni
220b08fbf24SPaolo Abeni	:> "$cout"
221b08fbf24SPaolo Abeni	:> "$sout"
222b08fbf24SPaolo Abeni	:> "$capout"
223b08fbf24SPaolo Abeni
224b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
225b08fbf24SPaolo Abeni		if [ -z $SUDO_USER ] ; then
226b08fbf24SPaolo Abeni			capuser=""
227b08fbf24SPaolo Abeni		else
228b08fbf24SPaolo Abeni			capuser="-Z $SUDO_USER"
229b08fbf24SPaolo Abeni		fi
230b08fbf24SPaolo Abeni
23100587187SFlorian Westphal		capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
232b08fbf24SPaolo Abeni
233b08fbf24SPaolo Abeni		echo "Capturing traffic for test $TEST_COUNT into $capfile"
234b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
235b08fbf24SPaolo Abeni		cappid=$!
236b08fbf24SPaolo Abeni
237b08fbf24SPaolo Abeni		sleep 1
238b08fbf24SPaolo Abeni	fi
239b08fbf24SPaolo Abeni
2408d014eaaSGeliang Tang	if [ $speed = "fast" ]; then
241dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -j"
242dd72b0feSGeliang Tang	else
243dd72b0feSGeliang Tang		mptcp_connect="./mptcp_connect -r"
244dd72b0feSGeliang Tang	fi
245dd72b0feSGeliang Tang
246523514edSGeliang Tang	local local_addr
247523514edSGeliang Tang	if is_v6 "${connect_addr}"; then
248523514edSGeliang Tang		local_addr="::"
249523514edSGeliang Tang	else
250523514edSGeliang Tang		local_addr="0.0.0.0"
251523514edSGeliang Tang	fi
252523514edSGeliang Tang
253523514edSGeliang Tang	ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port \
254523514edSGeliang Tang		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
255b08fbf24SPaolo Abeni	spid=$!
256b08fbf24SPaolo Abeni
257b08fbf24SPaolo Abeni	sleep 1
258b08fbf24SPaolo Abeni
2598b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
260dd72b0feSGeliang Tang		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr < "$cin" > "$cout" &
2618b819a84SFlorian Westphal	else
2628b819a84SFlorian Westphal		( cat "$cin" ; sleep 2; link_failure $listener_ns ; cat "$cin" ) | tee "$cinsent" | \
2638b819a84SFlorian Westphal		ip netns exec ${connector_ns} $mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr > "$cout" &
2648b819a84SFlorian Westphal	fi
265b08fbf24SPaolo Abeni	cpid=$!
266b08fbf24SPaolo Abeni
2676208fd82SGeliang Tang	if [ $addr_nr_ns1 -gt 0 ]; then
2686208fd82SGeliang Tang		let add_nr_ns1=addr_nr_ns1
2696208fd82SGeliang Tang		counter=2
2706208fd82SGeliang Tang		sleep 1
2716208fd82SGeliang Tang		while [ $add_nr_ns1 -gt 0 ]; do
2726208fd82SGeliang Tang			local addr
2736208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
2746208fd82SGeliang Tang				addr="dead:beef:$counter::1"
2756208fd82SGeliang Tang			else
2766208fd82SGeliang Tang				addr="10.0.$counter.1"
2776208fd82SGeliang Tang			fi
2786208fd82SGeliang Tang			ip netns exec $ns1 ./pm_nl_ctl add $addr flags signal
2796208fd82SGeliang Tang			let counter+=1
2806208fd82SGeliang Tang			let add_nr_ns1-=1
2816208fd82SGeliang Tang		done
2826208fd82SGeliang Tang		sleep 1
2836208fd82SGeliang Tang	elif [ $addr_nr_ns1 -lt 0 ]; then
2842e8cbf45SGeliang Tang		let rm_nr_ns1=-addr_nr_ns1
2856fe4ccdcSGeliang Tang		if [ $rm_nr_ns1 -lt 8 ]; then
286dd72b0feSGeliang Tang			counter=1
287dd72b0feSGeliang Tang			sleep 1
288dd72b0feSGeliang Tang
289dd72b0feSGeliang Tang			while [ $counter -le $rm_nr_ns1 ]
290dd72b0feSGeliang Tang			do
291dd72b0feSGeliang Tang				ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
292dd72b0feSGeliang Tang				sleep 1
293dd72b0feSGeliang Tang				let counter+=1
294dd72b0feSGeliang Tang			done
2956fe4ccdcSGeliang Tang		else
2966fe4ccdcSGeliang Tang			sleep 1
2976fe4ccdcSGeliang Tang			ip netns exec ${listener_ns} ./pm_nl_ctl flush
2986fe4ccdcSGeliang Tang		fi
299dd72b0feSGeliang Tang	fi
300dd72b0feSGeliang Tang
3016208fd82SGeliang Tang	if [ $addr_nr_ns2 -gt 0 ]; then
3026208fd82SGeliang Tang		let add_nr_ns2=addr_nr_ns2
3036208fd82SGeliang Tang		counter=3
3046208fd82SGeliang Tang		sleep 1
3056208fd82SGeliang Tang		while [ $add_nr_ns2 -gt 0 ]; do
3066208fd82SGeliang Tang			local addr
3076208fd82SGeliang Tang			if is_v6 "${connect_addr}"; then
3086208fd82SGeliang Tang				addr="dead:beef:$counter::2"
3096208fd82SGeliang Tang			else
3106208fd82SGeliang Tang				addr="10.0.$counter.2"
3116208fd82SGeliang Tang			fi
3126208fd82SGeliang Tang			ip netns exec $ns2 ./pm_nl_ctl add $addr flags subflow
3136208fd82SGeliang Tang			let counter+=1
3146208fd82SGeliang Tang			let add_nr_ns2-=1
3156208fd82SGeliang Tang		done
3166208fd82SGeliang Tang		sleep 1
3176208fd82SGeliang Tang	elif [ $addr_nr_ns2 -lt 0 ]; then
3182e8cbf45SGeliang Tang		let rm_nr_ns2=-addr_nr_ns2
3196fe4ccdcSGeliang Tang		if [ $rm_nr_ns2 -lt 8 ]; then
320dd72b0feSGeliang Tang			counter=1
321dd72b0feSGeliang Tang			sleep 1
322dd72b0feSGeliang Tang
323dd72b0feSGeliang Tang			while [ $counter -le $rm_nr_ns2 ]
324dd72b0feSGeliang Tang			do
325dd72b0feSGeliang Tang				ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
326dd72b0feSGeliang Tang				sleep 1
327dd72b0feSGeliang Tang				let counter+=1
328dd72b0feSGeliang Tang			done
3296fe4ccdcSGeliang Tang		else
3306fe4ccdcSGeliang Tang			sleep 1
3316fe4ccdcSGeliang Tang			ip netns exec ${connector_ns} ./pm_nl_ctl flush
3326fe4ccdcSGeliang Tang		fi
333dd72b0feSGeliang Tang	fi
334dd72b0feSGeliang Tang
335718eb44eSGeliang Tang	if [ ! -z $bkup ]; then
336718eb44eSGeliang Tang		sleep 1
337718eb44eSGeliang Tang		for netns in "$ns1" "$ns2"; do
338718eb44eSGeliang Tang			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
339718eb44eSGeliang Tang			if [ ${#dump[@]} -gt 0 ]; then
340718eb44eSGeliang Tang				addr=${dump[${#dump[@]} - 1]}
341718eb44eSGeliang Tang				backup="ip netns exec $netns ./pm_nl_ctl set $addr flags $bkup"
342718eb44eSGeliang Tang				$backup
343718eb44eSGeliang Tang			fi
344718eb44eSGeliang Tang		done
345718eb44eSGeliang Tang	fi
346718eb44eSGeliang Tang
347b08fbf24SPaolo Abeni	wait $cpid
348b08fbf24SPaolo Abeni	retc=$?
349b08fbf24SPaolo Abeni	wait $spid
350b08fbf24SPaolo Abeni	rets=$?
351b08fbf24SPaolo Abeni
352b08fbf24SPaolo Abeni	if [ $capture -eq 1 ]; then
353b08fbf24SPaolo Abeni	    sleep 1
354b08fbf24SPaolo Abeni	    kill $cappid
355b08fbf24SPaolo Abeni	fi
356b08fbf24SPaolo Abeni
357b08fbf24SPaolo Abeni	if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
358b08fbf24SPaolo Abeni		echo " client exit code $retc, server $rets" 1>&2
3598b974778SMatthieu Baerts		echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2
360b08fbf24SPaolo Abeni		ip netns exec ${listener_ns} ss -nita 1>&2 -o "sport = :$port"
3618b974778SMatthieu Baerts		echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2
362b08fbf24SPaolo Abeni		ip netns exec ${connector_ns} ss -nita 1>&2 -o "dport = :$port"
363b08fbf24SPaolo Abeni
364b08fbf24SPaolo Abeni		cat "$capout"
3658b819a84SFlorian Westphal		ret=1
366b08fbf24SPaolo Abeni		return 1
367b08fbf24SPaolo Abeni	fi
368b08fbf24SPaolo Abeni
369b08fbf24SPaolo Abeni	check_transfer $sin $cout "file received by client"
370b08fbf24SPaolo Abeni	retc=$?
3718b819a84SFlorian Westphal	if [ "$test_link_fail" -eq 0 ];then
372b08fbf24SPaolo Abeni		check_transfer $cin $sout "file received by server"
3738b819a84SFlorian Westphal	else
3748b819a84SFlorian Westphal		check_transfer $cinsent $sout "file received by server"
3758b819a84SFlorian Westphal	fi
376b08fbf24SPaolo Abeni	rets=$?
377b08fbf24SPaolo Abeni
378b08fbf24SPaolo Abeni	if [ $retc -eq 0 ] && [ $rets -eq 0 ];then
379b08fbf24SPaolo Abeni		cat "$capout"
380b08fbf24SPaolo Abeni		return 0
381b08fbf24SPaolo Abeni	fi
382b08fbf24SPaolo Abeni
383b08fbf24SPaolo Abeni	cat "$capout"
384b08fbf24SPaolo Abeni	return 1
385b08fbf24SPaolo Abeni}
386b08fbf24SPaolo Abeni
387b08fbf24SPaolo Abenimake_file()
388b08fbf24SPaolo Abeni{
389b08fbf24SPaolo Abeni	name=$1
390b08fbf24SPaolo Abeni	who=$2
3918b819a84SFlorian Westphal	size=$3
392b08fbf24SPaolo Abeni
3938b819a84SFlorian Westphal	dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
394b08fbf24SPaolo Abeni	echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
395b08fbf24SPaolo Abeni
3968b819a84SFlorian Westphal	echo "Created $name (size $size KB) containing data sent by $who"
397b08fbf24SPaolo Abeni}
398b08fbf24SPaolo Abeni
399b08fbf24SPaolo Abenirun_tests()
400b08fbf24SPaolo Abeni{
401b08fbf24SPaolo Abeni	listener_ns="$1"
402b08fbf24SPaolo Abeni	connector_ns="$2"
403b08fbf24SPaolo Abeni	connect_addr="$3"
4048b819a84SFlorian Westphal	test_linkfail="${4:-0}"
4052e8cbf45SGeliang Tang	addr_nr_ns1="${5:-0}"
4062e8cbf45SGeliang Tang	addr_nr_ns2="${6:-0}"
4078b819a84SFlorian Westphal	speed="${7:-fast}"
408718eb44eSGeliang Tang	bkup="${8:-""}"
409b08fbf24SPaolo Abeni	lret=0
4108b819a84SFlorian Westphal	oldin=""
4118b819a84SFlorian Westphal
4128b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
4138b819a84SFlorian Westphal		size=$((RANDOM%1024))
4148b819a84SFlorian Westphal		size=$((size+1))
4158b819a84SFlorian Westphal		size=$((size*128))
4168b819a84SFlorian Westphal
4178b819a84SFlorian Westphal		oldin=$(mktemp)
4188b819a84SFlorian Westphal		cp "$cin" "$oldin"
4198b819a84SFlorian Westphal		make_file "$cin" "client" $size
4208b819a84SFlorian Westphal	fi
421b08fbf24SPaolo Abeni
4228d014eaaSGeliang Tang	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
4232e8cbf45SGeliang Tang		${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${bkup}
424b08fbf24SPaolo Abeni	lret=$?
4258b819a84SFlorian Westphal
4268b819a84SFlorian Westphal	if [ "$test_linkfail" -eq 1 ];then
4278b819a84SFlorian Westphal		cp "$oldin" "$cin"
4288b819a84SFlorian Westphal		rm -f "$oldin"
4298b819a84SFlorian Westphal	fi
4308b819a84SFlorian Westphal
431b08fbf24SPaolo Abeni	if [ $lret -ne 0 ]; then
432b08fbf24SPaolo Abeni		ret=$lret
433b08fbf24SPaolo Abeni		return
434b08fbf24SPaolo Abeni	fi
435b08fbf24SPaolo Abeni}
436b08fbf24SPaolo Abeni
437b08fbf24SPaolo Abenichk_join_nr()
438b08fbf24SPaolo Abeni{
439b08fbf24SPaolo Abeni	local msg="$1"
440b08fbf24SPaolo Abeni	local syn_nr=$2
441b08fbf24SPaolo Abeni	local syn_ack_nr=$3
442b08fbf24SPaolo Abeni	local ack_nr=$4
443b08fbf24SPaolo Abeni	local count
444b08fbf24SPaolo Abeni	local dump_stats
445b08fbf24SPaolo Abeni
44600587187SFlorian Westphal	printf "%02u %-36s %s" "$TEST_COUNT" "$msg" "syn"
447b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}'`
448b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
449b08fbf24SPaolo Abeni	if [ "$count" != "$syn_nr" ]; then
450b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] syn expected $syn_nr"
451b08fbf24SPaolo Abeni		ret=1
452b08fbf24SPaolo Abeni		dump_stats=1
453b08fbf24SPaolo Abeni	else
454b08fbf24SPaolo Abeni		echo -n "[ ok ]"
455b08fbf24SPaolo Abeni	fi
456b08fbf24SPaolo Abeni
457b08fbf24SPaolo Abeni	echo -n " - synack"
458b08fbf24SPaolo Abeni	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}'`
459b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
460b08fbf24SPaolo Abeni	if [ "$count" != "$syn_ack_nr" ]; then
461b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr"
462b08fbf24SPaolo Abeni		ret=1
463b08fbf24SPaolo Abeni		dump_stats=1
464b08fbf24SPaolo Abeni	else
465b08fbf24SPaolo Abeni		echo -n "[ ok ]"
466b08fbf24SPaolo Abeni	fi
467b08fbf24SPaolo Abeni
468b08fbf24SPaolo Abeni	echo -n " - ack"
469b08fbf24SPaolo Abeni	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}'`
470b08fbf24SPaolo Abeni	[ -z "$count" ] && count=0
471b08fbf24SPaolo Abeni	if [ "$count" != "$ack_nr" ]; then
472b08fbf24SPaolo Abeni		echo "[fail] got $count JOIN[s] ack expected $ack_nr"
473b08fbf24SPaolo Abeni		ret=1
474b08fbf24SPaolo Abeni		dump_stats=1
475b08fbf24SPaolo Abeni	else
476b08fbf24SPaolo Abeni		echo "[ ok ]"
477b08fbf24SPaolo Abeni	fi
478b08fbf24SPaolo Abeni	if [ "${dump_stats}" = 1 ]; then
479b08fbf24SPaolo Abeni		echo Server ns stats
480b08fbf24SPaolo Abeni		ip netns exec $ns1 nstat -as | grep MPTcp
481b08fbf24SPaolo Abeni		echo Client ns stats
482b08fbf24SPaolo Abeni		ip netns exec $ns2 nstat -as | grep MPTcp
483b08fbf24SPaolo Abeni	fi
484b08fbf24SPaolo Abeni}
485b08fbf24SPaolo Abeni
486be613160SGeliang Tangchk_add_nr()
487be613160SGeliang Tang{
488be613160SGeliang Tang	local add_nr=$1
489be613160SGeliang Tang	local echo_nr=$2
4908a127bf6SGeliang Tang	local port_nr=${3:-0}
4918a127bf6SGeliang Tang	local syn_nr=${4:-$port_nr}
4928a127bf6SGeliang Tang	local syn_ack_nr=${5:-$port_nr}
4938a127bf6SGeliang Tang	local ack_nr=${6:-$port_nr}
4948a127bf6SGeliang Tang	local mis_syn_nr=${7:-0}
4958a127bf6SGeliang Tang	local mis_ack_nr=${8:-0}
496be613160SGeliang Tang	local count
497be613160SGeliang Tang	local dump_stats
498be613160SGeliang Tang
499be613160SGeliang Tang	printf "%-39s %s" " " "add"
500be613160SGeliang Tang	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
501be613160SGeliang Tang	[ -z "$count" ] && count=0
502be613160SGeliang Tang	if [ "$count" != "$add_nr" ]; then
503be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR[s] expected $add_nr"
504be613160SGeliang Tang		ret=1
505be613160SGeliang Tang		dump_stats=1
506be613160SGeliang Tang	else
507be613160SGeliang Tang		echo -n "[ ok ]"
508be613160SGeliang Tang	fi
509be613160SGeliang Tang
510be613160SGeliang Tang	echo -n " - echo  "
511be613160SGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
512be613160SGeliang Tang	[ -z "$count" ] && count=0
513be613160SGeliang Tang	if [ "$count" != "$echo_nr" ]; then
514be613160SGeliang Tang		echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr"
515be613160SGeliang Tang		ret=1
516be613160SGeliang Tang		dump_stats=1
517be613160SGeliang Tang	else
5188a127bf6SGeliang Tang		echo -n "[ ok ]"
5198a127bf6SGeliang Tang	fi
5208a127bf6SGeliang Tang
5218a127bf6SGeliang Tang	if [ $port_nr -gt 0 ]; then
5228a127bf6SGeliang Tang		echo -n " - pt "
5238a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}'`
5248a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5258a127bf6SGeliang Tang		if [ "$count" != "$port_nr" ]; then
5268a127bf6SGeliang Tang			echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr"
5278a127bf6SGeliang Tang			ret=1
5288a127bf6SGeliang Tang			dump_stats=1
5298a127bf6SGeliang Tang		else
530be613160SGeliang Tang			echo "[ ok ]"
531be613160SGeliang Tang		fi
532be613160SGeliang Tang
5338a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
5348a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx |
5358a127bf6SGeliang Tang			awk '{print $2}'`
5368a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5378a127bf6SGeliang Tang		if [ "$count" != "$syn_nr" ]; then
5388a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a different \
5398a127bf6SGeliang Tang				port-number expected $syn_nr"
5408a127bf6SGeliang Tang			ret=1
5418a127bf6SGeliang Tang			dump_stats=1
5428a127bf6SGeliang Tang		else
5438a127bf6SGeliang Tang			echo -n "[ ok ]"
5448a127bf6SGeliang Tang		fi
5458a127bf6SGeliang Tang
5468a127bf6SGeliang Tang		echo -n " - synack"
5478a127bf6SGeliang Tang		count=`ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx |
5488a127bf6SGeliang Tang			awk '{print $2}'`
5498a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5508a127bf6SGeliang Tang		if [ "$count" != "$syn_ack_nr" ]; then
5518a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] synack with a different \
5528a127bf6SGeliang Tang				port-number expected $syn_ack_nr"
5538a127bf6SGeliang Tang			ret=1
5548a127bf6SGeliang Tang			dump_stats=1
5558a127bf6SGeliang Tang		else
5568a127bf6SGeliang Tang			echo -n "[ ok ]"
5578a127bf6SGeliang Tang		fi
5588a127bf6SGeliang Tang
5598a127bf6SGeliang Tang		echo -n " - ack"
5608a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx |
5618a127bf6SGeliang Tang			awk '{print $2}'`
5628a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5638a127bf6SGeliang Tang		if [ "$count" != "$ack_nr" ]; then
5648a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a different \
5658a127bf6SGeliang Tang				port-number expected $ack_nr"
5668a127bf6SGeliang Tang			ret=1
5678a127bf6SGeliang Tang			dump_stats=1
5688a127bf6SGeliang Tang		else
5698a127bf6SGeliang Tang			echo "[ ok ]"
5708a127bf6SGeliang Tang		fi
5718a127bf6SGeliang Tang
5728a127bf6SGeliang Tang		printf "%-39s %s" " " "syn"
5738a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx |
5748a127bf6SGeliang Tang			awk '{print $2}'`
5758a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5768a127bf6SGeliang Tang		if [ "$count" != "$mis_syn_nr" ]; then
5778a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] syn with a mismatched \
5788a127bf6SGeliang Tang				port-number expected $mis_syn_nr"
5798a127bf6SGeliang Tang			ret=1
5808a127bf6SGeliang Tang			dump_stats=1
5818a127bf6SGeliang Tang		else
5828a127bf6SGeliang Tang			echo -n "[ ok ]"
5838a127bf6SGeliang Tang		fi
5848a127bf6SGeliang Tang
5858a127bf6SGeliang Tang		echo -n " - ack   "
5868a127bf6SGeliang Tang		count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx |
5878a127bf6SGeliang Tang			awk '{print $2}'`
5888a127bf6SGeliang Tang		[ -z "$count" ] && count=0
5898a127bf6SGeliang Tang		if [ "$count" != "$mis_ack_nr" ]; then
5908a127bf6SGeliang Tang			echo "[fail] got $count JOIN[s] ack with a mismatched \
5918a127bf6SGeliang Tang				port-number expected $mis_ack_nr"
5928a127bf6SGeliang Tang			ret=1
5938a127bf6SGeliang Tang			dump_stats=1
5948a127bf6SGeliang Tang		else
5958a127bf6SGeliang Tang			echo "[ ok ]"
5968a127bf6SGeliang Tang		fi
5978a127bf6SGeliang Tang	else
5988a127bf6SGeliang Tang		echo ""
5998a127bf6SGeliang Tang	fi
6008a127bf6SGeliang Tang
601be613160SGeliang Tang	if [ "${dump_stats}" = 1 ]; then
602be613160SGeliang Tang		echo Server ns stats
603be613160SGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
604be613160SGeliang Tang		echo Client ns stats
605be613160SGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
606be613160SGeliang Tang	fi
607be613160SGeliang Tang}
608be613160SGeliang Tang
609dd72b0feSGeliang Tangchk_rm_nr()
610dd72b0feSGeliang Tang{
611dd72b0feSGeliang Tang	local rm_addr_nr=$1
612dd72b0feSGeliang Tang	local rm_subflow_nr=$2
613*7028ba8aSGeliang Tang	local invert=${3:-""}
614dd72b0feSGeliang Tang	local count
615dd72b0feSGeliang Tang	local dump_stats
616*7028ba8aSGeliang Tang	local addr_ns
617*7028ba8aSGeliang Tang	local subflow_ns
618*7028ba8aSGeliang Tang
619*7028ba8aSGeliang Tang	if [ -z $invert ]; then
620*7028ba8aSGeliang Tang		addr_ns=$ns1
621*7028ba8aSGeliang Tang		subflow_ns=$ns2
622*7028ba8aSGeliang Tang	elif [ $invert = "invert" ]; then
623*7028ba8aSGeliang Tang		addr_ns=$ns2
624*7028ba8aSGeliang Tang		subflow_ns=$ns1
625*7028ba8aSGeliang Tang	fi
626dd72b0feSGeliang Tang
627dd72b0feSGeliang Tang	printf "%-39s %s" " " "rm "
628*7028ba8aSGeliang Tang	count=`ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}'`
629dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
630dd72b0feSGeliang Tang	if [ "$count" != "$rm_addr_nr" ]; then
631dd72b0feSGeliang Tang		echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr"
632dd72b0feSGeliang Tang		ret=1
633dd72b0feSGeliang Tang		dump_stats=1
634dd72b0feSGeliang Tang	else
635dd72b0feSGeliang Tang		echo -n "[ ok ]"
636dd72b0feSGeliang Tang	fi
637dd72b0feSGeliang Tang
638dd72b0feSGeliang Tang	echo -n " - sf    "
639*7028ba8aSGeliang Tang	count=`ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}'`
640dd72b0feSGeliang Tang	[ -z "$count" ] && count=0
641dd72b0feSGeliang Tang	if [ "$count" != "$rm_subflow_nr" ]; then
642dd72b0feSGeliang Tang		echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr"
643dd72b0feSGeliang Tang		ret=1
644dd72b0feSGeliang Tang		dump_stats=1
645dd72b0feSGeliang Tang	else
646dd72b0feSGeliang Tang		echo "[ ok ]"
647dd72b0feSGeliang Tang	fi
648dd72b0feSGeliang Tang
649dd72b0feSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
650dd72b0feSGeliang Tang		echo Server ns stats
651dd72b0feSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
652dd72b0feSGeliang Tang		echo Client ns stats
653dd72b0feSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
654dd72b0feSGeliang Tang	fi
655dd72b0feSGeliang Tang}
656dd72b0feSGeliang Tang
657718eb44eSGeliang Tangchk_prio_nr()
658718eb44eSGeliang Tang{
659718eb44eSGeliang Tang	local mp_prio_nr_tx=$1
660718eb44eSGeliang Tang	local mp_prio_nr_rx=$2
661718eb44eSGeliang Tang	local count
662718eb44eSGeliang Tang	local dump_stats
663718eb44eSGeliang Tang
664718eb44eSGeliang Tang	printf "%-39s %s" " " "ptx"
665718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}'`
666718eb44eSGeliang Tang	[ -z "$count" ] && count=0
667718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_tx" ]; then
668718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx"
669718eb44eSGeliang Tang		ret=1
670718eb44eSGeliang Tang		dump_stats=1
671718eb44eSGeliang Tang	else
672718eb44eSGeliang Tang		echo -n "[ ok ]"
673718eb44eSGeliang Tang	fi
674718eb44eSGeliang Tang
675718eb44eSGeliang Tang	echo -n " - prx   "
676718eb44eSGeliang Tang	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}'`
677718eb44eSGeliang Tang	[ -z "$count" ] && count=0
678718eb44eSGeliang Tang	if [ "$count" != "$mp_prio_nr_rx" ]; then
679718eb44eSGeliang Tang		echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx"
680718eb44eSGeliang Tang		ret=1
681718eb44eSGeliang Tang		dump_stats=1
682718eb44eSGeliang Tang	else
683718eb44eSGeliang Tang		echo "[ ok ]"
684718eb44eSGeliang Tang	fi
685718eb44eSGeliang Tang
686718eb44eSGeliang Tang	if [ "${dump_stats}" = 1 ]; then
687718eb44eSGeliang Tang		echo Server ns stats
688718eb44eSGeliang Tang		ip netns exec $ns1 nstat -as | grep MPTcp
689718eb44eSGeliang Tang		echo Client ns stats
690718eb44eSGeliang Tang		ip netns exec $ns2 nstat -as | grep MPTcp
691718eb44eSGeliang Tang	fi
692718eb44eSGeliang Tang}
693718eb44eSGeliang Tang
6941002b89fSGeliang Tangsubflows_tests()
6951002b89fSGeliang Tang{
6961002b89fSGeliang Tang	reset
697b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
698b08fbf24SPaolo Abeni	chk_join_nr "no JOIN" "0" "0" "0"
699b08fbf24SPaolo Abeni
7001002b89fSGeliang Tang	# subflow limited by client
701b08fbf24SPaolo Abeni	reset
702b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
703b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
704b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by client" 0 0 0
705b08fbf24SPaolo Abeni
7061002b89fSGeliang Tang	# subflow limited by server
707b08fbf24SPaolo Abeni	reset
708b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
709b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
710b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
711b08fbf24SPaolo Abeni	chk_join_nr "single subflow, limited by server" 1 1 0
712b08fbf24SPaolo Abeni
713b08fbf24SPaolo Abeni	# subflow
714b08fbf24SPaolo Abeni	reset
715b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
716b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
717b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
718b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
719b08fbf24SPaolo Abeni	chk_join_nr "single subflow" 1 1 1
720b08fbf24SPaolo Abeni
721b08fbf24SPaolo Abeni	# multiple subflows
722b08fbf24SPaolo Abeni	reset
723b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
724b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
725b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
726b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
727b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
728b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows" 2 2 2
729b08fbf24SPaolo Abeni
730b08fbf24SPaolo Abeni	# multiple subflows limited by serverf
731b08fbf24SPaolo Abeni	reset
732b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
733b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
734b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
735b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
736b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
737b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows, limited by server" 2 2 1
7381002b89fSGeliang Tang}
739b08fbf24SPaolo Abeni
7401002b89fSGeliang Tangsignal_address_tests()
7411002b89fSGeliang Tang{
742b08fbf24SPaolo Abeni	# add_address, unused
743b08fbf24SPaolo Abeni	reset
744b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
745b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
746b08fbf24SPaolo Abeni	chk_join_nr "unused signal address" 0 0 0
747be613160SGeliang Tang	chk_add_nr 1 1
748b08fbf24SPaolo Abeni
749b08fbf24SPaolo Abeni	# accept and use add_addr
750b08fbf24SPaolo Abeni	reset
751b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
752b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
753b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
754b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
755b08fbf24SPaolo Abeni	chk_join_nr "signal address" 1 1 1
756be613160SGeliang Tang	chk_add_nr 1 1
757b08fbf24SPaolo Abeni
758b08fbf24SPaolo Abeni	# accept and use add_addr with an additional subflow
759b08fbf24SPaolo Abeni	# note: signal address in server ns and local addresses in client ns must
760b08fbf24SPaolo Abeni	# belong to different subnets or one of the listed local address could be
761b08fbf24SPaolo Abeni	# used for 'add_addr' subflow
762b08fbf24SPaolo Abeni	reset
763b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
764b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
765b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
766b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
767b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
768b08fbf24SPaolo Abeni	chk_join_nr "subflow and signal" 2 2 2
769be613160SGeliang Tang	chk_add_nr 1 1
770b08fbf24SPaolo Abeni
771b08fbf24SPaolo Abeni	# accept and use add_addr with additional subflows
772b08fbf24SPaolo Abeni	reset
773b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
774b08fbf24SPaolo Abeni	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
775b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
776b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
777b08fbf24SPaolo Abeni	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
778b08fbf24SPaolo Abeni	run_tests $ns1 $ns2 10.0.1.1
779b08fbf24SPaolo Abeni	chk_join_nr "multiple subflows and signal" 3 3 3
780be613160SGeliang Tang	chk_add_nr 1 1
7811002b89fSGeliang Tang}
782b08fbf24SPaolo Abeni
7831002b89fSGeliang Tanglink_failure_tests()
7841002b89fSGeliang Tang{
7858b819a84SFlorian Westphal	# accept and use add_addr with additional subflows and link loss
7868b819a84SFlorian Westphal	reset
7878b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
7888b819a84SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
7898b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
7908b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
7918b819a84SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
7928b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 1
7938b819a84SFlorian Westphal	chk_join_nr "multiple flows, signal, link failure" 3 3 3
7948b819a84SFlorian Westphal	chk_add_nr 1 1
7951002b89fSGeliang Tang}
7968b819a84SFlorian Westphal
7971002b89fSGeliang Tangadd_addr_timeout_tests()
7981002b89fSGeliang Tang{
7998d014eaaSGeliang Tang	# add_addr timeout
8008d014eaaSGeliang Tang	reset_with_add_addr_timeout
8018d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
8028d014eaaSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
8038d014eaaSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
8048b819a84SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow
8058d014eaaSGeliang Tang	chk_join_nr "signal address, ADD_ADDR timeout" 1 1 1
8068d014eaaSGeliang Tang	chk_add_nr 4 0
8078d014eaaSGeliang Tang
8081002b89fSGeliang Tang	# add_addr timeout IPv6
8091002b89fSGeliang Tang	reset_with_add_addr_timeout 6
8101002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
8111002b89fSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
8121002b89fSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
8131002b89fSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
8141002b89fSGeliang Tang	chk_join_nr "signal address, ADD_ADDR6 timeout" 1 1 1
8151002b89fSGeliang Tang	chk_add_nr 4 0
8161002b89fSGeliang Tang}
8171002b89fSGeliang Tang
8181002b89fSGeliang Tangremove_tests()
8191002b89fSGeliang Tang{
820dd72b0feSGeliang Tang	# single subflow, remove
821dd72b0feSGeliang Tang	reset
822dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
823dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
824dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
8252e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
826dd72b0feSGeliang Tang	chk_join_nr "remove single subflow" 1 1 1
827dd72b0feSGeliang Tang	chk_rm_nr 1 1
828dd72b0feSGeliang Tang
829dd72b0feSGeliang Tang	# multiple subflows, remove
830dd72b0feSGeliang Tang	reset
831dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
832dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
833dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
834dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
8352e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
836dd72b0feSGeliang Tang	chk_join_nr "remove multiple subflows" 2 2 2
837dd72b0feSGeliang Tang	chk_rm_nr 2 2
838dd72b0feSGeliang Tang
839dd72b0feSGeliang Tang	# single address, remove
840dd72b0feSGeliang Tang	reset
841dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
842dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
843dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
8442e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
845dd72b0feSGeliang Tang	chk_join_nr "remove single address" 1 1 1
846dd72b0feSGeliang Tang	chk_add_nr 1 1
847*7028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
848dd72b0feSGeliang Tang
849dd72b0feSGeliang Tang	# subflow and signal, remove
850dd72b0feSGeliang Tang	reset
851dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
852dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
853dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
854dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
8552e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
856dd72b0feSGeliang Tang	chk_join_nr "remove subflow and signal" 2 2 2
857dd72b0feSGeliang Tang	chk_add_nr 1 1
858dd72b0feSGeliang Tang	chk_rm_nr 1 1
859dd72b0feSGeliang Tang
860dd72b0feSGeliang Tang	# subflows and signal, remove
861dd72b0feSGeliang Tang	reset
862dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
863dd72b0feSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
864dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
865dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
866dd72b0feSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
8672e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 slow
868dd72b0feSGeliang Tang	chk_join_nr "remove subflows and signal" 3 3 3
869dd72b0feSGeliang Tang	chk_add_nr 1 1
870dd72b0feSGeliang Tang	chk_rm_nr 2 2
871dd72b0feSGeliang Tang
8726fe4ccdcSGeliang Tang	# subflows and signal, flush
8736fe4ccdcSGeliang Tang	reset
8746fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
8756fe4ccdcSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
8766fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
8776fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
8786fe4ccdcSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
8792e8cbf45SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
8806fe4ccdcSGeliang Tang	chk_join_nr "flush subflows and signal" 3 3 3
8816fe4ccdcSGeliang Tang	chk_add_nr 1 1
8826fe4ccdcSGeliang Tang	chk_rm_nr 2 2
8831002b89fSGeliang Tang}
8846fe4ccdcSGeliang Tang
8851002b89fSGeliang Tangadd_tests()
8861002b89fSGeliang Tang{
8876208fd82SGeliang Tang	# add single subflow
8886208fd82SGeliang Tang	reset
8896208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
8906208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
8916208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow
8926208fd82SGeliang Tang	chk_join_nr "add single subflow" 1 1 1
8936208fd82SGeliang Tang
8946208fd82SGeliang Tang	# add signal address
8956208fd82SGeliang Tang	reset
8966208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
8976208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
8986208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow
8996208fd82SGeliang Tang	chk_join_nr "add signal address" 1 1 1
9006208fd82SGeliang Tang	chk_add_nr 1 1
9016208fd82SGeliang Tang
9026208fd82SGeliang Tang	# add multiple subflows
9036208fd82SGeliang Tang	reset
9046208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
9056208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
9066208fd82SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow
9076208fd82SGeliang Tang	chk_join_nr "add multiple subflows" 2 2 2
9086208fd82SGeliang Tang
9096208fd82SGeliang Tang	# add multiple subflows IPv6
9106208fd82SGeliang Tang	reset
9116208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
9126208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
9136208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow
9146208fd82SGeliang Tang	chk_join_nr "add multiple subflows IPv6" 2 2 2
9156208fd82SGeliang Tang
9166208fd82SGeliang Tang	# add multiple addresses IPv6
9176208fd82SGeliang Tang	reset
9186208fd82SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
9196208fd82SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
9206208fd82SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow
9216208fd82SGeliang Tang	chk_join_nr "add multiple addresses IPv6" 2 2 2
9226208fd82SGeliang Tang	chk_add_nr 2 2
9231002b89fSGeliang Tang}
9246208fd82SGeliang Tang
9251002b89fSGeliang Tangipv6_tests()
9261002b89fSGeliang Tang{
927523514edSGeliang Tang	# subflow IPv6
928523514edSGeliang Tang	reset
929523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
930523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
931523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
932523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
933523514edSGeliang Tang	chk_join_nr "single subflow IPv6" 1 1 1
934523514edSGeliang Tang
935523514edSGeliang Tang	# add_address, unused IPv6
936523514edSGeliang Tang	reset
937523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
938523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
939523514edSGeliang Tang	chk_join_nr "unused signal address IPv6" 0 0 0
940523514edSGeliang Tang	chk_add_nr 1 1
941523514edSGeliang Tang
942523514edSGeliang Tang	# signal address IPv6
943523514edSGeliang Tang	reset
944523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
945523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
946523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
947523514edSGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow
948523514edSGeliang Tang	chk_join_nr "single address IPv6" 1 1 1
949523514edSGeliang Tang	chk_add_nr 1 1
950523514edSGeliang Tang
951523514edSGeliang Tang	# single address IPv6, remove
952523514edSGeliang Tang	reset
953523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
954523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
955523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
9562e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow
957523514edSGeliang Tang	chk_join_nr "remove single address IPv6" 1 1 1
958523514edSGeliang Tang	chk_add_nr 1 1
959*7028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
960523514edSGeliang Tang
961523514edSGeliang Tang	# subflow and signal IPv6, remove
962523514edSGeliang Tang	reset
963523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
964523514edSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
965523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
966523514edSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
9672e8cbf45SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow
968523514edSGeliang Tang	chk_join_nr "remove subflow and signal IPv6" 2 2 2
969523514edSGeliang Tang	chk_add_nr 1 1
970523514edSGeliang Tang	chk_rm_nr 1 1
9711002b89fSGeliang Tang}
972523514edSGeliang Tang
9731002b89fSGeliang Tangv4mapped_tests()
9741002b89fSGeliang Tang{
975a6094788SGeliang Tang	# subflow IPv4-mapped to IPv4-mapped
976a6094788SGeliang Tang	reset
977a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
978a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
979a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
980a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
981a6094788SGeliang Tang	chk_join_nr "single subflow IPv4-mapped" 1 1 1
982a6094788SGeliang Tang
983a6094788SGeliang Tang	# signal address IPv4-mapped with IPv4-mapped sk
984a6094788SGeliang Tang	reset
985a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
986a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
987a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
988a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
989a6094788SGeliang Tang	chk_join_nr "signal address IPv4-mapped" 1 1 1
990a6094788SGeliang Tang	chk_add_nr 1 1
991a6094788SGeliang Tang
992a6094788SGeliang Tang	# subflow v4-map-v6
993a6094788SGeliang Tang	reset
994a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
995a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
996a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
997a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
998a6094788SGeliang Tang	chk_join_nr "single subflow v4-map-v6" 1 1 1
999a6094788SGeliang Tang
1000a6094788SGeliang Tang	# signal address v4-map-v6
1001a6094788SGeliang Tang	reset
1002a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1003a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1004a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1005a6094788SGeliang Tang	run_tests $ns1 $ns2 "::ffff:10.0.1.1"
1006a6094788SGeliang Tang	chk_join_nr "signal address v4-map-v6" 1 1 1
1007a6094788SGeliang Tang	chk_add_nr 1 1
1008a6094788SGeliang Tang
1009a6094788SGeliang Tang	# subflow v6-map-v4
1010a6094788SGeliang Tang	reset
1011a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1012a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1013a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add "::ffff:10.0.3.2" flags subflow
1014a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1015a6094788SGeliang Tang	chk_join_nr "single subflow v6-map-v4" 1 1 1
1016a6094788SGeliang Tang
1017a6094788SGeliang Tang	# signal address v6-map-v4
1018a6094788SGeliang Tang	reset
1019a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1020a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1021a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add "::ffff:10.0.2.1" flags signal
1022a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1023a6094788SGeliang Tang	chk_join_nr "signal address v6-map-v4" 1 1 1
1024a6094788SGeliang Tang	chk_add_nr 1 1
1025a6094788SGeliang Tang
1026a6094788SGeliang Tang	# no subflow IPv6 to v4 address
1027a6094788SGeliang Tang	reset
1028a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1029a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1030a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::2 flags subflow
1031a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1032a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
1033a6094788SGeliang Tang
1034a6094788SGeliang Tang	# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
1035a6094788SGeliang Tang	reset
1036a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1037a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1038a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add dead:beef:2::10.0.3.2 flags subflow
1039a6094788SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
1040a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
1041a6094788SGeliang Tang
1042a6094788SGeliang Tang	# no subflow IPv4 to v6 address, no need to slow down too then
1043a6094788SGeliang Tang	reset
1044a6094788SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1045a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1046a6094788SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
1047a6094788SGeliang Tang	run_tests $ns1 $ns2 dead:beef:1::1
1048a6094788SGeliang Tang	chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
10491002b89fSGeliang Tang}
1050a6094788SGeliang Tang
10511002b89fSGeliang Tangbackup_tests()
10521002b89fSGeliang Tang{
1053718eb44eSGeliang Tang	# single subflow, backup
1054718eb44eSGeliang Tang	reset
1055718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1056718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
1057718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow,backup
1058718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup
1059718eb44eSGeliang Tang	chk_join_nr "single subflow, backup" 1 1 1
1060718eb44eSGeliang Tang	chk_prio_nr 0 1
1061718eb44eSGeliang Tang
1062718eb44eSGeliang Tang	# single address, backup
1063718eb44eSGeliang Tang	reset
1064718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
1065718eb44eSGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
1066718eb44eSGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
1067718eb44eSGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
1068718eb44eSGeliang Tang	chk_join_nr "single address, backup" 1 1 1
1069718eb44eSGeliang Tang	chk_add_nr 1 1
1070718eb44eSGeliang Tang	chk_prio_nr 1 0
10711002b89fSGeliang Tang}
1072718eb44eSGeliang Tang
10731002b89fSGeliang Tangadd_addr_ports_tests()
10741002b89fSGeliang Tang{
10758a127bf6SGeliang Tang	# signal address with port
10768a127bf6SGeliang Tang	reset
10778a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
10788a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
10798a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
10808a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
10818a127bf6SGeliang Tang	chk_join_nr "signal address with port" 1 1 1
10828a127bf6SGeliang Tang	chk_add_nr 1 1 1
10838a127bf6SGeliang Tang
10848a127bf6SGeliang Tang	# subflow and signal with port
10858a127bf6SGeliang Tang	reset
10868a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
10878a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
10888a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
10898a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
10908a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
10918a127bf6SGeliang Tang	chk_join_nr "subflow and signal with port" 2 2 2
10928a127bf6SGeliang Tang	chk_add_nr 1 1 1
10938a127bf6SGeliang Tang
10948a127bf6SGeliang Tang	# single address with port, remove
10958a127bf6SGeliang Tang	reset
10968a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
10978a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
10988a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
10998a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow
11008a127bf6SGeliang Tang	chk_join_nr "remove single address with port" 1 1 1
11018a127bf6SGeliang Tang	chk_add_nr 1 1 1
1102*7028ba8aSGeliang Tang	chk_rm_nr 1 1 invert
11038a127bf6SGeliang Tang
11048a127bf6SGeliang Tang	# subflow and signal with port, remove
11058a127bf6SGeliang Tang	reset
11068a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
11078a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
11088a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
11098a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11108a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow
11118a127bf6SGeliang Tang	chk_join_nr "remove subflow and signal with port" 2 2 2
11128a127bf6SGeliang Tang	chk_add_nr 1 1 1
11138a127bf6SGeliang Tang	chk_rm_nr 1 1
11148a127bf6SGeliang Tang
11158a127bf6SGeliang Tang	# subflows and signal with port, flush
11168a127bf6SGeliang Tang	reset
11178a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
11188a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
11198a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
11208a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
11218a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
11228a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
11238a127bf6SGeliang Tang	chk_join_nr "flush subflows and signal with port" 3 3 3
11248a127bf6SGeliang Tang	chk_add_nr 1 1
11258a127bf6SGeliang Tang	chk_rm_nr 2 2
11268a127bf6SGeliang Tang
11278a127bf6SGeliang Tang	# multiple addresses with port
11288a127bf6SGeliang Tang	reset
11298a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11308a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
11318a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10100
11328a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11338a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
11348a127bf6SGeliang Tang	chk_join_nr "multiple addresses with port" 2 2 2
11358a127bf6SGeliang Tang	chk_add_nr 2 2 2
11368a127bf6SGeliang Tang
11378a127bf6SGeliang Tang	# multiple addresses with ports
11388a127bf6SGeliang Tang	reset
11398a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl limits 2 2
11408a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
11418a127bf6SGeliang Tang	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal port 10101
11428a127bf6SGeliang Tang	ip netns exec $ns2 ./pm_nl_ctl limits 2 2
11438a127bf6SGeliang Tang	run_tests $ns1 $ns2 10.0.1.1
11448a127bf6SGeliang Tang	chk_join_nr "multiple addresses with ports" 2 2 2
11458a127bf6SGeliang Tang	chk_add_nr 2 2 2
11461002b89fSGeliang Tang}
11478a127bf6SGeliang Tang
11481002b89fSGeliang Tangsyncookies_tests()
11491002b89fSGeliang Tang{
115000587187SFlorian Westphal	# single subflow, syncookies
115100587187SFlorian Westphal	reset_with_cookies
115200587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
115300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
115400587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
115500587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
115600587187SFlorian Westphal	chk_join_nr "single subflow with syn cookies" 1 1 1
115700587187SFlorian Westphal
115800587187SFlorian Westphal	# multiple subflows with syn cookies
115900587187SFlorian Westphal	reset_with_cookies
116000587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
116100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
116200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
116300587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
116400587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
116500587187SFlorian Westphal	chk_join_nr "multiple subflows with syn cookies" 2 2 2
116600587187SFlorian Westphal
116700587187SFlorian Westphal	# multiple subflows limited by server
116800587187SFlorian Westphal	reset_with_cookies
116900587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
117000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 0 2
117100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
117200587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow
117300587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
117400587187SFlorian Westphal	chk_join_nr "subflows limited by server w cookies" 2 2 1
117500587187SFlorian Westphal
117600587187SFlorian Westphal	# test signal address with cookies
117700587187SFlorian Westphal	reset_with_cookies
117800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
117900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
118000587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
118100587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
118200587187SFlorian Westphal	chk_join_nr "signal address with syn cookies" 1 1 1
1183be613160SGeliang Tang	chk_add_nr 1 1
118400587187SFlorian Westphal
118500587187SFlorian Westphal	# test cookie with subflow and signal
118600587187SFlorian Westphal	reset_with_cookies
118700587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
118800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 2
118900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 2
119000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
119100587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
119200587187SFlorian Westphal	chk_join_nr "subflow and signal w cookies" 2 2 2
1193be613160SGeliang Tang	chk_add_nr 1 1
119400587187SFlorian Westphal
119500587187SFlorian Westphal	# accept and use add_addr with additional subflows
119600587187SFlorian Westphal	reset_with_cookies
119700587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl limits 0 3
119800587187SFlorian Westphal	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
119900587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl limits 1 3
120000587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
120100587187SFlorian Westphal	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
120200587187SFlorian Westphal	run_tests $ns1 $ns2 10.0.1.1
120300587187SFlorian Westphal	chk_join_nr "subflows and signal w. cookies" 3 3 3
1204be613160SGeliang Tang	chk_add_nr 1 1
12051002b89fSGeliang Tang}
12061002b89fSGeliang Tang
12071002b89fSGeliang Tangall_tests()
12081002b89fSGeliang Tang{
12091002b89fSGeliang Tang	subflows_tests
12101002b89fSGeliang Tang	signal_address_tests
12111002b89fSGeliang Tang	link_failure_tests
12121002b89fSGeliang Tang	add_addr_timeout_tests
12131002b89fSGeliang Tang	remove_tests
12141002b89fSGeliang Tang	add_tests
12151002b89fSGeliang Tang	ipv6_tests
12161002b89fSGeliang Tang	v4mapped_tests
12171002b89fSGeliang Tang	backup_tests
12181002b89fSGeliang Tang	add_addr_ports_tests
12191002b89fSGeliang Tang	syncookies_tests
12201002b89fSGeliang Tang}
12211002b89fSGeliang Tang
12221002b89fSGeliang Tangusage()
12231002b89fSGeliang Tang{
12241002b89fSGeliang Tang	echo "mptcp_join usage:"
12251002b89fSGeliang Tang	echo "  -f subflows_tests"
12261002b89fSGeliang Tang	echo "  -s signal_address_tests"
12271002b89fSGeliang Tang	echo "  -l link_failure_tests"
12281002b89fSGeliang Tang	echo "  -t add_addr_timeout_tests"
12291002b89fSGeliang Tang	echo "  -r remove_tests"
12301002b89fSGeliang Tang	echo "  -a add_tests"
12311002b89fSGeliang Tang	echo "  -6 ipv6_tests"
12321002b89fSGeliang Tang	echo "  -4 v4mapped_tests"
12331002b89fSGeliang Tang	echo "  -b backup_tests"
12341002b89fSGeliang Tang	echo "  -p add_addr_ports_tests"
12351002b89fSGeliang Tang	echo "  -c syncookies_tests"
12361002b89fSGeliang Tang	echo "  -h help"
12371002b89fSGeliang Tang}
12381002b89fSGeliang Tang
12391002b89fSGeliang Tangsin=$(mktemp)
12401002b89fSGeliang Tangsout=$(mktemp)
12411002b89fSGeliang Tangcin=$(mktemp)
12421002b89fSGeliang Tangcinsent=$(mktemp)
12431002b89fSGeliang Tangcout=$(mktemp)
12441002b89fSGeliang Tanginit
12451002b89fSGeliang Tangmake_file "$cin" "client" 1
12461002b89fSGeliang Tangmake_file "$sin" "server" 1
12471002b89fSGeliang Tangtrap cleanup EXIT
12481002b89fSGeliang Tang
12491002b89fSGeliang Tangif [ -z $1 ]; then
12501002b89fSGeliang Tang	all_tests
12511002b89fSGeliang Tang	exit $ret
12521002b89fSGeliang Tangfi
12531002b89fSGeliang Tang
12541002b89fSGeliang Tangwhile getopts 'fsltra64bpch' opt; do
12551002b89fSGeliang Tang	case $opt in
12561002b89fSGeliang Tang		f)
12571002b89fSGeliang Tang			subflows_tests
12581002b89fSGeliang Tang			;;
12591002b89fSGeliang Tang		s)
12601002b89fSGeliang Tang			signal_address_tests
12611002b89fSGeliang Tang			;;
12621002b89fSGeliang Tang		l)
12631002b89fSGeliang Tang			link_failure_tests
12641002b89fSGeliang Tang			;;
12651002b89fSGeliang Tang		t)
12661002b89fSGeliang Tang			add_addr_timeout_tests
12671002b89fSGeliang Tang			;;
12681002b89fSGeliang Tang		r)
12691002b89fSGeliang Tang			remove_tests
12701002b89fSGeliang Tang			;;
12711002b89fSGeliang Tang		a)
12721002b89fSGeliang Tang			add_tests
12731002b89fSGeliang Tang			;;
12741002b89fSGeliang Tang		6)
12751002b89fSGeliang Tang			ipv6_tests
12761002b89fSGeliang Tang			;;
12771002b89fSGeliang Tang		4)
12781002b89fSGeliang Tang			v4mapped_tests
12791002b89fSGeliang Tang			;;
12801002b89fSGeliang Tang		b)
12811002b89fSGeliang Tang			backup_tests
12821002b89fSGeliang Tang			;;
12831002b89fSGeliang Tang		p)
12841002b89fSGeliang Tang			add_addr_ports_tests
12851002b89fSGeliang Tang			;;
12861002b89fSGeliang Tang		c)
12871002b89fSGeliang Tang			syncookies_tests
12881002b89fSGeliang Tang			;;
12891002b89fSGeliang Tang		h | *)
12901002b89fSGeliang Tang			usage
12911002b89fSGeliang Tang			;;
12921002b89fSGeliang Tang	esac
12931002b89fSGeliang Tangdone
129400587187SFlorian Westphal
1295b08fbf24SPaolo Abeniexit $ret
1296