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 #   udp4-multi-diffport01
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed with receiving and sending UDP
     29 #   datagram at many different ports 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-diffport01}
     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 many different ports 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 # Quantity of the connection for multi connection test
     71 CONNECTION_TOTAL=${CONNECTION_TOTAL:-4000}
     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 $CONNECTION_TOTAL"
    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 
    162 # Initialize the system configuration
    163 do_cleanup
    164 
    165 # Call do_cleanup function before exit
    166 trap do_cleanup 0
    167 
    168 # Configurate IP addresses
    169 case $IP_VER in
    170     4)
    171     # Network portion of the IPv4 address
    172     network_part=${IPV4_NETWORK:-"10.0.0"}
    173 
    174     # Netmask of the IPv4 network
    175     network_mask=24
    176 
    177     # Host portion of the IPv4 address
    178     lhost_host_part=${LHOST_IPV4_HOST:-"2"}     # local host
    179     rhost_host_part=${RHOST_IPV4_HOST:-"1"}     # remote host
    180 
    181     # Set IPv4 addresses to the interfaces
    182     set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part
    183     if [ $? -ne 0 ]; then
    184 	tst_resm TBROK "Failed to add any IP address at the local host"
    185 	exit 1
    186     fi
    187     set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part
    188     if [ $? -ne 0 ]; then
    189 	tst_resm TBROK "Failed to add any IP address at the remote host"
    190 	exit 1
    191     fi
    192 
    193     # IPv4 address of the local/remote host
    194     lhost_addr="${network_part}.${lhost_host_part}"
    195     rhost_addr="${network_part}.${rhost_host_part}"
    196     ;;
    197 
    198     6)
    199     # Network portion of the IPv6 address
    200     network_part="fd00:1:1:1"
    201 
    202     # Netmask of the IPv6 network
    203     network_mask=64
    204 
    205     # Host portion of the IPv6 address
    206     lhost_host_part=":2"     # local host
    207     rhost_host_part=":1"     # remote host
    208 
    209     # Set IPv6 addresses to the interfaces
    210     add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part
    211     if [ $? -ne 0 ]; then
    212 	tst_resm TBROK "Failed to add any IP address at the local host"
    213 	exit 1
    214     fi
    215 
    216     add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part
    217     if [ $? -ne 0 ]; then
    218 	tst_resm TBROK "Failed to add any IP address at the remote host"
    219 	exit 1
    220     fi
    221 
    222     # IPv6 address of the local/remote host
    223     lhost_addr="${network_part}:${lhost_host_part}"
    224     rhost_addr="${network_part}:${rhost_host_part}"
    225     ;;
    226 
    227     *)
    228     tst_resm TBROK "Unknown IP version"
    229     ;;
    230 esac
    231 
    232 # Configure SAD/SPD
    233 if $DO_IPSEC ; then
    234     ipsec_log=`mktemp -p $TMPDIR`
    235 
    236     output_ipsec_conf src \
    237 	$IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
    238 	    |  setkey -c 2>&1 | tee $ipsec_log
    239     if [ $? -ne 0 -o -s $ipsec_log ]; then
    240 	tst_resm TBROK "Failed to configure SAD/SPD on the local host."
    241 	rm -f $ipsec_log
    242 	exit 1
    243     fi
    244 
    245     $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
    246     if [ $? -ne 0 -o -s $ipsec_log ]; then
    247 	tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
    248 	rm -f $ipsec_log
    249 	exit 1
    250     fi
    251     rm -f $ipsec_log
    252 fi
    253 
    254 # Make sure the connectvity
    255 case $IP_VER in
    256     4)
    257     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    258     if [ $ret -ne 0 ]; then
    259 	tst_resm TBROK "There is no IPv4 connectivity."
    260 	exit 1
    261     fi
    262     ;;
    263 
    264     6)
    265     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    266     if [ $ret -ne 0 ]; then
    267 	tst_resm TBROK "There is no IPv6 connectivity."
    268 	exit 1
    269     fi
    270     ;;
    271 esac
    272 
    273 
    274 #-----------------------------------------------------------------------
    275 #
    276 # Main
    277 #
    278 #
    279 
    280 # Find the available consecutive ports
    281 portbundle=`find_portbundle udp 1025 $CONNECTION_TOTAL`
    282 if [ $? -ne 0 ]; then
    283     tst_resm TBROK "No port is available."
    284     exit 1
    285 fi
    286 
    287 start_port=`echo $portbundle | cut -f 1 -d '-'`
    288 end_port=`echo $portbundle | cut -f 2 -d '-'`
    289 
    290 
    291 # Run the pair of server and client
    292 connection_num=0
    293 current_port=$start_port
    294 while [ $current_port -le $end_port ]; do
    295     # Run a UDP traffic server
    296     ns-udpserver -b -f $IP_VER -p $current_port
    297     if [ $? -ne 0 ]; then
    298 	if [ $connection_num -eq 0 ]; then
    299 	    tst_resm TFAIL "Failed to run a server"
    300 	    exit 1
    301 	fi
    302 	tst_resm TINFO "$connection_num seems the maximum number of the client"
    303 	break
    304     fi
    305 
    306     ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpclient -b -f $IP_VER -S $lhost_addr -p $current_port'; echo $?'`
    307     if [ $ret -ne 0 ]; then
    308 	if [ $connection_num -eq 0 ]; then
    309 	    tst_resm TFAIL "Failed to run a client"
    310 	    exit 1
    311 	fi
    312 	tst_resm TINFO "$connection_num seems the maximum number of the client"
    313 	break
    314     fi
    315     current_port=`expr $current_port + 1`
    316     connection_num=`expr $connection_num + 1`
    317 done
    318 
    319 
    320 # Watch the UDP traffic server
    321 start_epoc=`date +%s`
    322 while true ; do
    323     current_epoc=`date +%s`
    324     elapse_epoc=`expr $current_epoc - $start_epoc`
    325     if [ $elapse_epoc -ge $NS_DURATION ]; then
    326 	break
    327     else
    328 	ps auxw | fgrep -v grep | fgrep -l ns-udpserver >/dev/null 2>&1
    329 	if [ $? -ne 0 ]; then
    330 	    tst_resm TFAIL "All udp traffic servers are dead in $elapse_epoc [sec]"
    331 	    exit 1
    332 	fi
    333     fi
    334     sleep 1
    335 done
    336 
    337 #-----------------------------------------------------------------------
    338 #
    339 # Clean up
    340 #
    341 
    342 tst_resm TPASS "Test is finished successfully."
    343 exit 0
    344