Skip to content

Commit ba9c80f

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 432849e commit ba9c80f

File tree

1 file changed

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

1 file changed

+92
-0
lines changed

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

Lines changed: 92 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,91 @@ static void test_iters_subflow(void)
551556
close(cgroup_fd);
552557
}
553558

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

0 commit comments

Comments
 (0)