Home | History | Annotate | Download | only in multi-diffport
      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-diffport01
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed with multiple connection to the
     29 #   different ports 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-diffport01}
     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 ports."
     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     # 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 $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 # Configurate IP addresses
    193 case $IP_VER in
    194     4)
    195     # Network portion of the IPv4 address
    196     network_part=${IPV4_NETWORK:-"10.0.0"}
    197 
    198     # Netmask of the IPv4 network
    199     network_mask=24
    200 
    201     # Host portion of the IPv4 address
    202     lhost_host_part=${LHOST_IPV4_HOST:-"2"}     # local host
    203     rhost_host_part=${RHOST_IPV4_HOST:-"1"}     # remote host
    204 
    205     # Set IPv4 addresses to the interfaces
    206     set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part
    207     if [ $? -ne 0 ]; then
    208 	tst_resm TBROK "Failed to add any IP address at the local host"
    209 	exit 1
    210     fi
    211     set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part
    212     if [ $? -ne 0 ]; then
    213 	tst_resm TBROK "Failed to add any IP address at the remote host"
    214 	exit 1
    215     fi
    216 
    217     # IPv4 address of the local/remote host
    218     lhost_addr="${network_part}.${lhost_host_part}"
    219     rhost_addr="${network_part}.${rhost_host_part}"
    220     ;;
    221 
    222     6)
    223     # Network portion of the IPv6 address
    224     network_part="fd00:1:1:1"
    225 
    226     # Netmask of the IPv6 network
    227     network_mask=64
    228 
    229     # Host portion of the IPv6 address
    230     lhost_host_part=":2"     # local host
    231     rhost_host_part=":1"     # remote host
    232 
    233     # Set IPv6 addresses to the interfaces
    234     add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part
    235     if [ $? -ne 0 ]; then
    236 	tst_resm TBROK "Failed to add any IP address at the local host"
    237 	exit 1
    238     fi
    239 
    240     add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part
    241     if [ $? -ne 0 ]; then
    242 	tst_resm TBROK "Failed to add any IP address at the remote host"
    243 	exit 1
    244     fi
    245 
    246     # IPv6 address of the local/remote host
    247     lhost_addr="${network_part}:${lhost_host_part}"
    248     rhost_addr="${network_part}:${rhost_host_part}"
    249     ;;
    250 
    251     *)
    252     tst_resm TBROK "Unknown IP version"
    253     ;;
    254 esac
    255 
    256 # Make the network delay
    257 if $DO_NET_DELAY ; then
    258     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 $?'`
    259     if [ $ret -ne 0 ]; then
    260 	tst_resm TBROK "Failed to make the delayed network"
    261 	exit 1
    262     fi
    263 fi
    264 
    265 # Configure SAD/SPD
    266 if $DO_IPSEC ; then
    267     ipsec_log=`mktemp -p $TMPDIR`
    268 
    269     output_ipsec_conf src \
    270 	$IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
    271 	    |  setkey -c 2>&1 | tee $ipsec_log
    272     if [ $? -ne 0 -o -s $ipsec_log ]; then
    273 	tst_resm TBROK "Failed to configure SAD/SPD on the local host."
    274 	rm -f $ipsec_log
    275 	exit 1
    276     fi
    277 
    278     $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
    279     if [ $? -ne 0 -o -s $ipsec_log ]; then
    280 	tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
    281 	rm -f $ipsec_log
    282 	exit 1
    283     fi
    284     rm -f $ipsec_log
    285 fi
    286 
    287 # Make sure the connectvity
    288 case $IP_VER in
    289     4)
    290     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    291     if [ $ret -ne 0 ]; then
    292 	tst_resm TBROK "There is no IPv4 connectivity."
    293 	exit 1
    294     fi
    295     ;;
    296 
    297     6)
    298     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    299     if [ $ret -ne 0 ]; then
    300 	tst_resm TBROK "There is no IPv6 connectivity."
    301 	exit 1
    302     fi
    303     ;;
    304 esac
    305 
    306 
    307 #-----------------------------------------------------------------------
    308 #
    309 # Main
    310 #
    311 #
    312 
    313 # Find the available consecutive ports
    314 portbundle=`find_portbundle tcp 1025 $CONNECTION_TOTAL`
    315 if [ $? -ne 0 ]; then
    316     tst_resm TBROK "No port is available."
    317     exit 1
    318 fi
    319 
    320 start_port=`echo $portbundle | cut -f 1 -d '-'`
    321 end_port=`echo $portbundle | cut -f 2 -d '-'`
    322 
    323 # Making connections
    324 connection_num=0
    325 current_port=$start_port
    326 while [ $current_port -le $end_port ]; do
    327     # Run a server
    328     ns-tcpserver -b -f $IP_VER -p $current_port
    329     if [ $? -ne 0 ]; then
    330 	# Failed to start no server
    331 	if [ $connection_num -eq 0 ]; then
    332 	    tst_resm TFAIL "Failed to run a server"
    333 	    exit 1
    334 	fi
    335 	# Failed to start a server
    336 	tst_resm TINFO "$connection_num seems the maximum number of the server"
    337 	break
    338     fi
    339 
    340     # Run a clinet
    341     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $current_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 
    353     current_port=`expr $current_port + 1`
    354     connection_num=`expr $connection_num + 1`
    355 done
    356 
    357 
    358 # Watch the TCP traffic server
    359 start_epoc=`date +%s`
    360 while true ; do
    361     current_epoc=`date +%s`
    362     elapse_epoc=`expr $current_epoc - $start_epoc`
    363     if [ $elapse_epoc -ge $NS_DURATION ]; then
    364 	killall -SIGHUP ns-tcpserver
    365 	break
    366     else
    367 	ps auxw | fgrep -v grep | fgrep -l ns-tcpserver >/dev/null 2>&1
    368 	if [ $? -ne 0 ]; then
    369 	    tst_resm TFAIL "All tcp traffic servers are dead in $elapse_epoc [sec]"
    370 	    exit 1
    371 	fi
    372     fi
    373     sleep 1
    374 done
    375 
    376 #-----------------------------------------------------------------------
    377 #
    378 # Clean up
    379 #
    380 
    381 tst_resm TPASS "Test is finished successfully."
    382 exit 0
    383