Skip to content

Commit b3983da

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 fecce22 commit b3983da

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
@@ -22,6 +22,8 @@
2222
#define ADDR6_3 "dead:beef:3::1"
2323
#define ADDR6_4 "dead:beef:4::1"
2424
#define PORT_1 10001
25+
#define WITH_DATA true
26+
#define WITHOUT_DATA false
2527

2628
#ifndef IPPROTO_MPTCP
2729
#define IPPROTO_MPTCP 262
@@ -44,6 +46,9 @@
4446
#define TCP_CA_NAME_MAX 16
4547
#endif
4648

49+
static const unsigned int total_bytes = 10 * 1024 * 1024;
50+
static int duration;
51+
4752
struct __mptcp_info {
4853
__u8 mptcpi_subflows;
4954
__u8 mptcpi_add_addr_signal;
@@ -480,6 +485,89 @@ static void test_subflow(void)
480485
close(cgroup_fd);
481486
}
482487

488+
static int sched_init(char *flags, char *sched)
489+
{
490+
if (endpoint_init(flags, 2) < 0)
491+
return -1;
492+
493+
SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);
494+
495+
return 0;
496+
fail:
497+
return -1;
498+
}
499+
500+
static int ss_search(char *src, char *dst, char *port, char *keyword)
501+
{
502+
return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
503+
NS_TEST, src, dst, port, PORT_1, keyword);
504+
}
505+
506+
static int has_bytes_sent(char *dst)
507+
{
508+
return ss_search(ADDR_1, dst, "sport", "bytes_sent:");
509+
}
510+
511+
static void send_data_and_verify(char *sched, bool addr1, bool addr2)
512+
{
513+
struct timespec start, end;
514+
int server_fd, client_fd;
515+
unsigned int delta_ms;
516+
517+
server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
518+
if (!ASSERT_OK_FD(server_fd, "start_mptcp_server"))
519+
return;
520+
521+
client_fd = connect_to_fd(server_fd, 0);
522+
if (!ASSERT_OK_FD(client_fd, "connect_to_fd"))
523+
goto fail;
524+
525+
if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
526+
goto fail;
527+
528+
if (!ASSERT_OK(send_recv_data(server_fd, client_fd, total_bytes),
529+
"send_recv_data"))
530+
goto fail;
531+
532+
if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
533+
goto fail;
534+
535+
delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
536+
printf("%s: %u ms\n", sched, delta_ms);
537+
538+
if (addr1)
539+
CHECK(has_bytes_sent(ADDR_1), sched, "should have bytes_sent on addr1\n");
540+
else
541+
CHECK(!has_bytes_sent(ADDR_1), sched, "shouldn't have bytes_sent on addr1\n");
542+
if (addr2)
543+
CHECK(has_bytes_sent(ADDR_2), sched, "should have bytes_sent on addr2\n");
544+
else
545+
CHECK(!has_bytes_sent(ADDR_2), sched, "shouldn't have bytes_sent on addr2\n");
546+
547+
close(client_fd);
548+
fail:
549+
close(server_fd);
550+
}
551+
552+
static void test_default(void)
553+
{
554+
struct netns_obj *netns;
555+
int err;
556+
557+
netns = netns_new(NS_TEST, true);
558+
if (!netns)
559+
goto fail;
560+
561+
err = sched_init("subflow", "default");
562+
if (!ASSERT_OK(err, "sched_init"))
563+
goto fail;
564+
565+
send_data_and_verify("default", WITH_DATA, WITH_DATA);
566+
567+
fail:
568+
netns_free(netns);
569+
}
570+
483571
void test_mptcp(void)
484572
{
485573
if (test__start_subtest("base"))
@@ -488,4 +576,6 @@ void test_mptcp(void)
488576
test_mptcpify();
489577
if (test__start_subtest("subflow"))
490578
test_subflow();
579+
if (test__start_subtest("default"))
580+
test_default();
491581
}

0 commit comments

Comments
 (0)