• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
4
5TST_NEEDS_TMPDIR=1
6TST_NEEDS_ROOT=1
7TST_NEEDS_CMDS="sysctl tc"
8
9. tst_net.sh
10
11def_alg="cubic"
12prev_qlen=
13prev_queue=
14prev_alg=
15
16set_cong_alg()
17{
18	local alg=$1
19	tst_res TINFO "setting $alg"
20
21	tst_set_sysctl net.ipv4.tcp_congestion_control $alg safe
22}
23
24tcp_cc_cleanup()
25{
26	local rmt_dev="dev $(tst_iface rhost)"
27
28	[ "$prev_cong_ctl" ] && \
29		tst_set_sysctl net.ipv4.tcp_congestion_control $prev_alg
30
31	[ "$prev_qlen" ] && \
32		tst_rhost_run -c "ip li set txqueuelen $prev_qlen $rmt_dev"
33
34	[ "$prev_queue" ] && \
35		tst_rhost_run -c "tc qdisc replace $rmt_dev root $prev_queue"
36}
37
38tcp_cc_check_support()
39{
40	local proc_cc="/proc/sys/net/ipv4/tcp_available_congestion_control"
41	local alg="$1"
42
43	modprobe tcp_$alg > /dev/null 2>&1
44	grep -q $alg $proc_cc || tst_brk TCONF "Local host doesn't support $alg"
45
46	if [ -z "$TST_USE_NETNS" ]; then
47		tst_rhost_run -c "modprobe tcp_$alg" > /dev/null 2>&1
48		tst_rhost_run -c "grep -q $alg $proc_cc" || \
49			tst_brk TCONF "Remote host doesn't support $alg"
50	fi
51}
52
53tcp_cc_setup()
54{
55	prev_alg="$(sysctl -n net.ipv4.tcp_congestion_control)"
56}
57
58tcp_cc_set_qdisc()
59{
60	local qdisc="$1"
61	local qlen="${2:-1000}"
62	local rmt_dev="$(tst_iface rhost)"
63
64	tst_res TINFO "set qdisc on $(tst_iface rhost) to $qdisc len $qlen"
65
66	[ -z "$prev_qlen" ] && \
67		prev_qlen=$(tst_rhost_run -s -c \
68			    "cat /sys/class/net/$rmt_dev/tx_queue_len")
69	tst_rhost_run -s -c "ip link set txqueuelen $qlen dev $rmt_dev"
70
71	[ -z "$prev_queue" ] && \
72		prev_queue=$(tst_rhost_run -s -c \
73			     "tc qdisc show dev $rmt_dev | head -1" | \
74			     cut -f2 -d' ')
75	[ "$qdisc" = "$prev_queue" ] && return 0
76
77	tst_rhost_run -c "tc qdisc replace dev $rmt_dev root $qdisc" >/dev/null
78	if [ $? -ne 0 ]; then
79		tst_res TCONF "$qdisc qdisc not supported"
80		return 1
81	fi
82
83	return 0
84}
85
86tcp_cc_test01()
87{
88	local alg=$1
89	local threshold=${2:-10}
90
91	tst_res TINFO "compare '$def_alg' and '$alg' congestion alg. results"
92
93	set_cong_alg "$def_alg"
94
95	tst_netload -H $(tst_ipaddr rhost) -A 15000
96	local res0="$(cat tst_netload.res)"
97
98	set_cong_alg "$alg"
99
100	tst_netload -H $(tst_ipaddr rhost) -A 15000
101	local res1="$(cat tst_netload.res)"
102
103	local per=$(( $res0 * 100 / $res1 - 100 ))
104
105	if [ "$per" -lt "$threshold" ]; then
106		tst_res TFAIL "$alg performance $per %"
107	else
108		tst_res TPASS "$alg performance $per %"
109	fi
110}
111