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="" 241b8af4baSGeliang Tangerr="" 251e777bd8SMatthieu Baertscapout="" 261e777bd8SMatthieu Baertsns1="" 271e777bd8SMatthieu Baertsns2="" 28b08fbf24SPaolo Abeniksft_skip=4 290c4cd3f8SMatthieu Baertsiptables="iptables" 300c4cd3f8SMatthieu Baertsip6tables="ip6tables" 315888a61cSMatthieu Baertstimeout_poll=30 325888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1)) 33b08fbf24SPaolo Abenicapture=0 34af66d3e1SGeliang Tangchecksum=0 3534aa6e3bSGeliang Tangip_mptcp=0 368117dac3SGeliang Tangcheck_invert=0 373c082695SGeliang Tangvalidate_checksum=0 3893827ad5SMatthieu Baertsinit=0 39a3735625SGeliang Tangevts_ns1="" 40a3735625SGeliang Tangevts_ns2="" 41a3735625SGeliang Tangevts_ns1_pid=0 42a3735625SGeliang Tangevts_ns2_pid=0 437f117cd3SMatthieu Baertslast_test_failed=0 447f117cd3SMatthieu Baertslast_test_skipped=0 457f117cd3SMatthieu Baertslast_test_ignored=1 46b08fbf24SPaolo Abeni 473afd0280SMatthieu Baertsdeclare -A all_tests 48c7d49c03SMatthieu Baertsdeclare -a only_tests_ids 49c7d49c03SMatthieu Baertsdeclare -a only_tests_names 5039aab882SMatthieu Baertsdeclare -A failed_tests 51b08fbf24SPaolo AbeniTEST_COUNT=0 52c7d49c03SMatthieu BaertsTEST_NAME="" 5303668c65SMatthieu Baertsnr_blank=6 54b08fbf24SPaolo Abeni 55662aa22dSGeliang Tang# These var are used only in some tests, make sure they are not already set 56662aa22dSGeliang Tangunset FAILING_LINKS 57662aa22dSGeliang Tangunset test_linkfail 58662aa22dSGeliang Tangunset addr_nr_ns1 59662aa22dSGeliang Tangunset addr_nr_ns2 60662aa22dSGeliang Tangunset sflags 61080b7f57SGeliang Tangunset fastclose 624aadde08SGeliang Tangunset fullmesh 63e571fb09SGeliang Tangunset speed 64e59300ceSMatthieu Baerts 658d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 668d014eaaSGeliang Tang# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 678d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 688d014eaaSGeliang Tang 48 0 0 0, 698d014eaaSGeliang Tang 84 0 0 240, 708d014eaaSGeliang Tang 21 0 3 64, 718d014eaaSGeliang Tang 48 0 0 54, 728d014eaaSGeliang Tang 84 0 0 240, 738d014eaaSGeliang Tang 21 6 7 48, 748d014eaaSGeliang Tang 48 0 0 0, 758d014eaaSGeliang Tang 84 0 0 240, 768d014eaaSGeliang Tang 21 0 4 96, 778d014eaaSGeliang Tang 48 0 0 74, 788d014eaaSGeliang Tang 84 0 0 240, 798d014eaaSGeliang Tang 21 0 1 48, 808d014eaaSGeliang Tang 6 0 0 65535, 818d014eaaSGeliang Tang 6 0 0 0" 828d014eaaSGeliang Tang 8393827ad5SMatthieu Baertsinit_partial() 84b08fbf24SPaolo Abeni{ 85b08fbf24SPaolo Abeni capout=$(mktemp) 86b08fbf24SPaolo Abeni 87787eb1e4SMatthieu Baerts local sec rndh 88787eb1e4SMatthieu Baerts sec=$(date +%s) 89787eb1e4SMatthieu Baerts rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 90b08fbf24SPaolo Abeni 91b08fbf24SPaolo Abeni ns1="ns1-$rndh" 92b08fbf24SPaolo Abeni ns2="ns2-$rndh" 93b08fbf24SPaolo Abeni 941e777bd8SMatthieu Baerts local netns 95b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 96b08fbf24SPaolo Abeni ip netns add $netns || exit $ksft_skip 97b08fbf24SPaolo Abeni ip -net $netns link set lo up 98b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.mptcp.enabled=1 99f2b492b0SMatthieu Baerts ip netns exec $netns sysctl -q net.mptcp.pm_type=0 2>/dev/null || true 100b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 101b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 102af66d3e1SGeliang Tang if [ $checksum -eq 1 ]; then 103af66d3e1SGeliang Tang ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 104af66d3e1SGeliang Tang fi 105b08fbf24SPaolo Abeni done 106b08fbf24SPaolo Abeni 1078117dac3SGeliang Tang check_invert=0 1083c082695SGeliang Tang validate_checksum=$checksum 1098117dac3SGeliang Tang 110b08fbf24SPaolo Abeni # ns1 ns2 111b08fbf24SPaolo Abeni # ns1eth1 ns2eth1 112b08fbf24SPaolo Abeni # ns1eth2 ns2eth2 113b08fbf24SPaolo Abeni # ns1eth3 ns2eth3 114b08fbf24SPaolo Abeni # ns1eth4 ns2eth4 115b08fbf24SPaolo Abeni 1161e777bd8SMatthieu Baerts local i 1174bfadd71SMatthieu Baerts for i in $(seq 1 4); do 118b08fbf24SPaolo Abeni ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 119b08fbf24SPaolo Abeni ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 120b08fbf24SPaolo Abeni ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 121b08fbf24SPaolo Abeni ip -net "$ns1" link set ns1eth$i up 122b08fbf24SPaolo Abeni 123b08fbf24SPaolo Abeni ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 124b08fbf24SPaolo Abeni ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 125b08fbf24SPaolo Abeni ip -net "$ns2" link set ns2eth$i up 126b08fbf24SPaolo Abeni 127b08fbf24SPaolo Abeni # let $ns2 reach any $ns1 address from any interface 128b08fbf24SPaolo Abeni ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 1299846921dSPaolo Abeni ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 130b08fbf24SPaolo Abeni done 131b08fbf24SPaolo Abeni} 132b08fbf24SPaolo Abeni 1337d1e6f16SPaolo Abeniinit_shapers() 1347d1e6f16SPaolo Abeni{ 1351e777bd8SMatthieu Baerts local i 1364bfadd71SMatthieu Baerts for i in $(seq 1 4); do 13799ac814eSGeliang Tang tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1ms 13899ac814eSGeliang Tang tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1ms 1397d1e6f16SPaolo Abeni done 1407d1e6f16SPaolo Abeni} 1417d1e6f16SPaolo Abeni 142b08fbf24SPaolo Abenicleanup_partial() 143b08fbf24SPaolo Abeni{ 144b08fbf24SPaolo Abeni rm -f "$capout" 145b08fbf24SPaolo Abeni 1461e777bd8SMatthieu Baerts local netns 147b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 148b08fbf24SPaolo Abeni ip netns del $netns 149c2a55e8fSMatthieu Baerts rm -f /tmp/$netns.{nstat,out} 150b08fbf24SPaolo Abeni done 151b08fbf24SPaolo Abeni} 152b08fbf24SPaolo Abeni 15387154755SMatthieu Baertscheck_tools() 15487154755SMatthieu Baerts{ 155715c78a8SMatthieu Baerts mptcp_lib_check_mptcp 156cdb50525SMatthieu Baerts mptcp_lib_check_kallsyms 157715c78a8SMatthieu Baerts 15887154755SMatthieu Baerts if ! ip -Version &> /dev/null; then 15987154755SMatthieu Baerts echo "SKIP: Could not run test without ip tool" 16087154755SMatthieu Baerts exit $ksft_skip 16187154755SMatthieu Baerts fi 16287154755SMatthieu Baerts 163536a661bSGeliang Tang if ! ss -h | grep -q MPTCP; then 164536a661bSGeliang Tang echo "SKIP: ss tool does not support MPTCP" 165536a661bSGeliang Tang exit $ksft_skip 166536a661bSGeliang Tang fi 167536a661bSGeliang Tang 1680c4cd3f8SMatthieu Baerts # Use the legacy version if available to support old kernel versions 1690c4cd3f8SMatthieu Baerts if iptables-legacy -V &> /dev/null; then 1700c4cd3f8SMatthieu Baerts iptables="iptables-legacy" 1710c4cd3f8SMatthieu Baerts ip6tables="ip6tables-legacy" 1720c4cd3f8SMatthieu Baerts elif ! iptables -V &> /dev/null; then 17387154755SMatthieu Baerts echo "SKIP: Could not run all tests without iptables tool" 17487154755SMatthieu Baerts exit $ksft_skip 175016e7ba4SMatthieu Baerts elif ! ip6tables -V &> /dev/null; then 17687154755SMatthieu Baerts echo "SKIP: Could not run all tests without ip6tables tool" 17787154755SMatthieu Baerts exit $ksft_skip 17887154755SMatthieu Baerts fi 17987154755SMatthieu Baerts} 18087154755SMatthieu Baerts 18193827ad5SMatthieu Baertsinit() { 18293827ad5SMatthieu Baerts init=1 18393827ad5SMatthieu Baerts 18487154755SMatthieu Baerts check_tools 18587154755SMatthieu Baerts 18693827ad5SMatthieu Baerts sin=$(mktemp) 18793827ad5SMatthieu Baerts sout=$(mktemp) 18893827ad5SMatthieu Baerts cin=$(mktemp) 18993827ad5SMatthieu Baerts cinsent=$(mktemp) 19093827ad5SMatthieu Baerts cout=$(mktemp) 1911b8af4baSGeliang Tang err=$(mktemp) 192a3735625SGeliang Tang evts_ns1=$(mktemp) 193a3735625SGeliang Tang evts_ns2=$(mktemp) 19493827ad5SMatthieu Baerts 19593827ad5SMatthieu Baerts trap cleanup EXIT 19693827ad5SMatthieu Baerts 19703668c65SMatthieu Baerts make_file "$cin" "client" 1 >/dev/null 19803668c65SMatthieu Baerts make_file "$sin" "server" 1 >/dev/null 19993827ad5SMatthieu Baerts} 20093827ad5SMatthieu Baerts 201b08fbf24SPaolo Abenicleanup() 202b08fbf24SPaolo Abeni{ 2037d1e6f16SPaolo Abeni rm -f "$cin" "$cout" "$sinfail" 2047d1e6f16SPaolo Abeni rm -f "$sin" "$sout" "$cinsent" "$cinfail" 205d328fe87SMatthieu Baerts rm -f "$tmpfile" 206a3735625SGeliang Tang rm -rf $evts_ns1 $evts_ns2 2071b8af4baSGeliang Tang rm -f "$err" 208b08fbf24SPaolo Abeni cleanup_partial 209b08fbf24SPaolo Abeni} 210b08fbf24SPaolo Abeni 211cdb50525SMatthieu Baertsprint_title() 212cdb50525SMatthieu Baerts{ 21303668c65SMatthieu Baerts printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}" 21403668c65SMatthieu Baerts} 21503668c65SMatthieu Baerts 21603668c65SMatthieu Baertsprint_check() 21703668c65SMatthieu Baerts{ 21803668c65SMatthieu Baerts printf "%-${nr_blank}s%-36s" " " "${*}" 21903668c65SMatthieu Baerts} 22003668c65SMatthieu Baerts 22103668c65SMatthieu Baertsprint_info() 22203668c65SMatthieu Baerts{ 22303668c65SMatthieu Baerts # It can be empty, no need to print anything then 22403668c65SMatthieu Baerts [ -z "${1}" ] && return 22503668c65SMatthieu Baerts 2269466df1aSMatthieu Baerts mptcp_lib_print_info " Info: ${*}" 22703668c65SMatthieu Baerts} 22803668c65SMatthieu Baerts 22903668c65SMatthieu Baertsprint_ok() 23003668c65SMatthieu Baerts{ 2319466df1aSMatthieu Baerts mptcp_lib_print_ok "[ ok ]${1:+ ${*}}" 23203668c65SMatthieu Baerts} 23303668c65SMatthieu Baerts 23403668c65SMatthieu Baertsprint_fail() 23503668c65SMatthieu Baerts{ 2369466df1aSMatthieu Baerts mptcp_lib_print_err "[fail]${1:+ ${*}}" 23703668c65SMatthieu Baerts} 23803668c65SMatthieu Baerts 23903668c65SMatthieu Baertsprint_skip() 24003668c65SMatthieu Baerts{ 2419466df1aSMatthieu Baerts mptcp_lib_print_warn "[skip]${1:+ ${*}}" 242cdb50525SMatthieu Baerts} 243cdb50525SMatthieu Baerts 244cdb50525SMatthieu Baerts# [ $1: fail msg ] 245cdb50525SMatthieu Baertsmark_as_skipped() 246cdb50525SMatthieu Baerts{ 247cdb50525SMatthieu Baerts local msg="${1:-"Feature not supported"}" 248cdb50525SMatthieu Baerts 249cdb50525SMatthieu Baerts mptcp_lib_fail_if_expected_feature "${msg}" 250cdb50525SMatthieu Baerts 25103668c65SMatthieu Baerts print_check "${msg}" 25203668c65SMatthieu Baerts print_skip 2537f117cd3SMatthieu Baerts 2547f117cd3SMatthieu Baerts last_test_skipped=1 255cdb50525SMatthieu Baerts} 256cdb50525SMatthieu Baerts 257cdb50525SMatthieu Baerts# $@: condition 258cdb50525SMatthieu Baertscontinue_if() 259cdb50525SMatthieu Baerts{ 260cdb50525SMatthieu Baerts if ! "${@}"; then 261cdb50525SMatthieu Baerts mark_as_skipped 262cdb50525SMatthieu Baerts return 1 263cdb50525SMatthieu Baerts fi 264cdb50525SMatthieu Baerts} 265cdb50525SMatthieu Baerts 266ae7bd9ccSMatthieu Baertsskip_test() 267ae7bd9ccSMatthieu Baerts{ 268c7d49c03SMatthieu Baerts if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 269ae7bd9ccSMatthieu Baerts return 1 270ae7bd9ccSMatthieu Baerts fi 271ae7bd9ccSMatthieu Baerts 272ae7bd9ccSMatthieu Baerts local i 273c7d49c03SMatthieu Baerts for i in "${only_tests_ids[@]}"; do 274ae7bd9ccSMatthieu Baerts if [ "${TEST_COUNT}" -eq "${i}" ]; then 275ae7bd9ccSMatthieu Baerts return 1 276ae7bd9ccSMatthieu Baerts fi 277ae7bd9ccSMatthieu Baerts done 278c7d49c03SMatthieu Baerts for i in "${only_tests_names[@]}"; do 279c7d49c03SMatthieu Baerts if [ "${TEST_NAME}" = "${i}" ]; then 280c7d49c03SMatthieu Baerts return 1 281c7d49c03SMatthieu Baerts fi 282c7d49c03SMatthieu Baerts done 283ae7bd9ccSMatthieu Baerts 284ae7bd9ccSMatthieu Baerts return 0 285ae7bd9ccSMatthieu Baerts} 286ae7bd9ccSMatthieu Baerts 2877f117cd3SMatthieu Baertsappend_prev_results() 2887f117cd3SMatthieu Baerts{ 2897f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 1 ]; then 2907f117cd3SMatthieu Baerts mptcp_lib_result_fail "${TEST_NAME}" 2917f117cd3SMatthieu Baerts elif [ ${last_test_skipped} -eq 1 ]; then 2927f117cd3SMatthieu Baerts mptcp_lib_result_skip "${TEST_NAME}" 2937f117cd3SMatthieu Baerts elif [ ${last_test_ignored} -ne 1 ]; then 2947f117cd3SMatthieu Baerts mptcp_lib_result_pass "${TEST_NAME}" 2957f117cd3SMatthieu Baerts fi 2967f117cd3SMatthieu Baerts 2977f117cd3SMatthieu Baerts last_test_failed=0 2987f117cd3SMatthieu Baerts last_test_skipped=0 2997f117cd3SMatthieu Baerts last_test_ignored=0 3007f117cd3SMatthieu Baerts} 3017f117cd3SMatthieu Baerts 302c7d49c03SMatthieu Baerts# $1: test name 303b08fbf24SPaolo Abenireset() 304b08fbf24SPaolo Abeni{ 3057f117cd3SMatthieu Baerts append_prev_results 3067f117cd3SMatthieu Baerts 307c7d49c03SMatthieu Baerts TEST_NAME="${1}" 308c7d49c03SMatthieu Baerts 309ae7bd9ccSMatthieu Baerts TEST_COUNT=$((TEST_COUNT+1)) 310ae7bd9ccSMatthieu Baerts 311ae7bd9ccSMatthieu Baerts if skip_test; then 3127f117cd3SMatthieu Baerts last_test_ignored=1 313ae7bd9ccSMatthieu Baerts return 1 314ae7bd9ccSMatthieu Baerts fi 315ae7bd9ccSMatthieu Baerts 31603668c65SMatthieu Baerts print_title 31703668c65SMatthieu Baerts 31893827ad5SMatthieu Baerts if [ "${init}" != "1" ]; then 319b08fbf24SPaolo Abeni init 32093827ad5SMatthieu Baerts else 32193827ad5SMatthieu Baerts cleanup_partial 32293827ad5SMatthieu Baerts fi 32393827ad5SMatthieu Baerts 32493827ad5SMatthieu Baerts init_partial 325ae7bd9ccSMatthieu Baerts 326ae7bd9ccSMatthieu Baerts return 0 327b08fbf24SPaolo Abeni} 328b08fbf24SPaolo Abeni 329ae947bb2SMatthieu Baerts# $1: test name ; $2: counter to check 330ae947bb2SMatthieu Baertsreset_check_counter() 331ae947bb2SMatthieu Baerts{ 332ae947bb2SMatthieu Baerts reset "${1}" || return 1 333ae947bb2SMatthieu Baerts 334ae947bb2SMatthieu Baerts local counter="${2}" 335ae947bb2SMatthieu Baerts 336ae947bb2SMatthieu Baerts if ! nstat -asz "${counter}" | grep -wq "${counter}"; then 337ae947bb2SMatthieu Baerts mark_as_skipped "counter '${counter}' is not available" 338ae947bb2SMatthieu Baerts return 1 339ae947bb2SMatthieu Baerts fi 340ae947bb2SMatthieu Baerts} 341ae947bb2SMatthieu Baerts 342c7d49c03SMatthieu Baerts# $1: test name 34300587187SFlorian Westphalreset_with_cookies() 34400587187SFlorian Westphal{ 345c7d49c03SMatthieu Baerts reset "${1}" || return 1 34600587187SFlorian Westphal 3471e777bd8SMatthieu Baerts local netns 34800587187SFlorian Westphal for netns in "$ns1" "$ns2"; do 34900587187SFlorian Westphal ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 35000587187SFlorian Westphal done 35100587187SFlorian Westphal} 35200587187SFlorian Westphal 353c7d49c03SMatthieu Baerts# $1: test name 3548d014eaaSGeliang Tangreset_with_add_addr_timeout() 3558d014eaaSGeliang Tang{ 356c7d49c03SMatthieu Baerts local ip="${2:-4}" 3578d014eaaSGeliang Tang local tables 3588d014eaaSGeliang Tang 359c7d49c03SMatthieu Baerts reset "${1}" || return 1 360c7d49c03SMatthieu Baerts 3610c4cd3f8SMatthieu Baerts tables="${iptables}" 3628d014eaaSGeliang Tang if [ $ip -eq 6 ]; then 3630c4cd3f8SMatthieu Baerts tables="${ip6tables}" 3648d014eaaSGeliang Tang fi 3658d014eaaSGeliang Tang 3668d014eaaSGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 3674a0b866aSMatthieu Baerts 3684a0b866aSMatthieu Baerts if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 3698d014eaaSGeliang Tang -m tcp --tcp-option 30 \ 3708d014eaaSGeliang Tang -m bpf --bytecode \ 3718d014eaaSGeliang Tang "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 3724a0b866aSMatthieu Baerts -j DROP; then 3734a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'add addr' rule" 3744a0b866aSMatthieu Baerts return 1 3754a0b866aSMatthieu Baerts fi 3768d014eaaSGeliang Tang} 3778d014eaaSGeliang Tang 378c7d49c03SMatthieu Baerts# $1: test name 379af66d3e1SGeliang Tangreset_with_checksum() 380af66d3e1SGeliang Tang{ 381af66d3e1SGeliang Tang local ns1_enable=$1 382af66d3e1SGeliang Tang local ns2_enable=$2 383af66d3e1SGeliang Tang 384c7d49c03SMatthieu Baerts reset "checksum test ${1} ${2}" || return 1 385af66d3e1SGeliang Tang 386af66d3e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 387af66d3e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 3883c082695SGeliang Tang 3893c082695SGeliang Tang validate_checksum=1 390af66d3e1SGeliang Tang} 391af66d3e1SGeliang Tang 3920cddb4a6SGeliang Tangreset_with_allow_join_id0() 3930cddb4a6SGeliang Tang{ 394c7d49c03SMatthieu Baerts local ns1_enable=$2 395c7d49c03SMatthieu Baerts local ns2_enable=$3 3960cddb4a6SGeliang Tang 397c7d49c03SMatthieu Baerts reset "${1}" || return 1 3980cddb4a6SGeliang Tang 3990cddb4a6SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 4000cddb4a6SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 4010cddb4a6SGeliang Tang} 4020cddb4a6SGeliang Tang 403b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet 404b6e074e1SGeliang Tang# 405b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 406b6e074e1SGeliang Tang# carrying enough data. 407b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still 408b6e074e1SGeliang Tang# considered as valid at the TCP level. 409b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been 410b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted: 411b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options. 412b6e074e1SGeliang Tang# 413b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets 414b6e074e1SGeliang Tang# not carrying enough data: 415b6e074e1SGeliang Tang# 416b6e074e1SGeliang Tang# tc action pedit offset 162 out of bounds 417b6e074e1SGeliang Tang# 418b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data. 4194a0b866aSMatthieu Baertssetup_fail_rules() 420b6e074e1SGeliang Tang{ 421b6e074e1SGeliang Tang check_invert=1 422b6e074e1SGeliang Tang validate_checksum=1 4234a0b866aSMatthieu Baerts local i="$1" 4244a0b866aSMatthieu Baerts local ip="${2:-4}" 425b6e074e1SGeliang Tang local tables 426b6e074e1SGeliang Tang 4270c4cd3f8SMatthieu Baerts tables="${iptables}" 428b6e074e1SGeliang Tang if [ $ip -eq 6 ]; then 4290c4cd3f8SMatthieu Baerts tables="${ip6tables}" 430b6e074e1SGeliang Tang fi 431b6e074e1SGeliang Tang 432b6e074e1SGeliang Tang ip netns exec $ns2 $tables \ 433b6e074e1SGeliang Tang -t mangle \ 434b6e074e1SGeliang Tang -A OUTPUT \ 435b6e074e1SGeliang Tang -o ns2eth$i \ 436b6e074e1SGeliang Tang -p tcp \ 437b6e074e1SGeliang Tang -m length --length 150:9999 \ 438b6e074e1SGeliang Tang -m statistic --mode nth --packet 1 --every 99999 \ 4394a0b866aSMatthieu Baerts -j MARK --set-mark 42 || return ${ksft_skip} 440b6e074e1SGeliang Tang 4414a0b866aSMatthieu Baerts tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${ksft_skip} 442b6e074e1SGeliang Tang tc -n $ns2 filter add dev ns2eth$i egress \ 443b6e074e1SGeliang Tang protocol ip prio 1000 \ 444b6e074e1SGeliang Tang handle 42 fw \ 445b6e074e1SGeliang Tang action pedit munge offset 148 u8 invert \ 446b6e074e1SGeliang Tang pipe csum tcp \ 4474a0b866aSMatthieu Baerts index 100 || return ${ksft_skip} 4484a0b866aSMatthieu Baerts} 4494a0b866aSMatthieu Baerts 4504a0b866aSMatthieu Baertsreset_with_fail() 4514a0b866aSMatthieu Baerts{ 452ff8897b5SMatthieu Baerts reset_check_counter "${1}" "MPTcpExtInfiniteMapTx" || return 1 4534a0b866aSMatthieu Baerts shift 4544a0b866aSMatthieu Baerts 4554a0b866aSMatthieu Baerts ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 4564a0b866aSMatthieu Baerts ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 4574a0b866aSMatthieu Baerts 4584a0b866aSMatthieu Baerts local rc=0 4594a0b866aSMatthieu Baerts setup_fail_rules "${@}" || rc=$? 4604a0b866aSMatthieu Baerts 4614a0b866aSMatthieu Baerts if [ ${rc} -eq ${ksft_skip} ]; then 4624a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'fail' rules" 4634a0b866aSMatthieu Baerts return 1 4644a0b866aSMatthieu Baerts fi 465b6e074e1SGeliang Tang} 466b6e074e1SGeliang Tang 467a417ef47SMatthieu Baerts (NGI0)start_events() 468a417ef47SMatthieu Baerts (NGI0){ 469a417ef47SMatthieu Baerts (NGI0) mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid 470a417ef47SMatthieu Baerts (NGI0) mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid 471a417ef47SMatthieu Baerts (NGI0)} 472a417ef47SMatthieu Baerts (NGI0) 473a3735625SGeliang Tangreset_with_events() 474a3735625SGeliang Tang{ 475a3735625SGeliang Tang reset "${1}" || return 1 476a3735625SGeliang Tang 477a417ef47SMatthieu Baerts (NGI0) start_events 478a3735625SGeliang Tang} 479a3735625SGeliang Tang 4804a0b866aSMatthieu Baertsreset_with_tcp_filter() 4814a0b866aSMatthieu Baerts{ 4824a0b866aSMatthieu Baerts reset "${1}" || return 1 4834a0b866aSMatthieu Baerts shift 4844a0b866aSMatthieu Baerts 4854a0b866aSMatthieu Baerts local ns="${!1}" 4864a0b866aSMatthieu Baerts local src="${2}" 4874a0b866aSMatthieu Baerts local target="${3}" 488ce2f28a5SMatthieu Baerts (NGI0) local chain="${4:-INPUT}" 4894a0b866aSMatthieu Baerts 4904a0b866aSMatthieu Baerts if ! ip netns exec "${ns}" ${iptables} \ 491ce2f28a5SMatthieu Baerts (NGI0) -A "${chain}" \ 4924a0b866aSMatthieu Baerts -s "${src}" \ 4934a0b866aSMatthieu Baerts -p tcp \ 4944a0b866aSMatthieu Baerts -j "${target}"; then 4954a0b866aSMatthieu Baerts mark_as_skipped "unable to set the filter rules" 4964a0b866aSMatthieu Baerts return 1 4974a0b866aSMatthieu Baerts fi 4984a0b866aSMatthieu Baerts} 4994a0b866aSMatthieu Baerts 50003668c65SMatthieu Baerts# $1: err msg 50139aab882SMatthieu Baertsfail_test() 50239aab882SMatthieu Baerts{ 50339aab882SMatthieu Baerts ret=1 504985de459SPaolo Abeni 50503668c65SMatthieu Baerts print_fail "${@}" 50603668c65SMatthieu Baerts 5077f117cd3SMatthieu Baerts # just in case a test is marked twice as failed 5087f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 0 ]; then 5097f117cd3SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 5107f117cd3SMatthieu Baerts dump_stats 5117f117cd3SMatthieu Baerts last_test_failed=1 5127f117cd3SMatthieu Baerts fi 51339aab882SMatthieu Baerts} 51439aab882SMatthieu Baerts 51539aab882SMatthieu Baertsget_failed_tests_ids() 51639aab882SMatthieu Baerts{ 51739aab882SMatthieu Baerts # sorted 51839aab882SMatthieu Baerts local i 51939aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 52039aab882SMatthieu Baerts echo "${i}" 52139aab882SMatthieu Baerts done | sort -n 52239aab882SMatthieu Baerts} 52339aab882SMatthieu Baerts 5248b819a84SFlorian Westphalprint_file_err() 5258b819a84SFlorian Westphal{ 5268b819a84SFlorian Westphal ls -l "$1" 1>&2 52703668c65SMatthieu Baerts echo -n "Trailing bytes are: " 5288b819a84SFlorian Westphal tail -c 27 "$1" 5298b819a84SFlorian Westphal} 5308b819a84SFlorian Westphal 531b08fbf24SPaolo Abenicheck_transfer() 532b08fbf24SPaolo Abeni{ 5331e777bd8SMatthieu Baerts local in=$1 5341e777bd8SMatthieu Baerts local out=$2 5351e777bd8SMatthieu Baerts local what=$3 5366bf41020SPaolo Abeni local bytes=$4 537d8d08302SMatthieu Baerts local i a b 538b08fbf24SPaolo Abeni 5391e777bd8SMatthieu Baerts local line 5406bf41020SPaolo Abeni if [ -n "$bytes" ]; then 5410fcd72dfSMatthieu Baerts local out_size 5426bf41020SPaolo Abeni # when truncating we must check the size explicitly 5430fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 5446bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 54503668c65SMatthieu Baerts fail_test "$what output file has wrong size ($out_size, $bytes)" 5466bf41020SPaolo Abeni return 1 5476bf41020SPaolo Abeni fi 548d328fe87SMatthieu Baerts 549d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 550d328fe87SMatthieu Baerts tmpfile=$(mktemp) 551d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 552d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 553d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 554d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 555d328fe87SMatthieu Baerts tmpfile="" 5566bf41020SPaolo Abeni fi 557d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 558d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 5598117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 56003668c65SMatthieu Baerts fail_test "$what does not match (in, out):" 561b08fbf24SPaolo Abeni print_file_err "$in" 562b08fbf24SPaolo Abeni print_file_err "$out" 563b08fbf24SPaolo Abeni 564b08fbf24SPaolo Abeni return 1 5658117dac3SGeliang Tang else 56603668c65SMatthieu Baerts print_info "$what has inverted byte at ${i}" 567b08fbf24SPaolo Abeni fi 5688117dac3SGeliang Tang done 569b08fbf24SPaolo Abeni 570b08fbf24SPaolo Abeni return 0 571b08fbf24SPaolo Abeni} 572b08fbf24SPaolo Abeni 573b08fbf24SPaolo Abenido_ping() 574b08fbf24SPaolo Abeni{ 5751e777bd8SMatthieu Baerts local listener_ns="$1" 5761e777bd8SMatthieu Baerts local connector_ns="$2" 5771e777bd8SMatthieu Baerts local connect_addr="$3" 578b08fbf24SPaolo Abeni 579d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 58003668c65SMatthieu Baerts fail_test "$listener_ns -> $connect_addr connectivity" 581b08fbf24SPaolo Abeni fi 582b08fbf24SPaolo Abeni} 583b08fbf24SPaolo Abeni 5848b819a84SFlorian Westphallink_failure() 5858b819a84SFlorian Westphal{ 5861e777bd8SMatthieu Baerts local ns="$1" 5878b819a84SFlorian Westphal 5887d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 5898b819a84SFlorian Westphal l=$((RANDOM%4)) 5907d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 5917d1e6f16SPaolo Abeni fi 5928b819a84SFlorian Westphal 5931e777bd8SMatthieu Baerts local l 5947d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 5951e777bd8SMatthieu Baerts local veth="ns1eth$l" 5968b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 5977d1e6f16SPaolo Abeni done 5988b819a84SFlorian Westphal} 5998b819a84SFlorian Westphal 600327b9a94SPaolo Abeni# $1: ns, $2: port 601327b9a94SPaolo Abeniwait_local_port_listen() 602327b9a94SPaolo Abeni{ 603327b9a94SPaolo Abeni local listener_ns="${1}" 604327b9a94SPaolo Abeni local port="${2}" 605327b9a94SPaolo Abeni 6061e777bd8SMatthieu Baerts local port_hex 607327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 6081e777bd8SMatthieu Baerts 6091e777bd8SMatthieu Baerts local i 610327b9a94SPaolo Abeni for i in $(seq 10); do 611327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 612327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 613327b9a94SPaolo Abeni break 614327b9a94SPaolo Abeni sleep 0.1 615327b9a94SPaolo Abeni done 616327b9a94SPaolo Abeni} 617327b9a94SPaolo Abeni 618327b9a94SPaolo Abenirm_addr_count() 619327b9a94SPaolo Abeni{ 620697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr" 621327b9a94SPaolo Abeni} 622327b9a94SPaolo Abeni 623327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 624327b9a94SPaolo Abeniwait_rm_addr() 625327b9a94SPaolo Abeni{ 626327b9a94SPaolo Abeni local ns="${1}" 627327b9a94SPaolo Abeni local old_cnt="${2}" 628327b9a94SPaolo Abeni local cnt 629327b9a94SPaolo Abeni 6301e777bd8SMatthieu Baerts local i 631327b9a94SPaolo Abeni for i in $(seq 10); do 632327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 633327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 634327b9a94SPaolo Abeni sleep 0.1 635327b9a94SPaolo Abeni done 636327b9a94SPaolo Abeni} 637327b9a94SPaolo Abeni 6384369c198SGeliang Tangrm_sf_count() 6394369c198SGeliang Tang{ 640697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow" 6414369c198SGeliang Tang} 6424369c198SGeliang Tang 6434369c198SGeliang Tang# $1: ns, $2: old rm_sf counter in $ns 6444369c198SGeliang Tangwait_rm_sf() 6454369c198SGeliang Tang{ 6464369c198SGeliang Tang local ns="${1}" 6474369c198SGeliang Tang local old_cnt="${2}" 6484369c198SGeliang Tang local cnt 6494369c198SGeliang Tang 6504369c198SGeliang Tang local i 6514369c198SGeliang Tang for i in $(seq 10); do 6524369c198SGeliang Tang cnt=$(rm_sf_count ${ns}) 6534369c198SGeliang Tang [ "$cnt" = "${old_cnt}" ] || break 6544369c198SGeliang Tang sleep 0.1 6554369c198SGeliang Tang done 6564369c198SGeliang Tang} 6574369c198SGeliang Tang 65869c6ce7bSPaolo Abeniwait_mpj() 65969c6ce7bSPaolo Abeni{ 66069c6ce7bSPaolo Abeni local ns="${1}" 66169c6ce7bSPaolo Abeni local cnt old_cnt 66269c6ce7bSPaolo Abeni 663697128a3SGeliang Tang old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 66469c6ce7bSPaolo Abeni 66569c6ce7bSPaolo Abeni local i 66669c6ce7bSPaolo Abeni for i in $(seq 10); do 667697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 66869c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 66969c6ce7bSPaolo Abeni sleep 0.1 67069c6ce7bSPaolo Abeni done 67169c6ce7bSPaolo Abeni} 67269c6ce7bSPaolo Abeni 673a3735625SGeliang Tangkill_events_pids() 674a3735625SGeliang Tang{ 6751fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns1_pid 676b66609e9SGeliang Tang evts_ns1_pid=0 6771fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns2_pid 678b66609e9SGeliang Tang evts_ns2_pid=0 679a3735625SGeliang Tang} 680a3735625SGeliang Tang 68134aa6e3bSGeliang Tangpm_nl_set_limits() 68234aa6e3bSGeliang Tang{ 68334aa6e3bSGeliang Tang local ns=$1 68434aa6e3bSGeliang Tang local addrs=$2 68534aa6e3bSGeliang Tang local subflows=$3 68634aa6e3bSGeliang Tang 68734aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 68834aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 68934aa6e3bSGeliang Tang else 69034aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 69134aa6e3bSGeliang Tang fi 69234aa6e3bSGeliang Tang} 69334aa6e3bSGeliang Tang 69434aa6e3bSGeliang Tangpm_nl_add_endpoint() 69534aa6e3bSGeliang Tang{ 69634aa6e3bSGeliang Tang local ns=$1 69734aa6e3bSGeliang Tang local addr=$2 6981e777bd8SMatthieu Baerts local flags _flags 6991e777bd8SMatthieu Baerts local port _port 7001e777bd8SMatthieu Baerts local dev _dev 7011e777bd8SMatthieu Baerts local id _id 70234aa6e3bSGeliang Tang local nr=2 70334aa6e3bSGeliang Tang 7041e777bd8SMatthieu Baerts local p 705d8d08302SMatthieu Baerts for p in "${@}" 70634aa6e3bSGeliang Tang do 70734aa6e3bSGeliang Tang if [ $p = "flags" ]; then 70834aa6e3bSGeliang Tang eval _flags=\$"$nr" 709d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 71034aa6e3bSGeliang Tang fi 71134aa6e3bSGeliang Tang if [ $p = "dev" ]; then 71234aa6e3bSGeliang Tang eval _dev=\$"$nr" 713d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 71434aa6e3bSGeliang Tang fi 71534aa6e3bSGeliang Tang if [ $p = "id" ]; then 71634aa6e3bSGeliang Tang eval _id=\$"$nr" 717d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 71834aa6e3bSGeliang Tang fi 71934aa6e3bSGeliang Tang if [ $p = "port" ]; then 72034aa6e3bSGeliang Tang eval _port=\$"$nr" 721d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 72234aa6e3bSGeliang Tang fi 72334aa6e3bSGeliang Tang 724d8d08302SMatthieu Baerts nr=$((nr + 1)) 72534aa6e3bSGeliang Tang done 72634aa6e3bSGeliang Tang 72734aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 72834aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 72934aa6e3bSGeliang Tang else 73034aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 73134aa6e3bSGeliang Tang fi 73234aa6e3bSGeliang Tang} 73334aa6e3bSGeliang Tang 73434aa6e3bSGeliang Tangpm_nl_del_endpoint() 73534aa6e3bSGeliang Tang{ 73634aa6e3bSGeliang Tang local ns=$1 73734aa6e3bSGeliang Tang local id=$2 73834aa6e3bSGeliang Tang local addr=$3 73934aa6e3bSGeliang Tang 74034aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 741aaf2123aSAndrea Claudi [ $id -ne 0 ] && addr='' 74234aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 74334aa6e3bSGeliang Tang else 74434aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 74534aa6e3bSGeliang Tang fi 74634aa6e3bSGeliang Tang} 74734aa6e3bSGeliang Tang 74834aa6e3bSGeliang Tangpm_nl_flush_endpoint() 74934aa6e3bSGeliang Tang{ 75034aa6e3bSGeliang Tang local ns=$1 75134aa6e3bSGeliang Tang 75234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 75334aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 75434aa6e3bSGeliang Tang else 75534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 75634aa6e3bSGeliang Tang fi 75734aa6e3bSGeliang Tang} 75834aa6e3bSGeliang Tang 759dda61b3dSGeliang Tangpm_nl_show_endpoints() 760dda61b3dSGeliang Tang{ 761dda61b3dSGeliang Tang local ns=$1 762dda61b3dSGeliang Tang 763dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 764dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 765dda61b3dSGeliang Tang else 766dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 767dda61b3dSGeliang Tang fi 768dda61b3dSGeliang Tang} 769dda61b3dSGeliang Tang 770f0140386SGeliang Tangpm_nl_change_endpoint() 771f0140386SGeliang Tang{ 772f0140386SGeliang Tang local ns=$1 773bccefb76SGeliang Tang local id=$2 774bccefb76SGeliang Tang local flags=$3 775f0140386SGeliang Tang 776f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 777f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 778f0140386SGeliang Tang else 779bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 780f0140386SGeliang Tang fi 781f0140386SGeliang Tang} 782f0140386SGeliang Tang 78369c6ce7bSPaolo Abenipm_nl_check_endpoint() 78469c6ce7bSPaolo Abeni{ 78569c6ce7bSPaolo Abeni local line expected_line 78603668c65SMatthieu Baerts local msg="$1" 78703668c65SMatthieu Baerts local ns=$2 78803668c65SMatthieu Baerts local addr=$3 78969c6ce7bSPaolo Abeni local _flags="" 79069c6ce7bSPaolo Abeni local flags 79169c6ce7bSPaolo Abeni local _port 79269c6ce7bSPaolo Abeni local port 79369c6ce7bSPaolo Abeni local dev 79469c6ce7bSPaolo Abeni local _id 79569c6ce7bSPaolo Abeni local id 79669c6ce7bSPaolo Abeni 79703668c65SMatthieu Baerts print_check "${msg}" 79869c6ce7bSPaolo Abeni 79903668c65SMatthieu Baerts shift 3 80069c6ce7bSPaolo Abeni while [ -n "$1" ]; do 80169c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 80269c6ce7bSPaolo Abeni _flags=$2 803d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 80469c6ce7bSPaolo Abeni shift 80569c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 806117eed29SGeliang Tang [ -n "$2" ]; dev="dev $2" 80769c6ce7bSPaolo Abeni shift 80869c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 80969c6ce7bSPaolo Abeni _id=$2 810d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 81169c6ce7bSPaolo Abeni shift 81269c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 81369c6ce7bSPaolo Abeni _port=$2 814d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 81569c6ce7bSPaolo Abeni shift 81669c6ce7bSPaolo Abeni fi 81769c6ce7bSPaolo Abeni 81869c6ce7bSPaolo Abeni shift 81969c6ce7bSPaolo Abeni done 82069c6ce7bSPaolo Abeni 82169c6ce7bSPaolo Abeni if [ -z "$id" ]; then 8228165c844SPaolo Abeni fail_test "bad test - missing endpoint id" 82369c6ce7bSPaolo Abeni return 82469c6ce7bSPaolo Abeni fi 82569c6ce7bSPaolo Abeni 82669c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 827c8c101aeSAndrea Claudi # get line and trim trailing whitespace 82869c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 829c8c101aeSAndrea Claudi line="${line% }" 83069c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 831c8c101aeSAndrea Claudi [ -n "$addr" ] && expected_line="$addr" 832732752baSGeliang Tang expected_line+=" $id" 833732752baSGeliang Tang [ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}" 834732752baSGeliang Tang [ -n "$dev" ] && expected_line+=" $dev" 835732752baSGeliang Tang [ -n "$port" ] && expected_line+=" $port" 83669c6ce7bSPaolo Abeni else 83769c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 83869c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 83969c6ce7bSPaolo Abeni expected_line="$id" 840732752baSGeliang Tang [ -n "$flags" ] && expected_line+=" $flags" 841732752baSGeliang Tang [ -n "$dev" ] && expected_line+=" $dev" 842732752baSGeliang Tang [ -n "$addr" ] && expected_line+=" $addr" 843732752baSGeliang Tang [ -n "$_port" ] && expected_line+=" $_port" 84469c6ce7bSPaolo Abeni fi 84569c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 84603668c65SMatthieu Baerts print_ok 84769c6ce7bSPaolo Abeni else 84803668c65SMatthieu Baerts fail_test "expected '$expected_line' found '$line'" 84969c6ce7bSPaolo Abeni fi 85069c6ce7bSPaolo Abeni} 85169c6ce7bSPaolo Abeni 8529e9d176dSGeliang Tangpm_nl_set_endpoint() 853b08fbf24SPaolo Abeni{ 8541e777bd8SMatthieu Baerts local listener_ns="$1" 8551e777bd8SMatthieu Baerts local connector_ns="$2" 8569e9d176dSGeliang Tang local connect_addr="$3" 857b08fbf24SPaolo Abeni 858662aa22dSGeliang Tang local addr_nr_ns1=${addr_nr_ns1:-0} 859662aa22dSGeliang Tang local addr_nr_ns2=${addr_nr_ns2:-0} 860662aa22dSGeliang Tang local sflags=${sflags:-""} 8614aadde08SGeliang Tang local fullmesh=${fullmesh:-""} 862662aa22dSGeliang Tang 863080b7f57SGeliang Tang local flags="subflow" 8644aadde08SGeliang Tang if [ -n "${fullmesh}" ]; then 865080b7f57SGeliang Tang flags="${flags},fullmesh" 8664aadde08SGeliang Tang addr_nr_ns2=${fullmesh} 867080b7f57SGeliang Tang fi 868080b7f57SGeliang Tang 869327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 870327b9a94SPaolo Abeni # do endpoint manipulation 871d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 872d8d08302SMatthieu Baerts sleep 1 873d8d08302SMatthieu Baerts fi 874327b9a94SPaolo Abeni 8756208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8761e777bd8SMatthieu Baerts local counter=2 877d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 87897040cf9SGeliang Tang local id=10 8796208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8806208fd82SGeliang Tang local addr 8818e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 8826208fd82SGeliang Tang addr="dead:beef:$counter::1" 8836208fd82SGeliang Tang else 8846208fd82SGeliang Tang addr="10.0.$counter.1" 8856208fd82SGeliang Tang fi 88634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 887d8d08302SMatthieu Baerts counter=$((counter + 1)) 888d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 88997040cf9SGeliang Tang id=$((id + 1)) 8906208fd82SGeliang Tang done 8916208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 892d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 8936fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 8941e777bd8SMatthieu Baerts local counter=0 8951e777bd8SMatthieu Baerts local line 896d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 897d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 898dda61b3dSGeliang Tang local arr=($line) 899dda61b3dSGeliang Tang local nr=0 900dda61b3dSGeliang Tang 9011e777bd8SMatthieu Baerts local i 902d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 903dda61b3dSGeliang Tang if [ $i = "id" ]; then 904dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 905dda61b3dSGeliang Tang break 906dda61b3dSGeliang Tang fi 907dda61b3dSGeliang Tang id=${arr[$nr+1]} 908327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 90934aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 910327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 911d8d08302SMatthieu Baerts counter=$((counter + 1)) 912f87744adSGeliang Tang fi 913d8d08302SMatthieu Baerts nr=$((nr + 1)) 914dda61b3dSGeliang Tang done 915dda61b3dSGeliang Tang done 9165e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 91734aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9185e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 91934aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9206fe4ccdcSGeliang Tang fi 921dd72b0feSGeliang Tang fi 922dd72b0feSGeliang Tang 923327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 924327b9a94SPaolo Abeni # some time to created them 925d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 926327b9a94SPaolo Abeni 9276208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 928d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9291e777bd8SMatthieu Baerts local counter=3 9305e986ec4SGeliang Tang local id=20 9316208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9326208fd82SGeliang Tang local addr 9338e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9346208fd82SGeliang Tang addr="dead:beef:$counter::2" 9356208fd82SGeliang Tang else 9366208fd82SGeliang Tang addr="10.0.$counter.2" 9376208fd82SGeliang Tang fi 93834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 939d8d08302SMatthieu Baerts counter=$((counter + 1)) 940d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9415e986ec4SGeliang Tang id=$((id + 1)) 9426208fd82SGeliang Tang done 9436208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 944d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9456fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9461e777bd8SMatthieu Baerts local counter=0 9471e777bd8SMatthieu Baerts local line 948d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 949d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 950dda61b3dSGeliang Tang local arr=($line) 951dda61b3dSGeliang Tang local nr=0 952dda61b3dSGeliang Tang 9531e777bd8SMatthieu Baerts local i 954d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 955dda61b3dSGeliang Tang if [ $i = "id" ]; then 956dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 957dda61b3dSGeliang Tang break 958dda61b3dSGeliang Tang fi 9591e777bd8SMatthieu Baerts local id rm_addr 960dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 961dda61b3dSGeliang Tang # complete 962dda61b3dSGeliang Tang id=${arr[$nr+1]} 963327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 96434aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 965327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 966d8d08302SMatthieu Baerts counter=$((counter + 1)) 967f87744adSGeliang Tang fi 968d8d08302SMatthieu Baerts nr=$((nr + 1)) 969dda61b3dSGeliang Tang done 970dda61b3dSGeliang Tang done 9715e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 97234aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9735e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9745e287fe7SGeliang Tang local addr 9758e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9765e287fe7SGeliang Tang addr="dead:beef:1::2" 9775e287fe7SGeliang Tang else 9785e287fe7SGeliang Tang addr="10.0.1.2" 9795e287fe7SGeliang Tang fi 98034aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9816fe4ccdcSGeliang Tang fi 982dd72b0feSGeliang Tang fi 983dd72b0feSGeliang Tang 984d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 985718eb44eSGeliang Tang sleep 1 9861e777bd8SMatthieu Baerts 9871e777bd8SMatthieu Baerts local netns 988718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9891e777bd8SMatthieu Baerts local line 990d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 991d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 99233397b83SGeliang Tang local arr=($line) 993bccefb76SGeliang Tang local nr=0 994f0140386SGeliang Tang local id 99533397b83SGeliang Tang 9961e777bd8SMatthieu Baerts local i 997d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 998bccefb76SGeliang Tang if [ $i = "id" ]; then 999bccefb76SGeliang Tang id=${arr[$nr+1]} 1000718eb44eSGeliang Tang fi 1001d8d08302SMatthieu Baerts nr=$((nr + 1)) 100233397b83SGeliang Tang done 1003bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 100433397b83SGeliang Tang done 1005718eb44eSGeliang Tang done 1006718eb44eSGeliang Tang fi 10079e9d176dSGeliang Tang} 10089e9d176dSGeliang Tang 10099e9d176dSGeliang Tangdo_transfer() 10109e9d176dSGeliang Tang{ 10119e9d176dSGeliang Tang local listener_ns="$1" 10129e9d176dSGeliang Tang local connector_ns="$2" 10139e9d176dSGeliang Tang local cl_proto="$3" 10149e9d176dSGeliang Tang local srv_proto="$4" 10159e9d176dSGeliang Tang local connect_addr="$5" 10169e9d176dSGeliang Tang 10179e9d176dSGeliang Tang local port=$((10000 + TEST_COUNT - 1)) 10189e9d176dSGeliang Tang local cappid 1019662aa22dSGeliang Tang local FAILING_LINKS=${FAILING_LINKS:-""} 1020080b7f57SGeliang Tang local fastclose=${fastclose:-""} 1021e571fb09SGeliang Tang local speed=${speed:-"fast"} 10229e9d176dSGeliang Tang 10239e9d176dSGeliang Tang :> "$cout" 10249e9d176dSGeliang Tang :> "$sout" 10259e9d176dSGeliang Tang :> "$capout" 10269e9d176dSGeliang Tang 10279e9d176dSGeliang Tang if [ $capture -eq 1 ]; then 10289e9d176dSGeliang Tang local capuser 10299e9d176dSGeliang Tang if [ -z $SUDO_USER ] ; then 10309e9d176dSGeliang Tang capuser="" 10319e9d176dSGeliang Tang else 10329e9d176dSGeliang Tang capuser="-Z $SUDO_USER" 10339e9d176dSGeliang Tang fi 10349e9d176dSGeliang Tang 10359e9d176dSGeliang Tang capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 10369e9d176dSGeliang Tang 10379e9d176dSGeliang Tang echo "Capturing traffic for test $TEST_COUNT into $capfile" 10389e9d176dSGeliang Tang ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 10399e9d176dSGeliang Tang cappid=$! 10409e9d176dSGeliang Tang 10419e9d176dSGeliang Tang sleep 1 10429e9d176dSGeliang Tang fi 10439e9d176dSGeliang Tang 10449e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 10459e9d176dSGeliang Tang nstat -n 10469e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 10479e9d176dSGeliang Tang nstat -n 10489e9d176dSGeliang Tang 10499e9d176dSGeliang Tang local extra_args 10509e9d176dSGeliang Tang if [ $speed = "fast" ]; then 10519e9d176dSGeliang Tang extra_args="-j" 10529e9d176dSGeliang Tang elif [ $speed = "slow" ]; then 10539e9d176dSGeliang Tang extra_args="-r 50" 1054e571fb09SGeliang Tang elif [ $speed -gt 0 ]; then 1055e571fb09SGeliang Tang extra_args="-r ${speed}" 10569e9d176dSGeliang Tang fi 10579e9d176dSGeliang Tang 10589e9d176dSGeliang Tang local extra_cl_args="" 10599e9d176dSGeliang Tang local extra_srv_args="" 10609e9d176dSGeliang Tang local trunc_size="" 1061080b7f57SGeliang Tang if [ -n "${fastclose}" ]; then 10629e9d176dSGeliang Tang if [ ${test_linkfail} -le 1 ]; then 106303668c65SMatthieu Baerts fail_test "fastclose tests need test_linkfail argument" 10649e9d176dSGeliang Tang return 1 10659e9d176dSGeliang Tang fi 10669e9d176dSGeliang Tang 10679e9d176dSGeliang Tang # disconnect 10689e9d176dSGeliang Tang trunc_size=${test_linkfail} 1069080b7f57SGeliang Tang local side=${fastclose} 10709e9d176dSGeliang Tang 10719e9d176dSGeliang Tang if [ ${side} = "client" ]; then 10729e9d176dSGeliang Tang extra_cl_args="-f ${test_linkfail}" 10739e9d176dSGeliang Tang extra_srv_args="-f -1" 10749e9d176dSGeliang Tang elif [ ${side} = "server" ]; then 10759e9d176dSGeliang Tang extra_srv_args="-f ${test_linkfail}" 10769e9d176dSGeliang Tang extra_cl_args="-f -1" 10779e9d176dSGeliang Tang else 107803668c65SMatthieu Baerts fail_test "wrong/unknown fastclose spec ${side}" 10799e9d176dSGeliang Tang return 1 10809e9d176dSGeliang Tang fi 10819e9d176dSGeliang Tang fi 10829e9d176dSGeliang Tang 10839e9d176dSGeliang Tang extra_srv_args="$extra_args $extra_srv_args" 10849e9d176dSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 10859e9d176dSGeliang Tang timeout ${timeout_test} \ 10869e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10879e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10889e9d176dSGeliang Tang $extra_srv_args "::" < "$sinfail" > "$sout" & 10899e9d176dSGeliang Tang else 10909e9d176dSGeliang Tang timeout ${timeout_test} \ 10919e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10929e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10939e9d176dSGeliang Tang $extra_srv_args "::" < "$sin" > "$sout" & 10949e9d176dSGeliang Tang fi 10959e9d176dSGeliang Tang local spid=$! 10969e9d176dSGeliang Tang 10979e9d176dSGeliang Tang wait_local_port_listen "${listener_ns}" "${port}" 10989e9d176dSGeliang Tang 10999e9d176dSGeliang Tang extra_cl_args="$extra_args $extra_cl_args" 11009e9d176dSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11019e9d176dSGeliang Tang timeout ${timeout_test} \ 11029e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11039e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11049e9d176dSGeliang Tang $extra_cl_args $connect_addr < "$cin" > "$cout" & 11059e9d176dSGeliang Tang elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 11069e9d176dSGeliang Tang ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 11079e9d176dSGeliang Tang tee "$cinsent" | \ 11089e9d176dSGeliang Tang timeout ${timeout_test} \ 11099e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11109e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11119e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11129e9d176dSGeliang Tang else 11139e9d176dSGeliang Tang tee "$cinsent" < "$cinfail" | \ 11149e9d176dSGeliang Tang timeout ${timeout_test} \ 11159e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11169e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11179e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11189e9d176dSGeliang Tang fi 11199e9d176dSGeliang Tang local cpid=$! 11209e9d176dSGeliang Tang 11219e9d176dSGeliang Tang pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 1122718eb44eSGeliang Tang 1123b08fbf24SPaolo Abeni wait $cpid 11241e777bd8SMatthieu Baerts local retc=$? 1125b08fbf24SPaolo Abeni wait $spid 11261e777bd8SMatthieu Baerts local rets=$? 1127b08fbf24SPaolo Abeni 1128b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1129b08fbf24SPaolo Abeni sleep 1 1130b08fbf24SPaolo Abeni kill $cappid 1131b08fbf24SPaolo Abeni fi 1132b08fbf24SPaolo Abeni 1133c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1134c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1135c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1136c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1137c2a55e8fSMatthieu Baerts 1138b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 113903668c65SMatthieu Baerts fail_test "client exit code $retc, server $rets" 11408b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1141c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1142c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 11438b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1144c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1145c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1146b08fbf24SPaolo Abeni 1147b08fbf24SPaolo Abeni cat "$capout" 1148b08fbf24SPaolo Abeni return 1 1149b08fbf24SPaolo Abeni fi 1150b08fbf24SPaolo Abeni 11510c93af1fSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 11526bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 11537d1e6f16SPaolo Abeni else 11546bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 11557d1e6f16SPaolo Abeni fi 1156b08fbf24SPaolo Abeni retc=$? 11570c93af1fSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11586bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 11598b819a84SFlorian Westphal else 11606bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 11618b819a84SFlorian Westphal fi 1162b08fbf24SPaolo Abeni rets=$? 1163b08fbf24SPaolo Abeni 1164b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1165b08fbf24SPaolo Abeni cat "$capout" 1166b08fbf24SPaolo Abeni return 0 1167b08fbf24SPaolo Abeni fi 1168b08fbf24SPaolo Abeni 1169b08fbf24SPaolo Abeni cat "$capout" 1170b08fbf24SPaolo Abeni return 1 1171b08fbf24SPaolo Abeni} 1172b08fbf24SPaolo Abeni 1173b08fbf24SPaolo Abenimake_file() 1174b08fbf24SPaolo Abeni{ 11751e777bd8SMatthieu Baerts local name=$1 11761e777bd8SMatthieu Baerts local who=$2 11771e777bd8SMatthieu Baerts local size=$3 1178b08fbf24SPaolo Abeni 11798b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1180b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1181b08fbf24SPaolo Abeni 118203668c65SMatthieu Baerts print_info "Test file (size $size KB) for $who" 1183b08fbf24SPaolo Abeni} 1184b08fbf24SPaolo Abeni 1185b08fbf24SPaolo Abenirun_tests() 1186b08fbf24SPaolo Abeni{ 11871e777bd8SMatthieu Baerts local listener_ns="$1" 11881e777bd8SMatthieu Baerts local connector_ns="$2" 11891e777bd8SMatthieu Baerts local connect_addr="$3" 11901e777bd8SMatthieu Baerts 11911e777bd8SMatthieu Baerts local size 1192662aa22dSGeliang Tang local test_linkfail=${test_linkfail:-0} 11938b819a84SFlorian Westphal 119434b572b7SGeliang Tang # The values above 2 are reused to make test files 119534b572b7SGeliang Tang # with the given sizes (KB) 119634b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 119734b572b7SGeliang Tang size=$test_linkfail 119834b572b7SGeliang Tang 119934b572b7SGeliang Tang if [ -z "$cinfail" ]; then 120034b572b7SGeliang Tang cinfail=$(mktemp) 120134b572b7SGeliang Tang fi 120234b572b7SGeliang Tang make_file "$cinfail" "client" $size 12037d1e6f16SPaolo Abeni # create the input file for the failure test when 12047d1e6f16SPaolo Abeni # the first failure test run 1205d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 12067d1e6f16SPaolo Abeni # the client file must be considerably larger 12077d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 12087d1e6f16SPaolo Abeni # link utilization will be not predicable 12097d1e6f16SPaolo Abeni size=$((RANDOM%2)) 12108b819a84SFlorian Westphal size=$((size+1)) 12117d1e6f16SPaolo Abeni size=$((size*8192)) 1212d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 12138b819a84SFlorian Westphal 12147d1e6f16SPaolo Abeni cinfail=$(mktemp) 12157d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 12167d1e6f16SPaolo Abeni fi 12177d1e6f16SPaolo Abeni 121834b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 121934b572b7SGeliang Tang size=$test_linkfail 122034b572b7SGeliang Tang 122134b572b7SGeliang Tang if [ -z "$sinfail" ]; then 122234b572b7SGeliang Tang sinfail=$(mktemp) 122334b572b7SGeliang Tang fi 122434b572b7SGeliang Tang make_file "$sinfail" "server" $size 1225d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 12267d1e6f16SPaolo Abeni size=$((RANDOM%16)) 12277d1e6f16SPaolo Abeni size=$((size+1)) 12287d1e6f16SPaolo Abeni size=$((size*2048)) 12297d1e6f16SPaolo Abeni 12307d1e6f16SPaolo Abeni sinfail=$(mktemp) 12317d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 12328b819a84SFlorian Westphal fi 1233b08fbf24SPaolo Abeni 1234e571fb09SGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 1235b08fbf24SPaolo Abeni} 1236b08fbf24SPaolo Abeni 1237327b9a94SPaolo Abenidump_stats() 1238327b9a94SPaolo Abeni{ 1239327b9a94SPaolo Abeni echo Server ns stats 1240327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1241327b9a94SPaolo Abeni echo Client ns stats 1242327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1243327b9a94SPaolo Abeni} 1244327b9a94SPaolo Abeni 1245af66d3e1SGeliang Tangchk_csum_nr() 1246af66d3e1SGeliang Tang{ 12473c082695SGeliang Tang local csum_ns1=${1:-0} 12483c082695SGeliang Tang local csum_ns2=${2:-0} 1249af66d3e1SGeliang Tang local count 125053f368bfSGeliang Tang local extra_msg="" 125126516e10SGeliang Tang local allow_multi_errors_ns1=0 125226516e10SGeliang Tang local allow_multi_errors_ns2=0 125326516e10SGeliang Tang 125426516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 125526516e10SGeliang Tang allow_multi_errors_ns1=1 125626516e10SGeliang Tang csum_ns1=${csum_ns1:1} 125726516e10SGeliang Tang fi 125826516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 125926516e10SGeliang Tang allow_multi_errors_ns2=1 126026516e10SGeliang Tang csum_ns2=${csum_ns2:1} 126126516e10SGeliang Tang fi 1262af66d3e1SGeliang Tang 126303668c65SMatthieu Baerts print_check "sum" 1264697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") 126599c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$csum_ns1" ]; then 1266732752baSGeliang Tang extra_msg+=" ns1=$count" 126753f368bfSGeliang Tang fi 126847867f0aSMatthieu Baerts if [ -z "$count" ]; then 126903668c65SMatthieu Baerts print_skip 127047867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1271d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 127203668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns1" 1273af66d3e1SGeliang Tang else 127403668c65SMatthieu Baerts print_ok 1275af66d3e1SGeliang Tang fi 127603668c65SMatthieu Baerts print_check "csum" 1277697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") 127899c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$csum_ns2" ]; then 1279732752baSGeliang Tang extra_msg+=" ns2=$count" 128053f368bfSGeliang Tang fi 128147867f0aSMatthieu Baerts if [ -z "$count" ]; then 128203668c65SMatthieu Baerts print_skip 128347867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1284d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 128503668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns2" 1286af66d3e1SGeliang Tang else 128703668c65SMatthieu Baerts print_ok 1288af66d3e1SGeliang Tang fi 128953f368bfSGeliang Tang 129003668c65SMatthieu Baerts print_info "$extra_msg" 1291af66d3e1SGeliang Tang} 1292af66d3e1SGeliang Tang 12936bb3ab49SGeliang Tangchk_fail_nr() 12946bb3ab49SGeliang Tang{ 129526516e10SGeliang Tang local fail_tx=$1 129626516e10SGeliang Tang local fail_rx=$2 12971f7d325fSGeliang Tang local ns_invert=${3:-""} 12986bb3ab49SGeliang Tang local count 12991f7d325fSGeliang Tang local ns_tx=$ns1 13001f7d325fSGeliang Tang local ns_rx=$ns2 13011f7d325fSGeliang Tang local extra_msg="" 13021f7d325fSGeliang Tang local allow_tx_lost=0 13031f7d325fSGeliang Tang local allow_rx_lost=0 13041f7d325fSGeliang Tang 13051f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 13061f7d325fSGeliang Tang ns_tx=$ns2 13071f7d325fSGeliang Tang ns_rx=$ns1 13081f7d325fSGeliang Tang extra_msg="invert" 13091f7d325fSGeliang Tang fi 13101f7d325fSGeliang Tang 13111f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 13121f7d325fSGeliang Tang allow_tx_lost=1 13131f7d325fSGeliang Tang fail_tx=${fail_tx:1} 13141f7d325fSGeliang Tang fi 13151f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 13161f7d325fSGeliang Tang allow_rx_lost=1 13171f7d325fSGeliang Tang fail_rx=${fail_rx:1} 13181f7d325fSGeliang Tang fi 13196bb3ab49SGeliang Tang 132003668c65SMatthieu Baerts print_check "ftx" 1321697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") 132299c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$fail_tx" ]; then 1323732752baSGeliang Tang extra_msg+=",tx=$count" 13241f7d325fSGeliang Tang fi 132547867f0aSMatthieu Baerts if [ -z "$count" ]; then 132603668c65SMatthieu Baerts print_skip 132747867f0aSMatthieu Baerts elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 13281f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 132903668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] TX expected $fail_tx" 13306bb3ab49SGeliang Tang else 133103668c65SMatthieu Baerts print_ok 13326bb3ab49SGeliang Tang fi 13336bb3ab49SGeliang Tang 133403668c65SMatthieu Baerts print_check "failrx" 1335697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") 133699c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$fail_rx" ]; then 1337732752baSGeliang Tang extra_msg+=",rx=$count" 13381f7d325fSGeliang Tang fi 133947867f0aSMatthieu Baerts if [ -z "$count" ]; then 134003668c65SMatthieu Baerts print_skip 134147867f0aSMatthieu Baerts elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 13421f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 134303668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] RX expected $fail_rx" 13446bb3ab49SGeliang Tang else 134503668c65SMatthieu Baerts print_ok 13466bb3ab49SGeliang Tang fi 13476bb3ab49SGeliang Tang 134803668c65SMatthieu Baerts print_info "$extra_msg" 13496bb3ab49SGeliang Tang} 13506bb3ab49SGeliang Tang 1351e8e947efSGeliang Tangchk_fclose_nr() 1352e8e947efSGeliang Tang{ 1353e8e947efSGeliang Tang local fclose_tx=$1 1354e8e947efSGeliang Tang local fclose_rx=$2 13556bf41020SPaolo Abeni local ns_invert=$3 1356e8e947efSGeliang Tang local count 13576bf41020SPaolo Abeni local ns_tx=$ns2 13586bf41020SPaolo Abeni local ns_rx=$ns1 13596bf41020SPaolo Abeni local extra_msg="" 13606bf41020SPaolo Abeni 13616bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 13626bf41020SPaolo Abeni ns_tx=$ns1 13636bf41020SPaolo Abeni ns_rx=$ns2 136403668c65SMatthieu Baerts extra_msg="invert" 13656bf41020SPaolo Abeni fi 1366e8e947efSGeliang Tang 136703668c65SMatthieu Baerts print_check "ctx" 1368697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx") 136947867f0aSMatthieu Baerts if [ -z "$count" ]; then 137003668c65SMatthieu Baerts print_skip 137147867f0aSMatthieu Baerts elif [ "$count" != "$fclose_tx" ]; then 1372732752baSGeliang Tang extra_msg+=",tx=$count" 137303668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1374e8e947efSGeliang Tang else 137503668c65SMatthieu Baerts print_ok 1376e8e947efSGeliang Tang fi 1377e8e947efSGeliang Tang 137803668c65SMatthieu Baerts print_check "fclzrx" 1379697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx") 138047867f0aSMatthieu Baerts if [ -z "$count" ]; then 138103668c65SMatthieu Baerts print_skip 138247867f0aSMatthieu Baerts elif [ "$count" != "$fclose_rx" ]; then 1383732752baSGeliang Tang extra_msg+=",rx=$count" 138403668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1385e8e947efSGeliang Tang else 138603668c65SMatthieu Baerts print_ok 1387e8e947efSGeliang Tang fi 1388e8e947efSGeliang Tang 138903668c65SMatthieu Baerts print_info "$extra_msg" 1390e8e947efSGeliang Tang} 1391e8e947efSGeliang Tang 1392922fd2b3SGeliang Tangchk_rst_nr() 1393922fd2b3SGeliang Tang{ 1394922fd2b3SGeliang Tang local rst_tx=$1 1395922fd2b3SGeliang Tang local rst_rx=$2 1396922fd2b3SGeliang Tang local ns_invert=${3:-""} 1397922fd2b3SGeliang Tang local count 1398922fd2b3SGeliang Tang local ns_tx=$ns1 1399922fd2b3SGeliang Tang local ns_rx=$ns2 1400922fd2b3SGeliang Tang local extra_msg="" 1401922fd2b3SGeliang Tang 1402922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1403922fd2b3SGeliang Tang ns_tx=$ns2 1404922fd2b3SGeliang Tang ns_rx=$ns1 1405922fd2b3SGeliang Tang extra_msg="invert" 1406922fd2b3SGeliang Tang fi 1407922fd2b3SGeliang Tang 140803668c65SMatthieu Baerts print_check "rtx" 1409697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx") 141047867f0aSMatthieu Baerts if [ -z "$count" ]; then 141103668c65SMatthieu Baerts print_skip 1412b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1413b134a580SMatthieu Baerts elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } || 1414b134a580SMatthieu Baerts { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then 141503668c65SMatthieu Baerts fail_test "got $count MP_RST[s] TX expected $rst_tx" 1416922fd2b3SGeliang Tang else 141703668c65SMatthieu Baerts print_ok 1418922fd2b3SGeliang Tang fi 1419922fd2b3SGeliang Tang 142003668c65SMatthieu Baerts print_check "rstrx" 1421697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx") 142247867f0aSMatthieu Baerts if [ -z "$count" ]; then 142303668c65SMatthieu Baerts print_skip 1424b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1425b134a580SMatthieu Baerts elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } || 1426b134a580SMatthieu Baerts { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then 142703668c65SMatthieu Baerts fail_test "got $count MP_RST[s] RX expected $rst_rx" 1428922fd2b3SGeliang Tang else 142903668c65SMatthieu Baerts print_ok 1430922fd2b3SGeliang Tang fi 1431922fd2b3SGeliang Tang 143203668c65SMatthieu Baerts print_info "$extra_msg" 1433922fd2b3SGeliang Tang} 1434922fd2b3SGeliang Tang 14358bd03be3SGeliang Tangchk_infi_nr() 14368bd03be3SGeliang Tang{ 14378bd03be3SGeliang Tang local infi_tx=$1 14388bd03be3SGeliang Tang local infi_rx=$2 14398bd03be3SGeliang Tang local count 14408bd03be3SGeliang Tang 144103668c65SMatthieu Baerts print_check "itx" 1442697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx") 144347867f0aSMatthieu Baerts if [ -z "$count" ]; then 144403668c65SMatthieu Baerts print_skip 144547867f0aSMatthieu Baerts elif [ "$count" != "$infi_tx" ]; then 144603668c65SMatthieu Baerts fail_test "got $count infinite map[s] TX expected $infi_tx" 14478bd03be3SGeliang Tang else 144803668c65SMatthieu Baerts print_ok 14498bd03be3SGeliang Tang fi 14508bd03be3SGeliang Tang 145103668c65SMatthieu Baerts print_check "infirx" 1452697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx") 145347867f0aSMatthieu Baerts if [ -z "$count" ]; then 145403668c65SMatthieu Baerts print_skip 145547867f0aSMatthieu Baerts elif [ "$count" != "$infi_rx" ]; then 145603668c65SMatthieu Baerts fail_test "got $count infinite map[s] RX expected $infi_rx" 14578bd03be3SGeliang Tang else 145803668c65SMatthieu Baerts print_ok 14598bd03be3SGeliang Tang fi 14608bd03be3SGeliang Tang} 14618bd03be3SGeliang Tang 1462b08fbf24SPaolo Abenichk_join_nr() 1463b08fbf24SPaolo Abeni{ 1464c7d49c03SMatthieu Baerts local syn_nr=$1 1465c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1466c7d49c03SMatthieu Baerts local ack_nr=$3 1467c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1468c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1469c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1470c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 14718bd03be3SGeliang Tang local infi_nr=${8:-0} 14728bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1473b08fbf24SPaolo Abeni local count 1474e35f885bSPaolo Abeni local with_cookie 1475b08fbf24SPaolo Abeni 1476c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 147703668c65SMatthieu Baerts print_info "${corrupted_pkts} corrupted pkts" 1478c7d49c03SMatthieu Baerts fi 1479c7d49c03SMatthieu Baerts 148003668c65SMatthieu Baerts print_check "syn" 1481697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx") 148247867f0aSMatthieu Baerts if [ -z "$count" ]; then 148303668c65SMatthieu Baerts print_skip 148447867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 148503668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn expected $syn_nr" 1486b08fbf24SPaolo Abeni else 148703668c65SMatthieu Baerts print_ok 1488b08fbf24SPaolo Abeni fi 1489b08fbf24SPaolo Abeni 149003668c65SMatthieu Baerts print_check "synack" 14914bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 1492697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx") 149347867f0aSMatthieu Baerts if [ -z "$count" ]; then 149403668c65SMatthieu Baerts print_skip 149547867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 1496e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1497e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1498e35f885bSPaolo Abeni # the subflow creation 1499e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 150003668c65SMatthieu Baerts print_ok 1501e35f885bSPaolo Abeni else 150203668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack expected $syn_ack_nr" 1503e35f885bSPaolo Abeni fi 1504b08fbf24SPaolo Abeni else 150503668c65SMatthieu Baerts print_ok 1506b08fbf24SPaolo Abeni fi 1507b08fbf24SPaolo Abeni 150803668c65SMatthieu Baerts print_check "ack" 1509697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx") 151047867f0aSMatthieu Baerts if [ -z "$count" ]; then 151103668c65SMatthieu Baerts print_skip 151247867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 151303668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack expected $ack_nr" 1514b08fbf24SPaolo Abeni else 151503668c65SMatthieu Baerts print_ok 1516b08fbf24SPaolo Abeni fi 1517b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 15183c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 151926516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 152026516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 15218bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1522af66d3e1SGeliang Tang fi 1523b08fbf24SPaolo Abeni} 1524b08fbf24SPaolo Abeni 15257d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 15267d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 15277d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 15287d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 15297d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 15307d1e6f16SPaolo Abenichk_stale_nr() 15317d1e6f16SPaolo Abeni{ 15327d1e6f16SPaolo Abeni local ns=$1 15337d1e6f16SPaolo Abeni local stale_min=$2 15347d1e6f16SPaolo Abeni local stale_max=$3 15357d1e6f16SPaolo Abeni local stale_delta=$4 15367d1e6f16SPaolo Abeni local dump_stats 15377d1e6f16SPaolo Abeni local stale_nr 15387d1e6f16SPaolo Abeni local recover_nr 15397d1e6f16SPaolo Abeni 154003668c65SMatthieu Baerts print_check "stale" 15417d1e6f16SPaolo Abeni 1542697128a3SGeliang Tang stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale") 1543697128a3SGeliang Tang recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover") 154447867f0aSMatthieu Baerts if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then 154503668c65SMatthieu Baerts print_skip 154647867f0aSMatthieu Baerts elif [ $stale_nr -lt $stale_min ] || 1547d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1548d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 154903668c65SMatthieu Baerts fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \ 15507d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 15517d1e6f16SPaolo Abeni " stale-recover delta $stale_delta" 15527d1e6f16SPaolo Abeni dump_stats=1 15537d1e6f16SPaolo Abeni else 155403668c65SMatthieu Baerts print_ok 15557d1e6f16SPaolo Abeni fi 15567d1e6f16SPaolo Abeni 15577d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 15587d1e6f16SPaolo Abeni echo $ns stats 15597d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 15607d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 15617d1e6f16SPaolo Abeni fi 15627d1e6f16SPaolo Abeni} 15637d1e6f16SPaolo Abeni 1564be613160SGeliang Tangchk_add_nr() 1565be613160SGeliang Tang{ 1566be613160SGeliang Tang local add_nr=$1 1567be613160SGeliang Tang local echo_nr=$2 15688a127bf6SGeliang Tang local port_nr=${3:-0} 1569e80cf3fcSMatthieu Baerts (NGI0) local ns_invert=${4:-""} 1570e80cf3fcSMatthieu Baerts (NGI0) local syn_nr=$port_nr 1571e80cf3fcSMatthieu Baerts (NGI0) local syn_ack_nr=$port_nr 1572e80cf3fcSMatthieu Baerts (NGI0) local ack_nr=$port_nr 1573e80cf3fcSMatthieu Baerts (NGI0) local mis_syn_nr=0 1574e80cf3fcSMatthieu Baerts (NGI0) local mis_ack_nr=0 1575e80cf3fcSMatthieu Baerts (NGI0) local ns_tx=$ns1 1576e80cf3fcSMatthieu Baerts (NGI0) local ns_rx=$ns2 1577e80cf3fcSMatthieu Baerts (NGI0) local extra_msg="" 1578be613160SGeliang Tang local count 15796ef84b15SPaolo Abeni local timeout 15806ef84b15SPaolo Abeni 1581e80cf3fcSMatthieu Baerts (NGI0) if [[ $ns_invert = "invert" ]]; then 1582e80cf3fcSMatthieu Baerts (NGI0) ns_tx=$ns2 1583e80cf3fcSMatthieu Baerts (NGI0) ns_rx=$ns1 1584e80cf3fcSMatthieu Baerts (NGI0) extra_msg="invert" 1585e80cf3fcSMatthieu Baerts (NGI0) fi 1586e80cf3fcSMatthieu Baerts (NGI0) 1587e80cf3fcSMatthieu Baerts (NGI0) timeout=$(ip netns exec ${ns_tx} sysctl -n net.mptcp.add_addr_timeout) 1588be613160SGeliang Tang 158903668c65SMatthieu Baerts print_check "add" 1590e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtAddAddr") 159147867f0aSMatthieu Baerts if [ -z "$count" ]; then 159203668c65SMatthieu Baerts print_skip 15936ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15946ef84b15SPaolo Abeni # add addrs options, due to retransmissions 159547867f0aSMatthieu Baerts elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 159603668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] expected $add_nr" 1597be613160SGeliang Tang else 159803668c65SMatthieu Baerts print_ok 1599be613160SGeliang Tang fi 1600be613160SGeliang Tang 160103668c65SMatthieu Baerts print_check "echo" 1602e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtEchoAdd") 160347867f0aSMatthieu Baerts if [ -z "$count" ]; then 160403668c65SMatthieu Baerts print_skip 160547867f0aSMatthieu Baerts elif [ "$count" != "$echo_nr" ]; then 160603668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] expected $echo_nr" 1607be613160SGeliang Tang else 160803668c65SMatthieu Baerts print_ok 16098a127bf6SGeliang Tang fi 16108a127bf6SGeliang Tang 16118a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 161203668c65SMatthieu Baerts print_check "pt" 1613e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtPortAdd") 161447867f0aSMatthieu Baerts if [ -z "$count" ]; then 161503668c65SMatthieu Baerts print_skip 161647867f0aSMatthieu Baerts elif [ "$count" != "$port_nr" ]; then 161703668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr" 16188a127bf6SGeliang Tang else 161903668c65SMatthieu Baerts print_ok 1620be613160SGeliang Tang fi 1621be613160SGeliang Tang 162203668c65SMatthieu Baerts print_check "syn" 1623e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortSynRx") 162447867f0aSMatthieu Baerts if [ -z "$count" ]; then 162503668c65SMatthieu Baerts print_skip 162647867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 162703668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a different \ 16288a127bf6SGeliang Tang port-number expected $syn_nr" 16298a127bf6SGeliang Tang else 163003668c65SMatthieu Baerts print_ok 16318a127bf6SGeliang Tang fi 16328a127bf6SGeliang Tang 163303668c65SMatthieu Baerts print_check "synack" 1634e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPJoinPortSynAckRx") 163547867f0aSMatthieu Baerts if [ -z "$count" ]; then 163603668c65SMatthieu Baerts print_skip 163747867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 163803668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack with a different \ 16398a127bf6SGeliang Tang port-number expected $syn_ack_nr" 16408a127bf6SGeliang Tang else 164103668c65SMatthieu Baerts print_ok 16428a127bf6SGeliang Tang fi 16438a127bf6SGeliang Tang 164403668c65SMatthieu Baerts print_check "ack" 1645e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortAckRx") 164647867f0aSMatthieu Baerts if [ -z "$count" ]; then 164703668c65SMatthieu Baerts print_skip 164847867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 164903668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a different \ 16508a127bf6SGeliang Tang port-number expected $ack_nr" 16518a127bf6SGeliang Tang else 165203668c65SMatthieu Baerts print_ok 16538a127bf6SGeliang Tang fi 16548a127bf6SGeliang Tang 165503668c65SMatthieu Baerts print_check "syn" 1656e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortSynRx") 165747867f0aSMatthieu Baerts if [ -z "$count" ]; then 165803668c65SMatthieu Baerts print_skip 165947867f0aSMatthieu Baerts elif [ "$count" != "$mis_syn_nr" ]; then 166003668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a mismatched \ 16618a127bf6SGeliang Tang port-number expected $mis_syn_nr" 16628a127bf6SGeliang Tang else 166303668c65SMatthieu Baerts print_ok 16648a127bf6SGeliang Tang fi 16658a127bf6SGeliang Tang 166603668c65SMatthieu Baerts print_check "ack" 1667e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortAckRx") 166847867f0aSMatthieu Baerts if [ -z "$count" ]; then 166903668c65SMatthieu Baerts print_skip 167047867f0aSMatthieu Baerts elif [ "$count" != "$mis_ack_nr" ]; then 167103668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a mismatched \ 16728a127bf6SGeliang Tang port-number expected $mis_ack_nr" 16738a127bf6SGeliang Tang else 167403668c65SMatthieu Baerts print_ok 16758a127bf6SGeliang Tang fi 16768a127bf6SGeliang Tang fi 1677e80cf3fcSMatthieu Baerts (NGI0) 1678e80cf3fcSMatthieu Baerts (NGI0) print_info "$extra_msg" 1679be613160SGeliang Tang} 1680be613160SGeliang Tang 16810639fa23SPaolo Abenichk_add_tx_nr() 16820639fa23SPaolo Abeni{ 16830639fa23SPaolo Abeni local add_tx_nr=$1 16840639fa23SPaolo Abeni local echo_tx_nr=$2 16850639fa23SPaolo Abeni local timeout 16860639fa23SPaolo Abeni local count 16870639fa23SPaolo Abeni 16880639fa23SPaolo Abeni timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 16890639fa23SPaolo Abeni 169003668c65SMatthieu Baerts print_check "add TX" 1691697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx") 169200079f18SMatthieu Baerts if [ -z "$count" ]; then 169303668c65SMatthieu Baerts print_skip 16940639fa23SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 16950639fa23SPaolo Abeni # add addrs options, due to retransmissions 169600079f18SMatthieu Baerts elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 169703668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr" 16980639fa23SPaolo Abeni else 169903668c65SMatthieu Baerts print_ok 17000639fa23SPaolo Abeni fi 17010639fa23SPaolo Abeni 170203668c65SMatthieu Baerts print_check "echo TX" 1703697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx") 170400079f18SMatthieu Baerts if [ -z "$count" ]; then 170503668c65SMatthieu Baerts print_skip 170600079f18SMatthieu Baerts elif [ "$count" != "$echo_tx_nr" ]; then 170703668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 17080639fa23SPaolo Abeni else 170903668c65SMatthieu Baerts print_ok 17100639fa23SPaolo Abeni fi 17110639fa23SPaolo Abeni} 17120639fa23SPaolo Abeni 1713dd72b0feSGeliang Tangchk_rm_nr() 1714dd72b0feSGeliang Tang{ 1715dd72b0feSGeliang Tang local rm_addr_nr=$1 1716dd72b0feSGeliang Tang local rm_subflow_nr=$2 17176fa0174aSPaolo Abeni local invert 17186fa0174aSPaolo Abeni local simult 1719dd72b0feSGeliang Tang local count 17207d9bf018SGeliang Tang local addr_ns=$ns1 17217d9bf018SGeliang Tang local subflow_ns=$ns2 17227d9bf018SGeliang Tang local extra_msg="" 17237028ba8aSGeliang Tang 17246fa0174aSPaolo Abeni shift 2 17256fa0174aSPaolo Abeni while [ -n "$1" ]; do 17266fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 17276fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 17286fa0174aSPaolo Abeni shift 17296fa0174aSPaolo Abeni done 17306fa0174aSPaolo Abeni 17316fa0174aSPaolo Abeni if [ -z $invert ]; then 17326fa0174aSPaolo Abeni addr_ns=$ns1 17336fa0174aSPaolo Abeni subflow_ns=$ns2 17346fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 17357028ba8aSGeliang Tang addr_ns=$ns2 17367028ba8aSGeliang Tang subflow_ns=$ns1 17377d9bf018SGeliang Tang extra_msg="invert" 17387028ba8aSGeliang Tang fi 1739dd72b0feSGeliang Tang 174003668c65SMatthieu Baerts print_check "rm" 1741697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr") 174200079f18SMatthieu Baerts if [ -z "$count" ]; then 174303668c65SMatthieu Baerts print_skip 174400079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_nr" ]; then 174503668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_nr" 1746dd72b0feSGeliang Tang else 174703668c65SMatthieu Baerts print_ok 1748dd72b0feSGeliang Tang fi 1749dd72b0feSGeliang Tang 175003668c65SMatthieu Baerts print_check "rmsf" 1751697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow") 175247867f0aSMatthieu Baerts if [ -z "$count" ]; then 175303668c65SMatthieu Baerts print_skip 175447867f0aSMatthieu Baerts elif [ -n "$simult" ]; then 1755d8d08302SMatthieu Baerts local cnt suffix 1756d8d08302SMatthieu Baerts 1757697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow") 17586fa0174aSPaolo Abeni 17596fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 17606fa0174aSPaolo Abeni # unreliable 17616fa0174aSPaolo Abeni count=$((count + cnt)) 1762a445eb1fSGeliang Tang if [ "$count" != "$rm_subflow_nr" ]; then 1763a445eb1fSGeliang Tang suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1764732752baSGeliang Tang extra_msg+=" simult" 1765a445eb1fSGeliang Tang fi 17666fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 17676fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 176803668c65SMatthieu Baerts print_ok "$suffix" 17696fa0174aSPaolo Abeni else 177003668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 17716fa0174aSPaolo Abeni fi 177247867f0aSMatthieu Baerts elif [ "$count" != "$rm_subflow_nr" ]; then 177303668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1774dd72b0feSGeliang Tang else 177503668c65SMatthieu Baerts print_ok 1776dd72b0feSGeliang Tang fi 1777dd72b0feSGeliang Tang 177803668c65SMatthieu Baerts print_info "$extra_msg" 1779dd72b0feSGeliang Tang} 1780dd72b0feSGeliang Tang 17810639fa23SPaolo Abenichk_rm_tx_nr() 17820639fa23SPaolo Abeni{ 17830639fa23SPaolo Abeni local rm_addr_tx_nr=$1 17840639fa23SPaolo Abeni 178503668c65SMatthieu Baerts print_check "rm TX" 1786697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx") 178700079f18SMatthieu Baerts if [ -z "$count" ]; then 178803668c65SMatthieu Baerts print_skip 178900079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_tx_nr" ]; then 179003668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr" 17910639fa23SPaolo Abeni else 179203668c65SMatthieu Baerts print_ok 17930639fa23SPaolo Abeni fi 17940639fa23SPaolo Abeni} 17950639fa23SPaolo Abeni 1796718eb44eSGeliang Tangchk_prio_nr() 1797718eb44eSGeliang Tang{ 1798718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1799718eb44eSGeliang Tang local mp_prio_nr_rx=$2 18008213b98eSMatthieu Baerts (NGI0) local mpj_syn=$3 18018213b98eSMatthieu Baerts (NGI0) local mpj_syn_ack=$4 1802718eb44eSGeliang Tang local count 1803718eb44eSGeliang Tang 180403668c65SMatthieu Baerts print_check "ptx" 1805697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx") 180647867f0aSMatthieu Baerts if [ -z "$count" ]; then 180703668c65SMatthieu Baerts print_skip 180847867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_tx" ]; then 180903668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1810718eb44eSGeliang Tang else 181103668c65SMatthieu Baerts print_ok 1812718eb44eSGeliang Tang fi 1813718eb44eSGeliang Tang 181403668c65SMatthieu Baerts print_check "prx" 1815697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx") 181647867f0aSMatthieu Baerts if [ -z "$count" ]; then 181703668c65SMatthieu Baerts print_skip 181847867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_rx" ]; then 181903668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1820718eb44eSGeliang Tang else 182103668c65SMatthieu Baerts print_ok 1822718eb44eSGeliang Tang fi 18238213b98eSMatthieu Baerts (NGI0) 18248213b98eSMatthieu Baerts (NGI0) print_check "syn backup" 18258213b98eSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynBackupRx") 18268213b98eSMatthieu Baerts (NGI0) if [ -z "$count" ]; then 18278213b98eSMatthieu Baerts (NGI0) print_skip 18288213b98eSMatthieu Baerts (NGI0) elif [ "$count" != "$mpj_syn" ]; then 18298213b98eSMatthieu Baerts (NGI0) fail_test "got $count JOIN[s] syn with Backup expected $mpj_syn" 18308213b98eSMatthieu Baerts (NGI0) else 18318213b98eSMatthieu Baerts (NGI0) print_ok 18328213b98eSMatthieu Baerts (NGI0) fi 18338213b98eSMatthieu Baerts (NGI0) 18348213b98eSMatthieu Baerts (NGI0) print_check "synack backup" 18358213b98eSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckBackupRx") 18368213b98eSMatthieu Baerts (NGI0) if [ -z "$count" ]; then 18378213b98eSMatthieu Baerts (NGI0) print_skip 18388213b98eSMatthieu Baerts (NGI0) elif [ "$count" != "$mpj_syn_ack" ]; then 18398213b98eSMatthieu Baerts (NGI0) fail_test "got $count JOIN[s] synack with Backup expected $mpj_syn_ack" 18408213b98eSMatthieu Baerts (NGI0) else 18418213b98eSMatthieu Baerts (NGI0) print_ok 18428213b98eSMatthieu Baerts (NGI0) fi 1843718eb44eSGeliang Tang} 1844718eb44eSGeliang Tang 1845e274f715SPaolo Abenichk_subflow_nr() 1846e274f715SPaolo Abeni{ 184703668c65SMatthieu Baerts local msg="$1" 184803668c65SMatthieu Baerts local subflow_nr=$2 1849e274f715SPaolo Abeni local cnt1 1850e274f715SPaolo Abeni local cnt2 1851a635a8c3SPaolo Abeni local dump_stats 1852e274f715SPaolo Abeni 185303668c65SMatthieu Baerts print_check "${msg}" 1854e274f715SPaolo Abeni 1855e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1856e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 18570fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 185803668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr" 1859e274f715SPaolo Abeni dump_stats=1 1860e274f715SPaolo Abeni else 186103668c65SMatthieu Baerts print_ok 1862e274f715SPaolo Abeni fi 1863e274f715SPaolo Abeni 1864a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1865a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1866a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1867a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1868a635a8c3SPaolo Abeni fi 1869e274f715SPaolo Abeni} 1870e274f715SPaolo Abeni 18719095ce97SGeliang Tangchk_mptcp_info() 18729095ce97SGeliang Tang{ 1873d7ced753SGeliang Tang local info1=$1 1874d7ced753SGeliang Tang local exp1=$2 1875d7ced753SGeliang Tang local info2=$3 1876d7ced753SGeliang Tang local exp2=$4 18779095ce97SGeliang Tang local cnt1 18789095ce97SGeliang Tang local cnt2 18799095ce97SGeliang Tang local dump_stats 18809095ce97SGeliang Tang 1881f9190d79SGeliang Tang print_check "mptcp_info ${info1:0:15}=$exp1:$exp2" 18829095ce97SGeliang Tang 1883ae1fa39dSGeliang Tang cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info1" "$info1") 1884ae1fa39dSGeliang Tang cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info2" "$info2") 1885d7ced753SGeliang Tang # 'ss' only display active connections and counters that are not 0. 18869095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 18879095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 1888d7ced753SGeliang Tang 1889d7ced753SGeliang Tang if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then 189003668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2" 18919095ce97SGeliang Tang dump_stats=1 18929095ce97SGeliang Tang else 189303668c65SMatthieu Baerts print_ok 18949095ce97SGeliang Tang fi 18959095ce97SGeliang Tang 18969095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 18979095ce97SGeliang Tang ss -N $ns1 -inmHM 18989095ce97SGeliang Tang ss -N $ns2 -inmHM 18999095ce97SGeliang Tang fi 19009095ce97SGeliang Tang} 19019095ce97SGeliang Tang 1902f9190d79SGeliang Tang# $1: subflows in ns1 ; $2: subflows in ns2 1903f9190d79SGeliang Tang# number of all subflows, including the initial subflow. 1904f9190d79SGeliang Tangchk_subflows_total() 1905f9190d79SGeliang Tang{ 1906f9190d79SGeliang Tang local cnt1 1907f9190d79SGeliang Tang local cnt2 1908f9190d79SGeliang Tang local info="subflows_total" 1909f9190d79SGeliang Tang local dump_stats 1910f9190d79SGeliang Tang 1911f9190d79SGeliang Tang # if subflows_total counter is supported, use it: 1912f9190d79SGeliang Tang if [ -n "$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value $info $info)" ]; then 1913f9190d79SGeliang Tang chk_mptcp_info $info $1 $info $2 1914f9190d79SGeliang Tang return 1915f9190d79SGeliang Tang fi 1916f9190d79SGeliang Tang 1917f9190d79SGeliang Tang print_check "$info $1:$2" 1918f9190d79SGeliang Tang 1919f9190d79SGeliang Tang # if not, count the TCP connections that are in fact MPTCP subflows 1920f9190d79SGeliang Tang cnt1=$(ss -N $ns1 -ti state established state syn-sent state syn-recv | 1921f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1922f9190d79SGeliang Tang cnt2=$(ss -N $ns2 -ti state established state syn-sent state syn-recv | 1923f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1924f9190d79SGeliang Tang 1925f9190d79SGeliang Tang if [ "$1" != "$cnt1" ] || [ "$2" != "$cnt2" ]; then 1926f9190d79SGeliang Tang fail_test "got subflows $cnt1:$cnt2 expected $1:$2" 1927f9190d79SGeliang Tang dump_stats=1 1928f9190d79SGeliang Tang else 1929f9190d79SGeliang Tang print_ok 1930f9190d79SGeliang Tang fi 1931f9190d79SGeliang Tang 1932f9190d79SGeliang Tang if [ "$dump_stats" = 1 ]; then 1933f9190d79SGeliang Tang ss -N $ns1 -ti 1934f9190d79SGeliang Tang ss -N $ns2 -ti 1935f9190d79SGeliang Tang fi 1936f9190d79SGeliang Tang} 1937f9190d79SGeliang Tang 19387d1e6f16SPaolo Abenichk_link_usage() 19397d1e6f16SPaolo Abeni{ 19407d1e6f16SPaolo Abeni local ns=$1 19417d1e6f16SPaolo Abeni local link=$2 19427d1e6f16SPaolo Abeni local out=$3 19437d1e6f16SPaolo Abeni local expected_rate=$4 19444bfadd71SMatthieu Baerts 19454bfadd71SMatthieu Baerts local tx_link tx_total 19464bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1947d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1948d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 19497d1e6f16SPaolo Abeni local tolerance=5 19507d1e6f16SPaolo Abeni 195103668c65SMatthieu Baerts print_check "link usage" 1952d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1953d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 195403668c65SMatthieu Baerts fail_test "got $tx_rate% usage, expected $expected_rate%" 19557d1e6f16SPaolo Abeni else 195603668c65SMatthieu Baerts print_ok 19577d1e6f16SPaolo Abeni fi 19587d1e6f16SPaolo Abeni} 19597d1e6f16SPaolo Abeni 1960f98c2bcaSMat Martineauwait_attempt_fail() 196146e967d1SPaolo Abeni{ 196246e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 196346e967d1SPaolo Abeni local time=0 196446e967d1SPaolo Abeni local ns=$1 196546e967d1SPaolo Abeni 196646e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 19671e777bd8SMatthieu Baerts local cnt 19681e777bd8SMatthieu Baerts 1969697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails") 197046e967d1SPaolo Abeni 197146e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 197246e967d1SPaolo Abeni time=$((time + 100)) 197346e967d1SPaolo Abeni sleep 0.1 197446e967d1SPaolo Abeni done 197546e967d1SPaolo Abeni return 1 197646e967d1SPaolo Abeni} 197746e967d1SPaolo Abeni 19785ac1d2d6SMat Martineauset_userspace_pm() 19795ac1d2d6SMat Martineau{ 19805ac1d2d6SMat Martineau local ns=$1 19815ac1d2d6SMat Martineau 19825ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 19835ac1d2d6SMat Martineau} 19845ac1d2d6SMat Martineau 19851002b89fSGeliang Tangsubflows_tests() 19861002b89fSGeliang Tang{ 1987c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1988b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1989c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1990ae7bd9ccSMatthieu Baerts fi 1991b08fbf24SPaolo Abeni 19921002b89fSGeliang Tang # subflow limited by client 1993c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 199434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 199534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 199634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1997b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1998c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1999ae7bd9ccSMatthieu Baerts fi 2000b08fbf24SPaolo Abeni 20011002b89fSGeliang Tang # subflow limited by server 2002c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 200334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 200434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 200534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2006b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2007c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 2008ae7bd9ccSMatthieu Baerts fi 2009b08fbf24SPaolo Abeni 2010b08fbf24SPaolo Abeni # subflow 2011c7d49c03SMatthieu Baerts if reset "single subflow"; then 201234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 201334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 201434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2015b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2016c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2017ae7bd9ccSMatthieu Baerts fi 2018b08fbf24SPaolo Abeni 2019b08fbf24SPaolo Abeni # multiple subflows 2020c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 202134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 202234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 202334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 202434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2025b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2026c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2027ae7bd9ccSMatthieu Baerts fi 2028b08fbf24SPaolo Abeni 202972bcbc46SPaolo Abeni # multiple subflows limited by server 2030c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 203134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 203234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 203334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 203434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2035b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2036c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 2037ae7bd9ccSMatthieu Baerts fi 2038c3eaa5f6SGeliang Tang 2039c3eaa5f6SGeliang Tang # single subflow, dev 2040c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 204134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 204234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 204334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 2044c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2045c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2046ae7bd9ccSMatthieu Baerts fi 20471002b89fSGeliang Tang} 2048b08fbf24SPaolo Abeni 204946e967d1SPaolo Abenisubflows_error_tests() 205046e967d1SPaolo Abeni{ 205146e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 205246e967d1SPaolo Abeni # address, no additional subflow should be created 2053c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 205434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 205534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 205634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2057e571fb09SGeliang Tang speed=slow \ 2058e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2059c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2060ae7bd9ccSMatthieu Baerts fi 206146e967d1SPaolo Abeni 206246e967d1SPaolo Abeni # multiple subflows, with subflow creation error 20634a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT && 20644a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 206534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 206634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 206734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 206834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2069e571fb09SGeliang Tang speed=slow \ 2070e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2071c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2072ae7bd9ccSMatthieu Baerts fi 207346e967d1SPaolo Abeni 207446e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 20754a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP && 20764a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 207734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 207834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 207934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 208034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2081e571fb09SGeliang Tang speed=slow \ 2082e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2083c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2084ae7bd9ccSMatthieu Baerts fi 208546e967d1SPaolo Abeni 208646e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 208746e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 208846e967d1SPaolo Abeni # subflows are added later 20894a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT && 20904a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 209134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 209234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 209334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2094e571fb09SGeliang Tang speed=slow \ 2095e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 209646e967d1SPaolo Abeni 209746e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 2098f98c2bcaSMat Martineau wait_attempt_fail $ns2 209934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 210046e967d1SPaolo Abeni wait 210146e967d1SPaolo Abeni 210246e967d1SPaolo Abeni # additional subflow could be created only if the PM select 210346e967d1SPaolo Abeni # the later endpoint, skipping the already used one 2104c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2105ae7bd9ccSMatthieu Baerts fi 210646e967d1SPaolo Abeni} 210746e967d1SPaolo Abeni 21081002b89fSGeliang Tangsignal_address_tests() 21091002b89fSGeliang Tang{ 2110b08fbf24SPaolo Abeni # add_address, unused 2111c7d49c03SMatthieu Baerts if reset "unused signal address"; then 211234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2113b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2114c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 21150639fa23SPaolo Abeni chk_add_tx_nr 1 1 2116be613160SGeliang Tang chk_add_nr 1 1 2117ae7bd9ccSMatthieu Baerts fi 2118b08fbf24SPaolo Abeni 2119b08fbf24SPaolo Abeni # accept and use add_addr 2120c7d49c03SMatthieu Baerts if reset "signal address"; then 212134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 212234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 212334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2124b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2125c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2126be613160SGeliang Tang chk_add_nr 1 1 2127ae7bd9ccSMatthieu Baerts fi 2128b08fbf24SPaolo Abeni 2129b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 2130b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 2131b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 2132b08fbf24SPaolo Abeni # used for 'add_addr' subflow 2133c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 213434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 213534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 213634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 213734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2138b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2139c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2140be613160SGeliang Tang chk_add_nr 1 1 2141ae7bd9ccSMatthieu Baerts fi 2142b08fbf24SPaolo Abeni 21439d97114fSMatthieu Baerts (NGI0) # uncommon: subflow and signal flags on the same endpoint 21449d97114fSMatthieu Baerts (NGI0) # or because the user wrongly picked both, but still expects the client 21459d97114fSMatthieu Baerts (NGI0) # to create additional subflows 21469d97114fSMatthieu Baerts (NGI0) if reset "subflow and signal together"; then 21479d97114fSMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 2 21489d97114fSMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 0 2 21499d97114fSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 flags signal,subflow 21509d97114fSMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 21519d97114fSMatthieu Baerts (NGI0) chk_join_nr 1 1 1 21529d97114fSMatthieu Baerts (NGI0) chk_add_nr 1 1 0 invert # only initiated by ns2 21539d97114fSMatthieu Baerts (NGI0) chk_add_nr 0 0 0 # none initiated by ns1 21549d97114fSMatthieu Baerts (NGI0) chk_rst_nr 0 0 invert # no RST sent by the client 21559d97114fSMatthieu Baerts (NGI0) chk_rst_nr 0 0 # no RST sent by the server 21569d97114fSMatthieu Baerts (NGI0) fi 21579d97114fSMatthieu Baerts (NGI0) 2158b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 2159c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 216034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 216134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 216234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 216334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 216434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2165b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2166c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2167be613160SGeliang Tang chk_add_nr 1 1 2168ae7bd9ccSMatthieu Baerts fi 2169ef360019SGeliang Tang 2170ef360019SGeliang Tang # signal addresses 2171c7d49c03SMatthieu Baerts if reset "signal addresses"; then 217234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 217334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 217434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 217534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 217634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2177ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2178c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2179ef360019SGeliang Tang chk_add_nr 3 3 2180ae7bd9ccSMatthieu Baerts fi 2181ef360019SGeliang Tang 2182ef360019SGeliang Tang # signal invalid addresses 2183c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 218434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 218534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 218634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 218734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 218834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2189ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2190c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2191ef360019SGeliang Tang chk_add_nr 3 3 2192ae7bd9ccSMatthieu Baerts fi 219333c563adSYonglong Li 219433c563adSYonglong Li # signal addresses race test 2195c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 219634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 219734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 219834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 219934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 220034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 220134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 220234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 220334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 220434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 220534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 22066ef84b15SPaolo Abeni 22076ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 22086ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2209e571fb09SGeliang Tang speed=slow \ 2210e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 221186e39e04SPaolo Abeni 2212d4c81bbbSMatthieu Baerts # It is not directly linked to the commit introducing this 2213d4c81bbbSMatthieu Baerts # symbol but for the parent one which is linked anyway. 2214d4c81bbbSMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 2215d4c81bbbSMatthieu Baerts chk_join_nr 3 3 2 2216d4c81bbbSMatthieu Baerts chk_add_nr 4 4 2217d4c81bbbSMatthieu Baerts else 2218d4c81bbbSMatthieu Baerts chk_join_nr 3 3 3 221986e39e04SPaolo Abeni # the server will not signal the address terminating 222086e39e04SPaolo Abeni # the MPC subflow 222186e39e04SPaolo Abeni chk_add_nr 3 3 2222ae7bd9ccSMatthieu Baerts fi 2223d4c81bbbSMatthieu Baerts fi 22241002b89fSGeliang Tang} 2225b08fbf24SPaolo Abeni 22261002b89fSGeliang Tanglink_failure_tests() 22271002b89fSGeliang Tang{ 22288b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2229c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 22307d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 22317d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 22327d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 22337d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 22347d1e6f16SPaolo Abeni # active backup and link switch-over. 22357d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 22367d1e6f16SPaolo Abeni init_shapers 223734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 223834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 223934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 224034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 224134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 22420c93af1fSGeliang Tang test_linkfail=1 \ 22430c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2244c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22458b819a84SFlorian Westphal chk_add_nr 1 1 22467d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2247ae7bd9ccSMatthieu Baerts fi 22487d1e6f16SPaolo Abeni 22497d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 22507d1e6f16SPaolo Abeni # for bidirectional transfer 2251c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 22527d1e6f16SPaolo Abeni init_shapers 225334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 225434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 225534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 225634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 225734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 22580c93af1fSGeliang Tang test_linkfail=2 \ 22590c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2260c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22617d1e6f16SPaolo Abeni chk_add_nr 1 1 22627d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2263ae7bd9ccSMatthieu Baerts fi 22647d1e6f16SPaolo Abeni 22657d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 22667d1e6f16SPaolo Abeni # will never be used 2267c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 22687d1e6f16SPaolo Abeni init_shapers 226934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 227034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 227134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 227234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22730c93af1fSGeliang Tang FAILING_LINKS="1" test_linkfail=1 \ 22740c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2275c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22767d1e6f16SPaolo Abeni chk_add_nr 1 1 22777d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2278ae7bd9ccSMatthieu Baerts fi 22797d1e6f16SPaolo Abeni 22807d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 22817d1e6f16SPaolo Abeni # the traffic 2282c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 22837d1e6f16SPaolo Abeni init_shapers 228434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 228534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 228634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 228734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22880c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=1 \ 22890c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2290c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22917d1e6f16SPaolo Abeni chk_add_nr 1 1 22927d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 22937d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2294ae7bd9ccSMatthieu Baerts fi 22957d1e6f16SPaolo Abeni 22967d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 22977d1e6f16SPaolo Abeni # for bidirectional transfer 2298c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 22997d1e6f16SPaolo Abeni init_shapers 230034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 230134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 230234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 230334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 23040c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=2 \ 23050c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2306c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23077d1e6f16SPaolo Abeni chk_add_nr 1 1 23087d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 23097d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2310ae7bd9ccSMatthieu Baerts fi 23111002b89fSGeliang Tang} 23128b819a84SFlorian Westphal 23131002b89fSGeliang Tangadd_addr_timeout_tests() 23141002b89fSGeliang Tang{ 23158d014eaaSGeliang Tang # add_addr timeout 2316c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 231734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 231834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 231934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2320e571fb09SGeliang Tang speed=slow \ 2321e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2322c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23230639fa23SPaolo Abeni chk_add_tx_nr 4 4 23248d014eaaSGeliang Tang chk_add_nr 4 0 2325ae7bd9ccSMatthieu Baerts fi 23268d014eaaSGeliang Tang 23271002b89fSGeliang Tang # add_addr timeout IPv6 2328c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 232934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 233034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 233134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2332e571fb09SGeliang Tang speed=slow \ 2333e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2334c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23351002b89fSGeliang Tang chk_add_nr 4 0 2336ae7bd9ccSMatthieu Baerts fi 23378da6229bSGeliang Tang 23388da6229bSGeliang Tang # signal addresses timeout 2339c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 234034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 234134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 234234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 234334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2344e571fb09SGeliang Tang speed=10 \ 2345e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2346c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23478da6229bSGeliang Tang chk_add_nr 8 0 2348ae7bd9ccSMatthieu Baerts fi 23498da6229bSGeliang Tang 23508da6229bSGeliang Tang # signal invalid addresses timeout 2351c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 235234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 235334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 235434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 235534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2356e571fb09SGeliang Tang speed=10 \ 2357e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2358c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23598da6229bSGeliang Tang chk_add_nr 8 0 2360ae7bd9ccSMatthieu Baerts fi 23611002b89fSGeliang Tang} 23621002b89fSGeliang Tang 23631002b89fSGeliang Tangremove_tests() 23641002b89fSGeliang Tang{ 2365dd72b0feSGeliang Tang # single subflow, remove 2366c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 236734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 236834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 236934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2370e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 2371e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2372c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23730639fa23SPaolo Abeni chk_rm_tx_nr 1 2374dd72b0feSGeliang Tang chk_rm_nr 1 1 23752cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2376ae7bd9ccSMatthieu Baerts fi 2377dd72b0feSGeliang Tang 2378dd72b0feSGeliang Tang # multiple subflows, remove 2379c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 238034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 238134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 238234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 238334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2384e571fb09SGeliang Tang addr_nr_ns2=-2 speed=slow \ 2385e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2386c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2387dd72b0feSGeliang Tang chk_rm_nr 2 2 23882cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2389ae7bd9ccSMatthieu Baerts fi 2390dd72b0feSGeliang Tang 2391dd72b0feSGeliang Tang # single address, remove 2392c7d49c03SMatthieu Baerts if reset "remove single address"; then 239334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 239434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 239534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2396e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2397e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2398c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2399dd72b0feSGeliang Tang chk_add_nr 1 1 24007028ba8aSGeliang Tang chk_rm_nr 1 1 invert 24012cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2402ae7bd9ccSMatthieu Baerts fi 2403dd72b0feSGeliang Tang 2404dd72b0feSGeliang Tang # subflow and signal, remove 2405c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 240634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 240734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 240834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 240934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2410e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2411e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2412c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2413dd72b0feSGeliang Tang chk_add_nr 1 1 2414dd72b0feSGeliang Tang chk_rm_nr 1 1 24152cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2416ae7bd9ccSMatthieu Baerts fi 2417dd72b0feSGeliang Tang 2418dd72b0feSGeliang Tang # subflows and signal, remove 2419c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 242034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 242134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 242234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 242334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 242434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2425e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \ 2426e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2427c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2428dd72b0feSGeliang Tang chk_add_nr 1 1 2429dd72b0feSGeliang Tang chk_rm_nr 2 2 24302cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2431ae7bd9ccSMatthieu Baerts fi 2432dd72b0feSGeliang Tang 2433ef360019SGeliang Tang # addresses remove 2434c7d49c03SMatthieu Baerts if reset "remove addresses"; then 243534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 243634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 243734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 243834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 243934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2440e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2441e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2442c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2443ef360019SGeliang Tang chk_add_nr 3 3 2444ef360019SGeliang Tang chk_rm_nr 3 3 invert 24452cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2446ae7bd9ccSMatthieu Baerts fi 2447ef360019SGeliang Tang 2448ef360019SGeliang Tang # invalid addresses remove 2449c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 245034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 245134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 245209469a08SYonglongLi # broadcast IP: no packet for this address will be received on ns1 245309469a08SYonglongLi pm_nl_add_endpoint $ns1 224.0.0.1 flags signal 2454dbf0787cSYonglongLi pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2455dbf0787cSYonglongLi pm_nl_set_limits $ns2 2 2 2456e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2457e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2458c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2459ef360019SGeliang Tang chk_add_nr 3 3 2460ef360019SGeliang Tang chk_rm_nr 3 1 invert 24612cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2462ae7bd9ccSMatthieu Baerts fi 2463ef360019SGeliang Tang 24646fe4ccdcSGeliang Tang # subflows and signal, flush 2465c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 246634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 246734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 246834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 246934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 247034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2471e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2472e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2473c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 24746fe4ccdcSGeliang Tang chk_add_nr 1 1 24756fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 24762cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2477ae7bd9ccSMatthieu Baerts fi 2478d2c4333aSGeliang Tang 2479d2c4333aSGeliang Tang # subflows flush 2480c7d49c03SMatthieu Baerts if reset "flush subflows"; then 248134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 248234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 248334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 248434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 248534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2486e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2487e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2488c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2489425ba803SMatthieu Baerts 2490425ba803SMatthieu Baerts if mptcp_lib_kversion_ge 5.18; then 24910639fa23SPaolo Abeni chk_rm_tx_nr 0 24926fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2493425ba803SMatthieu Baerts else 2494425ba803SMatthieu Baerts chk_rm_nr 3 3 2495425ba803SMatthieu Baerts fi 24962cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2497ae7bd9ccSMatthieu Baerts fi 2498d2c4333aSGeliang Tang 2499d2c4333aSGeliang Tang # addresses flush 2500c7d49c03SMatthieu Baerts if reset "flush addresses"; then 250134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 250234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 250334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 250434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 250534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2506e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2507e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2508c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2509d2c4333aSGeliang Tang chk_add_nr 3 3 25106fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 25112cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2512ae7bd9ccSMatthieu Baerts fi 2513ef360019SGeliang Tang 2514ef360019SGeliang Tang # invalid addresses flush 2515c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 251634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 251734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 251834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 251934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 252034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2521e571fb09SGeliang Tang addr_nr_ns1=-8 speed=slow \ 2522e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2523c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2524ef360019SGeliang Tang chk_add_nr 3 3 2525ef360019SGeliang Tang chk_rm_nr 3 1 invert 25262cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2527ae7bd9ccSMatthieu Baerts fi 25285e287fe7SGeliang Tang 25295e287fe7SGeliang Tang # remove id 0 subflow 2530c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 253134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 253234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 253334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2534e571fb09SGeliang Tang addr_nr_ns2=-9 speed=slow \ 2535e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2536c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25375e287fe7SGeliang Tang chk_rm_nr 1 1 25382cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2539ae7bd9ccSMatthieu Baerts fi 25405e287fe7SGeliang Tang 25415e287fe7SGeliang Tang # remove id 0 address 2542c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 254334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 254434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 254534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2546e571fb09SGeliang Tang addr_nr_ns1=-9 speed=slow \ 2547e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2548c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25495e287fe7SGeliang Tang chk_add_nr 1 1 25505e287fe7SGeliang Tang chk_rm_nr 1 1 invert 25512cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 invert 2552ae7bd9ccSMatthieu Baerts fi 25531002b89fSGeliang Tang} 25546fe4ccdcSGeliang Tang 25551002b89fSGeliang Tangadd_tests() 25561002b89fSGeliang Tang{ 25576208fd82SGeliang Tang # add single subflow 2558c7d49c03SMatthieu Baerts if reset "add single subflow"; then 255934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 256034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2561e571fb09SGeliang Tang addr_nr_ns2=1 speed=slow \ 2562e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2563c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2564ae7bd9ccSMatthieu Baerts fi 25656208fd82SGeliang Tang 25666208fd82SGeliang Tang # add signal address 2567c7d49c03SMatthieu Baerts if reset "add signal address"; then 256834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 256934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2570e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 2571e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2572c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25736208fd82SGeliang Tang chk_add_nr 1 1 2574ae7bd9ccSMatthieu Baerts fi 25756208fd82SGeliang Tang 25766208fd82SGeliang Tang # add multiple subflows 2577c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 257834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 257934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2580e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2581e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2582c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2583ae7bd9ccSMatthieu Baerts fi 25846208fd82SGeliang Tang 25856208fd82SGeliang Tang # add multiple subflows IPv6 2586c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 258734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 258834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2589e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2590e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2591c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2592ae7bd9ccSMatthieu Baerts fi 25936208fd82SGeliang Tang 25946208fd82SGeliang Tang # add multiple addresses IPv6 2595c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 259634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 259734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2598e571fb09SGeliang Tang addr_nr_ns1=2 speed=slow \ 2599e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2600c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 26016208fd82SGeliang Tang chk_add_nr 2 2 2602ae7bd9ccSMatthieu Baerts fi 26031002b89fSGeliang Tang} 26046208fd82SGeliang Tang 26051002b89fSGeliang Tangipv6_tests() 26061002b89fSGeliang Tang{ 2607523514edSGeliang Tang # subflow IPv6 2608c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 260934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 261034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 261134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2612e571fb09SGeliang Tang speed=slow \ 2613e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2614c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2615ae7bd9ccSMatthieu Baerts fi 2616523514edSGeliang Tang 2617523514edSGeliang Tang # add_address, unused IPv6 2618c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 261934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2620e571fb09SGeliang Tang speed=slow \ 2621e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2622c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2623523514edSGeliang Tang chk_add_nr 1 1 2624ae7bd9ccSMatthieu Baerts fi 2625523514edSGeliang Tang 2626523514edSGeliang Tang # signal address IPv6 2627c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 262834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 262934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 263034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2631e571fb09SGeliang Tang speed=slow \ 2632e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2633c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2634523514edSGeliang Tang chk_add_nr 1 1 2635ae7bd9ccSMatthieu Baerts fi 2636523514edSGeliang Tang 2637523514edSGeliang Tang # single address IPv6, remove 2638c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 263934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 264034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 264134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2642e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2643e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2644c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2645523514edSGeliang Tang chk_add_nr 1 1 26467028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2647ae7bd9ccSMatthieu Baerts fi 2648523514edSGeliang Tang 2649523514edSGeliang Tang # subflow and signal IPv6, remove 2650c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 265134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 265234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 265334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 265434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2655e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2656e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2657c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2658523514edSGeliang Tang chk_add_nr 1 1 2659523514edSGeliang Tang chk_rm_nr 1 1 2660ae7bd9ccSMatthieu Baerts fi 26611002b89fSGeliang Tang} 2662523514edSGeliang Tang 26631002b89fSGeliang Tangv4mapped_tests() 26641002b89fSGeliang Tang{ 2665a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2666c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 266734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 266834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 266934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2670a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2671c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2672ae7bd9ccSMatthieu Baerts fi 2673a6094788SGeliang Tang 2674a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2675c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 267634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 267734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 267834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2679a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2680c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2681a6094788SGeliang Tang chk_add_nr 1 1 2682ae7bd9ccSMatthieu Baerts fi 2683a6094788SGeliang Tang 2684a6094788SGeliang Tang # subflow v4-map-v6 2685c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 268634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 268734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 268834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2689a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2690c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2691ae7bd9ccSMatthieu Baerts fi 2692a6094788SGeliang Tang 2693a6094788SGeliang Tang # signal address v4-map-v6 2694c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 269534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 269634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 269734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2698a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2699c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2700a6094788SGeliang Tang chk_add_nr 1 1 2701ae7bd9ccSMatthieu Baerts fi 2702a6094788SGeliang Tang 2703a6094788SGeliang Tang # subflow v6-map-v4 2704c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 270534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 270634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 270734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2708a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2709c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2710ae7bd9ccSMatthieu Baerts fi 2711a6094788SGeliang Tang 2712a6094788SGeliang Tang # signal address v6-map-v4 2713c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 271434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 271534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 271634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2717a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2718c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2719a6094788SGeliang Tang chk_add_nr 1 1 2720ae7bd9ccSMatthieu Baerts fi 2721a6094788SGeliang Tang 2722a6094788SGeliang Tang # no subflow IPv6 to v4 address 2723c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 272434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 272534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 272634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2727a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2728c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2729ae7bd9ccSMatthieu Baerts fi 2730a6094788SGeliang Tang 2731a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2732c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 273334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 273434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 273534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2736a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2737c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2738ae7bd9ccSMatthieu Baerts fi 2739a6094788SGeliang Tang 2740a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2741c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 274234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 274334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 274434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2745a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2746c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2747ae7bd9ccSMatthieu Baerts fi 27481002b89fSGeliang Tang} 2749a6094788SGeliang Tang 2750ad349374SPaolo Abenimixed_tests() 2751ad349374SPaolo Abeni{ 27526673851bSMatthieu Baerts if reset "IPv4 sockets do not use IPv6 addresses" && 27536673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2754ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2755ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2756ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2757e571fb09SGeliang Tang speed=slow \ 2758e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2759ad349374SPaolo Abeni chk_join_nr 0 0 0 2760ad349374SPaolo Abeni fi 2761ad349374SPaolo Abeni 2762ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 27636673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows" && 27646673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2765ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2766ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2767ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2768e571fb09SGeliang Tang speed=slow \ 2769e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2770ad349374SPaolo Abeni chk_join_nr 1 1 1 2771ad349374SPaolo Abeni fi 2772ad349374SPaolo Abeni 2773ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 27746673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" && 27756673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2776ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2777ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2778ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2779ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2780e571fb09SGeliang Tang speed=slow \ 2781e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2782ad349374SPaolo Abeni chk_join_nr 1 1 1 2783ad349374SPaolo Abeni fi 2784ad349374SPaolo Abeni 2785ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2786ad349374SPaolo Abeni # matching family 27876673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" && 27886673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2789ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2790ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2791ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2792ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2793e571fb09SGeliang Tang fullmesh=1 speed=slow \ 2794e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2795ad349374SPaolo Abeni chk_join_nr 4 4 4 2796ad349374SPaolo Abeni fi 2797ad349374SPaolo Abeni} 2798ad349374SPaolo Abeni 27991002b89fSGeliang Tangbackup_tests() 28001002b89fSGeliang Tang{ 2801718eb44eSGeliang Tang # single subflow, backup 280207216a3cSMatthieu Baerts if reset "single subflow, backup" && 280307216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 280434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 280534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 280634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2807e571fb09SGeliang Tang sflags=nobackup speed=slow \ 2808e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2809c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28108213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 2811ae7bd9ccSMatthieu Baerts fi 2812718eb44eSGeliang Tang 2813718eb44eSGeliang Tang # single address, backup 281407216a3cSMatthieu Baerts if reset "single address, backup" && 281507216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 281634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 28176f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup 28186f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 1 1 28196f2b2180SMatthieu Baerts (NGI0) sflags=nobackup speed=slow \ 28206f2b2180SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 28216f2b2180SMatthieu Baerts (NGI0) chk_join_nr 1 1 1 28226f2b2180SMatthieu Baerts (NGI0) chk_add_nr 1 1 28236f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 0 0 1 28246f2b2180SMatthieu Baerts (NGI0) fi 28256f2b2180SMatthieu Baerts (NGI0) 28266f2b2180SMatthieu Baerts (NGI0) # single address, switch to backup 28276f2b2180SMatthieu Baerts (NGI0) if reset "single address, switch to backup" && 28286f2b2180SMatthieu Baerts (NGI0) continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 28296f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 1 283034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 283134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2832e571fb09SGeliang Tang sflags=backup speed=slow \ 2833e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2834c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2835718eb44eSGeliang Tang chk_add_nr 1 1 28368213b98eSMatthieu Baerts (NGI0) chk_prio_nr 1 1 0 0 2837ae7bd9ccSMatthieu Baerts fi 283833397b83SGeliang Tang 283933397b83SGeliang Tang # single address with port, backup 284007216a3cSMatthieu Baerts if reset "single address with port, backup" && 284107216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 284234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 28436f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup port 10100 284434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 28456f2b2180SMatthieu Baerts (NGI0) sflags=nobackup speed=slow \ 2846e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2847c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 284833397b83SGeliang Tang chk_add_nr 1 1 28496f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 0 0 1 2850ae7bd9ccSMatthieu Baerts fi 2851914f6a59SPaolo Abeni 2852632978f0SMatthieu Baerts if reset "mpc backup" && 2853c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2854914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2855e571fb09SGeliang Tang speed=slow \ 2856e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2857914f6a59SPaolo Abeni chk_join_nr 0 0 0 28588213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 0 0 2859914f6a59SPaolo Abeni fi 2860914f6a59SPaolo Abeni 2861632978f0SMatthieu Baerts if reset "mpc backup both sides" && 2862c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 28636f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 2 28646f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 1 2 28656f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.1.1 flags signal,backup 2866914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 28676f2b2180SMatthieu Baerts (NGI0) 28686f2b2180SMatthieu Baerts (NGI0) # 10.0.2.2 (non-backup) -> 10.0.1.1 (backup) 28696f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 28706f2b2180SMatthieu Baerts (NGI0) # 10.0.1.2 (backup) -> 10.0.2.1 (non-backup) 28716f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 28726f2b2180SMatthieu Baerts (NGI0) ip -net "$ns2" route add 10.0.2.1 via 10.0.1.1 dev ns2eth1 # force this path 28736f2b2180SMatthieu Baerts (NGI0) 2874e571fb09SGeliang Tang speed=slow \ 2875e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 28766f2b2180SMatthieu Baerts (NGI0) chk_join_nr 2 2 2 28776f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 1 1 1 2878914f6a59SPaolo Abeni fi 2879914f6a59SPaolo Abeni 2880632978f0SMatthieu Baerts if reset "mpc switch to backup" && 2881c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2882914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2883e571fb09SGeliang Tang sflags=backup speed=slow \ 2884e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2885914f6a59SPaolo Abeni chk_join_nr 0 0 0 28868213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 0 0 2887914f6a59SPaolo Abeni fi 2888914f6a59SPaolo Abeni 2889632978f0SMatthieu Baerts if reset "mpc switch to backup both sides" && 2890c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2891914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2892914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2893e571fb09SGeliang Tang sflags=backup speed=slow \ 2894e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2895914f6a59SPaolo Abeni chk_join_nr 0 0 0 28968213b98eSMatthieu Baerts (NGI0) chk_prio_nr 1 1 0 0 2897914f6a59SPaolo Abeni fi 28981002b89fSGeliang Tang} 2899718eb44eSGeliang Tang 2900178d0232SGeliang Tangverify_listener_events() 2901178d0232SGeliang Tang{ 2902178d0232SGeliang Tang local evt=$1 2903178d0232SGeliang Tang local e_type=$2 2904178d0232SGeliang Tang local e_family=$3 2905178d0232SGeliang Tang local e_saddr=$4 2906178d0232SGeliang Tang local e_sport=$5 2907178d0232SGeliang Tang local type 2908178d0232SGeliang Tang local family 2909178d0232SGeliang Tang local saddr 2910178d0232SGeliang Tang local sport 291196b84195SMatthieu Baerts local name 2912178d0232SGeliang Tang 2913a17d1419SGeliang Tang if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then 291496b84195SMatthieu Baerts name="LISTENER_CREATED" 2915a17d1419SGeliang Tang elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then 291696b84195SMatthieu Baerts name="LISTENER_CLOSED " 291796b84195SMatthieu Baerts else 291896b84195SMatthieu Baerts name="$e_type" 2919178d0232SGeliang Tang fi 2920178d0232SGeliang Tang 292103668c65SMatthieu Baerts print_check "$name $e_saddr:$e_sport" 292296b84195SMatthieu Baerts 29230471bb47SMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 292403668c65SMatthieu Baerts print_skip "event not supported" 29250471bb47SMatthieu Baerts return 29260471bb47SMatthieu Baerts fi 29270471bb47SMatthieu Baerts 2928ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" "$e_type") 2929ae1fa39dSGeliang Tang family=$(mptcp_lib_evts_get_info family "$evt" "$e_type") 2930ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type") 2931178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 2932ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type") 2933178d0232SGeliang Tang else 2934ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type") 2935178d0232SGeliang Tang fi 2936178d0232SGeliang Tang 2937178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2938178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2939178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2940178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 294103668c65SMatthieu Baerts print_ok 2942178d0232SGeliang Tang return 0 2943178d0232SGeliang Tang fi 294403668c65SMatthieu Baerts fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" 2945178d0232SGeliang Tang} 2946178d0232SGeliang Tang 29471002b89fSGeliang Tangadd_addr_ports_tests() 29481002b89fSGeliang Tang{ 29498a127bf6SGeliang Tang # signal address with port 2950c7d49c03SMatthieu Baerts if reset "signal address with port"; then 295134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 295234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 295334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 29548a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2955c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29568a127bf6SGeliang Tang chk_add_nr 1 1 1 2957ae7bd9ccSMatthieu Baerts fi 29588a127bf6SGeliang Tang 29598a127bf6SGeliang Tang # subflow and signal with port 2960c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 296134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 296234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 296334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 296434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29658a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2966c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29678a127bf6SGeliang Tang chk_add_nr 1 1 1 2968ae7bd9ccSMatthieu Baerts fi 29698a127bf6SGeliang Tang 29708a127bf6SGeliang Tang # single address with port, remove 2971178d0232SGeliang Tang # pm listener events 2972178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 297334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 297434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 297534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2976e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2977e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2978c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29798a127bf6SGeliang Tang chk_add_nr 1 1 1 29807028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2981178d0232SGeliang Tang 2982a17d1419SGeliang Tang verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CREATED \ 2983a17d1419SGeliang Tang $MPTCP_LIB_AF_INET 10.0.2.1 10100 2984a17d1419SGeliang Tang verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CLOSED \ 2985a17d1419SGeliang Tang $MPTCP_LIB_AF_INET 10.0.2.1 10100 2986178d0232SGeliang Tang kill_events_pids 2987ae7bd9ccSMatthieu Baerts fi 29888a127bf6SGeliang Tang 29898a127bf6SGeliang Tang # subflow and signal with port, remove 2990c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 299134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 299234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 299334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 299434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2995e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2996e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2997c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29988a127bf6SGeliang Tang chk_add_nr 1 1 1 29998a127bf6SGeliang Tang chk_rm_nr 1 1 3000ae7bd9ccSMatthieu Baerts fi 30018a127bf6SGeliang Tang 30028a127bf6SGeliang Tang # subflows and signal with port, flush 3003c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 300434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 300534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 300634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 300734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 300834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 3009e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \ 3010e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3011c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 30128a127bf6SGeliang Tang chk_add_nr 1 1 30136fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 3014ae7bd9ccSMatthieu Baerts fi 30158a127bf6SGeliang Tang 30168a127bf6SGeliang Tang # multiple addresses with port 3017c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 301834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 301934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 302034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 302134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 30228a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3023c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30248a127bf6SGeliang Tang chk_add_nr 2 2 2 3025ae7bd9ccSMatthieu Baerts fi 30268a127bf6SGeliang Tang 30278a127bf6SGeliang Tang # multiple addresses with ports 3028c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 302934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 303034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 303134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 303234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 30338a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3034c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30358a127bf6SGeliang Tang chk_add_nr 2 2 2 3036ae7bd9ccSMatthieu Baerts fi 30371002b89fSGeliang Tang} 30388a127bf6SGeliang Tang 30391002b89fSGeliang Tangsyncookies_tests() 30401002b89fSGeliang Tang{ 304100587187SFlorian Westphal # single subflow, syncookies 3042c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 304334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 304434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 304534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 304600587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3047c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3048ae7bd9ccSMatthieu Baerts fi 304900587187SFlorian Westphal 305000587187SFlorian Westphal # multiple subflows with syn cookies 3051c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 305234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 305334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 305434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 305534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 305600587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3057c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3058ae7bd9ccSMatthieu Baerts fi 305900587187SFlorian Westphal 306000587187SFlorian Westphal # multiple subflows limited by server 3061c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 306234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 306334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 306434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 306534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 306600587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3067c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 3068ae7bd9ccSMatthieu Baerts fi 306900587187SFlorian Westphal 307000587187SFlorian Westphal # test signal address with cookies 3071c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 307234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 307334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 307434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 307500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3076c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3077be613160SGeliang Tang chk_add_nr 1 1 3078ae7bd9ccSMatthieu Baerts fi 307900587187SFlorian Westphal 308000587187SFlorian Westphal # test cookie with subflow and signal 3081c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 308234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 308334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 308434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 308534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 308600587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3087c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3088be613160SGeliang Tang chk_add_nr 1 1 3089ae7bd9ccSMatthieu Baerts fi 309000587187SFlorian Westphal 309100587187SFlorian Westphal # accept and use add_addr with additional subflows 3092c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 309334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 309434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 309534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 309634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 309734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 309800587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3099c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 3100be613160SGeliang Tang chk_add_nr 1 1 3101ae7bd9ccSMatthieu Baerts fi 31021002b89fSGeliang Tang} 31031002b89fSGeliang Tang 3104af66d3e1SGeliang Tangchecksum_tests() 3105af66d3e1SGeliang Tang{ 3106af66d3e1SGeliang Tang # checksum test 0 0 3107ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 310834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 310934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3110af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3111c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3112ae7bd9ccSMatthieu Baerts fi 3113af66d3e1SGeliang Tang 3114af66d3e1SGeliang Tang # checksum test 1 1 3115ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 311634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 311734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3118af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3119c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3120ae7bd9ccSMatthieu Baerts fi 3121af66d3e1SGeliang Tang 3122af66d3e1SGeliang Tang # checksum test 0 1 3123ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 312434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 312534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3126af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3127c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3128ae7bd9ccSMatthieu Baerts fi 3129af66d3e1SGeliang Tang 3130af66d3e1SGeliang Tang # checksum test 1 0 3131ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 313234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 313334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3134af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3135c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3136ae7bd9ccSMatthieu Baerts fi 3137af66d3e1SGeliang Tang} 3138af66d3e1SGeliang Tang 31390cddb4a6SGeliang Tangdeny_join_id0_tests() 31400cddb4a6SGeliang Tang{ 31410cddb4a6SGeliang Tang # subflow allow join id0 ns1 3142c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 314334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 314434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 314534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31460cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3147c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3148ae7bd9ccSMatthieu Baerts fi 31490cddb4a6SGeliang Tang 31500cddb4a6SGeliang Tang # subflow allow join id0 ns2 3151c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 315234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 315334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 315434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31550cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3156c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3157ae7bd9ccSMatthieu Baerts fi 31580cddb4a6SGeliang Tang 31590cddb4a6SGeliang Tang # signal address allow join id0 ns1 31600cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3161c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 316234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 316334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 316434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 31650cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3166c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 31670cddb4a6SGeliang Tang chk_add_nr 1 1 3168ae7bd9ccSMatthieu Baerts fi 31690cddb4a6SGeliang Tang 31700cddb4a6SGeliang Tang # signal address allow join id0 ns2 31710cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3172c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 317334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 317434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 317534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 31760cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3177c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 31780cddb4a6SGeliang Tang chk_add_nr 1 1 3179ae7bd9ccSMatthieu Baerts fi 31800cddb4a6SGeliang Tang 31810cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 3182c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 318334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 318434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 318534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 318634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31870cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3188c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3189ae7bd9ccSMatthieu Baerts fi 31900cddb4a6SGeliang Tang 31910cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 3192c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 319334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 319434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 319534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 319634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31970cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3198c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3199ae7bd9ccSMatthieu Baerts fi 32000cddb4a6SGeliang Tang} 32010cddb4a6SGeliang Tang 32024f49d633SGeliang Tangfullmesh_tests() 32034f49d633SGeliang Tang{ 32044f49d633SGeliang Tang # fullmesh 1 32054f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 32064f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 3207c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 320834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 320934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 321034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 321134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 3212e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 3213e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3214c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 32154f49d633SGeliang Tang chk_add_nr 1 1 3216ae7bd9ccSMatthieu Baerts fi 32174f49d633SGeliang Tang 32184f49d633SGeliang Tang # fullmesh 2 32194f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32204f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 3221c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 322234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 322334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 322434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3225f845af67SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,fullmesh 3226e571fb09SGeliang Tang fullmesh=1 speed=slow \ 3227e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3228c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 32294f49d633SGeliang Tang chk_add_nr 1 1 3230ae7bd9ccSMatthieu Baerts fi 32314f49d633SGeliang Tang 32324f49d633SGeliang Tang # fullmesh 3 32334f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32344f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 3235c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 323634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 323734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 323834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3239e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3240e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3241c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 32424f49d633SGeliang Tang chk_add_nr 1 1 3243ae7bd9ccSMatthieu Baerts fi 32444f49d633SGeliang Tang 32454f49d633SGeliang Tang # fullmesh 4 32464f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32474f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 32484f49d633SGeliang Tang # limit max_subflows to 4. 3249c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 325034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 325134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 325234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3253e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3254e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3255c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 32564f49d633SGeliang Tang chk_add_nr 1 1 3257ae7bd9ccSMatthieu Baerts fi 32586a0653b9SGeliang Tang 32596a0653b9SGeliang Tang # set fullmesh flag 32609db34c42SMatthieu Baerts if reset "set fullmesh flag test" && 32619db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 326234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 326334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 326434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3265e571fb09SGeliang Tang addr_nr_ns2=1 sflags=fullmesh speed=slow \ 3266e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3267c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32686a0653b9SGeliang Tang chk_rm_nr 0 1 3269ae7bd9ccSMatthieu Baerts fi 32706a0653b9SGeliang Tang 32716a0653b9SGeliang Tang # set nofullmesh flag 32729db34c42SMatthieu Baerts if reset "set nofullmesh flag test" && 32739db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 327434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 327534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 327634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3277e571fb09SGeliang Tang fullmesh=1 sflags=nofullmesh speed=slow \ 3278e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3279c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32806a0653b9SGeliang Tang chk_rm_nr 0 1 3281ae7bd9ccSMatthieu Baerts fi 32826a0653b9SGeliang Tang 32836a0653b9SGeliang Tang # set backup,fullmesh flags 32849db34c42SMatthieu Baerts if reset "set backup,fullmesh flags test" && 32859db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 328634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 328734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 328834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3289e571fb09SGeliang Tang addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \ 3290e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3291c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32928213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 32936a0653b9SGeliang Tang chk_rm_nr 0 1 3294ae7bd9ccSMatthieu Baerts fi 32956a0653b9SGeliang Tang 32966a0653b9SGeliang Tang # set nobackup,nofullmesh flags 32979db34c42SMatthieu Baerts if reset "set nobackup,nofullmesh flags test" && 32989db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 329934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 330034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 330134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3302e571fb09SGeliang Tang sflags=nobackup,nofullmesh speed=slow \ 3303e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3304c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 33058213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 33066a0653b9SGeliang Tang chk_rm_nr 0 1 3307ae7bd9ccSMatthieu Baerts fi 33084f49d633SGeliang Tang} 33094f49d633SGeliang Tang 331001542c9bSGeliang Tangfastclose_tests() 331101542c9bSGeliang Tang{ 3312ae947bb2SMatthieu Baerts if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then 3313080b7f57SGeliang Tang test_linkfail=1024 fastclose=client \ 3314595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3315c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 331601542c9bSGeliang Tang chk_fclose_nr 1 1 331701542c9bSGeliang Tang chk_rst_nr 1 1 invert 3318ae7bd9ccSMatthieu Baerts fi 33196bf41020SPaolo Abeni 3320ae947bb2SMatthieu Baerts if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then 3321080b7f57SGeliang Tang test_linkfail=1024 fastclose=server \ 3322595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 332355dd3816SPaolo Abeni chk_join_nr 0 0 0 0 0 0 1 33246bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 33256bf41020SPaolo Abeni chk_rst_nr 1 1 33266bf41020SPaolo Abeni fi 332701542c9bSGeliang Tang} 332801542c9bSGeliang Tang 3329b6e074e1SGeliang Tangpedit_action_pkts() 3330b6e074e1SGeliang Tang{ 3331b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3332ae1fa39dSGeliang Tang mptcp_lib_get_info_value \"packets\" packets 3333b6e074e1SGeliang Tang} 3334b6e074e1SGeliang Tang 3335b6e074e1SGeliang Tangfail_tests() 3336b6e074e1SGeliang Tang{ 3337b6e074e1SGeliang Tang # single subflow 3338b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 3339562f8862SMatthieu Baerts (NGI0) MPTCP_LIB_SUBTEST_FLAKY=1 33400c93af1fSGeliang Tang test_linkfail=128 \ 33410c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3342b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 33431f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3344b6e074e1SGeliang Tang fi 33452ba18161SGeliang Tang 33462ba18161SGeliang Tang # multiple subflows 33472ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 3348562f8862SMatthieu Baerts (NGI0) MPTCP_LIB_SUBTEST_FLAKY=1 334999ac814eSGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5ms 33502ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 33512ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 33522ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 33530c93af1fSGeliang Tang test_linkfail=1024 \ 33540c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 33552ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 33562ba18161SGeliang Tang fi 3357b6e074e1SGeliang Tang} 3358b6e074e1SGeliang Tang 33599d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 33604369c198SGeliang Tanguserspace_pm_add_addr() 33614369c198SGeliang Tang{ 33629d71f43aSGeliang Tang local evts=$evts_ns1 33634369c198SGeliang Tang local tk 33644369c198SGeliang Tang 33659d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33669d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33679d71f43aSGeliang Tang 33689d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3 33694369c198SGeliang Tang sleep 1 33704369c198SGeliang Tang} 33714369c198SGeliang Tang 33729d71f43aSGeliang Tang# $1: ns ; $2: id 33739d71f43aSGeliang Tanguserspace_pm_rm_addr() 33744369c198SGeliang Tang{ 33759d71f43aSGeliang Tang local evts=$evts_ns1 33769d71f43aSGeliang Tang local tk 33779d71f43aSGeliang Tang local cnt 33784369c198SGeliang Tang 33799d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33809d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33819d71f43aSGeliang Tang 33829d71f43aSGeliang Tang cnt=$(rm_addr_count ${1}) 33839d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl rem token $tk id $2 33849d71f43aSGeliang Tang wait_rm_addr $1 "${cnt}" 33854369c198SGeliang Tang} 33864369c198SGeliang Tang 33879d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 33884369c198SGeliang Tanguserspace_pm_add_sf() 33894369c198SGeliang Tang{ 33909d71f43aSGeliang Tang local evts=$evts_ns1 33914369c198SGeliang Tang local tk da dp 33924369c198SGeliang Tang 33939d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33949d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33959d71f43aSGeliang Tang da=$(mptcp_lib_evts_get_info daddr4 "$evts") 33969d71f43aSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts") 33979d71f43aSGeliang Tang 33989d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \ 33994369c198SGeliang Tang rip $da rport $dp token $tk 34004369c198SGeliang Tang sleep 1 34014369c198SGeliang Tang} 34024369c198SGeliang Tang 34039d71f43aSGeliang Tang# $1: ns ; $2: addr $3: event type 34049d71f43aSGeliang Tanguserspace_pm_rm_sf() 34054369c198SGeliang Tang{ 34069d71f43aSGeliang Tang local evts=$evts_ns1 34079d71f43aSGeliang Tang local t=${3:-1} 3408ece1aaecSGeliang Tang local ip 34094369c198SGeliang Tang local tk da dp sp 34109d71f43aSGeliang Tang local cnt 34114369c198SGeliang Tang 34129d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 3413ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr4" "$evts" $t)" ] && ip=4 3414ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr6" "$evts" $t)" ] && ip=6 34159d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 3416ece1aaecSGeliang Tang da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t $2) 3417ece1aaecSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts" $t $2) 3418ece1aaecSGeliang Tang sp=$(mptcp_lib_evts_get_info sport "$evts" $t $2) 34199d71f43aSGeliang Tang 34209d71f43aSGeliang Tang cnt=$(rm_sf_count ${1}) 34219d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \ 34224369c198SGeliang Tang rip $da rport $dp token $tk 34239d71f43aSGeliang Tang wait_rm_sf $1 "${cnt}" 34244369c198SGeliang Tang} 34254369c198SGeliang Tang 34261b8af4baSGeliang Tangcheck_output() 34271b8af4baSGeliang Tang{ 34281b8af4baSGeliang Tang local cmd="$1" 34291b8af4baSGeliang Tang local expected="$2" 34301b8af4baSGeliang Tang local msg="$3" 34311b8af4baSGeliang Tang local rc=0 34321b8af4baSGeliang Tang 34331b8af4baSGeliang Tang mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?} 34341b8af4baSGeliang Tang if [ ${rc} -eq 2 ]; then 34351b8af4baSGeliang Tang fail_test "fail to check output # error ${rc}" 34361b8af4baSGeliang Tang elif [ ${rc} -eq 0 ]; then 34371b8af4baSGeliang Tang print_ok 34381b8af4baSGeliang Tang elif [ ${rc} -eq 1 ]; then 34391b8af4baSGeliang Tang fail_test "fail to check output # different output" 34401b8af4baSGeliang Tang fi 34411b8af4baSGeliang Tang} 34421b8af4baSGeliang Tang 34431b8af4baSGeliang Tang# $1: ns 34441b8af4baSGeliang Tanguserspace_pm_dump() 34451b8af4baSGeliang Tang{ 34461b8af4baSGeliang Tang local evts=$evts_ns1 34471b8af4baSGeliang Tang local tk 34481b8af4baSGeliang Tang 34491b8af4baSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 34501b8af4baSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 34511b8af4baSGeliang Tang 34521b8af4baSGeliang Tang ip netns exec $1 ./pm_nl_ctl dump token $tk 34531b8af4baSGeliang Tang} 34541b8af4baSGeliang Tang 3455485bb198SGeliang Tang# $1: ns ; $2: id 3456485bb198SGeliang Tanguserspace_pm_get_addr() 3457485bb198SGeliang Tang{ 3458485bb198SGeliang Tang local evts=$evts_ns1 3459485bb198SGeliang Tang local tk 3460485bb198SGeliang Tang 3461485bb198SGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 3462485bb198SGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 3463485bb198SGeliang Tang 3464485bb198SGeliang Tang ip netns exec $1 ./pm_nl_ctl get $2 token $tk 3465485bb198SGeliang Tang} 3466485bb198SGeliang Tang 34671b8af4baSGeliang Tanguserspace_pm_chk_dump_addr() 34681b8af4baSGeliang Tang{ 34691b8af4baSGeliang Tang local ns="${1}" 34701b8af4baSGeliang Tang local exp="${2}" 34711b8af4baSGeliang Tang local check="${3}" 34721b8af4baSGeliang Tang 34731b8af4baSGeliang Tang print_check "dump addrs ${check}" 34741b8af4baSGeliang Tang 34751b8af4baSGeliang Tang if mptcp_lib_kallsyms_has "mptcp_userspace_pm_dump_addr$"; then 34761b8af4baSGeliang Tang check_output "userspace_pm_dump ${ns}" "${exp}" 34771b8af4baSGeliang Tang else 34781b8af4baSGeliang Tang print_skip 34791b8af4baSGeliang Tang fi 34801b8af4baSGeliang Tang} 34811b8af4baSGeliang Tang 3482485bb198SGeliang Tanguserspace_pm_chk_get_addr() 3483485bb198SGeliang Tang{ 3484485bb198SGeliang Tang local ns="${1}" 3485485bb198SGeliang Tang local id="${2}" 3486485bb198SGeliang Tang local exp="${3}" 3487485bb198SGeliang Tang 3488485bb198SGeliang Tang print_check "get id ${id} addr" 3489485bb198SGeliang Tang 3490485bb198SGeliang Tang if mptcp_lib_kallsyms_has "mptcp_userspace_pm_get_addr$"; then 3491485bb198SGeliang Tang check_output "userspace_pm_get_addr ${ns} ${id}" "${exp}" 3492485bb198SGeliang Tang else 3493485bb198SGeliang Tang print_skip 3494485bb198SGeliang Tang fi 3495485bb198SGeliang Tang} 3496485bb198SGeliang Tang 3497a417ef47SMatthieu Baerts (NGI0)# $1: ns ; $2: event type ; $3: count 3498a417ef47SMatthieu Baerts (NGI0)chk_evt_nr() 3499a417ef47SMatthieu Baerts (NGI0){ 3500a417ef47SMatthieu Baerts (NGI0) local ns=${1} 3501a417ef47SMatthieu Baerts (NGI0) local evt_name="${2}" 3502a417ef47SMatthieu Baerts (NGI0) local exp="${3}" 3503a417ef47SMatthieu Baerts (NGI0) 3504a417ef47SMatthieu Baerts (NGI0) local evts="${evts_ns1}" 3505a417ef47SMatthieu Baerts (NGI0) local evt="${!evt_name}" 3506a417ef47SMatthieu Baerts (NGI0) local count 3507a417ef47SMatthieu Baerts (NGI0) 3508a417ef47SMatthieu Baerts (NGI0) evt_name="${evt_name:16}" # without MPTCP_LIB_EVENT_ 3509a417ef47SMatthieu Baerts (NGI0) [ "${ns}" == "ns2" ] && evts="${evts_ns2}" 3510a417ef47SMatthieu Baerts (NGI0) 3511a417ef47SMatthieu Baerts (NGI0) print_check "event ${ns} ${evt_name} (${exp})" 3512a417ef47SMatthieu Baerts (NGI0) 3513a417ef47SMatthieu Baerts (NGI0) if [[ "${evt_name}" = "LISTENER_"* ]] && 3514a417ef47SMatthieu Baerts (NGI0) ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 3515a417ef47SMatthieu Baerts (NGI0) print_skip "event not supported" 3516a417ef47SMatthieu Baerts (NGI0) return 3517a417ef47SMatthieu Baerts (NGI0) fi 3518a417ef47SMatthieu Baerts (NGI0) 3519a417ef47SMatthieu Baerts (NGI0) count=$(grep -cw "type:${evt}" "${evts}") 3520a417ef47SMatthieu Baerts (NGI0) if [ "${count}" != "${exp}" ]; then 3521a417ef47SMatthieu Baerts (NGI0) fail_test "got ${count} events, expected ${exp}" 3522a417ef47SMatthieu Baerts (NGI0) else 3523a417ef47SMatthieu Baerts (NGI0) print_ok 3524a417ef47SMatthieu Baerts (NGI0) fi 3525a417ef47SMatthieu Baerts (NGI0)} 3526a417ef47SMatthieu Baerts (NGI0) 35275ac1d2d6SMat Martineauuserspace_tests() 35285ac1d2d6SMat Martineau{ 35295ac1d2d6SMat Martineau # userspace pm type prevents add_addr 3530f2b492b0SMatthieu Baerts if reset "userspace pm type prevents add_addr" && 3531f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35325ac1d2d6SMat Martineau set_userspace_pm $ns1 35335ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 35345ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 35355ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 35365ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 35375ac1d2d6SMat Martineau chk_join_nr 0 0 0 35385ac1d2d6SMat Martineau chk_add_nr 0 0 35395ac1d2d6SMat Martineau fi 35405ac1d2d6SMat Martineau 3541b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3542f2b492b0SMatthieu Baerts if reset "userspace pm no echo w/o daemon" && 3543f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3544b3b71bf9SMat Martineau set_userspace_pm $ns2 3545b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3546b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3547b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3548b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3549b3b71bf9SMat Martineau chk_join_nr 0 0 0 3550b3b71bf9SMat Martineau chk_add_nr 1 0 3551b3b71bf9SMat Martineau fi 3552b3b71bf9SMat Martineau 35535ac1d2d6SMat Martineau # userspace pm type rejects join 3554f2b492b0SMatthieu Baerts if reset "userspace pm type rejects join" && 3555f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35565ac1d2d6SMat Martineau set_userspace_pm $ns1 35575ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 35585ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 35595ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 35605ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 35615ac1d2d6SMat Martineau chk_join_nr 1 1 0 35625ac1d2d6SMat Martineau fi 35635ac1d2d6SMat Martineau 35645ac1d2d6SMat Martineau # userspace pm type does not send join 3565f2b492b0SMatthieu Baerts if reset "userspace pm type does not send join" && 3566f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35675ac1d2d6SMat Martineau set_userspace_pm $ns2 35685ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 35695ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 35705ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 35715ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 35725ac1d2d6SMat Martineau chk_join_nr 0 0 0 35735ac1d2d6SMat Martineau fi 35745ac1d2d6SMat Martineau 35755ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 3576f2b492b0SMatthieu Baerts if reset "userspace pm type prevents mp_prio" && 3577f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35785ac1d2d6SMat Martineau set_userspace_pm $ns1 35795ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 35805ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 35815ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3582e571fb09SGeliang Tang sflags=backup speed=slow \ 3583e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 35845ac1d2d6SMat Martineau chk_join_nr 1 1 0 35858213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 0 0 0 35865ac1d2d6SMat Martineau fi 35875ac1d2d6SMat Martineau 35885ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 3589f2b492b0SMatthieu Baerts if reset "userspace pm type prevents rm_addr" && 3590f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35915ac1d2d6SMat Martineau set_userspace_pm $ns1 35925ac1d2d6SMat Martineau set_userspace_pm $ns2 35935ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 35945ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 35955ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3596e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 3597e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 35985ac1d2d6SMat Martineau chk_join_nr 0 0 0 35995ac1d2d6SMat Martineau chk_rm_nr 0 0 36005ac1d2d6SMat Martineau fi 360197040cf9SGeliang Tang 360297040cf9SGeliang Tang # userspace pm add & remove address 3603f2b492b0SMatthieu Baerts if reset_with_events "userspace pm add & remove address" && 3604f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 360597040cf9SGeliang Tang set_userspace_pm $ns1 3606ece1aaecSGeliang Tang pm_nl_set_limits $ns2 2 2 36071c6d07ddSGeliang Tang speed=5 \ 3608e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 36094369c198SGeliang Tang local tests_pid=$! 36104369c198SGeliang Tang wait_mpj $ns1 36119d71f43aSGeliang Tang userspace_pm_add_addr $ns1 10.0.2.1 10 3612ece1aaecSGeliang Tang userspace_pm_add_addr $ns1 10.0.3.1 20 3613ece1aaecSGeliang Tang chk_join_nr 2 2 2 3614ece1aaecSGeliang Tang chk_add_nr 2 2 3615ece1aaecSGeliang Tang chk_mptcp_info subflows 2 subflows 2 3616ece1aaecSGeliang Tang chk_subflows_total 3 3 3617ece1aaecSGeliang Tang chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 36181b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns1}" \ 36191b8af4baSGeliang Tang $'id 10 flags signal 10.0.2.1\nid 20 flags signal 10.0.3.1' \ 36201b8af4baSGeliang Tang "signal" 3621485bb198SGeliang Tang userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1" 3622485bb198SGeliang Tang userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1" 3623a17d1419SGeliang Tang userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED 36241b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns1}" \ 36258863e430SMatthieu Baerts (NGI0) "id 20 flags signal 10.0.3.1" "after rm_sf 10" 3626ece1aaecSGeliang Tang userspace_pm_rm_addr $ns1 20 36271b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20" 36288863e430SMatthieu Baerts (NGI0) chk_rm_nr 1 1 invert 3629d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3630f9190d79SGeliang Tang chk_subflows_total 1 1 3631a3735625SGeliang Tang kill_events_pids 3632a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 363397040cf9SGeliang Tang fi 36345e986ec4SGeliang Tang 36355e986ec4SGeliang Tang # userspace pm create destroy subflow 3636f2b492b0SMatthieu Baerts if reset_with_events "userspace pm create destroy subflow" && 3637f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 36385e986ec4SGeliang Tang set_userspace_pm $ns2 36395e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 36401c6d07ddSGeliang Tang speed=5 \ 3641e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 36424369c198SGeliang Tang local tests_pid=$! 36434369c198SGeliang Tang wait_mpj $ns2 36449d71f43aSGeliang Tang userspace_pm_add_sf $ns2 10.0.3.2 20 36455e986ec4SGeliang Tang chk_join_nr 1 1 1 3646d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3647f9190d79SGeliang Tang chk_subflows_total 2 2 36481b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns2}" \ 36491b8af4baSGeliang Tang "id 20 flags subflow 10.0.3.2" \ 36501b8af4baSGeliang Tang "subflow" 3651485bb198SGeliang Tang userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2" 3652a17d1419SGeliang Tang userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED 36531b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns2}" \ 36541b8af4baSGeliang Tang "" \ 36558863e430SMatthieu Baerts (NGI0) "after rm_sf 20" 36568863e430SMatthieu Baerts (NGI0) chk_rm_nr 0 1 3657d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3658f9190d79SGeliang Tang chk_subflows_total 1 1 3659a3735625SGeliang Tang kill_events_pids 3660a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 36615e986ec4SGeliang Tang fi 366205867195SGeliang Tang 366305867195SGeliang Tang # userspace pm create id 0 subflow 366405867195SGeliang Tang if reset_with_events "userspace pm create id 0 subflow" && 366505867195SGeliang Tang continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 366605867195SGeliang Tang set_userspace_pm $ns2 366705867195SGeliang Tang pm_nl_set_limits $ns1 0 1 366805867195SGeliang Tang speed=5 \ 366905867195SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 367005867195SGeliang Tang local tests_pid=$! 367105867195SGeliang Tang wait_mpj $ns2 367205867195SGeliang Tang chk_mptcp_info subflows 0 subflows 0 367305867195SGeliang Tang chk_subflows_total 1 1 367405867195SGeliang Tang userspace_pm_add_sf $ns2 10.0.3.2 0 36751b8af4baSGeliang Tang userspace_pm_chk_dump_addr "${ns2}" \ 36761b8af4baSGeliang Tang "id 0 flags subflow 10.0.3.2" "id 0 subflow" 367705867195SGeliang Tang chk_join_nr 1 1 1 367805867195SGeliang Tang chk_mptcp_info subflows 1 subflows 1 367905867195SGeliang Tang chk_subflows_total 2 2 368005867195SGeliang Tang kill_events_pids 368105867195SGeliang Tang wait $tests_pid 368205867195SGeliang Tang fi 36835ac1d2d6SMat Martineau} 36845ac1d2d6SMat Martineau 3685e274f715SPaolo Abeniendpoint_tests() 368669c6ce7bSPaolo Abeni{ 368736c4127aSMatthieu Baerts # subflow_rebuild_header is needed to support the implicit flag 368869c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 368936c4127aSMatthieu Baerts if reset "implicit EP" && 369036c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 369169c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 369269c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 369369c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3694e571fb09SGeliang Tang speed=slow \ 3695358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3696358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 369769c6ce7bSPaolo Abeni 369869c6ce7bSPaolo Abeni wait_mpj $ns1 369903668c65SMatthieu Baerts pm_nl_check_endpoint "creation" \ 370069c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 3701d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3702d7ced753SGeliang Tang chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 370369c6ce7bSPaolo Abeni 37041dc88d24SMatthieu Baerts pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null 370503668c65SMatthieu Baerts pm_nl_check_endpoint "ID change is prevented" \ 370669c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 370769c6ce7bSPaolo Abeni 370869c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 370903668c65SMatthieu Baerts pm_nl_check_endpoint "modif is allowed" \ 371069c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3711358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3712ae7bd9ccSMatthieu Baerts fi 3713e274f715SPaolo Abeni 3714ce2f28a5SMatthieu Baerts (NGI0) if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT && 371536c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3716a417ef47SMatthieu Baerts (NGI0) start_events 3717a81c87acSMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 3 3718a81c87acSMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 0 3 3719a81c87acSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow 3720e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 372109c423d6SMatthieu Baerts (NGI0) test_linkfail=4 speed=5 \ 3722358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3723358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 3724e274f715SPaolo Abeni 3725e274f715SPaolo Abeni wait_mpj $ns2 3726117eed29SGeliang Tang pm_nl_check_endpoint "creation" \ 3727117eed29SGeliang Tang $ns2 10.0.2.2 id 2 flags subflow dev ns2eth2 3728a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "before delete id 2" 2 3729d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 37309095ce97SGeliang Tang 3731e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3732e274f715SPaolo Abeni sleep 0.5 3733a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "after delete id 2" 1 3734d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3735e274f715SPaolo Abeni 3736ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3737e274f715SPaolo Abeni wait_mpj $ns2 3738a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "after re-add id 2" 2 3739d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3740ce2f28a5SMatthieu Baerts (NGI0) 3741ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow 3742ce2f28a5SMatthieu Baerts (NGI0) wait_attempt_fail $ns2 3743ce2f28a5SMatthieu Baerts (NGI0) chk_subflow_nr "after new reject" 2 3744ce2f28a5SMatthieu Baerts (NGI0) chk_mptcp_info subflows 1 subflows 1 3745ce2f28a5SMatthieu Baerts (NGI0) 3746ce2f28a5SMatthieu Baerts (NGI0) ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT 3747ce2f28a5SMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns2 3 10.0.3.2 3748ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow 3749ce2f28a5SMatthieu Baerts (NGI0) wait_mpj $ns2 3750ce2f28a5SMatthieu Baerts (NGI0) chk_subflow_nr "after no reject" 3 3751ce2f28a5SMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 3752ce2f28a5SMatthieu Baerts (NGI0) 375309c423d6SMatthieu Baerts (NGI0) local i 375409c423d6SMatthieu Baerts (NGI0) for i in $(seq 3); do 3755a81c87acSMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns2 1 10.0.1.2 3756a81c87acSMatthieu Baerts (NGI0) sleep 0.5 375709c423d6SMatthieu Baerts (NGI0) chk_subflow_nr "after delete id 0 ($i)" 2 3758a81c87acSMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 # only decr for additional sf 3759a81c87acSMatthieu Baerts (NGI0) 3760a81c87acSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow 3761a81c87acSMatthieu Baerts (NGI0) wait_mpj $ns2 376209c423d6SMatthieu Baerts (NGI0) chk_subflow_nr "after re-add id 0 ($i)" 3 3763a81c87acSMatthieu Baerts (NGI0) chk_mptcp_info subflows 3 subflows 3 376409c423d6SMatthieu Baerts (NGI0) done 3765a81c87acSMatthieu Baerts (NGI0) 3766358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3767ce2f28a5SMatthieu Baerts (NGI0) 3768a417ef47SMatthieu Baerts (NGI0) kill_events_pids 3769a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1 3770a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_CREATED 1 3771a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_ESTABLISHED 1 3772a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_ANNOUNCED 0 3773a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_REMOVED 4 3774a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_ESTABLISHED 6 3775a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_CLOSED 4 3776a417ef47SMatthieu Baerts (NGI0) 3777a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_CREATED 1 3778a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_ESTABLISHED 1 3779a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_ANNOUNCED 0 3780a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_REMOVED 0 3781a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_ESTABLISHED 6 3782a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_CLOSED 5 # one has been closed before estab 3783a417ef47SMatthieu Baerts (NGI0) 378409c423d6SMatthieu Baerts (NGI0) chk_join_nr 6 6 6 378509c423d6SMatthieu Baerts (NGI0) chk_rm_nr 4 4 3786e274f715SPaolo Abeni fi 3787a95e3e70SPaolo Abeni 3788a95e3e70SPaolo Abeni # remove and re-add 3789a417ef47SMatthieu Baerts (NGI0) if reset_with_events "delete re-add signal" && 3790a95e3e70SPaolo Abeni mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 37910a37a0ecSMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 3 37920a37a0ecSMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 3 3 3793a95e3e70SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 id 1 flags signal 379443ca9a10SMatthieu Baerts (NGI0) # broadcast IP: no packet for this address will be received on ns1 379543ca9a10SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 224.0.0.1 id 2 flags signal 37960a37a0ecSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.1.1 id 42 flags signal 3797*f9ca09beSMatthieu Baerts (NGI0) test_linkfail=4 speed=5 \ 3798a95e3e70SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 & 3799a95e3e70SPaolo Abeni local tests_pid=$! 3800a95e3e70SPaolo Abeni 3801a95e3e70SPaolo Abeni wait_mpj $ns2 3802a95e3e70SPaolo Abeni pm_nl_check_endpoint "creation" \ 3803a95e3e70SPaolo Abeni $ns1 10.0.2.1 id 1 flags signal 3804a95e3e70SPaolo Abeni chk_subflow_nr "before delete" 2 3805a95e3e70SPaolo Abeni chk_mptcp_info subflows 1 subflows 1 3806a95e3e70SPaolo Abeni 3807a95e3e70SPaolo Abeni pm_nl_del_endpoint $ns1 1 10.0.2.1 380843ca9a10SMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns1 2 224.0.0.1 3809a95e3e70SPaolo Abeni sleep 0.5 3810a95e3e70SPaolo Abeni chk_subflow_nr "after delete" 1 3811a95e3e70SPaolo Abeni chk_mptcp_info subflows 0 subflows 0 3812a95e3e70SPaolo Abeni 381343ca9a10SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 id 1 flags signal 381443ca9a10SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal 3815a95e3e70SPaolo Abeni wait_mpj $ns2 381643ca9a10SMatthieu Baerts (NGI0) chk_subflow_nr "after re-add" 3 381743ca9a10SMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 38180a37a0ecSMatthieu Baerts (NGI0) 38190a37a0ecSMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns1 42 10.0.1.1 38200a37a0ecSMatthieu Baerts (NGI0) sleep 0.5 38210a37a0ecSMatthieu Baerts (NGI0) chk_subflow_nr "after delete ID 0" 2 38220a37a0ecSMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 38230a37a0ecSMatthieu Baerts (NGI0) 38240a37a0ecSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.1.1 id 99 flags signal 38250a37a0ecSMatthieu Baerts (NGI0) wait_mpj $ns2 3826*f9ca09beSMatthieu Baerts (NGI0) chk_subflow_nr "after re-add ID 0" 3 3827*f9ca09beSMatthieu Baerts (NGI0) chk_mptcp_info subflows 3 subflows 3 3828*f9ca09beSMatthieu Baerts (NGI0) 3829*f9ca09beSMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns1 99 10.0.1.1 3830*f9ca09beSMatthieu Baerts (NGI0) sleep 0.5 3831*f9ca09beSMatthieu Baerts (NGI0) chk_subflow_nr "after re-delete ID 0" 2 3832*f9ca09beSMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 3833*f9ca09beSMatthieu Baerts (NGI0) 3834*f9ca09beSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.1.1 id 88 flags signal 3835*f9ca09beSMatthieu Baerts (NGI0) wait_mpj $ns2 3836*f9ca09beSMatthieu Baerts (NGI0) chk_subflow_nr "after re-re-add ID 0" 3 38370a37a0ecSMatthieu Baerts (NGI0) chk_mptcp_info subflows 3 subflows 3 3838a95e3e70SPaolo Abeni mptcp_lib_kill_wait $tests_pid 383943ca9a10SMatthieu Baerts (NGI0) 3840a417ef47SMatthieu Baerts (NGI0) kill_events_pids 3841a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_LISTENER_CREATED 1 3842a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_CREATED 1 3843a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_ESTABLISHED 1 3844a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_ANNOUNCED 0 3845a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_REMOVED 0 3846*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_ESTABLISHED 5 3847*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns1 MPTCP_LIB_EVENT_SUB_CLOSED 3 3848a417ef47SMatthieu Baerts (NGI0) 3849a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_CREATED 1 3850a417ef47SMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_ESTABLISHED 1 3851*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_ANNOUNCED 6 3852*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_REMOVED 4 3853*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_ESTABLISHED 5 3854*f9ca09beSMatthieu Baerts (NGI0) chk_evt_nr ns2 MPTCP_LIB_EVENT_SUB_CLOSED 3 3855a417ef47SMatthieu Baerts (NGI0) 3856*f9ca09beSMatthieu Baerts (NGI0) chk_join_nr 5 5 5 3857*f9ca09beSMatthieu Baerts (NGI0) chk_add_nr 6 6 3858*f9ca09beSMatthieu Baerts (NGI0) chk_rm_nr 4 3 invert 3859a95e3e70SPaolo Abeni fi 3860a95e3e70SPaolo Abeni 386169c6ce7bSPaolo Abeni} 386269c6ce7bSPaolo Abeni 386322514d52SMatthieu Baerts# [$1: error message] 38641002b89fSGeliang Tangusage() 38651002b89fSGeliang Tang{ 386622514d52SMatthieu Baerts if [ -n "${1}" ]; then 386722514d52SMatthieu Baerts echo "${1}" 386822514d52SMatthieu Baerts ret=1 386922514d52SMatthieu Baerts fi 387022514d52SMatthieu Baerts 38711002b89fSGeliang Tang echo "mptcp_join usage:" 38723afd0280SMatthieu Baerts 38733afd0280SMatthieu Baerts local key 38743afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 38753afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 38763afd0280SMatthieu Baerts done 38773afd0280SMatthieu Baerts 3878a673321aSMat Martineau echo " -c capture pcap files" 3879af66d3e1SGeliang Tang echo " -C enable data checksum" 3880621bd393SGeliang Tang echo " -i use ip mptcp" 38811002b89fSGeliang Tang echo " -h help" 388222514d52SMatthieu Baerts 3883c7d49c03SMatthieu Baerts echo "[test ids|names]" 3884ae7bd9ccSMatthieu Baerts 388522514d52SMatthieu Baerts exit ${ret} 38861002b89fSGeliang Tang} 38871002b89fSGeliang Tang 3888a673321aSMat Martineau 38893afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 38903afd0280SMatthieu Baertsall_tests_sorted=( 38913afd0280SMatthieu Baerts f@subflows_tests 38923afd0280SMatthieu Baerts e@subflows_error_tests 38933afd0280SMatthieu Baerts s@signal_address_tests 38943afd0280SMatthieu Baerts l@link_failure_tests 38953afd0280SMatthieu Baerts t@add_addr_timeout_tests 38963afd0280SMatthieu Baerts r@remove_tests 38973afd0280SMatthieu Baerts a@add_tests 38983afd0280SMatthieu Baerts 6@ipv6_tests 38993afd0280SMatthieu Baerts 4@v4mapped_tests 3900ad349374SPaolo Abeni M@mixed_tests 39013afd0280SMatthieu Baerts b@backup_tests 39023afd0280SMatthieu Baerts p@add_addr_ports_tests 39033afd0280SMatthieu Baerts k@syncookies_tests 39043afd0280SMatthieu Baerts S@checksum_tests 39053afd0280SMatthieu Baerts d@deny_join_id0_tests 39063afd0280SMatthieu Baerts m@fullmesh_tests 39073afd0280SMatthieu Baerts z@fastclose_tests 3908b6e074e1SGeliang Tang F@fail_tests 39095ac1d2d6SMat Martineau u@userspace_tests 3910e274f715SPaolo Abeni I@endpoint_tests 39113afd0280SMatthieu Baerts) 39123afd0280SMatthieu Baerts 39133afd0280SMatthieu Baertsall_tests_args="" 39143afd0280SMatthieu Baertsall_tests_names=() 39153afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 39163afd0280SMatthieu Baerts key="${subtests%@*}" 39173afd0280SMatthieu Baerts value="${subtests#*@}" 39183afd0280SMatthieu Baerts 39193afd0280SMatthieu Baerts all_tests_args+="${key}" 39203afd0280SMatthieu Baerts all_tests_names+=("${value}") 39213afd0280SMatthieu Baerts all_tests[${key}]="${value}" 39223afd0280SMatthieu Baertsdone 39233afd0280SMatthieu Baerts 3924826d7bdcSMatthieu Baertstests=() 39253afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 39261002b89fSGeliang Tang case $opt in 39273afd0280SMatthieu Baerts ["${all_tests_args}"]) 39283afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 392969c6ce7bSPaolo Abeni ;; 3930a673321aSMat Martineau c) 3931826d7bdcSMatthieu Baerts capture=1 3932a673321aSMat Martineau ;; 3933af66d3e1SGeliang Tang C) 3934826d7bdcSMatthieu Baerts checksum=1 3935af66d3e1SGeliang Tang ;; 3936621bd393SGeliang Tang i) 3937826d7bdcSMatthieu Baerts ip_mptcp=1 3938621bd393SGeliang Tang ;; 393922514d52SMatthieu Baerts h) 39401002b89fSGeliang Tang usage 39411002b89fSGeliang Tang ;; 394222514d52SMatthieu Baerts *) 394322514d52SMatthieu Baerts usage "Unknown option: -${opt}" 394422514d52SMatthieu Baerts ;; 39451002b89fSGeliang Tang esac 39461002b89fSGeliang Tangdone 394700587187SFlorian Westphal 3948ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3949ae7bd9ccSMatthieu Baerts 3950ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3951ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3952c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3953ae7bd9ccSMatthieu Baerts else 3954c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3955ae7bd9ccSMatthieu Baerts fi 3956ae7bd9ccSMatthieu Baertsdone 3957ae7bd9ccSMatthieu Baerts 3958826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 39593afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 39603afd0280SMatthieu Baertsfi 39613afd0280SMatthieu Baerts 3962826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3963826d7bdcSMatthieu Baerts "${subtests}" 3964826d7bdcSMatthieu Baertsdone 3965826d7bdcSMatthieu Baerts 396639aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 396739aab882SMatthieu Baerts echo 396839aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 396939aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 397039aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 397139aab882SMatthieu Baerts done 397239aab882SMatthieu Baerts echo 397339aab882SMatthieu Baertsfi 397439aab882SMatthieu Baerts 39757f117cd3SMatthieu Baertsappend_prev_results 39767f117cd3SMatthieu Baertsmptcp_lib_result_print_all_tap 39777f117cd3SMatthieu Baerts 3978b08fbf24SPaolo Abeniexit $ret 3979