1#!/bin/sh 2 3################################################################################ 4## ## 5## Copyright (c) International Business Machines Corp., 2005 ## 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# udp4-multi-diffnic01 26# 27# Description: 28# Verify that the kernel is not crashed with receiving and sending UDP 29# datagram at different NIC with the following conditions 30# - The version of IP is IPv4 31# - IPsec is not used 32# 33# *) This script may be read by the other test case 34# 35# Setup: 36# See testcases/network/stress/README 37# 38# Author: 39# Mitsuru Chinen <mitch@jp.ibm.com> 40# 41# History: 42# Oct 19 2005 - Created (Mitsuru Chinen) 43# 44#----------------------------------------------------------------------- 45# Uncomment line below for debug output. 46#trace_logic=${trace_logic:-"set -x"} 47$trace_logic 48 49# The test case ID, the test case count and the total number of test case 50TCID=${TCID:-udp4-multi-diffnic01} 51TST_TOTAL=1 52TST_COUNT=1 53export TCID 54export TST_COUNT 55export TST_TOTAL 56 57# Test description 58tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending UDP datagram at the different NICs with the following conditions" 59 60# Make sure the value of LTPROOT 61LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`} 62export LTPROOT 63 64# Check the environmanet variable 65. check_envval || exit $TST_TOTAL 66 67# Dulation of the test [sec] 68NS_DURATION=${NS_DURATION:-3600} # 1 hour 69 70#The number of the test link where tests run 71LINK_NUM=${LINK_NUM:-0} 72 73# The version of IP 74IP_VER=${IP_VER:-4} 75 76# true, if ipsec is used 77DO_IPSEC=${DO_IPSEC:-false} 78 79# The value of SPI 80SPI=${SPI:-1000} 81 82# IPsec Protocol ( ah / esp / ipcomp ) 83IPSEC_PROTO=${IPSEC_PROTO:-ah} 84 85# IPsec Mode ( transport / tunnel ) 86IPSEC_MODE=${IPSEC_MODE:-transport} 87 88 89#----------------------------------------------------------------------- 90# 91# Function: do_cleanup 92# 93# Description: 94# Recover the system configuration 95# 96#----------------------------------------------------------------------- 97do_cleanup() 98{ 99 # Kill the udp traffic server 100 killall_udp_traffic 101 102 # Unset SAD/SPD 103 output_ipsec_conf flush | setkey -c >/dev/null 2>&1 104 $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1 105 106 # Clean up each interface 107 link_num=0 108 while [ $link_num -lt $link_total ]; do 109 # Initialize the interfaces 110 initialize_if lhost ${link_num} 111 initialize_if rhost ${link_num} 112 link_num=`expr $link_num + 1` 113 done 114} 115 116 117#----------------------------------------------------------------------- 118# 119# Setup 120# 121 122# Unset the maximum number of processes 123ulimit -u unlimited 124 125# Output the informaion 126tst_resm TINFO "- Test duration is $NS_DURATION [sec]" 127 128link_total=`echo $LHOST_HWADDRS | wc -w` 129rhost_link_total=`echo $RHOST_HWADDRS | wc -w` 130if [ $link_total -ne $rhost_link_total ]; then 131 tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" 132 exit 1 133fi 134if [ $link_total -lt 2 ]; then 135 tst_resm TBROK "This test case requires plural NICs." 136 exit 1 137fi 138tst_resm TINFO "- Target number of the connection is $link_total" 139 140tst_resm TINFO "- Version of IP is IPv${IP_VER}" 141 142if $DO_IPSEC ; then 143 message=`check_setkey` 144 if [ $? -ne 0 ]; then 145 tst_resm TBROK "$message" 146 exit 1 147 fi 148 149 case $IPSEC_PROTO in 150 ah) 151 tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]" 152 ;; 153 esp) 154 tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]" 155 ;; 156 ipcomp) 157 tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]" 158 ;; 159 esac 160fi 161 162# Initialize the system configuration 163do_cleanup 164 165# Call do_cleanup function before exit 166trap do_cleanup 0 167 168# Loop for NIC configuration 169link_num=0 170lhost_addrs="" 171while [ $link_num -lt $link_total ]; do 172 # name of interface of the local/remote host 173 lhost_ifname=`get_ifname lhost $link_num` 174 if [ $? -ne 0 ]; then 175 tst_resm TBROK "Failed to get the interface name at the local host" 176 exit $TST_TOTAL 177 fi 178 rhost_ifname=`get_ifname rhost $link_num` 179 if [ $? -ne 0 ]; then 180 tst_resm TBROK "Failed to get the interface name at the remtoe host" 181 exit $TST_TOTAL 182 fi 183 184 # Set the IP address to each interface 185 case $IP_VER in 186 4) 187 network_part="10.0.${link_num}" 188 network_mask=24 189 lhost_host_part="2" # local host 190 rhost_host_part="1" # remote host 191 set_ipv4addr lhost $link_num $network_part $lhost_host_part 192 if [ $? -ne 0 ]; then 193 tst_resm TBROK "Failed to set IPv4 address at the local host" 194 exit 1 195 fi 196 set_ipv4addr rhost $link_num $network_part $rhost_host_part 197 if [ $? -ne 0 ]; then 198 tst_resm TBROK "Failed to set IPv4 address at the remote host" 199 exit 1 200 fi 201 202 # IPv4 address of the local/remote host 203 lhost_addr="${network_part}.${lhost_host_part}" 204 rhost_addr="${network_part}.${rhost_host_part}" 205 lhost_addrs="${lhost_addrs} ${lhost_addr}" 206 ;; 207 208 6) 209 network_part="fd00:1:0:`printf %x ${link_num}`" 210 network_mask=64 211 lhost_host_part=":2" # local host 212 rhost_host_part=":1" # remote host 213 add_ipv6addr lhost $link_num $network_part $lhost_host_part 214 if [ $? -ne 0 ]; then 215 tst_resm TBROK "Failed to set IPv6 address at the local host" 216 exit 1 217 fi 218 add_ipv6addr rhost $link_num $network_part $rhost_host_part 219 if [ $? -ne 0 ]; then 220 tst_resm TBROK "Failed to set IPv6 address at the remote host" 221 exit 1 222 fi 223 lhost_addr="${network_part}:${lhost_host_part}" 224 rhost_addr="${network_part}:${rhost_host_part}" 225 lhost_addrs="${lhost_addrs} ${lhost_addr}" 226 ;; 227 228 *) 229 tst_resm TBROK "Unknown IP version" 230 ;; 231 esac 232 233 # Configure SAD/SPD 234 if $DO_IPSEC ; then 235 ipsec_log=`mktemp -p $TMPDIR` 236 237 # Set SAD/SPD according to the variables 238 output_ipsec_conf src \ 239 $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \ 240 | setkey -c 2>&1 | tee $ipsec_log 241 if [ $? -ne 0 -o -s $ipsec_log ]; then 242 rm -f $ipsec_log 243 tst_resm TBROK "Failed to configure SAD/SPD on the local host." 244 exit 1 245 fi 246 247 $LTP_RSH $RHOST ${LTPROOT}/testcases/bin/output_ipsec_conf dst $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr' | PATH=/sbin:/usr/sbin:$PATH setkey -c' 2>&1 | tee $ipsec_log 248 if [ $? -ne 0 -o -s $ipsec_log ]; then 249 rm -f $ipsec_log 250 tst_resm TBROK "Failed to configure SAD/SPD on the remote host." 251 exit 1 252 fi 253 rm -f $ipsec_log 254 fi 255 256 # Make sure the connectivity 257 case $IP_VER in 258 4) 259 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 260 if [ $ret -ne 0 ]; then 261 tst_resm TBROK "There is no IPv4 connectivity on Link${link_num}" 262 exit 1 263 fi 264 ;; 265 266 6) 267 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 268 if [ $ret -ne 0 ]; then 269 tst_resm TBROK "There is no IPv6 connectivity on Link${link_num}" 270 exit 1 271 fi 272 ;; 273 esac 274 275 link_num=`expr $link_num + 1` 276done 277 278 279#----------------------------------------------------------------------- 280# 281# Main 282# 283# 284 285# Find the available consecutive ports 286server_port=`find_portbundle udp 1025 1` 287if [ $? -ne 0 ]; then 288 tst_resm TBROK "No port is available." 289 exit 1 290fi 291 292# Run a UDP traffic server 293info_file=`mktemp -p $TMPDIR` 294ns-udpserver -b -f $IP_VER -p $server_port -o $info_file 295if [ $? -ne 0 ]; then 296 tst_resm TFAIL "Failed to run a UDP traffic server" 297 exit 1 298fi 299 300# Collect the information of the server 301while true ; do 302 if [ -s $info_file ]; then 303 break 304 fi 305done 306server_pid=`grep PID: $info_file | cut -f 2 -d ' '` 307rm -f $info_file 308 309# Main loop 310connection_num=0 311while [ $connection_num -lt $link_total ]; do 312 field=`expr $connection_num + 1` 313 lhost_addr=`echo $lhost_addrs | cut -d ' ' -f $field` 314 315 # Run a client 316 ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'` 317 if [ $ret -ne 0 ]; then 318 tst_resm TFAIL "Failed to run client on Link${connection_num}" 319 exit 1 320 fi 321 connection_num=`expr $connection_num + 1` 322done 323 324 325# Watch the UDP traffic server 326start_epoc=`date +%s` 327while true ; do 328 current_epoc=`date +%s` 329 elapse_epoc=`expr $current_epoc - $start_epoc` 330 331 if [ $elapse_epoc -ge $NS_DURATION ]; then 332 break 333 else 334 ps auxw | fgrep ns-udpserver | fgrep -l $server_pid >/dev/null 2>&1 335 if [ $? -ne 0 ]; then 336 tst_resm TFAIL "udp traffic server is dead in $elapse_epoc [sec]" 337 exit 1 338 fi 339 fi 340 sleep 1 341done 342 343 344#----------------------------------------------------------------------- 345# 346# Clean up 347# 348 349tst_resm TPASS "Test is finished successfully." 350exit 0 351