1259a834fSKishen Maloor#!/bin/bash 2259a834fSKishen Maloor# SPDX-License-Identifier: GPL-2.0 3259a834fSKishen Maloor 48320b138SMatthieu Baerts# Double quotes to prevent globbing and word splitting is recommended in new 58320b138SMatthieu Baerts# code but we accept it. 68320b138SMatthieu Baerts#shellcheck disable=SC2086 78320b138SMatthieu Baerts 88320b138SMatthieu Baerts# Some variables are used below but indirectly, see check_expected_one() 98320b138SMatthieu Baerts#shellcheck disable=SC2034 108320b138SMatthieu Baerts 1163212608SMatthieu Baerts. "$(dirname "${0}")/mptcp_lib.sh" 1263212608SMatthieu Baerts 1363212608SMatthieu Baertsmptcp_lib_check_mptcp 14626cb7a5SMatthieu Baertsmptcp_lib_check_kallsyms 1563212608SMatthieu Baerts 16f90adb03SMatthieu Baertsif ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then 17f90adb03SMatthieu Baerts echo "userspace pm tests are not supported by the kernel: SKIP" 18f90adb03SMatthieu Baerts exit ${KSFT_SKIP} 19f90adb03SMatthieu Baertsfi 20f90adb03SMatthieu Baerts 218320b138SMatthieu Baertsif ! ip -Version &> /dev/null; then 22259a834fSKishen Maloor echo "SKIP: Cannot not run test without ip tool" 23723d6b9bSMatthieu Baerts exit ${KSFT_SKIP} 24259a834fSKishen Maloorfi 25259a834fSKishen Maloor 26a17d1419SGeliang TangANNOUNCED=${MPTCP_LIB_EVENT_ANNOUNCED} 27a17d1419SGeliang TangREMOVED=${MPTCP_LIB_EVENT_REMOVED} 28a17d1419SGeliang TangSUB_ESTABLISHED=${MPTCP_LIB_EVENT_SUB_ESTABLISHED} 29a17d1419SGeliang TangSUB_CLOSED=${MPTCP_LIB_EVENT_SUB_CLOSED} 30a17d1419SGeliang TangLISTENER_CREATED=${MPTCP_LIB_EVENT_LISTENER_CREATED} 31a17d1419SGeliang TangLISTENER_CLOSED=${MPTCP_LIB_EVENT_LISTENER_CLOSED} 32259a834fSKishen Maloor 33a17d1419SGeliang TangAF_INET=${MPTCP_LIB_AF_INET} 34a17d1419SGeliang TangAF_INET6=${MPTCP_LIB_AF_INET6} 35259a834fSKishen Maloor 361cc94ac1SGeliang Tangfile="" 371cc94ac1SGeliang Tangserver_evts="" 381cc94ac1SGeliang Tangclient_evts="" 391cc94ac1SGeliang Tangserver_evts_pid=0 401cc94ac1SGeliang Tangclient_evts_pid=0 41259a834fSKishen Maloorclient4_pid=0 42259a834fSKishen Maloorserver4_pid=0 43259a834fSKishen Maloorclient6_pid=0 44259a834fSKishen Maloorserver6_pid=0 45259a834fSKishen Maloorclient4_token="" 46259a834fSKishen Maloorserver4_token="" 47259a834fSKishen Maloorclient6_token="" 48259a834fSKishen Maloorserver6_token="" 49259a834fSKishen Maloorclient4_port=0; 50259a834fSKishen Maloorclient6_port=0; 51259a834fSKishen Maloorapp4_port=50002 52259a834fSKishen Maloornew4_port=50003 53259a834fSKishen Maloorapp6_port=50004 54259a834fSKishen Maloorclient_addr_id=${RANDOM:0:2} 55259a834fSKishen Maloorserver_addr_id=${RANDOM:0:2} 56259a834fSKishen Maloor 57259a834fSKishen Maloorsec=$(date +%s) 58787eb1e4SMatthieu Baertsrndh=$(printf %x "$sec")-$(mktemp -u XXXXXX) 59259a834fSKishen Maloorns1="ns1-$rndh" 60259a834fSKishen Maloorns2="ns2-$rndh" 61e141c1e8SMatthieu Baertsret=0 62f589234eSMatthieu Baertstest_name="" 63f589234eSMatthieu Baerts 64d8463d81SMatthieu Baerts_printf() { 65d8463d81SMatthieu Baerts stdbuf -o0 -e0 printf "${@}" 66d8463d81SMatthieu Baerts} 67259a834fSKishen Maloor 68f790ae03SMatthieu Baertsprint_title() 69f790ae03SMatthieu Baerts{ 70d8463d81SMatthieu Baerts _printf "INFO: %s\n" "${1}" 71f790ae03SMatthieu Baerts} 72f790ae03SMatthieu Baerts 73e198ad75SMatthieu Baerts# $1: test name 74e198ad75SMatthieu Baertsprint_test() 75e198ad75SMatthieu Baerts{ 76f589234eSMatthieu Baerts test_name="${1}" 77f589234eSMatthieu Baerts 785b9bc8e6SMatthieu Baerts (NGI0) _printf "%-68s" "${test_name}" 79e198ad75SMatthieu Baerts} 80e198ad75SMatthieu Baerts 81e198ad75SMatthieu Baertsprint_results() 82e198ad75SMatthieu Baerts{ 83d8463d81SMatthieu Baerts _printf "[%s]\n" "${1}" 84e198ad75SMatthieu Baerts} 85e198ad75SMatthieu Baerts 86e198ad75SMatthieu Baertstest_pass() 87e198ad75SMatthieu Baerts{ 88e198ad75SMatthieu Baerts print_results " OK " 89f589234eSMatthieu Baerts mptcp_lib_result_pass "${test_name}" 90e198ad75SMatthieu Baerts} 91e198ad75SMatthieu Baerts 92e198ad75SMatthieu Baertstest_skip() 93e198ad75SMatthieu Baerts{ 94e198ad75SMatthieu Baerts print_results "SKIP" 95f589234eSMatthieu Baerts mptcp_lib_result_skip "${test_name}" 96e198ad75SMatthieu Baerts} 97e198ad75SMatthieu Baerts 98e198ad75SMatthieu Baerts# $1: msg 99e198ad75SMatthieu Baertstest_fail() 100e198ad75SMatthieu Baerts{ 101e198ad75SMatthieu Baerts print_results "FAIL" 102e198ad75SMatthieu Baerts ret=1 103e198ad75SMatthieu Baerts 104e198ad75SMatthieu Baerts if [ -n "${1}" ]; then 105d8463d81SMatthieu Baerts _printf "\t%s\n" "${1}" 106e198ad75SMatthieu Baerts fi 107f589234eSMatthieu Baerts 108f589234eSMatthieu Baerts mptcp_lib_result_fail "${test_name}" 109e198ad75SMatthieu Baerts} 110e198ad75SMatthieu Baerts 1118320b138SMatthieu Baerts# This function is used in the cleanup trap 1128320b138SMatthieu Baerts#shellcheck disable=SC2317 113259a834fSKishen Maloorcleanup() 114259a834fSKishen Maloor{ 115f790ae03SMatthieu Baerts print_title "Cleanup" 116259a834fSKishen Maloor 117259a834fSKishen Maloor # Terminate the MPTCP connection and related processes 1188dbdf24fSMatthieu Baerts local pid 1198dbdf24fSMatthieu Baerts for pid in $client4_pid $server4_pid $client6_pid $server6_pid\ 1208dbdf24fSMatthieu Baerts $server_evts_pid $client_evts_pid 1218dbdf24fSMatthieu Baerts do 1221fdb37a6SGeliang Tang mptcp_lib_kill_wait $pid 1238dbdf24fSMatthieu Baerts done 1248dbdf24fSMatthieu Baerts 125259a834fSKishen Maloor local netns 126259a834fSKishen Maloor for netns in "$ns1" "$ns2" ;do 127259a834fSKishen Maloor ip netns del "$netns" 128259a834fSKishen Maloor done 129f790ae03SMatthieu Baerts 1308dbdf24fSMatthieu Baerts rm -rf $file $client_evts $server_evts 1318dbdf24fSMatthieu Baerts 132d8463d81SMatthieu Baerts _printf "Done\n" 133259a834fSKishen Maloor} 134259a834fSKishen Maloor 135259a834fSKishen Maloortrap cleanup EXIT 136259a834fSKishen Maloor 137259a834fSKishen Maloor# Create and configure network namespaces for testing 138259a834fSKishen Maloorfor i in "$ns1" "$ns2" ;do 139259a834fSKishen Maloor ip netns add "$i" || exit 1 140259a834fSKishen Maloor ip -net "$i" link set lo up 141259a834fSKishen Maloor ip netns exec "$i" sysctl -q net.mptcp.enabled=1 142259a834fSKishen Maloor ip netns exec "$i" sysctl -q net.mptcp.pm_type=1 143259a834fSKishen Maloordone 144259a834fSKishen Maloor 145259a834fSKishen Maloor# "$ns1" ns2 146259a834fSKishen Maloor# ns1eth2 ns2eth1 147259a834fSKishen Maloor 148259a834fSKishen Maloorip link add ns1eth2 netns "$ns1" type veth peer name ns2eth1 netns "$ns2" 149259a834fSKishen Maloor 150259a834fSKishen Maloor# Add IPv4/v6 addresses to the namespaces 151259a834fSKishen Maloorip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2 152259a834fSKishen Maloorip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2 153259a834fSKishen Maloorip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad 154259a834fSKishen Maloorip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad 155259a834fSKishen Maloorip -net "$ns1" link set ns1eth2 up 156259a834fSKishen Maloor 157259a834fSKishen Maloorip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1 158259a834fSKishen Maloorip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth1 159259a834fSKishen Maloorip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad 160259a834fSKishen Maloorip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad 161259a834fSKishen Maloorip -net "$ns2" link set ns2eth1 up 162259a834fSKishen Maloor 163f790ae03SMatthieu Baertsprint_title "Init" 164e198ad75SMatthieu Baertsprint_test "Created network namespaces ns1, ns2" 165e198ad75SMatthieu Baertstest_pass 166259a834fSKishen Maloor 167259a834fSKishen Maloormake_file() 168259a834fSKishen Maloor{ 169259a834fSKishen Maloor # Store a chunk of data in a file to transmit over an MPTCP connection 170259a834fSKishen Maloor local name=$1 171259a834fSKishen Maloor local ksize=1 172259a834fSKishen Maloor 173259a834fSKishen Maloor dd if=/dev/urandom of="$name" bs=2 count=$ksize 2> /dev/null 174259a834fSKishen Maloor echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" 175259a834fSKishen Maloor} 176259a834fSKishen Maloor 177259a834fSKishen Maloormake_connection() 178259a834fSKishen Maloor{ 1791cc94ac1SGeliang Tang if [ -z "$file" ]; then 180259a834fSKishen Maloor file=$(mktemp) 1811cc94ac1SGeliang Tang fi 182259a834fSKishen Maloor make_file "$file" "client" 183259a834fSKishen Maloor 184259a834fSKishen Maloor local is_v6=$1 185259a834fSKishen Maloor local app_port=$app4_port 186259a834fSKishen Maloor local connect_addr="10.0.1.1" 1872dcc136eSMatthieu Baerts (NGI0) local client_addr="10.0.1.2" 188259a834fSKishen Maloor local listen_addr="0.0.0.0" 189259a834fSKishen Maloor if [ "$is_v6" = "v6" ] 190259a834fSKishen Maloor then 191259a834fSKishen Maloor connect_addr="dead:beef:1::1" 1922dcc136eSMatthieu Baerts (NGI0) client_addr="dead:beef:1::2" 193259a834fSKishen Maloor listen_addr="::" 194259a834fSKishen Maloor app_port=$app6_port 195259a834fSKishen Maloor else 196259a834fSKishen Maloor is_v6="v4" 197259a834fSKishen Maloor fi 198259a834fSKishen Maloor 199259a834fSKishen Maloor # Capture netlink events over the two network namespaces running 200259a834fSKishen Maloor # the MPTCP client and server 2011cc94ac1SGeliang Tang if [ -z "$client_evts" ]; then 202259a834fSKishen Maloor client_evts=$(mktemp) 2031cc94ac1SGeliang Tang fi 204*b66609e9SGeliang Tang mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid 2051cc94ac1SGeliang Tang if [ -z "$server_evts" ]; then 206259a834fSKishen Maloor server_evts=$(mktemp) 2071cc94ac1SGeliang Tang fi 208*b66609e9SGeliang Tang mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid 209259a834fSKishen Maloor sleep 0.5 210259a834fSKishen Maloor 211259a834fSKishen Maloor # Run the server 212259a834fSKishen Maloor ip netns exec "$ns1" \ 213259a834fSKishen Maloor ./mptcp_connect -s MPTCP -w 300 -p $app_port -l $listen_addr > /dev/null 2>&1 & 214259a834fSKishen Maloor local server_pid=$! 215259a834fSKishen Maloor sleep 0.5 216259a834fSKishen Maloor 217259a834fSKishen Maloor # Run the client, transfer $file and stay connected to the server 218259a834fSKishen Maloor # to conduct tests 219259a834fSKishen Maloor ip netns exec "$ns2" \ 220259a834fSKishen Maloor ./mptcp_connect -s MPTCP -w 300 -m sendfile -p $app_port $connect_addr\ 221259a834fSKishen Maloor 2>&1 > /dev/null < "$file" & 222259a834fSKishen Maloor local client_pid=$! 223259a834fSKishen Maloor sleep 1 224259a834fSKishen Maloor 225259a834fSKishen Maloor # Capture client/server attributes from MPTCP connection netlink events 226259a834fSKishen Maloor 227259a834fSKishen Maloor local client_token 228259a834fSKishen Maloor local client_port 229259a834fSKishen Maloor local client_serverside 230259a834fSKishen Maloor local server_token 231259a834fSKishen Maloor local server_serverside 232259a834fSKishen Maloor 233ae1fa39dSGeliang Tang client_token=$(mptcp_lib_evts_get_info token "$client_evts") 234ae1fa39dSGeliang Tang client_port=$(mptcp_lib_evts_get_info sport "$client_evts") 235ae1fa39dSGeliang Tang client_serverside=$(mptcp_lib_evts_get_info server_side "$client_evts") 236ae1fa39dSGeliang Tang server_token=$(mptcp_lib_evts_get_info token "$server_evts") 237ae1fa39dSGeliang Tang server_serverside=$(mptcp_lib_evts_get_info server_side "$server_evts") 238259a834fSKishen Maloor 239e198ad75SMatthieu Baerts print_test "Established IP${is_v6} MPTCP Connection ns2 => ns1" 240259a834fSKishen Maloor if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] && 241259a834fSKishen Maloor [ "$server_serverside" = 1 ] 242259a834fSKishen Maloor then 243e198ad75SMatthieu Baerts test_pass 2442dcc136eSMatthieu Baerts (NGI0) print_title "Connection info: ${client_addr}:${client_port} -> ${connect_addr}:${app_port}" 245259a834fSKishen Maloor else 246e198ad75SMatthieu Baerts test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})" 247f589234eSMatthieu Baerts mptcp_lib_result_print_all_tap 248259a834fSKishen Maloor exit 1 249259a834fSKishen Maloor fi 250259a834fSKishen Maloor 251259a834fSKishen Maloor if [ "$is_v6" = "v6" ] 252259a834fSKishen Maloor then 253259a834fSKishen Maloor client6_token=$client_token 254259a834fSKishen Maloor server6_token=$server_token 255259a834fSKishen Maloor client6_port=$client_port 256259a834fSKishen Maloor client6_pid=$client_pid 257259a834fSKishen Maloor server6_pid=$server_pid 258259a834fSKishen Maloor else 259259a834fSKishen Maloor client4_token=$client_token 260259a834fSKishen Maloor server4_token=$server_token 261259a834fSKishen Maloor client4_port=$client_port 262259a834fSKishen Maloor client4_pid=$client_pid 263259a834fSKishen Maloor server4_pid=$server_pid 264259a834fSKishen Maloor fi 265259a834fSKishen Maloor} 266259a834fSKishen Maloor 26710d42734SMatthieu Baerts# $1: var name ; $2: prev ret 2681c0b0ee2SMatthieu Baertscheck_expected_one() 2691c0b0ee2SMatthieu Baerts{ 2701c0b0ee2SMatthieu Baerts local var="${1}" 2711c0b0ee2SMatthieu Baerts local exp="e_${var}" 27210d42734SMatthieu Baerts local prev_ret="${2}" 2731c0b0ee2SMatthieu Baerts 27410d42734SMatthieu Baerts if [ "${!var}" = "${!exp}" ] 27510d42734SMatthieu Baerts then 27610d42734SMatthieu Baerts return 0 27710d42734SMatthieu Baerts fi 27810d42734SMatthieu Baerts 27910d42734SMatthieu Baerts if [ "${prev_ret}" = "0" ] 28010d42734SMatthieu Baerts then 281e198ad75SMatthieu Baerts test_fail 28210d42734SMatthieu Baerts fi 28310d42734SMatthieu Baerts 284d8463d81SMatthieu Baerts _printf "\tExpected value for '%s': '%s', got '%s'.\n" \ 285840742b7SMatthieu Baerts "${var}" "${!exp}" "${!var}" 28610d42734SMatthieu Baerts return 1 2871c0b0ee2SMatthieu Baerts} 2881c0b0ee2SMatthieu Baerts 2891c0b0ee2SMatthieu Baerts# $@: all var names to check 2901c0b0ee2SMatthieu Baertscheck_expected() 2911c0b0ee2SMatthieu Baerts{ 292e141c1e8SMatthieu Baerts local rc=0 2931c0b0ee2SMatthieu Baerts local var 2941c0b0ee2SMatthieu Baerts 2951c0b0ee2SMatthieu Baerts for var in "${@}" 2961c0b0ee2SMatthieu Baerts do 297e141c1e8SMatthieu Baerts check_expected_one "${var}" "${rc}" || rc=1 2981c0b0ee2SMatthieu Baerts done 2991c0b0ee2SMatthieu Baerts 300e141c1e8SMatthieu Baerts if [ ${rc} -eq 0 ] 3011c0b0ee2SMatthieu Baerts then 302e198ad75SMatthieu Baerts test_pass 3031c0b0ee2SMatthieu Baerts return 0 3041c0b0ee2SMatthieu Baerts fi 3051c0b0ee2SMatthieu Baerts 306e198ad75SMatthieu Baerts return 1 3071c0b0ee2SMatthieu Baerts} 3081c0b0ee2SMatthieu Baerts 309259a834fSKishen Maloorverify_announce_event() 310259a834fSKishen Maloor{ 311259a834fSKishen Maloor local evt=$1 312259a834fSKishen Maloor local e_type=$2 313259a834fSKishen Maloor local e_token=$3 314259a834fSKishen Maloor local e_addr=$4 315259a834fSKishen Maloor local e_id=$5 316259a834fSKishen Maloor local e_dport=$6 317259a834fSKishen Maloor local e_af=$7 318259a834fSKishen Maloor local type 319259a834fSKishen Maloor local token 320259a834fSKishen Maloor local addr 321259a834fSKishen Maloor local dport 322259a834fSKishen Maloor local id 323259a834fSKishen Maloor 324ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 325ae1fa39dSGeliang Tang token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 326259a834fSKishen Maloor if [ "$e_af" = "v6" ] 327259a834fSKishen Maloor then 328ae1fa39dSGeliang Tang addr=$(mptcp_lib_evts_get_info daddr6 "$evt" $e_type) 329259a834fSKishen Maloor else 330ae1fa39dSGeliang Tang addr=$(mptcp_lib_evts_get_info daddr4 "$evt" $e_type) 331259a834fSKishen Maloor fi 332ae1fa39dSGeliang Tang dport=$(mptcp_lib_evts_get_info dport "$evt" $e_type) 333ae1fa39dSGeliang Tang id=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 3341c0b0ee2SMatthieu Baerts 3351c0b0ee2SMatthieu Baerts check_expected "type" "token" "addr" "dport" "id" 336259a834fSKishen Maloor} 337259a834fSKishen Maloor 338259a834fSKishen Maloortest_announce() 339259a834fSKishen Maloor{ 340f790ae03SMatthieu Baerts print_title "Announce tests" 341f790ae03SMatthieu Baerts 342259a834fSKishen Maloor # Capture events on the network namespace running the server 3431cc94ac1SGeliang Tang :>"$server_evts" 344259a834fSKishen Maloor 345259a834fSKishen Maloor # ADD_ADDR using an invalid token should result in no action 346259a834fSKishen Maloor local invalid_token=$(( client4_token - 1)) 347259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token $invalid_token id\ 348259a834fSKishen Maloor $client_addr_id dev ns2eth1 > /dev/null 2>&1 349259a834fSKishen Maloor 350259a834fSKishen Maloor local type 351ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$server_evts") 352e198ad75SMatthieu Baerts print_test "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token" 353259a834fSKishen Maloor if [ "$type" = "" ] 354259a834fSKishen Maloor then 355e198ad75SMatthieu Baerts test_pass 356259a834fSKishen Maloor else 357e198ad75SMatthieu Baerts test_fail "type defined: ${type}" 358259a834fSKishen Maloor fi 359259a834fSKishen Maloor 360259a834fSKishen Maloor # ADD_ADDR from the client to server machine reusing the subflow port 3611cc94ac1SGeliang Tang :>"$server_evts" 362259a834fSKishen Maloor ip netns exec "$ns2"\ 363259a834fSKishen Maloor ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\ 3646a5c8c69SMatthieu Baerts ns2eth1 3652dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR id:client 10.0.2.2 (ns2) => ns1, reuse port" 366259a834fSKishen Maloor sleep 0.5 3671cc94ac1SGeliang Tang verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \ 368259a834fSKishen Maloor "$client4_port" 369259a834fSKishen Maloor 370259a834fSKishen Maloor # ADD_ADDR6 from the client to server machine reusing the subflow port 3711cc94ac1SGeliang Tang :>"$server_evts" 372259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann\ 3736a5c8c69SMatthieu Baerts dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 3742dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR6 id:client dead:beef:2::2 (ns2) => ns1, reuse port" 375259a834fSKishen Maloor sleep 0.5 3761cc94ac1SGeliang Tang verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\ 377259a834fSKishen Maloor "$client_addr_id" "$client6_port" "v6" 378259a834fSKishen Maloor 379259a834fSKishen Maloor # ADD_ADDR from the client to server machine using a new port 3801cc94ac1SGeliang Tang :>"$server_evts" 381259a834fSKishen Maloor client_addr_id=$((client_addr_id+1)) 382259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 3836a5c8c69SMatthieu Baerts $client_addr_id dev ns2eth1 port $new4_port 3842dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR id:client+1 10.0.2.2 (ns2) => ns1, new port" 385259a834fSKishen Maloor sleep 0.5 3861cc94ac1SGeliang Tang verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\ 387259a834fSKishen Maloor "$client_addr_id" "$new4_port" 388259a834fSKishen Maloor 389259a834fSKishen Maloor # Capture events on the network namespace running the client 3901cc94ac1SGeliang Tang :>"$client_evts" 391259a834fSKishen Maloor 392259a834fSKishen Maloor # ADD_ADDR from the server to client machine reusing the subflow port 393259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 3946a5c8c69SMatthieu Baerts $server_addr_id dev ns1eth2 3952dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR id:server 10.0.2.1 (ns1) => ns2, reuse port" 396259a834fSKishen Maloor sleep 0.5 3971cc94ac1SGeliang Tang verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ 398259a834fSKishen Maloor "$server_addr_id" "$app4_port" 399259a834fSKishen Maloor 400259a834fSKishen Maloor # ADD_ADDR6 from the server to client machine reusing the subflow port 4011cc94ac1SGeliang Tang :>"$client_evts" 402259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ 4036a5c8c69SMatthieu Baerts $server_addr_id dev ns1eth2 4042dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR6 id:server dead:beef:2::1 (ns1) => ns2, reuse port" 405259a834fSKishen Maloor sleep 0.5 4061cc94ac1SGeliang Tang verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\ 407259a834fSKishen Maloor "$server_addr_id" "$app6_port" "v6" 408259a834fSKishen Maloor 409259a834fSKishen Maloor # ADD_ADDR from the server to client machine using a new port 4101cc94ac1SGeliang Tang :>"$client_evts" 411259a834fSKishen Maloor server_addr_id=$((server_addr_id+1)) 412259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 4136a5c8c69SMatthieu Baerts $server_addr_id dev ns1eth2 port $new4_port 4142dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR id:server+1 10.0.2.1 (ns1) => ns2, new port" 415259a834fSKishen Maloor sleep 0.5 4161cc94ac1SGeliang Tang verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\ 417259a834fSKishen Maloor "$server_addr_id" "$new4_port" 418259a834fSKishen Maloor} 419259a834fSKishen Maloor 420259a834fSKishen Maloorverify_remove_event() 421259a834fSKishen Maloor{ 422259a834fSKishen Maloor local evt=$1 423259a834fSKishen Maloor local e_type=$2 424259a834fSKishen Maloor local e_token=$3 425259a834fSKishen Maloor local e_id=$4 426259a834fSKishen Maloor local type 427259a834fSKishen Maloor local token 428259a834fSKishen Maloor local id 429259a834fSKishen Maloor 430ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 431ae1fa39dSGeliang Tang token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 432ae1fa39dSGeliang Tang id=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 4331c0b0ee2SMatthieu Baerts 4341c0b0ee2SMatthieu Baerts check_expected "type" "token" "id" 435259a834fSKishen Maloor} 436259a834fSKishen Maloor 437259a834fSKishen Maloortest_remove() 438259a834fSKishen Maloor{ 439f790ae03SMatthieu Baerts print_title "Remove tests" 440f790ae03SMatthieu Baerts 441259a834fSKishen Maloor # Capture events on the network namespace running the server 4421cc94ac1SGeliang Tang :>"$server_evts" 443259a834fSKishen Maloor 444259a834fSKishen Maloor # RM_ADDR using an invalid token should result in no action 445259a834fSKishen Maloor local invalid_token=$(( client4_token - 1 )) 446259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem token $invalid_token id\ 447259a834fSKishen Maloor $client_addr_id > /dev/null 2>&1 4482dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:client ns2 => ns1, invalid token" 449259a834fSKishen Maloor local type 450ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$server_evts") 451259a834fSKishen Maloor if [ "$type" = "" ] 452259a834fSKishen Maloor then 453e198ad75SMatthieu Baerts test_pass 454259a834fSKishen Maloor else 455e198ad75SMatthieu Baerts test_fail 456259a834fSKishen Maloor fi 457259a834fSKishen Maloor 458259a834fSKishen Maloor # RM_ADDR using an invalid addr id should result in no action 459259a834fSKishen Maloor local invalid_id=$(( client_addr_id + 1 )) 460259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 461259a834fSKishen Maloor $invalid_id > /dev/null 2>&1 4622dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:client+1 ns2 => ns1, invalid id" 463ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$server_evts") 464259a834fSKishen Maloor if [ "$type" = "" ] 465259a834fSKishen Maloor then 466e198ad75SMatthieu Baerts test_pass 467259a834fSKishen Maloor else 468e198ad75SMatthieu Baerts test_fail 469259a834fSKishen Maloor fi 470259a834fSKishen Maloor 471259a834fSKishen Maloor # RM_ADDR from the client to server machine 4721cc94ac1SGeliang Tang :>"$server_evts" 473259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 4746a5c8c69SMatthieu Baerts $client_addr_id 4752dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:client ns2 => ns1" 476259a834fSKishen Maloor sleep 0.5 4771cc94ac1SGeliang Tang verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id" 478259a834fSKishen Maloor 479259a834fSKishen Maloor # RM_ADDR from the client to server machine 4801cc94ac1SGeliang Tang :>"$server_evts" 481259a834fSKishen Maloor client_addr_id=$(( client_addr_id - 1 )) 482259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\ 4836a5c8c69SMatthieu Baerts $client_addr_id 4842dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:client-1 ns2 => ns1" 485259a834fSKishen Maloor sleep 0.5 4861cc94ac1SGeliang Tang verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id" 487259a834fSKishen Maloor 488259a834fSKishen Maloor # RM_ADDR6 from the client to server machine 4891cc94ac1SGeliang Tang :>"$server_evts" 490259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\ 4916a5c8c69SMatthieu Baerts $client_addr_id 4922dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR6 id:client-1 ns2 => ns1" 493259a834fSKishen Maloor sleep 0.5 4941cc94ac1SGeliang Tang verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id" 495259a834fSKishen Maloor 496259a834fSKishen Maloor # Capture events on the network namespace running the client 4971cc94ac1SGeliang Tang :>"$client_evts" 498259a834fSKishen Maloor 499259a834fSKishen Maloor # RM_ADDR from the server to client machine 500259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ 5016a5c8c69SMatthieu Baerts $server_addr_id 5022dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:server ns1 => ns2" 503259a834fSKishen Maloor sleep 0.5 5041cc94ac1SGeliang Tang verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id" 505259a834fSKishen Maloor 506259a834fSKishen Maloor # RM_ADDR from the server to client machine 5071cc94ac1SGeliang Tang :>"$client_evts" 508259a834fSKishen Maloor server_addr_id=$(( server_addr_id - 1 )) 509259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\ 5106a5c8c69SMatthieu Baerts $server_addr_id 5112dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR id:server-1 ns1 => ns2" 512259a834fSKishen Maloor sleep 0.5 5131cc94ac1SGeliang Tang verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id" 514259a834fSKishen Maloor 515259a834fSKishen Maloor # RM_ADDR6 from the server to client machine 5161cc94ac1SGeliang Tang :>"$client_evts" 517259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\ 5186a5c8c69SMatthieu Baerts $server_addr_id 5192dcc136eSMatthieu Baerts (NGI0) print_test "RM_ADDR6 id:server-1 ns1 => ns2" 520259a834fSKishen Maloor sleep 0.5 5211cc94ac1SGeliang Tang verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id" 522259a834fSKishen Maloor} 523259a834fSKishen Maloor 524259a834fSKishen Maloorverify_subflow_events() 525259a834fSKishen Maloor{ 526259a834fSKishen Maloor local evt=$1 527259a834fSKishen Maloor local e_type=$2 528259a834fSKishen Maloor local e_token=$3 529259a834fSKishen Maloor local e_family=$4 530259a834fSKishen Maloor local e_saddr=$5 531259a834fSKishen Maloor local e_daddr=$6 532259a834fSKishen Maloor local e_dport=$7 533259a834fSKishen Maloor local e_locid=$8 534259a834fSKishen Maloor local e_remid=$9 535259a834fSKishen Maloor shift 2 536259a834fSKishen Maloor local e_from=$8 537259a834fSKishen Maloor local e_to=$9 538259a834fSKishen Maloor local type 539259a834fSKishen Maloor local token 540259a834fSKishen Maloor local family 541259a834fSKishen Maloor local saddr 542259a834fSKishen Maloor local daddr 543259a834fSKishen Maloor local dport 544259a834fSKishen Maloor local locid 545259a834fSKishen Maloor local remid 546e198ad75SMatthieu Baerts local info 5472dcc136eSMatthieu Baerts (NGI0) local e_dport_txt 548e198ad75SMatthieu Baerts 5492dcc136eSMatthieu Baerts (NGI0) # only display the fixed ports 5502dcc136eSMatthieu Baerts (NGI0) if [ "${e_dport}" -ge "${app4_port}" ] && [ "${e_dport}" -le "${app6_port}" ]; then 5512dcc136eSMatthieu Baerts (NGI0) e_dport_txt=":${e_dport}" 5522dcc136eSMatthieu Baerts (NGI0) fi 5532dcc136eSMatthieu Baerts (NGI0) 5542dcc136eSMatthieu Baerts (NGI0) info="${e_saddr} (${e_from}) => ${e_daddr}${e_dport_txt} (${e_to})" 555259a834fSKishen Maloor 556259a834fSKishen Maloor if [ "$e_type" = "$SUB_ESTABLISHED" ] 557259a834fSKishen Maloor then 558259a834fSKishen Maloor if [ "$e_family" = "$AF_INET6" ] 559259a834fSKishen Maloor then 560e198ad75SMatthieu Baerts print_test "CREATE_SUBFLOW6 ${info}" 561259a834fSKishen Maloor else 562e198ad75SMatthieu Baerts print_test "CREATE_SUBFLOW ${info}" 563259a834fSKishen Maloor fi 564259a834fSKishen Maloor else 565259a834fSKishen Maloor if [ "$e_family" = "$AF_INET6" ] 566259a834fSKishen Maloor then 567e198ad75SMatthieu Baerts print_test "DESTROY_SUBFLOW6 ${info}" 568259a834fSKishen Maloor else 569e198ad75SMatthieu Baerts print_test "DESTROY_SUBFLOW ${info}" 570259a834fSKishen Maloor fi 571259a834fSKishen Maloor fi 572259a834fSKishen Maloor 573ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type "$evt" $e_type) 574ae1fa39dSGeliang Tang token=$(mptcp_lib_evts_get_info token "$evt" $e_type) 575ae1fa39dSGeliang Tang family=$(mptcp_lib_evts_get_info family "$evt" $e_type) 576ae1fa39dSGeliang Tang dport=$(mptcp_lib_evts_get_info dport "$evt" $e_type) 577ae1fa39dSGeliang Tang locid=$(mptcp_lib_evts_get_info loc_id "$evt" $e_type) 578ae1fa39dSGeliang Tang remid=$(mptcp_lib_evts_get_info rem_id "$evt" $e_type) 579259a834fSKishen Maloor if [ "$family" = "$AF_INET6" ] 580259a834fSKishen Maloor then 581ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" $e_type) 582ae1fa39dSGeliang Tang daddr=$(mptcp_lib_evts_get_info daddr6 "$evt" $e_type) 583259a834fSKishen Maloor else 584ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" $e_type) 585ae1fa39dSGeliang Tang daddr=$(mptcp_lib_evts_get_info daddr4 "$evt" $e_type) 586259a834fSKishen Maloor fi 587259a834fSKishen Maloor 5881c0b0ee2SMatthieu Baerts check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid" 589259a834fSKishen Maloor} 590259a834fSKishen Maloor 591259a834fSKishen Maloortest_subflows() 592259a834fSKishen Maloor{ 593f790ae03SMatthieu Baerts print_title "Subflows v4 or v6 only tests" 594f790ae03SMatthieu Baerts 595259a834fSKishen Maloor # Capture events on the network namespace running the server 5961cc94ac1SGeliang Tang :>"$server_evts" 597259a834fSKishen Maloor 598259a834fSKishen Maloor # Attempt to add a listener at 10.0.2.2:<subflow-port> 599259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\ 6006a5c8c69SMatthieu Baerts "$client4_port" & 601259a834fSKishen Maloor local listener_pid=$! 602259a834fSKishen Maloor 603259a834fSKishen Maloor # ADD_ADDR from client to server machine reusing the subflow port 604259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 6056a5c8c69SMatthieu Baerts $client_addr_id 606259a834fSKishen Maloor sleep 0.5 607259a834fSKishen Maloor 608259a834fSKishen Maloor # CREATE_SUBFLOW from server to client machine 6091cc94ac1SGeliang Tang :>"$server_evts" 610259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\ 6116a5c8c69SMatthieu Baerts rport "$client4_port" token "$server4_token" 612259a834fSKishen Maloor sleep 0.5 6131cc94ac1SGeliang Tang verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \ 614259a834fSKishen Maloor "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" 615259a834fSKishen Maloor 616259a834fSKishen Maloor # Delete the listener from the client ns, if one was created 6171fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 618259a834fSKishen Maloor 619259a834fSKishen Maloor local sport 620ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 621259a834fSKishen Maloor 622259a834fSKishen Maloor # DESTROY_SUBFLOW from server to client machine 6231cc94ac1SGeliang Tang :>"$server_evts" 624259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ 6256a5c8c69SMatthieu Baerts "$client4_port" token "$server4_token" 626259a834fSKishen Maloor sleep 0.5 6271cc94ac1SGeliang Tang verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ 628259a834fSKishen Maloor "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2" 629259a834fSKishen Maloor 630259a834fSKishen Maloor # RM_ADDR from client to server machine 631259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 6326a5c8c69SMatthieu Baerts "$client4_token" 633259a834fSKishen Maloor sleep 0.5 634259a834fSKishen Maloor 635259a834fSKishen Maloor # Attempt to add a listener at dead:beef:2::2:<subflow-port> 636259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl listen dead:beef:2::2\ 6376a5c8c69SMatthieu Baerts "$client6_port" & 638259a834fSKishen Maloor listener_pid=$! 639259a834fSKishen Maloor 640259a834fSKishen Maloor # ADD_ADDR6 from client to server machine reusing the subflow port 6411cc94ac1SGeliang Tang :>"$server_evts" 642259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\ 6436a5c8c69SMatthieu Baerts $client_addr_id 644259a834fSKishen Maloor sleep 0.5 645259a834fSKishen Maloor 646259a834fSKishen Maloor # CREATE_SUBFLOW6 from server to client machine 6471cc94ac1SGeliang Tang :>"$server_evts" 648259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\ 6496a5c8c69SMatthieu Baerts dead:beef:2::2 rport "$client6_port" token "$server6_token" 650259a834fSKishen Maloor sleep 0.5 6511cc94ac1SGeliang Tang verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\ 652259a834fSKishen Maloor "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ 653259a834fSKishen Maloor "$client_addr_id" "ns1" "ns2" 654259a834fSKishen Maloor 655259a834fSKishen Maloor # Delete the listener from the client ns, if one was created 6561fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 657259a834fSKishen Maloor 658ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 659259a834fSKishen Maloor 660259a834fSKishen Maloor # DESTROY_SUBFLOW6 from server to client machine 6611cc94ac1SGeliang Tang :>"$server_evts" 662259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\ 6636a5c8c69SMatthieu Baerts dead:beef:2::2 rport "$client6_port" token "$server6_token" 664259a834fSKishen Maloor sleep 0.5 6651cc94ac1SGeliang Tang verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\ 666259a834fSKishen Maloor "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\ 667259a834fSKishen Maloor "$client_addr_id" "ns1" "ns2" 668259a834fSKishen Maloor 669259a834fSKishen Maloor # RM_ADDR from client to server machine 670259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 6716a5c8c69SMatthieu Baerts "$client6_token" 672259a834fSKishen Maloor sleep 0.5 673259a834fSKishen Maloor 674259a834fSKishen Maloor # Attempt to add a listener at 10.0.2.2:<new-port> 675259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\ 6766a5c8c69SMatthieu Baerts $new4_port & 677259a834fSKishen Maloor listener_pid=$! 678259a834fSKishen Maloor 679259a834fSKishen Maloor # ADD_ADDR from client to server machine using a new port 6801cc94ac1SGeliang Tang :>"$server_evts" 681259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\ 6826a5c8c69SMatthieu Baerts $client_addr_id port $new4_port 683259a834fSKishen Maloor sleep 0.5 684259a834fSKishen Maloor 685259a834fSKishen Maloor # CREATE_SUBFLOW from server to client machine 6861cc94ac1SGeliang Tang :>"$server_evts" 687259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\ 6886a5c8c69SMatthieu Baerts $new4_port token "$server4_token" 689259a834fSKishen Maloor sleep 0.5 6901cc94ac1SGeliang Tang verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\ 691259a834fSKishen Maloor "10.0.2.1" "10.0.2.2" "$new4_port" "23"\ 692259a834fSKishen Maloor "$client_addr_id" "ns1" "ns2" 693259a834fSKishen Maloor 694259a834fSKishen Maloor # Delete the listener from the client ns, if one was created 6951fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 696259a834fSKishen Maloor 697ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$server_evts" $SUB_ESTABLISHED) 698259a834fSKishen Maloor 699259a834fSKishen Maloor # DESTROY_SUBFLOW from server to client machine 7001cc94ac1SGeliang Tang :>"$server_evts" 701259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\ 7026a5c8c69SMatthieu Baerts $new4_port token "$server4_token" 703259a834fSKishen Maloor sleep 0.5 7041cc94ac1SGeliang Tang verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\ 705259a834fSKishen Maloor "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2" 706259a834fSKishen Maloor 707259a834fSKishen Maloor # RM_ADDR from client to server machine 708259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\ 7096a5c8c69SMatthieu Baerts "$client4_token" 710259a834fSKishen Maloor 711259a834fSKishen Maloor # Capture events on the network namespace running the client 7121cc94ac1SGeliang Tang :>"$client_evts" 713259a834fSKishen Maloor 714259a834fSKishen Maloor # Attempt to add a listener at 10.0.2.1:<subflow-port> 715259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 7166a5c8c69SMatthieu Baerts $app4_port & 717259a834fSKishen Maloor listener_pid=$! 718259a834fSKishen Maloor 719259a834fSKishen Maloor # ADD_ADDR from server to client machine reusing the subflow port 720259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 7216a5c8c69SMatthieu Baerts $server_addr_id 722259a834fSKishen Maloor sleep 0.5 723259a834fSKishen Maloor 724259a834fSKishen Maloor # CREATE_SUBFLOW from client to server machine 7251cc94ac1SGeliang Tang :>"$client_evts" 726259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 7276a5c8c69SMatthieu Baerts $app4_port token "$client4_token" 728259a834fSKishen Maloor sleep 0.5 7291cc94ac1SGeliang Tang verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\ 730259a834fSKishen Maloor "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" 731259a834fSKishen Maloor 732259a834fSKishen Maloor # Delete the listener from the server ns, if one was created 7331fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 734259a834fSKishen Maloor 735ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 736259a834fSKishen Maloor 737259a834fSKishen Maloor # DESTROY_SUBFLOW from client to server machine 7381cc94ac1SGeliang Tang :>"$client_evts" 739259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 7406a5c8c69SMatthieu Baerts $app4_port token "$client4_token" 741259a834fSKishen Maloor sleep 0.5 7421cc94ac1SGeliang Tang verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ 743259a834fSKishen Maloor "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1" 744259a834fSKishen Maloor 745259a834fSKishen Maloor # RM_ADDR from server to client machine 746259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 7476a5c8c69SMatthieu Baerts "$server4_token" 748259a834fSKishen Maloor sleep 0.5 749259a834fSKishen Maloor 750259a834fSKishen Maloor # Attempt to add a listener at dead:beef:2::1:<subflow-port> 751259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl listen dead:beef:2::1\ 7526a5c8c69SMatthieu Baerts $app6_port & 753259a834fSKishen Maloor listener_pid=$! 754259a834fSKishen Maloor 755259a834fSKishen Maloor # ADD_ADDR6 from server to client machine reusing the subflow port 7561cc94ac1SGeliang Tang :>"$client_evts" 757259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\ 7586a5c8c69SMatthieu Baerts $server_addr_id 759259a834fSKishen Maloor sleep 0.5 760259a834fSKishen Maloor 761259a834fSKishen Maloor # CREATE_SUBFLOW6 from client to server machine 7621cc94ac1SGeliang Tang :>"$client_evts" 763259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\ 7646a5c8c69SMatthieu Baerts dead:beef:2::1 rport $app6_port token "$client6_token" 765259a834fSKishen Maloor sleep 0.5 7661cc94ac1SGeliang Tang verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\ 767259a834fSKishen Maloor "$AF_INET6" "dead:beef:2::2"\ 768259a834fSKishen Maloor "dead:beef:2::1" "$app6_port" "23"\ 769259a834fSKishen Maloor "$server_addr_id" "ns2" "ns1" 770259a834fSKishen Maloor 771259a834fSKishen Maloor # Delete the listener from the server ns, if one was created 7721fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 773259a834fSKishen Maloor 774ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 775259a834fSKishen Maloor 776259a834fSKishen Maloor # DESTROY_SUBFLOW6 from client to server machine 7771cc94ac1SGeliang Tang :>"$client_evts" 778259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\ 7796a5c8c69SMatthieu Baerts dead:beef:2::1 rport $app6_port token "$client6_token" 780259a834fSKishen Maloor sleep 0.5 7811cc94ac1SGeliang Tang verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\ 782259a834fSKishen Maloor "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1" 783259a834fSKishen Maloor 784259a834fSKishen Maloor # RM_ADDR6 from server to client machine 785259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 7866a5c8c69SMatthieu Baerts "$server6_token" 787259a834fSKishen Maloor sleep 0.5 788259a834fSKishen Maloor 789259a834fSKishen Maloor # Attempt to add a listener at 10.0.2.1:<new-port> 790259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 7916a5c8c69SMatthieu Baerts $new4_port & 792259a834fSKishen Maloor listener_pid=$! 793259a834fSKishen Maloor 794259a834fSKishen Maloor # ADD_ADDR from server to client machine using a new port 7951cc94ac1SGeliang Tang :>"$client_evts" 796259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\ 7976a5c8c69SMatthieu Baerts $server_addr_id port $new4_port 798259a834fSKishen Maloor sleep 0.5 799259a834fSKishen Maloor 800259a834fSKishen Maloor # CREATE_SUBFLOW from client to server machine 8011cc94ac1SGeliang Tang :>"$client_evts" 802259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 8036a5c8c69SMatthieu Baerts $new4_port token "$client4_token" 804259a834fSKishen Maloor sleep 0.5 8051cc94ac1SGeliang Tang verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\ 806259a834fSKishen Maloor "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" 807259a834fSKishen Maloor 808259a834fSKishen Maloor # Delete the listener from the server ns, if one was created 8091fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 810259a834fSKishen Maloor 811ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 812259a834fSKishen Maloor 813259a834fSKishen Maloor # DESTROY_SUBFLOW from client to server machine 8141cc94ac1SGeliang Tang :>"$client_evts" 815259a834fSKishen Maloor ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 8166a5c8c69SMatthieu Baerts $new4_port token "$client4_token" 817259a834fSKishen Maloor sleep 0.5 8181cc94ac1SGeliang Tang verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\ 819259a834fSKishen Maloor "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1" 820259a834fSKishen Maloor 821259a834fSKishen Maloor # RM_ADDR from server to client machine 822259a834fSKishen Maloor ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 8236a5c8c69SMatthieu Baerts "$server4_token" 824259a834fSKishen Maloor} 825259a834fSKishen Maloor 8264656d72cSMatthieu Baertstest_subflows_v4_v6_mix() 8274656d72cSMatthieu Baerts{ 828f790ae03SMatthieu Baerts print_title "Subflows v4 and v6 mix tests" 829f790ae03SMatthieu Baerts 8304656d72cSMatthieu Baerts # Attempt to add a listener at 10.0.2.1:<subflow-port> 8314656d72cSMatthieu Baerts ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\ 8326a5c8c69SMatthieu Baerts $app6_port & 8334656d72cSMatthieu Baerts local listener_pid=$! 8344656d72cSMatthieu Baerts 8354656d72cSMatthieu Baerts # ADD_ADDR4 from server to client machine reusing the subflow port on 8364656d72cSMatthieu Baerts # the established v6 connection 8374656d72cSMatthieu Baerts :>"$client_evts" 8384656d72cSMatthieu Baerts ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server6_token" id\ 8396a5c8c69SMatthieu Baerts $server_addr_id dev ns1eth2 8402dcc136eSMatthieu Baerts (NGI0) print_test "ADD_ADDR4 id:server 10.0.2.1 (ns1) => ns2, reuse port" 8414656d72cSMatthieu Baerts sleep 0.5 8424656d72cSMatthieu Baerts verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "10.0.2.1"\ 8434656d72cSMatthieu Baerts "$server_addr_id" "$app6_port" 8444656d72cSMatthieu Baerts 8454656d72cSMatthieu Baerts # CREATE_SUBFLOW from client to server machine 8464656d72cSMatthieu Baerts :>"$client_evts" 8474656d72cSMatthieu Baerts ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\ 8486a5c8c69SMatthieu Baerts $app6_port token "$client6_token" 8494656d72cSMatthieu Baerts sleep 0.5 8504656d72cSMatthieu Baerts verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\ 8514656d72cSMatthieu Baerts "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\ 8524656d72cSMatthieu Baerts "$server_addr_id" "ns2" "ns1" 8534656d72cSMatthieu Baerts 8544656d72cSMatthieu Baerts # Delete the listener from the server ns, if one was created 8551fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 8564656d72cSMatthieu Baerts 857ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport "$client_evts" $SUB_ESTABLISHED) 8584656d72cSMatthieu Baerts 8594656d72cSMatthieu Baerts # DESTROY_SUBFLOW from client to server machine 8604656d72cSMatthieu Baerts :>"$client_evts" 8614656d72cSMatthieu Baerts ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\ 8626a5c8c69SMatthieu Baerts $app6_port token "$client6_token" 8634656d72cSMatthieu Baerts sleep 0.5 8644656d72cSMatthieu Baerts verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client6_token" \ 8654656d72cSMatthieu Baerts "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\ 8664656d72cSMatthieu Baerts "$server_addr_id" "ns2" "ns1" 8674656d72cSMatthieu Baerts 8684656d72cSMatthieu Baerts # RM_ADDR from server to client machine 8694656d72cSMatthieu Baerts ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\ 8706a5c8c69SMatthieu Baerts "$server6_token" 8714656d72cSMatthieu Baerts sleep 0.5 8724656d72cSMatthieu Baerts} 8734656d72cSMatthieu Baerts 874ca188a25SKishen Maloortest_prio() 875ca188a25SKishen Maloor{ 876f790ae03SMatthieu Baerts print_title "Prio tests" 877f790ae03SMatthieu Baerts 878ca188a25SKishen Maloor local count 879ca188a25SKishen Maloor 880ca188a25SKishen Maloor # Send MP_PRIO signal from client to server machine 881d8566d0eSMatthieu Baerts ip netns exec "$ns2" ./pm_nl_ctl set 10.0.1.2 port "$client4_port" flags backup token "$client4_token" rip 10.0.1.1 rport "$app4_port" 882ca188a25SKishen Maloor sleep 0.5 883ca188a25SKishen Maloor 884ca188a25SKishen Maloor # Check TX 885e198ad75SMatthieu Baerts print_test "MP_PRIO TX" 886697128a3SGeliang Tang count=$(mptcp_lib_get_counter "$ns2" "MPTcpExtMPPrioTx") 887697128a3SGeliang Tang if [ -z "$count" ]; then 888697128a3SGeliang Tang test_skip 889697128a3SGeliang Tang elif [ $count != 1 ]; then 890e198ad75SMatthieu Baerts test_fail "Count != 1: ${count}" 891ca188a25SKishen Maloor else 892e198ad75SMatthieu Baerts test_pass 893ca188a25SKishen Maloor fi 894ca188a25SKishen Maloor 895ca188a25SKishen Maloor # Check RX 896e198ad75SMatthieu Baerts print_test "MP_PRIO RX" 897697128a3SGeliang Tang count=$(mptcp_lib_get_counter "$ns1" "MPTcpExtMPPrioRx") 898697128a3SGeliang Tang if [ -z "$count" ]; then 899697128a3SGeliang Tang test_skip 900697128a3SGeliang Tang elif [ $count != 1 ]; then 901e198ad75SMatthieu Baerts test_fail "Count != 1: ${count}" 902ca188a25SKishen Maloor else 903e198ad75SMatthieu Baerts test_pass 904ca188a25SKishen Maloor fi 905ca188a25SKishen Maloor} 906ca188a25SKishen Maloor 9076c73008aSGeliang Tangverify_listener_events() 9086c73008aSGeliang Tang{ 9096c73008aSGeliang Tang local evt=$1 9106c73008aSGeliang Tang local e_type=$2 9116c73008aSGeliang Tang local e_family=$3 9126c73008aSGeliang Tang local e_saddr=$4 9136c73008aSGeliang Tang local e_sport=$5 9146c73008aSGeliang Tang local type 9156c73008aSGeliang Tang local family 9166c73008aSGeliang Tang local saddr 9176c73008aSGeliang Tang local sport 9186c73008aSGeliang Tang 919ae1fa39dSGeliang Tang type=$(mptcp_lib_evts_get_info type $evt $e_type) 920ae1fa39dSGeliang Tang family=$(mptcp_lib_evts_get_info family $evt $e_type) 921ae1fa39dSGeliang Tang sport=$(mptcp_lib_evts_get_info sport $evt $e_type) 9226c73008aSGeliang Tang if [ $family ] && [ $family = $AF_INET6 ]; then 923ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr6 $evt $e_type) 9246c73008aSGeliang Tang else 925ae1fa39dSGeliang Tang saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type) 9266c73008aSGeliang Tang fi 9276c73008aSGeliang Tang 9281c0b0ee2SMatthieu Baerts check_expected "type" "family" "saddr" "sport" 9296c73008aSGeliang Tang} 9306c73008aSGeliang Tang 9316c73008aSGeliang Tangtest_listener() 9326c73008aSGeliang Tang{ 933f790ae03SMatthieu Baerts print_title "Listener tests" 934f790ae03SMatthieu Baerts 935626cb7a5SMatthieu Baerts if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then 936e198ad75SMatthieu Baerts print_test "LISTENER events" 937e198ad75SMatthieu Baerts test_skip 938626cb7a5SMatthieu Baerts return 939626cb7a5SMatthieu Baerts fi 940626cb7a5SMatthieu Baerts 9416c73008aSGeliang Tang # Capture events on the network namespace running the client 9426c73008aSGeliang Tang :>$client_evts 9436c73008aSGeliang Tang 9446c73008aSGeliang Tang # Attempt to add a listener at 10.0.2.2:<subflow-port> 9456c73008aSGeliang Tang ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\ 9466a5c8c69SMatthieu Baerts $client4_port & 9476c73008aSGeliang Tang local listener_pid=$! 9486c73008aSGeliang Tang 949711ae788SMatthieu Baerts sleep 0.5 9502dcc136eSMatthieu Baerts (NGI0) print_test "CREATE_LISTENER 10.0.2.2 (client port)" 9516c73008aSGeliang Tang verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port 9526c73008aSGeliang Tang 9536c73008aSGeliang Tang # ADD_ADDR from client to server machine reusing the subflow port 9546c73008aSGeliang Tang ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\ 9556a5c8c69SMatthieu Baerts $client_addr_id 9566c73008aSGeliang Tang sleep 0.5 9576c73008aSGeliang Tang 9586c73008aSGeliang Tang # CREATE_SUBFLOW from server to client machine 9596c73008aSGeliang Tang ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\ 9606a5c8c69SMatthieu Baerts rport $client4_port token $server4_token 9616c73008aSGeliang Tang sleep 0.5 9626c73008aSGeliang Tang 9636c73008aSGeliang Tang # Delete the listener from the client ns, if one was created 9641fdb37a6SGeliang Tang mptcp_lib_kill_wait $listener_pid 9656c73008aSGeliang Tang 966711ae788SMatthieu Baerts sleep 0.5 9672dcc136eSMatthieu Baerts (NGI0) print_test "CLOSE_LISTENER 10.0.2.2 (client port)" 9686c73008aSGeliang Tang verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port 9696c73008aSGeliang Tang} 9706c73008aSGeliang Tang 971f790ae03SMatthieu Baertsprint_title "Make connections" 972259a834fSKishen Maloormake_connection 973259a834fSKishen Maloormake_connection "v6" 9742dcc136eSMatthieu Baerts (NGI0)print_title "Will be using address IDs ${client_addr_id} (client) and ${server_addr_id} (server)" 975f790ae03SMatthieu Baerts 976259a834fSKishen Maloortest_announce 977259a834fSKishen Maloortest_remove 978259a834fSKishen Maloortest_subflows 9794656d72cSMatthieu Baertstest_subflows_v4_v6_mix 980ca188a25SKishen Maloortest_prio 9816c73008aSGeliang Tangtest_listener 982259a834fSKishen Maloor 983f589234eSMatthieu Baertsmptcp_lib_result_print_all_tap 984e141c1e8SMatthieu Baertsexit ${ret} 985