tcp4-multi-diffip01 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) International Business Machines Corp., 2005 ##
  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. # tcp4-multi-diffip01
  25. #
  26. # Description:
  27. # Verify that the kernel is not crashed with multiple connection to the
  28. # different IP address(alias) with the following condition:
  29. # - The version of IP is IPv4
  30. # - Network is not delayed
  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. # The test case ID, the test case count and the total number of test case
  49. TCID=${TCID:-tcp4-multi-diffip01}
  50. TST_TOTAL=1
  51. TST_COUNT=1
  52. export TCID
  53. export TST_COUNT
  54. export TST_TOTAL
  55. # Test description
  56. tst_resm TINFO "Verify that the kernel is not crashed with multiple connection to the different IP address(alias)."
  57. # Make sure the value of LTPROOT
  58. LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
  59. export LTPROOT
  60. # Check the environmanet variable
  61. . check_envval || exit $TST_TOTAL
  62. # Dulation of the test [sec]
  63. NS_DURATION=${NS_DURATION:-3600} # 1 hour
  64. # The number of IP address (alias)
  65. IP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}
  66. #The number of the test link where tests run
  67. LINK_NUM=${LINK_NUM:-0}
  68. # The version of IP
  69. IP_VER=${IP_VER:-4}
  70. # true, if ipsec is used
  71. DO_IPSEC=${DO_IPSEC:-false}
  72. # The value of SPI
  73. SPI=${SPI:-1000}
  74. # IPsec Protocol ( ah / esp / ipcomp )
  75. IPSEC_PROTO=${IPSEC_PROTO:-ah}
  76. # IPsec Mode ( transport / tunnel )
  77. IPSEC_MODE=${IPSEC_MODE:-transport}
  78. # true, if network is delayed
  79. DO_NET_DELAY=${DO_NET_DELAY:-false}
  80. # Amount of network delay [ms]
  81. NET_DELAY=${NET_DELAY:-600}
  82. # The deflection of network delay [ms]
  83. NET_DELAY_DEFL=${NET_DELAY_DEFL:-200}
  84. #-----------------------------------------------------------------------
  85. #
  86. # Function: do_cleanup
  87. #
  88. # Description:
  89. # Recover the system configuration
  90. #
  91. #-----------------------------------------------------------------------
  92. do_cleanup()
  93. {
  94. # Kill the tcp traffic server
  95. killall_tcp_traffic
  96. # Unset SAD/SPD
  97. output_ipsec_conf flush | setkey -c >/dev/null 2>&1
  98. $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
  99. # Unset network delay
  100. if [ x$rhost_ifname = x ]; then
  101. rhost_ifname=`get_ifname rhost $LINK_NUM`
  102. fi
  103. $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1
  104. # Clean up each interface
  105. initialize_if lhost ${LINK_NUM}
  106. initialize_if rhost ${LINK_NUM}
  107. }
  108. #-----------------------------------------------------------------------
  109. #
  110. # Setup
  111. #
  112. # Unset the maximum number of processes
  113. ulimit -u unlimited
  114. # Output the informaion
  115. tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
  116. tst_resm TINFO "- Target number of the connection is $IP_TOTAL_FOR_TCPIP"
  117. tst_resm TINFO "- Version of IP is IPv${IP_VER}"
  118. if $DO_NET_DELAY ; then
  119. message=`check_netem`
  120. if [ $? -ne 0 ]; then
  121. tst_resm TBROK "$message"
  122. exit 1
  123. fi
  124. tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms"
  125. fi
  126. if $DO_IPSEC ; then
  127. message=`check_setkey`
  128. if [ $? -ne 0 ]; then
  129. tst_resm TBROK "$message"
  130. exit 1
  131. fi
  132. case $IPSEC_PROTO in
  133. ah)
  134. tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
  135. ;;
  136. esp)
  137. tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
  138. ;;
  139. ipcomp)
  140. tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
  141. ;;
  142. esac
  143. fi
  144. # name of interface of the local/remote host
  145. lhost_ifname=`get_ifname lhost $LINK_NUM`
  146. if [ $? -ne 0 ]; then
  147. tst_resm TBROK "Failed to get the interface name at the local host"
  148. exit $TST_TOTAL
  149. fi
  150. rhost_ifname=`get_ifname rhost $LINK_NUM`
  151. if [ $? -ne 0 ]; then
  152. tst_resm TBROK "Failed to get the interface name at the remote host"
  153. exit $TST_TOTAL
  154. fi
  155. # Initialize the system configuration
  156. do_cleanup
  157. # Call do_cleanup function before exit
  158. trap do_cleanup 0
  159. # Make the network delay
  160. if $DO_NET_DELAY ; then
  161. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc add dev $rhost_ifname root netem delay ${NET_DELAY}ms ${NET_DELAY_DEFL}ms distribution normal' ; echo $?'`
  162. if [ $ret -ne 0 ]; then
  163. tst_resm TBROK "Failed to make the delayed network"
  164. exit 1
  165. fi
  166. fi
  167. # Loop for assign IP addresses
  168. ipaddr_pair_num=0
  169. while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
  170. # Add new IP addresses
  171. x=`expr $ipaddr_pair_num \/ 255 % 255`
  172. y=`expr $ipaddr_pair_num % 255`
  173. if [ $x -ge 255 ]; then
  174. tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
  175. break
  176. fi
  177. case $IP_VER in
  178. 4)
  179. network_part="10.${x}.${y}"
  180. network_broadcast=${network_part}.255
  181. network_mask=24
  182. lhost_addr="${network_part}.2"
  183. rhost_addr="${network_part}.1"
  184. # Set IPv4 addresses to the interfaces
  185. ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
  186. if [ $? -eq 2 ]; then
  187. ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname 2>&1
  188. ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
  189. fi
  190. if [ $? -ne 0 ]; then
  191. if [ $ipaddr_pair_num -eq 0 ]; then
  192. tst_resm TBROK "Failed to add any IP address at the local"
  193. exit 1
  194. else
  195. tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
  196. fi
  197. break
  198. fi
  199. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
  200. if [ $ret -eq 2 ]; then
  201. $LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
  202. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
  203. fi
  204. if [ $ret -ne 0 ]; then
  205. if [ $ipaddr_pair_num -eq 0 ]; then
  206. tst_resm TBROK "Failed to add any IP address at the remote"
  207. exit 1
  208. else
  209. tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
  210. fi
  211. break
  212. fi
  213. ;;
  214. 6)
  215. hex_x=`printf %x $x`
  216. hex_y=`printf %x $y`
  217. network_part="fd00:1:${hex_x}:${hex_y}"
  218. network_mask=64
  219. lhost_addr="${network_part}::2"
  220. rhost_addr="${network_part}::1"
  221. # Set IPv6 addresses to the interfaces
  222. ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
  223. if [ $? -eq 2 ]; then
  224. ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname 2>&1
  225. ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
  226. fi
  227. if [ $? -ne 0 ]; then
  228. if [ $ipaddr_pair_num -eq 0 ]; then
  229. tst_resm TBROK "Failed to add any IP address at the local"
  230. exit 1
  231. else
  232. tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
  233. fi
  234. break
  235. fi
  236. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
  237. if [ $ret -eq 2 ]; then
  238. $LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
  239. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
  240. fi
  241. if [ $ret -ne 0 ]; then
  242. if [ $ipaddr_pair_num -eq 0 ]; then
  243. tst_resm TBROK "Failed to add any IP address at the remote"
  244. exit 1
  245. else
  246. tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
  247. fi
  248. break
  249. fi
  250. ;;
  251. esac
  252. # Set SAD/SPD
  253. if $DO_IPSEC ; then
  254. ipsec_log=`mktemp -p $TMPDIR`
  255. output_ipsec_conf src \
  256. $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
  257. | setkey -c 2>&1 | tee $ipsec_log
  258. if [ $? -ne 0 -o -s $ipsec_log ]; then
  259. rm -f $ipsec_log
  260. if [ $ipaddr_pair_num -eq 0 ]; then
  261. tst_resm TBROK "Failed to add any SAD/SPD"
  262. exit 1
  263. else
  264. tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
  265. fi
  266. break
  267. fi
  268. rm -f $ipsec_log
  269. $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
  270. if [ $? -ne 0 -o -s $ipsec_log ]; then
  271. rm -f $ipsec_log
  272. if [ $ipaddr_pair_num -eq 0 ]; then
  273. tst_resm TBROK "Failed to add any SAD/SPD"
  274. exit 1
  275. else
  276. tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
  277. fi
  278. break
  279. fi
  280. rm -f $ipsec_log
  281. fi
  282. # Check the connectivity
  283. case $IP_VER in
  284. 4)
  285. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  286. if [ $ret -ne 0 ]; then
  287. tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP address pair"
  288. exit 1
  289. fi
  290. ;;
  291. 6)
  292. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  293. if [ $ret -ne 0 ]; then
  294. tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP address pair"
  295. exit 1
  296. fi
  297. ;;
  298. esac
  299. if [ $? -ne 0 ]; then
  300. tst_resm TFAIL "There is no connectivity."
  301. exit 1
  302. fi
  303. ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
  304. done
  305. #-----------------------------------------------------------------------
  306. #
  307. # Main
  308. #
  309. #
  310. # Find the available consecutive ports
  311. server_port=`find_portbundle tcp 1025 1`
  312. if [ $? -ne 0 ]; then
  313. tst_resm TFAIL "No port is available."
  314. exit 1
  315. fi
  316. # Run a server
  317. info_file=`mktemp -p $TMPDIR`
  318. ns-tcpserver -b -c -f $IP_VER -p $server_port -o $info_file
  319. if [ $? -ne 0 ]; then
  320. tst_resm TFAIL "Failed to run tcp traffic server."
  321. rm -f $info_file
  322. exit 1
  323. fi
  324. while true ; do
  325. if [ -s $info_file ]; then
  326. break
  327. fi
  328. done
  329. server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
  330. rm -f $info_file
  331. # Make connections
  332. connection_num=0
  333. while [ $connection_num -lt $ipaddr_pair_num ]; do
  334. # IP addresses
  335. x=`expr $connection_num \/ 255 % 255`
  336. y=`expr $connection_num % 255`
  337. case $IP_VER in
  338. 4)
  339. lhost_addr="10.${x}.${y}.2"
  340. ;;
  341. 6)
  342. hex_x=`printf %x $x`
  343. hex_y=`printf %x $y`
  344. lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
  345. ;;
  346. esac
  347. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
  348. if [ $ret -ne 0 ]; then
  349. if [ $connection_num -eq 0 ]; then
  350. tst_resm TFAIL "Failed to run any client"
  351. exit 1
  352. else
  353. tst_resm TINFO "$connection_num seems the maximum number of the client"
  354. fi
  355. break
  356. fi
  357. connection_num=`expr $connection_num + 1`
  358. done
  359. # Watch the TCP traffic server
  360. start_epoc=`date +%s`
  361. while true ; do
  362. current_epoc=`date +%s`
  363. elapse_epoc=`expr $current_epoc - $start_epoc`
  364. if [ $elapse_epoc -ge $NS_DURATION ]; then
  365. killall -SIGHUP ns-tcpserver
  366. break
  367. else
  368. ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1
  369. if [ $? -ne 0 ]; then
  370. tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]"
  371. exit 1
  372. fi
  373. fi
  374. sleep 1
  375. done
  376. #-----------------------------------------------------------------------
  377. #
  378. # Clean up
  379. #
  380. tst_resm TPASS "Test is finished successfully."
  381. exit 0