-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
daefd11
commit d402e53
Showing
11 changed files
with
1,791 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) | ||
|
||
USER_TARGETS := xdq-tester | ||
BPF_TARGETS := $(patsubst %.c,%,$(wildcard *.bpf.c)) | ||
|
||
USER_LIBS = -llua -ldl -lm | ||
|
||
LIB_DIR = ../lib | ||
|
||
include $(LIB_DIR)/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) | ||
|
||
#define EEXIST 17 /* File exists */ | ||
|
||
#define BPF_MAP_TYPE_PIFO_GENERIC 31 | ||
#define BPF_MAP_TYPE_PIFO_XDP 32 | ||
|
||
/* | ||
* bpf_packet_dequeue | ||
* | ||
* Dequeue the packet at the head of the PIFO in *map* and return a pointer | ||
* to the packet (or NULL if the PIFO is empty). | ||
* | ||
* Returns | ||
* On success, a pointer to the packet, or NULL if the PIFO is empty. The | ||
* packet pointer must be freed using *bpf_packet_drop()* or returning | ||
* the packet pointer. The *rank* pointer will be set to the rank of | ||
* the dequeued packet on success, or a negative error code on error. | ||
*/ | ||
static long (*bpf_packet_dequeue)(void *ctx, void *map, __u64 flags, __u64 *rank) = (void *) 194; | ||
static long (*bpf_packet_drop)(void *ctx, void *pkt) = (void *) 195; | ||
|
||
struct flow_address { | ||
struct in6_addr ip; | ||
__u16 port; | ||
__u16 reserved; | ||
}; | ||
|
||
struct network_tuple { | ||
struct flow_address saddr; | ||
struct flow_address daddr; | ||
__u16 proto; | ||
__u8 ipv; | ||
__u8 reserved; | ||
}; | ||
|
||
struct flow_state { | ||
__u32 pkts; | ||
__u32 finish_bytes; | ||
}; | ||
|
||
|
||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wunused-function" | ||
static __always_inline void * | ||
bpf_map_lookup_or_try_init(void *map, const void *key, const void *init) | ||
{ | ||
void *val; | ||
long err; | ||
|
||
val = bpf_map_lookup_elem(map, key); | ||
if (val) | ||
return val; | ||
|
||
err = bpf_map_update_elem(map, key, init, BPF_NOEXIST); | ||
if (err && err != -EEXIST) | ||
return NULL; | ||
|
||
return bpf_map_lookup_elem(map, key); | ||
} | ||
|
||
static __always_inline int bpf_max(__u64 left, __u64 right) | ||
{ | ||
return right > left ? right : left; | ||
} | ||
|
||
|
||
/* | ||
* Maps an IPv4 address into an IPv6 address according to RFC 4291 sec 2.5.5.2 | ||
*/ | ||
static void map_ipv4_to_ipv6(struct in6_addr *ipv6, __be32 ipv4) | ||
{ | ||
__builtin_memset(&ipv6->in6_u.u6_addr8[0], 0x00, 10); | ||
__builtin_memset(&ipv6->in6_u.u6_addr8[10], 0xff, 2); | ||
ipv6->in6_u.u6_addr32[3] = ipv4; | ||
} | ||
#pragma GCC diagnostic pop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- SPDX-License-Identifier: GPL-2.0 | ||
-- Copyright (c) 2022 Freysteinn Alfredsson <[email protected]> | ||
|
||
-- FIFO scheduler | ||
config.bpf.file = "./sched_fifo.bpf.o" | ||
|
||
-- Setup flows | ||
packet_flow1 = Udp:new() | ||
packet_flow1.udp.port = 8080 | ||
|
||
packet_flow2 = Udp:new() | ||
packet_flow2.udp.port = 8081 | ||
|
||
packet_flow3 = Udp:new() | ||
packet_flow3.udp.port = 8082 | ||
|
||
|
||
-- Test scheduler | ||
enqueue(packet_flow1) | ||
enqueue(packet_flow2) | ||
enqueue(packet_flow3) | ||
|
||
dequeue_cmp(packet_flow1) | ||
dequeue_cmp(packet_flow2) | ||
dequeue_cmp(packet_flow3) |
Oops, something went wrong.