Skip to contentSkip to conversation

add helpers and vars in mptcp_lib.sh, final

PATCH In review Geliang Tang 3 participants 16 messages Mar 19, 2024

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v4 cover add helpers and vars in mptcp_lib.sh, final

From: Geliang Tang <[email protected]>

v4:
- address every Matt's commends in v3.

v3:
- use check_output in pm_nl_check_endpoint.
- split #2 and #7 patches in v2.
- put "selftests: mptcp: join: fix dev in check_endpoint" into this series too.

v2:
- address every Matt's commends in v1.
- depends on "selftests: mptcp: join: fix dev in check_endpoint"

This is the last part for "add helpers and vars in mptcp_lib.sh" series, add endpoint operation helpers into mptcp_lib.sh.

Geliang Tang (9):
selftests: mptcp: export ip_mptcp to mptcp_lib
selftests: mptcp: add get_limits helper
selftests: mptcp: add get_endpoint helper
selftests: mptcp: add change_address helper
selftests: mptcp: join: update endpoint ops
selftests: mptcp: export pm_nl endpoint ops
selftests: mptcp: use pm_nl endpoint ops
selftests: mptcp: ip_mptcp option for more scripts
selftests: mptcp: netlink: drop disable=SC2086

 .../testing/selftests/net/mptcp/mptcp_join.sh | 147 ++-------
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 128 ++++++++
 .../selftests/net/mptcp/mptcp_sockopt.sh      |  34 +-
 .../testing/selftests/net/mptcp/pm_netlink.sh | 294 +++++++++++-------
 .../selftests/net/mptcp/simult_flows.sh       |  14 +-
 5 files changed, 366 insertions(+), 251 deletions(-)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH v4 1/9 selftests: mptcp: export ip_mptcp to mptcp_lib

From: Geliang Tang <[email protected]>

This patch exports ip_mptcp into mptcp_lib.sh as a public variable, named MPTCP_LIB_IP_MPTCP. Add a helper mptcp_lib_set_ip_mptcp() to set it, and a helper mptcp_lib_is_ip_mptcp() to test whether it is set. Use these two helpers in mptcp_join.sh.

This patch is prepared for coming commits.

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 17 ++++++++---------
 tools/testing/selftests/net/mptcp/mptcp_lib.sh  |  9 +++++++++
 2 files changed, 17 insertions(+), 9 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +8 -9
index 73a2131e6da2..62fcfeaa3430 100755
@@ -31,7 +31,6 @@ timeout_poll=30
 timeout_test=$((timeout_poll * 2 + 1))
 capture=false
 checksum=false
-ip_mptcp=0
 check_invert=0
 validate_checksum=false
 init=0
@@ -610,7 +609,7 @@ pm_nl_set_limits()
 	local addrs=$2
 	local subflows=$3
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
 	else
 		ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
@@ -650,7 +649,7 @@ pm_nl_add_endpoint()
 		nr=$((nr + 1))
 	done
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
 	else
 		ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
@@ -663,7 +662,7 @@ pm_nl_del_endpoint()
 	local id=$2
 	local addr=$3
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		[ $id -ne 0 ] && addr=''
 		ip -n $ns mptcp endpoint delete id $id $addr
 	else
@@ -675,7 +674,7 @@ pm_nl_flush_endpoint()
 {
 	local ns=$1
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		ip -n $ns mptcp endpoint flush
 	else
 		ip netns exec $ns ./pm_nl_ctl flush
@@ -686,7 +685,7 @@ pm_nl_show_endpoints()
 {
 	local ns=$1
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		ip -n $ns mptcp endpoint show
 	else
 		ip netns exec $ns ./pm_nl_ctl dump
@@ -699,7 +698,7 @@ pm_nl_change_endpoint()
 	local id=$2
 	local flags=$3
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
 	else
 		ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
@@ -749,7 +748,7 @@ pm_nl_check_endpoint()
 		return
 	fi
 
-	if [ $ip_mptcp -eq 1 ]; then
+	if mptcp_lib_is_ip_mptcp; then
 		# get line and trim trailing whitespace
 		line=$(ip -n $ns mptcp endpoint show $id)
 		line="${line% }"
@@ -3702,7 +3701,7 @@ while getopts "${all_tests_args}cCih" opt; do
 			checksum=true
 			;;
 		i)
-			ip_mptcp=1
+			mptcp_lib_set_ip_mptcp
 			;;
 		h)
 			usage
tools/testing/selftests/net/mptcp/mptcp_lib.sh +9 -0
index 1fa05405f65e..ca01d949fad8 100644
@@ -23,6 +23,7 @@ MPTCP_LIB_SUBTESTS=()
 MPTCP_LIB_SUBTESTS_DUPLICATED=0
 MPTCP_LIB_TEST_COUNTER=0
 MPTCP_LIB_TEST_FORMAT="%02u %-50s"
+MPTCP_LIB_IP_MPTCP=0
 
 # only if supported (or forced) and not disabled, see no-color.org
 if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
@@ -511,3 +512,11 @@ mptcp_lib_verify_listener_events() {
 	mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}"
 	return "${rc}"
 }
+
+mptcp_lib_set_ip_mptcp() {
+	MPTCP_LIB_IP_MPTCP=1
+}
+
+mptcp_lib_is_ip_mptcp() {
+	[ "${MPTCP_LIB_IP_MPTCP}" = "1" ]
+}
Signature · 1 line
2.40.1
author reviewer
#2 lore raw

PATCH v4 2/9 selftests: mptcp: add get_limits helper

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

The output format of 'ip mptcp limits' command is much different from that of 'pm_nl_ctl limits' command. This patch adds format_limits() helper to format the outputs of these two commands to hide the difference.

Just like set_limits() helper, add another one get_limits() to show the limits.

Use these two helpers in pm_netlink.sh to replace all 'pm_nl_ctl limits' commands and outputs.

---
 .../testing/selftests/net/mptcp/pm_netlink.sh | 32 +++++++++++++++----
 1 file changed, 25 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/pm_netlink.sh +25 -7
index 6ab8c5d36340..d672d1e5d470 100755
@@ -46,6 +46,26 @@ trap cleanup EXIT
 
 mptcp_lib_ns_init ns1
 
+format_limits() {
+	local accept="${1}"
+	local subflows="${2}"
+
+	if mptcp_lib_is_ip_mptcp; then
+		# with a space at the end
+		printf "add_addr_accepted %d subflows %d \n" "${accept}" "${subflows}"
+	else
+		printf "accept %d\nsubflows %d\n" "${accept}" "${subflows}"
+	fi
+}
+
+get_limits() {
+	if mptcp_lib_is_ip_mptcp; then
+		ip -n "${ns1}" mptcp limits
+	else
+		ip netns exec "${ns1}" ./pm_nl_ctl limits
+	fi
+}
+
 check()
 {
 	local cmd="$1"
@@ -69,10 +89,9 @@ check()
 
 check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "defaults addr list"
 
-default_limits="$(ip netns exec $ns1 ./pm_nl_ctl limits)"
+default_limits="$(get_limits)"
 if mptcp_lib_expect_all_features; then
-	check "ip netns exec $ns1 ./pm_nl_ctl limits" "accept 0
-subflows 2" "defaults limits"
+	check "get_limits" "$(format_limits 0 2)" "defaults limits"
 fi
 
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1
@@ -120,14 +139,13 @@ ip netns exec $ns1 ./pm_nl_ctl flush
 check "ip netns exec $ns1 ./pm_nl_ctl dump" "" "flush addrs"
 
 ip netns exec $ns1 ./pm_nl_ctl limits 9 1 2>/dev/null
-check "ip netns exec $ns1 ./pm_nl_ctl limits" "$default_limits" "rcv addrs above hard limit"
+check "get_limits" "${default_limits}" "rcv addrs above hard limit"
 
 ip netns exec $ns1 ./pm_nl_ctl limits 1 9 2>/dev/null
-check "ip netns exec $ns1 ./pm_nl_ctl limits" "$default_limits" "subflows above hard limit"
+check "get_limits" "${default_limits}" "subflows above hard limit"
 
 ip netns exec $ns1 ./pm_nl_ctl limits 8 8
-check "ip netns exec $ns1 ./pm_nl_ctl limits" "accept 8
-subflows 8" "set limits"
+check "get_limits" "$(format_limits 8 8)" "set limits"
 
 ip netns exec $ns1 ./pm_nl_ctl flush
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1
Signature · 1 line
2.40.1
maintainer
#3 lore raw

Re: [PATCH mptcp-next v4 2/9] selftests: mptcp: add get_limits helper

Hi Geliang,

Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

The output format of 'ip mptcp limits' command is much different from that of 'pm_nl_ctl limits' command. This patch adds format_limits() helper to format the outputs of these two commands to hide the difference.

Just like set_limits() helper, add another one get_limits() to show the limits.

There is no 'set_limits()' helper.

Quoted 2 lines

Use these two helpers in pm_netlink.sh to replace all 'pm_nl_ctl limits' commands and outputs.

(...)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#4 lore raw

PATCH v4 3/9 selftests: mptcp: add get_endpoint helper

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

The output formats of 'ip mptcp' commands are much different from that of 'pm_nl_ctl' commands. This patch adds a new helper format_endpoints() to format the outputs of 'ip mptcp' and 'pm_nl_ctl' with 'endpoints' arguments to hide these differences.

All endpoints are showed in show_endpoints(). Here add another helper named get_endpoint() to show a specofic endpoint identified by the given address ID.

Usage:
All endpoints - show_endpoints $ns
One endpoint - get_endpoint $ns $id

Use these two helpers in mptcp_join.sh and pm_netlink.sh to replace all 'pm_nl_ctl get' commands and outputs of 'pm_nl_ctl dump/get'.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh |  32 +-----
 .../testing/selftests/net/mptcp/mptcp_lib.sh  |  34 ++++++
 .../testing/selftests/net/mptcp/pm_netlink.sh | 101 ++++++++++--------
 3 files changed, 96 insertions(+), 71 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +5 -27
index 62fcfeaa3430..d48da81daa06 100755
@@ -712,12 +712,9 @@ pm_nl_check_endpoint()
 	local ns=$2
 	local addr=$3
 	local _flags=""
-	local flags
 	local _port
-	local port
 	local dev
 	local _id
-	local id
 
 	print_check "${msg}"
 
@@ -725,48 +722,29 @@ pm_nl_check_endpoint()
 	while [ -n "$1" ]; do
 		if [ $1 = "flags" ]; then
 			_flags=$2
-			[ -n "$_flags" ]; flags="flags $_flags"
 			shift
 		elif [ $1 = "dev" ]; then
-			[ -n "$2" ]; dev="dev $2"
+			[ -n "$2" ]; dev="$2"
 			shift
 		elif [ $1 = "id" ]; then
 			_id=$2
-			[ -n "$_id" ]; id="id $_id"
 			shift
 		elif [ $1 = "port" ]; then
 			_port=$2
-			[ -n "$_port" ]; port=" port $_port"
 			shift
 		fi
 
 		shift
 	done
 
-	if [ -z "$id" ]; then
+	if [ -z "${_id}" ]; then
 		test_fail "bad test - missing endpoint id"
 		return
 	fi
 
-	if mptcp_lib_is_ip_mptcp; then
-		# get line and trim trailing whitespace
-		line=$(ip -n $ns mptcp endpoint show $id)
-		line="${line% }"
-		# the dump order is: address id flags port dev
-		[ -n "$addr" ] && expected_line="$addr"
-		expected_line+=" $id"
-		[ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
-		[ -n "$dev" ] && expected_line+=" $dev"
-		[ -n "$port" ] && expected_line+=" $port"
-	else
-		line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
-		# the dump order is: id flags dev address port
-		expected_line="$id"
-		[ -n "$flags" ] && expected_line+=" $flags"
-		[ -n "$dev" ] && expected_line+=" $dev"
-		[ -n "$addr" ] && expected_line+=" $addr"
-		[ -n "$_port" ] && expected_line+=" $_port"
-	fi
+	line=$(mptcp_lib_pm_nl_get_endpoint "${ns}" "${_id}")
+	expected_line=$(mptcp_lib_pm_nl_format_endpoints \
+		"${_id},${addr},${_flags//","/" "},${dev},${_port}")
 	if [ "$line" = "$expected_line" ]; then
 		print_ok
 	else
tools/testing/selftests/net/mptcp/mptcp_lib.sh +34 -0
index ca01d949fad8..ceb8f272c69d 100644
@@ -520,3 +520,37 @@ mptcp_lib_set_ip_mptcp() {
 mptcp_lib_is_ip_mptcp() {
 	[ "${MPTCP_LIB_IP_MPTCP}" = "1" ]
 }
+
+# format: <id>,<ip>,<flags>,<dev>
+mptcp_lib_pm_nl_format_endpoints() {
+	local entry id ip flags dev port
+
+	for entry in "${@}"; do
+		IFS=, read -r id ip flags dev port <<< "${entry}"
+		if mptcp_lib_is_ip_mptcp; then
+			echo -n "${ip}"
+			[ -n "${port}" ] && echo -n " port ${port}"
+			echo -n " id ${id}"
+			[ -n "${flags}" ] && echo -n " ${flags}"
+			[ -n "${dev}" ] && echo -n " dev ${dev}"
+			echo " " # always a space at the end
+		else
+			echo -n "id ${id}"
+			echo -n " flags ${flags//" "/","}"
+			[ -n "${dev}" ] && echo -n " dev ${dev}"
+			echo -n " ${ip}"
+			[ -n "${port}" ] && echo " ${port}" || echo ""
+		fi
+	done
+}
+
+mptcp_lib_pm_nl_get_endpoint() {
+	local ns=${1}
+	local id=${2}
+
+	if mptcp_lib_is_ip_mptcp; then
+		ip -n "${ns}" mptcp endpoint show id "${id}"
+	else
+		ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
+	fi
+}
tools/testing/selftests/net/mptcp/pm_netlink.sh +57 -44

156 lines not on this page · raw message

Signature · 1 line
2.40.1
maintainer
#5 lore raw

Re: [PATCH mptcp-next v4 3/9] selftests: mptcp: add get_endpoint helper

Hi Geliang,

Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

The output formats of 'ip mptcp' commands are much different from that of 'pm_nl_ctl' commands. This patch adds a new helper format_endpoints() to format the outputs of 'ip mptcp' and 'pm_nl_ctl' with 'endpoints' arguments to hide these differences.

All endpoints are showed in show_endpoints(). Here add another helper named get_endpoint() to show a specofic endpoint identified by the given

s/specofic/specific

Quoted 5 lines

address ID.

Usage:
All endpoints - show_endpoints $ns
One endpoint - get_endpoint $ns $id

It is a bit confusing, you didn't add 'show_endpoints', maybe you are talking about 'pm_nl_show_endpoints' from mptcp_join.sh? But there is nothing about mptcp_lib_pm_nl_format_endpoints().

Quoted 3 lines

Use these two helpers in mptcp_join.sh and pm_netlink.sh to replace all 'pm_nl_ctl get' commands and outputs of 'pm_nl_ctl dump/get'.

(...)

Quoted 18 lines
tools/testing/selftests/net/mptcp/mptcp_lib.sh +10 -0
index ca01d949fad8..ceb8f272c69d 100644
@@ -520,3 +520,37 @@ mptcp_lib_set_ip_mptcp() {
 mptcp_lib_is_ip_mptcp() {
 	[ "${MPTCP_LIB_IP_MPTCP}" = "1" ]
 }
+
+# format: <id>,<ip>,<flags>,<dev>
+mptcp_lib_pm_nl_format_endpoints() {
+	local entry id ip flags dev port
+
+	for entry in "${@}"; do
+		IFS=, read -r id ip flags dev port <<< "${entry}"
+		if mptcp_lib_is_ip_mptcp; then
+			echo -n "${ip}"
+			[ -n "${port}" ] && echo -n " port ${port}"

tools/testing/selftests/net/mptcp/mptcp_lib.sh mptcp_lib_set_ip_mptcp() { · line 542

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_lib.sh +10 -0
+			echo -n " id ${id}"
+			[ -n "${flags}" ] && echo -n " ${flags}"
+			[ -n "${dev}" ] && echo -n " dev ${dev}"
+			echo " " # always a space at the end
+		else
+			echo -n "id ${id}"
+			echo -n " flags ${flags//" "/","}"
+			[ -n "${dev}" ] && echo -n " dev ${dev}"
+			echo -n " ${ip}"
+			[ -n "${port}" ] && echo " ${port}" || echo ""

detail: maybe easier to read with:

  [ -n "${port}" ] && echo -n " ${port}"
  echo
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_lib.sh +4 -0
+		fi
+	done
+}
+

tools/testing/selftests/net/mptcp/mptcp_lib.sh mptcp_lib_set_ip_mptcp() { · line 556

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_lib.sh +10 -0
+mptcp_lib_pm_nl_get_endpoint() {
+	local ns=${1}
+	local id=${2}
+
+	if mptcp_lib_is_ip_mptcp; then
+		ip -n "${ns}" mptcp endpoint show id "${id}"
+	else
+		ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
+	fi
+}

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#6 lore raw

PATCH v4 4/9 selftests: mptcp: add change_address helper

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

The address that needs to change flags can only be identified by an address ID in change_endpoint() helper. This patch adds another helper named change_address(), its 2nd parameter is an IP address.

Usage:
Address ID - change_endpoint $ns id $id $flags IP address - change_address $ns $addr $flags

Use this new helper in pm_netlink.sh to replace all 'pm_nl_ctl set' commands.

---
 tools/testing/selftests/net/mptcp/pm_netlink.sh | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/pm_netlink.sh +13 -2
index ff4355db03cd..08b78007e8c1 100755
@@ -74,6 +74,17 @@ get_endpoint() {
 	mptcp_lib_pm_nl_get_endpoint "${ns1}" "${@}"
 }
 
+change_address() {
+	local addr=${1}
+	local flags=${2}
+
+	if mptcp_lib_is_ip_mptcp; then
+		ip -n "${ns1}" mptcp endpoint change "${addr}" "${flags}"
+	else
+		ip netns exec "${ns1}" ./pm_nl_ctl set "${addr}" flags "${flags}"
+	fi
+}
+
 check()
 {
 	local cmd="$1"
@@ -196,10 +207,10 @@ check "ip netns exec $ns1 ./pm_nl_ctl dump" \
 
 ip netns exec $ns1 ./pm_nl_ctl flush
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow
-ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup
+change_address 10.0.1.1 backup
 check "ip netns exec $ns1 ./pm_nl_ctl dump" "$(format_endpoints "1,10.0.1.1,subflow backup")" \
 	"set flags (backup)"
-ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup
+change_address 10.0.1.1 nobackup
 check "ip netns exec $ns1 ./pm_nl_ctl dump" "$(format_endpoints "1,10.0.1.1,subflow")" \
 	"          (nobackup)"
 
Signature · 1 line
2.40.1
maintainer
#7 lore raw

Re: [PATCH mptcp-next v4 4/9] selftests: mptcp: add change_address helper

Hi Geliang,

Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

The address that needs to change flags can only be identified by an address ID in change_endpoint() helper. This patch adds another helper named change_address(), its 2nd parameter is an IP address.

Usage:
Address ID - change_endpoint $ns id $id $flags IP address - change_address $ns $addr $flags

It is confusing, there is no 'change_endpoint' helper.

Quoted 3 lines

Use this new helper in pm_netlink.sh to replace all 'pm_nl_ctl set' commands.

(...)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#8 lore raw

PATCH v4 5/9 selftests: mptcp: join: update endpoint ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch uses 'case' statements to simplify pm_nl_add_endpoint() and pm_nl_check_endpoint(). And simplify pm_nl_check_endpoint() with check_output() helper. Also update pm_nl_del_endpoint() to avoid the 'double quote' shellcheck warning.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 72 ++++++-------------
 1 file changed, 23 insertions(+), 49 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +23 -49
index d48da81daa06..8862b6a5caa0 100755
@@ -620,39 +620,27 @@ pm_nl_add_endpoint()
 {
 	local ns=$1
 	local addr=$2
-	local flags _flags
-	local port _port
-	local dev _dev
-	local id _id
+	local flags dev id port
 	local nr=2
 
 	local p
 	for p in "${@}"
 	do
-		if [ $p = "flags" ]; then
-			eval _flags=\$"$nr"
-			[ -n "$_flags" ]; flags="flags $_flags"
-		fi
-		if [ $p = "dev" ]; then
-			eval _dev=\$"$nr"
-			[ -n "$_dev" ]; dev="dev $_dev"
-		fi
-		if [ $p = "id" ]; then
-			eval _id=\$"$nr"
-			[ -n "$_id" ]; id="id $_id"
-		fi
-		if [ $p = "port" ]; then
-			eval _port=\$"$nr"
-			[ -n "$_port" ]; port="port $_port"
-		fi
+		case "${p}" in
+		"flags" | "dev" | "id" | "port")
+			eval "${p}"=\$"${nr}"
+			;;
+		esac
 
 		nr=$((nr + 1))
 	done
 
 	if mptcp_lib_is_ip_mptcp; then
-		ip -n $ns mptcp endpoint add $addr ${_flags//","/" "} $dev $id $port
+		ip -n "${ns}" mptcp endpoint add "${addr}" ${flags//","/" "} \
+			${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
 	else
-		ip netns exec $ns ./pm_nl_ctl add $addr $flags $dev $id $port
+		ip netns exec "${ns}" ./pm_nl_ctl add "${addr}" ${flags:+flags "${flags}"} \
+			${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
 	fi
 }
 
@@ -664,7 +652,7 @@ pm_nl_del_endpoint()
 
 	if mptcp_lib_is_ip_mptcp; then
 		[ $id -ne 0 ] && addr=''
-		ip -n $ns mptcp endpoint delete id $id $addr
+		ip -n $ns mptcp endpoint delete id $id ${addr:+"${addr}"}
 	else
 		ip netns exec $ns ./pm_nl_ctl del $id $addr
 	fi
@@ -707,49 +695,35 @@ pm_nl_change_endpoint()
 
 pm_nl_check_endpoint()
 {
-	local line expected_line
 	local msg="$1"
 	local ns=$2
 	local addr=$3
-	local _flags=""
-	local _port
-	local dev
-	local _id
+	local flags dev id port
 
 	print_check "${msg}"
 
 	shift 3
 	while [ -n "$1" ]; do
-		if [ $1 = "flags" ]; then
-			_flags=$2
-			shift
-		elif [ $1 = "dev" ]; then
-			[ -n "$2" ]; dev="$2"
-			shift
-		elif [ $1 = "id" ]; then
-			_id=$2
-			shift
-		elif [ $1 = "port" ]; then
-			_port=$2
+		case "${1}" in
+		"flags" | "dev" | "id" | "port")
+			eval "${1}"="${2}"
 			shift
-		fi
+			;;
+		*)
+			;;
+		esac
 
 		shift
 	done
 
-	if [ -z "${_id}" ]; then
+	if [ -z "${id}" ]; then
 		test_fail "bad test - missing endpoint id"
 		return
 	fi
 
-	line=$(mptcp_lib_pm_nl_get_endpoint "${ns}" "${_id}")
-	expected_line=$(mptcp_lib_pm_nl_format_endpoints \
-		"${_id},${addr},${_flags//","/" "},${dev},${_port}")
-	if [ "$line" = "$expected_line" ]; then
-		print_ok
-	else
-		fail_test "expected '$expected_line' found '$line'"
-	fi
+	check_output "mptcp_lib_pm_nl_get_endpoint ${ns} ${id}" \
+		"$(mptcp_lib_pm_nl_format_endpoints \
+			"${id},${addr},${flags//","/" "},${dev},${port}")"
 }
 
 pm_nl_set_endpoint()
Signature · 1 line
2.40.1
author reviewer
#9 lore raw

PATCH v4 6/9 selftests: mptcp: export pm_nl endpoint ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch exports six endpoint operation helpers with pm_nl_ prefix, pm_nl_set_limits(), pm_nl_add_endpoint(), pm_nl_del_endpoint(), pm_nl_flush_endpoint(), pm_nl_show_endpoints() and pm_nl_change_endpoint() into mptcp_lib.sh as public functions, and renamed each of them with a mptcp_lib_ prefix. Then these old pm_nl_ prefix helpers in mptcp_join.sh can be wrappers of mptcp_lib_ prefix ones.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 72 ++--------------
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 85 +++++++++++++++++++
 2 files changed, 91 insertions(+), 66 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +6 -66
index 8862b6a5caa0..fefa9173bdaa 100755
@@ -605,92 +605,32 @@ kill_events_pids()
 
 pm_nl_set_limits()
 {
-	local ns=$1
-	local addrs=$2
-	local subflows=$3
-
-	if mptcp_lib_is_ip_mptcp; then
-		ip -n $ns mptcp limits set add_addr_accepted $addrs subflows $subflows
-	else
-		ip netns exec $ns ./pm_nl_ctl limits $addrs $subflows
-	fi
+	mptcp_lib_pm_nl_set_limits "${@}"
 }
 
 pm_nl_add_endpoint()
 {
-	local ns=$1
-	local addr=$2
-	local flags dev id port
-	local nr=2
-
-	local p
-	for p in "${@}"
-	do
-		case "${p}" in
-		"flags" | "dev" | "id" | "port")
-			eval "${p}"=\$"${nr}"
-			;;
-		esac
-
-		nr=$((nr + 1))
-	done
-
-	if mptcp_lib_is_ip_mptcp; then
-		ip -n "${ns}" mptcp endpoint add "${addr}" ${flags//","/" "} \
-			${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
-	else
-		ip netns exec "${ns}" ./pm_nl_ctl add "${addr}" ${flags:+flags "${flags}"} \
-			${dev:+dev "${dev}"} ${id:+id "${id}"} ${port:+port "${port}"}
-	fi
+	mptcp_lib_pm_nl_add_endpoint "${@}"
 }
 
 pm_nl_del_endpoint()
 {
-	local ns=$1
-	local id=$2
-	local addr=$3
-
-	if mptcp_lib_is_ip_mptcp; then
-		[ $id -ne 0 ] && addr=''
-		ip -n $ns mptcp endpoint delete id $id ${addr:+"${addr}"}
-	else
-		ip netns exec $ns ./pm_nl_ctl del $id $addr
-	fi
+	mptcp_lib_pm_nl_del_endpoint "${@}"
 }
 
 pm_nl_flush_endpoint()
 {
-	local ns=$1
-
-	if mptcp_lib_is_ip_mptcp; then
-		ip -n $ns mptcp endpoint flush
-	else
-		ip netns exec $ns ./pm_nl_ctl flush
-	fi
+	mptcp_lib_pm_nl_flush_endpoint "${@}"
 }
 
 pm_nl_show_endpoints()
 {
-	local ns=$1
-
-	if mptcp_lib_is_ip_mptcp; then
-		ip -n $ns mptcp endpoint show
-	else
-		ip netns exec $ns ./pm_nl_ctl dump
-	fi
+	mptcp_lib_pm_nl_show_endpoints "${@}"
 }
 
 pm_nl_change_endpoint()
 {
-	local ns=$1
-	local id=$2
-	local flags=$3
-
-	if mptcp_lib_is_ip_mptcp; then
-		ip -n $ns mptcp endpoint change id $id ${flags//","/" "}
-	else
-		ip netns exec $ns ./pm_nl_ctl set id $id flags $flags
-	fi
+	mptcp_lib_pm_nl_change_endpoint "${@}"
 }
 
 pm_nl_check_endpoint()
tools/testing/selftests/net/mptcp/mptcp_lib.sh +85 -0

88 lines not on this page · raw message

Signature · 1 line
2.40.1
author reviewer
#10 lore raw

PATCH v4 7/9 selftests: mptcp: use pm_nl endpoint ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use those newly added pm_nl endpoint ops helpers to replace all 'pm_nl_ctl' commands with 'limits', 'add', 'del', 'flush', 'show' and 'set' arguments in scripts mptcp_sockopt.sh and simult_flows.sh.

In pm_netlink.sh, add wrappers of there helpers to make the function names shorter. Then use the wrappers to replace all 'pm_nl_ctl' commands.

---
 .../selftests/net/mptcp/mptcp_sockopt.sh      |  12 +-
 .../testing/selftests/net/mptcp/pm_netlink.sh | 132 +++++++++++-------
 .../selftests/net/mptcp/simult_flows.sh       |   6 +-
 3 files changed, 89 insertions(+), 61 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +6 -6
index e2d70c18786e..36e81383f0e2 100755
@@ -58,15 +58,15 @@ init()
 		# let $ns2 reach any $ns1 address from any interface
 		ip -net "$ns2" route add default via 10.0.$i.1 dev ns2eth$i metric 10$i
 
-		ip netns exec $ns1 ./pm_nl_ctl add 10.0.$i.1 flags signal
-		ip netns exec $ns1 ./pm_nl_ctl add dead:beef:$i::1 flags signal
+		mptcp_lib_pm_nl_add_endpoint "${ns1}" "10.0.${i}.1" flags signal
+		mptcp_lib_pm_nl_add_endpoint "${ns1}" "dead:beef:${i}::1" flags signal
 
-		ip netns exec $ns2 ./pm_nl_ctl add 10.0.$i.2 flags signal
-		ip netns exec $ns2 ./pm_nl_ctl add dead:beef:$i::2 flags signal
+		mptcp_lib_pm_nl_add_endpoint "${ns2}" "10.0.${i}.2" flags signal
+		mptcp_lib_pm_nl_add_endpoint "${ns2}" "dead:beef:${i}::2" flags signal
 	done
 
-	ip netns exec $ns1 ./pm_nl_ctl limits 8 8
-	ip netns exec $ns2 ./pm_nl_ctl limits 8 8
+	mptcp_lib_pm_nl_set_limits "${ns1}" 8 8
+	mptcp_lib_pm_nl_set_limits "${ns2}" 8 8
 
 	add_mark_rules $ns1 1
 	add_mark_rules $ns2 2
tools/testing/selftests/net/mptcp/pm_netlink.sh +80 -52

205 lines not on this page · raw message

tools/testing/selftests/net/mptcp/simult_flows.sh +3 -3
index e129fcb5a598..acc49fa652a2 100755
@@ -85,8 +85,8 @@ setup()
 	ip -net "$ns1" route add default via 10.0.2.2 metric 101
 	ip -net "$ns1" route add default via dead:beef:2::2 metric 101
 
-	ip netns exec "$ns1" ./pm_nl_ctl limits 1 1
-	ip netns exec "$ns1" ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags subflow
+	mptcp_lib_pm_nl_set_limits "${ns1}" 1 1
+	mptcp_lib_pm_nl_add_endpoint "${ns1}" 10.0.2.1 dev ns1eth2 flags subflow
 
 	ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
 	ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
@@ -108,7 +108,7 @@ setup()
 	ip -net "$ns3" route add default via 10.0.3.2
 	ip -net "$ns3" route add default via dead:beef:3::2
 
-	ip netns exec "$ns3" ./pm_nl_ctl limits 1 1
+	mptcp_lib_pm_nl_set_limits "${ns3}" 1 1
 
 	# debug build can slow down measurably the test program
 	# we use quite tight time limit on the run-time, to ensure
Signature · 1 line
2.40.1
author reviewer
#11 lore raw

PATCH v4 8/9 selftests: mptcp: ip_mptcp option for more scripts

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds '-i' option for mptcp_sockopt.sh, pm_netlink.sh, and simult_flows.sh, to use 'ip mptcp' command in the tests instead of 'pm_nl_ctl'. Update usage() correspondingly.

---
 .../selftests/net/mptcp/mptcp_sockopt.sh      | 22 +++++++++++++++++++
 .../testing/selftests/net/mptcp/pm_netlink.sh |  9 ++++++--
 .../selftests/net/mptcp/simult_flows.sh       |  8 +++++--
 3 files changed, 35 insertions(+), 4 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +22 -0
index 36e81383f0e2..68899a303a1a 100755
@@ -22,6 +22,28 @@ ns1=""
 ns2=""
 ns_sbox=""
 
+usage() {
+	echo "Usage: $0 [ -i ] [ -h ]"
+	echo -e "\t-i: use 'ip mptcp' instead of 'pm_nl_ctl'"
+	echo -e "\t-h: help"
+}
+
+while getopts "hi" option;do
+	case "$option" in
+	"h")
+		usage "$0"
+		exit ${KSFT_PASS}
+		;;
+	"i")
+		mptcp_lib_set_ip_mptcp
+		;;
+	"?")
+		usage "$0"
+		exit ${KSFT_FAIL}
+		;;
+	esac
+done
+
 add_mark_rules()
 {
 	local ns=$1
tools/testing/selftests/net/mptcp/pm_netlink.sh +7 -2
index d648383989d2..f48d13081d5c 100755
@@ -11,16 +11,21 @@
 ret=0
 
 usage() {
-	echo "Usage: $0 [ -h ]"
+	echo "Usage: $0 [ -i ] [ -h ]"
+	echo -e "\t-i: use 'ip mptcp' instead of 'pm_nl_ctl'"
+	echo -e "\t-h: help"
 }
 
-optstring=h
+optstring=hi
 while getopts "$optstring" option;do
 	case "$option" in
 	"h")
 		usage $0
 		exit ${KSFT_PASS}
 		;;
+	"i")
+		mptcp_lib_set_ip_mptcp
+		;;
 	"?")
 		usage $0
 		exit ${KSFT_FAIL}
tools/testing/selftests/net/mptcp/simult_flows.sh +6 -2
index acc49fa652a2..d0b39c2e38a3 100755
@@ -27,10 +27,11 @@ capout=""
 size=0
 
 usage() {
-	echo "Usage: $0 [ -b ] [ -c ] [ -d ]"
+	echo "Usage: $0 [ -b ] [ -c ] [ -d ] [ -i]"
 	echo -e "\t-b: bail out after first error, otherwise runs al testcases"
 	echo -e "\t-c: capture packets for each test using tcpdump (default: no capture)"
 	echo -e "\t-d: debug this script"
+	echo -e "\t-i: use 'ip mptcp' instead of 'pm_nl_ctl'"
 }
 
 # This function is used in the cleanup trap
@@ -259,7 +260,7 @@ run_test()
 	fi
 }
 
-while getopts "bcdh" option;do
+while getopts "bcdhi" option;do
 	case "$option" in
 	"h")
 		usage $0
@@ -274,6 +275,9 @@ while getopts "bcdh" option;do
 	"d")
 		set -x
 		;;
+	"i")
+		mptcp_lib_set_ip_mptcp
+		;;
 	"?")
 		usage $0
 		exit ${KSFT_FAIL}
Signature · 1 line
2.40.1
author reviewer
#12 lore raw

PATCH v4 9/9 selftests: mptcp: netlink: drop disable=SC2086

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Now there are only a few of variables are not using double quotes. Modifying them, then "shellcheck disable=SC2086" can be dropped.

---
 tools/testing/selftests/net/mptcp/pm_netlink.sh | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
tools/testing/selftests/net/mptcp/pm_netlink.sh +3 -8
index f48d13081d5c..155847c720cf 100755
@@ -1,11 +1,6 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
-# Double quotes to prevent globbing and word splitting is recommended in new
-# code but we accept it, especially because there were too many before having
-# address all other issues detected by shellcheck.
-#shellcheck disable=SC2086
-
 . "$(dirname "${0}")/mptcp_lib.sh"
 
 ret=0
@@ -20,14 +15,14 @@ optstring=hi
 while getopts "$optstring" option;do
 	case "$option" in
 	"h")
-		usage $0
+		usage "$0"
 		exit ${KSFT_PASS}
 		;;
 	"i")
 		mptcp_lib_set_ip_mptcp
 		;;
 	"?")
-		usage $0
+		usage "$0"
 		exit ${KSFT_FAIL}
 		;;
 	esac
@@ -40,7 +35,7 @@ err=$(mktemp)
 #shellcheck disable=SC2317
 cleanup()
 {
-	rm -f $err
+	rm -f "${err}"
 	mptcp_lib_ns_exit "${ns1}"
 }
 
Signature · 1 line
2.40.1
#13 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8339177200

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/3de9bfb424e6
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=836322

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v4 series
#14 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 4 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
- address every Matt's commends in v3.

Thank you for the new version. It looks good to me, just some details, mostly inconsistencies in the commit messages, I can fix that when applying the patches.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#15 lore raw

Hi Geliang,

Quoted 5 lines · Matthieu Baerts

Hi Geliang,

Quoted 2 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Quoted 8 lines
Quoted 2 lines

v4:
- address every Matt's commends in v3.

Thank you for the new version. It looks good to me, just some details, mostly inconsistencies in the commit messages, I can fix that when applying the patches.

Now in our tree (feat. for net-next):

New patches for t/upstream:
- 75006cfc55e1: selftests: mptcp: export ip_mptcp to mptcp_lib
- 47256e561ff7: selftests: mptcp: netlink: add 'limits' helpers
- 7b7877974627: selftests: mptcp: add {get,format}_endpoint(s) helpers
- d4812471cbd3: selftests: mptcp: netlink: add change_address helper
- a0e3a3cbcc44: selftests: mptcp: join: update endpoint ops
- 9affad23c8fb: selftests: mptcp: export pm_nl endpoint ops
- 6686695dd7c4: selftests: mptcp: use pm_nl endpoint ops
- 39b7f217cd25: selftests: mptcp: ip_mptcp option for more scripts
- 68e20b601685: selftests: mptcp: netlink: drop disable=SC2086
- Results: 2066a03d696e..eeea8900a12e (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/2a74a8d35e784648fb7c4851019456f4d6c432b1/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.