udp4-multi-diffport01 9.5 KB

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