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