Home | History | Annotate | Download | only in packet-flood
      1 #!/bin/sh
      2 
      3 ################################################################################
      4 ##                                                                            ##
      5 ## Copyright (c) International Business Machines  Corp., 2006                 ##
      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 #   mcast4-pktfld02
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed when joining plural IPv4 multicast
     29 #   groups on separate sockets, then receiving a large number of UDP packets at
     30 #   the each socket
     31 #
     32 # Setup:
     33 #   See ltp-yyyymmdd/testcases/network/stress/README
     34 #
     35 # Author:
     36 #   Mitsuru Chinen <mitch (at] jp.ibm.com>
     37 #
     38 # History:
     39 #	May 1 2006 - Created (Mitsuru Chinen)
     40 #
     41 #-----------------------------------------------------------------------
     42 # Uncomment line below for debug output.
     43 #trace_logic=${trace_logic:-"set -x"}
     44 $trace_logic
     45 
     46 # The test case ID, the test case count and the total number of test case
     47 TCID=mcast4-pktfld02
     48 TST_TOTAL=1
     49 TST_COUNT=1
     50 export TCID
     51 export TST_COUNT
     52 export TST_TOTAL
     53 
     54 LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
     55 export LTPROOT
     56 
     57 # Check the environmanet variable
     58 . check_envval || exit $TST_TOTAL
     59 
     60 # Dulation of the test [sec]
     61 NS_DURATION=${NS_DURATION:-3600}      # 1 hour
     62 
     63 # The number of the test link where tests run
     64 LINK_NUM=${LINK_NUM:-0}
     65 
     66 # Network portion of the IPv4 address
     67 NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
     68 
     69 # Netmask of the IPv4 network
     70 NETWORK_MASK=24
     71 
     72 # Host portion of the IPv4 address
     73 LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
     74 RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
     75 
     76 # Prefix of the multicast address
     77 MCAST_ADDR_PREFIX=224.10
     78 
     79 # Number of the multicast connection
     80 MCASTNUM_NORMAL=${MCASTNUM_NORMAL:-20}
     81 
     82 
     83 #-----------------------------------------------------------------------
     84 #
     85 # Function: do_cleanup
     86 #
     87 # Description:
     88 #   Recover the system configuration
     89 #
     90 #-----------------------------------------------------------------------
     91 do_cleanup()
     92 {
     93     # Make sure to kill the multicast receiver and sender
     94     killall -SIGHUP ns-mcast_receiver >/dev/null 2>&1
     95     $LTP_RSH $RHOST killall -SIGHUP ns-udpsender >/dev/null 2>&1
     96 
     97     # Clean up each interface
     98     initialize_if lhost ${LINK_NUM}
     99     initialize_if rhost ${LINK_NUM}
    100 }
    101 
    102 
    103 #-----------------------------------------------------------------------
    104 #
    105 # Function: do_setup
    106 #
    107 # Description:
    108 #   Configure the ssystem for the test
    109 #
    110 #-----------------------------------------------------------------------
    111 do_setup()
    112 {
    113     # Initialize the system configuration
    114     do_cleanup
    115 
    116     # Call do_cleanup function before exit
    117     trap do_cleanup 0
    118 
    119     # Unset the maximum number of processes
    120     ulimit -u unlimited
    121 
    122     # name of interface of the local/remote host
    123     lhost_ifname=`get_ifname lhost $LINK_NUM`
    124     if [ $? -ne 0 ]; then
    125 	tst_resm TBROK "Failed to get the interface name at the local host"
    126 	exit $TST_TOTAL
    127     fi
    128 
    129     rhost_ifname=`get_ifname rhost $LINK_NUM`
    130     if [ $? -ne 0 ]; then
    131 	tst_resm TBROK "Failed to get the interface name at the remote host"
    132 	exit $TST_TOTAL
    133     fi
    134 
    135     # Set IPv4 addresses to the interfaces
    136     set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
    137     if [ $? -ne 0 ]; then
    138 	tst_resm TBROK "Failed to add any IP address at the local host"
    139 	exit 1
    140     fi
    141 
    142     set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
    143     if [ $? -ne 0 ]; then
    144 	tst_resm TBROK "Failed to add any IP address at the remote host"
    145 	exit 1
    146     fi
    147 
    148     # IPv4 address of the local/remote host
    149     lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
    150     rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
    151 
    152     # Make sure the connectvity
    153     check_icmpv4_connectivity $lhost_ifname $rhost_addr
    154     if [ $? -ne 0 ]; then
    155 	tst_resm TBROK "There is no IPv4 connectivity."
    156 	exit 1
    157     fi
    158 
    159     # Make sure the sysctl values
    160     sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_NORMAL >/dev/null
    161     if [ $? -ne 0 ]; then
    162 	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
    163 	exit $TST_TOTAL
    164     fi
    165 
    166     sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
    167     sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
    168     sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
    169 }
    170 
    171 
    172 #-----------------------------------------------------------------------
    173 #
    174 # Main
    175 #
    176 #
    177 
    178 # Test description
    179 tst_resm TINFO "Verify that the kernel is not crashed when joining $MCASTNUM_NORMAL IPv4 multicast groups on separate sockets, then receiving a large number of UDP packets at the each socket in $NS_DURATION [sec]"
    180 
    181 # Make sure the value of LTPROOT
    182 do_setup
    183 
    184 mcastnum=0
    185 mcast_port_range=`find_portbundle udp 1025 $MCASTNUM_NORMAL`
    186 if [ $? -ne 0 ]; then
    187     tst_resm TBROK "Failed to get enough port"
    188     exit 1
    189 fi
    190 mcast_port_top=`echo $mcast_port_range | cut -f 1 -d '-'`
    191 
    192 while [ $mcastnum -lt $MCASTNUM_NORMAL ]; do
    193     # Define the multicast address
    194     x=`expr $mcastnum \/ 254`
    195     y=`expr $mcastnum % 254 + 1`
    196     if [ $x -gt 254 ]; then
    197 	tst_resm TINFO "The number of the connection is less than $mcastnum"
    198 	break
    199     fi
    200     mcast_addr=${MCAST_ADDR_PREFIX}.${x}.${y}
    201 
    202     # Run a receiver
    203     mcast_port=`expr $mcast_port_top + $mcastnum`
    204     ns-mcast_receiver -f 4 -I $lhost_ifname -m $mcast_addr -p $mcast_port -b
    205     if [ $? -ne 0 ]; then
    206 	tst_resm TBROK "Failed to start multicast receiver"
    207 	exit 1
    208     fi
    209 
    210     # Run a sender
    211     $LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpsender -D $mcast_addr -f 4 -p $mcast_port -m -I $rhost_ifname -b -t $NS_DURATION
    212 
    213     mcastnum=`expr $mcastnum + 1`
    214 done
    215 
    216 sleep $NS_DURATION
    217 do_cleanup
    218 
    219 #-----------------------------------------------------------------------
    220 #
    221 # Clean up
    222 #
    223 
    224 tst_resm TPASS "Test is finished successfully."
    225 exit 0
    226