Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Run a series of udpgro benchmarks
0005 
0006 readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
0007 
0008 cleanup() {
0009         local -r jobs="$(jobs -p)"
0010         local -r ns="$(ip netns list|grep $PEER_NS)"
0011 
0012         [ -n "${jobs}" ] && kill -INT ${jobs} 2>/dev/null
0013         [ -n "$ns" ] && ip netns del $ns 2>/dev/null
0014 }
0015 trap cleanup EXIT
0016 
0017 run_one() {
0018         # use 'rx' as separator between sender args and receiver args
0019         local -r all="$@"
0020         local -r tx_args=${all%rx*}
0021         local rx_args=${all#*rx}
0022 
0023 
0024 
0025         ip netns add "${PEER_NS}"
0026         ip -netns "${PEER_NS}" link set lo up
0027         ip link add type veth
0028         ip link set dev veth0 up
0029         ip addr add dev veth0 192.168.1.2/24
0030         ip addr add dev veth0 2001:db8::2/64 nodad
0031 
0032         ip link set dev veth1 netns "${PEER_NS}"
0033         ip -netns "${PEER_NS}" addr add dev veth1 192.168.1.1/24
0034         ip -netns "${PEER_NS}" addr add dev veth1 2001:db8::1/64 nodad
0035         ip -netns "${PEER_NS}" link set dev veth1 up
0036         ip netns exec "${PEER_NS}" ethtool -K veth1 rx-gro-list on
0037 
0038 
0039         ip -n "${PEER_NS}" link set veth1 xdp object ../bpf/xdp_dummy.o section xdp
0040         tc -n "${PEER_NS}" qdisc add dev veth1 clsact
0041         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
0042         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
0043         echo ${rx_args}
0044         ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
0045 
0046         # Hack: let bg programs complete the startup
0047         sleep 0.1
0048         ./udpgso_bench_tx ${tx_args}
0049 }
0050 
0051 run_in_netns() {
0052         local -r args=$@
0053   echo ${args}
0054         ./in_netns.sh $0 __subprocess ${args}
0055 }
0056 
0057 run_udp() {
0058         local -r args=$@
0059 
0060         echo "udp gso - over veth touching data"
0061         run_in_netns ${args} -u -S 0 rx -4 -v
0062 
0063         echo "udp gso and gro - over veth touching data"
0064         run_in_netns ${args} -S 0 rx -4 -G
0065 }
0066 
0067 run_tcp() {
0068         local -r args=$@
0069 
0070         echo "tcp - over veth touching data"
0071         run_in_netns ${args} -t rx -4 -t
0072 }
0073 
0074 run_all() {
0075         local -r core_args="-l 4"
0076         local -r ipv4_args="${core_args} -4  -D 192.168.1.1"
0077         local -r ipv6_args="${core_args} -6  -D 2001:db8::1"
0078 
0079         echo "ipv6"
0080         run_tcp "${ipv6_args}"
0081         run_udp "${ipv6_args}"
0082 }
0083 
0084 if [ ! -f ../bpf/xdp_dummy.o ]; then
0085         echo "Missing xdp_dummy helper. Build bpf selftest first"
0086         exit -1
0087 fi
0088 
0089 if [ ! -f bpf/nat6to4.o ]; then
0090         echo "Missing nat6to4 helper. Build bpfnat6to4.o selftest first"
0091         exit -1
0092 fi
0093 
0094 if [[ $# -eq 0 ]]; then
0095         run_all
0096 elif [[ $1 == "__subprocess" ]]; then
0097         shift
0098         run_one $@
0099 else
0100         run_in_netns $@
0101 fi