[PATCH mptcp-next v3 08/12] selftests: mptcp: add change_address helper

Geliang Tang posted 12 patches 1 year, 10 months ago
There is a newer version of this series
[PATCH mptcp-next v3 08/12] selftests: mptcp: add change_address helper
Posted by Geliang Tang 1 year, 10 months ago
From: Geliang Tang <tanggeliang@kylinos.cn>

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.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_lib.sh  | 13 +++++++++++++
 tools/testing/selftests/net/mptcp/pm_netlink.sh |  4 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index d83a67922b17..e26ef67e4ef1 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -588,3 +588,16 @@ mptcp_lib_pm_nl_get_endpoint() {
                ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
        fi
 }
+
+mptcp_lib_pm_nl_change_address() {
+	local ns=${1}
+	local addr=${2}
+	local flags=${3}
+
+	if mptcp_lib_is_ip_mptcp; then
+		# shellcheck disable=SC2086 # blanks in flags, no double quote
+		ip -n "${ns}" mptcp endpoint change "${addr}" ${flags//","/" "}
+	else
+		ip netns exec "${ns}" ./pm_nl_ctl set "${addr}" flags "${flags}"
+	fi
+}
diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh
index 28c89b576d1f..a42490885d88 100755
--- a/tools/testing/selftests/net/mptcp/pm_netlink.sh
+++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh
@@ -178,11 +178,11 @@ 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
+mptcp_lib_pm_nl_change_address "${ns1}" 10.0.1.1 backup
 check "ip netns exec $ns1 ./pm_nl_ctl dump" \
 	"$(mptcp_lib_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
+mptcp_lib_pm_nl_change_address "${ns1}" 10.0.1.1 nobackup
 check "ip netns exec $ns1 ./pm_nl_ctl dump" \
 	"$(mptcp_lib_format_endpoints "1,10.0.1.1,subflow")" \
 	"          (nobackup)"
-- 
2.40.1
Re: [PATCH mptcp-next v3 08/12] selftests: mptcp: add change_address helper
Posted by Matthieu Baerts 1 year, 10 months ago
Hi Geliang,

On 17/03/2024 01:58, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> 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.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/net/mptcp/mptcp_lib.sh  | 13 +++++++++++++
>  tools/testing/selftests/net/mptcp/pm_netlink.sh |  4 ++--
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index d83a67922b17..e26ef67e4ef1 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -588,3 +588,16 @@ mptcp_lib_pm_nl_get_endpoint() {
>                 ip netns exec "${ns}" ./pm_nl_ctl get "${id}"
>         fi
>  }
> +
> +mptcp_lib_pm_nl_change_address() {

Same here, if it is only used in pm_netlink.sh, keep it there, with a
shorter name, and without ns:

  change_address 10.0.1.1 backup

no?

> +	local ns=${1}
> +	local addr=${2}
> +	local flags=${3}
> +
> +	if mptcp_lib_is_ip_mptcp; then
> +		# shellcheck disable=SC2086 # blanks in flags, no double quote
> +		ip -n "${ns}" mptcp endpoint change "${addr}" ${flags//","/" "}

It looks like this helper is only used with 'backup' or 'nobackup' flag,
you can then use "${flags}" without the "disable=SC2086", no?

> +	else
> +		ip netns exec "${ns}" ./pm_nl_ctl set "${addr}" flags "${flags}"
> +	fi
> +}
(...)

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.