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-diffnic01 26# 27# Description: 28# Verify that the kernel is not crashed with multiple connection to the 29# different NIC 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-diffnic01} 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 NIC." 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#The number of the test link where tests run 72LINK_NUM=${LINK_NUM:-0} 73 74# The version of IP 75IP_VER=${IP_VER:-4} 76 77# true, if ipsec is used 78DO_IPSEC=${DO_IPSEC:-false} 79 80# The value of SPI 81SPI=${SPI:-1000} 82 83# IPsec Protocol ( ah / esp / ipcomp ) 84IPSEC_PROTO=${IPSEC_PROTO:-ah} 85 86# IPsec Mode ( transport / tunnel ) 87IPSEC_MODE=${IPSEC_MODE:-transport} 88 89# true, if network is delayed 90DO_NET_DELAY=${DO_NET_DELAY:-false} 91 92# Amount of network delay [ms] 93NET_DELAY=${NET_DELAY:-600} 94 95# The deflection of network delay [ms] 96NET_DELAY_DEFL=${NET_DELAY_DEFL:-200} 97 98 99#----------------------------------------------------------------------- 100# 101# Function: do_cleanup 102# 103# Description: 104# Recover the system configuration 105# 106#----------------------------------------------------------------------- 107do_cleanup() 108{ 109 # Kill the tcp traffic server 110 killall_tcp_traffic 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 # Clean up each interface 117 link_num=0 118 while [ $link_num -lt $link_total ]; do 119 # Unset network delay 120 rhost_ifname=`get_ifname rhost $link_num` 121 $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1 122 123 # Initialize the interfaces 124 initialize_if lhost ${link_num} 125 initialize_if rhost ${link_num} 126 127 link_num=`expr $link_num + 1` 128 done 129} 130 131 132#----------------------------------------------------------------------- 133# 134# Setup 135# 136# 137 138# Unset the maximum number of processes 139ulimit -u unlimited 140 141# Output the informaion 142tst_resm TINFO "- Test duration is $NS_DURATION [sec]" 143 144link_total=`echo $LHOST_HWADDRS | wc -w` 145rhost_link_total=`echo $RHOST_HWADDRS | wc -w` 146if [ $link_total -ne $rhost_link_total ]; then 147 tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" 148 exit 1 149fi 150if [ $link_total -lt 2 ]; then 151 tst_resm TBROK "This test case requires plural NICs." 152 exit 1 153fi 154tst_resm TINFO "- Target number of the connection is $link_total" 155 156tst_resm TINFO "- Version of IP is IPv${IP_VER}" 157 158if $DO_NET_DELAY ; then 159 message=`check_netem` 160 if [ $? -ne 0 ]; then 161 tst_resm TBROK "$message" 162 exit 1 163 fi 164 tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms" 165fi 166 167if $DO_IPSEC ; then 168 message=`check_setkey` 169 if [ $? -ne 0 ]; then 170 tst_resm TBROK "$message" 171 exit 1 172 fi 173 174 case $IPSEC_PROTO in 175 ah) 176 tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]" 177 ;; 178 esp) 179 tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]" 180 ;; 181 ipcomp) 182 tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]" 183 ;; 184 esac 185fi 186 187# Initialize the system configuration 188do_cleanup 189 190# Call do_cleanup function before exit 191trap do_cleanup 0 192 193# Loop for NIC configuration 194link_num=0 195lhost_addrs="" 196while [ $link_num -lt $link_total ]; do 197 lhost_ifname=`get_ifname lhost $link_num` 198 # name of interface of the local/remote host 199 if [ $? -ne 0 ]; then 200 tst_resm TBROK "Failed to get the interface name at the local host" 201 exit $TST_TOTAL 202 fi 203 rhost_ifname=`get_ifname rhost $link_num` 204 if [ $? -ne 0 ]; then 205 tst_resm TBROK "Failed to get the interface name at the remtoe host" 206 exit $TST_TOTAL 207 fi 208 209 # Set the IP address to each interface 210 case $IP_VER in 211 4) 212 network_part="10.0.${link_num}" 213 network_mask=24 214 lhost_host_part="2" # local host 215 rhost_host_part="1" # remote host 216 set_ipv4addr lhost $link_num $network_part $lhost_host_part 217 if [ $? -ne 0 ]; then 218 tst_resm TBROK "Failed to set IPv4 address at the local host" 219 exit 1 220 fi 221 set_ipv4addr rhost $link_num $network_part $rhost_host_part 222 if [ $? -ne 0 ]; then 223 tst_resm TBROK "Failed to set IPv4 address at the remote host" 224 exit 1 225 fi 226 227 # IPv4 address of the local/remote host 228 lhost_addr="${network_part}.${lhost_host_part}" 229 rhost_addr="${network_part}.${rhost_host_part}" 230 lhost_addrs="${lhost_addrs} ${lhost_addr}" 231 ;; 232 233 6) 234 network_part="fd00:1:0:`printf %x ${link_num}`" 235 network_mask=64 236 lhost_host_part=":2" # local host 237 rhost_host_part=":1" # remote host 238 add_ipv6addr lhost $link_num $network_part $lhost_host_part 239 if [ $? -ne 0 ]; then 240 tst_resm TBROK "Failed to set IPv6 address at the local host" 241 exit 1 242 fi 243 add_ipv6addr rhost $link_num $network_part $rhost_host_part 244 if [ $? -ne 0 ]; then 245 tst_resm TBROK "Failed to set IPv6 address at the remote host" 246 exit 1 247 fi 248 lhost_addr="${network_part}:${lhost_host_part}" 249 rhost_addr="${network_part}:${rhost_host_part}" 250 lhost_addrs="${lhost_addrs} ${lhost_addr}" 251 ;; 252 253 *) 254 tst_resm TBROK "Unknown IP version" 255 ;; 256 esac 257 258 # Make the network delay 259 if $DO_NET_DELAY ; then 260 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 $?'` 261 if [ $ret -ne 0 ]; then 262 tst_resm TBROK "Failed to make the delayed network" 263 exit 1 264 fi 265 fi 266 267 # Configure SAD/SPD 268 if $DO_IPSEC ; then 269 ipsec_log=`mktemp -p $TMPDIR` 270 271 # Set SAD/SPD according to the variables 272 output_ipsec_conf src \ 273 $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \ 274 | setkey -c 2>&1 | tee $ipsec_log 275 if [ $? -ne 0 -o -s $ipsec_log ]; then 276 rm -f $ipsec_log 277 tst_resm TBROK "Failed to configure SAD/SPD on the local host." 278 exit 1 279 fi 280 281 $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 282 if [ $? -ne 0 -o -s $ipsec_log ]; then 283 rm -f $ipsec_log 284 tst_resm TBROK "Failed to configure SAD/SPD on the remote host." 285 exit 1 286 fi 287 rm -f $ipsec_log 288 fi 289 290 # Make sure the connectivity 291 case $IP_VER in 292 4) 293 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 294 if [ $ret -ne 0 ]; then 295 tst_resm TBROK "There is no IPv4 connectivity on Link${link_num}" 296 exit 1 297 fi 298 ;; 299 300 6) 301 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 302 if [ $ret -ne 0 ]; then 303 tst_resm TBROK "There is no IPv6 connectivity on Link${link_num}" 304 exit 1 305 fi 306 ;; 307 esac 308 309 link_num=`expr $link_num + 1` 310done 311 312#----------------------------------------------------------------------- 313# 314# Main 315# 316# 317 318# Find the available consecutive ports 319server_port=`find_portbundle tcp 1025 1` 320if [ $? -ne 0 ]; then 321 tst_resm TBROK "No port is available." 322 exit 1 323fi 324 325# Run a server 326info_file=`mktemp -p $TMPDIR` 327ns-tcpserver -b -c -f $IP_VER -p $server_port -o $info_file 328if [ $? -ne 0 ]; then 329 tst_resm TFAIL "Failed to run tcp traffic server." 330 rm -f $info_file 331 exit 1 332fi 333 334# Collect the information of the server 335while true ; do 336 if [ -s $info_file ]; then 337 break 338 fi 339done 340server_pid=`grep PID: $info_file | cut -f 2 -d ' '` 341rm -f $info_file 342 343# Main loop 344connection_num=0 345while [ $connection_num -lt $link_total ]; do 346 field=`expr $connection_num + 1` 347 lhost_addr=`echo $lhost_addrs | cut -d ' ' -f $field` 348 349 # Run a client 350 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port'; echo $?'` 351 if [ $ret -ne 0 ]; then 352 tst_resm TFAIL "Failed to run client on Link${connection_num}" 353 exit 1 354 fi 355 connection_num=`expr $connection_num + 1` 356done 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 364 if [ $elapse_epoc -ge $NS_DURATION ]; then 365 break 366 else 367 ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1 368 if [ $? -ne 0 ]; then 369 tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]" 370 exit 1 371 fi 372 fi 373 sleep 1 374done 375 376 377#----------------------------------------------------------------------- 378# 379# Clean up 380# 381 382tst_resm TPASS "Test is finished successfully." 383exit 0 384