aboutsummaryrefslogtreecommitdiff
path: root/testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01
blob: c0d50efaf2e92d9ee27eff75cbc78bb17d17ecaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#!/bin/sh

################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2005                 ##
##                                                                            ##
## This program is free software;  you can redistribute it and#or modify      ##
## it under the terms of the GNU General Public License as published by       ##
## the Free Software Foundation; either version 2 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program is distributed in the hope that it will be useful, but        ##
## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
## for more details.                                                          ##
##                                                                            ##
## You should have received a copy of the GNU General Public License          ##
## along with this program;  if not, write to the Free Software               ##
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
##                                                                            ##
##                                                                            ##
################################################################################
#
# File:
#   udp4-multi-diffip01
#
# Description:
#   Verify that the kernel is not crashed with receiving and sending UDP
#   datagram at different IP address(alias) with the following conditions
#     - The version of IP is IPv4
#     - IPsec is not used
#
#   *) This script may be read by the other test case
#
# Setup:
#   See testcases/network/stress/README
#
# Author:
#   Mitsuru Chinen <mitch@jp.ibm.com>
#
# History:
#	Oct 19 2005 - Created (Mitsuru Chinen)
#
#-----------------------------------------------------------------------
# Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

# The test case ID, the test case count and the total number of test case
TCID=${TCID:-udp4-multi-diffip01}
TST_TOTAL=1
TST_COUNT=1
export TCID
export TST_COUNT
export TST_TOTAL

# Test description
tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending UDP datagram at the different IP addresses(aliases) with the following conditions"

# Make sure the value of LTPROOT
LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
export LTPROOT

# Check the environmanet variable
. check_envval || exit $TST_TOTAL

# Dulation of the test [sec]
NS_DURATION=${NS_DURATION:-3600}      # 1 hour

# The number of IP address (alias)
IP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}

#The number of the test link where tests run
LINK_NUM=${LINK_NUM:-0}

# The version of IP
IP_VER=${IP_VER:-4}

# true, if ipsec is used
DO_IPSEC=${DO_IPSEC:-false}

# The value of SPI
SPI=${SPI:-1000}

# IPsec Protocol ( ah / esp / ipcomp )
IPSEC_PROTO=${IPSEC_PROTO:-ah}

# IPsec Mode ( transport / tunnel )
IPSEC_MODE=${IPSEC_MODE:-transport}


#-----------------------------------------------------------------------
#
# Function: do_cleanup
#
# Description:
#   Recover the system configuration
#
#-----------------------------------------------------------------------
do_cleanup()
{
    # Kill the udp traffic server
    killall_udp_traffic

    # Unset SAD/SPD
    output_ipsec_conf flush | setkey -c >/dev/null 2>&1
    $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1

    # Clean up each interface
    initialize_if lhost ${LINK_NUM}
    initialize_if rhost ${LINK_NUM}
}


#-----------------------------------------------------------------------
#
# Setup
#

# Unset the maximum number of processes
ulimit -u unlimited

# Output the informaion
tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
tst_resm TINFO "- Target number of the connection is $IP_TOTAL_FOR_TCPIP"
tst_resm TINFO "- Version of IP is IPv${IP_VER}"

if $DO_IPSEC ; then
    message=`check_setkey`
    if [ $? -ne 0 ]; then
	tst_resm TBROK "$message"
	exit 1
    fi

    case $IPSEC_PROTO in
	ah)
	tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
	;;
	esp)
	tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
	;;
	ipcomp)
	tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
	;;
    esac
fi

# name of interface of the local/remote host
lhost_ifname=`get_ifname lhost $LINK_NUM`
if [ $? -ne 0 ]; then
    tst_resm TBROK "Failed to get the interface name at the local host"
    exit $TST_TOTAL
fi

rhost_ifname=`get_ifname rhost $LINK_NUM`
if [ $? -ne 0 ]; then
    tst_resm TBROK "Failed to get the interface name at the remote host"
    exit $TST_TOTAL
fi

# Initialize the system configuration
do_cleanup

# Call do_cleanup function before exit
trap do_cleanup 0

# Loop to assign IP addresses
ipaddr_pair_num=0
while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
    # Add new IP addresses
    x=`expr $ipaddr_pair_num \/ 255 % 255`
    y=`expr $ipaddr_pair_num % 255`
    if [ $x -ge 255 ]; then
	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
	break
    fi

    case $IP_VER in
	4)
	network_part="10.${x}.${y}"
	network_broadcast=${network_part}.255
	network_mask=24
	lhost_addr="${network_part}.2"
	rhost_addr="${network_part}.1"

	# Set IPv4 addresses to the interfaces
	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname

	### delete before setting
	if [ $? -eq 2 ]; then
	ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname  2>&1
	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
	fi

	if [ $? -ne 0 ]; then
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any IP address at the local"
		exit 1
	    else
		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
	    fi
	    break
	fi

	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
	if [ $ret -eq 2 ]; then
	$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
	fi
	if [ $ret -ne 0 ]; then
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any IP address at the remote"
		exit 1
	    else
		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
	    fi
	    break
	fi
	;;

	6)
	hex_x=`printf %x $x`
	hex_y=`printf %x $y`

	network_part="fd00:1:${hex_x}:${hex_y}"
	network_mask=64
	lhost_addr="${network_part}::2"
	rhost_addr="${network_part}::1"

	# Set IPv6 addresses to the interfaces
	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname

	if [ $? -eq 2 ]; then
	ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname  2>&1
	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
	fi

	if [ $? -ne 0 ]; then
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any IP address at the local"
		exit 1
	    else
		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
	    fi
	    break
	fi

	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`

	if [ $ret -eq 2 ]; then
	LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
	fi

	if [ $ret -ne 0 ]; then
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any IP address at the remote"
		exit 1
	    else
		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
	    fi
	    break
	fi
	;;
    esac

    # Set SAD/SPD
    if $DO_IPSEC ; then
	ipsec_log=`mktemp -p $TMPDIR`
	output_ipsec_conf src \
	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
		| setkey -c 2>&1 | tee $ipsec_log
	if [ $? -ne 0 -o -s $ipsec_log ]; then
	    rm -f $ipsec_log
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any SAD/SPD"
		exit 1
	    else
		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
	    fi
	    break
	fi
	rm -f $ipsec_log

	$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
	if [ $? -ne 0 -o -s $ipsec_log ]; then
	    rm -f $ipsec_log
	    if [ $ipaddr_pair_num -eq 0 ]; then
		tst_resm TBROK "Failed to add any SAD/SPD"
		exit 1
	    else
		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
	    fi
	    break
	fi
	rm -f $ipsec_log
    fi

    # Check the connectivity
    case $IP_VER in
	4)
	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
	if [ $ret -ne 0 ]; then
	    tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP a
	    ddress pair"
	    exit 1
	fi
	;;

	6)
	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
	if [ $ret -ne 0 ]; then
	    tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP a
	    ddress pair"
	    exit 1
	fi
	;;
    esac

    if [ $? -ne 0 ]; then
	tst_resm TFAIL "There is no connectivity."
	exit 1
    fi

    ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
done


#-----------------------------------------------------------------------
#
# Main
#
#

# Find the available consecutive ports
server_port=`find_portbundle udp 1025 1`
if [ $? -ne 0 ]; then
    tst_resm TBROK "No port is available."
    exit 1
fi

# Run a UDP traffic server
info_file=`mktemp -p $TMPDIR`
ns-udpserver -b -f $IP_VER -p $server_port -o $info_file
if [ $? -ne 0 ]; then
    tst_resm TFAIL "Failed to run a UDP traffic server"
    exit 1
fi

# Collect the information of the server
while true ; do
    if [ -s $info_file ]; then
	break
    fi
done
server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
rm -f $info_file

# Make connections
connection_num=0
while [ $connection_num -lt $ipaddr_pair_num ]; do
    # IP addresses
    x=`expr $connection_num \/ 255 % 255`
    y=`expr $connection_num % 255`

    case $IP_VER in
	4)
	lhost_addr="10.${x}.${y}.2"
	;;

	6)
	hex_x=`printf %x $x`
	hex_y=`printf %x $y`
	lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
	;;
    esac

    # Run a client
    ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
    if [ $ret -ne 0 ]; then
	if [ $connection_num -eq 0 ]; then
	    tst_resm TFAIL "Failed to run any client"
	    exit 1
	else
	    tst_resm TINFO "$connection_num seems the maximum number of the client"
	fi
	break
    fi
    connection_num=`expr $connection_num + 1`
done


# Watch the UDP traffic server
start_epoc=`date +%s`
while true ; do
    current_epoc=`date +%s`
    elapse_epoc=`expr $current_epoc - $start_epoc`

    if [ $elapse_epoc -ge $NS_DURATION ]; then
	break
    else
	ps auxw | fgrep ns-udpserver | fgrep -l $server_pid >/dev/null 2>&1
	if [ $? -ne 0 ]; then
	    tst_resm TFAIL "udp traffic server is dead in $elapse_epoc [sec]"
	    exit 1
	fi
    fi
    sleep 1
done


#-----------------------------------------------------------------------
#
# Clean up
#

tst_resm TPASS "Test is finished successfully."
exit 0