Skip to content

Commit a5be59d

Browse files
Geliang Tangmatttbe
authored andcommitted
selftests/bpf: Add bpf scheduler test
This patch extends the MPTCP test base to support MPTCP packet scheduler tests. Add a new test to use the default in-kernel scheduler. In the new helper sched_init(), 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. Use sysctl to set net.mptcp.scheduler to use the given sched. Invoke start_mptcp_server() to start the server on ADDR_1, and invoke connect_to_fd() to connect with the server from the client. Then invoke send_data() to send data. Some code in send_data() is from prog_tests/bpf_tcp_ca.c. Add time metrics for BPF tests to compare the performance of each schedulers. Run prog_tests with '-v' option can print out the running time of each test. Use the new helper has_bytes_sent() to check the bytes_sent filed of 'ss' output after send_data() to make sure no data has been sent on ADDR_2. All data has been sent on the first subflow. Invoke the new helper sched_cleanup() to set back net.mptcp.scheduler to default, flush all mptcp endpoints, and delete the veth net devices. Signed-off-by: Geliang Tang <[email protected]> Reviewed-by: Mat Martineau <[email protected]>
1 parent e7bc810 commit a5be59d

File tree

1 file changed

+90
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+90
-0
lines changed

tools/testing/selftests/bpf/prog_tests/mptcp.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define ADDR6_3 "dead:beef:3::1"
2424
#define ADDR6_4 "dead:beef:4::1"
2525
#define PORT_1 10001
26+
#define WITH_DATA true
27+
#define WITHOUT_DATA false
2628

2729
#ifndef IPPROTO_MPTCP
2830
#define IPPROTO_MPTCP 262
@@ -48,6 +50,9 @@
4850
#define TCP_CA_NAME_MAX 16
4951
#endif
5052

53+
static const unsigned int total_bytes = 10 * 1024 * 1024;
54+
static int duration;
55+
5156
struct __mptcp_info {
5257
__u8 mptcpi_subflows;
5358
__u8 mptcpi_add_addr_signal;
@@ -551,6 +556,89 @@ static void test_iters_subflow(void)
551556
close(cgroup_fd);
552557
}
553558

559+
static int sched_init(char *flags, char *sched)
560+
{
561+
if (endpoint_init(flags, 2) < 0)
562+
return -1;
563+
564+
SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);
565+
566+
return 0;
567+
fail:
568+
return -1;
569+
}
570+
571+
static int ss_search(char *src, char *dst, char *port, char *keyword)
572+
{
573+
return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
574+
NS_TEST, src, dst, port, PORT_1, keyword);
575+
}
576+
577+
static int has_bytes_sent(char *dst)
578+
{
579+
return ss_search(ADDR_1, dst, "sport", "bytes_sent:");
580+
}
581+
582+
static void send_data_and_verify(char *sched, bool addr1, bool addr2)
583+
{
584+
struct timespec start, end;
585+
int server_fd, client_fd;
586+
unsigned int delta_ms;
587+
588+
server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
589+
if (!ASSERT_OK_FD(server_fd, "start_mptcp_server"))
590+
return;
591+
592+
client_fd = connect_to_fd(server_fd, 0);
593+
if (!ASSERT_OK_FD(client_fd, "connect_to_fd"))
594+
goto fail;
595+
596+
if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
597+
goto fail;
598+
599+
if (!ASSERT_OK(send_recv_data(server_fd, client_fd, total_bytes),
600+
"send_recv_data"))
601+
goto fail;
602+
603+
if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
604+
goto fail;
605+
606+
delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
607+
printf("%s: %u ms\n", sched, delta_ms);
608+
609+
if (addr1)
610+
CHECK(has_bytes_sent(ADDR_1), sched, "should have bytes_sent on addr1\n");
611+
else
612+
CHECK(!has_bytes_sent(ADDR_1), sched, "shouldn't have bytes_sent on addr1\n");
613+
if (addr2)
614+
CHECK(has_bytes_sent(ADDR_2), sched, "should have bytes_sent on addr2\n");
615+
else
616+
CHECK(!has_bytes_sent(ADDR_2), sched, "shouldn't have bytes_sent on addr2\n");
617+
618+
close(client_fd);
619+
fail:
620+
close(server_fd);
621+
}
622+
623+
static void test_default(void)
624+
{
625+
struct netns_obj *netns;
626+
int err;
627+
628+
netns = netns_new(NS_TEST, true);
629+
if (!netns)
630+
goto fail;
631+
632+
err = sched_init("subflow", "default");
633+
if (!ASSERT_OK(err, "sched_init"))
634+
goto fail;
635+
636+
send_data_and_verify("default", WITH_DATA, WITH_DATA);
637+
638+
fail:
639+
netns_free(netns);
640+
}
641+
554642
void test_mptcp(void)
555643
{
556644
if (test__start_subtest("base"))
@@ -561,4 +649,6 @@ void test_mptcp(void)
561649
test_subflow();
562650
if (test__start_subtest("iters_subflow"))
563651
test_iters_subflow();
652+
if (test__start_subtest("default"))
653+
test_default();
564654
}

0 commit comments

Comments
 (0)