• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) International Business Machines  Corp., 2005                 ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21##                                                                            ##
22################################################################################
23#
24# File:
25#   tcp4-uni-basic01
26#
27# Description:
28#   Verify that the kernel is not crashed with a connection to with
29#   the following condition:
30#     - The version of IP is IPv4
31#     - Network is not delayed
32#     - IPsec is not used
33#     - Disable window scaling
34#     - Enable Nagle algorithm
35#     - Enable TCP Duplicate SACK support
36#     - Enable SACK Support
37#     - No packet are lost
38#     - No packet are duplicated
39#     - Disable TSO if it is avalable
40#
41#   *) This script may be read by the other test case
42#
43# Setup:
44#   See testcases/network/stress/README
45#
46# Author:
47#   Mitsuru Chinen <mitch@jp.ibm.com>
48#
49# History:
50#	Oct 19 2005 - Created (Mitsuru Chinen)
51#
52#-----------------------------------------------------------------------
53# Uncomment line below for debug output.
54#trace_logic=${trace_logic:-"set -x"}
55$trace_logic
56
57# The test case ID, the test case count and the total number of test case
58TCID=${TCID:-tcp4-uni-basic01}
59TST_TOTAL=1
60TST_COUNT=1
61export TCID
62export TST_COUNT
63export TST_TOTAL
64
65
66
67# Test description
68NON_BASIC=${NON_BASIC:-false}
69$NON_BASIC || tst_resm TINFO "Verify that the kernel is not crashed by a TCP connection"
70
71# Make sure the value of LTPROOT
72LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
73export LTPROOT
74
75# Check the environmanet variable
76. check_envval || exit $TST_TOTAL
77
78# Dulation of the test [sec]
79NS_DURATION=${NS_DURATION:-3600}      # 1 hour
80
81# The number of the test link where tests run
82LINK_NUM=${LINK_NUM:-0}
83
84# The version of IP
85IP_VER=${IP_VER:-4}
86
87# true, if ipsec is used
88DO_IPSEC=${DO_IPSEC:-false}
89
90# The value of SPI
91SPI=${SPI:-1000}
92
93# IPsec Protocol ( ah / esp / ipcomp )
94IPSEC_PROTO=${IPSEC_PROTO:-ah}
95
96# IPsec Mode ( transport / tunnel )
97IPSEC_MODE=${IPSEC_MODE:-transport}
98
99# true, if network is delayed
100DO_NET_DELAY=${DO_NET_DELAY:-false}
101
102# Amount of network delay [ms]
103NET_DELAY=${NET_DELAY:-600}
104
105# The deflection of network delay [ms]
106NET_DELAY_DEFL=${NET_DELAY_DEFL:-200}
107
108# true, if some packets are lost
109DO_PACKET_LOSS=${DO_PACKET_LOSS:-false}
110
111# Rate of packet loss [%]
112PACKET_LOSS_RATE=${PACKET_LOSS_RATE:-8}
113
114# true, if some packets are duplicated
115DO_PACKET_DUP=${DO_PACKET_DUP:-false}
116
117# Rate of packet dupulication [%]
118PACKET_DUP_RATE=${PACKET_DUP_RATE:-1}
119
120# true, if test is for small sending (Namely, disable NAGLE algorithm)
121DO_SMALL_SEND=${DO_SMALL_SEND:-false}
122
123# true, if test is for window scaling
124DO_WINDOW_SCALING=${DO_WINDOW_SCALING:-false}
125
126# true, if test is for DSACK
127DO_DSACK=${DO_DSACK:-true}
128
129# true, if test is for SACK
130DO_SACK=${DO_SACK:-true}
131
132# true, if test is for TSO
133DO_TSO=${DO_TSO:-false}
134
135#-----------------------------------------------------------------------
136#
137# Function: do_cleanup
138#
139# Description:
140#   Recover the system configuration
141#
142#-----------------------------------------------------------------------
143do_cleanup()
144{
145    # Kill the tcp traffic server
146    killall_tcp_traffic
147
148    # Enable window scaling
149    sysctl -w net.ipv4.tcp_window_scaling=1 >/dev/null 2>&1
150
151    # Enable TCP Duplicate SACK support
152    sysctl -w net.ipv4.tcp_dsack=1 >/dev/null 2>&1
153
154    # Enable SACK support
155    sysctl -w net.ipv4.tcp_sack=1 >/dev/null 2>&1
156
157    # Restore the tcp segmentation offload setting
158    if [ x${tso_orig} != x ]; then
159	ethtool -K $lhost_ifname tso $tso_orig
160    fi
161
162    # Unset SAD/SPD
163    output_ipsec_conf flush | setkey -c >/dev/null 2>&1
164    $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
165
166    # Disable network emulator
167    if [ x$rhost_ifname = x ]; then
168	rhost_ifname=`get_ifname rhost $LINK_NUM`
169    fi
170    $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1
171
172    # Clean up each interface
173    initialize_if lhost ${LINK_NUM} || exit 1
174    initialize_if rhost ${LINK_NUM} || exit 1
175}
176
177
178#-----------------------------------------------------------------------
179#
180# Function: do_setup
181#
182# Description:
183#   Setup the system for testing
184#
185#-----------------------------------------------------------------------
186do_setup()
187{
188    # Output the informaion
189    tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
190    tst_resm TINFO "- Version of IP is IPv${IP_VER}"
191
192    # Addtional server option
193    server_opt=""
194
195    # Addtional client option
196    client_opt=""
197
198    # Original TSO parameter
199    tso_orig=""
200
201    # Check the remote host has netem functionality
202    if $DO_NET_DELAY || $DO_PACKET_LOSS || $DO_PACKET_DUP ; then
203	message=`check_netem`
204	if [ $? -ne 0 ]; then
205	    tst_resm TBROK "$message"
206	    exit 1
207	fi
208    fi
209
210    $DO_NET_DELAY && tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms"
211
212    $DO_PACKET_LOSS && tst_resm TINFO "- Packet loss rate is ${PACKET_LOSS_RATE}%%"
213
214    $DO_PACKET_DUP && tst_resm TINFO "- Packet duplication rate is ${PACKET_DUP_RATE}%%"
215
216    # Check the setkey command is available
217    if $DO_IPSEC ; then
218	message=`check_setkey`
219	if [ $? -ne 0 ]; then
220	    tst_resm TBROK "$message"
221	    exit 1
222	fi
223
224	case $IPSEC_PROTO in
225	    ah)
226	    tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
227	    ;;
228	    esp)
229	    tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
230	    ;;
231	    ipcomp)
232	    tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
233	    ;;
234	esac
235    fi
236
237    # name of interface of the local/remote host
238    lhost_ifname=`get_ifname lhost $LINK_NUM`
239    if [ $? -ne 0 ]; then
240	tst_resm TBROK "Failed to get the interface name at the local host"
241	exit $TST_TOTAL
242    fi
243    rhost_ifname=`get_ifname rhost $LINK_NUM`
244    if [ $? -ne 0 ]; then
245	tst_resm TBROK "Failed to get the interface name at the remote host"
246	exit $TST_TOTAL
247    fi
248
249    # Initialize the system configuration
250    do_cleanup
251
252    # Call do_cleanup function before exit
253    trap do_cleanup 0
254
255    # Add option for small sending test
256    if $DO_SMALL_SEND ; then
257	server_opt="-s"
258    fi
259
260    # Configure window scaling parameter
261    if $DO_WINDOW_SCALING ; then
262	server_opt="-w"
263	client_opt="-w"
264	sysctl -w net.ipv4.tcp_window_scaling=1 >/dev/null
265	if [ $? -ne 0 ]; then
266	    tst_resm TBROK "Failed to enable window scaling"
267	    exit 1
268	fi
269    else
270	sysctl -w net.ipv4.tcp_window_scaling=0 >/dev/null 2>&1
271    fi
272
273    # Configure DSACK parameter
274    if $DO_DSACK ; then
275	sysctl -w net.ipv4.tcp_dsack=1 >/dev/null
276	if [ $? -ne 0 ]; then
277	    tst_resm TBROK "Failed to enable Duplicate SACK"
278	    exit 1
279	fi
280    else
281	sysctl -w net.ipv4.tcp_dsack=0 >/dev/null 2>&1
282    fi
283
284    # Configure SACK parameter
285    if $DO_SACK ; then
286	sysctl -w net.ipv4.tcp_sack=1 >/dev/null
287	if [ $? -ne 0 ]; then
288	    tst_resm TBROK "Failed to enable SACK"
289	    exit 1
290	fi
291    else
292	sysctl -w net.ipv4.tcp_sack=0 >/dev/null 2>&1
293    fi
294
295    # Store the current TSO parameter, then configure it
296    offload_info=`mktemp -p $TMPDIR`
297    ethtool -k $lhost_ifname > $offload_info 2>/dev/null
298    fgrep "tcp segmentation offload" $offload_info >/dev/null 2>&1
299    if [ $? -ne 0 ]; then
300	if $DO_TSO ; then
301	    tst_resm TCONF "The device at $lhost_ifname does not support TSO."
302	    rm -f $offload_info
303	    exit 1
304	fi
305	tso_orig=`fgrep "tcp segmentation offload" $offload_info | sed -e 's/^.*: //'`
306	if $DO_TSO ; then
307	    server_opt="-w"
308	    client_opt="-w"
309	    ethtool -K $lhost_ifname tso on
310	else
311	    ethtool -K $lhost_ifname tso off
312	fi
313    fi
314    rm -f $offload_info
315
316    # Configure the network interface
317    case $IP_VER in
318	4)
319	# Network portion of the IPv4 address
320	network_part=${IPV4_NETWORK:-"10.0.0"}
321
322	# Netmask of the IPv4 network
323	network_mask=24
324
325	# Host portion of the IPv4 address
326	lhost_host_part=${LHOST_IPV4_HOST:-"2"}     # local host
327	rhost_host_part=${RHOST_IPV4_HOST:-"1"}     # remote host
328
329	# Set IPv4 addresses to the interfaces
330	set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part
331	if [ $? -ne 0 ]; then
332	    tst_resm TBROK "Failed to add any IP address at the local host"
333	    exit 1
334	fi
335
336	set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part
337	if [ $? -ne 0 ]; then
338	    tst_resm TBROK "Failed to add any IP address at the remote host"
339	    exit 1
340	fi
341
342	# IPv4 address of the local/remote host
343	lhost_addr="${network_part}.${lhost_host_part}"
344	rhost_addr="${network_part}.${rhost_host_part}"
345	;;
346
347	6)
348	# Network portion of the IPv6 address
349	network_part="fd00:1:1:1"
350
351	# Netmask of the IPv6 network
352	network_mask=64
353
354	# Host portion of the IPv6 address
355	lhost_host_part=":2"     # local host
356	rhost_host_part=":1"     # remote host
357
358	# Set IPv6 addresses to the interfaces
359	add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part
360	if [ $? -ne 0 ]; then
361	    tst_resm TBROK "Failed to add any IP address at the local host"
362	    exit 1
363	fi
364
365	add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part
366	if [ $? -ne 0 ]; then
367	    tst_resm TBROK "Failed to add any IP address at the remote host"
368	    exit 1
369	fi
370
371	# IPv6 address of the local/remote host
372	lhost_addr="${network_part}:${lhost_host_part}"
373	rhost_addr="${network_part}:${rhost_host_part}"
374	;;
375
376	*)
377	tst_resm TBROK "Unknown IP version"
378	;;
379    esac
380
381    netem_param=
382
383    # Make the network delay
384    if $DO_NET_DELAY ; then
385	netem_param="delay ${NET_DELAY}ms ${NET_DELAY_DEFL}ms distribution normal"
386	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc add dev $rhost_ifname root netem $netem_param' ; echo $?'`
387	if [ $ret -ne 0 ]; then
388	    tst_resm TBROK "Failed to make the delayed network"
389	    exit 1
390	fi
391    fi
392
393    # Make some packets lost
394    if $DO_PACKET_LOSS ; then
395	tc_cmd="add"
396	if [ x"$netem_param" != x ]; then
397	    tc_cmd="change"
398	fi
399	netem_param="loss ${PACKET_LOSS_RATE}% $netem_param"
400	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc $tc_cmd dev $rhost_ifname root netem $netem_param' ; echo $?'`
401	if [ $ret -ne 0 ]; then
402	    tst_resm TBROK "Failed to use netem functionality"
403	    exit 1
404	fi
405    fi
406
407    # Make some packets duplicated
408    if $DO_PACKET_DUP ; then
409	tc_cmd="add"
410	if [ x"$netem_param" != x ]; then
411	    tc_cmd="change"
412	fi
413	netem_param="duplicate ${PACKET_DUP_RATE}% $netem_param"
414	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc $tc_cmd dev $rhost_ifname root netem $netem_param' ; echo $?'`
415	if [ $ret -ne 0 ]; then
416	    tst_resm TBROK "Failed to use netem functionality"
417	    exit 1
418	fi
419    fi
420
421    # Configure SAD/SPD
422    if $DO_IPSEC ; then
423	# Set SAD/SPD according to the variables
424	ipsec_log=`mktemp -p $TMPDIR`
425	output_ipsec_conf src \
426	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
427		|  setkey -c 2>&1 | tee $ipsec_log
428	if [ $? -ne 0 -o -s $ipsec_log ]; then
429	    tst_resm TBROK "Failed to configure SAD/SPD on the local host."
430	    rm -f $ipsec_log
431	    exit 1
432	fi
433
434	$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/output_ipsec_conf dst $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr' | PATH=/sbin:/usr/sbin:$PATH setkey -c' 2>&1 | tee $ipsec_log
435	if [ $? -ne 0 -o -s $ipsec_log ]; then
436	    tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
437	    rm -f $ipsec_log
438	    exit 1
439	fi
440    fi
441
442    # Make sure the connectvity
443    case $IP_VER in
444	4)
445	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
446	if [ $ret -ne 0 ]; then
447	    tst_resm TBROK "There is no IPv4 connectivity."
448	    exit 1
449	fi
450	;;
451
452	6)
453	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
454	if [ $ret -ne 0 ]; then
455	    tst_resm TBROK "There is no IPv6 connectivity."
456	    exit 1
457	fi
458	;;
459    esac
460
461}
462
463#-----------------------------------------------------------------------
464#
465# Main
466#
467#
468
469do_setup
470
471# Find the available consecutive ports
472server_port=`find_portbundle tcp 1025 1`
473if [ $? -ne 0 ]; then
474    tst_resm TBROK "No port is available."
475    exit 1
476fi
477
478# Run a tcp traffic server
479info_file=`mktemp -p $TMPDIR`
480ns-tcpserver -b -f $IP_VER -p $server_port -o $info_file $server_opt
481if [ $? -ne 0 ]; then
482    tst_resm TFAIL "Failed to run a tcp traffic server."
483    rm -f $info_file
484    exit 1
485fi
486
487while true ; do
488    if [ -s $info_file ]; then
489	break
490    fi
491done
492
493server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
494rm -f $info_file
495
496# Run a tcp taffic client
497ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port $client_opt' ; echo $?'`
498if [ $ret -ne 0 ]; then
499    tst_resm TFAIL "Failed to run a tcp traffic client"
500    exit 1
501fi
502
503start_epoc=`date +%s`
504while true ; do
505    current_epoc=`date +%s`
506    elapse_epoc=`expr $current_epoc - $start_epoc`
507
508    if [ $elapse_epoc -ge $NS_DURATION ]; then
509	killall -SIGHUP ns-tcpserver
510	break
511    fi
512
513    # Watch the TCP traffic server
514    ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1
515    if [ $? -ne 0 ]; then
516	tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]"
517	exit 1
518    fi
519    sleep 1
520done
521
522
523#-----------------------------------------------------------------------
524#
525# Clean up
526#
527
528tst_resm TPASS "Test is finished successfully."
529exit 0
530