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 #   udp4-multi-diffip01
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed with receiving and sending UDP
     29 #   datagram 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 (at] 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
     50 TCID=${TCID:-udp4-multi-diffip01}
     51 TST_TOTAL=1
     52 TST_COUNT=1
     53 export TCID
     54 export TST_COUNT
     55 export TST_TOTAL
     56 
     57 # Test description
     58 tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending UDP datagram at the different IP addresses(aliases) with the following conditions"
     59 
     60 # Make sure the value of LTPROOT
     61 LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
     62 export LTPROOT
     63 
     64 # Check the environmanet variable
     65 . check_envval || exit $TST_TOTAL
     66 
     67 # Dulation of the test [sec]
     68 NS_DURATION=${NS_DURATION:-3600}      # 1 hour
     69 
     70 # The number of IP address (alias)
     71 IP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}
     72 
     73 #The number of the test link where tests run
     74 LINK_NUM=${LINK_NUM:-0}
     75 
     76 # The version of IP
     77 IP_VER=${IP_VER:-4}
     78 
     79 # true, if ipsec is used
     80 DO_IPSEC=${DO_IPSEC:-false}
     81 
     82 # The value of SPI
     83 SPI=${SPI:-1000}
     84 
     85 # IPsec Protocol ( ah / esp / ipcomp )
     86 IPSEC_PROTO=${IPSEC_PROTO:-ah}
     87 
     88 # IPsec Mode ( transport / tunnel )
     89 IPSEC_MODE=${IPSEC_MODE:-transport}
     90 
     91 
     92 #-----------------------------------------------------------------------
     93 #
     94 # Function: do_cleanup
     95 #
     96 # Description:
     97 #   Recover the system configuration
     98 #
     99 #-----------------------------------------------------------------------
    100 do_cleanup()
    101 {
    102     # Kill the udp traffic server
    103     killall_udp_traffic
    104 
    105     # Unset SAD/SPD
    106     output_ipsec_conf flush | setkey -c >/dev/null 2>&1
    107     $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
    108 
    109     # Clean up each interface
    110     initialize_if lhost ${LINK_NUM}
    111     initialize_if rhost ${LINK_NUM}
    112 }
    113 
    114 
    115 #-----------------------------------------------------------------------
    116 #
    117 # Setup
    118 #
    119 
    120 # Unset the maximum number of processes
    121 ulimit -u unlimited
    122 
    123 # Output the informaion
    124 tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
    125 tst_resm TINFO "- Target number of the connection is $IP_TOTAL_FOR_TCPIP"
    126 tst_resm TINFO "- Version of IP is IPv${IP_VER}"
    127 
    128 if $DO_IPSEC ; then
    129     message=`check_setkey`
    130     if [ $? -ne 0 ]; then
    131 	tst_resm TBROK "$message"
    132 	exit 1
    133     fi
    134 
    135     case $IPSEC_PROTO in
    136 	ah)
    137 	tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
    138 	;;
    139 	esp)
    140 	tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
    141 	;;
    142 	ipcomp)
    143 	tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
    144 	;;
    145     esac
    146 fi
    147 
    148 # name of interface of the local/remote host
    149 lhost_ifname=`get_ifname lhost $LINK_NUM`
    150 if [ $? -ne 0 ]; then
    151     tst_resm TBROK "Failed to get the interface name at the local host"
    152     exit $TST_TOTAL
    153 fi
    154 
    155 rhost_ifname=`get_ifname rhost $LINK_NUM`
    156 if [ $? -ne 0 ]; then
    157     tst_resm TBROK "Failed to get the interface name at the remote host"
    158     exit $TST_TOTAL
    159 fi
    160 
    161 # Initialize the system configuration
    162 do_cleanup
    163 
    164 # Call do_cleanup function before exit
    165 trap do_cleanup 0
    166 
    167 # Loop to assign IP addresses
    168 ipaddr_pair_num=0
    169 while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
    170     # Add new IP addresses
    171     x=`expr $ipaddr_pair_num \/ 255 % 255`
    172     y=`expr $ipaddr_pair_num % 255`
    173     if [ $x -ge 255 ]; then
    174 	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
    175 	break
    176     fi
    177 
    178     case $IP_VER in
    179 	4)
    180 	network_part="10.${x}.${y}"
    181 	network_broadcast=${network_part}.255
    182 	network_mask=24
    183 	lhost_addr="${network_part}.2"
    184 	rhost_addr="${network_part}.1"
    185 
    186 	# Set IPv4 addresses to the interfaces
    187 	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
    188 
    189 	### delete before setting
    190 	if [ $? -eq 2 ]; then
    191 	ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname  2>&1
    192 	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
    193 	fi
    194 
    195 	if [ $? -ne 0 ]; then
    196 	    if [ $ipaddr_pair_num -eq 0 ]; then
    197 		tst_resm TBROK "Failed to add any IP address at the local"
    198 		exit 1
    199 	    else
    200 		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
    201 	    fi
    202 	    break
    203 	fi
    204 
    205 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
    206 	if [ $ret -eq 2 ]; then
    207 	$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
    208 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
    209 	fi
    210 	if [ $ret -ne 0 ]; then
    211 	    if [ $ipaddr_pair_num -eq 0 ]; then
    212 		tst_resm TBROK "Failed to add any IP address at the remote"
    213 		exit 1
    214 	    else
    215 		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
    216 	    fi
    217 	    break
    218 	fi
    219 	;;
    220 
    221 	6)
    222 	hex_x=`printf %x $x`
    223 	hex_y=`printf %x $y`
    224 
    225 	network_part="fd00:1:${hex_x}:${hex_y}"
    226 	network_mask=64
    227 	lhost_addr="${network_part}::2"
    228 	rhost_addr="${network_part}::1"
    229 
    230 	# Set IPv6 addresses to the interfaces
    231 	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
    232 
    233 	if [ $ret -eq 2 ]; then
    234 	ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname  2>&1
    235 	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
    236 	fi
    237 
    238 	if [ $? -ne 0 ]; then
    239 	    if [ $ipaddr_pair_num -eq 0 ]; then
    240 		tst_resm TBROK "Failed to add any IP address at the local"
    241 		exit 1
    242 	    else
    243 		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
    244 	    fi
    245 	    break
    246 	fi
    247 
    248 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
    249 
    250 	if [ $ret -eq 2 ]; then
    251 	LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
    252 	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
    253 	fi
    254 
    255 	if [ $ret -ne 0 ]; then
    256 	    if [ $ipaddr_pair_num -eq 0 ]; then
    257 		tst_resm TBROK "Failed to add any IP address at the remote"
    258 		exit 1
    259 	    else
    260 		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
    261 	    fi
    262 	    break
    263 	fi
    264 	;;
    265     esac
    266 
    267     # Set SAD/SPD
    268     if $DO_IPSEC ; then
    269 	ipsec_log=`mktemp -p $TMPDIR`
    270 	output_ipsec_conf src \
    271 	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
    272 		| setkey -c 2>&1 | tee $ipsec_log
    273 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    274 	    rm -f $ipsec_log
    275 	    if [ $ipaddr_pair_num -eq 0 ]; then
    276 		tst_resm TBROK "Failed to add any SAD/SPD"
    277 		exit 1
    278 	    else
    279 		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
    280 	    fi
    281 	    break
    282 	fi
    283 	rm -f $ipsec_log
    284 
    285 	$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
    286 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    287 	    rm -f $ipsec_log
    288 	    if [ $ipaddr_pair_num -eq 0 ]; then
    289 		tst_resm TBROK "Failed to add any SAD/SPD"
    290 		exit 1
    291 	    else
    292 		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
    293 	    fi
    294 	    break
    295 	fi
    296 	rm -f $ipsec_log
    297     fi
    298 
    299     # Check the connectivity
    300     case $IP_VER in
    301 	4)
    302 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    303 	if [ $ret -ne 0 ]; then
    304 	    tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP a
    305 	    ddress pair"
    306 	    exit 1
    307 	fi
    308 	;;
    309 
    310 	6)
    311 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    312 	if [ $ret -ne 0 ]; then
    313 	    tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP a
    314 	    ddress pair"
    315 	    exit 1
    316 	fi
    317 	;;
    318     esac
    319 
    320     if [ $? -ne 0 ]; then
    321 	tst_resm TFAIL "There is no connectivity."
    322 	exit 1
    323     fi
    324 
    325     ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
    326 done
    327 
    328 
    329 #-----------------------------------------------------------------------
    330 #
    331 # Main
    332 #
    333 #
    334 
    335 # Find the available consecutive ports
    336 server_port=`find_portbundle udp 1025 1`
    337 if [ $? -ne 0 ]; then
    338     tst_resm TBROK "No port is available."
    339     exit 1
    340 fi
    341 
    342 # Run a UDP traffic server
    343 info_file=`mktemp -p $TMPDIR`
    344 ns-udpserver -b -f $IP_VER -p $server_port -o $info_file
    345 if [ $? -ne 0 ]; then
    346     tst_resm TFAIL "Failed to run a UDP traffic server"
    347     exit 1
    348 fi
    349 
    350 # Collect the information of the server
    351 while true ; do
    352     if [ -s $info_file ]; then
    353 	break
    354     fi
    355 done
    356 server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
    357 rm -f $info_file
    358 
    359 # Make connections
    360 connection_num=0
    361 while [ $connection_num -lt $ipaddr_pair_num ]; do
    362     # IP addresses
    363     x=`expr $connection_num \/ 255 % 255`
    364     y=`expr $connection_num % 255`
    365 
    366     case $IP_VER in
    367 	4)
    368 	lhost_addr="10.${x}.${y}.2"
    369 	;;
    370 
    371 	6)
    372 	hex_x=`printf %x $x`
    373 	hex_y=`printf %x $y`
    374 	lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
    375 	;;
    376     esac
    377 
    378     # Run a client
    379     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
    380     if [ $ret -ne 0 ]; then
    381 	if [ $connection_num -eq 0 ]; then
    382 	    tst_resm TFAIL "Failed to run any client"
    383 	    exit 1
    384 	else
    385 	    tst_resm TINFO "$connection_num seems the maximum number of the client"
    386 	fi
    387 	break
    388     fi
    389     connection_num=`expr $connection_num + 1`
    390 done
    391 
    392 
    393 # Watch the UDP traffic server
    394 start_epoc=`date +%s`
    395 while true ; do
    396     current_epoc=`date +%s`
    397     elapse_epoc=`expr $current_epoc - $start_epoc`
    398 
    399     if [ $elapse_epoc -ge $NS_DURATION ]; then
    400 	break
    401     else
    402 	ps auxw | fgrep ns-udpserver | fgrep -l $server_pid >/dev/null 2>&1
    403 	if [ $? -ne 0 ]; then
    404 	    tst_resm TFAIL "udp traffic server is dead in $elapse_epoc [sec]"
    405 	    exit 1
    406 	fi
    407     fi
    408     sleep 1
    409 done
    410 
    411 
    412 #-----------------------------------------------------------------------
    413 #
    414 # Clean up
    415 #
    416 
    417 tst_resm TPASS "Test is finished successfully."
    418 exit 0
    419