From 729b4efe0e0e14c8519c7b3d5d3578067a0a5803 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 3 Aug 2023 14:51:39 +0800 Subject: [PATCH] selftests/bpf: Add bpf_stale test 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 --- .../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 ad6b5e889d9ded..865d45842d2a88 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -12,6 +12,7 @@ #include "mptcp_bpf_rr.skel.h" #include "mptcp_bpf_red.skel.h" #include "mptcp_bpf_burst.skel.h" +#include "mptcp_bpf_stale.skel.h" char NS_TEST[32]; @@ -525,6 +526,41 @@ static void test_burst(void) mptcp_bpf_burst__destroy(burst_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, PORT_1, 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")) @@ -541,4 +577,6 @@ void test_mptcp(void) test_red(); if (test__start_subtest("burst")) test_burst(); + if (test__start_subtest("stale")) + test_stale(); }