1#!/bin/sh
2# Copyright (c) 2014-2017 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, write the Free Software Foundation,
16# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17#
18# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
19#
20
21TST_NETLOAD_MAX_SRV_REPLIES=3
22TST_TOTAL=1
23TCID="tcp_fastopen"
24TST_NEEDS_TMPDIR=1
25
26. test_net.sh
27
28while getopts :hr:n:R:6 opt; do
29	case "$opt" in
30	h)
31		echo "Usage:"
32		echo "h        help"
33		echo "R x      num of requests, after which conn. closed"
34		echo "6        run over IPv6"
35		exit 0
36	;;
37	R) TST_NETLOAD_MAX_SRV_REPLIES=$OPTARG ;;
38	6) # skip, test_net library already processed it
39	;;
40	*) tst_brkm TBROK "unknown option: $opt" ;;
41	esac
42done
43
44cleanup()
45{
46	tst_rmdir
47	tc qdisc del dev $(tst_iface) root netem delay 100 >/dev/null
48}
49
50compare()
51{
52	tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off ))
53
54	if [ "$tfo_cmp" -lt 3 ]; then
55		tst_resm TFAIL "$1 perf result is '$tfo_cmp' percent"
56	else
57		tst_resm TPASS "$1 perf result is '$tfo_cmp' percent"
58	fi
59}
60
61tst_require_root
62
63if tst_kvcmp -lt "3.7"; then
64	tst_brkm TCONF "test must be run with kernel 3.7 or newer"
65fi
66
67if tst_kvcmp -lt "3.16" && [ "$TST_IPV6" ]; then
68	tst_brkm TCONF "test must be run with kernel 3.16 or newer"
69fi
70
71trap "tst_brkm TBROK 'test interrupted'" INT
72TST_CLEANUP="cleanup"
73
74ROD tc qdisc add dev $(tst_iface) root netem delay 100
75
76tst_resm TINFO "using old TCP API and set tcp_fastopen to '0'"
77tst_netload -H $(tst_ipaddr rhost) -t 0
78time_tfo_off=$(cat tst_netload.res)
79
80tst_resm TINFO "using new TCP API and set tcp_fastopen to '3'"
81tst_netload -H $(tst_ipaddr rhost) -f -t 3
82time_tfo_on=$(cat tst_netload.res)
83
84compare
85
86tst_kvcmp -lt "4.11" && \
87	tst_brkm TCONF "next test must be run with kernel 4.11 or newer"
88
89tst_resm TINFO "using connect() and TCP_FASTOPEN_CONNECT socket option"
90tst_netload -H $(tst_ipaddr rhost) -F -t 3
91time_tfo_on=$(cat tst_netload.res)
92
93compare
94
95tst_exit
96