Skip to content

Commit d402e53

Browse files
committed
Adds the draft of the XDP scheduler testing tool
This commit contains the XDP scheduling framework. It consists of a testing program called xdq-tester used to test schedulers using the XDP and DEQUEUE hooks. It does this using trace files written in Lua that the xdq-tester program uses to check the XDP schedulers for correctness. I changed the name to xdq-tester because I found the old name too long. I reused the XDQ name because I sometimes find it hard to distinguish between the XDP hook or the XDP and DEQUEUE hooks in text or code. I am sure we can find a better name later. Like before, the FIFO and PIFO schedulers are fully functional in this commit. However, it defines flows as UDP port numbers instead of using five tuples that I am currently finishing now. This program version has two issues that I need to resolve, but I have not spent much time on them. The first issue is that the WFQ scheduler fails to dequeue its third packet. The second issue is that the upstream bpf-examples now includes libxdp, and I have not updated my code to work with it. However, when I have libxdp support, I suspect that I can finally use the lib/util/logging.h as part of my project to get more verbose output. Signed-off-by: Frey Alfredsson <[email protected]>
1 parent daefd11 commit d402e53

11 files changed

+1791
-0
lines changed

xdq-tester/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
3+
USER_TARGETS := xdq-tester
4+
BPF_TARGETS := $(patsubst %.c,%,$(wildcard *.bpf.c))
5+
6+
USER_LIBS = -llua -ldl -lm
7+
8+
LIB_DIR = ../lib
9+
10+
include $(LIB_DIR)/common.mk

xdq-tester/bpf_local_helpers.h

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
3+
#define EEXIST 17 /* File exists */
4+
5+
#define BPF_MAP_TYPE_PIFO_GENERIC 31
6+
#define BPF_MAP_TYPE_PIFO_XDP 32
7+
8+
/*
9+
* bpf_packet_dequeue
10+
*
11+
* Dequeue the packet at the head of the PIFO in *map* and return a pointer
12+
* to the packet (or NULL if the PIFO is empty).
13+
*
14+
* Returns
15+
* On success, a pointer to the packet, or NULL if the PIFO is empty. The
16+
* packet pointer must be freed using *bpf_packet_drop()* or returning
17+
* the packet pointer. The *rank* pointer will be set to the rank of
18+
* the dequeued packet on success, or a negative error code on error.
19+
*/
20+
static long (*bpf_packet_dequeue)(void *ctx, void *map, __u64 flags, __u64 *rank) = (void *) 194;
21+
static long (*bpf_packet_drop)(void *ctx, void *pkt) = (void *) 195;
22+
23+
struct flow_address {
24+
struct in6_addr ip;
25+
__u16 port;
26+
__u16 reserved;
27+
};
28+
29+
struct network_tuple {
30+
struct flow_address saddr;
31+
struct flow_address daddr;
32+
__u16 proto;
33+
__u8 ipv;
34+
__u8 reserved;
35+
};
36+
37+
struct flow_state {
38+
__u32 pkts;
39+
__u32 finish_bytes;
40+
};
41+
42+
43+
#pragma GCC diagnostic push
44+
#pragma GCC diagnostic ignored "-Wunused-function"
45+
static __always_inline void *
46+
bpf_map_lookup_or_try_init(void *map, const void *key, const void *init)
47+
{
48+
void *val;
49+
long err;
50+
51+
val = bpf_map_lookup_elem(map, key);
52+
if (val)
53+
return val;
54+
55+
err = bpf_map_update_elem(map, key, init, BPF_NOEXIST);
56+
if (err && err != -EEXIST)
57+
return NULL;
58+
59+
return bpf_map_lookup_elem(map, key);
60+
}
61+
62+
static __always_inline int bpf_max(__u64 left, __u64 right)
63+
{
64+
return right > left ? right : left;
65+
}
66+
67+
68+
/*
69+
* Maps an IPv4 address into an IPv6 address according to RFC 4291 sec 2.5.5.2
70+
*/
71+
static void map_ipv4_to_ipv6(struct in6_addr *ipv6, __be32 ipv4)
72+
{
73+
__builtin_memset(&ipv6->in6_u.u6_addr8[0], 0x00, 10);
74+
__builtin_memset(&ipv6->in6_u.u6_addr8[10], 0xff, 2);
75+
ipv6->in6_u.u6_addr32[3] = ipv4;
76+
}
77+
#pragma GCC diagnostic pop

xdq-tester/fifo.lua

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- SPDX-License-Identifier: GPL-2.0
2+
-- Copyright (c) 2022 Freysteinn Alfredsson <[email protected]>
3+
4+
-- FIFO scheduler
5+
config.bpf.file = "./sched_fifo.bpf.o"
6+
7+
-- Setup flows
8+
packet_flow1 = Udp:new()
9+
packet_flow1.udp.port = 8080
10+
11+
packet_flow2 = Udp:new()
12+
packet_flow2.udp.port = 8081
13+
14+
packet_flow3 = Udp:new()
15+
packet_flow3.udp.port = 8082
16+
17+
18+
-- Test scheduler
19+
enqueue(packet_flow1)
20+
enqueue(packet_flow2)
21+
enqueue(packet_flow3)
22+
23+
dequeue_cmp(packet_flow1)
24+
dequeue_cmp(packet_flow2)
25+
dequeue_cmp(packet_flow3)

0 commit comments

Comments
 (0)