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