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