2 # SPDX-License-Identifier: GPL-2.0
4 . "$(dirname "${0}")/mptcp_lib.sh"
7 mptcp_lib_check_kallsyms
9 if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
10 echo "userspace pm tests are not supported by the kernel: SKIP"
14 ip -Version > /dev/null 2>&1
16 echo "SKIP: Cannot not run test without ip tool"
20 ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
21 REMOVED=7 # MPTCP_EVENT_REMOVED
22 SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
23 SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED
24 LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
25 LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
48 client_addr_id=${RANDOM:0:2}
49 server_addr_id=${RANDOM:0:2}
52 rndh=$(printf %x "$sec")-$(mktemp -u XXXXXX)
58 stdbuf -o0 -e0 printf "INFO: %s\n" "${1}"
63 [ $1 -eq 0 ] && return 0
65 kill -SIGUSR1 $1 > /dev/null 2>&1
66 kill $1 > /dev/null 2>&1
74 # Terminate the MPTCP connection and related processes
76 for pid in $client4_pid $server4_pid $client6_pid $server6_pid\
77 $server_evts_pid $client_evts_pid
83 for netns in "$ns1" "$ns2" ;do
87 rm -rf $file $client_evts $server_evts
89 stdbuf -o0 -e0 printf "Done\n"
94 # Create and configure network namespaces for testing
95 for i in "$ns1" "$ns2" ;do
96 ip netns add "$i" || exit 1
97 ip -net "$i" link set lo up
98 ip netns exec "$i" sysctl -q net.mptcp.enabled=1
99 ip netns exec "$i" sysctl -q net.mptcp.pm_type=1
105 ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
107 # Add IPv4/v6 addresses to the namespaces
108 ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2
109 ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2
110 ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
111 ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad
112 ip -net "$ns1" link set ns1eth2 up
114 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
115 ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth1
116 ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
117 ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad
118 ip -net "$ns2" link set ns2eth1 up
121 stdbuf -o0 -e0 printf "Created network namespaces ns1, ns2 \t\t\t[OK]\n"
125 # Store a chunk of data in a file to transmit over an MPTCP connection
129 dd if=/dev/urandom of="$name" bs=2 count=$ksize 2> /dev/null
130 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
135 if [ -z "$file" ]; then
138 make_file "$file" "client"
141 local app_port=$app4_port
142 local connect_addr="10.0.1.1"
143 local listen_addr="0.0.0.0"
144 if [ "$is_v6" = "v6" ]
146 connect_addr="dead:beef:1::1"
153 # Capture netlink events over the two network namespaces running
154 # the MPTCP client and server
155 if [ -z "$client_evts" ]; then
156 client_evts=$(mktemp)
159 if [ $client_evts_pid -ne 0 ]; then
160 kill_wait $client_evts_pid
162 ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
164 if [ -z "$server_evts" ]; then
165 server_evts=$(mktemp)
168 if [ $server_evts_pid -ne 0 ]; then
169 kill_wait $server_evts_pid
171 ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
176 ip netns exec "$ns1" \
177 ./mptcp_connect -s MPTCP -w 300 -p $app_port -l $listen_addr > /dev/null 2>&1 &
181 # Run the client, transfer $file and stay connected to the server
183 ip netns exec "$ns2" \
184 ./mptcp_connect -s MPTCP -w 300 -m sendfile -p $app_port $connect_addr\
185 2>&1 > /dev/null < "$file" &
189 # Capture client/server attributes from MPTCP connection netlink events
193 local client_serverside
195 local server_serverside
197 client_token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
198 client_port=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
199 client_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\
201 server_token=$(grep "type:1," "$server_evts" |
202 sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
203 server_serverside=$(grep "type:1," "$server_evts" |
204 sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
206 stdbuf -o0 -e0 printf "Established IP%s MPTCP Connection ns2 => ns1 \t\t" $is_v6
207 if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
208 [ "$server_serverside" = 1 ]
210 stdbuf -o0 -e0 printf "[OK]\n"
212 stdbuf -o0 -e0 printf "[FAIL]\n"
213 stdbuf -o0 -e0 printf "\tExpected tokens (c:%s - s:%s) and server (c:%d - s:%d)\n" \
214 "${client_token}" "${server_token}" \
215 "${client_serverside}" "${server_serverside}"
219 if [ "$is_v6" = "v6" ]
221 client6_token=$client_token
222 server6_token=$server_token
223 client6_port=$client_port
224 client6_pid=$client_pid
225 server6_pid=$server_pid
227 client4_token=$client_token
228 server4_token=$server_token
229 client4_port=$client_port
230 client4_pid=$client_pid
231 server4_pid=$server_pid
235 # $1: var name ; $2: prev ret
240 local prev_ret="${2}"
242 if [ "${!var}" = "${!exp}" ]
247 if [ "${prev_ret}" = "0" ]
249 stdbuf -o0 -e0 printf "[FAIL]\n"
252 stdbuf -o0 -e0 printf "\tExpected value for '%s': '%s', got '%s'.\n" \
253 "${var}" "${!exp}" "${!var}"
257 # $@: all var names to check
265 check_expected_one "${var}" "${ret}" || ret=1
270 stdbuf -o0 -e0 printf "[OK]\n"
277 verify_announce_event()
292 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
293 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
294 if [ "$e_af" = "v6" ]
296 addr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
298 addr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
300 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
301 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
303 check_expected "type" "token" "addr" "dport" "id"
308 print_title "Announce tests"
310 # Capture events on the network namespace running the server
313 # ADD_ADDR using an invalid token should result in no action
314 local invalid_token=$(( client4_token - 1))
315 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token $invalid_token id\
316 $client_addr_id dev ns2eth1 > /dev/null 2>&1
319 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
320 stdbuf -o0 -e0 printf "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token \t\t"
323 stdbuf -o0 -e0 printf "[OK]\n"
325 stdbuf -o0 -e0 printf "[FAIL]\n\ttype defined: %s\n" "${type}"
329 # ADD_ADDR from the client to server machine reusing the subflow port
331 ip netns exec "$ns2"\
332 ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\
333 ns2eth1 > /dev/null 2>&1
334 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, reuse port \t\t" $client_addr_id
336 verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \
339 # ADD_ADDR6 from the client to server machine reusing the subflow port
341 ip netns exec "$ns2" ./pm_nl_ctl ann\
342 dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 > /dev/null 2>&1
343 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::2 (ns2) => ns1, reuse port\t\t" $client_addr_id
345 verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\
346 "$client_addr_id" "$client6_port" "v6"
348 # ADD_ADDR from the client to server machine using a new port
350 client_addr_id=$((client_addr_id+1))
351 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
352 $client_addr_id dev ns2eth1 port $new4_port > /dev/null 2>&1
353 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, new port \t\t\t" $client_addr_id
355 verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\
356 "$client_addr_id" "$new4_port"
358 # Capture events on the network namespace running the client
361 # ADD_ADDR from the server to client machine reusing the subflow port
362 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
363 $server_addr_id dev ns1eth2 > /dev/null 2>&1
364 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, reuse port \t\t" $server_addr_id
366 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
367 "$server_addr_id" "$app4_port"
369 # ADD_ADDR6 from the server to client machine reusing the subflow port
371 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
372 $server_addr_id dev ns1eth2 > /dev/null 2>&1
373 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::1 (ns1) => ns2, reuse port\t\t" $server_addr_id
375 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\
376 "$server_addr_id" "$app6_port" "v6"
378 # ADD_ADDR from the server to client machine using a new port
380 server_addr_id=$((server_addr_id+1))
381 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
382 $server_addr_id dev ns1eth2 port $new4_port > /dev/null 2>&1
383 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, new port \t\t\t" $server_addr_id
385 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
386 "$server_addr_id" "$new4_port"
389 verify_remove_event()
399 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
400 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
401 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
403 check_expected "type" "token" "id"
408 print_title "Remove tests"
410 # Capture events on the network namespace running the server
413 # RM_ADDR using an invalid token should result in no action
414 local invalid_token=$(( client4_token - 1 ))
415 ip netns exec "$ns2" ./pm_nl_ctl rem token $invalid_token id\
416 $client_addr_id > /dev/null 2>&1
417 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid token \t"\
420 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
423 stdbuf -o0 -e0 printf "[OK]\n"
425 stdbuf -o0 -e0 printf "[FAIL]\n"
429 # RM_ADDR using an invalid addr id should result in no action
430 local invalid_id=$(( client_addr_id + 1 ))
431 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
432 $invalid_id > /dev/null 2>&1
433 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid id \t"\
435 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
438 stdbuf -o0 -e0 printf "[OK]\n"
440 stdbuf -o0 -e0 printf "[FAIL]\n"
444 # RM_ADDR from the client to server machine
446 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
447 $client_addr_id > /dev/null 2>&1
448 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
451 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
453 # RM_ADDR from the client to server machine
455 client_addr_id=$(( client_addr_id - 1 ))
456 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
457 $client_addr_id > /dev/null 2>&1
458 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
461 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
463 # RM_ADDR6 from the client to server machine
465 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\
466 $client_addr_id > /dev/null 2>&1
467 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns2 => ns1 \t"\
470 verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id"
472 # Capture events on the network namespace running the client
475 # RM_ADDR from the server to client machine
476 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
477 $server_addr_id > /dev/null 2>&1
478 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t"\
481 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
483 # RM_ADDR from the server to client machine
485 server_addr_id=$(( server_addr_id - 1 ))
486 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
487 $server_addr_id > /dev/null 2>&1
488 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t" $server_addr_id
490 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
492 # RM_ADDR6 from the server to client machine
494 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\
495 $server_addr_id > /dev/null 2>&1
496 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns1 => ns2 \t" $server_addr_id
498 verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id"
501 verify_subflow_events()
524 if [ "$e_type" = "$SUB_ESTABLISHED" ]
526 if [ "$e_family" = "$AF_INET6" ]
528 stdbuf -o0 -e0 printf "CREATE_SUBFLOW6 %s (%s) => %s (%s) "\
529 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
531 stdbuf -o0 -e0 printf "CREATE_SUBFLOW %s (%s) => %s (%s) \t"\
532 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
535 if [ "$e_family" = "$AF_INET6" ]
537 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW6 %s (%s) => %s (%s) "\
538 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
540 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW %s (%s) => %s (%s) \t"\
541 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
545 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
546 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
547 family=$(sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
548 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
549 locid=$(sed --unbuffered -n 's/.*\(loc_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
550 remid=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
551 if [ "$family" = "$AF_INET6" ]
553 saddr=$(sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
554 daddr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
556 saddr=$(sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
557 daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
560 check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid"
565 print_title "Subflows v4 or v6 only tests"
567 # Capture events on the network namespace running the server
570 # Attempt to add a listener at 10.0.2.2:<subflow-port>
571 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
572 "$client4_port" > /dev/null 2>&1 &
573 local listener_pid=$!
575 # ADD_ADDR from client to server machine reusing the subflow port
576 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
577 $client_addr_id > /dev/null 2>&1
580 # CREATE_SUBFLOW from server to client machine
582 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
583 rport "$client4_port" token "$server4_token" > /dev/null 2>&1
585 verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \
586 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
588 # Delete the listener from the client ns, if one was created
589 kill_wait $listener_pid
592 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
594 # DESTROY_SUBFLOW from server to client machine
596 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
597 "$client4_port" token "$server4_token" > /dev/null 2>&1
599 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
600 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
602 # RM_ADDR from client to server machine
603 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
604 "$client4_token" > /dev/null 2>&1
607 # Attempt to add a listener at dead:beef:2::2:<subflow-port>
608 ip netns exec "$ns2" ./pm_nl_ctl listen dead:beef:2::2\
609 "$client6_port" > /dev/null 2>&1 &
612 # ADD_ADDR6 from client to server machine reusing the subflow port
614 ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\
615 $client_addr_id > /dev/null 2>&1
618 # CREATE_SUBFLOW6 from server to client machine
620 ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\
621 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
623 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\
624 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
625 "$client_addr_id" "ns1" "ns2"
627 # Delete the listener from the client ns, if one was created
628 kill_wait $listener_pid
630 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
632 # DESTROY_SUBFLOW6 from server to client machine
634 ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\
635 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
637 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\
638 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
639 "$client_addr_id" "ns1" "ns2"
641 # RM_ADDR from client to server machine
642 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
643 "$client6_token" > /dev/null 2>&1
646 # Attempt to add a listener at 10.0.2.2:<new-port>
647 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
648 $new4_port > /dev/null 2>&1 &
651 # ADD_ADDR from client to server machine using a new port
653 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
654 $client_addr_id port $new4_port > /dev/null 2>&1
657 # CREATE_SUBFLOW from server to client machine
659 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\
660 $new4_port token "$server4_token" > /dev/null 2>&1
662 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\
663 "10.0.2.1" "10.0.2.2" "$new4_port" "23"\
664 "$client_addr_id" "ns1" "ns2"
666 # Delete the listener from the client ns, if one was created
667 kill_wait $listener_pid
669 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
671 # DESTROY_SUBFLOW from server to client machine
673 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
674 $new4_port token "$server4_token" > /dev/null 2>&1
676 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
677 "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2"
679 # RM_ADDR from client to server machine
680 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
681 "$client4_token" > /dev/null 2>&1
683 # Capture events on the network namespace running the client
686 # Attempt to add a listener at 10.0.2.1:<subflow-port>
687 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
688 $app4_port > /dev/null 2>&1 &
691 # ADD_ADDR from server to client machine reusing the subflow port
692 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
693 $server_addr_id > /dev/null 2>&1
696 # CREATE_SUBFLOW from client to server machine
698 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
699 $app4_port token "$client4_token" > /dev/null 2>&1
701 verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\
702 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
704 # Delete the listener from the server ns, if one was created
705 kill_wait $listener_pid
707 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
709 # DESTROY_SUBFLOW from client to server machine
711 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
712 $app4_port token "$client4_token" > /dev/null 2>&1
714 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
715 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
717 # RM_ADDR from server to client machine
718 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
719 "$server4_token" > /dev/null 2>&1
722 # Attempt to add a listener at dead:beef:2::1:<subflow-port>
723 ip netns exec "$ns1" ./pm_nl_ctl listen dead:beef:2::1\
724 $app6_port > /dev/null 2>&1 &
727 # ADD_ADDR6 from server to client machine reusing the subflow port
729 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
730 $server_addr_id > /dev/null 2>&1
733 # CREATE_SUBFLOW6 from client to server machine
735 ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\
736 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
738 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
739 "$AF_INET6" "dead:beef:2::2"\
740 "dead:beef:2::1" "$app6_port" "23"\
741 "$server_addr_id" "ns2" "ns1"
743 # Delete the listener from the server ns, if one was created
744 kill_wait $listener_pid
746 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
748 # DESTROY_SUBFLOW6 from client to server machine
750 ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\
751 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
753 verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\
754 "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1"
756 # RM_ADDR6 from server to client machine
757 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
758 "$server6_token" > /dev/null 2>&1
761 # Attempt to add a listener at 10.0.2.1:<new-port>
762 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
763 $new4_port > /dev/null 2>&1 &
766 # ADD_ADDR from server to client machine using a new port
768 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
769 $server_addr_id port $new4_port > /dev/null 2>&1
772 # CREATE_SUBFLOW from client to server machine
774 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
775 $new4_port token "$client4_token" > /dev/null 2>&1
777 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\
778 "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
780 # Delete the listener from the server ns, if one was created
781 kill_wait $listener_pid
783 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
785 # DESTROY_SUBFLOW from client to server machine
787 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
788 $new4_port token "$client4_token" > /dev/null 2>&1
790 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
791 "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
793 # RM_ADDR from server to client machine
794 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
795 "$server4_token" > /dev/null 2>&1
798 test_subflows_v4_v6_mix()
800 print_title "Subflows v4 and v6 mix tests"
802 # Attempt to add a listener at 10.0.2.1:<subflow-port>
803 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
804 $app6_port > /dev/null 2>&1 &
805 local listener_pid=$!
807 # ADD_ADDR4 from server to client machine reusing the subflow port on
808 # the established v6 connection
810 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server6_token" id\
811 $server_addr_id dev ns1eth2 > /dev/null 2>&1
812 stdbuf -o0 -e0 printf "ADD_ADDR4 id:%d 10.0.2.1 (ns1) => ns2, reuse port\t\t" $server_addr_id
814 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "10.0.2.1"\
815 "$server_addr_id" "$app6_port"
817 # CREATE_SUBFLOW from client to server machine
819 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
820 $app6_port token "$client6_token" > /dev/null 2>&1
822 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
823 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\
824 "$server_addr_id" "ns2" "ns1"
826 # Delete the listener from the server ns, if one was created
827 kill_wait $listener_pid
829 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
831 # DESTROY_SUBFLOW from client to server machine
833 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
834 $app6_port token "$client6_token" > /dev/null 2>&1
836 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client6_token" \
837 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\
838 "$server_addr_id" "ns2" "ns1"
840 # RM_ADDR from server to client machine
841 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
842 "$server6_token" > /dev/null 2>&1
848 print_title "Prio tests"
852 # Send MP_PRIO signal from client to server machine
853 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"
857 stdbuf -o0 -e0 printf "MP_PRIO TX \t"
858 count=$(ip netns exec "$ns2" nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
859 [ -z "$count" ] && count=0
860 if [ $count != 1 ]; then
861 stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
864 stdbuf -o0 -e0 printf "[OK]\n"
868 stdbuf -o0 -e0 printf "MP_PRIO RX \t"
869 count=$(ip netns exec "$ns1" nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
870 [ -z "$count" ] && count=0
871 if [ $count != 1 ]; then
872 stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
875 stdbuf -o0 -e0 printf "[OK]\n"
879 verify_listener_events()
891 if [ $e_type = $LISTENER_CREATED ]; then
892 stdbuf -o0 -e0 printf "CREATE_LISTENER %s:%s\t\t\t\t\t"\
894 elif [ $e_type = $LISTENER_CLOSED ]; then
895 stdbuf -o0 -e0 printf "CLOSE_LISTENER %s:%s\t\t\t\t\t"\
899 type=$(grep "type:$e_type," $evt |
900 sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
901 family=$(grep "type:$e_type," $evt |
902 sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
903 sport=$(grep "type:$e_type," $evt |
904 sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
905 if [ $family ] && [ $family = $AF_INET6 ]; then
906 saddr=$(grep "type:$e_type," $evt |
907 sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
909 saddr=$(grep "type:$e_type," $evt |
910 sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
913 check_expected "type" "family" "saddr" "sport"
918 print_title "Listener tests"
920 if ! mptcp_lib_kallsyms_has "mptcp_event_pm_listener$"; then
921 stdbuf -o0 -e0 printf "LISTENER events \t[SKIP] Not supported\n"
925 # Capture events on the network namespace running the client
928 # Attempt to add a listener at 10.0.2.2:<subflow-port>
929 ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\
930 $client4_port > /dev/null 2>&1 &
931 local listener_pid=$!
934 verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
936 # ADD_ADDR from client to server machine reusing the subflow port
937 ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\
938 $client_addr_id > /dev/null 2>&1
941 # CREATE_SUBFLOW from server to client machine
942 ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
943 rport $client4_port token $server4_token > /dev/null 2>&1
946 # Delete the listener from the client ns, if one was created
947 kill_wait $listener_pid
950 verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port
953 print_title "Make connections"
960 test_subflows_v4_v6_mix