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 kill $1 > /dev/null 2>&1
56 rm -rf $file $client_evts $server_evts
58 # Terminate the MPTCP connection and related processes
59 if [ $client4_pid -ne 0 ]; then
60 kill -SIGUSR1 $client4_pid > /dev/null 2>&1
62 if [ $server4_pid -ne 0 ]; then
63 kill_wait $server4_pid
65 if [ $client6_pid -ne 0 ]; then
66 kill -SIGUSR1 $client6_pid > /dev/null 2>&1
68 if [ $server6_pid -ne 0 ]; then
69 kill_wait $server6_pid
71 if [ $server_evts_pid -ne 0 ]; then
72 kill_wait $server_evts_pid
74 if [ $client_evts_pid -ne 0 ]; then
75 kill_wait $client_evts_pid
78 for netns in "$ns1" "$ns2" ;do
85 # Create and configure network namespaces for testing
86 for i in "$ns1" "$ns2" ;do
87 ip netns add "$i" || exit 1
88 ip -net "$i" link set lo up
89 ip netns exec "$i" sysctl -q net.mptcp.enabled=1
90 ip netns exec "$i" sysctl -q net.mptcp.pm_type=1
96 ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
98 # Add IPv4/v6 addresses to the namespaces
99 ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2
100 ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2
101 ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
102 ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad
103 ip -net "$ns1" link set ns1eth2 up
105 ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
106 ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth1
107 ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
108 ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth1 nodad
109 ip -net "$ns2" link set ns2eth1 up
111 stdbuf -o0 -e0 printf "Created network namespaces ns1, ns2 \t\t\t[OK]\n"
115 # Store a chunk of data in a file to transmit over an MPTCP connection
119 dd if=/dev/urandom of="$name" bs=2 count=$ksize 2> /dev/null
120 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
125 if [ -z "$file" ]; then
128 make_file "$file" "client"
131 local app_port=$app4_port
132 local connect_addr="10.0.1.1"
133 local listen_addr="0.0.0.0"
134 if [ "$is_v6" = "v6" ]
136 connect_addr="dead:beef:1::1"
143 # Capture netlink events over the two network namespaces running
144 # the MPTCP client and server
145 if [ -z "$client_evts" ]; then
146 client_evts=$(mktemp)
149 if [ $client_evts_pid -ne 0 ]; then
150 kill_wait $client_evts_pid
152 ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
154 if [ -z "$server_evts" ]; then
155 server_evts=$(mktemp)
158 if [ $server_evts_pid -ne 0 ]; then
159 kill_wait $server_evts_pid
161 ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
166 ip netns exec "$ns1" \
167 ./mptcp_connect -s MPTCP -w 300 -p $app_port -l $listen_addr > /dev/null 2>&1 &
171 # Run the client, transfer $file and stay connected to the server
173 ip netns exec "$ns2" \
174 ./mptcp_connect -s MPTCP -w 300 -m sendfile -p $app_port $connect_addr\
175 2>&1 > /dev/null < "$file" &
179 # Capture client/server attributes from MPTCP connection netlink events
183 local client_serverside
185 local server_serverside
187 client_token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
188 client_port=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
189 client_serverside=$(sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q'\
191 server_token=$(grep "type:1," "$server_evts" |
192 sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q')
193 server_serverside=$(grep "type:1," "$server_evts" |
194 sed --unbuffered -n 's/.*\(server_side:\)\([[:digit:]]*\).*$/\2/p;q')
196 if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
197 [ "$server_serverside" = 1 ]
199 stdbuf -o0 -e0 printf "Established IP%s MPTCP Connection ns2 => ns1 \t\t[OK]\n" $is_v6
204 if [ "$is_v6" = "v6" ]
206 client6_token=$client_token
207 server6_token=$server_token
208 client6_port=$client_port
209 client6_pid=$client_pid
210 server6_pid=$server_pid
212 client4_token=$client_token
213 server4_token=$server_token
214 client4_port=$client_port
215 client4_pid=$client_pid
216 server4_pid=$server_pid
220 verify_announce_event()
235 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
236 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
237 if [ "$e_af" = "v6" ]
239 addr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
241 addr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
243 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
244 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
245 if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
246 [ "$addr" = "$e_addr" ] && [ "$dport" = "$e_dport" ] &&
249 stdbuf -o0 -e0 printf "[OK]\n"
252 stdbuf -o0 -e0 printf "[FAIL]\n"
258 # Capture events on the network namespace running the server
261 # ADD_ADDR using an invalid token should result in no action
262 local invalid_token=$(( client4_token - 1))
263 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token $invalid_token id\
264 $client_addr_id dev ns2eth1 > /dev/null 2>&1
267 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
268 stdbuf -o0 -e0 printf "ADD_ADDR 10.0.2.2 (ns2) => ns1, invalid token \t\t"
271 stdbuf -o0 -e0 printf "[OK]\n"
273 stdbuf -o0 -e0 printf "[FAIL]\n"
277 # ADD_ADDR from the client to server machine reusing the subflow port
279 ip netns exec "$ns2"\
280 ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id $client_addr_id dev\
281 ns2eth1 > /dev/null 2>&1
282 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, reuse port \t\t" $client_addr_id
284 verify_announce_event $server_evts $ANNOUNCED $server4_token "10.0.2.2" $client_addr_id \
287 # ADD_ADDR6 from the client to server machine reusing the subflow port
289 ip netns exec "$ns2" ./pm_nl_ctl ann\
290 dead:beef:2::2 token "$client6_token" id $client_addr_id dev ns2eth1 > /dev/null 2>&1
291 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::2 (ns2) => ns1, reuse port\t\t" $client_addr_id
293 verify_announce_event "$server_evts" "$ANNOUNCED" "$server6_token" "dead:beef:2::2"\
294 "$client_addr_id" "$client6_port" "v6"
296 # ADD_ADDR from the client to server machine using a new port
298 client_addr_id=$((client_addr_id+1))
299 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
300 $client_addr_id dev ns2eth1 port $new4_port > /dev/null 2>&1
301 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.2 (ns2) => ns1, new port \t\t\t" $client_addr_id
303 verify_announce_event "$server_evts" "$ANNOUNCED" "$server4_token" "10.0.2.2"\
304 "$client_addr_id" "$new4_port"
306 # Capture events on the network namespace running the client
309 # ADD_ADDR from the server to client machine reusing the subflow port
310 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
311 $server_addr_id dev ns1eth2 > /dev/null 2>&1
312 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, reuse port \t\t" $server_addr_id
314 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
315 "$server_addr_id" "$app4_port"
317 # ADD_ADDR6 from the server to client machine reusing the subflow port
319 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
320 $server_addr_id dev ns1eth2 > /dev/null 2>&1
321 stdbuf -o0 -e0 printf "ADD_ADDR6 id:%d dead:beef:2::1 (ns1) => ns2, reuse port\t\t" $server_addr_id
323 verify_announce_event "$client_evts" "$ANNOUNCED" "$client6_token" "dead:beef:2::1"\
324 "$server_addr_id" "$app6_port" "v6"
326 # ADD_ADDR from the server to client machine using a new port
328 server_addr_id=$((server_addr_id+1))
329 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
330 $server_addr_id dev ns1eth2 port $new4_port > /dev/null 2>&1
331 stdbuf -o0 -e0 printf "ADD_ADDR id:%d 10.0.2.1 (ns1) => ns2, new port \t\t\t" $server_addr_id
333 verify_announce_event "$client_evts" "$ANNOUNCED" "$client4_token" "10.0.2.1"\
334 "$server_addr_id" "$new4_port"
337 verify_remove_event()
347 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
348 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
349 id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
350 if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
353 stdbuf -o0 -e0 printf "[OK]\n"
356 stdbuf -o0 -e0 printf "[FAIL]\n"
362 # Capture events on the network namespace running the server
365 # RM_ADDR using an invalid token should result in no action
366 local invalid_token=$(( client4_token - 1 ))
367 ip netns exec "$ns2" ./pm_nl_ctl rem token $invalid_token id\
368 $client_addr_id > /dev/null 2>&1
369 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid token \t"\
372 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
375 stdbuf -o0 -e0 printf "[OK]\n"
377 stdbuf -o0 -e0 printf "[FAIL]\n"
380 # RM_ADDR using an invalid addr id should result in no action
381 local invalid_id=$(( client_addr_id + 1 ))
382 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
383 $invalid_id > /dev/null 2>&1
384 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1, invalid id \t"\
386 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
389 stdbuf -o0 -e0 printf "[OK]\n"
391 stdbuf -o0 -e0 printf "[FAIL]\n"
394 # RM_ADDR from the client to server machine
396 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
397 $client_addr_id > /dev/null 2>&1
398 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
401 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
403 # RM_ADDR from the client to server machine
405 client_addr_id=$(( client_addr_id - 1 ))
406 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client4_token" id\
407 $client_addr_id > /dev/null 2>&1
408 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns2 => ns1 \t"\
411 verify_remove_event "$server_evts" "$REMOVED" "$server4_token" "$client_addr_id"
413 # RM_ADDR6 from the client to server machine
415 ip netns exec "$ns2" ./pm_nl_ctl rem token "$client6_token" id\
416 $client_addr_id > /dev/null 2>&1
417 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns2 => ns1 \t"\
420 verify_remove_event "$server_evts" "$REMOVED" "$server6_token" "$client_addr_id"
422 # Capture events on the network namespace running the client
425 # RM_ADDR from the server to client machine
426 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
427 $server_addr_id > /dev/null 2>&1
428 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t"\
431 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
433 # RM_ADDR from the server to client machine
435 server_addr_id=$(( server_addr_id - 1 ))
436 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server4_token" id\
437 $server_addr_id > /dev/null 2>&1
438 stdbuf -o0 -e0 printf "RM_ADDR id:%d ns1 => ns2 \t" $server_addr_id
440 verify_remove_event "$client_evts" "$REMOVED" "$client4_token" "$server_addr_id"
442 # RM_ADDR6 from the server to client machine
444 ip netns exec "$ns1" ./pm_nl_ctl rem token "$server6_token" id\
445 $server_addr_id > /dev/null 2>&1
446 stdbuf -o0 -e0 printf "RM_ADDR6 id:%d ns1 => ns2 \t" $server_addr_id
448 verify_remove_event "$client_evts" "$REMOVED" "$client6_token" "$server_addr_id"
451 verify_subflow_events()
474 if [ "$e_type" = "$SUB_ESTABLISHED" ]
476 if [ "$e_family" = "$AF_INET6" ]
478 stdbuf -o0 -e0 printf "CREATE_SUBFLOW6 %s (%s) => %s (%s) "\
479 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
481 stdbuf -o0 -e0 printf "CREATE_SUBFLOW %s (%s) => %s (%s) \t"\
482 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
485 if [ "$e_family" = "$AF_INET6" ]
487 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW6 %s (%s) => %s (%s) "\
488 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
490 stdbuf -o0 -e0 printf "DESTROY_SUBFLOW %s (%s) => %s (%s) \t"\
491 "$e_saddr" "$e_from" "$e_daddr" "$e_to"
495 type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
496 token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
497 family=$(sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
498 dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
499 locid=$(sed --unbuffered -n 's/.*\(loc_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
500 remid=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
501 if [ "$family" = "$AF_INET6" ]
503 saddr=$(sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
504 daddr=$(sed --unbuffered -n 's/.*\(daddr6:\)\([0-9a-f:.]*\).*$/\2/p;q' "$evt")
506 saddr=$(sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
507 daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
510 if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
511 [ "$daddr" = "$e_daddr" ] && [ "$e_dport" = "$dport" ] &&
512 [ "$family" = "$e_family" ] && [ "$saddr" = "$e_saddr" ] &&
513 [ "$e_locid" = "$locid" ] && [ "$e_remid" = "$remid" ]
515 stdbuf -o0 -e0 printf "[OK]\n"
518 stdbuf -o0 -e0 printf "[FAIL]\n"
524 # Capture events on the network namespace running the server
527 # Attempt to add a listener at 10.0.2.2:<subflow-port>
528 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
529 "$client4_port" > /dev/null 2>&1 &
530 local listener_pid=$!
532 # ADD_ADDR from client to server machine reusing the subflow port
533 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
534 $client_addr_id > /dev/null 2>&1
537 # CREATE_SUBFLOW from server to client machine
539 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
540 rport "$client4_port" token "$server4_token" > /dev/null 2>&1
542 verify_subflow_events $server_evts $SUB_ESTABLISHED $server4_token $AF_INET "10.0.2.1" \
543 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
545 # Delete the listener from the client ns, if one was created
546 kill_wait $listener_pid
549 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
551 # DESTROY_SUBFLOW from server to client machine
553 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
554 "$client4_port" token "$server4_token" > /dev/null 2>&1
556 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
557 "10.0.2.2" "$client4_port" "23" "$client_addr_id" "ns1" "ns2"
559 # RM_ADDR from client to server machine
560 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
561 "$client4_token" > /dev/null 2>&1
564 # Attempt to add a listener at dead:beef:2::2:<subflow-port>
565 ip netns exec "$ns2" ./pm_nl_ctl listen dead:beef:2::2\
566 "$client6_port" > /dev/null 2>&1 &
569 # ADD_ADDR6 from client to server machine reusing the subflow port
571 ip netns exec "$ns2" ./pm_nl_ctl ann dead:beef:2::2 token "$client6_token" id\
572 $client_addr_id > /dev/null 2>&1
575 # CREATE_SUBFLOW6 from server to client machine
577 ip netns exec "$ns1" ./pm_nl_ctl csf lip dead:beef:2::1 lid 23 rip\
578 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
580 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server6_token" "$AF_INET6"\
581 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
582 "$client_addr_id" "ns1" "ns2"
584 # Delete the listener from the client ns, if one was created
585 kill_wait $listener_pid
587 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$server_evts")
589 # DESTROY_SUBFLOW6 from server to client machine
591 ip netns exec "$ns1" ./pm_nl_ctl dsf lip dead:beef:2::1 lport "$sport" rip\
592 dead:beef:2::2 rport "$client6_port" token "$server6_token" > /dev/null 2>&1
594 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server6_token" "$AF_INET6"\
595 "dead:beef:2::1" "dead:beef:2::2" "$client6_port" "23"\
596 "$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 "$client6_token" > /dev/null 2>&1
603 # Attempt to add a listener at 10.0.2.2:<new-port>
604 ip netns exec "$ns2" ./pm_nl_ctl listen 10.0.2.2\
605 $new4_port > /dev/null 2>&1 &
608 # ADD_ADDR from client to server machine using a new port
610 ip netns exec "$ns2" ./pm_nl_ctl ann 10.0.2.2 token "$client4_token" id\
611 $client_addr_id port $new4_port > /dev/null 2>&1
614 # CREATE_SUBFLOW from server to client machine
616 ip netns exec "$ns1" ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2 rport\
617 $new4_port token "$server4_token" > /dev/null 2>&1
619 verify_subflow_events "$server_evts" "$SUB_ESTABLISHED" "$server4_token" "$AF_INET"\
620 "10.0.2.1" "10.0.2.2" "$new4_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_SUBFLOW from server to client machine
630 ip netns exec "$ns1" ./pm_nl_ctl dsf lip 10.0.2.1 lport "$sport" rip 10.0.2.2 rport\
631 $new4_port token "$server4_token" > /dev/null 2>&1
633 verify_subflow_events "$server_evts" "$SUB_CLOSED" "$server4_token" "$AF_INET" "10.0.2.1"\
634 "10.0.2.2" "$new4_port" "23" "$client_addr_id" "ns1" "ns2"
636 # RM_ADDR from client to server machine
637 ip netns exec "$ns2" ./pm_nl_ctl rem id $client_addr_id token\
638 "$client4_token" > /dev/null 2>&1
640 # Capture events on the network namespace running the client
643 # Attempt to add a listener at 10.0.2.1:<subflow-port>
644 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
645 $app4_port > /dev/null 2>&1 &
648 # ADD_ADDR from server to client machine reusing the subflow port
649 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
650 $server_addr_id > /dev/null 2>&1
653 # CREATE_SUBFLOW from client to server machine
655 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
656 $app4_port token "$client4_token" > /dev/null 2>&1
658 verify_subflow_events $client_evts $SUB_ESTABLISHED $client4_token $AF_INET "10.0.2.2"\
659 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
661 # Delete the listener from the server ns, if one was created
662 kill_wait $listener_pid
664 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
666 # DESTROY_SUBFLOW from client to server machine
668 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
669 $app4_port token "$client4_token" > /dev/null 2>&1
671 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
672 "10.0.2.1" "$app4_port" "23" "$server_addr_id" "ns2" "ns1"
674 # RM_ADDR from server to client machine
675 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
676 "$server4_token" > /dev/null 2>&1
679 # Attempt to add a listener at dead:beef:2::1:<subflow-port>
680 ip netns exec "$ns1" ./pm_nl_ctl listen dead:beef:2::1\
681 $app6_port > /dev/null 2>&1 &
684 # ADD_ADDR6 from server to client machine reusing the subflow port
686 ip netns exec "$ns1" ./pm_nl_ctl ann dead:beef:2::1 token "$server6_token" id\
687 $server_addr_id > /dev/null 2>&1
690 # CREATE_SUBFLOW6 from client to server machine
692 ip netns exec "$ns2" ./pm_nl_ctl csf lip dead:beef:2::2 lid 23 rip\
693 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
695 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client6_token"\
696 "$AF_INET6" "dead:beef:2::2"\
697 "dead:beef:2::1" "$app6_port" "23"\
698 "$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_SUBFLOW6 from client to server machine
707 ip netns exec "$ns2" ./pm_nl_ctl dsf lip dead:beef:2::2 lport "$sport" rip\
708 dead:beef:2::1 rport $app6_port token "$client6_token" > /dev/null 2>&1
710 verify_subflow_events $client_evts $SUB_CLOSED $client6_token $AF_INET6 "dead:beef:2::2"\
711 "dead:beef:2::1" "$app6_port" "23" "$server_addr_id" "ns2" "ns1"
713 # RM_ADDR6 from server to client machine
714 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
715 "$server6_token" > /dev/null 2>&1
718 # Attempt to add a listener at 10.0.2.1:<new-port>
719 ip netns exec "$ns1" ./pm_nl_ctl listen 10.0.2.1\
720 $new4_port > /dev/null 2>&1 &
723 # ADD_ADDR from server to client machine using a new port
725 ip netns exec "$ns1" ./pm_nl_ctl ann 10.0.2.1 token "$server4_token" id\
726 $server_addr_id port $new4_port > /dev/null 2>&1
729 # CREATE_SUBFLOW from client to server machine
731 ip netns exec "$ns2" ./pm_nl_ctl csf lip 10.0.2.2 lid 23 rip 10.0.2.1 rport\
732 $new4_port token "$client4_token" > /dev/null 2>&1
734 verify_subflow_events "$client_evts" "$SUB_ESTABLISHED" "$client4_token" "$AF_INET"\
735 "10.0.2.2" "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
737 # Delete the listener from the server ns, if one was created
738 kill_wait $listener_pid
740 sport=$(sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q' "$client_evts")
742 # DESTROY_SUBFLOW from client to server machine
744 ip netns exec "$ns2" ./pm_nl_ctl dsf lip 10.0.2.2 lport "$sport" rip 10.0.2.1 rport\
745 $new4_port token "$client4_token" > /dev/null 2>&1
747 verify_subflow_events "$client_evts" "$SUB_CLOSED" "$client4_token" "$AF_INET" "10.0.2.2"\
748 "10.0.2.1" "$new4_port" "23" "$server_addr_id" "ns2" "ns1"
750 # RM_ADDR from server to client machine
751 ip netns exec "$ns1" ./pm_nl_ctl rem id $server_addr_id token\
752 "$server4_token" > /dev/null 2>&1
759 # Send MP_PRIO signal from client to server machine
760 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"
764 stdbuf -o0 -e0 printf "MP_PRIO TX \t"
765 count=$(ip netns exec "$ns2" nstat -as | grep MPTcpExtMPPrioTx | awk '{print $2}')
766 [ -z "$count" ] && count=0
767 if [ $count != 1 ]; then
768 stdbuf -o0 -e0 printf "[FAIL]\n"
771 stdbuf -o0 -e0 printf "[OK]\n"
775 stdbuf -o0 -e0 printf "MP_PRIO RX \t"
776 count=$(ip netns exec "$ns1" nstat -as | grep MPTcpExtMPPrioRx | awk '{print $2}')
777 [ -z "$count" ] && count=0
778 if [ $count != 1 ]; then
779 stdbuf -o0 -e0 printf "[FAIL]\n"
782 stdbuf -o0 -e0 printf "[OK]\n"
786 verify_listener_events()
798 if [ $e_type = $LISTENER_CREATED ]; then
799 stdbuf -o0 -e0 printf "CREATE_LISTENER %s:%s\t\t\t\t\t"\
801 elif [ $e_type = $LISTENER_CLOSED ]; then
802 stdbuf -o0 -e0 printf "CLOSE_LISTENER %s:%s\t\t\t\t\t"\
806 type=$(grep "type:$e_type," $evt |
807 sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
808 family=$(grep "type:$e_type," $evt |
809 sed --unbuffered -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
810 sport=$(grep "type:$e_type," $evt |
811 sed --unbuffered -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
812 if [ $family ] && [ $family = $AF_INET6 ]; then
813 saddr=$(grep "type:$e_type," $evt |
814 sed --unbuffered -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
816 saddr=$(grep "type:$e_type," $evt |
817 sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
820 if [ $type ] && [ $type = $e_type ] &&
821 [ $family ] && [ $family = $e_family ] &&
822 [ $saddr ] && [ $saddr = $e_saddr ] &&
823 [ $sport ] && [ $sport = $e_sport ]; then
824 stdbuf -o0 -e0 printf "[OK]\n"
827 stdbuf -o0 -e0 printf "[FAIL]\n"
833 # Capture events on the network namespace running the client
836 # Attempt to add a listener at 10.0.2.2:<subflow-port>
837 ip netns exec $ns2 ./pm_nl_ctl listen 10.0.2.2\
838 $client4_port > /dev/null 2>&1 &
839 local listener_pid=$!
841 verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
843 # ADD_ADDR from client to server machine reusing the subflow port
844 ip netns exec $ns2 ./pm_nl_ctl ann 10.0.2.2 token $client4_token id\
845 $client_addr_id > /dev/null 2>&1
848 # CREATE_SUBFLOW from server to client machine
849 ip netns exec $ns1 ./pm_nl_ctl csf lip 10.0.2.1 lid 23 rip 10.0.2.2\
850 rport $client4_port token $server4_token > /dev/null 2>&1
853 # Delete the listener from the client ns, if one was created
854 kill_wait $listener_pid
856 verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port