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 1620c4cd3f8SMatthieu Baerts # Use the legacy version if available to support old kernel versions 1630c4cd3f8SMatthieu Baerts if iptables-legacy -V &> /dev/null; then 1640c4cd3f8SMatthieu Baerts iptables="iptables-legacy" 1650c4cd3f8SMatthieu Baerts ip6tables="ip6tables-legacy" 1660c4cd3f8SMatthieu Baerts elif ! iptables -V &> /dev/null; then 16787154755SMatthieu Baerts echo "SKIP: Could not run all tests without iptables tool" 16887154755SMatthieu Baerts exit $ksft_skip 169016e7ba4SMatthieu Baerts elif ! ip6tables -V &> /dev/null; then 17087154755SMatthieu Baerts echo "SKIP: Could not run all tests without ip6tables tool" 17187154755SMatthieu Baerts exit $ksft_skip 17287154755SMatthieu Baerts fi 17387154755SMatthieu Baerts} 17487154755SMatthieu Baerts 17593827ad5SMatthieu Baertsinit() { 17693827ad5SMatthieu Baerts init=1 17793827ad5SMatthieu Baerts 17887154755SMatthieu Baerts check_tools 17987154755SMatthieu Baerts 18093827ad5SMatthieu Baerts sin=$(mktemp) 18193827ad5SMatthieu Baerts sout=$(mktemp) 18293827ad5SMatthieu Baerts cin=$(mktemp) 18393827ad5SMatthieu Baerts cinsent=$(mktemp) 18493827ad5SMatthieu Baerts cout=$(mktemp) 185a3735625SGeliang Tang evts_ns1=$(mktemp) 186a3735625SGeliang Tang evts_ns2=$(mktemp) 18793827ad5SMatthieu Baerts 18893827ad5SMatthieu Baerts trap cleanup EXIT 18993827ad5SMatthieu Baerts 19003668c65SMatthieu Baerts make_file "$cin" "client" 1 >/dev/null 19103668c65SMatthieu Baerts make_file "$sin" "server" 1 >/dev/null 19293827ad5SMatthieu Baerts} 19393827ad5SMatthieu Baerts 194b08fbf24SPaolo Abenicleanup() 195b08fbf24SPaolo Abeni{ 1967d1e6f16SPaolo Abeni rm -f "$cin" "$cout" "$sinfail" 1977d1e6f16SPaolo Abeni rm -f "$sin" "$sout" "$cinsent" "$cinfail" 198d328fe87SMatthieu Baerts rm -f "$tmpfile" 199a3735625SGeliang Tang rm -rf $evts_ns1 $evts_ns2 200b08fbf24SPaolo Abeni cleanup_partial 201b08fbf24SPaolo Abeni} 202b08fbf24SPaolo Abeni 203cdb50525SMatthieu Baertsprint_title() 204cdb50525SMatthieu Baerts{ 20503668c65SMatthieu Baerts printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}" 20603668c65SMatthieu Baerts} 20703668c65SMatthieu Baerts 20803668c65SMatthieu Baertsprint_check() 20903668c65SMatthieu Baerts{ 21003668c65SMatthieu Baerts printf "%-${nr_blank}s%-36s" " " "${*}" 21103668c65SMatthieu Baerts} 21203668c65SMatthieu Baerts 21303668c65SMatthieu Baertsprint_info() 21403668c65SMatthieu Baerts{ 21503668c65SMatthieu Baerts # It can be empty, no need to print anything then 21603668c65SMatthieu Baerts [ -z "${1}" ] && return 21703668c65SMatthieu Baerts 2189466df1aSMatthieu Baerts mptcp_lib_print_info " Info: ${*}" 21903668c65SMatthieu Baerts} 22003668c65SMatthieu Baerts 22103668c65SMatthieu Baertsprint_ok() 22203668c65SMatthieu Baerts{ 2239466df1aSMatthieu Baerts mptcp_lib_print_ok "[ ok ]${1:+ ${*}}" 22403668c65SMatthieu Baerts} 22503668c65SMatthieu Baerts 22603668c65SMatthieu Baertsprint_fail() 22703668c65SMatthieu Baerts{ 2289466df1aSMatthieu Baerts mptcp_lib_print_err "[fail]${1:+ ${*}}" 22903668c65SMatthieu Baerts} 23003668c65SMatthieu Baerts 23103668c65SMatthieu Baertsprint_skip() 23203668c65SMatthieu Baerts{ 2339466df1aSMatthieu Baerts mptcp_lib_print_warn "[skip]${1:+ ${*}}" 234cdb50525SMatthieu Baerts} 235cdb50525SMatthieu Baerts 236cdb50525SMatthieu Baerts# [ $1: fail msg ] 237cdb50525SMatthieu Baertsmark_as_skipped() 238cdb50525SMatthieu Baerts{ 239cdb50525SMatthieu Baerts local msg="${1:-"Feature not supported"}" 240cdb50525SMatthieu Baerts 241cdb50525SMatthieu Baerts mptcp_lib_fail_if_expected_feature "${msg}" 242cdb50525SMatthieu Baerts 24303668c65SMatthieu Baerts print_check "${msg}" 24403668c65SMatthieu Baerts print_skip 2457f117cd3SMatthieu Baerts 2467f117cd3SMatthieu Baerts last_test_skipped=1 247cdb50525SMatthieu Baerts} 248cdb50525SMatthieu Baerts 249cdb50525SMatthieu Baerts# $@: condition 250cdb50525SMatthieu Baertscontinue_if() 251cdb50525SMatthieu Baerts{ 252cdb50525SMatthieu Baerts if ! "${@}"; then 253cdb50525SMatthieu Baerts mark_as_skipped 254cdb50525SMatthieu Baerts return 1 255cdb50525SMatthieu Baerts fi 256cdb50525SMatthieu Baerts} 257cdb50525SMatthieu Baerts 258ae7bd9ccSMatthieu Baertsskip_test() 259ae7bd9ccSMatthieu Baerts{ 260c7d49c03SMatthieu Baerts if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 261ae7bd9ccSMatthieu Baerts return 1 262ae7bd9ccSMatthieu Baerts fi 263ae7bd9ccSMatthieu Baerts 264ae7bd9ccSMatthieu Baerts local i 265c7d49c03SMatthieu Baerts for i in "${only_tests_ids[@]}"; do 266ae7bd9ccSMatthieu Baerts if [ "${TEST_COUNT}" -eq "${i}" ]; then 267ae7bd9ccSMatthieu Baerts return 1 268ae7bd9ccSMatthieu Baerts fi 269ae7bd9ccSMatthieu Baerts done 270c7d49c03SMatthieu Baerts for i in "${only_tests_names[@]}"; do 271c7d49c03SMatthieu Baerts if [ "${TEST_NAME}" = "${i}" ]; then 272c7d49c03SMatthieu Baerts return 1 273c7d49c03SMatthieu Baerts fi 274c7d49c03SMatthieu Baerts done 275ae7bd9ccSMatthieu Baerts 276ae7bd9ccSMatthieu Baerts return 0 277ae7bd9ccSMatthieu Baerts} 278ae7bd9ccSMatthieu Baerts 2797f117cd3SMatthieu Baertsappend_prev_results() 2807f117cd3SMatthieu Baerts{ 2817f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 1 ]; then 2827f117cd3SMatthieu Baerts mptcp_lib_result_fail "${TEST_NAME}" 2837f117cd3SMatthieu Baerts elif [ ${last_test_skipped} -eq 1 ]; then 2847f117cd3SMatthieu Baerts mptcp_lib_result_skip "${TEST_NAME}" 2857f117cd3SMatthieu Baerts elif [ ${last_test_ignored} -ne 1 ]; then 2867f117cd3SMatthieu Baerts mptcp_lib_result_pass "${TEST_NAME}" 2877f117cd3SMatthieu Baerts fi 2887f117cd3SMatthieu Baerts 2897f117cd3SMatthieu Baerts last_test_failed=0 2907f117cd3SMatthieu Baerts last_test_skipped=0 2917f117cd3SMatthieu Baerts last_test_ignored=0 2927f117cd3SMatthieu Baerts} 2937f117cd3SMatthieu Baerts 294c7d49c03SMatthieu Baerts# $1: test name 295b08fbf24SPaolo Abenireset() 296b08fbf24SPaolo Abeni{ 2977f117cd3SMatthieu Baerts append_prev_results 2987f117cd3SMatthieu Baerts 299c7d49c03SMatthieu Baerts TEST_NAME="${1}" 300c7d49c03SMatthieu Baerts 301ae7bd9ccSMatthieu Baerts TEST_COUNT=$((TEST_COUNT+1)) 302ae7bd9ccSMatthieu Baerts 303ae7bd9ccSMatthieu Baerts if skip_test; then 3047f117cd3SMatthieu Baerts last_test_ignored=1 305ae7bd9ccSMatthieu Baerts return 1 306ae7bd9ccSMatthieu Baerts fi 307ae7bd9ccSMatthieu Baerts 30803668c65SMatthieu Baerts print_title 30903668c65SMatthieu Baerts 31093827ad5SMatthieu Baerts if [ "${init}" != "1" ]; then 311b08fbf24SPaolo Abeni init 31293827ad5SMatthieu Baerts else 31393827ad5SMatthieu Baerts cleanup_partial 31493827ad5SMatthieu Baerts fi 31593827ad5SMatthieu Baerts 31693827ad5SMatthieu Baerts init_partial 317ae7bd9ccSMatthieu Baerts 318ae7bd9ccSMatthieu Baerts return 0 319b08fbf24SPaolo Abeni} 320b08fbf24SPaolo Abeni 321ae947bb2SMatthieu Baerts# $1: test name ; $2: counter to check 322ae947bb2SMatthieu Baertsreset_check_counter() 323ae947bb2SMatthieu Baerts{ 324ae947bb2SMatthieu Baerts reset "${1}" || return 1 325ae947bb2SMatthieu Baerts 326ae947bb2SMatthieu Baerts local counter="${2}" 327ae947bb2SMatthieu Baerts 328ae947bb2SMatthieu Baerts if ! nstat -asz "${counter}" | grep -wq "${counter}"; then 329ae947bb2SMatthieu Baerts mark_as_skipped "counter '${counter}' is not available" 330ae947bb2SMatthieu Baerts return 1 331ae947bb2SMatthieu Baerts fi 332ae947bb2SMatthieu Baerts} 333ae947bb2SMatthieu Baerts 334c7d49c03SMatthieu Baerts# $1: test name 33500587187SFlorian Westphalreset_with_cookies() 33600587187SFlorian Westphal{ 337c7d49c03SMatthieu Baerts reset "${1}" || return 1 33800587187SFlorian Westphal 3391e777bd8SMatthieu Baerts local netns 34000587187SFlorian Westphal for netns in "$ns1" "$ns2"; do 34100587187SFlorian Westphal ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 34200587187SFlorian Westphal done 34300587187SFlorian Westphal} 34400587187SFlorian Westphal 345c7d49c03SMatthieu Baerts# $1: test name 3468d014eaaSGeliang Tangreset_with_add_addr_timeout() 3478d014eaaSGeliang Tang{ 348c7d49c03SMatthieu Baerts local ip="${2:-4}" 3498d014eaaSGeliang Tang local tables 3508d014eaaSGeliang Tang 351c7d49c03SMatthieu Baerts reset "${1}" || return 1 352c7d49c03SMatthieu Baerts 3530c4cd3f8SMatthieu Baerts tables="${iptables}" 3548d014eaaSGeliang Tang if [ $ip -eq 6 ]; then 3550c4cd3f8SMatthieu Baerts tables="${ip6tables}" 3568d014eaaSGeliang Tang fi 3578d014eaaSGeliang Tang 3588d014eaaSGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 3594a0b866aSMatthieu Baerts 3604a0b866aSMatthieu Baerts if ! ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 3618d014eaaSGeliang Tang -m tcp --tcp-option 30 \ 3628d014eaaSGeliang Tang -m bpf --bytecode \ 3638d014eaaSGeliang Tang "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 3644a0b866aSMatthieu Baerts -j DROP; then 3654a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'add addr' rule" 3664a0b866aSMatthieu Baerts return 1 3674a0b866aSMatthieu Baerts fi 3688d014eaaSGeliang Tang} 3698d014eaaSGeliang Tang 370c7d49c03SMatthieu Baerts# $1: test name 371af66d3e1SGeliang Tangreset_with_checksum() 372af66d3e1SGeliang Tang{ 373af66d3e1SGeliang Tang local ns1_enable=$1 374af66d3e1SGeliang Tang local ns2_enable=$2 375af66d3e1SGeliang Tang 376c7d49c03SMatthieu Baerts reset "checksum test ${1} ${2}" || return 1 377af66d3e1SGeliang Tang 378af66d3e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 379af66d3e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 3803c082695SGeliang Tang 3813c082695SGeliang Tang validate_checksum=1 382af66d3e1SGeliang Tang} 383af66d3e1SGeliang Tang 3840cddb4a6SGeliang Tangreset_with_allow_join_id0() 3850cddb4a6SGeliang Tang{ 386c7d49c03SMatthieu Baerts local ns1_enable=$2 387c7d49c03SMatthieu Baerts local ns2_enable=$3 3880cddb4a6SGeliang Tang 389c7d49c03SMatthieu Baerts reset "${1}" || return 1 3900cddb4a6SGeliang Tang 3910cddb4a6SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 3920cddb4a6SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 3930cddb4a6SGeliang Tang} 3940cddb4a6SGeliang Tang 395b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet 396b6e074e1SGeliang Tang# 397b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 398b6e074e1SGeliang Tang# carrying enough data. 399b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still 400b6e074e1SGeliang Tang# considered as valid at the TCP level. 401b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been 402b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted: 403b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options. 404b6e074e1SGeliang Tang# 405b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets 406b6e074e1SGeliang Tang# not carrying enough data: 407b6e074e1SGeliang Tang# 408b6e074e1SGeliang Tang# tc action pedit offset 162 out of bounds 409b6e074e1SGeliang Tang# 410b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data. 4114a0b866aSMatthieu Baertssetup_fail_rules() 412b6e074e1SGeliang Tang{ 413b6e074e1SGeliang Tang check_invert=1 414b6e074e1SGeliang Tang validate_checksum=1 4154a0b866aSMatthieu Baerts local i="$1" 4164a0b866aSMatthieu Baerts local ip="${2:-4}" 417b6e074e1SGeliang Tang local tables 418b6e074e1SGeliang Tang 4190c4cd3f8SMatthieu Baerts tables="${iptables}" 420b6e074e1SGeliang Tang if [ $ip -eq 6 ]; then 4210c4cd3f8SMatthieu Baerts tables="${ip6tables}" 422b6e074e1SGeliang Tang fi 423b6e074e1SGeliang Tang 424b6e074e1SGeliang Tang ip netns exec $ns2 $tables \ 425b6e074e1SGeliang Tang -t mangle \ 426b6e074e1SGeliang Tang -A OUTPUT \ 427b6e074e1SGeliang Tang -o ns2eth$i \ 428b6e074e1SGeliang Tang -p tcp \ 429b6e074e1SGeliang Tang -m length --length 150:9999 \ 430b6e074e1SGeliang Tang -m statistic --mode nth --packet 1 --every 99999 \ 4314a0b866aSMatthieu Baerts -j MARK --set-mark 42 || return ${ksft_skip} 432b6e074e1SGeliang Tang 4334a0b866aSMatthieu Baerts tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${ksft_skip} 434b6e074e1SGeliang Tang tc -n $ns2 filter add dev ns2eth$i egress \ 435b6e074e1SGeliang Tang protocol ip prio 1000 \ 436b6e074e1SGeliang Tang handle 42 fw \ 437b6e074e1SGeliang Tang action pedit munge offset 148 u8 invert \ 438b6e074e1SGeliang Tang pipe csum tcp \ 4394a0b866aSMatthieu Baerts index 100 || return ${ksft_skip} 4404a0b866aSMatthieu Baerts} 4414a0b866aSMatthieu Baerts 4424a0b866aSMatthieu Baertsreset_with_fail() 4434a0b866aSMatthieu Baerts{ 444ff8897b5SMatthieu Baerts reset_check_counter "${1}" "MPTcpExtInfiniteMapTx" || return 1 4454a0b866aSMatthieu Baerts shift 4464a0b866aSMatthieu Baerts 4474a0b866aSMatthieu Baerts ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 4484a0b866aSMatthieu Baerts ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 4494a0b866aSMatthieu Baerts 4504a0b866aSMatthieu Baerts local rc=0 4514a0b866aSMatthieu Baerts setup_fail_rules "${@}" || rc=$? 4524a0b866aSMatthieu Baerts 4534a0b866aSMatthieu Baerts if [ ${rc} -eq ${ksft_skip} ]; then 4544a0b866aSMatthieu Baerts mark_as_skipped "unable to set the 'fail' rules" 4554a0b866aSMatthieu Baerts return 1 4564a0b866aSMatthieu Baerts fi 457b6e074e1SGeliang Tang} 458b6e074e1SGeliang Tang 459a3735625SGeliang Tangreset_with_events() 460a3735625SGeliang Tang{ 461a3735625SGeliang Tang reset "${1}" || return 1 462a3735625SGeliang Tang 463a3735625SGeliang Tang :> "$evts_ns1" 464a3735625SGeliang Tang :> "$evts_ns2" 465a3735625SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 466a3735625SGeliang Tang evts_ns1_pid=$! 467a3735625SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 468a3735625SGeliang Tang evts_ns2_pid=$! 469a3735625SGeliang Tang} 470a3735625SGeliang Tang 4714a0b866aSMatthieu Baertsreset_with_tcp_filter() 4724a0b866aSMatthieu Baerts{ 4734a0b866aSMatthieu Baerts reset "${1}" || return 1 4744a0b866aSMatthieu Baerts shift 4754a0b866aSMatthieu Baerts 4764a0b866aSMatthieu Baerts local ns="${!1}" 4774a0b866aSMatthieu Baerts local src="${2}" 4784a0b866aSMatthieu Baerts local target="${3}" 4794a0b866aSMatthieu Baerts 4804a0b866aSMatthieu Baerts if ! ip netns exec "${ns}" ${iptables} \ 4814a0b866aSMatthieu Baerts -A INPUT \ 4824a0b866aSMatthieu Baerts -s "${src}" \ 4834a0b866aSMatthieu Baerts -p tcp \ 4844a0b866aSMatthieu Baerts -j "${target}"; then 4854a0b866aSMatthieu Baerts mark_as_skipped "unable to set the filter rules" 4864a0b866aSMatthieu Baerts return 1 4874a0b866aSMatthieu Baerts fi 4884a0b866aSMatthieu Baerts} 4894a0b866aSMatthieu Baerts 49003668c65SMatthieu Baerts# $1: err msg 49139aab882SMatthieu Baertsfail_test() 49239aab882SMatthieu Baerts{ 49339aab882SMatthieu Baerts ret=1 494985de459SPaolo Abeni 49503668c65SMatthieu Baerts print_fail "${@}" 49603668c65SMatthieu Baerts 4977f117cd3SMatthieu Baerts # just in case a test is marked twice as failed 4987f117cd3SMatthieu Baerts if [ ${last_test_failed} -eq 0 ]; then 4997f117cd3SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 5007f117cd3SMatthieu Baerts dump_stats 5017f117cd3SMatthieu Baerts last_test_failed=1 5027f117cd3SMatthieu Baerts fi 50339aab882SMatthieu Baerts} 50439aab882SMatthieu Baerts 50539aab882SMatthieu Baertsget_failed_tests_ids() 50639aab882SMatthieu Baerts{ 50739aab882SMatthieu Baerts # sorted 50839aab882SMatthieu Baerts local i 50939aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 51039aab882SMatthieu Baerts echo "${i}" 51139aab882SMatthieu Baerts done | sort -n 51239aab882SMatthieu Baerts} 51339aab882SMatthieu Baerts 5148b819a84SFlorian Westphalprint_file_err() 5158b819a84SFlorian Westphal{ 5168b819a84SFlorian Westphal ls -l "$1" 1>&2 51703668c65SMatthieu Baerts echo -n "Trailing bytes are: " 5188b819a84SFlorian Westphal tail -c 27 "$1" 5198b819a84SFlorian Westphal} 5208b819a84SFlorian Westphal 521b08fbf24SPaolo Abenicheck_transfer() 522b08fbf24SPaolo Abeni{ 5231e777bd8SMatthieu Baerts local in=$1 5241e777bd8SMatthieu Baerts local out=$2 5251e777bd8SMatthieu Baerts local what=$3 5266bf41020SPaolo Abeni local bytes=$4 527d8d08302SMatthieu Baerts local i a b 528b08fbf24SPaolo Abeni 5291e777bd8SMatthieu Baerts local line 5306bf41020SPaolo Abeni if [ -n "$bytes" ]; then 5310fcd72dfSMatthieu Baerts local out_size 5326bf41020SPaolo Abeni # when truncating we must check the size explicitly 5330fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 5346bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 53503668c65SMatthieu Baerts fail_test "$what output file has wrong size ($out_size, $bytes)" 5366bf41020SPaolo Abeni return 1 5376bf41020SPaolo Abeni fi 538d328fe87SMatthieu Baerts 539d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 540d328fe87SMatthieu Baerts tmpfile=$(mktemp) 541d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 542d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 543d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 544d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 545d328fe87SMatthieu Baerts tmpfile="" 5466bf41020SPaolo Abeni fi 547d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 548d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 5498117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 55003668c65SMatthieu Baerts fail_test "$what does not match (in, out):" 551b08fbf24SPaolo Abeni print_file_err "$in" 552b08fbf24SPaolo Abeni print_file_err "$out" 553b08fbf24SPaolo Abeni 554b08fbf24SPaolo Abeni return 1 5558117dac3SGeliang Tang else 55603668c65SMatthieu Baerts print_info "$what has inverted byte at ${i}" 557b08fbf24SPaolo Abeni fi 5588117dac3SGeliang Tang done 559b08fbf24SPaolo Abeni 560b08fbf24SPaolo Abeni return 0 561b08fbf24SPaolo Abeni} 562b08fbf24SPaolo Abeni 563b08fbf24SPaolo Abenido_ping() 564b08fbf24SPaolo Abeni{ 5651e777bd8SMatthieu Baerts local listener_ns="$1" 5661e777bd8SMatthieu Baerts local connector_ns="$2" 5671e777bd8SMatthieu Baerts local connect_addr="$3" 568b08fbf24SPaolo Abeni 569d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 57003668c65SMatthieu Baerts fail_test "$listener_ns -> $connect_addr connectivity" 571b08fbf24SPaolo Abeni fi 572b08fbf24SPaolo Abeni} 573b08fbf24SPaolo Abeni 5748b819a84SFlorian Westphallink_failure() 5758b819a84SFlorian Westphal{ 5761e777bd8SMatthieu Baerts local ns="$1" 5778b819a84SFlorian Westphal 5787d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 5798b819a84SFlorian Westphal l=$((RANDOM%4)) 5807d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 5817d1e6f16SPaolo Abeni fi 5828b819a84SFlorian Westphal 5831e777bd8SMatthieu Baerts local l 5847d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 5851e777bd8SMatthieu Baerts local veth="ns1eth$l" 5868b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 5877d1e6f16SPaolo Abeni done 5888b819a84SFlorian Westphal} 5898b819a84SFlorian Westphal 590523514edSGeliang Tang# $1: IP address 591523514edSGeliang Tangis_v6() 592523514edSGeliang Tang{ 593523514edSGeliang Tang [ -z "${1##*:*}" ] 594523514edSGeliang Tang} 595523514edSGeliang Tang 596327b9a94SPaolo Abeni# $1: ns, $2: port 597327b9a94SPaolo Abeniwait_local_port_listen() 598327b9a94SPaolo Abeni{ 599327b9a94SPaolo Abeni local listener_ns="${1}" 600327b9a94SPaolo Abeni local port="${2}" 601327b9a94SPaolo Abeni 6021e777bd8SMatthieu Baerts local port_hex 603327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 6041e777bd8SMatthieu Baerts 6051e777bd8SMatthieu Baerts local i 606327b9a94SPaolo Abeni for i in $(seq 10); do 607327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 608327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 609327b9a94SPaolo Abeni break 610327b9a94SPaolo Abeni sleep 0.1 611327b9a94SPaolo Abeni done 612327b9a94SPaolo Abeni} 613327b9a94SPaolo Abeni 61447867f0aSMatthieu Baerts# $1: ns ; $2: counter 61547867f0aSMatthieu Baertsget_counter() 61647867f0aSMatthieu Baerts{ 61747867f0aSMatthieu Baerts local ns="${1}" 61847867f0aSMatthieu Baerts local counter="${2}" 61947867f0aSMatthieu Baerts local count 62047867f0aSMatthieu Baerts 62147867f0aSMatthieu Baerts count=$(ip netns exec ${ns} nstat -asz "${counter}" | awk 'NR==1 {next} {print $2}') 62247867f0aSMatthieu Baerts if [ -z "${count}" ]; then 62347867f0aSMatthieu Baerts mptcp_lib_fail_if_expected_feature "${counter} counter" 62447867f0aSMatthieu Baerts return 1 62547867f0aSMatthieu Baerts fi 62647867f0aSMatthieu Baerts 62747867f0aSMatthieu Baerts echo "${count}" 62847867f0aSMatthieu Baerts} 62947867f0aSMatthieu Baerts 630327b9a94SPaolo Abenirm_addr_count() 631327b9a94SPaolo Abeni{ 63247867f0aSMatthieu Baerts get_counter "${1}" "MPTcpExtRmAddr" 633327b9a94SPaolo Abeni} 634327b9a94SPaolo Abeni 635327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 636327b9a94SPaolo Abeniwait_rm_addr() 637327b9a94SPaolo Abeni{ 638327b9a94SPaolo Abeni local ns="${1}" 639327b9a94SPaolo Abeni local old_cnt="${2}" 640327b9a94SPaolo Abeni local cnt 641327b9a94SPaolo Abeni 6421e777bd8SMatthieu Baerts local i 643327b9a94SPaolo Abeni for i in $(seq 10); do 644327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 645327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 646327b9a94SPaolo Abeni sleep 0.1 647327b9a94SPaolo Abeni done 648327b9a94SPaolo Abeni} 649327b9a94SPaolo Abeni 6504369c198SGeliang Tangrm_sf_count() 6514369c198SGeliang Tang{ 6524369c198SGeliang Tang get_counter "${1}" "MPTcpExtRmSubflow" 6534369c198SGeliang Tang} 6544369c198SGeliang Tang 6554369c198SGeliang Tang# $1: ns, $2: old rm_sf counter in $ns 6564369c198SGeliang Tangwait_rm_sf() 6574369c198SGeliang Tang{ 6584369c198SGeliang Tang local ns="${1}" 6594369c198SGeliang Tang local old_cnt="${2}" 6604369c198SGeliang Tang local cnt 6614369c198SGeliang Tang 6624369c198SGeliang Tang local i 6634369c198SGeliang Tang for i in $(seq 10); do 6644369c198SGeliang Tang cnt=$(rm_sf_count ${ns}) 6654369c198SGeliang Tang [ "$cnt" = "${old_cnt}" ] || break 6664369c198SGeliang Tang sleep 0.1 6674369c198SGeliang Tang done 6684369c198SGeliang Tang} 6694369c198SGeliang Tang 67069c6ce7bSPaolo Abeniwait_mpj() 67169c6ce7bSPaolo Abeni{ 67269c6ce7bSPaolo Abeni local ns="${1}" 67369c6ce7bSPaolo Abeni local cnt old_cnt 67469c6ce7bSPaolo Abeni 67547867f0aSMatthieu Baerts old_cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx") 67669c6ce7bSPaolo Abeni 67769c6ce7bSPaolo Abeni local i 67869c6ce7bSPaolo Abeni for i in $(seq 10); do 67947867f0aSMatthieu Baerts cnt=$(get_counter ${ns} "MPTcpExtMPJoinAckRx") 68069c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 68169c6ce7bSPaolo Abeni sleep 0.1 68269c6ce7bSPaolo Abeni done 68369c6ce7bSPaolo Abeni} 68469c6ce7bSPaolo Abeni 685a3735625SGeliang Tangkill_events_pids() 686a3735625SGeliang Tang{ 6871fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns1_pid 6881fdb37a6SGeliang Tang mptcp_lib_kill_wait $evts_ns2_pid 689a3735625SGeliang Tang} 690a3735625SGeliang Tang 69134aa6e3bSGeliang Tangpm_nl_set_limits() 69234aa6e3bSGeliang Tang{ 69334aa6e3bSGeliang Tang local ns=$1 69434aa6e3bSGeliang Tang local addrs=$2 69534aa6e3bSGeliang Tang local subflows=$3 69634aa6e3bSGeliang Tang 69734aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 69834aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 69934aa6e3bSGeliang Tang else 70034aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 70134aa6e3bSGeliang Tang fi 70234aa6e3bSGeliang Tang} 70334aa6e3bSGeliang Tang 70434aa6e3bSGeliang Tangpm_nl_add_endpoint() 70534aa6e3bSGeliang Tang{ 70634aa6e3bSGeliang Tang local ns=$1 70734aa6e3bSGeliang Tang local addr=$2 7081e777bd8SMatthieu Baerts local flags _flags 7091e777bd8SMatthieu Baerts local port _port 7101e777bd8SMatthieu Baerts local dev _dev 7111e777bd8SMatthieu Baerts local id _id 71234aa6e3bSGeliang Tang local nr=2 71334aa6e3bSGeliang Tang 7141e777bd8SMatthieu Baerts local p 715d8d08302SMatthieu Baerts for p in "${@}" 71634aa6e3bSGeliang Tang do 71734aa6e3bSGeliang Tang if [ $p = "flags" ]; then 71834aa6e3bSGeliang Tang eval _flags=\$"$nr" 719d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 72034aa6e3bSGeliang Tang fi 72134aa6e3bSGeliang Tang if [ $p = "dev" ]; then 72234aa6e3bSGeliang Tang eval _dev=\$"$nr" 723d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 72434aa6e3bSGeliang Tang fi 72534aa6e3bSGeliang Tang if [ $p = "id" ]; then 72634aa6e3bSGeliang Tang eval _id=\$"$nr" 727d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 72834aa6e3bSGeliang Tang fi 72934aa6e3bSGeliang Tang if [ $p = "port" ]; then 73034aa6e3bSGeliang Tang eval _port=\$"$nr" 731d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 73234aa6e3bSGeliang Tang fi 73334aa6e3bSGeliang Tang 734d8d08302SMatthieu Baerts nr=$((nr + 1)) 73534aa6e3bSGeliang Tang done 73634aa6e3bSGeliang Tang 73734aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 73834aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 73934aa6e3bSGeliang Tang else 74034aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 74134aa6e3bSGeliang Tang fi 74234aa6e3bSGeliang Tang} 74334aa6e3bSGeliang Tang 74434aa6e3bSGeliang Tangpm_nl_del_endpoint() 74534aa6e3bSGeliang Tang{ 74634aa6e3bSGeliang Tang local ns=$1 74734aa6e3bSGeliang Tang local id=$2 74834aa6e3bSGeliang Tang local addr=$3 74934aa6e3bSGeliang Tang 75034aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 751aaf2123aSAndrea Claudi [ $id -ne 0 ] && addr='' 75234aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 75334aa6e3bSGeliang Tang else 75434aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 75534aa6e3bSGeliang Tang fi 75634aa6e3bSGeliang Tang} 75734aa6e3bSGeliang Tang 75834aa6e3bSGeliang Tangpm_nl_flush_endpoint() 75934aa6e3bSGeliang Tang{ 76034aa6e3bSGeliang Tang local ns=$1 76134aa6e3bSGeliang Tang 76234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 76334aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 76434aa6e3bSGeliang Tang else 76534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 76634aa6e3bSGeliang Tang fi 76734aa6e3bSGeliang Tang} 76834aa6e3bSGeliang Tang 769dda61b3dSGeliang Tangpm_nl_show_endpoints() 770dda61b3dSGeliang Tang{ 771dda61b3dSGeliang Tang local ns=$1 772dda61b3dSGeliang Tang 773dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 774dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 775dda61b3dSGeliang Tang else 776dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 777dda61b3dSGeliang Tang fi 778dda61b3dSGeliang Tang} 779dda61b3dSGeliang Tang 780f0140386SGeliang Tangpm_nl_change_endpoint() 781f0140386SGeliang Tang{ 782f0140386SGeliang Tang local ns=$1 783bccefb76SGeliang Tang local id=$2 784bccefb76SGeliang Tang local flags=$3 785f0140386SGeliang Tang 786f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 787f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 788f0140386SGeliang Tang else 789bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 790f0140386SGeliang Tang fi 791f0140386SGeliang Tang} 792f0140386SGeliang Tang 79369c6ce7bSPaolo Abenipm_nl_check_endpoint() 79469c6ce7bSPaolo Abeni{ 79569c6ce7bSPaolo Abeni local line expected_line 79603668c65SMatthieu Baerts local msg="$1" 79703668c65SMatthieu Baerts local ns=$2 79803668c65SMatthieu Baerts local addr=$3 79969c6ce7bSPaolo Abeni local _flags="" 80069c6ce7bSPaolo Abeni local flags 80169c6ce7bSPaolo Abeni local _port 80269c6ce7bSPaolo Abeni local port 80369c6ce7bSPaolo Abeni local dev 80469c6ce7bSPaolo Abeni local _id 80569c6ce7bSPaolo Abeni local id 80669c6ce7bSPaolo Abeni 80703668c65SMatthieu Baerts print_check "${msg}" 80869c6ce7bSPaolo Abeni 80903668c65SMatthieu Baerts shift 3 81069c6ce7bSPaolo Abeni while [ -n "$1" ]; do 81169c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 81269c6ce7bSPaolo Abeni _flags=$2 813d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 81469c6ce7bSPaolo Abeni shift 81569c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 816d8d08302SMatthieu Baerts [ -n "$2" ]; dev="dev $1" 81769c6ce7bSPaolo Abeni shift 81869c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 81969c6ce7bSPaolo Abeni _id=$2 820d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 82169c6ce7bSPaolo Abeni shift 82269c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 82369c6ce7bSPaolo Abeni _port=$2 824d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 82569c6ce7bSPaolo Abeni shift 82669c6ce7bSPaolo Abeni fi 82769c6ce7bSPaolo Abeni 82869c6ce7bSPaolo Abeni shift 82969c6ce7bSPaolo Abeni done 83069c6ce7bSPaolo Abeni 83169c6ce7bSPaolo Abeni if [ -z "$id" ]; then 83203668c65SMatthieu Baerts test_fail "bad test - missing endpoint id" 83369c6ce7bSPaolo Abeni return 83469c6ce7bSPaolo Abeni fi 83569c6ce7bSPaolo Abeni 83669c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 837c8c101aeSAndrea Claudi # get line and trim trailing whitespace 83869c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 839c8c101aeSAndrea Claudi line="${line% }" 84069c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 841c8c101aeSAndrea Claudi [ -n "$addr" ] && expected_line="$addr" 84269c6ce7bSPaolo Abeni expected_line="$expected_line $id" 84369c6ce7bSPaolo Abeni [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" 84469c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 84569c6ce7bSPaolo Abeni [ -n "$port" ] && expected_line="$expected_line $port" 84669c6ce7bSPaolo Abeni else 84769c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 84869c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 84969c6ce7bSPaolo Abeni expected_line="$id" 85069c6ce7bSPaolo Abeni [ -n "$flags" ] && expected_line="$expected_line $flags" 85169c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 85269c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 85369c6ce7bSPaolo Abeni [ -n "$_port" ] && expected_line="$expected_line $_port" 85469c6ce7bSPaolo Abeni fi 85569c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 85603668c65SMatthieu Baerts print_ok 85769c6ce7bSPaolo Abeni else 85803668c65SMatthieu Baerts fail_test "expected '$expected_line' found '$line'" 85969c6ce7bSPaolo Abeni fi 86069c6ce7bSPaolo Abeni} 86169c6ce7bSPaolo Abeni 8629e9d176dSGeliang Tangpm_nl_set_endpoint() 863b08fbf24SPaolo Abeni{ 8641e777bd8SMatthieu Baerts local listener_ns="$1" 8651e777bd8SMatthieu Baerts local connector_ns="$2" 8669e9d176dSGeliang Tang local connect_addr="$3" 867b08fbf24SPaolo Abeni 868662aa22dSGeliang Tang local addr_nr_ns1=${addr_nr_ns1:-0} 869662aa22dSGeliang Tang local addr_nr_ns2=${addr_nr_ns2:-0} 870662aa22dSGeliang Tang local sflags=${sflags:-""} 8714aadde08SGeliang Tang local fullmesh=${fullmesh:-""} 872662aa22dSGeliang Tang 873080b7f57SGeliang Tang local flags="subflow" 8744aadde08SGeliang Tang if [ -n "${fullmesh}" ]; then 875080b7f57SGeliang Tang flags="${flags},fullmesh" 8764aadde08SGeliang Tang addr_nr_ns2=${fullmesh} 877080b7f57SGeliang Tang fi 878080b7f57SGeliang Tang 879327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 880327b9a94SPaolo Abeni # do endpoint manipulation 881d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 882d8d08302SMatthieu Baerts sleep 1 883d8d08302SMatthieu Baerts fi 884327b9a94SPaolo Abeni 8856208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8861e777bd8SMatthieu Baerts local counter=2 887d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 88897040cf9SGeliang Tang local id=10 8896208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8906208fd82SGeliang Tang local addr 8916208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 8926208fd82SGeliang Tang addr="dead:beef:$counter::1" 8936208fd82SGeliang Tang else 8946208fd82SGeliang Tang addr="10.0.$counter.1" 8956208fd82SGeliang Tang fi 89634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 897d8d08302SMatthieu Baerts counter=$((counter + 1)) 898d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 89997040cf9SGeliang Tang id=$((id + 1)) 9006208fd82SGeliang Tang done 9016208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 902d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 9036fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 9041e777bd8SMatthieu Baerts local counter=0 9051e777bd8SMatthieu Baerts local line 906d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 907d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 908dda61b3dSGeliang Tang local arr=($line) 909dda61b3dSGeliang Tang local nr=0 910dda61b3dSGeliang Tang 9111e777bd8SMatthieu Baerts local i 912d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 913dda61b3dSGeliang Tang if [ $i = "id" ]; then 914dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 915dda61b3dSGeliang Tang break 916dda61b3dSGeliang Tang fi 917dda61b3dSGeliang Tang id=${arr[$nr+1]} 918327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 91934aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 920327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 921d8d08302SMatthieu Baerts counter=$((counter + 1)) 922f87744adSGeliang Tang fi 923d8d08302SMatthieu Baerts nr=$((nr + 1)) 924dda61b3dSGeliang Tang done 925dda61b3dSGeliang Tang done 9265e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 92734aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9285e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 92934aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9306fe4ccdcSGeliang Tang fi 931dd72b0feSGeliang Tang fi 932dd72b0feSGeliang Tang 933327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 934327b9a94SPaolo Abeni # some time to created them 935d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 936327b9a94SPaolo Abeni 9376208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 938d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9391e777bd8SMatthieu Baerts local counter=3 9405e986ec4SGeliang Tang local id=20 9416208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9426208fd82SGeliang Tang local addr 9436208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 9446208fd82SGeliang Tang addr="dead:beef:$counter::2" 9456208fd82SGeliang Tang else 9466208fd82SGeliang Tang addr="10.0.$counter.2" 9476208fd82SGeliang Tang fi 94834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 949d8d08302SMatthieu Baerts counter=$((counter + 1)) 950d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9515e986ec4SGeliang Tang id=$((id + 1)) 9526208fd82SGeliang Tang done 9536208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 954d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9556fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9561e777bd8SMatthieu Baerts local counter=0 9571e777bd8SMatthieu Baerts local line 958d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 959d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 960dda61b3dSGeliang Tang local arr=($line) 961dda61b3dSGeliang Tang local nr=0 962dda61b3dSGeliang Tang 9631e777bd8SMatthieu Baerts local i 964d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 965dda61b3dSGeliang Tang if [ $i = "id" ]; then 966dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 967dda61b3dSGeliang Tang break 968dda61b3dSGeliang Tang fi 9691e777bd8SMatthieu Baerts local id rm_addr 970dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 971dda61b3dSGeliang Tang # complete 972dda61b3dSGeliang Tang id=${arr[$nr+1]} 973327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 97434aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 975327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 976d8d08302SMatthieu Baerts counter=$((counter + 1)) 977f87744adSGeliang Tang fi 978d8d08302SMatthieu Baerts nr=$((nr + 1)) 979dda61b3dSGeliang Tang done 980dda61b3dSGeliang Tang done 9815e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 98234aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9835e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9845e287fe7SGeliang Tang local addr 9855e287fe7SGeliang Tang if is_v6 "${connect_addr}"; then 9865e287fe7SGeliang Tang addr="dead:beef:1::2" 9875e287fe7SGeliang Tang else 9885e287fe7SGeliang Tang addr="10.0.1.2" 9895e287fe7SGeliang Tang fi 99034aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9916fe4ccdcSGeliang Tang fi 992dd72b0feSGeliang Tang fi 993dd72b0feSGeliang Tang 994d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 995718eb44eSGeliang Tang sleep 1 9961e777bd8SMatthieu Baerts 9971e777bd8SMatthieu Baerts local netns 998718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9991e777bd8SMatthieu Baerts local line 1000d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 1001d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 100233397b83SGeliang Tang local arr=($line) 1003bccefb76SGeliang Tang local nr=0 1004f0140386SGeliang Tang local id 100533397b83SGeliang Tang 10061e777bd8SMatthieu Baerts local i 1007d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 1008bccefb76SGeliang Tang if [ $i = "id" ]; then 1009bccefb76SGeliang Tang id=${arr[$nr+1]} 1010718eb44eSGeliang Tang fi 1011d8d08302SMatthieu Baerts nr=$((nr + 1)) 101233397b83SGeliang Tang done 1013bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 101433397b83SGeliang Tang done 1015718eb44eSGeliang Tang done 1016718eb44eSGeliang Tang fi 10179e9d176dSGeliang Tang} 10189e9d176dSGeliang Tang 10199e9d176dSGeliang Tangdo_transfer() 10209e9d176dSGeliang Tang{ 10219e9d176dSGeliang Tang local listener_ns="$1" 10229e9d176dSGeliang Tang local connector_ns="$2" 10239e9d176dSGeliang Tang local cl_proto="$3" 10249e9d176dSGeliang Tang local srv_proto="$4" 10259e9d176dSGeliang Tang local connect_addr="$5" 10269e9d176dSGeliang Tang 10279e9d176dSGeliang Tang local port=$((10000 + TEST_COUNT - 1)) 10289e9d176dSGeliang Tang local cappid 1029662aa22dSGeliang Tang local FAILING_LINKS=${FAILING_LINKS:-""} 1030080b7f57SGeliang Tang local fastclose=${fastclose:-""} 1031e571fb09SGeliang Tang local speed=${speed:-"fast"} 10329e9d176dSGeliang Tang 10339e9d176dSGeliang Tang :> "$cout" 10349e9d176dSGeliang Tang :> "$sout" 10359e9d176dSGeliang Tang :> "$capout" 10369e9d176dSGeliang Tang 10379e9d176dSGeliang Tang if [ $capture -eq 1 ]; then 10389e9d176dSGeliang Tang local capuser 10399e9d176dSGeliang Tang if [ -z $SUDO_USER ] ; then 10409e9d176dSGeliang Tang capuser="" 10419e9d176dSGeliang Tang else 10429e9d176dSGeliang Tang capuser="-Z $SUDO_USER" 10439e9d176dSGeliang Tang fi 10449e9d176dSGeliang Tang 10459e9d176dSGeliang Tang capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 10469e9d176dSGeliang Tang 10479e9d176dSGeliang Tang echo "Capturing traffic for test $TEST_COUNT into $capfile" 10489e9d176dSGeliang Tang ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 10499e9d176dSGeliang Tang cappid=$! 10509e9d176dSGeliang Tang 10519e9d176dSGeliang Tang sleep 1 10529e9d176dSGeliang Tang fi 10539e9d176dSGeliang Tang 10549e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 10559e9d176dSGeliang Tang nstat -n 10569e9d176dSGeliang Tang NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 10579e9d176dSGeliang Tang nstat -n 10589e9d176dSGeliang Tang 10599e9d176dSGeliang Tang local extra_args 10609e9d176dSGeliang Tang if [ $speed = "fast" ]; then 10619e9d176dSGeliang Tang extra_args="-j" 10629e9d176dSGeliang Tang elif [ $speed = "slow" ]; then 10639e9d176dSGeliang Tang extra_args="-r 50" 1064e571fb09SGeliang Tang elif [ $speed -gt 0 ]; then 1065e571fb09SGeliang Tang extra_args="-r ${speed}" 10669e9d176dSGeliang Tang fi 10679e9d176dSGeliang Tang 10689e9d176dSGeliang Tang local extra_cl_args="" 10699e9d176dSGeliang Tang local extra_srv_args="" 10709e9d176dSGeliang Tang local trunc_size="" 1071080b7f57SGeliang Tang if [ -n "${fastclose}" ]; then 10729e9d176dSGeliang Tang if [ ${test_linkfail} -le 1 ]; then 107303668c65SMatthieu Baerts fail_test "fastclose tests need test_linkfail argument" 10749e9d176dSGeliang Tang return 1 10759e9d176dSGeliang Tang fi 10769e9d176dSGeliang Tang 10779e9d176dSGeliang Tang # disconnect 10789e9d176dSGeliang Tang trunc_size=${test_linkfail} 1079080b7f57SGeliang Tang local side=${fastclose} 10809e9d176dSGeliang Tang 10819e9d176dSGeliang Tang if [ ${side} = "client" ]; then 10829e9d176dSGeliang Tang extra_cl_args="-f ${test_linkfail}" 10839e9d176dSGeliang Tang extra_srv_args="-f -1" 10849e9d176dSGeliang Tang elif [ ${side} = "server" ]; then 10859e9d176dSGeliang Tang extra_srv_args="-f ${test_linkfail}" 10869e9d176dSGeliang Tang extra_cl_args="-f -1" 10879e9d176dSGeliang Tang else 108803668c65SMatthieu Baerts fail_test "wrong/unknown fastclose spec ${side}" 10899e9d176dSGeliang Tang return 1 10909e9d176dSGeliang Tang fi 10919e9d176dSGeliang Tang fi 10929e9d176dSGeliang Tang 10939e9d176dSGeliang Tang extra_srv_args="$extra_args $extra_srv_args" 10949e9d176dSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 10959e9d176dSGeliang Tang timeout ${timeout_test} \ 10969e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 10979e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 10989e9d176dSGeliang Tang $extra_srv_args "::" < "$sinfail" > "$sout" & 10999e9d176dSGeliang Tang else 11009e9d176dSGeliang Tang timeout ${timeout_test} \ 11019e9d176dSGeliang Tang ip netns exec ${listener_ns} \ 11029e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 11039e9d176dSGeliang Tang $extra_srv_args "::" < "$sin" > "$sout" & 11049e9d176dSGeliang Tang fi 11059e9d176dSGeliang Tang local spid=$! 11069e9d176dSGeliang Tang 11079e9d176dSGeliang Tang wait_local_port_listen "${listener_ns}" "${port}" 11089e9d176dSGeliang Tang 11099e9d176dSGeliang Tang extra_cl_args="$extra_args $extra_cl_args" 11109e9d176dSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11119e9d176dSGeliang Tang timeout ${timeout_test} \ 11129e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11139e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11149e9d176dSGeliang Tang $extra_cl_args $connect_addr < "$cin" > "$cout" & 11159e9d176dSGeliang Tang elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then 11169e9d176dSGeliang Tang ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 11179e9d176dSGeliang Tang tee "$cinsent" | \ 11189e9d176dSGeliang Tang timeout ${timeout_test} \ 11199e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11209e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11219e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11229e9d176dSGeliang Tang else 11239e9d176dSGeliang Tang tee "$cinsent" < "$cinfail" | \ 11249e9d176dSGeliang Tang timeout ${timeout_test} \ 11259e9d176dSGeliang Tang ip netns exec ${connector_ns} \ 11269e9d176dSGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 11279e9d176dSGeliang Tang $extra_cl_args $connect_addr > "$cout" & 11289e9d176dSGeliang Tang fi 11299e9d176dSGeliang Tang local cpid=$! 11309e9d176dSGeliang Tang 11319e9d176dSGeliang Tang pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr 1132718eb44eSGeliang Tang 1133b08fbf24SPaolo Abeni wait $cpid 11341e777bd8SMatthieu Baerts local retc=$? 1135b08fbf24SPaolo Abeni wait $spid 11361e777bd8SMatthieu Baerts local rets=$? 1137b08fbf24SPaolo Abeni 1138b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1139b08fbf24SPaolo Abeni sleep 1 1140b08fbf24SPaolo Abeni kill $cappid 1141b08fbf24SPaolo Abeni fi 1142b08fbf24SPaolo Abeni 1143c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1144c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1145c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1146c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1147c2a55e8fSMatthieu Baerts 1148b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 114903668c65SMatthieu Baerts fail_test "client exit code $retc, server $rets" 11508b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1151c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1152c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 11538b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1154c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1155c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1156b08fbf24SPaolo Abeni 1157b08fbf24SPaolo Abeni cat "$capout" 1158b08fbf24SPaolo Abeni return 1 1159b08fbf24SPaolo Abeni fi 1160b08fbf24SPaolo Abeni 11610c93af1fSGeliang Tang if [ "$test_linkfail" -gt 1 ];then 11626bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 11637d1e6f16SPaolo Abeni else 11646bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 11657d1e6f16SPaolo Abeni fi 1166b08fbf24SPaolo Abeni retc=$? 11670c93af1fSGeliang Tang if [ "$test_linkfail" -eq 0 ];then 11686bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 11698b819a84SFlorian Westphal else 11706bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 11718b819a84SFlorian Westphal fi 1172b08fbf24SPaolo Abeni rets=$? 1173b08fbf24SPaolo Abeni 1174b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1175b08fbf24SPaolo Abeni cat "$capout" 1176b08fbf24SPaolo Abeni return 0 1177b08fbf24SPaolo Abeni fi 1178b08fbf24SPaolo Abeni 1179b08fbf24SPaolo Abeni cat "$capout" 1180b08fbf24SPaolo Abeni return 1 1181b08fbf24SPaolo Abeni} 1182b08fbf24SPaolo Abeni 1183b08fbf24SPaolo Abenimake_file() 1184b08fbf24SPaolo Abeni{ 11851e777bd8SMatthieu Baerts local name=$1 11861e777bd8SMatthieu Baerts local who=$2 11871e777bd8SMatthieu Baerts local size=$3 1188b08fbf24SPaolo Abeni 11898b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1190b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1191b08fbf24SPaolo Abeni 119203668c65SMatthieu Baerts print_info "Test file (size $size KB) for $who" 1193b08fbf24SPaolo Abeni} 1194b08fbf24SPaolo Abeni 1195b08fbf24SPaolo Abenirun_tests() 1196b08fbf24SPaolo Abeni{ 11971e777bd8SMatthieu Baerts local listener_ns="$1" 11981e777bd8SMatthieu Baerts local connector_ns="$2" 11991e777bd8SMatthieu Baerts local connect_addr="$3" 12001e777bd8SMatthieu Baerts 12011e777bd8SMatthieu Baerts local size 1202662aa22dSGeliang Tang local test_linkfail=${test_linkfail:-0} 12038b819a84SFlorian Westphal 120434b572b7SGeliang Tang # The values above 2 are reused to make test files 120534b572b7SGeliang Tang # with the given sizes (KB) 120634b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 120734b572b7SGeliang Tang size=$test_linkfail 120834b572b7SGeliang Tang 120934b572b7SGeliang Tang if [ -z "$cinfail" ]; then 121034b572b7SGeliang Tang cinfail=$(mktemp) 121134b572b7SGeliang Tang fi 121234b572b7SGeliang Tang make_file "$cinfail" "client" $size 12137d1e6f16SPaolo Abeni # create the input file for the failure test when 12147d1e6f16SPaolo Abeni # the first failure test run 1215d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 12167d1e6f16SPaolo Abeni # the client file must be considerably larger 12177d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 12187d1e6f16SPaolo Abeni # link utilization will be not predicable 12197d1e6f16SPaolo Abeni size=$((RANDOM%2)) 12208b819a84SFlorian Westphal size=$((size+1)) 12217d1e6f16SPaolo Abeni size=$((size*8192)) 1222d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 12238b819a84SFlorian Westphal 12247d1e6f16SPaolo Abeni cinfail=$(mktemp) 12257d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 12267d1e6f16SPaolo Abeni fi 12277d1e6f16SPaolo Abeni 122834b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 122934b572b7SGeliang Tang size=$test_linkfail 123034b572b7SGeliang Tang 123134b572b7SGeliang Tang if [ -z "$sinfail" ]; then 123234b572b7SGeliang Tang sinfail=$(mktemp) 123334b572b7SGeliang Tang fi 123434b572b7SGeliang Tang make_file "$sinfail" "server" $size 1235d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 12367d1e6f16SPaolo Abeni size=$((RANDOM%16)) 12377d1e6f16SPaolo Abeni size=$((size+1)) 12387d1e6f16SPaolo Abeni size=$((size*2048)) 12397d1e6f16SPaolo Abeni 12407d1e6f16SPaolo Abeni sinfail=$(mktemp) 12417d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 12428b819a84SFlorian Westphal fi 1243b08fbf24SPaolo Abeni 1244e571fb09SGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} 1245b08fbf24SPaolo Abeni} 1246b08fbf24SPaolo Abeni 1247327b9a94SPaolo Abenidump_stats() 1248327b9a94SPaolo Abeni{ 1249327b9a94SPaolo Abeni echo Server ns stats 1250327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1251327b9a94SPaolo Abeni echo Client ns stats 1252327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1253327b9a94SPaolo Abeni} 1254327b9a94SPaolo Abeni 1255af66d3e1SGeliang Tangchk_csum_nr() 1256af66d3e1SGeliang Tang{ 12573c082695SGeliang Tang local csum_ns1=${1:-0} 12583c082695SGeliang Tang local csum_ns2=${2:-0} 1259af66d3e1SGeliang Tang local count 126053f368bfSGeliang Tang local extra_msg="" 126126516e10SGeliang Tang local allow_multi_errors_ns1=0 126226516e10SGeliang Tang local allow_multi_errors_ns2=0 126326516e10SGeliang Tang 126426516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 126526516e10SGeliang Tang allow_multi_errors_ns1=1 126626516e10SGeliang Tang csum_ns1=${csum_ns1:1} 126726516e10SGeliang Tang fi 126826516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 126926516e10SGeliang Tang allow_multi_errors_ns2=1 127026516e10SGeliang Tang csum_ns2=${csum_ns2:1} 127126516e10SGeliang Tang fi 1272af66d3e1SGeliang Tang 127303668c65SMatthieu Baerts print_check "sum" 127447867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtDataCsumErr") 127553f368bfSGeliang Tang if [ "$count" != "$csum_ns1" ]; then 127653f368bfSGeliang Tang extra_msg="$extra_msg ns1=$count" 127753f368bfSGeliang Tang fi 127847867f0aSMatthieu Baerts if [ -z "$count" ]; then 127903668c65SMatthieu Baerts print_skip 128047867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1281d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 128203668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns1" 1283af66d3e1SGeliang Tang else 128403668c65SMatthieu Baerts print_ok 1285af66d3e1SGeliang Tang fi 128603668c65SMatthieu Baerts print_check "csum" 128747867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtDataCsumErr") 128853f368bfSGeliang Tang if [ "$count" != "$csum_ns2" ]; then 128953f368bfSGeliang Tang extra_msg="$extra_msg ns2=$count" 129053f368bfSGeliang Tang fi 129147867f0aSMatthieu Baerts if [ -z "$count" ]; then 129203668c65SMatthieu Baerts print_skip 129347867f0aSMatthieu Baerts elif { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1294d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 129503668c65SMatthieu Baerts fail_test "got $count data checksum error[s] expected $csum_ns2" 1296af66d3e1SGeliang Tang else 129703668c65SMatthieu Baerts print_ok 1298af66d3e1SGeliang Tang fi 129953f368bfSGeliang Tang 130003668c65SMatthieu Baerts print_info "$extra_msg" 1301af66d3e1SGeliang Tang} 1302af66d3e1SGeliang Tang 13036bb3ab49SGeliang Tangchk_fail_nr() 13046bb3ab49SGeliang Tang{ 130526516e10SGeliang Tang local fail_tx=$1 130626516e10SGeliang Tang local fail_rx=$2 13071f7d325fSGeliang Tang local ns_invert=${3:-""} 13086bb3ab49SGeliang Tang local count 13091f7d325fSGeliang Tang local ns_tx=$ns1 13101f7d325fSGeliang Tang local ns_rx=$ns2 13111f7d325fSGeliang Tang local extra_msg="" 13121f7d325fSGeliang Tang local allow_tx_lost=0 13131f7d325fSGeliang Tang local allow_rx_lost=0 13141f7d325fSGeliang Tang 13151f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 13161f7d325fSGeliang Tang ns_tx=$ns2 13171f7d325fSGeliang Tang ns_rx=$ns1 13181f7d325fSGeliang Tang extra_msg="invert" 13191f7d325fSGeliang Tang fi 13201f7d325fSGeliang Tang 13211f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 13221f7d325fSGeliang Tang allow_tx_lost=1 13231f7d325fSGeliang Tang fail_tx=${fail_tx:1} 13241f7d325fSGeliang Tang fi 13251f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 13261f7d325fSGeliang Tang allow_rx_lost=1 13271f7d325fSGeliang Tang fail_rx=${fail_rx:1} 13281f7d325fSGeliang Tang fi 13296bb3ab49SGeliang Tang 133003668c65SMatthieu Baerts print_check "ftx" 133147867f0aSMatthieu Baerts count=$(get_counter ${ns_tx} "MPTcpExtMPFailTx") 133226516e10SGeliang Tang if [ "$count" != "$fail_tx" ]; then 13331f7d325fSGeliang Tang extra_msg="$extra_msg,tx=$count" 13341f7d325fSGeliang Tang fi 133547867f0aSMatthieu Baerts if [ -z "$count" ]; then 133603668c65SMatthieu Baerts print_skip 133747867f0aSMatthieu Baerts elif { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 13381f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 133903668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] TX expected $fail_tx" 13406bb3ab49SGeliang Tang else 134103668c65SMatthieu Baerts print_ok 13426bb3ab49SGeliang Tang fi 13436bb3ab49SGeliang Tang 134403668c65SMatthieu Baerts print_check "failrx" 134547867f0aSMatthieu Baerts count=$(get_counter ${ns_rx} "MPTcpExtMPFailRx") 134626516e10SGeliang Tang if [ "$count" != "$fail_rx" ]; then 13471f7d325fSGeliang Tang extra_msg="$extra_msg,rx=$count" 13481f7d325fSGeliang Tang fi 134947867f0aSMatthieu Baerts if [ -z "$count" ]; then 135003668c65SMatthieu Baerts print_skip 135147867f0aSMatthieu Baerts elif { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 13521f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 135303668c65SMatthieu Baerts fail_test "got $count MP_FAIL[s] RX expected $fail_rx" 13546bb3ab49SGeliang Tang else 135503668c65SMatthieu Baerts print_ok 13566bb3ab49SGeliang Tang fi 13576bb3ab49SGeliang Tang 135803668c65SMatthieu Baerts print_info "$extra_msg" 13596bb3ab49SGeliang Tang} 13606bb3ab49SGeliang Tang 1361e8e947efSGeliang Tangchk_fclose_nr() 1362e8e947efSGeliang Tang{ 1363e8e947efSGeliang Tang local fclose_tx=$1 1364e8e947efSGeliang Tang local fclose_rx=$2 13656bf41020SPaolo Abeni local ns_invert=$3 1366e8e947efSGeliang Tang local count 13676bf41020SPaolo Abeni local ns_tx=$ns2 13686bf41020SPaolo Abeni local ns_rx=$ns1 13696bf41020SPaolo Abeni local extra_msg="" 13706bf41020SPaolo Abeni 13716bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 13726bf41020SPaolo Abeni ns_tx=$ns1 13736bf41020SPaolo Abeni ns_rx=$ns2 137403668c65SMatthieu Baerts extra_msg="invert" 13756bf41020SPaolo Abeni fi 1376e8e947efSGeliang Tang 137703668c65SMatthieu Baerts print_check "ctx" 137847867f0aSMatthieu Baerts count=$(get_counter ${ns_tx} "MPTcpExtMPFastcloseTx") 137947867f0aSMatthieu Baerts if [ -z "$count" ]; then 138003668c65SMatthieu Baerts print_skip 138147867f0aSMatthieu Baerts elif [ "$count" != "$fclose_tx" ]; then 138247867f0aSMatthieu Baerts extra_msg="$extra_msg,tx=$count" 138303668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1384e8e947efSGeliang Tang else 138503668c65SMatthieu Baerts print_ok 1386e8e947efSGeliang Tang fi 1387e8e947efSGeliang Tang 138803668c65SMatthieu Baerts print_check "fclzrx" 138947867f0aSMatthieu Baerts count=$(get_counter ${ns_rx} "MPTcpExtMPFastcloseRx") 139047867f0aSMatthieu Baerts if [ -z "$count" ]; then 139103668c65SMatthieu Baerts print_skip 139247867f0aSMatthieu Baerts elif [ "$count" != "$fclose_rx" ]; then 139347867f0aSMatthieu Baerts extra_msg="$extra_msg,rx=$count" 139403668c65SMatthieu Baerts fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1395e8e947efSGeliang Tang else 139603668c65SMatthieu Baerts print_ok 1397e8e947efSGeliang Tang fi 1398e8e947efSGeliang Tang 139903668c65SMatthieu Baerts print_info "$extra_msg" 1400e8e947efSGeliang Tang} 1401e8e947efSGeliang Tang 1402922fd2b3SGeliang Tangchk_rst_nr() 1403922fd2b3SGeliang Tang{ 1404922fd2b3SGeliang Tang local rst_tx=$1 1405922fd2b3SGeliang Tang local rst_rx=$2 1406922fd2b3SGeliang Tang local ns_invert=${3:-""} 1407922fd2b3SGeliang Tang local count 1408922fd2b3SGeliang Tang local ns_tx=$ns1 1409922fd2b3SGeliang Tang local ns_rx=$ns2 1410922fd2b3SGeliang Tang local extra_msg="" 1411922fd2b3SGeliang Tang 1412922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1413922fd2b3SGeliang Tang ns_tx=$ns2 1414922fd2b3SGeliang Tang ns_rx=$ns1 1415922fd2b3SGeliang Tang extra_msg="invert" 1416922fd2b3SGeliang Tang fi 1417922fd2b3SGeliang Tang 141803668c65SMatthieu Baerts print_check "rtx" 141947867f0aSMatthieu Baerts count=$(get_counter ${ns_tx} "MPTcpExtMPRstTx") 142047867f0aSMatthieu Baerts if [ -z "$count" ]; then 142103668c65SMatthieu Baerts print_skip 1422b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1423b134a580SMatthieu Baerts elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } || 1424b134a580SMatthieu Baerts { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then 142503668c65SMatthieu Baerts fail_test "got $count MP_RST[s] TX expected $rst_tx" 1426922fd2b3SGeliang Tang else 142703668c65SMatthieu Baerts print_ok 1428922fd2b3SGeliang Tang fi 1429922fd2b3SGeliang Tang 143003668c65SMatthieu Baerts print_check "rstrx" 143147867f0aSMatthieu Baerts count=$(get_counter ${ns_rx} "MPTcpExtMPRstRx") 143247867f0aSMatthieu Baerts if [ -z "$count" ]; then 143303668c65SMatthieu Baerts print_skip 1434b134a580SMatthieu Baerts # accept more rst than expected except if we don't expect any 1435b134a580SMatthieu Baerts elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } || 1436b134a580SMatthieu Baerts { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then 143703668c65SMatthieu Baerts fail_test "got $count MP_RST[s] RX expected $rst_rx" 1438922fd2b3SGeliang Tang else 143903668c65SMatthieu Baerts print_ok 1440922fd2b3SGeliang Tang fi 1441922fd2b3SGeliang Tang 144203668c65SMatthieu Baerts print_info "$extra_msg" 1443922fd2b3SGeliang Tang} 1444922fd2b3SGeliang Tang 14458bd03be3SGeliang Tangchk_infi_nr() 14468bd03be3SGeliang Tang{ 14478bd03be3SGeliang Tang local infi_tx=$1 14488bd03be3SGeliang Tang local infi_rx=$2 14498bd03be3SGeliang Tang local count 14508bd03be3SGeliang Tang 145103668c65SMatthieu Baerts print_check "itx" 145247867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtInfiniteMapTx") 145347867f0aSMatthieu Baerts if [ -z "$count" ]; then 145403668c65SMatthieu Baerts print_skip 145547867f0aSMatthieu Baerts elif [ "$count" != "$infi_tx" ]; then 145603668c65SMatthieu Baerts fail_test "got $count infinite map[s] TX expected $infi_tx" 14578bd03be3SGeliang Tang else 145803668c65SMatthieu Baerts print_ok 14598bd03be3SGeliang Tang fi 14608bd03be3SGeliang Tang 146103668c65SMatthieu Baerts print_check "infirx" 146247867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtInfiniteMapRx") 146347867f0aSMatthieu Baerts if [ -z "$count" ]; then 146403668c65SMatthieu Baerts print_skip 146547867f0aSMatthieu Baerts elif [ "$count" != "$infi_rx" ]; then 146603668c65SMatthieu Baerts fail_test "got $count infinite map[s] RX expected $infi_rx" 14678bd03be3SGeliang Tang else 146803668c65SMatthieu Baerts print_ok 14698bd03be3SGeliang Tang fi 14708bd03be3SGeliang Tang} 14718bd03be3SGeliang Tang 1472b08fbf24SPaolo Abenichk_join_nr() 1473b08fbf24SPaolo Abeni{ 1474c7d49c03SMatthieu Baerts local syn_nr=$1 1475c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1476c7d49c03SMatthieu Baerts local ack_nr=$3 1477c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1478c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1479c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1480c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 14818bd03be3SGeliang Tang local infi_nr=${8:-0} 14828bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1483b08fbf24SPaolo Abeni local count 1484e35f885bSPaolo Abeni local with_cookie 1485b08fbf24SPaolo Abeni 1486c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 148703668c65SMatthieu Baerts print_info "${corrupted_pkts} corrupted pkts" 1488c7d49c03SMatthieu Baerts fi 1489c7d49c03SMatthieu Baerts 149003668c65SMatthieu Baerts print_check "syn" 149147867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPJoinSynRx") 149247867f0aSMatthieu Baerts if [ -z "$count" ]; then 149303668c65SMatthieu Baerts print_skip 149447867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 149503668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn expected $syn_nr" 1496b08fbf24SPaolo Abeni else 149703668c65SMatthieu Baerts print_ok 1498b08fbf24SPaolo Abeni fi 1499b08fbf24SPaolo Abeni 150003668c65SMatthieu Baerts print_check "synack" 15014bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 150247867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtMPJoinSynAckRx") 150347867f0aSMatthieu Baerts if [ -z "$count" ]; then 150403668c65SMatthieu Baerts print_skip 150547867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 1506e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1507e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1508e35f885bSPaolo Abeni # the subflow creation 1509e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 151003668c65SMatthieu Baerts print_ok 1511e35f885bSPaolo Abeni else 151203668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack expected $syn_ack_nr" 1513e35f885bSPaolo Abeni fi 1514b08fbf24SPaolo Abeni else 151503668c65SMatthieu Baerts print_ok 1516b08fbf24SPaolo Abeni fi 1517b08fbf24SPaolo Abeni 151803668c65SMatthieu Baerts print_check "ack" 151947867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPJoinAckRx") 152047867f0aSMatthieu Baerts if [ -z "$count" ]; then 152103668c65SMatthieu Baerts print_skip 152247867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 152303668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack expected $ack_nr" 1524b08fbf24SPaolo Abeni else 152503668c65SMatthieu Baerts print_ok 1526b08fbf24SPaolo Abeni fi 1527b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 15283c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 152926516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 153026516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 15318bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1532af66d3e1SGeliang Tang fi 1533b08fbf24SPaolo Abeni} 1534b08fbf24SPaolo Abeni 15357d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 15367d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 15377d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 15387d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 15397d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 15407d1e6f16SPaolo Abenichk_stale_nr() 15417d1e6f16SPaolo Abeni{ 15427d1e6f16SPaolo Abeni local ns=$1 15437d1e6f16SPaolo Abeni local stale_min=$2 15447d1e6f16SPaolo Abeni local stale_max=$3 15457d1e6f16SPaolo Abeni local stale_delta=$4 15467d1e6f16SPaolo Abeni local dump_stats 15477d1e6f16SPaolo Abeni local stale_nr 15487d1e6f16SPaolo Abeni local recover_nr 15497d1e6f16SPaolo Abeni 155003668c65SMatthieu Baerts print_check "stale" 15517d1e6f16SPaolo Abeni 155247867f0aSMatthieu Baerts stale_nr=$(get_counter ${ns} "MPTcpExtSubflowStale") 155347867f0aSMatthieu Baerts recover_nr=$(get_counter ${ns} "MPTcpExtSubflowRecover") 155447867f0aSMatthieu Baerts if [ -z "$stale_nr" ] || [ -z "$recover_nr" ]; then 155503668c65SMatthieu Baerts print_skip 155647867f0aSMatthieu Baerts elif [ $stale_nr -lt $stale_min ] || 1557d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1558d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 155903668c65SMatthieu Baerts fail_test "got $stale_nr stale[s] $recover_nr recover[s], " \ 15607d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 15617d1e6f16SPaolo Abeni " stale-recover delta $stale_delta" 15627d1e6f16SPaolo Abeni dump_stats=1 15637d1e6f16SPaolo Abeni else 156403668c65SMatthieu Baerts print_ok 15657d1e6f16SPaolo Abeni fi 15667d1e6f16SPaolo Abeni 15677d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 15687d1e6f16SPaolo Abeni echo $ns stats 15697d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 15707d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 15717d1e6f16SPaolo Abeni fi 15727d1e6f16SPaolo Abeni} 15737d1e6f16SPaolo Abeni 1574be613160SGeliang Tangchk_add_nr() 1575be613160SGeliang Tang{ 1576be613160SGeliang Tang local add_nr=$1 1577be613160SGeliang Tang local echo_nr=$2 15788a127bf6SGeliang Tang local port_nr=${3:-0} 15798a127bf6SGeliang Tang local syn_nr=${4:-$port_nr} 15808a127bf6SGeliang Tang local syn_ack_nr=${5:-$port_nr} 15818a127bf6SGeliang Tang local ack_nr=${6:-$port_nr} 15828a127bf6SGeliang Tang local mis_syn_nr=${7:-0} 15838a127bf6SGeliang Tang local mis_ack_nr=${8:-0} 1584be613160SGeliang Tang local count 15856ef84b15SPaolo Abeni local timeout 15866ef84b15SPaolo Abeni 15874bfadd71SMatthieu Baerts timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1588be613160SGeliang Tang 158903668c65SMatthieu Baerts print_check "add" 159047867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtAddAddr") 159147867f0aSMatthieu Baerts if [ -z "$count" ]; then 159203668c65SMatthieu Baerts print_skip 15936ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15946ef84b15SPaolo Abeni # add addrs options, due to retransmissions 159547867f0aSMatthieu Baerts elif [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 159603668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] expected $add_nr" 1597be613160SGeliang Tang else 159803668c65SMatthieu Baerts print_ok 1599be613160SGeliang Tang fi 1600be613160SGeliang Tang 160103668c65SMatthieu Baerts print_check "echo" 160247867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtEchoAdd") 160347867f0aSMatthieu Baerts if [ -z "$count" ]; then 160403668c65SMatthieu Baerts print_skip 160547867f0aSMatthieu Baerts elif [ "$count" != "$echo_nr" ]; then 160603668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] expected $echo_nr" 1607be613160SGeliang Tang else 160803668c65SMatthieu Baerts print_ok 16098a127bf6SGeliang Tang fi 16108a127bf6SGeliang Tang 16118a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 161203668c65SMatthieu Baerts print_check "pt" 161347867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtPortAdd") 161447867f0aSMatthieu Baerts if [ -z "$count" ]; then 161503668c65SMatthieu Baerts print_skip 161647867f0aSMatthieu Baerts elif [ "$count" != "$port_nr" ]; then 161703668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] with a port-number expected $port_nr" 16188a127bf6SGeliang Tang else 161903668c65SMatthieu Baerts print_ok 1620be613160SGeliang Tang fi 1621be613160SGeliang Tang 162203668c65SMatthieu Baerts print_check "syn" 162347867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPJoinPortSynRx") 162447867f0aSMatthieu Baerts if [ -z "$count" ]; then 162503668c65SMatthieu Baerts print_skip 162647867f0aSMatthieu Baerts elif [ "$count" != "$syn_nr" ]; then 162703668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a different \ 16288a127bf6SGeliang Tang port-number expected $syn_nr" 16298a127bf6SGeliang Tang else 163003668c65SMatthieu Baerts print_ok 16318a127bf6SGeliang Tang fi 16328a127bf6SGeliang Tang 163303668c65SMatthieu Baerts print_check "synack" 163447867f0aSMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx") 163547867f0aSMatthieu Baerts if [ -z "$count" ]; then 163603668c65SMatthieu Baerts print_skip 163747867f0aSMatthieu Baerts elif [ "$count" != "$syn_ack_nr" ]; then 163803668c65SMatthieu Baerts fail_test "got $count JOIN[s] synack with a different \ 16398a127bf6SGeliang Tang port-number expected $syn_ack_nr" 16408a127bf6SGeliang Tang else 164103668c65SMatthieu Baerts print_ok 16428a127bf6SGeliang Tang fi 16438a127bf6SGeliang Tang 164403668c65SMatthieu Baerts print_check "ack" 164547867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPJoinPortAckRx") 164647867f0aSMatthieu Baerts if [ -z "$count" ]; then 164703668c65SMatthieu Baerts print_skip 164847867f0aSMatthieu Baerts elif [ "$count" != "$ack_nr" ]; then 164903668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a different \ 16508a127bf6SGeliang Tang port-number expected $ack_nr" 16518a127bf6SGeliang Tang else 165203668c65SMatthieu Baerts print_ok 16538a127bf6SGeliang Tang fi 16548a127bf6SGeliang Tang 165503668c65SMatthieu Baerts print_check "syn" 165647867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMismatchPortSynRx") 165747867f0aSMatthieu Baerts if [ -z "$count" ]; then 165803668c65SMatthieu Baerts print_skip 165947867f0aSMatthieu Baerts elif [ "$count" != "$mis_syn_nr" ]; then 166003668c65SMatthieu Baerts fail_test "got $count JOIN[s] syn with a mismatched \ 16618a127bf6SGeliang Tang port-number expected $mis_syn_nr" 16628a127bf6SGeliang Tang else 166303668c65SMatthieu Baerts print_ok 16648a127bf6SGeliang Tang fi 16658a127bf6SGeliang Tang 166603668c65SMatthieu Baerts print_check "ack" 166747867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMismatchPortAckRx") 166847867f0aSMatthieu Baerts if [ -z "$count" ]; then 166903668c65SMatthieu Baerts print_skip 167047867f0aSMatthieu Baerts elif [ "$count" != "$mis_ack_nr" ]; then 167103668c65SMatthieu Baerts fail_test "got $count JOIN[s] ack with a mismatched \ 16728a127bf6SGeliang Tang port-number expected $mis_ack_nr" 16738a127bf6SGeliang Tang else 167403668c65SMatthieu Baerts print_ok 16758a127bf6SGeliang Tang fi 16768a127bf6SGeliang Tang fi 1677be613160SGeliang Tang} 1678be613160SGeliang Tang 16790639fa23SPaolo Abenichk_add_tx_nr() 16800639fa23SPaolo Abeni{ 16810639fa23SPaolo Abeni local add_tx_nr=$1 16820639fa23SPaolo Abeni local echo_tx_nr=$2 16830639fa23SPaolo Abeni local timeout 16840639fa23SPaolo Abeni local count 16850639fa23SPaolo Abeni 16860639fa23SPaolo Abeni timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 16870639fa23SPaolo Abeni 168803668c65SMatthieu Baerts print_check "add TX" 168900079f18SMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtAddAddrTx") 169000079f18SMatthieu Baerts if [ -z "$count" ]; then 169103668c65SMatthieu Baerts print_skip 16920639fa23SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 16930639fa23SPaolo Abeni # add addrs options, due to retransmissions 169400079f18SMatthieu Baerts elif [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 169503668c65SMatthieu Baerts fail_test "got $count ADD_ADDR[s] TX, expected $add_tx_nr" 16960639fa23SPaolo Abeni else 169703668c65SMatthieu Baerts print_ok 16980639fa23SPaolo Abeni fi 16990639fa23SPaolo Abeni 170003668c65SMatthieu Baerts print_check "echo TX" 170100079f18SMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtEchoAddTx") 170200079f18SMatthieu Baerts if [ -z "$count" ]; then 170303668c65SMatthieu Baerts print_skip 170400079f18SMatthieu Baerts elif [ "$count" != "$echo_tx_nr" ]; then 170503668c65SMatthieu Baerts fail_test "got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 17060639fa23SPaolo Abeni else 170703668c65SMatthieu Baerts print_ok 17080639fa23SPaolo Abeni fi 17090639fa23SPaolo Abeni} 17100639fa23SPaolo Abeni 1711dd72b0feSGeliang Tangchk_rm_nr() 1712dd72b0feSGeliang Tang{ 1713dd72b0feSGeliang Tang local rm_addr_nr=$1 1714dd72b0feSGeliang Tang local rm_subflow_nr=$2 17156fa0174aSPaolo Abeni local invert 17166fa0174aSPaolo Abeni local simult 1717dd72b0feSGeliang Tang local count 17187d9bf018SGeliang Tang local addr_ns=$ns1 17197d9bf018SGeliang Tang local subflow_ns=$ns2 17207d9bf018SGeliang Tang local extra_msg="" 17217028ba8aSGeliang Tang 17226fa0174aSPaolo Abeni shift 2 17236fa0174aSPaolo Abeni while [ -n "$1" ]; do 17246fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 17256fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 17266fa0174aSPaolo Abeni shift 17276fa0174aSPaolo Abeni done 17286fa0174aSPaolo Abeni 17296fa0174aSPaolo Abeni if [ -z $invert ]; then 17306fa0174aSPaolo Abeni addr_ns=$ns1 17316fa0174aSPaolo Abeni subflow_ns=$ns2 17326fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 17337028ba8aSGeliang Tang addr_ns=$ns2 17347028ba8aSGeliang Tang subflow_ns=$ns1 17357d9bf018SGeliang Tang extra_msg="invert" 17367028ba8aSGeliang Tang fi 1737dd72b0feSGeliang Tang 173803668c65SMatthieu Baerts print_check "rm" 173900079f18SMatthieu Baerts count=$(get_counter ${addr_ns} "MPTcpExtRmAddr") 174000079f18SMatthieu Baerts if [ -z "$count" ]; then 174103668c65SMatthieu Baerts print_skip 174200079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_nr" ]; then 174303668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_nr" 1744dd72b0feSGeliang Tang else 174503668c65SMatthieu Baerts print_ok 1746dd72b0feSGeliang Tang fi 1747dd72b0feSGeliang Tang 174803668c65SMatthieu Baerts print_check "rmsf" 174947867f0aSMatthieu Baerts count=$(get_counter ${subflow_ns} "MPTcpExtRmSubflow") 175047867f0aSMatthieu Baerts if [ -z "$count" ]; then 175103668c65SMatthieu Baerts print_skip 175247867f0aSMatthieu Baerts elif [ -n "$simult" ]; then 1753d8d08302SMatthieu Baerts local cnt suffix 1754d8d08302SMatthieu Baerts 175547867f0aSMatthieu Baerts cnt=$(get_counter ${addr_ns} "MPTcpExtRmSubflow") 17566fa0174aSPaolo Abeni 17576fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 17586fa0174aSPaolo Abeni # unreliable 17596fa0174aSPaolo Abeni count=$((count + cnt)) 17606fa0174aSPaolo Abeni [ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 17616fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 17626fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 176303668c65SMatthieu Baerts print_ok "$suffix" 17646fa0174aSPaolo Abeni else 176503668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 17666fa0174aSPaolo Abeni fi 176747867f0aSMatthieu Baerts elif [ "$count" != "$rm_subflow_nr" ]; then 176803668c65SMatthieu Baerts fail_test "got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1769dd72b0feSGeliang Tang else 177003668c65SMatthieu Baerts print_ok 1771dd72b0feSGeliang Tang fi 1772dd72b0feSGeliang Tang 177303668c65SMatthieu Baerts print_info "$extra_msg" 1774dd72b0feSGeliang Tang} 1775dd72b0feSGeliang Tang 17760639fa23SPaolo Abenichk_rm_tx_nr() 17770639fa23SPaolo Abeni{ 17780639fa23SPaolo Abeni local rm_addr_tx_nr=$1 17790639fa23SPaolo Abeni 178003668c65SMatthieu Baerts print_check "rm TX" 178100079f18SMatthieu Baerts count=$(get_counter ${ns2} "MPTcpExtRmAddrTx") 178200079f18SMatthieu Baerts if [ -z "$count" ]; then 178303668c65SMatthieu Baerts print_skip 178400079f18SMatthieu Baerts elif [ "$count" != "$rm_addr_tx_nr" ]; then 178503668c65SMatthieu Baerts fail_test "got $count RM_ADDR[s] expected $rm_addr_tx_nr" 17860639fa23SPaolo Abeni else 178703668c65SMatthieu Baerts print_ok 17880639fa23SPaolo Abeni fi 17890639fa23SPaolo Abeni} 17900639fa23SPaolo Abeni 1791718eb44eSGeliang Tangchk_prio_nr() 1792718eb44eSGeliang Tang{ 1793718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1794718eb44eSGeliang Tang local mp_prio_nr_rx=$2 1795718eb44eSGeliang Tang local count 1796718eb44eSGeliang Tang 179703668c65SMatthieu Baerts print_check "ptx" 179847867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPPrioTx") 179947867f0aSMatthieu Baerts if [ -z "$count" ]; then 180003668c65SMatthieu Baerts print_skip 180147867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_tx" ]; then 180203668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1803718eb44eSGeliang Tang else 180403668c65SMatthieu Baerts print_ok 1805718eb44eSGeliang Tang fi 1806718eb44eSGeliang Tang 180703668c65SMatthieu Baerts print_check "prx" 180847867f0aSMatthieu Baerts count=$(get_counter ${ns1} "MPTcpExtMPPrioRx") 180947867f0aSMatthieu Baerts if [ -z "$count" ]; then 181003668c65SMatthieu Baerts print_skip 181147867f0aSMatthieu Baerts elif [ "$count" != "$mp_prio_nr_rx" ]; then 181203668c65SMatthieu Baerts fail_test "got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1813718eb44eSGeliang Tang else 181403668c65SMatthieu Baerts print_ok 1815718eb44eSGeliang Tang fi 1816718eb44eSGeliang Tang} 1817718eb44eSGeliang Tang 1818e274f715SPaolo Abenichk_subflow_nr() 1819e274f715SPaolo Abeni{ 182003668c65SMatthieu Baerts local msg="$1" 182103668c65SMatthieu Baerts local subflow_nr=$2 1822e274f715SPaolo Abeni local cnt1 1823e274f715SPaolo Abeni local cnt2 1824a635a8c3SPaolo Abeni local dump_stats 1825e274f715SPaolo Abeni 182603668c65SMatthieu Baerts print_check "${msg}" 1827e274f715SPaolo Abeni 1828e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1829e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 18300fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 183103668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 subflows expected $subflow_nr" 1832e274f715SPaolo Abeni dump_stats=1 1833e274f715SPaolo Abeni else 183403668c65SMatthieu Baerts print_ok 1835e274f715SPaolo Abeni fi 1836e274f715SPaolo Abeni 1837a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1838a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1839a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1840a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1841a635a8c3SPaolo Abeni fi 1842e274f715SPaolo Abeni} 1843e274f715SPaolo Abeni 18449095ce97SGeliang Tangchk_mptcp_info() 18459095ce97SGeliang Tang{ 1846d7ced753SGeliang Tang local info1=$1 1847d7ced753SGeliang Tang local exp1=$2 1848d7ced753SGeliang Tang local info2=$3 1849d7ced753SGeliang Tang local exp2=$4 18509095ce97SGeliang Tang local cnt1 18519095ce97SGeliang Tang local cnt2 18529095ce97SGeliang Tang local dump_stats 18539095ce97SGeliang Tang 185403668c65SMatthieu Baerts print_check "mptcp_info ${info1:0:8}=$exp1:$exp2" 18559095ce97SGeliang Tang 1856d7ced753SGeliang Tang cnt1=$(ss -N $ns1 -inmHM | grep "$info1:" | 1857d7ced753SGeliang Tang sed -n 's/.*\('"$info1"':\)\([[:digit:]]*\).*$/\2/p;q') 1858d7ced753SGeliang Tang cnt2=$(ss -N $ns2 -inmHM | grep "$info2:" | 1859d7ced753SGeliang Tang sed -n 's/.*\('"$info2"':\)\([[:digit:]]*\).*$/\2/p;q') 1860d7ced753SGeliang Tang # 'ss' only display active connections and counters that are not 0. 18619095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 18629095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 1863d7ced753SGeliang Tang 1864d7ced753SGeliang Tang if [ "$cnt1" != "$exp1" ] || [ "$cnt2" != "$exp2" ]; then 186503668c65SMatthieu Baerts fail_test "got $cnt1:$cnt2 $info1:$info2 expected $exp1:$exp2" 18669095ce97SGeliang Tang dump_stats=1 18679095ce97SGeliang Tang else 186803668c65SMatthieu Baerts print_ok 18699095ce97SGeliang Tang fi 18709095ce97SGeliang Tang 18719095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 18729095ce97SGeliang Tang ss -N $ns1 -inmHM 18739095ce97SGeliang Tang ss -N $ns2 -inmHM 18749095ce97SGeliang Tang fi 18759095ce97SGeliang Tang} 18769095ce97SGeliang Tang 18777d1e6f16SPaolo Abenichk_link_usage() 18787d1e6f16SPaolo Abeni{ 18797d1e6f16SPaolo Abeni local ns=$1 18807d1e6f16SPaolo Abeni local link=$2 18817d1e6f16SPaolo Abeni local out=$3 18827d1e6f16SPaolo Abeni local expected_rate=$4 18834bfadd71SMatthieu Baerts 18844bfadd71SMatthieu Baerts local tx_link tx_total 18854bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1886d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1887d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 18887d1e6f16SPaolo Abeni local tolerance=5 18897d1e6f16SPaolo Abeni 189003668c65SMatthieu Baerts print_check "link usage" 1891d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1892d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 189303668c65SMatthieu Baerts fail_test "got $tx_rate% usage, expected $expected_rate%" 18947d1e6f16SPaolo Abeni else 189503668c65SMatthieu Baerts print_ok 18967d1e6f16SPaolo Abeni fi 18977d1e6f16SPaolo Abeni} 18987d1e6f16SPaolo Abeni 1899f98c2bcaSMat Martineauwait_attempt_fail() 190046e967d1SPaolo Abeni{ 190146e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 190246e967d1SPaolo Abeni local time=0 190346e967d1SPaolo Abeni local ns=$1 190446e967d1SPaolo Abeni 190546e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 19061e777bd8SMatthieu Baerts local cnt 19071e777bd8SMatthieu Baerts 190847867f0aSMatthieu Baerts cnt=$(get_counter ${ns} "TcpAttemptFails") 190946e967d1SPaolo Abeni 191046e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 191146e967d1SPaolo Abeni time=$((time + 100)) 191246e967d1SPaolo Abeni sleep 0.1 191346e967d1SPaolo Abeni done 191446e967d1SPaolo Abeni return 1 191546e967d1SPaolo Abeni} 191646e967d1SPaolo Abeni 19175ac1d2d6SMat Martineauset_userspace_pm() 19185ac1d2d6SMat Martineau{ 19195ac1d2d6SMat Martineau local ns=$1 19205ac1d2d6SMat Martineau 19215ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 19225ac1d2d6SMat Martineau} 19235ac1d2d6SMat Martineau 19241002b89fSGeliang Tangsubflows_tests() 19251002b89fSGeliang Tang{ 1926c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1927b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1928c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1929ae7bd9ccSMatthieu Baerts fi 1930b08fbf24SPaolo Abeni 19311002b89fSGeliang Tang # subflow limited by client 1932c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 193334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 193434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 193534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1936b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1937c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1938ae7bd9ccSMatthieu Baerts fi 1939b08fbf24SPaolo Abeni 19401002b89fSGeliang Tang # subflow limited by server 1941c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 194234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 194334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 194434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1945b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1946c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 1947ae7bd9ccSMatthieu Baerts fi 1948b08fbf24SPaolo Abeni 1949b08fbf24SPaolo Abeni # subflow 1950c7d49c03SMatthieu Baerts if reset "single subflow"; then 195134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 195234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 195334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1954b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1955c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1956ae7bd9ccSMatthieu Baerts fi 1957b08fbf24SPaolo Abeni 1958b08fbf24SPaolo Abeni # multiple subflows 1959c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 196034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 196134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 196234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 196334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1964b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1965c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1966ae7bd9ccSMatthieu Baerts fi 1967b08fbf24SPaolo Abeni 196872bcbc46SPaolo Abeni # multiple subflows limited by server 1969c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 197034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 197134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 197234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 197334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1974b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1975c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 1976ae7bd9ccSMatthieu Baerts fi 1977c3eaa5f6SGeliang Tang 1978c3eaa5f6SGeliang Tang # single subflow, dev 1979c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 198034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 198134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 198234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 1983c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1984c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1985ae7bd9ccSMatthieu Baerts fi 19861002b89fSGeliang Tang} 1987b08fbf24SPaolo Abeni 198846e967d1SPaolo Abenisubflows_error_tests() 198946e967d1SPaolo Abeni{ 199046e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 199146e967d1SPaolo Abeni # address, no additional subflow should be created 1992c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 199334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 199434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 199534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 1996e571fb09SGeliang Tang speed=slow \ 1997e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1998c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1999ae7bd9ccSMatthieu Baerts fi 200046e967d1SPaolo Abeni 200146e967d1SPaolo Abeni # multiple subflows, with subflow creation error 20024a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with failing subflow" ns1 10.0.3.2 REJECT && 20034a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 200434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 200534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 200634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 200734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2008e571fb09SGeliang Tang speed=slow \ 2009e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2010c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2011ae7bd9ccSMatthieu Baerts fi 201246e967d1SPaolo Abeni 201346e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 20144a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, with subflow timeout" ns1 10.0.3.2 DROP && 20154a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 201634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 201734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 201834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 201934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2020e571fb09SGeliang Tang speed=slow \ 2021e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2022c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2023ae7bd9ccSMatthieu Baerts fi 202446e967d1SPaolo Abeni 202546e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 202646e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 202746e967d1SPaolo Abeni # subflows are added later 20284a0b866aSMatthieu Baerts if reset_with_tcp_filter "multi subflows, fair usage on close" ns1 10.0.3.2 REJECT && 20294a0b866aSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 203034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 203134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 203234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2033e571fb09SGeliang Tang speed=slow \ 2034e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 203546e967d1SPaolo Abeni 203646e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 2037f98c2bcaSMat Martineau wait_attempt_fail $ns2 203834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 203946e967d1SPaolo Abeni wait 204046e967d1SPaolo Abeni 204146e967d1SPaolo Abeni # additional subflow could be created only if the PM select 204246e967d1SPaolo Abeni # the later endpoint, skipping the already used one 2043c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2044ae7bd9ccSMatthieu Baerts fi 204546e967d1SPaolo Abeni} 204646e967d1SPaolo Abeni 20471002b89fSGeliang Tangsignal_address_tests() 20481002b89fSGeliang Tang{ 2049b08fbf24SPaolo Abeni # add_address, unused 2050c7d49c03SMatthieu Baerts if reset "unused signal address"; then 205134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2052b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2053c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 20540639fa23SPaolo Abeni chk_add_tx_nr 1 1 2055be613160SGeliang Tang chk_add_nr 1 1 2056ae7bd9ccSMatthieu Baerts fi 2057b08fbf24SPaolo Abeni 2058b08fbf24SPaolo Abeni # accept and use add_addr 2059c7d49c03SMatthieu Baerts if reset "signal address"; then 206034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 206134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 206234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2063b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2064c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2065be613160SGeliang Tang chk_add_nr 1 1 2066ae7bd9ccSMatthieu Baerts fi 2067b08fbf24SPaolo Abeni 2068b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 2069b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 2070b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 2071b08fbf24SPaolo Abeni # used for 'add_addr' subflow 2072c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 207334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 207434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 207534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 207634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2077b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2078c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2079be613160SGeliang Tang chk_add_nr 1 1 2080ae7bd9ccSMatthieu Baerts fi 2081b08fbf24SPaolo Abeni 2082b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 2083c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 208434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 208534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 208634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 208734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 208834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2089b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2090c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2091be613160SGeliang Tang chk_add_nr 1 1 2092ae7bd9ccSMatthieu Baerts fi 2093ef360019SGeliang Tang 2094ef360019SGeliang Tang # signal addresses 2095c7d49c03SMatthieu Baerts if reset "signal addresses"; then 209634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 209734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 209834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 209934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 210034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2101ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2102c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2103ef360019SGeliang Tang chk_add_nr 3 3 2104ae7bd9ccSMatthieu Baerts fi 2105ef360019SGeliang Tang 2106ef360019SGeliang Tang # signal invalid addresses 2107c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 210834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 210934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 211034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 211134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 211234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2113ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2114c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2115ef360019SGeliang Tang chk_add_nr 3 3 2116ae7bd9ccSMatthieu Baerts fi 211733c563adSYonglong Li 211833c563adSYonglong Li # signal addresses race test 2119c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 212034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 212134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 212234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 212334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 212434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 212534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 212634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 212734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 212834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 212934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 21306ef84b15SPaolo Abeni 21316ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 21326ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2133e571fb09SGeliang Tang speed=slow \ 2134e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 213586e39e04SPaolo Abeni 2136d4c81bbbSMatthieu Baerts # It is not directly linked to the commit introducing this 2137d4c81bbbSMatthieu Baerts # symbol but for the parent one which is linked anyway. 2138d4c81bbbSMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_pm_subflow_check_next$"; then 2139d4c81bbbSMatthieu Baerts chk_join_nr 3 3 2 2140d4c81bbbSMatthieu Baerts chk_add_nr 4 4 2141d4c81bbbSMatthieu Baerts else 2142d4c81bbbSMatthieu Baerts chk_join_nr 3 3 3 214386e39e04SPaolo Abeni # the server will not signal the address terminating 214486e39e04SPaolo Abeni # the MPC subflow 214586e39e04SPaolo Abeni chk_add_nr 3 3 2146ae7bd9ccSMatthieu Baerts fi 2147d4c81bbbSMatthieu Baerts fi 21481002b89fSGeliang Tang} 2149b08fbf24SPaolo Abeni 21501002b89fSGeliang Tanglink_failure_tests() 21511002b89fSGeliang Tang{ 21528b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2153c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 21547d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 21557d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 21567d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 21577d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 21587d1e6f16SPaolo Abeni # active backup and link switch-over. 21597d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 21607d1e6f16SPaolo Abeni init_shapers 216134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 216234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 216334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 216434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 216534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 21660c93af1fSGeliang Tang test_linkfail=1 \ 21670c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2168c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 21698b819a84SFlorian Westphal chk_add_nr 1 1 21707d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2171ae7bd9ccSMatthieu Baerts fi 21727d1e6f16SPaolo Abeni 21737d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 21747d1e6f16SPaolo Abeni # for bidirectional transfer 2175c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 21767d1e6f16SPaolo Abeni init_shapers 217734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 217834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 217934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 218034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 218134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 21820c93af1fSGeliang Tang test_linkfail=2 \ 21830c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2184c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 21857d1e6f16SPaolo Abeni chk_add_nr 1 1 21867d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2187ae7bd9ccSMatthieu Baerts fi 21887d1e6f16SPaolo Abeni 21897d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 21907d1e6f16SPaolo Abeni # will never be used 2191c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 21927d1e6f16SPaolo Abeni init_shapers 219334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 219434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 219534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 219634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 21970c93af1fSGeliang Tang FAILING_LINKS="1" test_linkfail=1 \ 21980c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2199c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22007d1e6f16SPaolo Abeni chk_add_nr 1 1 22017d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2202ae7bd9ccSMatthieu Baerts fi 22037d1e6f16SPaolo Abeni 22047d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 22057d1e6f16SPaolo Abeni # the traffic 2206c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 22077d1e6f16SPaolo Abeni init_shapers 220834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 220934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 221034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 221134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22120c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=1 \ 22130c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2214c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22157d1e6f16SPaolo Abeni chk_add_nr 1 1 22167d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 22177d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2218ae7bd9ccSMatthieu Baerts fi 22197d1e6f16SPaolo Abeni 22207d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 22217d1e6f16SPaolo Abeni # for bidirectional transfer 2222c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 22237d1e6f16SPaolo Abeni init_shapers 222434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 222534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 222634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 222734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 22280c93af1fSGeliang Tang FAILING_LINKS="1 2" test_linkfail=2 \ 22290c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2230c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22317d1e6f16SPaolo Abeni chk_add_nr 1 1 22327d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 22337d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2234ae7bd9ccSMatthieu Baerts fi 22351002b89fSGeliang Tang} 22368b819a84SFlorian Westphal 22371002b89fSGeliang Tangadd_addr_timeout_tests() 22381002b89fSGeliang Tang{ 22398d014eaaSGeliang Tang # add_addr timeout 2240c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 224134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 224234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 224334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2244e571fb09SGeliang Tang speed=slow \ 2245e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2246c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22470639fa23SPaolo Abeni chk_add_tx_nr 4 4 22488d014eaaSGeliang Tang chk_add_nr 4 0 2249ae7bd9ccSMatthieu Baerts fi 22508d014eaaSGeliang Tang 22511002b89fSGeliang Tang # add_addr timeout IPv6 2252c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 225334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 225434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 225534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2256e571fb09SGeliang Tang speed=slow \ 2257e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2258c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22591002b89fSGeliang Tang chk_add_nr 4 0 2260ae7bd9ccSMatthieu Baerts fi 22618da6229bSGeliang Tang 22628da6229bSGeliang Tang # signal addresses timeout 2263c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 226434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 226534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 226634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 226734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2268e571fb09SGeliang Tang speed=10 \ 2269e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2270c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 22718da6229bSGeliang Tang chk_add_nr 8 0 2272ae7bd9ccSMatthieu Baerts fi 22738da6229bSGeliang Tang 22748da6229bSGeliang Tang # signal invalid addresses timeout 2275c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 227634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 227734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 227834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 227934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2280e571fb09SGeliang Tang speed=10 \ 2281e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2282c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22838da6229bSGeliang Tang chk_add_nr 8 0 2284ae7bd9ccSMatthieu Baerts fi 22851002b89fSGeliang Tang} 22861002b89fSGeliang Tang 22871002b89fSGeliang Tangremove_tests() 22881002b89fSGeliang Tang{ 2289dd72b0feSGeliang Tang # single subflow, remove 2290c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 229134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 229234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 229334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2294e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 2295e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2296c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 22970639fa23SPaolo Abeni chk_rm_tx_nr 1 2298dd72b0feSGeliang Tang chk_rm_nr 1 1 22992cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2300ae7bd9ccSMatthieu Baerts fi 2301dd72b0feSGeliang Tang 2302dd72b0feSGeliang Tang # multiple subflows, remove 2303c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 230434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 230534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 230634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 230734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2308e571fb09SGeliang Tang addr_nr_ns2=-2 speed=slow \ 2309e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2310c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2311dd72b0feSGeliang Tang chk_rm_nr 2 2 23122cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2313ae7bd9ccSMatthieu Baerts fi 2314dd72b0feSGeliang Tang 2315dd72b0feSGeliang Tang # single address, remove 2316c7d49c03SMatthieu Baerts if reset "remove single address"; then 231734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 231834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 231934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2320e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2321e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2322c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2323dd72b0feSGeliang Tang chk_add_nr 1 1 23247028ba8aSGeliang Tang chk_rm_nr 1 1 invert 23252cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2326ae7bd9ccSMatthieu Baerts fi 2327dd72b0feSGeliang Tang 2328dd72b0feSGeliang Tang # subflow and signal, remove 2329c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 233034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 233134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 233234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 233334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2334e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2335e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2336c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2337dd72b0feSGeliang Tang chk_add_nr 1 1 2338dd72b0feSGeliang Tang chk_rm_nr 1 1 23392cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2340ae7bd9ccSMatthieu Baerts fi 2341dd72b0feSGeliang Tang 2342dd72b0feSGeliang Tang # subflows and signal, remove 2343c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 234434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 234534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 234634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 234734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 234834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2349e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-2 speed=10 \ 2350e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2351c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2352dd72b0feSGeliang Tang chk_add_nr 1 1 2353dd72b0feSGeliang Tang chk_rm_nr 2 2 23542cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2355ae7bd9ccSMatthieu Baerts fi 2356dd72b0feSGeliang Tang 2357ef360019SGeliang Tang # addresses remove 2358c7d49c03SMatthieu Baerts if reset "remove addresses"; then 235934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 236034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 236134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 236234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 236334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2364e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2365e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2366c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2367ef360019SGeliang Tang chk_add_nr 3 3 2368ef360019SGeliang Tang chk_rm_nr 3 3 invert 23692cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2370ae7bd9ccSMatthieu Baerts fi 2371ef360019SGeliang Tang 2372ef360019SGeliang Tang # invalid addresses remove 2373c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 237434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 237534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 237634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 237734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 237834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2379e571fb09SGeliang Tang addr_nr_ns1=-3 speed=10 \ 2380e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2381c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2382ef360019SGeliang Tang chk_add_nr 3 3 2383ef360019SGeliang Tang chk_rm_nr 3 1 invert 23842cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2385ae7bd9ccSMatthieu Baerts fi 2386ef360019SGeliang Tang 23876fe4ccdcSGeliang Tang # subflows and signal, flush 2388c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 238934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 239034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 239134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 239234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 239334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2394e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2395e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2396c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 23976fe4ccdcSGeliang Tang chk_add_nr 1 1 23986fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 23992cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2400ae7bd9ccSMatthieu Baerts fi 2401d2c4333aSGeliang Tang 2402d2c4333aSGeliang Tang # subflows flush 2403c7d49c03SMatthieu Baerts if reset "flush subflows"; then 240434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 240534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 240634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 240734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 240834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2409e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-8 speed=slow \ 2410e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2411c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2412425ba803SMatthieu Baerts 2413425ba803SMatthieu Baerts if mptcp_lib_kversion_ge 5.18; then 24140639fa23SPaolo Abeni chk_rm_tx_nr 0 24156fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2416425ba803SMatthieu Baerts else 2417425ba803SMatthieu Baerts chk_rm_nr 3 3 2418425ba803SMatthieu Baerts fi 24192cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2420ae7bd9ccSMatthieu Baerts fi 2421d2c4333aSGeliang Tang 2422d2c4333aSGeliang Tang # addresses flush 2423c7d49c03SMatthieu Baerts if reset "flush addresses"; then 242434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 242534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 242634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 242734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 242834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 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 2432d2c4333aSGeliang Tang chk_add_nr 3 3 24336fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 24342cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2435ae7bd9ccSMatthieu Baerts fi 2436ef360019SGeliang Tang 2437ef360019SGeliang Tang # invalid addresses flush 2438c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 243934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 244034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 244134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 244234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 244334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2444e571fb09SGeliang Tang addr_nr_ns1=-8 speed=slow \ 2445e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2446c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2447ef360019SGeliang Tang chk_add_nr 3 3 2448ef360019SGeliang Tang chk_rm_nr 3 1 invert 24492cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2450ae7bd9ccSMatthieu Baerts fi 24515e287fe7SGeliang Tang 24525e287fe7SGeliang Tang # remove id 0 subflow 2453c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 245434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 245534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 245634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2457e571fb09SGeliang Tang addr_nr_ns2=-9 speed=slow \ 2458e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2459c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 24605e287fe7SGeliang Tang chk_rm_nr 1 1 24612cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 2462ae7bd9ccSMatthieu Baerts fi 24635e287fe7SGeliang Tang 24645e287fe7SGeliang Tang # remove id 0 address 2465c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 246634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 246734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 246834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2469e571fb09SGeliang Tang addr_nr_ns1=-9 speed=slow \ 2470e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2471c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 24725e287fe7SGeliang Tang chk_add_nr 1 1 24735e287fe7SGeliang Tang chk_rm_nr 1 1 invert 24742cfaa8b3SMatthieu Baerts chk_rst_nr 0 0 invert 2475ae7bd9ccSMatthieu Baerts fi 24761002b89fSGeliang Tang} 24776fe4ccdcSGeliang Tang 24781002b89fSGeliang Tangadd_tests() 24791002b89fSGeliang Tang{ 24806208fd82SGeliang Tang # add single subflow 2481c7d49c03SMatthieu Baerts if reset "add single subflow"; then 248234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 248334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2484e571fb09SGeliang Tang addr_nr_ns2=1 speed=slow \ 2485e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2486c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2487ae7bd9ccSMatthieu Baerts fi 24886208fd82SGeliang Tang 24896208fd82SGeliang Tang # add signal address 2490c7d49c03SMatthieu Baerts if reset "add signal address"; then 249134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 249234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2493e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 2494e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2495c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 24966208fd82SGeliang Tang chk_add_nr 1 1 2497ae7bd9ccSMatthieu Baerts fi 24986208fd82SGeliang Tang 24996208fd82SGeliang Tang # add multiple subflows 2500c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 250134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 250234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2503e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2504e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2505c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2506ae7bd9ccSMatthieu Baerts fi 25076208fd82SGeliang Tang 25086208fd82SGeliang Tang # add multiple subflows IPv6 2509c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 251034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 251134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 2512e571fb09SGeliang Tang addr_nr_ns2=2 speed=slow \ 2513e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2514c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2515ae7bd9ccSMatthieu Baerts fi 25166208fd82SGeliang Tang 25176208fd82SGeliang Tang # add multiple addresses IPv6 2518c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 251934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 252034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2521e571fb09SGeliang Tang addr_nr_ns1=2 speed=slow \ 2522e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2523c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 25246208fd82SGeliang Tang chk_add_nr 2 2 2525ae7bd9ccSMatthieu Baerts fi 25261002b89fSGeliang Tang} 25276208fd82SGeliang Tang 25281002b89fSGeliang Tangipv6_tests() 25291002b89fSGeliang Tang{ 2530523514edSGeliang Tang # subflow IPv6 2531c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 253234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 253334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 253434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2535e571fb09SGeliang Tang speed=slow \ 2536e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2537c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2538ae7bd9ccSMatthieu Baerts fi 2539523514edSGeliang Tang 2540523514edSGeliang Tang # add_address, unused IPv6 2541c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 254234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2543e571fb09SGeliang Tang speed=slow \ 2544e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2545c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2546523514edSGeliang Tang chk_add_nr 1 1 2547ae7bd9ccSMatthieu Baerts fi 2548523514edSGeliang Tang 2549523514edSGeliang Tang # signal address IPv6 2550c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 255134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 255234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 255334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2554e571fb09SGeliang Tang speed=slow \ 2555e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2556c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2557523514edSGeliang Tang chk_add_nr 1 1 2558ae7bd9ccSMatthieu Baerts fi 2559523514edSGeliang Tang 2560523514edSGeliang Tang # single address IPv6, remove 2561c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 256234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 256334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 256434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2565e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2566e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2567c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2568523514edSGeliang Tang chk_add_nr 1 1 25697028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2570ae7bd9ccSMatthieu Baerts fi 2571523514edSGeliang Tang 2572523514edSGeliang Tang # subflow and signal IPv6, remove 2573c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 257434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 257534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 257634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 257734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2578e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2579e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2580c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2581523514edSGeliang Tang chk_add_nr 1 1 2582523514edSGeliang Tang chk_rm_nr 1 1 2583ae7bd9ccSMatthieu Baerts fi 25841002b89fSGeliang Tang} 2585523514edSGeliang Tang 25861002b89fSGeliang Tangv4mapped_tests() 25871002b89fSGeliang Tang{ 2588a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2589c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 259034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 259134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 259234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2593a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2594c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2595ae7bd9ccSMatthieu Baerts fi 2596a6094788SGeliang Tang 2597a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2598c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 259934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 260034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 260134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2602a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2603c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2604a6094788SGeliang Tang chk_add_nr 1 1 2605ae7bd9ccSMatthieu Baerts fi 2606a6094788SGeliang Tang 2607a6094788SGeliang Tang # subflow v4-map-v6 2608c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 260934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 261034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 261134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2612a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2613c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2614ae7bd9ccSMatthieu Baerts fi 2615a6094788SGeliang Tang 2616a6094788SGeliang Tang # signal address v4-map-v6 2617c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 261834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 261934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 262034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2621a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2622c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2623a6094788SGeliang Tang chk_add_nr 1 1 2624ae7bd9ccSMatthieu Baerts fi 2625a6094788SGeliang Tang 2626a6094788SGeliang Tang # subflow v6-map-v4 2627c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 262834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 262934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 263034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2631a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2632c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2633ae7bd9ccSMatthieu Baerts fi 2634a6094788SGeliang Tang 2635a6094788SGeliang Tang # signal address v6-map-v4 2636c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 263734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 263834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 263934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2640a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2641c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2642a6094788SGeliang Tang chk_add_nr 1 1 2643ae7bd9ccSMatthieu Baerts fi 2644a6094788SGeliang Tang 2645a6094788SGeliang Tang # no subflow IPv6 to v4 address 2646c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 264734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 264834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 264934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2650a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2651c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2652ae7bd9ccSMatthieu Baerts fi 2653a6094788SGeliang Tang 2654a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2655c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 265634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 265734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 265834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2659a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2660c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2661ae7bd9ccSMatthieu Baerts fi 2662a6094788SGeliang Tang 2663a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2664c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 266534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 266634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 266734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2668a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2669c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2670ae7bd9ccSMatthieu Baerts fi 26711002b89fSGeliang Tang} 2672a6094788SGeliang Tang 2673ad349374SPaolo Abenimixed_tests() 2674ad349374SPaolo Abeni{ 26756673851bSMatthieu Baerts if reset "IPv4 sockets do not use IPv6 addresses" && 26766673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2677ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2678ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2679ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2680e571fb09SGeliang Tang speed=slow \ 2681e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2682ad349374SPaolo Abeni chk_join_nr 0 0 0 2683ad349374SPaolo Abeni fi 2684ad349374SPaolo Abeni 2685ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 26866673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows" && 26876673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2688ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2689ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2690ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2691e571fb09SGeliang Tang speed=slow \ 2692e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2693ad349374SPaolo Abeni chk_join_nr 1 1 1 2694ad349374SPaolo Abeni fi 2695ad349374SPaolo Abeni 2696ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 26976673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1" && 26986673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2699ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2700ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2701ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2702ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2703e571fb09SGeliang Tang speed=slow \ 2704e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:2::1 2705ad349374SPaolo Abeni chk_join_nr 1 1 1 2706ad349374SPaolo Abeni fi 2707ad349374SPaolo Abeni 2708ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2709ad349374SPaolo Abeni # matching family 27106673851bSMatthieu Baerts if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2" && 27116673851bSMatthieu Baerts continue_if mptcp_lib_kversion_ge 6.3; then 2712ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2713ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2714ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2715ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2716e571fb09SGeliang Tang fullmesh=1 speed=slow \ 2717e571fb09SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2718ad349374SPaolo Abeni chk_join_nr 4 4 4 2719ad349374SPaolo Abeni fi 2720ad349374SPaolo Abeni} 2721ad349374SPaolo Abeni 27221002b89fSGeliang Tangbackup_tests() 27231002b89fSGeliang Tang{ 2724718eb44eSGeliang Tang # single subflow, backup 272507216a3cSMatthieu Baerts if reset "single subflow, backup" && 272607216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 272734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 272834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 272934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2730e571fb09SGeliang Tang sflags=nobackup speed=slow \ 2731e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2732c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2733718eb44eSGeliang Tang chk_prio_nr 0 1 2734ae7bd9ccSMatthieu Baerts fi 2735718eb44eSGeliang Tang 2736718eb44eSGeliang Tang # single address, backup 273707216a3cSMatthieu Baerts if reset "single address, backup" && 273807216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 273934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 274034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 274134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2742e571fb09SGeliang Tang sflags=backup speed=slow \ 2743e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2744c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2745718eb44eSGeliang Tang chk_add_nr 1 1 2746d045b9ebSPaolo Abeni chk_prio_nr 1 1 2747ae7bd9ccSMatthieu Baerts fi 274833397b83SGeliang Tang 274933397b83SGeliang Tang # single address with port, backup 275007216a3cSMatthieu Baerts if reset "single address with port, backup" && 275107216a3cSMatthieu Baerts continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 275234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 275334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 275434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2755e571fb09SGeliang Tang sflags=backup speed=slow \ 2756e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2757c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 275833397b83SGeliang Tang chk_add_nr 1 1 2759d045b9ebSPaolo Abeni chk_prio_nr 1 1 2760ae7bd9ccSMatthieu Baerts fi 2761914f6a59SPaolo Abeni 2762632978f0SMatthieu Baerts if reset "mpc backup" && 2763c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2764914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2765e571fb09SGeliang Tang speed=slow \ 2766e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2767914f6a59SPaolo Abeni chk_join_nr 0 0 0 2768914f6a59SPaolo Abeni chk_prio_nr 0 1 2769914f6a59SPaolo Abeni fi 2770914f6a59SPaolo Abeni 2771632978f0SMatthieu Baerts if reset "mpc backup both sides" && 2772c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2773914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2774914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2775e571fb09SGeliang Tang speed=slow \ 2776e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2777914f6a59SPaolo Abeni chk_join_nr 0 0 0 2778914f6a59SPaolo Abeni chk_prio_nr 1 1 2779914f6a59SPaolo Abeni fi 2780914f6a59SPaolo Abeni 2781632978f0SMatthieu Baerts if reset "mpc switch to backup" && 2782c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2783914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2784e571fb09SGeliang Tang sflags=backup speed=slow \ 2785e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2786914f6a59SPaolo Abeni chk_join_nr 0 0 0 2787914f6a59SPaolo Abeni chk_prio_nr 0 1 2788914f6a59SPaolo Abeni fi 2789914f6a59SPaolo Abeni 2790632978f0SMatthieu Baerts if reset "mpc switch to backup both sides" && 2791c18cf955SGeliang Tang continue_if mptcp_lib_kallsyms_doesnt_have "T mptcp_subflow_send_ack$"; then 2792914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2793914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2794e571fb09SGeliang Tang sflags=backup speed=slow \ 2795e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2796914f6a59SPaolo Abeni chk_join_nr 0 0 0 2797914f6a59SPaolo Abeni chk_prio_nr 1 1 2798914f6a59SPaolo Abeni fi 27991002b89fSGeliang Tang} 2800718eb44eSGeliang Tang 2801178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2802178d0232SGeliang TangLISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2803178d0232SGeliang Tang 2804178d0232SGeliang TangAF_INET=2 2805178d0232SGeliang TangAF_INET6=10 2806178d0232SGeliang Tang 2807178d0232SGeliang Tangverify_listener_events() 2808178d0232SGeliang Tang{ 2809178d0232SGeliang Tang local evt=$1 2810178d0232SGeliang Tang local e_type=$2 2811178d0232SGeliang Tang local e_family=$3 2812178d0232SGeliang Tang local e_saddr=$4 2813178d0232SGeliang Tang local e_sport=$5 2814178d0232SGeliang Tang local type 2815178d0232SGeliang Tang local family 2816178d0232SGeliang Tang local saddr 2817178d0232SGeliang Tang local sport 281896b84195SMatthieu Baerts local name 2819178d0232SGeliang Tang 2820178d0232SGeliang Tang if [ $e_type = $LISTENER_CREATED ]; then 282196b84195SMatthieu Baerts name="LISTENER_CREATED" 2822178d0232SGeliang Tang elif [ $e_type = $LISTENER_CLOSED ]; then 282396b84195SMatthieu Baerts name="LISTENER_CLOSED " 282496b84195SMatthieu Baerts else 282596b84195SMatthieu Baerts name="$e_type" 2826178d0232SGeliang Tang fi 2827178d0232SGeliang Tang 282803668c65SMatthieu Baerts print_check "$name $e_saddr:$e_sport" 282996b84195SMatthieu Baerts 28300471bb47SMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 283103668c65SMatthieu Baerts print_skip "event not supported" 28320471bb47SMatthieu Baerts return 28330471bb47SMatthieu Baerts fi 28340471bb47SMatthieu Baerts 283596b84195SMatthieu Baerts type=$(grep "type:$e_type," $evt | sed -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q') 283696b84195SMatthieu Baerts family=$(grep "type:$e_type," $evt | sed -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q') 283796b84195SMatthieu Baerts sport=$(grep "type:$e_type," $evt | sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 2838178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 283996b84195SMatthieu Baerts saddr=$(grep "type:$e_type," $evt | sed -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 2840178d0232SGeliang Tang else 284196b84195SMatthieu Baerts saddr=$(grep "type:$e_type," $evt | sed -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q') 2842178d0232SGeliang Tang fi 2843178d0232SGeliang Tang 2844178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2845178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2846178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2847178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 284803668c65SMatthieu Baerts print_ok 2849178d0232SGeliang Tang return 0 2850178d0232SGeliang Tang fi 285103668c65SMatthieu Baerts fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport" 2852178d0232SGeliang Tang} 2853178d0232SGeliang Tang 28541002b89fSGeliang Tangadd_addr_ports_tests() 28551002b89fSGeliang Tang{ 28568a127bf6SGeliang Tang # signal address with port 2857c7d49c03SMatthieu Baerts if reset "signal address with port"; then 285834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 285934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 286034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 28618a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2862c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28638a127bf6SGeliang Tang chk_add_nr 1 1 1 2864ae7bd9ccSMatthieu Baerts fi 28658a127bf6SGeliang Tang 28668a127bf6SGeliang Tang # subflow and signal with port 2867c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 286834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 286934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 287034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 287134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28728a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2873c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 28748a127bf6SGeliang Tang chk_add_nr 1 1 1 2875ae7bd9ccSMatthieu Baerts fi 28768a127bf6SGeliang Tang 28778a127bf6SGeliang Tang # single address with port, remove 2878178d0232SGeliang Tang # pm listener events 2879178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 288034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 288134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 288234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2883e571fb09SGeliang Tang addr_nr_ns1=-1 speed=slow \ 2884e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2885c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28868a127bf6SGeliang Tang chk_add_nr 1 1 1 28877028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2888178d0232SGeliang Tang 2889178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2890178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2891178d0232SGeliang Tang kill_events_pids 2892ae7bd9ccSMatthieu Baerts fi 28938a127bf6SGeliang Tang 28948a127bf6SGeliang Tang # subflow and signal with port, remove 2895c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 289634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 289734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 289834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 289934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2900e571fb09SGeliang Tang addr_nr_ns1=-1 addr_nr_ns2=-1 speed=slow \ 2901e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2902c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29038a127bf6SGeliang Tang chk_add_nr 1 1 1 29048a127bf6SGeliang Tang chk_rm_nr 1 1 2905ae7bd9ccSMatthieu Baerts fi 29068a127bf6SGeliang Tang 29078a127bf6SGeliang Tang # subflows and signal with port, flush 2908c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 290934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 291034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 291134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 291234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 291334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2914e571fb09SGeliang Tang addr_nr_ns1=-8 addr_nr_ns2=-2 speed=slow \ 2915e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2916c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 29178a127bf6SGeliang Tang chk_add_nr 1 1 29186fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2919ae7bd9ccSMatthieu Baerts fi 29208a127bf6SGeliang Tang 29218a127bf6SGeliang Tang # multiple addresses with port 2922c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 292334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 292434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 292534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 292634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 29278a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2928c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29298a127bf6SGeliang Tang chk_add_nr 2 2 2 2930ae7bd9ccSMatthieu Baerts fi 29318a127bf6SGeliang Tang 29328a127bf6SGeliang Tang # multiple addresses with ports 2933c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 293434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 293534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 293634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 293734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 29388a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2939c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29408a127bf6SGeliang Tang chk_add_nr 2 2 2 2941ae7bd9ccSMatthieu Baerts fi 29421002b89fSGeliang Tang} 29438a127bf6SGeliang Tang 29441002b89fSGeliang Tangsyncookies_tests() 29451002b89fSGeliang Tang{ 294600587187SFlorian Westphal # single subflow, syncookies 2947c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 294834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 294934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 295034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 295100587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2952c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2953ae7bd9ccSMatthieu Baerts fi 295400587187SFlorian Westphal 295500587187SFlorian Westphal # multiple subflows with syn cookies 2956c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 295734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 295834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 295934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 296034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 296100587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2962c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2963ae7bd9ccSMatthieu Baerts fi 296400587187SFlorian Westphal 296500587187SFlorian Westphal # multiple subflows limited by server 2966c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 296734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 296834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 296934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 297034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 297100587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2972c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 2973ae7bd9ccSMatthieu Baerts fi 297400587187SFlorian Westphal 297500587187SFlorian Westphal # test signal address with cookies 2976c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 297734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 297834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 297934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 298000587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2981c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2982be613160SGeliang Tang chk_add_nr 1 1 2983ae7bd9ccSMatthieu Baerts fi 298400587187SFlorian Westphal 298500587187SFlorian Westphal # test cookie with subflow and signal 2986c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 298734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 298834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 298934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 299034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 299100587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2992c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2993be613160SGeliang Tang chk_add_nr 1 1 2994ae7bd9ccSMatthieu Baerts fi 299500587187SFlorian Westphal 299600587187SFlorian Westphal # accept and use add_addr with additional subflows 2997c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 299834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 299934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 300034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 300134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 300234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 300300587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 3004c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 3005be613160SGeliang Tang chk_add_nr 1 1 3006ae7bd9ccSMatthieu Baerts fi 30071002b89fSGeliang Tang} 30081002b89fSGeliang Tang 3009af66d3e1SGeliang Tangchecksum_tests() 3010af66d3e1SGeliang Tang{ 3011af66d3e1SGeliang Tang # checksum test 0 0 3012ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 301334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 301434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3015af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3016c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3017ae7bd9ccSMatthieu Baerts fi 3018af66d3e1SGeliang Tang 3019af66d3e1SGeliang Tang # checksum test 1 1 3020ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 302134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 302234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3023af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3024c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3025ae7bd9ccSMatthieu Baerts fi 3026af66d3e1SGeliang Tang 3027af66d3e1SGeliang Tang # checksum test 0 1 3028ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 302934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 303034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3031af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3032c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3033ae7bd9ccSMatthieu Baerts fi 3034af66d3e1SGeliang Tang 3035af66d3e1SGeliang Tang # checksum test 1 0 3036ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 303734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 303834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 3039af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3040c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3041ae7bd9ccSMatthieu Baerts fi 3042af66d3e1SGeliang Tang} 3043af66d3e1SGeliang Tang 30440cddb4a6SGeliang Tangdeny_join_id0_tests() 30450cddb4a6SGeliang Tang{ 30460cddb4a6SGeliang Tang # subflow allow join id0 ns1 3047c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 304834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 304934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 305034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30510cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3052c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3053ae7bd9ccSMatthieu Baerts fi 30540cddb4a6SGeliang Tang 30550cddb4a6SGeliang Tang # subflow allow join id0 ns2 3056c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 305734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 305834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 305934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30600cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3061c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 3062ae7bd9ccSMatthieu Baerts fi 30630cddb4a6SGeliang Tang 30640cddb4a6SGeliang Tang # signal address allow join id0 ns1 30650cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3066c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 306734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 306834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 306934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 30700cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3071c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 30720cddb4a6SGeliang Tang chk_add_nr 1 1 3073ae7bd9ccSMatthieu Baerts fi 30740cddb4a6SGeliang Tang 30750cddb4a6SGeliang Tang # signal address allow join id0 ns2 30760cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 3077c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address 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 $ns1 10.0.2.1 flags signal 30810cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3082c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 30830cddb4a6SGeliang Tang chk_add_nr 1 1 3084ae7bd9ccSMatthieu Baerts fi 30850cddb4a6SGeliang Tang 30860cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 3087c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 308834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 308934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 309034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 309134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30920cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3093c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 3094ae7bd9ccSMatthieu Baerts fi 30950cddb4a6SGeliang Tang 30960cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 3097c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 309834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 309934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 310034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 310134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31020cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3103c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 3104ae7bd9ccSMatthieu Baerts fi 31050cddb4a6SGeliang Tang} 31060cddb4a6SGeliang Tang 31074f49d633SGeliang Tangfullmesh_tests() 31084f49d633SGeliang Tang{ 31094f49d633SGeliang Tang # fullmesh 1 31104f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 31114f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 3112c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 311334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 311434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 311534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 311634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 3117e571fb09SGeliang Tang addr_nr_ns1=1 speed=slow \ 3118e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3119c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 31204f49d633SGeliang Tang chk_add_nr 1 1 3121ae7bd9ccSMatthieu Baerts fi 31224f49d633SGeliang Tang 31234f49d633SGeliang Tang # fullmesh 2 31244f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31254f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 3126c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 312734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 312834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 312934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3130e571fb09SGeliang Tang fullmesh=1 speed=slow \ 3131e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3132c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 31334f49d633SGeliang Tang chk_add_nr 1 1 3134ae7bd9ccSMatthieu Baerts fi 31354f49d633SGeliang Tang 31364f49d633SGeliang Tang # fullmesh 3 31374f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31384f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 3139c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 314034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 314134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 314234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3143e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3144e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3145c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 31464f49d633SGeliang Tang chk_add_nr 1 1 3147ae7bd9ccSMatthieu Baerts fi 31484f49d633SGeliang Tang 31494f49d633SGeliang Tang # fullmesh 4 31504f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 31514f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 31524f49d633SGeliang Tang # limit max_subflows to 4. 3153c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 315434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 315534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 315634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3157e571fb09SGeliang Tang fullmesh=2 speed=slow \ 3158e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3159c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 31604f49d633SGeliang Tang chk_add_nr 1 1 3161ae7bd9ccSMatthieu Baerts fi 31626a0653b9SGeliang Tang 31636a0653b9SGeliang Tang # set fullmesh flag 31649db34c42SMatthieu Baerts if reset "set fullmesh flag test" && 31659db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 316634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 316734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 316834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3169e571fb09SGeliang Tang addr_nr_ns2=1 sflags=fullmesh speed=slow \ 3170e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3171c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 31726a0653b9SGeliang Tang chk_rm_nr 0 1 3173ae7bd9ccSMatthieu Baerts fi 31746a0653b9SGeliang Tang 31756a0653b9SGeliang Tang # set nofullmesh flag 31769db34c42SMatthieu Baerts if reset "set nofullmesh flag test" && 31779db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 317834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 317934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 318034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3181e571fb09SGeliang Tang fullmesh=1 sflags=nofullmesh speed=slow \ 3182e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3183c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 31846a0653b9SGeliang Tang chk_rm_nr 0 1 3185ae7bd9ccSMatthieu Baerts fi 31866a0653b9SGeliang Tang 31876a0653b9SGeliang Tang # set backup,fullmesh flags 31889db34c42SMatthieu Baerts if reset "set backup,fullmesh flags test" && 31899db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 319034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 319134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 319234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 3193e571fb09SGeliang Tang addr_nr_ns2=1 sflags=backup,fullmesh speed=slow \ 3194e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3195c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 31966a0653b9SGeliang Tang chk_prio_nr 0 1 31976a0653b9SGeliang Tang chk_rm_nr 0 1 3198ae7bd9ccSMatthieu Baerts fi 31996a0653b9SGeliang Tang 32006a0653b9SGeliang Tang # set nobackup,nofullmesh flags 32019db34c42SMatthieu Baerts if reset "set nobackup,nofullmesh flags test" && 32029db34c42SMatthieu Baerts continue_if mptcp_lib_kversion_ge 5.18; then 320334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 320434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 320534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3206e571fb09SGeliang Tang sflags=nobackup,nofullmesh speed=slow \ 3207e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3208c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 32096a0653b9SGeliang Tang chk_prio_nr 0 1 32106a0653b9SGeliang Tang chk_rm_nr 0 1 3211ae7bd9ccSMatthieu Baerts fi 32124f49d633SGeliang Tang} 32134f49d633SGeliang Tang 321401542c9bSGeliang Tangfastclose_tests() 321501542c9bSGeliang Tang{ 3216ae947bb2SMatthieu Baerts if reset_check_counter "fastclose test" "MPTcpExtMPFastcloseTx"; then 3217080b7f57SGeliang Tang test_linkfail=1024 fastclose=client \ 3218595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3219c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 322001542c9bSGeliang Tang chk_fclose_nr 1 1 322101542c9bSGeliang Tang chk_rst_nr 1 1 invert 3222ae7bd9ccSMatthieu Baerts fi 32236bf41020SPaolo Abeni 3224ae947bb2SMatthieu Baerts if reset_check_counter "fastclose server test" "MPTcpExtMPFastcloseRx"; then 3225080b7f57SGeliang Tang test_linkfail=1024 fastclose=server \ 3226595ef566SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 322755dd3816SPaolo Abeni chk_join_nr 0 0 0 0 0 0 1 32286bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 32296bf41020SPaolo Abeni chk_rst_nr 1 1 32306bf41020SPaolo Abeni fi 323101542c9bSGeliang Tang} 323201542c9bSGeliang Tang 3233b6e074e1SGeliang Tangpedit_action_pkts() 3234b6e074e1SGeliang Tang{ 3235b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3236c43ce398SGeliang Tang grep "packets" | \ 3237b6e074e1SGeliang Tang sed 's/.*"packets":\([0-9]\+\),.*/\1/' 3238b6e074e1SGeliang Tang} 3239b6e074e1SGeliang Tang 3240b6e074e1SGeliang Tangfail_tests() 3241b6e074e1SGeliang Tang{ 3242b6e074e1SGeliang Tang # single subflow 3243b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 32440c93af1fSGeliang Tang test_linkfail=128 \ 32450c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 3246b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 32471f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3248b6e074e1SGeliang Tang fi 32492ba18161SGeliang Tang 32502ba18161SGeliang Tang # multiple subflows 32512ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 32522ba18161SGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 32532ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 32542ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 32552ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 32560c93af1fSGeliang Tang test_linkfail=1024 \ 32570c93af1fSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 32582ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 32592ba18161SGeliang Tang fi 3260b6e074e1SGeliang Tang} 3261b6e074e1SGeliang Tang 32624369c198SGeliang Tanguserspace_pm_add_addr() 32634369c198SGeliang Tang{ 32644369c198SGeliang Tang local addr=$1 32654369c198SGeliang Tang local id=$2 32664369c198SGeliang Tang local tk 32674369c198SGeliang Tang 32684369c198SGeliang Tang tk=$(grep "type:1," "$evts_ns1" | 32694369c198SGeliang Tang sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q') 32704369c198SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl ann $addr token $tk id $id 32714369c198SGeliang Tang sleep 1 32724369c198SGeliang Tang} 32734369c198SGeliang Tang 32744369c198SGeliang Tanguserspace_pm_rm_sf_addr_ns1() 32754369c198SGeliang Tang{ 32764369c198SGeliang Tang local addr=$1 32774369c198SGeliang Tang local id=$2 32784369c198SGeliang Tang local tk sp da dp 3279e8b45937SGeliang Tang local cnt_addr cnt_sf 32804369c198SGeliang Tang 32814369c198SGeliang Tang tk=$(grep "type:1," "$evts_ns1" | 32824369c198SGeliang Tang sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q') 32834369c198SGeliang Tang sp=$(grep "type:10" "$evts_ns1" | 32844369c198SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 32854369c198SGeliang Tang da=$(grep "type:10" "$evts_ns1" | 32864369c198SGeliang Tang sed -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 32874369c198SGeliang Tang dp=$(grep "type:10" "$evts_ns1" | 32884369c198SGeliang Tang sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q') 3289e8b45937SGeliang Tang cnt_addr=$(rm_addr_count ${ns1}) 3290e8b45937SGeliang Tang cnt_sf=$(rm_sf_count ${ns1}) 32914369c198SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl rem token $tk id $id 32924369c198SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl dsf lip "::ffff:$addr" \ 32934369c198SGeliang Tang lport $sp rip $da rport $dp token $tk 3294e8b45937SGeliang Tang wait_rm_addr $ns1 "${cnt_addr}" 3295e8b45937SGeliang Tang wait_rm_sf $ns1 "${cnt_sf}" 32964369c198SGeliang Tang} 32974369c198SGeliang Tang 32984369c198SGeliang Tanguserspace_pm_add_sf() 32994369c198SGeliang Tang{ 33004369c198SGeliang Tang local addr=$1 33014369c198SGeliang Tang local id=$2 33024369c198SGeliang Tang local tk da dp 33034369c198SGeliang Tang 33044369c198SGeliang Tang tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 33054369c198SGeliang Tang da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2") 33064369c198SGeliang Tang dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 33074369c198SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl csf lip $addr lid $id \ 33084369c198SGeliang Tang rip $da rport $dp token $tk 33094369c198SGeliang Tang sleep 1 33104369c198SGeliang Tang} 33114369c198SGeliang Tang 33124369c198SGeliang Tanguserspace_pm_rm_sf_addr_ns2() 33134369c198SGeliang Tang{ 33144369c198SGeliang Tang local addr=$1 33154369c198SGeliang Tang local id=$2 33164369c198SGeliang Tang local tk da dp sp 3317e8b45937SGeliang Tang local cnt_addr cnt_sf 33184369c198SGeliang Tang 33194369c198SGeliang Tang tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 33204369c198SGeliang Tang da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2") 33214369c198SGeliang Tang dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 33224369c198SGeliang Tang sp=$(grep "type:10" "$evts_ns2" | 33234369c198SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 3324e8b45937SGeliang Tang cnt_addr=$(rm_addr_count ${ns2}) 3325e8b45937SGeliang Tang cnt_sf=$(rm_sf_count ${ns2}) 33264369c198SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl rem token $tk id $id 33274369c198SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl dsf lip $addr lport $sp \ 33284369c198SGeliang Tang rip $da rport $dp token $tk 3329e8b45937SGeliang Tang wait_rm_addr $ns2 "${cnt_addr}" 3330e8b45937SGeliang Tang wait_rm_sf $ns2 "${cnt_sf}" 33314369c198SGeliang Tang} 33324369c198SGeliang Tang 33335ac1d2d6SMat Martineauuserspace_tests() 33345ac1d2d6SMat Martineau{ 33355ac1d2d6SMat Martineau # userspace pm type prevents add_addr 3336f2b492b0SMatthieu Baerts if reset "userspace pm type prevents add_addr" && 3337f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33385ac1d2d6SMat Martineau set_userspace_pm $ns1 33395ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 33405ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 33415ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 33425ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33435ac1d2d6SMat Martineau chk_join_nr 0 0 0 33445ac1d2d6SMat Martineau chk_add_nr 0 0 33455ac1d2d6SMat Martineau fi 33465ac1d2d6SMat Martineau 3347b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3348f2b492b0SMatthieu Baerts if reset "userspace pm no echo w/o daemon" && 3349f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 3350b3b71bf9SMat Martineau set_userspace_pm $ns2 3351b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3352b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3353b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3354b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3355b3b71bf9SMat Martineau chk_join_nr 0 0 0 3356b3b71bf9SMat Martineau chk_add_nr 1 0 3357b3b71bf9SMat Martineau fi 3358b3b71bf9SMat Martineau 33595ac1d2d6SMat Martineau # userspace pm type rejects join 3360f2b492b0SMatthieu Baerts if reset "userspace pm type rejects join" && 3361f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33625ac1d2d6SMat Martineau set_userspace_pm $ns1 33635ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 33645ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 33655ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 33665ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33675ac1d2d6SMat Martineau chk_join_nr 1 1 0 33685ac1d2d6SMat Martineau fi 33695ac1d2d6SMat Martineau 33705ac1d2d6SMat Martineau # userspace pm type does not send join 3371f2b492b0SMatthieu Baerts if reset "userspace pm type does not send join" && 3372f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33735ac1d2d6SMat Martineau set_userspace_pm $ns2 33745ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 33755ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 33765ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 33775ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 33785ac1d2d6SMat Martineau chk_join_nr 0 0 0 33795ac1d2d6SMat Martineau fi 33805ac1d2d6SMat Martineau 33815ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 3382f2b492b0SMatthieu Baerts if reset "userspace pm type prevents mp_prio" && 3383f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33845ac1d2d6SMat Martineau set_userspace_pm $ns1 33855ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 33865ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 33875ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3388e571fb09SGeliang Tang sflags=backup speed=slow \ 3389e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 33905ac1d2d6SMat Martineau chk_join_nr 1 1 0 33915ac1d2d6SMat Martineau chk_prio_nr 0 0 33925ac1d2d6SMat Martineau fi 33935ac1d2d6SMat Martineau 33945ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 3395f2b492b0SMatthieu Baerts if reset "userspace pm type prevents rm_addr" && 3396f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 33975ac1d2d6SMat Martineau set_userspace_pm $ns1 33985ac1d2d6SMat Martineau set_userspace_pm $ns2 33995ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 34005ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 34015ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3402e571fb09SGeliang Tang addr_nr_ns2=-1 speed=slow \ 3403e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 34045ac1d2d6SMat Martineau chk_join_nr 0 0 0 34055ac1d2d6SMat Martineau chk_rm_nr 0 0 34065ac1d2d6SMat Martineau fi 340797040cf9SGeliang Tang 340897040cf9SGeliang Tang # userspace pm add & remove address 3409f2b492b0SMatthieu Baerts if reset_with_events "userspace pm add & remove address" && 3410f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 341197040cf9SGeliang Tang set_userspace_pm $ns1 341297040cf9SGeliang Tang pm_nl_set_limits $ns2 1 1 34131c6d07ddSGeliang Tang speed=5 \ 3414e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 34154369c198SGeliang Tang local tests_pid=$! 34164369c198SGeliang Tang wait_mpj $ns1 34174369c198SGeliang Tang userspace_pm_add_addr 10.0.2.1 10 341897040cf9SGeliang Tang chk_join_nr 1 1 1 341997040cf9SGeliang Tang chk_add_nr 1 1 3420d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3421d7ced753SGeliang Tang chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 34224369c198SGeliang Tang userspace_pm_rm_sf_addr_ns1 10.0.2.1 10 342397040cf9SGeliang Tang chk_rm_nr 1 1 invert 3424d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3425a3735625SGeliang Tang kill_events_pids 3426a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 342797040cf9SGeliang Tang fi 34285e986ec4SGeliang Tang 34295e986ec4SGeliang Tang # userspace pm create destroy subflow 3430f2b492b0SMatthieu Baerts if reset_with_events "userspace pm create destroy subflow" && 3431f2b492b0SMatthieu Baerts continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 34325e986ec4SGeliang Tang set_userspace_pm $ns2 34335e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 34341c6d07ddSGeliang Tang speed=5 \ 3435e571fb09SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 & 34364369c198SGeliang Tang local tests_pid=$! 34374369c198SGeliang Tang wait_mpj $ns2 34384369c198SGeliang Tang userspace_pm_add_sf 10.0.3.2 20 34395e986ec4SGeliang Tang chk_join_nr 1 1 1 3440d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 34414369c198SGeliang Tang userspace_pm_rm_sf_addr_ns2 10.0.3.2 20 34426c160b63SGeliang Tang chk_rm_nr 1 1 3443d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3444a3735625SGeliang Tang kill_events_pids 3445a259173bSMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 34465e986ec4SGeliang Tang fi 34475ac1d2d6SMat Martineau} 34485ac1d2d6SMat Martineau 3449e274f715SPaolo Abeniendpoint_tests() 345069c6ce7bSPaolo Abeni{ 345136c4127aSMatthieu Baerts # subflow_rebuild_header is needed to support the implicit flag 345269c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 345336c4127aSMatthieu Baerts if reset "implicit EP" && 345436c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 345569c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 345669c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 345769c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3458e571fb09SGeliang Tang speed=slow \ 3459*358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3460*358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 346169c6ce7bSPaolo Abeni 346269c6ce7bSPaolo Abeni wait_mpj $ns1 346303668c65SMatthieu Baerts pm_nl_check_endpoint "creation" \ 346469c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 3465d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3466d7ced753SGeliang Tang chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 346769c6ce7bSPaolo Abeni 34681dc88d24SMatthieu Baerts pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null 346903668c65SMatthieu Baerts pm_nl_check_endpoint "ID change is prevented" \ 347069c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 347169c6ce7bSPaolo Abeni 347269c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 347303668c65SMatthieu Baerts pm_nl_check_endpoint "modif is allowed" \ 347469c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3475*358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3476ae7bd9ccSMatthieu Baerts fi 3477e274f715SPaolo Abeni 347836c4127aSMatthieu Baerts if reset "delete and re-add" && 347936c4127aSMatthieu Baerts mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then 3480e274f715SPaolo Abeni pm_nl_set_limits $ns1 1 1 3481e274f715SPaolo Abeni pm_nl_set_limits $ns2 1 1 3482e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3483e571fb09SGeliang Tang test_linkfail=4 speed=20 \ 3484*358f02b8SMatthieu Baerts (NGI0) run_tests $ns1 $ns2 10.0.1.1 & 3485*358f02b8SMatthieu Baerts (NGI0) local tests_pid=$! 3486e274f715SPaolo Abeni 3487e274f715SPaolo Abeni wait_mpj $ns2 348803668c65SMatthieu Baerts chk_subflow_nr "before delete" 2 3489d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 34909095ce97SGeliang Tang 3491e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3492e274f715SPaolo Abeni sleep 0.5 349303668c65SMatthieu Baerts chk_subflow_nr "after delete" 1 3494d7ced753SGeliang Tang chk_mptcp_info subflows 0 subflows 0 3495e274f715SPaolo Abeni 3496e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3497e274f715SPaolo Abeni wait_mpj $ns2 349803668c65SMatthieu Baerts chk_subflow_nr "after re-add" 2 3499d7ced753SGeliang Tang chk_mptcp_info subflows 1 subflows 1 3500*358f02b8SMatthieu Baerts (NGI0) mptcp_lib_kill_wait $tests_pid 3501e274f715SPaolo Abeni fi 350269c6ce7bSPaolo Abeni} 350369c6ce7bSPaolo Abeni 350422514d52SMatthieu Baerts# [$1: error message] 35051002b89fSGeliang Tangusage() 35061002b89fSGeliang Tang{ 350722514d52SMatthieu Baerts if [ -n "${1}" ]; then 350822514d52SMatthieu Baerts echo "${1}" 350922514d52SMatthieu Baerts ret=1 351022514d52SMatthieu Baerts fi 351122514d52SMatthieu Baerts 35121002b89fSGeliang Tang echo "mptcp_join usage:" 35133afd0280SMatthieu Baerts 35143afd0280SMatthieu Baerts local key 35153afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 35163afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 35173afd0280SMatthieu Baerts done 35183afd0280SMatthieu Baerts 3519a673321aSMat Martineau echo " -c capture pcap files" 3520af66d3e1SGeliang Tang echo " -C enable data checksum" 3521621bd393SGeliang Tang echo " -i use ip mptcp" 35221002b89fSGeliang Tang echo " -h help" 352322514d52SMatthieu Baerts 3524c7d49c03SMatthieu Baerts echo "[test ids|names]" 3525ae7bd9ccSMatthieu Baerts 352622514d52SMatthieu Baerts exit ${ret} 35271002b89fSGeliang Tang} 35281002b89fSGeliang Tang 3529a673321aSMat Martineau 35303afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 35313afd0280SMatthieu Baertsall_tests_sorted=( 35323afd0280SMatthieu Baerts f@subflows_tests 35333afd0280SMatthieu Baerts e@subflows_error_tests 35343afd0280SMatthieu Baerts s@signal_address_tests 35353afd0280SMatthieu Baerts l@link_failure_tests 35363afd0280SMatthieu Baerts t@add_addr_timeout_tests 35373afd0280SMatthieu Baerts r@remove_tests 35383afd0280SMatthieu Baerts a@add_tests 35393afd0280SMatthieu Baerts 6@ipv6_tests 35403afd0280SMatthieu Baerts 4@v4mapped_tests 3541ad349374SPaolo Abeni M@mixed_tests 35423afd0280SMatthieu Baerts b@backup_tests 35433afd0280SMatthieu Baerts p@add_addr_ports_tests 35443afd0280SMatthieu Baerts k@syncookies_tests 35453afd0280SMatthieu Baerts S@checksum_tests 35463afd0280SMatthieu Baerts d@deny_join_id0_tests 35473afd0280SMatthieu Baerts m@fullmesh_tests 35483afd0280SMatthieu Baerts z@fastclose_tests 3549b6e074e1SGeliang Tang F@fail_tests 35505ac1d2d6SMat Martineau u@userspace_tests 3551e274f715SPaolo Abeni I@endpoint_tests 35523afd0280SMatthieu Baerts) 35533afd0280SMatthieu Baerts 35543afd0280SMatthieu Baertsall_tests_args="" 35553afd0280SMatthieu Baertsall_tests_names=() 35563afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 35573afd0280SMatthieu Baerts key="${subtests%@*}" 35583afd0280SMatthieu Baerts value="${subtests#*@}" 35593afd0280SMatthieu Baerts 35603afd0280SMatthieu Baerts all_tests_args+="${key}" 35613afd0280SMatthieu Baerts all_tests_names+=("${value}") 35623afd0280SMatthieu Baerts all_tests[${key}]="${value}" 35633afd0280SMatthieu Baertsdone 35643afd0280SMatthieu Baerts 3565826d7bdcSMatthieu Baertstests=() 35663afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 35671002b89fSGeliang Tang case $opt in 35683afd0280SMatthieu Baerts ["${all_tests_args}"]) 35693afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 357069c6ce7bSPaolo Abeni ;; 3571a673321aSMat Martineau c) 3572826d7bdcSMatthieu Baerts capture=1 3573a673321aSMat Martineau ;; 3574af66d3e1SGeliang Tang C) 3575826d7bdcSMatthieu Baerts checksum=1 3576af66d3e1SGeliang Tang ;; 3577621bd393SGeliang Tang i) 3578826d7bdcSMatthieu Baerts ip_mptcp=1 3579621bd393SGeliang Tang ;; 358022514d52SMatthieu Baerts h) 35811002b89fSGeliang Tang usage 35821002b89fSGeliang Tang ;; 358322514d52SMatthieu Baerts *) 358422514d52SMatthieu Baerts usage "Unknown option: -${opt}" 358522514d52SMatthieu Baerts ;; 35861002b89fSGeliang Tang esac 35871002b89fSGeliang Tangdone 358800587187SFlorian Westphal 3589ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3590ae7bd9ccSMatthieu Baerts 3591ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3592ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3593c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3594ae7bd9ccSMatthieu Baerts else 3595c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3596ae7bd9ccSMatthieu Baerts fi 3597ae7bd9ccSMatthieu Baertsdone 3598ae7bd9ccSMatthieu Baerts 3599826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 36003afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 36013afd0280SMatthieu Baertsfi 36023afd0280SMatthieu Baerts 3603826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3604826d7bdcSMatthieu Baerts "${subtests}" 3605826d7bdcSMatthieu Baertsdone 3606826d7bdcSMatthieu Baerts 360739aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 360839aab882SMatthieu Baerts echo 360939aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 361039aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 361139aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 361239aab882SMatthieu Baerts done 361339aab882SMatthieu Baerts echo 361439aab882SMatthieu Baertsfi 361539aab882SMatthieu Baerts 36167f117cd3SMatthieu Baertsappend_prev_results 36177f117cd3SMatthieu Baertsmptcp_lib_result_print_all_tap 36187f117cd3SMatthieu Baerts 3619b08fbf24SPaolo Abeniexit $ret 3620