1b08fbf24SPaolo Abeni#!/bin/bash 2b08fbf24SPaolo Abeni# SPDX-License-Identifier: GPL-2.0 3b08fbf24SPaolo Abeni 4d8d08302SMatthieu Baerts# Double quotes to prevent globbing and word splitting is recommended in new 5d8d08302SMatthieu Baerts# code but we accept it, especially because there were too many before having 6d8d08302SMatthieu Baerts# address all other issues detected by shellcheck. 7d8d08302SMatthieu Baerts#shellcheck disable=SC2086 8d8d08302SMatthieu Baerts 90fcd72dfSMatthieu Baerts# ShellCheck incorrectly believes that most of the code here is unreachable 100fcd72dfSMatthieu Baerts# because it's invoked by variable name, see how the "tests" array is used 110fcd72dfSMatthieu Baerts#shellcheck disable=SC2317 120fcd72dfSMatthieu Baerts 13715c78a8SMatthieu Baerts. "$(dirname "${0}")/mptcp_lib.sh" 14715c78a8SMatthieu Baerts 15b08fbf24SPaolo Abeniret=0 16b08fbf24SPaolo Abenisin="" 177d1e6f16SPaolo Abenisinfail="" 18b08fbf24SPaolo Abenisout="" 19b08fbf24SPaolo Abenicin="" 207d1e6f16SPaolo Abenicinfail="" 218b819a84SFlorian Westphalcinsent="" 22d328fe87SMatthieu Baertstmpfile="" 23b08fbf24SPaolo Abenicout="" 241e777bd8SMatthieu Baertscapout="" 251e777bd8SMatthieu Baertsns1="" 261e777bd8SMatthieu Baertsns2="" 27b08fbf24SPaolo Abeniksft_skip=4 285888a61cSMatthieu Baertstimeout_poll=30 295888a61cSMatthieu Baertstimeout_test=$((timeout_poll * 2 + 1)) 30b08fbf24SPaolo Abenicapture=0 31af66d3e1SGeliang Tangchecksum=0 3234aa6e3bSGeliang Tangip_mptcp=0 338117dac3SGeliang Tangcheck_invert=0 343c082695SGeliang Tangvalidate_checksum=0 3593827ad5SMatthieu Baertsinit=0 36a3735625SGeliang Tangevts_ns1="" 37a3735625SGeliang Tangevts_ns2="" 38a3735625SGeliang Tangevts_ns1_pid=0 39a3735625SGeliang Tangevts_ns2_pid=0 40b08fbf24SPaolo Abeni 413afd0280SMatthieu Baertsdeclare -A all_tests 42c7d49c03SMatthieu Baertsdeclare -a only_tests_ids 43c7d49c03SMatthieu Baertsdeclare -a only_tests_names 4439aab882SMatthieu Baertsdeclare -A failed_tests 45b08fbf24SPaolo AbeniTEST_COUNT=0 46c7d49c03SMatthieu BaertsTEST_NAME="" 479a0a9367SGeliang Tangnr_blank=40 48b08fbf24SPaolo Abeni 49e59300ceSMatthieu Baertsexport FAILING_LINKS="" 50e59300ceSMatthieu Baerts 518d014eaaSGeliang Tang# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 528d014eaaSGeliang Tang# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 538d014eaaSGeliang TangCBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 548d014eaaSGeliang Tang 48 0 0 0, 558d014eaaSGeliang Tang 84 0 0 240, 568d014eaaSGeliang Tang 21 0 3 64, 578d014eaaSGeliang Tang 48 0 0 54, 588d014eaaSGeliang Tang 84 0 0 240, 598d014eaaSGeliang Tang 21 6 7 48, 608d014eaaSGeliang Tang 48 0 0 0, 618d014eaaSGeliang Tang 84 0 0 240, 628d014eaaSGeliang Tang 21 0 4 96, 638d014eaaSGeliang Tang 48 0 0 74, 648d014eaaSGeliang Tang 84 0 0 240, 658d014eaaSGeliang Tang 21 0 1 48, 668d014eaaSGeliang Tang 6 0 0 65535, 678d014eaaSGeliang Tang 6 0 0 0" 688d014eaaSGeliang Tang 6993827ad5SMatthieu Baertsinit_partial() 70b08fbf24SPaolo Abeni{ 71b08fbf24SPaolo Abeni capout=$(mktemp) 72b08fbf24SPaolo Abeni 73787eb1e4SMatthieu Baerts local sec rndh 74787eb1e4SMatthieu Baerts sec=$(date +%s) 75787eb1e4SMatthieu Baerts rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 76b08fbf24SPaolo Abeni 77b08fbf24SPaolo Abeni ns1="ns1-$rndh" 78b08fbf24SPaolo Abeni ns2="ns2-$rndh" 79b08fbf24SPaolo Abeni 801e777bd8SMatthieu Baerts local netns 81b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 82b08fbf24SPaolo Abeni ip netns add $netns || exit $ksft_skip 83b08fbf24SPaolo Abeni ip -net $netns link set lo up 84b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.mptcp.enabled=1 855ac1d2d6SMat Martineau ip netns exec $netns sysctl -q net.mptcp.pm_type=0 86b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 87b08fbf24SPaolo Abeni ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 88af66d3e1SGeliang Tang if [ $checksum -eq 1 ]; then 89af66d3e1SGeliang Tang ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 90af66d3e1SGeliang Tang fi 91b08fbf24SPaolo Abeni done 92b08fbf24SPaolo Abeni 938117dac3SGeliang Tang check_invert=0 943c082695SGeliang Tang validate_checksum=$checksum 95e59300ceSMatthieu Baerts FAILING_LINKS="" 968117dac3SGeliang Tang 97b08fbf24SPaolo Abeni # ns1 ns2 98b08fbf24SPaolo Abeni # ns1eth1 ns2eth1 99b08fbf24SPaolo Abeni # ns1eth2 ns2eth2 100b08fbf24SPaolo Abeni # ns1eth3 ns2eth3 101b08fbf24SPaolo Abeni # ns1eth4 ns2eth4 102b08fbf24SPaolo Abeni 1031e777bd8SMatthieu Baerts local i 1044bfadd71SMatthieu Baerts for i in $(seq 1 4); do 105b08fbf24SPaolo Abeni ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 106b08fbf24SPaolo Abeni ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 107b08fbf24SPaolo Abeni ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 108b08fbf24SPaolo Abeni ip -net "$ns1" link set ns1eth$i up 109b08fbf24SPaolo Abeni 110b08fbf24SPaolo Abeni ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 111b08fbf24SPaolo Abeni ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 112b08fbf24SPaolo Abeni ip -net "$ns2" link set ns2eth$i up 113b08fbf24SPaolo Abeni 114b08fbf24SPaolo Abeni # let $ns2 reach any $ns1 address from any interface 115b08fbf24SPaolo Abeni ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 1169846921dSPaolo Abeni ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 117b08fbf24SPaolo Abeni done 118b08fbf24SPaolo Abeni} 119b08fbf24SPaolo Abeni 1207d1e6f16SPaolo Abeniinit_shapers() 1217d1e6f16SPaolo Abeni{ 1221e777bd8SMatthieu Baerts local i 1234bfadd71SMatthieu Baerts for i in $(seq 1 4); do 1247d1e6f16SPaolo Abeni tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 1257d1e6f16SPaolo Abeni tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 1267d1e6f16SPaolo Abeni done 1277d1e6f16SPaolo Abeni} 1287d1e6f16SPaolo Abeni 129b08fbf24SPaolo Abenicleanup_partial() 130b08fbf24SPaolo Abeni{ 131b08fbf24SPaolo Abeni rm -f "$capout" 132b08fbf24SPaolo Abeni 1331e777bd8SMatthieu Baerts local netns 134b08fbf24SPaolo Abeni for netns in "$ns1" "$ns2"; do 135b08fbf24SPaolo Abeni ip netns del $netns 136c2a55e8fSMatthieu Baerts rm -f /tmp/$netns.{nstat,out} 137b08fbf24SPaolo Abeni done 138b08fbf24SPaolo Abeni} 139b08fbf24SPaolo Abeni 14087154755SMatthieu Baertscheck_tools() 14187154755SMatthieu Baerts{ 142715c78a8SMatthieu Baerts mptcp_lib_check_mptcp 143715c78a8SMatthieu Baerts 14487154755SMatthieu Baerts if ! ip -Version &> /dev/null; then 14587154755SMatthieu Baerts echo "SKIP: Could not run test without ip tool" 14687154755SMatthieu Baerts exit $ksft_skip 14787154755SMatthieu Baerts fi 14887154755SMatthieu Baerts 14987154755SMatthieu Baerts if ! iptables -V &> /dev/null; then 15087154755SMatthieu Baerts echo "SKIP: Could not run all tests without iptables tool" 15187154755SMatthieu Baerts exit $ksft_skip 15287154755SMatthieu Baerts fi 15387154755SMatthieu Baerts 15487154755SMatthieu Baerts if ! ip6tables -V &> /dev/null; then 15587154755SMatthieu Baerts echo "SKIP: Could not run all tests without ip6tables tool" 15687154755SMatthieu Baerts exit $ksft_skip 15787154755SMatthieu Baerts fi 15887154755SMatthieu Baerts} 15987154755SMatthieu Baerts 16093827ad5SMatthieu Baertsinit() { 16193827ad5SMatthieu Baerts init=1 16293827ad5SMatthieu Baerts 16387154755SMatthieu Baerts check_tools 16487154755SMatthieu Baerts 16593827ad5SMatthieu Baerts sin=$(mktemp) 16693827ad5SMatthieu Baerts sout=$(mktemp) 16793827ad5SMatthieu Baerts cin=$(mktemp) 16893827ad5SMatthieu Baerts cinsent=$(mktemp) 16993827ad5SMatthieu Baerts cout=$(mktemp) 170a3735625SGeliang Tang evts_ns1=$(mktemp) 171a3735625SGeliang Tang evts_ns2=$(mktemp) 17293827ad5SMatthieu Baerts 17393827ad5SMatthieu Baerts trap cleanup EXIT 17493827ad5SMatthieu Baerts 17593827ad5SMatthieu Baerts make_file "$cin" "client" 1 17693827ad5SMatthieu Baerts make_file "$sin" "server" 1 17793827ad5SMatthieu Baerts} 17893827ad5SMatthieu Baerts 179b08fbf24SPaolo Abenicleanup() 180b08fbf24SPaolo Abeni{ 1817d1e6f16SPaolo Abeni rm -f "$cin" "$cout" "$sinfail" 1827d1e6f16SPaolo Abeni rm -f "$sin" "$sout" "$cinsent" "$cinfail" 183d328fe87SMatthieu Baerts rm -f "$tmpfile" 184a3735625SGeliang Tang rm -rf $evts_ns1 $evts_ns2 185b08fbf24SPaolo Abeni cleanup_partial 186b08fbf24SPaolo Abeni} 187b08fbf24SPaolo Abeni 188ae7bd9ccSMatthieu Baertsskip_test() 189ae7bd9ccSMatthieu Baerts{ 190c7d49c03SMatthieu Baerts if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 191ae7bd9ccSMatthieu Baerts return 1 192ae7bd9ccSMatthieu Baerts fi 193ae7bd9ccSMatthieu Baerts 194ae7bd9ccSMatthieu Baerts local i 195c7d49c03SMatthieu Baerts for i in "${only_tests_ids[@]}"; do 196ae7bd9ccSMatthieu Baerts if [ "${TEST_COUNT}" -eq "${i}" ]; then 197ae7bd9ccSMatthieu Baerts return 1 198ae7bd9ccSMatthieu Baerts fi 199ae7bd9ccSMatthieu Baerts done 200c7d49c03SMatthieu Baerts for i in "${only_tests_names[@]}"; do 201c7d49c03SMatthieu Baerts if [ "${TEST_NAME}" = "${i}" ]; then 202c7d49c03SMatthieu Baerts return 1 203c7d49c03SMatthieu Baerts fi 204c7d49c03SMatthieu Baerts done 205ae7bd9ccSMatthieu Baerts 206ae7bd9ccSMatthieu Baerts return 0 207ae7bd9ccSMatthieu Baerts} 208ae7bd9ccSMatthieu Baerts 209c7d49c03SMatthieu Baerts# $1: test name 210b08fbf24SPaolo Abenireset() 211b08fbf24SPaolo Abeni{ 212c7d49c03SMatthieu Baerts TEST_NAME="${1}" 213c7d49c03SMatthieu Baerts 214ae7bd9ccSMatthieu Baerts TEST_COUNT=$((TEST_COUNT+1)) 215ae7bd9ccSMatthieu Baerts 216ae7bd9ccSMatthieu Baerts if skip_test; then 217ae7bd9ccSMatthieu Baerts return 1 218ae7bd9ccSMatthieu Baerts fi 219ae7bd9ccSMatthieu Baerts 22093827ad5SMatthieu Baerts if [ "${init}" != "1" ]; then 221b08fbf24SPaolo Abeni init 22293827ad5SMatthieu Baerts else 22393827ad5SMatthieu Baerts cleanup_partial 22493827ad5SMatthieu Baerts fi 22593827ad5SMatthieu Baerts 22693827ad5SMatthieu Baerts init_partial 227ae7bd9ccSMatthieu Baerts 228ae7bd9ccSMatthieu Baerts return 0 229b08fbf24SPaolo Abeni} 230b08fbf24SPaolo Abeni 231c7d49c03SMatthieu Baerts# $1: test name 23200587187SFlorian Westphalreset_with_cookies() 23300587187SFlorian Westphal{ 234c7d49c03SMatthieu Baerts reset "${1}" || return 1 23500587187SFlorian Westphal 2361e777bd8SMatthieu Baerts local netns 23700587187SFlorian Westphal for netns in "$ns1" "$ns2"; do 23800587187SFlorian Westphal ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 23900587187SFlorian Westphal done 24000587187SFlorian Westphal} 24100587187SFlorian Westphal 242c7d49c03SMatthieu Baerts# $1: test name 2438d014eaaSGeliang Tangreset_with_add_addr_timeout() 2448d014eaaSGeliang Tang{ 245c7d49c03SMatthieu Baerts local ip="${2:-4}" 2468d014eaaSGeliang Tang local tables 2478d014eaaSGeliang Tang 248c7d49c03SMatthieu Baerts reset "${1}" || return 1 249c7d49c03SMatthieu Baerts 2508d014eaaSGeliang Tang tables="iptables" 2518d014eaaSGeliang Tang if [ $ip -eq 6 ]; then 2528d014eaaSGeliang Tang tables="ip6tables" 2538d014eaaSGeliang Tang fi 2548d014eaaSGeliang Tang 2558d014eaaSGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2568d014eaaSGeliang Tang ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 2578d014eaaSGeliang Tang -m tcp --tcp-option 30 \ 2588d014eaaSGeliang Tang -m bpf --bytecode \ 2598d014eaaSGeliang Tang "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 2608d014eaaSGeliang Tang -j DROP 2618d014eaaSGeliang Tang} 2628d014eaaSGeliang Tang 263c7d49c03SMatthieu Baerts# $1: test name 264af66d3e1SGeliang Tangreset_with_checksum() 265af66d3e1SGeliang Tang{ 266af66d3e1SGeliang Tang local ns1_enable=$1 267af66d3e1SGeliang Tang local ns2_enable=$2 268af66d3e1SGeliang Tang 269c7d49c03SMatthieu Baerts reset "checksum test ${1} ${2}" || return 1 270af66d3e1SGeliang Tang 271af66d3e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 272af66d3e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 2733c082695SGeliang Tang 2743c082695SGeliang Tang validate_checksum=1 275af66d3e1SGeliang Tang} 276af66d3e1SGeliang Tang 2770cddb4a6SGeliang Tangreset_with_allow_join_id0() 2780cddb4a6SGeliang Tang{ 279c7d49c03SMatthieu Baerts local ns1_enable=$2 280c7d49c03SMatthieu Baerts local ns2_enable=$3 2810cddb4a6SGeliang Tang 282c7d49c03SMatthieu Baerts reset "${1}" || return 1 2830cddb4a6SGeliang Tang 2840cddb4a6SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 2850cddb4a6SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 2860cddb4a6SGeliang Tang} 2870cddb4a6SGeliang Tang 288b6e074e1SGeliang Tang# Modify TCP payload without corrupting the TCP packet 289b6e074e1SGeliang Tang# 290b6e074e1SGeliang Tang# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 291b6e074e1SGeliang Tang# carrying enough data. 292b6e074e1SGeliang Tang# Once it is done, the TCP Checksum field is updated so the packet is still 293b6e074e1SGeliang Tang# considered as valid at the TCP level. 294b6e074e1SGeliang Tang# Because the MPTCP checksum, covering the TCP options and data, has not been 295b6e074e1SGeliang Tang# updated, the modification will be detected and an MP_FAIL will be emitted: 296b6e074e1SGeliang Tang# what we want to validate here without corrupting "random" MPTCP options. 297b6e074e1SGeliang Tang# 298b6e074e1SGeliang Tang# To avoid having tc producing this pr_info() message for each TCP ACK packets 299b6e074e1SGeliang Tang# not carrying enough data: 300b6e074e1SGeliang Tang# 301b6e074e1SGeliang Tang# tc action pedit offset 162 out of bounds 302b6e074e1SGeliang Tang# 303b6e074e1SGeliang Tang# Netfilter is used to mark packets with enough data. 304b6e074e1SGeliang Tangreset_with_fail() 305b6e074e1SGeliang Tang{ 306b6e074e1SGeliang Tang reset "${1}" || return 1 307b6e074e1SGeliang Tang 308b6e074e1SGeliang Tang ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 309b6e074e1SGeliang Tang ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 310b6e074e1SGeliang Tang 311b6e074e1SGeliang Tang check_invert=1 312b6e074e1SGeliang Tang validate_checksum=1 313b6e074e1SGeliang Tang local i="$2" 314b6e074e1SGeliang Tang local ip="${3:-4}" 315b6e074e1SGeliang Tang local tables 316b6e074e1SGeliang Tang 317b6e074e1SGeliang Tang tables="iptables" 318b6e074e1SGeliang Tang if [ $ip -eq 6 ]; then 319b6e074e1SGeliang Tang tables="ip6tables" 320b6e074e1SGeliang Tang fi 321b6e074e1SGeliang Tang 322b6e074e1SGeliang Tang ip netns exec $ns2 $tables \ 323b6e074e1SGeliang Tang -t mangle \ 324b6e074e1SGeliang Tang -A OUTPUT \ 325b6e074e1SGeliang Tang -o ns2eth$i \ 326b6e074e1SGeliang Tang -p tcp \ 327b6e074e1SGeliang Tang -m length --length 150:9999 \ 328b6e074e1SGeliang Tang -m statistic --mode nth --packet 1 --every 99999 \ 329b6e074e1SGeliang Tang -j MARK --set-mark 42 || exit 1 330b6e074e1SGeliang Tang 331b6e074e1SGeliang Tang tc -n $ns2 qdisc add dev ns2eth$i clsact || exit 1 332b6e074e1SGeliang Tang tc -n $ns2 filter add dev ns2eth$i egress \ 333b6e074e1SGeliang Tang protocol ip prio 1000 \ 334b6e074e1SGeliang Tang handle 42 fw \ 335b6e074e1SGeliang Tang action pedit munge offset 148 u8 invert \ 336b6e074e1SGeliang Tang pipe csum tcp \ 337b6e074e1SGeliang Tang index 100 || exit 1 338b6e074e1SGeliang Tang} 339b6e074e1SGeliang Tang 340a3735625SGeliang Tangreset_with_events() 341a3735625SGeliang Tang{ 342a3735625SGeliang Tang reset "${1}" || return 1 343a3735625SGeliang Tang 344a3735625SGeliang Tang :> "$evts_ns1" 345a3735625SGeliang Tang :> "$evts_ns2" 346a3735625SGeliang Tang ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 347a3735625SGeliang Tang evts_ns1_pid=$! 348a3735625SGeliang Tang ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 349a3735625SGeliang Tang evts_ns2_pid=$! 350a3735625SGeliang Tang} 351a3735625SGeliang Tang 35239aab882SMatthieu Baertsfail_test() 35339aab882SMatthieu Baerts{ 35439aab882SMatthieu Baerts ret=1 35539aab882SMatthieu Baerts failed_tests[${TEST_COUNT}]="${TEST_NAME}" 35639aab882SMatthieu Baerts} 35739aab882SMatthieu Baerts 35839aab882SMatthieu Baertsget_failed_tests_ids() 35939aab882SMatthieu Baerts{ 36039aab882SMatthieu Baerts # sorted 36139aab882SMatthieu Baerts local i 36239aab882SMatthieu Baerts for i in "${!failed_tests[@]}"; do 36339aab882SMatthieu Baerts echo "${i}" 36439aab882SMatthieu Baerts done | sort -n 36539aab882SMatthieu Baerts} 36639aab882SMatthieu Baerts 3678b819a84SFlorian Westphalprint_file_err() 3688b819a84SFlorian Westphal{ 3698b819a84SFlorian Westphal ls -l "$1" 1>&2 3708b819a84SFlorian Westphal echo "Trailing bytes are: " 3718b819a84SFlorian Westphal tail -c 27 "$1" 3728b819a84SFlorian Westphal} 3738b819a84SFlorian Westphal 374b08fbf24SPaolo Abenicheck_transfer() 375b08fbf24SPaolo Abeni{ 3761e777bd8SMatthieu Baerts local in=$1 3771e777bd8SMatthieu Baerts local out=$2 3781e777bd8SMatthieu Baerts local what=$3 3796bf41020SPaolo Abeni local bytes=$4 380d8d08302SMatthieu Baerts local i a b 381b08fbf24SPaolo Abeni 3821e777bd8SMatthieu Baerts local line 3836bf41020SPaolo Abeni if [ -n "$bytes" ]; then 3840fcd72dfSMatthieu Baerts local out_size 3856bf41020SPaolo Abeni # when truncating we must check the size explicitly 3860fcd72dfSMatthieu Baerts out_size=$(wc -c $out | awk '{print $1}') 3876bf41020SPaolo Abeni if [ $out_size -ne $bytes ]; then 3886bf41020SPaolo Abeni echo "[ FAIL ] $what output file has wrong size ($out_size, $bytes)" 3896bf41020SPaolo Abeni fail_test 3906bf41020SPaolo Abeni return 1 3916bf41020SPaolo Abeni fi 392d328fe87SMatthieu Baerts 393d328fe87SMatthieu Baerts # note: BusyBox's "cmp" command doesn't support --bytes 394d328fe87SMatthieu Baerts tmpfile=$(mktemp) 395d328fe87SMatthieu Baerts head --bytes="$bytes" "$in" > "$tmpfile" 396d328fe87SMatthieu Baerts mv "$tmpfile" "$in" 397d328fe87SMatthieu Baerts head --bytes="$bytes" "$out" > "$tmpfile" 398d328fe87SMatthieu Baerts mv "$tmpfile" "$out" 399d328fe87SMatthieu Baerts tmpfile="" 4006bf41020SPaolo Abeni fi 401d328fe87SMatthieu Baerts cmp -l "$in" "$out" | while read -r i a b; do 402d8d08302SMatthieu Baerts local sum=$((0${a} + 0${b})) 4038117dac3SGeliang Tang if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 404b08fbf24SPaolo Abeni echo "[ FAIL ] $what does not match (in, out):" 405b08fbf24SPaolo Abeni print_file_err "$in" 406b08fbf24SPaolo Abeni print_file_err "$out" 40739aab882SMatthieu Baerts fail_test 408b08fbf24SPaolo Abeni 409b08fbf24SPaolo Abeni return 1 4108117dac3SGeliang Tang else 411d8d08302SMatthieu Baerts echo "$what has inverted byte at ${i}" 412b08fbf24SPaolo Abeni fi 4138117dac3SGeliang Tang done 414b08fbf24SPaolo Abeni 415b08fbf24SPaolo Abeni return 0 416b08fbf24SPaolo Abeni} 417b08fbf24SPaolo Abeni 418b08fbf24SPaolo Abenido_ping() 419b08fbf24SPaolo Abeni{ 4201e777bd8SMatthieu Baerts local listener_ns="$1" 4211e777bd8SMatthieu Baerts local connector_ns="$2" 4221e777bd8SMatthieu Baerts local connect_addr="$3" 423b08fbf24SPaolo Abeni 424d8d08302SMatthieu Baerts if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 425b08fbf24SPaolo Abeni echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2 42639aab882SMatthieu Baerts fail_test 427b08fbf24SPaolo Abeni fi 428b08fbf24SPaolo Abeni} 429b08fbf24SPaolo Abeni 4308b819a84SFlorian Westphallink_failure() 4318b819a84SFlorian Westphal{ 4321e777bd8SMatthieu Baerts local ns="$1" 4338b819a84SFlorian Westphal 4347d1e6f16SPaolo Abeni if [ -z "$FAILING_LINKS" ]; then 4358b819a84SFlorian Westphal l=$((RANDOM%4)) 4367d1e6f16SPaolo Abeni FAILING_LINKS=$((l+1)) 4377d1e6f16SPaolo Abeni fi 4388b819a84SFlorian Westphal 4391e777bd8SMatthieu Baerts local l 4407d1e6f16SPaolo Abeni for l in $FAILING_LINKS; do 4411e777bd8SMatthieu Baerts local veth="ns1eth$l" 4428b819a84SFlorian Westphal ip -net "$ns" link set "$veth" down 4437d1e6f16SPaolo Abeni done 4448b819a84SFlorian Westphal} 4458b819a84SFlorian Westphal 446523514edSGeliang Tang# $1: IP address 447523514edSGeliang Tangis_v6() 448523514edSGeliang Tang{ 449523514edSGeliang Tang [ -z "${1##*:*}" ] 450523514edSGeliang Tang} 451523514edSGeliang Tang 452327b9a94SPaolo Abeni# $1: ns, $2: port 453327b9a94SPaolo Abeniwait_local_port_listen() 454327b9a94SPaolo Abeni{ 455327b9a94SPaolo Abeni local listener_ns="${1}" 456327b9a94SPaolo Abeni local port="${2}" 457327b9a94SPaolo Abeni 4581e777bd8SMatthieu Baerts local port_hex 459327b9a94SPaolo Abeni port_hex="$(printf "%04X" "${port}")" 4601e777bd8SMatthieu Baerts 4611e777bd8SMatthieu Baerts local i 462327b9a94SPaolo Abeni for i in $(seq 10); do 463327b9a94SPaolo Abeni ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 464327b9a94SPaolo Abeni awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 465327b9a94SPaolo Abeni break 466327b9a94SPaolo Abeni sleep 0.1 467327b9a94SPaolo Abeni done 468327b9a94SPaolo Abeni} 469327b9a94SPaolo Abeni 470327b9a94SPaolo Abenirm_addr_count() 471327b9a94SPaolo Abeni{ 4721e777bd8SMatthieu Baerts local ns=${1} 473327b9a94SPaolo Abeni 474327b9a94SPaolo Abeni ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}' 475327b9a94SPaolo Abeni} 476327b9a94SPaolo Abeni 477327b9a94SPaolo Abeni# $1: ns, $2: old rm_addr counter in $ns 478327b9a94SPaolo Abeniwait_rm_addr() 479327b9a94SPaolo Abeni{ 480327b9a94SPaolo Abeni local ns="${1}" 481327b9a94SPaolo Abeni local old_cnt="${2}" 482327b9a94SPaolo Abeni local cnt 483327b9a94SPaolo Abeni 4841e777bd8SMatthieu Baerts local i 485327b9a94SPaolo Abeni for i in $(seq 10); do 486327b9a94SPaolo Abeni cnt=$(rm_addr_count ${ns}) 487327b9a94SPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 488327b9a94SPaolo Abeni sleep 0.1 489327b9a94SPaolo Abeni done 490327b9a94SPaolo Abeni} 491327b9a94SPaolo Abeni 49269c6ce7bSPaolo Abeniwait_mpj() 49369c6ce7bSPaolo Abeni{ 49469c6ce7bSPaolo Abeni local ns="${1}" 49569c6ce7bSPaolo Abeni local cnt old_cnt 49669c6ce7bSPaolo Abeni 49769c6ce7bSPaolo Abeni old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 49869c6ce7bSPaolo Abeni 49969c6ce7bSPaolo Abeni local i 50069c6ce7bSPaolo Abeni for i in $(seq 10); do 50169c6ce7bSPaolo Abeni cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 50269c6ce7bSPaolo Abeni [ "$cnt" = "${old_cnt}" ] || break 50369c6ce7bSPaolo Abeni sleep 0.1 50469c6ce7bSPaolo Abeni done 50569c6ce7bSPaolo Abeni} 50669c6ce7bSPaolo Abeni 50797040cf9SGeliang Tangkill_wait() 50897040cf9SGeliang Tang{ 50997040cf9SGeliang Tang kill $1 > /dev/null 2>&1 51097040cf9SGeliang Tang wait $1 2>/dev/null 51197040cf9SGeliang Tang} 51297040cf9SGeliang Tang 513a3735625SGeliang Tangkill_events_pids() 514a3735625SGeliang Tang{ 515a3735625SGeliang Tang kill_wait $evts_ns1_pid 516a3735625SGeliang Tang kill_wait $evts_ns2_pid 517a3735625SGeliang Tang} 518a3735625SGeliang Tang 519070d6dafSMatthieu Baertskill_tests_wait() 520070d6dafSMatthieu Baerts{ 5210fcd72dfSMatthieu Baerts #shellcheck disable=SC2046 522070d6dafSMatthieu Baerts kill -SIGUSR1 $(ip netns pids $ns2) $(ip netns pids $ns1) 523070d6dafSMatthieu Baerts wait 524070d6dafSMatthieu Baerts} 525070d6dafSMatthieu Baerts 52634aa6e3bSGeliang Tangpm_nl_set_limits() 52734aa6e3bSGeliang Tang{ 52834aa6e3bSGeliang Tang local ns=$1 52934aa6e3bSGeliang Tang local addrs=$2 53034aa6e3bSGeliang Tang local subflows=$3 53134aa6e3bSGeliang Tang 53234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 53334aa6e3bSGeliang Tang ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 53434aa6e3bSGeliang Tang else 53534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 53634aa6e3bSGeliang Tang fi 53734aa6e3bSGeliang Tang} 53834aa6e3bSGeliang Tang 53934aa6e3bSGeliang Tangpm_nl_add_endpoint() 54034aa6e3bSGeliang Tang{ 54134aa6e3bSGeliang Tang local ns=$1 54234aa6e3bSGeliang Tang local addr=$2 5431e777bd8SMatthieu Baerts local flags _flags 5441e777bd8SMatthieu Baerts local port _port 5451e777bd8SMatthieu Baerts local dev _dev 5461e777bd8SMatthieu Baerts local id _id 54734aa6e3bSGeliang Tang local nr=2 54834aa6e3bSGeliang Tang 5491e777bd8SMatthieu Baerts local p 550d8d08302SMatthieu Baerts for p in "${@}" 55134aa6e3bSGeliang Tang do 55234aa6e3bSGeliang Tang if [ $p = "flags" ]; then 55334aa6e3bSGeliang Tang eval _flags=\$"$nr" 554d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 55534aa6e3bSGeliang Tang fi 55634aa6e3bSGeliang Tang if [ $p = "dev" ]; then 55734aa6e3bSGeliang Tang eval _dev=\$"$nr" 558d8d08302SMatthieu Baerts [ -n "$_dev" ]; dev="dev $_dev" 55934aa6e3bSGeliang Tang fi 56034aa6e3bSGeliang Tang if [ $p = "id" ]; then 56134aa6e3bSGeliang Tang eval _id=\$"$nr" 562d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 56334aa6e3bSGeliang Tang fi 56434aa6e3bSGeliang Tang if [ $p = "port" ]; then 56534aa6e3bSGeliang Tang eval _port=\$"$nr" 566d8d08302SMatthieu Baerts [ -n "$_port" ]; port="port $_port" 56734aa6e3bSGeliang Tang fi 56834aa6e3bSGeliang Tang 569d8d08302SMatthieu Baerts nr=$((nr + 1)) 57034aa6e3bSGeliang Tang done 57134aa6e3bSGeliang Tang 57234aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 57334aa6e3bSGeliang Tang ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 57434aa6e3bSGeliang Tang else 57534aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 57634aa6e3bSGeliang Tang fi 57734aa6e3bSGeliang Tang} 57834aa6e3bSGeliang Tang 57934aa6e3bSGeliang Tangpm_nl_del_endpoint() 58034aa6e3bSGeliang Tang{ 58134aa6e3bSGeliang Tang local ns=$1 58234aa6e3bSGeliang Tang local id=$2 58334aa6e3bSGeliang Tang local addr=$3 58434aa6e3bSGeliang Tang 58534aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 58634aa6e3bSGeliang Tang ip -n $ns mptcp endpoint delete id $id $addr 58734aa6e3bSGeliang Tang else 58834aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl del $id $addr 58934aa6e3bSGeliang Tang fi 59034aa6e3bSGeliang Tang} 59134aa6e3bSGeliang Tang 59234aa6e3bSGeliang Tangpm_nl_flush_endpoint() 59334aa6e3bSGeliang Tang{ 59434aa6e3bSGeliang Tang local ns=$1 59534aa6e3bSGeliang Tang 59634aa6e3bSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 59734aa6e3bSGeliang Tang ip -n $ns mptcp endpoint flush 59834aa6e3bSGeliang Tang else 59934aa6e3bSGeliang Tang ip netns exec $ns ./pm_nl_ctl flush 60034aa6e3bSGeliang Tang fi 60134aa6e3bSGeliang Tang} 60234aa6e3bSGeliang Tang 603dda61b3dSGeliang Tangpm_nl_show_endpoints() 604dda61b3dSGeliang Tang{ 605dda61b3dSGeliang Tang local ns=$1 606dda61b3dSGeliang Tang 607dda61b3dSGeliang Tang if [ $ip_mptcp -eq 1 ]; then 608dda61b3dSGeliang Tang ip -n $ns mptcp endpoint show 609dda61b3dSGeliang Tang else 610dda61b3dSGeliang Tang ip netns exec $ns ./pm_nl_ctl dump 611dda61b3dSGeliang Tang fi 612dda61b3dSGeliang Tang} 613dda61b3dSGeliang Tang 614f0140386SGeliang Tangpm_nl_change_endpoint() 615f0140386SGeliang Tang{ 616f0140386SGeliang Tang local ns=$1 617bccefb76SGeliang Tang local id=$2 618bccefb76SGeliang Tang local flags=$3 619f0140386SGeliang Tang 620f0140386SGeliang Tang if [ $ip_mptcp -eq 1 ]; then 621f0140386SGeliang Tang ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 622f0140386SGeliang Tang else 623bccefb76SGeliang Tang ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 624f0140386SGeliang Tang fi 625f0140386SGeliang Tang} 626f0140386SGeliang Tang 62769c6ce7bSPaolo Abenipm_nl_check_endpoint() 62869c6ce7bSPaolo Abeni{ 62969c6ce7bSPaolo Abeni local line expected_line 630c7d49c03SMatthieu Baerts local need_title=$1 63169c6ce7bSPaolo Abeni local msg="$2" 63269c6ce7bSPaolo Abeni local ns=$3 63369c6ce7bSPaolo Abeni local addr=$4 63469c6ce7bSPaolo Abeni local _flags="" 63569c6ce7bSPaolo Abeni local flags 63669c6ce7bSPaolo Abeni local _port 63769c6ce7bSPaolo Abeni local port 63869c6ce7bSPaolo Abeni local dev 63969c6ce7bSPaolo Abeni local _id 64069c6ce7bSPaolo Abeni local id 64169c6ce7bSPaolo Abeni 642c7d49c03SMatthieu Baerts if [ "${need_title}" = 1 ]; then 643c7d49c03SMatthieu Baerts printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 64469c6ce7bSPaolo Abeni else 64569c6ce7bSPaolo Abeni printf "%-${nr_blank}s %s" " " "${msg}" 64669c6ce7bSPaolo Abeni fi 64769c6ce7bSPaolo Abeni 64869c6ce7bSPaolo Abeni shift 4 64969c6ce7bSPaolo Abeni while [ -n "$1" ]; do 65069c6ce7bSPaolo Abeni if [ $1 = "flags" ]; then 65169c6ce7bSPaolo Abeni _flags=$2 652d8d08302SMatthieu Baerts [ -n "$_flags" ]; flags="flags $_flags" 65369c6ce7bSPaolo Abeni shift 65469c6ce7bSPaolo Abeni elif [ $1 = "dev" ]; then 655d8d08302SMatthieu Baerts [ -n "$2" ]; dev="dev $1" 65669c6ce7bSPaolo Abeni shift 65769c6ce7bSPaolo Abeni elif [ $1 = "id" ]; then 65869c6ce7bSPaolo Abeni _id=$2 659d8d08302SMatthieu Baerts [ -n "$_id" ]; id="id $_id" 66069c6ce7bSPaolo Abeni shift 66169c6ce7bSPaolo Abeni elif [ $1 = "port" ]; then 66269c6ce7bSPaolo Abeni _port=$2 663d8d08302SMatthieu Baerts [ -n "$_port" ]; port=" port $_port" 66469c6ce7bSPaolo Abeni shift 66569c6ce7bSPaolo Abeni fi 66669c6ce7bSPaolo Abeni 66769c6ce7bSPaolo Abeni shift 66869c6ce7bSPaolo Abeni done 66969c6ce7bSPaolo Abeni 67069c6ce7bSPaolo Abeni if [ -z "$id" ]; then 67169c6ce7bSPaolo Abeni echo "[skip] bad test - missing endpoint id" 67269c6ce7bSPaolo Abeni return 67369c6ce7bSPaolo Abeni fi 67469c6ce7bSPaolo Abeni 67569c6ce7bSPaolo Abeni if [ $ip_mptcp -eq 1 ]; then 67669c6ce7bSPaolo Abeni line=$(ip -n $ns mptcp endpoint show $id) 67769c6ce7bSPaolo Abeni # the dump order is: address id flags port dev 67869c6ce7bSPaolo Abeni expected_line="$addr" 67969c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 68069c6ce7bSPaolo Abeni expected_line="$expected_line $id" 68169c6ce7bSPaolo Abeni [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" 68269c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 68369c6ce7bSPaolo Abeni [ -n "$port" ] && expected_line="$expected_line $port" 68469c6ce7bSPaolo Abeni else 68569c6ce7bSPaolo Abeni line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 68669c6ce7bSPaolo Abeni # the dump order is: id flags dev address port 68769c6ce7bSPaolo Abeni expected_line="$id" 68869c6ce7bSPaolo Abeni [ -n "$flags" ] && expected_line="$expected_line $flags" 68969c6ce7bSPaolo Abeni [ -n "$dev" ] && expected_line="$expected_line $dev" 69069c6ce7bSPaolo Abeni [ -n "$addr" ] && expected_line="$expected_line $addr" 69169c6ce7bSPaolo Abeni [ -n "$_port" ] && expected_line="$expected_line $_port" 69269c6ce7bSPaolo Abeni fi 69369c6ce7bSPaolo Abeni if [ "$line" = "$expected_line" ]; then 69469c6ce7bSPaolo Abeni echo "[ ok ]" 69569c6ce7bSPaolo Abeni else 69669c6ce7bSPaolo Abeni echo "[fail] expected '$expected_line' found '$line'" 69739aab882SMatthieu Baerts fail_test 69869c6ce7bSPaolo Abeni fi 69969c6ce7bSPaolo Abeni} 70069c6ce7bSPaolo Abeni 7013469d72fSMatthieu Baertsfilter_tcp_from() 7023469d72fSMatthieu Baerts{ 7033469d72fSMatthieu Baerts local ns="${1}" 7043469d72fSMatthieu Baerts local src="${2}" 7053469d72fSMatthieu Baerts local target="${3}" 7063469d72fSMatthieu Baerts 7073469d72fSMatthieu Baerts ip netns exec "${ns}" iptables -A INPUT -s "${src}" -p tcp -j "${target}" 7083469d72fSMatthieu Baerts} 7093469d72fSMatthieu Baerts 710b08fbf24SPaolo Abenido_transfer() 711b08fbf24SPaolo Abeni{ 7121e777bd8SMatthieu Baerts local listener_ns="$1" 7131e777bd8SMatthieu Baerts local connector_ns="$2" 7141e777bd8SMatthieu Baerts local cl_proto="$3" 7151e777bd8SMatthieu Baerts local srv_proto="$4" 7161e777bd8SMatthieu Baerts local connect_addr="$5" 7171e777bd8SMatthieu Baerts local test_link_fail="$6" 7181e777bd8SMatthieu Baerts local addr_nr_ns1="$7" 7191e777bd8SMatthieu Baerts local addr_nr_ns2="$8" 7201e777bd8SMatthieu Baerts local speed="$9" 7211e777bd8SMatthieu Baerts local sflags="${10}" 722b08fbf24SPaolo Abeni 7231e777bd8SMatthieu Baerts local port=$((10000 + TEST_COUNT - 1)) 7241e777bd8SMatthieu Baerts local cappid 72597040cf9SGeliang Tang local userspace_pm=0 726b08fbf24SPaolo Abeni 727b08fbf24SPaolo Abeni :> "$cout" 728b08fbf24SPaolo Abeni :> "$sout" 729b08fbf24SPaolo Abeni :> "$capout" 730b08fbf24SPaolo Abeni 731b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 7321e777bd8SMatthieu Baerts local capuser 733b08fbf24SPaolo Abeni if [ -z $SUDO_USER ] ; then 734b08fbf24SPaolo Abeni capuser="" 735b08fbf24SPaolo Abeni else 736b08fbf24SPaolo Abeni capuser="-Z $SUDO_USER" 737b08fbf24SPaolo Abeni fi 738b08fbf24SPaolo Abeni 73900587187SFlorian Westphal capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 740b08fbf24SPaolo Abeni 741b08fbf24SPaolo Abeni echo "Capturing traffic for test $TEST_COUNT into $capfile" 742b08fbf24SPaolo Abeni ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 743b08fbf24SPaolo Abeni cappid=$! 744b08fbf24SPaolo Abeni 745b08fbf24SPaolo Abeni sleep 1 746b08fbf24SPaolo Abeni fi 747b08fbf24SPaolo Abeni 748c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 749c2a55e8fSMatthieu Baerts nstat -n 750c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 751c2a55e8fSMatthieu Baerts nstat -n 752c2a55e8fSMatthieu Baerts 753cbfafac4SGeliang Tang local extra_args 7548d014eaaSGeliang Tang if [ $speed = "fast" ]; then 755cbfafac4SGeliang Tang extra_args="-j" 7568da6229bSGeliang Tang elif [ $speed = "slow" ]; then 757cbfafac4SGeliang Tang extra_args="-r 50" 758cbfafac4SGeliang Tang elif [[ $speed = "speed_"* ]]; then 759cbfafac4SGeliang Tang extra_args="-r ${speed:6}" 760dd72b0feSGeliang Tang fi 761dd72b0feSGeliang Tang 76297040cf9SGeliang Tang if [[ "${addr_nr_ns1}" = "userspace_"* ]]; then 76397040cf9SGeliang Tang userspace_pm=1 76497040cf9SGeliang Tang addr_nr_ns1=${addr_nr_ns1:10} 76597040cf9SGeliang Tang fi 76697040cf9SGeliang Tang 767a1c3bdd9SGeliang Tang local flags="subflow" 7686bf41020SPaolo Abeni local extra_cl_args="" 7696bf41020SPaolo Abeni local extra_srv_args="" 7706bf41020SPaolo Abeni local trunc_size="" 77101542c9bSGeliang Tang if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then 7726bf41020SPaolo Abeni if [ ${test_link_fail} -le 1 ]; then 7736bf41020SPaolo Abeni echo "fastclose tests need test_link_fail argument" 7746bf41020SPaolo Abeni fail_test 7756bf41020SPaolo Abeni return 1 7766bf41020SPaolo Abeni fi 7776bf41020SPaolo Abeni 77801542c9bSGeliang Tang # disconnect 7796bf41020SPaolo Abeni trunc_size=${test_link_fail} 7806bf41020SPaolo Abeni local side=${addr_nr_ns2:10} 7816bf41020SPaolo Abeni 7826bf41020SPaolo Abeni if [ ${side} = "client" ]; then 7836bf41020SPaolo Abeni extra_cl_args="-f ${test_link_fail}" 7846bf41020SPaolo Abeni extra_srv_args="-f -1" 7856bf41020SPaolo Abeni elif [ ${side} = "server" ]; then 7866bf41020SPaolo Abeni extra_srv_args="-f ${test_link_fail}" 7876bf41020SPaolo Abeni extra_cl_args="-f -1" 7886bf41020SPaolo Abeni else 7896bf41020SPaolo Abeni echo "wrong/unknown fastclose spec ${side}" 7906bf41020SPaolo Abeni fail_test 7916bf41020SPaolo Abeni return 1 7926bf41020SPaolo Abeni fi 79301542c9bSGeliang Tang addr_nr_ns2=0 7945e986ec4SGeliang Tang elif [[ "${addr_nr_ns2}" = "userspace_"* ]]; then 7955e986ec4SGeliang Tang userspace_pm=1 7965e986ec4SGeliang Tang addr_nr_ns2=${addr_nr_ns2:10} 797a1c3bdd9SGeliang Tang elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then 798a1c3bdd9SGeliang Tang flags="${flags},fullmesh" 799a1c3bdd9SGeliang Tang addr_nr_ns2=${addr_nr_ns2:9} 80001542c9bSGeliang Tang fi 80101542c9bSGeliang Tang 8026bf41020SPaolo Abeni extra_srv_args="$extra_args $extra_srv_args" 80334b572b7SGeliang Tang if [ "$test_link_fail" -gt 1 ];then 8047d1e6f16SPaolo Abeni timeout ${timeout_test} \ 8057d1e6f16SPaolo Abeni ip netns exec ${listener_ns} \ 806cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 807ad349374SPaolo Abeni $extra_srv_args "::" < "$sinfail" > "$sout" & 8087d1e6f16SPaolo Abeni else 8095888a61cSMatthieu Baerts timeout ${timeout_test} \ 8105888a61cSMatthieu Baerts ip netns exec ${listener_ns} \ 811cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 812ad349374SPaolo Abeni $extra_srv_args "::" < "$sin" > "$sout" & 8137d1e6f16SPaolo Abeni fi 8141e777bd8SMatthieu Baerts local spid=$! 815b08fbf24SPaolo Abeni 816327b9a94SPaolo Abeni wait_local_port_listen "${listener_ns}" "${port}" 817b08fbf24SPaolo Abeni 8186bf41020SPaolo Abeni extra_cl_args="$extra_args $extra_cl_args" 8198b819a84SFlorian Westphal if [ "$test_link_fail" -eq 0 ];then 8205888a61cSMatthieu Baerts timeout ${timeout_test} \ 8215888a61cSMatthieu Baerts ip netns exec ${connector_ns} \ 822cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8236bf41020SPaolo Abeni $extra_cl_args $connect_addr < "$cin" > "$cout" & 82434b572b7SGeliang Tang elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then 8257d1e6f16SPaolo Abeni ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 8265888a61cSMatthieu Baerts tee "$cinsent" | \ 8275888a61cSMatthieu Baerts timeout ${timeout_test} \ 8285888a61cSMatthieu Baerts ip netns exec ${connector_ns} \ 829cbfafac4SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8306bf41020SPaolo Abeni $extra_cl_args $connect_addr > "$cout" & 83134b572b7SGeliang Tang else 832d8d08302SMatthieu Baerts tee "$cinsent" < "$cinfail" | \ 83334b572b7SGeliang Tang timeout ${timeout_test} \ 83434b572b7SGeliang Tang ip netns exec ${connector_ns} \ 83534b572b7SGeliang Tang ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 8366bf41020SPaolo Abeni $extra_cl_args $connect_addr > "$cout" & 8378b819a84SFlorian Westphal fi 8381e777bd8SMatthieu Baerts local cpid=$! 839b08fbf24SPaolo Abeni 840327b9a94SPaolo Abeni # let the mptcp subflow be established in background before 841327b9a94SPaolo Abeni # do endpoint manipulation 842d8d08302SMatthieu Baerts if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 843d8d08302SMatthieu Baerts sleep 1 844d8d08302SMatthieu Baerts fi 845327b9a94SPaolo Abeni 8466208fd82SGeliang Tang if [ $addr_nr_ns1 -gt 0 ]; then 8471e777bd8SMatthieu Baerts local counter=2 848d8d08302SMatthieu Baerts local add_nr_ns1=${addr_nr_ns1} 84997040cf9SGeliang Tang local id=10 85097040cf9SGeliang Tang local tk 8516208fd82SGeliang Tang while [ $add_nr_ns1 -gt 0 ]; do 8526208fd82SGeliang Tang local addr 8536208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 8546208fd82SGeliang Tang addr="dead:beef:$counter::1" 8556208fd82SGeliang Tang else 8566208fd82SGeliang Tang addr="10.0.$counter.1" 8576208fd82SGeliang Tang fi 85897040cf9SGeliang Tang if [ $userspace_pm -eq 0 ]; then 85934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 $addr flags signal 86097040cf9SGeliang Tang else 8617dff74f5SGeliang Tang tk=$(grep "type:1," "$evts_ns1" | 8627dff74f5SGeliang Tang sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q') 86397040cf9SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id 86497040cf9SGeliang Tang sleep 1 865*48d73f60SGeliang Tang sp=$(grep "type:10" "$evts_ns1" | 866*48d73f60SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 867*48d73f60SGeliang Tang da=$(grep "type:10" "$evts_ns1" | 868*48d73f60SGeliang Tang sed -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 869*48d73f60SGeliang Tang dp=$(grep "type:10" "$evts_ns1" | 870*48d73f60SGeliang Tang sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q') 87197040cf9SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id 872*48d73f60SGeliang Tang ip netns exec ${listener_ns} ./pm_nl_ctl dsf lip "::ffff:$addr" \ 873*48d73f60SGeliang Tang lport $sp rip $da rport $dp token $tk 87497040cf9SGeliang Tang fi 87597040cf9SGeliang Tang 876d8d08302SMatthieu Baerts counter=$((counter + 1)) 877d8d08302SMatthieu Baerts add_nr_ns1=$((add_nr_ns1 - 1)) 87897040cf9SGeliang Tang id=$((id + 1)) 8796208fd82SGeliang Tang done 8806208fd82SGeliang Tang elif [ $addr_nr_ns1 -lt 0 ]; then 881d8d08302SMatthieu Baerts local rm_nr_ns1=$((-addr_nr_ns1)) 8826fe4ccdcSGeliang Tang if [ $rm_nr_ns1 -lt 8 ]; then 8831e777bd8SMatthieu Baerts local counter=0 8841e777bd8SMatthieu Baerts local line 885d8d08302SMatthieu Baerts pm_nl_show_endpoints ${listener_ns} | while read -r line; do 886d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 887dda61b3dSGeliang Tang local arr=($line) 888dda61b3dSGeliang Tang local nr=0 889dda61b3dSGeliang Tang 8901e777bd8SMatthieu Baerts local i 891d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 892dda61b3dSGeliang Tang if [ $i = "id" ]; then 893dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns1 ]; then 894dda61b3dSGeliang Tang break 895dda61b3dSGeliang Tang fi 896dda61b3dSGeliang Tang id=${arr[$nr+1]} 897327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${connector_ns}) 89834aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} $id 899327b9a94SPaolo Abeni wait_rm_addr ${connector_ns} ${rm_addr} 900d8d08302SMatthieu Baerts counter=$((counter + 1)) 901f87744adSGeliang Tang fi 902d8d08302SMatthieu Baerts nr=$((nr + 1)) 903dda61b3dSGeliang Tang done 904dda61b3dSGeliang Tang done 9055e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 8 ]; then 90634aa6e3bSGeliang Tang pm_nl_flush_endpoint ${listener_ns} 9075e287fe7SGeliang Tang elif [ $rm_nr_ns1 -eq 9 ]; then 90834aa6e3bSGeliang Tang pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 9096fe4ccdcSGeliang Tang fi 910dd72b0feSGeliang Tang fi 911dd72b0feSGeliang Tang 912327b9a94SPaolo Abeni # if newly added endpoints must be deleted, give the background msk 913327b9a94SPaolo Abeni # some time to created them 914d8d08302SMatthieu Baerts [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 915327b9a94SPaolo Abeni 9166208fd82SGeliang Tang if [ $addr_nr_ns2 -gt 0 ]; then 917d8d08302SMatthieu Baerts local add_nr_ns2=${addr_nr_ns2} 9181e777bd8SMatthieu Baerts local counter=3 9195e986ec4SGeliang Tang local id=20 9205e986ec4SGeliang Tang local tk da dp sp 9216208fd82SGeliang Tang while [ $add_nr_ns2 -gt 0 ]; do 9226208fd82SGeliang Tang local addr 9236208fd82SGeliang Tang if is_v6 "${connect_addr}"; then 9246208fd82SGeliang Tang addr="dead:beef:$counter::2" 9256208fd82SGeliang Tang else 9266208fd82SGeliang Tang addr="10.0.$counter.2" 9276208fd82SGeliang Tang fi 9285e986ec4SGeliang Tang if [ $userspace_pm -eq 0 ]; then 92934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 $addr flags $flags 9305e986ec4SGeliang Tang else 9315e986ec4SGeliang Tang tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 9325e986ec4SGeliang Tang da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2") 9335e986ec4SGeliang Tang dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 9345e986ec4SGeliang Tang ip netns exec ${connector_ns} ./pm_nl_ctl csf lip $addr lid $id \ 9355e986ec4SGeliang Tang rip $da rport $dp token $tk 9365e986ec4SGeliang Tang sleep 1 9375e986ec4SGeliang Tang sp=$(grep "type:10" "$evts_ns2" | 9385e986ec4SGeliang Tang sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 9395e986ec4SGeliang Tang ip netns exec ${connector_ns} ./pm_nl_ctl dsf lip $addr lport $sp \ 9405e986ec4SGeliang Tang rip $da rport $dp token $tk 9415e986ec4SGeliang Tang fi 942d8d08302SMatthieu Baerts counter=$((counter + 1)) 943d8d08302SMatthieu Baerts add_nr_ns2=$((add_nr_ns2 - 1)) 9445e986ec4SGeliang Tang id=$((id + 1)) 9456208fd82SGeliang Tang done 9466208fd82SGeliang Tang elif [ $addr_nr_ns2 -lt 0 ]; then 947d8d08302SMatthieu Baerts local rm_nr_ns2=$((-addr_nr_ns2)) 9486fe4ccdcSGeliang Tang if [ $rm_nr_ns2 -lt 8 ]; then 9491e777bd8SMatthieu Baerts local counter=0 9501e777bd8SMatthieu Baerts local line 951d8d08302SMatthieu Baerts pm_nl_show_endpoints ${connector_ns} | while read -r line; do 952d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 953dda61b3dSGeliang Tang local arr=($line) 954dda61b3dSGeliang Tang local nr=0 955dda61b3dSGeliang Tang 9561e777bd8SMatthieu Baerts local i 957d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 958dda61b3dSGeliang Tang if [ $i = "id" ]; then 959dda61b3dSGeliang Tang if [ $counter -eq $rm_nr_ns2 ]; then 960dda61b3dSGeliang Tang break 961dda61b3dSGeliang Tang fi 9621e777bd8SMatthieu Baerts local id rm_addr 963dda61b3dSGeliang Tang # rm_addr are serialized, allow the previous one to 964dda61b3dSGeliang Tang # complete 965dda61b3dSGeliang Tang id=${arr[$nr+1]} 966327b9a94SPaolo Abeni rm_addr=$(rm_addr_count ${listener_ns}) 96734aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} $id 968327b9a94SPaolo Abeni wait_rm_addr ${listener_ns} ${rm_addr} 969d8d08302SMatthieu Baerts counter=$((counter + 1)) 970f87744adSGeliang Tang fi 971d8d08302SMatthieu Baerts nr=$((nr + 1)) 972dda61b3dSGeliang Tang done 973dda61b3dSGeliang Tang done 9745e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 8 ]; then 97534aa6e3bSGeliang Tang pm_nl_flush_endpoint ${connector_ns} 9765e287fe7SGeliang Tang elif [ $rm_nr_ns2 -eq 9 ]; then 9775e287fe7SGeliang Tang local addr 9785e287fe7SGeliang Tang if is_v6 "${connect_addr}"; then 9795e287fe7SGeliang Tang addr="dead:beef:1::2" 9805e287fe7SGeliang Tang else 9815e287fe7SGeliang Tang addr="10.0.1.2" 9825e287fe7SGeliang Tang fi 98334aa6e3bSGeliang Tang pm_nl_del_endpoint ${connector_ns} 0 $addr 9846fe4ccdcSGeliang Tang fi 985dd72b0feSGeliang Tang fi 986dd72b0feSGeliang Tang 987d8d08302SMatthieu Baerts if [ -n "${sflags}" ]; then 988718eb44eSGeliang Tang sleep 1 9891e777bd8SMatthieu Baerts 9901e777bd8SMatthieu Baerts local netns 991718eb44eSGeliang Tang for netns in "$ns1" "$ns2"; do 9921e777bd8SMatthieu Baerts local line 993d8d08302SMatthieu Baerts pm_nl_show_endpoints $netns | while read -r line; do 994d8d08302SMatthieu Baerts # shellcheck disable=SC2206 # we do want to split per word 99533397b83SGeliang Tang local arr=($line) 996bccefb76SGeliang Tang local nr=0 997f0140386SGeliang Tang local id 99833397b83SGeliang Tang 9991e777bd8SMatthieu Baerts local i 1000d8d08302SMatthieu Baerts for i in "${arr[@]}"; do 1001bccefb76SGeliang Tang if [ $i = "id" ]; then 1002bccefb76SGeliang Tang id=${arr[$nr+1]} 1003718eb44eSGeliang Tang fi 1004d8d08302SMatthieu Baerts nr=$((nr + 1)) 100533397b83SGeliang Tang done 1006bccefb76SGeliang Tang pm_nl_change_endpoint $netns $id $sflags 100733397b83SGeliang Tang done 1008718eb44eSGeliang Tang done 1009718eb44eSGeliang Tang fi 1010718eb44eSGeliang Tang 1011b08fbf24SPaolo Abeni wait $cpid 10121e777bd8SMatthieu Baerts local retc=$? 1013b08fbf24SPaolo Abeni wait $spid 10141e777bd8SMatthieu Baerts local rets=$? 1015b08fbf24SPaolo Abeni 1016b08fbf24SPaolo Abeni if [ $capture -eq 1 ]; then 1017b08fbf24SPaolo Abeni sleep 1 1018b08fbf24SPaolo Abeni kill $cappid 1019b08fbf24SPaolo Abeni fi 1020b08fbf24SPaolo Abeni 1021c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1022c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${listener_ns}.out 1023c2a55e8fSMatthieu Baerts NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1024c2a55e8fSMatthieu Baerts nstat | grep Tcp > /tmp/${connector_ns}.out 1025c2a55e8fSMatthieu Baerts 1026b08fbf24SPaolo Abeni if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 1027b08fbf24SPaolo Abeni echo " client exit code $retc, server $rets" 1>&2 10288b974778SMatthieu Baerts echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1029c2a55e8fSMatthieu Baerts ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1030c2a55e8fSMatthieu Baerts cat /tmp/${listener_ns}.out 10318b974778SMatthieu Baerts echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1032c2a55e8fSMatthieu Baerts ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1033c2a55e8fSMatthieu Baerts cat /tmp/${connector_ns}.out 1034b08fbf24SPaolo Abeni 1035b08fbf24SPaolo Abeni cat "$capout" 103639aab882SMatthieu Baerts fail_test 1037b08fbf24SPaolo Abeni return 1 1038b08fbf24SPaolo Abeni fi 1039b08fbf24SPaolo Abeni 104034b572b7SGeliang Tang if [ "$test_link_fail" -gt 1 ];then 10416bf41020SPaolo Abeni check_transfer $sinfail $cout "file received by client" $trunc_size 10427d1e6f16SPaolo Abeni else 10436bf41020SPaolo Abeni check_transfer $sin $cout "file received by client" $trunc_size 10447d1e6f16SPaolo Abeni fi 1045b08fbf24SPaolo Abeni retc=$? 10468b819a84SFlorian Westphal if [ "$test_link_fail" -eq 0 ];then 10476bf41020SPaolo Abeni check_transfer $cin $sout "file received by server" $trunc_size 10488b819a84SFlorian Westphal else 10496bf41020SPaolo Abeni check_transfer $cinsent $sout "file received by server" $trunc_size 10508b819a84SFlorian Westphal fi 1051b08fbf24SPaolo Abeni rets=$? 1052b08fbf24SPaolo Abeni 1053b08fbf24SPaolo Abeni if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1054b08fbf24SPaolo Abeni cat "$capout" 1055b08fbf24SPaolo Abeni return 0 1056b08fbf24SPaolo Abeni fi 1057b08fbf24SPaolo Abeni 1058b08fbf24SPaolo Abeni cat "$capout" 1059b08fbf24SPaolo Abeni return 1 1060b08fbf24SPaolo Abeni} 1061b08fbf24SPaolo Abeni 1062b08fbf24SPaolo Abenimake_file() 1063b08fbf24SPaolo Abeni{ 10641e777bd8SMatthieu Baerts local name=$1 10651e777bd8SMatthieu Baerts local who=$2 10661e777bd8SMatthieu Baerts local size=$3 1067b08fbf24SPaolo Abeni 10688b819a84SFlorian Westphal dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1069b08fbf24SPaolo Abeni echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1070b08fbf24SPaolo Abeni 10718b819a84SFlorian Westphal echo "Created $name (size $size KB) containing data sent by $who" 1072b08fbf24SPaolo Abeni} 1073b08fbf24SPaolo Abeni 1074b08fbf24SPaolo Abenirun_tests() 1075b08fbf24SPaolo Abeni{ 10761e777bd8SMatthieu Baerts local listener_ns="$1" 10771e777bd8SMatthieu Baerts local connector_ns="$2" 10781e777bd8SMatthieu Baerts local connect_addr="$3" 10791e777bd8SMatthieu Baerts local test_linkfail="${4:-0}" 10801e777bd8SMatthieu Baerts local addr_nr_ns1="${5:-0}" 10811e777bd8SMatthieu Baerts local addr_nr_ns2="${6:-0}" 10821e777bd8SMatthieu Baerts local speed="${7:-fast}" 10831e777bd8SMatthieu Baerts local sflags="${8:-""}" 10841e777bd8SMatthieu Baerts 10851e777bd8SMatthieu Baerts local size 10868b819a84SFlorian Westphal 108734b572b7SGeliang Tang # The values above 2 are reused to make test files 108834b572b7SGeliang Tang # with the given sizes (KB) 108934b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 109034b572b7SGeliang Tang size=$test_linkfail 109134b572b7SGeliang Tang 109234b572b7SGeliang Tang if [ -z "$cinfail" ]; then 109334b572b7SGeliang Tang cinfail=$(mktemp) 109434b572b7SGeliang Tang fi 109534b572b7SGeliang Tang make_file "$cinfail" "client" $size 10967d1e6f16SPaolo Abeni # create the input file for the failure test when 10977d1e6f16SPaolo Abeni # the first failure test run 1098d8d08302SMatthieu Baerts elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 10997d1e6f16SPaolo Abeni # the client file must be considerably larger 11007d1e6f16SPaolo Abeni # of the maximum expected cwin value, or the 11017d1e6f16SPaolo Abeni # link utilization will be not predicable 11027d1e6f16SPaolo Abeni size=$((RANDOM%2)) 11038b819a84SFlorian Westphal size=$((size+1)) 11047d1e6f16SPaolo Abeni size=$((size*8192)) 1105d8d08302SMatthieu Baerts size=$((size + ( RANDOM % 8192) )) 11068b819a84SFlorian Westphal 11077d1e6f16SPaolo Abeni cinfail=$(mktemp) 11087d1e6f16SPaolo Abeni make_file "$cinfail" "client" $size 11097d1e6f16SPaolo Abeni fi 11107d1e6f16SPaolo Abeni 111134b572b7SGeliang Tang if [ "$test_linkfail" -gt 2 ]; then 111234b572b7SGeliang Tang size=$test_linkfail 111334b572b7SGeliang Tang 111434b572b7SGeliang Tang if [ -z "$sinfail" ]; then 111534b572b7SGeliang Tang sinfail=$(mktemp) 111634b572b7SGeliang Tang fi 111734b572b7SGeliang Tang make_file "$sinfail" "server" $size 1118d8d08302SMatthieu Baerts elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 11197d1e6f16SPaolo Abeni size=$((RANDOM%16)) 11207d1e6f16SPaolo Abeni size=$((size+1)) 11217d1e6f16SPaolo Abeni size=$((size*2048)) 11227d1e6f16SPaolo Abeni 11237d1e6f16SPaolo Abeni sinfail=$(mktemp) 11247d1e6f16SPaolo Abeni make_file "$sinfail" "server" $size 11258b819a84SFlorian Westphal fi 1126b08fbf24SPaolo Abeni 11278d014eaaSGeliang Tang do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \ 11286a0653b9SGeliang Tang ${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${sflags} 1129b08fbf24SPaolo Abeni} 1130b08fbf24SPaolo Abeni 1131327b9a94SPaolo Abenidump_stats() 1132327b9a94SPaolo Abeni{ 1133327b9a94SPaolo Abeni echo Server ns stats 1134327b9a94SPaolo Abeni ip netns exec $ns1 nstat -as | grep Tcp 1135327b9a94SPaolo Abeni echo Client ns stats 1136327b9a94SPaolo Abeni ip netns exec $ns2 nstat -as | grep Tcp 1137327b9a94SPaolo Abeni} 1138327b9a94SPaolo Abeni 1139af66d3e1SGeliang Tangchk_csum_nr() 1140af66d3e1SGeliang Tang{ 11413c082695SGeliang Tang local csum_ns1=${1:-0} 11423c082695SGeliang Tang local csum_ns2=${2:-0} 1143af66d3e1SGeliang Tang local count 1144af66d3e1SGeliang Tang local dump_stats 114553f368bfSGeliang Tang local extra_msg="" 114626516e10SGeliang Tang local allow_multi_errors_ns1=0 114726516e10SGeliang Tang local allow_multi_errors_ns2=0 114826516e10SGeliang Tang 114926516e10SGeliang Tang if [[ "${csum_ns1}" = "+"* ]]; then 115026516e10SGeliang Tang allow_multi_errors_ns1=1 115126516e10SGeliang Tang csum_ns1=${csum_ns1:1} 115226516e10SGeliang Tang fi 115326516e10SGeliang Tang if [[ "${csum_ns2}" = "+"* ]]; then 115426516e10SGeliang Tang allow_multi_errors_ns2=1 115526516e10SGeliang Tang csum_ns2=${csum_ns2:1} 115626516e10SGeliang Tang fi 1157af66d3e1SGeliang Tang 11583c082695SGeliang Tang printf "%-${nr_blank}s %s" " " "sum" 11594bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1160af66d3e1SGeliang Tang [ -z "$count" ] && count=0 116153f368bfSGeliang Tang if [ "$count" != "$csum_ns1" ]; then 116253f368bfSGeliang Tang extra_msg="$extra_msg ns1=$count" 116353f368bfSGeliang Tang fi 1164d8d08302SMatthieu Baerts if { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1165d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 116626516e10SGeliang Tang echo "[fail] got $count data checksum error[s] expected $csum_ns1" 116739aab882SMatthieu Baerts fail_test 1168af66d3e1SGeliang Tang dump_stats=1 1169af66d3e1SGeliang Tang else 1170af66d3e1SGeliang Tang echo -n "[ ok ]" 1171af66d3e1SGeliang Tang fi 1172af66d3e1SGeliang Tang echo -n " - csum " 11734bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1174af66d3e1SGeliang Tang [ -z "$count" ] && count=0 117553f368bfSGeliang Tang if [ "$count" != "$csum_ns2" ]; then 117653f368bfSGeliang Tang extra_msg="$extra_msg ns2=$count" 117753f368bfSGeliang Tang fi 1178d8d08302SMatthieu Baerts if { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1179d8d08302SMatthieu Baerts { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 118026516e10SGeliang Tang echo "[fail] got $count data checksum error[s] expected $csum_ns2" 118139aab882SMatthieu Baerts fail_test 1182af66d3e1SGeliang Tang dump_stats=1 1183af66d3e1SGeliang Tang else 118453f368bfSGeliang Tang echo -n "[ ok ]" 1185af66d3e1SGeliang Tang fi 1186327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 118753f368bfSGeliang Tang 118853f368bfSGeliang Tang echo "$extra_msg" 1189af66d3e1SGeliang Tang} 1190af66d3e1SGeliang Tang 11916bb3ab49SGeliang Tangchk_fail_nr() 11926bb3ab49SGeliang Tang{ 119326516e10SGeliang Tang local fail_tx=$1 119426516e10SGeliang Tang local fail_rx=$2 11951f7d325fSGeliang Tang local ns_invert=${3:-""} 11966bb3ab49SGeliang Tang local count 11976bb3ab49SGeliang Tang local dump_stats 11981f7d325fSGeliang Tang local ns_tx=$ns1 11991f7d325fSGeliang Tang local ns_rx=$ns2 12001f7d325fSGeliang Tang local extra_msg="" 12011f7d325fSGeliang Tang local allow_tx_lost=0 12021f7d325fSGeliang Tang local allow_rx_lost=0 12031f7d325fSGeliang Tang 12041f7d325fSGeliang Tang if [[ $ns_invert = "invert" ]]; then 12051f7d325fSGeliang Tang ns_tx=$ns2 12061f7d325fSGeliang Tang ns_rx=$ns1 12071f7d325fSGeliang Tang extra_msg=" invert" 12081f7d325fSGeliang Tang fi 12091f7d325fSGeliang Tang 12101f7d325fSGeliang Tang if [[ "${fail_tx}" = "-"* ]]; then 12111f7d325fSGeliang Tang allow_tx_lost=1 12121f7d325fSGeliang Tang fail_tx=${fail_tx:1} 12131f7d325fSGeliang Tang fi 12141f7d325fSGeliang Tang if [[ "${fail_rx}" = "-"* ]]; then 12151f7d325fSGeliang Tang allow_rx_lost=1 12161f7d325fSGeliang Tang fail_rx=${fail_rx:1} 12171f7d325fSGeliang Tang fi 12186bb3ab49SGeliang Tang 12199a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "ftx" 12201f7d325fSGeliang Tang count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}') 12216bb3ab49SGeliang Tang [ -z "$count" ] && count=0 122226516e10SGeliang Tang if [ "$count" != "$fail_tx" ]; then 12231f7d325fSGeliang Tang extra_msg="$extra_msg,tx=$count" 12241f7d325fSGeliang Tang fi 12251f7d325fSGeliang Tang if { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 12261f7d325fSGeliang Tang { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 122726516e10SGeliang Tang echo "[fail] got $count MP_FAIL[s] TX expected $fail_tx" 122839aab882SMatthieu Baerts fail_test 12296bb3ab49SGeliang Tang dump_stats=1 12306bb3ab49SGeliang Tang else 12316bb3ab49SGeliang Tang echo -n "[ ok ]" 12326bb3ab49SGeliang Tang fi 12336bb3ab49SGeliang Tang 123426516e10SGeliang Tang echo -n " - failrx" 12351f7d325fSGeliang Tang count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}') 12366bb3ab49SGeliang Tang [ -z "$count" ] && count=0 123726516e10SGeliang Tang if [ "$count" != "$fail_rx" ]; then 12381f7d325fSGeliang Tang extra_msg="$extra_msg,rx=$count" 12391f7d325fSGeliang Tang fi 12401f7d325fSGeliang Tang if { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 12411f7d325fSGeliang Tang { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 124226516e10SGeliang Tang echo "[fail] got $count MP_FAIL[s] RX expected $fail_rx" 124339aab882SMatthieu Baerts fail_test 12446bb3ab49SGeliang Tang dump_stats=1 12456bb3ab49SGeliang Tang else 12461f7d325fSGeliang Tang echo -n "[ ok ]" 12476bb3ab49SGeliang Tang fi 12486bb3ab49SGeliang Tang 1249327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 12501f7d325fSGeliang Tang 12511f7d325fSGeliang Tang echo "$extra_msg" 12526bb3ab49SGeliang Tang} 12536bb3ab49SGeliang Tang 1254e8e947efSGeliang Tangchk_fclose_nr() 1255e8e947efSGeliang Tang{ 1256e8e947efSGeliang Tang local fclose_tx=$1 1257e8e947efSGeliang Tang local fclose_rx=$2 12586bf41020SPaolo Abeni local ns_invert=$3 1259e8e947efSGeliang Tang local count 1260e8e947efSGeliang Tang local dump_stats 12616bf41020SPaolo Abeni local ns_tx=$ns2 12626bf41020SPaolo Abeni local ns_rx=$ns1 12636bf41020SPaolo Abeni local extra_msg=" " 12646bf41020SPaolo Abeni 12656bf41020SPaolo Abeni if [[ $ns_invert = "invert" ]]; then 12666bf41020SPaolo Abeni ns_tx=$ns1 12676bf41020SPaolo Abeni ns_rx=$ns2 12686bf41020SPaolo Abeni extra_msg=${extra_msg}"invert" 12696bf41020SPaolo Abeni fi 1270e8e947efSGeliang Tang 1271e8e947efSGeliang Tang printf "%-${nr_blank}s %s" " " "ctx" 12726bf41020SPaolo Abeni count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFastcloseTx | awk '{print $2}') 1273e8e947efSGeliang Tang [ -z "$count" ] && count=0 12746bf41020SPaolo Abeni [ "$count" != "$fclose_tx" ] && extra_msg="$extra_msg,tx=$count" 1275e8e947efSGeliang Tang if [ "$count" != "$fclose_tx" ]; then 1276e8e947efSGeliang Tang echo "[fail] got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 127739aab882SMatthieu Baerts fail_test 1278e8e947efSGeliang Tang dump_stats=1 1279e8e947efSGeliang Tang else 1280e8e947efSGeliang Tang echo -n "[ ok ]" 1281e8e947efSGeliang Tang fi 1282e8e947efSGeliang Tang 1283e8e947efSGeliang Tang echo -n " - fclzrx" 12846bf41020SPaolo Abeni count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFastcloseRx | awk '{print $2}') 1285e8e947efSGeliang Tang [ -z "$count" ] && count=0 12866bf41020SPaolo Abeni [ "$count" != "$fclose_rx" ] && extra_msg="$extra_msg,rx=$count" 1287e8e947efSGeliang Tang if [ "$count" != "$fclose_rx" ]; then 1288e8e947efSGeliang Tang echo "[fail] got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 128939aab882SMatthieu Baerts fail_test 1290e8e947efSGeliang Tang dump_stats=1 1291e8e947efSGeliang Tang else 12926bf41020SPaolo Abeni echo -n "[ ok ]" 1293e8e947efSGeliang Tang fi 1294e8e947efSGeliang Tang 1295e8e947efSGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 12966bf41020SPaolo Abeni 12976bf41020SPaolo Abeni echo "$extra_msg" 1298e8e947efSGeliang Tang} 1299e8e947efSGeliang Tang 1300922fd2b3SGeliang Tangchk_rst_nr() 1301922fd2b3SGeliang Tang{ 1302922fd2b3SGeliang Tang local rst_tx=$1 1303922fd2b3SGeliang Tang local rst_rx=$2 1304922fd2b3SGeliang Tang local ns_invert=${3:-""} 1305922fd2b3SGeliang Tang local count 1306922fd2b3SGeliang Tang local dump_stats 1307922fd2b3SGeliang Tang local ns_tx=$ns1 1308922fd2b3SGeliang Tang local ns_rx=$ns2 1309922fd2b3SGeliang Tang local extra_msg="" 1310922fd2b3SGeliang Tang 1311922fd2b3SGeliang Tang if [[ $ns_invert = "invert" ]]; then 1312922fd2b3SGeliang Tang ns_tx=$ns2 1313922fd2b3SGeliang Tang ns_rx=$ns1 1314922fd2b3SGeliang Tang extra_msg=" invert" 1315922fd2b3SGeliang Tang fi 1316922fd2b3SGeliang Tang 1317922fd2b3SGeliang Tang printf "%-${nr_blank}s %s" " " "rtx" 1318922fd2b3SGeliang Tang count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPRstTx | awk '{print $2}') 1319922fd2b3SGeliang Tang [ -z "$count" ] && count=0 13206bf41020SPaolo Abeni if [ $count -lt $rst_tx ]; then 1321922fd2b3SGeliang Tang echo "[fail] got $count MP_RST[s] TX expected $rst_tx" 132239aab882SMatthieu Baerts fail_test 1323922fd2b3SGeliang Tang dump_stats=1 1324922fd2b3SGeliang Tang else 1325922fd2b3SGeliang Tang echo -n "[ ok ]" 1326922fd2b3SGeliang Tang fi 1327922fd2b3SGeliang Tang 1328922fd2b3SGeliang Tang echo -n " - rstrx " 1329922fd2b3SGeliang Tang count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPRstRx | awk '{print $2}') 1330922fd2b3SGeliang Tang [ -z "$count" ] && count=0 13316bf41020SPaolo Abeni if [ "$count" -lt "$rst_rx" ]; then 1332922fd2b3SGeliang Tang echo "[fail] got $count MP_RST[s] RX expected $rst_rx" 133339aab882SMatthieu Baerts fail_test 1334922fd2b3SGeliang Tang dump_stats=1 1335922fd2b3SGeliang Tang else 1336922fd2b3SGeliang Tang echo -n "[ ok ]" 1337922fd2b3SGeliang Tang fi 1338922fd2b3SGeliang Tang 1339922fd2b3SGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 1340922fd2b3SGeliang Tang 1341922fd2b3SGeliang Tang echo "$extra_msg" 1342922fd2b3SGeliang Tang} 1343922fd2b3SGeliang Tang 13448bd03be3SGeliang Tangchk_infi_nr() 13458bd03be3SGeliang Tang{ 13468bd03be3SGeliang Tang local infi_tx=$1 13478bd03be3SGeliang Tang local infi_rx=$2 13488bd03be3SGeliang Tang local count 13498bd03be3SGeliang Tang local dump_stats 13508bd03be3SGeliang Tang 13518bd03be3SGeliang Tang printf "%-${nr_blank}s %s" " " "itx" 13528bd03be3SGeliang Tang count=$(ip netns exec $ns2 nstat -as | grep InfiniteMapTx | awk '{print $2}') 13538bd03be3SGeliang Tang [ -z "$count" ] && count=0 13548bd03be3SGeliang Tang if [ "$count" != "$infi_tx" ]; then 13558bd03be3SGeliang Tang echo "[fail] got $count infinite map[s] TX expected $infi_tx" 13568bd03be3SGeliang Tang fail_test 13578bd03be3SGeliang Tang dump_stats=1 13588bd03be3SGeliang Tang else 13598bd03be3SGeliang Tang echo -n "[ ok ]" 13608bd03be3SGeliang Tang fi 13618bd03be3SGeliang Tang 13628bd03be3SGeliang Tang echo -n " - infirx" 13638bd03be3SGeliang Tang count=$(ip netns exec $ns1 nstat -as | grep InfiniteMapRx | awk '{print $2}') 13648bd03be3SGeliang Tang [ -z "$count" ] && count=0 13658bd03be3SGeliang Tang if [ "$count" != "$infi_rx" ]; then 13668bd03be3SGeliang Tang echo "[fail] got $count infinite map[s] RX expected $infi_rx" 13678bd03be3SGeliang Tang fail_test 13688bd03be3SGeliang Tang dump_stats=1 13698bd03be3SGeliang Tang else 13708bd03be3SGeliang Tang echo "[ ok ]" 13718bd03be3SGeliang Tang fi 13728bd03be3SGeliang Tang 13738bd03be3SGeliang Tang [ "${dump_stats}" = 1 ] && dump_stats 13748bd03be3SGeliang Tang} 13758bd03be3SGeliang Tang 1376b08fbf24SPaolo Abenichk_join_nr() 1377b08fbf24SPaolo Abeni{ 1378c7d49c03SMatthieu Baerts local syn_nr=$1 1379c7d49c03SMatthieu Baerts local syn_ack_nr=$2 1380c7d49c03SMatthieu Baerts local ack_nr=$3 1381c7d49c03SMatthieu Baerts local csum_ns1=${4:-0} 1382c7d49c03SMatthieu Baerts local csum_ns2=${5:-0} 1383c7d49c03SMatthieu Baerts local fail_nr=${6:-0} 1384c7d49c03SMatthieu Baerts local rst_nr=${7:-0} 13858bd03be3SGeliang Tang local infi_nr=${8:-0} 13868bd03be3SGeliang Tang local corrupted_pkts=${9:-0} 1387b08fbf24SPaolo Abeni local count 1388b08fbf24SPaolo Abeni local dump_stats 1389e35f885bSPaolo Abeni local with_cookie 1390c7d49c03SMatthieu Baerts local title="${TEST_NAME}" 1391b08fbf24SPaolo Abeni 1392c7d49c03SMatthieu Baerts if [ "${corrupted_pkts}" -gt 0 ]; then 1393c7d49c03SMatthieu Baerts title+=": ${corrupted_pkts} corrupted pkts" 1394c7d49c03SMatthieu Baerts fi 1395c7d49c03SMatthieu Baerts 1396c7d49c03SMatthieu Baerts printf "%03u %-36s %s" "${TEST_COUNT}" "${title}" "syn" 13974bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}') 1398b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1399b08fbf24SPaolo Abeni if [ "$count" != "$syn_nr" ]; then 1400b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] syn expected $syn_nr" 140139aab882SMatthieu Baerts fail_test 1402b08fbf24SPaolo Abeni dump_stats=1 1403b08fbf24SPaolo Abeni else 1404b08fbf24SPaolo Abeni echo -n "[ ok ]" 1405b08fbf24SPaolo Abeni fi 1406b08fbf24SPaolo Abeni 1407b08fbf24SPaolo Abeni echo -n " - synack" 14084bfadd71SMatthieu Baerts with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 14094bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}') 1410b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1411b08fbf24SPaolo Abeni if [ "$count" != "$syn_ack_nr" ]; then 1412e35f885bSPaolo Abeni # simult connections exceeding the limit with cookie enabled could go up to 1413e35f885bSPaolo Abeni # synack validation as the conn limit can be enforced reliably only after 1414e35f885bSPaolo Abeni # the subflow creation 1415e35f885bSPaolo Abeni if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 1416e35f885bSPaolo Abeni echo -n "[ ok ]" 1417e35f885bSPaolo Abeni else 1418b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr" 141939aab882SMatthieu Baerts fail_test 1420b08fbf24SPaolo Abeni dump_stats=1 1421e35f885bSPaolo Abeni fi 1422b08fbf24SPaolo Abeni else 1423b08fbf24SPaolo Abeni echo -n "[ ok ]" 1424b08fbf24SPaolo Abeni fi 1425b08fbf24SPaolo Abeni 1426b08fbf24SPaolo Abeni echo -n " - ack" 14274bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}') 1428b08fbf24SPaolo Abeni [ -z "$count" ] && count=0 1429b08fbf24SPaolo Abeni if [ "$count" != "$ack_nr" ]; then 1430b08fbf24SPaolo Abeni echo "[fail] got $count JOIN[s] ack expected $ack_nr" 143139aab882SMatthieu Baerts fail_test 1432b08fbf24SPaolo Abeni dump_stats=1 1433b08fbf24SPaolo Abeni else 1434b08fbf24SPaolo Abeni echo "[ ok ]" 1435b08fbf24SPaolo Abeni fi 1436327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1437b6e074e1SGeliang Tang if [ $validate_checksum -eq 1 ]; then 14383c082695SGeliang Tang chk_csum_nr $csum_ns1 $csum_ns2 143926516e10SGeliang Tang chk_fail_nr $fail_nr $fail_nr 144026516e10SGeliang Tang chk_rst_nr $rst_nr $rst_nr 14418bd03be3SGeliang Tang chk_infi_nr $infi_nr $infi_nr 1442af66d3e1SGeliang Tang fi 1443b08fbf24SPaolo Abeni} 1444b08fbf24SPaolo Abeni 14457d1e6f16SPaolo Abeni# a negative value for 'stale_max' means no upper bound: 14467d1e6f16SPaolo Abeni# for bidirectional transfer, if one peer sleep for a while 14477d1e6f16SPaolo Abeni# - as these tests do - we can have a quite high number of 14487d1e6f16SPaolo Abeni# stale/recover conversions, proportional to 14497d1e6f16SPaolo Abeni# sleep duration/ MPTCP-level RTX interval. 14507d1e6f16SPaolo Abenichk_stale_nr() 14517d1e6f16SPaolo Abeni{ 14527d1e6f16SPaolo Abeni local ns=$1 14537d1e6f16SPaolo Abeni local stale_min=$2 14547d1e6f16SPaolo Abeni local stale_max=$3 14557d1e6f16SPaolo Abeni local stale_delta=$4 14567d1e6f16SPaolo Abeni local dump_stats 14577d1e6f16SPaolo Abeni local stale_nr 14587d1e6f16SPaolo Abeni local recover_nr 14597d1e6f16SPaolo Abeni 14609a0a9367SGeliang Tang printf "%-${nr_blank}s %-18s" " " "stale" 14614bfadd71SMatthieu Baerts stale_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}') 14627d1e6f16SPaolo Abeni [ -z "$stale_nr" ] && stale_nr=0 14634bfadd71SMatthieu Baerts recover_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}') 14647d1e6f16SPaolo Abeni [ -z "$recover_nr" ] && recover_nr=0 14657d1e6f16SPaolo Abeni 14667d1e6f16SPaolo Abeni if [ $stale_nr -lt $stale_min ] || 1467d8d08302SMatthieu Baerts { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1468d8d08302SMatthieu Baerts [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 14697d1e6f16SPaolo Abeni echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \ 14707d1e6f16SPaolo Abeni " expected stale in range [$stale_min..$stale_max]," \ 14717d1e6f16SPaolo Abeni " stale-recover delta $stale_delta " 147239aab882SMatthieu Baerts fail_test 14737d1e6f16SPaolo Abeni dump_stats=1 14747d1e6f16SPaolo Abeni else 14757d1e6f16SPaolo Abeni echo "[ ok ]" 14767d1e6f16SPaolo Abeni fi 14777d1e6f16SPaolo Abeni 14787d1e6f16SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 14797d1e6f16SPaolo Abeni echo $ns stats 14807d1e6f16SPaolo Abeni ip netns exec $ns ip -s link show 14817d1e6f16SPaolo Abeni ip netns exec $ns nstat -as | grep MPTcp 14827d1e6f16SPaolo Abeni fi 14837d1e6f16SPaolo Abeni} 14847d1e6f16SPaolo Abeni 1485be613160SGeliang Tangchk_add_nr() 1486be613160SGeliang Tang{ 1487be613160SGeliang Tang local add_nr=$1 1488be613160SGeliang Tang local echo_nr=$2 14898a127bf6SGeliang Tang local port_nr=${3:-0} 14908a127bf6SGeliang Tang local syn_nr=${4:-$port_nr} 14918a127bf6SGeliang Tang local syn_ack_nr=${5:-$port_nr} 14928a127bf6SGeliang Tang local ack_nr=${6:-$port_nr} 14938a127bf6SGeliang Tang local mis_syn_nr=${7:-0} 14948a127bf6SGeliang Tang local mis_ack_nr=${8:-0} 1495be613160SGeliang Tang local count 1496be613160SGeliang Tang local dump_stats 14976ef84b15SPaolo Abeni local timeout 14986ef84b15SPaolo Abeni 14994bfadd71SMatthieu Baerts timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1500be613160SGeliang Tang 15019a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "add" 15024bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as MPTcpExtAddAddr | grep MPTcpExtAddAddr | awk '{print $2}') 1503be613160SGeliang Tang [ -z "$count" ] && count=0 15046ef84b15SPaolo Abeni 15056ef84b15SPaolo Abeni # if the test configured a short timeout tolerate greater then expected 15066ef84b15SPaolo Abeni # add addrs options, due to retransmissions 1507d8d08302SMatthieu Baerts if [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 1508be613160SGeliang Tang echo "[fail] got $count ADD_ADDR[s] expected $add_nr" 150939aab882SMatthieu Baerts fail_test 1510be613160SGeliang Tang dump_stats=1 1511be613160SGeliang Tang else 1512be613160SGeliang Tang echo -n "[ ok ]" 1513be613160SGeliang Tang fi 1514be613160SGeliang Tang 1515be613160SGeliang Tang echo -n " - echo " 15164bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}') 1517be613160SGeliang Tang [ -z "$count" ] && count=0 1518be613160SGeliang Tang if [ "$count" != "$echo_nr" ]; then 1519be613160SGeliang Tang echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr" 152039aab882SMatthieu Baerts fail_test 1521be613160SGeliang Tang dump_stats=1 1522be613160SGeliang Tang else 15238a127bf6SGeliang Tang echo -n "[ ok ]" 15248a127bf6SGeliang Tang fi 15258a127bf6SGeliang Tang 15268a127bf6SGeliang Tang if [ $port_nr -gt 0 ]; then 15278a127bf6SGeliang Tang echo -n " - pt " 15284bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}') 15298a127bf6SGeliang Tang [ -z "$count" ] && count=0 15308a127bf6SGeliang Tang if [ "$count" != "$port_nr" ]; then 15318a127bf6SGeliang Tang echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" 153239aab882SMatthieu Baerts fail_test 15338a127bf6SGeliang Tang dump_stats=1 15348a127bf6SGeliang Tang else 1535be613160SGeliang Tang echo "[ ok ]" 1536be613160SGeliang Tang fi 1537be613160SGeliang Tang 15389a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "syn" 15394bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | 15404bfadd71SMatthieu Baerts awk '{print $2}') 15418a127bf6SGeliang Tang [ -z "$count" ] && count=0 15428a127bf6SGeliang Tang if [ "$count" != "$syn_nr" ]; then 15438a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] syn with a different \ 15448a127bf6SGeliang Tang port-number expected $syn_nr" 154539aab882SMatthieu Baerts fail_test 15468a127bf6SGeliang Tang dump_stats=1 15478a127bf6SGeliang Tang else 15488a127bf6SGeliang Tang echo -n "[ ok ]" 15498a127bf6SGeliang Tang fi 15508a127bf6SGeliang Tang 15518a127bf6SGeliang Tang echo -n " - synack" 15524bfadd71SMatthieu Baerts count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | 15534bfadd71SMatthieu Baerts awk '{print $2}') 15548a127bf6SGeliang Tang [ -z "$count" ] && count=0 15558a127bf6SGeliang Tang if [ "$count" != "$syn_ack_nr" ]; then 15568a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] synack with a different \ 15578a127bf6SGeliang Tang port-number expected $syn_ack_nr" 155839aab882SMatthieu Baerts fail_test 15598a127bf6SGeliang Tang dump_stats=1 15608a127bf6SGeliang Tang else 15618a127bf6SGeliang Tang echo -n "[ ok ]" 15628a127bf6SGeliang Tang fi 15638a127bf6SGeliang Tang 15648a127bf6SGeliang Tang echo -n " - ack" 15654bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | 15664bfadd71SMatthieu Baerts awk '{print $2}') 15678a127bf6SGeliang Tang [ -z "$count" ] && count=0 15688a127bf6SGeliang Tang if [ "$count" != "$ack_nr" ]; then 15698a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] ack with a different \ 15708a127bf6SGeliang Tang port-number expected $ack_nr" 157139aab882SMatthieu Baerts fail_test 15728a127bf6SGeliang Tang dump_stats=1 15738a127bf6SGeliang Tang else 15748a127bf6SGeliang Tang echo "[ ok ]" 15758a127bf6SGeliang Tang fi 15768a127bf6SGeliang Tang 15779a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "syn" 15784bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | 15794bfadd71SMatthieu Baerts awk '{print $2}') 15808a127bf6SGeliang Tang [ -z "$count" ] && count=0 15818a127bf6SGeliang Tang if [ "$count" != "$mis_syn_nr" ]; then 15828a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] syn with a mismatched \ 15838a127bf6SGeliang Tang port-number expected $mis_syn_nr" 158439aab882SMatthieu Baerts fail_test 15858a127bf6SGeliang Tang dump_stats=1 15868a127bf6SGeliang Tang else 15878a127bf6SGeliang Tang echo -n "[ ok ]" 15888a127bf6SGeliang Tang fi 15898a127bf6SGeliang Tang 15908a127bf6SGeliang Tang echo -n " - ack " 15914bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | 15924bfadd71SMatthieu Baerts awk '{print $2}') 15938a127bf6SGeliang Tang [ -z "$count" ] && count=0 15948a127bf6SGeliang Tang if [ "$count" != "$mis_ack_nr" ]; then 15958a127bf6SGeliang Tang echo "[fail] got $count JOIN[s] ack with a mismatched \ 15968a127bf6SGeliang Tang port-number expected $mis_ack_nr" 159739aab882SMatthieu Baerts fail_test 15988a127bf6SGeliang Tang dump_stats=1 15998a127bf6SGeliang Tang else 16008a127bf6SGeliang Tang echo "[ ok ]" 16018a127bf6SGeliang Tang fi 16028a127bf6SGeliang Tang else 16038a127bf6SGeliang Tang echo "" 16048a127bf6SGeliang Tang fi 16058a127bf6SGeliang Tang 1606327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1607be613160SGeliang Tang} 1608be613160SGeliang Tang 1609dd72b0feSGeliang Tangchk_rm_nr() 1610dd72b0feSGeliang Tang{ 1611dd72b0feSGeliang Tang local rm_addr_nr=$1 1612dd72b0feSGeliang Tang local rm_subflow_nr=$2 16136fa0174aSPaolo Abeni local invert 16146fa0174aSPaolo Abeni local simult 1615dd72b0feSGeliang Tang local count 1616dd72b0feSGeliang Tang local dump_stats 16177d9bf018SGeliang Tang local addr_ns=$ns1 16187d9bf018SGeliang Tang local subflow_ns=$ns2 16197d9bf018SGeliang Tang local extra_msg="" 16207028ba8aSGeliang Tang 16216fa0174aSPaolo Abeni shift 2 16226fa0174aSPaolo Abeni while [ -n "$1" ]; do 16236fa0174aSPaolo Abeni [ "$1" = "invert" ] && invert=true 16246fa0174aSPaolo Abeni [ "$1" = "simult" ] && simult=true 16256fa0174aSPaolo Abeni shift 16266fa0174aSPaolo Abeni done 16276fa0174aSPaolo Abeni 16286fa0174aSPaolo Abeni if [ -z $invert ]; then 16296fa0174aSPaolo Abeni addr_ns=$ns1 16306fa0174aSPaolo Abeni subflow_ns=$ns2 16316fa0174aSPaolo Abeni elif [ $invert = "true" ]; then 16327028ba8aSGeliang Tang addr_ns=$ns2 16337028ba8aSGeliang Tang subflow_ns=$ns1 16347d9bf018SGeliang Tang extra_msg=" invert" 16357028ba8aSGeliang Tang fi 1636dd72b0feSGeliang Tang 16379a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "rm " 16384bfadd71SMatthieu Baerts count=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmAddr | awk '{print $2}') 1639dd72b0feSGeliang Tang [ -z "$count" ] && count=0 1640dd72b0feSGeliang Tang if [ "$count" != "$rm_addr_nr" ]; then 1641dd72b0feSGeliang Tang echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr" 164239aab882SMatthieu Baerts fail_test 1643dd72b0feSGeliang Tang dump_stats=1 1644dd72b0feSGeliang Tang else 1645dd72b0feSGeliang Tang echo -n "[ ok ]" 1646dd72b0feSGeliang Tang fi 1647dd72b0feSGeliang Tang 16487d9bf018SGeliang Tang echo -n " - rmsf " 16494bfadd71SMatthieu Baerts count=$(ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 1650dd72b0feSGeliang Tang [ -z "$count" ] && count=0 16516fa0174aSPaolo Abeni if [ -n "$simult" ]; then 1652d8d08302SMatthieu Baerts local cnt suffix 1653d8d08302SMatthieu Baerts 1654d8d08302SMatthieu Baerts cnt=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 16556fa0174aSPaolo Abeni 16566fa0174aSPaolo Abeni # in case of simult flush, the subflow removal count on each side is 16576fa0174aSPaolo Abeni # unreliable 16586fa0174aSPaolo Abeni [ -z "$cnt" ] && cnt=0 16596fa0174aSPaolo Abeni count=$((count + cnt)) 16606fa0174aSPaolo Abeni [ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 16616fa0174aSPaolo Abeni if [ $count -ge "$rm_subflow_nr" ] && \ 16626fa0174aSPaolo Abeni [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 16636fa0174aSPaolo Abeni echo "[ ok ] $suffix" 16646fa0174aSPaolo Abeni else 16656fa0174aSPaolo Abeni echo "[fail] got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 166639aab882SMatthieu Baerts fail_test 16676fa0174aSPaolo Abeni dump_stats=1 16686fa0174aSPaolo Abeni fi 16696fa0174aSPaolo Abeni return 16706fa0174aSPaolo Abeni fi 1671dd72b0feSGeliang Tang if [ "$count" != "$rm_subflow_nr" ]; then 1672dd72b0feSGeliang Tang echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 167339aab882SMatthieu Baerts fail_test 1674dd72b0feSGeliang Tang dump_stats=1 1675dd72b0feSGeliang Tang else 16767d9bf018SGeliang Tang echo -n "[ ok ]" 1677dd72b0feSGeliang Tang fi 1678dd72b0feSGeliang Tang 1679327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 16807d9bf018SGeliang Tang 16817d9bf018SGeliang Tang echo "$extra_msg" 1682dd72b0feSGeliang Tang} 1683dd72b0feSGeliang Tang 1684718eb44eSGeliang Tangchk_prio_nr() 1685718eb44eSGeliang Tang{ 1686718eb44eSGeliang Tang local mp_prio_nr_tx=$1 1687718eb44eSGeliang Tang local mp_prio_nr_rx=$2 1688718eb44eSGeliang Tang local count 1689718eb44eSGeliang Tang local dump_stats 1690718eb44eSGeliang Tang 16919a0a9367SGeliang Tang printf "%-${nr_blank}s %s" " " "ptx" 16924bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}') 1693718eb44eSGeliang Tang [ -z "$count" ] && count=0 1694718eb44eSGeliang Tang if [ "$count" != "$mp_prio_nr_tx" ]; then 1695718eb44eSGeliang Tang echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 169639aab882SMatthieu Baerts fail_test 1697718eb44eSGeliang Tang dump_stats=1 1698718eb44eSGeliang Tang else 1699718eb44eSGeliang Tang echo -n "[ ok ]" 1700718eb44eSGeliang Tang fi 1701718eb44eSGeliang Tang 1702718eb44eSGeliang Tang echo -n " - prx " 17034bfadd71SMatthieu Baerts count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}') 1704718eb44eSGeliang Tang [ -z "$count" ] && count=0 1705718eb44eSGeliang Tang if [ "$count" != "$mp_prio_nr_rx" ]; then 1706718eb44eSGeliang Tang echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 170739aab882SMatthieu Baerts fail_test 1708718eb44eSGeliang Tang dump_stats=1 1709718eb44eSGeliang Tang else 1710718eb44eSGeliang Tang echo "[ ok ]" 1711718eb44eSGeliang Tang fi 1712718eb44eSGeliang Tang 1713327b9a94SPaolo Abeni [ "${dump_stats}" = 1 ] && dump_stats 1714718eb44eSGeliang Tang} 1715718eb44eSGeliang Tang 1716e274f715SPaolo Abenichk_subflow_nr() 1717e274f715SPaolo Abeni{ 1718e274f715SPaolo Abeni local need_title="$1" 1719e274f715SPaolo Abeni local msg="$2" 1720e274f715SPaolo Abeni local subflow_nr=$3 1721e274f715SPaolo Abeni local cnt1 1722e274f715SPaolo Abeni local cnt2 1723a635a8c3SPaolo Abeni local dump_stats 1724e274f715SPaolo Abeni 1725e274f715SPaolo Abeni if [ -n "${need_title}" ]; then 1726e274f715SPaolo Abeni printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 1727e274f715SPaolo Abeni else 1728e274f715SPaolo Abeni printf "%-${nr_blank}s %s" " " "${msg}" 1729e274f715SPaolo Abeni fi 1730e274f715SPaolo Abeni 1731e274f715SPaolo Abeni cnt1=$(ss -N $ns1 -tOni | grep -c token) 1732e274f715SPaolo Abeni cnt2=$(ss -N $ns2 -tOni | grep -c token) 17330fcd72dfSMatthieu Baerts if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 1734e274f715SPaolo Abeni echo "[fail] got $cnt1:$cnt2 subflows expected $subflow_nr" 1735e274f715SPaolo Abeni fail_test 1736e274f715SPaolo Abeni dump_stats=1 1737e274f715SPaolo Abeni else 1738e274f715SPaolo Abeni echo "[ ok ]" 1739e274f715SPaolo Abeni fi 1740e274f715SPaolo Abeni 1741a635a8c3SPaolo Abeni if [ "${dump_stats}" = 1 ]; then 1742a635a8c3SPaolo Abeni ss -N $ns1 -tOni 1743a635a8c3SPaolo Abeni ss -N $ns1 -tOni | grep token 1744a635a8c3SPaolo Abeni ip -n $ns1 mptcp endpoint 1745a635a8c3SPaolo Abeni dump_stats 1746a635a8c3SPaolo Abeni fi 1747e274f715SPaolo Abeni} 1748e274f715SPaolo Abeni 17499095ce97SGeliang Tangchk_mptcp_info() 17509095ce97SGeliang Tang{ 17519095ce97SGeliang Tang local nr_info=$1 17529095ce97SGeliang Tang local info 17539095ce97SGeliang Tang local cnt1 17549095ce97SGeliang Tang local cnt2 17559095ce97SGeliang Tang local dump_stats 17569095ce97SGeliang Tang 17579095ce97SGeliang Tang if [[ $nr_info = "subflows_"* ]]; then 17589095ce97SGeliang Tang info="subflows" 17599095ce97SGeliang Tang nr_info=${nr_info:9} 17609095ce97SGeliang Tang else 17619095ce97SGeliang Tang echo "[fail] unsupported argument: $nr_info" 17629095ce97SGeliang Tang fail_test 17639095ce97SGeliang Tang return 1 17649095ce97SGeliang Tang fi 17659095ce97SGeliang Tang 17669095ce97SGeliang Tang printf "%-${nr_blank}s %-30s" " " "mptcp_info $info=$nr_info" 17679095ce97SGeliang Tang 17689095ce97SGeliang Tang cnt1=$(ss -N $ns1 -inmHM | grep "$info:" | 17699095ce97SGeliang Tang sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 17709095ce97SGeliang Tang [ -z "$cnt1" ] && cnt1=0 17719095ce97SGeliang Tang cnt2=$(ss -N $ns2 -inmHM | grep "$info:" | 17729095ce97SGeliang Tang sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 17739095ce97SGeliang Tang [ -z "$cnt2" ] && cnt2=0 17749095ce97SGeliang Tang if [ "$cnt1" != "$nr_info" ] || [ "$cnt2" != "$nr_info" ]; then 17759095ce97SGeliang Tang echo "[fail] got $cnt1:$cnt2 $info expected $nr_info" 17769095ce97SGeliang Tang fail_test 17779095ce97SGeliang Tang dump_stats=1 17789095ce97SGeliang Tang else 17799095ce97SGeliang Tang echo "[ ok ]" 17809095ce97SGeliang Tang fi 17819095ce97SGeliang Tang 17829095ce97SGeliang Tang if [ "$dump_stats" = 1 ]; then 17839095ce97SGeliang Tang ss -N $ns1 -inmHM 17849095ce97SGeliang Tang ss -N $ns2 -inmHM 17859095ce97SGeliang Tang dump_stats 17869095ce97SGeliang Tang fi 17879095ce97SGeliang Tang} 17889095ce97SGeliang Tang 17897d1e6f16SPaolo Abenichk_link_usage() 17907d1e6f16SPaolo Abeni{ 17917d1e6f16SPaolo Abeni local ns=$1 17927d1e6f16SPaolo Abeni local link=$2 17937d1e6f16SPaolo Abeni local out=$3 17947d1e6f16SPaolo Abeni local expected_rate=$4 17954bfadd71SMatthieu Baerts 17964bfadd71SMatthieu Baerts local tx_link tx_total 17974bfadd71SMatthieu Baerts tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1798d8d08302SMatthieu Baerts tx_total=$(stat --format=%s $out) 1799d8d08302SMatthieu Baerts local tx_rate=$((tx_link * 100 / tx_total)) 18007d1e6f16SPaolo Abeni local tolerance=5 18017d1e6f16SPaolo Abeni 18029a0a9367SGeliang Tang printf "%-${nr_blank}s %-18s" " " "link usage" 1803d8d08302SMatthieu Baerts if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1804d8d08302SMatthieu Baerts [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 18057d1e6f16SPaolo Abeni echo "[fail] got $tx_rate% usage, expected $expected_rate%" 180639aab882SMatthieu Baerts fail_test 18077d1e6f16SPaolo Abeni else 18087d1e6f16SPaolo Abeni echo "[ ok ]" 18097d1e6f16SPaolo Abeni fi 18107d1e6f16SPaolo Abeni} 18117d1e6f16SPaolo Abeni 1812f98c2bcaSMat Martineauwait_attempt_fail() 181346e967d1SPaolo Abeni{ 181446e967d1SPaolo Abeni local timeout_ms=$((timeout_poll * 1000)) 181546e967d1SPaolo Abeni local time=0 181646e967d1SPaolo Abeni local ns=$1 181746e967d1SPaolo Abeni 181846e967d1SPaolo Abeni while [ $time -lt $timeout_ms ]; do 18191e777bd8SMatthieu Baerts local cnt 18201e777bd8SMatthieu Baerts 18211e777bd8SMatthieu Baerts cnt=$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFails | awk '{print $2}') 182246e967d1SPaolo Abeni 182346e967d1SPaolo Abeni [ "$cnt" = 1 ] && return 1 182446e967d1SPaolo Abeni time=$((time + 100)) 182546e967d1SPaolo Abeni sleep 0.1 182646e967d1SPaolo Abeni done 182746e967d1SPaolo Abeni return 1 182846e967d1SPaolo Abeni} 182946e967d1SPaolo Abeni 18305ac1d2d6SMat Martineauset_userspace_pm() 18315ac1d2d6SMat Martineau{ 18325ac1d2d6SMat Martineau local ns=$1 18335ac1d2d6SMat Martineau 18345ac1d2d6SMat Martineau ip netns exec $ns sysctl -q net.mptcp.pm_type=1 18355ac1d2d6SMat Martineau} 18365ac1d2d6SMat Martineau 18371002b89fSGeliang Tangsubflows_tests() 18381002b89fSGeliang Tang{ 1839c7d49c03SMatthieu Baerts if reset "no JOIN"; then 1840b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1841c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1842ae7bd9ccSMatthieu Baerts fi 1843b08fbf24SPaolo Abeni 18441002b89fSGeliang Tang # subflow limited by client 1845c7d49c03SMatthieu Baerts if reset "single subflow, limited by client"; then 184634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 184734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 0 184834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1849b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1850c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1851ae7bd9ccSMatthieu Baerts fi 1852b08fbf24SPaolo Abeni 18531002b89fSGeliang Tang # subflow limited by server 1854c7d49c03SMatthieu Baerts if reset "single subflow, limited by server"; then 185534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 0 185634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 185734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1858b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1859c7d49c03SMatthieu Baerts chk_join_nr 1 1 0 1860ae7bd9ccSMatthieu Baerts fi 1861b08fbf24SPaolo Abeni 1862b08fbf24SPaolo Abeni # subflow 1863c7d49c03SMatthieu Baerts if reset "single subflow"; then 186434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 186534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 186634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1867b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1868c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1869ae7bd9ccSMatthieu Baerts fi 1870b08fbf24SPaolo Abeni 1871b08fbf24SPaolo Abeni # multiple subflows 1872c7d49c03SMatthieu Baerts if reset "multiple subflows"; then 187334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 187434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 187534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 187634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1877b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1878c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1879ae7bd9ccSMatthieu Baerts fi 1880b08fbf24SPaolo Abeni 188172bcbc46SPaolo Abeni # multiple subflows limited by server 1882c7d49c03SMatthieu Baerts if reset "multiple subflows, limited by server"; then 188334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 188434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 188534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 188634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1887b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1888c7d49c03SMatthieu Baerts chk_join_nr 2 2 1 1889ae7bd9ccSMatthieu Baerts fi 1890c3eaa5f6SGeliang Tang 1891c3eaa5f6SGeliang Tang # single subflow, dev 1892c7d49c03SMatthieu Baerts if reset "single subflow, dev"; then 189334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 189434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 189534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 1896c3eaa5f6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1897c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1898ae7bd9ccSMatthieu Baerts fi 18991002b89fSGeliang Tang} 1900b08fbf24SPaolo Abeni 190146e967d1SPaolo Abenisubflows_error_tests() 190246e967d1SPaolo Abeni{ 190346e967d1SPaolo Abeni # If a single subflow is configured, and matches the MPC src 190446e967d1SPaolo Abeni # address, no additional subflow should be created 1905c7d49c03SMatthieu Baerts if reset "no MPC reuse with single endpoint"; then 190634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 190734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 190834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 190946e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1910c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1911ae7bd9ccSMatthieu Baerts fi 191246e967d1SPaolo Abeni 191346e967d1SPaolo Abeni # multiple subflows, with subflow creation error 1914c7d49c03SMatthieu Baerts if reset "multi subflows, with failing subflow"; then 191534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 191634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 191734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 191834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 19193469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 REJECT 192046e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1921c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1922ae7bd9ccSMatthieu Baerts fi 192346e967d1SPaolo Abeni 192446e967d1SPaolo Abeni # multiple subflows, with subflow timeout on MPJ 1925c7d49c03SMatthieu Baerts if reset "multi subflows, with subflow timeout"; then 192634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 192734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 192834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 192934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 19303469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 DROP 193146e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1932c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1933ae7bd9ccSMatthieu Baerts fi 193446e967d1SPaolo Abeni 193546e967d1SPaolo Abeni # multiple subflows, check that the endpoint corresponding to 193646e967d1SPaolo Abeni # closed subflow (due to reset) is not reused if additional 193746e967d1SPaolo Abeni # subflows are added later 1938c7d49c03SMatthieu Baerts if reset "multi subflows, fair usage on close"; then 193934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 194034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 194134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 19423469d72fSMatthieu Baerts filter_tcp_from $ns1 10.0.3.2 REJECT 194346e967d1SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow & 194446e967d1SPaolo Abeni 194546e967d1SPaolo Abeni # mpj subflow will be in TW after the reset 1946f98c2bcaSMat Martineau wait_attempt_fail $ns2 194734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 194846e967d1SPaolo Abeni wait 194946e967d1SPaolo Abeni 195046e967d1SPaolo Abeni # additional subflow could be created only if the PM select 195146e967d1SPaolo Abeni # the later endpoint, skipping the already used one 1952c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1953ae7bd9ccSMatthieu Baerts fi 195446e967d1SPaolo Abeni} 195546e967d1SPaolo Abeni 19561002b89fSGeliang Tangsignal_address_tests() 19571002b89fSGeliang Tang{ 1958b08fbf24SPaolo Abeni # add_address, unused 1959c7d49c03SMatthieu Baerts if reset "unused signal address"; then 196034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1961b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1962c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 1963be613160SGeliang Tang chk_add_nr 1 1 1964ae7bd9ccSMatthieu Baerts fi 1965b08fbf24SPaolo Abeni 1966b08fbf24SPaolo Abeni # accept and use add_addr 1967c7d49c03SMatthieu Baerts if reset "signal address"; then 196834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 196934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 197034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1971b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1972c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 1973be613160SGeliang Tang chk_add_nr 1 1 1974ae7bd9ccSMatthieu Baerts fi 1975b08fbf24SPaolo Abeni 1976b08fbf24SPaolo Abeni # accept and use add_addr with an additional subflow 1977b08fbf24SPaolo Abeni # note: signal address in server ns and local addresses in client ns must 1978b08fbf24SPaolo Abeni # belong to different subnets or one of the listed local address could be 1979b08fbf24SPaolo Abeni # used for 'add_addr' subflow 1980c7d49c03SMatthieu Baerts if reset "subflow and signal"; then 198134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 198234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 198334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 198434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1985b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1986c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 1987be613160SGeliang Tang chk_add_nr 1 1 1988ae7bd9ccSMatthieu Baerts fi 1989b08fbf24SPaolo Abeni 1990b08fbf24SPaolo Abeni # accept and use add_addr with additional subflows 1991c7d49c03SMatthieu Baerts if reset "multiple subflows and signal"; then 199234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 199334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 199434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 199534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 199634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 1997b08fbf24SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1998c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 1999be613160SGeliang Tang chk_add_nr 1 1 2000ae7bd9ccSMatthieu Baerts fi 2001ef360019SGeliang Tang 2002ef360019SGeliang Tang # signal addresses 2003c7d49c03SMatthieu Baerts if reset "signal addresses"; then 200434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 200534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 200634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 200734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 200834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2009ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2010c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2011ef360019SGeliang Tang chk_add_nr 3 3 2012ae7bd9ccSMatthieu Baerts fi 2013ef360019SGeliang Tang 2014ef360019SGeliang Tang # signal invalid addresses 2015c7d49c03SMatthieu Baerts if reset "signal invalid addresses"; then 201634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 201734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 201834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 201934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 202034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2021ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2022c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2023ef360019SGeliang Tang chk_add_nr 3 3 2024ae7bd9ccSMatthieu Baerts fi 202533c563adSYonglong Li 202633c563adSYonglong Li # signal addresses race test 2027c7d49c03SMatthieu Baerts if reset "signal addresses race test"; then 202834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 202934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 203034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 203134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 203234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 203334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 203434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 203534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 203634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 203734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 20386ef84b15SPaolo Abeni 20396ef84b15SPaolo Abeni # the peer could possibly miss some addr notification, allow retransmission 20406ef84b15SPaolo Abeni ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 20416ef84b15SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2042c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 204386e39e04SPaolo Abeni 204486e39e04SPaolo Abeni # the server will not signal the address terminating 204586e39e04SPaolo Abeni # the MPC subflow 204686e39e04SPaolo Abeni chk_add_nr 3 3 2047ae7bd9ccSMatthieu Baerts fi 20481002b89fSGeliang Tang} 2049b08fbf24SPaolo Abeni 20501002b89fSGeliang Tanglink_failure_tests() 20511002b89fSGeliang Tang{ 20528b819a84SFlorian Westphal # accept and use add_addr with additional subflows and link loss 2053c7d49c03SMatthieu Baerts if reset "multiple flows, signal, link failure"; then 20547d1e6f16SPaolo Abeni # without any b/w limit each veth could spool the packets and get 20557d1e6f16SPaolo Abeni # them acked at xmit time, so that the corresponding subflow will 20567d1e6f16SPaolo Abeni # have almost always no outstanding pkts, the scheduler will pick 20577d1e6f16SPaolo Abeni # always the first subflow and we will have hard time testing 20587d1e6f16SPaolo Abeni # active backup and link switch-over. 20597d1e6f16SPaolo Abeni # Let's set some arbitrary (low) virtual link limits. 20607d1e6f16SPaolo Abeni init_shapers 206134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 206234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 206334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 206434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 206534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 20668b819a84SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 1 2067c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 20688b819a84SFlorian Westphal chk_add_nr 1 1 20697d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 5 1 2070ae7bd9ccSMatthieu Baerts fi 20717d1e6f16SPaolo Abeni 20727d1e6f16SPaolo Abeni # accept and use add_addr with additional subflows and link loss 20737d1e6f16SPaolo Abeni # for bidirectional transfer 2074c7d49c03SMatthieu Baerts if reset "multi flows, signal, bidi, link fail"; then 20757d1e6f16SPaolo Abeni init_shapers 207634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 207734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 207834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 207934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 208034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 20817d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2 2082c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 20837d1e6f16SPaolo Abeni chk_add_nr 1 1 20847d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 1 2085ae7bd9ccSMatthieu Baerts fi 20867d1e6f16SPaolo Abeni 20877d1e6f16SPaolo Abeni # 2 subflows plus 1 backup subflow with a lossy link, backup 20887d1e6f16SPaolo Abeni # will never be used 2089c7d49c03SMatthieu Baerts if reset "backup subflow unused, link failure"; then 20907d1e6f16SPaolo Abeni init_shapers 209134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 209234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 209334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 2094e59300ceSMatthieu Baerts FAILING_LINKS="1" 209534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 20967d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1 2097c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 20987d1e6f16SPaolo Abeni chk_add_nr 1 1 20997d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 0 2100ae7bd9ccSMatthieu Baerts fi 21017d1e6f16SPaolo Abeni 21027d1e6f16SPaolo Abeni # 2 lossy links after half transfer, backup will get half of 21037d1e6f16SPaolo Abeni # the traffic 2104c7d49c03SMatthieu Baerts if reset "backup flow used, multi links fail"; then 21057d1e6f16SPaolo Abeni init_shapers 210634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 210734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 210834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 210934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2110e59300ceSMatthieu Baerts FAILING_LINKS="1 2" 21117d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1 2112c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21137d1e6f16SPaolo Abeni chk_add_nr 1 1 21147d1e6f16SPaolo Abeni chk_stale_nr $ns2 2 4 2 21157d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2116ae7bd9ccSMatthieu Baerts fi 21177d1e6f16SPaolo Abeni 21187d1e6f16SPaolo Abeni # use a backup subflow with the first subflow on a lossy link 21197d1e6f16SPaolo Abeni # for bidirectional transfer 2120c7d49c03SMatthieu Baerts if reset "backup flow used, bidi, link failure"; then 21217d1e6f16SPaolo Abeni init_shapers 212234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 212334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 212434aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 212534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2126e59300ceSMatthieu Baerts FAILING_LINKS="1 2" 21277d1e6f16SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 2 2128c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21297d1e6f16SPaolo Abeni chk_add_nr 1 1 21307d1e6f16SPaolo Abeni chk_stale_nr $ns2 1 -1 2 21317d1e6f16SPaolo Abeni chk_link_usage $ns2 ns2eth3 $cinsent 50 2132ae7bd9ccSMatthieu Baerts fi 21331002b89fSGeliang Tang} 21348b819a84SFlorian Westphal 21351002b89fSGeliang Tangadd_addr_timeout_tests() 21361002b89fSGeliang Tang{ 21378d014eaaSGeliang Tang # add_addr timeout 2138c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 213934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 214034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 214134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 21428b819a84SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2143c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21448d014eaaSGeliang Tang chk_add_nr 4 0 2145ae7bd9ccSMatthieu Baerts fi 21468d014eaaSGeliang Tang 21471002b89fSGeliang Tang # add_addr timeout IPv6 2148c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 214934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 215034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 215134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 21521002b89fSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2153c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21541002b89fSGeliang Tang chk_add_nr 4 0 2155ae7bd9ccSMatthieu Baerts fi 21568da6229bSGeliang Tang 21578da6229bSGeliang Tang # signal addresses timeout 2158c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 215934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 216034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 216134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 216234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2163cbfafac4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2164c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 21658da6229bSGeliang Tang chk_add_nr 8 0 2166ae7bd9ccSMatthieu Baerts fi 21678da6229bSGeliang Tang 21688da6229bSGeliang Tang # signal invalid addresses timeout 2169c7d49c03SMatthieu Baerts if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 217034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 217134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 217234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 217334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 2174cbfafac4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2175c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 21768da6229bSGeliang Tang chk_add_nr 8 0 2177ae7bd9ccSMatthieu Baerts fi 21781002b89fSGeliang Tang} 21791002b89fSGeliang Tang 21801002b89fSGeliang Tangremove_tests() 21811002b89fSGeliang Tang{ 2182dd72b0feSGeliang Tang # single subflow, remove 2183c7d49c03SMatthieu Baerts if reset "remove single subflow"; then 218434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 218534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 218634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 21872e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 2188c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2189dd72b0feSGeliang Tang chk_rm_nr 1 1 2190ae7bd9ccSMatthieu Baerts fi 2191dd72b0feSGeliang Tang 2192dd72b0feSGeliang Tang # multiple subflows, remove 2193c7d49c03SMatthieu Baerts if reset "remove multiple subflows"; then 219434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 219534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 219634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 219734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 21982e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow 2199c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2200dd72b0feSGeliang Tang chk_rm_nr 2 2 2201ae7bd9ccSMatthieu Baerts fi 2202dd72b0feSGeliang Tang 2203dd72b0feSGeliang Tang # single address, remove 2204c7d49c03SMatthieu Baerts if reset "remove single address"; then 220534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 220634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 220734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 22082e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2209c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2210dd72b0feSGeliang Tang chk_add_nr 1 1 22117028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2212ae7bd9ccSMatthieu Baerts fi 2213dd72b0feSGeliang Tang 2214dd72b0feSGeliang Tang # subflow and signal, remove 2215c7d49c03SMatthieu Baerts if reset "remove subflow and signal"; then 221634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 221734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 221834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 221934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 22202e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2221c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2222dd72b0feSGeliang Tang chk_add_nr 1 1 2223dd72b0feSGeliang Tang chk_rm_nr 1 1 2224ae7bd9ccSMatthieu Baerts fi 2225dd72b0feSGeliang Tang 2226dd72b0feSGeliang Tang # subflows and signal, remove 2227c7d49c03SMatthieu Baerts if reset "remove subflows and signal"; then 222834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 222934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 223034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 223134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 223234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 223322b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 speed_10 2234c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2235dd72b0feSGeliang Tang chk_add_nr 1 1 2236dd72b0feSGeliang Tang chk_rm_nr 2 2 2237ae7bd9ccSMatthieu Baerts fi 2238dd72b0feSGeliang Tang 2239ef360019SGeliang Tang # addresses remove 2240c7d49c03SMatthieu Baerts if reset "remove addresses"; then 224134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 224234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 224334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 224434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 224534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 224622b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2247c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2248ef360019SGeliang Tang chk_add_nr 3 3 2249ef360019SGeliang Tang chk_rm_nr 3 3 invert 2250ae7bd9ccSMatthieu Baerts fi 2251ef360019SGeliang Tang 2252ef360019SGeliang Tang # invalid addresses remove 2253c7d49c03SMatthieu Baerts if reset "remove invalid addresses"; then 225434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 225534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 225634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 225734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 225834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 225922b29557SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2260c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2261ef360019SGeliang Tang chk_add_nr 3 3 2262ef360019SGeliang Tang chk_rm_nr 3 1 invert 2263ae7bd9ccSMatthieu Baerts fi 2264ef360019SGeliang Tang 22656fe4ccdcSGeliang Tang # subflows and signal, flush 2266c7d49c03SMatthieu Baerts if reset "flush subflows and signal"; then 226734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 226834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 226934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 227034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 227134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 22722e8cbf45SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2273c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22746fe4ccdcSGeliang Tang chk_add_nr 1 1 22756fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2276ae7bd9ccSMatthieu Baerts fi 2277d2c4333aSGeliang Tang 2278d2c4333aSGeliang Tang # subflows flush 2279c7d49c03SMatthieu Baerts if reset "flush subflows"; then 228034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 228134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 228234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 228334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 228434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2285d2c4333aSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2286c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 22876fa0174aSPaolo Abeni chk_rm_nr 0 3 simult 2288ae7bd9ccSMatthieu Baerts fi 2289d2c4333aSGeliang Tang 2290d2c4333aSGeliang Tang # addresses flush 2291c7d49c03SMatthieu Baerts if reset "flush addresses"; then 229234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 229334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 229434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 229534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 229634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2297d2c4333aSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2298c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2299d2c4333aSGeliang Tang chk_add_nr 3 3 23006fa0174aSPaolo Abeni chk_rm_nr 3 3 invert simult 2301ae7bd9ccSMatthieu Baerts fi 2302ef360019SGeliang Tang 2303ef360019SGeliang Tang # invalid addresses flush 2304c7d49c03SMatthieu Baerts if reset "flush invalid addresses"; then 230534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 3 3 230634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 230734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 230834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 230934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 3 3 2310ef360019SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow 2311c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2312ef360019SGeliang Tang chk_add_nr 3 3 2313ef360019SGeliang Tang chk_rm_nr 3 1 invert 2314ae7bd9ccSMatthieu Baerts fi 23155e287fe7SGeliang Tang 23165e287fe7SGeliang Tang # remove id 0 subflow 2317c7d49c03SMatthieu Baerts if reset "remove id 0 subflow"; then 231834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 231934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 232034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 23215e287fe7SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow 2322c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23235e287fe7SGeliang Tang chk_rm_nr 1 1 2324ae7bd9ccSMatthieu Baerts fi 23255e287fe7SGeliang Tang 23265e287fe7SGeliang Tang # remove id 0 address 2327c7d49c03SMatthieu Baerts if reset "remove id 0 address"; then 232834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 232934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 233034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 23315e287fe7SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow 2332c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23335e287fe7SGeliang Tang chk_add_nr 1 1 23345e287fe7SGeliang Tang chk_rm_nr 1 1 invert 2335ae7bd9ccSMatthieu Baerts fi 23361002b89fSGeliang Tang} 23376fe4ccdcSGeliang Tang 23381002b89fSGeliang Tangadd_tests() 23391002b89fSGeliang Tang{ 23406208fd82SGeliang Tang # add single subflow 2341c7d49c03SMatthieu Baerts if reset "add single subflow"; then 234234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 234334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 23446208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow 2345c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2346ae7bd9ccSMatthieu Baerts fi 23476208fd82SGeliang Tang 23486208fd82SGeliang Tang # add signal address 2349c7d49c03SMatthieu Baerts if reset "add signal address"; then 235034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 235134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 23526208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2353c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 23546208fd82SGeliang Tang chk_add_nr 1 1 2355ae7bd9ccSMatthieu Baerts fi 23566208fd82SGeliang Tang 23576208fd82SGeliang Tang # add multiple subflows 2358c7d49c03SMatthieu Baerts if reset "add multiple subflows"; then 235934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 236034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 23616208fd82SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow 2362c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2363ae7bd9ccSMatthieu Baerts fi 23646208fd82SGeliang Tang 23656208fd82SGeliang Tang # add multiple subflows IPv6 2366c7d49c03SMatthieu Baerts if reset "add multiple subflows IPv6"; then 236734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 236834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 23696208fd82SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow 2370c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2371ae7bd9ccSMatthieu Baerts fi 23726208fd82SGeliang Tang 23736208fd82SGeliang Tang # add multiple addresses IPv6 2374c7d49c03SMatthieu Baerts if reset "add multiple addresses IPv6"; then 237534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 237634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 23776208fd82SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow 2378c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 23796208fd82SGeliang Tang chk_add_nr 2 2 2380ae7bd9ccSMatthieu Baerts fi 23811002b89fSGeliang Tang} 23826208fd82SGeliang Tang 23831002b89fSGeliang Tangipv6_tests() 23841002b89fSGeliang Tang{ 2385523514edSGeliang Tang # subflow IPv6 2386c7d49c03SMatthieu Baerts if reset "single subflow IPv6"; then 238734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 238834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 238934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2390523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2391c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2392ae7bd9ccSMatthieu Baerts fi 2393523514edSGeliang Tang 2394523514edSGeliang Tang # add_address, unused IPv6 2395c7d49c03SMatthieu Baerts if reset "unused signal address IPv6"; then 239634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2397523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2398c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2399523514edSGeliang Tang chk_add_nr 1 1 2400ae7bd9ccSMatthieu Baerts fi 2401523514edSGeliang Tang 2402523514edSGeliang Tang # signal address IPv6 2403c7d49c03SMatthieu Baerts if reset "single address IPv6"; then 240434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 240534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 240634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2407523514edSGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2408c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2409523514edSGeliang Tang chk_add_nr 1 1 2410ae7bd9ccSMatthieu Baerts fi 2411523514edSGeliang Tang 2412523514edSGeliang Tang # single address IPv6, remove 2413c7d49c03SMatthieu Baerts if reset "remove single address IPv6"; then 241434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 241534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 241634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 24172e8cbf45SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow 2418c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2419523514edSGeliang Tang chk_add_nr 1 1 24207028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2421ae7bd9ccSMatthieu Baerts fi 2422523514edSGeliang Tang 2423523514edSGeliang Tang # subflow and signal IPv6, remove 2424c7d49c03SMatthieu Baerts if reset "remove subflow and signal IPv6"; then 242534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 242634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 242734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 242834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 24292e8cbf45SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow 2430c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2431523514edSGeliang Tang chk_add_nr 1 1 2432523514edSGeliang Tang chk_rm_nr 1 1 2433ae7bd9ccSMatthieu Baerts fi 24341002b89fSGeliang Tang} 2435523514edSGeliang Tang 24361002b89fSGeliang Tangv4mapped_tests() 24371002b89fSGeliang Tang{ 2438a6094788SGeliang Tang # subflow IPv4-mapped to IPv4-mapped 2439c7d49c03SMatthieu Baerts if reset "single subflow IPv4-mapped"; then 244034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 244134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 244234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2443a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2444c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2445ae7bd9ccSMatthieu Baerts fi 2446a6094788SGeliang Tang 2447a6094788SGeliang Tang # signal address IPv4-mapped with IPv4-mapped sk 2448c7d49c03SMatthieu Baerts if reset "signal address IPv4-mapped"; then 244934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 245034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 245134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2452a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2453c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2454a6094788SGeliang Tang chk_add_nr 1 1 2455ae7bd9ccSMatthieu Baerts fi 2456a6094788SGeliang Tang 2457a6094788SGeliang Tang # subflow v4-map-v6 2458c7d49c03SMatthieu Baerts if reset "single subflow v4-map-v6"; then 245934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 246034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 246134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2462a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2463c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2464ae7bd9ccSMatthieu Baerts fi 2465a6094788SGeliang Tang 2466a6094788SGeliang Tang # signal address v4-map-v6 2467c7d49c03SMatthieu Baerts if reset "signal address v4-map-v6"; then 246834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 246934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 247034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2471a6094788SGeliang Tang run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2472c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2473a6094788SGeliang Tang chk_add_nr 1 1 2474ae7bd9ccSMatthieu Baerts fi 2475a6094788SGeliang Tang 2476a6094788SGeliang Tang # subflow v6-map-v4 2477c7d49c03SMatthieu Baerts if reset "single subflow v6-map-v4"; then 247834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 247934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 248034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2481a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2482c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2483ae7bd9ccSMatthieu Baerts fi 2484a6094788SGeliang Tang 2485a6094788SGeliang Tang # signal address v6-map-v4 2486c7d49c03SMatthieu Baerts if reset "signal address v6-map-v4"; then 248734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 248834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 248934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2490a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2491c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2492a6094788SGeliang Tang chk_add_nr 1 1 2493ae7bd9ccSMatthieu Baerts fi 2494a6094788SGeliang Tang 2495a6094788SGeliang Tang # no subflow IPv6 to v4 address 2496c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6"; then 249734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 249834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 249934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2500a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2501c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2502ae7bd9ccSMatthieu Baerts fi 2503a6094788SGeliang Tang 2504a6094788SGeliang Tang # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2505c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v4-v6-2"; then 250634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 250734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 250834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2509a6094788SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2510c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2511ae7bd9ccSMatthieu Baerts fi 2512a6094788SGeliang Tang 2513a6094788SGeliang Tang # no subflow IPv4 to v6 address, no need to slow down too then 2514c7d49c03SMatthieu Baerts if reset "no JOIN with diff families v6-v4"; then 251534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 251634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 251734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2518a6094788SGeliang Tang run_tests $ns1 $ns2 dead:beef:1::1 2519c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2520ae7bd9ccSMatthieu Baerts fi 25211002b89fSGeliang Tang} 2522a6094788SGeliang Tang 2523ad349374SPaolo Abenimixed_tests() 2524ad349374SPaolo Abeni{ 2525ad349374SPaolo Abeni if reset "IPv4 sockets do not use IPv6 addresses"; then 2526ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2527ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2528ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2529ad349374SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2530ad349374SPaolo Abeni chk_join_nr 0 0 0 2531ad349374SPaolo Abeni fi 2532ad349374SPaolo Abeni 2533ad349374SPaolo Abeni # Need an IPv6 mptcp socket to allow subflows of both families 2534ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows"; then 2535ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 1 2536ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 1 2537ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2538ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2539ad349374SPaolo Abeni chk_join_nr 1 1 1 2540ad349374SPaolo Abeni fi 2541ad349374SPaolo Abeni 2542ad349374SPaolo Abeni # cross families subflows will not be created even in fullmesh mode 2543ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1"; then 2544ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2545ad349374SPaolo Abeni pm_nl_set_limits $ns2 1 4 2546ad349374SPaolo Abeni pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2547ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2548ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2549ad349374SPaolo Abeni chk_join_nr 1 1 1 2550ad349374SPaolo Abeni fi 2551ad349374SPaolo Abeni 2552ad349374SPaolo Abeni # fullmesh still tries to create all the possibly subflows with 2553ad349374SPaolo Abeni # matching family 2554ad349374SPaolo Abeni if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2"; then 2555ad349374SPaolo Abeni pm_nl_set_limits $ns1 0 4 2556ad349374SPaolo Abeni pm_nl_set_limits $ns2 2 4 2557ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2558ad349374SPaolo Abeni pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2559ad349374SPaolo Abeni run_tests $ns1 $ns2 dead:beef:1::1 0 0 fullmesh_1 slow 2560ad349374SPaolo Abeni chk_join_nr 4 4 4 2561ad349374SPaolo Abeni fi 2562ad349374SPaolo Abeni} 2563ad349374SPaolo Abeni 25641002b89fSGeliang Tangbackup_tests() 25651002b89fSGeliang Tang{ 2566718eb44eSGeliang Tang # single subflow, backup 2567c7d49c03SMatthieu Baerts if reset "single subflow, backup"; then 256834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 256934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 257034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2571718eb44eSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup 2572c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2573718eb44eSGeliang Tang chk_prio_nr 0 1 2574ae7bd9ccSMatthieu Baerts fi 2575718eb44eSGeliang Tang 2576718eb44eSGeliang Tang # single address, backup 2577c7d49c03SMatthieu Baerts if reset "single address, backup"; then 257834aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 257934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 258034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 2581718eb44eSGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2582c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2583718eb44eSGeliang Tang chk_add_nr 1 1 2584d045b9ebSPaolo Abeni chk_prio_nr 1 1 2585ae7bd9ccSMatthieu Baerts fi 258633397b83SGeliang Tang 258733397b83SGeliang Tang # single address with port, backup 2588c7d49c03SMatthieu Baerts if reset "single address with port, backup"; then 258934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 259034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 259134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 259233397b83SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2593c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 259433397b83SGeliang Tang chk_add_nr 1 1 2595d045b9ebSPaolo Abeni chk_prio_nr 1 1 2596ae7bd9ccSMatthieu Baerts fi 2597914f6a59SPaolo Abeni 2598914f6a59SPaolo Abeni if reset "mpc backup"; then 2599914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2600914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2601914f6a59SPaolo Abeni chk_join_nr 0 0 0 2602914f6a59SPaolo Abeni chk_prio_nr 0 1 2603914f6a59SPaolo Abeni fi 2604914f6a59SPaolo Abeni 2605914f6a59SPaolo Abeni if reset "mpc backup both sides"; then 2606914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2607914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2608914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2609914f6a59SPaolo Abeni chk_join_nr 0 0 0 2610914f6a59SPaolo Abeni chk_prio_nr 1 1 2611914f6a59SPaolo Abeni fi 2612914f6a59SPaolo Abeni 2613914f6a59SPaolo Abeni if reset "mpc switch to backup"; then 2614914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2615914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2616914f6a59SPaolo Abeni chk_join_nr 0 0 0 2617914f6a59SPaolo Abeni chk_prio_nr 0 1 2618914f6a59SPaolo Abeni fi 2619914f6a59SPaolo Abeni 2620914f6a59SPaolo Abeni if reset "mpc switch to backup both sides"; then 2621914f6a59SPaolo Abeni pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2622914f6a59SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2623914f6a59SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2624914f6a59SPaolo Abeni chk_join_nr 0 0 0 2625914f6a59SPaolo Abeni chk_prio_nr 1 1 2626914f6a59SPaolo Abeni fi 26271002b89fSGeliang Tang} 2628718eb44eSGeliang Tang 2629178d0232SGeliang TangLISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2630178d0232SGeliang TangLISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2631178d0232SGeliang Tang 2632178d0232SGeliang TangAF_INET=2 2633178d0232SGeliang TangAF_INET6=10 2634178d0232SGeliang Tang 2635178d0232SGeliang Tangverify_listener_events() 2636178d0232SGeliang Tang{ 2637178d0232SGeliang Tang local evt=$1 2638178d0232SGeliang Tang local e_type=$2 2639178d0232SGeliang Tang local e_family=$3 2640178d0232SGeliang Tang local e_saddr=$4 2641178d0232SGeliang Tang local e_sport=$5 2642178d0232SGeliang Tang local type 2643178d0232SGeliang Tang local family 2644178d0232SGeliang Tang local saddr 2645178d0232SGeliang Tang local sport 2646178d0232SGeliang Tang 2647178d0232SGeliang Tang if [ $e_type = $LISTENER_CREATED ]; then 2648178d0232SGeliang Tang stdbuf -o0 -e0 printf "\t\t\t\t\t CREATE_LISTENER %s:%s"\ 2649178d0232SGeliang Tang $e_saddr $e_sport 2650178d0232SGeliang Tang elif [ $e_type = $LISTENER_CLOSED ]; then 2651178d0232SGeliang Tang stdbuf -o0 -e0 printf "\t\t\t\t\t CLOSE_LISTENER %s:%s "\ 2652178d0232SGeliang Tang $e_saddr $e_sport 2653178d0232SGeliang Tang fi 2654178d0232SGeliang Tang 2655178d0232SGeliang Tang type=$(grep "type:$e_type," $evt | 2656178d0232SGeliang Tang sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q') 2657178d0232SGeliang Tang family=$(grep "type:$e_type," $evt | 2658178d0232SGeliang Tang sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q') 2659178d0232SGeliang Tang sport=$(grep "type:$e_type," $evt | 2660178d0232SGeliang Tang sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 2661178d0232SGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 2662178d0232SGeliang Tang saddr=$(grep "type:$e_type," $evt | 2663178d0232SGeliang Tang sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 2664178d0232SGeliang Tang else 2665178d0232SGeliang Tang saddr=$(grep "type:$e_type," $evt | 2666178d0232SGeliang Tang sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q') 2667178d0232SGeliang Tang fi 2668178d0232SGeliang Tang 2669178d0232SGeliang Tang if [ $type ] && [ $type = $e_type ] && 2670178d0232SGeliang Tang [ $family ] && [ $family = $e_family ] && 2671178d0232SGeliang Tang [ $saddr ] && [ $saddr = $e_saddr ] && 2672178d0232SGeliang Tang [ $sport ] && [ $sport = $e_sport ]; then 2673178d0232SGeliang Tang stdbuf -o0 -e0 printf "[ ok ]\n" 2674178d0232SGeliang Tang return 0 2675178d0232SGeliang Tang fi 2676178d0232SGeliang Tang fail_test 2677178d0232SGeliang Tang stdbuf -o0 -e0 printf "[fail]\n" 2678178d0232SGeliang Tang} 2679178d0232SGeliang Tang 26801002b89fSGeliang Tangadd_addr_ports_tests() 26811002b89fSGeliang Tang{ 26828a127bf6SGeliang Tang # signal address with port 2683c7d49c03SMatthieu Baerts if reset "signal address with port"; then 268434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 268534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 268634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 26878a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2688c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 26898a127bf6SGeliang Tang chk_add_nr 1 1 1 2690ae7bd9ccSMatthieu Baerts fi 26918a127bf6SGeliang Tang 26928a127bf6SGeliang Tang # subflow and signal with port 2693c7d49c03SMatthieu Baerts if reset "subflow and signal with port"; then 269434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 269534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 269634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 269734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 26988a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2699c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27008a127bf6SGeliang Tang chk_add_nr 1 1 1 2701ae7bd9ccSMatthieu Baerts fi 27028a127bf6SGeliang Tang 27038a127bf6SGeliang Tang # single address with port, remove 2704178d0232SGeliang Tang # pm listener events 2705178d0232SGeliang Tang if reset_with_events "remove single address with port"; then 270634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 270734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 270834aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 27098a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2710c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 27118a127bf6SGeliang Tang chk_add_nr 1 1 1 27127028ba8aSGeliang Tang chk_rm_nr 1 1 invert 2713178d0232SGeliang Tang 2714178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2715178d0232SGeliang Tang verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2716178d0232SGeliang Tang kill_events_pids 2717ae7bd9ccSMatthieu Baerts fi 27188a127bf6SGeliang Tang 27198a127bf6SGeliang Tang # subflow and signal with port, remove 2720c7d49c03SMatthieu Baerts if reset "remove subflow and signal with port"; then 272134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 272234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 272334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 272434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 27258a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2726c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27278a127bf6SGeliang Tang chk_add_nr 1 1 1 27288a127bf6SGeliang Tang chk_rm_nr 1 1 2729ae7bd9ccSMatthieu Baerts fi 27308a127bf6SGeliang Tang 27318a127bf6SGeliang Tang # subflows and signal with port, flush 2732c7d49c03SMatthieu Baerts if reset "flush subflows and signal with port"; then 273334aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 273434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 273534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 273634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 273734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2738327b9a94SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 0 -8 -2 slow 2739c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 27408a127bf6SGeliang Tang chk_add_nr 1 1 27416fa0174aSPaolo Abeni chk_rm_nr 1 3 invert simult 2742ae7bd9ccSMatthieu Baerts fi 27438a127bf6SGeliang Tang 27448a127bf6SGeliang Tang # multiple addresses with port 2745c7d49c03SMatthieu Baerts if reset "multiple addresses with port"; then 274634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 274734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 274834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 274934aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 27508a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2751c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27528a127bf6SGeliang Tang chk_add_nr 2 2 2 2753ae7bd9ccSMatthieu Baerts fi 27548a127bf6SGeliang Tang 27558a127bf6SGeliang Tang # multiple addresses with ports 2756c7d49c03SMatthieu Baerts if reset "multiple addresses with ports"; then 275734aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 275834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 275934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 276034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 27618a127bf6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2762c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 27638a127bf6SGeliang Tang chk_add_nr 2 2 2 2764ae7bd9ccSMatthieu Baerts fi 27651002b89fSGeliang Tang} 27668a127bf6SGeliang Tang 27671002b89fSGeliang Tangsyncookies_tests() 27681002b89fSGeliang Tang{ 276900587187SFlorian Westphal # single subflow, syncookies 2770c7d49c03SMatthieu Baerts if reset_with_cookies "single subflow with syn cookies"; then 277134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 277234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 277334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 277400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2775c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2776ae7bd9ccSMatthieu Baerts fi 277700587187SFlorian Westphal 277800587187SFlorian Westphal # multiple subflows with syn cookies 2779c7d49c03SMatthieu Baerts if reset_with_cookies "multiple subflows with syn cookies"; then 278034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 278134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 278234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 278334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 278400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2785c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2786ae7bd9ccSMatthieu Baerts fi 278700587187SFlorian Westphal 278800587187SFlorian Westphal # multiple subflows limited by server 2789c7d49c03SMatthieu Baerts if reset_with_cookies "subflows limited by server w cookies"; then 279034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 279134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 2 279234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 279334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 279400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2795c7d49c03SMatthieu Baerts chk_join_nr 2 1 1 2796ae7bd9ccSMatthieu Baerts fi 279700587187SFlorian Westphal 279800587187SFlorian Westphal # test signal address with cookies 2799c7d49c03SMatthieu Baerts if reset_with_cookies "signal address with syn cookies"; then 280034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 280134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 280234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 280300587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2804c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2805be613160SGeliang Tang chk_add_nr 1 1 2806ae7bd9ccSMatthieu Baerts fi 280700587187SFlorian Westphal 280800587187SFlorian Westphal # test cookie with subflow and signal 2809c7d49c03SMatthieu Baerts if reset_with_cookies "subflow and signal w cookies"; then 281034aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 281134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 2 281234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 2 281334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 281400587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2815c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2816be613160SGeliang Tang chk_add_nr 1 1 2817ae7bd9ccSMatthieu Baerts fi 281800587187SFlorian Westphal 281900587187SFlorian Westphal # accept and use add_addr with additional subflows 2820c7d49c03SMatthieu Baerts if reset_with_cookies "subflows and signal w. cookies"; then 282134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 3 282234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 282334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 282434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 282534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 282600587187SFlorian Westphal run_tests $ns1 $ns2 10.0.1.1 2827c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 2828be613160SGeliang Tang chk_add_nr 1 1 2829ae7bd9ccSMatthieu Baerts fi 28301002b89fSGeliang Tang} 28311002b89fSGeliang Tang 2832af66d3e1SGeliang Tangchecksum_tests() 2833af66d3e1SGeliang Tang{ 2834af66d3e1SGeliang Tang # checksum test 0 0 2835ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 0; then 283634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 283734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2838af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2839c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2840ae7bd9ccSMatthieu Baerts fi 2841af66d3e1SGeliang Tang 2842af66d3e1SGeliang Tang # checksum test 1 1 2843ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 1; then 284434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 284534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2846af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2847c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2848ae7bd9ccSMatthieu Baerts fi 2849af66d3e1SGeliang Tang 2850af66d3e1SGeliang Tang # checksum test 0 1 2851ae7bd9ccSMatthieu Baerts if reset_with_checksum 0 1; then 285234aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 285334aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2854af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2855c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2856ae7bd9ccSMatthieu Baerts fi 2857af66d3e1SGeliang Tang 2858af66d3e1SGeliang Tang # checksum test 1 0 2859ae7bd9ccSMatthieu Baerts if reset_with_checksum 1 0; then 286034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 1 286134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 0 1 2862af66d3e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2863c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2864ae7bd9ccSMatthieu Baerts fi 2865af66d3e1SGeliang Tang} 2866af66d3e1SGeliang Tang 28670cddb4a6SGeliang Tangdeny_join_id0_tests() 28680cddb4a6SGeliang Tang{ 28690cddb4a6SGeliang Tang # subflow allow join id0 ns1 2870c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 287134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 287234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 287334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28740cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2875c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2876ae7bd9ccSMatthieu Baerts fi 28770cddb4a6SGeliang Tang 28780cddb4a6SGeliang Tang # subflow allow join id0 ns2 2879c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 288034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 288134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 288234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 28830cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2884c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 2885ae7bd9ccSMatthieu Baerts fi 28860cddb4a6SGeliang Tang 28870cddb4a6SGeliang Tang # signal address allow join id0 ns1 28880cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 2889c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 289034aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 289134aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 289234aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 28930cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2894c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 28950cddb4a6SGeliang Tang chk_add_nr 1 1 2896ae7bd9ccSMatthieu Baerts fi 28970cddb4a6SGeliang Tang 28980cddb4a6SGeliang Tang # signal address allow join id0 ns2 28990cddb4a6SGeliang Tang # ADD_ADDRs are not affected by allow_join_id0 value. 2900c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 290134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 1 290234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 1 290334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29040cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2905c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 29060cddb4a6SGeliang Tang chk_add_nr 1 1 2907ae7bd9ccSMatthieu Baerts fi 29080cddb4a6SGeliang Tang 29090cddb4a6SGeliang Tang # subflow and address allow join id0 ns1 2910c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 291134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 291234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 291334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 291434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29150cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2916c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 2917ae7bd9ccSMatthieu Baerts fi 29180cddb4a6SGeliang Tang 29190cddb4a6SGeliang Tang # subflow and address allow join id0 ns2 2920c7d49c03SMatthieu Baerts if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 292134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 2 292234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 2 2 292334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 292434aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 29250cddb4a6SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 2926c7d49c03SMatthieu Baerts chk_join_nr 1 1 1 2927ae7bd9ccSMatthieu Baerts fi 29280cddb4a6SGeliang Tang} 29290cddb4a6SGeliang Tang 29304f49d633SGeliang Tangfullmesh_tests() 29314f49d633SGeliang Tang{ 29324f49d633SGeliang Tang # fullmesh 1 29334f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added before the connection, 29344f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added during the connection. 2935c7d49c03SMatthieu Baerts if reset "fullmesh test 2x1"; then 293634aa6e3bSGeliang Tang pm_nl_set_limits $ns1 0 4 293734aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 293834aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 293934aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 29404f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2941c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 29424f49d633SGeliang Tang chk_add_nr 1 1 2943ae7bd9ccSMatthieu Baerts fi 29444f49d633SGeliang Tang 29454f49d633SGeliang Tang # fullmesh 2 29464f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29474f49d633SGeliang Tang # 1 fullmesh addr in ns2, added during the connection. 2948c7d49c03SMatthieu Baerts if reset "fullmesh test 1x1"; then 294934aa6e3bSGeliang Tang pm_nl_set_limits $ns1 1 3 295034aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 3 295134aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29524f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow 2953c7d49c03SMatthieu Baerts chk_join_nr 3 3 3 29544f49d633SGeliang Tang chk_add_nr 1 1 2955ae7bd9ccSMatthieu Baerts fi 29564f49d633SGeliang Tang 29574f49d633SGeliang Tang # fullmesh 3 29584f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29594f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection. 2960c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2"; then 296134aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 5 296234aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 5 296334aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29644f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2965c7d49c03SMatthieu Baerts chk_join_nr 5 5 5 29664f49d633SGeliang Tang chk_add_nr 1 1 2967ae7bd9ccSMatthieu Baerts fi 29684f49d633SGeliang Tang 29694f49d633SGeliang Tang # fullmesh 4 29704f49d633SGeliang Tang # 1 non-fullmesh addr in ns1, added before the connection, 29714f49d633SGeliang Tang # 2 fullmesh addrs in ns2, added during the connection, 29724f49d633SGeliang Tang # limit max_subflows to 4. 2973c7d49c03SMatthieu Baerts if reset "fullmesh test 1x2, limited"; then 297434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 2 4 297534aa6e3bSGeliang Tang pm_nl_set_limits $ns2 1 4 297634aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 29774f49d633SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2978c7d49c03SMatthieu Baerts chk_join_nr 4 4 4 29794f49d633SGeliang Tang chk_add_nr 1 1 2980ae7bd9ccSMatthieu Baerts fi 29816a0653b9SGeliang Tang 29826a0653b9SGeliang Tang # set fullmesh flag 2983c7d49c03SMatthieu Baerts if reset "set fullmesh flag test"; then 298434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 298534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 298634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 29876a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow fullmesh 2988c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29896a0653b9SGeliang Tang chk_rm_nr 0 1 2990ae7bd9ccSMatthieu Baerts fi 29916a0653b9SGeliang Tang 29926a0653b9SGeliang Tang # set nofullmesh flag 2993c7d49c03SMatthieu Baerts if reset "set nofullmesh flag test"; then 299434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 299534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 299634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 29976a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow nofullmesh 2998c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 29996a0653b9SGeliang Tang chk_rm_nr 0 1 3000ae7bd9ccSMatthieu Baerts fi 30016a0653b9SGeliang Tang 30026a0653b9SGeliang Tang # set backup,fullmesh flags 3003c7d49c03SMatthieu Baerts if reset "set backup,fullmesh flags test"; then 300434aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 300534aa6e3bSGeliang Tang pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 300634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 30076a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow backup,fullmesh 3008c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30096a0653b9SGeliang Tang chk_prio_nr 0 1 30106a0653b9SGeliang Tang chk_rm_nr 0 1 3011ae7bd9ccSMatthieu Baerts fi 30126a0653b9SGeliang Tang 30136a0653b9SGeliang Tang # set nobackup,nofullmesh flags 3014c7d49c03SMatthieu Baerts if reset "set nobackup,nofullmesh flags test"; then 301534aa6e3bSGeliang Tang pm_nl_set_limits $ns1 4 4 301634aa6e3bSGeliang Tang pm_nl_set_limits $ns2 4 4 301734aa6e3bSGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 30186a0653b9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup,nofullmesh 3019c7d49c03SMatthieu Baerts chk_join_nr 2 2 2 30206a0653b9SGeliang Tang chk_prio_nr 0 1 30216a0653b9SGeliang Tang chk_rm_nr 0 1 3022ae7bd9ccSMatthieu Baerts fi 30234f49d633SGeliang Tang} 30244f49d633SGeliang Tang 302501542c9bSGeliang Tangfastclose_tests() 302601542c9bSGeliang Tang{ 3027c7d49c03SMatthieu Baerts if reset "fastclose test"; then 30286bf41020SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_client 3029c7d49c03SMatthieu Baerts chk_join_nr 0 0 0 303001542c9bSGeliang Tang chk_fclose_nr 1 1 303101542c9bSGeliang Tang chk_rst_nr 1 1 invert 3032ae7bd9ccSMatthieu Baerts fi 30336bf41020SPaolo Abeni 30346bf41020SPaolo Abeni if reset "fastclose server test"; then 30356bf41020SPaolo Abeni run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_server 30366bf41020SPaolo Abeni chk_join_nr 0 0 0 30376bf41020SPaolo Abeni chk_fclose_nr 1 1 invert 30386bf41020SPaolo Abeni chk_rst_nr 1 1 30396bf41020SPaolo Abeni fi 304001542c9bSGeliang Tang} 304101542c9bSGeliang Tang 3042b6e074e1SGeliang Tangpedit_action_pkts() 3043b6e074e1SGeliang Tang{ 3044b6e074e1SGeliang Tang tc -n $ns2 -j -s action show action pedit index 100 | \ 3045c43ce398SGeliang Tang grep "packets" | \ 3046b6e074e1SGeliang Tang sed 's/.*"packets":\([0-9]\+\),.*/\1/' 3047b6e074e1SGeliang Tang} 3048b6e074e1SGeliang Tang 3049b6e074e1SGeliang Tangfail_tests() 3050b6e074e1SGeliang Tang{ 3051b6e074e1SGeliang Tang # single subflow 3052b6e074e1SGeliang Tang if reset_with_fail "Infinite map" 1; then 3053b6e074e1SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 128 3054b6e074e1SGeliang Tang chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 30551f7d325fSGeliang Tang chk_fail_nr 1 -1 invert 3056b6e074e1SGeliang Tang fi 30572ba18161SGeliang Tang 30582ba18161SGeliang Tang # multiple subflows 30592ba18161SGeliang Tang if reset_with_fail "MP_FAIL MP_RST" 2; then 30602ba18161SGeliang Tang tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 30612ba18161SGeliang Tang pm_nl_set_limits $ns1 0 1 30622ba18161SGeliang Tang pm_nl_set_limits $ns2 0 1 30632ba18161SGeliang Tang pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 30642ba18161SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 1024 30652ba18161SGeliang Tang chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 30662ba18161SGeliang Tang fi 3067b6e074e1SGeliang Tang} 3068b6e074e1SGeliang Tang 30695ac1d2d6SMat Martineauuserspace_tests() 30705ac1d2d6SMat Martineau{ 30715ac1d2d6SMat Martineau # userspace pm type prevents add_addr 30725ac1d2d6SMat Martineau if reset "userspace pm type prevents add_addr"; then 30735ac1d2d6SMat Martineau set_userspace_pm $ns1 30745ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 2 30755ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 2 30765ac1d2d6SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 30775ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 30785ac1d2d6SMat Martineau chk_join_nr 0 0 0 30795ac1d2d6SMat Martineau chk_add_nr 0 0 30805ac1d2d6SMat Martineau fi 30815ac1d2d6SMat Martineau 3082b3b71bf9SMat Martineau # userspace pm type does not echo add_addr without daemon 3083b3b71bf9SMat Martineau if reset "userspace pm no echo w/o daemon"; then 3084b3b71bf9SMat Martineau set_userspace_pm $ns2 3085b3b71bf9SMat Martineau pm_nl_set_limits $ns1 0 2 3086b3b71bf9SMat Martineau pm_nl_set_limits $ns2 0 2 3087b3b71bf9SMat Martineau pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3088b3b71bf9SMat Martineau run_tests $ns1 $ns2 10.0.1.1 3089b3b71bf9SMat Martineau chk_join_nr 0 0 0 3090b3b71bf9SMat Martineau chk_add_nr 1 0 3091b3b71bf9SMat Martineau fi 3092b3b71bf9SMat Martineau 30935ac1d2d6SMat Martineau # userspace pm type rejects join 30945ac1d2d6SMat Martineau if reset "userspace pm type rejects join"; then 30955ac1d2d6SMat Martineau set_userspace_pm $ns1 30965ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 30975ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 30985ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 30995ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 31005ac1d2d6SMat Martineau chk_join_nr 1 1 0 31015ac1d2d6SMat Martineau fi 31025ac1d2d6SMat Martineau 31035ac1d2d6SMat Martineau # userspace pm type does not send join 31045ac1d2d6SMat Martineau if reset "userspace pm type does not send join"; then 31055ac1d2d6SMat Martineau set_userspace_pm $ns2 31065ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 31075ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 31085ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31095ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 31105ac1d2d6SMat Martineau chk_join_nr 0 0 0 31115ac1d2d6SMat Martineau fi 31125ac1d2d6SMat Martineau 31135ac1d2d6SMat Martineau # userspace pm type prevents mp_prio 31145ac1d2d6SMat Martineau if reset "userspace pm type prevents mp_prio"; then 31155ac1d2d6SMat Martineau set_userspace_pm $ns1 31165ac1d2d6SMat Martineau pm_nl_set_limits $ns1 1 1 31175ac1d2d6SMat Martineau pm_nl_set_limits $ns2 1 1 31185ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31195ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 31205ac1d2d6SMat Martineau chk_join_nr 1 1 0 31215ac1d2d6SMat Martineau chk_prio_nr 0 0 31225ac1d2d6SMat Martineau fi 31235ac1d2d6SMat Martineau 31245ac1d2d6SMat Martineau # userspace pm type prevents rm_addr 31255ac1d2d6SMat Martineau if reset "userspace pm type prevents rm_addr"; then 31265ac1d2d6SMat Martineau set_userspace_pm $ns1 31275ac1d2d6SMat Martineau set_userspace_pm $ns2 31285ac1d2d6SMat Martineau pm_nl_set_limits $ns1 0 1 31295ac1d2d6SMat Martineau pm_nl_set_limits $ns2 0 1 31305ac1d2d6SMat Martineau pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 31315ac1d2d6SMat Martineau run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 31325ac1d2d6SMat Martineau chk_join_nr 0 0 0 31335ac1d2d6SMat Martineau chk_rm_nr 0 0 31345ac1d2d6SMat Martineau fi 313597040cf9SGeliang Tang 313697040cf9SGeliang Tang # userspace pm add & remove address 3137a3735625SGeliang Tang if reset_with_events "userspace pm add & remove address"; then 313897040cf9SGeliang Tang set_userspace_pm $ns1 313997040cf9SGeliang Tang pm_nl_set_limits $ns2 1 1 314097040cf9SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow 314197040cf9SGeliang Tang chk_join_nr 1 1 1 314297040cf9SGeliang Tang chk_add_nr 1 1 314397040cf9SGeliang Tang chk_rm_nr 1 1 invert 3144a3735625SGeliang Tang kill_events_pids 314597040cf9SGeliang Tang fi 31465e986ec4SGeliang Tang 31475e986ec4SGeliang Tang # userspace pm create destroy subflow 3148a3735625SGeliang Tang if reset_with_events "userspace pm create destroy subflow"; then 31495e986ec4SGeliang Tang set_userspace_pm $ns2 31505e986ec4SGeliang Tang pm_nl_set_limits $ns1 0 1 31515e986ec4SGeliang Tang run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow 31525e986ec4SGeliang Tang chk_join_nr 1 1 1 31535e986ec4SGeliang Tang chk_rm_nr 0 1 3154a3735625SGeliang Tang kill_events_pids 31555e986ec4SGeliang Tang fi 31565ac1d2d6SMat Martineau} 31575ac1d2d6SMat Martineau 3158e274f715SPaolo Abeniendpoint_tests() 315969c6ce7bSPaolo Abeni{ 316069c6ce7bSPaolo Abeni # userspace pm type prevents add_addr 3161c7d49c03SMatthieu Baerts if reset "implicit EP"; then 316269c6ce7bSPaolo Abeni pm_nl_set_limits $ns1 2 2 316369c6ce7bSPaolo Abeni pm_nl_set_limits $ns2 2 2 316469c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3165070d6dafSMatthieu Baerts run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2>/dev/null & 316669c6ce7bSPaolo Abeni 316769c6ce7bSPaolo Abeni wait_mpj $ns1 3168c7d49c03SMatthieu Baerts pm_nl_check_endpoint 1 "creation" \ 316969c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 317069c6ce7bSPaolo Abeni 317169c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 33 3172c7d49c03SMatthieu Baerts pm_nl_check_endpoint 0 "ID change is prevented" \ 317369c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags implicit 317469c6ce7bSPaolo Abeni 317569c6ce7bSPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 3176c7d49c03SMatthieu Baerts pm_nl_check_endpoint 0 "modif is allowed" \ 317769c6ce7bSPaolo Abeni $ns2 10.0.2.2 id 1 flags signal 3178070d6dafSMatthieu Baerts kill_tests_wait 3179ae7bd9ccSMatthieu Baerts fi 3180e274f715SPaolo Abeni 3181e274f715SPaolo Abeni if reset "delete and re-add"; then 3182e274f715SPaolo Abeni pm_nl_set_limits $ns1 1 1 3183e274f715SPaolo Abeni pm_nl_set_limits $ns2 1 1 3184e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3185070d6dafSMatthieu Baerts run_tests $ns1 $ns2 10.0.1.1 4 0 0 speed_20 2>/dev/null & 3186e274f715SPaolo Abeni 3187e274f715SPaolo Abeni wait_mpj $ns2 31889095ce97SGeliang Tang chk_subflow_nr needtitle "before delete" 2 31899095ce97SGeliang Tang chk_mptcp_info subflows_1 31909095ce97SGeliang Tang 3191e274f715SPaolo Abeni pm_nl_del_endpoint $ns2 2 10.0.2.2 3192e274f715SPaolo Abeni sleep 0.5 31939095ce97SGeliang Tang chk_subflow_nr "" "after delete" 1 31949095ce97SGeliang Tang chk_mptcp_info subflows_0 3195e274f715SPaolo Abeni 3196e274f715SPaolo Abeni pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3197e274f715SPaolo Abeni wait_mpj $ns2 3198e274f715SPaolo Abeni chk_subflow_nr "" "after re-add" 2 31999095ce97SGeliang Tang chk_mptcp_info subflows_1 3200070d6dafSMatthieu Baerts kill_tests_wait 3201e274f715SPaolo Abeni fi 320269c6ce7bSPaolo Abeni} 320369c6ce7bSPaolo Abeni 320422514d52SMatthieu Baerts# [$1: error message] 32051002b89fSGeliang Tangusage() 32061002b89fSGeliang Tang{ 320722514d52SMatthieu Baerts if [ -n "${1}" ]; then 320822514d52SMatthieu Baerts echo "${1}" 320922514d52SMatthieu Baerts ret=1 321022514d52SMatthieu Baerts fi 321122514d52SMatthieu Baerts 32121002b89fSGeliang Tang echo "mptcp_join usage:" 32133afd0280SMatthieu Baerts 32143afd0280SMatthieu Baerts local key 32153afd0280SMatthieu Baerts for key in "${!all_tests[@]}"; do 32163afd0280SMatthieu Baerts echo " -${key} ${all_tests[${key}]}" 32173afd0280SMatthieu Baerts done 32183afd0280SMatthieu Baerts 3219a673321aSMat Martineau echo " -c capture pcap files" 3220af66d3e1SGeliang Tang echo " -C enable data checksum" 3221621bd393SGeliang Tang echo " -i use ip mptcp" 32221002b89fSGeliang Tang echo " -h help" 322322514d52SMatthieu Baerts 3224c7d49c03SMatthieu Baerts echo "[test ids|names]" 3225ae7bd9ccSMatthieu Baerts 322622514d52SMatthieu Baerts exit ${ret} 32271002b89fSGeliang Tang} 32281002b89fSGeliang Tang 3229a673321aSMat Martineau 32303afd0280SMatthieu Baerts# Use a "simple" array to force an specific order we cannot have with an associative one 32313afd0280SMatthieu Baertsall_tests_sorted=( 32323afd0280SMatthieu Baerts f@subflows_tests 32333afd0280SMatthieu Baerts e@subflows_error_tests 32343afd0280SMatthieu Baerts s@signal_address_tests 32353afd0280SMatthieu Baerts l@link_failure_tests 32363afd0280SMatthieu Baerts t@add_addr_timeout_tests 32373afd0280SMatthieu Baerts r@remove_tests 32383afd0280SMatthieu Baerts a@add_tests 32393afd0280SMatthieu Baerts 6@ipv6_tests 32403afd0280SMatthieu Baerts 4@v4mapped_tests 3241ad349374SPaolo Abeni M@mixed_tests 32423afd0280SMatthieu Baerts b@backup_tests 32433afd0280SMatthieu Baerts p@add_addr_ports_tests 32443afd0280SMatthieu Baerts k@syncookies_tests 32453afd0280SMatthieu Baerts S@checksum_tests 32463afd0280SMatthieu Baerts d@deny_join_id0_tests 32473afd0280SMatthieu Baerts m@fullmesh_tests 32483afd0280SMatthieu Baerts z@fastclose_tests 3249b6e074e1SGeliang Tang F@fail_tests 32505ac1d2d6SMat Martineau u@userspace_tests 3251e274f715SPaolo Abeni I@endpoint_tests 32523afd0280SMatthieu Baerts) 32533afd0280SMatthieu Baerts 32543afd0280SMatthieu Baertsall_tests_args="" 32553afd0280SMatthieu Baertsall_tests_names=() 32563afd0280SMatthieu Baertsfor subtests in "${all_tests_sorted[@]}"; do 32573afd0280SMatthieu Baerts key="${subtests%@*}" 32583afd0280SMatthieu Baerts value="${subtests#*@}" 32593afd0280SMatthieu Baerts 32603afd0280SMatthieu Baerts all_tests_args+="${key}" 32613afd0280SMatthieu Baerts all_tests_names+=("${value}") 32623afd0280SMatthieu Baerts all_tests[${key}]="${value}" 32633afd0280SMatthieu Baertsdone 32643afd0280SMatthieu Baerts 3265826d7bdcSMatthieu Baertstests=() 32663afd0280SMatthieu Baertswhile getopts "${all_tests_args}cCih" opt; do 32671002b89fSGeliang Tang case $opt in 32683afd0280SMatthieu Baerts ["${all_tests_args}"]) 32693afd0280SMatthieu Baerts tests+=("${all_tests[${opt}]}") 327069c6ce7bSPaolo Abeni ;; 3271a673321aSMat Martineau c) 3272826d7bdcSMatthieu Baerts capture=1 3273a673321aSMat Martineau ;; 3274af66d3e1SGeliang Tang C) 3275826d7bdcSMatthieu Baerts checksum=1 3276af66d3e1SGeliang Tang ;; 3277621bd393SGeliang Tang i) 3278826d7bdcSMatthieu Baerts ip_mptcp=1 3279621bd393SGeliang Tang ;; 328022514d52SMatthieu Baerts h) 32811002b89fSGeliang Tang usage 32821002b89fSGeliang Tang ;; 328322514d52SMatthieu Baerts *) 328422514d52SMatthieu Baerts usage "Unknown option: -${opt}" 328522514d52SMatthieu Baerts ;; 32861002b89fSGeliang Tang esac 32871002b89fSGeliang Tangdone 328800587187SFlorian Westphal 3289ae7bd9ccSMatthieu Baertsshift $((OPTIND - 1)) 3290ae7bd9ccSMatthieu Baerts 3291ae7bd9ccSMatthieu Baertsfor arg in "${@}"; do 3292ae7bd9ccSMatthieu Baerts if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3293c7d49c03SMatthieu Baerts only_tests_ids+=("${arg}") 3294ae7bd9ccSMatthieu Baerts else 3295c7d49c03SMatthieu Baerts only_tests_names+=("${arg}") 3296ae7bd9ccSMatthieu Baerts fi 3297ae7bd9ccSMatthieu Baertsdone 3298ae7bd9ccSMatthieu Baerts 3299826d7bdcSMatthieu Baertsif [ ${#tests[@]} -eq 0 ]; then 33003afd0280SMatthieu Baerts tests=("${all_tests_names[@]}") 33013afd0280SMatthieu Baertsfi 33023afd0280SMatthieu Baerts 3303826d7bdcSMatthieu Baertsfor subtests in "${tests[@]}"; do 3304826d7bdcSMatthieu Baerts "${subtests}" 3305826d7bdcSMatthieu Baertsdone 3306826d7bdcSMatthieu Baerts 330739aab882SMatthieu Baertsif [ ${ret} -ne 0 ]; then 330839aab882SMatthieu Baerts echo 330939aab882SMatthieu Baerts echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 331039aab882SMatthieu Baerts for i in $(get_failed_tests_ids); do 331139aab882SMatthieu Baerts echo -e "\t- ${i}: ${failed_tests[${i}]}" 331239aab882SMatthieu Baerts done 331339aab882SMatthieu Baerts echo 331439aab882SMatthieu Baertsfi 331539aab882SMatthieu Baerts 3316b08fbf24SPaolo Abeniexit $ret 3317