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-gw 26# 27# Description: 28# Verify the kernel is not crashed when the gateway 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@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 48LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`} 49export LTPROOT 50 51# Total number of the test case 52TST_TOTAL=2 53export TST_TOTAL 54 55# Default of the test case ID and the test case count 56TCID=route4-change-gw 57TST_COUNT=0 58export TCID 59export TST_COUNT 60 61# Check the environmanet variable 62. check_envval || exit $TST_TOTAL 63 64# The number of times where route is changed 65NS_TIMES=${NS_TIMES:-10000} 66 67# The number of the test link where tests run 68LINK_NUM=${LINK_NUM:-0} 69 70# Network portion of the IPv4 address 71IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"} 72 73# Netmask of for the tested network 74IPV4_NETMASK_NUM=24 75 76# Broadcast address of the tested network 77IPV4_BROADCAST=${IPV4_NETWORK}.255 78 79# Host portion of the IPv4 address 80LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"} # src 81RHOST_IPV4_HOST_TOP="10" # gateway 82RHOST_IPV4_HOST_LAST=19 83 84# The destination network 85DST_NETWORK="10.10.0" # destination network would be 10.10.0.0/24 86DST_HOST="5" 87DST_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#----------------------------------------------------------------------- 104do_setup() 105{ 106 TCID=route4-change-gw 107 TST_COUNT=0 108 109 # Get the Interface name of local host 110 lhost_ifname=`get_ifname lhost ${LINK_NUM}` 111 if [ $? -ne 0 ]; then 112 tst_resm TBROK "Failed to get the interface name at the local host" 113 exit $TST_TOTAL 114 fi 115 116 # Get the Interface name of remote host 117 rhost_ifname=`get_ifname rhost ${LINK_NUM}` 118 if [ $? -ne 0 ]; then 119 tst_resm TBROK "Failed to get the interface name at the remote host" 120 exit $TST_TOTAL 121 fi 122 123 # Initialize the interfaces of the remote host 124 initialize_if rhost ${LINK_NUM} 125 126 # Set IPv4 address to the interface of the remote host 127 rhost_part=$RHOST_IPV4_HOST_TOP 128 while [ $rhost_part -le $RHOST_IPV4_HOST_LAST ]; do 129 ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ip addr add '${IPV4_NETWORK}.${rhost_part}/${IPV4_NETMASK_NUM}' broadcast '${IPV4_NETWORK}'.255 dev '$rhost_ifname' ) > /dev/null ; echo $?'` 130 if [ $ret -ne 0 ]; then 131 tst_resm TBROK "Failed to assign IP address to the interface at the remote host" 132 exit $TST_TOTAL 133 fi 134 rhost_part=`expr $rhost_part + 1` 135 done 136} 137 138 139#----------------------------------------------------------------------- 140# 141# NAME: 142# do_cleanup 143# 144# DESCRIPTION: 145# Recover the tested interfaces 146# 147#----------------------------------------------------------------------- 148do_cleanup() 149{ 150 killall -SIGHUP ns-udpsender >/dev/null 2>&1 151 152 # Initialize the interfaces 153 initialize_if lhost ${LINK_NUM} 154 initialize_if rhost ${LINK_NUM} 155} 156 157 158#----------------------------------------------------------------------- 159# 160# FUNCTION: 161# test_body 162# 163# DESCRIPTION: 164# main code of the test 165# 166# Arguments: 167# $1: define the test type 168# 1 - route command case 169# 2 - ip command case 170# 171#----------------------------------------------------------------------- 172test_body() 173{ 174 test_type=$1 175 176 TCID=route4-change-gw0${test_type} 177 TST_COUNT=$test_type 178 179 case $test_type in 180 1) 181 test_command="route" 182 ;; 183 2) 184 test_command="ip" 185 ;; 186 *) 187 tst_resm TBROK "unspecified case" 188 return 1 189 ;; 190 esac 191 192 tst_resm TINFO "Verify the kernel is not crashed when the gateway of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times" 193 194 # Initialize the interface of the local host 195 initialize_if lhost ${LINK_NUM} 196 197 # Assign IPv4 address to the interface of the local host 198 set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} 199 if [ $? -ne 0 ]; then 200 tst_resm TBROK "Failed to assign an IPv4 address at the local host" 201 return 1 202 fi 203 204 # Check the connectivity to the gateway 205 rhost_part=$RHOST_IPV4_HOST_TOP 206 check_icmpv4_connectivity $lhost_ifname ${IPV4_NETWORK}.${rhost_part} 207 if [ $? -ne 0 ]; then 208 tst_resm TBROK "Test Link $LINK_NUM is somthing wrong." 209 return 1 210 fi 211 212 # Set the variables regarding the destination host 213 dst_addr=${DST_NETWORK}.${DST_HOST} 214 dst_network=${DST_NETWORK}.0 215 216 # Set the first route 217 case $test_type in 218 1) 219 route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname 220 ;; 221 2) 222 ip route add ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname 223 ;; 224 esac 225 226 # Load the route with UDP traffic 227 ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472 228 if [ $? -ne 0 ]; then 229 tst_resm TFAIL "Failed to run a UDP datagram sender" 230 return 1 231 fi 232 233 # Loop for changing the route 234 cnt=0 235 while [ $cnt -lt $NS_TIMES ]; do 236 pre_rhost_part=$rhost_part 237 rhost_part=`expr $rhost_part + 1` 238 if [ $rhost_part -gt $RHOST_IPV4_HOST_LAST ]; then 239 rhost_part=$RHOST_IPV4_HOST_TOP 240 fi 241 242 case $test_type in 243 1) 244 route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname 245 route del -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${pre_rhost_part} dev $lhost_ifname 246 ;; 247 2) 248 ip route change ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname 249 ;; 250 esac 251 if [ $? -ne 0 ]; then 252 tst_resm TFAIL "Failed to change the gateway to ${IPV4_NETWORK}.${rhost_part}" 253 return 1 254 fi 255 256 # Rerun if udp datagram sender is dead 257 ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null 258 if [ $? -ne 0 ]; then 259 ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472 260 if [ $? -ne 0 ]; then 261 tst_resm TFAIL "Failed to run a UDP datagram sender" 262 return 1 263 fi 264 fi 265 266 cnt=`expr $cnt + 1` 267 done 268 269 # Kill the udp datagram sender 270 killall -SIGHUP ns-udpsender >/dev/null 2>&1 271 272 tst_resm TPASS "Test is finished correctly." 273 return 0 274} 275 276 277#----------------------------------------------------------------------- 278# 279# Main 280# 281# Exit Value: 282# The number of the failure 283# 284#----------------------------------------------------------------------- 285 286RC=0 287do_setup 288test_body 1 || RC=`expr $RC + 1` # Case of route command 289test_body 2 || RC=`expr $RC + 1` # Case of ip command 290do_cleanup 291 292exit $RC 293