icmp4-multi-diffnic01 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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-diffnic01
  25. #
  26. # Description:
  27. # Verify that the kernel is not crashed with receiving and sending ICMP
  28. # message at differnt NIC 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-diffnic01}
  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 differnt NIC 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 version of IP
  64. IP_VER=${IP_VER:-4}
  65. # true, if ipsec is used
  66. DO_IPSEC=${DO_IPSEC:-false}
  67. # The value of SPI
  68. SPI=${SPI:-1000}
  69. # IPsec Protocol ( ah / esp / ipcomp )
  70. IPSEC_PROTO=${IPSEC_PROTO:-ah}
  71. # IPsec Mode ( transport / tunnel )
  72. IPSEC_MODE=${IPSEC_MODE:-transport}
  73. # Array of the echo request packet size
  74. ICMP_SIZE_ARRAY=${ICMP_SIZE_ARRAY:-"10 100 1000 10000 65507"}
  75. #-----------------------------------------------------------------------
  76. #
  77. # Function: do_cleanup
  78. #
  79. # Description:
  80. # Recover the system configuration
  81. #
  82. #-----------------------------------------------------------------------
  83. do_cleanup()
  84. {
  85. # Kill the icmp traffic server
  86. killall_icmp_traffic
  87. # Unset SAD/SPD
  88. output_ipsec_conf flush | setkey -c >/dev/null 2>&1
  89. $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
  90. # Clean up each interface
  91. link_num=0
  92. while [ $link_num -lt $link_total ]; do
  93. initialize_if lhost ${link_num}
  94. initialize_if rhost ${link_num}
  95. link_num=`expr $link_num + 1`
  96. done
  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. link_total=`echo $LHOST_HWADDRS | wc -w`
  107. rhost_link_total=`echo $RHOST_HWADDRS | wc -w`
  108. if [ $link_total -ne $rhost_link_total ]; then
  109. tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS"
  110. exit 1
  111. fi
  112. if [ $link_total -lt 2 ]; then
  113. tst_resm TBROK "This test case requires plural NICs."
  114. exit 1
  115. fi
  116. tst_resm TINFO "- Target number of the connection is $link_total"
  117. tst_resm TINFO "- Version of IP is IPv${IP_VER}"
  118. tst_resm TINFO "- Size of packets are ( $ICMP_SIZE_ARRAY )"
  119. if $DO_IPSEC ; then
  120. message=`check_setkey`
  121. if [ $? -ne 0 ]; then
  122. tst_resm TBROK "$message"
  123. exit 1
  124. fi
  125. case $IPSEC_PROTO in
  126. ah)
  127. tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
  128. ;;
  129. esp)
  130. tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
  131. ;;
  132. ipcomp)
  133. tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
  134. ;;
  135. esac
  136. fi
  137. # Initialize the system configuration
  138. do_cleanup
  139. # Call do_cleanup function before exit
  140. trap do_cleanup 0
  141. # Loop for NIC configuration
  142. link_num=0
  143. lhost_addrs=""
  144. while [ $link_num -lt $link_total ]; do
  145. # name of interface of the local/remote host
  146. lhost_ifname=`get_ifname lhost $link_num`
  147. rhost_ifname=`get_ifname rhost $link_num`
  148. # Set the IP address to each interface
  149. case $IP_VER in
  150. 4)
  151. network_part="10.0.${link_num}"
  152. network_mask=24
  153. lhost_host_part="2" # local host
  154. rhost_host_part="1" # remote host
  155. set_ipv4addr lhost $link_num $network_part $lhost_host_part
  156. if [ $? -ne 0 ]; then
  157. tst_resm TBROK "Failed to set IPv4 address at the local host"
  158. exit 1
  159. fi
  160. set_ipv4addr rhost $link_num $network_part $rhost_host_part
  161. if [ $? -ne 0 ]; then
  162. tst_resm TBROK "Failed to set IPv4 address at the remote host"
  163. exit 1
  164. fi
  165. # IPv4 address of the local/remote host
  166. lhost_addr="${network_part}.${lhost_host_part}"
  167. rhost_addr="${network_part}.${rhost_host_part}"
  168. lhost_addrs="${lhost_addrs} ${lhost_addr}"
  169. ;;
  170. 6)
  171. network_part="fd00:1:0:`printf %x ${link_num}`"
  172. network_mask=64
  173. lhost_host_part=":2" # local host
  174. rhost_host_part=":1" # remote host
  175. add_ipv6addr lhost $link_num $network_part $lhost_host_part
  176. if [ $? -ne 0 ]; then
  177. tst_resm TBROK "Failed to set IPv6 address at the local host"
  178. exit 1
  179. fi
  180. add_ipv6addr rhost $link_num $network_part $rhost_host_part
  181. if [ $? -ne 0 ]; then
  182. tst_resm TBROK "Failed to set IPv6 address at the remote host"
  183. exit 1
  184. fi
  185. lhost_addr="${network_part}:${lhost_host_part}"
  186. rhost_addr="${network_part}:${rhost_host_part}"
  187. lhost_addrs="${lhost_addrs} ${lhost_addr}"
  188. ;;
  189. *)
  190. tst_resm TBROK "Unknown IP version"
  191. ;;
  192. esac
  193. # Configure SAD/SPD
  194. if $DO_IPSEC ; then
  195. ipsec_log=`mktemp -p $TMPDIR`
  196. # Set SAD/SPD according to the variables
  197. output_ipsec_conf src \
  198. $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
  199. | setkey -c 2>&1 | tee $ipsec_log
  200. if [ $? -ne 0 -o -s $ipsec_log ]; then
  201. rm -f $ipsec_log
  202. tst_resm TBROK "Failed to configure SAD/SPD on the local host."
  203. exit 1
  204. fi
  205. $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
  206. if [ $? -ne 0 -o -s $ipsec_log ]; then
  207. rm -f $ipsec_log
  208. tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
  209. exit 1
  210. fi
  211. rm -f $ipsec_log
  212. fi
  213. # Make sure the connectivity
  214. case $IP_VER in
  215. 4)
  216. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  217. if [ $ret -ne 0 ]; then
  218. tst_resm TBROK "There is no IPv4 connectivity on Link${link_num}"
  219. exit 1
  220. fi
  221. ;;
  222. 6)
  223. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  224. if [ $ret -ne 0 ]; then
  225. tst_resm TBROK "There is no IPv6 connectivity on Link${link_num}"
  226. exit 1
  227. fi
  228. ;;
  229. esac
  230. link_num=`expr $link_num + 1`
  231. done
  232. #-----------------------------------------------------------------------
  233. #
  234. # Main
  235. #
  236. #
  237. connection_num=0
  238. while [ $connection_num -lt $link_total ]; do
  239. field=`expr $connection_num + 1`
  240. lhost_addr=`echo $lhost_addrs | cut -d ' ' -f $field`
  241. lhost_ifname=`get_ifname lhost $connection_num`
  242. rhost_ifname=`get_ifname rhost $connection_num`
  243. # Run a client
  244. $LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-echoclient -S $lhost_addr -f $IP_VER -s \"$ICMP_SIZE_ARRAY\"" &
  245. connection_num=`expr $connection_num + 1`
  246. done
  247. sleep $NS_DURATION
  248. killall_icmp_traffic
  249. wait
  250. #-----------------------------------------------------------------------
  251. #
  252. # Clean up
  253. #
  254. tst_resm TPASS "Test is finished successfully."
  255. exit 0