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 1367d1e6f16SPaolo Abeni tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 1377d1e6f16SPaolo Abeni tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 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}" 4844a0b866aSMatthieu Baerts 4854a0b866aSMatthieu Baerts if ! ip netns exec "${ns}" ${iptables} \ 4864a0b866aSMatthieu Baerts -A INPUT \ 4874a0b866aSMatthieu Baerts -s "${src}" \ 4884a0b866aSMatthieu Baerts -p tcp \ 4894a0b866aSMatthieu Baerts -j "${target}"; then 4904a0b866aSMatthieu Baerts mark_as_skipped "unable to set the filter rules" 4914a0b866aSMatthieu Baerts return 1 4924a0b866aSMatthieu Baerts fi 4934a0b866aSMatthieu Baerts} 4944a0b866aSMatthieu Baerts 49503668c65SMatthieu Baerts# $1: err msg 49639aab882SMatthieu Baertsfail_test() 49739aab882SMatthieu Baerts{ 49839aab882SMatthieu Baerts ret=1 499985de459SPaolo Abeni 50003668c65SMatthieu Baerts print_fail "${@}" 50103668c65SMatthieu Baerts 5027f117cd3SMatthieu Baerts # just in case a test is marked twice as failed 5037f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 0 ]; then 5047f117cd3SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 5057f117cd3SMatthieu Baerts dump_stats 5067f117cd3SMatthieu Baerts last_test_failed=1 5077f117cd3SMatthieu Baerts fi 50839aab882SMatthieu Baerts} 50939aab882SMatthieu Baerts 51039aab882SMatthieu Baertsget_failed_tests_ids() 51139aab882SMatthieu Baerts{ 51239aab882SMatthieu Baerts # sorted 51339aab882SMatthieu Baerts local i 51439aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 51539aab882SMatthieu Baerts echo "${i}" 51639aab882SMatthieu Baerts done | sort -n 51739aab882SMatthieu Baerts} 51839aab882SMatthieu Baerts 5198b819a84SFlorian Westphalprint_file_err() 5208b819a84SFlorian Westphal{ 5218b819a84SFlorian Westphal ls -l "$1" 1>&2 52203668c65SMatthieu Baerts echo -n "Trailing bytes are: " 5238b819a84SFlorian Westphal tail -c 27 "$1" 5248b819a84SFlorian Westphal} 5258b819a84SFlorian Westphal 526b08fbf24SPaolo Abenicheck_transfer() 527b08fbf24SPaolo Abeni{ 5281e777bd8SMatthieu Baerts local in=$1 5291e777bd8SMatthieu Baerts local out=$2 5301e777bd8SMatthieu Baerts local what=$3 5316bf41020SPaolo Abeni local bytes=$4 532d8d08302SMatthieu Baerts local i a b 533b08fbf24SPaolo Abeni 5341e777bd8SMatthieu Baerts local line 5356bf41020SPaolo Abeni if [ -n "$bytes" ]; then 5360fcd72dfSMatthieu Baerts local out_size 5376bf41020SPaolo Abeni # when truncating we must check the size explicitly 5380fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 5396bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 54003668c65SMatthieu Baerts fail_test "$what output file has wrong size ($out_size, $bytes)" 5416bf41020SPaolo Abeni return 1 5426bf41020SPaolo Abeni fi 543d328fe87SMatthieu Baerts 544d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 545d328fe87SMatthieu Baerts tmpfile=$(mktemp) 546d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 547d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 548d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 549d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 550d328fe87SMatthieu Baerts tmpfile="" 5516bf41020SPaolo Abeni fi 552d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 553d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 5548117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 55503668c65SMatthieu Baerts fail_test "$what does not match (in, out):" 556b08fbf24SPaolo Abeni print_file_err "$in" 557b08fbf24SPaolo Abeni print_file_err "$out" 558b08fbf24SPaolo Abeni 559b08fbf24SPaolo Abeni return 1 5608117dac3SGeliang Tang else 56103668c65SMatthieu Baerts print_info "$what has inverted byte at ${i}" 562b08fbf24SPaolo Abeni fi 5638117dac3SGeliang Tang done 564b08fbf24SPaolo Abeni 565b08fbf24SPaolo Abeni return 0 566b08fbf24SPaolo Abeni} 567b08fbf24SPaolo Abeni 568b08fbf24SPaolo Abenido_ping() 569b08fbf24SPaolo Abeni{ 5701e777bd8SMatthieu Baerts local listener_ns="$1" 5711e777bd8SMatthieu Baerts local connector_ns="$2" 5721e777bd8SMatthieu Baerts local connect_addr="$3" 573b08fbf24SPaolo Abeni 574d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 57503668c65SMatthieu Baerts fail_test "$listener_ns -> $connect_addr connectivity" 576b08fbf24SPaolo Abeni fi 577b08fbf24SPaolo Abeni} 578b08fbf24SPaolo Abeni 5798b819a84SFlorian Westphallink_failure() 5808b819a84SFlorian Westphal{ 5811e777bd8SMatthieu Baerts local ns="$1" 5828b819a84SFlorian Westphal 5837d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 5848b819a84SFlorian Westphal l=$((RANDOM%4)) 5857d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 5867d1e6f16SPaolo Abeni fi 5878b819a84SFlorian Westphal 5881e777bd8SMatthieu Baerts local l 5897d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 5901e777bd8SMatthieu Baerts local veth="ns1eth$l" 5918b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 5927d1e6f16SPaolo Abeni done 5938b819a84SFlorian Westphal} 5948b819a84SFlorian Westphal 595327b9a94SPaolo Abeni# $1: ns, $2: port 596327b9a94SPaolo Abeniwait_local_port_listen() 597327b9a94SPaolo Abeni{ 598327b9a94SPaolo Abeni local listener_ns="${1}" 599327b9a94SPaolo Abeni local port="${2}" 600327b9a94SPaolo Abeni 6011e777bd8SMatthieu Baerts local port_hex 602327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 6031e777bd8SMatthieu Baerts 6041e777bd8SMatthieu Baerts local i 605327b9a94SPaolo Abeni for i in $(seq 10); do 606327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 607327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 608327b9a94SPaolo Abeni break 609327b9a94SPaolo Abeni sleep 0.1 610327b9a94SPaolo Abeni done 611327b9a94SPaolo Abeni} 612327b9a94SPaolo Abeni 613327b9a94SPaolo Abenirm_addr_count() 614327b9a94SPaolo Abeni{ 615697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr" 616327b9a94SPaolo Abeni} 617327b9a94SPaolo Abeni 618327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 619327b9a94SPaolo Abeniwait_rm_addr() 620327b9a94SPaolo Abeni{ 621327b9a94SPaolo Abeni local ns="${1}" 622327b9a94SPaolo Abeni local old_cnt="${2}" 623327b9a94SPaolo Abeni local cnt 624327b9a94SPaolo Abeni 6251e777bd8SMatthieu Baerts local i 626327b9a94SPaolo Abeni for i in $(seq 10); do 627327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 628327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 629327b9a94SPaolo Abeni sleep 0.1 630327b9a94SPaolo Abeni done 631327b9a94SPaolo Abeni} 632327b9a94SPaolo Abeni 6334369c198SGeliang Tangrm_sf_count() 6344369c198SGeliang Tang{ 635697128a3SGeliang Tang mptcp_lib_get_counter "${1}" "MPTcpExtRmSubflow" 6364369c198SGeliang Tang} 6374369c198SGeliang Tang 6384369c198SGeliang Tang# $1: ns, $2: old rm_sf counter in $ns 6394369c198SGeliang Tangwait_rm_sf() 6404369c198SGeliang Tang{ 6414369c198SGeliang Tang local ns="${1}" 6424369c198SGeliang Tang local old_cnt="${2}" 6434369c198SGeliang Tang local cnt 6444369c198SGeliang Tang 6454369c198SGeliang Tang local i 6464369c198SGeliang Tang for i in $(seq 10); do 6474369c198SGeliang Tang cnt=$(rm_sf_count ${ns}) 6484369c198SGeliang Tang [ "$cnt" = "${old_cnt}" ] || break 6494369c198SGeliang Tang sleep 0.1 6504369c198SGeliang Tang done 6514369c198SGeliang Tang} 6524369c198SGeliang Tang 65369c6ce7bSPaolo Abeniwait_mpj() 65469c6ce7bSPaolo Abeni{ 65569c6ce7bSPaolo Abeni local ns="${1}" 65669c6ce7bSPaolo Abeni local cnt old_cnt 65769c6ce7bSPaolo Abeni 658697128a3SGeliang Tang old_cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 65969c6ce7bSPaolo Abeni 66069c6ce7bSPaolo Abeni local i 66169c6ce7bSPaolo Abeni for i in $(seq 10); do 662697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "MPTcpExtMPJoinAckRx") 66369c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 66469c6ce7bSPaolo Abeni sleep 0.1 66569c6ce7bSPaolo Abeni done 66669c6ce7bSPaolo Abeni} 66769c6ce7bSPaolo Abeni 668a3735625SGeliang Tangkill_events_pids() 669a3735625SGeliang Tang{ 6701fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns1_pid 6711fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns2_pid 672a3735625SGeliang Tang} 673a3735625SGeliang Tang 67434aa6e3bSGeliang Tangpm_nl_set_limits() 67534aa6e3bSGeliang Tang{ 67634aa6e3bSGeliang Tang local ns=$1 67734aa6e3bSGeliang Tang local addrs=$2 67834aa6e3bSGeliang Tang local subflows=$3 67934aa6e3bSGeliang Tang 68034aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 68134aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 68234aa6e3bSGeliang Tang else 68334aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 68434aa6e3bSGeliang Tang fi 68534aa6e3bSGeliang Tang} 68634aa6e3bSGeliang Tang 68734aa6e3bSGeliang Tangpm_nl_add_endpoint() 68834aa6e3bSGeliang Tang{ 68934aa6e3bSGeliang Tang local ns=$1 69034aa6e3bSGeliang Tang local addr=$2 6911e777bd8SMatthieu Baerts local flags _flags 6921e777bd8SMatthieu Baerts local port _port 6931e777bd8SMatthieu Baerts local dev _dev 6941e777bd8SMatthieu Baerts local id _id 69534aa6e3bSGeliang Tang local nr=2 69634aa6e3bSGeliang Tang 6971e777bd8SMatthieu Baerts local p 698d8d08302SMatthieu Baerts for p in "${@}" 69934aa6e3bSGeliang Tang do 70034aa6e3bSGeliang Tang if [ $p = "flags" ]; then 70134aa6e3bSGeliang Tang eval _flags=\$"$nr" 702d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 70334aa6e3bSGeliang Tang fi 70434aa6e3bSGeliang Tang if [ $p = "dev" ]; then 70534aa6e3bSGeliang Tang eval _dev=\$"$nr" 706d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 70734aa6e3bSGeliang Tang fi 70834aa6e3bSGeliang Tang if [ $p = "id" ]; then 70934aa6e3bSGeliang Tang eval _id=\$"$nr" 710d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 71134aa6e3bSGeliang Tang fi 71234aa6e3bSGeliang Tang if [ $p = "port" ]; then 71334aa6e3bSGeliang Tang eval _port=\$"$nr" 714d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 71534aa6e3bSGeliang Tang fi 71634aa6e3bSGeliang Tang 717d8d08302SMatthieu Baerts nr=$((nr + 1)) 71834aa6e3bSGeliang Tang done 71934aa6e3bSGeliang Tang 72034aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 72134aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 72234aa6e3bSGeliang Tang else 72334aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 72434aa6e3bSGeliang Tang fi 72534aa6e3bSGeliang Tang} 72634aa6e3bSGeliang Tang 72734aa6e3bSGeliang Tangpm_nl_del_endpoint() 72834aa6e3bSGeliang Tang{ 72934aa6e3bSGeliang Tang local ns=$1 73034aa6e3bSGeliang Tang local id=$2 73134aa6e3bSGeliang Tang local addr=$3 73234aa6e3bSGeliang Tang 73334aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 734aaf2123aSAndrea Claudi [ $id -ne 0 ] && addr='' 73534aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 73634aa6e3bSGeliang Tang else 73734aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 73834aa6e3bSGeliang Tang fi 73934aa6e3bSGeliang Tang} 74034aa6e3bSGeliang Tang 74134aa6e3bSGeliang Tangpm_nl_flush_endpoint() 74234aa6e3bSGeliang Tang{ 74334aa6e3bSGeliang Tang local ns=$1 74434aa6e3bSGeliang Tang 74534aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 74634aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 74734aa6e3bSGeliang Tang else 74834aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 74934aa6e3bSGeliang Tang fi 75034aa6e3bSGeliang Tang} 75134aa6e3bSGeliang Tang 752dda61b3dSGeliang Tangpm_nl_show_endpoints() 753dda61b3dSGeliang Tang{ 754dda61b3dSGeliang Tang local ns=$1 755dda61b3dSGeliang Tang 756dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 757dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 758dda61b3dSGeliang Tang else 759dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 760dda61b3dSGeliang Tang fi 761dda61b3dSGeliang Tang} 762dda61b3dSGeliang Tang 763f0140386SGeliang Tangpm_nl_change_endpoint() 764f0140386SGeliang Tang{ 765f0140386SGeliang Tang local ns=$1 766bccefb76SGeliang Tang local id=$2 767bccefb76SGeliang Tang local flags=$3 768f0140386SGeliang Tang 769f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 770f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 771f0140386SGeliang Tang else 772bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 773f0140386SGeliang Tang fi 774f0140386SGeliang Tang} 775f0140386SGeliang Tang 77669c6ce7bSPaolo Abenipm_nl_check_endpoint() 77769c6ce7bSPaolo Abeni{ 77869c6ce7bSPaolo Abeni local line expected_line 77903668c65SMatthieu Baerts local msg="$1" 78003668c65SMatthieu Baerts local ns=$2 78103668c65SMatthieu Baerts local addr=$3 78269c6ce7bSPaolo Abeni local _flags="" 78369c6ce7bSPaolo Abeni local flags 78469c6ce7bSPaolo Abeni local _port 78569c6ce7bSPaolo Abeni local port 78669c6ce7bSPaolo Abeni local dev 78769c6ce7bSPaolo Abeni local _id 78869c6ce7bSPaolo Abeni local id 78969c6ce7bSPaolo Abeni 79003668c65SMatthieu Baerts print_check "${msg}" 79169c6ce7bSPaolo Abeni 79203668c65SMatthieu Baerts shift 3 79369c6ce7bSPaolo Abeni while [ -n "$1" ]; do 79469c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 79569c6ce7bSPaolo Abeni _flags=$2 796d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 79769c6ce7bSPaolo Abeni shift 79869c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 799117eed29SGeliang Tang [ -n "$2" ]; dev="dev $2" 80069c6ce7bSPaolo Abeni shift 80169c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 80269c6ce7bSPaolo Abeni _id=$2 803d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 80469c6ce7bSPaolo Abeni shift 80569c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 80669c6ce7bSPaolo Abeni _port=$2 807d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 80869c6ce7bSPaolo Abeni shift 80969c6ce7bSPaolo Abeni fi 81069c6ce7bSPaolo Abeni 81169c6ce7bSPaolo Abeni shift 81269c6ce7bSPaolo Abeni done 81369c6ce7bSPaolo Abeni 81469c6ce7bSPaolo Abeni if [ -z "$id" ]; then 81503668c65SMatthieu Baerts test_fail "bad test - missing endpoint id" 81669c6ce7bSPaolo Abeni return 81769c6ce7bSPaolo Abeni fi 81869c6ce7bSPaolo Abeni 81969c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 820c8c101aeSAndrea Claudi # get line and trim trailing whitespace 82169c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 822c8c101aeSAndrea Claudi line="${line% }" 82369c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 824c8c101aeSAndrea Claudi [ -n "$addr" ] && expected_line="$addr" 82569c6ce7bSPaolo Abeni expected_line="$expected_line $id" 82669c6ce7bSPaolo Abeni [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" 82769c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 82869c6ce7bSPaolo Abeni [ -n "$port" ] && expected_line="$expected_line $port" 82969c6ce7bSPaolo Abeni else 83069c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 83169c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 83269c6ce7bSPaolo Abeni expected_line="$id" 83369c6ce7bSPaolo Abeni [ -n "$flags" ] && expected_line="$expected_line $flags" 83469c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 83569c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 83669c6ce7bSPaolo Abeni [ -n "$_port" ] && expected_line="$expected_line $_port" 83769c6ce7bSPaolo Abeni fi 83869c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 83903668c65SMatthieu Baerts print_ok 84069c6ce7bSPaolo Abeni else 84103668c65SMatthieu Baerts fail_test "expected '$expected_line' found '$line'" 84269c6ce7bSPaolo Abeni fi 84369c6ce7bSPaolo Abeni} 84469c6ce7bSPaolo Abeni 8459e9d176dSGeliang Tangpm_nl_set_endpoint() 846b08fbf24SPaolo Abeni{ 8471e777bd8SMatthieu Baerts local listener_ns="$1" 8481e777bd8SMatthieu Baerts local connector_ns="$2" 8499e9d176dSGeliang Tang local connect_addr="$3" 850b08fbf24SPaolo Abeni 851662aa22dSGeliang Tang local addr_nr_ns1=${addr_nr_ns1:-0} 852662aa22dSGeliang Tang local addr_nr_ns2=${addr_nr_ns2:-0} 853662aa22dSGeliang Tang local sflags=${sflags:-""} 8544aadde08SGeliang Tang local fullmesh=${fullmesh:-""} 855662aa22dSGeliang Tang 856080b7f57SGeliang Tang local flags="subflow" 8574aadde08SGeliang Tang if [ -n "${fullmesh}" ]; then 858080b7f57SGeliang Tang flags="${flags},fullmesh" 8594aadde08SGeliang Tang addr_nr_ns2=${fullmesh} 860080b7f57SGeliang Tang fi 861080b7f57SGeliang Tang 862327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 863327b9a94SPaolo Abeni # do endpoint manipulation 864d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 865d8d08302SMatthieu Baerts sleep 1 866d8d08302SMatthieu Baerts fi 867327b9a94SPaolo Abeni 8686208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8691e777bd8SMatthieu Baerts local counter=2 870d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 87197040cf9SGeliang Tang local id=10 8726208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8736208fd82SGeliang Tang local addr 8748e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 8756208fd82SGeliang Tang addr="dead:beef:$counter::1" 8766208fd82SGeliang Tang else 8776208fd82SGeliang Tang addr="10.0.$counter.1" 8786208fd82SGeliang Tang fi 87934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 880d8d08302SMatthieu Baerts counter=$((counter + 1)) 881d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 88297040cf9SGeliang Tang id=$((id + 1)) 8836208fd82SGeliang Tang done 8846208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 885d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 8866fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 8871e777bd8SMatthieu Baerts local counter=0 8881e777bd8SMatthieu Baerts local line 889d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 890d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 891dda61b3dSGeliang Tang local arr=($line) 892dda61b3dSGeliang Tang local nr=0 893dda61b3dSGeliang Tang 8941e777bd8SMatthieu Baerts local i 895d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 896dda61b3dSGeliang Tang if [ $i = "id" ]; then 897dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 898dda61b3dSGeliang Tang break 899dda61b3dSGeliang Tang fi 900dda61b3dSGeliang Tang id=${arr[$nr+1]} 901327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 90234aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 903327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 904d8d08302SMatthieu Baerts counter=$((counter + 1)) 905f87744adSGeliang Tang fi 906d8d08302SMatthieu Baerts nr=$((nr + 1)) 907dda61b3dSGeliang Tang done 908dda61b3dSGeliang Tang done 9095e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 91034aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9115e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 91234aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9136fe4ccdcSGeliang Tang fi 914dd72b0feSGeliang Tang fi 915dd72b0feSGeliang Tang 916327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 917327b9a94SPaolo Abeni # some time to created them 918d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 919327b9a94SPaolo Abeni 9206208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 921d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9221e777bd8SMatthieu Baerts local counter=3 9235e986ec4SGeliang Tang local id=20 9246208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9256208fd82SGeliang Tang local addr 9268e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9276208fd82SGeliang Tang addr="dead:beef:$counter::2" 9286208fd82SGeliang Tang else 9296208fd82SGeliang Tang addr="10.0.$counter.2" 9306208fd82SGeliang Tang fi 93134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 932d8d08302SMatthieu Baerts counter=$((counter + 1)) 933d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9345e986ec4SGeliang Tang id=$((id + 1)) 9356208fd82SGeliang Tang done 9366208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 937d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9386fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9391e777bd8SMatthieu Baerts local counter=0 9401e777bd8SMatthieu Baerts local line 941d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 942d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 943dda61b3dSGeliang Tang local arr=($line) 944dda61b3dSGeliang Tang local nr=0 945dda61b3dSGeliang Tang 9461e777bd8SMatthieu Baerts local i 947d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 948dda61b3dSGeliang Tang if [ $i = "id" ]; then 949dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 950dda61b3dSGeliang Tang break 951dda61b3dSGeliang Tang fi 9521e777bd8SMatthieu Baerts local id rm_addr 953dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 954dda61b3dSGeliang Tang # complete 955dda61b3dSGeliang Tang id=${arr[$nr+1]} 956327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 95734aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 958327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 959d8d08302SMatthieu Baerts counter=$((counter + 1)) 960f87744adSGeliang Tang fi 961d8d08302SMatthieu Baerts nr=$((nr + 1)) 962dda61b3dSGeliang Tang done 963dda61b3dSGeliang Tang done 9645e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 96534aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9665e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9675e287fe7SGeliang Tang local addr 9688e7f31bfSGeliang Tang if mptcp_lib_is_v6 "${connect_addr}"; then 9695e287fe7SGeliang Tang addr="dead:beef:1::2" 9705e287fe7SGeliang Tang else 9715e287fe7SGeliang Tang addr="10.0.1.2" 9725e287fe7SGeliang Tang fi 97334aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9746fe4ccdcSGeliang Tang fi 975dd72b0feSGeliang Tang fi 976dd72b0feSGeliang Tang 977d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 978718eb44eSGeliang Tang sleep 1 9791e777bd8SMatthieu Baerts 9801e777bd8SMatthieu Baerts local netns 981718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9821e777bd8SMatthieu Baerts local line 983d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 984d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 98533397b83SGeliang Tang local arr=($line) 986bccefb76SGeliang Tang local nr=0 987f0140386SGeliang Tang local id 98833397b83SGeliang Tang 9891e777bd8SMatthieu Baerts local i 990d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 991bccefb76SGeliang Tang if [ $i = "id" ]; then 992bccefb76SGeliang Tang id=${arr[$nr+1]} 993718eb44eSGeliang Tang fi 994d8d08302SMatthieu Baerts nr=$((nr + 1)) 99533397b83SGeliang Tang done 996bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 99733397b83SGeliang Tang done 998718eb44eSGeliang Tang done 999718eb44eSGeliang Tang fi 10009e9d176dSGeliang Tang} 10019e9d176dSGeliang Tang 10029e9d176dSGeliang Tangdo_transfer() 10039e9d176dSGeliang Tang{ 10049e9d176dSGeliang Tang local listener_ns="$1" 10059e9d176dSGeliang Tang local connector_ns="$2" 10069e9d176dSGeliang Tang local cl_proto="$3" 10079e9d176dSGeliang Tang local srv_proto="$4" 10089e9d176dSGeliang Tang local connect_addr="$5" 10099e9d176dSGeliang Tang 10109e9d176dSGeliang Tang local port=$((10000 + TEST_COUNT - 1)) 10119e9d176dSGeliang Tang local cappid 1012662aa22dSGeliang Tang local FAILING_LINKS=${FAILING_LINKS:-""} 1013080b7f57SGeliang Tang local fastclose=${fastclose:-""} 1014e571fb09SGeliang Tang local speed=${speed:-"fast"} 10159e9d176dSGeliang Tang 10169e9d176dSGeliang Tang :> "$cout" 10179e9d176dSGeliang Tang :> "$sout" 10189e9d176dSGeliang Tang :> "$capout" 10199e9d176dSGeliang Tang 10209e9d176dSGeliang Tang if [ $capture -eq 1 ]; then 10219e9d176dSGeliang Tang local capuser 10229e9d176dSGeliang Tang if [ -z $SUDO_USER ] ; then 10239e9d176dSGeliang Tang capuser="" 10249e9d176dSGeliang Tang else 10259e9d176dSGeliang Tang capuser="-Z $SUDO_USER" 10269e9d176dSGeliang Tang fi 10279e9d176dSGeliang Tang 10289e9d176dSGeliang Tang capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 10299e9d176dSGeliang Tang 10309e9d176dSGeliang Tang echo "Capturing traffic for test $TEST_COUNT into $capfile" 10319e9d176dSGeliang Tang ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 10329e9d176dSGeliang Tang cappid=$! 10339e9d176dSGeliang Tang 10349e9d176dSGeliang Tang sleep 1 10359e9d176dSGeliang Tang fi 10369e9d176dSGeliang Tang 10379e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 10389e9d176dSGeliang Tang nstat -n 10399e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 10409e9d176dSGeliang Tang nstat -n 10419e9d176dSGeliang Tang 10429e9d176dSGeliang Tang local extra_args 10439e9d176dSGeliang Tang if [ $speed = "fast" ]; then 10449e9d176dSGeliang Tang extra_args="-j" 10459e9d176dSGeliang Tang elif [ $speed = "slow" ]; then 10469e9d176dSGeliang Tang extra_args="-r 50" 1047e571fb09SGeliang Tang elif [ $speed -gt 0 ]; then 1048e571fb09SGeliang Tang extra_args="-r ${speed}" 10499e9d176dSGeliang Tang fi 10509e9d176dSGeliang Tang 10519e9d176dSGeliang Tang local extra_cl_args="" 10529e9d176dSGeliang Tang local extra_srv_args="" 10539e9d176dSGeliang Tang local trunc_size="" 1054080b7f57SGeliang Tang if [ -n "${fastclose}" ]; then 10559e9d176dSGeliang Tang if [ ${test_linkfail} -le 1 ]; then 105603668c65SMatthieu Baerts fail_test "fastclose tests need test_linkfail argument" 10579e9d176dSGeliang Tang return 1 10589e9d176dSGeliang Tang fi 10599e9d176dSGeliang Tang 10609e9d176dSGeliang Tang # disconnect 10619e9d176dSGeliang Tang trunc_size=${test_linkfail} 1062080b7f57SGeliang Tang local side=${fastclose} 10639e9d176dSGeliang Tang 10649e9d176dSGeliang Tang if [ ${side} = "client" ]; then 10659e9d176dSGeliang Tang extra_cl_args="-f ${test_linkfail}" 10669e9d176dSGeliang Tang extra_srv_args="-f -1" 10679e9d176dSGeliang Tang elif [ ${side} = "server" ]; then 10689e9d176dSGeliang Tang extra_srv_args="-f ${test_linkfail}" 10699e9d176dSGeliang Tang extra_cl_args="-f -1" 10709e9d176dSGeliang Tang else 107103668c65SMatthieu Baerts fail_test "wrong/unknown fastclose spec ${side}" 10729e9d176dSGeliang Tang return 1 10739e9d176dSGeliang Tang fi 10749e9d176dSGeliang Tang fi 10759e9d176dSGeliang Tang 10769e9d176dSGeliang Tang extra_srv_args="$extra_args $extra_srv_args" 10779e9d176dSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 10789e9d176dSGeliang Tang timeout ${timeout_test} \ 10799e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10809e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10819e9d176dSGeliang Tang $extra_srv_args "::" < "$sinfail" > "$sout" & 10829e9d176dSGeliang Tang else 10839e9d176dSGeliang Tang timeout ${timeout_test} \ 10849e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10859e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10869e9d176dSGeliang Tang $extra_srv_args "::" < "$sin" > "$sout" & 10879e9d176dSGeliang Tang fi 10889e9d176dSGeliang Tang local spid=$! 10899e9d176dSGeliang Tang 10909e9d176dSGeliang Tang wait_local_port_listen "${listener_ns}" "${port}" 10919e9d176dSGeliang Tang 10929e9d176dSGeliang Tang extra_cl_args="$extra_args $extra_cl_args" 10939e9d176dSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 10949e9d176dSGeliang Tang timeout ${timeout_test} \ 10959e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 10969e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 10979e9d176dSGeliang Tang $extra_cl_args $connect_addr < "$cin" > "$cout" & 10989e9d176dSGeliang Tang elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 10999e9d176dSGeliang Tang ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 11009e9d176dSGeliang Tang tee "$cinsent" | \ 11019e9d176dSGeliang Tang timeout ${timeout_test} \ 11029e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11039e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11049e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11059e9d176dSGeliang Tang else 11069e9d176dSGeliang Tang tee "$cinsent" < "$cinfail" | \ 11079e9d176dSGeliang Tang timeout ${timeout_test} \ 11089e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11099e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11109e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11119e9d176dSGeliang Tang fi 11129e9d176dSGeliang Tang local cpid=$! 11139e9d176dSGeliang Tang 11149e9d176dSGeliang Tang pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 1115718eb44eSGeliang Tang 1116b08fbf24SPaolo Abeni wait $cpid 11171e777bd8SMatthieu Baerts local retc=$? 1118b08fbf24SPaolo Abeni wait $spid 11191e777bd8SMatthieu Baerts local rets=$? 1120b08fbf24SPaolo Abeni 1121b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1122b08fbf24SPaolo Abeni sleep 1 1123b08fbf24SPaolo Abeni kill $cappid 1124b08fbf24SPaolo Abeni fi 1125b08fbf24SPaolo Abeni 1126c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1127c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1128c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1129c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1130c2a55e8fSMatthieu Baerts 1131b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 113203668c65SMatthieu Baerts fail_test "client exit code $retc, server $rets" 11338b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1134c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1135c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 11368b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1137c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1138c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1139b08fbf24SPaolo Abeni 1140b08fbf24SPaolo Abeni cat "$capout" 1141b08fbf24SPaolo Abeni return 1 1142b08fbf24SPaolo Abeni fi 1143b08fbf24SPaolo Abeni 11440c93af1fSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 11456bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 11467d1e6f16SPaolo Abeni else 11476bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 11487d1e6f16SPaolo Abeni fi 1149b08fbf24SPaolo Abeni retc=$? 11500c93af1fSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11516bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 11528b819a84SFlorian Westphal else 11536bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 11548b819a84SFlorian Westphal fi 1155b08fbf24SPaolo Abeni rets=$? 1156b08fbf24SPaolo Abeni 1157b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1158b08fbf24SPaolo Abeni cat "$capout" 1159b08fbf24SPaolo Abeni return 0 1160b08fbf24SPaolo Abeni fi 1161b08fbf24SPaolo Abeni 1162b08fbf24SPaolo Abeni cat "$capout" 1163b08fbf24SPaolo Abeni return 1 1164b08fbf24SPaolo Abeni} 1165b08fbf24SPaolo Abeni 1166b08fbf24SPaolo Abenimake_file() 1167b08fbf24SPaolo Abeni{ 11681e777bd8SMatthieu Baerts local name=$1 11691e777bd8SMatthieu Baerts local who=$2 11701e777bd8SMatthieu Baerts local size=$3 1171b08fbf24SPaolo Abeni 11728b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1173b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1174b08fbf24SPaolo Abeni 117503668c65SMatthieu Baerts print_info "Test file (size $size KB) for $who" 1176b08fbf24SPaolo Abeni} 1177b08fbf24SPaolo Abeni 1178b08fbf24SPaolo Abenirun_tests() 1179b08fbf24SPaolo Abeni{ 11801e777bd8SMatthieu Baerts local listener_ns="$1" 11811e777bd8SMatthieu Baerts local connector_ns="$2" 11821e777bd8SMatthieu Baerts local connect_addr="$3" 11831e777bd8SMatthieu Baerts 11841e777bd8SMatthieu Baerts local size 1185662aa22dSGeliang Tang local test_linkfail=${test_linkfail:-0} 11868b819a84SFlorian Westphal 118734b572b7SGeliang Tang # The values above 2 are reused to make test files 118834b572b7SGeliang Tang # with the given sizes (KB) 118934b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 119034b572b7SGeliang Tang size=$test_linkfail 119134b572b7SGeliang Tang 119234b572b7SGeliang Tang if [ -z "$cinfail" ]; then 119334b572b7SGeliang Tang cinfail=$(mktemp) 119434b572b7SGeliang Tang fi 119534b572b7SGeliang Tang make_file "$cinfail" "client" $size 11967d1e6f16SPaolo Abeni # create the input file for the failure test when 11977d1e6f16SPaolo Abeni # the first failure test run 1198d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 11997d1e6f16SPaolo Abeni # the client file must be considerably larger 12007d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 12017d1e6f16SPaolo Abeni # link utilization will be not predicable 12027d1e6f16SPaolo Abeni size=$((RANDOM%2)) 12038b819a84SFlorian Westphal size=$((size+1)) 12047d1e6f16SPaolo Abeni size=$((size*8192)) 1205d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 12068b819a84SFlorian Westphal 12077d1e6f16SPaolo Abeni cinfail=$(mktemp) 12087d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 12097d1e6f16SPaolo Abeni fi 12107d1e6f16SPaolo Abeni 121134b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 121234b572b7SGeliang Tang size=$test_linkfail 121334b572b7SGeliang Tang 121434b572b7SGeliang Tang if [ -z "$sinfail" ]; then 121534b572b7SGeliang Tang sinfail=$(mktemp) 121634b572b7SGeliang Tang fi 121734b572b7SGeliang Tang make_file "$sinfail" "server" $size 1218d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 12197d1e6f16SPaolo Abeni size=$((RANDOM%16)) 12207d1e6f16SPaolo Abeni size=$((size+1)) 12217d1e6f16SPaolo Abeni size=$((size*2048)) 12227d1e6f16SPaolo Abeni 12237d1e6f16SPaolo Abeni sinfail=$(mktemp) 12247d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 12258b819a84SFlorian Westphal fi 1226b08fbf24SPaolo Abeni 1227e571fb09SGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 1228b08fbf24SPaolo Abeni} 1229b08fbf24SPaolo Abeni 1230327b9a94SPaolo Abenidump_stats() 1231327b9a94SPaolo Abeni{ 1232327b9a94SPaolo Abeni echo Server ns stats 1233327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1234327b9a94SPaolo Abeni echo Client ns stats 1235327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1236327b9a94SPaolo Abeni} 1237327b9a94SPaolo Abeni 1238af66d3e1SGeliang Tangchk_csum_nr() 1239af66d3e1SGeliang Tang{ 12403c082695SGeliang Tang local csum_ns1=${1:-0} 12413c082695SGeliang Tang local csum_ns2=${2:-0} 1242af66d3e1SGeliang Tang local count 124353f368bfSGeliang Tang local extra_msg="" 124426516e10SGeliang Tang local allow_multi_errors_ns1=0 124526516e10SGeliang Tang local allow_multi_errors_ns2=0 124626516e10SGeliang Tang 124726516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 124826516e10SGeliang Tang allow_multi_errors_ns1=1 124926516e10SGeliang Tang csum_ns1=${csum_ns1:1} 125026516e10SGeliang Tang fi 125126516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 125226516e10SGeliang Tang allow_multi_errors_ns2=1 125326516e10SGeliang Tang csum_ns2=${csum_ns2:1} 125426516e10SGeliang Tang fi 1255af66d3e1SGeliang Tang 125603668c65SMatthieu Baerts print_check "sum" 1257697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr") 125853f368bfSGeliang Tang if [ "$count" != "$csum_ns1" ]; then 125953f368bfSGeliang Tang extra_msg="$extra_msg ns1=$count" 126053f368bfSGeliang Tang fi 126147867f0aSMatthieu Baerts if [ -z "$count" ]; then 126203668c65SMatthieu Baerts print_skip 126347867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1264d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 126503668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns1" 1266af66d3e1SGeliang Tang else 126703668c65SMatthieu Baerts print_ok 1268af66d3e1SGeliang Tang fi 126903668c65SMatthieu Baerts print_check "csum" 1270697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr") 127153f368bfSGeliang Tang if [ "$count" != "$csum_ns2" ]; then 127253f368bfSGeliang Tang extra_msg="$extra_msg ns2=$count" 127353f368bfSGeliang Tang fi 127447867f0aSMatthieu Baerts if [ -z "$count" ]; then 127503668c65SMatthieu Baerts print_skip 127647867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1277d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 127803668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns2" 1279af66d3e1SGeliang Tang else 128003668c65SMatthieu Baerts print_ok 1281af66d3e1SGeliang Tang fi 128253f368bfSGeliang Tang 128303668c65SMatthieu Baerts print_info "$extra_msg" 1284af66d3e1SGeliang Tang} 1285af66d3e1SGeliang Tang 12866bb3ab49SGeliang Tangchk_fail_nr() 12876bb3ab49SGeliang Tang{ 128826516e10SGeliang Tang local fail_tx=$1 128926516e10SGeliang Tang local fail_rx=$2 12901f7d325fSGeliang Tang local ns_invert=${3:-""} 12916bb3ab49SGeliang Tang local count 12921f7d325fSGeliang Tang local ns_tx=$ns1 12931f7d325fSGeliang Tang local ns_rx=$ns2 12941f7d325fSGeliang Tang local extra_msg="" 12951f7d325fSGeliang Tang local allow_tx_lost=0 12961f7d325fSGeliang Tang local allow_rx_lost=0 12971f7d325fSGeliang Tang 12981f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 12991f7d325fSGeliang Tang ns_tx=$ns2 13001f7d325fSGeliang Tang ns_rx=$ns1 13011f7d325fSGeliang Tang extra_msg="invert" 13021f7d325fSGeliang Tang fi 13031f7d325fSGeliang Tang 13041f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 13051f7d325fSGeliang Tang allow_tx_lost=1 13061f7d325fSGeliang Tang fail_tx=${fail_tx:1} 13071f7d325fSGeliang Tang fi 13081f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 13091f7d325fSGeliang Tang allow_rx_lost=1 13101f7d325fSGeliang Tang fail_rx=${fail_rx:1} 13111f7d325fSGeliang Tang fi 13126bb3ab49SGeliang Tang 131303668c65SMatthieu Baerts print_check "ftx" 1314697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx") 131526516e10SGeliang Tang if [ "$count" != "$fail_tx" ]; then 13161f7d325fSGeliang Tang extra_msg="$extra_msg,tx=$count" 13171f7d325fSGeliang Tang fi 131847867f0aSMatthieu Baerts if [ -z "$count" ]; then 131903668c65SMatthieu Baerts print_skip 132047867f0aSMatthieu Baerts elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 13211f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 132203668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] TX expected $fail_tx" 13236bb3ab49SGeliang Tang else 132403668c65SMatthieu Baerts print_ok 13256bb3ab49SGeliang Tang fi 13266bb3ab49SGeliang Tang 132703668c65SMatthieu Baerts print_check "failrx" 1328697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx") 132926516e10SGeliang Tang if [ "$count" != "$fail_rx" ]; then 13301f7d325fSGeliang Tang extra_msg="$extra_msg,rx=$count" 13311f7d325fSGeliang Tang fi 133247867f0aSMatthieu Baerts if [ -z "$count" ]; then 133303668c65SMatthieu Baerts print_skip 133447867f0aSMatthieu Baerts elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 13351f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 133603668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] RX expected $fail_rx" 13376bb3ab49SGeliang Tang else 133803668c65SMatthieu Baerts print_ok 13396bb3ab49SGeliang Tang fi 13406bb3ab49SGeliang Tang 134103668c65SMatthieu Baerts print_info "$extra_msg" 13426bb3ab49SGeliang Tang} 13436bb3ab49SGeliang Tang 1344e8e947efSGeliang Tangchk_fclose_nr() 1345e8e947efSGeliang Tang{ 1346e8e947efSGeliang Tang local fclose_tx=$1 1347e8e947efSGeliang Tang local fclose_rx=$2 13486bf41020SPaolo Abeni local ns_invert=$3 1349e8e947efSGeliang Tang local count 13506bf41020SPaolo Abeni local ns_tx=$ns2 13516bf41020SPaolo Abeni local ns_rx=$ns1 13526bf41020SPaolo Abeni local extra_msg="" 13536bf41020SPaolo Abeni 13546bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 13556bf41020SPaolo Abeni ns_tx=$ns1 13566bf41020SPaolo Abeni ns_rx=$ns2 135703668c65SMatthieu Baerts extra_msg="invert" 13586bf41020SPaolo Abeni fi 1359e8e947efSGeliang Tang 136003668c65SMatthieu Baerts print_check "ctx" 1361697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFastcloseTx") 136247867f0aSMatthieu Baerts if [ -z "$count" ]; then 136303668c65SMatthieu Baerts print_skip 136447867f0aSMatthieu Baerts elif [ "$count" != "$fclose_tx" ]; then 136547867f0aSMatthieu Baerts extra_msg="$extra_msg,tx=$count" 136603668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1367e8e947efSGeliang Tang else 136803668c65SMatthieu Baerts print_ok 1369e8e947efSGeliang Tang fi 1370e8e947efSGeliang Tang 137103668c65SMatthieu Baerts print_check "fclzrx" 1372697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFastcloseRx") 137347867f0aSMatthieu Baerts if [ -z "$count" ]; then 137403668c65SMatthieu Baerts print_skip 137547867f0aSMatthieu Baerts elif [ "$count" != "$fclose_rx" ]; then 137647867f0aSMatthieu Baerts extra_msg="$extra_msg,rx=$count" 137703668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1378e8e947efSGeliang Tang else 137903668c65SMatthieu Baerts print_ok 1380e8e947efSGeliang Tang fi 1381e8e947efSGeliang Tang 138203668c65SMatthieu Baerts print_info "$extra_msg" 1383e8e947efSGeliang Tang} 1384e8e947efSGeliang Tang 1385922fd2b3SGeliang Tangchk_rst_nr() 1386922fd2b3SGeliang Tang{ 1387922fd2b3SGeliang Tang local rst_tx=$1 1388922fd2b3SGeliang Tang local rst_rx=$2 1389922fd2b3SGeliang Tang local ns_invert=${3:-""} 1390922fd2b3SGeliang Tang local count 1391922fd2b3SGeliang Tang local ns_tx=$ns1 1392922fd2b3SGeliang Tang local ns_rx=$ns2 1393922fd2b3SGeliang Tang local extra_msg="" 1394922fd2b3SGeliang Tang 1395922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1396922fd2b3SGeliang Tang ns_tx=$ns2 1397922fd2b3SGeliang Tang ns_rx=$ns1 1398922fd2b3SGeliang Tang extra_msg="invert" 1399922fd2b3SGeliang Tang fi 1400922fd2b3SGeliang Tang 140103668c65SMatthieu Baerts print_check "rtx" 1402697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPRstTx") 140347867f0aSMatthieu Baerts if [ -z "$count" ]; then 140403668c65SMatthieu Baerts print_skip 1405b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1406b134a580SMatthieu Baerts elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } || 1407b134a580SMatthieu Baerts { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then 140803668c65SMatthieu Baerts fail_test "got $count MP_RST[s] TX expected $rst_tx" 1409922fd2b3SGeliang Tang else 141003668c65SMatthieu Baerts print_ok 1411922fd2b3SGeliang Tang fi 1412922fd2b3SGeliang Tang 141303668c65SMatthieu Baerts print_check "rstrx" 1414697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPRstRx") 141547867f0aSMatthieu Baerts if [ -z "$count" ]; then 141603668c65SMatthieu Baerts print_skip 1417b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1418b134a580SMatthieu Baerts elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } || 1419b134a580SMatthieu Baerts { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then 142003668c65SMatthieu Baerts fail_test "got $count MP_RST[s] RX expected $rst_rx" 1421922fd2b3SGeliang Tang else 142203668c65SMatthieu Baerts print_ok 1423922fd2b3SGeliang Tang fi 1424922fd2b3SGeliang Tang 142503668c65SMatthieu Baerts print_info "$extra_msg" 1426922fd2b3SGeliang Tang} 1427922fd2b3SGeliang Tang 14288bd03be3SGeliang Tangchk_infi_nr() 14298bd03be3SGeliang Tang{ 14308bd03be3SGeliang Tang local infi_tx=$1 14318bd03be3SGeliang Tang local infi_rx=$2 14328bd03be3SGeliang Tang local count 14338bd03be3SGeliang Tang 143403668c65SMatthieu Baerts print_check "itx" 1435697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtInfiniteMapTx") 143647867f0aSMatthieu Baerts if [ -z "$count" ]; then 143703668c65SMatthieu Baerts print_skip 143847867f0aSMatthieu Baerts elif [ "$count" != "$infi_tx" ]; then 143903668c65SMatthieu Baerts fail_test "got $count infinite map[s] TX expected $infi_tx" 14408bd03be3SGeliang Tang else 144103668c65SMatthieu Baerts print_ok 14428bd03be3SGeliang Tang fi 14438bd03be3SGeliang Tang 144403668c65SMatthieu Baerts print_check "infirx" 1445697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtInfiniteMapRx") 144647867f0aSMatthieu Baerts if [ -z "$count" ]; then 144703668c65SMatthieu Baerts print_skip 144847867f0aSMatthieu Baerts elif [ "$count" != "$infi_rx" ]; then 144903668c65SMatthieu Baerts fail_test "got $count infinite map[s] RX expected $infi_rx" 14508bd03be3SGeliang Tang else 145103668c65SMatthieu Baerts print_ok 14528bd03be3SGeliang Tang fi 14538bd03be3SGeliang Tang} 14548bd03be3SGeliang Tang 1455b08fbf24SPaolo Abenichk_join_nr() 1456b08fbf24SPaolo Abeni{ 1457c7d49c03SMatthieu Baerts local syn_nr=$1 1458c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1459c7d49c03SMatthieu Baerts local ack_nr=$3 1460c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1461c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1462c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1463c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 14648bd03be3SGeliang Tang local infi_nr=${8:-0} 14658bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1466b08fbf24SPaolo Abeni local count 1467e35f885bSPaolo Abeni local with_cookie 1468b08fbf24SPaolo Abeni 1469c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 147003668c65SMatthieu Baerts print_info "${corrupted_pkts} corrupted pkts" 1471c7d49c03SMatthieu Baerts fi 1472c7d49c03SMatthieu Baerts 147303668c65SMatthieu Baerts print_check "syn" 1474697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinSynRx") 147547867f0aSMatthieu Baerts if [ -z "$count" ]; then 147603668c65SMatthieu Baerts print_skip 147747867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 147803668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn expected $syn_nr" 1479b08fbf24SPaolo Abeni else 148003668c65SMatthieu Baerts print_ok 1481b08fbf24SPaolo Abeni fi 1482b08fbf24SPaolo Abeni 148303668c65SMatthieu Baerts print_check "synack" 14844bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 1485697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinSynAckRx") 148647867f0aSMatthieu Baerts if [ -z "$count" ]; then 148703668c65SMatthieu Baerts print_skip 148847867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 1489e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1490e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1491e35f885bSPaolo Abeni # the subflow creation 1492e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 149303668c65SMatthieu Baerts print_ok 1494e35f885bSPaolo Abeni else 149503668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack expected $syn_ack_nr" 1496e35f885bSPaolo Abeni fi 1497b08fbf24SPaolo Abeni else 149803668c65SMatthieu Baerts print_ok 1499b08fbf24SPaolo Abeni fi 1500b08fbf24SPaolo Abeni 150103668c65SMatthieu Baerts print_check "ack" 1502697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinAckRx") 150347867f0aSMatthieu Baerts if [ -z "$count" ]; then 150403668c65SMatthieu Baerts print_skip 150547867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 150603668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack expected $ack_nr" 1507b08fbf24SPaolo Abeni else 150803668c65SMatthieu Baerts print_ok 1509b08fbf24SPaolo Abeni fi 1510b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 15113c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 151226516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 151326516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 15148bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1515af66d3e1SGeliang Tang fi 1516b08fbf24SPaolo Abeni} 1517b08fbf24SPaolo Abeni 15187d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 15197d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 15207d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 15217d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 15227d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 15237d1e6f16SPaolo Abenichk_stale_nr() 15247d1e6f16SPaolo Abeni{ 15257d1e6f16SPaolo Abeni local ns=$1 15267d1e6f16SPaolo Abeni local stale_min=$2 15277d1e6f16SPaolo Abeni local stale_max=$3 15287d1e6f16SPaolo Abeni local stale_delta=$4 15297d1e6f16SPaolo Abeni local dump_stats 15307d1e6f16SPaolo Abeni local stale_nr 15317d1e6f16SPaolo Abeni local recover_nr 15327d1e6f16SPaolo Abeni 153303668c65SMatthieu Baerts print_check "stale" 15347d1e6f16SPaolo Abeni 1535697128a3SGeliang Tang stale_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowStale") 1536697128a3SGeliang Tang recover_nr=$(mptcp_lib_get_counter ${ns} "MPTcpExtSubflowRecover") 153747867f0aSMatthieu Baerts if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then 153803668c65SMatthieu Baerts print_skip 153947867f0aSMatthieu Baerts elif [ $stale_nr -lt $stale_min ] || 1540d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1541d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 154203668c65SMatthieu Baerts fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \ 15437d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 15447d1e6f16SPaolo Abeni " stale-recover delta $stale_delta" 15457d1e6f16SPaolo Abeni dump_stats=1 15467d1e6f16SPaolo Abeni else 154703668c65SMatthieu Baerts print_ok 15487d1e6f16SPaolo Abeni fi 15497d1e6f16SPaolo Abeni 15507d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 15517d1e6f16SPaolo Abeni echo $ns stats 15527d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 15537d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 15547d1e6f16SPaolo Abeni fi 15557d1e6f16SPaolo Abeni} 15567d1e6f16SPaolo Abeni 1557be613160SGeliang Tangchk_add_nr() 1558be613160SGeliang Tang{ 1559be613160SGeliang Tang local add_nr=$1 1560be613160SGeliang Tang local echo_nr=$2 15618a127bf6SGeliang Tang local port_nr=${3:-0} 15628a127bf6SGeliang Tang local syn_nr=${4:-$port_nr} 15638a127bf6SGeliang Tang local syn_ack_nr=${5:-$port_nr} 15648a127bf6SGeliang Tang local ack_nr=${6:-$port_nr} 15658a127bf6SGeliang Tang local mis_syn_nr=${7:-0} 15668a127bf6SGeliang Tang local mis_ack_nr=${8:-0} 1567be613160SGeliang Tang local count 15686ef84b15SPaolo Abeni local timeout 15696ef84b15SPaolo Abeni 15704bfadd71SMatthieu Baerts timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1571be613160SGeliang Tang 157203668c65SMatthieu Baerts print_check "add" 1573697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtAddAddr") 157447867f0aSMatthieu Baerts if [ -z "$count" ]; then 157503668c65SMatthieu Baerts print_skip 15766ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15776ef84b15SPaolo Abeni # add addrs options, due to retransmissions 157847867f0aSMatthieu Baerts elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 157903668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] expected $add_nr" 1580be613160SGeliang Tang else 158103668c65SMatthieu Baerts print_ok 1582be613160SGeliang Tang fi 1583be613160SGeliang Tang 158403668c65SMatthieu Baerts print_check "echo" 1585697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtEchoAdd") 158647867f0aSMatthieu Baerts if [ -z "$count" ]; then 158703668c65SMatthieu Baerts print_skip 158847867f0aSMatthieu Baerts elif [ "$count" != "$echo_nr" ]; then 158903668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] expected $echo_nr" 1590be613160SGeliang Tang else 159103668c65SMatthieu Baerts print_ok 15928a127bf6SGeliang Tang fi 15938a127bf6SGeliang Tang 15948a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 159503668c65SMatthieu Baerts print_check "pt" 1596697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtPortAdd") 159747867f0aSMatthieu Baerts if [ -z "$count" ]; then 159803668c65SMatthieu Baerts print_skip 159947867f0aSMatthieu Baerts elif [ "$count" != "$port_nr" ]; then 160003668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr" 16018a127bf6SGeliang Tang else 160203668c65SMatthieu Baerts print_ok 1603be613160SGeliang Tang fi 1604be613160SGeliang Tang 160503668c65SMatthieu Baerts print_check "syn" 1606697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortSynRx") 160747867f0aSMatthieu Baerts if [ -z "$count" ]; then 160803668c65SMatthieu Baerts print_skip 160947867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 161003668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a different \ 16118a127bf6SGeliang Tang port-number expected $syn_nr" 16128a127bf6SGeliang Tang else 161303668c65SMatthieu Baerts print_ok 16148a127bf6SGeliang Tang fi 16158a127bf6SGeliang Tang 161603668c65SMatthieu Baerts print_check "synack" 1617697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx") 161847867f0aSMatthieu Baerts if [ -z "$count" ]; then 161903668c65SMatthieu Baerts print_skip 162047867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 162103668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack with a different \ 16228a127bf6SGeliang Tang port-number expected $syn_ack_nr" 16238a127bf6SGeliang Tang else 162403668c65SMatthieu Baerts print_ok 16258a127bf6SGeliang Tang fi 16268a127bf6SGeliang Tang 162703668c65SMatthieu Baerts print_check "ack" 1628697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortAckRx") 162947867f0aSMatthieu Baerts if [ -z "$count" ]; then 163003668c65SMatthieu Baerts print_skip 163147867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 163203668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a different \ 16338a127bf6SGeliang Tang port-number expected $ack_nr" 16348a127bf6SGeliang Tang else 163503668c65SMatthieu Baerts print_ok 16368a127bf6SGeliang Tang fi 16378a127bf6SGeliang Tang 163803668c65SMatthieu Baerts print_check "syn" 1639697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortSynRx") 164047867f0aSMatthieu Baerts if [ -z "$count" ]; then 164103668c65SMatthieu Baerts print_skip 164247867f0aSMatthieu Baerts elif [ "$count" != "$mis_syn_nr" ]; then 164303668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a mismatched \ 16448a127bf6SGeliang Tang port-number expected $mis_syn_nr" 16458a127bf6SGeliang Tang else 164603668c65SMatthieu Baerts print_ok 16478a127bf6SGeliang Tang fi 16488a127bf6SGeliang Tang 164903668c65SMatthieu Baerts print_check "ack" 1650697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortAckRx") 165147867f0aSMatthieu Baerts if [ -z "$count" ]; then 165203668c65SMatthieu Baerts print_skip 165347867f0aSMatthieu Baerts elif [ "$count" != "$mis_ack_nr" ]; then 165403668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a mismatched \ 16558a127bf6SGeliang Tang port-number expected $mis_ack_nr" 16568a127bf6SGeliang Tang else 165703668c65SMatthieu Baerts print_ok 16588a127bf6SGeliang Tang fi 16598a127bf6SGeliang Tang fi 1660be613160SGeliang Tang} 1661be613160SGeliang Tang 16620639fa23SPaolo Abenichk_add_tx_nr() 16630639fa23SPaolo Abeni{ 16640639fa23SPaolo Abeni local add_tx_nr=$1 16650639fa23SPaolo Abeni local echo_tx_nr=$2 16660639fa23SPaolo Abeni local timeout 16670639fa23SPaolo Abeni local count 16680639fa23SPaolo Abeni 16690639fa23SPaolo Abeni timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 16700639fa23SPaolo Abeni 167103668c65SMatthieu Baerts print_check "add TX" 1672697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtAddAddrTx") 167300079f18SMatthieu Baerts if [ -z "$count" ]; then 167403668c65SMatthieu Baerts print_skip 16750639fa23SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 16760639fa23SPaolo Abeni # add addrs options, due to retransmissions 167700079f18SMatthieu Baerts elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 167803668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr" 16790639fa23SPaolo Abeni else 168003668c65SMatthieu Baerts print_ok 16810639fa23SPaolo Abeni fi 16820639fa23SPaolo Abeni 168303668c65SMatthieu Baerts print_check "echo TX" 1684697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtEchoAddTx") 168500079f18SMatthieu Baerts if [ -z "$count" ]; then 168603668c65SMatthieu Baerts print_skip 168700079f18SMatthieu Baerts elif [ "$count" != "$echo_tx_nr" ]; then 168803668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 16890639fa23SPaolo Abeni else 169003668c65SMatthieu Baerts print_ok 16910639fa23SPaolo Abeni fi 16920639fa23SPaolo Abeni} 16930639fa23SPaolo Abeni 1694dd72b0feSGeliang Tangchk_rm_nr() 1695dd72b0feSGeliang Tang{ 1696dd72b0feSGeliang Tang local rm_addr_nr=$1 1697dd72b0feSGeliang Tang local rm_subflow_nr=$2 16986fa0174aSPaolo Abeni local invert 16996fa0174aSPaolo Abeni local simult 1700dd72b0feSGeliang Tang local count 17017d9bf018SGeliang Tang local addr_ns=$ns1 17027d9bf018SGeliang Tang local subflow_ns=$ns2 17037d9bf018SGeliang Tang local extra_msg="" 17047028ba8aSGeliang Tang 17056fa0174aSPaolo Abeni shift 2 17066fa0174aSPaolo Abeni while [ -n "$1" ]; do 17076fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 17086fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 17096fa0174aSPaolo Abeni shift 17106fa0174aSPaolo Abeni done 17116fa0174aSPaolo Abeni 17126fa0174aSPaolo Abeni if [ -z $invert ]; then 17136fa0174aSPaolo Abeni addr_ns=$ns1 17146fa0174aSPaolo Abeni subflow_ns=$ns2 17156fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 17167028ba8aSGeliang Tang addr_ns=$ns2 17177028ba8aSGeliang Tang subflow_ns=$ns1 17187d9bf018SGeliang Tang extra_msg="invert" 17197028ba8aSGeliang Tang fi 1720dd72b0feSGeliang Tang 172103668c65SMatthieu Baerts print_check "rm" 1722697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmAddr") 172300079f18SMatthieu Baerts if [ -z "$count" ]; then 172403668c65SMatthieu Baerts print_skip 172500079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_nr" ]; then 172603668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_nr" 1727dd72b0feSGeliang Tang else 172803668c65SMatthieu Baerts print_ok 1729dd72b0feSGeliang Tang fi 1730dd72b0feSGeliang Tang 173103668c65SMatthieu Baerts print_check "rmsf" 1732697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${subflow_ns} "MPTcpExtRmSubflow") 173347867f0aSMatthieu Baerts if [ -z "$count" ]; then 173403668c65SMatthieu Baerts print_skip 173547867f0aSMatthieu Baerts elif [ -n "$simult" ]; then 1736d8d08302SMatthieu Baerts local cnt suffix 1737d8d08302SMatthieu Baerts 1738697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${addr_ns} "MPTcpExtRmSubflow") 17396fa0174aSPaolo Abeni 17406fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 17416fa0174aSPaolo Abeni # unreliable 17426fa0174aSPaolo Abeni count=$((count + cnt)) 1743*a445eb1fSGeliang Tang if [ "$count" != "$rm_subflow_nr" ]; then 1744*a445eb1fSGeliang Tang suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1745*a445eb1fSGeliang Tang extra_msg="$extra_msg simult" 1746*a445eb1fSGeliang Tang fi 17476fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 17486fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 174903668c65SMatthieu Baerts print_ok "$suffix" 17506fa0174aSPaolo Abeni else 175103668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 17526fa0174aSPaolo Abeni fi 175347867f0aSMatthieu Baerts elif [ "$count" != "$rm_subflow_nr" ]; then 175403668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1755dd72b0feSGeliang Tang else 175603668c65SMatthieu Baerts print_ok 1757dd72b0feSGeliang Tang fi 1758dd72b0feSGeliang Tang 175903668c65SMatthieu Baerts print_info "$extra_msg" 1760dd72b0feSGeliang Tang} 1761dd72b0feSGeliang Tang 17620639fa23SPaolo Abenichk_rm_tx_nr() 17630639fa23SPaolo Abeni{ 17640639fa23SPaolo Abeni local rm_addr_tx_nr=$1 17650639fa23SPaolo Abeni 176603668c65SMatthieu Baerts print_check "rm TX" 1767697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtRmAddrTx") 176800079f18SMatthieu Baerts if [ -z "$count" ]; then 176903668c65SMatthieu Baerts print_skip 177000079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_tx_nr" ]; then 177103668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr" 17720639fa23SPaolo Abeni else 177303668c65SMatthieu Baerts print_ok 17740639fa23SPaolo Abeni fi 17750639fa23SPaolo Abeni} 17760639fa23SPaolo Abeni 1777718eb44eSGeliang Tangchk_prio_nr() 1778718eb44eSGeliang Tang{ 1779718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1780718eb44eSGeliang Tang local mp_prio_nr_rx=$2 1781718eb44eSGeliang Tang local count 1782718eb44eSGeliang Tang 178303668c65SMatthieu Baerts print_check "ptx" 1784697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioTx") 178547867f0aSMatthieu Baerts if [ -z "$count" ]; then 178603668c65SMatthieu Baerts print_skip 178747867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_tx" ]; then 178803668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1789718eb44eSGeliang Tang else 179003668c65SMatthieu Baerts print_ok 1791718eb44eSGeliang Tang fi 1792718eb44eSGeliang Tang 179303668c65SMatthieu Baerts print_check "prx" 1794697128a3SGeliang Tang count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPPrioRx") 179547867f0aSMatthieu Baerts if [ -z "$count" ]; then 179603668c65SMatthieu Baerts print_skip 179747867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_rx" ]; then 179803668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1799718eb44eSGeliang Tang else 180003668c65SMatthieu Baerts print_ok 1801718eb44eSGeliang Tang fi 1802718eb44eSGeliang Tang} 1803718eb44eSGeliang Tang 1804e274f715SPaolo Abenichk_subflow_nr() 1805e274f715SPaolo Abeni{ 180603668c65SMatthieu Baerts local msg="$1" 180703668c65SMatthieu Baerts local subflow_nr=$2 1808e274f715SPaolo Abeni local cnt1 1809e274f715SPaolo Abeni local cnt2 1810a635a8c3SPaolo Abeni local dump_stats 1811e274f715SPaolo Abeni 181203668c65SMatthieu Baerts print_check "${msg}" 1813e274f715SPaolo Abeni 1814e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1815e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 18160fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 181703668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr" 1818e274f715SPaolo Abeni dump_stats=1 1819e274f715SPaolo Abeni else 182003668c65SMatthieu Baerts print_ok 1821e274f715SPaolo Abeni fi 1822e274f715SPaolo Abeni 1823a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1824a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1825a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1826a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1827a635a8c3SPaolo Abeni fi 1828e274f715SPaolo Abeni} 1829e274f715SPaolo Abeni 18309095ce97SGeliang Tangchk_mptcp_info() 18319095ce97SGeliang Tang{ 1832d7ced753SGeliang Tang local info1=$1 1833d7ced753SGeliang Tang local exp1=$2 1834d7ced753SGeliang Tang local info2=$3 1835d7ced753SGeliang Tang local exp2=$4 18369095ce97SGeliang Tang local cnt1 18379095ce97SGeliang Tang local cnt2 18389095ce97SGeliang Tang local dump_stats 18399095ce97SGeliang Tang 1840f9190d79SGeliang Tang print_check "mptcp_info ${info1:0:15}=$exp1:$exp2" 18419095ce97SGeliang Tang 1842ae1fa39dSGeliang Tang cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info1" "$info1") 1843ae1fa39dSGeliang Tang cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info2" "$info2") 1844d7ced753SGeliang Tang # 'ss' only display active connections and counters that are not 0. 18459095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 18469095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 1847d7ced753SGeliang Tang 1848d7ced753SGeliang Tang if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then 184903668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2" 18509095ce97SGeliang Tang dump_stats=1 18519095ce97SGeliang Tang else 185203668c65SMatthieu Baerts print_ok 18539095ce97SGeliang Tang fi 18549095ce97SGeliang Tang 18559095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 18569095ce97SGeliang Tang ss -N $ns1 -inmHM 18579095ce97SGeliang Tang ss -N $ns2 -inmHM 18589095ce97SGeliang Tang fi 18599095ce97SGeliang Tang} 18609095ce97SGeliang Tang 1861f9190d79SGeliang Tang# $1: subflows in ns1 ; $2: subflows in ns2 1862f9190d79SGeliang Tang# number of all subflows, including the initial subflow. 1863f9190d79SGeliang Tangchk_subflows_total() 1864f9190d79SGeliang Tang{ 1865f9190d79SGeliang Tang local cnt1 1866f9190d79SGeliang Tang local cnt2 1867f9190d79SGeliang Tang local info="subflows_total" 1868f9190d79SGeliang Tang local dump_stats 1869f9190d79SGeliang Tang 1870f9190d79SGeliang Tang # if subflows_total counter is supported, use it: 1871f9190d79SGeliang Tang if [ -n "$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value $info $info)" ]; then 1872f9190d79SGeliang Tang chk_mptcp_info $info $1 $info $2 1873f9190d79SGeliang Tang return 1874f9190d79SGeliang Tang fi 1875f9190d79SGeliang Tang 1876f9190d79SGeliang Tang print_check "$info $1:$2" 1877f9190d79SGeliang Tang 1878f9190d79SGeliang Tang # if not, count the TCP connections that are in fact MPTCP subflows 1879f9190d79SGeliang Tang cnt1=$(ss -N $ns1 -ti state established state syn-sent state syn-recv | 1880f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1881f9190d79SGeliang Tang cnt2=$(ss -N $ns2 -ti state established state syn-sent state syn-recv | 1882f9190d79SGeliang Tang grep -c tcp-ulp-mptcp) 1883f9190d79SGeliang Tang 1884f9190d79SGeliang Tang if [ "$1" != "$cnt1" ] || [ "$2" != "$cnt2" ]; then 1885f9190d79SGeliang Tang fail_test "got subflows $cnt1:$cnt2 expected $1:$2" 1886f9190d79SGeliang Tang dump_stats=1 1887f9190d79SGeliang Tang else 1888f9190d79SGeliang Tang print_ok 1889f9190d79SGeliang Tang fi 1890f9190d79SGeliang Tang 1891f9190d79SGeliang Tang if [ "$dump_stats" = 1 ]; then 1892f9190d79SGeliang Tang ss -N $ns1 -ti 1893f9190d79SGeliang Tang ss -N $ns2 -ti 1894f9190d79SGeliang Tang fi 1895f9190d79SGeliang Tang} 1896f9190d79SGeliang Tang 18977d1e6f16SPaolo Abenichk_link_usage() 18987d1e6f16SPaolo Abeni{ 18997d1e6f16SPaolo Abeni local ns=$1 19007d1e6f16SPaolo Abeni local link=$2 19017d1e6f16SPaolo Abeni local out=$3 19027d1e6f16SPaolo Abeni local expected_rate=$4 19034bfadd71SMatthieu Baerts 19044bfadd71SMatthieu Baerts local tx_link tx_total 19054bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1906d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1907d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 19087d1e6f16SPaolo Abeni local tolerance=5 19097d1e6f16SPaolo Abeni 191003668c65SMatthieu Baerts print_check "link usage" 1911d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1912d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 191303668c65SMatthieu Baerts fail_test "got $tx_rate% usage, expected $expected_rate%" 19147d1e6f16SPaolo Abeni else 191503668c65SMatthieu Baerts print_ok 19167d1e6f16SPaolo Abeni fi 19177d1e6f16SPaolo Abeni} 19187d1e6f16SPaolo Abeni 1919f98c2bcaSMat Martineauwait_attempt_fail() 192046e967d1SPaolo Abeni{ 192146e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 192246e967d1SPaolo Abeni local time=0 192346e967d1SPaolo Abeni local ns=$1 192446e967d1SPaolo Abeni 192546e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 19261e777bd8SMatthieu Baerts local cnt 19271e777bd8SMatthieu Baerts 1928697128a3SGeliang Tang cnt=$(mptcp_lib_get_counter ${ns} "TcpAttemptFails") 192946e967d1SPaolo Abeni 193046e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 193146e967d1SPaolo Abeni time=$((time + 100)) 193246e967d1SPaolo Abeni sleep 0.1 193346e967d1SPaolo Abeni done 193446e967d1SPaolo Abeni return 1 193546e967d1SPaolo Abeni} 193646e967d1SPaolo Abeni 19375ac1d2d6SMat Martineauset_userspace_pm() 19385ac1d2d6SMat Martineau{ 19395ac1d2d6SMat Martineau local ns=$1 19405ac1d2d6SMat Martineau 19415ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 19425ac1d2d6SMat Martineau} 19435ac1d2d6SMat Martineau 19441002b89fSGeliang Tangsubflows_tests() 19451002b89fSGeliang Tang{ 1946c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1947b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1948c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1949ae7bd9ccSMatthieu Baerts fi 1950b08fbf24SPaolo Abeni 19511002b89fSGeliang Tang # subflow limited by client 1952c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 195334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 195434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 195534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1956b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1957c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1958ae7bd9ccSMatthieu Baerts fi 1959b08fbf24SPaolo Abeni 19601002b89fSGeliang Tang # subflow limited by server 1961c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 196234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 196334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 196434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1965b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1966c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 1967ae7bd9ccSMatthieu Baerts fi 1968b08fbf24SPaolo Abeni 1969b08fbf24SPaolo Abeni # subflow 1970c7d49c03SMatthieu Baerts if reset "single subflow"; then 197134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 197234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 197334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1974b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1975c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1976ae7bd9ccSMatthieu Baerts fi 1977b08fbf24SPaolo Abeni 1978b08fbf24SPaolo Abeni # multiple subflows 1979c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 198034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 198134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 198234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 198334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1984b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1985c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1986ae7bd9ccSMatthieu Baerts fi 1987b08fbf24SPaolo Abeni 198872bcbc46SPaolo Abeni # multiple subflows limited by server 1989c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 199034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 199134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 199234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 199334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1994b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1995c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 1996ae7bd9ccSMatthieu Baerts fi 1997c3eaa5f6SGeliang Tang 1998c3eaa5f6SGeliang Tang # single subflow, dev 1999c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 200034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 200134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 200234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 2003c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2004c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2005ae7bd9ccSMatthieu Baerts fi 20061002b89fSGeliang Tang} 2007b08fbf24SPaolo Abeni 200846e967d1SPaolo Abenisubflows_error_tests() 200946e967d1SPaolo Abeni{ 201046e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 201146e967d1SPaolo Abeni # address, no additional subflow should be created 2012c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 201334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 201434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 201534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2016e571fb09SGeliang Tang speed=slow \ 2017e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2018c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2019ae7bd9ccSMatthieu Baerts fi 202046e967d1SPaolo Abeni 202146e967d1SPaolo Abeni # multiple subflows, with subflow creation error 20224a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT && 20234a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 202434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 202534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 202634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 202734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2028e571fb09SGeliang Tang speed=slow \ 2029e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2030c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2031ae7bd9ccSMatthieu Baerts fi 203246e967d1SPaolo Abeni 203346e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 20344a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP && 20354a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 203634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 203734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 203834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 203934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2040e571fb09SGeliang Tang speed=slow \ 2041e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2042c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2043ae7bd9ccSMatthieu Baerts fi 204446e967d1SPaolo Abeni 204546e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 204646e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 204746e967d1SPaolo Abeni # subflows are added later 20484a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT && 20494a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 205034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 205134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 205234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2053e571fb09SGeliang Tang speed=slow \ 2054e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 205546e967d1SPaolo Abeni 205646e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 2057f98c2bcaSMat Martineau wait_attempt_fail $ns2 205834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 205946e967d1SPaolo Abeni wait 206046e967d1SPaolo Abeni 206146e967d1SPaolo Abeni # additional subflow could be created only if the PM select 206246e967d1SPaolo Abeni # the later endpoint, skipping the already used one 2063c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2064ae7bd9ccSMatthieu Baerts fi 206546e967d1SPaolo Abeni} 206646e967d1SPaolo Abeni 20671002b89fSGeliang Tangsignal_address_tests() 20681002b89fSGeliang Tang{ 2069b08fbf24SPaolo Abeni # add_address, unused 2070c7d49c03SMatthieu Baerts if reset "unused signal address"; then 207134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2072b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2073c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 20740639fa23SPaolo Abeni chk_add_tx_nr 1 1 2075be613160SGeliang Tang chk_add_nr 1 1 2076ae7bd9ccSMatthieu Baerts fi 2077b08fbf24SPaolo Abeni 2078b08fbf24SPaolo Abeni # accept and use add_addr 2079c7d49c03SMatthieu Baerts if reset "signal address"; then 208034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 208134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 208234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2083b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2084c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2085be613160SGeliang Tang chk_add_nr 1 1 2086ae7bd9ccSMatthieu Baerts fi 2087b08fbf24SPaolo Abeni 2088b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 2089b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 2090b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 2091b08fbf24SPaolo Abeni # used for 'add_addr' subflow 2092c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 209334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 209434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 209534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 209634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2097b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2098c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2099be613160SGeliang Tang chk_add_nr 1 1 2100ae7bd9ccSMatthieu Baerts fi 2101b08fbf24SPaolo Abeni 2102b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 2103c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 210434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 210534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 210634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 210734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 210834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2109b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2110c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2111be613160SGeliang Tang chk_add_nr 1 1 2112ae7bd9ccSMatthieu Baerts fi 2113ef360019SGeliang Tang 2114ef360019SGeliang Tang # signal addresses 2115c7d49c03SMatthieu Baerts if reset "signal addresses"; then 211634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 211734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 211834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 211934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 212034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2121ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2122c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2123ef360019SGeliang Tang chk_add_nr 3 3 2124ae7bd9ccSMatthieu Baerts fi 2125ef360019SGeliang Tang 2126ef360019SGeliang Tang # signal invalid addresses 2127c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 212834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 212934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 213034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 213134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 213234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2133ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2134c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2135ef360019SGeliang Tang chk_add_nr 3 3 2136ae7bd9ccSMatthieu Baerts fi 213733c563adSYonglong Li 213833c563adSYonglong Li # signal addresses race test 2139c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 214034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 214134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 214234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 214334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 214434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 214534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 214634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 214734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 214834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 214934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 21506ef84b15SPaolo Abeni 21516ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 21526ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2153e571fb09SGeliang Tang speed=slow \ 2154e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 215586e39e04SPaolo Abeni 2156d4c81bbbSMatthieu Baerts # It is not directly linked to the commit introducing this 2157d4c81bbbSMatthieu Baerts # symbol but for the parent one which is linked anyway. 2158d4c81bbbSMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 2159d4c81bbbSMatthieu Baerts chk_join_nr 3 3 2 2160d4c81bbbSMatthieu Baerts chk_add_nr 4 4 2161d4c81bbbSMatthieu Baerts else 2162d4c81bbbSMatthieu Baerts chk_join_nr 3 3 3 216386e39e04SPaolo Abeni # the server will not signal the address terminating 216486e39e04SPaolo Abeni # the MPC subflow 216586e39e04SPaolo Abeni chk_add_nr 3 3 2166ae7bd9ccSMatthieu Baerts fi 2167d4c81bbbSMatthieu Baerts fi 21681002b89fSGeliang Tang} 2169b08fbf24SPaolo Abeni 21701002b89fSGeliang Tanglink_failure_tests() 21711002b89fSGeliang Tang{ 21728b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2173c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 21747d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 21757d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 21767d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 21777d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 21787d1e6f16SPaolo Abeni # active backup and link switch-over. 21797d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 21807d1e6f16SPaolo Abeni init_shapers 218134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 218234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 218334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 218434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 218534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 21860c93af1fSGeliang Tang test_linkfail=1 \ 21870c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2188c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 21898b819a84SFlorian Westphal chk_add_nr 1 1 21907d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2191ae7bd9ccSMatthieu Baerts fi 21927d1e6f16SPaolo Abeni 21937d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 21947d1e6f16SPaolo Abeni # for bidirectional transfer 2195c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 21967d1e6f16SPaolo Abeni init_shapers 219734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 219834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 219934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 220034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 220134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 22020c93af1fSGeliang Tang test_linkfail=2 \ 22030c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2204c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22057d1e6f16SPaolo Abeni chk_add_nr 1 1 22067d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2207ae7bd9ccSMatthieu Baerts fi 22087d1e6f16SPaolo Abeni 22097d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 22107d1e6f16SPaolo Abeni # will never be used 2211c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 22127d1e6f16SPaolo Abeni init_shapers 221334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 221434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 221534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 221634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22170c93af1fSGeliang Tang FAILING_LINKS="1" test_linkfail=1 \ 22180c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2219c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22207d1e6f16SPaolo Abeni chk_add_nr 1 1 22217d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2222ae7bd9ccSMatthieu Baerts fi 22237d1e6f16SPaolo Abeni 22247d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 22257d1e6f16SPaolo Abeni # the traffic 2226c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 22277d1e6f16SPaolo Abeni init_shapers 222834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 222934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 223034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 223134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22320c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=1 \ 22330c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2234c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22357d1e6f16SPaolo Abeni chk_add_nr 1 1 22367d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 22377d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2238ae7bd9ccSMatthieu Baerts fi 22397d1e6f16SPaolo Abeni 22407d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 22417d1e6f16SPaolo Abeni # for bidirectional transfer 2242c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 22437d1e6f16SPaolo Abeni init_shapers 224434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 224534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 224634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 224734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22480c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=2 \ 22490c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2250c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22517d1e6f16SPaolo Abeni chk_add_nr 1 1 22527d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 22537d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2254ae7bd9ccSMatthieu Baerts fi 22551002b89fSGeliang Tang} 22568b819a84SFlorian Westphal 22571002b89fSGeliang Tangadd_addr_timeout_tests() 22581002b89fSGeliang Tang{ 22598d014eaaSGeliang Tang # add_addr timeout 2260c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 226134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 226234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 226334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2264e571fb09SGeliang Tang speed=slow \ 2265e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2266c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22670639fa23SPaolo Abeni chk_add_tx_nr 4 4 22688d014eaaSGeliang Tang chk_add_nr 4 0 2269ae7bd9ccSMatthieu Baerts fi 22708d014eaaSGeliang Tang 22711002b89fSGeliang Tang # add_addr timeout IPv6 2272c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 227334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 227434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 227534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2276e571fb09SGeliang Tang speed=slow \ 2277e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2278c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22791002b89fSGeliang Tang chk_add_nr 4 0 2280ae7bd9ccSMatthieu Baerts fi 22818da6229bSGeliang Tang 22828da6229bSGeliang Tang # signal addresses timeout 2283c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 228434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 228534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 228634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 228734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2288e571fb09SGeliang Tang speed=10 \ 2289e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2290c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22918da6229bSGeliang Tang chk_add_nr 8 0 2292ae7bd9ccSMatthieu Baerts fi 22938da6229bSGeliang Tang 22948da6229bSGeliang Tang # signal invalid addresses timeout 2295c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 229634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 229734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 229834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 229934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2300e571fb09SGeliang Tang speed=10 \ 2301e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2302c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23038da6229bSGeliang Tang chk_add_nr 8 0 2304ae7bd9ccSMatthieu Baerts fi 23051002b89fSGeliang Tang} 23061002b89fSGeliang Tang 23071002b89fSGeliang Tangremove_tests() 23081002b89fSGeliang Tang{ 2309dd72b0feSGeliang Tang # single subflow, remove 2310c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 231134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 231234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 231334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2314e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 2315e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2316c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23170639fa23SPaolo Abeni chk_rm_tx_nr 1 2318dd72b0feSGeliang Tang chk_rm_nr 1 1 23192cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2320ae7bd9ccSMatthieu Baerts fi 2321dd72b0feSGeliang Tang 2322dd72b0feSGeliang Tang # multiple subflows, remove 2323c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 232434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 232534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 232634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 232734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2328e571fb09SGeliang Tang addr_nr_ns2=-2 speed=slow \ 2329e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2330c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2331dd72b0feSGeliang Tang chk_rm_nr 2 2 23322cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2333ae7bd9ccSMatthieu Baerts fi 2334dd72b0feSGeliang Tang 2335dd72b0feSGeliang Tang # single address, remove 2336c7d49c03SMatthieu Baerts if reset "remove single address"; then 233734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 233834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 233934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2340e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2341e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2342c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2343dd72b0feSGeliang Tang chk_add_nr 1 1 23447028ba8aSGeliang Tang chk_rm_nr 1 1 invert 23452cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2346ae7bd9ccSMatthieu Baerts fi 2347dd72b0feSGeliang Tang 2348dd72b0feSGeliang Tang # subflow and signal, remove 2349c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 235034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 235134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 235234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 235334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2354e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2355e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2356c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2357dd72b0feSGeliang Tang chk_add_nr 1 1 2358dd72b0feSGeliang Tang chk_rm_nr 1 1 23592cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2360ae7bd9ccSMatthieu Baerts fi 2361dd72b0feSGeliang Tang 2362dd72b0feSGeliang Tang # subflows and signal, remove 2363c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 236434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 236534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 236634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 236734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 236834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2369e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \ 2370e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2371c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2372dd72b0feSGeliang Tang chk_add_nr 1 1 2373dd72b0feSGeliang Tang chk_rm_nr 2 2 23742cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2375ae7bd9ccSMatthieu Baerts fi 2376dd72b0feSGeliang Tang 2377ef360019SGeliang Tang # addresses remove 2378c7d49c03SMatthieu Baerts if reset "remove addresses"; then 237934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 238034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 238134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 238234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 238334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2384e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2385e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2386c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2387ef360019SGeliang Tang chk_add_nr 3 3 2388ef360019SGeliang Tang chk_rm_nr 3 3 invert 23892cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2390ae7bd9ccSMatthieu Baerts fi 2391ef360019SGeliang Tang 2392ef360019SGeliang Tang # invalid addresses remove 2393c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 239434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 239534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 239634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 239734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 239834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2399e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2400e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2401c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2402ef360019SGeliang Tang chk_add_nr 3 3 2403ef360019SGeliang Tang chk_rm_nr 3 1 invert 24042cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2405ae7bd9ccSMatthieu Baerts fi 2406ef360019SGeliang Tang 24076fe4ccdcSGeliang Tang # subflows and signal, flush 2408c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 240934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 241034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 241134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 241234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 241334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2414e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2415e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2416c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 24176fe4ccdcSGeliang Tang chk_add_nr 1 1 24186fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 24192cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2420ae7bd9ccSMatthieu Baerts fi 2421d2c4333aSGeliang Tang 2422d2c4333aSGeliang Tang # subflows flush 2423c7d49c03SMatthieu Baerts if reset "flush subflows"; then 242434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 242534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 242634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 242734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 242834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2429e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2430e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2431c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2432425ba803SMatthieu Baerts 2433425ba803SMatthieu Baerts if mptcp_lib_kversion_ge 5.18; then 24340639fa23SPaolo Abeni chk_rm_tx_nr 0 24356fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2436425ba803SMatthieu Baerts else 2437425ba803SMatthieu Baerts chk_rm_nr 3 3 2438425ba803SMatthieu Baerts fi 24392cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2440ae7bd9ccSMatthieu Baerts fi 2441d2c4333aSGeliang Tang 2442d2c4333aSGeliang Tang # addresses flush 2443c7d49c03SMatthieu Baerts if reset "flush addresses"; then 244434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 244534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 244634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 244734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 244834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2449e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2450e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2451c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2452d2c4333aSGeliang Tang chk_add_nr 3 3 24536fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 24542cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2455ae7bd9ccSMatthieu Baerts fi 2456ef360019SGeliang Tang 2457ef360019SGeliang Tang # invalid addresses flush 2458c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 245934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 246034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 246134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 246234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 246334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2464e571fb09SGeliang Tang addr_nr_ns1=-8 speed=slow \ 2465e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2466c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2467ef360019SGeliang Tang chk_add_nr 3 3 2468ef360019SGeliang Tang chk_rm_nr 3 1 invert 24692cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2470ae7bd9ccSMatthieu Baerts fi 24715e287fe7SGeliang Tang 24725e287fe7SGeliang Tang # remove id 0 subflow 2473c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 247434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 247534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 247634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2477e571fb09SGeliang Tang addr_nr_ns2=-9 speed=slow \ 2478e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2479c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 24805e287fe7SGeliang Tang chk_rm_nr 1 1 24812cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2482ae7bd9ccSMatthieu Baerts fi 24835e287fe7SGeliang Tang 24845e287fe7SGeliang Tang # remove id 0 address 2485c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 248634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 248734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 248834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2489e571fb09SGeliang Tang addr_nr_ns1=-9 speed=slow \ 2490e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2491c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 24925e287fe7SGeliang Tang chk_add_nr 1 1 24935e287fe7SGeliang Tang chk_rm_nr 1 1 invert 24942cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 invert 2495ae7bd9ccSMatthieu Baerts fi 24961002b89fSGeliang Tang} 24976fe4ccdcSGeliang Tang 24981002b89fSGeliang Tangadd_tests() 24991002b89fSGeliang Tang{ 25006208fd82SGeliang Tang # add single subflow 2501c7d49c03SMatthieu Baerts if reset "add single subflow"; then 250234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 250334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2504e571fb09SGeliang Tang addr_nr_ns2=1 speed=slow \ 2505e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2506c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2507ae7bd9ccSMatthieu Baerts fi 25086208fd82SGeliang Tang 25096208fd82SGeliang Tang # add signal address 2510c7d49c03SMatthieu Baerts if reset "add signal address"; then 251134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 251234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2513e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 2514e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2515c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 25166208fd82SGeliang Tang chk_add_nr 1 1 2517ae7bd9ccSMatthieu Baerts fi 25186208fd82SGeliang Tang 25196208fd82SGeliang Tang # add multiple subflows 2520c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 252134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 252234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2523e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2524e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2525c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2526ae7bd9ccSMatthieu Baerts fi 25276208fd82SGeliang Tang 25286208fd82SGeliang Tang # add multiple subflows IPv6 2529c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 253034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 253134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2532e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2533e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2534c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2535ae7bd9ccSMatthieu Baerts fi 25366208fd82SGeliang Tang 25376208fd82SGeliang Tang # add multiple addresses IPv6 2538c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 253934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 254034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2541e571fb09SGeliang Tang addr_nr_ns1=2 speed=slow \ 2542e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2543c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 25446208fd82SGeliang Tang chk_add_nr 2 2 2545ae7bd9ccSMatthieu Baerts fi 25461002b89fSGeliang Tang} 25476208fd82SGeliang Tang 25481002b89fSGeliang Tangipv6_tests() 25491002b89fSGeliang Tang{ 2550523514edSGeliang Tang # subflow IPv6 2551c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 255234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 255334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 255434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2555e571fb09SGeliang Tang speed=slow \ 2556e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2557c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2558ae7bd9ccSMatthieu Baerts fi 2559523514edSGeliang Tang 2560523514edSGeliang Tang # add_address, unused IPv6 2561c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 256234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2563e571fb09SGeliang Tang speed=slow \ 2564e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2565c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2566523514edSGeliang Tang chk_add_nr 1 1 2567ae7bd9ccSMatthieu Baerts fi 2568523514edSGeliang Tang 2569523514edSGeliang Tang # signal address IPv6 2570c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 257134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 257234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 257334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2574e571fb09SGeliang Tang speed=slow \ 2575e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2576c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2577523514edSGeliang Tang chk_add_nr 1 1 2578ae7bd9ccSMatthieu Baerts fi 2579523514edSGeliang Tang 2580523514edSGeliang Tang # single address IPv6, remove 2581c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 258234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 258334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 258434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2585e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2586e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2587c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2588523514edSGeliang Tang chk_add_nr 1 1 25897028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2590ae7bd9ccSMatthieu Baerts fi 2591523514edSGeliang Tang 2592523514edSGeliang Tang # subflow and signal IPv6, remove 2593c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 259434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 259534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 259634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 259734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2598e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2599e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2600c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2601523514edSGeliang Tang chk_add_nr 1 1 2602523514edSGeliang Tang chk_rm_nr 1 1 2603ae7bd9ccSMatthieu Baerts fi 26041002b89fSGeliang Tang} 2605523514edSGeliang Tang 26061002b89fSGeliang Tangv4mapped_tests() 26071002b89fSGeliang Tang{ 2608a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2609c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 261034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 261134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 261234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2613a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2614c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2615ae7bd9ccSMatthieu Baerts fi 2616a6094788SGeliang Tang 2617a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2618c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 261934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 262034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 262134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2622a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2623c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2624a6094788SGeliang Tang chk_add_nr 1 1 2625ae7bd9ccSMatthieu Baerts fi 2626a6094788SGeliang Tang 2627a6094788SGeliang Tang # subflow v4-map-v6 2628c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 262934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 263034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 263134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2632a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2633c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2634ae7bd9ccSMatthieu Baerts fi 2635a6094788SGeliang Tang 2636a6094788SGeliang Tang # signal address v4-map-v6 2637c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 263834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 263934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 264034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2641a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2642c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2643a6094788SGeliang Tang chk_add_nr 1 1 2644ae7bd9ccSMatthieu Baerts fi 2645a6094788SGeliang Tang 2646a6094788SGeliang Tang # subflow v6-map-v4 2647c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 264834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 264934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 265034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2651a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2652c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2653ae7bd9ccSMatthieu Baerts fi 2654a6094788SGeliang Tang 2655a6094788SGeliang Tang # signal address v6-map-v4 2656c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 265734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 265834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 265934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2660a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2661c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2662a6094788SGeliang Tang chk_add_nr 1 1 2663ae7bd9ccSMatthieu Baerts fi 2664a6094788SGeliang Tang 2665a6094788SGeliang Tang # no subflow IPv6 to v4 address 2666c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 266734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 266834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 266934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2670a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2671c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2672ae7bd9ccSMatthieu Baerts fi 2673a6094788SGeliang Tang 2674a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2675c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 267634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 267734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 267834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2679a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2680c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2681ae7bd9ccSMatthieu Baerts fi 2682a6094788SGeliang Tang 2683a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2684c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 268534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 268634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 268734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2688a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2689c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2690ae7bd9ccSMatthieu Baerts fi 26911002b89fSGeliang Tang} 2692a6094788SGeliang Tang 2693ad349374SPaolo Abenimixed_tests() 2694ad349374SPaolo Abeni{ 26956673851bSMatthieu Baerts if reset "IPv4 sockets do not use IPv6 addresses" && 26966673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2697ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2698ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2699ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2700e571fb09SGeliang Tang speed=slow \ 2701e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2702ad349374SPaolo Abeni chk_join_nr 0 0 0 2703ad349374SPaolo Abeni fi 2704ad349374SPaolo Abeni 2705ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 27066673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows" && 27076673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2708ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2709ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2710ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2711e571fb09SGeliang Tang speed=slow \ 2712e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2713ad349374SPaolo Abeni chk_join_nr 1 1 1 2714ad349374SPaolo Abeni fi 2715ad349374SPaolo Abeni 2716ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 27176673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" && 27186673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2719ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2720ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2721ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2722ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2723e571fb09SGeliang Tang speed=slow \ 2724e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2725ad349374SPaolo Abeni chk_join_nr 1 1 1 2726ad349374SPaolo Abeni fi 2727ad349374SPaolo Abeni 2728ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2729ad349374SPaolo Abeni # matching family 27306673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" && 27316673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2732ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2733ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2734ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2735ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2736e571fb09SGeliang Tang fullmesh=1 speed=slow \ 2737e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2738ad349374SPaolo Abeni chk_join_nr 4 4 4 2739ad349374SPaolo Abeni fi 2740ad349374SPaolo Abeni} 2741ad349374SPaolo Abeni 27421002b89fSGeliang Tangbackup_tests() 27431002b89fSGeliang Tang{ 2744718eb44eSGeliang Tang # single subflow, backup 274507216a3cSMatthieu Baerts if reset "single subflow, backup" && 274607216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 274734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 274834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 274934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2750e571fb09SGeliang Tang sflags=nobackup speed=slow \ 2751e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2752c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2753718eb44eSGeliang Tang chk_prio_nr 0 1 2754ae7bd9ccSMatthieu Baerts fi 2755718eb44eSGeliang Tang 2756718eb44eSGeliang Tang # single address, backup 275707216a3cSMatthieu Baerts if reset "single address, backup" && 275807216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 275934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 276034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 276134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2762e571fb09SGeliang Tang sflags=backup speed=slow \ 2763e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2764c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2765718eb44eSGeliang Tang chk_add_nr 1 1 2766d045b9ebSPaolo Abeni chk_prio_nr 1 1 2767ae7bd9ccSMatthieu Baerts fi 276833397b83SGeliang Tang 276933397b83SGeliang Tang # single address with port, backup 277007216a3cSMatthieu Baerts if reset "single address with port, backup" && 277107216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 277234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 277334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 277434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2775e571fb09SGeliang Tang sflags=backup speed=slow \ 2776e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2777c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 277833397b83SGeliang Tang chk_add_nr 1 1 2779d045b9ebSPaolo Abeni chk_prio_nr 1 1 2780ae7bd9ccSMatthieu Baerts fi 2781914f6a59SPaolo Abeni 2782632978f0SMatthieu Baerts if reset "mpc backup" && 2783c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2784914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2785e571fb09SGeliang Tang speed=slow \ 2786e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2787914f6a59SPaolo Abeni chk_join_nr 0 0 0 2788914f6a59SPaolo Abeni chk_prio_nr 0 1 2789914f6a59SPaolo Abeni fi 2790914f6a59SPaolo Abeni 2791632978f0SMatthieu Baerts if reset "mpc backup both sides" && 2792c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2793914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2794914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2795e571fb09SGeliang Tang speed=slow \ 2796e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2797914f6a59SPaolo Abeni chk_join_nr 0 0 0 2798914f6a59SPaolo Abeni chk_prio_nr 1 1 2799914f6a59SPaolo Abeni fi 2800914f6a59SPaolo Abeni 2801632978f0SMatthieu Baerts if reset "mpc switch to backup" && 2802c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2803914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2804e571fb09SGeliang Tang sflags=backup speed=slow \ 2805e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2806914f6a59SPaolo Abeni chk_join_nr 0 0 0 2807914f6a59SPaolo Abeni chk_prio_nr 0 1 2808914f6a59SPaolo Abeni fi 2809914f6a59SPaolo Abeni 2810632978f0SMatthieu Baerts if reset "mpc switch to backup both sides" && 2811c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2812914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2813914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2814e571fb09SGeliang Tang sflags=backup speed=slow \ 2815e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2816914f6a59SPaolo Abeni chk_join_nr 0 0 0 2817914f6a59SPaolo Abeni chk_prio_nr 1 1 2818914f6a59SPaolo Abeni fi 28191002b89fSGeliang Tang} 2820718eb44eSGeliang Tang 28219d71f43aSGeliang TangSUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED 2822178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2823178d0232SGeliang TangLISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2824178d0232SGeliang Tang 2825178d0232SGeliang TangAF_INET=2 2826178d0232SGeliang TangAF_INET6=10 2827178d0232SGeliang Tang 2828178d0232SGeliang Tangverify_listener_events() 2829178d0232SGeliang Tang{ 2830178d0232SGeliang Tang local evt=$1 2831178d0232SGeliang Tang local e_type=$2 2832178d0232SGeliang Tang local e_family=$3 2833178d0232SGeliang Tang local e_saddr=$4 2834178d0232SGeliang Tang local e_sport=$5 2835178d0232SGeliang Tang local type 2836178d0232SGeliang Tang local family 2837178d0232SGeliang Tang local saddr 2838178d0232SGeliang Tang local sport 283996b84195SMatthieu Baerts local name 2840178d0232SGeliang Tang 2841178d0232SGeliang Tang if [ $e_type = $LISTENER_CREATED ]; then 284296b84195SMatthieu Baerts name="LISTENER_CREATED" 2843178d0232SGeliang Tang elif [ $e_type = $LISTENER_CLOSED ]; then 284496b84195SMatthieu Baerts name="LISTENER_CLOSED " 284596b84195SMatthieu Baerts else 284696b84195SMatthieu Baerts name="$e_type" 2847178d0232SGeliang Tang fi 2848178d0232SGeliang Tang 284903668c65SMatthieu Baerts print_check "$name $e_saddr:$e_sport" 285096b84195SMatthieu Baerts 28510471bb47SMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 285203668c65SMatthieu Baerts print_skip "event not supported" 28530471bb47SMatthieu Baerts return 28540471bb47SMatthieu Baerts fi 28550471bb47SMatthieu Baerts 2856ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" "$e_type") 2857ae1fa39dSGeliang Tang family=$(mptcp_lib_evts_get_info family "$evt" "$e_type") 2858ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type") 2859178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 2860ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type") 2861178d0232SGeliang Tang else 2862ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type") 2863178d0232SGeliang Tang fi 2864178d0232SGeliang Tang 2865178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2866178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2867178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2868178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 286903668c65SMatthieu Baerts print_ok 2870178d0232SGeliang Tang return 0 2871178d0232SGeliang Tang fi 287203668c65SMatthieu Baerts fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" 2873178d0232SGeliang Tang} 2874178d0232SGeliang Tang 28751002b89fSGeliang Tangadd_addr_ports_tests() 28761002b89fSGeliang Tang{ 28778a127bf6SGeliang Tang # signal address with port 2878c7d49c03SMatthieu Baerts if reset "signal address with port"; then 287934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 288034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 288134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 28828a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2883c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28848a127bf6SGeliang Tang chk_add_nr 1 1 1 2885ae7bd9ccSMatthieu Baerts fi 28868a127bf6SGeliang Tang 28878a127bf6SGeliang Tang # subflow and signal with port 2888c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 288934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 289034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 289134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 289234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28938a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2894c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 28958a127bf6SGeliang Tang chk_add_nr 1 1 1 2896ae7bd9ccSMatthieu Baerts fi 28978a127bf6SGeliang Tang 28988a127bf6SGeliang Tang # single address with port, remove 2899178d0232SGeliang Tang # pm listener events 2900178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 290134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 290234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 290334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2904e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2905e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2906c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29078a127bf6SGeliang Tang chk_add_nr 1 1 1 29087028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2909178d0232SGeliang Tang 2910178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2911178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2912178d0232SGeliang Tang kill_events_pids 2913ae7bd9ccSMatthieu Baerts fi 29148a127bf6SGeliang Tang 29158a127bf6SGeliang Tang # subflow and signal with port, remove 2916c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 291734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 291834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 291934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 292034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2921e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2922e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2923c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29248a127bf6SGeliang Tang chk_add_nr 1 1 1 29258a127bf6SGeliang Tang chk_rm_nr 1 1 2926ae7bd9ccSMatthieu Baerts fi 29278a127bf6SGeliang Tang 29288a127bf6SGeliang Tang # subflows and signal with port, flush 2929c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 293034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 293134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 293234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 293334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 293434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2935e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \ 2936e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2937c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 29388a127bf6SGeliang Tang chk_add_nr 1 1 29396fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2940ae7bd9ccSMatthieu Baerts fi 29418a127bf6SGeliang Tang 29428a127bf6SGeliang Tang # multiple addresses with port 2943c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 294434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 294534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 294634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 294734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 29488a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2949c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29508a127bf6SGeliang Tang chk_add_nr 2 2 2 2951ae7bd9ccSMatthieu Baerts fi 29528a127bf6SGeliang Tang 29538a127bf6SGeliang Tang # multiple addresses with ports 2954c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 295534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 295634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 295734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 295834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 29598a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2960c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29618a127bf6SGeliang Tang chk_add_nr 2 2 2 2962ae7bd9ccSMatthieu Baerts fi 29631002b89fSGeliang Tang} 29648a127bf6SGeliang Tang 29651002b89fSGeliang Tangsyncookies_tests() 29661002b89fSGeliang Tang{ 296700587187SFlorian Westphal # single subflow, syncookies 2968c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 296934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 297034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 297134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 297200587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2973c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2974ae7bd9ccSMatthieu Baerts fi 297500587187SFlorian Westphal 297600587187SFlorian Westphal # multiple subflows with syn cookies 2977c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 297834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 297934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 298034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 298134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 298200587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2983c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2984ae7bd9ccSMatthieu Baerts fi 298500587187SFlorian Westphal 298600587187SFlorian Westphal # multiple subflows limited by server 2987c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 298834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 298934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 299034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 299134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 299200587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2993c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 2994ae7bd9ccSMatthieu Baerts fi 299500587187SFlorian Westphal 299600587187SFlorian Westphal # test signal address with cookies 2997c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 299834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 299934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 300034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 300100587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3002c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3003be613160SGeliang Tang chk_add_nr 1 1 3004ae7bd9ccSMatthieu Baerts fi 300500587187SFlorian Westphal 300600587187SFlorian Westphal # test cookie with subflow and signal 3007c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 300834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 300934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 301034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 301134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 301200587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3013c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3014be613160SGeliang Tang chk_add_nr 1 1 3015ae7bd9ccSMatthieu Baerts fi 301600587187SFlorian Westphal 301700587187SFlorian Westphal # accept and use add_addr with additional subflows 3018c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 301934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 302034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 302134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 302234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 302334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 302400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3025c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 3026be613160SGeliang Tang chk_add_nr 1 1 3027ae7bd9ccSMatthieu Baerts fi 30281002b89fSGeliang Tang} 30291002b89fSGeliang Tang 3030af66d3e1SGeliang Tangchecksum_tests() 3031af66d3e1SGeliang Tang{ 3032af66d3e1SGeliang Tang # checksum test 0 0 3033ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 303434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 303534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3036af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3037c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3038ae7bd9ccSMatthieu Baerts fi 3039af66d3e1SGeliang Tang 3040af66d3e1SGeliang Tang # checksum test 1 1 3041ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 304234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 304334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3044af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3045c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3046ae7bd9ccSMatthieu Baerts fi 3047af66d3e1SGeliang Tang 3048af66d3e1SGeliang Tang # checksum test 0 1 3049ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 305034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 305134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3052af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3053c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3054ae7bd9ccSMatthieu Baerts fi 3055af66d3e1SGeliang Tang 3056af66d3e1SGeliang Tang # checksum test 1 0 3057ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 305834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 305934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3060af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3061c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3062ae7bd9ccSMatthieu Baerts fi 3063af66d3e1SGeliang Tang} 3064af66d3e1SGeliang Tang 30650cddb4a6SGeliang Tangdeny_join_id0_tests() 30660cddb4a6SGeliang Tang{ 30670cddb4a6SGeliang Tang # subflow allow join id0 ns1 3068c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 306934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 307034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 307134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30720cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3073c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3074ae7bd9ccSMatthieu Baerts fi 30750cddb4a6SGeliang Tang 30760cddb4a6SGeliang Tang # subflow allow join id0 ns2 3077c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 307834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 307934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 308034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30810cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3082c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3083ae7bd9ccSMatthieu Baerts fi 30840cddb4a6SGeliang Tang 30850cddb4a6SGeliang Tang # signal address allow join id0 ns1 30860cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3087c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 308834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 308934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 309034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 30910cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3092c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 30930cddb4a6SGeliang Tang chk_add_nr 1 1 3094ae7bd9ccSMatthieu Baerts fi 30950cddb4a6SGeliang Tang 30960cddb4a6SGeliang Tang # signal address allow join id0 ns2 30970cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3098c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 309934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 310034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 310134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 31020cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3103c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 31040cddb4a6SGeliang Tang chk_add_nr 1 1 3105ae7bd9ccSMatthieu Baerts fi 31060cddb4a6SGeliang Tang 31070cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 3108c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 310934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 311034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 311134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 311234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31130cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3114c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3115ae7bd9ccSMatthieu Baerts fi 31160cddb4a6SGeliang Tang 31170cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 3118c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 311934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 312034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 312134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 312234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31230cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3124c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3125ae7bd9ccSMatthieu Baerts fi 31260cddb4a6SGeliang Tang} 31270cddb4a6SGeliang Tang 31284f49d633SGeliang Tangfullmesh_tests() 31294f49d633SGeliang Tang{ 31304f49d633SGeliang Tang # fullmesh 1 31314f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 31324f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 3133c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 313434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 313534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 313634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 313734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 3138e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 3139e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3140c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 31414f49d633SGeliang Tang chk_add_nr 1 1 3142ae7bd9ccSMatthieu Baerts fi 31434f49d633SGeliang Tang 31444f49d633SGeliang Tang # fullmesh 2 31454f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31464f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 3147c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 314834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 314934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 315034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3151e571fb09SGeliang Tang fullmesh=1 speed=slow \ 3152e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3153c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 31544f49d633SGeliang Tang chk_add_nr 1 1 3155ae7bd9ccSMatthieu Baerts fi 31564f49d633SGeliang Tang 31574f49d633SGeliang Tang # fullmesh 3 31584f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31594f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 3160c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 316134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 316234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 316334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3164e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3165e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3166c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 31674f49d633SGeliang Tang chk_add_nr 1 1 3168ae7bd9ccSMatthieu Baerts fi 31694f49d633SGeliang Tang 31704f49d633SGeliang Tang # fullmesh 4 31714f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31724f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 31734f49d633SGeliang Tang # limit max_subflows to 4. 3174c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 317534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 317634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 317734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3178e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3179e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3180c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 31814f49d633SGeliang Tang chk_add_nr 1 1 3182ae7bd9ccSMatthieu Baerts fi 31836a0653b9SGeliang Tang 31846a0653b9SGeliang Tang # set fullmesh flag 31859db34c42SMatthieu Baerts if reset "set fullmesh flag test" && 31869db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 318734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 318834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 318934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3190e571fb09SGeliang Tang addr_nr_ns2=1 sflags=fullmesh speed=slow \ 3191e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3192c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 31936a0653b9SGeliang Tang chk_rm_nr 0 1 3194ae7bd9ccSMatthieu Baerts fi 31956a0653b9SGeliang Tang 31966a0653b9SGeliang Tang # set nofullmesh flag 31979db34c42SMatthieu Baerts if reset "set nofullmesh flag test" && 31989db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 319934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 320034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 320134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3202e571fb09SGeliang Tang fullmesh=1 sflags=nofullmesh speed=slow \ 3203e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3204c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32056a0653b9SGeliang Tang chk_rm_nr 0 1 3206ae7bd9ccSMatthieu Baerts fi 32076a0653b9SGeliang Tang 32086a0653b9SGeliang Tang # set backup,fullmesh flags 32099db34c42SMatthieu Baerts if reset "set backup,fullmesh flags test" && 32109db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 321134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 321234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 321334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3214e571fb09SGeliang Tang addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \ 3215e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3216c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32176a0653b9SGeliang Tang chk_prio_nr 0 1 32186a0653b9SGeliang Tang chk_rm_nr 0 1 3219ae7bd9ccSMatthieu Baerts fi 32206a0653b9SGeliang Tang 32216a0653b9SGeliang Tang # set nobackup,nofullmesh flags 32229db34c42SMatthieu Baerts if reset "set nobackup,nofullmesh flags test" && 32239db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 322434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 322534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 322634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3227e571fb09SGeliang Tang sflags=nobackup,nofullmesh speed=slow \ 3228e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3229c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32306a0653b9SGeliang Tang chk_prio_nr 0 1 32316a0653b9SGeliang Tang chk_rm_nr 0 1 3232ae7bd9ccSMatthieu Baerts fi 32334f49d633SGeliang Tang} 32344f49d633SGeliang Tang 323501542c9bSGeliang Tangfastclose_tests() 323601542c9bSGeliang Tang{ 3237ae947bb2SMatthieu Baerts if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then 3238080b7f57SGeliang Tang test_linkfail=1024 fastclose=client \ 3239595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3240c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 324101542c9bSGeliang Tang chk_fclose_nr 1 1 324201542c9bSGeliang Tang chk_rst_nr 1 1 invert 3243ae7bd9ccSMatthieu Baerts fi 32446bf41020SPaolo Abeni 3245ae947bb2SMatthieu Baerts if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then 3246080b7f57SGeliang Tang test_linkfail=1024 fastclose=server \ 3247595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 324855dd3816SPaolo Abeni chk_join_nr 0 0 0 0 0 0 1 32496bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 32506bf41020SPaolo Abeni chk_rst_nr 1 1 32516bf41020SPaolo Abeni fi 325201542c9bSGeliang Tang} 325301542c9bSGeliang Tang 3254b6e074e1SGeliang Tangpedit_action_pkts() 3255b6e074e1SGeliang Tang{ 3256b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3257ae1fa39dSGeliang Tang mptcp_lib_get_info_value \"packets\" packets 3258b6e074e1SGeliang Tang} 3259b6e074e1SGeliang Tang 3260b6e074e1SGeliang Tangfail_tests() 3261b6e074e1SGeliang Tang{ 3262b6e074e1SGeliang Tang # single subflow 3263b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 32640c93af1fSGeliang Tang test_linkfail=128 \ 32650c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3266b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 32671f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3268b6e074e1SGeliang Tang fi 32692ba18161SGeliang Tang 32702ba18161SGeliang Tang # multiple subflows 32712ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 32722ba18161SGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 32732ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 32742ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 32752ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 32760c93af1fSGeliang Tang test_linkfail=1024 \ 32770c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 32782ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 32792ba18161SGeliang Tang fi 3280b6e074e1SGeliang Tang} 3281b6e074e1SGeliang Tang 32829d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 32834369c198SGeliang Tanguserspace_pm_add_addr() 32844369c198SGeliang Tang{ 32859d71f43aSGeliang Tang local evts=$evts_ns1 32864369c198SGeliang Tang local tk 32874369c198SGeliang Tang 32889d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 32899d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 32909d71f43aSGeliang Tang 32919d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl ann $2 token $tk id $3 32924369c198SGeliang Tang sleep 1 32934369c198SGeliang Tang} 32944369c198SGeliang Tang 32959d71f43aSGeliang Tang# $1: ns ; $2: id 32969d71f43aSGeliang Tanguserspace_pm_rm_addr() 32974369c198SGeliang Tang{ 32989d71f43aSGeliang Tang local evts=$evts_ns1 32999d71f43aSGeliang Tang local tk 33009d71f43aSGeliang Tang local cnt 33014369c198SGeliang Tang 33029d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33039d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33049d71f43aSGeliang Tang 33059d71f43aSGeliang Tang cnt=$(rm_addr_count ${1}) 33069d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl rem token $tk id $2 33079d71f43aSGeliang Tang wait_rm_addr $1 "${cnt}" 33084369c198SGeliang Tang} 33094369c198SGeliang Tang 33109d71f43aSGeliang Tang# $1: ns ; $2: addr ; $3: id 33114369c198SGeliang Tanguserspace_pm_add_sf() 33124369c198SGeliang Tang{ 33139d71f43aSGeliang Tang local evts=$evts_ns1 33144369c198SGeliang Tang local tk da dp 33154369c198SGeliang Tang 33169d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 33179d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 33189d71f43aSGeliang Tang da=$(mptcp_lib_evts_get_info daddr4 "$evts") 33199d71f43aSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts") 33209d71f43aSGeliang Tang 33219d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl csf lip $2 lid $3 \ 33224369c198SGeliang Tang rip $da rport $dp token $tk 33234369c198SGeliang Tang sleep 1 33244369c198SGeliang Tang} 33254369c198SGeliang Tang 33269d71f43aSGeliang Tang# $1: ns ; $2: addr $3: event type 33279d71f43aSGeliang Tanguserspace_pm_rm_sf() 33284369c198SGeliang Tang{ 33299d71f43aSGeliang Tang local evts=$evts_ns1 33309d71f43aSGeliang Tang local t=${3:-1} 3331ece1aaecSGeliang Tang local ip 33324369c198SGeliang Tang local tk da dp sp 33339d71f43aSGeliang Tang local cnt 33344369c198SGeliang Tang 33359d71f43aSGeliang Tang [ "$1" == "$ns2" ] && evts=$evts_ns2 3336ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr4" "$evts" $t)" ] && ip=4 3337ece1aaecSGeliang Tang [ -n "$(mptcp_lib_evts_get_info "saddr6" "$evts" $t)" ] && ip=6 33389d71f43aSGeliang Tang tk=$(mptcp_lib_evts_get_info token "$evts") 3339ece1aaecSGeliang Tang da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t $2) 3340ece1aaecSGeliang Tang dp=$(mptcp_lib_evts_get_info dport "$evts" $t $2) 3341ece1aaecSGeliang Tang sp=$(mptcp_lib_evts_get_info sport "$evts" $t $2) 33429d71f43aSGeliang Tang 33439d71f43aSGeliang Tang cnt=$(rm_sf_count ${1}) 33449d71f43aSGeliang Tang ip netns exec $1 ./pm_nl_ctl dsf lip $2 lport $sp \ 33454369c198SGeliang Tang rip $da rport $dp token $tk 33469d71f43aSGeliang Tang wait_rm_sf $1 "${cnt}" 33474369c198SGeliang Tang} 33484369c198SGeliang Tang 33495ac1d2d6SMat Martineauuserspace_tests() 33505ac1d2d6SMat Martineau{ 33515ac1d2d6SMat Martineau # userspace pm type prevents add_addr 3352f2b492b0SMatthieu Baerts if reset "userspace pm type prevents add_addr" && 3353f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33545ac1d2d6SMat Martineau set_userspace_pm $ns1 33555ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 33565ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 33575ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 33585ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33595ac1d2d6SMat Martineau chk_join_nr 0 0 0 33605ac1d2d6SMat Martineau chk_add_nr 0 0 33615ac1d2d6SMat Martineau fi 33625ac1d2d6SMat Martineau 3363b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3364f2b492b0SMatthieu Baerts if reset "userspace pm no echo w/o daemon" && 3365f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3366b3b71bf9SMat Martineau set_userspace_pm $ns2 3367b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3368b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3369b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3370b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3371b3b71bf9SMat Martineau chk_join_nr 0 0 0 3372b3b71bf9SMat Martineau chk_add_nr 1 0 3373b3b71bf9SMat Martineau fi 3374b3b71bf9SMat Martineau 33755ac1d2d6SMat Martineau # userspace pm type rejects join 3376f2b492b0SMatthieu Baerts if reset "userspace pm type rejects join" && 3377f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33785ac1d2d6SMat Martineau set_userspace_pm $ns1 33795ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 33805ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 33815ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 33825ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33835ac1d2d6SMat Martineau chk_join_nr 1 1 0 33845ac1d2d6SMat Martineau fi 33855ac1d2d6SMat Martineau 33865ac1d2d6SMat Martineau # userspace pm type does not send join 3387f2b492b0SMatthieu Baerts if reset "userspace pm type does not send join" && 3388f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33895ac1d2d6SMat Martineau set_userspace_pm $ns2 33905ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 33915ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 33925ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 33935ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33945ac1d2d6SMat Martineau chk_join_nr 0 0 0 33955ac1d2d6SMat Martineau fi 33965ac1d2d6SMat Martineau 33975ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 3398f2b492b0SMatthieu Baerts if reset "userspace pm type prevents mp_prio" && 3399f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34005ac1d2d6SMat Martineau set_userspace_pm $ns1 34015ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 34025ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 34035ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3404e571fb09SGeliang Tang sflags=backup speed=slow \ 3405e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 34065ac1d2d6SMat Martineau chk_join_nr 1 1 0 34075ac1d2d6SMat Martineau chk_prio_nr 0 0 34085ac1d2d6SMat Martineau fi 34095ac1d2d6SMat Martineau 34105ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 3411f2b492b0SMatthieu Baerts if reset "userspace pm type prevents rm_addr" && 3412f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34135ac1d2d6SMat Martineau set_userspace_pm $ns1 34145ac1d2d6SMat Martineau set_userspace_pm $ns2 34155ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 34165ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 34175ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3418e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 3419e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 34205ac1d2d6SMat Martineau chk_join_nr 0 0 0 34215ac1d2d6SMat Martineau chk_rm_nr 0 0 34225ac1d2d6SMat Martineau fi 342397040cf9SGeliang Tang 342497040cf9SGeliang Tang # userspace pm add & remove address 3425f2b492b0SMatthieu Baerts if reset_with_events "userspace pm add & remove address" && 3426f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 342797040cf9SGeliang Tang set_userspace_pm $ns1 3428ece1aaecSGeliang Tang pm_nl_set_limits $ns2 2 2 34291c6d07ddSGeliang Tang speed=5 \ 3430e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 34314369c198SGeliang Tang local tests_pid=$! 34324369c198SGeliang Tang wait_mpj $ns1 34339d71f43aSGeliang Tang userspace_pm_add_addr $ns1 10.0.2.1 10 3434ece1aaecSGeliang Tang userspace_pm_add_addr $ns1 10.0.3.1 20 3435ece1aaecSGeliang Tang chk_join_nr 2 2 2 3436ece1aaecSGeliang Tang chk_add_nr 2 2 3437ece1aaecSGeliang Tang chk_mptcp_info subflows 2 subflows 2 3438ece1aaecSGeliang Tang chk_subflows_total 3 3 3439ece1aaecSGeliang Tang chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 34409d71f43aSGeliang Tang userspace_pm_rm_addr $ns1 10 34419d71f43aSGeliang Tang userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED 3442ece1aaecSGeliang Tang userspace_pm_rm_addr $ns1 20 3443ece1aaecSGeliang Tang userspace_pm_rm_sf $ns1 10.0.3.1 $SUB_ESTABLISHED 3444ece1aaecSGeliang Tang chk_rm_nr 2 2 invert 3445d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3446f9190d79SGeliang Tang chk_subflows_total 1 1 3447a3735625SGeliang Tang kill_events_pids 3448a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 344997040cf9SGeliang Tang fi 34505e986ec4SGeliang Tang 34515e986ec4SGeliang Tang # userspace pm create destroy subflow 3452f2b492b0SMatthieu Baerts if reset_with_events "userspace pm create destroy subflow" && 3453f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34545e986ec4SGeliang Tang set_userspace_pm $ns2 34555e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 34561c6d07ddSGeliang Tang speed=5 \ 3457e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 34584369c198SGeliang Tang local tests_pid=$! 34594369c198SGeliang Tang wait_mpj $ns2 34609d71f43aSGeliang Tang userspace_pm_add_sf $ns2 10.0.3.2 20 34615e986ec4SGeliang Tang chk_join_nr 1 1 1 3462d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3463f9190d79SGeliang Tang chk_subflows_total 2 2 34649d71f43aSGeliang Tang userspace_pm_rm_addr $ns2 20 34659d71f43aSGeliang Tang userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED 34666c160b63SGeliang Tang chk_rm_nr 1 1 3467d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3468f9190d79SGeliang Tang chk_subflows_total 1 1 3469a3735625SGeliang Tang kill_events_pids 3470a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 34715e986ec4SGeliang Tang fi 34725ac1d2d6SMat Martineau} 34735ac1d2d6SMat Martineau 3474e274f715SPaolo Abeniendpoint_tests() 347569c6ce7bSPaolo Abeni{ 347636c4127aSMatthieu Baerts # subflow_rebuild_header is needed to support the implicit flag 347769c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 347836c4127aSMatthieu Baerts if reset "implicit EP" && 347936c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 348069c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 348169c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 348269c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3483e571fb09SGeliang Tang speed=slow \ 3484358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3485358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 348669c6ce7bSPaolo Abeni 348769c6ce7bSPaolo Abeni wait_mpj $ns1 348803668c65SMatthieu Baerts pm_nl_check_endpoint "creation" \ 348969c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 3490d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3491d7ced753SGeliang Tang chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 349269c6ce7bSPaolo Abeni 34931dc88d24SMatthieu Baerts pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null 349403668c65SMatthieu Baerts pm_nl_check_endpoint "ID change is prevented" \ 349569c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 349669c6ce7bSPaolo Abeni 349769c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 349803668c65SMatthieu Baerts pm_nl_check_endpoint "modif is allowed" \ 349969c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3500358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3501ae7bd9ccSMatthieu Baerts fi 3502e274f715SPaolo Abeni 350336c4127aSMatthieu Baerts if reset "delete and re-add" && 350436c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3505e274f715SPaolo Abeni pm_nl_set_limits $ns1 1 1 3506e274f715SPaolo Abeni pm_nl_set_limits $ns2 1 1 3507e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3508e571fb09SGeliang Tang test_linkfail=4 speed=20 \ 3509358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3510358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 3511e274f715SPaolo Abeni 3512e274f715SPaolo Abeni wait_mpj $ns2 3513117eed29SGeliang Tang pm_nl_check_endpoint "creation" \ 3514117eed29SGeliang Tang $ns2 10.0.2.2 id 2 flags subflow dev ns2eth2 351503668c65SMatthieu Baerts chk_subflow_nr "before delete" 2 3516d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 35179095ce97SGeliang Tang 3518e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3519e274f715SPaolo Abeni sleep 0.5 352003668c65SMatthieu Baerts chk_subflow_nr "after delete" 1 3521d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3522e274f715SPaolo Abeni 3523e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3524e274f715SPaolo Abeni wait_mpj $ns2 352503668c65SMatthieu Baerts chk_subflow_nr "after re-add" 2 3526d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3527358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3528e274f715SPaolo Abeni fi 352969c6ce7bSPaolo Abeni} 353069c6ce7bSPaolo Abeni 353122514d52SMatthieu Baerts# [$1: error message] 35321002b89fSGeliang Tangusage() 35331002b89fSGeliang Tang{ 353422514d52SMatthieu Baerts if [ -n "${1}" ]; then 353522514d52SMatthieu Baerts echo "${1}" 353622514d52SMatthieu Baerts ret=1 353722514d52SMatthieu Baerts fi 353822514d52SMatthieu Baerts 35391002b89fSGeliang Tang echo "mptcp_join usage:" 35403afd0280SMatthieu Baerts 35413afd0280SMatthieu Baerts local key 35423afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 35433afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 35443afd0280SMatthieu Baerts done 35453afd0280SMatthieu Baerts 3546a673321aSMat Martineau echo " -c capture pcap files" 3547af66d3e1SGeliang Tang echo " -C enable data checksum" 3548621bd393SGeliang Tang echo " -i use ip mptcp" 35491002b89fSGeliang Tang echo " -h help" 355022514d52SMatthieu Baerts 3551c7d49c03SMatthieu Baerts echo "[test ids|names]" 3552ae7bd9ccSMatthieu Baerts 355322514d52SMatthieu Baerts exit ${ret} 35541002b89fSGeliang Tang} 35551002b89fSGeliang Tang 3556a673321aSMat Martineau 35573afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 35583afd0280SMatthieu Baertsall_tests_sorted=( 35593afd0280SMatthieu Baerts f@subflows_tests 35603afd0280SMatthieu Baerts e@subflows_error_tests 35613afd0280SMatthieu Baerts s@signal_address_tests 35623afd0280SMatthieu Baerts l@link_failure_tests 35633afd0280SMatthieu Baerts t@add_addr_timeout_tests 35643afd0280SMatthieu Baerts r@remove_tests 35653afd0280SMatthieu Baerts a@add_tests 35663afd0280SMatthieu Baerts 6@ipv6_tests 35673afd0280SMatthieu Baerts 4@v4mapped_tests 3568ad349374SPaolo Abeni M@mixed_tests 35693afd0280SMatthieu Baerts b@backup_tests 35703afd0280SMatthieu Baerts p@add_addr_ports_tests 35713afd0280SMatthieu Baerts k@syncookies_tests 35723afd0280SMatthieu Baerts S@checksum_tests 35733afd0280SMatthieu Baerts d@deny_join_id0_tests 35743afd0280SMatthieu Baerts m@fullmesh_tests 35753afd0280SMatthieu Baerts z@fastclose_tests 3576b6e074e1SGeliang Tang F@fail_tests 35775ac1d2d6SMat Martineau u@userspace_tests 3578e274f715SPaolo Abeni I@endpoint_tests 35793afd0280SMatthieu Baerts) 35803afd0280SMatthieu Baerts 35813afd0280SMatthieu Baertsall_tests_args="" 35823afd0280SMatthieu Baertsall_tests_names=() 35833afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 35843afd0280SMatthieu Baerts key="${subtests%@*}" 35853afd0280SMatthieu Baerts value="${subtests#*@}" 35863afd0280SMatthieu Baerts 35873afd0280SMatthieu Baerts all_tests_args+="${key}" 35883afd0280SMatthieu Baerts all_tests_names+=("${value}") 35893afd0280SMatthieu Baerts all_tests[${key}]="${value}" 35903afd0280SMatthieu Baertsdone 35913afd0280SMatthieu Baerts 3592826d7bdcSMatthieu Baertstests=() 35933afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 35941002b89fSGeliang Tang case $opt in 35953afd0280SMatthieu Baerts ["${all_tests_args}"]) 35963afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 359769c6ce7bSPaolo Abeni ;; 3598a673321aSMat Martineau c) 3599826d7bdcSMatthieu Baerts capture=1 3600a673321aSMat Martineau ;; 3601af66d3e1SGeliang Tang C) 3602826d7bdcSMatthieu Baerts checksum=1 3603af66d3e1SGeliang Tang ;; 3604621bd393SGeliang Tang i) 3605826d7bdcSMatthieu Baerts ip_mptcp=1 3606621bd393SGeliang Tang ;; 360722514d52SMatthieu Baerts h) 36081002b89fSGeliang Tang usage 36091002b89fSGeliang Tang ;; 361022514d52SMatthieu Baerts *) 361122514d52SMatthieu Baerts usage "Unknown option: -${opt}" 361222514d52SMatthieu Baerts ;; 36131002b89fSGeliang Tang esac 36141002b89fSGeliang Tangdone 361500587187SFlorian Westphal 3616ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3617ae7bd9ccSMatthieu Baerts 3618ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3619ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3620c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3621ae7bd9ccSMatthieu Baerts else 3622c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3623ae7bd9ccSMatthieu Baerts fi 3624ae7bd9ccSMatthieu Baertsdone 3625ae7bd9ccSMatthieu Baerts 3626826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 36273afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 36283afd0280SMatthieu Baertsfi 36293afd0280SMatthieu Baerts 3630826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3631826d7bdcSMatthieu Baerts "${subtests}" 3632826d7bdcSMatthieu Baertsdone 3633826d7bdcSMatthieu Baerts 363439aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 363539aab882SMatthieu Baerts echo 363639aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 363739aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 363839aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 363939aab882SMatthieu Baerts done 364039aab882SMatthieu Baerts echo 364139aab882SMatthieu Baertsfi 364239aab882SMatthieu Baerts 36437f117cd3SMatthieu Baertsappend_prev_results 36447f117cd3SMatthieu Baertsmptcp_lib_result_print_all_tap 36457f117cd3SMatthieu Baerts 3646b08fbf24SPaolo Abeniexit $ret 3647