1b08fbf24SPaolo Abeni#!/bin/bash 2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0 3b08fbf24SPaolo Abeni 4d8d08302SMatthieu Baerts# Double quotes to prevent globbing and word splitting is recommended in new 5d8d08302SMatthieu Baerts# code but we accept it, especially because there were too many before having 6d8d08302SMatthieu Baerts# address all other issues detected by shellcheck. 7d8d08302SMatthieu Baerts#shellcheck disable=SC2086 8d8d08302SMatthieu Baerts 90fcd72dfSMatthieu Baerts# ShellCheck incorrectly believes that most of the code here is unreachable 100fcd72dfSMatthieu Baerts# because it's invoked by variable name, see how the "tests" array is used 110fcd72dfSMatthieu Baerts#shellcheck disable=SC2317 120fcd72dfSMatthieu Baerts 13715c78a8SMatthieu Baerts. "$(dirname "${0}")/mptcp_lib.sh" 14715c78a8SMatthieu Baerts 15b08fbf24SPaolo Abeniret=0 16b08fbf24SPaolo Abenisin="" 177d1e6f16SPaolo Abenisinfail="" 18b08fbf24SPaolo Abenisout="" 19b08fbf24SPaolo Abenicin="" 207d1e6f16SPaolo Abenicinfail="" 218b819a84SFlorian Westphalcinsent="" 22d328fe87SMatthieu Baertstmpfile="" 23b08fbf24SPaolo Abenicout="" 241e777bd8SMatthieu Baertscapout="" 251e777bd8SMatthieu Baertsns1="" 261e777bd8SMatthieu Baertsns2="" 27b08fbf24SPaolo Abeniksft_skip=4 280c4cd3f8SMatthieu Baertsiptables="iptables" 290c4cd3f8SMatthieu Baertsip6tables="ip6tables" 305888a61cSMatthieu Baertstimeout_poll=30 315888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1)) 32b08fbf24SPaolo Abenicapture=0 33af66d3e1SGeliang Tangchecksum=0 3434aa6e3bSGeliang Tangip_mptcp=0 358117dac3SGeliang Tangcheck_invert=0 363c082695SGeliang Tangvalidate_checksum=0 3793827ad5SMatthieu Baertsinit=0 38a3735625SGeliang Tangevts_ns1="" 39a3735625SGeliang Tangevts_ns2="" 40a3735625SGeliang Tangevts_ns1_pid=0 41a3735625SGeliang Tangevts_ns2_pid=0 427f117cd3SMatthieu Baertslast_test_failed=0 437f117cd3SMatthieu Baertslast_test_skipped=0 447f117cd3SMatthieu Baertslast_test_ignored=1 45b08fbf24SPaolo Abeni 463afd0280SMatthieu Baertsdeclare -A all_tests 47c7d49c03SMatthieu Baertsdeclare -a only_tests_ids 48c7d49c03SMatthieu Baertsdeclare -a only_tests_names 4939aab882SMatthieu Baertsdeclare -A failed_tests 50b08fbf24SPaolo AbeniTEST_COUNT=0 51c7d49c03SMatthieu BaertsTEST_NAME="" 5203668c65SMatthieu Baertsnr_blank=6 53b08fbf24SPaolo Abeni 54662aa22dSGeliang Tang# These var are used only in some tests, make sure they are not already set 55662aa22dSGeliang Tangunset FAILING_LINKS 56662aa22dSGeliang Tangunset test_linkfail 57662aa22dSGeliang Tangunset addr_nr_ns1 58662aa22dSGeliang Tangunset addr_nr_ns2 59662aa22dSGeliang Tangunset sflags 60080b7f57SGeliang Tangunset fastclose 614aadde08SGeliang Tangunset fullmesh 62e571fb09SGeliang Tangunset speed 63e59300ceSMatthieu Baerts 648d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 658d014eaaSGeliang Tang# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 668d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 678d014eaaSGeliang Tang 48 0 0 0, 688d014eaaSGeliang Tang 84 0 0 240, 698d014eaaSGeliang Tang 21 0 3 64, 708d014eaaSGeliang Tang 48 0 0 54, 718d014eaaSGeliang Tang 84 0 0 240, 728d014eaaSGeliang Tang 21 6 7 48, 738d014eaaSGeliang Tang 48 0 0 0, 748d014eaaSGeliang Tang 84 0 0 240, 758d014eaaSGeliang Tang 21 0 4 96, 768d014eaaSGeliang Tang 48 0 0 74, 778d014eaaSGeliang Tang 84 0 0 240, 788d014eaaSGeliang Tang 21 0 1 48, 798d014eaaSGeliang Tang 6 0 0 65535, 808d014eaaSGeliang Tang 6 0 0 0" 818d014eaaSGeliang Tang 8293827ad5SMatthieu Baertsinit_partial() 83b08fbf24SPaolo Abeni{ 84b08fbf24SPaolo Abeni capout=$(mktemp) 85b08fbf24SPaolo Abeni 86787eb1e4SMatthieu Baerts local sec rndh 87787eb1e4SMatthieu Baerts sec=$(date +%s) 88787eb1e4SMatthieu Baerts rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 89b08fbf24SPaolo Abeni 90b08fbf24SPaolo Abeni ns1="ns1-$rndh" 91b08fbf24SPaolo Abeni ns2="ns2-$rndh" 92b08fbf24SPaolo Abeni 931e777bd8SMatthieu Baerts local netns 94b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 95b08fbf24SPaolo Abeni ip netns add $netns || exit $ksft_skip 96b08fbf24SPaolo Abeni ip -net $netns link set lo up 97b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.mptcp.enabled=1 98f2b492b0SMatthieu Baerts ip netns exec $netns sysctl -q net.mptcp.pm_type=0 2>/dev/null || true 99b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 100b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 101af66d3e1SGeliang Tang if [ $checksum -eq 1 ]; then 102af66d3e1SGeliang Tang ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 103af66d3e1SGeliang Tang fi 104b08fbf24SPaolo Abeni done 105b08fbf24SPaolo Abeni 1068117dac3SGeliang Tang check_invert=0 1073c082695SGeliang Tang validate_checksum=$checksum 1088117dac3SGeliang Tang 109b08fbf24SPaolo Abeni # ns1 ns2 110b08fbf24SPaolo Abeni # ns1eth1 ns2eth1 111b08fbf24SPaolo Abeni # ns1eth2 ns2eth2 112b08fbf24SPaolo Abeni # ns1eth3 ns2eth3 113b08fbf24SPaolo Abeni # ns1eth4 ns2eth4 114b08fbf24SPaolo Abeni 1151e777bd8SMatthieu Baerts local i 1164bfadd71SMatthieu Baerts for i in $(seq 1 4); do 117b08fbf24SPaolo Abeni ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 118b08fbf24SPaolo Abeni ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 119b08fbf24SPaolo Abeni ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 120b08fbf24SPaolo Abeni ip -net "$ns1" link set ns1eth$i up 121b08fbf24SPaolo Abeni 122b08fbf24SPaolo Abeni ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 123b08fbf24SPaolo Abeni ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 124b08fbf24SPaolo Abeni ip -net "$ns2" link set ns2eth$i up 125b08fbf24SPaolo Abeni 126b08fbf24SPaolo Abeni # let $ns2 reach any $ns1 address from any interface 127b08fbf24SPaolo Abeni ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 1289846921dSPaolo Abeni ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 129b08fbf24SPaolo Abeni done 130b08fbf24SPaolo Abeni} 131b08fbf24SPaolo Abeni 1327d1e6f16SPaolo Abeniinit_shapers() 1337d1e6f16SPaolo Abeni{ 1341e777bd8SMatthieu Baerts local i 1354bfadd71SMatthieu Baerts for i in $(seq 1 4); do 13699ac814eSGeliang Tang tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1ms 13799ac814eSGeliang Tang tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1ms 1387d1e6f16SPaolo Abeni done 1397d1e6f16SPaolo Abeni} 1407d1e6f16SPaolo Abeni 141b08fbf24SPaolo Abenicleanup_partial() 142b08fbf24SPaolo Abeni{ 143b08fbf24SPaolo Abeni rm -f "$capout" 144b08fbf24SPaolo Abeni 1451e777bd8SMatthieu Baerts local netns 146b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 147b08fbf24SPaolo Abeni ip netns del $netns 148c2a55e8fSMatthieu Baerts rm -f /tmp/$netns.{nstat,out} 149b08fbf24SPaolo Abeni done 150b08fbf24SPaolo Abeni} 151b08fbf24SPaolo Abeni 15287154755SMatthieu Baertscheck_tools() 15387154755SMatthieu Baerts{ 154715c78a8SMatthieu Baerts mptcp_lib_check_mptcp 155cdb50525SMatthieu Baerts mptcp_lib_check_kallsyms 156715c78a8SMatthieu Baerts 15787154755SMatthieu Baerts if ! ip -Version &> /dev/null; then 15887154755SMatthieu Baerts echo "SKIP: Could not run test without ip tool" 15987154755SMatthieu Baerts exit $ksft_skip 16087154755SMatthieu Baerts fi 16187154755SMatthieu Baerts 162536a661bSGeliang Tang if ! ss -h | grep -q MPTCP; then 163536a661bSGeliang Tang echo "SKIP: ss tool does not support MPTCP" 164536a661bSGeliang Tang exit $ksft_skip 165536a661bSGeliang Tang fi 166536a661bSGeliang Tang 1670c4cd3f8SMatthieu Baerts # Use the legacy version if available to support old kernel versions 1680c4cd3f8SMatthieu Baerts if iptables-legacy -V &> /dev/null; then 1690c4cd3f8SMatthieu Baerts iptables="iptables-legacy" 1700c4cd3f8SMatthieu Baerts ip6tables="ip6tables-legacy" 1710c4cd3f8SMatthieu Baerts elif ! iptables -V &> /dev/null; then 17287154755SMatthieu Baerts echo "SKIP: Could not run all tests without iptables tool" 17387154755SMatthieu Baerts exit $ksft_skip 174016e7ba4SMatthieu Baerts elif ! ip6tables -V &> /dev/null; then 17587154755SMatthieu Baerts echo "SKIP: Could not run all tests without ip6tables tool" 17687154755SMatthieu Baerts exit $ksft_skip 17787154755SMatthieu Baerts fi 17887154755SMatthieu Baerts} 17987154755SMatthieu Baerts 18093827ad5SMatthieu Baertsinit() { 18193827ad5SMatthieu Baerts init=1 18293827ad5SMatthieu Baerts 18387154755SMatthieu Baerts check_tools 18487154755SMatthieu Baerts 18593827ad5SMatthieu Baerts sin=$(mktemp) 18693827ad5SMatthieu Baerts sout=$(mktemp) 18793827ad5SMatthieu Baerts cin=$(mktemp) 18893827ad5SMatthieu Baerts cinsent=$(mktemp) 18993827ad5SMatthieu Baerts cout=$(mktemp) 190a3735625SGeliang Tang evts_ns1=$(mktemp) 191a3735625SGeliang Tang evts_ns2=$(mktemp) 19293827ad5SMatthieu Baerts 19393827ad5SMatthieu Baerts trap cleanup EXIT 19493827ad5SMatthieu Baerts 19503668c65SMatthieu Baerts make_file "$cin" "client" 1 >/dev/null 19603668c65SMatthieu Baerts make_file "$sin" "server" 1 >/dev/null 19793827ad5SMatthieu Baerts} 19893827ad5SMatthieu Baerts 199b08fbf24SPaolo Abenicleanup() 200b08fbf24SPaolo Abeni{ 2017d1e6f16SPaolo Abeni rm -f "$cin" "$cout" "$sinfail" 2027d1e6f16SPaolo Abeni rm -f "$sin" "$sout" "$cinsent" "$cinfail" 203d328fe87SMatthieu Baerts rm -f "$tmpfile" 204a3735625SGeliang Tang rm -rf $evts_ns1 $evts_ns2 205b08fbf24SPaolo Abeni cleanup_partial 206b08fbf24SPaolo Abeni} 207b08fbf24SPaolo Abeni 208cdb50525SMatthieu Baertsprint_title() 209cdb50525SMatthieu Baerts{ 21003668c65SMatthieu Baerts printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}" 21103668c65SMatthieu Baerts} 21203668c65SMatthieu Baerts 21303668c65SMatthieu Baertsprint_check() 21403668c65SMatthieu Baerts{ 21503668c65SMatthieu Baerts printf "%-${nr_blank}s%-36s" " " "${*}" 21603668c65SMatthieu Baerts} 21703668c65SMatthieu Baerts 21803668c65SMatthieu Baertsprint_info() 21903668c65SMatthieu Baerts{ 22003668c65SMatthieu Baerts # It can be empty, no need to print anything then 22103668c65SMatthieu Baerts [ -z "${1}" ] && return 22203668c65SMatthieu Baerts 2239466df1aSMatthieu Baerts mptcp_lib_print_info " Info: ${*}" 22403668c65SMatthieu Baerts} 22503668c65SMatthieu Baerts 22603668c65SMatthieu Baertsprint_ok() 22703668c65SMatthieu Baerts{ 2289466df1aSMatthieu Baerts mptcp_lib_print_ok "[ ok ]${1:+ ${*}}" 22903668c65SMatthieu Baerts} 23003668c65SMatthieu Baerts 23103668c65SMatthieu Baertsprint_fail() 23203668c65SMatthieu Baerts{ 2339466df1aSMatthieu Baerts mptcp_lib_print_err "[fail]${1:+ ${*}}" 23403668c65SMatthieu Baerts} 23503668c65SMatthieu Baerts 23603668c65SMatthieu Baertsprint_skip() 23703668c65SMatthieu Baerts{ 2389466df1aSMatthieu Baerts mptcp_lib_print_warn "[skip]${1:+ ${*}}" 239cdb50525SMatthieu Baerts} 240cdb50525SMatthieu Baerts 241cdb50525SMatthieu Baerts# [ $1: fail msg ] 242cdb50525SMatthieu Baertsmark_as_skipped() 243cdb50525SMatthieu Baerts{ 244cdb50525SMatthieu Baerts local msg="${1:-"Feature not supported"}" 245cdb50525SMatthieu Baerts 246cdb50525SMatthieu Baerts mptcp_lib_fail_if_expected_feature "${msg}" 247cdb50525SMatthieu Baerts 24803668c65SMatthieu Baerts print_check "${msg}" 24903668c65SMatthieu Baerts print_skip 2507f117cd3SMatthieu Baerts 2517f117cd3SMatthieu Baerts last_test_skipped=1 252cdb50525SMatthieu Baerts} 253cdb50525SMatthieu Baerts 254cdb50525SMatthieu Baerts# $@: condition 255cdb50525SMatthieu Baertscontinue_if() 256cdb50525SMatthieu Baerts{ 257cdb50525SMatthieu Baerts if ! "${@}"; then 258cdb50525SMatthieu Baerts mark_as_skipped 259cdb50525SMatthieu Baerts return 1 260cdb50525SMatthieu Baerts fi 261cdb50525SMatthieu Baerts} 262cdb50525SMatthieu Baerts 263ae7bd9ccSMatthieu Baertsskip_test() 264ae7bd9ccSMatthieu Baerts{ 265c7d49c03SMatthieu Baerts if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 266ae7bd9ccSMatthieu Baerts return 1 267ae7bd9ccSMatthieu Baerts fi 268ae7bd9ccSMatthieu Baerts 269ae7bd9ccSMatthieu Baerts local i 270c7d49c03SMatthieu Baerts for i in "${only_tests_ids[@]}"; do 271ae7bd9ccSMatthieu Baerts if [ "${TEST_COUNT}" -eq "${i}" ]; then 272ae7bd9ccSMatthieu Baerts return 1 273ae7bd9ccSMatthieu Baerts fi 274ae7bd9ccSMatthieu Baerts done 275c7d49c03SMatthieu Baerts for i in "${only_tests_names[@]}"; do 276c7d49c03SMatthieu Baerts if [ "${TEST_NAME}" = "${i}" ]; then 277c7d49c03SMatthieu Baerts return 1 278c7d49c03SMatthieu Baerts fi 279c7d49c03SMatthieu Baerts done 280ae7bd9ccSMatthieu Baerts 281ae7bd9ccSMatthieu Baerts return 0 282ae7bd9ccSMatthieu Baerts} 283ae7bd9ccSMatthieu Baerts 2847f117cd3SMatthieu Baertsappend_prev_results() 2857f117cd3SMatthieu Baerts{ 2867f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 1 ]; then 2877f117cd3SMatthieu Baerts mptcp_lib_result_fail "${TEST_NAME}" 2887f117cd3SMatthieu Baerts elif [ ${last_test_skipped} -eq 1 ]; then 2897f117cd3SMatthieu Baerts mptcp_lib_result_skip "${TEST_NAME}" 2907f117cd3SMatthieu Baerts elif [ ${last_test_ignored} -ne 1 ]; then 2917f117cd3SMatthieu Baerts mptcp_lib_result_pass "${TEST_NAME}" 2927f117cd3SMatthieu Baerts fi 2937f117cd3SMatthieu Baerts 2947f117cd3SMatthieu Baerts last_test_failed=0 2957f117cd3SMatthieu Baerts last_test_skipped=0 2967f117cd3SMatthieu Baerts last_test_ignored=0 2977f117cd3SMatthieu Baerts} 2987f117cd3SMatthieu Baerts 299c7d49c03SMatthieu Baerts# $1: test name 300b08fbf24SPaolo Abenireset() 301b08fbf24SPaolo Abeni{ 3027f117cd3SMatthieu Baerts append_prev_results 3037f117cd3SMatthieu Baerts 304c7d49c03SMatthieu Baerts TEST_NAME="${1}" 305c7d49c03SMatthieu Baerts 306ae7bd9ccSMatthieu Baerts TEST_COUNT=$((TEST_COUNT+1)) 307ae7bd9ccSMatthieu Baerts 308ae7bd9ccSMatthieu Baerts if skip_test; then 3097f117cd3SMatthieu Baerts last_test_ignored=1 310ae7bd9ccSMatthieu Baerts return 1 311ae7bd9ccSMatthieu Baerts fi 312ae7bd9ccSMatthieu Baerts 31303668c65SMatthieu Baerts print_title 31403668c65SMatthieu Baerts 31593827ad5SMatthieu Baerts if [ "${init}" != "1" ]; then 316b08fbf24SPaolo Abeni init 31793827ad5SMatthieu Baerts else 31893827ad5SMatthieu Baerts cleanup_partial 31993827ad5SMatthieu Baerts fi 32093827ad5SMatthieu Baerts 32193827ad5SMatthieu Baerts init_partial 322ae7bd9ccSMatthieu Baerts 323ae7bd9ccSMatthieu Baerts return 0 324b08fbf24SPaolo Abeni} 325b08fbf24SPaolo Abeni 326ae947bb2SMatthieu Baerts# $1: test name ; $2: counter to check 327ae947bb2SMatthieu Baertsreset_check_counter() 328ae947bb2SMatthieu Baerts{ 329ae947bb2SMatthieu Baerts reset "${1}" || return 1 330ae947bb2SMatthieu Baerts 331ae947bb2SMatthieu Baerts local counter="${2}" 332ae947bb2SMatthieu Baerts 333ae947bb2SMatthieu Baerts if ! nstat -asz "${counter}" | grep -wq "${counter}"; then 334ae947bb2SMatthieu Baerts mark_as_skipped "counter '${counter}' is not available" 335ae947bb2SMatthieu Baerts return 1 336ae947bb2SMatthieu Baerts fi 337ae947bb2SMatthieu Baerts} 338ae947bb2SMatthieu Baerts 339c7d49c03SMatthieu Baerts# $1: test name 34000587187SFlorian Westphalreset_with_cookies() 34100587187SFlorian Westphal{ 342c7d49c03SMatthieu Baerts reset "${1}" || return 1 34300587187SFlorian Westphal 3441e777bd8SMatthieu Baerts local netns 34500587187SFlorian Westphal for netns in "$ns1" "$ns2"; do 34600587187SFlorian Westphal ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 34700587187SFlorian Westphal done 34800587187SFlorian Westphal} 34900587187SFlorian Westphal 350c7d49c03SMatthieu Baerts# $1: test name 3518d014eaaSGeliang Tangreset_with_add_addr_timeout() 3528d014eaaSGeliang Tang{ 353c7d49c03SMatthieu Baerts local ip="${2:-4}" 3548d014eaaSGeliang Tang local tables 3558d014eaaSGeliang Tang 356c7d49c03SMatthieu Baerts reset "${1}" || return 1 357c7d49c03SMatthieu Baerts 3580c4cd3f8SMatthieu Baerts tables="${iptables}" 3598d014eaaSGeliang Tang if [ $ip -eq 6 ]; then 3600c4cd3f8SMatthieu Baerts tables="${ip6tables}" 3618d014eaaSGeliang Tang fi 3628d014eaaSGeliang Tang 3638d014eaaSGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 3644a0b866aSMatthieu Baerts 3654a0b866aSMatthieu Baerts if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 3668d014eaaSGeliang Tang -m tcp --tcp-option 30 \ 3678d014eaaSGeliang Tang -m bpf --bytecode \ 3688d014eaaSGeliang Tang "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 3694a0b866aSMatthieu Baerts -j DROP; then 3704a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'add addr' rule" 3714a0b866aSMatthieu Baerts return 1 3724a0b866aSMatthieu Baerts fi 3738d014eaaSGeliang Tang} 3748d014eaaSGeliang Tang 375c7d49c03SMatthieu Baerts# $1: test name 376af66d3e1SGeliang Tangreset_with_checksum() 377af66d3e1SGeliang Tang{ 378af66d3e1SGeliang Tang local ns1_enable=$1 379af66d3e1SGeliang Tang local ns2_enable=$2 380af66d3e1SGeliang Tang 381c7d49c03SMatthieu Baerts reset "checksum test ${1} ${2}" || return 1 382af66d3e1SGeliang Tang 383af66d3e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 384af66d3e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 3853c082695SGeliang Tang 3863c082695SGeliang Tang validate_checksum=1 387af66d3e1SGeliang Tang} 388af66d3e1SGeliang Tang 3890cddb4a6SGeliang Tangreset_with_allow_join_id0() 3900cddb4a6SGeliang Tang{ 391c7d49c03SMatthieu Baerts local ns1_enable=$2 392c7d49c03SMatthieu Baerts local ns2_enable=$3 3930cddb4a6SGeliang Tang 394c7d49c03SMatthieu Baerts reset "${1}" || return 1 3950cddb4a6SGeliang Tang 3960cddb4a6SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 3970cddb4a6SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 3980cddb4a6SGeliang Tang} 3990cddb4a6SGeliang Tang 400b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet 401b6e074e1SGeliang Tang# 402b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 403b6e074e1SGeliang Tang# carrying enough data. 404b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still 405b6e074e1SGeliang Tang# considered as valid at the TCP level. 406b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been 407b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted: 408b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options. 409b6e074e1SGeliang Tang# 410b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets 411b6e074e1SGeliang Tang# not carrying enough data: 412b6e074e1SGeliang Tang# 413b6e074e1SGeliang Tang# tc action pedit offset 162 out of bounds 414b6e074e1SGeliang Tang# 415b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data. 4164a0b866aSMatthieu Baertssetup_fail_rules() 417b6e074e1SGeliang Tang{ 418b6e074e1SGeliang Tang check_invert=1 419b6e074e1SGeliang Tang validate_checksum=1 4204a0b866aSMatthieu Baerts local i="$1" 4214a0b866aSMatthieu Baerts local ip="${2:-4}" 422b6e074e1SGeliang Tang local tables 423b6e074e1SGeliang Tang 4240c4cd3f8SMatthieu Baerts tables="${iptables}" 425b6e074e1SGeliang Tang if [ $ip -eq 6 ]; then 4260c4cd3f8SMatthieu Baerts tables="${ip6tables}" 427b6e074e1SGeliang Tang fi 428b6e074e1SGeliang Tang 429b6e074e1SGeliang Tang ip netns exec $ns2 $tables \ 430b6e074e1SGeliang Tang -t mangle \ 431b6e074e1SGeliang Tang -A OUTPUT \ 432b6e074e1SGeliang Tang -o ns2eth$i \ 433b6e074e1SGeliang Tang -p tcp \ 434b6e074e1SGeliang Tang -m length --length 150:9999 \ 435b6e074e1SGeliang Tang -m statistic --mode nth --packet 1 --every 99999 \ 4364a0b866aSMatthieu Baerts -j MARK --set-mark 42 || return ${ksft_skip} 437b6e074e1SGeliang Tang 4384a0b866aSMatthieu Baerts tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${ksft_skip} 439b6e074e1SGeliang Tang tc -n $ns2 filter add dev ns2eth$i egress \ 440b6e074e1SGeliang Tang protocol ip prio 1000 \ 441b6e074e1SGeliang Tang handle 42 fw \ 442b6e074e1SGeliang Tang action pedit munge offset 148 u8 invert \ 443b6e074e1SGeliang Tang pipe csum tcp \ 4444a0b866aSMatthieu Baerts index 100 || return ${ksft_skip} 4454a0b866aSMatthieu Baerts} 4464a0b866aSMatthieu Baerts 4474a0b866aSMatthieu Baertsreset_with_fail() 4484a0b866aSMatthieu Baerts{ 449ff8897b5SMatthieu Baerts reset_check_counter "${1}" "MPTcpExtInfiniteMapTx" || return 1 4504a0b866aSMatthieu Baerts shift 4514a0b866aSMatthieu Baerts 4524a0b866aSMatthieu Baerts ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 4534a0b866aSMatthieu Baerts ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 4544a0b866aSMatthieu Baerts 4554a0b866aSMatthieu Baerts local rc=0 4564a0b866aSMatthieu Baerts setup_fail_rules "${@}" || rc=$? 4574a0b866aSMatthieu Baerts 4584a0b866aSMatthieu Baerts if [ ${rc} -eq ${ksft_skip} ]; then 4594a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'fail' rules" 4604a0b866aSMatthieu Baerts return 1 4614a0b866aSMatthieu Baerts fi 462b6e074e1SGeliang Tang} 463b6e074e1SGeliang Tang 464a3735625SGeliang Tangreset_with_events() 465a3735625SGeliang Tang{ 466a3735625SGeliang Tang reset "${1}" || return 1 467a3735625SGeliang Tang 468a3735625SGeliang Tang :> "$evts_ns1" 469a3735625SGeliang Tang :> "$evts_ns2" 470a3735625SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 471a3735625SGeliang Tang evts_ns1_pid=$! 472a3735625SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 473a3735625SGeliang Tang evts_ns2_pid=$! 474a3735625SGeliang Tang} 475a3735625SGeliang Tang 4764a0b866aSMatthieu Baertsreset_with_tcp_filter() 4774a0b866aSMatthieu Baerts{ 4784a0b866aSMatthieu Baerts reset "${1}" || return 1 4794a0b866aSMatthieu Baerts shift 4804a0b866aSMatthieu Baerts 4814a0b866aSMatthieu Baerts local ns="${!1}" 4824a0b866aSMatthieu Baerts local src="${2}" 4834a0b866aSMatthieu Baerts local target="${3}" 484ce2f28a5SMatthieu Baerts (NGI0) local chain="${4:-INPUT}" 4854a0b866aSMatthieu Baerts 4864a0b866aSMatthieu Baerts if ! ip netns exec "${ns}" ${iptables} \ 487ce2f28a5SMatthieu Baerts (NGI0) -A "${chain}" \ 4884a0b866aSMatthieu Baerts -s "${src}" \ 4894a0b866aSMatthieu Baerts -p tcp \ 4904a0b866aSMatthieu Baerts -j "${target}"; then 4914a0b866aSMatthieu Baerts mark_as_skipped "unable to set the filter rules" 4924a0b866aSMatthieu Baerts return 1 4934a0b866aSMatthieu Baerts fi 4944a0b866aSMatthieu Baerts} 4954a0b866aSMatthieu Baerts 49603668c65SMatthieu Baerts# $1: err msg 49739aab882SMatthieu Baertsfail_test() 49839aab882SMatthieu Baerts{ 49939aab882SMatthieu Baerts ret=1 500985de459SPaolo Abeni 50103668c65SMatthieu Baerts print_fail "${@}" 50203668c65SMatthieu Baerts 5037f117cd3SMatthieu Baerts # just in case a test is marked twice as failed 5047f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 0 ]; then 5057f117cd3SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 5067f117cd3SMatthieu Baerts dump_stats 5077f117cd3SMatthieu Baerts last_test_failed=1 5087f117cd3SMatthieu Baerts fi 50939aab882SMatthieu Baerts} 51039aab882SMatthieu Baerts 51139aab882SMatthieu Baertsget_failed_tests_ids() 51239aab882SMatthieu Baerts{ 51339aab882SMatthieu Baerts # sorted 51439aab882SMatthieu Baerts local i 51539aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 51639aab882SMatthieu Baerts echo "${i}" 51739aab882SMatthieu Baerts done | sort -n 51839aab882SMatthieu Baerts} 51939aab882SMatthieu Baerts 5208b819a84SFlorian Westphalprint_file_err() 5218b819a84SFlorian Westphal{ 5228b819a84SFlorian Westphal ls -l "$1" 1>&2 52303668c65SMatthieu Baerts echo -n "Trailing bytes are: " 5248b819a84SFlorian Westphal tail -c 27 "$1" 5258b819a84SFlorian Westphal} 5268b819a84SFlorian Westphal 527b08fbf24SPaolo Abenicheck_transfer() 528b08fbf24SPaolo Abeni{ 5291e777bd8SMatthieu Baerts local in=$1 5301e777bd8SMatthieu Baerts local out=$2 5311e777bd8SMatthieu Baerts local what=$3 5326bf41020SPaolo Abeni local bytes=$4 533d8d08302SMatthieu Baerts local i a b 534b08fbf24SPaolo Abeni 5351e777bd8SMatthieu Baerts local line 5366bf41020SPaolo Abeni if [ -n "$bytes" ]; then 5370fcd72dfSMatthieu Baerts local out_size 5386bf41020SPaolo Abeni # when truncating we must check the size explicitly 5390fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 5406bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 54103668c65SMatthieu Baerts fail_test "$what output file has wrong size ($out_size, $bytes)" 5426bf41020SPaolo Abeni return 1 5436bf41020SPaolo Abeni fi 544d328fe87SMatthieu Baerts 545d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 546d328fe87SMatthieu Baerts tmpfile=$(mktemp) 547d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 548d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 549d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 550d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 551d328fe87SMatthieu Baerts tmpfile="" 5526bf41020SPaolo Abeni fi 553d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 554d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 5558117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 55603668c65SMatthieu Baerts fail_test "$what does not match (in, out):" 557b08fbf24SPaolo Abeni print_file_err "$in" 558b08fbf24SPaolo Abeni print_file_err "$out" 559b08fbf24SPaolo Abeni 560b08fbf24SPaolo Abeni return 1 5618117dac3SGeliang Tang else 56203668c65SMatthieu Baerts print_info "$what has inverted byte at ${i}" 563b08fbf24SPaolo Abeni fi 5648117dac3SGeliang Tang done 565b08fbf24SPaolo Abeni 566b08fbf24SPaolo Abeni return 0 567b08fbf24SPaolo Abeni} 568b08fbf24SPaolo Abeni 569b08fbf24SPaolo Abenido_ping() 570b08fbf24SPaolo Abeni{ 5711e777bd8SMatthieu Baerts local listener_ns="$1" 5721e777bd8SMatthieu Baerts local connector_ns="$2" 5731e777bd8SMatthieu Baerts local connect_addr="$3" 574b08fbf24SPaolo Abeni 575d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 57603668c65SMatthieu Baerts fail_test "$listener_ns -> $connect_addr connectivity" 577b08fbf24SPaolo Abeni fi 578b08fbf24SPaolo Abeni} 579b08fbf24SPaolo Abeni 5808b819a84SFlorian Westphallink_failure() 5818b819a84SFlorian Westphal{ 5821e777bd8SMatthieu Baerts local ns="$1" 5838b819a84SFlorian Westphal 5847d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 5858b819a84SFlorian Westphal l=$((RANDOM%4)) 5867d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 5877d1e6f16SPaolo Abeni fi 5888b819a84SFlorian Westphal 5891e777bd8SMatthieu Baerts local l 5907d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 5911e777bd8SMatthieu Baerts local veth="ns1eth$l" 5928b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 5937d1e6f16SPaolo Abeni done 5948b819a84SFlorian Westphal} 5958b819a84SFlorian Westphal 596327b9a94SPaolo Abeni# $1: ns, $2: port 597327b9a94SPaolo Abeniwait_local_port_listen() 598327b9a94SPaolo Abeni{ 599327b9a94SPaolo Abeni local listener_ns="${1}" 600327b9a94SPaolo Abeni local port="${2}" 601327b9a94SPaolo Abeni 6021e777bd8SMatthieu Baerts local port_hex 603327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 6041e777bd8SMatthieu Baerts 6051e777bd8SMatthieu Baerts local i 606327b9a94SPaolo Abeni for i in $(seq 10); do 607327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 608327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 609327b9a94SPaolo Abeni break 610327b9a94SPaolo Abeni sleep 0.1 611327b9a94SPaolo Abeni done 612327b9a94SPaolo Abeni} 613327b9a94SPaolo Abeni 614327b9a94SPaolo Abenirm_addr_count() 615327b9a94SPaolo Abeni{ 616697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr" 617327b9a94SPaolo Abeni} 618327b9a94SPaolo Abeni 619327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 620327b9a94SPaolo Abeniwait_rm_addr() 621327b9a94SPaolo Abeni{ 622327b9a94SPaolo Abeni local ns="${1}" 623327b9a94SPaolo Abeni local old_cnt="${2}" 624327b9a94SPaolo Abeni local cnt 625327b9a94SPaolo Abeni 6261e777bd8SMatthieu Baerts local i 627327b9a94SPaolo Abeni for i in $(seq 10); do 628327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 629327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 630327b9a94SPaolo Abeni sleep 0.1 631327b9a94SPaolo Abeni done 632327b9a94SPaolo Abeni} 633327b9a94SPaolo Abeni 6344369c198SGeliang Tangrm_sf_count() 6354369c198SGeliang Tang{ 636697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow" 6374369c198SGeliang Tang} 6384369c198SGeliang Tang 6394369c198SGeliang Tang# $1: ns, $2: old rm_sf counter in $ns 6404369c198SGeliang Tangwait_rm_sf() 6414369c198SGeliang Tang{ 6424369c198SGeliang Tang local ns="${1}" 6434369c198SGeliang Tang local old_cnt="${2}" 6444369c198SGeliang Tang local cnt 6454369c198SGeliang Tang 6464369c198SGeliang Tang local i 6474369c198SGeliang Tang for i in $(seq 10); do 6484369c198SGeliang Tang cnt=$(rm_sf_count ${ns}) 6494369c198SGeliang Tang [ "$cnt" = "${old_cnt}" ] || break 6504369c198SGeliang Tang sleep 0.1 6514369c198SGeliang Tang done 6524369c198SGeliang Tang} 6534369c198SGeliang Tang 65469c6ce7bSPaolo Abeniwait_mpj() 65569c6ce7bSPaolo Abeni{ 65669c6ce7bSPaolo Abeni local ns="${1}" 65769c6ce7bSPaolo Abeni local cnt old_cnt 65869c6ce7bSPaolo Abeni 659697128a3SGeliang Tang old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 66069c6ce7bSPaolo Abeni 66169c6ce7bSPaolo Abeni local i 66269c6ce7bSPaolo Abeni for i in $(seq 10); do 663697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 66469c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 66569c6ce7bSPaolo Abeni sleep 0.1 66669c6ce7bSPaolo Abeni done 66769c6ce7bSPaolo Abeni} 66869c6ce7bSPaolo Abeni 669a3735625SGeliang Tangkill_events_pids() 670a3735625SGeliang Tang{ 6711fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns1_pid 6721fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns2_pid 673a3735625SGeliang Tang} 674a3735625SGeliang Tang 67534aa6e3bSGeliang Tangpm_nl_set_limits() 67634aa6e3bSGeliang Tang{ 67734aa6e3bSGeliang Tang local ns=$1 67834aa6e3bSGeliang Tang local addrs=$2 67934aa6e3bSGeliang Tang local subflows=$3 68034aa6e3bSGeliang Tang 68134aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 68234aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 68334aa6e3bSGeliang Tang else 68434aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 68534aa6e3bSGeliang Tang fi 68634aa6e3bSGeliang Tang} 68734aa6e3bSGeliang Tang 68834aa6e3bSGeliang Tangpm_nl_add_endpoint() 68934aa6e3bSGeliang Tang{ 69034aa6e3bSGeliang Tang local ns=$1 69134aa6e3bSGeliang Tang local addr=$2 6921e777bd8SMatthieu Baerts local flags _flags 6931e777bd8SMatthieu Baerts local port _port 6941e777bd8SMatthieu Baerts local dev _dev 6951e777bd8SMatthieu Baerts local id _id 69634aa6e3bSGeliang Tang local nr=2 69734aa6e3bSGeliang Tang 6981e777bd8SMatthieu Baerts local p 699d8d08302SMatthieu Baerts for p in "${@}" 70034aa6e3bSGeliang Tang do 70134aa6e3bSGeliang Tang if [ $p = "flags" ]; then 70234aa6e3bSGeliang Tang eval _flags=\$"$nr" 703d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 70434aa6e3bSGeliang Tang fi 70534aa6e3bSGeliang Tang if [ $p = "dev" ]; then 70634aa6e3bSGeliang Tang eval _dev=\$"$nr" 707d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 70834aa6e3bSGeliang Tang fi 70934aa6e3bSGeliang Tang if [ $p = "id" ]; then 71034aa6e3bSGeliang Tang eval _id=\$"$nr" 711d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 71234aa6e3bSGeliang Tang fi 71334aa6e3bSGeliang Tang if [ $p = "port" ]; then 71434aa6e3bSGeliang Tang eval _port=\$"$nr" 715d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 71634aa6e3bSGeliang Tang fi 71734aa6e3bSGeliang Tang 718d8d08302SMatthieu Baerts nr=$((nr + 1)) 71934aa6e3bSGeliang Tang done 72034aa6e3bSGeliang Tang 72134aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 72234aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 72334aa6e3bSGeliang Tang else 72434aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 72534aa6e3bSGeliang Tang fi 72634aa6e3bSGeliang Tang} 72734aa6e3bSGeliang Tang 72834aa6e3bSGeliang Tangpm_nl_del_endpoint() 72934aa6e3bSGeliang Tang{ 73034aa6e3bSGeliang Tang local ns=$1 73134aa6e3bSGeliang Tang local id=$2 73234aa6e3bSGeliang Tang local addr=$3 73334aa6e3bSGeliang Tang 73434aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 735aaf2123aSAndrea Claudi [ $id -ne 0 ] && addr='' 73634aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 73734aa6e3bSGeliang Tang else 73834aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 73934aa6e3bSGeliang Tang fi 74034aa6e3bSGeliang Tang} 74134aa6e3bSGeliang Tang 74234aa6e3bSGeliang Tangpm_nl_flush_endpoint() 74334aa6e3bSGeliang Tang{ 74434aa6e3bSGeliang Tang local ns=$1 74534aa6e3bSGeliang Tang 74634aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 74734aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 74834aa6e3bSGeliang Tang else 74934aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 75034aa6e3bSGeliang Tang fi 75134aa6e3bSGeliang Tang} 75234aa6e3bSGeliang Tang 753dda61b3dSGeliang Tangpm_nl_show_endpoints() 754dda61b3dSGeliang Tang{ 755dda61b3dSGeliang Tang local ns=$1 756dda61b3dSGeliang Tang 757dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 758dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 759dda61b3dSGeliang Tang else 760dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 761dda61b3dSGeliang Tang fi 762dda61b3dSGeliang Tang} 763dda61b3dSGeliang Tang 764f0140386SGeliang Tangpm_nl_change_endpoint() 765f0140386SGeliang Tang{ 766f0140386SGeliang Tang local ns=$1 767bccefb76SGeliang Tang local id=$2 768bccefb76SGeliang Tang local flags=$3 769f0140386SGeliang Tang 770f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 771f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 772f0140386SGeliang Tang else 773bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 774f0140386SGeliang Tang fi 775f0140386SGeliang Tang} 776f0140386SGeliang Tang 77769c6ce7bSPaolo Abenipm_nl_check_endpoint() 77869c6ce7bSPaolo Abeni{ 77969c6ce7bSPaolo Abeni local line expected_line 78003668c65SMatthieu Baerts local msg="$1" 78103668c65SMatthieu Baerts local ns=$2 78203668c65SMatthieu Baerts local addr=$3 78369c6ce7bSPaolo Abeni local _flags="" 78469c6ce7bSPaolo Abeni local flags 78569c6ce7bSPaolo Abeni local _port 78669c6ce7bSPaolo Abeni local port 78769c6ce7bSPaolo Abeni local dev 78869c6ce7bSPaolo Abeni local _id 78969c6ce7bSPaolo Abeni local id 79069c6ce7bSPaolo Abeni 79103668c65SMatthieu Baerts print_check "${msg}" 79269c6ce7bSPaolo Abeni 79303668c65SMatthieu Baerts shift 3 79469c6ce7bSPaolo Abeni while [ -n "$1" ]; do 79569c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 79669c6ce7bSPaolo Abeni _flags=$2 797d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 79869c6ce7bSPaolo Abeni shift 79969c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 800117eed29SGeliang Tang [ -n "$2" ]; dev="dev $2" 80169c6ce7bSPaolo Abeni shift 80269c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 80369c6ce7bSPaolo Abeni _id=$2 804d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 80569c6ce7bSPaolo Abeni shift 80669c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 80769c6ce7bSPaolo Abeni _port=$2 808d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 80969c6ce7bSPaolo Abeni shift 81069c6ce7bSPaolo Abeni fi 81169c6ce7bSPaolo Abeni 81269c6ce7bSPaolo Abeni shift 81369c6ce7bSPaolo Abeni done 81469c6ce7bSPaolo Abeni 81569c6ce7bSPaolo Abeni if [ -z "$id" ]; then 8168165c844SPaolo Abeni fail_test "bad test - missing endpoint id" 81769c6ce7bSPaolo Abeni return 81869c6ce7bSPaolo Abeni fi 81969c6ce7bSPaolo Abeni 82069c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 821c8c101aeSAndrea Claudi # get line and trim trailing whitespace 82269c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 823c8c101aeSAndrea Claudi line="${line% }" 82469c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 825c8c101aeSAndrea Claudi [ -n "$addr" ] && expected_line="$addr" 826732752baSGeliang Tang expected_line+=" $id" 827732752baSGeliang Tang [ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}" 828732752baSGeliang Tang [ -n "$dev" ] && expected_line+=" $dev" 829732752baSGeliang Tang [ -n "$port" ] && expected_line+=" $port" 83069c6ce7bSPaolo Abeni else 83169c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 83269c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 83369c6ce7bSPaolo Abeni expected_line="$id" 834732752baSGeliang Tang [ -n "$flags" ] && expected_line+=" $flags" 835732752baSGeliang Tang [ -n "$dev" ] && expected_line+=" $dev" 836732752baSGeliang Tang [ -n "$addr" ] && expected_line+=" $addr" 837732752baSGeliang Tang [ -n "$_port" ] && expected_line+=" $_port" 83869c6ce7bSPaolo Abeni fi 83969c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 84003668c65SMatthieu Baerts print_ok 84169c6ce7bSPaolo Abeni else 84203668c65SMatthieu Baerts fail_test "expected '$expected_line' found '$line'" 84369c6ce7bSPaolo Abeni fi 84469c6ce7bSPaolo Abeni} 84569c6ce7bSPaolo Abeni 8469e9d176dSGeliang Tangpm_nl_set_endpoint() 847b08fbf24SPaolo Abeni{ 8481e777bd8SMatthieu Baerts local listener_ns="$1" 8491e777bd8SMatthieu Baerts local connector_ns="$2" 8509e9d176dSGeliang Tang local connect_addr="$3" 851b08fbf24SPaolo Abeni 852662aa22dSGeliang Tang local addr_nr_ns1=${addr_nr_ns1:-0} 853662aa22dSGeliang Tang local addr_nr_ns2=${addr_nr_ns2:-0} 854662aa22dSGeliang Tang local sflags=${sflags:-""} 8554aadde08SGeliang Tang local fullmesh=${fullmesh:-""} 856662aa22dSGeliang Tang 857080b7f57SGeliang Tang local flags="subflow" 8584aadde08SGeliang Tang if [ -n "${fullmesh}" ]; then 859080b7f57SGeliang Tang flags="${flags},fullmesh" 8604aadde08SGeliang Tang addr_nr_ns2=${fullmesh} 861080b7f57SGeliang Tang fi 862080b7f57SGeliang Tang 863327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 864327b9a94SPaolo Abeni # do endpoint manipulation 865d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 866d8d08302SMatthieu Baerts sleep 1 867d8d08302SMatthieu Baerts fi 868327b9a94SPaolo Abeni 8696208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8701e777bd8SMatthieu Baerts local counter=2 871d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 87297040cf9SGeliang Tang local id=10 8736208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8746208fd82SGeliang Tang local addr 8758e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 8766208fd82SGeliang Tang addr="dead:beef:$counter::1" 8776208fd82SGeliang Tang else 8786208fd82SGeliang Tang addr="10.0.$counter.1" 8796208fd82SGeliang Tang fi 88034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 881d8d08302SMatthieu Baerts counter=$((counter + 1)) 882d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 88397040cf9SGeliang Tang id=$((id + 1)) 8846208fd82SGeliang Tang done 8856208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 886d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 8876fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 8881e777bd8SMatthieu Baerts local counter=0 8891e777bd8SMatthieu Baerts local line 890d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 891d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 892dda61b3dSGeliang Tang local arr=($line) 893dda61b3dSGeliang Tang local nr=0 894dda61b3dSGeliang Tang 8951e777bd8SMatthieu Baerts local i 896d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 897dda61b3dSGeliang Tang if [ $i = "id" ]; then 898dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 899dda61b3dSGeliang Tang break 900dda61b3dSGeliang Tang fi 901dda61b3dSGeliang Tang id=${arr[$nr+1]} 902327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 90334aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 904327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 905d8d08302SMatthieu Baerts counter=$((counter + 1)) 906f87744adSGeliang Tang fi 907d8d08302SMatthieu Baerts nr=$((nr + 1)) 908dda61b3dSGeliang Tang done 909dda61b3dSGeliang Tang done 9105e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 91134aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9125e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 91334aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9146fe4ccdcSGeliang Tang fi 915dd72b0feSGeliang Tang fi 916dd72b0feSGeliang Tang 917327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 918327b9a94SPaolo Abeni # some time to created them 919d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 920327b9a94SPaolo Abeni 9216208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 922d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9231e777bd8SMatthieu Baerts local counter=3 9245e986ec4SGeliang Tang local id=20 9256208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9266208fd82SGeliang Tang local addr 9278e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9286208fd82SGeliang Tang addr="dead:beef:$counter::2" 9296208fd82SGeliang Tang else 9306208fd82SGeliang Tang addr="10.0.$counter.2" 9316208fd82SGeliang Tang fi 93234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 933d8d08302SMatthieu Baerts counter=$((counter + 1)) 934d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9355e986ec4SGeliang Tang id=$((id + 1)) 9366208fd82SGeliang Tang done 9376208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 938d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9396fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9401e777bd8SMatthieu Baerts local counter=0 9411e777bd8SMatthieu Baerts local line 942d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 943d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 944dda61b3dSGeliang Tang local arr=($line) 945dda61b3dSGeliang Tang local nr=0 946dda61b3dSGeliang Tang 9471e777bd8SMatthieu Baerts local i 948d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 949dda61b3dSGeliang Tang if [ $i = "id" ]; then 950dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 951dda61b3dSGeliang Tang break 952dda61b3dSGeliang Tang fi 9531e777bd8SMatthieu Baerts local id rm_addr 954dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 955dda61b3dSGeliang Tang # complete 956dda61b3dSGeliang Tang id=${arr[$nr+1]} 957327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 95834aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 959327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 960d8d08302SMatthieu Baerts counter=$((counter + 1)) 961f87744adSGeliang Tang fi 962d8d08302SMatthieu Baerts nr=$((nr + 1)) 963dda61b3dSGeliang Tang done 964dda61b3dSGeliang Tang done 9655e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 96634aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9675e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9685e287fe7SGeliang Tang local addr 9698e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9705e287fe7SGeliang Tang addr="dead:beef:1::2" 9715e287fe7SGeliang Tang else 9725e287fe7SGeliang Tang addr="10.0.1.2" 9735e287fe7SGeliang Tang fi 97434aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9756fe4ccdcSGeliang Tang fi 976dd72b0feSGeliang Tang fi 977dd72b0feSGeliang Tang 978d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 979718eb44eSGeliang Tang sleep 1 9801e777bd8SMatthieu Baerts 9811e777bd8SMatthieu Baerts local netns 982718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9831e777bd8SMatthieu Baerts local line 984d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 985d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 98633397b83SGeliang Tang local arr=($line) 987bccefb76SGeliang Tang local nr=0 988f0140386SGeliang Tang local id 98933397b83SGeliang Tang 9901e777bd8SMatthieu Baerts local i 991d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 992bccefb76SGeliang Tang if [ $i = "id" ]; then 993bccefb76SGeliang Tang id=${arr[$nr+1]} 994718eb44eSGeliang Tang fi 995d8d08302SMatthieu Baerts nr=$((nr + 1)) 99633397b83SGeliang Tang done 997bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 99833397b83SGeliang Tang done 999718eb44eSGeliang Tang done 1000718eb44eSGeliang Tang fi 10019e9d176dSGeliang Tang} 10029e9d176dSGeliang Tang 10039e9d176dSGeliang Tangdo_transfer() 10049e9d176dSGeliang Tang{ 10059e9d176dSGeliang Tang local listener_ns="$1" 10069e9d176dSGeliang Tang local connector_ns="$2" 10079e9d176dSGeliang Tang local cl_proto="$3" 10089e9d176dSGeliang Tang local srv_proto="$4" 10099e9d176dSGeliang Tang local connect_addr="$5" 10109e9d176dSGeliang Tang 10119e9d176dSGeliang Tang local port=$((10000 + TEST_COUNT - 1)) 10129e9d176dSGeliang Tang local cappid 1013662aa22dSGeliang Tang local FAILING_LINKS=${FAILING_LINKS:-""} 1014080b7f57SGeliang Tang local fastclose=${fastclose:-""} 1015e571fb09SGeliang Tang local speed=${speed:-"fast"} 10169e9d176dSGeliang Tang 10179e9d176dSGeliang Tang :> "$cout" 10189e9d176dSGeliang Tang :> "$sout" 10199e9d176dSGeliang Tang :> "$capout" 10209e9d176dSGeliang Tang 10219e9d176dSGeliang Tang if [ $capture -eq 1 ]; then 10229e9d176dSGeliang Tang local capuser 10239e9d176dSGeliang Tang if [ -z $SUDO_USER ] ; then 10249e9d176dSGeliang Tang capuser="" 10259e9d176dSGeliang Tang else 10269e9d176dSGeliang Tang capuser="-Z $SUDO_USER" 10279e9d176dSGeliang Tang fi 10289e9d176dSGeliang Tang 10299e9d176dSGeliang Tang capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 10309e9d176dSGeliang Tang 10319e9d176dSGeliang Tang echo "Capturing traffic for test $TEST_COUNT into $capfile" 10329e9d176dSGeliang Tang ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 10339e9d176dSGeliang Tang cappid=$! 10349e9d176dSGeliang Tang 10359e9d176dSGeliang Tang sleep 1 10369e9d176dSGeliang Tang fi 10379e9d176dSGeliang Tang 10389e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 10399e9d176dSGeliang Tang nstat -n 10409e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 10419e9d176dSGeliang Tang nstat -n 10429e9d176dSGeliang Tang 10439e9d176dSGeliang Tang local extra_args 10449e9d176dSGeliang Tang if [ $speed = "fast" ]; then 10459e9d176dSGeliang Tang extra_args="-j" 10469e9d176dSGeliang Tang elif [ $speed = "slow" ]; then 10479e9d176dSGeliang Tang extra_args="-r 50" 1048e571fb09SGeliang Tang elif [ $speed -gt 0 ]; then 1049e571fb09SGeliang Tang extra_args="-r ${speed}" 10509e9d176dSGeliang Tang fi 10519e9d176dSGeliang Tang 10529e9d176dSGeliang Tang local extra_cl_args="" 10539e9d176dSGeliang Tang local extra_srv_args="" 10549e9d176dSGeliang Tang local trunc_size="" 1055080b7f57SGeliang Tang if [ -n "${fastclose}" ]; then 10569e9d176dSGeliang Tang if [ ${test_linkfail} -le 1 ]; then 105703668c65SMatthieu Baerts fail_test "fastclose tests need test_linkfail argument" 10589e9d176dSGeliang Tang return 1 10599e9d176dSGeliang Tang fi 10609e9d176dSGeliang Tang 10619e9d176dSGeliang Tang # disconnect 10629e9d176dSGeliang Tang trunc_size=${test_linkfail} 1063080b7f57SGeliang Tang local side=${fastclose} 10649e9d176dSGeliang Tang 10659e9d176dSGeliang Tang if [ ${side} = "client" ]; then 10669e9d176dSGeliang Tang extra_cl_args="-f ${test_linkfail}" 10679e9d176dSGeliang Tang extra_srv_args="-f -1" 10689e9d176dSGeliang Tang elif [ ${side} = "server" ]; then 10699e9d176dSGeliang Tang extra_srv_args="-f ${test_linkfail}" 10709e9d176dSGeliang Tang extra_cl_args="-f -1" 10719e9d176dSGeliang Tang else 107203668c65SMatthieu Baerts fail_test "wrong/unknown fastclose spec ${side}" 10739e9d176dSGeliang Tang return 1 10749e9d176dSGeliang Tang fi 10759e9d176dSGeliang Tang fi 10769e9d176dSGeliang Tang 10779e9d176dSGeliang Tang extra_srv_args="$extra_args $extra_srv_args" 10789e9d176dSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 10799e9d176dSGeliang Tang timeout ${timeout_test} \ 10809e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10819e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10829e9d176dSGeliang Tang $extra_srv_args "::" < "$sinfail" > "$sout" & 10839e9d176dSGeliang Tang else 10849e9d176dSGeliang Tang timeout ${timeout_test} \ 10859e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10869e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10879e9d176dSGeliang Tang $extra_srv_args "::" < "$sin" > "$sout" & 10889e9d176dSGeliang Tang fi 10899e9d176dSGeliang Tang local spid=$! 10909e9d176dSGeliang Tang 10919e9d176dSGeliang Tang wait_local_port_listen "${listener_ns}" "${port}" 10929e9d176dSGeliang Tang 10939e9d176dSGeliang Tang extra_cl_args="$extra_args $extra_cl_args" 10949e9d176dSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 10959e9d176dSGeliang Tang timeout ${timeout_test} \ 10969e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 10979e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 10989e9d176dSGeliang Tang $extra_cl_args $connect_addr < "$cin" > "$cout" & 10999e9d176dSGeliang Tang elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 11009e9d176dSGeliang Tang ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 11019e9d176dSGeliang Tang tee "$cinsent" | \ 11029e9d176dSGeliang Tang timeout ${timeout_test} \ 11039e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11049e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11059e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11069e9d176dSGeliang Tang else 11079e9d176dSGeliang Tang tee "$cinsent" < "$cinfail" | \ 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 fi 11139e9d176dSGeliang Tang local cpid=$! 11149e9d176dSGeliang Tang 11159e9d176dSGeliang Tang pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 1116718eb44eSGeliang Tang 1117b08fbf24SPaolo Abeni wait $cpid 11181e777bd8SMatthieu Baerts local retc=$? 1119b08fbf24SPaolo Abeni wait $spid 11201e777bd8SMatthieu Baerts local rets=$? 1121b08fbf24SPaolo Abeni 1122b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1123b08fbf24SPaolo Abeni sleep 1 1124b08fbf24SPaolo Abeni kill $cappid 1125b08fbf24SPaolo Abeni fi 1126b08fbf24SPaolo Abeni 1127c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1128c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1129c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1130c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1131c2a55e8fSMatthieu Baerts 1132b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 113303668c65SMatthieu Baerts fail_test "client exit code $retc, server $rets" 11348b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1135c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1136c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 11378b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1138c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1139c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1140b08fbf24SPaolo Abeni 1141b08fbf24SPaolo Abeni cat "$capout" 1142b08fbf24SPaolo Abeni return 1 1143b08fbf24SPaolo Abeni fi 1144b08fbf24SPaolo Abeni 11450c93af1fSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 11466bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 11477d1e6f16SPaolo Abeni else 11486bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 11497d1e6f16SPaolo Abeni fi 1150b08fbf24SPaolo Abeni retc=$? 11510c93af1fSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11526bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 11538b819a84SFlorian Westphal else 11546bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 11558b819a84SFlorian Westphal fi 1156b08fbf24SPaolo Abeni rets=$? 1157b08fbf24SPaolo Abeni 1158b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1159b08fbf24SPaolo Abeni cat "$capout" 1160b08fbf24SPaolo Abeni return 0 1161b08fbf24SPaolo Abeni fi 1162b08fbf24SPaolo Abeni 1163b08fbf24SPaolo Abeni cat "$capout" 1164b08fbf24SPaolo Abeni return 1 1165b08fbf24SPaolo Abeni} 1166b08fbf24SPaolo Abeni 1167b08fbf24SPaolo Abenimake_file() 1168b08fbf24SPaolo Abeni{ 11691e777bd8SMatthieu Baerts local name=$1 11701e777bd8SMatthieu Baerts local who=$2 11711e777bd8SMatthieu Baerts local size=$3 1172b08fbf24SPaolo Abeni 11738b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1174b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1175b08fbf24SPaolo Abeni 117603668c65SMatthieu Baerts print_info "Test file (size $size KB) for $who" 1177b08fbf24SPaolo Abeni} 1178b08fbf24SPaolo Abeni 1179b08fbf24SPaolo Abenirun_tests() 1180b08fbf24SPaolo Abeni{ 11811e777bd8SMatthieu Baerts local listener_ns="$1" 11821e777bd8SMatthieu Baerts local connector_ns="$2" 11831e777bd8SMatthieu Baerts local connect_addr="$3" 11841e777bd8SMatthieu Baerts 11851e777bd8SMatthieu Baerts local size 1186662aa22dSGeliang Tang local test_linkfail=${test_linkfail:-0} 11878b819a84SFlorian Westphal 118834b572b7SGeliang Tang # The values above 2 are reused to make test files 118934b572b7SGeliang Tang # with the given sizes (KB) 119034b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 119134b572b7SGeliang Tang size=$test_linkfail 119234b572b7SGeliang Tang 119334b572b7SGeliang Tang if [ -z "$cinfail" ]; then 119434b572b7SGeliang Tang cinfail=$(mktemp) 119534b572b7SGeliang Tang fi 119634b572b7SGeliang Tang make_file "$cinfail" "client" $size 11977d1e6f16SPaolo Abeni # create the input file for the failure test when 11987d1e6f16SPaolo Abeni # the first failure test run 1199d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 12007d1e6f16SPaolo Abeni # the client file must be considerably larger 12017d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 12027d1e6f16SPaolo Abeni # link utilization will be not predicable 12037d1e6f16SPaolo Abeni size=$((RANDOM%2)) 12048b819a84SFlorian Westphal size=$((size+1)) 12057d1e6f16SPaolo Abeni size=$((size*8192)) 1206d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 12078b819a84SFlorian Westphal 12087d1e6f16SPaolo Abeni cinfail=$(mktemp) 12097d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 12107d1e6f16SPaolo Abeni fi 12117d1e6f16SPaolo Abeni 121234b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 121334b572b7SGeliang Tang size=$test_linkfail 121434b572b7SGeliang Tang 121534b572b7SGeliang Tang if [ -z "$sinfail" ]; then 121634b572b7SGeliang Tang sinfail=$(mktemp) 121734b572b7SGeliang Tang fi 121834b572b7SGeliang Tang make_file "$sinfail" "server" $size 1219d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 12207d1e6f16SPaolo Abeni size=$((RANDOM%16)) 12217d1e6f16SPaolo Abeni size=$((size+1)) 12227d1e6f16SPaolo Abeni size=$((size*2048)) 12237d1e6f16SPaolo Abeni 12247d1e6f16SPaolo Abeni sinfail=$(mktemp) 12257d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 12268b819a84SFlorian Westphal fi 1227b08fbf24SPaolo Abeni 1228e571fb09SGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 1229b08fbf24SPaolo Abeni} 1230b08fbf24SPaolo Abeni 1231327b9a94SPaolo Abenidump_stats() 1232327b9a94SPaolo Abeni{ 1233327b9a94SPaolo Abeni echo Server ns stats 1234327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1235327b9a94SPaolo Abeni echo Client ns stats 1236327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1237327b9a94SPaolo Abeni} 1238327b9a94SPaolo Abeni 1239af66d3e1SGeliang Tangchk_csum_nr() 1240af66d3e1SGeliang Tang{ 12413c082695SGeliang Tang local csum_ns1=${1:-0} 12423c082695SGeliang Tang local csum_ns2=${2:-0} 1243af66d3e1SGeliang Tang local count 124453f368bfSGeliang Tang local extra_msg="" 124526516e10SGeliang Tang local allow_multi_errors_ns1=0 124626516e10SGeliang Tang local allow_multi_errors_ns2=0 124726516e10SGeliang Tang 124826516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 124926516e10SGeliang Tang allow_multi_errors_ns1=1 125026516e10SGeliang Tang csum_ns1=${csum_ns1:1} 125126516e10SGeliang Tang fi 125226516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 125326516e10SGeliang Tang allow_multi_errors_ns2=1 125426516e10SGeliang Tang csum_ns2=${csum_ns2:1} 125526516e10SGeliang Tang fi 1256af66d3e1SGeliang Tang 125703668c65SMatthieu Baerts print_check "sum" 1258697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") 125999c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$csum_ns1" ]; then 1260732752baSGeliang Tang extra_msg+=" ns1=$count" 126153f368bfSGeliang Tang fi 126247867f0aSMatthieu Baerts if [ -z "$count" ]; then 126303668c65SMatthieu Baerts print_skip 126447867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1265d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 126603668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns1" 1267af66d3e1SGeliang Tang else 126803668c65SMatthieu Baerts print_ok 1269af66d3e1SGeliang Tang fi 127003668c65SMatthieu Baerts print_check "csum" 1271697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") 127299c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$csum_ns2" ]; then 1273732752baSGeliang Tang extra_msg+=" ns2=$count" 127453f368bfSGeliang Tang fi 127547867f0aSMatthieu Baerts if [ -z "$count" ]; then 127603668c65SMatthieu Baerts print_skip 127747867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1278d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 127903668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns2" 1280af66d3e1SGeliang Tang else 128103668c65SMatthieu Baerts print_ok 1282af66d3e1SGeliang Tang fi 128353f368bfSGeliang Tang 128403668c65SMatthieu Baerts print_info "$extra_msg" 1285af66d3e1SGeliang Tang} 1286af66d3e1SGeliang Tang 12876bb3ab49SGeliang Tangchk_fail_nr() 12886bb3ab49SGeliang Tang{ 128926516e10SGeliang Tang local fail_tx=$1 129026516e10SGeliang Tang local fail_rx=$2 12911f7d325fSGeliang Tang local ns_invert=${3:-""} 12926bb3ab49SGeliang Tang local count 12931f7d325fSGeliang Tang local ns_tx=$ns1 12941f7d325fSGeliang Tang local ns_rx=$ns2 12951f7d325fSGeliang Tang local extra_msg="" 12961f7d325fSGeliang Tang local allow_tx_lost=0 12971f7d325fSGeliang Tang local allow_rx_lost=0 12981f7d325fSGeliang Tang 12991f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 13001f7d325fSGeliang Tang ns_tx=$ns2 13011f7d325fSGeliang Tang ns_rx=$ns1 13021f7d325fSGeliang Tang extra_msg="invert" 13031f7d325fSGeliang Tang fi 13041f7d325fSGeliang Tang 13051f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 13061f7d325fSGeliang Tang allow_tx_lost=1 13071f7d325fSGeliang Tang fail_tx=${fail_tx:1} 13081f7d325fSGeliang Tang fi 13091f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 13101f7d325fSGeliang Tang allow_rx_lost=1 13111f7d325fSGeliang Tang fail_rx=${fail_rx:1} 13121f7d325fSGeliang Tang fi 13136bb3ab49SGeliang Tang 131403668c65SMatthieu Baerts print_check "ftx" 1315697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") 131699c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$fail_tx" ]; then 1317732752baSGeliang Tang extra_msg+=",tx=$count" 13181f7d325fSGeliang Tang fi 131947867f0aSMatthieu Baerts if [ -z "$count" ]; then 132003668c65SMatthieu Baerts print_skip 132147867f0aSMatthieu Baerts elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 13221f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 132303668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] TX expected $fail_tx" 13246bb3ab49SGeliang Tang else 132503668c65SMatthieu Baerts print_ok 13266bb3ab49SGeliang Tang fi 13276bb3ab49SGeliang Tang 132803668c65SMatthieu Baerts print_check "failrx" 1329697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") 133099c17b3bSMatthieu Baerts (NGI0) if [ -n "$count" ] && [ "$count" != "$fail_rx" ]; then 1331732752baSGeliang Tang extra_msg+=",rx=$count" 13321f7d325fSGeliang Tang fi 133347867f0aSMatthieu Baerts if [ -z "$count" ]; then 133403668c65SMatthieu Baerts print_skip 133547867f0aSMatthieu Baerts elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 13361f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 133703668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] RX expected $fail_rx" 13386bb3ab49SGeliang Tang else 133903668c65SMatthieu Baerts print_ok 13406bb3ab49SGeliang Tang fi 13416bb3ab49SGeliang Tang 134203668c65SMatthieu Baerts print_info "$extra_msg" 13436bb3ab49SGeliang Tang} 13446bb3ab49SGeliang Tang 1345e8e947efSGeliang Tangchk_fclose_nr() 1346e8e947efSGeliang Tang{ 1347e8e947efSGeliang Tang local fclose_tx=$1 1348e8e947efSGeliang Tang local fclose_rx=$2 13496bf41020SPaolo Abeni local ns_invert=$3 1350e8e947efSGeliang Tang local count 13516bf41020SPaolo Abeni local ns_tx=$ns2 13526bf41020SPaolo Abeni local ns_rx=$ns1 13536bf41020SPaolo Abeni local extra_msg="" 13546bf41020SPaolo Abeni 13556bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 13566bf41020SPaolo Abeni ns_tx=$ns1 13576bf41020SPaolo Abeni ns_rx=$ns2 135803668c65SMatthieu Baerts extra_msg="invert" 13596bf41020SPaolo Abeni fi 1360e8e947efSGeliang Tang 136103668c65SMatthieu Baerts print_check "ctx" 1362697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx") 136347867f0aSMatthieu Baerts if [ -z "$count" ]; then 136403668c65SMatthieu Baerts print_skip 136547867f0aSMatthieu Baerts elif [ "$count" != "$fclose_tx" ]; then 1366732752baSGeliang Tang extra_msg+=",tx=$count" 136703668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1368e8e947efSGeliang Tang else 136903668c65SMatthieu Baerts print_ok 1370e8e947efSGeliang Tang fi 1371e8e947efSGeliang Tang 137203668c65SMatthieu Baerts print_check "fclzrx" 1373697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx") 137447867f0aSMatthieu Baerts if [ -z "$count" ]; then 137503668c65SMatthieu Baerts print_skip 137647867f0aSMatthieu Baerts elif [ "$count" != "$fclose_rx" ]; then 1377732752baSGeliang Tang extra_msg+=",rx=$count" 137803668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1379e8e947efSGeliang Tang else 138003668c65SMatthieu Baerts print_ok 1381e8e947efSGeliang Tang fi 1382e8e947efSGeliang Tang 138303668c65SMatthieu Baerts print_info "$extra_msg" 1384e8e947efSGeliang Tang} 1385e8e947efSGeliang Tang 1386922fd2b3SGeliang Tangchk_rst_nr() 1387922fd2b3SGeliang Tang{ 1388922fd2b3SGeliang Tang local rst_tx=$1 1389922fd2b3SGeliang Tang local rst_rx=$2 1390922fd2b3SGeliang Tang local ns_invert=${3:-""} 1391922fd2b3SGeliang Tang local count 1392922fd2b3SGeliang Tang local ns_tx=$ns1 1393922fd2b3SGeliang Tang local ns_rx=$ns2 1394922fd2b3SGeliang Tang local extra_msg="" 1395922fd2b3SGeliang Tang 1396922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1397922fd2b3SGeliang Tang ns_tx=$ns2 1398922fd2b3SGeliang Tang ns_rx=$ns1 1399922fd2b3SGeliang Tang extra_msg="invert" 1400922fd2b3SGeliang Tang fi 1401922fd2b3SGeliang Tang 140203668c65SMatthieu Baerts print_check "rtx" 1403697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx") 140447867f0aSMatthieu Baerts if [ -z "$count" ]; then 140503668c65SMatthieu Baerts print_skip 1406b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1407b134a580SMatthieu Baerts elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } || 1408b134a580SMatthieu Baerts { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then 140903668c65SMatthieu Baerts fail_test "got $count MP_RST[s] TX expected $rst_tx" 1410922fd2b3SGeliang Tang else 141103668c65SMatthieu Baerts print_ok 1412922fd2b3SGeliang Tang fi 1413922fd2b3SGeliang Tang 141403668c65SMatthieu Baerts print_check "rstrx" 1415697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx") 141647867f0aSMatthieu Baerts if [ -z "$count" ]; then 141703668c65SMatthieu Baerts print_skip 1418b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1419b134a580SMatthieu Baerts elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } || 1420b134a580SMatthieu Baerts { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then 142103668c65SMatthieu Baerts fail_test "got $count MP_RST[s] RX expected $rst_rx" 1422922fd2b3SGeliang Tang else 142303668c65SMatthieu Baerts print_ok 1424922fd2b3SGeliang Tang fi 1425922fd2b3SGeliang Tang 142603668c65SMatthieu Baerts print_info "$extra_msg" 1427922fd2b3SGeliang Tang} 1428922fd2b3SGeliang Tang 14298bd03be3SGeliang Tangchk_infi_nr() 14308bd03be3SGeliang Tang{ 14318bd03be3SGeliang Tang local infi_tx=$1 14328bd03be3SGeliang Tang local infi_rx=$2 14338bd03be3SGeliang Tang local count 14348bd03be3SGeliang Tang 143503668c65SMatthieu Baerts print_check "itx" 1436697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx") 143747867f0aSMatthieu Baerts if [ -z "$count" ]; then 143803668c65SMatthieu Baerts print_skip 143947867f0aSMatthieu Baerts elif [ "$count" != "$infi_tx" ]; then 144003668c65SMatthieu Baerts fail_test "got $count infinite map[s] TX expected $infi_tx" 14418bd03be3SGeliang Tang else 144203668c65SMatthieu Baerts print_ok 14438bd03be3SGeliang Tang fi 14448bd03be3SGeliang Tang 144503668c65SMatthieu Baerts print_check "infirx" 1446697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx") 144747867f0aSMatthieu Baerts if [ -z "$count" ]; then 144803668c65SMatthieu Baerts print_skip 144947867f0aSMatthieu Baerts elif [ "$count" != "$infi_rx" ]; then 145003668c65SMatthieu Baerts fail_test "got $count infinite map[s] RX expected $infi_rx" 14518bd03be3SGeliang Tang else 145203668c65SMatthieu Baerts print_ok 14538bd03be3SGeliang Tang fi 14548bd03be3SGeliang Tang} 14558bd03be3SGeliang Tang 1456b08fbf24SPaolo Abenichk_join_nr() 1457b08fbf24SPaolo Abeni{ 1458c7d49c03SMatthieu Baerts local syn_nr=$1 1459c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1460c7d49c03SMatthieu Baerts local ack_nr=$3 1461c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1462c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1463c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1464c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 14658bd03be3SGeliang Tang local infi_nr=${8:-0} 14668bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1467b08fbf24SPaolo Abeni local count 1468e35f885bSPaolo Abeni local with_cookie 1469b08fbf24SPaolo Abeni 1470c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 147103668c65SMatthieu Baerts print_info "${corrupted_pkts} corrupted pkts" 1472c7d49c03SMatthieu Baerts fi 1473c7d49c03SMatthieu Baerts 147403668c65SMatthieu Baerts print_check "syn" 1475697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx") 147647867f0aSMatthieu Baerts if [ -z "$count" ]; then 147703668c65SMatthieu Baerts print_skip 147847867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 147903668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn expected $syn_nr" 1480b08fbf24SPaolo Abeni else 148103668c65SMatthieu Baerts print_ok 1482b08fbf24SPaolo Abeni fi 1483b08fbf24SPaolo Abeni 148403668c65SMatthieu Baerts print_check "synack" 14854bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 1486697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx") 148747867f0aSMatthieu Baerts if [ -z "$count" ]; then 148803668c65SMatthieu Baerts print_skip 148947867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 1490e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1491e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1492e35f885bSPaolo Abeni # the subflow creation 1493e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 149403668c65SMatthieu Baerts print_ok 1495e35f885bSPaolo Abeni else 149603668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack expected $syn_ack_nr" 1497e35f885bSPaolo Abeni fi 1498b08fbf24SPaolo Abeni else 149903668c65SMatthieu Baerts print_ok 1500b08fbf24SPaolo Abeni fi 1501b08fbf24SPaolo Abeni 150203668c65SMatthieu Baerts print_check "ack" 1503697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx") 150447867f0aSMatthieu Baerts if [ -z "$count" ]; then 150503668c65SMatthieu Baerts print_skip 150647867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 150703668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack expected $ack_nr" 1508b08fbf24SPaolo Abeni else 150903668c65SMatthieu Baerts print_ok 1510b08fbf24SPaolo Abeni fi 1511b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 15123c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 151326516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 151426516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 15158bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1516af66d3e1SGeliang Tang fi 1517b08fbf24SPaolo Abeni} 1518b08fbf24SPaolo Abeni 15197d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 15207d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 15217d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 15227d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 15237d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 15247d1e6f16SPaolo Abenichk_stale_nr() 15257d1e6f16SPaolo Abeni{ 15267d1e6f16SPaolo Abeni local ns=$1 15277d1e6f16SPaolo Abeni local stale_min=$2 15287d1e6f16SPaolo Abeni local stale_max=$3 15297d1e6f16SPaolo Abeni local stale_delta=$4 15307d1e6f16SPaolo Abeni local dump_stats 15317d1e6f16SPaolo Abeni local stale_nr 15327d1e6f16SPaolo Abeni local recover_nr 15337d1e6f16SPaolo Abeni 153403668c65SMatthieu Baerts print_check "stale" 15357d1e6f16SPaolo Abeni 1536697128a3SGeliang Tang stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale") 1537697128a3SGeliang Tang recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover") 153847867f0aSMatthieu Baerts if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then 153903668c65SMatthieu Baerts print_skip 154047867f0aSMatthieu Baerts elif [ $stale_nr -lt $stale_min ] || 1541d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1542d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 154303668c65SMatthieu Baerts fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \ 15447d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 15457d1e6f16SPaolo Abeni " stale-recover delta $stale_delta" 15467d1e6f16SPaolo Abeni dump_stats=1 15477d1e6f16SPaolo Abeni else 154803668c65SMatthieu Baerts print_ok 15497d1e6f16SPaolo Abeni fi 15507d1e6f16SPaolo Abeni 15517d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 15527d1e6f16SPaolo Abeni echo $ns stats 15537d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 15547d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 15557d1e6f16SPaolo Abeni fi 15567d1e6f16SPaolo Abeni} 15577d1e6f16SPaolo Abeni 1558be613160SGeliang Tangchk_add_nr() 1559be613160SGeliang Tang{ 1560be613160SGeliang Tang local add_nr=$1 1561be613160SGeliang Tang local echo_nr=$2 15628a127bf6SGeliang Tang local port_nr=${3:-0} 1563e80cf3fcSMatthieu Baerts (NGI0) local ns_invert=${4:-""} 1564e80cf3fcSMatthieu Baerts (NGI0) local syn_nr=$port_nr 1565e80cf3fcSMatthieu Baerts (NGI0) local syn_ack_nr=$port_nr 1566e80cf3fcSMatthieu Baerts (NGI0) local ack_nr=$port_nr 1567e80cf3fcSMatthieu Baerts (NGI0) local mis_syn_nr=0 1568e80cf3fcSMatthieu Baerts (NGI0) local mis_ack_nr=0 1569e80cf3fcSMatthieu Baerts (NGI0) local ns_tx=$ns1 1570e80cf3fcSMatthieu Baerts (NGI0) local ns_rx=$ns2 1571e80cf3fcSMatthieu Baerts (NGI0) local extra_msg="" 1572be613160SGeliang Tang local count 15736ef84b15SPaolo Abeni local timeout 15746ef84b15SPaolo Abeni 1575e80cf3fcSMatthieu Baerts (NGI0) if [[ $ns_invert = "invert" ]]; then 1576e80cf3fcSMatthieu Baerts (NGI0) ns_tx=$ns2 1577e80cf3fcSMatthieu Baerts (NGI0) ns_rx=$ns1 1578e80cf3fcSMatthieu Baerts (NGI0) extra_msg="invert" 1579e80cf3fcSMatthieu Baerts (NGI0) fi 1580e80cf3fcSMatthieu Baerts (NGI0) 1581e80cf3fcSMatthieu Baerts (NGI0) timeout=$(ip netns exec ${ns_tx} sysctl -n net.mptcp.add_addr_timeout) 1582be613160SGeliang Tang 158303668c65SMatthieu Baerts print_check "add" 1584e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtAddAddr") 158547867f0aSMatthieu Baerts if [ -z "$count" ]; then 158603668c65SMatthieu Baerts print_skip 15876ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15886ef84b15SPaolo Abeni # add addrs options, due to retransmissions 158947867f0aSMatthieu Baerts elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 159003668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] expected $add_nr" 1591be613160SGeliang Tang else 159203668c65SMatthieu Baerts print_ok 1593be613160SGeliang Tang fi 1594be613160SGeliang Tang 159503668c65SMatthieu Baerts print_check "echo" 1596e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtEchoAdd") 159747867f0aSMatthieu Baerts if [ -z "$count" ]; then 159803668c65SMatthieu Baerts print_skip 159947867f0aSMatthieu Baerts elif [ "$count" != "$echo_nr" ]; then 160003668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] expected $echo_nr" 1601be613160SGeliang Tang else 160203668c65SMatthieu Baerts print_ok 16038a127bf6SGeliang Tang fi 16048a127bf6SGeliang Tang 16058a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 160603668c65SMatthieu Baerts print_check "pt" 1607e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtPortAdd") 160847867f0aSMatthieu Baerts if [ -z "$count" ]; then 160903668c65SMatthieu Baerts print_skip 161047867f0aSMatthieu Baerts elif [ "$count" != "$port_nr" ]; then 161103668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr" 16128a127bf6SGeliang Tang else 161303668c65SMatthieu Baerts print_ok 1614be613160SGeliang Tang fi 1615be613160SGeliang Tang 161603668c65SMatthieu Baerts print_check "syn" 1617e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortSynRx") 161847867f0aSMatthieu Baerts if [ -z "$count" ]; then 161903668c65SMatthieu Baerts print_skip 162047867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 162103668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a different \ 16228a127bf6SGeliang Tang port-number expected $syn_nr" 16238a127bf6SGeliang Tang else 162403668c65SMatthieu Baerts print_ok 16258a127bf6SGeliang Tang fi 16268a127bf6SGeliang Tang 162703668c65SMatthieu Baerts print_check "synack" 1628e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPJoinPortSynAckRx") 162947867f0aSMatthieu Baerts if [ -z "$count" ]; then 163003668c65SMatthieu Baerts print_skip 163147867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 163203668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack with a different \ 16338a127bf6SGeliang Tang port-number expected $syn_ack_nr" 16348a127bf6SGeliang Tang else 163503668c65SMatthieu Baerts print_ok 16368a127bf6SGeliang Tang fi 16378a127bf6SGeliang Tang 163803668c65SMatthieu Baerts print_check "ack" 1639e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortAckRx") 164047867f0aSMatthieu Baerts if [ -z "$count" ]; then 164103668c65SMatthieu Baerts print_skip 164247867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 164303668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a different \ 16448a127bf6SGeliang Tang port-number expected $ack_nr" 16458a127bf6SGeliang Tang else 164603668c65SMatthieu Baerts print_ok 16478a127bf6SGeliang Tang fi 16488a127bf6SGeliang Tang 164903668c65SMatthieu Baerts print_check "syn" 1650e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortSynRx") 165147867f0aSMatthieu Baerts if [ -z "$count" ]; then 165203668c65SMatthieu Baerts print_skip 165347867f0aSMatthieu Baerts elif [ "$count" != "$mis_syn_nr" ]; then 165403668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a mismatched \ 16558a127bf6SGeliang Tang port-number expected $mis_syn_nr" 16568a127bf6SGeliang Tang else 165703668c65SMatthieu Baerts print_ok 16588a127bf6SGeliang Tang fi 16598a127bf6SGeliang Tang 166003668c65SMatthieu Baerts print_check "ack" 1661e80cf3fcSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortAckRx") 166247867f0aSMatthieu Baerts if [ -z "$count" ]; then 166303668c65SMatthieu Baerts print_skip 166447867f0aSMatthieu Baerts elif [ "$count" != "$mis_ack_nr" ]; then 166503668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a mismatched \ 16668a127bf6SGeliang Tang port-number expected $mis_ack_nr" 16678a127bf6SGeliang Tang else 166803668c65SMatthieu Baerts print_ok 16698a127bf6SGeliang Tang fi 16708a127bf6SGeliang Tang fi 1671e80cf3fcSMatthieu Baerts (NGI0) 1672e80cf3fcSMatthieu Baerts (NGI0) print_info "$extra_msg" 1673be613160SGeliang Tang} 1674be613160SGeliang Tang 16750639fa23SPaolo Abenichk_add_tx_nr() 16760639fa23SPaolo Abeni{ 16770639fa23SPaolo Abeni local add_tx_nr=$1 16780639fa23SPaolo Abeni local echo_tx_nr=$2 16790639fa23SPaolo Abeni local timeout 16800639fa23SPaolo Abeni local count 16810639fa23SPaolo Abeni 16820639fa23SPaolo Abeni timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 16830639fa23SPaolo Abeni 168403668c65SMatthieu Baerts print_check "add TX" 1685697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx") 168600079f18SMatthieu Baerts if [ -z "$count" ]; then 168703668c65SMatthieu Baerts print_skip 16880639fa23SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 16890639fa23SPaolo Abeni # add addrs options, due to retransmissions 169000079f18SMatthieu Baerts elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 169103668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr" 16920639fa23SPaolo Abeni else 169303668c65SMatthieu Baerts print_ok 16940639fa23SPaolo Abeni fi 16950639fa23SPaolo Abeni 169603668c65SMatthieu Baerts print_check "echo TX" 1697697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx") 169800079f18SMatthieu Baerts if [ -z "$count" ]; then 169903668c65SMatthieu Baerts print_skip 170000079f18SMatthieu Baerts elif [ "$count" != "$echo_tx_nr" ]; then 170103668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 17020639fa23SPaolo Abeni else 170303668c65SMatthieu Baerts print_ok 17040639fa23SPaolo Abeni fi 17050639fa23SPaolo Abeni} 17060639fa23SPaolo Abeni 1707dd72b0feSGeliang Tangchk_rm_nr() 1708dd72b0feSGeliang Tang{ 1709dd72b0feSGeliang Tang local rm_addr_nr=$1 1710dd72b0feSGeliang Tang local rm_subflow_nr=$2 17116fa0174aSPaolo Abeni local invert 17126fa0174aSPaolo Abeni local simult 1713dd72b0feSGeliang Tang local count 17147d9bf018SGeliang Tang local addr_ns=$ns1 17157d9bf018SGeliang Tang local subflow_ns=$ns2 17167d9bf018SGeliang Tang local extra_msg="" 17177028ba8aSGeliang Tang 17186fa0174aSPaolo Abeni shift 2 17196fa0174aSPaolo Abeni while [ -n "$1" ]; do 17206fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 17216fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 17226fa0174aSPaolo Abeni shift 17236fa0174aSPaolo Abeni done 17246fa0174aSPaolo Abeni 17256fa0174aSPaolo Abeni if [ -z $invert ]; then 17266fa0174aSPaolo Abeni addr_ns=$ns1 17276fa0174aSPaolo Abeni subflow_ns=$ns2 17286fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 17297028ba8aSGeliang Tang addr_ns=$ns2 17307028ba8aSGeliang Tang subflow_ns=$ns1 17317d9bf018SGeliang Tang extra_msg="invert" 17327028ba8aSGeliang Tang fi 1733dd72b0feSGeliang Tang 173403668c65SMatthieu Baerts print_check "rm" 1735697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr") 173600079f18SMatthieu Baerts if [ -z "$count" ]; then 173703668c65SMatthieu Baerts print_skip 173800079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_nr" ]; then 173903668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_nr" 1740dd72b0feSGeliang Tang else 174103668c65SMatthieu Baerts print_ok 1742dd72b0feSGeliang Tang fi 1743dd72b0feSGeliang Tang 174403668c65SMatthieu Baerts print_check "rmsf" 1745697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow") 174647867f0aSMatthieu Baerts if [ -z "$count" ]; then 174703668c65SMatthieu Baerts print_skip 174847867f0aSMatthieu Baerts elif [ -n "$simult" ]; then 1749d8d08302SMatthieu Baerts local cnt suffix 1750d8d08302SMatthieu Baerts 1751697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow") 17526fa0174aSPaolo Abeni 17536fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 17546fa0174aSPaolo Abeni # unreliable 17556fa0174aSPaolo Abeni count=$((count + cnt)) 1756a445eb1fSGeliang Tang if [ "$count" != "$rm_subflow_nr" ]; then 1757a445eb1fSGeliang Tang suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1758732752baSGeliang Tang extra_msg+=" simult" 1759a445eb1fSGeliang Tang fi 17606fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 17616fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 176203668c65SMatthieu Baerts print_ok "$suffix" 17636fa0174aSPaolo Abeni else 176403668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 17656fa0174aSPaolo Abeni fi 176647867f0aSMatthieu Baerts elif [ "$count" != "$rm_subflow_nr" ]; then 176703668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1768dd72b0feSGeliang Tang else 176903668c65SMatthieu Baerts print_ok 1770dd72b0feSGeliang Tang fi 1771dd72b0feSGeliang Tang 177203668c65SMatthieu Baerts print_info "$extra_msg" 1773dd72b0feSGeliang Tang} 1774dd72b0feSGeliang Tang 17750639fa23SPaolo Abenichk_rm_tx_nr() 17760639fa23SPaolo Abeni{ 17770639fa23SPaolo Abeni local rm_addr_tx_nr=$1 17780639fa23SPaolo Abeni 177903668c65SMatthieu Baerts print_check "rm TX" 1780697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx") 178100079f18SMatthieu Baerts if [ -z "$count" ]; then 178203668c65SMatthieu Baerts print_skip 178300079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_tx_nr" ]; then 178403668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr" 17850639fa23SPaolo Abeni else 178603668c65SMatthieu Baerts print_ok 17870639fa23SPaolo Abeni fi 17880639fa23SPaolo Abeni} 17890639fa23SPaolo Abeni 1790718eb44eSGeliang Tangchk_prio_nr() 1791718eb44eSGeliang Tang{ 1792718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1793718eb44eSGeliang Tang local mp_prio_nr_rx=$2 17948213b98eSMatthieu Baerts (NGI0) local mpj_syn=$3 17958213b98eSMatthieu Baerts (NGI0) local mpj_syn_ack=$4 1796718eb44eSGeliang Tang local count 1797718eb44eSGeliang Tang 179803668c65SMatthieu Baerts print_check "ptx" 1799697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx") 180047867f0aSMatthieu Baerts if [ -z "$count" ]; then 180103668c65SMatthieu Baerts print_skip 180247867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_tx" ]; then 180303668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1804718eb44eSGeliang Tang else 180503668c65SMatthieu Baerts print_ok 1806718eb44eSGeliang Tang fi 1807718eb44eSGeliang Tang 180803668c65SMatthieu Baerts print_check "prx" 1809697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx") 181047867f0aSMatthieu Baerts if [ -z "$count" ]; then 181103668c65SMatthieu Baerts print_skip 181247867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_rx" ]; then 181303668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1814718eb44eSGeliang Tang else 181503668c65SMatthieu Baerts print_ok 1816718eb44eSGeliang Tang fi 18178213b98eSMatthieu Baerts (NGI0) 18188213b98eSMatthieu Baerts (NGI0) print_check "syn backup" 18198213b98eSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynBackupRx") 18208213b98eSMatthieu Baerts (NGI0) if [ -z "$count" ]; then 18218213b98eSMatthieu Baerts (NGI0) print_skip 18228213b98eSMatthieu Baerts (NGI0) elif [ "$count" != "$mpj_syn" ]; then 18238213b98eSMatthieu Baerts (NGI0) fail_test "got $count JOIN[s] syn with Backup expected $mpj_syn" 18248213b98eSMatthieu Baerts (NGI0) else 18258213b98eSMatthieu Baerts (NGI0) print_ok 18268213b98eSMatthieu Baerts (NGI0) fi 18278213b98eSMatthieu Baerts (NGI0) 18288213b98eSMatthieu Baerts (NGI0) print_check "synack backup" 18298213b98eSMatthieu Baerts (NGI0) count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckBackupRx") 18308213b98eSMatthieu Baerts (NGI0) if [ -z "$count" ]; then 18318213b98eSMatthieu Baerts (NGI0) print_skip 18328213b98eSMatthieu Baerts (NGI0) elif [ "$count" != "$mpj_syn_ack" ]; then 18338213b98eSMatthieu Baerts (NGI0) fail_test "got $count JOIN[s] synack with Backup expected $mpj_syn_ack" 18348213b98eSMatthieu Baerts (NGI0) else 18358213b98eSMatthieu Baerts (NGI0) print_ok 18368213b98eSMatthieu Baerts (NGI0) fi 1837718eb44eSGeliang Tang} 1838718eb44eSGeliang Tang 1839e274f715SPaolo Abenichk_subflow_nr() 1840e274f715SPaolo Abeni{ 184103668c65SMatthieu Baerts local msg="$1" 184203668c65SMatthieu Baerts local subflow_nr=$2 1843e274f715SPaolo Abeni local cnt1 1844e274f715SPaolo Abeni local cnt2 1845a635a8c3SPaolo Abeni local dump_stats 1846e274f715SPaolo Abeni 184703668c65SMatthieu Baerts print_check "${msg}" 1848e274f715SPaolo Abeni 1849e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1850e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 18510fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 185203668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr" 1853e274f715SPaolo Abeni dump_stats=1 1854e274f715SPaolo Abeni else 185503668c65SMatthieu Baerts print_ok 1856e274f715SPaolo Abeni fi 1857e274f715SPaolo Abeni 1858a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1859a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1860a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1861a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1862a635a8c3SPaolo Abeni fi 1863e274f715SPaolo Abeni} 1864e274f715SPaolo Abeni 18659095ce97SGeliang Tangchk_mptcp_info() 18669095ce97SGeliang Tang{ 1867d7ced753SGeliang Tang local info1=$1 1868d7ced753SGeliang Tang local exp1=$2 1869d7ced753SGeliang Tang local info2=$3 1870d7ced753SGeliang Tang local exp2=$4 18719095ce97SGeliang Tang local cnt1 18729095ce97SGeliang Tang local cnt2 18739095ce97SGeliang Tang local dump_stats 18749095ce97SGeliang Tang 1875f9190d79SGeliang Tang print_check "mptcp_info ${info1:0:15}=$exp1:$exp2" 18769095ce97SGeliang Tang 1877ae1fa39dSGeliang Tang cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info1" "$info1") 1878ae1fa39dSGeliang Tang cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info2" "$info2") 1879d7ced753SGeliang Tang # 'ss' only display active connections and counters that are not 0. 18809095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 18819095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 1882d7ced753SGeliang Tang 1883d7ced753SGeliang Tang if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then 188403668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2" 18859095ce97SGeliang Tang dump_stats=1 18869095ce97SGeliang Tang else 188703668c65SMatthieu Baerts print_ok 18889095ce97SGeliang Tang fi 18899095ce97SGeliang Tang 18909095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 18919095ce97SGeliang Tang ss -N $ns1 -inmHM 18929095ce97SGeliang Tang ss -N $ns2 -inmHM 18939095ce97SGeliang Tang fi 18949095ce97SGeliang Tang} 18959095ce97SGeliang Tang 1896f9190d79SGeliang Tang# $1: subflows in ns1 ; $2: subflows in ns2 1897f9190d79SGeliang Tang# number of all subflows, including the initial subflow. 1898f9190d79SGeliang Tangchk_subflows_total() 1899f9190d79SGeliang Tang{ 1900f9190d79SGeliang Tang local cnt1 1901f9190d79SGeliang Tang local cnt2 1902f9190d79SGeliang Tang local info="subflows_total" 1903f9190d79SGeliang Tang local dump_stats 1904f9190d79SGeliang Tang 1905f9190d79SGeliang Tang # if subflows_total counter is supported, use it: 1906f9190d79SGeliang Tang if [ -n "$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value $info $info)" ]; then 1907f9190d79SGeliang Tang chk_mptcp_info $info $1 $info $2 1908f9190d79SGeliang Tang return 1909f9190d79SGeliang Tang fi 1910f9190d79SGeliang Tang 1911f9190d79SGeliang Tang print_check "$info $1:$2" 1912f9190d79SGeliang Tang 1913f9190d79SGeliang Tang # if not, count the TCP connections that are in fact MPTCP subflows 1914f9190d79SGeliang Tang cnt1=$(ss -N $ns1 -ti state established state syn-sent state syn-recv | 1915f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1916f9190d79SGeliang Tang cnt2=$(ss -N $ns2 -ti state established state syn-sent state syn-recv | 1917f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1918f9190d79SGeliang Tang 1919f9190d79SGeliang Tang if [ "$1" != "$cnt1" ] || [ "$2" != "$cnt2" ]; then 1920f9190d79SGeliang Tang fail_test "got subflows $cnt1:$cnt2 expected $1:$2" 1921f9190d79SGeliang Tang dump_stats=1 1922f9190d79SGeliang Tang else 1923f9190d79SGeliang Tang print_ok 1924f9190d79SGeliang Tang fi 1925f9190d79SGeliang Tang 1926f9190d79SGeliang Tang if [ "$dump_stats" = 1 ]; then 1927f9190d79SGeliang Tang ss -N $ns1 -ti 1928f9190d79SGeliang Tang ss -N $ns2 -ti 1929f9190d79SGeliang Tang fi 1930f9190d79SGeliang Tang} 1931f9190d79SGeliang Tang 19327d1e6f16SPaolo Abenichk_link_usage() 19337d1e6f16SPaolo Abeni{ 19347d1e6f16SPaolo Abeni local ns=$1 19357d1e6f16SPaolo Abeni local link=$2 19367d1e6f16SPaolo Abeni local out=$3 19377d1e6f16SPaolo Abeni local expected_rate=$4 19384bfadd71SMatthieu Baerts 19394bfadd71SMatthieu Baerts local tx_link tx_total 19404bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1941d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1942d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 19437d1e6f16SPaolo Abeni local tolerance=5 19447d1e6f16SPaolo Abeni 194503668c65SMatthieu Baerts print_check "link usage" 1946d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1947d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 194803668c65SMatthieu Baerts fail_test "got $tx_rate% usage, expected $expected_rate%" 19497d1e6f16SPaolo Abeni else 195003668c65SMatthieu Baerts print_ok 19517d1e6f16SPaolo Abeni fi 19527d1e6f16SPaolo Abeni} 19537d1e6f16SPaolo Abeni 1954f98c2bcaSMat Martineauwait_attempt_fail() 195546e967d1SPaolo Abeni{ 195646e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 195746e967d1SPaolo Abeni local time=0 195846e967d1SPaolo Abeni local ns=$1 195946e967d1SPaolo Abeni 196046e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 19611e777bd8SMatthieu Baerts local cnt 19621e777bd8SMatthieu Baerts 1963697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails") 196446e967d1SPaolo Abeni 196546e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 196646e967d1SPaolo Abeni time=$((time + 100)) 196746e967d1SPaolo Abeni sleep 0.1 196846e967d1SPaolo Abeni done 196946e967d1SPaolo Abeni return 1 197046e967d1SPaolo Abeni} 197146e967d1SPaolo Abeni 19725ac1d2d6SMat Martineauset_userspace_pm() 19735ac1d2d6SMat Martineau{ 19745ac1d2d6SMat Martineau local ns=$1 19755ac1d2d6SMat Martineau 19765ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 19775ac1d2d6SMat Martineau} 19785ac1d2d6SMat Martineau 19791002b89fSGeliang Tangsubflows_tests() 19801002b89fSGeliang Tang{ 1981c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1982b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1983c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1984ae7bd9ccSMatthieu Baerts fi 1985b08fbf24SPaolo Abeni 19861002b89fSGeliang Tang # subflow limited by client 1987c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 198834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 198934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 199034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1991b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1992c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1993ae7bd9ccSMatthieu Baerts fi 1994b08fbf24SPaolo Abeni 19951002b89fSGeliang Tang # subflow limited by server 1996c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 199734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 199834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 199934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2000b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2001c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 2002ae7bd9ccSMatthieu Baerts fi 2003b08fbf24SPaolo Abeni 2004b08fbf24SPaolo Abeni # subflow 2005c7d49c03SMatthieu Baerts if reset "single subflow"; then 200634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 200734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 200834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2009b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2010c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2011ae7bd9ccSMatthieu Baerts fi 2012b08fbf24SPaolo Abeni 2013b08fbf24SPaolo Abeni # multiple subflows 2014c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 201534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 201634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 201734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 201834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2019b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2020c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2021ae7bd9ccSMatthieu Baerts fi 2022b08fbf24SPaolo Abeni 202372bcbc46SPaolo Abeni # multiple subflows limited by server 2024c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 202534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 202634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 202734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 202834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2029b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2030c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 2031ae7bd9ccSMatthieu Baerts fi 2032c3eaa5f6SGeliang Tang 2033c3eaa5f6SGeliang Tang # single subflow, dev 2034c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 203534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 203634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 203734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 2038c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2039c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2040ae7bd9ccSMatthieu Baerts fi 20411002b89fSGeliang Tang} 2042b08fbf24SPaolo Abeni 204346e967d1SPaolo Abenisubflows_error_tests() 204446e967d1SPaolo Abeni{ 204546e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 204646e967d1SPaolo Abeni # address, no additional subflow should be created 2047c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 204834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 204934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 205034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2051e571fb09SGeliang Tang speed=slow \ 2052e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2053c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2054ae7bd9ccSMatthieu Baerts fi 205546e967d1SPaolo Abeni 205646e967d1SPaolo Abeni # multiple subflows, with subflow creation error 20574a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT && 20584a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 205934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 206034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 206134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 206234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2063e571fb09SGeliang Tang speed=slow \ 2064e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2065c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2066ae7bd9ccSMatthieu Baerts fi 206746e967d1SPaolo Abeni 206846e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 20694a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP && 20704a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 207134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 207234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 207334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 207434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2075e571fb09SGeliang Tang speed=slow \ 2076e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2077c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2078ae7bd9ccSMatthieu Baerts fi 207946e967d1SPaolo Abeni 208046e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 208146e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 208246e967d1SPaolo Abeni # subflows are added later 20834a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT && 20844a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 208534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 208634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 208734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2088e571fb09SGeliang Tang speed=slow \ 2089e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 209046e967d1SPaolo Abeni 209146e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 2092f98c2bcaSMat Martineau wait_attempt_fail $ns2 209334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 209446e967d1SPaolo Abeni wait 209546e967d1SPaolo Abeni 209646e967d1SPaolo Abeni # additional subflow could be created only if the PM select 209746e967d1SPaolo Abeni # the later endpoint, skipping the already used one 2098c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2099ae7bd9ccSMatthieu Baerts fi 210046e967d1SPaolo Abeni} 210146e967d1SPaolo Abeni 21021002b89fSGeliang Tangsignal_address_tests() 21031002b89fSGeliang Tang{ 2104b08fbf24SPaolo Abeni # add_address, unused 2105c7d49c03SMatthieu Baerts if reset "unused signal address"; then 210634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2107b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2108c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 21090639fa23SPaolo Abeni chk_add_tx_nr 1 1 2110be613160SGeliang Tang chk_add_nr 1 1 2111ae7bd9ccSMatthieu Baerts fi 2112b08fbf24SPaolo Abeni 2113b08fbf24SPaolo Abeni # accept and use add_addr 2114c7d49c03SMatthieu Baerts if reset "signal address"; then 211534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 211634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 211734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2118b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2119c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2120be613160SGeliang Tang chk_add_nr 1 1 2121ae7bd9ccSMatthieu Baerts fi 2122b08fbf24SPaolo Abeni 2123b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 2124b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 2125b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 2126b08fbf24SPaolo Abeni # used for 'add_addr' subflow 2127c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 212834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 212934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 213034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 213134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2132b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2133c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2134be613160SGeliang Tang chk_add_nr 1 1 2135ae7bd9ccSMatthieu Baerts fi 2136b08fbf24SPaolo Abeni 21379d97114fSMatthieu Baerts (NGI0) # uncommon: subflow and signal flags on the same endpoint 21389d97114fSMatthieu Baerts (NGI0) # or because the user wrongly picked both, but still expects the client 21399d97114fSMatthieu Baerts (NGI0) # to create additional subflows 21409d97114fSMatthieu Baerts (NGI0) if reset "subflow and signal together"; then 21419d97114fSMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 2 21429d97114fSMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 0 2 21439d97114fSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 flags signal,subflow 21449d97114fSMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 21459d97114fSMatthieu Baerts (NGI0) chk_join_nr 1 1 1 21469d97114fSMatthieu Baerts (NGI0) chk_add_nr 1 1 0 invert # only initiated by ns2 21479d97114fSMatthieu Baerts (NGI0) chk_add_nr 0 0 0 # none initiated by ns1 21489d97114fSMatthieu Baerts (NGI0) chk_rst_nr 0 0 invert # no RST sent by the client 21499d97114fSMatthieu Baerts (NGI0) chk_rst_nr 0 0 # no RST sent by the server 21509d97114fSMatthieu Baerts (NGI0) fi 21519d97114fSMatthieu Baerts (NGI0) 2152b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 2153c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 215434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 215534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 215634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 215734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 215834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2159b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2160c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2161be613160SGeliang Tang chk_add_nr 1 1 2162ae7bd9ccSMatthieu Baerts fi 2163ef360019SGeliang Tang 2164ef360019SGeliang Tang # signal addresses 2165c7d49c03SMatthieu Baerts if reset "signal addresses"; then 216634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 216734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 216834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 216934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 217034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2171ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2172c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2173ef360019SGeliang Tang chk_add_nr 3 3 2174ae7bd9ccSMatthieu Baerts fi 2175ef360019SGeliang Tang 2176ef360019SGeliang Tang # signal invalid addresses 2177c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 217834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 217934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 218034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 218134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 218234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2183ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2184c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2185ef360019SGeliang Tang chk_add_nr 3 3 2186ae7bd9ccSMatthieu Baerts fi 218733c563adSYonglong Li 218833c563adSYonglong Li # signal addresses race test 2189c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 219034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 219134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 219234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 219334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 219434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 219534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 219634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 219734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 219834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 219934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 22006ef84b15SPaolo Abeni 22016ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 22026ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2203e571fb09SGeliang Tang speed=slow \ 2204e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 220586e39e04SPaolo Abeni 2206d4c81bbbSMatthieu Baerts # It is not directly linked to the commit introducing this 2207d4c81bbbSMatthieu Baerts # symbol but for the parent one which is linked anyway. 2208d4c81bbbSMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 2209d4c81bbbSMatthieu Baerts chk_join_nr 3 3 2 2210d4c81bbbSMatthieu Baerts chk_add_nr 4 4 2211d4c81bbbSMatthieu Baerts else 2212d4c81bbbSMatthieu Baerts chk_join_nr 3 3 3 221386e39e04SPaolo Abeni # the server will not signal the address terminating 221486e39e04SPaolo Abeni # the MPC subflow 221586e39e04SPaolo Abeni chk_add_nr 3 3 2216ae7bd9ccSMatthieu Baerts fi 2217d4c81bbbSMatthieu Baerts fi 22181002b89fSGeliang Tang} 2219b08fbf24SPaolo Abeni 22201002b89fSGeliang Tanglink_failure_tests() 22211002b89fSGeliang Tang{ 22228b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2223c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 22247d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 22257d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 22267d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 22277d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 22287d1e6f16SPaolo Abeni # active backup and link switch-over. 22297d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 22307d1e6f16SPaolo Abeni init_shapers 223134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 223234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 223334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 223434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 223534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 22360c93af1fSGeliang Tang test_linkfail=1 \ 22370c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2238c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22398b819a84SFlorian Westphal chk_add_nr 1 1 22407d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2241ae7bd9ccSMatthieu Baerts fi 22427d1e6f16SPaolo Abeni 22437d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 22447d1e6f16SPaolo Abeni # for bidirectional transfer 2245c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 22467d1e6f16SPaolo Abeni init_shapers 224734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 224834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 224934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 225034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 225134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 22520c93af1fSGeliang Tang test_linkfail=2 \ 22530c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2254c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22557d1e6f16SPaolo Abeni chk_add_nr 1 1 22567d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2257ae7bd9ccSMatthieu Baerts fi 22587d1e6f16SPaolo Abeni 22597d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 22607d1e6f16SPaolo Abeni # will never be used 2261c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 22627d1e6f16SPaolo Abeni init_shapers 226334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 226434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 226534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 226634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22670c93af1fSGeliang Tang FAILING_LINKS="1" test_linkfail=1 \ 22680c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2269c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22707d1e6f16SPaolo Abeni chk_add_nr 1 1 22717d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2272ae7bd9ccSMatthieu Baerts fi 22737d1e6f16SPaolo Abeni 22747d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 22757d1e6f16SPaolo Abeni # the traffic 2276c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 22777d1e6f16SPaolo Abeni init_shapers 227834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 227934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 228034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 228134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22820c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=1 \ 22830c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2284c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22857d1e6f16SPaolo Abeni chk_add_nr 1 1 22867d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 22877d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2288ae7bd9ccSMatthieu Baerts fi 22897d1e6f16SPaolo Abeni 22907d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 22917d1e6f16SPaolo Abeni # for bidirectional transfer 2292c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 22937d1e6f16SPaolo Abeni init_shapers 229434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 229534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 229634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 229734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22980c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=2 \ 22990c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2300c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23017d1e6f16SPaolo Abeni chk_add_nr 1 1 23027d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 23037d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2304ae7bd9ccSMatthieu Baerts fi 23051002b89fSGeliang Tang} 23068b819a84SFlorian Westphal 23071002b89fSGeliang Tangadd_addr_timeout_tests() 23081002b89fSGeliang Tang{ 23098d014eaaSGeliang Tang # add_addr timeout 2310c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 231134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 231234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 231334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2314e571fb09SGeliang Tang speed=slow \ 2315e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2316c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23170639fa23SPaolo Abeni chk_add_tx_nr 4 4 23188d014eaaSGeliang Tang chk_add_nr 4 0 2319ae7bd9ccSMatthieu Baerts fi 23208d014eaaSGeliang Tang 23211002b89fSGeliang Tang # add_addr timeout IPv6 2322c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 232334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 232434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 232534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2326e571fb09SGeliang Tang speed=slow \ 2327e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2328c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23291002b89fSGeliang Tang chk_add_nr 4 0 2330ae7bd9ccSMatthieu Baerts fi 23318da6229bSGeliang Tang 23328da6229bSGeliang Tang # signal addresses timeout 2333c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 233434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 233534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 233634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 233734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2338e571fb09SGeliang Tang speed=10 \ 2339e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2340c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23418da6229bSGeliang Tang chk_add_nr 8 0 2342ae7bd9ccSMatthieu Baerts fi 23438da6229bSGeliang Tang 23448da6229bSGeliang Tang # signal invalid addresses timeout 2345c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 234634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 234734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 234834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 234934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2350e571fb09SGeliang Tang speed=10 \ 2351e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2352c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23538da6229bSGeliang Tang chk_add_nr 8 0 2354ae7bd9ccSMatthieu Baerts fi 23551002b89fSGeliang Tang} 23561002b89fSGeliang Tang 23571002b89fSGeliang Tangremove_tests() 23581002b89fSGeliang Tang{ 2359dd72b0feSGeliang Tang # single subflow, remove 2360c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 236134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 236234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 236334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2364e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 2365e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2366c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23670639fa23SPaolo Abeni chk_rm_tx_nr 1 2368dd72b0feSGeliang Tang chk_rm_nr 1 1 23692cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2370ae7bd9ccSMatthieu Baerts fi 2371dd72b0feSGeliang Tang 2372dd72b0feSGeliang Tang # multiple subflows, remove 2373c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 237434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 237534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 237634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 237734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2378e571fb09SGeliang Tang addr_nr_ns2=-2 speed=slow \ 2379e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2380c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2381dd72b0feSGeliang Tang chk_rm_nr 2 2 23822cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2383ae7bd9ccSMatthieu Baerts fi 2384dd72b0feSGeliang Tang 2385dd72b0feSGeliang Tang # single address, remove 2386c7d49c03SMatthieu Baerts if reset "remove single address"; then 238734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 238834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 238934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2390e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2391e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2392c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2393dd72b0feSGeliang Tang chk_add_nr 1 1 23947028ba8aSGeliang Tang chk_rm_nr 1 1 invert 23952cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2396ae7bd9ccSMatthieu Baerts fi 2397dd72b0feSGeliang Tang 2398dd72b0feSGeliang Tang # subflow and signal, remove 2399c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 240034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 240134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 240234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 240334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2404e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2405e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2406c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2407dd72b0feSGeliang Tang chk_add_nr 1 1 2408dd72b0feSGeliang Tang chk_rm_nr 1 1 24092cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2410ae7bd9ccSMatthieu Baerts fi 2411dd72b0feSGeliang Tang 2412dd72b0feSGeliang Tang # subflows and signal, remove 2413c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 241434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 241534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 241634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 241734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 241834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2419e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \ 2420e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2421c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2422dd72b0feSGeliang Tang chk_add_nr 1 1 2423dd72b0feSGeliang Tang chk_rm_nr 2 2 24242cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2425ae7bd9ccSMatthieu Baerts fi 2426dd72b0feSGeliang Tang 2427ef360019SGeliang Tang # addresses remove 2428c7d49c03SMatthieu Baerts if reset "remove addresses"; then 242934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 243034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 243134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 243234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 243334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2434e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2435e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2436c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2437ef360019SGeliang Tang chk_add_nr 3 3 2438ef360019SGeliang Tang chk_rm_nr 3 3 invert 24392cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2440ae7bd9ccSMatthieu Baerts fi 2441ef360019SGeliang Tang 2442ef360019SGeliang Tang # invalid addresses remove 2443c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 244434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 244534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 244609469a08SYonglongLi # broadcast IP: no packet for this address will be received on ns1 244709469a08SYonglongLi pm_nl_add_endpoint $ns1 224.0.0.1 flags signal 2448dbf0787cSYonglongLi pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2449dbf0787cSYonglongLi pm_nl_set_limits $ns2 2 2 2450e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2451e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2452c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2453ef360019SGeliang Tang chk_add_nr 3 3 2454ef360019SGeliang Tang chk_rm_nr 3 1 invert 24552cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2456ae7bd9ccSMatthieu Baerts fi 2457ef360019SGeliang Tang 24586fe4ccdcSGeliang Tang # subflows and signal, flush 2459c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 246034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 246134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 246234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 246334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 246434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2465e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2466e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2467c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 24686fe4ccdcSGeliang Tang chk_add_nr 1 1 24696fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 24702cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2471ae7bd9ccSMatthieu Baerts fi 2472d2c4333aSGeliang Tang 2473d2c4333aSGeliang Tang # subflows flush 2474c7d49c03SMatthieu Baerts if reset "flush subflows"; then 247534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 247634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 247734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 247834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 247934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2480e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2481e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2482c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2483425ba803SMatthieu Baerts 2484425ba803SMatthieu Baerts if mptcp_lib_kversion_ge 5.18; then 24850639fa23SPaolo Abeni chk_rm_tx_nr 0 24866fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2487425ba803SMatthieu Baerts else 2488425ba803SMatthieu Baerts chk_rm_nr 3 3 2489425ba803SMatthieu Baerts fi 24902cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2491ae7bd9ccSMatthieu Baerts fi 2492d2c4333aSGeliang Tang 2493d2c4333aSGeliang Tang # addresses flush 2494c7d49c03SMatthieu Baerts if reset "flush addresses"; then 249534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 249634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 249734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 249834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 249934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2500e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2501e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2502c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2503d2c4333aSGeliang Tang chk_add_nr 3 3 25046fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 25052cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2506ae7bd9ccSMatthieu Baerts fi 2507ef360019SGeliang Tang 2508ef360019SGeliang Tang # invalid addresses flush 2509c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 251034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 251134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 251234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 251334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 251434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2515e571fb09SGeliang Tang addr_nr_ns1=-8 speed=slow \ 2516e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2517c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2518ef360019SGeliang Tang chk_add_nr 3 3 2519ef360019SGeliang Tang chk_rm_nr 3 1 invert 25202cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2521ae7bd9ccSMatthieu Baerts fi 25225e287fe7SGeliang Tang 25235e287fe7SGeliang Tang # remove id 0 subflow 2524c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 252534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 252634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 252734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2528e571fb09SGeliang Tang addr_nr_ns2=-9 speed=slow \ 2529e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2530c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25315e287fe7SGeliang Tang chk_rm_nr 1 1 25322cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2533ae7bd9ccSMatthieu Baerts fi 25345e287fe7SGeliang Tang 25355e287fe7SGeliang Tang # remove id 0 address 2536c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 253734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 253834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 253934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2540e571fb09SGeliang Tang addr_nr_ns1=-9 speed=slow \ 2541e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2542c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25435e287fe7SGeliang Tang chk_add_nr 1 1 25445e287fe7SGeliang Tang chk_rm_nr 1 1 invert 25452cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 invert 2546ae7bd9ccSMatthieu Baerts fi 25471002b89fSGeliang Tang} 25486fe4ccdcSGeliang Tang 25491002b89fSGeliang Tangadd_tests() 25501002b89fSGeliang Tang{ 25516208fd82SGeliang Tang # add single subflow 2552c7d49c03SMatthieu Baerts if reset "add single subflow"; then 255334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 255434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2555e571fb09SGeliang Tang addr_nr_ns2=1 speed=slow \ 2556e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2557c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2558ae7bd9ccSMatthieu Baerts fi 25596208fd82SGeliang Tang 25606208fd82SGeliang Tang # add signal address 2561c7d49c03SMatthieu Baerts if reset "add signal address"; then 256234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 256334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2564e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 2565e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2566c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25676208fd82SGeliang Tang chk_add_nr 1 1 2568ae7bd9ccSMatthieu Baerts fi 25696208fd82SGeliang Tang 25706208fd82SGeliang Tang # add multiple subflows 2571c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 257234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 257334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2574e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2575e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2576c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2577ae7bd9ccSMatthieu Baerts fi 25786208fd82SGeliang Tang 25796208fd82SGeliang Tang # add multiple subflows IPv6 2580c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 258134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 258234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2583e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2584e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2585c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2586ae7bd9ccSMatthieu Baerts fi 25876208fd82SGeliang Tang 25886208fd82SGeliang Tang # add multiple addresses IPv6 2589c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 259034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 259134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2592e571fb09SGeliang Tang addr_nr_ns1=2 speed=slow \ 2593e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2594c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 25956208fd82SGeliang Tang chk_add_nr 2 2 2596ae7bd9ccSMatthieu Baerts fi 25971002b89fSGeliang Tang} 25986208fd82SGeliang Tang 25991002b89fSGeliang Tangipv6_tests() 26001002b89fSGeliang Tang{ 2601523514edSGeliang Tang # subflow IPv6 2602c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 260334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 260434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 260534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2606e571fb09SGeliang Tang speed=slow \ 2607e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2608c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2609ae7bd9ccSMatthieu Baerts fi 2610523514edSGeliang Tang 2611523514edSGeliang Tang # add_address, unused IPv6 2612c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 261334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2614e571fb09SGeliang Tang speed=slow \ 2615e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2616c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2617523514edSGeliang Tang chk_add_nr 1 1 2618ae7bd9ccSMatthieu Baerts fi 2619523514edSGeliang Tang 2620523514edSGeliang Tang # signal address IPv6 2621c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 262234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 262334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 262434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2625e571fb09SGeliang Tang speed=slow \ 2626e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2627c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2628523514edSGeliang Tang chk_add_nr 1 1 2629ae7bd9ccSMatthieu Baerts fi 2630523514edSGeliang Tang 2631523514edSGeliang Tang # single address IPv6, remove 2632c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 263334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 263434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 263534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2636e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2637e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2638c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2639523514edSGeliang Tang chk_add_nr 1 1 26407028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2641ae7bd9ccSMatthieu Baerts fi 2642523514edSGeliang Tang 2643523514edSGeliang Tang # subflow and signal IPv6, remove 2644c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 264534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 264634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 264734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 264834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2649e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2650e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2651c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2652523514edSGeliang Tang chk_add_nr 1 1 2653523514edSGeliang Tang chk_rm_nr 1 1 2654ae7bd9ccSMatthieu Baerts fi 26551002b89fSGeliang Tang} 2656523514edSGeliang Tang 26571002b89fSGeliang Tangv4mapped_tests() 26581002b89fSGeliang Tang{ 2659a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2660c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 266134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 266234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 266334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2664a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2665c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2666ae7bd9ccSMatthieu Baerts fi 2667a6094788SGeliang Tang 2668a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2669c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 267034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 267134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 267234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2673a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2674c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2675a6094788SGeliang Tang chk_add_nr 1 1 2676ae7bd9ccSMatthieu Baerts fi 2677a6094788SGeliang Tang 2678a6094788SGeliang Tang # subflow v4-map-v6 2679c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 268034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 268134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 268234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2683a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2684c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2685ae7bd9ccSMatthieu Baerts fi 2686a6094788SGeliang Tang 2687a6094788SGeliang Tang # signal address v4-map-v6 2688c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 268934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 269034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 269134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2692a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2693c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2694a6094788SGeliang Tang chk_add_nr 1 1 2695ae7bd9ccSMatthieu Baerts fi 2696a6094788SGeliang Tang 2697a6094788SGeliang Tang # subflow v6-map-v4 2698c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 269934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 270034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 270134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2702a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2703c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2704ae7bd9ccSMatthieu Baerts fi 2705a6094788SGeliang Tang 2706a6094788SGeliang Tang # signal address v6-map-v4 2707c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 270834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 270934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 271034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2711a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2712c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2713a6094788SGeliang Tang chk_add_nr 1 1 2714ae7bd9ccSMatthieu Baerts fi 2715a6094788SGeliang Tang 2716a6094788SGeliang Tang # no subflow IPv6 to v4 address 2717c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 271834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 271934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 272034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2721a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2722c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2723ae7bd9ccSMatthieu Baerts fi 2724a6094788SGeliang Tang 2725a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2726c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 272734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 272834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 272934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2730a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2731c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2732ae7bd9ccSMatthieu Baerts fi 2733a6094788SGeliang Tang 2734a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2735c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 273634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 273734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 273834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2739a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2740c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2741ae7bd9ccSMatthieu Baerts fi 27421002b89fSGeliang Tang} 2743a6094788SGeliang Tang 2744ad349374SPaolo Abenimixed_tests() 2745ad349374SPaolo Abeni{ 27466673851bSMatthieu Baerts if reset "IPv4 sockets do not use IPv6 addresses" && 27476673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2748ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2749ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2750ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2751e571fb09SGeliang Tang speed=slow \ 2752e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2753ad349374SPaolo Abeni chk_join_nr 0 0 0 2754ad349374SPaolo Abeni fi 2755ad349374SPaolo Abeni 2756ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 27576673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows" && 27586673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2759ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2760ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2761ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2762e571fb09SGeliang Tang speed=slow \ 2763e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2764ad349374SPaolo Abeni chk_join_nr 1 1 1 2765ad349374SPaolo Abeni fi 2766ad349374SPaolo Abeni 2767ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 27686673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" && 27696673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2770ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2771ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2772ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2773ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2774e571fb09SGeliang Tang speed=slow \ 2775e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2776ad349374SPaolo Abeni chk_join_nr 1 1 1 2777ad349374SPaolo Abeni fi 2778ad349374SPaolo Abeni 2779ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2780ad349374SPaolo Abeni # matching family 27816673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" && 27826673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2783ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2784ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2785ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2786ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2787e571fb09SGeliang Tang fullmesh=1 speed=slow \ 2788e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2789ad349374SPaolo Abeni chk_join_nr 4 4 4 2790ad349374SPaolo Abeni fi 2791ad349374SPaolo Abeni} 2792ad349374SPaolo Abeni 27931002b89fSGeliang Tangbackup_tests() 27941002b89fSGeliang Tang{ 2795718eb44eSGeliang Tang # single subflow, backup 279607216a3cSMatthieu Baerts if reset "single subflow, backup" && 279707216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 279834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 279934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 280034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2801e571fb09SGeliang Tang sflags=nobackup speed=slow \ 2802e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2803c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28048213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 2805ae7bd9ccSMatthieu Baerts fi 2806718eb44eSGeliang Tang 2807718eb44eSGeliang Tang # single address, backup 280807216a3cSMatthieu Baerts if reset "single address, backup" && 280907216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 281034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 28116f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup 28126f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 1 1 28136f2b2180SMatthieu Baerts (NGI0) sflags=nobackup speed=slow \ 28146f2b2180SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 28156f2b2180SMatthieu Baerts (NGI0) chk_join_nr 1 1 1 28166f2b2180SMatthieu Baerts (NGI0) chk_add_nr 1 1 28176f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 0 0 1 28186f2b2180SMatthieu Baerts (NGI0) fi 28196f2b2180SMatthieu Baerts (NGI0) 28206f2b2180SMatthieu Baerts (NGI0) # single address, switch to backup 28216f2b2180SMatthieu Baerts (NGI0) if reset "single address, switch to backup" && 28226f2b2180SMatthieu Baerts (NGI0) continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 28236f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 1 282434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 282534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2826e571fb09SGeliang Tang sflags=backup speed=slow \ 2827e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2828c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2829718eb44eSGeliang Tang chk_add_nr 1 1 28308213b98eSMatthieu Baerts (NGI0) chk_prio_nr 1 1 0 0 2831ae7bd9ccSMatthieu Baerts fi 283233397b83SGeliang Tang 283333397b83SGeliang Tang # single address with port, backup 283407216a3cSMatthieu Baerts if reset "single address with port, backup" && 283507216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 283634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 28376f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal,backup port 10100 283834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 28396f2b2180SMatthieu Baerts (NGI0) sflags=nobackup speed=slow \ 2840e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2841c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 284233397b83SGeliang Tang chk_add_nr 1 1 28436f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 0 0 1 2844ae7bd9ccSMatthieu Baerts fi 2845914f6a59SPaolo Abeni 2846632978f0SMatthieu Baerts if reset "mpc backup" && 2847c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2848914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2849e571fb09SGeliang Tang speed=slow \ 2850e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2851914f6a59SPaolo Abeni chk_join_nr 0 0 0 28528213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 0 0 2853914f6a59SPaolo Abeni fi 2854914f6a59SPaolo Abeni 2855632978f0SMatthieu Baerts if reset "mpc backup both sides" && 2856c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 28576f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 2 28586f2b2180SMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 1 2 28596f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.1.1 flags signal,backup 2860914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 28616f2b2180SMatthieu Baerts (NGI0) 28626f2b2180SMatthieu Baerts (NGI0) # 10.0.2.2 (non-backup) -> 10.0.1.1 (backup) 28636f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 28646f2b2180SMatthieu Baerts (NGI0) # 10.0.1.2 (backup) -> 10.0.2.1 (non-backup) 28656f2b2180SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 28666f2b2180SMatthieu Baerts (NGI0) ip -net "$ns2" route add 10.0.2.1 via 10.0.1.1 dev ns2eth1 # force this path 28676f2b2180SMatthieu Baerts (NGI0) 2868e571fb09SGeliang Tang speed=slow \ 2869e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 28706f2b2180SMatthieu Baerts (NGI0) chk_join_nr 2 2 2 28716f2b2180SMatthieu Baerts (NGI0) chk_prio_nr 1 1 1 1 2872914f6a59SPaolo Abeni fi 2873914f6a59SPaolo Abeni 2874632978f0SMatthieu Baerts if reset "mpc switch to backup" && 2875c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2876914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2877e571fb09SGeliang Tang sflags=backup speed=slow \ 2878e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2879914f6a59SPaolo Abeni chk_join_nr 0 0 0 28808213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 0 0 2881914f6a59SPaolo Abeni fi 2882914f6a59SPaolo Abeni 2883632978f0SMatthieu Baerts if reset "mpc switch to backup both sides" && 2884c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2885914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2886914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2887e571fb09SGeliang Tang sflags=backup speed=slow \ 2888e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2889914f6a59SPaolo Abeni chk_join_nr 0 0 0 28908213b98eSMatthieu Baerts (NGI0) chk_prio_nr 1 1 0 0 2891914f6a59SPaolo Abeni fi 28921002b89fSGeliang Tang} 2893718eb44eSGeliang Tang 28949d71f43aSGeliang TangSUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED 2895178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2896178d0232SGeliang TangLISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2897178d0232SGeliang Tang 2898178d0232SGeliang TangAF_INET=2 2899178d0232SGeliang TangAF_INET6=10 2900178d0232SGeliang Tang 2901178d0232SGeliang Tangverify_listener_events() 2902178d0232SGeliang Tang{ 2903178d0232SGeliang Tang local evt=$1 2904178d0232SGeliang Tang local e_type=$2 2905178d0232SGeliang Tang local e_family=$3 2906178d0232SGeliang Tang local e_saddr=$4 2907178d0232SGeliang Tang local e_sport=$5 2908178d0232SGeliang Tang local type 2909178d0232SGeliang Tang local family 2910178d0232SGeliang Tang local saddr 2911178d0232SGeliang Tang local sport 291296b84195SMatthieu Baerts local name 2913178d0232SGeliang Tang 2914178d0232SGeliang Tang if [ $e_type = $LISTENER_CREATED ]; then 291596b84195SMatthieu Baerts name="LISTENER_CREATED" 2916178d0232SGeliang Tang elif [ $e_type = $LISTENER_CLOSED ]; then 291796b84195SMatthieu Baerts name="LISTENER_CLOSED " 291896b84195SMatthieu Baerts else 291996b84195SMatthieu Baerts name="$e_type" 2920178d0232SGeliang Tang fi 2921178d0232SGeliang Tang 292203668c65SMatthieu Baerts print_check "$name $e_saddr:$e_sport" 292396b84195SMatthieu Baerts 29240471bb47SMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 292503668c65SMatthieu Baerts print_skip "event not supported" 29260471bb47SMatthieu Baerts return 29270471bb47SMatthieu Baerts fi 29280471bb47SMatthieu Baerts 2929ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" "$e_type") 2930ae1fa39dSGeliang Tang family=$(mptcp_lib_evts_get_info family "$evt" "$e_type") 2931ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type") 2932178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 2933ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type") 2934178d0232SGeliang Tang else 2935ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type") 2936178d0232SGeliang Tang fi 2937178d0232SGeliang Tang 2938178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2939178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2940178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2941178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 294203668c65SMatthieu Baerts print_ok 2943178d0232SGeliang Tang return 0 2944178d0232SGeliang Tang fi 294503668c65SMatthieu Baerts fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" 2946178d0232SGeliang Tang} 2947178d0232SGeliang Tang 29481002b89fSGeliang Tangadd_addr_ports_tests() 29491002b89fSGeliang Tang{ 29508a127bf6SGeliang Tang # signal address with port 2951c7d49c03SMatthieu Baerts if reset "signal address with port"; then 295234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 295334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 295434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 29558a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2956c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29578a127bf6SGeliang Tang chk_add_nr 1 1 1 2958ae7bd9ccSMatthieu Baerts fi 29598a127bf6SGeliang Tang 29608a127bf6SGeliang Tang # subflow and signal with port 2961c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 296234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 296334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 296434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 296534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29668a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2967c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29688a127bf6SGeliang Tang chk_add_nr 1 1 1 2969ae7bd9ccSMatthieu Baerts fi 29708a127bf6SGeliang Tang 29718a127bf6SGeliang Tang # single address with port, remove 2972178d0232SGeliang Tang # pm listener events 2973178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 297434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 297534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 297634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2977e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2978e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2979c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29808a127bf6SGeliang Tang chk_add_nr 1 1 1 29817028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2982178d0232SGeliang Tang 2983178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2984178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2985178d0232SGeliang Tang kill_events_pids 2986ae7bd9ccSMatthieu Baerts fi 29878a127bf6SGeliang Tang 29888a127bf6SGeliang Tang # subflow and signal with port, remove 2989c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 299034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 299134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 299234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 299334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2994e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2995e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2996c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29978a127bf6SGeliang Tang chk_add_nr 1 1 1 29988a127bf6SGeliang Tang chk_rm_nr 1 1 2999ae7bd9ccSMatthieu Baerts fi 30008a127bf6SGeliang Tang 30018a127bf6SGeliang Tang # subflows and signal with port, flush 3002c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 300334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 300434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 300534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 300634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 300734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 3008e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \ 3009e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3010c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 30118a127bf6SGeliang Tang chk_add_nr 1 1 30126fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 3013ae7bd9ccSMatthieu Baerts fi 30148a127bf6SGeliang Tang 30158a127bf6SGeliang Tang # multiple addresses with port 3016c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 301734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 301834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 301934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 302034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 30218a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3022c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30238a127bf6SGeliang Tang chk_add_nr 2 2 2 3024ae7bd9ccSMatthieu Baerts fi 30258a127bf6SGeliang Tang 30268a127bf6SGeliang Tang # multiple addresses with ports 3027c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 302834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 302934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 303034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 303134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 30328a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3033c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30348a127bf6SGeliang Tang chk_add_nr 2 2 2 3035ae7bd9ccSMatthieu Baerts fi 30361002b89fSGeliang Tang} 30378a127bf6SGeliang Tang 30381002b89fSGeliang Tangsyncookies_tests() 30391002b89fSGeliang Tang{ 304000587187SFlorian Westphal # single subflow, syncookies 3041c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 304234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 304334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 304434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 304500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3046c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3047ae7bd9ccSMatthieu Baerts fi 304800587187SFlorian Westphal 304900587187SFlorian Westphal # multiple subflows with syn cookies 3050c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 305134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 305234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 305334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 305434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 305500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3056c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3057ae7bd9ccSMatthieu Baerts fi 305800587187SFlorian Westphal 305900587187SFlorian Westphal # multiple subflows limited by server 3060c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 306134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 306234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 306334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 306434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 306500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3066c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 3067ae7bd9ccSMatthieu Baerts fi 306800587187SFlorian Westphal 306900587187SFlorian Westphal # test signal address with cookies 3070c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 307134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 307234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 307334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 307400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3075c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3076be613160SGeliang Tang chk_add_nr 1 1 3077ae7bd9ccSMatthieu Baerts fi 307800587187SFlorian Westphal 307900587187SFlorian Westphal # test cookie with subflow and signal 3080c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 308134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 308234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 308334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 308434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 308500587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3086c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3087be613160SGeliang Tang chk_add_nr 1 1 3088ae7bd9ccSMatthieu Baerts fi 308900587187SFlorian Westphal 309000587187SFlorian Westphal # accept and use add_addr with additional subflows 3091c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 309234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 309334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 309434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 309534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 309634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 309700587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3098c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 3099be613160SGeliang Tang chk_add_nr 1 1 3100ae7bd9ccSMatthieu Baerts fi 31011002b89fSGeliang Tang} 31021002b89fSGeliang Tang 3103af66d3e1SGeliang Tangchecksum_tests() 3104af66d3e1SGeliang Tang{ 3105af66d3e1SGeliang Tang # checksum test 0 0 3106ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 310734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 310834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3109af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3110c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3111ae7bd9ccSMatthieu Baerts fi 3112af66d3e1SGeliang Tang 3113af66d3e1SGeliang Tang # checksum test 1 1 3114ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 311534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 311634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3117af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3118c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3119ae7bd9ccSMatthieu Baerts fi 3120af66d3e1SGeliang Tang 3121af66d3e1SGeliang Tang # checksum test 0 1 3122ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 312334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 312434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3125af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3126c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3127ae7bd9ccSMatthieu Baerts fi 3128af66d3e1SGeliang Tang 3129af66d3e1SGeliang Tang # checksum test 1 0 3130ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 313134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 313234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3133af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3134c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3135ae7bd9ccSMatthieu Baerts fi 3136af66d3e1SGeliang Tang} 3137af66d3e1SGeliang Tang 31380cddb4a6SGeliang Tangdeny_join_id0_tests() 31390cddb4a6SGeliang Tang{ 31400cddb4a6SGeliang Tang # subflow allow join id0 ns1 3141c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 314234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 314334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 314434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31450cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3146c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3147ae7bd9ccSMatthieu Baerts fi 31480cddb4a6SGeliang Tang 31490cddb4a6SGeliang Tang # subflow allow join id0 ns2 3150c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 315134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 315234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 315334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31540cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3155c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3156ae7bd9ccSMatthieu Baerts fi 31570cddb4a6SGeliang Tang 31580cddb4a6SGeliang Tang # signal address allow join id0 ns1 31590cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3160c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 316134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 316234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 316334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 31640cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3165c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 31660cddb4a6SGeliang Tang chk_add_nr 1 1 3167ae7bd9ccSMatthieu Baerts fi 31680cddb4a6SGeliang Tang 31690cddb4a6SGeliang Tang # signal address allow join id0 ns2 31700cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3171c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 317234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 317334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 317434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 31750cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3176c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 31770cddb4a6SGeliang Tang chk_add_nr 1 1 3178ae7bd9ccSMatthieu Baerts fi 31790cddb4a6SGeliang Tang 31800cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 3181c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 318234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 318334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 318434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 318534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31860cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3187c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3188ae7bd9ccSMatthieu Baerts fi 31890cddb4a6SGeliang Tang 31900cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 3191c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 319234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 319334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 319434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 319534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31960cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3197c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3198ae7bd9ccSMatthieu Baerts fi 31990cddb4a6SGeliang Tang} 32000cddb4a6SGeliang Tang 32014f49d633SGeliang Tangfullmesh_tests() 32024f49d633SGeliang Tang{ 32034f49d633SGeliang Tang # fullmesh 1 32044f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 32054f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 3206c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 320734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 320834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 320934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 321034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 3211e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 3212e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3213c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 32144f49d633SGeliang Tang chk_add_nr 1 1 3215ae7bd9ccSMatthieu Baerts fi 32164f49d633SGeliang Tang 32174f49d633SGeliang Tang # fullmesh 2 32184f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32194f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 3220c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 322134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 322234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 322334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3224f845af67SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,fullmesh 3225e571fb09SGeliang Tang fullmesh=1 speed=slow \ 3226e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3227c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 32284f49d633SGeliang Tang chk_add_nr 1 1 3229ae7bd9ccSMatthieu Baerts fi 32304f49d633SGeliang Tang 32314f49d633SGeliang Tang # fullmesh 3 32324f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32334f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 3234c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 323534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 323634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 323734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3238e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3239e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3240c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 32414f49d633SGeliang Tang chk_add_nr 1 1 3242ae7bd9ccSMatthieu Baerts fi 32434f49d633SGeliang Tang 32444f49d633SGeliang Tang # fullmesh 4 32454f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 32464f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 32474f49d633SGeliang Tang # limit max_subflows to 4. 3248c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 324934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 325034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 325134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3252e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3253e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3254c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 32554f49d633SGeliang Tang chk_add_nr 1 1 3256ae7bd9ccSMatthieu Baerts fi 32576a0653b9SGeliang Tang 32586a0653b9SGeliang Tang # set fullmesh flag 32599db34c42SMatthieu Baerts if reset "set fullmesh flag test" && 32609db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 326134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 326234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 326334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3264e571fb09SGeliang Tang addr_nr_ns2=1 sflags=fullmesh speed=slow \ 3265e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3266c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32676a0653b9SGeliang Tang chk_rm_nr 0 1 3268ae7bd9ccSMatthieu Baerts fi 32696a0653b9SGeliang Tang 32706a0653b9SGeliang Tang # set nofullmesh flag 32719db34c42SMatthieu Baerts if reset "set nofullmesh flag test" && 32729db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 327334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 327434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 327534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3276e571fb09SGeliang Tang fullmesh=1 sflags=nofullmesh speed=slow \ 3277e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3278c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32796a0653b9SGeliang Tang chk_rm_nr 0 1 3280ae7bd9ccSMatthieu Baerts fi 32816a0653b9SGeliang Tang 32826a0653b9SGeliang Tang # set backup,fullmesh flags 32839db34c42SMatthieu Baerts if reset "set backup,fullmesh flags test" && 32849db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 328534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 328634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 328734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3288e571fb09SGeliang Tang addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \ 3289e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3290c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32918213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 32926a0653b9SGeliang Tang chk_rm_nr 0 1 3293ae7bd9ccSMatthieu Baerts fi 32946a0653b9SGeliang Tang 32956a0653b9SGeliang Tang # set nobackup,nofullmesh flags 32969db34c42SMatthieu Baerts if reset "set nobackup,nofullmesh flags test" && 32979db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 329834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 329934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 330034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3301e571fb09SGeliang Tang sflags=nobackup,nofullmesh speed=slow \ 3302e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3303c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 33048213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 1 1 0 33056a0653b9SGeliang Tang chk_rm_nr 0 1 3306ae7bd9ccSMatthieu Baerts fi 33074f49d633SGeliang Tang} 33084f49d633SGeliang Tang 330901542c9bSGeliang Tangfastclose_tests() 331001542c9bSGeliang Tang{ 3311ae947bb2SMatthieu Baerts if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then 3312080b7f57SGeliang Tang test_linkfail=1024 fastclose=client \ 3313595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3314c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 331501542c9bSGeliang Tang chk_fclose_nr 1 1 331601542c9bSGeliang Tang chk_rst_nr 1 1 invert 3317ae7bd9ccSMatthieu Baerts fi 33186bf41020SPaolo Abeni 3319ae947bb2SMatthieu Baerts if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then 3320080b7f57SGeliang Tang test_linkfail=1024 fastclose=server \ 3321595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 332255dd3816SPaolo Abeni chk_join_nr 0 0 0 0 0 0 1 33236bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 33246bf41020SPaolo Abeni chk_rst_nr 1 1 33256bf41020SPaolo Abeni fi 332601542c9bSGeliang Tang} 332701542c9bSGeliang Tang 3328b6e074e1SGeliang Tangpedit_action_pkts() 3329b6e074e1SGeliang Tang{ 3330b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3331ae1fa39dSGeliang Tang mptcp_lib_get_info_value \"packets\" packets 3332b6e074e1SGeliang Tang} 3333b6e074e1SGeliang Tang 3334b6e074e1SGeliang Tangfail_tests() 3335b6e074e1SGeliang Tang{ 3336b6e074e1SGeliang Tang # single subflow 3337b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 3338562f8862SMatthieu Baerts (NGI0) MPTCP_LIB_SUBTEST_FLAKY=1 33390c93af1fSGeliang Tang test_linkfail=128 \ 33400c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3341b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 33421f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3343b6e074e1SGeliang Tang fi 33442ba18161SGeliang Tang 33452ba18161SGeliang Tang # multiple subflows 33462ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 3347562f8862SMatthieu Baerts (NGI0) MPTCP_LIB_SUBTEST_FLAKY=1 334899ac814eSGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5ms 33492ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 33502ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 33512ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 33520c93af1fSGeliang Tang test_linkfail=1024 \ 33530c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 33542ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 33552ba18161SGeliang Tang fi 3356b6e074e1SGeliang Tang} 3357b6e074e1SGeliang Tang 33589d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 33594369c198SGeliang Tanguserspace_pm_add_addr() 33604369c198SGeliang Tang{ 33619d71f43aSGeliang Tang local evts=$evts_ns1 33624369c198SGeliang Tang local tk 33634369c198SGeliang Tang 33649d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33659d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33669d71f43aSGeliang Tang 33679d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3 33684369c198SGeliang Tang sleep 1 33694369c198SGeliang Tang} 33704369c198SGeliang Tang 33719d71f43aSGeliang Tang# $1: ns ; $2: id 33729d71f43aSGeliang Tanguserspace_pm_rm_addr() 33734369c198SGeliang Tang{ 33749d71f43aSGeliang Tang local evts=$evts_ns1 33759d71f43aSGeliang Tang local tk 33769d71f43aSGeliang Tang local cnt 33774369c198SGeliang Tang 33789d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33799d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33809d71f43aSGeliang Tang 33819d71f43aSGeliang Tang cnt=$(rm_addr_count ${1}) 33829d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl rem token $tk id $2 33839d71f43aSGeliang Tang wait_rm_addr $1 "${cnt}" 33844369c198SGeliang Tang} 33854369c198SGeliang Tang 33869d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 33874369c198SGeliang Tanguserspace_pm_add_sf() 33884369c198SGeliang Tang{ 33899d71f43aSGeliang Tang local evts=$evts_ns1 33904369c198SGeliang Tang local tk da dp 33914369c198SGeliang Tang 33929d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33939d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33949d71f43aSGeliang Tang da=$(mptcp_lib_evts_get_info daddr4 "$evts") 33959d71f43aSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts") 33969d71f43aSGeliang Tang 33979d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \ 33984369c198SGeliang Tang rip $da rport $dp token $tk 33994369c198SGeliang Tang sleep 1 34004369c198SGeliang Tang} 34014369c198SGeliang Tang 34029d71f43aSGeliang Tang# $1: ns ; $2: addr $3: event type 34039d71f43aSGeliang Tanguserspace_pm_rm_sf() 34044369c198SGeliang Tang{ 34059d71f43aSGeliang Tang local evts=$evts_ns1 34069d71f43aSGeliang Tang local t=${3:-1} 3407ece1aaecSGeliang Tang local ip 34084369c198SGeliang Tang local tk da dp sp 34099d71f43aSGeliang Tang local cnt 34104369c198SGeliang Tang 34119d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 3412ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr4" "$evts" $t)" ] && ip=4 3413ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr6" "$evts" $t)" ] && ip=6 34149d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 3415ece1aaecSGeliang Tang da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t $2) 3416ece1aaecSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts" $t $2) 3417ece1aaecSGeliang Tang sp=$(mptcp_lib_evts_get_info sport "$evts" $t $2) 34189d71f43aSGeliang Tang 34199d71f43aSGeliang Tang cnt=$(rm_sf_count ${1}) 34209d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \ 34214369c198SGeliang Tang rip $da rport $dp token $tk 34229d71f43aSGeliang Tang wait_rm_sf $1 "${cnt}" 34234369c198SGeliang Tang} 34244369c198SGeliang Tang 34255ac1d2d6SMat Martineauuserspace_tests() 34265ac1d2d6SMat Martineau{ 34275ac1d2d6SMat Martineau # userspace pm type prevents add_addr 3428f2b492b0SMatthieu Baerts if reset "userspace pm type prevents add_addr" && 3429f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34305ac1d2d6SMat Martineau set_userspace_pm $ns1 34315ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 34325ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 34335ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 34345ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 34355ac1d2d6SMat Martineau chk_join_nr 0 0 0 34365ac1d2d6SMat Martineau chk_add_nr 0 0 34375ac1d2d6SMat Martineau fi 34385ac1d2d6SMat Martineau 3439b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3440f2b492b0SMatthieu Baerts if reset "userspace pm no echo w/o daemon" && 3441f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3442b3b71bf9SMat Martineau set_userspace_pm $ns2 3443b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3444b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3445b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3446b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3447b3b71bf9SMat Martineau chk_join_nr 0 0 0 3448b3b71bf9SMat Martineau chk_add_nr 1 0 3449b3b71bf9SMat Martineau fi 3450b3b71bf9SMat Martineau 34515ac1d2d6SMat Martineau # userspace pm type rejects join 3452f2b492b0SMatthieu Baerts if reset "userspace pm type rejects join" && 3453f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34545ac1d2d6SMat Martineau set_userspace_pm $ns1 34555ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 34565ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 34575ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 34585ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 34595ac1d2d6SMat Martineau chk_join_nr 1 1 0 34605ac1d2d6SMat Martineau fi 34615ac1d2d6SMat Martineau 34625ac1d2d6SMat Martineau # userspace pm type does not send join 3463f2b492b0SMatthieu Baerts if reset "userspace pm type does not send join" && 3464f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34655ac1d2d6SMat Martineau set_userspace_pm $ns2 34665ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 34675ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 34685ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 34695ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 34705ac1d2d6SMat Martineau chk_join_nr 0 0 0 34715ac1d2d6SMat Martineau fi 34725ac1d2d6SMat Martineau 34735ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 3474f2b492b0SMatthieu Baerts if reset "userspace pm type prevents mp_prio" && 3475f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34765ac1d2d6SMat Martineau set_userspace_pm $ns1 34775ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 34785ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 34795ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3480e571fb09SGeliang Tang sflags=backup speed=slow \ 3481e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 34825ac1d2d6SMat Martineau chk_join_nr 1 1 0 34838213b98eSMatthieu Baerts (NGI0) chk_prio_nr 0 0 0 0 34845ac1d2d6SMat Martineau fi 34855ac1d2d6SMat Martineau 34865ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 3487f2b492b0SMatthieu Baerts if reset "userspace pm type prevents rm_addr" && 3488f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34895ac1d2d6SMat Martineau set_userspace_pm $ns1 34905ac1d2d6SMat Martineau set_userspace_pm $ns2 34915ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 34925ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 34935ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3494e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 3495e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 34965ac1d2d6SMat Martineau chk_join_nr 0 0 0 34975ac1d2d6SMat Martineau chk_rm_nr 0 0 34985ac1d2d6SMat Martineau fi 349997040cf9SGeliang Tang 350097040cf9SGeliang Tang # userspace pm add & remove address 3501f2b492b0SMatthieu Baerts if reset_with_events "userspace pm add & remove address" && 3502f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 350397040cf9SGeliang Tang set_userspace_pm $ns1 3504ece1aaecSGeliang Tang pm_nl_set_limits $ns2 2 2 35051c6d07ddSGeliang Tang speed=5 \ 3506e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 35074369c198SGeliang Tang local tests_pid=$! 35084369c198SGeliang Tang wait_mpj $ns1 35099d71f43aSGeliang Tang userspace_pm_add_addr $ns1 10.0.2.1 10 3510ece1aaecSGeliang Tang userspace_pm_add_addr $ns1 10.0.3.1 20 3511ece1aaecSGeliang Tang chk_join_nr 2 2 2 3512ece1aaecSGeliang Tang chk_add_nr 2 2 3513ece1aaecSGeliang Tang chk_mptcp_info subflows 2 subflows 2 3514ece1aaecSGeliang Tang chk_subflows_total 3 3 3515ece1aaecSGeliang Tang chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 35169d71f43aSGeliang Tang userspace_pm_rm_addr $ns1 10 35179d71f43aSGeliang Tang userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED 3518ece1aaecSGeliang Tang userspace_pm_rm_addr $ns1 20 3519ece1aaecSGeliang Tang userspace_pm_rm_sf $ns1 10.0.3.1 $SUB_ESTABLISHED 3520ece1aaecSGeliang Tang chk_rm_nr 2 2 invert 3521d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3522f9190d79SGeliang Tang chk_subflows_total 1 1 3523a3735625SGeliang Tang kill_events_pids 3524a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 352597040cf9SGeliang Tang fi 35265e986ec4SGeliang Tang 35275e986ec4SGeliang Tang # userspace pm create destroy subflow 3528f2b492b0SMatthieu Baerts if reset_with_events "userspace pm create destroy subflow" && 3529f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 35305e986ec4SGeliang Tang set_userspace_pm $ns2 35315e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 35321c6d07ddSGeliang Tang speed=5 \ 3533e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 35344369c198SGeliang Tang local tests_pid=$! 35354369c198SGeliang Tang wait_mpj $ns2 35369d71f43aSGeliang Tang userspace_pm_add_sf $ns2 10.0.3.2 20 35375e986ec4SGeliang Tang chk_join_nr 1 1 1 3538d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3539f9190d79SGeliang Tang chk_subflows_total 2 2 35409d71f43aSGeliang Tang userspace_pm_rm_addr $ns2 20 35419d71f43aSGeliang Tang userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED 35426c160b63SGeliang Tang chk_rm_nr 1 1 3543d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3544f9190d79SGeliang Tang chk_subflows_total 1 1 3545a3735625SGeliang Tang kill_events_pids 3546a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 35475e986ec4SGeliang Tang fi 3548*05867195SGeliang Tang 3549*05867195SGeliang Tang # userspace pm create id 0 subflow 3550*05867195SGeliang Tang if reset_with_events "userspace pm create id 0 subflow" && 3551*05867195SGeliang Tang continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3552*05867195SGeliang Tang set_userspace_pm $ns2 3553*05867195SGeliang Tang pm_nl_set_limits $ns1 0 1 3554*05867195SGeliang Tang speed=5 \ 3555*05867195SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 3556*05867195SGeliang Tang local tests_pid=$! 3557*05867195SGeliang Tang wait_mpj $ns2 3558*05867195SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3559*05867195SGeliang Tang chk_subflows_total 1 1 3560*05867195SGeliang Tang userspace_pm_add_sf $ns2 10.0.3.2 0 3561*05867195SGeliang Tang chk_join_nr 1 1 1 3562*05867195SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3563*05867195SGeliang Tang chk_subflows_total 2 2 3564*05867195SGeliang Tang kill_events_pids 3565*05867195SGeliang Tang wait $tests_pid 3566*05867195SGeliang Tang fi 35675ac1d2d6SMat Martineau} 35685ac1d2d6SMat Martineau 3569e274f715SPaolo Abeniendpoint_tests() 357069c6ce7bSPaolo Abeni{ 357136c4127aSMatthieu Baerts # subflow_rebuild_header is needed to support the implicit flag 357269c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 357336c4127aSMatthieu Baerts if reset "implicit EP" && 357436c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 357569c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 357669c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 357769c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3578e571fb09SGeliang Tang speed=slow \ 3579358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3580358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 358169c6ce7bSPaolo Abeni 358269c6ce7bSPaolo Abeni wait_mpj $ns1 358303668c65SMatthieu Baerts pm_nl_check_endpoint "creation" \ 358469c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 3585d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3586d7ced753SGeliang Tang chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 358769c6ce7bSPaolo Abeni 35881dc88d24SMatthieu Baerts pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null 358903668c65SMatthieu Baerts pm_nl_check_endpoint "ID change is prevented" \ 359069c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 359169c6ce7bSPaolo Abeni 359269c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 359303668c65SMatthieu Baerts pm_nl_check_endpoint "modif is allowed" \ 359469c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3595358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3596ae7bd9ccSMatthieu Baerts fi 3597e274f715SPaolo Abeni 3598ce2f28a5SMatthieu Baerts (NGI0) if reset_with_tcp_filter "delete and re-add" ns2 10.0.3.2 REJECT OUTPUT && 359936c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3600a81c87acSMatthieu Baerts (NGI0) pm_nl_set_limits $ns1 0 3 3601a81c87acSMatthieu Baerts (NGI0) pm_nl_set_limits $ns2 0 3 3602a81c87acSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow 3603e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 360409c423d6SMatthieu Baerts (NGI0) test_linkfail=4 speed=5 \ 3605358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3606358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 3607e274f715SPaolo Abeni 3608e274f715SPaolo Abeni wait_mpj $ns2 3609117eed29SGeliang Tang pm_nl_check_endpoint "creation" \ 3610117eed29SGeliang Tang $ns2 10.0.2.2 id 2 flags subflow dev ns2eth2 3611a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "before delete id 2" 2 3612d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 36139095ce97SGeliang Tang 3614e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3615e274f715SPaolo Abeni sleep 0.5 3616a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "after delete id 2" 1 3617d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3618e274f715SPaolo Abeni 3619ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3620e274f715SPaolo Abeni wait_mpj $ns2 3621a81c87acSMatthieu Baerts (NGI0) chk_subflow_nr "after re-add id 2" 2 3622d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3623ce2f28a5SMatthieu Baerts (NGI0) 3624ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow 3625ce2f28a5SMatthieu Baerts (NGI0) wait_attempt_fail $ns2 3626ce2f28a5SMatthieu Baerts (NGI0) chk_subflow_nr "after new reject" 2 3627ce2f28a5SMatthieu Baerts (NGI0) chk_mptcp_info subflows 1 subflows 1 3628ce2f28a5SMatthieu Baerts (NGI0) 3629ce2f28a5SMatthieu Baerts (NGI0) ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT 3630ce2f28a5SMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns2 3 10.0.3.2 3631ce2f28a5SMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow 3632ce2f28a5SMatthieu Baerts (NGI0) wait_mpj $ns2 3633ce2f28a5SMatthieu Baerts (NGI0) chk_subflow_nr "after no reject" 3 3634ce2f28a5SMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 3635ce2f28a5SMatthieu Baerts (NGI0) 363609c423d6SMatthieu Baerts (NGI0) local i 363709c423d6SMatthieu Baerts (NGI0) for i in $(seq 3); do 3638a81c87acSMatthieu Baerts (NGI0) pm_nl_del_endpoint $ns2 1 10.0.1.2 3639a81c87acSMatthieu Baerts (NGI0) sleep 0.5 364009c423d6SMatthieu Baerts (NGI0) chk_subflow_nr "after delete id 0 ($i)" 2 3641a81c87acSMatthieu Baerts (NGI0) chk_mptcp_info subflows 2 subflows 2 # only decr for additional sf 3642a81c87acSMatthieu Baerts (NGI0) 3643a81c87acSMatthieu Baerts (NGI0) pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow 3644a81c87acSMatthieu Baerts (NGI0) wait_mpj $ns2 364509c423d6SMatthieu Baerts (NGI0) chk_subflow_nr "after re-add id 0 ($i)" 3 3646a81c87acSMatthieu Baerts (NGI0) chk_mptcp_info subflows 3 subflows 3 364709c423d6SMatthieu Baerts (NGI0) done 3648a81c87acSMatthieu Baerts (NGI0) 3649358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3650ce2f28a5SMatthieu Baerts (NGI0) 365109c423d6SMatthieu Baerts (NGI0) chk_join_nr 6 6 6 365209c423d6SMatthieu Baerts (NGI0) chk_rm_nr 4 4 3653e274f715SPaolo Abeni fi 365469c6ce7bSPaolo Abeni} 365569c6ce7bSPaolo Abeni 365622514d52SMatthieu Baerts# [$1: error message] 36571002b89fSGeliang Tangusage() 36581002b89fSGeliang Tang{ 365922514d52SMatthieu Baerts if [ -n "${1}" ]; then 366022514d52SMatthieu Baerts echo "${1}" 366122514d52SMatthieu Baerts ret=1 366222514d52SMatthieu Baerts fi 366322514d52SMatthieu Baerts 36641002b89fSGeliang Tang echo "mptcp_join usage:" 36653afd0280SMatthieu Baerts 36663afd0280SMatthieu Baerts local key 36673afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 36683afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 36693afd0280SMatthieu Baerts done 36703afd0280SMatthieu Baerts 3671a673321aSMat Martineau echo " -c capture pcap files" 3672af66d3e1SGeliang Tang echo " -C enable data checksum" 3673621bd393SGeliang Tang echo " -i use ip mptcp" 36741002b89fSGeliang Tang echo " -h help" 367522514d52SMatthieu Baerts 3676c7d49c03SMatthieu Baerts echo "[test ids|names]" 3677ae7bd9ccSMatthieu Baerts 367822514d52SMatthieu Baerts exit ${ret} 36791002b89fSGeliang Tang} 36801002b89fSGeliang Tang 3681a673321aSMat Martineau 36823afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 36833afd0280SMatthieu Baertsall_tests_sorted=( 36843afd0280SMatthieu Baerts f@subflows_tests 36853afd0280SMatthieu Baerts e@subflows_error_tests 36863afd0280SMatthieu Baerts s@signal_address_tests 36873afd0280SMatthieu Baerts l@link_failure_tests 36883afd0280SMatthieu Baerts t@add_addr_timeout_tests 36893afd0280SMatthieu Baerts r@remove_tests 36903afd0280SMatthieu Baerts a@add_tests 36913afd0280SMatthieu Baerts 6@ipv6_tests 36923afd0280SMatthieu Baerts 4@v4mapped_tests 3693ad349374SPaolo Abeni M@mixed_tests 36943afd0280SMatthieu Baerts b@backup_tests 36953afd0280SMatthieu Baerts p@add_addr_ports_tests 36963afd0280SMatthieu Baerts k@syncookies_tests 36973afd0280SMatthieu Baerts S@checksum_tests 36983afd0280SMatthieu Baerts d@deny_join_id0_tests 36993afd0280SMatthieu Baerts m@fullmesh_tests 37003afd0280SMatthieu Baerts z@fastclose_tests 3701b6e074e1SGeliang Tang F@fail_tests 37025ac1d2d6SMat Martineau u@userspace_tests 3703e274f715SPaolo Abeni I@endpoint_tests 37043afd0280SMatthieu Baerts) 37053afd0280SMatthieu Baerts 37063afd0280SMatthieu Baertsall_tests_args="" 37073afd0280SMatthieu Baertsall_tests_names=() 37083afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 37093afd0280SMatthieu Baerts key="${subtests%@*}" 37103afd0280SMatthieu Baerts value="${subtests#*@}" 37113afd0280SMatthieu Baerts 37123afd0280SMatthieu Baerts all_tests_args+="${key}" 37133afd0280SMatthieu Baerts all_tests_names+=("${value}") 37143afd0280SMatthieu Baerts all_tests[${key}]="${value}" 37153afd0280SMatthieu Baertsdone 37163afd0280SMatthieu Baerts 3717826d7bdcSMatthieu Baertstests=() 37183afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 37191002b89fSGeliang Tang case $opt in 37203afd0280SMatthieu Baerts ["${all_tests_args}"]) 37213afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 372269c6ce7bSPaolo Abeni ;; 3723a673321aSMat Martineau c) 3724826d7bdcSMatthieu Baerts capture=1 3725a673321aSMat Martineau ;; 3726af66d3e1SGeliang Tang C) 3727826d7bdcSMatthieu Baerts checksum=1 3728af66d3e1SGeliang Tang ;; 3729621bd393SGeliang Tang i) 3730826d7bdcSMatthieu Baerts ip_mptcp=1 3731621bd393SGeliang Tang ;; 373222514d52SMatthieu Baerts h) 37331002b89fSGeliang Tang usage 37341002b89fSGeliang Tang ;; 373522514d52SMatthieu Baerts *) 373622514d52SMatthieu Baerts usage "Unknown option: -${opt}" 373722514d52SMatthieu Baerts ;; 37381002b89fSGeliang Tang esac 37391002b89fSGeliang Tangdone 374000587187SFlorian Westphal 3741ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3742ae7bd9ccSMatthieu Baerts 3743ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3744ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3745c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3746ae7bd9ccSMatthieu Baerts else 3747c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3748ae7bd9ccSMatthieu Baerts fi 3749ae7bd9ccSMatthieu Baertsdone 3750ae7bd9ccSMatthieu Baerts 3751826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 37523afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 37533afd0280SMatthieu Baertsfi 37543afd0280SMatthieu Baerts 3755826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3756826d7bdcSMatthieu Baerts "${subtests}" 3757826d7bdcSMatthieu Baertsdone 3758826d7bdcSMatthieu Baerts 375939aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 376039aab882SMatthieu Baerts echo 376139aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 376239aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 376339aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 376439aab882SMatthieu Baerts done 376539aab882SMatthieu Baerts echo 376639aab882SMatthieu Baertsfi 376739aab882SMatthieu Baerts 37687f117cd3SMatthieu Baertsappend_prev_results 37697f117cd3SMatthieu Baertsmptcp_lib_result_print_all_tap 37707f117cd3SMatthieu Baerts 3771b08fbf24SPaolo Abeniexit $ret 3772