brintos

brintos / linux-shallow public Read only

0
0
Text · 2.4 KiB · 17404f4 Raw
105 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Run a series of udpgro benchmarks5 6source net_helper.sh7 8readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"9 10BPF_FILE="xdp_dummy.bpf.o"11 12cleanup() {13	local -r jobs="$(jobs -p)"14	local -r ns="$(ip netns list|grep $PEER_NS)"15 16	[ -n "${jobs}" ] && kill -INT ${jobs} 2>/dev/null17	[ -n "$ns" ] && ip netns del $ns 2>/dev/null18}19trap cleanup EXIT20 21run_one() {22	# use 'rx' as separator between sender args and receiver args23	local -r all="$@"24	local -r tx_args=${all%rx*}25	local rx_args=${all#*rx}26 27 28 29	ip netns add "${PEER_NS}"30	ip -netns "${PEER_NS}" link set lo up31	ip link add type veth32	ip link set dev veth0 up33	ip addr add dev veth0 192.168.1.2/2434	ip addr add dev veth0 2001:db8::2/64 nodad35 36	ip link set dev veth1 netns "${PEER_NS}"37	ip -netns "${PEER_NS}" addr add dev veth1 192.168.1.1/2438	ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad39	ip -netns "${PEER_NS}" link set dev veth1 up40	ip netns exec "${PEER_NS}" ethtool -K veth1 rx-gro-list on41 42 43	ip -n "${PEER_NS}" link set veth1 xdp object ${BPF_FILE} section xdp44	tc -n "${PEER_NS}" qdisc add dev veth1 clsact45	tc -n "${PEER_NS}" filter add dev veth1 ingress prio 4 protocol ipv6 bpf object-file nat6to4.bpf.o section schedcls/ingress6/nat_6  direct-action46	tc -n "${PEER_NS}" filter add dev veth1 egress prio 4 protocol ip bpf object-file nat6to4.bpf.o section schedcls/egress4/snat4 direct-action47        echo ${rx_args}48	ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &49 50	wait_local_port_listen "${PEER_NS}" 8000 udp51	./udpgso_bench_tx ${tx_args}52}53 54run_in_netns() {55	local -r args=$@56  echo ${args}57	./in_netns.sh $0 __subprocess ${args}58}59 60run_udp() {61	local -r args=$@62 63	echo "udp gso - over veth touching data"64	run_in_netns ${args} -u -S 0 rx -4 -v65 66	echo "udp gso and gro - over veth touching data"67	run_in_netns ${args} -S 0 rx -4 -G68}69 70run_tcp() {71	local -r args=$@72 73	echo "tcp - over veth touching data"74	run_in_netns ${args} -t rx -4 -t75}76 77run_all() {78	local -r core_args="-l 4"79	local -r ipv4_args="${core_args} -4  -D 192.168.1.1"80	local -r ipv6_args="${core_args} -6  -D 2001:db8::1"81 82	echo "ipv6"83	run_tcp "${ipv6_args}"84	run_udp "${ipv6_args}"85}86 87if [ ! -f ${BPF_FILE} ]; then88	echo "Missing ${BPF_FILE}. Run 'make' first"89	exit -190fi91 92if [ ! -f nat6to4.bpf.o ]; then93	echo "Missing nat6to4 helper. Run 'make' first"94	exit -195fi96 97if [[ $# -eq 0 ]]; then98	run_all99elif [[ $1 == "__subprocess" ]]; then100	shift101	run_one $@102else103	run_in_netns $@104fi105