2 # SPDX-License-Identifier: GPL-2.0
4 ip -Version > /dev/null 2>&1
6 echo "SKIP: Cannot not run test without ip tool"
10 ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
11 REMOVED=7 # MPTCP_EVENT_REMOVED
12 SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
13 SUB_CLOSED=11 # MPTCP_EVENT_SUB_CLOSED
14 LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
15 LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
38 client_addr_id=${RANDOM:0:2}
39 server_addr_id=${RANDOM:0:2}
42 rndh=$(printf %x "$sec")-$(mktemp -u XXXXXX)
48 stdbuf -o0 -e0 printf "INFO: %s\n" "${1}"
53 kill $1 > /dev/null 2>&1
61 rm -rf $file $client_evts $server_evts
63 # Terminate the MPTCP connection and related processes
64 if [ $client4_pid -ne 0 ]; then
65 kill -SIGUSR1 $client4_pid > /dev/null 2>&1
67 if [ $server4_pid -ne 0 ]; then
68 kill_wait $server4_pid
70 if [ $client6_pid -ne 0 ]; then
71 kill -SIGUSR1 $client6_pid > /dev/null 2>&1
73 if [ $server6_pid -ne 0 ]; then
74 kill_wait $server6_pid
76 if [ $server_evts_pid -ne 0 ]; then
77 kill_wait $server_evts_pid
79 if [ $client_evts_pid -ne 0 ]; then
80 kill_wait $client_evts_pid
83 for netns in "$ns1" "$ns2" ;do
87 stdbuf -o0 -e0 printf "Done\n"
92 # Create and configure network namespaces for testing
93 for i in "$ns1" "$ns2" ;do
94 ip netns add "$i" || exit 1
95 ip -net "$i" link set lo up
96 ip netns exec "$i" sysctl -q net.mptcp.enabled=1
97 ip netns exec "$i" sysctl -q net.mptcp.pm_type=1
103 ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
105 # Add IPv4/v6 addresses to the namespaces
106 ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2
107 ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2
108 ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
109 ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad
110 ip -net "$ns1" link set ns1eth2 up
112 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
113 ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth1
114 ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
115 ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad
116 ip -net "$ns2" link set ns2eth1 up
119 stdbuf -o0 -e0 printf "Created network namespaces ns1, ns2 \t\t\t[OK]\n"
123 # Store a chunk of data in a file to transmit over an MPTCP connection
127 dd if=/dev/urandom of="$name" bs=2 count=$ksize 2> /dev/null
128 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
133 if [ -z "$file" ]; then
136 make_file "$file" "client"
139 local app_port=$app4_port
140 local connect_addr="10.0.1.1"
141 local listen_addr="0.0.0.0"
142 if [ "$is_v6" = "v6" ]
144 connect_addr="dead:beef:1::1"
151 # Capture netlink events over the two network namespaces running
152 # the MPTCP client and server
153 if [ -z "$client_evts" ]; then
154 client_evts=$(mktemp)
157 if [ $client_evts_pid -ne 0 ]; then
158 kill_wait $client_evts_pid
160 ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
162 if [ -z "$server_evts" ]; then
163 server_evts=$(mktemp)
166 if [ $server_evts_pid -ne 0 ]; then
167 kill_wait $server_evts_pid
169 ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
174 ip netns exec "$ns1" \
175 ./mptcp_connect -s MPTCP -w 300 -p $app_port -l $listen_addr > /dev/null 2>&1 &
179 # Run the client, transfer $file and stay connected to the server
181 ip netns exec "$ns2" \
182 ./mptcp_connect -s MPTCP -w 300 -m sendfile -p $app_port $connect_addr\
183 2>&1 > /dev/null < "$file" &
187 # Capture client/server attributes from MPTCP connection netlink events
191 local client_serverside
193 local server_serverside
195 client_token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
196 client_port=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
197 client_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\
199 server_token=$(grep "type:1," "$server_evts" |
200 sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
201 server_serverside=$(grep "type:1," "$server_evts" |
202 sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
204 stdbuf -o0 -e0 printf "Established IP%s MPTCP Connection ns2 => ns1 \t\t" $is_v6
205 if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
206 [ "$server_serverside" = 1 ]
208 stdbuf -o0 -e0 printf "[OK]\n"
210 stdbuf -o0 -e0 printf "[FAIL]\n"
211 stdbuf -o0 -e0 printf "\tExpected tokens (c:%s - s:%s) and server (c:%d - s:%d)\n" \
212 "${client_token}" "${server_token}" \
213 "${client_serverside}" "${server_serverside}"
217 if [ "$is_v6" = "v6" ]
219 client6_token=$client_token
220 server6_token=$server_token
221 client6_port=$client_port
222 client6_pid=$client_pid
223 server6_pid=$server_pid
225 client4_token=$client_token
226 server4_token=$server_token
227 client4_port=$client_port
228 client4_pid=$client_pid
229 server4_pid=$server_pid
233 # $1: var name ; $2: prev ret
238 local prev_ret="${2}"
240 if [ "${!var}" = "${!exp}" ]
245 if [ "${prev_ret}" = "0" ]
247 stdbuf -o0 -e0 printf "[FAIL]\n"
250 stdbuf -o0 -e0 printf "\tExpected value for '%s': '%s', got '%s'.\n" \
251 "${var}" "${!var}" "${!exp}"
255 # $@: all var names to check
263 check_expected_one "${var}" "${ret}" || ret=1
268 stdbuf -o0 -e0 printf "[OK]\n"
275 verify_announce_event()
290 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
291 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
292 if [ "$e_af" = "v6" ]
294 addr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
296 addr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
298 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
299 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
301 check_expected "type" "token" "addr" "dport" "id"
306 print_title "Announce tests"
308 # Capture events on the network namespace running the server
311 # ADD_ADDR using an invalid token should result in no action
312 local invalid_token=$(( client4_token - 1))
313 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token $invalid_token id\
314 $client_addr_id dev ns2eth1 > /dev/null 2>&1
317 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
318 stdbuf -o0 -e0 printf "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token \t\t"
321 stdbuf -o0 -e0 printf "[OK]\n"
323 stdbuf -o0 -e0 printf "[FAIL]\n\ttype defined: %s\n" "${type}"
327 # ADD_ADDR from the client to server machine reusing the subflow port
329 ip netns exec "$ns2"\
330 ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\
331 ns2eth1 > /dev/null 2>&1
332 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, reuse port \t\t" $client_addr_id
334 verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \
337 # ADD_ADDR6 from the client to server machine reusing the subflow port
339 ip netns exec "$ns2" ./pm_nl_ctl ann\
340 dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 > /dev/null 2>&1
341 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::2 (ns2) => ns1, reuse port\t\t" $client_addr_id
343 verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\
344 "$client_addr_id" "$client6_port" "v6"
346 # ADD_ADDR from the client to server machine using a new port
348 client_addr_id=$((client_addr_id+1))
349 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
350 $client_addr_id dev ns2eth1 port $new4_port > /dev/null 2>&1
351 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, new port \t\t\t" $client_addr_id
353 verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\
354 "$client_addr_id" "$new4_port"
356 # Capture events on the network namespace running the client
359 # ADD_ADDR from the server to client machine reusing the subflow port
360 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
361 $server_addr_id dev ns1eth2 > /dev/null 2>&1
362 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, reuse port \t\t" $server_addr_id
364 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
365 "$server_addr_id" "$app4_port"
367 # ADD_ADDR6 from the server to client machine reusing the subflow port
369 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
370 $server_addr_id dev ns1eth2 > /dev/null 2>&1
371 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::1 (ns1) => ns2, reuse port\t\t" $server_addr_id
373 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\
374 "$server_addr_id" "$app6_port" "v6"
376 # ADD_ADDR from the server to client machine using a new port
378 server_addr_id=$((server_addr_id+1))
379 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
380 $server_addr_id dev ns1eth2 port $new4_port > /dev/null 2>&1
381 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, new port \t\t\t" $server_addr_id
383 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
384 "$server_addr_id" "$new4_port"
387 verify_remove_event()
397 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
398 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
399 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
401 check_expected "type" "token" "id"
406 print_title "Remove tests"
408 # Capture events on the network namespace running the server
411 # RM_ADDR using an invalid token should result in no action
412 local invalid_token=$(( client4_token - 1 ))
413 ip netns exec "$ns2" ./pm_nl_ctl rem token $invalid_token id\
414 $client_addr_id > /dev/null 2>&1
415 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid token \t"\
418 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
421 stdbuf -o0 -e0 printf "[OK]\n"
423 stdbuf -o0 -e0 printf "[FAIL]\n"
426 # RM_ADDR using an invalid addr id should result in no action
427 local invalid_id=$(( client_addr_id + 1 ))
428 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
429 $invalid_id > /dev/null 2>&1
430 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid id \t"\
432 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
435 stdbuf -o0 -e0 printf "[OK]\n"
437 stdbuf -o0 -e0 printf "[FAIL]\n"
440 # RM_ADDR from the client to server machine
442 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
443 $client_addr_id > /dev/null 2>&1
444 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
447 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
449 # RM_ADDR from the client to server machine
451 client_addr_id=$(( client_addr_id - 1 ))
452 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
453 $client_addr_id > /dev/null 2>&1
454 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
457 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
459 # RM_ADDR6 from the client to server machine
461 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\
462 $client_addr_id > /dev/null 2>&1
463 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns2 => ns1 \t"\
466 verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id"
468 # Capture events on the network namespace running the client
471 # RM_ADDR from the server to client machine
472 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
473 $server_addr_id > /dev/null 2>&1
474 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t"\
477 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
479 # RM_ADDR from the server to client machine
481 server_addr_id=$(( server_addr_id - 1 ))
482 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
483 $server_addr_id > /dev/null 2>&1
484 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t" $server_addr_id
486 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
488 # RM_ADDR6 from the server to client machine
490 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\
491 $server_addr_id > /dev/null 2>&1
492 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns1 => ns2 \t" $server_addr_id
494 verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id"
497 verify_subflow_events()
520 if [ "$e_type" = "$SUB_ESTABLISHED" ]
522 if [ "$e_family" = "$AF_INET6" ]
524 stdbuf -o0 -e0 printf "CREATE_SUBFLOW6 %s (%s) => %s (%s) "\
525 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
527 stdbuf -o0 -e0 printf "CREATE_SUBFLOW %s (%s) => %s (%s) \t"\
528 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
531 if [ "$e_family" = "$AF_INET6" ]
533 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW6 %s (%s) => %s (%s) "\
534 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
536 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW %s (%s) => %s (%s) \t"\
537 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
541 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
542 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
543 family=$(sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
544 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
545 locid=$(sed --unbuffered -n 's/.*\(loc_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
546 remid=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
547 if [ "$family" = "$AF_INET6" ]
549 saddr=$(sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
550 daddr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
552 saddr=$(sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
553 daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
556 check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid"
561 print_title "Subflows v4 or v6 only tests"
563 # Capture events on the network namespace running the server
566 # Attempt to add a listener at 10.0.2.2:<subflow-port>
567 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
568 "$client4_port" > /dev/null 2>&1 &
569 local listener_pid=$!
571 # ADD_ADDR from client to server machine reusing the subflow port
572 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
573 $client_addr_id > /dev/null 2>&1
576 # CREATE_SUBFLOW from server to client machine
578 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
579 rport "$client4_port" token "$server4_token" > /dev/null 2>&1
581 verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \
582 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
584 # Delete the listener from the client ns, if one was created
585 kill_wait $listener_pid
588 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
590 # DESTROY_SUBFLOW from server to client machine
592 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
593 "$client4_port" token "$server4_token" > /dev/null 2>&1
595 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
596 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
598 # RM_ADDR from client to server machine
599 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
600 "$client4_token" > /dev/null 2>&1
603 # Attempt to add a listener at dead:beef:2::2:<subflow-port>
604 ip netns exec "$ns2" ./pm_nl_ctl listen dead:beef:2::2\
605 "$client6_port" > /dev/null 2>&1 &
608 # ADD_ADDR6 from client to server machine reusing the subflow port
610 ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\
611 $client_addr_id > /dev/null 2>&1
614 # CREATE_SUBFLOW6 from server to client machine
616 ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\
617 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
619 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\
620 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
621 "$client_addr_id" "ns1" "ns2"
623 # Delete the listener from the client ns, if one was created
624 kill_wait $listener_pid
626 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
628 # DESTROY_SUBFLOW6 from server to client machine
630 ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\
631 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
633 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\
634 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
635 "$client_addr_id" "ns1" "ns2"
637 # RM_ADDR from client to server machine
638 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
639 "$client6_token" > /dev/null 2>&1
642 # Attempt to add a listener at 10.0.2.2:<new-port>
643 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
644 $new4_port > /dev/null 2>&1 &
647 # ADD_ADDR from client to server machine using a new port
649 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
650 $client_addr_id port $new4_port > /dev/null 2>&1
653 # CREATE_SUBFLOW from server to client machine
655 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\
656 $new4_port token "$server4_token" > /dev/null 2>&1
658 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\
659 "10.0.2.1" "10.0.2.2" "$new4_port" "23"\
660 "$client_addr_id" "ns1" "ns2"
662 # Delete the listener from the client ns, if one was created
663 kill_wait $listener_pid
665 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
667 # DESTROY_SUBFLOW from server to client machine
669 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
670 $new4_port token "$server4_token" > /dev/null 2>&1
672 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
673 "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2"
675 # RM_ADDR from client to server machine
676 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
677 "$client4_token" > /dev/null 2>&1
679 # Capture events on the network namespace running the client
682 # Attempt to add a listener at 10.0.2.1:<subflow-port>
683 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
684 $app4_port > /dev/null 2>&1 &
687 # ADD_ADDR from server to client machine reusing the subflow port
688 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
689 $server_addr_id > /dev/null 2>&1
692 # CREATE_SUBFLOW from client to server machine
694 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
695 $app4_port token "$client4_token" > /dev/null 2>&1
697 verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\
698 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
700 # Delete the listener from the server ns, if one was created
701 kill_wait $listener_pid
703 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
705 # DESTROY_SUBFLOW from client to server machine
707 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
708 $app4_port token "$client4_token" > /dev/null 2>&1
710 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
711 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
713 # RM_ADDR from server to client machine
714 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
715 "$server4_token" > /dev/null 2>&1
718 # Attempt to add a listener at dead:beef:2::1:<subflow-port>
719 ip netns exec "$ns1" ./pm_nl_ctl listen dead:beef:2::1\
720 $app6_port > /dev/null 2>&1 &
723 # ADD_ADDR6 from server to client machine reusing the subflow port
725 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
726 $server_addr_id > /dev/null 2>&1
729 # CREATE_SUBFLOW6 from client to server machine
731 ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\
732 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
734 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
735 "$AF_INET6" "dead:beef:2::2"\
736 "dead:beef:2::1" "$app6_port" "23"\
737 "$server_addr_id" "ns2" "ns1"
739 # Delete the listener from the server ns, if one was created
740 kill_wait $listener_pid
742 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
744 # DESTROY_SUBFLOW6 from client to server machine
746 ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\
747 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
749 verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\
750 "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1"
752 # RM_ADDR6 from server to client machine
753 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
754 "$server6_token" > /dev/null 2>&1
757 # Attempt to add a listener at 10.0.2.1:<new-port>
758 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
759 $new4_port > /dev/null 2>&1 &
762 # ADD_ADDR from server to client machine using a new port
764 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
765 $server_addr_id port $new4_port > /dev/null 2>&1
768 # CREATE_SUBFLOW from client to server machine
770 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
771 $new4_port token "$client4_token" > /dev/null 2>&1
773 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\
774 "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
776 # Delete the listener from the server ns, if one was created
777 kill_wait $listener_pid
779 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
781 # DESTROY_SUBFLOW from client to server machine
783 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
784 $new4_port token "$client4_token" > /dev/null 2>&1
786 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
787 "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
789 # RM_ADDR from server to client machine
790 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
791 "$server4_token" > /dev/null 2>&1
794 test_subflows_v4_v6_mix()
796 print_title "Subflows v4 and v6 mix tests"
798 # Attempt to add a listener at 10.0.2.1:<subflow-port>
799 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
800 $app6_port > /dev/null 2>&1 &
801 local listener_pid=$!
803 # ADD_ADDR4 from server to client machine reusing the subflow port on
804 # the established v6 connection
806 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server6_token" id\
807 $server_addr_id dev ns1eth2 > /dev/null 2>&1
808 stdbuf -o0 -e0 printf "ADD_ADDR4 id:%d 10.0.2.1 (ns1) => ns2, reuse port\t\t" $server_addr_id
810 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "10.0.2.1"\
811 "$server_addr_id" "$app6_port"
813 # CREATE_SUBFLOW from client to server machine
815 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
816 $app6_port token "$client6_token" > /dev/null 2>&1
818 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
819 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\
820 "$server_addr_id" "ns2" "ns1"
822 # Delete the listener from the server ns, if one was created
823 kill_wait $listener_pid
825 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
827 # DESTROY_SUBFLOW from client to server machine
829 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
830 $app6_port token "$client6_token" > /dev/null 2>&1
832 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client6_token" \
833 "$AF_INET" "10.0.2.2" "10.0.2.1" "$app6_port" "23"\
834 "$server_addr_id" "ns2" "ns1"
836 # RM_ADDR from server to client machine
837 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
838 "$server6_token" > /dev/null 2>&1
844 print_title "Prio tests"
848 # Send MP_PRIO signal from client to server machine
849 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 "$server4_port"
853 stdbuf -o0 -e0 printf "MP_PRIO TX \t"
854 count=$(ip netns exec "$ns2" nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
855 [ -z "$count" ] && count=0
856 if [ $count != 1 ]; then
857 stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
860 stdbuf -o0 -e0 printf "[OK]\n"
864 stdbuf -o0 -e0 printf "MP_PRIO RX \t"
865 count=$(ip netns exec "$ns1" nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
866 [ -z "$count" ] && count=0
867 if [ $count != 1 ]; then
868 stdbuf -o0 -e0 printf "[FAIL]\n\tCount != 1: %d\n" "${count}"
871 stdbuf -o0 -e0 printf "[OK]\n"
875 verify_listener_events()
887 if [ $e_type = $LISTENER_CREATED ]; then
888 stdbuf -o0 -e0 printf "CREATE_LISTENER %s:%s\t\t\t\t\t"\
890 elif [ $e_type = $LISTENER_CLOSED ]; then
891 stdbuf -o0 -e0 printf "CLOSE_LISTENER %s:%s\t\t\t\t\t"\
895 type=$(grep "type:$e_type," $evt |
896 sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
897 family=$(grep "type:$e_type," $evt |
898 sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
899 sport=$(grep "type:$e_type," $evt |
900 sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
901 if [ $family ] && [ $family = $AF_INET6 ]; then
902 saddr=$(grep "type:$e_type," $evt |
903 sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
905 saddr=$(grep "type:$e_type," $evt |
906 sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
909 check_expected "type" "family" "saddr" "sport"
914 print_title "Listener tests"
916 # Capture events on the network namespace running the client
919 # Attempt to add a listener at 10.0.2.2:<subflow-port>
920 ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\
921 $client4_port > /dev/null 2>&1 &
922 local listener_pid=$!
924 verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
926 # ADD_ADDR from client to server machine reusing the subflow port
927 ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\
928 $client_addr_id > /dev/null 2>&1
931 # CREATE_SUBFLOW from server to client machine
932 ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
933 rport $client4_port token $server4_token > /dev/null 2>&1
936 # Delete the listener from the client ns, if one was created
937 kill_wait $listener_pid
939 verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port
942 print_title "Make connections"
949 test_subflows_v4_v6_mix