From aa09224635cc05e6a4783239c0697f6ac6e5cb41 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sat, 4 Jun 2022 12:39:37 +0200 Subject: [PATCH] selftests/bpf: Add bpf_rr test This patch adds the round-robin BPF MPTCP scheduler test. Use sysctl to set net.mptcp.scheduler to use this sched. Add a veth net device to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add this new endpoint to PM netlink. Send data and check bytes_sent of 'ss' output after it to make sure the data has been sent on the new veth net device. Reviewed-by: Mat Martineau Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index f3c73cd2c7860..1ecc8a2b76b63 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -8,6 +8,7 @@ #include "mptcp_sock.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" +#include "mptcp_bpf_rr.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 @@ -329,6 +330,38 @@ static void test_bkup(void) mptcp_bpf_bkup__destroy(bkup_skel); } +static void test_rr(void) +{ + struct mptcp_bpf_rr *rr_skel; + int server_fd, client_fd; + struct bpf_link *link; + + rr_skel = mptcp_bpf_rr__open_and_load(); + if (!ASSERT_OK_PTR(rr_skel, "bpf_rr__open_and_load")) + return; + + link = bpf_map__attach_struct_ops(rr_skel->maps.rr); + if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) { + mptcp_bpf_rr__destroy(rr_skel); + return; + } + + add_veth(); + system("ip mptcp endpoint add 10.0.1.1 subflow"); + system("sysctl -qw net.mptcp.scheduler=bpf_rr"); + server_fd = start_mptcp_server(AF_INET, NULL, 0, 0); + client_fd = connect_to_fd(server_fd, 0); + + send_data(server_fd, client_fd); + ASSERT_OK(system("ss -MOenita | grep '10.0.1.1' | grep -q 'bytes_sent:'"), "ss"); + + close(client_fd); + close(server_fd); + cleanup(); + bpf_link__destroy(link); + mptcp_bpf_rr__destroy(rr_skel); +} + void test_mptcp(void) { if (test__start_subtest("base")) @@ -337,4 +370,6 @@ void test_mptcp(void) test_first(); if (test__start_subtest("bkup")) test_bkup(); + if (test__start_subtest("rr")) + test_rr(); }