1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Run a series of udpgro benchmarks
5
6readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
7
8cleanup() {
9	local -r jobs="$(jobs -p)"
10	local -r ns="$(ip netns list|grep $PEER_NS)"
11
12	[ -n "${jobs}" ] && kill -INT ${jobs} 2>/dev/null
13	[ -n "$ns" ] && ip netns del $ns 2>/dev/null
14}
15trap cleanup EXIT
16
17run_one() {
18	# use 'rx' as separator between sender args and receiver args
19	local -r all="$@"
20	local -r tx_args=${all%rx*}
21	local rx_args=${all#*rx}
22
23
24
25	ip netns add "${PEER_NS}"
26	ip -netns "${PEER_NS}" link set lo up
27	ip link add type veth
28	ip link set dev veth0 up
29	ip addr add dev veth0 192.168.1.2/24
30	ip addr add dev veth0 2001:db8::2/64 nodad
31
32	ip link set dev veth1 netns "${PEER_NS}"
33	ip -netns "${PEER_NS}" addr add dev veth1 192.168.1.1/24
34	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
35	ip -netns "${PEER_NS}" link set dev veth1 up
36	ip netns exec "${PEER_NS}" ethtool -K veth1 rx-gro-list on
37
38
39	ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
40	tc -n "${PEER_NS}" qdisc add dev veth1 clsact
41	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file ../bpf/nat6to4.o section schedcls/ingress6/nat_6  direct-action
42	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file ../bpf/nat6to4.o section schedcls/egress4/snat4 direct-action
43        echo ${rx_args}
44	ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
45
46	# Hack: let bg programs complete the startup
47	sleep 0.2
48	./udpgso_bench_tx ${tx_args}
49}
50
51run_in_netns() {
52	local -r args=$@
53  echo ${args}
54	./in_netns.sh $0 __subprocess ${args}
55}
56
57run_udp() {
58	local -r args=$@
59
60	echo "udp gso - over veth touching data"
61	run_in_netns ${args} -u -S 0 rx -4 -v
62
63	echo "udp gso and gro - over veth touching data"
64	run_in_netns ${args} -S 0 rx -4 -G
65}
66
67run_tcp() {
68	local -r args=$@
69
70	echo "tcp - over veth touching data"
71	run_in_netns ${args} -t rx -4 -t
72}
73
74run_all() {
75	local -r core_args="-l 4"
76	local -r ipv4_args="${core_args} -4  -D 192.168.1.1"
77	local -r ipv6_args="${core_args} -6  -D 2001:db8::1"
78
79	echo "ipv6"
80	run_tcp "${ipv6_args}"
81	run_udp "${ipv6_args}"
82}
83
84if [ ! -f ../bpf/xdp_dummy.o ]; then
85	echo "Missing xdp_dummy helper. Build bpf selftest first"
86	exit -1
87fi
88
89if [ ! -f bpf/nat6to4.o ]; then
90	echo "Missing nat6to4 helper. Build bpfnat6to4.o selftest first"
91	exit -1
92fi
93
94if [[ $# -eq 0 ]]; then
95	run_all
96elif [[ $1 == "__subprocess" ]]; then
97	shift
98	run_one $@
99else
100	run_in_netns $@
101fi
102