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