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-dst 26# 27# Description: 28# Verify the kernel is not crashed when the destination 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@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=route6-change-dst 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 IPv6 address 71IPV6_NETWORK="fec0:1:1:1" 72 73# Netmask of for the tested network 74IPV6_NETMASK_NUM=64 75 76# Host portion of the IPv6 address 77LHOST_IPV6_HOST=":2" # src 78RHOST_IPV6_HOST=":3" # gateway 79 80# The destination network 81DST_NETWORK_PREFIX="fd00:100:1" # dest network would be fd00:100:1:n:::/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-dst 103 TST_COUNT=0 104 105 # Initialize the interfaces of the remote host 106 initialize_if rhost ${LINK_NUM} 107 108 # Set IPv6 address to the interfaces 109 add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${RHOST_IPV6_HOST} 110 if [ $? -ne 0 ]; then 111 tst_resm TBROK "Failed to add an IPv6 address the remote host" 112 exit $TST_TOTAL 113 fi 114 115 # IPv6 address of the remote host (gateway) 116 rhost_ipv6addr="${IPV6_NETWORK}:${RHOST_IPV6_HOST}" 117 118 # Get the Interface name of 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 125 # Get the Interface name of remote host 126 rhost_ifname=`get_ifname rhost ${LINK_NUM}` 127 if [ $? -ne 0 ]; then 128 tst_resm TBROK "Failed to get the interface name at the remote host" 129 exit $TST_TOTAL 130 fi 131} 132 133 134#----------------------------------------------------------------------- 135# 136# NAME: 137# do_cleanup 138# 139# DESCRIPTION: 140# Recover the tested interfaces 141# 142#----------------------------------------------------------------------- 143do_cleanup() 144{ 145 # Initialize the interfaces 146 initialize_if lhost ${LINK_NUM} 147 initialize_if rhost ${LINK_NUM} 148} 149 150 151#----------------------------------------------------------------------- 152# 153# FUNCTION: 154# test_body 155# 156# DESCRIPTION: 157# main code of the test 158# 159# Arguments: 160# $1: define the test type 161# 1 - route command case 162# 2 - ip command case 163# 164#----------------------------------------------------------------------- 165test_body() 166{ 167 test_type=$1 168 169 TCID=route6-change-dst0${test_type} 170 TST_COUNT=$test_type 171 172 case $test_type in 173 1) 174 test_command="route" 175 ;; 176 2) 177 test_command="ip" 178 ;; 179 *) 180 tst_resm TBROK "unspecified case" 181 return 1 182 ;; 183 esac 184 185 tst_resm TINFO "Verify the kernel is not crashed when the destination of an IPv6 route is changed frequently by $test_command command in $NS_TIMES times" 186 187 # Initialize the interface of the local host 188 initialize_if lhost ${LINK_NUM} 189 190 # Assign IPv6 address to the interface of the local host 191 add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST} 192 if [ $? -ne 0 ]; then 193 tst_resm TBROK "Failed to assign an IPv6 address at the local host" 194 return 1 195 fi 196 lhost_ipv6addr="${IPV6_NETWORK}:${LHOST_IPV6_HOST}" 197 198 # Check the connectivity to the gateway 199 check_icmpv6_connectivity $lhost_ifname $rhost_ipv6addr 200 if [ $? -ne 0 ]; then 201 tst_resm TBROK "Test Link $LINK_NUM is something wrong." 202 return 1 203 fi 204 205 # Start the loop 206 cnt=0 207 while [ $cnt -lt $NS_TIMES ]; do 208 # Define the destination IP address 209 tmp_postfix=`expr $cnt % 65535` 210 dst_network_postfix=`printf "%x" $tmp_postfix` 211 dst_addr=${DST_NETWORK_PREFIX}:${dst_network_postfix}::${DST_HOST} 212 dst_network=${DST_NETWORK_PREFIX}:${dst_network_postfix}:: 213 214 # Add the route 215 case $test_type in 216 1) 217 route -A inet6 add ${dst_network}/64 gw $rhost_ipv6addr dev $lhost_ifname 218 ;; 219 2) 220 ip -f inet6 route add ${dst_network}/64 via $rhost_ipv6addr dev $lhost_ifname 221 ;; 222 esac 223 if [ $? -ne 0 ]; then 224 tst_resm TFAIL "Failed to add the route to ${dst_network}/64" 225 return 1 226 fi 227 228 # Load the route with UDP datagram 229 ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -o -s 1452 230 if [ $? -ne 0 ]; then 231 tst_resm TFAIL "Failed to run a UDP datagram sender" 232 return 1 233 fi 234 235 # Delete the route 236 case $test_type in 237 1) 238 route -A inet6 del ${dst_network}/64 gw $rhost_ipv6addr dev $lhost_ifname 239 ;; 240 2) 241 ip -f inet6 route del ${dst_network}/64 via $rhost_ipv6addr dev $lhost_ifname 242 ;; 243 esac 244 if [ $? -ne 0 ]; then 245 tst_resm TFAIL "Cannot delete the route to ${ADDDEL_ROUTE}" 246 return 1 247 fi 248 249 cnt=`expr $cnt + 1` 250 done 251 252 tst_resm TPASS "Test is finished correctly." 253 return 0 254} 255 256 257#----------------------------------------------------------------------- 258# 259# Main 260# 261# Exit Value: 262# The number of the failure 263# 264#----------------------------------------------------------------------- 265 266RC=0 267do_setup 268test_body 1 || RC=`expr $RC + 1` # Case of route command 269test_body 2 || RC=`expr $RC + 1` # Case of ip command 270do_cleanup 271 272exit $RC 273