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