1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# Double quotes to prevent globbing and word splitting is recommended in new 5# code but we accept it, especially because there were too many before having 6# address all other issues detected by shellcheck. 7#shellcheck disable=SC2086 8 9# ShellCheck incorrectly believes that most of the code here is unreachable 10# because it's invoked by variable name, see how the "tests" array is used 11#shellcheck disable=SC2317 12 13ret=0 14sin="" 15sinfail="" 16sout="" 17cin="" 18cinfail="" 19cinsent="" 20cout="" 21capout="" 22ns1="" 23ns2="" 24ksft_skip=4 25timeout_poll=30 26timeout_test=$((timeout_poll * 2 + 1)) 27capture=0 28checksum=0 29ip_mptcp=0 30check_invert=0 31validate_checksum=0 32init=0 33evts_ns1="" 34evts_ns2="" 35evts_ns1_pid=0 36evts_ns2_pid=0 37stats_dumped=0 38 39declare -A all_tests 40declare -a only_tests_ids 41declare -a only_tests_names 42declare -A failed_tests 43TEST_COUNT=0 44TEST_NAME="" 45nr_blank=40 46 47export FAILING_LINKS="" 48 49# generated using "nfbpf_compile '(ip && (ip[54] & 0xf0) == 0x30) || 50# (ip6 && (ip6[74] & 0xf0) == 0x30)'" 51CBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 52 48 0 0 0, 53 84 0 0 240, 54 21 0 3 64, 55 48 0 0 54, 56 84 0 0 240, 57 21 6 7 48, 58 48 0 0 0, 59 84 0 0 240, 60 21 0 4 96, 61 48 0 0 74, 62 84 0 0 240, 63 21 0 1 48, 64 6 0 0 65535, 65 6 0 0 0" 66 67init_partial() 68{ 69 capout=$(mktemp) 70 71 local sec rndh 72 sec=$(date +%s) 73 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX) 74 75 ns1="ns1-$rndh" 76 ns2="ns2-$rndh" 77 78 local netns 79 for netns in "$ns1" "$ns2"; do 80 ip netns add $netns || exit $ksft_skip 81 ip -net $netns link set lo up 82 ip netns exec $netns sysctl -q net.mptcp.enabled=1 83 ip netns exec $netns sysctl -q net.mptcp.pm_type=0 84 ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=0 85 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 86 if [ $checksum -eq 1 ]; then 87 ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=1 88 fi 89 done 90 91 stats_dumped=0 92 check_invert=0 93 validate_checksum=$checksum 94 FAILING_LINKS="" 95 96 # ns1 ns2 97 # ns1eth1 ns2eth1 98 # ns1eth2 ns2eth2 99 # ns1eth3 ns2eth3 100 # ns1eth4 ns2eth4 101 102 local i 103 for i in $(seq 1 4); do 104 ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" 105 ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i 106 ip -net "$ns1" addr add dead:beef:$i::1/64 dev ns1eth$i nodad 107 ip -net "$ns1" link set ns1eth$i up 108 109 ip -net "$ns2" addr add 10.0.$i.2/24 dev ns2eth$i 110 ip -net "$ns2" addr add dead:beef:$i::2/64 dev ns2eth$i nodad 111 ip -net "$ns2" link set ns2eth$i up 112 113 # let $ns2 reach any $ns1 address from any interface 114 ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i 115 ip -net "$ns2" route add default via dead:beef:$i::1 dev ns2eth$i metric 10$i 116 done 117} 118 119init_shapers() 120{ 121 local i 122 for i in $(seq 1 4); do 123 tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 124 tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 125 done 126} 127 128cleanup_partial() 129{ 130 rm -f "$capout" 131 132 local netns 133 for netns in "$ns1" "$ns2"; do 134 ip netns del $netns 135 rm -f /tmp/$netns.{nstat,out} 136 done 137} 138 139check_tools() 140{ 141 if ! ip -Version &> /dev/null; then 142 echo "SKIP: Could not run test without ip tool" 143 exit $ksft_skip 144 fi 145 146 if ! iptables -V &> /dev/null; then 147 echo "SKIP: Could not run all tests without iptables tool" 148 exit $ksft_skip 149 fi 150 151 if ! ip6tables -V &> /dev/null; then 152 echo "SKIP: Could not run all tests without ip6tables tool" 153 exit $ksft_skip 154 fi 155} 156 157init() { 158 init=1 159 160 check_tools 161 162 sin=$(mktemp) 163 sout=$(mktemp) 164 cin=$(mktemp) 165 cinsent=$(mktemp) 166 cout=$(mktemp) 167 evts_ns1=$(mktemp) 168 evts_ns2=$(mktemp) 169 170 trap cleanup EXIT 171 172 make_file "$cin" "client" 1 173 make_file "$sin" "server" 1 174} 175 176cleanup() 177{ 178 rm -f "$cin" "$cout" "$sinfail" 179 rm -f "$sin" "$sout" "$cinsent" "$cinfail" 180 rm -rf $evts_ns1 $evts_ns2 181 cleanup_partial 182} 183 184skip_test() 185{ 186 if [ "${#only_tests_ids[@]}" -eq 0 ] && [ "${#only_tests_names[@]}" -eq 0 ]; then 187 return 1 188 fi 189 190 local i 191 for i in "${only_tests_ids[@]}"; do 192 if [ "${TEST_COUNT}" -eq "${i}" ]; then 193 return 1 194 fi 195 done 196 for i in "${only_tests_names[@]}"; do 197 if [ "${TEST_NAME}" = "${i}" ]; then 198 return 1 199 fi 200 done 201 202 return 0 203} 204 205# $1: test name 206reset() 207{ 208 TEST_NAME="${1}" 209 210 TEST_COUNT=$((TEST_COUNT+1)) 211 212 if skip_test; then 213 return 1 214 fi 215 216 if [ "${init}" != "1" ]; then 217 init 218 else 219 cleanup_partial 220 fi 221 222 init_partial 223 224 return 0 225} 226 227# $1: test name 228reset_with_cookies() 229{ 230 reset "${1}" || return 1 231 232 local netns 233 for netns in "$ns1" "$ns2"; do 234 ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=2 235 done 236} 237 238# $1: test name 239reset_with_add_addr_timeout() 240{ 241 local ip="${2:-4}" 242 local tables 243 244 reset "${1}" || return 1 245 246 tables="iptables" 247 if [ $ip -eq 6 ]; then 248 tables="ip6tables" 249 fi 250 251 ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 252 ip netns exec $ns2 $tables -A OUTPUT -p tcp \ 253 -m tcp --tcp-option 30 \ 254 -m bpf --bytecode \ 255 "$CBPF_MPTCP_SUBOPTION_ADD_ADDR" \ 256 -j DROP 257} 258 259# $1: test name 260reset_with_checksum() 261{ 262 local ns1_enable=$1 263 local ns2_enable=$2 264 265 reset "checksum test ${1} ${2}" || return 1 266 267 ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=$ns1_enable 268 ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable 269 270 validate_checksum=1 271} 272 273reset_with_allow_join_id0() 274{ 275 local ns1_enable=$2 276 local ns2_enable=$3 277 278 reset "${1}" || return 1 279 280 ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable 281 ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable 282} 283 284# Modify TCP payload without corrupting the TCP packet 285# 286# This rule inverts a 8-bit word at byte offset 148 for the 2nd TCP ACK packets 287# carrying enough data. 288# Once it is done, the TCP Checksum field is updated so the packet is still 289# considered as valid at the TCP level. 290# Because the MPTCP checksum, covering the TCP options and data, has not been 291# updated, the modification will be detected and an MP_FAIL will be emitted: 292# what we want to validate here without corrupting "random" MPTCP options. 293# 294# To avoid having tc producing this pr_info() message for each TCP ACK packets 295# not carrying enough data: 296# 297# tc action pedit offset 162 out of bounds 298# 299# Netfilter is used to mark packets with enough data. 300reset_with_fail() 301{ 302 reset "${1}" || return 1 303 304 ip netns exec $ns1 sysctl -q net.mptcp.checksum_enabled=1 305 ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=1 306 307 check_invert=1 308 validate_checksum=1 309 local i="$2" 310 local ip="${3:-4}" 311 local tables 312 313 tables="iptables" 314 if [ $ip -eq 6 ]; then 315 tables="ip6tables" 316 fi 317 318 ip netns exec $ns2 $tables \ 319 -t mangle \ 320 -A OUTPUT \ 321 -o ns2eth$i \ 322 -p tcp \ 323 -m length --length 150:9999 \ 324 -m statistic --mode nth --packet 1 --every 99999 \ 325 -j MARK --set-mark 42 || exit 1 326 327 tc -n $ns2 qdisc add dev ns2eth$i clsact || exit 1 328 tc -n $ns2 filter add dev ns2eth$i egress \ 329 protocol ip prio 1000 \ 330 handle 42 fw \ 331 action pedit munge offset 148 u8 invert \ 332 pipe csum tcp \ 333 index 100 || exit 1 334} 335 336reset_with_events() 337{ 338 reset "${1}" || return 1 339 340 :> "$evts_ns1" 341 :> "$evts_ns2" 342 ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & 343 evts_ns1_pid=$! 344 ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & 345 evts_ns2_pid=$! 346} 347 348fail_test() 349{ 350 ret=1 351 failed_tests[${TEST_COUNT}]="${TEST_NAME}" 352 353 [ "${stats_dumped}" = 0 ] && dump_stats 354 stats_dumped=1 355} 356 357get_failed_tests_ids() 358{ 359 # sorted 360 local i 361 for i in "${!failed_tests[@]}"; do 362 echo "${i}" 363 done | sort -n 364} 365 366print_file_err() 367{ 368 ls -l "$1" 1>&2 369 echo "Trailing bytes are: " 370 tail -c 27 "$1" 371} 372 373check_transfer() 374{ 375 local in=$1 376 local out=$2 377 local what=$3 378 local bytes=$4 379 local i a b 380 381 local line 382 if [ -n "$bytes" ]; then 383 local out_size 384 # when truncating we must check the size explicitly 385 out_size=$(wc -c $out | awk '{print $1}') 386 if [ $out_size -ne $bytes ]; then 387 echo "[ FAIL ] $what output file has wrong size ($out_size, $bytes)" 388 fail_test 389 return 1 390 fi 391 bytes="--bytes=${bytes}" 392 fi 393 cmp -l "$in" "$out" ${bytes} | while read -r i a b; do 394 local sum=$((0${a} + 0${b})) 395 if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 396 echo "[ FAIL ] $what does not match (in, out):" 397 print_file_err "$in" 398 print_file_err "$out" 399 fail_test 400 401 return 1 402 else 403 echo "$what has inverted byte at ${i}" 404 fi 405 done 406 407 return 0 408} 409 410do_ping() 411{ 412 local listener_ns="$1" 413 local connector_ns="$2" 414 local connect_addr="$3" 415 416 if ! ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null; then 417 echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2 418 fail_test 419 fi 420} 421 422link_failure() 423{ 424 local ns="$1" 425 426 if [ -z "$FAILING_LINKS" ]; then 427 l=$((RANDOM%4)) 428 FAILING_LINKS=$((l+1)) 429 fi 430 431 local l 432 for l in $FAILING_LINKS; do 433 local veth="ns1eth$l" 434 ip -net "$ns" link set "$veth" down 435 done 436} 437 438# $1: IP address 439is_v6() 440{ 441 [ -z "${1##*:*}" ] 442} 443 444# $1: ns, $2: port 445wait_local_port_listen() 446{ 447 local listener_ns="${1}" 448 local port="${2}" 449 450 local port_hex 451 port_hex="$(printf "%04X" "${port}")" 452 453 local i 454 for i in $(seq 10); do 455 ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ 456 awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" && 457 break 458 sleep 0.1 459 done 460} 461 462rm_addr_count() 463{ 464 local ns=${1} 465 466 ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}' 467} 468 469# $1: ns, $2: old rm_addr counter in $ns 470wait_rm_addr() 471{ 472 local ns="${1}" 473 local old_cnt="${2}" 474 local cnt 475 476 local i 477 for i in $(seq 10); do 478 cnt=$(rm_addr_count ${ns}) 479 [ "$cnt" = "${old_cnt}" ] || break 480 sleep 0.1 481 done 482} 483 484wait_mpj() 485{ 486 local ns="${1}" 487 local cnt old_cnt 488 489 old_cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 490 491 local i 492 for i in $(seq 10); do 493 cnt=$(ip netns exec ${ns} nstat -as | grep MPJoinAckRx | awk '{print $2}') 494 [ "$cnt" = "${old_cnt}" ] || break 495 sleep 0.1 496 done 497} 498 499kill_wait() 500{ 501 kill $1 > /dev/null 2>&1 502 wait $1 2>/dev/null 503} 504 505kill_events_pids() 506{ 507 kill_wait $evts_ns1_pid 508 kill_wait $evts_ns2_pid 509} 510 511kill_tests_wait() 512{ 513 #shellcheck disable=SC2046 514 kill -SIGUSR1 $(ip netns pids $ns2) $(ip netns pids $ns1) 515 wait 516} 517 518pm_nl_set_limits() 519{ 520 local ns=$1 521 local addrs=$2 522 local subflows=$3 523 524 if [ $ip_mptcp -eq 1 ]; then 525 ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows 526 else 527 ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows 528 fi 529} 530 531pm_nl_add_endpoint() 532{ 533 local ns=$1 534 local addr=$2 535 local flags _flags 536 local port _port 537 local dev _dev 538 local id _id 539 local nr=2 540 541 local p 542 for p in "${@}" 543 do 544 if [ $p = "flags" ]; then 545 eval _flags=\$"$nr" 546 [ -n "$_flags" ]; flags="flags $_flags" 547 fi 548 if [ $p = "dev" ]; then 549 eval _dev=\$"$nr" 550 [ -n "$_dev" ]; dev="dev $_dev" 551 fi 552 if [ $p = "id" ]; then 553 eval _id=\$"$nr" 554 [ -n "$_id" ]; id="id $_id" 555 fi 556 if [ $p = "port" ]; then 557 eval _port=\$"$nr" 558 [ -n "$_port" ]; port="port $_port" 559 fi 560 561 nr=$((nr + 1)) 562 done 563 564 if [ $ip_mptcp -eq 1 ]; then 565 ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port 566 else 567 ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port 568 fi 569} 570 571pm_nl_del_endpoint() 572{ 573 local ns=$1 574 local id=$2 575 local addr=$3 576 577 if [ $ip_mptcp -eq 1 ]; then 578 ip -n $ns mptcp endpoint delete id $id $addr 579 else 580 ip netns exec $ns ./pm_nl_ctl del $id $addr 581 fi 582} 583 584pm_nl_flush_endpoint() 585{ 586 local ns=$1 587 588 if [ $ip_mptcp -eq 1 ]; then 589 ip -n $ns mptcp endpoint flush 590 else 591 ip netns exec $ns ./pm_nl_ctl flush 592 fi 593} 594 595pm_nl_show_endpoints() 596{ 597 local ns=$1 598 599 if [ $ip_mptcp -eq 1 ]; then 600 ip -n $ns mptcp endpoint show 601 else 602 ip netns exec $ns ./pm_nl_ctl dump 603 fi 604} 605 606pm_nl_change_endpoint() 607{ 608 local ns=$1 609 local id=$2 610 local flags=$3 611 612 if [ $ip_mptcp -eq 1 ]; then 613 ip -n $ns mptcp endpoint change id $id ${flags//","/" "} 614 else 615 ip netns exec $ns ./pm_nl_ctl set id $id flags $flags 616 fi 617} 618 619pm_nl_check_endpoint() 620{ 621 local line expected_line 622 local need_title=$1 623 local msg="$2" 624 local ns=$3 625 local addr=$4 626 local _flags="" 627 local flags 628 local _port 629 local port 630 local dev 631 local _id 632 local id 633 634 if [ "${need_title}" = 1 ]; then 635 printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 636 else 637 printf "%-${nr_blank}s %s" " " "${msg}" 638 fi 639 640 shift 4 641 while [ -n "$1" ]; do 642 if [ $1 = "flags" ]; then 643 _flags=$2 644 [ -n "$_flags" ]; flags="flags $_flags" 645 shift 646 elif [ $1 = "dev" ]; then 647 [ -n "$2" ]; dev="dev $1" 648 shift 649 elif [ $1 = "id" ]; then 650 _id=$2 651 [ -n "$_id" ]; id="id $_id" 652 shift 653 elif [ $1 = "port" ]; then 654 _port=$2 655 [ -n "$_port" ]; port=" port $_port" 656 shift 657 fi 658 659 shift 660 done 661 662 if [ -z "$id" ]; then 663 echo "[skip] bad test - missing endpoint id" 664 return 665 fi 666 667 if [ $ip_mptcp -eq 1 ]; then 668 line=$(ip -n $ns mptcp endpoint show $id) 669 # the dump order is: address id flags port dev 670 expected_line="$addr" 671 [ -n "$addr" ] && expected_line="$expected_line $addr" 672 expected_line="$expected_line $id" 673 [ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}" 674 [ -n "$dev" ] && expected_line="$expected_line $dev" 675 [ -n "$port" ] && expected_line="$expected_line $port" 676 else 677 line=$(ip netns exec $ns ./pm_nl_ctl get $_id) 678 # the dump order is: id flags dev address port 679 expected_line="$id" 680 [ -n "$flags" ] && expected_line="$expected_line $flags" 681 [ -n "$dev" ] && expected_line="$expected_line $dev" 682 [ -n "$addr" ] && expected_line="$expected_line $addr" 683 [ -n "$_port" ] && expected_line="$expected_line $_port" 684 fi 685 if [ "$line" = "$expected_line" ]; then 686 echo "[ ok ]" 687 else 688 echo "[fail] expected '$expected_line' found '$line'" 689 fail_test 690 fi 691} 692 693filter_tcp_from() 694{ 695 local ns="${1}" 696 local src="${2}" 697 local target="${3}" 698 699 ip netns exec "${ns}" iptables -A INPUT -s "${src}" -p tcp -j "${target}" 700} 701 702do_transfer() 703{ 704 local listener_ns="$1" 705 local connector_ns="$2" 706 local cl_proto="$3" 707 local srv_proto="$4" 708 local connect_addr="$5" 709 local test_link_fail="$6" 710 local addr_nr_ns1="$7" 711 local addr_nr_ns2="$8" 712 local speed="$9" 713 local sflags="${10}" 714 715 local port=$((10000 + TEST_COUNT - 1)) 716 local cappid 717 local userspace_pm=0 718 719 :> "$cout" 720 :> "$sout" 721 :> "$capout" 722 723 if [ $capture -eq 1 ]; then 724 local capuser 725 if [ -z $SUDO_USER ] ; then 726 capuser="" 727 else 728 capuser="-Z $SUDO_USER" 729 fi 730 731 capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}") 732 733 echo "Capturing traffic for test $TEST_COUNT into $capfile" 734 ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 & 735 cappid=$! 736 737 sleep 1 738 fi 739 740 NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 741 nstat -n 742 NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 743 nstat -n 744 745 local extra_args 746 if [ $speed = "fast" ]; then 747 extra_args="-j" 748 elif [ $speed = "slow" ]; then 749 extra_args="-r 50" 750 elif [[ $speed = "speed_"* ]]; then 751 extra_args="-r ${speed:6}" 752 fi 753 754 if [[ "${addr_nr_ns1}" = "userspace_"* ]]; then 755 userspace_pm=1 756 addr_nr_ns1=${addr_nr_ns1:10} 757 fi 758 759 local flags="subflow" 760 local extra_cl_args="" 761 local extra_srv_args="" 762 local trunc_size="" 763 if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then 764 if [ ${test_link_fail} -le 1 ]; then 765 echo "fastclose tests need test_link_fail argument" 766 fail_test 767 return 1 768 fi 769 770 # disconnect 771 trunc_size=${test_link_fail} 772 local side=${addr_nr_ns2:10} 773 774 if [ ${side} = "client" ]; then 775 extra_cl_args="-f ${test_link_fail}" 776 extra_srv_args="-f -1" 777 elif [ ${side} = "server" ]; then 778 extra_srv_args="-f ${test_link_fail}" 779 extra_cl_args="-f -1" 780 else 781 echo "wrong/unknown fastclose spec ${side}" 782 fail_test 783 return 1 784 fi 785 addr_nr_ns2=0 786 elif [[ "${addr_nr_ns2}" = "userspace_"* ]]; then 787 userspace_pm=1 788 addr_nr_ns2=${addr_nr_ns2:10} 789 elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then 790 flags="${flags},fullmesh" 791 addr_nr_ns2=${addr_nr_ns2:9} 792 fi 793 794 extra_srv_args="$extra_args $extra_srv_args" 795 if [ "$test_link_fail" -gt 1 ];then 796 timeout ${timeout_test} \ 797 ip netns exec ${listener_ns} \ 798 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 799 $extra_srv_args "::" < "$sinfail" > "$sout" & 800 else 801 timeout ${timeout_test} \ 802 ip netns exec ${listener_ns} \ 803 ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ 804 $extra_srv_args "::" < "$sin" > "$sout" & 805 fi 806 local spid=$! 807 808 wait_local_port_listen "${listener_ns}" "${port}" 809 810 extra_cl_args="$extra_args $extra_cl_args" 811 if [ "$test_link_fail" -eq 0 ];then 812 timeout ${timeout_test} \ 813 ip netns exec ${connector_ns} \ 814 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 815 $extra_cl_args $connect_addr < "$cin" > "$cout" & 816 elif [ "$test_link_fail" -eq 1 ] || [ "$test_link_fail" -eq 2 ];then 817 ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \ 818 tee "$cinsent" | \ 819 timeout ${timeout_test} \ 820 ip netns exec ${connector_ns} \ 821 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 822 $extra_cl_args $connect_addr > "$cout" & 823 else 824 tee "$cinsent" < "$cinfail" | \ 825 timeout ${timeout_test} \ 826 ip netns exec ${connector_ns} \ 827 ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ 828 $extra_cl_args $connect_addr > "$cout" & 829 fi 830 local cpid=$! 831 832 # let the mptcp subflow be established in background before 833 # do endpoint manipulation 834 if [ $addr_nr_ns1 != "0" ] || [ $addr_nr_ns2 != "0" ]; then 835 sleep 1 836 fi 837 838 if [ $addr_nr_ns1 -gt 0 ]; then 839 local counter=2 840 local add_nr_ns1=${addr_nr_ns1} 841 local id=10 842 local tk 843 while [ $add_nr_ns1 -gt 0 ]; do 844 local addr 845 if is_v6 "${connect_addr}"; then 846 addr="dead:beef:$counter::1" 847 else 848 addr="10.0.$counter.1" 849 fi 850 if [ $userspace_pm -eq 0 ]; then 851 pm_nl_add_endpoint $ns1 $addr flags signal 852 else 853 tk=$(grep "type:1," "$evts_ns1" | 854 sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q') 855 ip netns exec ${listener_ns} ./pm_nl_ctl ann $addr token $tk id $id 856 sleep 1 857 ip netns exec ${listener_ns} ./pm_nl_ctl rem token $tk id $id 858 fi 859 860 counter=$((counter + 1)) 861 add_nr_ns1=$((add_nr_ns1 - 1)) 862 id=$((id + 1)) 863 done 864 elif [ $addr_nr_ns1 -lt 0 ]; then 865 local rm_nr_ns1=$((-addr_nr_ns1)) 866 if [ $rm_nr_ns1 -lt 8 ]; then 867 local counter=0 868 local line 869 pm_nl_show_endpoints ${listener_ns} | while read -r line; do 870 # shellcheck disable=SC2206 # we do want to split per word 871 local arr=($line) 872 local nr=0 873 874 local i 875 for i in "${arr[@]}"; do 876 if [ $i = "id" ]; then 877 if [ $counter -eq $rm_nr_ns1 ]; then 878 break 879 fi 880 id=${arr[$nr+1]} 881 rm_addr=$(rm_addr_count ${connector_ns}) 882 pm_nl_del_endpoint ${listener_ns} $id 883 wait_rm_addr ${connector_ns} ${rm_addr} 884 counter=$((counter + 1)) 885 fi 886 nr=$((nr + 1)) 887 done 888 done 889 elif [ $rm_nr_ns1 -eq 8 ]; then 890 pm_nl_flush_endpoint ${listener_ns} 891 elif [ $rm_nr_ns1 -eq 9 ]; then 892 pm_nl_del_endpoint ${listener_ns} 0 ${connect_addr} 893 fi 894 fi 895 896 # if newly added endpoints must be deleted, give the background msk 897 # some time to created them 898 [ $addr_nr_ns1 -gt 0 ] && [ $addr_nr_ns2 -lt 0 ] && sleep 1 899 900 if [ $addr_nr_ns2 -gt 0 ]; then 901 local add_nr_ns2=${addr_nr_ns2} 902 local counter=3 903 local id=20 904 local tk da dp sp 905 while [ $add_nr_ns2 -gt 0 ]; do 906 local addr 907 if is_v6 "${connect_addr}"; then 908 addr="dead:beef:$counter::2" 909 else 910 addr="10.0.$counter.2" 911 fi 912 if [ $userspace_pm -eq 0 ]; then 913 pm_nl_add_endpoint $ns2 $addr flags $flags 914 else 915 tk=$(sed -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 916 da=$(sed -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evts_ns2") 917 dp=$(sed -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evts_ns2") 918 ip netns exec ${connector_ns} ./pm_nl_ctl csf lip $addr lid $id \ 919 rip $da rport $dp token $tk 920 sleep 1 921 sp=$(grep "type:10" "$evts_ns2" | 922 sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 923 ip netns exec ${connector_ns} ./pm_nl_ctl dsf lip $addr lport $sp \ 924 rip $da rport $dp token $tk 925 fi 926 counter=$((counter + 1)) 927 add_nr_ns2=$((add_nr_ns2 - 1)) 928 id=$((id + 1)) 929 done 930 elif [ $addr_nr_ns2 -lt 0 ]; then 931 local rm_nr_ns2=$((-addr_nr_ns2)) 932 if [ $rm_nr_ns2 -lt 8 ]; then 933 local counter=0 934 local line 935 pm_nl_show_endpoints ${connector_ns} | while read -r line; do 936 # shellcheck disable=SC2206 # we do want to split per word 937 local arr=($line) 938 local nr=0 939 940 local i 941 for i in "${arr[@]}"; do 942 if [ $i = "id" ]; then 943 if [ $counter -eq $rm_nr_ns2 ]; then 944 break 945 fi 946 local id rm_addr 947 # rm_addr are serialized, allow the previous one to 948 # complete 949 id=${arr[$nr+1]} 950 rm_addr=$(rm_addr_count ${listener_ns}) 951 pm_nl_del_endpoint ${connector_ns} $id 952 wait_rm_addr ${listener_ns} ${rm_addr} 953 counter=$((counter + 1)) 954 fi 955 nr=$((nr + 1)) 956 done 957 done 958 elif [ $rm_nr_ns2 -eq 8 ]; then 959 pm_nl_flush_endpoint ${connector_ns} 960 elif [ $rm_nr_ns2 -eq 9 ]; then 961 local addr 962 if is_v6 "${connect_addr}"; then 963 addr="dead:beef:1::2" 964 else 965 addr="10.0.1.2" 966 fi 967 pm_nl_del_endpoint ${connector_ns} 0 $addr 968 fi 969 fi 970 971 if [ -n "${sflags}" ]; then 972 sleep 1 973 974 local netns 975 for netns in "$ns1" "$ns2"; do 976 local line 977 pm_nl_show_endpoints $netns | while read -r line; do 978 # shellcheck disable=SC2206 # we do want to split per word 979 local arr=($line) 980 local nr=0 981 local id 982 983 local i 984 for i in "${arr[@]}"; do 985 if [ $i = "id" ]; then 986 id=${arr[$nr+1]} 987 fi 988 nr=$((nr + 1)) 989 done 990 pm_nl_change_endpoint $netns $id $sflags 991 done 992 done 993 fi 994 995 wait $cpid 996 local retc=$? 997 wait $spid 998 local rets=$? 999 1000 if [ $capture -eq 1 ]; then 1001 sleep 1 1002 kill $cappid 1003 fi 1004 1005 NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \ 1006 nstat | grep Tcp > /tmp/${listener_ns}.out 1007 NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \ 1008 nstat | grep Tcp > /tmp/${connector_ns}.out 1009 1010 if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then 1011 echo " client exit code $retc, server $rets" 1>&2 1012 echo -e "\nnetns ${listener_ns} socket stat for ${port}:" 1>&2 1013 ip netns exec ${listener_ns} ss -Menita 1>&2 -o "sport = :$port" 1014 cat /tmp/${listener_ns}.out 1015 echo -e "\nnetns ${connector_ns} socket stat for ${port}:" 1>&2 1016 ip netns exec ${connector_ns} ss -Menita 1>&2 -o "dport = :$port" 1017 cat /tmp/${connector_ns}.out 1018 1019 cat "$capout" 1020 fail_test 1021 return 1 1022 fi 1023 1024 if [ "$test_link_fail" -gt 1 ];then 1025 check_transfer $sinfail $cout "file received by client" $trunc_size 1026 else 1027 check_transfer $sin $cout "file received by client" $trunc_size 1028 fi 1029 retc=$? 1030 if [ "$test_link_fail" -eq 0 ];then 1031 check_transfer $cin $sout "file received by server" $trunc_size 1032 else 1033 check_transfer $cinsent $sout "file received by server" $trunc_size 1034 fi 1035 rets=$? 1036 1037 if [ $retc -eq 0 ] && [ $rets -eq 0 ];then 1038 cat "$capout" 1039 return 0 1040 fi 1041 1042 cat "$capout" 1043 return 1 1044} 1045 1046make_file() 1047{ 1048 local name=$1 1049 local who=$2 1050 local size=$3 1051 1052 dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null 1053 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 1054 1055 echo "Created $name (size $size KB) containing data sent by $who" 1056} 1057 1058run_tests() 1059{ 1060 local listener_ns="$1" 1061 local connector_ns="$2" 1062 local connect_addr="$3" 1063 local test_linkfail="${4:-0}" 1064 local addr_nr_ns1="${5:-0}" 1065 local addr_nr_ns2="${6:-0}" 1066 local speed="${7:-fast}" 1067 local sflags="${8:-""}" 1068 1069 local size 1070 1071 # The values above 2 are reused to make test files 1072 # with the given sizes (KB) 1073 if [ "$test_linkfail" -gt 2 ]; then 1074 size=$test_linkfail 1075 1076 if [ -z "$cinfail" ]; then 1077 cinfail=$(mktemp) 1078 fi 1079 make_file "$cinfail" "client" $size 1080 # create the input file for the failure test when 1081 # the first failure test run 1082 elif [ "$test_linkfail" -ne 0 ] && [ -z "$cinfail" ]; then 1083 # the client file must be considerably larger 1084 # of the maximum expected cwin value, or the 1085 # link utilization will be not predicable 1086 size=$((RANDOM%2)) 1087 size=$((size+1)) 1088 size=$((size*8192)) 1089 size=$((size + ( RANDOM % 8192) )) 1090 1091 cinfail=$(mktemp) 1092 make_file "$cinfail" "client" $size 1093 fi 1094 1095 if [ "$test_linkfail" -gt 2 ]; then 1096 size=$test_linkfail 1097 1098 if [ -z "$sinfail" ]; then 1099 sinfail=$(mktemp) 1100 fi 1101 make_file "$sinfail" "server" $size 1102 elif [ "$test_linkfail" -eq 2 ] && [ -z "$sinfail" ]; then 1103 size=$((RANDOM%16)) 1104 size=$((size+1)) 1105 size=$((size*2048)) 1106 1107 sinfail=$(mktemp) 1108 make_file "$sinfail" "server" $size 1109 fi 1110 1111 do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \ 1112 ${test_linkfail} ${addr_nr_ns1} ${addr_nr_ns2} ${speed} ${sflags} 1113} 1114 1115dump_stats() 1116{ 1117 echo Server ns stats 1118 ip netns exec $ns1 nstat -as | grep Tcp 1119 echo Client ns stats 1120 ip netns exec $ns2 nstat -as | grep Tcp 1121} 1122 1123chk_csum_nr() 1124{ 1125 local csum_ns1=${1:-0} 1126 local csum_ns2=${2:-0} 1127 local count 1128 local extra_msg="" 1129 local allow_multi_errors_ns1=0 1130 local allow_multi_errors_ns2=0 1131 1132 if [[ "${csum_ns1}" = "+"* ]]; then 1133 allow_multi_errors_ns1=1 1134 csum_ns1=${csum_ns1:1} 1135 fi 1136 if [[ "${csum_ns2}" = "+"* ]]; then 1137 allow_multi_errors_ns2=1 1138 csum_ns2=${csum_ns2:1} 1139 fi 1140 1141 printf "%-${nr_blank}s %s" " " "sum" 1142 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1143 [ -z "$count" ] && count=0 1144 if [ "$count" != "$csum_ns1" ]; then 1145 extra_msg="$extra_msg ns1=$count" 1146 fi 1147 if { [ "$count" != $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 0 ]; } || 1148 { [ "$count" -lt $csum_ns1 ] && [ $allow_multi_errors_ns1 -eq 1 ]; }; then 1149 echo "[fail] got $count data checksum error[s] expected $csum_ns1" 1150 fail_test 1151 else 1152 echo -n "[ ok ]" 1153 fi 1154 echo -n " - csum " 1155 count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtDataCsumErr | awk '{print $2}') 1156 [ -z "$count" ] && count=0 1157 if [ "$count" != "$csum_ns2" ]; then 1158 extra_msg="$extra_msg ns2=$count" 1159 fi 1160 if { [ "$count" != $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 0 ]; } || 1161 { [ "$count" -lt $csum_ns2 ] && [ $allow_multi_errors_ns2 -eq 1 ]; }; then 1162 echo "[fail] got $count data checksum error[s] expected $csum_ns2" 1163 fail_test 1164 else 1165 echo -n "[ ok ]" 1166 fi 1167 1168 echo "$extra_msg" 1169} 1170 1171chk_fail_nr() 1172{ 1173 local fail_tx=$1 1174 local fail_rx=$2 1175 local ns_invert=${3:-""} 1176 local count 1177 local ns_tx=$ns1 1178 local ns_rx=$ns2 1179 local extra_msg="" 1180 local allow_tx_lost=0 1181 local allow_rx_lost=0 1182 1183 if [[ $ns_invert = "invert" ]]; then 1184 ns_tx=$ns2 1185 ns_rx=$ns1 1186 extra_msg=" invert" 1187 fi 1188 1189 if [[ "${fail_tx}" = "-"* ]]; then 1190 allow_tx_lost=1 1191 fail_tx=${fail_tx:1} 1192 fi 1193 if [[ "${fail_rx}" = "-"* ]]; then 1194 allow_rx_lost=1 1195 fail_rx=${fail_rx:1} 1196 fi 1197 1198 printf "%-${nr_blank}s %s" " " "ftx" 1199 count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFailTx | awk '{print $2}') 1200 [ -z "$count" ] && count=0 1201 if [ "$count" != "$fail_tx" ]; then 1202 extra_msg="$extra_msg,tx=$count" 1203 fi 1204 if { [ "$count" != "$fail_tx" ] && [ $allow_tx_lost -eq 0 ]; } || 1205 { [ "$count" -gt "$fail_tx" ] && [ $allow_tx_lost -eq 1 ]; }; then 1206 echo "[fail] got $count MP_FAIL[s] TX expected $fail_tx" 1207 fail_test 1208 else 1209 echo -n "[ ok ]" 1210 fi 1211 1212 echo -n " - failrx" 1213 count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFailRx | awk '{print $2}') 1214 [ -z "$count" ] && count=0 1215 if [ "$count" != "$fail_rx" ]; then 1216 extra_msg="$extra_msg,rx=$count" 1217 fi 1218 if { [ "$count" != "$fail_rx" ] && [ $allow_rx_lost -eq 0 ]; } || 1219 { [ "$count" -gt "$fail_rx" ] && [ $allow_rx_lost -eq 1 ]; }; then 1220 echo "[fail] got $count MP_FAIL[s] RX expected $fail_rx" 1221 fail_test 1222 else 1223 echo -n "[ ok ]" 1224 fi 1225 1226 echo "$extra_msg" 1227} 1228 1229chk_fclose_nr() 1230{ 1231 local fclose_tx=$1 1232 local fclose_rx=$2 1233 local ns_invert=$3 1234 local count 1235 local ns_tx=$ns2 1236 local ns_rx=$ns1 1237 local extra_msg=" " 1238 1239 if [[ $ns_invert = "invert" ]]; then 1240 ns_tx=$ns1 1241 ns_rx=$ns2 1242 extra_msg=${extra_msg}"invert" 1243 fi 1244 1245 printf "%-${nr_blank}s %s" " " "ctx" 1246 count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPFastcloseTx | awk '{print $2}') 1247 [ -z "$count" ] && count=0 1248 [ "$count" != "$fclose_tx" ] && extra_msg="$extra_msg,tx=$count" 1249 if [ "$count" != "$fclose_tx" ]; then 1250 echo "[fail] got $count MP_FASTCLOSE[s] TX expected $fclose_tx" 1251 fail_test 1252 else 1253 echo -n "[ ok ]" 1254 fi 1255 1256 echo -n " - fclzrx" 1257 count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPFastcloseRx | awk '{print $2}') 1258 [ -z "$count" ] && count=0 1259 [ "$count" != "$fclose_rx" ] && extra_msg="$extra_msg,rx=$count" 1260 if [ "$count" != "$fclose_rx" ]; then 1261 echo "[fail] got $count MP_FASTCLOSE[s] RX expected $fclose_rx" 1262 fail_test 1263 else 1264 echo -n "[ ok ]" 1265 fi 1266 1267 echo "$extra_msg" 1268} 1269 1270chk_rst_nr() 1271{ 1272 local rst_tx=$1 1273 local rst_rx=$2 1274 local ns_invert=${3:-""} 1275 local count 1276 local ns_tx=$ns1 1277 local ns_rx=$ns2 1278 local extra_msg="" 1279 1280 if [[ $ns_invert = "invert" ]]; then 1281 ns_tx=$ns2 1282 ns_rx=$ns1 1283 extra_msg=" invert" 1284 fi 1285 1286 printf "%-${nr_blank}s %s" " " "rtx" 1287 count=$(ip netns exec $ns_tx nstat -as | grep MPTcpExtMPRstTx | awk '{print $2}') 1288 [ -z "$count" ] && count=0 1289 if [ $count -lt $rst_tx ]; then 1290 echo "[fail] got $count MP_RST[s] TX expected $rst_tx" 1291 fail_test 1292 else 1293 echo -n "[ ok ]" 1294 fi 1295 1296 echo -n " - rstrx " 1297 count=$(ip netns exec $ns_rx nstat -as | grep MPTcpExtMPRstRx | awk '{print $2}') 1298 [ -z "$count" ] && count=0 1299 if [ "$count" -lt "$rst_rx" ]; then 1300 echo "[fail] got $count MP_RST[s] RX expected $rst_rx" 1301 fail_test 1302 else 1303 echo -n "[ ok ]" 1304 fi 1305 1306 echo "$extra_msg" 1307} 1308 1309chk_infi_nr() 1310{ 1311 local infi_tx=$1 1312 local infi_rx=$2 1313 local count 1314 1315 printf "%-${nr_blank}s %s" " " "itx" 1316 count=$(ip netns exec $ns2 nstat -as | grep InfiniteMapTx | awk '{print $2}') 1317 [ -z "$count" ] && count=0 1318 if [ "$count" != "$infi_tx" ]; then 1319 echo "[fail] got $count infinite map[s] TX expected $infi_tx" 1320 fail_test 1321 else 1322 echo -n "[ ok ]" 1323 fi 1324 1325 echo -n " - infirx" 1326 count=$(ip netns exec $ns1 nstat -as | grep InfiniteMapRx | awk '{print $2}') 1327 [ -z "$count" ] && count=0 1328 if [ "$count" != "$infi_rx" ]; then 1329 echo "[fail] got $count infinite map[s] RX expected $infi_rx" 1330 fail_test 1331 else 1332 echo "[ ok ]" 1333 fi 1334} 1335 1336chk_join_nr() 1337{ 1338 local syn_nr=$1 1339 local syn_ack_nr=$2 1340 local ack_nr=$3 1341 local csum_ns1=${4:-0} 1342 local csum_ns2=${5:-0} 1343 local fail_nr=${6:-0} 1344 local rst_nr=${7:-0} 1345 local infi_nr=${8:-0} 1346 local corrupted_pkts=${9:-0} 1347 local count 1348 local with_cookie 1349 local title="${TEST_NAME}" 1350 1351 if [ "${corrupted_pkts}" -gt 0 ]; then 1352 title+=": ${corrupted_pkts} corrupted pkts" 1353 fi 1354 1355 printf "%03u %-36s %s" "${TEST_COUNT}" "${title}" "syn" 1356 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinSynRx | awk '{print $2}') 1357 [ -z "$count" ] && count=0 1358 if [ "$count" != "$syn_nr" ]; then 1359 echo "[fail] got $count JOIN[s] syn expected $syn_nr" 1360 fail_test 1361 else 1362 echo -n "[ ok ]" 1363 fi 1364 1365 echo -n " - synack" 1366 with_cookie=$(ip netns exec $ns2 sysctl -n net.ipv4.tcp_syncookies) 1367 count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinSynAckRx | awk '{print $2}') 1368 [ -z "$count" ] && count=0 1369 if [ "$count" != "$syn_ack_nr" ]; then 1370 # simult connections exceeding the limit with cookie enabled could go up to 1371 # synack validation as the conn limit can be enforced reliably only after 1372 # the subflow creation 1373 if [ "$with_cookie" = 2 ] && [ "$count" -gt "$syn_ack_nr" ] && [ "$count" -le "$syn_nr" ]; then 1374 echo -n "[ ok ]" 1375 else 1376 echo "[fail] got $count JOIN[s] synack expected $syn_ack_nr" 1377 fail_test 1378 fi 1379 else 1380 echo -n "[ ok ]" 1381 fi 1382 1383 echo -n " - ack" 1384 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinAckRx | awk '{print $2}') 1385 [ -z "$count" ] && count=0 1386 if [ "$count" != "$ack_nr" ]; then 1387 echo "[fail] got $count JOIN[s] ack expected $ack_nr" 1388 fail_test 1389 else 1390 echo "[ ok ]" 1391 fi 1392 if [ $validate_checksum -eq 1 ]; then 1393 chk_csum_nr $csum_ns1 $csum_ns2 1394 chk_fail_nr $fail_nr $fail_nr 1395 chk_rst_nr $rst_nr $rst_nr 1396 chk_infi_nr $infi_nr $infi_nr 1397 fi 1398} 1399 1400# a negative value for 'stale_max' means no upper bound: 1401# for bidirectional transfer, if one peer sleep for a while 1402# - as these tests do - we can have a quite high number of 1403# stale/recover conversions, proportional to 1404# sleep duration/ MPTCP-level RTX interval. 1405chk_stale_nr() 1406{ 1407 local ns=$1 1408 local stale_min=$2 1409 local stale_max=$3 1410 local stale_delta=$4 1411 local dump_stats 1412 local stale_nr 1413 local recover_nr 1414 1415 printf "%-${nr_blank}s %-18s" " " "stale" 1416 stale_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowStale | awk '{print $2}') 1417 [ -z "$stale_nr" ] && stale_nr=0 1418 recover_nr=$(ip netns exec $ns nstat -as | grep MPTcpExtSubflowRecover | awk '{print $2}') 1419 [ -z "$recover_nr" ] && recover_nr=0 1420 1421 if [ $stale_nr -lt $stale_min ] || 1422 { [ $stale_max -gt 0 ] && [ $stale_nr -gt $stale_max ]; } || 1423 [ $((stale_nr - recover_nr)) -ne $stale_delta ]; then 1424 echo "[fail] got $stale_nr stale[s] $recover_nr recover[s], " \ 1425 " expected stale in range [$stale_min..$stale_max]," \ 1426 " stale-recover delta $stale_delta " 1427 fail_test 1428 dump_stats=1 1429 else 1430 echo "[ ok ]" 1431 fi 1432 1433 if [ "${dump_stats}" = 1 ]; then 1434 echo $ns stats 1435 ip netns exec $ns ip -s link show 1436 ip netns exec $ns nstat -as | grep MPTcp 1437 fi 1438} 1439 1440chk_add_nr() 1441{ 1442 local add_nr=$1 1443 local echo_nr=$2 1444 local port_nr=${3:-0} 1445 local syn_nr=${4:-$port_nr} 1446 local syn_ack_nr=${5:-$port_nr} 1447 local ack_nr=${6:-$port_nr} 1448 local mis_syn_nr=${7:-0} 1449 local mis_ack_nr=${8:-0} 1450 local count 1451 local timeout 1452 1453 timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1454 1455 printf "%-${nr_blank}s %s" " " "add" 1456 count=$(ip netns exec $ns2 nstat -as MPTcpExtAddAddr | grep MPTcpExtAddAddr | awk '{print $2}') 1457 [ -z "$count" ] && count=0 1458 1459 # if the test configured a short timeout tolerate greater then expected 1460 # add addrs options, due to retransmissions 1461 if [ "$count" != "$add_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_nr" ]; }; then 1462 echo "[fail] got $count ADD_ADDR[s] expected $add_nr" 1463 fail_test 1464 else 1465 echo -n "[ ok ]" 1466 fi 1467 1468 echo -n " - echo " 1469 count=$(ip netns exec $ns1 nstat -as MPTcpExtEchoAdd | grep MPTcpExtEchoAdd | awk '{print $2}') 1470 [ -z "$count" ] && count=0 1471 if [ "$count" != "$echo_nr" ]; then 1472 echo "[fail] got $count ADD_ADDR echo[s] expected $echo_nr" 1473 fail_test 1474 else 1475 echo -n "[ ok ]" 1476 fi 1477 1478 if [ $port_nr -gt 0 ]; then 1479 echo -n " - pt " 1480 count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtPortAdd | awk '{print $2}') 1481 [ -z "$count" ] && count=0 1482 if [ "$count" != "$port_nr" ]; then 1483 echo "[fail] got $count ADD_ADDR[s] with a port-number expected $port_nr" 1484 fail_test 1485 else 1486 echo "[ ok ]" 1487 fi 1488 1489 printf "%-${nr_blank}s %s" " " "syn" 1490 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortSynRx | 1491 awk '{print $2}') 1492 [ -z "$count" ] && count=0 1493 if [ "$count" != "$syn_nr" ]; then 1494 echo "[fail] got $count JOIN[s] syn with a different \ 1495 port-number expected $syn_nr" 1496 fail_test 1497 else 1498 echo -n "[ ok ]" 1499 fi 1500 1501 echo -n " - synack" 1502 count=$(ip netns exec $ns2 nstat -as | grep MPTcpExtMPJoinPortSynAckRx | 1503 awk '{print $2}') 1504 [ -z "$count" ] && count=0 1505 if [ "$count" != "$syn_ack_nr" ]; then 1506 echo "[fail] got $count JOIN[s] synack with a different \ 1507 port-number expected $syn_ack_nr" 1508 fail_test 1509 else 1510 echo -n "[ ok ]" 1511 fi 1512 1513 echo -n " - ack" 1514 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPJoinPortAckRx | 1515 awk '{print $2}') 1516 [ -z "$count" ] && count=0 1517 if [ "$count" != "$ack_nr" ]; then 1518 echo "[fail] got $count JOIN[s] ack with a different \ 1519 port-number expected $ack_nr" 1520 fail_test 1521 else 1522 echo "[ ok ]" 1523 fi 1524 1525 printf "%-${nr_blank}s %s" " " "syn" 1526 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortSynRx | 1527 awk '{print $2}') 1528 [ -z "$count" ] && count=0 1529 if [ "$count" != "$mis_syn_nr" ]; then 1530 echo "[fail] got $count JOIN[s] syn with a mismatched \ 1531 port-number expected $mis_syn_nr" 1532 fail_test 1533 else 1534 echo -n "[ ok ]" 1535 fi 1536 1537 echo -n " - ack " 1538 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMismatchPortAckRx | 1539 awk '{print $2}') 1540 [ -z "$count" ] && count=0 1541 if [ "$count" != "$mis_ack_nr" ]; then 1542 echo "[fail] got $count JOIN[s] ack with a mismatched \ 1543 port-number expected $mis_ack_nr" 1544 fail_test 1545 else 1546 echo "[ ok ]" 1547 fi 1548 else 1549 echo "" 1550 fi 1551} 1552 1553chk_add_tx_nr() 1554{ 1555 local add_tx_nr=$1 1556 local echo_tx_nr=$2 1557 local timeout 1558 local count 1559 1560 timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout) 1561 1562 printf "%-${nr_blank}s %s" " " "add TX" 1563 count=$(ip netns exec $ns1 nstat -as MPTcpExtAddAddrTx | grep MPTcpExtAddAddrTx | awk '{print $2}') 1564 [ -z "$count" ] && count=0 1565 1566 # if the test configured a short timeout tolerate greater then expected 1567 # add addrs options, due to retransmissions 1568 if [ "$count" != "$add_tx_nr" ] && { [ "$timeout" -gt 1 ] || [ "$count" -lt "$add_tx_nr" ]; }; then 1569 echo "[fail] got $count ADD_ADDR[s] TX, expected $add_tx_nr" 1570 fail_test 1571 else 1572 echo -n "[ ok ]" 1573 fi 1574 1575 echo -n " - echo TX " 1576 count=$(ip netns exec $ns2 nstat -as MPTcpExtEchoAddTx | grep MPTcpExtEchoAddTx | awk '{print $2}') 1577 [ -z "$count" ] && count=0 1578 if [ "$count" != "$echo_tx_nr" ]; then 1579 echo "[fail] got $count ADD_ADDR echo[s] TX, expected $echo_tx_nr" 1580 fail_test 1581 else 1582 echo "[ ok ]" 1583 fi 1584} 1585 1586chk_rm_nr() 1587{ 1588 local rm_addr_nr=$1 1589 local rm_subflow_nr=$2 1590 local invert 1591 local simult 1592 local count 1593 local addr_ns=$ns1 1594 local subflow_ns=$ns2 1595 local extra_msg="" 1596 1597 shift 2 1598 while [ -n "$1" ]; do 1599 [ "$1" = "invert" ] && invert=true 1600 [ "$1" = "simult" ] && simult=true 1601 shift 1602 done 1603 1604 if [ -z $invert ]; then 1605 addr_ns=$ns1 1606 subflow_ns=$ns2 1607 elif [ $invert = "true" ]; then 1608 addr_ns=$ns2 1609 subflow_ns=$ns1 1610 extra_msg=" invert" 1611 fi 1612 1613 printf "%-${nr_blank}s %s" " " "rm " 1614 count=$(ip netns exec $addr_ns nstat -as MPTcpExtRmAddr | grep MPTcpExtRmAddr | awk '{print $2}') 1615 [ -z "$count" ] && count=0 1616 if [ "$count" != "$rm_addr_nr" ]; then 1617 echo "[fail] got $count RM_ADDR[s] expected $rm_addr_nr" 1618 fail_test 1619 else 1620 echo -n "[ ok ]" 1621 fi 1622 1623 echo -n " - rmsf " 1624 count=$(ip netns exec $subflow_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 1625 [ -z "$count" ] && count=0 1626 if [ -n "$simult" ]; then 1627 local cnt suffix 1628 1629 cnt=$(ip netns exec $addr_ns nstat -as | grep MPTcpExtRmSubflow | awk '{print $2}') 1630 1631 # in case of simult flush, the subflow removal count on each side is 1632 # unreliable 1633 [ -z "$cnt" ] && cnt=0 1634 count=$((count + cnt)) 1635 [ "$count" != "$rm_subflow_nr" ] && suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1636 if [ $count -ge "$rm_subflow_nr" ] && \ 1637 [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then 1638 echo "[ ok ] $suffix" 1639 else 1640 echo "[fail] got $count RM_SUBFLOW[s] expected in range [$rm_subflow_nr:$((rm_subflow_nr*2))]" 1641 fail_test 1642 fi 1643 return 1644 fi 1645 if [ "$count" != "$rm_subflow_nr" ]; then 1646 echo "[fail] got $count RM_SUBFLOW[s] expected $rm_subflow_nr" 1647 fail_test 1648 else 1649 echo -n "[ ok ]" 1650 fi 1651 1652 echo "$extra_msg" 1653} 1654 1655chk_rm_tx_nr() 1656{ 1657 local rm_addr_tx_nr=$1 1658 1659 printf "%-${nr_blank}s %s" " " "rm TX " 1660 count=$(ip netns exec $ns2 nstat -as MPTcpExtRmAddrTx | grep MPTcpExtRmAddrTx | awk '{print $2}') 1661 [ -z "$count" ] && count=0 1662 if [ "$count" != "$rm_addr_tx_nr" ]; then 1663 echo "[fail] got $count RM_ADDR[s] expected $rm_addr_tx_nr" 1664 fail_test 1665 else 1666 echo -n "[ ok ]" 1667 fi 1668 1669 echo "$extra_msg" 1670} 1671 1672chk_prio_nr() 1673{ 1674 local mp_prio_nr_tx=$1 1675 local mp_prio_nr_rx=$2 1676 local count 1677 1678 printf "%-${nr_blank}s %s" " " "ptx" 1679 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}') 1680 [ -z "$count" ] && count=0 1681 if [ "$count" != "$mp_prio_nr_tx" ]; then 1682 echo "[fail] got $count MP_PRIO[s] TX expected $mp_prio_nr_tx" 1683 fail_test 1684 else 1685 echo -n "[ ok ]" 1686 fi 1687 1688 echo -n " - prx " 1689 count=$(ip netns exec $ns1 nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}') 1690 [ -z "$count" ] && count=0 1691 if [ "$count" != "$mp_prio_nr_rx" ]; then 1692 echo "[fail] got $count MP_PRIO[s] RX expected $mp_prio_nr_rx" 1693 fail_test 1694 else 1695 echo "[ ok ]" 1696 fi 1697} 1698 1699chk_subflow_nr() 1700{ 1701 local need_title="$1" 1702 local msg="$2" 1703 local subflow_nr=$3 1704 local cnt1 1705 local cnt2 1706 local dump_stats 1707 1708 if [ -n "${need_title}" ]; then 1709 printf "%03u %-36s %s" "${TEST_COUNT}" "${TEST_NAME}" "${msg}" 1710 else 1711 printf "%-${nr_blank}s %s" " " "${msg}" 1712 fi 1713 1714 cnt1=$(ss -N $ns1 -tOni | grep -c token) 1715 cnt2=$(ss -N $ns2 -tOni | grep -c token) 1716 if [ "$cnt1" != "$subflow_nr" ] || [ "$cnt2" != "$subflow_nr" ]; then 1717 echo "[fail] got $cnt1:$cnt2 subflows expected $subflow_nr" 1718 fail_test 1719 dump_stats=1 1720 else 1721 echo "[ ok ]" 1722 fi 1723 1724 if [ "${dump_stats}" = 1 ]; then 1725 ss -N $ns1 -tOni 1726 ss -N $ns1 -tOni | grep token 1727 ip -n $ns1 mptcp endpoint 1728 fi 1729} 1730 1731chk_mptcp_info() 1732{ 1733 local nr_info=$1 1734 local info 1735 local cnt1 1736 local cnt2 1737 local dump_stats 1738 1739 if [[ $nr_info = "subflows_"* ]]; then 1740 info="subflows" 1741 nr_info=${nr_info:9} 1742 else 1743 echo "[fail] unsupported argument: $nr_info" 1744 fail_test 1745 return 1 1746 fi 1747 1748 printf "%-${nr_blank}s %-30s" " " "mptcp_info $info=$nr_info" 1749 1750 cnt1=$(ss -N $ns1 -inmHM | grep "$info:" | 1751 sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 1752 [ -z "$cnt1" ] && cnt1=0 1753 cnt2=$(ss -N $ns2 -inmHM | grep "$info:" | 1754 sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q') 1755 [ -z "$cnt2" ] && cnt2=0 1756 if [ "$cnt1" != "$nr_info" ] || [ "$cnt2" != "$nr_info" ]; then 1757 echo "[fail] got $cnt1:$cnt2 $info expected $nr_info" 1758 fail_test 1759 dump_stats=1 1760 else 1761 echo "[ ok ]" 1762 fi 1763 1764 if [ "$dump_stats" = 1 ]; then 1765 ss -N $ns1 -inmHM 1766 ss -N $ns2 -inmHM 1767 fi 1768} 1769 1770chk_link_usage() 1771{ 1772 local ns=$1 1773 local link=$2 1774 local out=$3 1775 local expected_rate=$4 1776 1777 local tx_link tx_total 1778 tx_link=$(ip netns exec $ns cat /sys/class/net/$link/statistics/tx_bytes) 1779 tx_total=$(stat --format=%s $out) 1780 local tx_rate=$((tx_link * 100 / tx_total)) 1781 local tolerance=5 1782 1783 printf "%-${nr_blank}s %-18s" " " "link usage" 1784 if [ $tx_rate -lt $((expected_rate - tolerance)) ] || \ 1785 [ $tx_rate -gt $((expected_rate + tolerance)) ]; then 1786 echo "[fail] got $tx_rate% usage, expected $expected_rate%" 1787 fail_test 1788 else 1789 echo "[ ok ]" 1790 fi 1791} 1792 1793wait_attempt_fail() 1794{ 1795 local timeout_ms=$((timeout_poll * 1000)) 1796 local time=0 1797 local ns=$1 1798 1799 while [ $time -lt $timeout_ms ]; do 1800 local cnt 1801 1802 cnt=$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFails | awk '{print $2}') 1803 1804 [ "$cnt" = 1 ] && return 1 1805 time=$((time + 100)) 1806 sleep 0.1 1807 done 1808 return 1 1809} 1810 1811set_userspace_pm() 1812{ 1813 local ns=$1 1814 1815 ip netns exec $ns sysctl -q net.mptcp.pm_type=1 1816} 1817 1818subflows_tests() 1819{ 1820 if reset "no JOIN"; then 1821 run_tests $ns1 $ns2 10.0.1.1 1822 chk_join_nr 0 0 0 1823 fi 1824 1825 # subflow limited by client 1826 if reset "single subflow, limited by client"; then 1827 pm_nl_set_limits $ns1 0 0 1828 pm_nl_set_limits $ns2 0 0 1829 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1830 run_tests $ns1 $ns2 10.0.1.1 1831 chk_join_nr 0 0 0 1832 fi 1833 1834 # subflow limited by server 1835 if reset "single subflow, limited by server"; then 1836 pm_nl_set_limits $ns1 0 0 1837 pm_nl_set_limits $ns2 0 1 1838 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1839 run_tests $ns1 $ns2 10.0.1.1 1840 chk_join_nr 1 1 0 1841 fi 1842 1843 # subflow 1844 if reset "single subflow"; then 1845 pm_nl_set_limits $ns1 0 1 1846 pm_nl_set_limits $ns2 0 1 1847 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1848 run_tests $ns1 $ns2 10.0.1.1 1849 chk_join_nr 1 1 1 1850 fi 1851 1852 # multiple subflows 1853 if reset "multiple subflows"; then 1854 pm_nl_set_limits $ns1 0 2 1855 pm_nl_set_limits $ns2 0 2 1856 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1857 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1858 run_tests $ns1 $ns2 10.0.1.1 1859 chk_join_nr 2 2 2 1860 fi 1861 1862 # multiple subflows limited by server 1863 if reset "multiple subflows, limited by server"; then 1864 pm_nl_set_limits $ns1 0 1 1865 pm_nl_set_limits $ns2 0 2 1866 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1867 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1868 run_tests $ns1 $ns2 10.0.1.1 1869 chk_join_nr 2 2 1 1870 fi 1871 1872 # single subflow, dev 1873 if reset "single subflow, dev"; then 1874 pm_nl_set_limits $ns1 0 1 1875 pm_nl_set_limits $ns2 0 1 1876 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow dev ns2eth3 1877 run_tests $ns1 $ns2 10.0.1.1 1878 chk_join_nr 1 1 1 1879 fi 1880} 1881 1882subflows_error_tests() 1883{ 1884 # If a single subflow is configured, and matches the MPC src 1885 # address, no additional subflow should be created 1886 if reset "no MPC reuse with single endpoint"; then 1887 pm_nl_set_limits $ns1 0 1 1888 pm_nl_set_limits $ns2 0 1 1889 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 1890 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1891 chk_join_nr 0 0 0 1892 fi 1893 1894 # multiple subflows, with subflow creation error 1895 if reset "multi subflows, with failing subflow"; then 1896 pm_nl_set_limits $ns1 0 2 1897 pm_nl_set_limits $ns2 0 2 1898 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1899 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1900 filter_tcp_from $ns1 10.0.3.2 REJECT 1901 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1902 chk_join_nr 1 1 1 1903 fi 1904 1905 # multiple subflows, with subflow timeout on MPJ 1906 if reset "multi subflows, with subflow timeout"; then 1907 pm_nl_set_limits $ns1 0 2 1908 pm_nl_set_limits $ns2 0 2 1909 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1910 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1911 filter_tcp_from $ns1 10.0.3.2 DROP 1912 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 1913 chk_join_nr 1 1 1 1914 fi 1915 1916 # multiple subflows, check that the endpoint corresponding to 1917 # closed subflow (due to reset) is not reused if additional 1918 # subflows are added later 1919 if reset "multi subflows, fair usage on close"; then 1920 pm_nl_set_limits $ns1 0 1 1921 pm_nl_set_limits $ns2 0 1 1922 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1923 filter_tcp_from $ns1 10.0.3.2 REJECT 1924 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow & 1925 1926 # mpj subflow will be in TW after the reset 1927 wait_attempt_fail $ns2 1928 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 1929 wait 1930 1931 # additional subflow could be created only if the PM select 1932 # the later endpoint, skipping the already used one 1933 chk_join_nr 1 1 1 1934 fi 1935} 1936 1937signal_address_tests() 1938{ 1939 # add_address, unused 1940 if reset "unused signal address"; then 1941 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1942 run_tests $ns1 $ns2 10.0.1.1 1943 chk_join_nr 0 0 0 1944 chk_add_tx_nr 1 1 1945 chk_add_nr 1 1 1946 fi 1947 1948 # accept and use add_addr 1949 if reset "signal address"; then 1950 pm_nl_set_limits $ns1 0 1 1951 pm_nl_set_limits $ns2 1 1 1952 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1953 run_tests $ns1 $ns2 10.0.1.1 1954 chk_join_nr 1 1 1 1955 chk_add_nr 1 1 1956 fi 1957 1958 # accept and use add_addr with an additional subflow 1959 # note: signal address in server ns and local addresses in client ns must 1960 # belong to different subnets or one of the listed local address could be 1961 # used for 'add_addr' subflow 1962 if reset "subflow and signal"; then 1963 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1964 pm_nl_set_limits $ns1 0 2 1965 pm_nl_set_limits $ns2 1 2 1966 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1967 run_tests $ns1 $ns2 10.0.1.1 1968 chk_join_nr 2 2 2 1969 chk_add_nr 1 1 1970 fi 1971 1972 # accept and use add_addr with additional subflows 1973 if reset "multiple subflows and signal"; then 1974 pm_nl_set_limits $ns1 0 3 1975 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1976 pm_nl_set_limits $ns2 1 3 1977 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 1978 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 1979 run_tests $ns1 $ns2 10.0.1.1 1980 chk_join_nr 3 3 3 1981 chk_add_nr 1 1 1982 fi 1983 1984 # signal addresses 1985 if reset "signal addresses"; then 1986 pm_nl_set_limits $ns1 3 3 1987 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 1988 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 1989 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 1990 pm_nl_set_limits $ns2 3 3 1991 run_tests $ns1 $ns2 10.0.1.1 1992 chk_join_nr 3 3 3 1993 chk_add_nr 3 3 1994 fi 1995 1996 # signal invalid addresses 1997 if reset "signal invalid addresses"; then 1998 pm_nl_set_limits $ns1 3 3 1999 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2000 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2001 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 2002 pm_nl_set_limits $ns2 3 3 2003 run_tests $ns1 $ns2 10.0.1.1 2004 chk_join_nr 1 1 1 2005 chk_add_nr 3 3 2006 fi 2007 2008 # signal addresses race test 2009 if reset "signal addresses race test"; then 2010 pm_nl_set_limits $ns1 4 4 2011 pm_nl_set_limits $ns2 4 4 2012 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2013 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2014 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2015 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2016 pm_nl_add_endpoint $ns2 10.0.1.2 flags signal 2017 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 2018 pm_nl_add_endpoint $ns2 10.0.3.2 flags signal 2019 pm_nl_add_endpoint $ns2 10.0.4.2 flags signal 2020 2021 # the peer could possibly miss some addr notification, allow retransmission 2022 ip netns exec $ns1 sysctl -q net.mptcp.add_addr_timeout=1 2023 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2024 chk_join_nr 3 3 3 2025 2026 # the server will not signal the address terminating 2027 # the MPC subflow 2028 chk_add_nr 3 3 2029 fi 2030} 2031 2032link_failure_tests() 2033{ 2034 # accept and use add_addr with additional subflows and link loss 2035 if reset "multiple flows, signal, link failure"; then 2036 # without any b/w limit each veth could spool the packets and get 2037 # them acked at xmit time, so that the corresponding subflow will 2038 # have almost always no outstanding pkts, the scheduler will pick 2039 # always the first subflow and we will have hard time testing 2040 # active backup and link switch-over. 2041 # Let's set some arbitrary (low) virtual link limits. 2042 init_shapers 2043 pm_nl_set_limits $ns1 0 3 2044 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2045 pm_nl_set_limits $ns2 1 3 2046 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 2047 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 2048 run_tests $ns1 $ns2 10.0.1.1 1 2049 chk_join_nr 3 3 3 2050 chk_add_nr 1 1 2051 chk_stale_nr $ns2 1 5 1 2052 fi 2053 2054 # accept and use add_addr with additional subflows and link loss 2055 # for bidirectional transfer 2056 if reset "multi flows, signal, bidi, link fail"; then 2057 init_shapers 2058 pm_nl_set_limits $ns1 0 3 2059 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2060 pm_nl_set_limits $ns2 1 3 2061 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow 2062 pm_nl_add_endpoint $ns2 10.0.4.2 dev ns2eth4 flags subflow 2063 run_tests $ns1 $ns2 10.0.1.1 2 2064 chk_join_nr 3 3 3 2065 chk_add_nr 1 1 2066 chk_stale_nr $ns2 1 -1 1 2067 fi 2068 2069 # 2 subflows plus 1 backup subflow with a lossy link, backup 2070 # will never be used 2071 if reset "backup subflow unused, link failure"; then 2072 init_shapers 2073 pm_nl_set_limits $ns1 0 2 2074 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2075 pm_nl_set_limits $ns2 1 2 2076 FAILING_LINKS="1" 2077 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2078 run_tests $ns1 $ns2 10.0.1.1 1 2079 chk_join_nr 2 2 2 2080 chk_add_nr 1 1 2081 chk_link_usage $ns2 ns2eth3 $cinsent 0 2082 fi 2083 2084 # 2 lossy links after half transfer, backup will get half of 2085 # the traffic 2086 if reset "backup flow used, multi links fail"; then 2087 init_shapers 2088 pm_nl_set_limits $ns1 0 2 2089 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2090 pm_nl_set_limits $ns2 1 2 2091 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2092 FAILING_LINKS="1 2" 2093 run_tests $ns1 $ns2 10.0.1.1 1 2094 chk_join_nr 2 2 2 2095 chk_add_nr 1 1 2096 chk_stale_nr $ns2 2 4 2 2097 chk_link_usage $ns2 ns2eth3 $cinsent 50 2098 fi 2099 2100 # use a backup subflow with the first subflow on a lossy link 2101 # for bidirectional transfer 2102 if reset "backup flow used, bidi, link failure"; then 2103 init_shapers 2104 pm_nl_set_limits $ns1 0 2 2105 pm_nl_add_endpoint $ns1 10.0.2.1 dev ns1eth2 flags signal 2106 pm_nl_set_limits $ns2 1 3 2107 pm_nl_add_endpoint $ns2 10.0.3.2 dev ns2eth3 flags subflow,backup 2108 FAILING_LINKS="1 2" 2109 run_tests $ns1 $ns2 10.0.1.1 2 2110 chk_join_nr 2 2 2 2111 chk_add_nr 1 1 2112 chk_stale_nr $ns2 1 -1 2 2113 chk_link_usage $ns2 ns2eth3 $cinsent 50 2114 fi 2115} 2116 2117add_addr_timeout_tests() 2118{ 2119 # add_addr timeout 2120 if reset_with_add_addr_timeout "signal address, ADD_ADDR timeout"; then 2121 pm_nl_set_limits $ns1 0 1 2122 pm_nl_set_limits $ns2 1 1 2123 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2124 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2125 chk_join_nr 1 1 1 2126 chk_add_tx_nr 4 4 2127 chk_add_nr 4 0 2128 fi 2129 2130 # add_addr timeout IPv6 2131 if reset_with_add_addr_timeout "signal address, ADD_ADDR6 timeout" 6; then 2132 pm_nl_set_limits $ns1 0 1 2133 pm_nl_set_limits $ns2 1 1 2134 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2135 run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2136 chk_join_nr 1 1 1 2137 chk_add_nr 4 0 2138 fi 2139 2140 # signal addresses timeout 2141 if reset_with_add_addr_timeout "signal addresses, ADD_ADDR timeout"; then 2142 pm_nl_set_limits $ns1 2 2 2143 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2144 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2145 pm_nl_set_limits $ns2 2 2 2146 run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2147 chk_join_nr 2 2 2 2148 chk_add_nr 8 0 2149 fi 2150 2151 # signal invalid addresses timeout 2152 if reset_with_add_addr_timeout "invalid address, ADD_ADDR timeout"; then 2153 pm_nl_set_limits $ns1 2 2 2154 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2155 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2156 pm_nl_set_limits $ns2 2 2 2157 run_tests $ns1 $ns2 10.0.1.1 0 0 0 speed_10 2158 chk_join_nr 1 1 1 2159 chk_add_nr 8 0 2160 fi 2161} 2162 2163remove_tests() 2164{ 2165 # single subflow, remove 2166 if reset "remove single subflow"; then 2167 pm_nl_set_limits $ns1 0 1 2168 pm_nl_set_limits $ns2 0 1 2169 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2170 run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 2171 chk_join_nr 1 1 1 2172 chk_rm_tx_nr 1 2173 chk_rm_nr 1 1 2174 fi 2175 2176 # multiple subflows, remove 2177 if reset "remove multiple subflows"; then 2178 pm_nl_set_limits $ns1 0 2 2179 pm_nl_set_limits $ns2 0 2 2180 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2181 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2182 run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow 2183 chk_join_nr 2 2 2 2184 chk_rm_nr 2 2 2185 fi 2186 2187 # single address, remove 2188 if reset "remove single address"; then 2189 pm_nl_set_limits $ns1 0 1 2190 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2191 pm_nl_set_limits $ns2 1 1 2192 run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2193 chk_join_nr 1 1 1 2194 chk_add_nr 1 1 2195 chk_rm_nr 1 1 invert 2196 fi 2197 2198 # subflow and signal, remove 2199 if reset "remove subflow and signal"; then 2200 pm_nl_set_limits $ns1 0 2 2201 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2202 pm_nl_set_limits $ns2 1 2 2203 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2204 run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2205 chk_join_nr 2 2 2 2206 chk_add_nr 1 1 2207 chk_rm_nr 1 1 2208 fi 2209 2210 # subflows and signal, remove 2211 if reset "remove subflows and signal"; then 2212 pm_nl_set_limits $ns1 0 3 2213 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2214 pm_nl_set_limits $ns2 1 3 2215 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2216 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2217 run_tests $ns1 $ns2 10.0.1.1 0 -1 -2 speed_10 2218 chk_join_nr 3 3 3 2219 chk_add_nr 1 1 2220 chk_rm_nr 2 2 2221 fi 2222 2223 # addresses remove 2224 if reset "remove addresses"; then 2225 pm_nl_set_limits $ns1 3 3 2226 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 2227 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2228 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2229 pm_nl_set_limits $ns2 3 3 2230 run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2231 chk_join_nr 3 3 3 2232 chk_add_nr 3 3 2233 chk_rm_nr 3 3 invert 2234 fi 2235 2236 # invalid addresses remove 2237 if reset "remove invalid addresses"; then 2238 pm_nl_set_limits $ns1 3 3 2239 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2240 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2241 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 2242 pm_nl_set_limits $ns2 3 3 2243 run_tests $ns1 $ns2 10.0.1.1 0 -3 0 speed_10 2244 chk_join_nr 1 1 1 2245 chk_add_nr 3 3 2246 chk_rm_nr 3 1 invert 2247 fi 2248 2249 # subflows and signal, flush 2250 if reset "flush subflows and signal"; then 2251 pm_nl_set_limits $ns1 0 3 2252 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2253 pm_nl_set_limits $ns2 1 3 2254 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2255 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2256 run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2257 chk_join_nr 3 3 3 2258 chk_add_nr 1 1 2259 chk_rm_nr 1 3 invert simult 2260 fi 2261 2262 # subflows flush 2263 if reset "flush subflows"; then 2264 pm_nl_set_limits $ns1 3 3 2265 pm_nl_set_limits $ns2 3 3 2266 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow id 150 2267 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2268 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2269 run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2270 chk_join_nr 3 3 3 2271 chk_rm_tx_nr 0 2272 chk_rm_nr 0 3 simult 2273 fi 2274 2275 # addresses flush 2276 if reset "flush addresses"; then 2277 pm_nl_set_limits $ns1 3 3 2278 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal id 250 2279 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2280 pm_nl_add_endpoint $ns1 10.0.4.1 flags signal 2281 pm_nl_set_limits $ns2 3 3 2282 run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow 2283 chk_join_nr 3 3 3 2284 chk_add_nr 3 3 2285 chk_rm_nr 3 3 invert simult 2286 fi 2287 2288 # invalid addresses flush 2289 if reset "flush invalid addresses"; then 2290 pm_nl_set_limits $ns1 3 3 2291 pm_nl_add_endpoint $ns1 10.0.12.1 flags signal 2292 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal 2293 pm_nl_add_endpoint $ns1 10.0.14.1 flags signal 2294 pm_nl_set_limits $ns2 3 3 2295 run_tests $ns1 $ns2 10.0.1.1 0 -8 0 slow 2296 chk_join_nr 1 1 1 2297 chk_add_nr 3 3 2298 chk_rm_nr 3 1 invert 2299 fi 2300 2301 # remove id 0 subflow 2302 if reset "remove id 0 subflow"; then 2303 pm_nl_set_limits $ns1 0 1 2304 pm_nl_set_limits $ns2 0 1 2305 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2306 run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow 2307 chk_join_nr 1 1 1 2308 chk_rm_nr 1 1 2309 fi 2310 2311 # remove id 0 address 2312 if reset "remove id 0 address"; then 2313 pm_nl_set_limits $ns1 0 1 2314 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2315 pm_nl_set_limits $ns2 1 1 2316 run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow 2317 chk_join_nr 1 1 1 2318 chk_add_nr 1 1 2319 chk_rm_nr 1 1 invert 2320 fi 2321} 2322 2323add_tests() 2324{ 2325 # add single subflow 2326 if reset "add single subflow"; then 2327 pm_nl_set_limits $ns1 0 1 2328 pm_nl_set_limits $ns2 0 1 2329 run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow 2330 chk_join_nr 1 1 1 2331 fi 2332 2333 # add signal address 2334 if reset "add signal address"; then 2335 pm_nl_set_limits $ns1 0 1 2336 pm_nl_set_limits $ns2 1 1 2337 run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2338 chk_join_nr 1 1 1 2339 chk_add_nr 1 1 2340 fi 2341 2342 # add multiple subflows 2343 if reset "add multiple subflows"; then 2344 pm_nl_set_limits $ns1 0 2 2345 pm_nl_set_limits $ns2 0 2 2346 run_tests $ns1 $ns2 10.0.1.1 0 0 2 slow 2347 chk_join_nr 2 2 2 2348 fi 2349 2350 # add multiple subflows IPv6 2351 if reset "add multiple subflows IPv6"; then 2352 pm_nl_set_limits $ns1 0 2 2353 pm_nl_set_limits $ns2 0 2 2354 run_tests $ns1 $ns2 dead:beef:1::1 0 0 2 slow 2355 chk_join_nr 2 2 2 2356 fi 2357 2358 # add multiple addresses IPv6 2359 if reset "add multiple addresses IPv6"; then 2360 pm_nl_set_limits $ns1 0 2 2361 pm_nl_set_limits $ns2 2 2 2362 run_tests $ns1 $ns2 dead:beef:1::1 0 2 0 slow 2363 chk_join_nr 2 2 2 2364 chk_add_nr 2 2 2365 fi 2366} 2367 2368ipv6_tests() 2369{ 2370 # subflow IPv6 2371 if reset "single subflow IPv6"; then 2372 pm_nl_set_limits $ns1 0 1 2373 pm_nl_set_limits $ns2 0 1 2374 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2375 run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2376 chk_join_nr 1 1 1 2377 fi 2378 2379 # add_address, unused IPv6 2380 if reset "unused signal address IPv6"; then 2381 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2382 run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2383 chk_join_nr 0 0 0 2384 chk_add_nr 1 1 2385 fi 2386 2387 # signal address IPv6 2388 if reset "single address IPv6"; then 2389 pm_nl_set_limits $ns1 0 1 2390 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2391 pm_nl_set_limits $ns2 1 1 2392 run_tests $ns1 $ns2 dead:beef:1::1 0 0 0 slow 2393 chk_join_nr 1 1 1 2394 chk_add_nr 1 1 2395 fi 2396 2397 # single address IPv6, remove 2398 if reset "remove single address IPv6"; then 2399 pm_nl_set_limits $ns1 0 1 2400 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2401 pm_nl_set_limits $ns2 1 1 2402 run_tests $ns1 $ns2 dead:beef:1::1 0 -1 0 slow 2403 chk_join_nr 1 1 1 2404 chk_add_nr 1 1 2405 chk_rm_nr 1 1 invert 2406 fi 2407 2408 # subflow and signal IPv6, remove 2409 if reset "remove subflow and signal IPv6"; then 2410 pm_nl_set_limits $ns1 0 2 2411 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2412 pm_nl_set_limits $ns2 1 2 2413 pm_nl_add_endpoint $ns2 dead:beef:3::2 dev ns2eth3 flags subflow 2414 run_tests $ns1 $ns2 dead:beef:1::1 0 -1 -1 slow 2415 chk_join_nr 2 2 2 2416 chk_add_nr 1 1 2417 chk_rm_nr 1 1 2418 fi 2419} 2420 2421v4mapped_tests() 2422{ 2423 # subflow IPv4-mapped to IPv4-mapped 2424 if reset "single subflow IPv4-mapped"; then 2425 pm_nl_set_limits $ns1 0 1 2426 pm_nl_set_limits $ns2 0 1 2427 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2428 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2429 chk_join_nr 1 1 1 2430 fi 2431 2432 # signal address IPv4-mapped with IPv4-mapped sk 2433 if reset "signal address IPv4-mapped"; then 2434 pm_nl_set_limits $ns1 0 1 2435 pm_nl_set_limits $ns2 1 1 2436 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2437 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2438 chk_join_nr 1 1 1 2439 chk_add_nr 1 1 2440 fi 2441 2442 # subflow v4-map-v6 2443 if reset "single subflow v4-map-v6"; then 2444 pm_nl_set_limits $ns1 0 1 2445 pm_nl_set_limits $ns2 0 1 2446 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2447 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2448 chk_join_nr 1 1 1 2449 fi 2450 2451 # signal address v4-map-v6 2452 if reset "signal address v4-map-v6"; then 2453 pm_nl_set_limits $ns1 0 1 2454 pm_nl_set_limits $ns2 1 1 2455 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2456 run_tests $ns1 $ns2 "::ffff:10.0.1.1" 2457 chk_join_nr 1 1 1 2458 chk_add_nr 1 1 2459 fi 2460 2461 # subflow v6-map-v4 2462 if reset "single subflow v6-map-v4"; then 2463 pm_nl_set_limits $ns1 0 1 2464 pm_nl_set_limits $ns2 0 1 2465 pm_nl_add_endpoint $ns2 "::ffff:10.0.3.2" flags subflow 2466 run_tests $ns1 $ns2 10.0.1.1 2467 chk_join_nr 1 1 1 2468 fi 2469 2470 # signal address v6-map-v4 2471 if reset "signal address v6-map-v4"; then 2472 pm_nl_set_limits $ns1 0 1 2473 pm_nl_set_limits $ns2 1 1 2474 pm_nl_add_endpoint $ns1 "::ffff:10.0.2.1" flags signal 2475 run_tests $ns1 $ns2 10.0.1.1 2476 chk_join_nr 1 1 1 2477 chk_add_nr 1 1 2478 fi 2479 2480 # no subflow IPv6 to v4 address 2481 if reset "no JOIN with diff families v4-v6"; then 2482 pm_nl_set_limits $ns1 0 1 2483 pm_nl_set_limits $ns2 0 1 2484 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow 2485 run_tests $ns1 $ns2 10.0.1.1 2486 chk_join_nr 0 0 0 2487 fi 2488 2489 # no subflow IPv6 to v4 address even if v6 has a valid v4 at the end 2490 if reset "no JOIN with diff families v4-v6-2"; then 2491 pm_nl_set_limits $ns1 0 1 2492 pm_nl_set_limits $ns2 0 1 2493 pm_nl_add_endpoint $ns2 dead:beef:2::10.0.3.2 flags subflow 2494 run_tests $ns1 $ns2 10.0.1.1 2495 chk_join_nr 0 0 0 2496 fi 2497 2498 # no subflow IPv4 to v6 address, no need to slow down too then 2499 if reset "no JOIN with diff families v6-v4"; then 2500 pm_nl_set_limits $ns1 0 1 2501 pm_nl_set_limits $ns2 0 1 2502 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2503 run_tests $ns1 $ns2 dead:beef:1::1 2504 chk_join_nr 0 0 0 2505 fi 2506} 2507 2508mixed_tests() 2509{ 2510 if reset "IPv4 sockets do not use IPv6 addresses"; then 2511 pm_nl_set_limits $ns1 0 1 2512 pm_nl_set_limits $ns2 1 1 2513 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2514 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2515 chk_join_nr 0 0 0 2516 fi 2517 2518 # Need an IPv6 mptcp socket to allow subflows of both families 2519 if reset "simult IPv4 and IPv6 subflows"; then 2520 pm_nl_set_limits $ns1 0 1 2521 pm_nl_set_limits $ns2 1 1 2522 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2523 run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2524 chk_join_nr 1 1 1 2525 fi 2526 2527 # cross families subflows will not be created even in fullmesh mode 2528 if reset "simult IPv4 and IPv6 subflows, fullmesh 1x1"; then 2529 pm_nl_set_limits $ns1 0 4 2530 pm_nl_set_limits $ns2 1 4 2531 pm_nl_add_endpoint $ns2 dead:beef:2::2 flags subflow,fullmesh 2532 pm_nl_add_endpoint $ns1 10.0.1.1 flags signal 2533 run_tests $ns1 $ns2 dead:beef:2::1 0 0 0 slow 2534 chk_join_nr 1 1 1 2535 fi 2536 2537 # fullmesh still tries to create all the possibly subflows with 2538 # matching family 2539 if reset "simult IPv4 and IPv6 subflows, fullmesh 2x2"; then 2540 pm_nl_set_limits $ns1 0 4 2541 pm_nl_set_limits $ns2 2 4 2542 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2543 pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal 2544 run_tests $ns1 $ns2 dead:beef:1::1 0 0 fullmesh_1 slow 2545 chk_join_nr 4 4 4 2546 fi 2547} 2548 2549backup_tests() 2550{ 2551 # single subflow, backup 2552 if reset "single subflow, backup"; then 2553 pm_nl_set_limits $ns1 0 1 2554 pm_nl_set_limits $ns2 0 1 2555 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,backup 2556 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup 2557 chk_join_nr 1 1 1 2558 chk_prio_nr 0 1 2559 fi 2560 2561 # single address, backup 2562 if reset "single address, backup"; then 2563 pm_nl_set_limits $ns1 0 1 2564 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2565 pm_nl_set_limits $ns2 1 1 2566 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2567 chk_join_nr 1 1 1 2568 chk_add_nr 1 1 2569 chk_prio_nr 1 1 2570 fi 2571 2572 # single address with port, backup 2573 if reset "single address with port, backup"; then 2574 pm_nl_set_limits $ns1 0 1 2575 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2576 pm_nl_set_limits $ns2 1 1 2577 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2578 chk_join_nr 1 1 1 2579 chk_add_nr 1 1 2580 chk_prio_nr 1 1 2581 fi 2582 2583 if reset "mpc backup"; then 2584 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2585 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2586 chk_join_nr 0 0 0 2587 chk_prio_nr 0 1 2588 fi 2589 2590 if reset "mpc backup both sides"; then 2591 pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow,backup 2592 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,backup 2593 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2594 chk_join_nr 0 0 0 2595 chk_prio_nr 1 1 2596 fi 2597 2598 if reset "mpc switch to backup"; then 2599 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2600 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2601 chk_join_nr 0 0 0 2602 chk_prio_nr 0 1 2603 fi 2604 2605 if reset "mpc switch to backup both sides"; then 2606 pm_nl_add_endpoint $ns1 10.0.1.1 flags subflow 2607 pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow 2608 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 2609 chk_join_nr 0 0 0 2610 chk_prio_nr 1 1 2611 fi 2612} 2613 2614LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED 2615LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED 2616 2617AF_INET=2 2618AF_INET6=10 2619 2620verify_listener_events() 2621{ 2622 local evt=$1 2623 local e_type=$2 2624 local e_family=$3 2625 local e_saddr=$4 2626 local e_sport=$5 2627 local type 2628 local family 2629 local saddr 2630 local sport 2631 2632 if [ $e_type = $LISTENER_CREATED ]; then 2633 stdbuf -o0 -e0 printf "\t\t\t\t\t CREATE_LISTENER %s:%s"\ 2634 $e_saddr $e_sport 2635 elif [ $e_type = $LISTENER_CLOSED ]; then 2636 stdbuf -o0 -e0 printf "\t\t\t\t\t CLOSE_LISTENER %s:%s "\ 2637 $e_saddr $e_sport 2638 fi 2639 2640 type=$(grep "type:$e_type," $evt | 2641 sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q') 2642 family=$(grep "type:$e_type," $evt | 2643 sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q') 2644 sport=$(grep "type:$e_type," $evt | 2645 sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q') 2646 if [ $family ] && [ $family = $AF_INET6 ]; then 2647 saddr=$(grep "type:$e_type," $evt | 2648 sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q') 2649 else 2650 saddr=$(grep "type:$e_type," $evt | 2651 sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q') 2652 fi 2653 2654 if [ $type ] && [ $type = $e_type ] && 2655 [ $family ] && [ $family = $e_family ] && 2656 [ $saddr ] && [ $saddr = $e_saddr ] && 2657 [ $sport ] && [ $sport = $e_sport ]; then 2658 stdbuf -o0 -e0 printf "[ ok ]\n" 2659 return 0 2660 fi 2661 fail_test 2662 stdbuf -o0 -e0 printf "[fail]\n" 2663} 2664 2665add_addr_ports_tests() 2666{ 2667 # signal address with port 2668 if reset "signal address with port"; then 2669 pm_nl_set_limits $ns1 0 1 2670 pm_nl_set_limits $ns2 1 1 2671 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2672 run_tests $ns1 $ns2 10.0.1.1 2673 chk_join_nr 1 1 1 2674 chk_add_nr 1 1 1 2675 fi 2676 2677 # subflow and signal with port 2678 if reset "subflow and signal with port"; then 2679 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2680 pm_nl_set_limits $ns1 0 2 2681 pm_nl_set_limits $ns2 1 2 2682 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2683 run_tests $ns1 $ns2 10.0.1.1 2684 chk_join_nr 2 2 2 2685 chk_add_nr 1 1 1 2686 fi 2687 2688 # single address with port, remove 2689 # pm listener events 2690 if reset_with_events "remove single address with port"; then 2691 pm_nl_set_limits $ns1 0 1 2692 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2693 pm_nl_set_limits $ns2 1 1 2694 run_tests $ns1 $ns2 10.0.1.1 0 -1 0 slow 2695 chk_join_nr 1 1 1 2696 chk_add_nr 1 1 1 2697 chk_rm_nr 1 1 invert 2698 2699 verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100 2700 verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100 2701 kill_events_pids 2702 fi 2703 2704 # subflow and signal with port, remove 2705 if reset "remove subflow and signal with port"; then 2706 pm_nl_set_limits $ns1 0 2 2707 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2708 pm_nl_set_limits $ns2 1 2 2709 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2710 run_tests $ns1 $ns2 10.0.1.1 0 -1 -1 slow 2711 chk_join_nr 2 2 2 2712 chk_add_nr 1 1 1 2713 chk_rm_nr 1 1 2714 fi 2715 2716 # subflows and signal with port, flush 2717 if reset "flush subflows and signal with port"; then 2718 pm_nl_set_limits $ns1 0 3 2719 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2720 pm_nl_set_limits $ns2 1 3 2721 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2722 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2723 run_tests $ns1 $ns2 10.0.1.1 0 -8 -2 slow 2724 chk_join_nr 3 3 3 2725 chk_add_nr 1 1 2726 chk_rm_nr 1 3 invert simult 2727 fi 2728 2729 # multiple addresses with port 2730 if reset "multiple addresses with port"; then 2731 pm_nl_set_limits $ns1 2 2 2732 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2733 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10100 2734 pm_nl_set_limits $ns2 2 2 2735 run_tests $ns1 $ns2 10.0.1.1 2736 chk_join_nr 2 2 2 2737 chk_add_nr 2 2 2 2738 fi 2739 2740 # multiple addresses with ports 2741 if reset "multiple addresses with ports"; then 2742 pm_nl_set_limits $ns1 2 2 2743 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal port 10100 2744 pm_nl_add_endpoint $ns1 10.0.3.1 flags signal port 10101 2745 pm_nl_set_limits $ns2 2 2 2746 run_tests $ns1 $ns2 10.0.1.1 2747 chk_join_nr 2 2 2 2748 chk_add_nr 2 2 2 2749 fi 2750} 2751 2752syncookies_tests() 2753{ 2754 # single subflow, syncookies 2755 if reset_with_cookies "single subflow with syn cookies"; then 2756 pm_nl_set_limits $ns1 0 1 2757 pm_nl_set_limits $ns2 0 1 2758 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2759 run_tests $ns1 $ns2 10.0.1.1 2760 chk_join_nr 1 1 1 2761 fi 2762 2763 # multiple subflows with syn cookies 2764 if reset_with_cookies "multiple subflows with syn cookies"; then 2765 pm_nl_set_limits $ns1 0 2 2766 pm_nl_set_limits $ns2 0 2 2767 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2768 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2769 run_tests $ns1 $ns2 10.0.1.1 2770 chk_join_nr 2 2 2 2771 fi 2772 2773 # multiple subflows limited by server 2774 if reset_with_cookies "subflows limited by server w cookies"; then 2775 pm_nl_set_limits $ns1 0 1 2776 pm_nl_set_limits $ns2 0 2 2777 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2778 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow 2779 run_tests $ns1 $ns2 10.0.1.1 2780 chk_join_nr 2 1 1 2781 fi 2782 2783 # test signal address with cookies 2784 if reset_with_cookies "signal address with syn cookies"; then 2785 pm_nl_set_limits $ns1 0 1 2786 pm_nl_set_limits $ns2 1 1 2787 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2788 run_tests $ns1 $ns2 10.0.1.1 2789 chk_join_nr 1 1 1 2790 chk_add_nr 1 1 2791 fi 2792 2793 # test cookie with subflow and signal 2794 if reset_with_cookies "subflow and signal w cookies"; then 2795 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2796 pm_nl_set_limits $ns1 0 2 2797 pm_nl_set_limits $ns2 1 2 2798 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2799 run_tests $ns1 $ns2 10.0.1.1 2800 chk_join_nr 2 2 2 2801 chk_add_nr 1 1 2802 fi 2803 2804 # accept and use add_addr with additional subflows 2805 if reset_with_cookies "subflows and signal w. cookies"; then 2806 pm_nl_set_limits $ns1 0 3 2807 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2808 pm_nl_set_limits $ns2 1 3 2809 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2810 pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow 2811 run_tests $ns1 $ns2 10.0.1.1 2812 chk_join_nr 3 3 3 2813 chk_add_nr 1 1 2814 fi 2815} 2816 2817checksum_tests() 2818{ 2819 # checksum test 0 0 2820 if reset_with_checksum 0 0; then 2821 pm_nl_set_limits $ns1 0 1 2822 pm_nl_set_limits $ns2 0 1 2823 run_tests $ns1 $ns2 10.0.1.1 2824 chk_join_nr 0 0 0 2825 fi 2826 2827 # checksum test 1 1 2828 if reset_with_checksum 1 1; then 2829 pm_nl_set_limits $ns1 0 1 2830 pm_nl_set_limits $ns2 0 1 2831 run_tests $ns1 $ns2 10.0.1.1 2832 chk_join_nr 0 0 0 2833 fi 2834 2835 # checksum test 0 1 2836 if reset_with_checksum 0 1; then 2837 pm_nl_set_limits $ns1 0 1 2838 pm_nl_set_limits $ns2 0 1 2839 run_tests $ns1 $ns2 10.0.1.1 2840 chk_join_nr 0 0 0 2841 fi 2842 2843 # checksum test 1 0 2844 if reset_with_checksum 1 0; then 2845 pm_nl_set_limits $ns1 0 1 2846 pm_nl_set_limits $ns2 0 1 2847 run_tests $ns1 $ns2 10.0.1.1 2848 chk_join_nr 0 0 0 2849 fi 2850} 2851 2852deny_join_id0_tests() 2853{ 2854 # subflow allow join id0 ns1 2855 if reset_with_allow_join_id0 "single subflow allow join id0 ns1" 1 0; then 2856 pm_nl_set_limits $ns1 1 1 2857 pm_nl_set_limits $ns2 1 1 2858 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2859 run_tests $ns1 $ns2 10.0.1.1 2860 chk_join_nr 1 1 1 2861 fi 2862 2863 # subflow allow join id0 ns2 2864 if reset_with_allow_join_id0 "single subflow allow join id0 ns2" 0 1; then 2865 pm_nl_set_limits $ns1 1 1 2866 pm_nl_set_limits $ns2 1 1 2867 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2868 run_tests $ns1 $ns2 10.0.1.1 2869 chk_join_nr 0 0 0 2870 fi 2871 2872 # signal address allow join id0 ns1 2873 # ADD_ADDRs are not affected by allow_join_id0 value. 2874 if reset_with_allow_join_id0 "signal address allow join id0 ns1" 1 0; then 2875 pm_nl_set_limits $ns1 1 1 2876 pm_nl_set_limits $ns2 1 1 2877 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2878 run_tests $ns1 $ns2 10.0.1.1 2879 chk_join_nr 1 1 1 2880 chk_add_nr 1 1 2881 fi 2882 2883 # signal address allow join id0 ns2 2884 # ADD_ADDRs are not affected by allow_join_id0 value. 2885 if reset_with_allow_join_id0 "signal address allow join id0 ns2" 0 1; then 2886 pm_nl_set_limits $ns1 1 1 2887 pm_nl_set_limits $ns2 1 1 2888 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2889 run_tests $ns1 $ns2 10.0.1.1 2890 chk_join_nr 1 1 1 2891 chk_add_nr 1 1 2892 fi 2893 2894 # subflow and address allow join id0 ns1 2895 if reset_with_allow_join_id0 "subflow and address allow join id0 1" 1 0; then 2896 pm_nl_set_limits $ns1 2 2 2897 pm_nl_set_limits $ns2 2 2 2898 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2899 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2900 run_tests $ns1 $ns2 10.0.1.1 2901 chk_join_nr 2 2 2 2902 fi 2903 2904 # subflow and address allow join id0 ns2 2905 if reset_with_allow_join_id0 "subflow and address allow join id0 2" 0 1; then 2906 pm_nl_set_limits $ns1 2 2 2907 pm_nl_set_limits $ns2 2 2 2908 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2909 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 2910 run_tests $ns1 $ns2 10.0.1.1 2911 chk_join_nr 1 1 1 2912 fi 2913} 2914 2915fullmesh_tests() 2916{ 2917 # fullmesh 1 2918 # 2 fullmesh addrs in ns2, added before the connection, 2919 # 1 non-fullmesh addr in ns1, added during the connection. 2920 if reset "fullmesh test 2x1"; then 2921 pm_nl_set_limits $ns1 0 4 2922 pm_nl_set_limits $ns2 1 4 2923 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,fullmesh 2924 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow,fullmesh 2925 run_tests $ns1 $ns2 10.0.1.1 0 1 0 slow 2926 chk_join_nr 4 4 4 2927 chk_add_nr 1 1 2928 fi 2929 2930 # fullmesh 2 2931 # 1 non-fullmesh addr in ns1, added before the connection, 2932 # 1 fullmesh addr in ns2, added during the connection. 2933 if reset "fullmesh test 1x1"; then 2934 pm_nl_set_limits $ns1 1 3 2935 pm_nl_set_limits $ns2 1 3 2936 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2937 run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow 2938 chk_join_nr 3 3 3 2939 chk_add_nr 1 1 2940 fi 2941 2942 # fullmesh 3 2943 # 1 non-fullmesh addr in ns1, added before the connection, 2944 # 2 fullmesh addrs in ns2, added during the connection. 2945 if reset "fullmesh test 1x2"; then 2946 pm_nl_set_limits $ns1 2 5 2947 pm_nl_set_limits $ns2 1 5 2948 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2949 run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2950 chk_join_nr 5 5 5 2951 chk_add_nr 1 1 2952 fi 2953 2954 # fullmesh 4 2955 # 1 non-fullmesh addr in ns1, added before the connection, 2956 # 2 fullmesh addrs in ns2, added during the connection, 2957 # limit max_subflows to 4. 2958 if reset "fullmesh test 1x2, limited"; then 2959 pm_nl_set_limits $ns1 2 4 2960 pm_nl_set_limits $ns2 1 4 2961 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 2962 run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_2 slow 2963 chk_join_nr 4 4 4 2964 chk_add_nr 1 1 2965 fi 2966 2967 # set fullmesh flag 2968 if reset "set fullmesh flag test"; then 2969 pm_nl_set_limits $ns1 4 4 2970 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 2971 pm_nl_set_limits $ns2 4 4 2972 run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow fullmesh 2973 chk_join_nr 2 2 2 2974 chk_rm_nr 0 1 2975 fi 2976 2977 # set nofullmesh flag 2978 if reset "set nofullmesh flag test"; then 2979 pm_nl_set_limits $ns1 4 4 2980 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow,fullmesh 2981 pm_nl_set_limits $ns2 4 4 2982 run_tests $ns1 $ns2 10.0.1.1 0 0 fullmesh_1 slow nofullmesh 2983 chk_join_nr 2 2 2 2984 chk_rm_nr 0 1 2985 fi 2986 2987 # set backup,fullmesh flags 2988 if reset "set backup,fullmesh flags test"; then 2989 pm_nl_set_limits $ns1 4 4 2990 pm_nl_add_endpoint $ns1 10.0.2.1 flags subflow 2991 pm_nl_set_limits $ns2 4 4 2992 run_tests $ns1 $ns2 10.0.1.1 0 0 1 slow backup,fullmesh 2993 chk_join_nr 2 2 2 2994 chk_prio_nr 0 1 2995 chk_rm_nr 0 1 2996 fi 2997 2998 # set nobackup,nofullmesh flags 2999 if reset "set nobackup,nofullmesh flags test"; then 3000 pm_nl_set_limits $ns1 4 4 3001 pm_nl_set_limits $ns2 4 4 3002 pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow,backup,fullmesh 3003 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow nobackup,nofullmesh 3004 chk_join_nr 2 2 2 3005 chk_prio_nr 0 1 3006 chk_rm_nr 0 1 3007 fi 3008} 3009 3010fastclose_tests() 3011{ 3012 if reset "fastclose test"; then 3013 run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_client 3014 chk_join_nr 0 0 0 3015 chk_fclose_nr 1 1 3016 chk_rst_nr 1 1 invert 3017 fi 3018 3019 if reset "fastclose server test"; then 3020 run_tests $ns1 $ns2 10.0.1.1 1024 0 fastclose_server 3021 chk_join_nr 0 0 0 3022 chk_fclose_nr 1 1 invert 3023 chk_rst_nr 1 1 3024 fi 3025} 3026 3027pedit_action_pkts() 3028{ 3029 tc -n $ns2 -j -s action show action pedit index 100 | \ 3030 grep "packets" | \ 3031 sed 's/.*"packets":\([0-9]\+\),.*/\1/' 3032} 3033 3034fail_tests() 3035{ 3036 # single subflow 3037 if reset_with_fail "Infinite map" 1; then 3038 run_tests $ns1 $ns2 10.0.1.1 128 3039 chk_join_nr 0 0 0 +1 +0 1 0 1 "$(pedit_action_pkts)" 3040 chk_fail_nr 1 -1 invert 3041 fi 3042 3043 # multiple subflows 3044 if reset_with_fail "MP_FAIL MP_RST" 2; then 3045 tc -n $ns2 qdisc add dev ns2eth1 root netem rate 1mbit delay 5 3046 pm_nl_set_limits $ns1 0 1 3047 pm_nl_set_limits $ns2 0 1 3048 pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3049 run_tests $ns1 $ns2 10.0.1.1 1024 3050 chk_join_nr 1 1 1 1 0 1 1 0 "$(pedit_action_pkts)" 3051 fi 3052} 3053 3054userspace_tests() 3055{ 3056 # userspace pm type prevents add_addr 3057 if reset "userspace pm type prevents add_addr"; then 3058 set_userspace_pm $ns1 3059 pm_nl_set_limits $ns1 0 2 3060 pm_nl_set_limits $ns2 0 2 3061 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3062 run_tests $ns1 $ns2 10.0.1.1 3063 chk_join_nr 0 0 0 3064 chk_add_nr 0 0 3065 fi 3066 3067 # userspace pm type does not echo add_addr without daemon 3068 if reset "userspace pm no echo w/o daemon"; then 3069 set_userspace_pm $ns2 3070 pm_nl_set_limits $ns1 0 2 3071 pm_nl_set_limits $ns2 0 2 3072 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3073 run_tests $ns1 $ns2 10.0.1.1 3074 chk_join_nr 0 0 0 3075 chk_add_nr 1 0 3076 fi 3077 3078 # userspace pm type rejects join 3079 if reset "userspace pm type rejects join"; then 3080 set_userspace_pm $ns1 3081 pm_nl_set_limits $ns1 1 1 3082 pm_nl_set_limits $ns2 1 1 3083 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3084 run_tests $ns1 $ns2 10.0.1.1 3085 chk_join_nr 1 1 0 3086 fi 3087 3088 # userspace pm type does not send join 3089 if reset "userspace pm type does not send join"; then 3090 set_userspace_pm $ns2 3091 pm_nl_set_limits $ns1 1 1 3092 pm_nl_set_limits $ns2 1 1 3093 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3094 run_tests $ns1 $ns2 10.0.1.1 3095 chk_join_nr 0 0 0 3096 fi 3097 3098 # userspace pm type prevents mp_prio 3099 if reset "userspace pm type prevents mp_prio"; then 3100 set_userspace_pm $ns1 3101 pm_nl_set_limits $ns1 1 1 3102 pm_nl_set_limits $ns2 1 1 3103 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3104 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup 3105 chk_join_nr 1 1 0 3106 chk_prio_nr 0 0 3107 fi 3108 3109 # userspace pm type prevents rm_addr 3110 if reset "userspace pm type prevents rm_addr"; then 3111 set_userspace_pm $ns1 3112 set_userspace_pm $ns2 3113 pm_nl_set_limits $ns1 0 1 3114 pm_nl_set_limits $ns2 0 1 3115 pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow 3116 run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow 3117 chk_join_nr 0 0 0 3118 chk_rm_nr 0 0 3119 fi 3120 3121 # userspace pm add & remove address 3122 if reset_with_events "userspace pm add & remove address"; then 3123 set_userspace_pm $ns1 3124 pm_nl_set_limits $ns2 1 1 3125 run_tests $ns1 $ns2 10.0.1.1 0 userspace_1 0 slow 3126 chk_join_nr 1 1 1 3127 chk_add_nr 1 1 3128 chk_rm_nr 1 1 invert 3129 kill_events_pids 3130 fi 3131 3132 # userspace pm create destroy subflow 3133 if reset_with_events "userspace pm create destroy subflow"; then 3134 set_userspace_pm $ns2 3135 pm_nl_set_limits $ns1 0 1 3136 run_tests $ns1 $ns2 10.0.1.1 0 0 userspace_1 slow 3137 chk_join_nr 1 1 1 3138 chk_rm_nr 0 1 3139 kill_events_pids 3140 fi 3141} 3142 3143endpoint_tests() 3144{ 3145 # userspace pm type prevents add_addr 3146 if reset "implicit EP"; then 3147 pm_nl_set_limits $ns1 2 2 3148 pm_nl_set_limits $ns2 2 2 3149 pm_nl_add_endpoint $ns1 10.0.2.1 flags signal 3150 run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow 2>/dev/null & 3151 3152 wait_mpj $ns1 3153 pm_nl_check_endpoint 1 "creation" \ 3154 $ns2 10.0.2.2 id 1 flags implicit 3155 3156 pm_nl_add_endpoint $ns2 10.0.2.2 id 33 3157 pm_nl_check_endpoint 0 "ID change is prevented" \ 3158 $ns2 10.0.2.2 id 1 flags implicit 3159 3160 pm_nl_add_endpoint $ns2 10.0.2.2 flags signal 3161 pm_nl_check_endpoint 0 "modif is allowed" \ 3162 $ns2 10.0.2.2 id 1 flags signal 3163 kill_tests_wait 3164 fi 3165 3166 if reset "delete and re-add"; then 3167 pm_nl_set_limits $ns1 1 1 3168 pm_nl_set_limits $ns2 1 1 3169 pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow 3170 run_tests $ns1 $ns2 10.0.1.1 4 0 0 speed_20 2>/dev/null & 3171 3172 wait_mpj $ns2 3173 chk_subflow_nr needtitle "before delete" 2 3174 chk_mptcp_info subflows_1 3175 3176 pm_nl_del_endpoint $ns2 2 10.0.2.2 3177 sleep 0.5 3178 chk_subflow_nr "" "after delete" 1 3179 chk_mptcp_info subflows_0 3180 3181 pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow 3182 wait_mpj $ns2 3183 chk_subflow_nr "" "after re-add" 2 3184 chk_mptcp_info subflows_1 3185 kill_tests_wait 3186 fi 3187} 3188 3189# [$1: error message] 3190usage() 3191{ 3192 if [ -n "${1}" ]; then 3193 echo "${1}" 3194 ret=1 3195 fi 3196 3197 echo "mptcp_join usage:" 3198 3199 local key 3200 for key in "${!all_tests[@]}"; do 3201 echo " -${key} ${all_tests[${key}]}" 3202 done 3203 3204 echo " -c capture pcap files" 3205 echo " -C enable data checksum" 3206 echo " -i use ip mptcp" 3207 echo " -h help" 3208 3209 echo "[test ids|names]" 3210 3211 exit ${ret} 3212} 3213 3214 3215# Use a "simple" array to force an specific order we cannot have with an associative one 3216all_tests_sorted=( 3217 f@subflows_tests 3218 e@subflows_error_tests 3219 s@signal_address_tests 3220 l@link_failure_tests 3221 t@add_addr_timeout_tests 3222 r@remove_tests 3223 a@add_tests 3224 6@ipv6_tests 3225 4@v4mapped_tests 3226 M@mixed_tests 3227 b@backup_tests 3228 p@add_addr_ports_tests 3229 k@syncookies_tests 3230 S@checksum_tests 3231 d@deny_join_id0_tests 3232 m@fullmesh_tests 3233 z@fastclose_tests 3234 F@fail_tests 3235 u@userspace_tests 3236 I@endpoint_tests 3237) 3238 3239all_tests_args="" 3240all_tests_names=() 3241for subtests in "${all_tests_sorted[@]}"; do 3242 key="${subtests%@*}" 3243 value="${subtests#*@}" 3244 3245 all_tests_args+="${key}" 3246 all_tests_names+=("${value}") 3247 all_tests[${key}]="${value}" 3248done 3249 3250tests=() 3251while getopts "${all_tests_args}cCih" opt; do 3252 case $opt in 3253 ["${all_tests_args}"]) 3254 tests+=("${all_tests[${opt}]}") 3255 ;; 3256 c) 3257 capture=1 3258 ;; 3259 C) 3260 checksum=1 3261 ;; 3262 i) 3263 ip_mptcp=1 3264 ;; 3265 h) 3266 usage 3267 ;; 3268 *) 3269 usage "Unknown option: -${opt}" 3270 ;; 3271 esac 3272done 3273 3274shift $((OPTIND - 1)) 3275 3276for arg in "${@}"; do 3277 if [[ "${arg}" =~ ^[0-9]+$ ]]; then 3278 only_tests_ids+=("${arg}") 3279 else 3280 only_tests_names+=("${arg}") 3281 fi 3282done 3283 3284if [ ${#tests[@]} -eq 0 ]; then 3285 tests=("${all_tests_names[@]}") 3286fi 3287 3288for subtests in "${tests[@]}"; do 3289 "${subtests}" 3290done 3291 3292if [ ${ret} -ne 0 ]; then 3293 echo 3294 echo "${#failed_tests[@]} failure(s) has(ve) been detected:" 3295 for i in $(get_failed_tests_ids); do 3296 echo -e "\t- ${i}: ${failed_tests[${i}]}" 3297 done 3298 echo 3299fi 3300 3301exit $ret 3302