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