selftests: mptcp: add pm_nl_set_endpoint helper
authorGeliang Tang <geliang.tang@suse.com>
Fri, 23 Jun 2023 17:34:13 +0000 (10:34 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 24 Jun 2023 22:37:57 +0000 (15:37 -0700)
This patch moves endpoint settings out of do_transfer() into a new
helper pm_nl_set_endpoint(). And invoke this helper in do_transfer().
This makes the code much more clearer.

Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230623-send-net-next-20230623-v1-7-a883213c8ba9@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_join.sh

index 5cb66f8..e6c9d54 100755 (executable)
@@ -822,122 +822,11 @@ pm_nl_check_endpoint()
        fi
 }
 
-do_transfer()
+pm_nl_set_endpoint()
 {
        local listener_ns="$1"
        local connector_ns="$2"
-       local cl_proto="$3"
-       local srv_proto="$4"
-       local connect_addr="$5"
-       local speed="$6"
-
-       local port=$((10000 + TEST_COUNT - 1))
-       local cappid
-
-       :> "$cout"
-       :> "$sout"
-       :> "$capout"
-
-       if [ $capture -eq 1 ]; then
-               local capuser
-               if [ -z $SUDO_USER ] ; then
-                       capuser=""
-               else
-                       capuser="-Z $SUDO_USER"
-               fi
-
-               capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
-
-               echo "Capturing traffic for test $TEST_COUNT into $capfile"
-               ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
-               cappid=$!
-
-               sleep 1
-       fi
-
-       NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
-               nstat -n
-       NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
-               nstat -n
-
-       local extra_args
-       if [ $speed = "fast" ]; then
-               extra_args="-j"
-       elif [ $speed = "slow" ]; then
-               extra_args="-r 50"
-       elif [[ $speed = "speed_"* ]]; then
-               extra_args="-r ${speed:6}"
-       fi
-
-       local flags="subflow"
-       local extra_cl_args=""
-       local extra_srv_args=""
-       local trunc_size=""
-       if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then
-               if [ ${test_linkfail} -le 1 ]; then
-                       echo "fastclose tests need test_linkfail argument"
-                       fail_test
-                       return 1
-               fi
-
-               # disconnect
-               trunc_size=${test_linkfail}
-               local side=${addr_nr_ns2:10}
-
-               if [ ${side} = "client" ]; then
-                       extra_cl_args="-f ${test_linkfail}"
-                       extra_srv_args="-f -1"
-               elif [ ${side} = "server" ]; then
-                       extra_srv_args="-f ${test_linkfail}"
-                       extra_cl_args="-f -1"
-               else
-                       echo "wrong/unknown fastclose spec ${side}"
-                       fail_test
-                       return 1
-               fi
-               addr_nr_ns2=0
-       elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
-               flags="${flags},fullmesh"
-               addr_nr_ns2=${addr_nr_ns2:9}
-       fi
-
-       extra_srv_args="$extra_args $extra_srv_args"
-       if [ "$test_linkfail" -gt 1 ];then
-               timeout ${timeout_test} \
-                       ip netns exec ${listener_ns} \
-                               ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
-                                       $extra_srv_args "::" < "$sinfail" > "$sout" &
-       else
-               timeout ${timeout_test} \
-                       ip netns exec ${listener_ns} \
-                               ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
-                                       $extra_srv_args "::" < "$sin" > "$sout" &
-       fi
-       local spid=$!
-
-       wait_local_port_listen "${listener_ns}" "${port}"
-
-       extra_cl_args="$extra_args $extra_cl_args"
-       if [ "$test_linkfail" -eq 0 ];then
-               timeout ${timeout_test} \
-                       ip netns exec ${connector_ns} \
-                               ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                                       $extra_cl_args $connect_addr < "$cin" > "$cout" &
-       elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then
-               ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
-                       tee "$cinsent" | \
-                       timeout ${timeout_test} \
-                               ip netns exec ${connector_ns} \
-                                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                                               $extra_cl_args $connect_addr > "$cout" &
-       else
-               tee "$cinsent" < "$cinfail" | \
-                       timeout ${timeout_test} \
-                               ip netns exec ${connector_ns} \
-                                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
-                                               $extra_cl_args $connect_addr > "$cout" &
-       fi
-       local cpid=$!
+       local connect_addr="$3"
 
        # let the mptcp subflow be established in background before
        # do endpoint manipulation
@@ -1077,6 +966,126 @@ do_transfer()
                        done
                done
        fi
+}
+
+do_transfer()
+{
+       local listener_ns="$1"
+       local connector_ns="$2"
+       local cl_proto="$3"
+       local srv_proto="$4"
+       local connect_addr="$5"
+       local speed="$6"
+
+       local port=$((10000 + TEST_COUNT - 1))
+       local cappid
+
+       :> "$cout"
+       :> "$sout"
+       :> "$capout"
+
+       if [ $capture -eq 1 ]; then
+               local capuser
+               if [ -z $SUDO_USER ] ; then
+                       capuser=""
+               else
+                       capuser="-Z $SUDO_USER"
+               fi
+
+               capfile=$(printf "mp_join-%02u-%s.pcap" "$TEST_COUNT" "${listener_ns}")
+
+               echo "Capturing traffic for test $TEST_COUNT into $capfile"
+               ip netns exec ${listener_ns} tcpdump -i any -s 65535 -B 32768 $capuser -w $capfile > "$capout" 2>&1 &
+               cappid=$!
+
+               sleep 1
+       fi
+
+       NSTAT_HISTORY=/tmp/${listener_ns}.nstat ip netns exec ${listener_ns} \
+               nstat -n
+       NSTAT_HISTORY=/tmp/${connector_ns}.nstat ip netns exec ${connector_ns} \
+               nstat -n
+
+       local extra_args
+       if [ $speed = "fast" ]; then
+               extra_args="-j"
+       elif [ $speed = "slow" ]; then
+               extra_args="-r 50"
+       elif [[ $speed = "speed_"* ]]; then
+               extra_args="-r ${speed:6}"
+       fi
+
+       local flags="subflow"
+       local extra_cl_args=""
+       local extra_srv_args=""
+       local trunc_size=""
+       if [[ "${addr_nr_ns2}" = "fastclose_"* ]]; then
+               if [ ${test_linkfail} -le 1 ]; then
+                       echo "fastclose tests need test_linkfail argument"
+                       fail_test
+                       return 1
+               fi
+
+               # disconnect
+               trunc_size=${test_linkfail}
+               local side=${addr_nr_ns2:10}
+
+               if [ ${side} = "client" ]; then
+                       extra_cl_args="-f ${test_linkfail}"
+                       extra_srv_args="-f -1"
+               elif [ ${side} = "server" ]; then
+                       extra_srv_args="-f ${test_linkfail}"
+                       extra_cl_args="-f -1"
+               else
+                       echo "wrong/unknown fastclose spec ${side}"
+                       fail_test
+                       return 1
+               fi
+               addr_nr_ns2=0
+       elif [[ "${addr_nr_ns2}" = "fullmesh_"* ]]; then
+               flags="${flags},fullmesh"
+               addr_nr_ns2=${addr_nr_ns2:9}
+       fi
+
+       extra_srv_args="$extra_args $extra_srv_args"
+       if [ "$test_linkfail" -gt 1 ];then
+               timeout ${timeout_test} \
+                       ip netns exec ${listener_ns} \
+                               ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
+                                       $extra_srv_args "::" < "$sinfail" > "$sout" &
+       else
+               timeout ${timeout_test} \
+                       ip netns exec ${listener_ns} \
+                               ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
+                                       $extra_srv_args "::" < "$sin" > "$sout" &
+       fi
+       local spid=$!
+
+       wait_local_port_listen "${listener_ns}" "${port}"
+
+       extra_cl_args="$extra_args $extra_cl_args"
+       if [ "$test_linkfail" -eq 0 ];then
+               timeout ${timeout_test} \
+                       ip netns exec ${connector_ns} \
+                               ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                                       $extra_cl_args $connect_addr < "$cin" > "$cout" &
+       elif [ "$test_linkfail" -eq 1 ] || [ "$test_linkfail" -eq 2 ];then
+               ( cat "$cinfail" ; sleep 2; link_failure $listener_ns ; cat "$cinfail" ) | \
+                       tee "$cinsent" | \
+                       timeout ${timeout_test} \
+                               ip netns exec ${connector_ns} \
+                                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                                               $extra_cl_args $connect_addr > "$cout" &
+       else
+               tee "$cinsent" < "$cinfail" | \
+                       timeout ${timeout_test} \
+                               ip netns exec ${connector_ns} \
+                                       ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \
+                                               $extra_cl_args $connect_addr > "$cout" &
+       fi
+       local cpid=$!
+
+       pm_nl_set_endpoint $listener_ns $connector_ns $connect_addr
 
        wait $cpid
        local retc=$?