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-multi-diffport01 26# 27# Description: 28# Verify that the kernel is not crashed with multiple connection to the 29# different ports with the following condition: 30# - The version of IP is IPv4 31# - Network is not delayed 32# - IPsec is not used 33# 34# *) This script may be read by the other test case 35# 36# Setup: 37# See testcases/network/stress/README 38# 39# Author: 40# Mitsuru Chinen <mitch@jp.ibm.com> 41# 42# History: 43# Oct 19 2005 - Created (Mitsuru Chinen) 44# 45#----------------------------------------------------------------------- 46# Uncomment line below for debug output. 47#trace_logic=${trace_logic:-"set -x"} 48$trace_logic 49 50# The test case ID, the test case count and the total number of test case 51TCID=${TCID:-tcp4-multi-diffport01} 52TST_TOTAL=1 53TST_COUNT=1 54export TCID 55export TST_COUNT 56export TST_TOTAL 57 58# Test description 59tst_resm TINFO "Verify that the kernel is not crashed with multiple connection to the different ports." 60 61# Make sure the value of LTPROOT 62LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`} 63export LTPROOT 64 65# Check the environmanet variable 66. check_envval || exit $TST_TOTAL 67 68# Dulation of the test [sec] 69NS_DURATION=${NS_DURATION:-3600} # 1 hour 70 71# Quantity of the connection for multi connection test 72CONNECTION_TOTAL=${CONNECTION_TOTAL:-4000} 73 74#The number of the test link where tests run 75LINK_NUM=${LINK_NUM:-0} 76 77# The version of IP 78IP_VER=${IP_VER:-4} 79 80# true, if ipsec is used 81DO_IPSEC=${DO_IPSEC:-false} 82 83# The value of SPI 84SPI=${SPI:-1000} 85 86# IPsec Protocol ( ah / esp / ipcomp ) 87IPSEC_PROTO=${IPSEC_PROTO:-ah} 88 89# IPsec Mode ( transport / tunnel ) 90IPSEC_MODE=${IPSEC_MODE:-transport} 91 92# true, if network is delayed 93DO_NET_DELAY=${DO_NET_DELAY:-false} 94 95# Amount of network delay [ms] 96NET_DELAY=${NET_DELAY:-600} 97 98# The deflection of network delay [ms] 99NET_DELAY_DEFL=${NET_DELAY_DEFL:-200} 100 101 102#----------------------------------------------------------------------- 103# 104# Function: do_cleanup 105# 106# Description: 107# Recover the system configuration 108# 109#----------------------------------------------------------------------- 110do_cleanup() 111{ 112 # Kill the tcp traffic server 113 killall_tcp_traffic 114 115 # Unset SAD/SPD 116 output_ipsec_conf flush | setkey -c >/dev/null 2>&1 117 $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1 118 119 # Unset network delay 120 if [ x$rhost_ifname = x ]; then 121 rhost_ifname=`get_ifname rhost $LINK_NUM` 122 fi 123 $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1 124 125 # Clean up each interface 126 initialize_if lhost ${LINK_NUM} 127 initialize_if rhost ${LINK_NUM} 128} 129 130 131#----------------------------------------------------------------------- 132# 133# Setup 134# 135 136# Unset the maximum number of processes 137ulimit -u unlimited 138 139# Output the informaion 140tst_resm TINFO "- Test duration is $NS_DURATION [sec]" 141tst_resm TINFO "- Target number of the connection is $CONNECTION_TOTAL" 142tst_resm TINFO "- Version of IP is IPv${IP_VER}" 143 144if $DO_NET_DELAY ; then 145 message=`check_netem` 146 if [ $? -ne 0 ]; then 147 tst_resm TBROK "$message" 148 exit 1 149 fi 150 tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms" 151fi 152 153if $DO_IPSEC ; then 154 message=`check_setkey` 155 if [ $? -ne 0 ]; then 156 tst_resm TBROK "$message" 157 exit 1 158 fi 159 160 case $IPSEC_PROTO in 161 ah) 162 tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]" 163 ;; 164 esp) 165 tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]" 166 ;; 167 ipcomp) 168 tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]" 169 ;; 170 esac 171fi 172 173# name of interface of the local/remote host 174lhost_ifname=`get_ifname lhost $LINK_NUM` 175if [ $? -ne 0 ]; then 176 tst_resm TBROK "Failed to get the interface name at the local host" 177 exit $TST_TOTAL 178fi 179 180rhost_ifname=`get_ifname rhost $LINK_NUM` 181if [ $? -ne 0 ]; then 182 tst_resm TBROK "Failed to get the interface name at the remote host" 183 exit $TST_TOTAL 184fi 185 186# Initialize the system configuration 187do_cleanup 188 189# Call do_cleanup function before exit 190trap do_cleanup 0 191 192# Configurate IP addresses 193case $IP_VER in 194 4) 195 # Network portion of the IPv4 address 196 network_part=${IPV4_NETWORK:-"10.0.0"} 197 198 # Netmask of the IPv4 network 199 network_mask=24 200 201 # Host portion of the IPv4 address 202 lhost_host_part=${LHOST_IPV4_HOST:-"2"} # local host 203 rhost_host_part=${RHOST_IPV4_HOST:-"1"} # remote host 204 205 # Set IPv4 addresses to the interfaces 206 set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part 207 if [ $? -ne 0 ]; then 208 tst_resm TBROK "Failed to add any IP address at the local host" 209 exit 1 210 fi 211 set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part 212 if [ $? -ne 0 ]; then 213 tst_resm TBROK "Failed to add any IP address at the remote host" 214 exit 1 215 fi 216 217 # IPv4 address of the local/remote host 218 lhost_addr="${network_part}.${lhost_host_part}" 219 rhost_addr="${network_part}.${rhost_host_part}" 220 ;; 221 222 6) 223 # Network portion of the IPv6 address 224 network_part="fd00:1:1:1" 225 226 # Netmask of the IPv6 network 227 network_mask=64 228 229 # Host portion of the IPv6 address 230 lhost_host_part=":2" # local host 231 rhost_host_part=":1" # remote host 232 233 # Set IPv6 addresses to the interfaces 234 add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part 235 if [ $? -ne 0 ]; then 236 tst_resm TBROK "Failed to add any IP address at the local host" 237 exit 1 238 fi 239 240 add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part 241 if [ $? -ne 0 ]; then 242 tst_resm TBROK "Failed to add any IP address at the remote host" 243 exit 1 244 fi 245 246 # IPv6 address of the local/remote host 247 lhost_addr="${network_part}:${lhost_host_part}" 248 rhost_addr="${network_part}:${rhost_host_part}" 249 ;; 250 251 *) 252 tst_resm TBROK "Unknown IP version" 253 ;; 254esac 255 256# Make the network delay 257if $DO_NET_DELAY ; then 258 ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc add dev $rhost_ifname root netem delay ${NET_DELAY}ms ${NET_DELAY_DEFL}ms distribution normal' ; echo $?'` 259 if [ $ret -ne 0 ]; then 260 tst_resm TBROK "Failed to make the delayed network" 261 exit 1 262 fi 263fi 264 265# Configure SAD/SPD 266if $DO_IPSEC ; then 267 ipsec_log=`mktemp -p $TMPDIR` 268 269 output_ipsec_conf src \ 270 $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \ 271 | setkey -c 2>&1 | tee $ipsec_log 272 if [ $? -ne 0 -o -s $ipsec_log ]; then 273 tst_resm TBROK "Failed to configure SAD/SPD on the local host." 274 rm -f $ipsec_log 275 exit 1 276 fi 277 278 $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 279 if [ $? -ne 0 -o -s $ipsec_log ]; then 280 tst_resm TBROK "Failed to configure SAD/SPD on the remote host." 281 rm -f $ipsec_log 282 exit 1 283 fi 284 rm -f $ipsec_log 285fi 286 287# Make sure the connectvity 288case $IP_VER in 289 4) 290 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 291 if [ $ret -ne 0 ]; then 292 tst_resm TBROK "There is no IPv4 connectivity." 293 exit 1 294 fi 295 ;; 296 297 6) 298 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 299 if [ $ret -ne 0 ]; then 300 tst_resm TBROK "There is no IPv6 connectivity." 301 exit 1 302 fi 303 ;; 304esac 305 306 307#----------------------------------------------------------------------- 308# 309# Main 310# 311# 312 313# Find the available consecutive ports 314portbundle=`find_portbundle tcp 1025 $CONNECTION_TOTAL` 315if [ $? -ne 0 ]; then 316 tst_resm TBROK "No port is available." 317 exit 1 318fi 319 320start_port=`echo $portbundle | cut -f 1 -d '-'` 321end_port=`echo $portbundle | cut -f 2 -d '-'` 322 323# Making connections 324connection_num=0 325current_port=$start_port 326while [ $current_port -le $end_port ]; do 327 # Run a server 328 ns-tcpserver -b -f $IP_VER -p $current_port 329 if [ $? -ne 0 ]; then 330 # Failed to start no server 331 if [ $connection_num -eq 0 ]; then 332 tst_resm TFAIL "Failed to run a server" 333 exit 1 334 fi 335 # Failed to start a server 336 tst_resm TINFO "$connection_num seems the maximum number of the server" 337 break 338 fi 339 340 # Run a clinet 341 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $current_port' ; echo $?'` 342 if [ $ret -ne 0 ]; then 343 # Failed to start any client 344 if [ $connection_num -eq 0 ]; then 345 tst_resm TFAIL "Failed to run any client." 346 exit 1 347 fi 348 # Failed to start a client 349 tst_resm TINFO "$connection_num seems the maximum number of the client" 350 break 351 fi 352 353 current_port=`expr $current_port + 1` 354 connection_num=`expr $connection_num + 1` 355done 356 357 358# Watch the TCP traffic server 359start_epoc=`date +%s` 360while true ; do 361 current_epoc=`date +%s` 362 elapse_epoc=`expr $current_epoc - $start_epoc` 363 if [ $elapse_epoc -ge $NS_DURATION ]; then 364 killall -SIGHUP ns-tcpserver 365 break 366 else 367 ps auxw | fgrep -v grep | fgrep -l ns-tcpserver >/dev/null 2>&1 368 if [ $? -ne 0 ]; then 369 tst_resm TFAIL "All tcp traffic servers are dead in $elapse_epoc [sec]" 370 exit 1 371 fi 372 fi 373 sleep 1 374done 375 376#----------------------------------------------------------------------- 377# 378# Clean up 379# 380 381tst_resm TPASS "Test is finished successfully." 382exit 0 383