1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0-or-later 3 # Copyright (c) 2014-2018 Oracle and/or its affiliates. All Rights Reserved. 4 # 5 # Author: Alexey Kodanev <alexey.kodanev (at] oracle.com> 6 7 TST_SETUP="setup" 8 TST_TESTFUNC="test" 9 TST_CNT=2 10 TST_CLEANUP="cleanup" 11 TST_MIN_KVER="3.7" 12 TST_NEEDS_TMPDIR=1 13 TST_NEEDS_ROOT=1 14 TST_NEEDS_CMDS="tc" 15 TST_OPTS="R:" 16 TST_USAGE=tcp_fastopen_usage 17 TST_PARSE_ARGS=tcp_fastopen_parse_args 18 19 srv_replies=3 20 21 tcp_fastopen_usage() 22 { 23 echo "-R x Number of requests, after which connection is closed" 24 } 25 26 tcp_fastopen_parse_args() 27 { 28 case "$1" in 29 R) srv_replies=$2 ;; 30 esac 31 } 32 33 . tst_net.sh 34 35 cleanup() 36 { 37 tc qdisc del dev $(tst_iface) root netem delay 100 >/dev/null 38 } 39 40 compare() 41 { 42 tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off )) 43 44 if [ "$tfo_cmp" -lt 3 ]; then 45 tst_res TFAIL "$1 perf result is '$tfo_cmp' percent" 46 else 47 tst_res TPASS "$1 perf result is '$tfo_cmp' percent" 48 fi 49 } 50 51 setup() 52 { 53 if tst_kvcmp -lt "3.16" && [ "$TST_IPV6" ]; then 54 tst_brk TCONF "test must be run with kernel 3.16 or newer" 55 fi 56 57 ROD tc qdisc add dev $(tst_iface) root netem delay 100 58 } 59 60 test1() 61 { 62 tst_res TINFO "using old TCP API and set tcp_fastopen to '0'" 63 tst_netload -H $(tst_ipaddr rhost) -t 0 -R $srv_replies 64 time_tfo_off=$(cat tst_netload.res) 65 66 tst_res TINFO "using new TCP API and set tcp_fastopen to '3'" 67 tst_netload -H $(tst_ipaddr rhost) -f -t 3 -R $srv_replies 68 time_tfo_on=$(cat tst_netload.res) 69 70 compare 71 } 72 73 test2() 74 { 75 tst_kvcmp -lt "4.11" && \ 76 tst_brk TCONF "next test must be run with kernel 4.11 or newer" 77 78 tst_res TINFO "using connect() and TCP_FASTOPEN_CONNECT socket option" 79 tst_netload -H $(tst_ipaddr rhost) -F -t 3 -R $srv_replies 80 time_tfo_on=$(cat tst_netload.res) 81 82 compare 83 } 84 85 tst_run 86