icmp4-multi-diffip01 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. # icmp4-multi-diffip01
  25. #
  26. # Description:
  27. # Verify that the kernel is not crashed with receiving and sending ICMP
  28. # message at different IP address(alias) 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:-icmp4-multi-diffip01}
  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 various size of ICMP message at the different IP address(alias) simultaneously 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. # The number of IP address (alias)
  64. IP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}
  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. # Array of the echo request packet size
  78. ICMP_SIZE_ARRAY=${ICMP_SIZE_ARRAY:-"10 100 1000 10000 65507"}
  79. #-----------------------------------------------------------------------
  80. #
  81. # Function: do_cleanup
  82. #
  83. # Description:
  84. # Recover the system configuration
  85. #
  86. #-----------------------------------------------------------------------
  87. do_cleanup()
  88. {
  89. # Kill the icmp traffic server
  90. killall_icmp_traffic
  91. # Unset SAD/SPD
  92. output_ipsec_conf flush | setkey -c >/dev/null 2>&1
  93. $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
  94. # Clean up each interface
  95. initialize_if lhost ${LINK_NUM}
  96. initialize_if rhost ${LINK_NUM}
  97. }
  98. #-----------------------------------------------------------------------
  99. #
  100. # Setup
  101. #
  102. # Unset the maximum number of processes
  103. ulimit -u unlimited
  104. # Output the informaion
  105. tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
  106. tst_resm TINFO "- Target number of the connection is $IP_TOTAL_FOR_TCPIP"
  107. tst_resm TINFO "- Version of IP is IPv${IP_VER}"
  108. tst_resm TINFO "- Size of packets are ( $ICMP_SIZE_ARRAY )"
  109. if $DO_IPSEC ; then
  110. message=`check_setkey`
  111. if [ $? -ne 0 ]; then
  112. tst_resm TBROK "$message"
  113. exit 1
  114. fi
  115. case $IPSEC_PROTO in
  116. ah)
  117. tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
  118. ;;
  119. esp)
  120. tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
  121. ;;
  122. ipcomp)
  123. tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
  124. ;;
  125. esac
  126. fi
  127. # name of interface of the local/remote host
  128. lhost_ifname=`get_ifname lhost $LINK_NUM`
  129. if [ $? -ne 0 ]; then
  130. tst_resm TBROK "Failed to get the interface name at the local host"
  131. exit $TST_TOTAL
  132. fi
  133. rhost_ifname=`get_ifname rhost $LINK_NUM`
  134. if [ $? -ne 0 ]; then
  135. tst_resm TBROK "Failed to get the interface name at the remote host"
  136. exit $TST_TOTAL
  137. fi
  138. # Initialize the system configuration
  139. do_cleanup
  140. # Call do_cleanup function before exit
  141. trap do_cleanup 0
  142. # Loop to assign IP addresses
  143. ipaddr_pair_num=0
  144. while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
  145. # Add new IP addresses
  146. x=`expr $ipaddr_pair_num \/ 255 % 255`
  147. y=`expr $ipaddr_pair_num % 255`
  148. if [ $x -ge 255 ]; then
  149. tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
  150. break
  151. fi
  152. case $IP_VER in
  153. 4)
  154. network_part="10.${x}.${y}"
  155. network_broadcast=${network_part}.255
  156. network_mask=24
  157. lhost_addr="${network_part}.2"
  158. rhost_addr="${network_part}.1"
  159. # Set IPv4 addresses to the interfaces
  160. ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
  161. ### delete before setting
  162. if [ $? -eq 2 ]; then
  163. ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname 2>&1
  164. ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
  165. fi
  166. if [ $? -ne 0 ]; then
  167. if [ $ipaddr_pair_num -eq 0 ]; then
  168. tst_resm TBROK "Failed to add any IP address at the local"
  169. exit 1
  170. else
  171. tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
  172. fi
  173. break
  174. fi
  175. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
  176. if [ $ret -eq 2 ]; then
  177. $LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
  178. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
  179. fi
  180. if [ $ret -ne 0 ]; then
  181. if [ $ipaddr_pair_num -eq 0 ]; then
  182. tst_resm TBROK "Failed to add any IP address at the remote"
  183. exit 1
  184. else
  185. tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
  186. fi
  187. break
  188. fi
  189. ;;
  190. 6)
  191. hex_x=`printf %x $x`
  192. hex_y=`printf %x $y`
  193. network_part="fd00:1:${hex_x}:${hex_y}"
  194. network_mask=64
  195. lhost_addr="${network_part}::2"
  196. rhost_addr="${network_part}::1"
  197. # Set IPv6 addresses to the interfaces
  198. ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
  199. if [ $? -eq 2 ]; then
  200. ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname 2>&1
  201. ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
  202. fi
  203. if [ $? -ne 0 ]; then
  204. if [ $ipaddr_pair_num -eq 0 ]; then
  205. tst_resm TBROK "Failed to add any IP address at the local"
  206. exit 1
  207. else
  208. tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
  209. fi
  210. break
  211. fi
  212. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
  213. if [ $ret -eq 2 ]; then
  214. $LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
  215. ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
  216. fi
  217. if [ $ret -ne 0 ]; then
  218. if [ $ipaddr_pair_num -eq 0 ]; then
  219. tst_resm TBROK "Failed to add any IP address at the remote"
  220. exit 1
  221. else
  222. tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
  223. fi
  224. break
  225. fi
  226. ;;
  227. esac
  228. # Set SAD/SPD
  229. if $DO_IPSEC ; then
  230. ipsec_log=`mktemp -p $TMPDIR`
  231. output_ipsec_conf src \
  232. $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
  233. | setkey -c 2>&1 | tee $ipsec_log
  234. if [ $? -ne 0 -o -s $ipsec_log ]; then
  235. rm -f $ipsec_log
  236. if [ $ipaddr_pair_num -eq 0 ]; then
  237. tst_resm TBROK "Failed to add any SAD/SPD"
  238. exit 1
  239. else
  240. tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
  241. fi
  242. break
  243. fi
  244. rm -f $ipsec_log
  245. $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
  246. if [ -s $ipsec_log ]; then
  247. rm -f $ipsec_log
  248. if [ $ipaddr_pair_num -eq 0 ]; then
  249. tst_resm TBROK "Failed to add any SAD/SPD"
  250. exit 1
  251. else
  252. tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
  253. fi
  254. break
  255. fi
  256. rm -f $ipsec_log
  257. fi
  258. # Check the connectivity
  259. case $IP_VER in
  260. 4)
  261. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  262. if [ $ret -ne 0 ]; then
  263. tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP address pair"
  264. exit 1
  265. fi
  266. ;;
  267. 6)
  268. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  269. if [ $ret -ne 0 ]; then
  270. tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP address pair"
  271. exit 1
  272. fi
  273. ;;
  274. esac
  275. if [ $? -ne 0 ]; then
  276. tst_resm TFAIL "There is no connectivity."
  277. exit 1
  278. fi
  279. ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
  280. done
  281. #-----------------------------------------------------------------------
  282. #
  283. # Main
  284. #
  285. #
  286. # Start to receiving/replying ICMP echo
  287. connection_num=0
  288. while [ $connection_num -lt $ipaddr_pair_num ]; do
  289. # IP addresses
  290. x=`expr $connection_num \/ 255 % 255`
  291. y=`expr $connection_num % 255`
  292. case $IP_VER in
  293. 4)
  294. lhost_addr="10.${x}.${y}.2"
  295. ;;
  296. 6)
  297. hex_x=`printf %x $x`
  298. hex_y=`printf %x $y`
  299. lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
  300. ;;
  301. esac
  302. # Run a client
  303. $LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-echoclient -S $lhost_addr -f $IP_VER -s \"$ICMP_SIZE_ARRAY\"" &
  304. connection_num=`expr $connection_num + 1`
  305. done
  306. sleep $NS_DURATION
  307. killall_icmp_traffic
  308. wait
  309. #-----------------------------------------------------------------------
  310. #
  311. # Clean up
  312. #
  313. tst_resm TPASS "Test is finished successfully."
  314. exit 0