[PATCH mptcp-next 07/10] selftests/bpf: Add bpf_stale test

Geliang Tang posted 10 patches 2 years, 7 months ago
Maintainers: Matthieu Baerts <matthieu.baerts@tessares.net>, Mat Martineau <martineau@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>, Shuah Khan <shuah@kernel.org>
There is a newer version of this series
[PATCH mptcp-next 07/10] selftests/bpf: Add bpf_stale test
Posted by Geliang Tang 2 years, 7 months ago
This patch adds the bpf_stale scheduler test: test_stale(). Use sysctl to
set net.mptcp.scheduler to use this sched. Add two veth net devices to
simulate the multiple addresses case. Use 'ip mptcp endpoint' command to
add the new endpoint ADDR_2 to PM netlink. Send data and check bytes_sent
of 'ss' output after it to make sure the data has been only sent on ADDR_1
since ADDR_2 is set as stale.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 4b346eeaf8e2..851ea32dc1d0 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -11,6 +11,7 @@
 #include "mptcp_bpf_bkup.skel.h"
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
+#include "mptcp_bpf_stale.skel.h"
 
 char NS_TEST[32];
 
@@ -488,6 +489,41 @@ static void test_red(void)
 	mptcp_bpf_red__destroy(red_skel);
 }
 
+static void test_stale(void)
+{
+	struct mptcp_bpf_stale *stale_skel;
+	int server_fd, client_fd;
+	struct nstoken *nstoken;
+	struct bpf_link *link;
+
+	stale_skel = mptcp_bpf_stale__open_and_load();
+	if (!ASSERT_OK_PTR(stale_skel, "bpf_stale__open_and_load"))
+		return;
+
+	link = bpf_map__attach_struct_ops(stale_skel->maps.stale);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
+		mptcp_bpf_stale__destroy(stale_skel);
+		return;
+	}
+
+	nstoken = sched_init("subflow", "bpf_stale");
+	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_stale"))
+		goto fail;
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	client_fd = connect_to_fd(server_fd, 0);
+
+	send_data(server_fd, client_fd, "bpf_stale");
+	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
+	ASSERT_GT(has_bytes_sent(ADDR_2), 0, "has_bytes_sent addr_2");
+
+	close(client_fd);
+	close(server_fd);
+fail:
+	cleanup_netns(nstoken);
+	bpf_link__destroy(link);
+	mptcp_bpf_stale__destroy(stale_skel);
+}
+
 void test_mptcp(void)
 {
 	if (test__start_subtest("base"))
@@ -502,4 +538,6 @@ void test_mptcp(void)
 		test_rr();
 	if (test__start_subtest("red"))
 		test_red();
+	if (test__start_subtest("stale"))
+		test_stale();
 }
-- 
2.35.3
Re: [PATCH mptcp-next 07/10] selftests/bpf: Add bpf_stale test
Posted by Mat Martineau 2 years, 7 months ago
On Tue, 27 Jun 2023, Geliang Tang wrote:

> This patch adds the bpf_stale scheduler test: test_stale(). Use sysctl to
> set net.mptcp.scheduler to use this sched. Add two veth net devices to
> simulate the multiple addresses case. Use 'ip mptcp endpoint' command to
> add the new endpoint ADDR_2 to PM netlink. Send data and check bytes_sent
> of 'ss' output after it to make sure the data has been only sent on ADDR_1
> since ADDR_2 is set as stale.
>
> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
> .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> index 4b346eeaf8e2..851ea32dc1d0 100644
> --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
> +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
> @@ -11,6 +11,7 @@
> #include "mptcp_bpf_bkup.skel.h"
> #include "mptcp_bpf_rr.skel.h"
> #include "mptcp_bpf_red.skel.h"
> +#include "mptcp_bpf_stale.skel.h"
>
> char NS_TEST[32];
>
> @@ -488,6 +489,41 @@ static void test_red(void)
> 	mptcp_bpf_red__destroy(red_skel);
> }
>
> +static void test_stale(void)
> +{
> +	struct mptcp_bpf_stale *stale_skel;
> +	int server_fd, client_fd;
> +	struct nstoken *nstoken;
> +	struct bpf_link *link;
> +
> +	stale_skel = mptcp_bpf_stale__open_and_load();
> +	if (!ASSERT_OK_PTR(stale_skel, "bpf_stale__open_and_load"))
> +		return;
> +
> +	link = bpf_map__attach_struct_ops(stale_skel->maps.stale);
> +	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
> +		mptcp_bpf_stale__destroy(stale_skel);
> +		return;
> +	}
> +
> +	nstoken = sched_init("subflow", "bpf_stale");
> +	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_stale"))
> +		goto fail;
> +	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
> +	client_fd = connect_to_fd(server_fd, 0);
> +
> +	send_data(server_fd, client_fd, "bpf_stale");
> +	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
> +	ASSERT_GT(has_bytes_sent(ADDR_2), 0, "has_bytes_sent addr_2");

I don't think it is guaranteed that ADDR_2 will always be at index 1 like 
the bpf_stale_get_subflow() expects. How about using checking for an 
odd/even value in the last byte of the IPv4 addresses for ADDR_1/ADDR_2 
instead?

- Mat

> +
> +	close(client_fd);
> +	close(server_fd);
> +fail:
> +	cleanup_netns(nstoken);
> +	bpf_link__destroy(link);
> +	mptcp_bpf_stale__destroy(stale_skel);
> +}
> +
> void test_mptcp(void)
> {
> 	if (test__start_subtest("base"))
> @@ -502,4 +538,6 @@ void test_mptcp(void)
> 		test_rr();
> 	if (test__start_subtest("red"))
> 		test_red();
> +	if (test__start_subtest("stale"))
> +		test_stale();
> }
> -- 
> 2.35.3
>
>
>