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