1#!/bin/sh 2################################################################################ 3## ## 4## Copyright (c) International Business Machines Corp., 2006 ## 5## ## 6## This program is free software; you can redistribute it and#or modify ## 7## it under the terms of the GNU General Public License as published by ## 8## the Free Software Foundation; either version 2 of the License, or ## 9## (at your option) any later version. ## 10## ## 11## This program is distributed in the hope that it will be useful, but ## 12## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 13## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 14## for more details. ## 15## ## 16## You should have received a copy of the GNU General Public License ## 17## along with this program; if not, write to the Free Software ## 18## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 19## ## 20## ## 21################################################################################ 22# 23# File: 24# route6-change-gw 25# 26# Description: 27# Verify the kernel is not crashed when the gateway of an IPv6 route is 28# changed frequently 29# test01 - by route command 30# test02 - by ip command 31# 32# Setup: 33# See testcases/network/stress/README 34# 35# Author: 36# Mitsuru Chinen <mitch@jp.ibm.com> 37# 38# History: 39# Mar 16 2006 - Created (Mitsuru Chinen) 40# 41#----------------------------------------------------------------------- 42# Uncomment line below for debug output. 43#trace_logic=${trace_logic:-"set -x"} 44$trace_logic 45 46# Make sure the value of LTPROOT 47LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`} 48export LTPROOT 49 50# Total number of the test case 51TST_TOTAL=2 52export TST_TOTAL 53 54# Default of the test case ID and the test case count 55TCID=route6-change-gw 56TST_COUNT=0 57export TCID 58export TST_COUNT 59 60# Check the environmanet variable 61. check_envval || exit $TST_TOTAL 62 63# The number of times where route is changed 64NS_TIMES=${NS_TIMES:-10000} 65 66# The number of the test link where tests run 67LINK_NUM=${LINK_NUM:-0} 68 69# Network portion of the IPv6 address 70IPV6_NETWORK="fec0:1:1:1" 71 72# Netmask of for the tested network 73IPV6_NETMASK_NUM=64 74 75# Host portion of the IPv6 address 76LHOST_IPV6_HOST=":2" # src 77RHOST_IPV6_HOST_TOP="10" # gateway 78RHOST_IPV6_HOST_LAST="19" 79 80# The destination network 81DST_NETWORK="fd00:100:1:1" # dest network would be fd00:100:1:1:::/64 82DST_HOST="5" 83DST_PORT="7" 84 85 86#----------------------------------------------------------------------- 87# 88# NAME: 89# do_setup 90# 91# DESCRIPTION: 92# Make a IPv6 connectivity 93# 94# SET VALUES: 95# rhost_ipv6addr - IPv6 Address of the remote host 96# lhost_ifname - Interface name of the local host 97# rhost_ifname - Interface name of the remote host 98# 99#----------------------------------------------------------------------- 100do_setup() 101{ 102 TCID=route6-change-gw 103 TST_COUNT=0 104 105 # Get the Interface name of local host 106 lhost_ifname=`get_ifname lhost ${LINK_NUM}` 107 if [ $? -ne 0 ]; then 108 tst_resm TBROK "Failed to get the interface name at the local host" 109 exit $TST_TOTAL 110 fi 111 112 # Get the Interface name of remote host 113 rhost_ifname=`get_ifname rhost ${LINK_NUM}` 114 if [ $? -ne 0 ]; then 115 tst_resm TBROK "Failed to get the interface name at the remote host" 116 exit $TST_TOTAL 117 fi 118 119 # Initialize the interfaces of the remote host 120 initialize_if rhost ${LINK_NUM} 121 122 # Set IPv6 address to the interface of the remote host 123 rhost_part=$RHOST_IPV6_HOST_TOP 124 rhost_part_hex=`printf "%x" $rhost_part` 125 while [ $rhost_part -le $RHOST_IPV6_HOST_LAST ]; do 126 rhost_part_hex=":`printf "%x" $rhost_part`" 127 add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${rhost_part_hex} 128 if [ $? -ne 0 ]; then 129 tst_resm TBROK "Failed to assign IP address to the interface at the remote host" 130 exit $TST_TOTAL 131 fi 132 rhost_part=`expr $rhost_part + 1` 133 done 134} 135 136 137#----------------------------------------------------------------------- 138# 139# NAME: 140# do_cleanup 141# 142# DESCRIPTION: 143# Recover the tested interfaces 144# 145#----------------------------------------------------------------------- 146do_cleanup() 147{ 148 killall -SIGHUP ns-udpsender >/dev/null 2>&1 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#----------------------------------------------------------------------- 170test_body() 171{ 172 test_type=$1 173 174 TCID=route6-change-gw0${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 gateway of an IPv6 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 IPv6 address to the interface of the local host 196 add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST} 197 if [ $? -ne 0 ]; then 198 tst_resm TBROK "Failed to assign an IPv6 address at the local host" 199 return 1 200 fi 201 202 # Check the connectivity to the gateway 203 rhost_part=$RHOST_IPV6_HOST_TOP 204 rhost_part_hex=":`printf "%x" $rhost_part`" 205 check_icmpv6_connectivity $lhost_ifname ${IPV6_NETWORK}:${rhost_part_hex} 206 if [ $? -ne 0 ]; then 207 tst_resm TBROK "Test Link $LINK_NUM is somthing wrong." 208 return 1 209 fi 210 211 # Set the variables regarding the destination host 212 dst_addr=${DST_NETWORK}::${DST_HOST} 213 dst_network=${DST_NETWORK}:: 214 215 # Set the first route 216 case $test_type in 217 1) 218 route -A inet6 add ${dst_network}/64 gw ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname 219 ;; 220 2) 221 ip -f inet6 route add ${dst_network}/64 via ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname 222 ;; 223 esac 224 225 # Load the route with UDP traffic 226 ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -b -s 1452 227 if [ $? -ne 0 ]; then 228 tst_resm TFAIL "Failed to run a UDP datagram sender" 229 return 1 230 fi 231 232 # Loop for changing the route 233 cnt=0 234 while [ $cnt -lt $NS_TIMES ]; do 235 pre_rhost_part_hex=$rhost_part_hex 236 rhost_part=`expr $rhost_part + 1` 237 if [ $rhost_part -gt $RHOST_IPV6_HOST_LAST ]; then 238 rhost_part=$RHOST_IPV6_HOST_TOP 239 fi 240 rhost_part_hex=":`printf "%x" $rhost_part`" 241 242 case $test_type in 243 1) 244 route -A inet6 add ${dst_network}/64 gw ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname 245 route -A inet6 del ${dst_network}/64 gw ${IPV6_NETWORK}:${pre_rhost_part_hex} dev $lhost_ifname 246 ;; 247 2) 248 ip -f inet6 route change ${dst_network}/64 via ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname 249 ;; 250 esac 251 if [ $? -ne 0 ]; then 252 tst_resm TFAIL "Failed to change the gateway to ${IPV6_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 -o -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