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 # route6-change-if 26 # 27 # Description: 28 # Verify the kernel is not crashed when the interface of an IPv6 route is 29 # changed frequently 30 # test01 - by route command 31 # test02 - by ip command 32 # 33 # Setup: 34 # See testcases/network/stress/README 35 # 36 # Author: 37 # Mitsuru Chinen <mitch (at] jp.ibm.com> 38 # 39 # History: 40 # Mar 17 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=route6-change-if 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 first 2 ocnted of the Network portion of the gateway address 68 IPV6_NETWORK_PRE="fec0:1:1" 69 70 # Netmask of for the gateway 71 IPV6_NETMASK_NUM=64 72 73 # Host portion of the IPv6 address 74 LHOST_IPV6_HOST=":2" # src 75 RHOST_IPV6_HOST=":1" # gateway 76 77 # The destination network 78 DST_NETWORK="fd00:100:1:1" # dest network would be fd00:100:1:1:::/64 79 DST_HOST=":5" 80 DST_PORT="7" 81 82 83 #----------------------------------------------------------------------- 84 # 85 # NAME: 86 # do_setup 87 # 88 # DESCRIPTION: 89 # Make a IPv6 connectivity 90 # 91 # SET VALUES: 92 # rhost_ipv6addr - IPv6 Address of the remote host 93 # lhost_ifname - Interface name of the local host 94 # rhost_ifname - Interface name of the remote host 95 # 96 #----------------------------------------------------------------------- 97 do_setup() 98 { 99 TCID=route6-change-if 100 TST_COUNT=0 101 102 # Get the number of the test links 103 link_total=`echo $LHOST_HWADDRS | wc -w` 104 rhost_link_total=`echo $RHOST_HWADDRS | wc -w` 105 if [ $link_total -ne $rhost_link_total ]; then 106 tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" 107 exit $TST_TOTAL 108 fi 109 if [ $link_total -lt 2 ]; then 110 tst_resm TBROK "This test case requires plural Test Links" 111 exit $TST_TOTAL 112 fi 113 114 lhost_ifname_array="" 115 rhost_ifname_array="" 116 link_num=0 117 while [ $link_num -lt $link_total ]; do 118 # Get the Interface names of the local host 119 lhost_ifname=`get_ifname lhost ${link_num}` 120 if [ $? -ne 0 ]; then 121 tst_resm TBROK "Failed to get the interface name at the local host" 122 exit $TST_TOTAL 123 fi 124 lhost_ifname_array="$lhost_ifname_array $lhost_ifname" 125 126 # Get the Interface names of the remote host 127 rhost_ifname=`get_ifname rhost ${link_num}` 128 if [ $? -ne 0 ]; then 129 tst_resm TBROK "Failed to get the interface name at the remote host" 130 exit $TST_TOTAL 131 fi 132 rhost_ifname_array="$rhost_ifname_array $rhost_ifname" 133 134 # Initialize the interfaces of the remote host 135 initialize_if rhost ${link_num} 136 137 # Set IPv6 address to the interface of the remote host 138 add_ipv6addr rhost ${link_num} "${IPV6_NETWORK_PRE}:${link_num}" ${RHOST_IPV6_HOST} 139 if [ $? -ne 0 ]; then 140 tst_resm TBROK "Failed to assign IP address to the interface $rhost_ifname at the remote host" 141 exit $TST_TOTAL 142 fi 143 144 link_num=`expr $link_num + 1` 145 done 146 } 147 148 149 #----------------------------------------------------------------------- 150 # 151 # NAME: 152 # do_cleanup 153 # 154 # DESCRIPTION: 155 # Recover the tested interfaces 156 # 157 #----------------------------------------------------------------------- 158 do_cleanup() 159 { 160 # Make sure to kill the udp datagram sender 161 killall -SIGHUP ns-udpsender >/dev/null 2>&1 162 163 # Initialize the interfaces 164 link_num=0 165 while [ $link_num -lt $link_total ]; do 166 initialize_if lhost ${link_num} 167 initialize_if rhost ${link_num} 168 link_num=`expr $link_num + 1` 169 done 170 } 171 172 173 #----------------------------------------------------------------------- 174 # 175 # FUNCTION: 176 # test_body 177 # 178 # DESCRIPTION: 179 # main code of the test 180 # 181 # Arguments: 182 # $1: define the test type 183 # 1 - route command case 184 # 2 - ip command case 185 # 186 #----------------------------------------------------------------------- 187 test_body() 188 { 189 test_type=$1 190 191 TCID=route6-change-if0${test_type} 192 TST_COUNT=$test_type 193 194 case $test_type in 195 1) 196 test_command="route" 197 ;; 198 2) 199 test_command="ip" 200 ;; 201 *) 202 tst_resm TBROK "unspecified case" 203 return 1 204 ;; 205 esac 206 207 tst_resm TINFO "Verify the kernel is not crashed when the interface of an IPv6 route is changed frequently by $test_command command in $NS_TIMES times" 208 209 link_num=0 210 while [ $link_num -lt $link_total ]; do 211 # Initialize the interface of the local host 212 initialize_if lhost ${link_num} 213 214 # Assign IPv6 address to the interface of the local host 215 add_ipv6addr lhost ${link_num} "${IPV6_NETWORK_PRE}:${link_num}" ${LHOST_IPV6_HOST} 216 if [ $? -ne 0 ]; then 217 tst_resm TBROK "Failed to assign an IPv6 address at the local host" 218 return 1 219 fi 220 221 # Check the connectivity to the gateway 222 field=`expr $link_num + 1` 223 lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field` 224 check_icmpv6_connectivity $lhost_ifname "${IPV6_NETWORK_PRE}:${link_num}:${LHOST_IPV6_HOST}" 225 if [ $? -ne 0 ]; then 226 tst_resm TBROK "Test Link $link_num is somthing wrong." 227 return 1 228 fi 229 link_num=`expr $link_num + 1` 230 done 231 232 # Set the variables regarding the destination host 233 dst_addr=${DST_NETWORK}:${DST_HOST} 234 dst_network=${DST_NETWORK}:: 235 236 # Set the first route 237 link_num=0 238 field=`expr $link_num + 1` 239 lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field` 240 gateway="${IPV6_NETWORK_PRE}:${link_num}:${RHOST_IPV6_HOST}" 241 case $test_type in 242 1) 243 route -A inet6 add ${dst_network}/64 gw $gateway dev $lhost_ifname 244 ;; 245 2) 246 ip -f inet6 route add ${dst_network}/64 via $gateway dev $lhost_ifname 247 ;; 248 esac 249 250 # Load the route with UDP traffic 251 ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -b -s 1452 252 if [ $? -ne 0 ]; then 253 tst_resm TFAIL "Failed to run a UDP datagram sender" 254 return 1 255 fi 256 257 # Loop for changing the route 258 cnt=0 259 while [ $cnt -lt $NS_TIMES ]; do 260 link_num=`expr $link_num + 1` 261 if [ $link_num -ge $link_total ]; then 262 link_num=0 263 fi 264 265 pre_lhost_ifname=$lhost_ifname 266 pre_gateway=$gateway 267 268 field=`expr $link_num + 1` 269 lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field` 270 gateway="${IPV6_NETWORK_PRE}:${link_num}:${RHOST_IPV6_HOST}" 271 272 case $test_type in 273 1) 274 route -A inet6 add ${dst_network}/64 gw $gateway dev $lhost_ifname 275 route -A inet6 del ${dst_network}/64 gw $pre_gateway dev $pre_lhost_ifname 276 ;; 277 2) 278 ip -f inet6 route add ${dst_network}/64 via $gateway dev $lhost_ifname 279 ip -f inet6 route del ${dst_network}/64 via $pre_gateway dev $pre_lhost_ifname 280 ;; 281 esac 282 if [ $? -ne 0 ]; then 283 tst_resm TFAIL "Failed to change the gateway to $gateway" 284 return 1 285 fi 286 287 # Rerun if udp datagram sender is dead 288 ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null 289 if [ $? -ne 0 ]; then 290 ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -b -s 1452 291 if [ $? -ne 0 ]; then 292 tst_resm TFAIL "Failed to run a UDP datagram sender" 293 return 1 294 fi 295 fi 296 297 cnt=`expr $cnt + 1` 298 done 299 300 # Kill the udp datagram sender 301 killall -SIGHUP ns-udpsender 302 303 tst_resm TPASS "Test is finished correctly." 304 return 0 305 } 306 307 308 #----------------------------------------------------------------------- 309 # 310 # Main 311 # 312 # Exit Value: 313 # The number of the failure 314 # 315 #----------------------------------------------------------------------- 316 317 RC=0 318 do_setup 319 test_body 1 || RC=`expr $RC + 1` # Case of route command 320 test_body 2 || RC=`expr $RC + 1` # Case of ip command 321 do_cleanup 322 323 exit $RC 324