Skip to content

Commit

Permalink
selftests/bpf: Add bpf_bkup scheduler & test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Geliang Tang authored and matttbe committed Jan 3, 2025
1 parent 768e5e2 commit 3fa1e6b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mptcp_subflow.skel.h"
#include "mptcp_bpf_iters.skel.h"
#include "mptcp_bpf_first.skel.h"
#include "mptcp_bpf_bkup.skel.h"

#define NS_TEST "mptcp_ns"
#define ADDR_1 "10.0.1.1"
Expand Down Expand Up @@ -683,6 +684,18 @@ static void test_first(void)
mptcp_bpf_first__destroy(skel);
}

static void test_bkup(void)
{
struct mptcp_bpf_bkup *skel;

skel = mptcp_bpf_bkup__open_and_load();
if (!ASSERT_OK_PTR(skel, "open_and_load: bkup"))
return;

test_bpf_sched(skel->obj, "bkup", WITH_DATA, WITHOUT_DATA);
mptcp_bpf_bkup__destroy(skel);
}

void test_mptcp(void)
{
if (test__start_subtest("base"))
Expand All @@ -697,4 +710,6 @@ void test_mptcp(void)
test_default();
if (test__start_subtest("first"))
test_first();
if (test__start_subtest("bkup"))
test_bkup();
}
3 changes: 3 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "bpf_experimental.h"

/* mptcp helpers from include/net/mptcp.h */
#define MPTCP_SUBFLOWS_MAX 8

/* list helpers from include/linux/list.h */
static inline int list_is_head(const struct list_head *list,
const struct list_head *head)
Expand Down
52 changes: 52 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022, SUSE. */

#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

SEC("struct_ops")
void BPF_PROG(mptcp_sched_bkup_init, struct mptcp_sock *msk)
{
}

SEC("struct_ops")
void BPF_PROG(mptcp_sched_bkup_release, struct mptcp_sock *msk)
{
}

SEC("struct_ops")
int BPF_PROG(bpf_bkup_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
int nr = -1;

for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
struct mptcp_subflow_context *subflow;

subflow = bpf_mptcp_subflow_ctx_by_pos(data, i);
if (!subflow)
break;

if (!BPF_CORE_READ_BITFIELD_PROBED(subflow, backup) ||
!BPF_CORE_READ_BITFIELD_PROBED(subflow, request_bkup)) {
nr = i;
break;
}
}

if (nr != -1) {
mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, nr), true);
return -1;
}
return 0;
}

SEC(".struct_ops")
struct mptcp_sched_ops bkup = {
.init = (void *)mptcp_sched_bkup_init,
.release = (void *)mptcp_sched_bkup_release,
.get_subflow = (void *)bpf_bkup_get_subflow,
.name = "bpf_bkup",
};

0 comments on commit 3fa1e6b

Please sign in to comment.