1b08fbf24SPaolo Abeni#!/bin/bash 2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0 3b08fbf24SPaolo Abeni 4d8d08302SMatthieu Baerts# Double quotes to prevent globbing and word splitting is recommended in new 5d8d08302SMatthieu Baerts# code but we accept it, especially because there were too many before having 6d8d08302SMatthieu Baerts# address all other issues detected by shellcheck. 7d8d08302SMatthieu Baerts#shellcheck disable=SC2086 8d8d08302SMatthieu Baerts 90fcd72dfSMatthieu Baerts# ShellCheck incorrectly believes that most of the code here is unreachable 100fcd72dfSMatthieu Baerts# because it's invoked by variable name, see how the "tests" array is used 110fcd72dfSMatthieu Baerts#shellcheck disable=SC2317 120fcd72dfSMatthieu Baerts 13715c78a8SMatthieu Baerts. "$(dirname "${0}")/mptcp_lib.sh" 14715c78a8SMatthieu Baerts 15b08fbf24SPaolo Abeniret=0 16b08fbf24SPaolo Abenisin="" 177d1e6f16SPaolo Abenisinfail="" 18b08fbf24SPaolo Abenisout="" 19b08fbf24SPaolo Abenicin="" 207d1e6f16SPaolo Abenicinfail="" 218b819a84SFlorian Westphalcinsent="" 22d328fe87SMatthieu Baertstmpfile="" 23b08fbf24SPaolo Abenicout="" 241e777bd8SMatthieu Baertscapout="" 251e777bd8SMatthieu Baertsns1="" 261e777bd8SMatthieu Baertsns2="" 27b08fbf24SPaolo Abeniksft_skip=4 285888a61cSMatthieu Baertstimeout_poll=30 295888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1)) 30b08fbf24SPaolo Abenicapture=0 31af66d3e1SGeliang Tangchecksum=0 3234aa6e3bSGeliang Tangip_mptcp=0 338117dac3SGeliang Tangcheck_invert=0 343c082695SGeliang Tangvalidate_checksum=0 3593827ad5SMatthieu Baertsinit=0 36a3735625SGeliang Tangevts_ns1="" 37a3735625SGeliang Tangevts_ns2="" 38a3735625SGeliang Tangevts_ns1_pid=0 39a3735625SGeliang Tangevts_ns2_pid=0 40b08fbf24SPaolo Abeni 413afd0280SMatthieu Baertsdeclare -A all_tests 42c7d49c03SMatthieu Baertsdeclare -a only_tests_ids 43c7d49c03SMatthieu Baertsdeclare -a only_tests_names 4439aab882SMatthieu Baertsdeclare -A failed_tests 45b08fbf24SPaolo AbeniTEST_COUNT=0 46c7d49c03SMatthieu BaertsTEST_NAME="" 479a0a9367SGeliang Tangnr_blank=40 48b08fbf24SPaolo Abeni 49e59300ceSMatthieu Baertsexport FAILING_LINKS="" 50e59300ceSMatthieu Baerts 518d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 528d014eaaSGeliang Tang# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 538d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 548d014eaaSGeliang Tang 48 0 0 0, 558d014eaaSGeliang Tang 84 0 0 240, 568d014eaaSGeliang Tang 21 0 3 64, 578d014eaaSGeliang Tang 48 0 0 54, 588d014eaaSGeliang Tang 84 0 0 240, 598d014eaaSGeliang Tang 21 6 7 48, 608d014eaaSGeliang Tang 48 0 0 0, 618d014eaaSGeliang Tang 84 0 0 240, 628d014eaaSGeliang Tang 21 0 4 96, 638d014eaaSGeliang Tang 48 0 0 74, 648d014eaaSGeliang Tang 84 0 0 240, 658d014eaaSGeliang Tang 21 0 1 48, 668d014eaaSGeliang Tang 6 0 0 65535, 678d014eaaSGeliang Tang 6 0 0 0" 688d014eaaSGeliang Tang 6993827ad5SMatthieu Baertsinit_partial() 70b08fbf24SPaolo Abeni{ 71b08fbf24SPaolo Abeni capout=$(mktemp) 72b08fbf24SPaolo Abeni 73787eb1e4SMatthieu Baerts local sec rndh 74787eb1e4SMatthieu Baerts sec=$(date +%s) 75787eb1e4SMatthieu Baerts rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 76b08fbf24SPaolo Abeni 77b08fbf24SPaolo Abeni ns1="ns1-$rndh" 78b08fbf24SPaolo Abeni ns2="ns2-$rndh" 79b08fbf24SPaolo Abeni 801e777bd8SMatthieu Baerts local netns 81b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 82b08fbf24SPaolo Abeni ip netns add $netns || exit $ksft_skip 83b08fbf24SPaolo Abeni ip -net $netns link set lo up 84b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.mptcp.enabled=1 855ac1d2d6SMat Martineau ip netns exec $netns sysctl -q net.mptcp.pm_type=0 86b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 87b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 88af66d3e1SGeliang Tang if [ $checksum -eq 1 ]; then 89af66d3e1SGeliang Tang ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 90af66d3e1SGeliang Tang fi 91b08fbf24SPaolo Abeni done 92b08fbf24SPaolo Abeni 938117dac3SGeliang Tang check_invert=0 943c082695SGeliang Tang validate_checksum=$checksum 95e59300ceSMatthieu Baerts FAILING_LINKS="" 968117dac3SGeliang Tang 97b08fbf24SPaolo Abeni # ns1 ns2 98b08fbf24SPaolo Abeni # ns1eth1 ns2eth1 99b08fbf24SPaolo Abeni # ns1eth2 ns2eth2 100b08fbf24SPaolo Abeni # ns1eth3 ns2eth3 101b08fbf24SPaolo Abeni # ns1eth4 ns2eth4 102b08fbf24SPaolo Abeni 1031e777bd8SMatthieu Baerts local i 1044bfadd71SMatthieu Baerts for i in $(seq 1 4); do 105b08fbf24SPaolo Abeni ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 106b08fbf24SPaolo Abeni ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 107b08fbf24SPaolo Abeni ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 108b08fbf24SPaolo Abeni ip -net "$ns1" link set ns1eth$i up 109b08fbf24SPaolo Abeni 110b08fbf24SPaolo Abeni ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 111b08fbf24SPaolo Abeni ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 112b08fbf24SPaolo Abeni ip -net "$ns2" link set ns2eth$i up 113b08fbf24SPaolo Abeni 114b08fbf24SPaolo Abeni # let $ns2 reach any $ns1 address from any interface 115b08fbf24SPaolo Abeni ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 1169846921dSPaolo Abeni ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 117b08fbf24SPaolo Abeni done 118b08fbf24SPaolo Abeni} 119b08fbf24SPaolo Abeni 1207d1e6f16SPaolo Abeniinit_shapers() 1217d1e6f16SPaolo Abeni{ 1221e777bd8SMatthieu Baerts local i 1234bfadd71SMatthieu Baerts for i in $(seq 1 4); do 1247d1e6f16SPaolo Abeni tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 1257d1e6f16SPaolo Abeni tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 1267d1e6f16SPaolo Abeni done 1277d1e6f16SPaolo Abeni} 1287d1e6f16SPaolo Abeni 129b08fbf24SPaolo Abenicleanup_partial() 130b08fbf24SPaolo Abeni{ 131b08fbf24SPaolo Abeni rm -f "$capout" 132b08fbf24SPaolo Abeni 1331e777bd8SMatthieu Baerts local netns 134b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 135b08fbf24SPaolo Abeni ip netns del $netns 136c2a55e8fSMatthieu Baerts rm -f /tmp/$netns.{nstat,out} 137b08fbf24SPaolo Abeni done 138b08fbf24SPaolo Abeni} 139b08fbf24SPaolo Abeni 14087154755SMatthieu Baertscheck_tools() 14187154755SMatthieu Baerts{ 142715c78a8SMatthieu Baerts mptcp_lib_check_mptcp 143715c78a8SMatthieu Baerts 14487154755SMatthieu Baerts if ! ip -Version &> /dev/null; then 14587154755SMatthieu Baerts echo "SKIP: Could not run test without ip tool" 14687154755SMatthieu Baerts exit $ksft_skip 14787154755SMatthieu Baerts fi 14887154755SMatthieu Baerts 14987154755SMatthieu Baerts if ! iptables -V &> /dev/null; then 15087154755SMatthieu Baerts echo "SKIP: Could not run all tests without iptables tool" 15187154755SMatthieu Baerts exit $ksft_skip 15287154755SMatthieu Baerts fi 15387154755SMatthieu Baerts 15487154755SMatthieu Baerts if ! ip6tables -V &> /dev/null; then 15587154755SMatthieu Baerts echo "SKIP: Could not run all tests without ip6tables tool" 15687154755SMatthieu Baerts exit $ksft_skip 15787154755SMatthieu Baerts fi 15887154755SMatthieu Baerts} 15987154755SMatthieu Baerts 16093827ad5SMatthieu Baertsinit() { 16193827ad5SMatthieu Baerts init=1 16293827ad5SMatthieu Baerts 16387154755SMatthieu Baerts check_tools 16487154755SMatthieu Baerts 16593827ad5SMatthieu Baerts sin=$(mktemp) 16693827ad5SMatthieu Baerts sout=$(mktemp) 16793827ad5SMatthieu Baerts cin=$(mktemp) 16893827ad5SMatthieu Baerts cinsent=$(mktemp) 16993827ad5SMatthieu Baerts cout=$(mktemp) 170a3735625SGeliang Tang evts_ns1=$(mktemp) 171a3735625SGeliang Tang evts_ns2=$(mktemp) 17293827ad5SMatthieu Baerts 17393827ad5SMatthieu Baerts trap cleanup EXIT 17493827ad5SMatthieu Baerts 17593827ad5SMatthieu Baerts make_file "$cin" "client" 1 17693827ad5SMatthieu Baerts make_file "$sin" "server" 1 17793827ad5SMatthieu Baerts} 17893827ad5SMatthieu Baerts 179b08fbf24SPaolo Abenicleanup() 180b08fbf24SPaolo Abeni{ 1817d1e6f16SPaolo Abeni rm -f "$cin" "$cout" "$sinfail" 1827d1e6f16SPaolo Abeni rm -f "$sin" "$sout" "$cinsent" "$cinfail" 183d328fe87SMatthieu Baerts rm -f "$tmpfile" 184a3735625SGeliang Tang rm -rf $evts_ns1 $evts_ns2 185b08fbf24SPaolo Abeni cleanup_partial 186b08fbf24SPaolo Abeni} 187b08fbf24SPaolo Abeni 188ae7bd9ccSMatthieu Baertsskip_test() 189ae7bd9ccSMatthieu Baerts{ 190c7d49c03SMatthieu Baerts if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 191ae7bd9ccSMatthieu Baerts return 1 192ae7bd9ccSMatthieu Baerts fi 193ae7bd9ccSMatthieu Baerts 194ae7bd9ccSMatthieu Baerts local i 195c7d49c03SMatthieu Baerts for i in "${only_tests_ids[@]}"; do 196ae7bd9ccSMatthieu Baerts if [ "${TEST_COUNT}" -eq "${i}" ]; then 197ae7bd9ccSMatthieu Baerts return 1 198ae7bd9ccSMatthieu Baerts fi 199ae7bd9ccSMatthieu Baerts done 200c7d49c03SMatthieu Baerts for i in "${only_tests_names[@]}"; do 201c7d49c03SMatthieu Baerts if [ "${TEST_NAME}" = "${i}" ]; then 202c7d49c03SMatthieu Baerts return 1 203c7d49c03SMatthieu Baerts fi 204c7d49c03SMatthieu Baerts done 205ae7bd9ccSMatthieu Baerts 206ae7bd9ccSMatthieu Baerts return 0 207ae7bd9ccSMatthieu Baerts} 208ae7bd9ccSMatthieu Baerts 209c7d49c03SMatthieu Baerts# $1: test name 210b08fbf24SPaolo Abenireset() 211b08fbf24SPaolo Abeni{ 212c7d49c03SMatthieu Baerts TEST_NAME="${1}" 213c7d49c03SMatthieu Baerts 214ae7bd9ccSMatthieu Baerts TEST_COUNT=$((TEST_COUNT+1)) 215ae7bd9ccSMatthieu Baerts 216ae7bd9ccSMatthieu Baerts if skip_test; then 217ae7bd9ccSMatthieu Baerts return 1 218ae7bd9ccSMatthieu Baerts fi 219ae7bd9ccSMatthieu Baerts 22093827ad5SMatthieu Baerts if [ "${init}" != "1" ]; then 221b08fbf24SPaolo Abeni init 22293827ad5SMatthieu Baerts else 22393827ad5SMatthieu Baerts cleanup_partial 22493827ad5SMatthieu Baerts fi 22593827ad5SMatthieu Baerts 22693827ad5SMatthieu Baerts init_partial 227ae7bd9ccSMatthieu Baerts 228ae7bd9ccSMatthieu Baerts return 0 229b08fbf24SPaolo Abeni} 230b08fbf24SPaolo Abeni 231c7d49c03SMatthieu Baerts# $1: test name 23200587187SFlorian Westphalreset_with_cookies() 23300587187SFlorian Westphal{ 234c7d49c03SMatthieu Baerts reset "${1}" || return 1 23500587187SFlorian Westphal 2361e777bd8SMatthieu Baerts local netns 23700587187SFlorian Westphal for netns in "$ns1" "$ns2"; do 23800587187SFlorian Westphal ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 23900587187SFlorian Westphal done 24000587187SFlorian Westphal} 24100587187SFlorian Westphal 242c7d49c03SMatthieu Baerts# $1: test name 2438d014eaaSGeliang Tangreset_with_add_addr_timeout() 2448d014eaaSGeliang Tang{ 245c7d49c03SMatthieu Baerts local ip="${2:-4}" 2468d014eaaSGeliang Tang local tables 2478d014eaaSGeliang Tang 248c7d49c03SMatthieu Baerts reset "${1}" || return 1 249c7d49c03SMatthieu Baerts 2508d014eaaSGeliang Tang tables="iptables" 2518d014eaaSGeliang Tang if [ $ip -eq 6 ]; then 2528d014eaaSGeliang Tang tables="ip6tables" 2538d014eaaSGeliang Tang fi 2548d014eaaSGeliang Tang 2558d014eaaSGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2568d014eaaSGeliang Tang ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 2578d014eaaSGeliang Tang -m tcp --tcp-option 30 \ 2588d014eaaSGeliang Tang -m bpf --bytecode \ 2598d014eaaSGeliang Tang "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 2608d014eaaSGeliang Tang -j DROP 2618d014eaaSGeliang Tang} 2628d014eaaSGeliang Tang 263c7d49c03SMatthieu Baerts# $1: test name 264af66d3e1SGeliang Tangreset_with_checksum() 265af66d3e1SGeliang Tang{ 266af66d3e1SGeliang Tang local ns1_enable=$1 267af66d3e1SGeliang Tang local ns2_enable=$2 268af66d3e1SGeliang Tang 269c7d49c03SMatthieu Baerts reset "checksum test ${1} ${2}" || return 1 270af66d3e1SGeliang Tang 271af66d3e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 272af66d3e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 2733c082695SGeliang Tang 2743c082695SGeliang Tang validate_checksum=1 275af66d3e1SGeliang Tang} 276af66d3e1SGeliang Tang 2770cddb4a6SGeliang Tangreset_with_allow_join_id0() 2780cddb4a6SGeliang Tang{ 279c7d49c03SMatthieu Baerts local ns1_enable=$2 280c7d49c03SMatthieu Baerts local ns2_enable=$3 2810cddb4a6SGeliang Tang 282c7d49c03SMatthieu Baerts reset "${1}" || return 1 2830cddb4a6SGeliang Tang 2840cddb4a6SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 2850cddb4a6SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 2860cddb4a6SGeliang Tang} 2870cddb4a6SGeliang Tang 288b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet 289b6e074e1SGeliang Tang# 290b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 291b6e074e1SGeliang Tang# carrying enough data. 292b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still 293b6e074e1SGeliang Tang# considered as valid at the TCP level. 294b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been 295b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted: 296b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options. 297b6e074e1SGeliang Tang# 298b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets 299b6e074e1SGeliang Tang# not carrying enough data: 300b6e074e1SGeliang Tang# 301b6e074e1SGeliang Tang# tc action pedit offset 162 out of bounds 302b6e074e1SGeliang Tang# 303b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data. 304b6e074e1SGeliang Tangreset_with_fail() 305b6e074e1SGeliang Tang{ 306b6e074e1SGeliang Tang reset "${1}" || return 1 307b6e074e1SGeliang Tang 308b6e074e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 309b6e074e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 310b6e074e1SGeliang Tang 311b6e074e1SGeliang Tang check_invert=1 312b6e074e1SGeliang Tang validate_checksum=1 313b6e074e1SGeliang Tang local i="$2" 314b6e074e1SGeliang Tang local ip="${3:-4}" 315b6e074e1SGeliang Tang local tables 316b6e074e1SGeliang Tang 317b6e074e1SGeliang Tang tables="iptables" 318b6e074e1SGeliang Tang if [ $ip -eq 6 ]; then 319b6e074e1SGeliang Tang tables="ip6tables" 320b6e074e1SGeliang Tang fi 321b6e074e1SGeliang Tang 322b6e074e1SGeliang Tang ip netns exec $ns2 $tables \ 323b6e074e1SGeliang Tang -t mangle \ 324b6e074e1SGeliang Tang -A OUTPUT \ 325b6e074e1SGeliang Tang -o ns2eth$i \ 326b6e074e1SGeliang Tang -p tcp \ 327b6e074e1SGeliang Tang -m length --length 150:9999 \ 328b6e074e1SGeliang Tang -m statistic --mode nth --packet 1 --every 99999 \ 329b6e074e1SGeliang Tang -j MARK --set-mark 42 || exit 1 330b6e074e1SGeliang Tang 331b6e074e1SGeliang Tang tc -n $ns2 qdisc add dev ns2eth$i clsact || exit 1 332b6e074e1SGeliang Tang tc -n $ns2 filter add dev ns2eth$i egress \ 333b6e074e1SGeliang Tang protocol ip prio 1000 \ 334b6e074e1SGeliang Tang handle 42 fw \ 335b6e074e1SGeliang Tang action pedit munge offset 148 u8 invert \ 336b6e074e1SGeliang Tang pipe csum tcp \ 337b6e074e1SGeliang Tang index 100 || exit 1 338b6e074e1SGeliang Tang} 339b6e074e1SGeliang Tang 340a3735625SGeliang Tangreset_with_events() 341a3735625SGeliang Tang{ 342a3735625SGeliang Tang reset "${1}" || return 1 343a3735625SGeliang Tang 344a3735625SGeliang Tang :> "$evts_ns1" 345a3735625SGeliang Tang :> "$evts_ns2" 346a3735625SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 347a3735625SGeliang Tang evts_ns1_pid=$! 348a3735625SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 349a3735625SGeliang Tang evts_ns2_pid=$! 350a3735625SGeliang Tang} 351a3735625SGeliang Tang 35239aab882SMatthieu Baertsfail_test() 35339aab882SMatthieu Baerts{ 35439aab882SMatthieu Baerts ret=1 35539aab882SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 35639aab882SMatthieu Baerts} 35739aab882SMatthieu Baerts 35839aab882SMatthieu Baertsget_failed_tests_ids() 35939aab882SMatthieu Baerts{ 36039aab882SMatthieu Baerts # sorted 36139aab882SMatthieu Baerts local i 36239aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 36339aab882SMatthieu Baerts echo "${i}" 36439aab882SMatthieu Baerts done | sort -n 36539aab882SMatthieu Baerts} 36639aab882SMatthieu Baerts 3678b819a84SFlorian Westphalprint_file_err() 3688b819a84SFlorian Westphal{ 3698b819a84SFlorian Westphal ls -l "$1" 1>&2 3708b819a84SFlorian Westphal echo "Trailing bytes are: " 3718b819a84SFlorian Westphal tail -c 27 "$1" 3728b819a84SFlorian Westphal} 3738b819a84SFlorian Westphal 374b08fbf24SPaolo Abenicheck_transfer() 375b08fbf24SPaolo Abeni{ 3761e777bd8SMatthieu Baerts local in=$1 3771e777bd8SMatthieu Baerts local out=$2 3781e777bd8SMatthieu Baerts local what=$3 3796bf41020SPaolo Abeni local bytes=$4 380d8d08302SMatthieu Baerts local i a b 381b08fbf24SPaolo Abeni 3821e777bd8SMatthieu Baerts local line 3836bf41020SPaolo Abeni if [ -n "$bytes" ]; then 3840fcd72dfSMatthieu Baerts local out_size 3856bf41020SPaolo Abeni # when truncating we must check the size explicitly 3860fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 3876bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 3886bf41020SPaolo Abeni echo "[ FAIL ] $what output file has wrong size ($out_size, $bytes)" 3896bf41020SPaolo Abeni fail_test 3906bf41020SPaolo Abeni return 1 3916bf41020SPaolo Abeni fi 392d328fe87SMatthieu Baerts 393d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 394d328fe87SMatthieu Baerts tmpfile=$(mktemp) 395d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 396d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 397d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 398d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 399d328fe87SMatthieu Baerts tmpfile="" 4006bf41020SPaolo Abeni fi 401d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 402d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 4038117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 404b08fbf24SPaolo Abeni echo "[ FAIL ] $what does not match (in, out):" 405b08fbf24SPaolo Abeni print_file_err "$in" 406b08fbf24SPaolo Abeni print_file_err "$out" 40739aab882SMatthieu Baerts fail_test 408b08fbf24SPaolo Abeni 409b08fbf24SPaolo Abeni return 1 4108117dac3SGeliang Tang else 411d8d08302SMatthieu Baerts echo "$what has inverted byte at ${i}" 412b08fbf24SPaolo Abeni fi 4138117dac3SGeliang Tang done 414b08fbf24SPaolo Abeni 415b08fbf24SPaolo Abeni return 0 416b08fbf24SPaolo Abeni} 417b08fbf24SPaolo Abeni 418b08fbf24SPaolo Abenido_ping() 419b08fbf24SPaolo Abeni{ 4201e777bd8SMatthieu Baerts local listener_ns="$1" 4211e777bd8SMatthieu Baerts local connector_ns="$2" 4221e777bd8SMatthieu Baerts local connect_addr="$3" 423b08fbf24SPaolo Abeni 424d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 425b08fbf24SPaolo Abeni echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2 42639aab882SMatthieu Baerts fail_test 427b08fbf24SPaolo Abeni fi 428b08fbf24SPaolo Abeni} 429b08fbf24SPaolo Abeni 4308b819a84SFlorian Westphallink_failure() 4318b819a84SFlorian Westphal{ 4321e777bd8SMatthieu Baerts local ns="$1" 4338b819a84SFlorian Westphal 4347d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 4358b819a84SFlorian Westphal l=$((RANDOM%4)) 4367d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 4377d1e6f16SPaolo Abeni fi 4388b819a84SFlorian Westphal 4391e777bd8SMatthieu Baerts local l 4407d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 4411e777bd8SMatthieu Baerts local veth="ns1eth$l" 4428b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 4437d1e6f16SPaolo Abeni done 4448b819a84SFlorian Westphal} 4458b819a84SFlorian Westphal 446523514edSGeliang Tang# $1: IP address 447523514edSGeliang Tangis_v6() 448523514edSGeliang Tang{ 449523514edSGeliang Tang [ -z "${1##*:*}" ] 450523514edSGeliang Tang} 451523514edSGeliang Tang 452327b9a94SPaolo Abeni# $1: ns, $2: port 453327b9a94SPaolo Abeniwait_local_port_listen() 454327b9a94SPaolo Abeni{ 455327b9a94SPaolo Abeni local listener_ns="${1}" 456327b9a94SPaolo Abeni local port="${2}" 457327b9a94SPaolo Abeni 4581e777bd8SMatthieu Baerts local port_hex 459327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 4601e777bd8SMatthieu Baerts 4611e777bd8SMatthieu Baerts local i 462327b9a94SPaolo Abeni for i in $(seq 10); do 463327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 464327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 465327b9a94SPaolo Abeni break 466327b9a94SPaolo Abeni sleep 0.1 467327b9a94SPaolo Abeni done 468327b9a94SPaolo Abeni} 469327b9a94SPaolo Abeni 470327b9a94SPaolo Abenirm_addr_count() 471327b9a94SPaolo Abeni{ 4721e777bd8SMatthieu Baerts local ns=${1} 473327b9a94SPaolo Abeni 474327b9a94SPaolo Abeni ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}' 475327b9a94SPaolo Abeni} 476327b9a94SPaolo Abeni 477327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 478327b9a94SPaolo Abeniwait_rm_addr() 479327b9a94SPaolo Abeni{ 480327b9a94SPaolo Abeni local ns="${1}" 481327b9a94SPaolo Abeni local old_cnt="${2}" 482327b9a94SPaolo Abeni local cnt 483327b9a94SPaolo Abeni 4841e777bd8SMatthieu Baerts local i 485327b9a94SPaolo Abeni for i in $(seq 10); do 486327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 487327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 488327b9a94SPaolo Abeni sleep 0.1 489327b9a94SPaolo Abeni done 490327b9a94SPaolo Abeni} 491327b9a94SPaolo Abeni 49269c6ce7bSPaolo Abeniwait_mpj() 49369c6ce7bSPaolo Abeni{ 49469c6ce7bSPaolo Abeni local ns="${1}" 49569c6ce7bSPaolo Abeni local cnt old_cnt 49669c6ce7bSPaolo Abeni 49769c6ce7bSPaolo Abeni old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 49869c6ce7bSPaolo Abeni 49969c6ce7bSPaolo Abeni local i 50069c6ce7bSPaolo Abeni for i in $(seq 10); do 50169c6ce7bSPaolo Abeni cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 50269c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 50369c6ce7bSPaolo Abeni sleep 0.1 50469c6ce7bSPaolo Abeni done 50569c6ce7bSPaolo Abeni} 50669c6ce7bSPaolo Abeni 50797040cf9SGeliang Tangkill_wait() 50897040cf9SGeliang Tang{ 50997040cf9SGeliang Tang kill $1 > /dev/null 2>&1 51097040cf9SGeliang Tang wait $1 2>/dev/null 51197040cf9SGeliang Tang} 51297040cf9SGeliang Tang 513a3735625SGeliang Tangkill_events_pids() 514a3735625SGeliang Tang{ 515a3735625SGeliang Tang kill_wait $evts_ns1_pid 516a3735625SGeliang Tang kill_wait $evts_ns2_pid 517a3735625SGeliang Tang} 518a3735625SGeliang Tang 519070d6dafSMatthieu Baertskill_tests_wait() 520070d6dafSMatthieu Baerts{ 5210fcd72dfSMatthieu Baerts #shellcheck disable=SC2046 522070d6dafSMatthieu Baerts kill -SIGUSR1 $(ip netns pids $ns2) $(ip netns pids $ns1) 523070d6dafSMatthieu Baerts wait 524070d6dafSMatthieu Baerts} 525070d6dafSMatthieu Baerts 52634aa6e3bSGeliang Tangpm_nl_set_limits() 52734aa6e3bSGeliang Tang{ 52834aa6e3bSGeliang Tang local ns=$1 52934aa6e3bSGeliang Tang local addrs=$2 53034aa6e3bSGeliang Tang local subflows=$3 53134aa6e3bSGeliang Tang 53234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 53334aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 53434aa6e3bSGeliang Tang else 53534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 53634aa6e3bSGeliang Tang fi 53734aa6e3bSGeliang Tang} 53834aa6e3bSGeliang Tang 53934aa6e3bSGeliang Tangpm_nl_add_endpoint() 54034aa6e3bSGeliang Tang{ 54134aa6e3bSGeliang Tang local ns=$1 54234aa6e3bSGeliang Tang local addr=$2 5431e777bd8SMatthieu Baerts local flags _flags 5441e777bd8SMatthieu Baerts local port _port 5451e777bd8SMatthieu Baerts local dev _dev 5461e777bd8SMatthieu Baerts local id _id 54734aa6e3bSGeliang Tang local nr=2 54834aa6e3bSGeliang Tang 5491e777bd8SMatthieu Baerts local p 550d8d08302SMatthieu Baerts for p in "${@}" 55134aa6e3bSGeliang Tang do 55234aa6e3bSGeliang Tang if [ $p = "flags" ]; then 55334aa6e3bSGeliang Tang eval _flags=\$"$nr" 554d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 55534aa6e3bSGeliang Tang fi 55634aa6e3bSGeliang Tang if [ $p = "dev" ]; then 55734aa6e3bSGeliang Tang eval _dev=\$"$nr" 558d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 55934aa6e3bSGeliang Tang fi 56034aa6e3bSGeliang Tang if [ $p = "id" ]; then 56134aa6e3bSGeliang Tang eval _id=\$"$nr" 562d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 56334aa6e3bSGeliang Tang fi 56434aa6e3bSGeliang Tang if [ $p = "port" ]; then 56534aa6e3bSGeliang Tang eval _port=\$"$nr" 566d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 56734aa6e3bSGeliang Tang fi 56834aa6e3bSGeliang Tang 569d8d08302SMatthieu Baerts nr=$((nr + 1)) 57034aa6e3bSGeliang Tang done 57134aa6e3bSGeliang Tang 57234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 57334aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 57434aa6e3bSGeliang Tang else 57534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 57634aa6e3bSGeliang Tang fi 57734aa6e3bSGeliang Tang} 57834aa6e3bSGeliang Tang 57934aa6e3bSGeliang Tangpm_nl_del_endpoint() 58034aa6e3bSGeliang Tang{ 58134aa6e3bSGeliang Tang local ns=$1 58234aa6e3bSGeliang Tang local id=$2 58334aa6e3bSGeliang Tang local addr=$3 58434aa6e3bSGeliang Tang 58534aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 58634aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 58734aa6e3bSGeliang Tang else 58834aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 58934aa6e3bSGeliang Tang fi 59034aa6e3bSGeliang Tang} 59134aa6e3bSGeliang Tang 59234aa6e3bSGeliang Tangpm_nl_flush_endpoint() 59334aa6e3bSGeliang Tang{ 59434aa6e3bSGeliang Tang local ns=$1 59534aa6e3bSGeliang Tang 59634aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 59734aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 59834aa6e3bSGeliang Tang else 59934aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 60034aa6e3bSGeliang Tang fi 60134aa6e3bSGeliang Tang} 60234aa6e3bSGeliang Tang 603dda61b3dSGeliang Tangpm_nl_show_endpoints() 604dda61b3dSGeliang Tang{ 605dda61b3dSGeliang Tang local ns=$1 606dda61b3dSGeliang Tang 607dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 608dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 609dda61b3dSGeliang Tang else 610dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 611dda61b3dSGeliang Tang fi 612dda61b3dSGeliang Tang} 613dda61b3dSGeliang Tang 614f0140386SGeliang Tangpm_nl_change_endpoint() 615f0140386SGeliang Tang{ 616f0140386SGeliang Tang local ns=$1 617bccefb76SGeliang Tang local id=$2 618bccefb76SGeliang Tang local flags=$3 619f0140386SGeliang Tang 620f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 621f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 622f0140386SGeliang Tang else 623bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 624f0140386SGeliang Tang fi 625f0140386SGeliang Tang} 626f0140386SGeliang Tang 62769c6ce7bSPaolo Abenipm_nl_check_endpoint() 62869c6ce7bSPaolo Abeni{ 62969c6ce7bSPaolo Abeni local line expected_line 630c7d49c03SMatthieu Baerts local need_title=$1 63169c6ce7bSPaolo Abeni local msg="$2" 63269c6ce7bSPaolo Abeni local ns=$3 63369c6ce7bSPaolo Abeni local addr=$4 63469c6ce7bSPaolo Abeni local _flags="" 63569c6ce7bSPaolo Abeni local flags 63669c6ce7bSPaolo Abeni local _port 63769c6ce7bSPaolo Abeni local port 63869c6ce7bSPaolo Abeni local dev 63969c6ce7bSPaolo Abeni local _id 64069c6ce7bSPaolo Abeni local id 64169c6ce7bSPaolo Abeni 642c7d49c03SMatthieu Baerts if [ "${need_title}" = 1 ]; then 643c7d49c03SMatthieu Baerts printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 64469c6ce7bSPaolo Abeni else 64569c6ce7bSPaolo Abeni printf "%-${nr_blank}s %s" " " "${msg}" 64669c6ce7bSPaolo Abeni fi 64769c6ce7bSPaolo Abeni 64869c6ce7bSPaolo Abeni shift 4 64969c6ce7bSPaolo Abeni while [ -n "$1" ]; do 65069c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 65169c6ce7bSPaolo Abeni _flags=$2 652d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 65369c6ce7bSPaolo Abeni shift 65469c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 655d8d08302SMatthieu Baerts [ -n "$2" ]; dev="dev $1" 65669c6ce7bSPaolo Abeni shift 65769c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 65869c6ce7bSPaolo Abeni _id=$2 659d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 66069c6ce7bSPaolo Abeni shift 66169c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 66269c6ce7bSPaolo Abeni _port=$2 663d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 66469c6ce7bSPaolo Abeni shift 66569c6ce7bSPaolo Abeni fi 66669c6ce7bSPaolo Abeni 66769c6ce7bSPaolo Abeni shift 66869c6ce7bSPaolo Abeni done 66969c6ce7bSPaolo Abeni 67069c6ce7bSPaolo Abeni if [ -z "$id" ]; then 67169c6ce7bSPaolo Abeni echo "[skip] bad test - missing endpoint id" 67269c6ce7bSPaolo Abeni return 67369c6ce7bSPaolo Abeni fi 67469c6ce7bSPaolo Abeni 67569c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 67669c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 67769c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 67869c6ce7bSPaolo Abeni expected_line="$addr" 67969c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 68069c6ce7bSPaolo Abeni expected_line="$expected_line $id" 68169c6ce7bSPaolo Abeni [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" 68269c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 68369c6ce7bSPaolo Abeni [ -n "$port" ] && expected_line="$expected_line $port" 68469c6ce7bSPaolo Abeni else 68569c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 68669c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 68769c6ce7bSPaolo Abeni expected_line="$id" 68869c6ce7bSPaolo Abeni [ -n "$flags" ] && expected_line="$expected_line $flags" 68969c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 69069c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 69169c6ce7bSPaolo Abeni [ -n "$_port" ] && expected_line="$expected_line $_port" 69269c6ce7bSPaolo Abeni fi 69369c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 69469c6ce7bSPaolo Abeni echo "[ ok ]" 69569c6ce7bSPaolo Abeni else 69669c6ce7bSPaolo Abeni echo "[fail] expected '$expected_line' found '$line'" 69739aab882SMatthieu Baerts fail_test 69869c6ce7bSPaolo Abeni fi 69969c6ce7bSPaolo Abeni} 70069c6ce7bSPaolo Abeni 7013469d72fSMatthieu Baertsfilter_tcp_from() 7023469d72fSMatthieu Baerts{ 7033469d72fSMatthieu Baerts local ns="${1}" 7043469d72fSMatthieu Baerts local src="${2}" 7053469d72fSMatthieu Baerts local target="${3}" 7063469d72fSMatthieu Baerts 7073469d72fSMatthieu Baerts ip netns exec "${ns}" iptables -A INPUT -s "${src}" -p tcp -j "${target}" 7083469d72fSMatthieu Baerts} 7093469d72fSMatthieu Baerts 710b08fbf24SPaolo Abenido_transfer() 711b08fbf24SPaolo Abeni{ 7121e777bd8SMatthieu Baerts local listener_ns="$1" 7131e777bd8SMatthieu Baerts local connector_ns="$2" 7141e777bd8SMatthieu Baerts local cl_proto="$3" 7151e777bd8SMatthieu Baerts local srv_proto="$4" 7161e777bd8SMatthieu Baerts local connect_addr="$5" 7171e777bd8SMatthieu Baerts local test_link_fail="$6" 7181e777bd8SMatthieu Baerts local addr_nr_ns1="$7" 7191e777bd8SMatthieu Baerts local addr_nr_ns2="$8" 7201e777bd8SMatthieu Baerts local speed="$9" 7211e777bd8SMatthieu Baerts local sflags="${10}" 722b08fbf24SPaolo Abeni 7231e777bd8SMatthieu Baerts local port=$((10000 + TEST_COUNT - 1)) 7241e777bd8SMatthieu Baerts local cappid 72597040cf9SGeliang Tang local userspace_pm=0 726b08fbf24SPaolo Abeni 727b08fbf24SPaolo Abeni :> "$cout" 728b08fbf24SPaolo Abeni :> "$sout" 729b08fbf24SPaolo Abeni :> "$capout" 730b08fbf24SPaolo Abeni 731b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 7321e777bd8SMatthieu Baerts local capuser 733b08fbf24SPaolo Abeni if [ -z $SUDO_USER ] ; then 734b08fbf24SPaolo Abeni capuser="" 735b08fbf24SPaolo Abeni else 736b08fbf24SPaolo Abeni capuser="-Z $SUDO_USER" 737b08fbf24SPaolo Abeni fi 738b08fbf24SPaolo Abeni 73900587187SFlorian Westphal capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 740b08fbf24SPaolo Abeni 741b08fbf24SPaolo Abeni echo "Capturing traffic for test $TEST_COUNT into $capfile" 742b08fbf24SPaolo Abeni ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 743b08fbf24SPaolo Abeni cappid=$! 744b08fbf24SPaolo Abeni 745b08fbf24SPaolo Abeni sleep 1 746b08fbf24SPaolo Abeni fi 747b08fbf24SPaolo Abeni 748c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 749c2a55e8fSMatthieu Baerts nstat -n 750c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 751c2a55e8fSMatthieu Baerts nstat -n 752c2a55e8fSMatthieu Baerts 753cbfafac4SGeliang Tang local extra_args 7548d014eaaSGeliang Tang if [ $speed = "fast" ]; then 755cbfafac4SGeliang Tang extra_args="-j" 7568da6229bSGeliang Tang elif [ $speed = "slow" ]; then 757cbfafac4SGeliang Tang extra_args="-r 50" 758cbfafac4SGeliang Tang elif [[ $speed = "speed_"* ]]; then 759cbfafac4SGeliang Tang extra_args="-r ${speed:6}" 760dd72b0feSGeliang Tang fi 761dd72b0feSGeliang Tang 76297040cf9SGeliang Tang if [[ "${addr_nr_ns1}" = "userspace_"* ]]; then 76397040cf9SGeliang Tang userspace_pm=1 76497040cf9SGeliang Tang addr_nr_ns1=${addr_nr_ns1:10} 76597040cf9SGeliang Tang fi 76697040cf9SGeliang Tang 767a1c3bdd9SGeliang Tang local flags="subflow" 7686bf41020SPaolo Abeni local extra_cl_args="" 7696bf41020SPaolo Abeni local extra_srv_args="" 7706bf41020SPaolo Abeni local trunc_size="" 77101542c9bSGeliang Tang if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then 7726bf41020SPaolo Abeni if [ ${test_link_fail} -le 1 ]; then 7736bf41020SPaolo Abeni echo "fastclose tests need test_link_fail argument" 7746bf41020SPaolo Abeni fail_test 7756bf41020SPaolo Abeni return 1 7766bf41020SPaolo Abeni fi 7776bf41020SPaolo Abeni 77801542c9bSGeliang Tang # disconnect 7796bf41020SPaolo Abeni trunc_size=${test_link_fail} 7806bf41020SPaolo Abeni local side=${addr_nr_ns2:10} 7816bf41020SPaolo Abeni 7826bf41020SPaolo Abeni if [ ${side} = "client" ]; then 7836bf41020SPaolo Abeni extra_cl_args="-f ${test_link_fail}" 7846bf41020SPaolo Abeni extra_srv_args="-f -1" 7856bf41020SPaolo Abeni elif [ ${side} = "server" ]; then 7866bf41020SPaolo Abeni extra_srv_args="-f ${test_link_fail}" 7876bf41020SPaolo Abeni extra_cl_args="-f -1" 7886bf41020SPaolo Abeni else 7896bf41020SPaolo Abeni echo "wrong/unknown fastclose spec ${side}" 7906bf41020SPaolo Abeni fail_test 7916bf41020SPaolo Abeni return 1 7926bf41020SPaolo Abeni fi 79301542c9bSGeliang Tang addr_nr_ns2=0 7945e986ec4SGeliang Tang elif [[ "${addr_nr_ns2}" = "userspace_"* ]]; then 7955e986ec4SGeliang Tang userspace_pm=1 7965e986ec4SGeliang Tang addr_nr_ns2=${addr_nr_ns2:10} 797a1c3bdd9SGeliang Tang elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then 798a1c3bdd9SGeliang Tang flags="${flags},fullmesh" 799a1c3bdd9SGeliang Tang addr_nr_ns2=${addr_nr_ns2:9} 80001542c9bSGeliang Tang fi 80101542c9bSGeliang Tang 8026bf41020SPaolo Abeni extra_srv_args="$extra_args $extra_srv_args" 80334b572b7SGeliang Tang if [ "$test_link_fail" -gt 1 ];then 8047d1e6f16SPaolo Abeni timeout ${timeout_test} \ 8057d1e6f16SPaolo Abeni ip netns exec ${listener_ns} \ 806cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 807ad349374SPaolo Abeni $extra_srv_args "::" < "$sinfail" > "$sout" & 8087d1e6f16SPaolo Abeni else 8095888a61cSMatthieu Baerts timeout ${timeout_test} \ 8105888a61cSMatthieu Baerts ip netns exec ${listener_ns} \ 811cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 812ad349374SPaolo Abeni $extra_srv_args "::" < "$sin" > "$sout" & 8137d1e6f16SPaolo Abeni fi 8141e777bd8SMatthieu Baerts local spid=$! 815b08fbf24SPaolo Abeni 816327b9a94SPaolo Abeni wait_local_port_listen "${listener_ns}" "${port}" 817b08fbf24SPaolo Abeni 8186bf41020SPaolo Abeni extra_cl_args="$extra_args $extra_cl_args" 8198b819a84SFlorian Westphal if [ "$test_link_fail" -eq 0 ];then 8205888a61cSMatthieu Baerts timeout ${timeout_test} \ 8215888a61cSMatthieu Baerts ip netns exec ${connector_ns} \ 822cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8236bf41020SPaolo Abeni $extra_cl_args $connect_addr < "$cin" > "$cout" & 82434b572b7SGeliang Tang elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then 8257d1e6f16SPaolo Abeni ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 8265888a61cSMatthieu Baerts tee "$cinsent" | \ 8275888a61cSMatthieu Baerts timeout ${timeout_test} \ 8285888a61cSMatthieu Baerts ip netns exec ${connector_ns} \ 829cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8306bf41020SPaolo Abeni $extra_cl_args $connect_addr > "$cout" & 83134b572b7SGeliang Tang else 832d8d08302SMatthieu Baerts tee "$cinsent" < "$cinfail" | \ 83334b572b7SGeliang Tang timeout ${timeout_test} \ 83434b572b7SGeliang Tang ip netns exec ${connector_ns} \ 83534b572b7SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8366bf41020SPaolo Abeni $extra_cl_args $connect_addr > "$cout" & 8378b819a84SFlorian Westphal fi 8381e777bd8SMatthieu Baerts local cpid=$! 839b08fbf24SPaolo Abeni 840327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 841327b9a94SPaolo Abeni # do endpoint manipulation 842d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 843d8d08302SMatthieu Baerts sleep 1 844d8d08302SMatthieu Baerts fi 845327b9a94SPaolo Abeni 8466208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8471e777bd8SMatthieu Baerts local counter=2 848d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 84997040cf9SGeliang Tang local id=10 85097040cf9SGeliang Tang local tk 8516208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8526208fd82SGeliang Tang local addr 8536208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 8546208fd82SGeliang Tang addr="dead:beef:$counter::1" 8556208fd82SGeliang Tang else 8566208fd82SGeliang Tang addr="10.0.$counter.1" 8576208fd82SGeliang Tang fi 85897040cf9SGeliang Tang if [ $userspace_pm -eq 0 ]; then 85934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 86097040cf9SGeliang Tang else 8617dff74f5SGeliang Tang tk=$(grep "type:1," "$evts_ns1" | 8627dff74f5SGeliang Tang sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q') 86397040cf9SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id 86497040cf9SGeliang Tang sleep 1 86548d73f60SGeliang Tang sp=$(grep "type:10" "$evts_ns1" | 86648d73f60SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 86748d73f60SGeliang Tang da=$(grep "type:10" "$evts_ns1" | 86848d73f60SGeliang Tang sed -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 86948d73f60SGeliang Tang dp=$(grep "type:10" "$evts_ns1" | 87048d73f60SGeliang Tang sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q') 87197040cf9SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id 87248d73f60SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl dsf lip "::ffff:$addr" \ 87348d73f60SGeliang Tang lport $sp rip $da rport $dp token $tk 87497040cf9SGeliang Tang fi 87597040cf9SGeliang Tang 876d8d08302SMatthieu Baerts counter=$((counter + 1)) 877d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 87897040cf9SGeliang Tang id=$((id + 1)) 8796208fd82SGeliang Tang done 8806208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 881d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 8826fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 8831e777bd8SMatthieu Baerts local counter=0 8841e777bd8SMatthieu Baerts local line 885d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 886d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 887dda61b3dSGeliang Tang local arr=($line) 888dda61b3dSGeliang Tang local nr=0 889dda61b3dSGeliang Tang 8901e777bd8SMatthieu Baerts local i 891d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 892dda61b3dSGeliang Tang if [ $i = "id" ]; then 893dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 894dda61b3dSGeliang Tang break 895dda61b3dSGeliang Tang fi 896dda61b3dSGeliang Tang id=${arr[$nr+1]} 897327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 89834aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 899327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 900d8d08302SMatthieu Baerts counter=$((counter + 1)) 901f87744adSGeliang Tang fi 902d8d08302SMatthieu Baerts nr=$((nr + 1)) 903dda61b3dSGeliang Tang done 904dda61b3dSGeliang Tang done 9055e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 90634aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9075e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 90834aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9096fe4ccdcSGeliang Tang fi 910dd72b0feSGeliang Tang fi 911dd72b0feSGeliang Tang 912327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 913327b9a94SPaolo Abeni # some time to created them 914d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 915327b9a94SPaolo Abeni 9166208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 917d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9181e777bd8SMatthieu Baerts local counter=3 9195e986ec4SGeliang Tang local id=20 9205e986ec4SGeliang Tang local tk da dp sp 9216208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9226208fd82SGeliang Tang local addr 9236208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 9246208fd82SGeliang Tang addr="dead:beef:$counter::2" 9256208fd82SGeliang Tang else 9266208fd82SGeliang Tang addr="10.0.$counter.2" 9276208fd82SGeliang Tang fi 9285e986ec4SGeliang Tang if [ $userspace_pm -eq 0 ]; then 92934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 9305e986ec4SGeliang Tang else 9315e986ec4SGeliang Tang tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 9325e986ec4SGeliang Tang da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2") 9335e986ec4SGeliang Tang dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 9345e986ec4SGeliang Tang ip netns exec ${connector_ns} ./pm_nl_ctl csf lip $addr lid $id \ 9355e986ec4SGeliang Tang rip $da rport $dp token $tk 9365e986ec4SGeliang Tang sleep 1 9375e986ec4SGeliang Tang sp=$(grep "type:10" "$evts_ns2" | 9385e986ec4SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 939*6c160b63SGeliang Tang ip netns exec ${connector_ns} ./pm_nl_ctl rem token $tk id $id 9405e986ec4SGeliang Tang ip netns exec ${connector_ns} ./pm_nl_ctl dsf lip $addr lport $sp \ 9415e986ec4SGeliang Tang rip $da rport $dp token $tk 9425e986ec4SGeliang Tang fi 943d8d08302SMatthieu Baerts counter=$((counter + 1)) 944d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9455e986ec4SGeliang Tang id=$((id + 1)) 9466208fd82SGeliang Tang done 9476208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 948d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9496fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9501e777bd8SMatthieu Baerts local counter=0 9511e777bd8SMatthieu Baerts local line 952d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 953d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 954dda61b3dSGeliang Tang local arr=($line) 955dda61b3dSGeliang Tang local nr=0 956dda61b3dSGeliang Tang 9571e777bd8SMatthieu Baerts local i 958d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 959dda61b3dSGeliang Tang if [ $i = "id" ]; then 960dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 961dda61b3dSGeliang Tang break 962dda61b3dSGeliang Tang fi 9631e777bd8SMatthieu Baerts local id rm_addr 964dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 965dda61b3dSGeliang Tang # complete 966dda61b3dSGeliang Tang id=${arr[$nr+1]} 967327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 96834aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 969327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 970d8d08302SMatthieu Baerts counter=$((counter + 1)) 971f87744adSGeliang Tang fi 972d8d08302SMatthieu Baerts nr=$((nr + 1)) 973dda61b3dSGeliang Tang done 974dda61b3dSGeliang Tang done 9755e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 97634aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9775e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9785e287fe7SGeliang Tang local addr 9795e287fe7SGeliang Tang if is_v6 "${connect_addr}"; then 9805e287fe7SGeliang Tang addr="dead:beef:1::2" 9815e287fe7SGeliang Tang else 9825e287fe7SGeliang Tang addr="10.0.1.2" 9835e287fe7SGeliang Tang fi 98434aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9856fe4ccdcSGeliang Tang fi 986dd72b0feSGeliang Tang fi 987dd72b0feSGeliang Tang 988d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 989718eb44eSGeliang Tang sleep 1 9901e777bd8SMatthieu Baerts 9911e777bd8SMatthieu Baerts local netns 992718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9931e777bd8SMatthieu Baerts local line 994d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 995d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 99633397b83SGeliang Tang local arr=($line) 997bccefb76SGeliang Tang local nr=0 998f0140386SGeliang Tang local id 99933397b83SGeliang Tang 10001e777bd8SMatthieu Baerts local i 1001d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 1002bccefb76SGeliang Tang if [ $i = "id" ]; then 1003bccefb76SGeliang Tang id=${arr[$nr+1]} 1004718eb44eSGeliang Tang fi 1005d8d08302SMatthieu Baerts nr=$((nr + 1)) 100633397b83SGeliang Tang done 1007bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 100833397b83SGeliang Tang done 1009718eb44eSGeliang Tang done 1010718eb44eSGeliang Tang fi 1011718eb44eSGeliang Tang 1012b08fbf24SPaolo Abeni wait $cpid 10131e777bd8SMatthieu Baerts local retc=$? 1014b08fbf24SPaolo Abeni wait $spid 10151e777bd8SMatthieu Baerts local rets=$? 1016b08fbf24SPaolo Abeni 1017b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1018b08fbf24SPaolo Abeni sleep 1 1019b08fbf24SPaolo Abeni kill $cappid 1020b08fbf24SPaolo Abeni fi 1021b08fbf24SPaolo Abeni 1022c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1023c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1024c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1025c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1026c2a55e8fSMatthieu Baerts 1027b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 1028b08fbf24SPaolo Abeni echo " client exit code $retc, server $rets" 1>&2 10298b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1030c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1031c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 10328b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1033c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1034c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1035b08fbf24SPaolo Abeni 1036b08fbf24SPaolo Abeni cat "$capout" 103739aab882SMatthieu Baerts fail_test 1038b08fbf24SPaolo Abeni return 1 1039b08fbf24SPaolo Abeni fi 1040b08fbf24SPaolo Abeni 104134b572b7SGeliang Tang if [ "$test_link_fail" -gt 1 ];then 10426bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 10437d1e6f16SPaolo Abeni else 10446bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 10457d1e6f16SPaolo Abeni fi 1046b08fbf24SPaolo Abeni retc=$? 10478b819a84SFlorian Westphal if [ "$test_link_fail" -eq 0 ];then 10486bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 10498b819a84SFlorian Westphal else 10506bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 10518b819a84SFlorian Westphal fi 1052b08fbf24SPaolo Abeni rets=$? 1053b08fbf24SPaolo Abeni 1054b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1055b08fbf24SPaolo Abeni cat "$capout" 1056b08fbf24SPaolo Abeni return 0 1057b08fbf24SPaolo Abeni fi 1058b08fbf24SPaolo Abeni 1059b08fbf24SPaolo Abeni cat "$capout" 1060b08fbf24SPaolo Abeni return 1 1061b08fbf24SPaolo Abeni} 1062b08fbf24SPaolo Abeni 1063b08fbf24SPaolo Abenimake_file() 1064b08fbf24SPaolo Abeni{ 10651e777bd8SMatthieu Baerts local name=$1 10661e777bd8SMatthieu Baerts local who=$2 10671e777bd8SMatthieu Baerts local size=$3 1068b08fbf24SPaolo Abeni 10698b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1070b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1071b08fbf24SPaolo Abeni 10728b819a84SFlorian Westphal echo "Created $name (size $size KB) containing data sent by $who" 1073b08fbf24SPaolo Abeni} 1074b08fbf24SPaolo Abeni 1075b08fbf24SPaolo Abenirun_tests() 1076b08fbf24SPaolo Abeni{ 10771e777bd8SMatthieu Baerts local listener_ns="$1" 10781e777bd8SMatthieu Baerts local connector_ns="$2" 10791e777bd8SMatthieu Baerts local connect_addr="$3" 10801e777bd8SMatthieu Baerts local test_linkfail="${4:-0}" 10811e777bd8SMatthieu Baerts local addr_nr_ns1="${5:-0}" 10821e777bd8SMatthieu Baerts local addr_nr_ns2="${6:-0}" 10831e777bd8SMatthieu Baerts local speed="${7:-fast}" 10841e777bd8SMatthieu Baerts local sflags="${8:-""}" 10851e777bd8SMatthieu Baerts 10861e777bd8SMatthieu Baerts local size 10878b819a84SFlorian Westphal 108834b572b7SGeliang Tang # The values above 2 are reused to make test files 108934b572b7SGeliang Tang # with the given sizes (KB) 109034b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 109134b572b7SGeliang Tang size=$test_linkfail 109234b572b7SGeliang Tang 109334b572b7SGeliang Tang if [ -z "$cinfail" ]; then 109434b572b7SGeliang Tang cinfail=$(mktemp) 109534b572b7SGeliang Tang fi 109634b572b7SGeliang Tang make_file "$cinfail" "client" $size 10977d1e6f16SPaolo Abeni # create the input file for the failure test when 10987d1e6f16SPaolo Abeni # the first failure test run 1099d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 11007d1e6f16SPaolo Abeni # the client file must be considerably larger 11017d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 11027d1e6f16SPaolo Abeni # link utilization will be not predicable 11037d1e6f16SPaolo Abeni size=$((RANDOM%2)) 11048b819a84SFlorian Westphal size=$((size+1)) 11057d1e6f16SPaolo Abeni size=$((size*8192)) 1106d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 11078b819a84SFlorian Westphal 11087d1e6f16SPaolo Abeni cinfail=$(mktemp) 11097d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 11107d1e6f16SPaolo Abeni fi 11117d1e6f16SPaolo Abeni 111234b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 111334b572b7SGeliang Tang size=$test_linkfail 111434b572b7SGeliang Tang 111534b572b7SGeliang Tang if [ -z "$sinfail" ]; then 111634b572b7SGeliang Tang sinfail=$(mktemp) 111734b572b7SGeliang Tang fi 111834b572b7SGeliang Tang make_file "$sinfail" "server" $size 1119d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 11207d1e6f16SPaolo Abeni size=$((RANDOM%16)) 11217d1e6f16SPaolo Abeni size=$((size+1)) 11227d1e6f16SPaolo Abeni size=$((size*2048)) 11237d1e6f16SPaolo Abeni 11247d1e6f16SPaolo Abeni sinfail=$(mktemp) 11257d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 11268b819a84SFlorian Westphal fi 1127b08fbf24SPaolo Abeni 11288d014eaaSGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \ 11296a0653b9SGeliang Tang ${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${sflags} 1130b08fbf24SPaolo Abeni} 1131b08fbf24SPaolo Abeni 1132327b9a94SPaolo Abenidump_stats() 1133327b9a94SPaolo Abeni{ 1134327b9a94SPaolo Abeni echo Server ns stats 1135327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1136327b9a94SPaolo Abeni echo Client ns stats 1137327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1138327b9a94SPaolo Abeni} 1139327b9a94SPaolo Abeni 1140af66d3e1SGeliang Tangchk_csum_nr() 1141af66d3e1SGeliang Tang{ 11423c082695SGeliang Tang local csum_ns1=${1:-0} 11433c082695SGeliang Tang local csum_ns2=${2:-0} 1144af66d3e1SGeliang Tang local count 1145af66d3e1SGeliang Tang local dump_stats 114653f368bfSGeliang Tang local extra_msg="" 114726516e10SGeliang Tang local allow_multi_errors_ns1=0 114826516e10SGeliang Tang local allow_multi_errors_ns2=0 114926516e10SGeliang Tang 115026516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 115126516e10SGeliang Tang allow_multi_errors_ns1=1 115226516e10SGeliang Tang csum_ns1=${csum_ns1:1} 115326516e10SGeliang Tang fi 115426516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 115526516e10SGeliang Tang allow_multi_errors_ns2=1 115626516e10SGeliang Tang csum_ns2=${csum_ns2:1} 115726516e10SGeliang Tang fi 1158af66d3e1SGeliang Tang 11593c082695SGeliang Tang printf "%-${nr_blank}s %s" " " "sum" 11604bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1161af66d3e1SGeliang Tang [ -z "$count" ] && count=0 116253f368bfSGeliang Tang if [ "$count" != "$csum_ns1" ]; then 116353f368bfSGeliang Tang extra_msg="$extra_msg ns1=$count" 116453f368bfSGeliang Tang fi 1165d8d08302SMatthieu Baerts if { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1166d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 116726516e10SGeliang Tang echo "[fail] got $count data checksum error[s] expected $csum_ns1" 116839aab882SMatthieu Baerts fail_test 1169af66d3e1SGeliang Tang dump_stats=1 1170af66d3e1SGeliang Tang else 1171af66d3e1SGeliang Tang echo -n "[ ok ]" 1172af66d3e1SGeliang Tang fi 1173af66d3e1SGeliang Tang echo -n " - csum " 11744bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1175af66d3e1SGeliang Tang [ -z "$count" ] && count=0 117653f368bfSGeliang Tang if [ "$count" != "$csum_ns2" ]; then 117753f368bfSGeliang Tang extra_msg="$extra_msg ns2=$count" 117853f368bfSGeliang Tang fi 1179d8d08302SMatthieu Baerts if { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1180d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 118126516e10SGeliang Tang echo "[fail] got $count data checksum error[s] expected $csum_ns2" 118239aab882SMatthieu Baerts fail_test 1183af66d3e1SGeliang Tang dump_stats=1 1184af66d3e1SGeliang Tang else 118553f368bfSGeliang Tang echo -n "[ ok ]" 1186af66d3e1SGeliang Tang fi 1187327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 118853f368bfSGeliang Tang 118953f368bfSGeliang Tang echo "$extra_msg" 1190af66d3e1SGeliang Tang} 1191af66d3e1SGeliang Tang 11926bb3ab49SGeliang Tangchk_fail_nr() 11936bb3ab49SGeliang Tang{ 119426516e10SGeliang Tang local fail_tx=$1 119526516e10SGeliang Tang local fail_rx=$2 11961f7d325fSGeliang Tang local ns_invert=${3:-""} 11976bb3ab49SGeliang Tang local count 11986bb3ab49SGeliang Tang local dump_stats 11991f7d325fSGeliang Tang local ns_tx=$ns1 12001f7d325fSGeliang Tang local ns_rx=$ns2 12011f7d325fSGeliang Tang local extra_msg="" 12021f7d325fSGeliang Tang local allow_tx_lost=0 12031f7d325fSGeliang Tang local allow_rx_lost=0 12041f7d325fSGeliang Tang 12051f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 12061f7d325fSGeliang Tang ns_tx=$ns2 12071f7d325fSGeliang Tang ns_rx=$ns1 12081f7d325fSGeliang Tang extra_msg=" invert" 12091f7d325fSGeliang Tang fi 12101f7d325fSGeliang Tang 12111f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 12121f7d325fSGeliang Tang allow_tx_lost=1 12131f7d325fSGeliang Tang fail_tx=${fail_tx:1} 12141f7d325fSGeliang Tang fi 12151f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 12161f7d325fSGeliang Tang allow_rx_lost=1 12171f7d325fSGeliang Tang fail_rx=${fail_rx:1} 12181f7d325fSGeliang Tang fi 12196bb3ab49SGeliang Tang 12209a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "ftx" 12211f7d325fSGeliang Tang count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}') 12226bb3ab49SGeliang Tang [ -z "$count" ] && count=0 122326516e10SGeliang Tang if [ "$count" != "$fail_tx" ]; then 12241f7d325fSGeliang Tang extra_msg="$extra_msg,tx=$count" 12251f7d325fSGeliang Tang fi 12261f7d325fSGeliang Tang if { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 12271f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 122826516e10SGeliang Tang echo "[fail] got $count MP_FAIL[s] TX expected $fail_tx" 122939aab882SMatthieu Baerts fail_test 12306bb3ab49SGeliang Tang dump_stats=1 12316bb3ab49SGeliang Tang else 12326bb3ab49SGeliang Tang echo -n "[ ok ]" 12336bb3ab49SGeliang Tang fi 12346bb3ab49SGeliang Tang 123526516e10SGeliang Tang echo -n " - failrx" 12361f7d325fSGeliang Tang count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}') 12376bb3ab49SGeliang Tang [ -z "$count" ] && count=0 123826516e10SGeliang Tang if [ "$count" != "$fail_rx" ]; then 12391f7d325fSGeliang Tang extra_msg="$extra_msg,rx=$count" 12401f7d325fSGeliang Tang fi 12411f7d325fSGeliang Tang if { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 12421f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 124326516e10SGeliang Tang echo "[fail] got $count MP_FAIL[s] RX expected $fail_rx" 124439aab882SMatthieu Baerts fail_test 12456bb3ab49SGeliang Tang dump_stats=1 12466bb3ab49SGeliang Tang else 12471f7d325fSGeliang Tang echo -n "[ ok ]" 12486bb3ab49SGeliang Tang fi 12496bb3ab49SGeliang Tang 1250327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 12511f7d325fSGeliang Tang 12521f7d325fSGeliang Tang echo "$extra_msg" 12536bb3ab49SGeliang Tang} 12546bb3ab49SGeliang Tang 1255e8e947efSGeliang Tangchk_fclose_nr() 1256e8e947efSGeliang Tang{ 1257e8e947efSGeliang Tang local fclose_tx=$1 1258e8e947efSGeliang Tang local fclose_rx=$2 12596bf41020SPaolo Abeni local ns_invert=$3 1260e8e947efSGeliang Tang local count 1261e8e947efSGeliang Tang local dump_stats 12626bf41020SPaolo Abeni local ns_tx=$ns2 12636bf41020SPaolo Abeni local ns_rx=$ns1 12646bf41020SPaolo Abeni local extra_msg=" " 12656bf41020SPaolo Abeni 12666bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 12676bf41020SPaolo Abeni ns_tx=$ns1 12686bf41020SPaolo Abeni ns_rx=$ns2 12696bf41020SPaolo Abeni extra_msg=${extra_msg}"invert" 12706bf41020SPaolo Abeni fi 1271e8e947efSGeliang Tang 1272e8e947efSGeliang Tang printf "%-${nr_blank}s %s" " " "ctx" 12736bf41020SPaolo Abeni count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFastcloseTx | awk '{print $2}') 1274e8e947efSGeliang Tang [ -z "$count" ] && count=0 12756bf41020SPaolo Abeni [ "$count" != "$fclose_tx" ] && extra_msg="$extra_msg,tx=$count" 1276e8e947efSGeliang Tang if [ "$count" != "$fclose_tx" ]; then 1277e8e947efSGeliang Tang echo "[fail] got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 127839aab882SMatthieu Baerts fail_test 1279e8e947efSGeliang Tang dump_stats=1 1280e8e947efSGeliang Tang else 1281e8e947efSGeliang Tang echo -n "[ ok ]" 1282e8e947efSGeliang Tang fi 1283e8e947efSGeliang Tang 1284e8e947efSGeliang Tang echo -n " - fclzrx" 12856bf41020SPaolo Abeni count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFastcloseRx | awk '{print $2}') 1286e8e947efSGeliang Tang [ -z "$count" ] && count=0 12876bf41020SPaolo Abeni [ "$count" != "$fclose_rx" ] && extra_msg="$extra_msg,rx=$count" 1288e8e947efSGeliang Tang if [ "$count" != "$fclose_rx" ]; then 1289e8e947efSGeliang Tang echo "[fail] got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 129039aab882SMatthieu Baerts fail_test 1291e8e947efSGeliang Tang dump_stats=1 1292e8e947efSGeliang Tang else 12936bf41020SPaolo Abeni echo -n "[ ok ]" 1294e8e947efSGeliang Tang fi 1295e8e947efSGeliang Tang 1296e8e947efSGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 12976bf41020SPaolo Abeni 12986bf41020SPaolo Abeni echo "$extra_msg" 1299e8e947efSGeliang Tang} 1300e8e947efSGeliang Tang 1301922fd2b3SGeliang Tangchk_rst_nr() 1302922fd2b3SGeliang Tang{ 1303922fd2b3SGeliang Tang local rst_tx=$1 1304922fd2b3SGeliang Tang local rst_rx=$2 1305922fd2b3SGeliang Tang local ns_invert=${3:-""} 1306922fd2b3SGeliang Tang local count 1307922fd2b3SGeliang Tang local dump_stats 1308922fd2b3SGeliang Tang local ns_tx=$ns1 1309922fd2b3SGeliang Tang local ns_rx=$ns2 1310922fd2b3SGeliang Tang local extra_msg="" 1311922fd2b3SGeliang Tang 1312922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1313922fd2b3SGeliang Tang ns_tx=$ns2 1314922fd2b3SGeliang Tang ns_rx=$ns1 1315922fd2b3SGeliang Tang extra_msg=" invert" 1316922fd2b3SGeliang Tang fi 1317922fd2b3SGeliang Tang 1318922fd2b3SGeliang Tang printf "%-${nr_blank}s %s" " " "rtx" 1319922fd2b3SGeliang Tang count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPRstTx | awk '{print $2}') 1320922fd2b3SGeliang Tang [ -z "$count" ] && count=0 13216bf41020SPaolo Abeni if [ $count -lt $rst_tx ]; then 1322922fd2b3SGeliang Tang echo "[fail] got $count MP_RST[s] TX expected $rst_tx" 132339aab882SMatthieu Baerts fail_test 1324922fd2b3SGeliang Tang dump_stats=1 1325922fd2b3SGeliang Tang else 1326922fd2b3SGeliang Tang echo -n "[ ok ]" 1327922fd2b3SGeliang Tang fi 1328922fd2b3SGeliang Tang 1329922fd2b3SGeliang Tang echo -n " - rstrx " 1330922fd2b3SGeliang Tang count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPRstRx | awk '{print $2}') 1331922fd2b3SGeliang Tang [ -z "$count" ] && count=0 13326bf41020SPaolo Abeni if [ "$count" -lt "$rst_rx" ]; then 1333922fd2b3SGeliang Tang echo "[fail] got $count MP_RST[s] RX expected $rst_rx" 133439aab882SMatthieu Baerts fail_test 1335922fd2b3SGeliang Tang dump_stats=1 1336922fd2b3SGeliang Tang else 1337922fd2b3SGeliang Tang echo -n "[ ok ]" 1338922fd2b3SGeliang Tang fi 1339922fd2b3SGeliang Tang 1340922fd2b3SGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 1341922fd2b3SGeliang Tang 1342922fd2b3SGeliang Tang echo "$extra_msg" 1343922fd2b3SGeliang Tang} 1344922fd2b3SGeliang Tang 13458bd03be3SGeliang Tangchk_infi_nr() 13468bd03be3SGeliang Tang{ 13478bd03be3SGeliang Tang local infi_tx=$1 13488bd03be3SGeliang Tang local infi_rx=$2 13498bd03be3SGeliang Tang local count 13508bd03be3SGeliang Tang local dump_stats 13518bd03be3SGeliang Tang 13528bd03be3SGeliang Tang printf "%-${nr_blank}s %s" " " "itx" 13538bd03be3SGeliang Tang count=$(ip netns exec $ns2 nstat -as | grep InfiniteMapTx | awk '{print $2}') 13548bd03be3SGeliang Tang [ -z "$count" ] && count=0 13558bd03be3SGeliang Tang if [ "$count" != "$infi_tx" ]; then 13568bd03be3SGeliang Tang echo "[fail] got $count infinite map[s] TX expected $infi_tx" 13578bd03be3SGeliang Tang fail_test 13588bd03be3SGeliang Tang dump_stats=1 13598bd03be3SGeliang Tang else 13608bd03be3SGeliang Tang echo -n "[ ok ]" 13618bd03be3SGeliang Tang fi 13628bd03be3SGeliang Tang 13638bd03be3SGeliang Tang echo -n " - infirx" 13648bd03be3SGeliang Tang count=$(ip netns exec $ns1 nstat -as | grep InfiniteMapRx | awk '{print $2}') 13658bd03be3SGeliang Tang [ -z "$count" ] && count=0 13668bd03be3SGeliang Tang if [ "$count" != "$infi_rx" ]; then 13678bd03be3SGeliang Tang echo "[fail] got $count infinite map[s] RX expected $infi_rx" 13688bd03be3SGeliang Tang fail_test 13698bd03be3SGeliang Tang dump_stats=1 13708bd03be3SGeliang Tang else 13718bd03be3SGeliang Tang echo "[ ok ]" 13728bd03be3SGeliang Tang fi 13738bd03be3SGeliang Tang 13748bd03be3SGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 13758bd03be3SGeliang Tang} 13768bd03be3SGeliang Tang 1377b08fbf24SPaolo Abenichk_join_nr() 1378b08fbf24SPaolo Abeni{ 1379c7d49c03SMatthieu Baerts local syn_nr=$1 1380c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1381c7d49c03SMatthieu Baerts local ack_nr=$3 1382c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1383c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1384c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1385c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 13868bd03be3SGeliang Tang local infi_nr=${8:-0} 13878bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1388b08fbf24SPaolo Abeni local count 1389b08fbf24SPaolo Abeni local dump_stats 1390e35f885bSPaolo Abeni local with_cookie 1391c7d49c03SMatthieu Baerts local title="${TEST_NAME}" 1392b08fbf24SPaolo Abeni 1393c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 1394c7d49c03SMatthieu Baerts title+=": ${corrupted_pkts} corrupted pkts" 1395c7d49c03SMatthieu Baerts fi 1396c7d49c03SMatthieu Baerts 1397c7d49c03SMatthieu Baerts printf "%03u %-36s %s" "${TEST_COUNT}" "${title}" "syn" 13984bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}') 1399b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1400b08fbf24SPaolo Abeni if [ "$count" != "$syn_nr" ]; then 1401b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] syn expected $syn_nr" 140239aab882SMatthieu Baerts fail_test 1403b08fbf24SPaolo Abeni dump_stats=1 1404b08fbf24SPaolo Abeni else 1405b08fbf24SPaolo Abeni echo -n "[ ok ]" 1406b08fbf24SPaolo Abeni fi 1407b08fbf24SPaolo Abeni 1408b08fbf24SPaolo Abeni echo -n " - synack" 14094bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 14104bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}') 1411b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1412b08fbf24SPaolo Abeni if [ "$count" != "$syn_ack_nr" ]; then 1413e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1414e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1415e35f885bSPaolo Abeni # the subflow creation 1416e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 1417e35f885bSPaolo Abeni echo -n "[ ok ]" 1418e35f885bSPaolo Abeni else 1419b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr" 142039aab882SMatthieu Baerts fail_test 1421b08fbf24SPaolo Abeni dump_stats=1 1422e35f885bSPaolo Abeni fi 1423b08fbf24SPaolo Abeni else 1424b08fbf24SPaolo Abeni echo -n "[ ok ]" 1425b08fbf24SPaolo Abeni fi 1426b08fbf24SPaolo Abeni 1427b08fbf24SPaolo Abeni echo -n " - ack" 14284bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}') 1429b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1430b08fbf24SPaolo Abeni if [ "$count" != "$ack_nr" ]; then 1431b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] ack expected $ack_nr" 143239aab882SMatthieu Baerts fail_test 1433b08fbf24SPaolo Abeni dump_stats=1 1434b08fbf24SPaolo Abeni else 1435b08fbf24SPaolo Abeni echo "[ ok ]" 1436b08fbf24SPaolo Abeni fi 1437327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1438b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 14393c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 144026516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 144126516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 14428bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1443af66d3e1SGeliang Tang fi 1444b08fbf24SPaolo Abeni} 1445b08fbf24SPaolo Abeni 14467d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 14477d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 14487d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 14497d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 14507d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 14517d1e6f16SPaolo Abenichk_stale_nr() 14527d1e6f16SPaolo Abeni{ 14537d1e6f16SPaolo Abeni local ns=$1 14547d1e6f16SPaolo Abeni local stale_min=$2 14557d1e6f16SPaolo Abeni local stale_max=$3 14567d1e6f16SPaolo Abeni local stale_delta=$4 14577d1e6f16SPaolo Abeni local dump_stats 14587d1e6f16SPaolo Abeni local stale_nr 14597d1e6f16SPaolo Abeni local recover_nr 14607d1e6f16SPaolo Abeni 14619a0a9367SGeliang Tang printf "%-${nr_blank}s %-18s" " " "stale" 14624bfadd71SMatthieu Baerts stale_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}') 14637d1e6f16SPaolo Abeni [ -z "$stale_nr" ] && stale_nr=0 14644bfadd71SMatthieu Baerts recover_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}') 14657d1e6f16SPaolo Abeni [ -z "$recover_nr" ] && recover_nr=0 14667d1e6f16SPaolo Abeni 14677d1e6f16SPaolo Abeni if [ $stale_nr -lt $stale_min ] || 1468d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1469d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 14707d1e6f16SPaolo Abeni echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \ 14717d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 14727d1e6f16SPaolo Abeni " stale-recover delta $stale_delta " 147339aab882SMatthieu Baerts fail_test 14747d1e6f16SPaolo Abeni dump_stats=1 14757d1e6f16SPaolo Abeni else 14767d1e6f16SPaolo Abeni echo "[ ok ]" 14777d1e6f16SPaolo Abeni fi 14787d1e6f16SPaolo Abeni 14797d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 14807d1e6f16SPaolo Abeni echo $ns stats 14817d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 14827d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 14837d1e6f16SPaolo Abeni fi 14847d1e6f16SPaolo Abeni} 14857d1e6f16SPaolo Abeni 1486be613160SGeliang Tangchk_add_nr() 1487be613160SGeliang Tang{ 1488be613160SGeliang Tang local add_nr=$1 1489be613160SGeliang Tang local echo_nr=$2 14908a127bf6SGeliang Tang local port_nr=${3:-0} 14918a127bf6SGeliang Tang local syn_nr=${4:-$port_nr} 14928a127bf6SGeliang Tang local syn_ack_nr=${5:-$port_nr} 14938a127bf6SGeliang Tang local ack_nr=${6:-$port_nr} 14948a127bf6SGeliang Tang local mis_syn_nr=${7:-0} 14958a127bf6SGeliang Tang local mis_ack_nr=${8:-0} 1496be613160SGeliang Tang local count 1497be613160SGeliang Tang local dump_stats 14986ef84b15SPaolo Abeni local timeout 14996ef84b15SPaolo Abeni 15004bfadd71SMatthieu Baerts timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1501be613160SGeliang Tang 15029a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "add" 15034bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as MPTcpExtAddAddr | grep MPTcpExtAddAddr | awk '{print $2}') 1504be613160SGeliang Tang [ -z "$count" ] && count=0 15056ef84b15SPaolo Abeni 15066ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15076ef84b15SPaolo Abeni # add addrs options, due to retransmissions 1508d8d08302SMatthieu Baerts if [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 1509be613160SGeliang Tang echo "[fail] got $count ADD_ADDR[s] expected $add_nr" 151039aab882SMatthieu Baerts fail_test 1511be613160SGeliang Tang dump_stats=1 1512be613160SGeliang Tang else 1513be613160SGeliang Tang echo -n "[ ok ]" 1514be613160SGeliang Tang fi 1515be613160SGeliang Tang 1516be613160SGeliang Tang echo -n " - echo " 15174bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}') 1518be613160SGeliang Tang [ -z "$count" ] && count=0 1519be613160SGeliang Tang if [ "$count" != "$echo_nr" ]; then 1520be613160SGeliang Tang echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr" 152139aab882SMatthieu Baerts fail_test 1522be613160SGeliang Tang dump_stats=1 1523be613160SGeliang Tang else 15248a127bf6SGeliang Tang echo -n "[ ok ]" 15258a127bf6SGeliang Tang fi 15268a127bf6SGeliang Tang 15278a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 15288a127bf6SGeliang Tang echo -n " - pt " 15294bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}') 15308a127bf6SGeliang Tang [ -z "$count" ] && count=0 15318a127bf6SGeliang Tang if [ "$count" != "$port_nr" ]; then 15328a127bf6SGeliang Tang echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" 153339aab882SMatthieu Baerts fail_test 15348a127bf6SGeliang Tang dump_stats=1 15358a127bf6SGeliang Tang else 1536be613160SGeliang Tang echo "[ ok ]" 1537be613160SGeliang Tang fi 1538be613160SGeliang Tang 15399a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "syn" 15404bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | 15414bfadd71SMatthieu Baerts awk '{print $2}') 15428a127bf6SGeliang Tang [ -z "$count" ] && count=0 15438a127bf6SGeliang Tang if [ "$count" != "$syn_nr" ]; then 15448a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] syn with a different \ 15458a127bf6SGeliang Tang port-number expected $syn_nr" 154639aab882SMatthieu Baerts fail_test 15478a127bf6SGeliang Tang dump_stats=1 15488a127bf6SGeliang Tang else 15498a127bf6SGeliang Tang echo -n "[ ok ]" 15508a127bf6SGeliang Tang fi 15518a127bf6SGeliang Tang 15528a127bf6SGeliang Tang echo -n " - synack" 15534bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | 15544bfadd71SMatthieu Baerts awk '{print $2}') 15558a127bf6SGeliang Tang [ -z "$count" ] && count=0 15568a127bf6SGeliang Tang if [ "$count" != "$syn_ack_nr" ]; then 15578a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] synack with a different \ 15588a127bf6SGeliang Tang port-number expected $syn_ack_nr" 155939aab882SMatthieu Baerts fail_test 15608a127bf6SGeliang Tang dump_stats=1 15618a127bf6SGeliang Tang else 15628a127bf6SGeliang Tang echo -n "[ ok ]" 15638a127bf6SGeliang Tang fi 15648a127bf6SGeliang Tang 15658a127bf6SGeliang Tang echo -n " - ack" 15664bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | 15674bfadd71SMatthieu Baerts awk '{print $2}') 15688a127bf6SGeliang Tang [ -z "$count" ] && count=0 15698a127bf6SGeliang Tang if [ "$count" != "$ack_nr" ]; then 15708a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] ack with a different \ 15718a127bf6SGeliang Tang port-number expected $ack_nr" 157239aab882SMatthieu Baerts fail_test 15738a127bf6SGeliang Tang dump_stats=1 15748a127bf6SGeliang Tang else 15758a127bf6SGeliang Tang echo "[ ok ]" 15768a127bf6SGeliang Tang fi 15778a127bf6SGeliang Tang 15789a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "syn" 15794bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | 15804bfadd71SMatthieu Baerts awk '{print $2}') 15818a127bf6SGeliang Tang [ -z "$count" ] && count=0 15828a127bf6SGeliang Tang if [ "$count" != "$mis_syn_nr" ]; then 15838a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] syn with a mismatched \ 15848a127bf6SGeliang Tang port-number expected $mis_syn_nr" 158539aab882SMatthieu Baerts fail_test 15868a127bf6SGeliang Tang dump_stats=1 15878a127bf6SGeliang Tang else 15888a127bf6SGeliang Tang echo -n "[ ok ]" 15898a127bf6SGeliang Tang fi 15908a127bf6SGeliang Tang 15918a127bf6SGeliang Tang echo -n " - ack " 15924bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | 15934bfadd71SMatthieu Baerts awk '{print $2}') 15948a127bf6SGeliang Tang [ -z "$count" ] && count=0 15958a127bf6SGeliang Tang if [ "$count" != "$mis_ack_nr" ]; then 15968a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] ack with a mismatched \ 15978a127bf6SGeliang Tang port-number expected $mis_ack_nr" 159839aab882SMatthieu Baerts fail_test 15998a127bf6SGeliang Tang dump_stats=1 16008a127bf6SGeliang Tang else 16018a127bf6SGeliang Tang echo "[ ok ]" 16028a127bf6SGeliang Tang fi 16038a127bf6SGeliang Tang else 16048a127bf6SGeliang Tang echo "" 16058a127bf6SGeliang Tang fi 16068a127bf6SGeliang Tang 1607327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1608be613160SGeliang Tang} 1609be613160SGeliang Tang 1610dd72b0feSGeliang Tangchk_rm_nr() 1611dd72b0feSGeliang Tang{ 1612dd72b0feSGeliang Tang local rm_addr_nr=$1 1613dd72b0feSGeliang Tang local rm_subflow_nr=$2 16146fa0174aSPaolo Abeni local invert 16156fa0174aSPaolo Abeni local simult 1616dd72b0feSGeliang Tang local count 1617dd72b0feSGeliang Tang local dump_stats 16187d9bf018SGeliang Tang local addr_ns=$ns1 16197d9bf018SGeliang Tang local subflow_ns=$ns2 16207d9bf018SGeliang Tang local extra_msg="" 16217028ba8aSGeliang Tang 16226fa0174aSPaolo Abeni shift 2 16236fa0174aSPaolo Abeni while [ -n "$1" ]; do 16246fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 16256fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 16266fa0174aSPaolo Abeni shift 16276fa0174aSPaolo Abeni done 16286fa0174aSPaolo Abeni 16296fa0174aSPaolo Abeni if [ -z $invert ]; then 16306fa0174aSPaolo Abeni addr_ns=$ns1 16316fa0174aSPaolo Abeni subflow_ns=$ns2 16326fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 16337028ba8aSGeliang Tang addr_ns=$ns2 16347028ba8aSGeliang Tang subflow_ns=$ns1 16357d9bf018SGeliang Tang extra_msg=" invert" 16367028ba8aSGeliang Tang fi 1637dd72b0feSGeliang Tang 16389a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "rm " 16394bfadd71SMatthieu Baerts count=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}') 1640dd72b0feSGeliang Tang [ -z "$count" ] && count=0 1641dd72b0feSGeliang Tang if [ "$count" != "$rm_addr_nr" ]; then 1642dd72b0feSGeliang Tang echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr" 164339aab882SMatthieu Baerts fail_test 1644dd72b0feSGeliang Tang dump_stats=1 1645dd72b0feSGeliang Tang else 1646dd72b0feSGeliang Tang echo -n "[ ok ]" 1647dd72b0feSGeliang Tang fi 1648dd72b0feSGeliang Tang 16497d9bf018SGeliang Tang echo -n " - rmsf " 16504bfadd71SMatthieu Baerts count=$(ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 1651dd72b0feSGeliang Tang [ -z "$count" ] && count=0 16526fa0174aSPaolo Abeni if [ -n "$simult" ]; then 1653d8d08302SMatthieu Baerts local cnt suffix 1654d8d08302SMatthieu Baerts 1655d8d08302SMatthieu Baerts cnt=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 16566fa0174aSPaolo Abeni 16576fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 16586fa0174aSPaolo Abeni # unreliable 16596fa0174aSPaolo Abeni [ -z "$cnt" ] && cnt=0 16606fa0174aSPaolo Abeni count=$((count + cnt)) 16616fa0174aSPaolo Abeni [ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 16626fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 16636fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 16646fa0174aSPaolo Abeni echo "[ ok ] $suffix" 16656fa0174aSPaolo Abeni else 16666fa0174aSPaolo Abeni echo "[fail] got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 166739aab882SMatthieu Baerts fail_test 16686fa0174aSPaolo Abeni dump_stats=1 16696fa0174aSPaolo Abeni fi 16706fa0174aSPaolo Abeni return 16716fa0174aSPaolo Abeni fi 1672dd72b0feSGeliang Tang if [ "$count" != "$rm_subflow_nr" ]; then 1673dd72b0feSGeliang Tang echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 167439aab882SMatthieu Baerts fail_test 1675dd72b0feSGeliang Tang dump_stats=1 1676dd72b0feSGeliang Tang else 16777d9bf018SGeliang Tang echo -n "[ ok ]" 1678dd72b0feSGeliang Tang fi 1679dd72b0feSGeliang Tang 1680327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 16817d9bf018SGeliang Tang 16827d9bf018SGeliang Tang echo "$extra_msg" 1683dd72b0feSGeliang Tang} 1684dd72b0feSGeliang Tang 1685718eb44eSGeliang Tangchk_prio_nr() 1686718eb44eSGeliang Tang{ 1687718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1688718eb44eSGeliang Tang local mp_prio_nr_rx=$2 1689718eb44eSGeliang Tang local count 1690718eb44eSGeliang Tang local dump_stats 1691718eb44eSGeliang Tang 16929a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "ptx" 16934bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}') 1694718eb44eSGeliang Tang [ -z "$count" ] && count=0 1695718eb44eSGeliang Tang if [ "$count" != "$mp_prio_nr_tx" ]; then 1696718eb44eSGeliang Tang echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 169739aab882SMatthieu Baerts fail_test 1698718eb44eSGeliang Tang dump_stats=1 1699718eb44eSGeliang Tang else 1700718eb44eSGeliang Tang echo -n "[ ok ]" 1701718eb44eSGeliang Tang fi 1702718eb44eSGeliang Tang 1703718eb44eSGeliang Tang echo -n " - prx " 17044bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}') 1705718eb44eSGeliang Tang [ -z "$count" ] && count=0 1706718eb44eSGeliang Tang if [ "$count" != "$mp_prio_nr_rx" ]; then 1707718eb44eSGeliang Tang echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 170839aab882SMatthieu Baerts fail_test 1709718eb44eSGeliang Tang dump_stats=1 1710718eb44eSGeliang Tang else 1711718eb44eSGeliang Tang echo "[ ok ]" 1712718eb44eSGeliang Tang fi 1713718eb44eSGeliang Tang 1714327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1715718eb44eSGeliang Tang} 1716718eb44eSGeliang Tang 1717e274f715SPaolo Abenichk_subflow_nr() 1718e274f715SPaolo Abeni{ 1719e274f715SPaolo Abeni local need_title="$1" 1720e274f715SPaolo Abeni local msg="$2" 1721e274f715SPaolo Abeni local subflow_nr=$3 1722e274f715SPaolo Abeni local cnt1 1723e274f715SPaolo Abeni local cnt2 1724a635a8c3SPaolo Abeni local dump_stats 1725e274f715SPaolo Abeni 1726e274f715SPaolo Abeni if [ -n "${need_title}" ]; then 1727e274f715SPaolo Abeni printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 1728e274f715SPaolo Abeni else 1729e274f715SPaolo Abeni printf "%-${nr_blank}s %s" " " "${msg}" 1730e274f715SPaolo Abeni fi 1731e274f715SPaolo Abeni 1732e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1733e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 17340fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 1735e274f715SPaolo Abeni echo "[fail] got $cnt1:$cnt2 subflows expected $subflow_nr" 1736e274f715SPaolo Abeni fail_test 1737e274f715SPaolo Abeni dump_stats=1 1738e274f715SPaolo Abeni else 1739e274f715SPaolo Abeni echo "[ ok ]" 1740e274f715SPaolo Abeni fi 1741e274f715SPaolo Abeni 1742a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1743a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1744a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1745a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1746a635a8c3SPaolo Abeni dump_stats 1747a635a8c3SPaolo Abeni fi 1748e274f715SPaolo Abeni} 1749e274f715SPaolo Abeni 17509095ce97SGeliang Tangchk_mptcp_info() 17519095ce97SGeliang Tang{ 17529095ce97SGeliang Tang local nr_info=$1 17539095ce97SGeliang Tang local info 17549095ce97SGeliang Tang local cnt1 17559095ce97SGeliang Tang local cnt2 17569095ce97SGeliang Tang local dump_stats 17579095ce97SGeliang Tang 17589095ce97SGeliang Tang if [[ $nr_info = "subflows_"* ]]; then 17599095ce97SGeliang Tang info="subflows" 17609095ce97SGeliang Tang nr_info=${nr_info:9} 17619095ce97SGeliang Tang else 17629095ce97SGeliang Tang echo "[fail] unsupported argument: $nr_info" 17639095ce97SGeliang Tang fail_test 17649095ce97SGeliang Tang return 1 17659095ce97SGeliang Tang fi 17669095ce97SGeliang Tang 17679095ce97SGeliang Tang printf "%-${nr_blank}s %-30s" " " "mptcp_info $info=$nr_info" 17689095ce97SGeliang Tang 17699095ce97SGeliang Tang cnt1=$(ss -N $ns1 -inmHM | grep "$info:" | 17709095ce97SGeliang Tang sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 17719095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 17729095ce97SGeliang Tang cnt2=$(ss -N $ns2 -inmHM | grep "$info:" | 17739095ce97SGeliang Tang sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 17749095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 17759095ce97SGeliang Tang if [ "$cnt1" != "$nr_info" ] || [ "$cnt2" != "$nr_info" ]; then 17769095ce97SGeliang Tang echo "[fail] got $cnt1:$cnt2 $info expected $nr_info" 17779095ce97SGeliang Tang fail_test 17789095ce97SGeliang Tang dump_stats=1 17799095ce97SGeliang Tang else 17809095ce97SGeliang Tang echo "[ ok ]" 17819095ce97SGeliang Tang fi 17829095ce97SGeliang Tang 17839095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 17849095ce97SGeliang Tang ss -N $ns1 -inmHM 17859095ce97SGeliang Tang ss -N $ns2 -inmHM 17869095ce97SGeliang Tang dump_stats 17879095ce97SGeliang Tang fi 17889095ce97SGeliang Tang} 17899095ce97SGeliang Tang 17907d1e6f16SPaolo Abenichk_link_usage() 17917d1e6f16SPaolo Abeni{ 17927d1e6f16SPaolo Abeni local ns=$1 17937d1e6f16SPaolo Abeni local link=$2 17947d1e6f16SPaolo Abeni local out=$3 17957d1e6f16SPaolo Abeni local expected_rate=$4 17964bfadd71SMatthieu Baerts 17974bfadd71SMatthieu Baerts local tx_link tx_total 17984bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1799d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1800d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 18017d1e6f16SPaolo Abeni local tolerance=5 18027d1e6f16SPaolo Abeni 18039a0a9367SGeliang Tang printf "%-${nr_blank}s %-18s" " " "link usage" 1804d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1805d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 18067d1e6f16SPaolo Abeni echo "[fail] got $tx_rate% usage, expected $expected_rate%" 180739aab882SMatthieu Baerts fail_test 18087d1e6f16SPaolo Abeni else 18097d1e6f16SPaolo Abeni echo "[ ok ]" 18107d1e6f16SPaolo Abeni fi 18117d1e6f16SPaolo Abeni} 18127d1e6f16SPaolo Abeni 1813f98c2bcaSMat Martineauwait_attempt_fail() 181446e967d1SPaolo Abeni{ 181546e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 181646e967d1SPaolo Abeni local time=0 181746e967d1SPaolo Abeni local ns=$1 181846e967d1SPaolo Abeni 181946e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 18201e777bd8SMatthieu Baerts local cnt 18211e777bd8SMatthieu Baerts 18221e777bd8SMatthieu Baerts cnt=$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFails | awk '{print $2}') 182346e967d1SPaolo Abeni 182446e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 182546e967d1SPaolo Abeni time=$((time + 100)) 182646e967d1SPaolo Abeni sleep 0.1 182746e967d1SPaolo Abeni done 182846e967d1SPaolo Abeni return 1 182946e967d1SPaolo Abeni} 183046e967d1SPaolo Abeni 18315ac1d2d6SMat Martineauset_userspace_pm() 18325ac1d2d6SMat Martineau{ 18335ac1d2d6SMat Martineau local ns=$1 18345ac1d2d6SMat Martineau 18355ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 18365ac1d2d6SMat Martineau} 18375ac1d2d6SMat Martineau 18381002b89fSGeliang Tangsubflows_tests() 18391002b89fSGeliang Tang{ 1840c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1841b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1842c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1843ae7bd9ccSMatthieu Baerts fi 1844b08fbf24SPaolo Abeni 18451002b89fSGeliang Tang # subflow limited by client 1846c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 184734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 184834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 184934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1850b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1851c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1852ae7bd9ccSMatthieu Baerts fi 1853b08fbf24SPaolo Abeni 18541002b89fSGeliang Tang # subflow limited by server 1855c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 185634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 185734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 185834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1859b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1860c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 1861ae7bd9ccSMatthieu Baerts fi 1862b08fbf24SPaolo Abeni 1863b08fbf24SPaolo Abeni # subflow 1864c7d49c03SMatthieu Baerts if reset "single subflow"; then 186534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 186634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 186734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1868b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1869c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1870ae7bd9ccSMatthieu Baerts fi 1871b08fbf24SPaolo Abeni 1872b08fbf24SPaolo Abeni # multiple subflows 1873c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 187434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 187534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 187634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 187734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1878b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1879c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1880ae7bd9ccSMatthieu Baerts fi 1881b08fbf24SPaolo Abeni 188272bcbc46SPaolo Abeni # multiple subflows limited by server 1883c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 188434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 188534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 188634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 188734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1888b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1889c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 1890ae7bd9ccSMatthieu Baerts fi 1891c3eaa5f6SGeliang Tang 1892c3eaa5f6SGeliang Tang # single subflow, dev 1893c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 189434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 189534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 189634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 1897c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1898c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1899ae7bd9ccSMatthieu Baerts fi 19001002b89fSGeliang Tang} 1901b08fbf24SPaolo Abeni 190246e967d1SPaolo Abenisubflows_error_tests() 190346e967d1SPaolo Abeni{ 190446e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 190546e967d1SPaolo Abeni # address, no additional subflow should be created 1906c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 190734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 190834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 190934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 191046e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1911c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1912ae7bd9ccSMatthieu Baerts fi 191346e967d1SPaolo Abeni 191446e967d1SPaolo Abeni # multiple subflows, with subflow creation error 1915c7d49c03SMatthieu Baerts if reset "multi subflows, with failing subflow"; then 191634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 191734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 191834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 191934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 19203469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 REJECT 192146e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1922c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1923ae7bd9ccSMatthieu Baerts fi 192446e967d1SPaolo Abeni 192546e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 1926c7d49c03SMatthieu Baerts if reset "multi subflows, with subflow timeout"; then 192734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 192834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 192934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 193034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 19313469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 DROP 193246e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1933c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1934ae7bd9ccSMatthieu Baerts fi 193546e967d1SPaolo Abeni 193646e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 193746e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 193846e967d1SPaolo Abeni # subflows are added later 1939c7d49c03SMatthieu Baerts if reset "multi subflows, fair usage on close"; then 194034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 194134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 194234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 19433469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 REJECT 194446e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow & 194546e967d1SPaolo Abeni 194646e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 1947f98c2bcaSMat Martineau wait_attempt_fail $ns2 194834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 194946e967d1SPaolo Abeni wait 195046e967d1SPaolo Abeni 195146e967d1SPaolo Abeni # additional subflow could be created only if the PM select 195246e967d1SPaolo Abeni # the later endpoint, skipping the already used one 1953c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1954ae7bd9ccSMatthieu Baerts fi 195546e967d1SPaolo Abeni} 195646e967d1SPaolo Abeni 19571002b89fSGeliang Tangsignal_address_tests() 19581002b89fSGeliang Tang{ 1959b08fbf24SPaolo Abeni # add_address, unused 1960c7d49c03SMatthieu Baerts if reset "unused signal address"; then 196134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1962b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1963c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1964be613160SGeliang Tang chk_add_nr 1 1 1965ae7bd9ccSMatthieu Baerts fi 1966b08fbf24SPaolo Abeni 1967b08fbf24SPaolo Abeni # accept and use add_addr 1968c7d49c03SMatthieu Baerts if reset "signal address"; then 196934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 197034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 197134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1972b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1973c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1974be613160SGeliang Tang chk_add_nr 1 1 1975ae7bd9ccSMatthieu Baerts fi 1976b08fbf24SPaolo Abeni 1977b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 1978b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 1979b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 1980b08fbf24SPaolo Abeni # used for 'add_addr' subflow 1981c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 198234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 198334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 198434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 198534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1986b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1987c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1988be613160SGeliang Tang chk_add_nr 1 1 1989ae7bd9ccSMatthieu Baerts fi 1990b08fbf24SPaolo Abeni 1991b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 1992c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 199334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 199434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 199534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 199634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 199734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 1998b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1999c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2000be613160SGeliang Tang chk_add_nr 1 1 2001ae7bd9ccSMatthieu Baerts fi 2002ef360019SGeliang Tang 2003ef360019SGeliang Tang # signal addresses 2004c7d49c03SMatthieu Baerts if reset "signal addresses"; then 200534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 200634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 200734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 200834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 200934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2010ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2011c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2012ef360019SGeliang Tang chk_add_nr 3 3 2013ae7bd9ccSMatthieu Baerts fi 2014ef360019SGeliang Tang 2015ef360019SGeliang Tang # signal invalid addresses 2016c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 201734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 201834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 201934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 202034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 202134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2022ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2023c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2024ef360019SGeliang Tang chk_add_nr 3 3 2025ae7bd9ccSMatthieu Baerts fi 202633c563adSYonglong Li 202733c563adSYonglong Li # signal addresses race test 2028c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 202934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 203034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 203134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 203234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 203334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 203434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 203534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 203634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 203734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 203834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 20396ef84b15SPaolo Abeni 20406ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 20416ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 20426ef84b15SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2043c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 204486e39e04SPaolo Abeni 204586e39e04SPaolo Abeni # the server will not signal the address terminating 204686e39e04SPaolo Abeni # the MPC subflow 204786e39e04SPaolo Abeni chk_add_nr 3 3 2048ae7bd9ccSMatthieu Baerts fi 20491002b89fSGeliang Tang} 2050b08fbf24SPaolo Abeni 20511002b89fSGeliang Tanglink_failure_tests() 20521002b89fSGeliang Tang{ 20538b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2054c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 20557d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 20567d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 20577d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 20587d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 20597d1e6f16SPaolo Abeni # active backup and link switch-over. 20607d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 20617d1e6f16SPaolo Abeni init_shapers 206234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 206334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 206434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 206534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 206634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 20678b819a84SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 1 2068c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 20698b819a84SFlorian Westphal chk_add_nr 1 1 20707d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2071ae7bd9ccSMatthieu Baerts fi 20727d1e6f16SPaolo Abeni 20737d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 20747d1e6f16SPaolo Abeni # for bidirectional transfer 2075c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 20767d1e6f16SPaolo Abeni init_shapers 207734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 207834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 207934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 208034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 208134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 20827d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2 2083c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 20847d1e6f16SPaolo Abeni chk_add_nr 1 1 20857d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2086ae7bd9ccSMatthieu Baerts fi 20877d1e6f16SPaolo Abeni 20887d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 20897d1e6f16SPaolo Abeni # will never be used 2090c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 20917d1e6f16SPaolo Abeni init_shapers 209234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 209334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 209434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 2095e59300ceSMatthieu Baerts FAILING_LINKS="1" 209634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 20977d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1 2098c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 20997d1e6f16SPaolo Abeni chk_add_nr 1 1 21007d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2101ae7bd9ccSMatthieu Baerts fi 21027d1e6f16SPaolo Abeni 21037d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 21047d1e6f16SPaolo Abeni # the traffic 2105c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 21067d1e6f16SPaolo Abeni init_shapers 210734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 210834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 210934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 211034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2111e59300ceSMatthieu Baerts FAILING_LINKS="1 2" 21127d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1 2113c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21147d1e6f16SPaolo Abeni chk_add_nr 1 1 21157d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 21167d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2117ae7bd9ccSMatthieu Baerts fi 21187d1e6f16SPaolo Abeni 21197d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 21207d1e6f16SPaolo Abeni # for bidirectional transfer 2121c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 21227d1e6f16SPaolo Abeni init_shapers 212334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 212434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 212534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 212634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2127e59300ceSMatthieu Baerts FAILING_LINKS="1 2" 21287d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2 2129c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21307d1e6f16SPaolo Abeni chk_add_nr 1 1 21317d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 21327d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2133ae7bd9ccSMatthieu Baerts fi 21341002b89fSGeliang Tang} 21358b819a84SFlorian Westphal 21361002b89fSGeliang Tangadd_addr_timeout_tests() 21371002b89fSGeliang Tang{ 21388d014eaaSGeliang Tang # add_addr timeout 2139c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 214034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 214134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 214234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 21438b819a84SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2144c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21458d014eaaSGeliang Tang chk_add_nr 4 0 2146ae7bd9ccSMatthieu Baerts fi 21478d014eaaSGeliang Tang 21481002b89fSGeliang Tang # add_addr timeout IPv6 2149c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 215034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 215134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 215234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 21531002b89fSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2154c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21551002b89fSGeliang Tang chk_add_nr 4 0 2156ae7bd9ccSMatthieu Baerts fi 21578da6229bSGeliang Tang 21588da6229bSGeliang Tang # signal addresses timeout 2159c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 216034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 216134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 216234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 216334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2164cbfafac4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2165c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21668da6229bSGeliang Tang chk_add_nr 8 0 2167ae7bd9ccSMatthieu Baerts fi 21688da6229bSGeliang Tang 21698da6229bSGeliang Tang # signal invalid addresses timeout 2170c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 217134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 217234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 217334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 217434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2175cbfafac4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2176c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21778da6229bSGeliang Tang chk_add_nr 8 0 2178ae7bd9ccSMatthieu Baerts fi 21791002b89fSGeliang Tang} 21801002b89fSGeliang Tang 21811002b89fSGeliang Tangremove_tests() 21821002b89fSGeliang Tang{ 2183dd72b0feSGeliang Tang # single subflow, remove 2184c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 218534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 218634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 218734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 21882e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 2189c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2190dd72b0feSGeliang Tang chk_rm_nr 1 1 2191ae7bd9ccSMatthieu Baerts fi 2192dd72b0feSGeliang Tang 2193dd72b0feSGeliang Tang # multiple subflows, remove 2194c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 219534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 219634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 219734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 219834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 21992e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow 2200c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2201dd72b0feSGeliang Tang chk_rm_nr 2 2 2202ae7bd9ccSMatthieu Baerts fi 2203dd72b0feSGeliang Tang 2204dd72b0feSGeliang Tang # single address, remove 2205c7d49c03SMatthieu Baerts if reset "remove single address"; then 220634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 220734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 220834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 22092e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2210c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2211dd72b0feSGeliang Tang chk_add_nr 1 1 22127028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2213ae7bd9ccSMatthieu Baerts fi 2214dd72b0feSGeliang Tang 2215dd72b0feSGeliang Tang # subflow and signal, remove 2216c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 221734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 221834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 221934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 222034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 22212e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2222c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2223dd72b0feSGeliang Tang chk_add_nr 1 1 2224dd72b0feSGeliang Tang chk_rm_nr 1 1 2225ae7bd9ccSMatthieu Baerts fi 2226dd72b0feSGeliang Tang 2227dd72b0feSGeliang Tang # subflows and signal, remove 2228c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 222934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 223034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 223134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 223234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 223334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 223422b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 speed_10 2235c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2236dd72b0feSGeliang Tang chk_add_nr 1 1 2237dd72b0feSGeliang Tang chk_rm_nr 2 2 2238ae7bd9ccSMatthieu Baerts fi 2239dd72b0feSGeliang Tang 2240ef360019SGeliang Tang # addresses remove 2241c7d49c03SMatthieu Baerts if reset "remove addresses"; then 224234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 224334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 224434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 224534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 224634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 224722b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2248c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2249ef360019SGeliang Tang chk_add_nr 3 3 2250ef360019SGeliang Tang chk_rm_nr 3 3 invert 2251ae7bd9ccSMatthieu Baerts fi 2252ef360019SGeliang Tang 2253ef360019SGeliang Tang # invalid addresses remove 2254c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 225534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 225634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 225734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 225834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 225934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 226022b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2261c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2262ef360019SGeliang Tang chk_add_nr 3 3 2263ef360019SGeliang Tang chk_rm_nr 3 1 invert 2264ae7bd9ccSMatthieu Baerts fi 2265ef360019SGeliang Tang 22666fe4ccdcSGeliang Tang # subflows and signal, flush 2267c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 226834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 226934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 227034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 227134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 227234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 22732e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2274c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22756fe4ccdcSGeliang Tang chk_add_nr 1 1 22766fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2277ae7bd9ccSMatthieu Baerts fi 2278d2c4333aSGeliang Tang 2279d2c4333aSGeliang Tang # subflows flush 2280c7d49c03SMatthieu Baerts if reset "flush subflows"; then 228134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 228234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 228334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 228434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 228534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2286d2c4333aSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2287c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22886fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2289ae7bd9ccSMatthieu Baerts fi 2290d2c4333aSGeliang Tang 2291d2c4333aSGeliang Tang # addresses flush 2292c7d49c03SMatthieu Baerts if reset "flush addresses"; then 229334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 229434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 229534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 229634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 229734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2298d2c4333aSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2299c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2300d2c4333aSGeliang Tang chk_add_nr 3 3 23016fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 2302ae7bd9ccSMatthieu Baerts fi 2303ef360019SGeliang Tang 2304ef360019SGeliang Tang # invalid addresses flush 2305c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 230634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 230734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 230834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 230934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 231034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2311ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow 2312c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2313ef360019SGeliang Tang chk_add_nr 3 3 2314ef360019SGeliang Tang chk_rm_nr 3 1 invert 2315ae7bd9ccSMatthieu Baerts fi 23165e287fe7SGeliang Tang 23175e287fe7SGeliang Tang # remove id 0 subflow 2318c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 231934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 232034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 232134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 23225e287fe7SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow 2323c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23245e287fe7SGeliang Tang chk_rm_nr 1 1 2325ae7bd9ccSMatthieu Baerts fi 23265e287fe7SGeliang Tang 23275e287fe7SGeliang Tang # remove id 0 address 2328c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 232934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 233034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 233134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 23325e287fe7SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow 2333c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23345e287fe7SGeliang Tang chk_add_nr 1 1 23355e287fe7SGeliang Tang chk_rm_nr 1 1 invert 2336ae7bd9ccSMatthieu Baerts fi 23371002b89fSGeliang Tang} 23386fe4ccdcSGeliang Tang 23391002b89fSGeliang Tangadd_tests() 23401002b89fSGeliang Tang{ 23416208fd82SGeliang Tang # add single subflow 2342c7d49c03SMatthieu Baerts if reset "add single subflow"; then 234334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 234434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 23456208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow 2346c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2347ae7bd9ccSMatthieu Baerts fi 23486208fd82SGeliang Tang 23496208fd82SGeliang Tang # add signal address 2350c7d49c03SMatthieu Baerts if reset "add signal address"; then 235134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 235234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 23536208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2354c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23556208fd82SGeliang Tang chk_add_nr 1 1 2356ae7bd9ccSMatthieu Baerts fi 23576208fd82SGeliang Tang 23586208fd82SGeliang Tang # add multiple subflows 2359c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 236034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 236134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 23626208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow 2363c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2364ae7bd9ccSMatthieu Baerts fi 23656208fd82SGeliang Tang 23666208fd82SGeliang Tang # add multiple subflows IPv6 2367c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 236834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 236934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 23706208fd82SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow 2371c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2372ae7bd9ccSMatthieu Baerts fi 23736208fd82SGeliang Tang 23746208fd82SGeliang Tang # add multiple addresses IPv6 2375c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 237634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 237734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 23786208fd82SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow 2379c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23806208fd82SGeliang Tang chk_add_nr 2 2 2381ae7bd9ccSMatthieu Baerts fi 23821002b89fSGeliang Tang} 23836208fd82SGeliang Tang 23841002b89fSGeliang Tangipv6_tests() 23851002b89fSGeliang Tang{ 2386523514edSGeliang Tang # subflow IPv6 2387c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 238834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 238934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 239034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2391523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2392c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2393ae7bd9ccSMatthieu Baerts fi 2394523514edSGeliang Tang 2395523514edSGeliang Tang # add_address, unused IPv6 2396c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 239734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2398523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2399c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2400523514edSGeliang Tang chk_add_nr 1 1 2401ae7bd9ccSMatthieu Baerts fi 2402523514edSGeliang Tang 2403523514edSGeliang Tang # signal address IPv6 2404c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 240534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 240634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 240734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2408523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2409c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2410523514edSGeliang Tang chk_add_nr 1 1 2411ae7bd9ccSMatthieu Baerts fi 2412523514edSGeliang Tang 2413523514edSGeliang Tang # single address IPv6, remove 2414c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 241534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 241634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 241734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 24182e8cbf45SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow 2419c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2420523514edSGeliang Tang chk_add_nr 1 1 24217028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2422ae7bd9ccSMatthieu Baerts fi 2423523514edSGeliang Tang 2424523514edSGeliang Tang # subflow and signal IPv6, remove 2425c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 242634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 242734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 242834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 242934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 24302e8cbf45SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow 2431c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2432523514edSGeliang Tang chk_add_nr 1 1 2433523514edSGeliang Tang chk_rm_nr 1 1 2434ae7bd9ccSMatthieu Baerts fi 24351002b89fSGeliang Tang} 2436523514edSGeliang Tang 24371002b89fSGeliang Tangv4mapped_tests() 24381002b89fSGeliang Tang{ 2439a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2440c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 244134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 244234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 244334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2444a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2445c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2446ae7bd9ccSMatthieu Baerts fi 2447a6094788SGeliang Tang 2448a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2449c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 245034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 245134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 245234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2453a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2454c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2455a6094788SGeliang Tang chk_add_nr 1 1 2456ae7bd9ccSMatthieu Baerts fi 2457a6094788SGeliang Tang 2458a6094788SGeliang Tang # subflow v4-map-v6 2459c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 246034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 246134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 246234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2463a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2464c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2465ae7bd9ccSMatthieu Baerts fi 2466a6094788SGeliang Tang 2467a6094788SGeliang Tang # signal address v4-map-v6 2468c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 246934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 247034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 247134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2472a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2473c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2474a6094788SGeliang Tang chk_add_nr 1 1 2475ae7bd9ccSMatthieu Baerts fi 2476a6094788SGeliang Tang 2477a6094788SGeliang Tang # subflow v6-map-v4 2478c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 247934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 248034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 248134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2482a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2483c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2484ae7bd9ccSMatthieu Baerts fi 2485a6094788SGeliang Tang 2486a6094788SGeliang Tang # signal address v6-map-v4 2487c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 248834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 248934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 249034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2491a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2492c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2493a6094788SGeliang Tang chk_add_nr 1 1 2494ae7bd9ccSMatthieu Baerts fi 2495a6094788SGeliang Tang 2496a6094788SGeliang Tang # no subflow IPv6 to v4 address 2497c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 249834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 249934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 250034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2501a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2502c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2503ae7bd9ccSMatthieu Baerts fi 2504a6094788SGeliang Tang 2505a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2506c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 250734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 250834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 250934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2510a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2511c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2512ae7bd9ccSMatthieu Baerts fi 2513a6094788SGeliang Tang 2514a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2515c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 251634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 251734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 251834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2519a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2520c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2521ae7bd9ccSMatthieu Baerts fi 25221002b89fSGeliang Tang} 2523a6094788SGeliang Tang 2524ad349374SPaolo Abenimixed_tests() 2525ad349374SPaolo Abeni{ 2526ad349374SPaolo Abeni if reset "IPv4 sockets do not use IPv6 addresses"; then 2527ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2528ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2529ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2530ad349374SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2531ad349374SPaolo Abeni chk_join_nr 0 0 0 2532ad349374SPaolo Abeni fi 2533ad349374SPaolo Abeni 2534ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 2535ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows"; then 2536ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2537ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2538ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2539ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2540ad349374SPaolo Abeni chk_join_nr 1 1 1 2541ad349374SPaolo Abeni fi 2542ad349374SPaolo Abeni 2543ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 2544ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1"; then 2545ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2546ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2547ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2548ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2549ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2550ad349374SPaolo Abeni chk_join_nr 1 1 1 2551ad349374SPaolo Abeni fi 2552ad349374SPaolo Abeni 2553ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2554ad349374SPaolo Abeni # matching family 2555ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2"; then 2556ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2557ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2558ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2559ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2560ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:1::1 0 0 fullmesh_1 slow 2561ad349374SPaolo Abeni chk_join_nr 4 4 4 2562ad349374SPaolo Abeni fi 2563ad349374SPaolo Abeni} 2564ad349374SPaolo Abeni 25651002b89fSGeliang Tangbackup_tests() 25661002b89fSGeliang Tang{ 2567718eb44eSGeliang Tang # single subflow, backup 2568c7d49c03SMatthieu Baerts if reset "single subflow, backup"; then 256934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 257034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 257134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2572718eb44eSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup 2573c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2574718eb44eSGeliang Tang chk_prio_nr 0 1 2575ae7bd9ccSMatthieu Baerts fi 2576718eb44eSGeliang Tang 2577718eb44eSGeliang Tang # single address, backup 2578c7d49c03SMatthieu Baerts if reset "single address, backup"; then 257934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 258034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 258134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2582718eb44eSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2583c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2584718eb44eSGeliang Tang chk_add_nr 1 1 2585d045b9ebSPaolo Abeni chk_prio_nr 1 1 2586ae7bd9ccSMatthieu Baerts fi 258733397b83SGeliang Tang 258833397b83SGeliang Tang # single address with port, backup 2589c7d49c03SMatthieu Baerts if reset "single address with port, backup"; then 259034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 259134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 259234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 259333397b83SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2594c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 259533397b83SGeliang Tang chk_add_nr 1 1 2596d045b9ebSPaolo Abeni chk_prio_nr 1 1 2597ae7bd9ccSMatthieu Baerts fi 2598914f6a59SPaolo Abeni 2599914f6a59SPaolo Abeni if reset "mpc backup"; then 2600914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2601914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2602914f6a59SPaolo Abeni chk_join_nr 0 0 0 2603914f6a59SPaolo Abeni chk_prio_nr 0 1 2604914f6a59SPaolo Abeni fi 2605914f6a59SPaolo Abeni 2606914f6a59SPaolo Abeni if reset "mpc backup both sides"; then 2607914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2608914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2609914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2610914f6a59SPaolo Abeni chk_join_nr 0 0 0 2611914f6a59SPaolo Abeni chk_prio_nr 1 1 2612914f6a59SPaolo Abeni fi 2613914f6a59SPaolo Abeni 2614914f6a59SPaolo Abeni if reset "mpc switch to backup"; then 2615914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2616914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2617914f6a59SPaolo Abeni chk_join_nr 0 0 0 2618914f6a59SPaolo Abeni chk_prio_nr 0 1 2619914f6a59SPaolo Abeni fi 2620914f6a59SPaolo Abeni 2621914f6a59SPaolo Abeni if reset "mpc switch to backup both sides"; then 2622914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2623914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2624914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2625914f6a59SPaolo Abeni chk_join_nr 0 0 0 2626914f6a59SPaolo Abeni chk_prio_nr 1 1 2627914f6a59SPaolo Abeni fi 26281002b89fSGeliang Tang} 2629718eb44eSGeliang Tang 2630178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2631178d0232SGeliang TangLISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2632178d0232SGeliang Tang 2633178d0232SGeliang TangAF_INET=2 2634178d0232SGeliang TangAF_INET6=10 2635178d0232SGeliang Tang 2636178d0232SGeliang Tangverify_listener_events() 2637178d0232SGeliang Tang{ 2638178d0232SGeliang Tang local evt=$1 2639178d0232SGeliang Tang local e_type=$2 2640178d0232SGeliang Tang local e_family=$3 2641178d0232SGeliang Tang local e_saddr=$4 2642178d0232SGeliang Tang local e_sport=$5 2643178d0232SGeliang Tang local type 2644178d0232SGeliang Tang local family 2645178d0232SGeliang Tang local saddr 2646178d0232SGeliang Tang local sport 2647178d0232SGeliang Tang 2648178d0232SGeliang Tang if [ $e_type = $LISTENER_CREATED ]; then 2649178d0232SGeliang Tang stdbuf -o0 -e0 printf "\t\t\t\t\t CREATE_LISTENER %s:%s"\ 2650178d0232SGeliang Tang $e_saddr $e_sport 2651178d0232SGeliang Tang elif [ $e_type = $LISTENER_CLOSED ]; then 2652178d0232SGeliang Tang stdbuf -o0 -e0 printf "\t\t\t\t\t CLOSE_LISTENER %s:%s "\ 2653178d0232SGeliang Tang $e_saddr $e_sport 2654178d0232SGeliang Tang fi 2655178d0232SGeliang Tang 2656178d0232SGeliang Tang type=$(grep "type:$e_type," $evt | 2657178d0232SGeliang Tang sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q') 2658178d0232SGeliang Tang family=$(grep "type:$e_type," $evt | 2659178d0232SGeliang Tang sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q') 2660178d0232SGeliang Tang sport=$(grep "type:$e_type," $evt | 2661178d0232SGeliang Tang sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 2662178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 2663178d0232SGeliang Tang saddr=$(grep "type:$e_type," $evt | 2664178d0232SGeliang Tang sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 2665178d0232SGeliang Tang else 2666178d0232SGeliang Tang saddr=$(grep "type:$e_type," $evt | 2667178d0232SGeliang Tang sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q') 2668178d0232SGeliang Tang fi 2669178d0232SGeliang Tang 2670178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2671178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2672178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2673178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 2674178d0232SGeliang Tang stdbuf -o0 -e0 printf "[ ok ]\n" 2675178d0232SGeliang Tang return 0 2676178d0232SGeliang Tang fi 2677178d0232SGeliang Tang fail_test 2678178d0232SGeliang Tang stdbuf -o0 -e0 printf "[fail]\n" 2679178d0232SGeliang Tang} 2680178d0232SGeliang Tang 26811002b89fSGeliang Tangadd_addr_ports_tests() 26821002b89fSGeliang Tang{ 26838a127bf6SGeliang Tang # signal address with port 2684c7d49c03SMatthieu Baerts if reset "signal address with port"; then 268534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 268634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 268734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 26888a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2689c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 26908a127bf6SGeliang Tang chk_add_nr 1 1 1 2691ae7bd9ccSMatthieu Baerts fi 26928a127bf6SGeliang Tang 26938a127bf6SGeliang Tang # subflow and signal with port 2694c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 269534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 269634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 269734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 269834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 26998a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2700c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27018a127bf6SGeliang Tang chk_add_nr 1 1 1 2702ae7bd9ccSMatthieu Baerts fi 27038a127bf6SGeliang Tang 27048a127bf6SGeliang Tang # single address with port, remove 2705178d0232SGeliang Tang # pm listener events 2706178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 270734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 270834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 270934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 27108a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2711c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 27128a127bf6SGeliang Tang chk_add_nr 1 1 1 27137028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2714178d0232SGeliang Tang 2715178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2716178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2717178d0232SGeliang Tang kill_events_pids 2718ae7bd9ccSMatthieu Baerts fi 27198a127bf6SGeliang Tang 27208a127bf6SGeliang Tang # subflow and signal with port, remove 2721c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 272234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 272334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 272434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 272534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 27268a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2727c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27288a127bf6SGeliang Tang chk_add_nr 1 1 1 27298a127bf6SGeliang Tang chk_rm_nr 1 1 2730ae7bd9ccSMatthieu Baerts fi 27318a127bf6SGeliang Tang 27328a127bf6SGeliang Tang # subflows and signal with port, flush 2733c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 273434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 273534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 273634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 273734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 273834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2739327b9a94SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -8 -2 slow 2740c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 27418a127bf6SGeliang Tang chk_add_nr 1 1 27426fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2743ae7bd9ccSMatthieu Baerts fi 27448a127bf6SGeliang Tang 27458a127bf6SGeliang Tang # multiple addresses with port 2746c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 274734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 274834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 274934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 275034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 27518a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2752c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27538a127bf6SGeliang Tang chk_add_nr 2 2 2 2754ae7bd9ccSMatthieu Baerts fi 27558a127bf6SGeliang Tang 27568a127bf6SGeliang Tang # multiple addresses with ports 2757c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 275834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 275934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 276034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 276134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 27628a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2763c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27648a127bf6SGeliang Tang chk_add_nr 2 2 2 2765ae7bd9ccSMatthieu Baerts fi 27661002b89fSGeliang Tang} 27678a127bf6SGeliang Tang 27681002b89fSGeliang Tangsyncookies_tests() 27691002b89fSGeliang Tang{ 277000587187SFlorian Westphal # single subflow, syncookies 2771c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 277234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 277334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 277434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 277500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2776c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2777ae7bd9ccSMatthieu Baerts fi 277800587187SFlorian Westphal 277900587187SFlorian Westphal # multiple subflows with syn cookies 2780c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 278134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 278234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 278334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 278434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 278500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2786c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2787ae7bd9ccSMatthieu Baerts fi 278800587187SFlorian Westphal 278900587187SFlorian Westphal # multiple subflows limited by server 2790c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 279134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 279234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 279334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 279434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 279500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2796c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 2797ae7bd9ccSMatthieu Baerts fi 279800587187SFlorian Westphal 279900587187SFlorian Westphal # test signal address with cookies 2800c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 280134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 280234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 280334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 280400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2805c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2806be613160SGeliang Tang chk_add_nr 1 1 2807ae7bd9ccSMatthieu Baerts fi 280800587187SFlorian Westphal 280900587187SFlorian Westphal # test cookie with subflow and signal 2810c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 281134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 281234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 281334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 281434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 281500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2816c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2817be613160SGeliang Tang chk_add_nr 1 1 2818ae7bd9ccSMatthieu Baerts fi 281900587187SFlorian Westphal 282000587187SFlorian Westphal # accept and use add_addr with additional subflows 2821c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 282234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 282334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 282434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 282534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 282634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 282700587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2828c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2829be613160SGeliang Tang chk_add_nr 1 1 2830ae7bd9ccSMatthieu Baerts fi 28311002b89fSGeliang Tang} 28321002b89fSGeliang Tang 2833af66d3e1SGeliang Tangchecksum_tests() 2834af66d3e1SGeliang Tang{ 2835af66d3e1SGeliang Tang # checksum test 0 0 2836ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 283734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 283834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2839af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2840c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2841ae7bd9ccSMatthieu Baerts fi 2842af66d3e1SGeliang Tang 2843af66d3e1SGeliang Tang # checksum test 1 1 2844ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 284534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 284634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2847af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2848c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2849ae7bd9ccSMatthieu Baerts fi 2850af66d3e1SGeliang Tang 2851af66d3e1SGeliang Tang # checksum test 0 1 2852ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 285334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 285434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2855af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2856c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2857ae7bd9ccSMatthieu Baerts fi 2858af66d3e1SGeliang Tang 2859af66d3e1SGeliang Tang # checksum test 1 0 2860ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 286134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 286234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2863af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2864c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2865ae7bd9ccSMatthieu Baerts fi 2866af66d3e1SGeliang Tang} 2867af66d3e1SGeliang Tang 28680cddb4a6SGeliang Tangdeny_join_id0_tests() 28690cddb4a6SGeliang Tang{ 28700cddb4a6SGeliang Tang # subflow allow join id0 ns1 2871c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 287234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 287334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 287434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28750cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2876c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2877ae7bd9ccSMatthieu Baerts fi 28780cddb4a6SGeliang Tang 28790cddb4a6SGeliang Tang # subflow allow join id0 ns2 2880c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 288134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 288234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 288334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28840cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2885c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2886ae7bd9ccSMatthieu Baerts fi 28870cddb4a6SGeliang Tang 28880cddb4a6SGeliang Tang # signal address allow join id0 ns1 28890cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 2890c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 289134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 289234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 289334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 28940cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2895c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28960cddb4a6SGeliang Tang chk_add_nr 1 1 2897ae7bd9ccSMatthieu Baerts fi 28980cddb4a6SGeliang Tang 28990cddb4a6SGeliang Tang # signal address allow join id0 ns2 29000cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 2901c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 290234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 290334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 290434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29050cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2906c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29070cddb4a6SGeliang Tang chk_add_nr 1 1 2908ae7bd9ccSMatthieu Baerts fi 29090cddb4a6SGeliang Tang 29100cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 2911c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 291234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 291334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 291434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 291534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29160cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2917c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2918ae7bd9ccSMatthieu Baerts fi 29190cddb4a6SGeliang Tang 29200cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 2921c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 292234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 292334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 292434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 292534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29260cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2927c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2928ae7bd9ccSMatthieu Baerts fi 29290cddb4a6SGeliang Tang} 29300cddb4a6SGeliang Tang 29314f49d633SGeliang Tangfullmesh_tests() 29324f49d633SGeliang Tang{ 29334f49d633SGeliang Tang # fullmesh 1 29344f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 29354f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 2936c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 293734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 293834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 293934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 294034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 29414f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2942c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 29434f49d633SGeliang Tang chk_add_nr 1 1 2944ae7bd9ccSMatthieu Baerts fi 29454f49d633SGeliang Tang 29464f49d633SGeliang Tang # fullmesh 2 29474f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29484f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 2949c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 295034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 295134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 295234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29534f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow 2954c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 29554f49d633SGeliang Tang chk_add_nr 1 1 2956ae7bd9ccSMatthieu Baerts fi 29574f49d633SGeliang Tang 29584f49d633SGeliang Tang # fullmesh 3 29594f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29604f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 2961c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 296234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 296334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 296434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29654f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2966c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 29674f49d633SGeliang Tang chk_add_nr 1 1 2968ae7bd9ccSMatthieu Baerts fi 29694f49d633SGeliang Tang 29704f49d633SGeliang Tang # fullmesh 4 29714f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29724f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 29734f49d633SGeliang Tang # limit max_subflows to 4. 2974c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 297534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 297634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 297734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29784f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2979c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 29804f49d633SGeliang Tang chk_add_nr 1 1 2981ae7bd9ccSMatthieu Baerts fi 29826a0653b9SGeliang Tang 29836a0653b9SGeliang Tang # set fullmesh flag 2984c7d49c03SMatthieu Baerts if reset "set fullmesh flag test"; then 298534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 298634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 298734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 29886a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow fullmesh 2989c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29906a0653b9SGeliang Tang chk_rm_nr 0 1 2991ae7bd9ccSMatthieu Baerts fi 29926a0653b9SGeliang Tang 29936a0653b9SGeliang Tang # set nofullmesh flag 2994c7d49c03SMatthieu Baerts if reset "set nofullmesh flag test"; then 299534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 299634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 299734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 29986a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow nofullmesh 2999c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30006a0653b9SGeliang Tang chk_rm_nr 0 1 3001ae7bd9ccSMatthieu Baerts fi 30026a0653b9SGeliang Tang 30036a0653b9SGeliang Tang # set backup,fullmesh flags 3004c7d49c03SMatthieu Baerts if reset "set backup,fullmesh flags test"; then 300534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 300634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 300734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 30086a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow backup,fullmesh 3009c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30106a0653b9SGeliang Tang chk_prio_nr 0 1 30116a0653b9SGeliang Tang chk_rm_nr 0 1 3012ae7bd9ccSMatthieu Baerts fi 30136a0653b9SGeliang Tang 30146a0653b9SGeliang Tang # set nobackup,nofullmesh flags 3015c7d49c03SMatthieu Baerts if reset "set nobackup,nofullmesh flags test"; then 301634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 301734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 301834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 30196a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup,nofullmesh 3020c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30216a0653b9SGeliang Tang chk_prio_nr 0 1 30226a0653b9SGeliang Tang chk_rm_nr 0 1 3023ae7bd9ccSMatthieu Baerts fi 30244f49d633SGeliang Tang} 30254f49d633SGeliang Tang 302601542c9bSGeliang Tangfastclose_tests() 302701542c9bSGeliang Tang{ 3028c7d49c03SMatthieu Baerts if reset "fastclose test"; then 30296bf41020SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_client 3030c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 303101542c9bSGeliang Tang chk_fclose_nr 1 1 303201542c9bSGeliang Tang chk_rst_nr 1 1 invert 3033ae7bd9ccSMatthieu Baerts fi 30346bf41020SPaolo Abeni 30356bf41020SPaolo Abeni if reset "fastclose server test"; then 30366bf41020SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_server 30376bf41020SPaolo Abeni chk_join_nr 0 0 0 30386bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 30396bf41020SPaolo Abeni chk_rst_nr 1 1 30406bf41020SPaolo Abeni fi 304101542c9bSGeliang Tang} 304201542c9bSGeliang Tang 3043b6e074e1SGeliang Tangpedit_action_pkts() 3044b6e074e1SGeliang Tang{ 3045b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3046c43ce398SGeliang Tang grep "packets" | \ 3047b6e074e1SGeliang Tang sed 's/.*"packets":\([0-9]\+\),.*/\1/' 3048b6e074e1SGeliang Tang} 3049b6e074e1SGeliang Tang 3050b6e074e1SGeliang Tangfail_tests() 3051b6e074e1SGeliang Tang{ 3052b6e074e1SGeliang Tang # single subflow 3053b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 3054b6e074e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 128 3055b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 30561f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3057b6e074e1SGeliang Tang fi 30582ba18161SGeliang Tang 30592ba18161SGeliang Tang # multiple subflows 30602ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 30612ba18161SGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 30622ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 30632ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 30642ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 30652ba18161SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1024 30662ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 30672ba18161SGeliang Tang fi 3068b6e074e1SGeliang Tang} 3069b6e074e1SGeliang Tang 30705ac1d2d6SMat Martineauuserspace_tests() 30715ac1d2d6SMat Martineau{ 30725ac1d2d6SMat Martineau # userspace pm type prevents add_addr 30735ac1d2d6SMat Martineau if reset "userspace pm type prevents add_addr"; then 30745ac1d2d6SMat Martineau set_userspace_pm $ns1 30755ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 30765ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 30775ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 30785ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 30795ac1d2d6SMat Martineau chk_join_nr 0 0 0 30805ac1d2d6SMat Martineau chk_add_nr 0 0 30815ac1d2d6SMat Martineau fi 30825ac1d2d6SMat Martineau 3083b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3084b3b71bf9SMat Martineau if reset "userspace pm no echo w/o daemon"; then 3085b3b71bf9SMat Martineau set_userspace_pm $ns2 3086b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3087b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3088b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3089b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3090b3b71bf9SMat Martineau chk_join_nr 0 0 0 3091b3b71bf9SMat Martineau chk_add_nr 1 0 3092b3b71bf9SMat Martineau fi 3093b3b71bf9SMat Martineau 30945ac1d2d6SMat Martineau # userspace pm type rejects join 30955ac1d2d6SMat Martineau if reset "userspace pm type rejects join"; then 30965ac1d2d6SMat Martineau set_userspace_pm $ns1 30975ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 30985ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 30995ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31005ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 31015ac1d2d6SMat Martineau chk_join_nr 1 1 0 31025ac1d2d6SMat Martineau fi 31035ac1d2d6SMat Martineau 31045ac1d2d6SMat Martineau # userspace pm type does not send join 31055ac1d2d6SMat Martineau if reset "userspace pm type does not send join"; then 31065ac1d2d6SMat Martineau set_userspace_pm $ns2 31075ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 31085ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 31095ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31105ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 31115ac1d2d6SMat Martineau chk_join_nr 0 0 0 31125ac1d2d6SMat Martineau fi 31135ac1d2d6SMat Martineau 31145ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 31155ac1d2d6SMat Martineau if reset "userspace pm type prevents mp_prio"; then 31165ac1d2d6SMat Martineau set_userspace_pm $ns1 31175ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 31185ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 31195ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31205ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 31215ac1d2d6SMat Martineau chk_join_nr 1 1 0 31225ac1d2d6SMat Martineau chk_prio_nr 0 0 31235ac1d2d6SMat Martineau fi 31245ac1d2d6SMat Martineau 31255ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 31265ac1d2d6SMat Martineau if reset "userspace pm type prevents rm_addr"; then 31275ac1d2d6SMat Martineau set_userspace_pm $ns1 31285ac1d2d6SMat Martineau set_userspace_pm $ns2 31295ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 31305ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 31315ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31325ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 31335ac1d2d6SMat Martineau chk_join_nr 0 0 0 31345ac1d2d6SMat Martineau chk_rm_nr 0 0 31355ac1d2d6SMat Martineau fi 313697040cf9SGeliang Tang 313797040cf9SGeliang Tang # userspace pm add & remove address 3138a3735625SGeliang Tang if reset_with_events "userspace pm add & remove address"; then 313997040cf9SGeliang Tang set_userspace_pm $ns1 314097040cf9SGeliang Tang pm_nl_set_limits $ns2 1 1 314197040cf9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow 314297040cf9SGeliang Tang chk_join_nr 1 1 1 314397040cf9SGeliang Tang chk_add_nr 1 1 314497040cf9SGeliang Tang chk_rm_nr 1 1 invert 3145a3735625SGeliang Tang kill_events_pids 314697040cf9SGeliang Tang fi 31475e986ec4SGeliang Tang 31485e986ec4SGeliang Tang # userspace pm create destroy subflow 3149a3735625SGeliang Tang if reset_with_events "userspace pm create destroy subflow"; then 31505e986ec4SGeliang Tang set_userspace_pm $ns2 31515e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 31525e986ec4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow 31535e986ec4SGeliang Tang chk_join_nr 1 1 1 3154*6c160b63SGeliang Tang chk_rm_nr 1 1 3155a3735625SGeliang Tang kill_events_pids 31565e986ec4SGeliang Tang fi 31575ac1d2d6SMat Martineau} 31585ac1d2d6SMat Martineau 3159e274f715SPaolo Abeniendpoint_tests() 316069c6ce7bSPaolo Abeni{ 316169c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 3162c7d49c03SMatthieu Baerts if reset "implicit EP"; then 316369c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 316469c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 316569c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3166070d6dafSMatthieu Baerts run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2>/dev/null & 316769c6ce7bSPaolo Abeni 316869c6ce7bSPaolo Abeni wait_mpj $ns1 3169c7d49c03SMatthieu Baerts pm_nl_check_endpoint 1 "creation" \ 317069c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 317169c6ce7bSPaolo Abeni 317269c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 33 3173c7d49c03SMatthieu Baerts pm_nl_check_endpoint 0 "ID change is prevented" \ 317469c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 317569c6ce7bSPaolo Abeni 317669c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 3177c7d49c03SMatthieu Baerts pm_nl_check_endpoint 0 "modif is allowed" \ 317869c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3179070d6dafSMatthieu Baerts kill_tests_wait 3180ae7bd9ccSMatthieu Baerts fi 3181e274f715SPaolo Abeni 3182e274f715SPaolo Abeni if reset "delete and re-add"; then 3183e274f715SPaolo Abeni pm_nl_set_limits $ns1 1 1 3184e274f715SPaolo Abeni pm_nl_set_limits $ns2 1 1 3185e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3186070d6dafSMatthieu Baerts run_tests $ns1 $ns2 10.0.1.1 4 0 0 speed_20 2>/dev/null & 3187e274f715SPaolo Abeni 3188e274f715SPaolo Abeni wait_mpj $ns2 31899095ce97SGeliang Tang chk_subflow_nr needtitle "before delete" 2 31909095ce97SGeliang Tang chk_mptcp_info subflows_1 31919095ce97SGeliang Tang 3192e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3193e274f715SPaolo Abeni sleep 0.5 31949095ce97SGeliang Tang chk_subflow_nr "" "after delete" 1 31959095ce97SGeliang Tang chk_mptcp_info subflows_0 3196e274f715SPaolo Abeni 3197e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3198e274f715SPaolo Abeni wait_mpj $ns2 3199e274f715SPaolo Abeni chk_subflow_nr "" "after re-add" 2 32009095ce97SGeliang Tang chk_mptcp_info subflows_1 3201070d6dafSMatthieu Baerts kill_tests_wait 3202e274f715SPaolo Abeni fi 320369c6ce7bSPaolo Abeni} 320469c6ce7bSPaolo Abeni 320522514d52SMatthieu Baerts# [$1: error message] 32061002b89fSGeliang Tangusage() 32071002b89fSGeliang Tang{ 320822514d52SMatthieu Baerts if [ -n "${1}" ]; then 320922514d52SMatthieu Baerts echo "${1}" 321022514d52SMatthieu Baerts ret=1 321122514d52SMatthieu Baerts fi 321222514d52SMatthieu Baerts 32131002b89fSGeliang Tang echo "mptcp_join usage:" 32143afd0280SMatthieu Baerts 32153afd0280SMatthieu Baerts local key 32163afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 32173afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 32183afd0280SMatthieu Baerts done 32193afd0280SMatthieu Baerts 3220a673321aSMat Martineau echo " -c capture pcap files" 3221af66d3e1SGeliang Tang echo " -C enable data checksum" 3222621bd393SGeliang Tang echo " -i use ip mptcp" 32231002b89fSGeliang Tang echo " -h help" 322422514d52SMatthieu Baerts 3225c7d49c03SMatthieu Baerts echo "[test ids|names]" 3226ae7bd9ccSMatthieu Baerts 322722514d52SMatthieu Baerts exit ${ret} 32281002b89fSGeliang Tang} 32291002b89fSGeliang Tang 3230a673321aSMat Martineau 32313afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 32323afd0280SMatthieu Baertsall_tests_sorted=( 32333afd0280SMatthieu Baerts f@subflows_tests 32343afd0280SMatthieu Baerts e@subflows_error_tests 32353afd0280SMatthieu Baerts s@signal_address_tests 32363afd0280SMatthieu Baerts l@link_failure_tests 32373afd0280SMatthieu Baerts t@add_addr_timeout_tests 32383afd0280SMatthieu Baerts r@remove_tests 32393afd0280SMatthieu Baerts a@add_tests 32403afd0280SMatthieu Baerts 6@ipv6_tests 32413afd0280SMatthieu Baerts 4@v4mapped_tests 3242ad349374SPaolo Abeni M@mixed_tests 32433afd0280SMatthieu Baerts b@backup_tests 32443afd0280SMatthieu Baerts p@add_addr_ports_tests 32453afd0280SMatthieu Baerts k@syncookies_tests 32463afd0280SMatthieu Baerts S@checksum_tests 32473afd0280SMatthieu Baerts d@deny_join_id0_tests 32483afd0280SMatthieu Baerts m@fullmesh_tests 32493afd0280SMatthieu Baerts z@fastclose_tests 3250b6e074e1SGeliang Tang F@fail_tests 32515ac1d2d6SMat Martineau u@userspace_tests 3252e274f715SPaolo Abeni I@endpoint_tests 32533afd0280SMatthieu Baerts) 32543afd0280SMatthieu Baerts 32553afd0280SMatthieu Baertsall_tests_args="" 32563afd0280SMatthieu Baertsall_tests_names=() 32573afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 32583afd0280SMatthieu Baerts key="${subtests%@*}" 32593afd0280SMatthieu Baerts value="${subtests#*@}" 32603afd0280SMatthieu Baerts 32613afd0280SMatthieu Baerts all_tests_args+="${key}" 32623afd0280SMatthieu Baerts all_tests_names+=("${value}") 32633afd0280SMatthieu Baerts all_tests[${key}]="${value}" 32643afd0280SMatthieu Baertsdone 32653afd0280SMatthieu Baerts 3266826d7bdcSMatthieu Baertstests=() 32673afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 32681002b89fSGeliang Tang case $opt in 32693afd0280SMatthieu Baerts ["${all_tests_args}"]) 32703afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 327169c6ce7bSPaolo Abeni ;; 3272a673321aSMat Martineau c) 3273826d7bdcSMatthieu Baerts capture=1 3274a673321aSMat Martineau ;; 3275af66d3e1SGeliang Tang C) 3276826d7bdcSMatthieu Baerts checksum=1 3277af66d3e1SGeliang Tang ;; 3278621bd393SGeliang Tang i) 3279826d7bdcSMatthieu Baerts ip_mptcp=1 3280621bd393SGeliang Tang ;; 328122514d52SMatthieu Baerts h) 32821002b89fSGeliang Tang usage 32831002b89fSGeliang Tang ;; 328422514d52SMatthieu Baerts *) 328522514d52SMatthieu Baerts usage "Unknown option: -${opt}" 328622514d52SMatthieu Baerts ;; 32871002b89fSGeliang Tang esac 32881002b89fSGeliang Tangdone 328900587187SFlorian Westphal 3290ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3291ae7bd9ccSMatthieu Baerts 3292ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3293ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3294c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3295ae7bd9ccSMatthieu Baerts else 3296c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3297ae7bd9ccSMatthieu Baerts fi 3298ae7bd9ccSMatthieu Baertsdone 3299ae7bd9ccSMatthieu Baerts 3300826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 33013afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 33023afd0280SMatthieu Baertsfi 33033afd0280SMatthieu Baerts 3304826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3305826d7bdcSMatthieu Baerts "${subtests}" 3306826d7bdcSMatthieu Baertsdone 3307826d7bdcSMatthieu Baerts 330839aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 330939aab882SMatthieu Baerts echo 331039aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 331139aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 331239aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 331339aab882SMatthieu Baerts done 331439aab882SMatthieu Baerts echo 331539aab882SMatthieu Baertsfi 331639aab882SMatthieu Baerts 3317b08fbf24SPaolo Abeniexit $ret 3318