Home | History | Annotate | Download | only in route
      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 #   route4-ifdown
     26 #
     27 # Description:
     28 #   Verify the kernel is not crashed when IPv4 route is add then it is deleted
     29 #   by the interface down
     30 #
     31 # Setup:
     32 #   See ltp-yyyymmdd/testcases/network/stress/README
     33 #
     34 # Author:
     35 #   Mitsuru Chinen <mitch (at] jp.ibm.com>
     36 #
     37 # History:
     38 #	Apr 8 2006 - Created (Mitsuru Chinen)
     39 #
     40 #-----------------------------------------------------------------------
     41 # Uncomment line below for debug output.
     42 #trace_logic=${trace_logic:-"set -x"}
     43 $trace_logic
     44 
     45 # Make sure the value of LTPROOT
     46 LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
     47 export LTPROOT
     48 
     49 # Total number of the test case
     50 TST_TOTAL=2
     51 export TST_TOTAL
     52 
     53 # Default of the test case ID and the test case count
     54 TCID=route4-ifdown
     55 TST_COUNT=0
     56 export TCID
     57 export TST_COUNT
     58 
     59 # Check the environmanet variable
     60 . check_envval || exit $TST_TOTAL
     61 
     62 # The number of times where IPv4 route is add/delete
     63 NS_TIMES=${NS_TIMES:-10000}
     64 
     65 # The number of the test link where tests run
     66 LINK_NUM=${LINK_NUM:-0}
     67 
     68 # Network portion of the IPv4 address
     69 IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
     70 
     71 # Netmask of for the tested network
     72 IPV4_NETMASK="255.255.255.0"
     73 IPV4_NETMASK_NUM=24
     74 
     75 # Broadcast address of the tested network
     76 IPV4_BROADCAST=${IPV4_NETWORK}.255
     77 
     78 # Host portion of the IPv4 address
     79 LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
     80 RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
     81 
     82 # The destination network
     83 DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
     84 DST_HOST="5"
     85 DST_PORT="7"
     86 
     87 
     88 #-----------------------------------------------------------------------
     89 #
     90 # NAME:
     91 #   do_cleanup
     92 #
     93 # DESCRIPTION:
     94 #   Recover the tested interfaces
     95 #
     96 #-----------------------------------------------------------------------
     97 do_cleanup()
     98 {
     99     # Initialize the interfaces
    100     initialize_if lhost ${LINK_NUM}
    101     initialize_if rhost ${LINK_NUM}
    102 }
    103 
    104 
    105 #-----------------------------------------------------------------------
    106 #
    107 # NAME:
    108 #   do_setup
    109 #
    110 # DESCRIPTION:
    111 #   Make a IPv4 connectivity
    112 #
    113 # SET VALUES:
    114 #   rhost_ipv4addr	- IPv4 Address of the remote host
    115 #   lhost_ifname	- Interface name of the local host
    116 #   rhost_ifname	- Interface name of the remote host
    117 #
    118 #-----------------------------------------------------------------------
    119 do_setup()
    120 {
    121     # Make sure to clean up
    122     do_cleanup
    123 
    124     # Set IPv4 address to the interfaces of the remote host
    125     set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
    126     if [ $? -ne 0 ]; then
    127 	tst_resm TBROK "Failed to add an IPv4 address the remote host"
    128 	exit $TST_TOTAL
    129     fi
    130     rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
    131 
    132     # Assign IPv4 address to the interface of the local host
    133     set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
    134     if [ $? -ne 0 ]; then
    135 	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
    136 	return 1
    137     fi
    138     lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
    139 
    140     # Get the Interface names
    141     lhost_ifname=`get_ifname lhost ${LINK_NUM}`
    142     if [ $? -ne 0 ]; then
    143 	tst_resm TBROK "Failed to get the interface name at the local host"
    144 	exit $TST_TOTAL
    145     fi
    146 
    147     rhost_ifname=`get_ifname rhost ${LINK_NUM}`
    148     if [ $? -ne 0 ]; then
    149 	tst_resm TBROK "Failed to get the interface name at the remote host"
    150 	exit $TST_TOTAL
    151     fi
    152 
    153     # Set the variables for destination network
    154     dst_addr=${DST_NETWORK}.${DST_HOST}
    155     dst_network=${DST_NETWORK}.0
    156 }
    157 
    158 
    159 #-----------------------------------------------------------------------
    160 #
    161 # FUNCTION:
    162 #   test_body
    163 #
    164 # DESCRIPTION:
    165 #   main code of the test
    166 #
    167 # Arguments:
    168 #   $1: define the test type
    169 #	1 - route command case
    170 #	2 - ip command case
    171 #
    172 #-----------------------------------------------------------------------
    173 test_body()
    174 {
    175     test_type=$1
    176 
    177     TCID=route4-ifdown0${test_type}
    178     TST_COUNT=$test_type
    179 
    180     case $test_type in
    181 	1)
    182 	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by the interface down with ifconfing command in $NS_TIMES times"
    183 	;;
    184 	2)
    185 	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by the interface down with ip command in $NS_TIMES times"
    186 	;;
    187 	*)
    188 	tst_resm TBROK "unspecified case"
    189 	return 1
    190 	;;
    191     esac
    192 
    193     # Start the loop
    194     cnt=0
    195     while [ $cnt -lt $NS_TIMES ]; do
    196 	# Check the connectivity to the gateway
    197 	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
    198 	if [ $? -ne 0 ]; then
    199 	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
    200 	    return 1
    201 	fi
    202 
    203 	# Add the route
    204 	case $test_type in
    205 	    1)
    206 	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
    207 	    ;;
    208 	    2)
    209 	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
    210 	    ;;
    211 	esac
    212 	if [ $? -ne 0 ]; then
    213 	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
    214 	    return 1
    215 	fi
    216 
    217 	# Load the route with UDP datagram
    218 	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
    219 	if [ $? -ne 0 ]; then
    220 	    tst_resm TFAIL "Failed to run a UDP datagram sender"
    221 	    return 1
    222 	fi
    223 
    224 	# Down then up the interface
    225 	case $test_type in
    226 	    1)
    227 	    ifconfig $lhost_ifname down && ifconfig $lhost_ifname up
    228 	    ;;
    229 	    2)
    230 	    ip link set down dev $lhost_ifname && ip link set up dev $lhost_ifname
    231 	    ;;
    232 	esac
    233 	if [ $? -ne 0 ]; then
    234 	    tst_resm TFAIL "Failed to down/up the interface"
    235 	    return 1
    236 	fi
    237 
    238 	cnt=`expr $cnt + 1`
    239     done
    240 
    241     tst_resm TPASS "Test is finished correctly."
    242     return 0
    243 }
    244 
    245 
    246 #-----------------------------------------------------------------------
    247 #
    248 # Main
    249 #
    250 # Exit Value:
    251 #   The number of the failure
    252 #
    253 #-----------------------------------------------------------------------
    254 
    255 RC=0
    256 do_setup
    257 test_body 1 || RC=`expr $RC + 1`      # Case of route command
    258 test_body 2 || RC=`expr $RC + 1`      # Case of ip command
    259 do_cleanup
    260 
    261 exit $RC
    262