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