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