• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 2 of
7# the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it would be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
18
19TCID=dctcp01
20TST_TOTAL=1
21TST_CLEANUP="cleanup"
22def_alg="cubic"
23prev_alg=
24
25. test_net.sh
26
27set_cong_alg()
28{
29	local alg=$1
30	tst_resm TINFO "setting $alg"
31
32	ROD sysctl -q -w net.ipv4.tcp_congestion_control=$alg
33	tst_rhost_run -s -c "sysctl -q -w net.ipv4.tcp_congestion_control=$alg"
34}
35
36cleanup()
37{
38	if [ "$prev_cong_ctl" ]; then
39		sysctl -q -w net.ipv4.tcp_congestion_control=$prev_alg
40		tst_rhost_run -c \
41			"sysctl -q -w net.ipv4.tcp_congestion_control=$prev_alg"
42	fi
43	tst_rmdir
44	tc qdisc del dev $(tst_iface) root netem loss 0.03% ecn
45}
46
47setup()
48{
49	tst_kvercmp 3 18 0
50	[ $? -eq 0 ] && tst_brkm TCONF "test requires kernel 3.18 or newer"
51
52	tst_require_root
53	tst_check_cmds ip sysctl tc
54
55	tst_resm TINFO "emulate congestion with packet loss 0.03% and ECN"
56	tc qdisc add dev $(tst_iface) root netem loss 0.03% ecn > /dev/null 2>&1
57	if [ $? -ne 0 ]; then
58		tst_brkm TCONF "netem doesn't support ECN"
59	fi
60
61	tst_tmpdir
62
63	prev_alg="$(cat /proc/sys/net/ipv4/tcp_congestion_control)"
64}
65
66test_run()
67{
68	tst_resm TINFO "compare '$def_alg' and 'dctcp' congestion alg. results"
69
70	set_cong_alg "$def_alg"
71
72	tst_netload $(tst_ipaddr rhost) tfo_res TFO
73	if [ $? -ne 0 ]; then
74		tst_resm TFAIL "test with '$def_alg' has failed"
75		return
76	fi
77	local res0="$(cat tfo_res)"
78	tst_resm TINFO "$def_alg time '$res0' ms"
79
80	set_cong_alg "dctcp"
81
82	tst_netload $(tst_ipaddr rhost) tfo_res TFO
83	if [ $? -ne 0 ]; then
84		tst_resm TFAIL "test with 'dctcp' has failed"
85		return
86	fi
87	local res1="$(cat tfo_res)"
88	tst_resm TINFO "dctcp time '$res1' ms"
89
90	local per=$(( $res0 * 100 / $res1 - 100 ))
91
92	if [ "$per" -lt "10" ]; then
93		tst_resm TFAIL "dctcp performance $per %"
94	else
95		tst_resm TPASS "dctcp performance $per %"
96	fi
97}
98
99setup
100
101test_run
102
103tst_exit
104