udp4-multi-diffnic01 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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-diffnic01
  25. #
  26. # Description:
  27. # Verify that the kernel is not crashed with receiving and sending UDP
  28. # datagram 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:-udp4-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 UDP datagram at the differnt NICs 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 the test link where tests run
  64. LINK_NUM=${LINK_NUM:-0}
  65. # The version of IP
  66. IP_VER=${IP_VER:-4}
  67. # true, if ipsec is used
  68. DO_IPSEC=${DO_IPSEC:-false}
  69. # The value of SPI
  70. SPI=${SPI:-1000}
  71. # IPsec Protocol ( ah / esp / ipcomp )
  72. IPSEC_PROTO=${IPSEC_PROTO:-ah}
  73. # IPsec Mode ( transport / tunnel )
  74. IPSEC_MODE=${IPSEC_MODE:-transport}
  75. #-----------------------------------------------------------------------
  76. #
  77. # Function: do_cleanup
  78. #
  79. # Description:
  80. # Recover the system configuration
  81. #
  82. #-----------------------------------------------------------------------
  83. do_cleanup()
  84. {
  85. # Kill the udp traffic server
  86. killall_udp_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 the interfaces
  94. initialize_if lhost ${link_num}
  95. initialize_if rhost ${link_num}
  96. link_num=`expr $link_num + 1`
  97. done
  98. }
  99. #-----------------------------------------------------------------------
  100. #
  101. # Setup
  102. #
  103. # Unset the maximum number of processes
  104. ulimit -u unlimited
  105. # Output the informaion
  106. tst_resm TINFO "- Test duration is $NS_DURATION [sec]"
  107. link_total=`echo $LHOST_HWADDRS | wc -w`
  108. rhost_link_total=`echo $RHOST_HWADDRS | wc -w`
  109. if [ $link_total -ne $rhost_link_total ]; then
  110. tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS"
  111. exit 1
  112. fi
  113. if [ $link_total -lt 2 ]; then
  114. tst_resm TBROK "This test case requires plural NICs."
  115. exit 1
  116. fi
  117. tst_resm TINFO "- Target number of the connection is $link_total"
  118. tst_resm TINFO "- Version of IP is IPv${IP_VER}"
  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. if [ $? -ne 0 ]; then
  148. tst_resm TBROK "Failed to get the interface name at the local host"
  149. exit $TST_TOTAL
  150. fi
  151. rhost_ifname=`get_ifname rhost $link_num`
  152. if [ $? -ne 0 ]; then
  153. tst_resm TBROK "Failed to get the interface name at the remtoe host"
  154. exit $TST_TOTAL
  155. fi
  156. # Set the IP address to each interface
  157. case $IP_VER in
  158. 4)
  159. network_part="10.0.${link_num}"
  160. network_mask=24
  161. lhost_host_part="2" # local host
  162. rhost_host_part="1" # remote host
  163. set_ipv4addr lhost $link_num $network_part $lhost_host_part
  164. if [ $? -ne 0 ]; then
  165. tst_resm TBROK "Failed to set IPv4 address at the local host"
  166. exit 1
  167. fi
  168. set_ipv4addr rhost $link_num $network_part $rhost_host_part
  169. if [ $? -ne 0 ]; then
  170. tst_resm TBROK "Failed to set IPv4 address at the remote host"
  171. exit 1
  172. fi
  173. # IPv4 address of the local/remote host
  174. lhost_addr="${network_part}.${lhost_host_part}"
  175. rhost_addr="${network_part}.${rhost_host_part}"
  176. lhost_addrs="${lhost_addrs} ${lhost_addr}"
  177. ;;
  178. 6)
  179. network_part="fd00:1:0:`printf %x ${link_num}`"
  180. network_mask=64
  181. lhost_host_part=":2" # local host
  182. rhost_host_part=":1" # remote host
  183. add_ipv6addr lhost $link_num $network_part $lhost_host_part
  184. if [ $? -ne 0 ]; then
  185. tst_resm TBROK "Failed to set IPv6 address at the local host"
  186. exit 1
  187. fi
  188. add_ipv6addr rhost $link_num $network_part $rhost_host_part
  189. if [ $? -ne 0 ]; then
  190. tst_resm TBROK "Failed to set IPv6 address at the remote host"
  191. exit 1
  192. fi
  193. lhost_addr="${network_part}:${lhost_host_part}"
  194. rhost_addr="${network_part}:${rhost_host_part}"
  195. lhost_addrs="${lhost_addrs} ${lhost_addr}"
  196. ;;
  197. *)
  198. tst_resm TBROK "Unknown IP version"
  199. ;;
  200. esac
  201. # Configure SAD/SPD
  202. if $DO_IPSEC ; then
  203. ipsec_log=`mktemp -p $TMPDIR`
  204. # Set SAD/SPD according to the variables
  205. output_ipsec_conf src \
  206. $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
  207. | setkey -c 2>&1 | tee $ipsec_log
  208. if [ $? -ne 0 -o -s $ipsec_log ]; then
  209. rm -f $ipsec_log
  210. tst_resm TBROK "Failed to configure SAD/SPD on the local host."
  211. exit 1
  212. fi
  213. $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
  214. if [ $? -ne 0 -o -s $ipsec_log ]; then
  215. rm -f $ipsec_log
  216. tst_resm TBROK "Failed to configure SAD/SPD on the remote host."
  217. exit 1
  218. fi
  219. rm -f $ipsec_log
  220. fi
  221. # Make sure the connectivity
  222. case $IP_VER in
  223. 4)
  224. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  225. if [ $ret -ne 0 ]; then
  226. tst_resm TBROK "There is no IPv4 connectivity on Link${link_num}"
  227. exit 1
  228. fi
  229. ;;
  230. 6)
  231. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
  232. if [ $ret -ne 0 ]; then
  233. tst_resm TBROK "There is no IPv6 connectivity on Link${link_num}"
  234. exit 1
  235. fi
  236. ;;
  237. esac
  238. link_num=`expr $link_num + 1`
  239. done
  240. #-----------------------------------------------------------------------
  241. #
  242. # Main
  243. #
  244. #
  245. # Find the available consecutive ports
  246. server_port=`find_portbundle udp 1025 1`
  247. if [ $? -ne 0 ]; then
  248. tst_resm TBROK "No port is available."
  249. exit 1
  250. fi
  251. # Run a UDP traffic server
  252. info_file=`mktemp -p $TMPDIR`
  253. ns-udpserver -b -f $IP_VER -p $server_port -o $info_file
  254. if [ $? -ne 0 ]; then
  255. tst_resm TFAIL "Failed to run a UDP traffic server"
  256. exit 1
  257. fi
  258. # Collect the information of the server
  259. while true ; do
  260. if [ -s $info_file ]; then
  261. break
  262. fi
  263. done
  264. server_pid=`grep PID: $info_file | cut -f 2 -d ' '`
  265. rm -f $info_file
  266. # Main loop
  267. connection_num=0
  268. while [ $connection_num -lt $link_total ]; do
  269. field=`expr $connection_num + 1`
  270. lhost_addr=`echo $lhost_addrs | cut -d ' ' -f $field`
  271. # Run a client
  272. ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-udpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
  273. if [ $ret -ne 0 ]; then
  274. tst_resm TFAIL "Failed to run client on Link${connection_num}"
  275. exit 1
  276. fi
  277. connection_num=`expr $connection_num + 1`
  278. done
  279. # Watch the UDP traffic server
  280. start_epoc=`date +%s`
  281. while true ; do
  282. current_epoc=`date +%s`
  283. elapse_epoc=`expr $current_epoc - $start_epoc`
  284. if [ $elapse_epoc -ge $NS_DURATION ]; then
  285. break
  286. else
  287. ps auxw | fgrep ns-udpserver | fgrep -l $server_pid >/dev/null 2>&1
  288. if [ $? -ne 0 ]; then
  289. tst_resm TFAIL "udp traffic server is dead in $elapse_epoc [sec]"
  290. exit 1
  291. fi
  292. fi
  293. sleep 1
  294. done
  295. #-----------------------------------------------------------------------
  296. #
  297. # Clean up
  298. #
  299. tst_resm TPASS "Test is finished successfully."
  300. exit 0