tcp4-multi-diffport01 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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-diffport01
  25. #
  26. # Description:
  27. # Verify that the kernel is not crashed with multiple connection to the
  28. # different ports 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-diffport01}
  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 ports."
  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. # Quantity of the connection for multi connection test
  65. CONNECTION_TOTAL=${CONNECTION_TOTAL:-4000}
  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 $CONNECTION_TOTAL"
  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. # Configurate IP addresses
  160. case $IP_VER in
  161. 4)
  162. # Network portion of the IPv4 address
  163. network_part=${IPV4_NETWORK:-"10.0.0"}
  164. # Netmask of the IPv4 network
  165. network_mask=24
  166. # Host portion of the IPv4 address
  167. lhost_host_part=${LHOST_IPV4_HOST:-"2"} # local host
  168. rhost_host_part=${RHOST_IPV4_HOST:-"1"} # remote host
  169. # Set IPv4 addresses to the interfaces
  170. set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part
  171. if [ $? -ne 0 ]; then
  172. tst_resm TBROK "Failed to add any IP address at the local host"
  173. exit 1
  174. fi
  175. set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part
  176. if [ $? -ne 0 ]; then
  177. tst_resm TBROK "Failed to add any IP address at the remote host"
  178. exit 1
  179. fi
  180. # IPv4 address of the local/remote host
  181. lhost_addr="${network_part}.${lhost_host_part}"
  182. rhost_addr="${network_part}.${rhost_host_part}"
  183. ;;
  184. 6)
  185. # Network portion of the IPv6 address
  186. network_part="fd00:1:1:1"
  187. # Netmask of the IPv6 network
  188. network_mask=64
  189. # Host portion of the IPv6 address
  190. lhost_host_part=":2" # local host
  191. rhost_host_part=":1" # remote host
  192. # Set IPv6 addresses to the interfaces
  193. add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part
  194. if [ $? -ne 0 ]; then
  195. tst_resm TBROK "Failed to add any IP address at the local host"
  196. exit 1
  197. fi
  198. add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part
  199. if [ $? -ne 0 ]; then
  200. tst_resm TBROK "Failed to add any IP address at the remote host"
  201. exit 1
  202. fi
  203. # IPv6 address of the local/remote host
  204. lhost_addr="${network_part}:${lhost_host_part}"
  205. rhost_addr="${network_part}:${rhost_host_part}"
  206. ;;
  207. *)
  208. tst_resm TBROK "Unknown IP version"
  209. ;;
  210. esac
  211. # Make the network delay
  212. if $DO_NET_DELAY ; then
  213. 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 $?'`
  214. if [ $ret -ne 0 ]; then
  215. tst_resm TBROK "Failed to make the delayed network"
  216. exit 1
  217. fi
  218. fi
  219. # Configure SAD/SPD
  220. if $DO_IPSEC ; then
  221. ipsec_log=`mktemp -p $TMPDIR`
  222. output_ipsec_conf src \
  223. $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
  224. | setkey -c 2>&1 | tee $ipsec_log
  225. if [ $? -ne 0 -o -s $ipsec_log ]; then
  226. tst_resm TBROK "Failed to configure SAD/SPD on the local host."
  227. rm -f $ipsec_log
  228. exit 1
  229. fi
  230. $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
  231. if [ $? -ne 0 -o -s $ipsec_log ]; then
  232. tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
  233. rm -f $ipsec_log
  234. exit 1
  235. fi
  236. rm -f $ipsec_log
  237. fi
  238. # Make sure the connectvity
  239. case $IP_VER in
  240. 4)
  241. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  242. if [ $ret -ne 0 ]; then
  243. tst_resm TBROK "There is no IPv4 connectivity."
  244. exit 1
  245. fi
  246. ;;
  247. 6)
  248. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  249. if [ $ret -ne 0 ]; then
  250. tst_resm TBROK "There is no IPv6 connectivity."
  251. exit 1
  252. fi
  253. ;;
  254. esac
  255. #-----------------------------------------------------------------------
  256. #
  257. # Main
  258. #
  259. #
  260. # Find the available consecutive ports
  261. portbundle=`find_portbundle tcp 1025 $CONNECTION_TOTAL`
  262. if [ $? -ne 0 ]; then
  263. tst_resm TBROK "No port is available."
  264. exit 1
  265. fi
  266. start_port=`echo $portbundle | cut -f 1 -d '-'`
  267. end_port=`echo $portbundle | cut -f 2 -d '-'`
  268. # Making connections
  269. connection_num=0
  270. current_port=$start_port
  271. while [ $current_port -le $end_port ]; do
  272. # Run a server
  273. ns-tcpserver -b -f $IP_VER -p $current_port
  274. if [ $? -ne 0 ]; then
  275. # Failed to start no server
  276. if [ $connection_num -eq 0 ]; then
  277. tst_resm TFAIL "Failed to run a server"
  278. exit 1
  279. fi
  280. # Failed to start a server
  281. tst_resm TINFO "$connection_num seems the maximum number of the server"
  282. break
  283. fi
  284. # Run a clinet
  285. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $current_port' ; echo $?'`
  286. if [ $ret -ne 0 ]; then
  287. # Failed to start any client
  288. if [ $connection_num -eq 0 ]; then
  289. tst_resm TFAIL "Failed to run any client."
  290. exit 1
  291. fi
  292. # Failed to start a client
  293. tst_resm TINFO "$connection_num seems the maximum number of the client"
  294. break
  295. fi
  296. current_port=`expr $current_port + 1`
  297. connection_num=`expr $connection_num + 1`
  298. done
  299. # Watch the TCP traffic server
  300. start_epoc=`date +%s`
  301. while true ; do
  302. current_epoc=`date +%s`
  303. elapse_epoc=`expr $current_epoc - $start_epoc`
  304. if [ $elapse_epoc -ge $NS_DURATION ]; then
  305. killall -SIGHUP ns-tcpserver
  306. break
  307. else
  308. ps auxw | fgrep -v grep | fgrep -l ns-tcpserver >/dev/null 2>&1
  309. if [ $? -ne 0 ]; then
  310. tst_resm TFAIL "All tcp traffic servers are dead in $elapse_epoc [sec]"
  311. exit 1
  312. fi
  313. fi
  314. sleep 1
  315. done
  316. #-----------------------------------------------------------------------
  317. #
  318. # Clean up
  319. #
  320. tst_resm TPASS "Test is finished successfully."
  321. exit 0