tcp4-multi-sameport01 10 KB

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