Home | History | Annotate | Download | only in multi-diffip
      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-diffip01
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed with multiple connection to the
     29 #   different IP address(alias) 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 ltp-yyyymmdd/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-diffip01}
     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 different IP address(alias)."
     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 # The number of IP address (alias)
     72 IP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}
     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     # 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
    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 $IP_TOTAL_FOR_TCPIP"
    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 # Make the network delay
    193 if $DO_NET_DELAY ; then
    194     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 $?'`
    195     if [ $ret -ne 0 ]; then
    196 	tst_resm TBROK "Failed to make the delayed network"
    197 	exit 1
    198     fi
    199 fi
    200 
    201 # Loop for assign IP addresses
    202 ipaddr_pair_num=0
    203 while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
    204     # Add new IP addresses
    205     x=`expr $ipaddr_pair_num \/ 255 % 255`
    206     y=`expr $ipaddr_pair_num % 255`
    207     if [ $x -ge 255 ]; then
    208 	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
    209 	break
    210     fi
    211 
    212     case $IP_VER in
    213 	4)
    214 	network_part="10.${x}.${y}"
    215 	network_broadcast=${network_part}.255
    216 	network_mask=24
    217 	lhost_addr="${network_part}.2"
    218 	rhost_addr="${network_part}.1"
    219 
    220 	# Set IPv4 addresses to the interfaces
    221 	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
    222 	if [ $? -eq 2 ]; then
    223 		ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname  2>&1
    224 		ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
    225 	fi
    226 	if [ $? -ne 0 ]; then
    227 	    if [ $ipaddr_pair_num -eq 0 ]; then
    228 		tst_resm TBROK "Failed to add any IP address at the local"
    229 		exit 1
    230 	    else
    231 		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
    232 	    fi
    233 	    break
    234 	fi
    235 
    236 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
    237 
    238 	if [ $ret -eq 2 ]; then
    239 		$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
    240 		ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
    241 	fi
    242 
    243 	if [ $ret -ne 0 ]; then
    244 	    if [ $ipaddr_pair_num -eq 0 ]; then
    245 		tst_resm TBROK "Failed to add any IP address at the remote"
    246 		exit 1
    247 	    else
    248 		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
    249 	    fi
    250 	    break
    251 	fi
    252 	;;
    253 
    254 	6)
    255 	hex_x=`printf %x $x`
    256 	hex_y=`printf %x $y`
    257 
    258 	network_part="fd00:1:${hex_x}:${hex_y}"
    259 	network_mask=64
    260 	lhost_addr="${network_part}::2"
    261 	rhost_addr="${network_part}::1"
    262 
    263 	# Set IPv6 addresses to the interfaces
    264 	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
    265 
    266 	if [ $? -eq 2 ]; then
    267 		ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname  2>&1
    268 		ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
    269 	fi
    270 
    271 	if [ $? -ne 0 ]; then
    272 	    if [ $ipaddr_pair_num -eq 0 ]; then
    273 		tst_resm TBROK "Failed to add any IP address at the local"
    274 		exit 1
    275 	    else
    276 		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
    277 	    fi
    278 	    break
    279 	fi
    280 
    281 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
    282 
    283 	if [ $ret -eq 2 ]; then
    284 		$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
    285 		ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
    286 	fi
    287 
    288 	if [ $ret -ne 0 ]; then
    289 	    if [ $ipaddr_pair_num -eq 0 ]; then
    290 		tst_resm TBROK "Failed to add any IP address at the remote"
    291 		exit 1
    292 	    else
    293 		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
    294 	    fi
    295 	    break
    296 	fi
    297 	;;
    298     esac
    299 
    300     # Set SAD/SPD
    301     if $DO_IPSEC ; then
    302 	ipsec_log=`mktemp -p $TMPDIR`
    303 	output_ipsec_conf src \
    304 	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
    305 		    | setkey -c 2>&1 | tee $ipsec_log
    306 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    307 	    rm -f $ipsec_log
    308 	    if [ $ipaddr_pair_num -eq 0 ]; then
    309 		tst_resm TBROK "Failed to add any SAD/SPD"
    310 		exit 1
    311 	    else
    312 		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
    313 	    fi
    314 	    break
    315 	fi
    316 	rm -f $ipsec_log
    317 
    318 	$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
    319 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    320 	    rm -f $ipsec_log
    321 	    if [ $ipaddr_pair_num -eq 0 ]; then
    322 		tst_resm TBROK "Failed to add any SAD/SPD"
    323 		exit 1
    324 	    else
    325 		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
    326 	    fi
    327 	    break
    328 	fi
    329 	rm -f $ipsec_log
    330     fi
    331 
    332     # Check the connectivity
    333     case $IP_VER in
    334 	4)
    335 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    336 	if [ $ret -ne 0 ]; then
    337 	    tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP address pair"
    338 	    exit 1
    339 	fi
    340 	;;
    341 
    342 	6)
    343 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    344 	if [ $ret -ne 0 ]; then
    345 	    tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP address pair"
    346 	    exit 1
    347 	fi
    348 	;;
    349     esac
    350 
    351     if [ $? -ne 0 ]; then
    352 	tst_resm TFAIL "There is no connectivity."
    353 	exit 1
    354     fi
    355 
    356     ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
    357 done
    358 
    359 
    360 #-----------------------------------------------------------------------
    361 #
    362 # Main
    363 #
    364 #
    365 
    366 # Find the available consecutive ports
    367 server_port=`find_portbundle tcp 1025 1`
    368 if [ $? -ne 0 ]; then
    369     tst_resm TFAIL "No port is available."
    370     exit 1
    371 fi
    372 
    373 # Run a server
    374 info_file=`mktemp -p $TMPDIR`
    375 
    376 ns-tcpserver -b -c -f $IP_VER -p $server_port -o $info_file
    377 if [ $? -ne 0 ]; then
    378     tst_resm TFAIL "Failed to run tcp traffic server."
    379     rm -f $info_file
    380     exit 1
    381 fi
    382 
    383 while true ; do
    384     if [ -s $info_file ]; then
    385 	break
    386     fi
    387 done
    388 
    389 server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
    390 rm -f $info_file
    391 
    392 # Make connections
    393 connection_num=0
    394 while [ $connection_num -lt $ipaddr_pair_num ]; do
    395     # IP addresses
    396     x=`expr $connection_num \/ 255 % 255`
    397     y=`expr $connection_num % 255`
    398 
    399     case $IP_VER in
    400 	4)
    401 	lhost_addr="10.${x}.${y}.2"
    402 	;;
    403 
    404 	6)
    405 	hex_x=`printf %x $x`
    406 	hex_y=`printf %x $y`
    407 	lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
    408 	;;
    409     esac
    410 
    411     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
    412     if [ $ret -ne 0 ]; then
    413 	if [ $connection_num -eq 0 ]; then
    414 	    tst_resm TFAIL "Failed to run any client"
    415 		exit 1
    416 	else
    417 	    tst_resm TINFO "$connection_num seems the maximum number of the client"
    418 	fi
    419 	break
    420     fi
    421     connection_num=`expr $connection_num + 1`
    422 done
    423 
    424 # Watch the TCP traffic server
    425 start_epoc=`date +%s`
    426 while true ; do
    427     current_epoc=`date +%s`
    428     elapse_epoc=`expr $current_epoc - $start_epoc`
    429 
    430     if [ $elapse_epoc -ge $NS_DURATION ]; then
    431 	killall -SIGHUP ns-tcpserver
    432 	break
    433     else
    434 	ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1
    435 	if [ $? -ne 0 ]; then
    436 	    tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]"
    437 	    exit 1
    438 	fi
    439     fi
    440     sleep 1
    441 done
    442 
    443 
    444 #-----------------------------------------------------------------------
    445 #
    446 # Clean up
    447 #
    448 
    449 tst_resm TPASS "Test is finished successfully."
    450 exit 0
    451