Skip to content

Commit 5910f04

Browse files
Geliang Tangmatttbe
authored andcommitted
selftests/bpf: Add bpf_bkup scheduler & test
This patch implements the backup flag test scheduler, named bpf_bkup, which picks the first non-backup subflow to send data. Using MPTCP_SCHED_TEST macro to add a new test for this bpf_bkup scheduler, the arguments "1 0" means data has been only sent on the first subflow ADDR1. Run this test by RUN_MPTCP_TEST macro. Signed-off-by: Geliang Tang <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent de41d3f commit 5910f04

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "mptcp_subflow.skel.h"
1414
#include "mptcp_bpf_iters.skel.h"
1515
#include "mptcp_bpf_first.skel.h"
16+
#include "mptcp_bpf_bkup.skel.h"
1617

1718
#define NS_TEST "mptcp_ns"
1819
#define ADDR_1 "10.0.1.1"
@@ -701,6 +702,18 @@ static void test_first(void)
701702
mptcp_bpf_first__destroy(skel);
702703
}
703704

705+
static void test_bkup(void)
706+
{
707+
struct mptcp_bpf_bkup *skel;
708+
709+
skel = mptcp_bpf_bkup__open_and_load();
710+
if (!ASSERT_OK_PTR(skel, "open_and_load: bkup"))
711+
return;
712+
713+
test_bpf_sched(skel->obj, "bkup", WITH_DATA, WITHOUT_DATA);
714+
mptcp_bpf_bkup__destroy(skel);
715+
}
716+
704717
void test_mptcp(void)
705718
{
706719
if (test__start_subtest("base"))
@@ -715,4 +728,6 @@ void test_mptcp(void)
715728
test_default();
716729
if (test__start_subtest("first"))
717730
test_first();
731+
if (test__start_subtest("bkup"))
732+
test_bkup();
718733
}

tools/testing/selftests/bpf/progs/mptcp_bpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "bpf_experimental.h"
66

7+
/* mptcp helpers from include/net/mptcp.h */
8+
#define MPTCP_SUBFLOWS_MAX 8
9+
710
/* list helpers from include/linux/list.h */
811
static inline int list_is_head(const struct list_head *list,
912
const struct list_head *head)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2022, SUSE. */
3+
4+
#include "mptcp_bpf.h"
5+
#include <bpf/bpf_tracing.h>
6+
7+
char _license[] SEC("license") = "GPL";
8+
9+
SEC("struct_ops")
10+
void BPF_PROG(mptcp_sched_bkup_init, struct mptcp_sock *msk)
11+
{
12+
}
13+
14+
SEC("struct_ops")
15+
void BPF_PROG(mptcp_sched_bkup_release, struct mptcp_sock *msk)
16+
{
17+
}
18+
19+
SEC("struct_ops")
20+
int BPF_PROG(bpf_bkup_get_subflow, struct mptcp_sock *msk,
21+
struct mptcp_sched_data *data)
22+
{
23+
int nr = -1;
24+
25+
for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
26+
struct mptcp_subflow_context *subflow;
27+
28+
subflow = bpf_mptcp_subflow_ctx_by_pos(data, i);
29+
if (!subflow)
30+
break;
31+
32+
if (!BPF_CORE_READ_BITFIELD_PROBED(subflow, backup) ||
33+
!BPF_CORE_READ_BITFIELD_PROBED(subflow, request_bkup)) {
34+
nr = i;
35+
break;
36+
}
37+
}
38+
39+
if (nr != -1) {
40+
mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, nr), true);
41+
return -1;
42+
}
43+
return 0;
44+
}
45+
46+
SEC(".struct_ops")
47+
struct mptcp_sched_ops bkup = {
48+
.init = (void *)mptcp_sched_bkup_init,
49+
.release = (void *)mptcp_sched_bkup_release,
50+
.get_subflow = (void *)bpf_bkup_get_subflow,
51+
.name = "bpf_bkup",
52+
};

0 commit comments

Comments
 (0)