• 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	tst_set_sysctl net.ipv4.tcp_congestion_control $alg safe
33}
34
35cleanup()
36{
37	if [ "$prev_cong_ctl" ]; then
38		tst_set_sysctl net.ipv4.tcp_congestion_control $prev_alg
39	fi
40	tst_rmdir
41	tc qdisc del dev $(tst_iface) root netem loss 0.03% ecn
42}
43
44setup()
45{
46	if tst_kvcmp -lt "3.18"; then
47		tst_brkm TCONF "test requires kernel 3.18 or newer"
48	fi
49
50	tst_require_root
51	tst_check_cmds ip sysctl tc
52
53	tst_resm TINFO "emulate congestion with packet loss 0.03% and ECN"
54	tc qdisc add dev $(tst_iface) root netem loss 0.03% ecn > /dev/null 2>&1
55	if [ $? -ne 0 ]; then
56		tst_brkm TCONF "netem doesn't support ECN"
57	fi
58
59	tst_tmpdir
60
61	prev_alg="$(sysctl -n net.ipv4.tcp_congestion_control)"
62}
63
64test_run()
65{
66	tst_resm TINFO "compare '$def_alg' and 'dctcp' congestion alg. results"
67
68	set_cong_alg "$def_alg"
69
70	tst_netload -H $(tst_ipaddr rhost)
71	local res0="$(cat tst_netload.res)"
72
73	set_cong_alg "dctcp"
74
75	tst_netload -H $(tst_ipaddr rhost)
76	local res1="$(cat tst_netload.res)"
77
78	local per=$(( $res0 * 100 / $res1 - 100 ))
79
80	if [ "$per" -lt "10" ]; then
81		tst_resm TFAIL "dctcp performance $per %"
82	else
83		tst_resm TPASS "dctcp performance $per %"
84	fi
85}
86
87setup
88
89test_run
90
91tst_exit
92