Home | History | Annotate | Download | only in multi-diffnic
      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 #   icmp4-multi-diffnic01
     26 #
     27 # Description:
     28 #   Verify that the kernel is not crashed with receiving and sending ICMP
     29 #   message at differnt NIC 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 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:-icmp4-multi-diffnic01}
     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 various size of ICMP message at differnt NIC simultaneously 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 version of IP
     71 IP_VER=${IP_VER:-4}
     72 
     73 # true, if ipsec is used
     74 DO_IPSEC=${DO_IPSEC:-false}
     75 
     76 # The value of SPI
     77 SPI=${SPI:-1000}
     78 
     79 # IPsec Protocol ( ah / esp / ipcomp )
     80 IPSEC_PROTO=${IPSEC_PROTO:-ah}
     81 
     82 # IPsec Mode ( transport / tunnel )
     83 IPSEC_MODE=${IPSEC_MODE:-transport}
     84 
     85 # Array of the echo request packet size
     86 ICMP_SIZE_ARRAY=${ICMP_SIZE_ARRAY:-"10 100 1000 10000 65507"}
     87 
     88 
     89 
     90 #-----------------------------------------------------------------------
     91 #
     92 # Function: do_cleanup
     93 #
     94 # Description:
     95 #   Recover the system configuration
     96 #
     97 #-----------------------------------------------------------------------
     98 do_cleanup()
     99 {
    100     # Kill the icmp traffic server
    101     killall_icmp_traffic
    102 
    103     # Unset SAD/SPD
    104     output_ipsec_conf flush | setkey -c >/dev/null 2>&1
    105     $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
    106 
    107     # Clean up each interface
    108     link_num=0
    109     while [ $link_num -lt $link_total ]; do
    110 	initialize_if lhost ${link_num}
    111 	initialize_if rhost ${link_num}
    112 	link_num=`expr $link_num + 1`
    113     done
    114 }
    115 
    116 
    117 #-----------------------------------------------------------------------
    118 #
    119 # Setup
    120 #
    121 
    122 # Unset the maximum number of processes
    123 ulimit -u unlimited
    124 
    125 # Output the informaion
    126 tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
    127 
    128 link_total=`echo $LHOST_HWADDRS | wc -w`
    129 rhost_link_total=`echo $RHOST_HWADDRS | wc -w`
    130 if [ $link_total -ne $rhost_link_total ]; then
    131     tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS"
    132     exit 1
    133 fi
    134 if [ $link_total -lt 2 ]; then
    135     tst_resm TBROK "This test case requires plural NICs."
    136     exit 1
    137 fi
    138 tst_resm TINFO "- Target number of the connection is $link_total"
    139 
    140 tst_resm TINFO "- Version of IP is IPv${IP_VER}"
    141 tst_resm TINFO "- Size of packets are ( $ICMP_SIZE_ARRAY )"
    142 
    143 if $DO_IPSEC ; then
    144     message=`check_setkey`
    145     if [ $? -ne 0 ]; then
    146 	tst_resm TBROK "$message"
    147 	exit 1
    148     fi
    149 
    150     case $IPSEC_PROTO in
    151 	ah)
    152 	tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
    153 	;;
    154 	esp)
    155 	tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
    156 	;;
    157 	ipcomp)
    158 	tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
    159 	;;
    160     esac
    161 fi
    162 
    163 # Initialize the system configuration
    164 do_cleanup
    165 
    166 # Call do_cleanup function before exit
    167 trap do_cleanup 0
    168 
    169 # Loop for NIC configuration
    170 link_num=0
    171 lhost_addrs=""
    172 while [ $link_num -lt $link_total ]; do
    173     # name of interface of the local/remote host
    174     lhost_ifname=`get_ifname lhost $link_num`
    175     rhost_ifname=`get_ifname rhost $link_num`
    176 
    177     # Set the IP address to each interface
    178     case $IP_VER in
    179 	4)
    180 	network_part="10.0.${link_num}"
    181 	network_mask=24
    182 	lhost_host_part="2"     # local host
    183 	rhost_host_part="1"     # remote host
    184 	set_ipv4addr lhost $link_num $network_part $lhost_host_part
    185 	if [ $? -ne 0 ]; then
    186 	    tst_resm TBROK "Failed to set IPv4 address at the local host"
    187 	    exit 1
    188 	fi
    189 	set_ipv4addr rhost $link_num $network_part $rhost_host_part
    190 	if [ $? -ne 0 ]; then
    191 	    tst_resm TBROK "Failed to set IPv4 address at the remote host"
    192 	    exit 1
    193 	fi
    194 
    195 	# IPv4 address of the local/remote host
    196 	lhost_addr="${network_part}.${lhost_host_part}"
    197 	rhost_addr="${network_part}.${rhost_host_part}"
    198 	lhost_addrs="${lhost_addrs} ${lhost_addr}"
    199 	;;
    200 
    201 	6)
    202 	network_part="fd00:1:0:`printf %x ${link_num}`"
    203 	network_mask=64
    204 	lhost_host_part=":2"     # local host
    205 	rhost_host_part=":1"     # remote host
    206 	add_ipv6addr lhost $link_num $network_part $lhost_host_part
    207 	if [ $? -ne 0 ]; then
    208 	    tst_resm TBROK "Failed to set IPv6 address at the local host"
    209 	    exit 1
    210 	fi
    211 	add_ipv6addr rhost $link_num $network_part $rhost_host_part
    212 	if [ $? -ne 0 ]; then
    213 	    tst_resm TBROK "Failed to set IPv6 address at the remote host"
    214 	    exit 1
    215 	fi
    216 	lhost_addr="${network_part}:${lhost_host_part}"
    217 	rhost_addr="${network_part}:${rhost_host_part}"
    218 	lhost_addrs="${lhost_addrs} ${lhost_addr}"
    219 	;;
    220 
    221 	*)
    222 	tst_resm TBROK "Unknown IP version"
    223 	;;
    224     esac
    225 
    226     # Configure SAD/SPD
    227     if $DO_IPSEC ; then
    228 	ipsec_log=`mktemp -p $TMPDIR`
    229 
    230 	# Set SAD/SPD according to the variables
    231 	output_ipsec_conf src \
    232 	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
    233 		| setkey -c 2>&1 | tee $ipsec_log
    234 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    235 	    rm -f $ipsec_log
    236 	    tst_resm TBROK "Failed to configure SAD/SPD on the local host."
    237 	    exit 1
    238 	fi
    239 
    240 	$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
    241 	if [ $? -ne 0 -o -s $ipsec_log ]; then
    242 	    rm -f $ipsec_log
    243 	    tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
    244 	    exit 1
    245 	fi
    246 	rm -f $ipsec_log
    247     fi
    248 
    249     # Make sure the connectivity
    250     case $IP_VER in
    251 	4)
    252 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    253 	if [ $ret -ne 0 ]; then
    254 	    tst_resm TBROK "There is no IPv4 connectivity on Link${link_num}"
    255 	    exit 1
    256 	fi
    257 	;;
    258 
    259 	6)
    260 	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
    261 	if [ $ret -ne 0 ]; then
    262 	    tst_resm TBROK "There is no IPv6 connectivity on Link${link_num}"
    263 	    exit 1
    264 	fi
    265 	;;
    266     esac
    267 
    268     link_num=`expr $link_num + 1`
    269 done
    270 
    271 
    272 #-----------------------------------------------------------------------
    273 #
    274 # Main
    275 #
    276 #
    277 
    278 connection_num=0
    279 while [ $connection_num -lt $link_total ]; do
    280     field=`expr $connection_num + 1`
    281     lhost_addr=`echo $lhost_addrs | cut -d ' ' -f $field`
    282 
    283     lhost_ifname=`get_ifname lhost $connection_num`
    284     rhost_ifname=`get_ifname rhost $connection_num`
    285 
    286     # Run a client
    287     $LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-echoclient -S $lhost_addr -f $IP_VER -s \"$ICMP_SIZE_ARRAY\"" &
    288     connection_num=`expr $connection_num + 1`
    289 done
    290 
    291 sleep $NS_DURATION
    292 killall_icmp_traffic
    293 wait
    294 
    295 #-----------------------------------------------------------------------
    296 #
    297 # Clean up
    298 #
    299 
    300 tst_resm TPASS "Test is finished successfully."
    301 exit 0
    302