dns-stress.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/sh
  2. # Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) International Business Machines Corp., 2005
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; either version 2 of
  8. # the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it would be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write the Free Software Foundation,
  17. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  20. TCID=dns-stress
  21. TST_TOTAL=2
  22. TST_CLEANUP="cleanup"
  23. TST_USE_LEGACY_API=1
  24. . tst_net.sh
  25. # Minimum host ID in the zone file.
  26. # The ID is used as the host portion of the address
  27. MIN_ID=2
  28. # Maximum host ID in the zone file.
  29. MAX_ID=254
  30. # Domain name for testing
  31. DOMAIN="ltp-ns.org"
  32. cleanup()
  33. {
  34. # Stop the dns daemon
  35. test -s named.pid && kill -9 $(cat named.pid) > /dev/null
  36. tst_rmdir
  37. }
  38. common_setup()
  39. {
  40. tst_require_root
  41. tst_require_cmds named dig
  42. if [ "$TST_IPV6" ]; then
  43. record="AAAA"
  44. net="fd00:cafe"
  45. net_rev="0.0.0.0.0.0.0.0.e.f.a.c.0.0.d.f"
  46. else
  47. record="A"
  48. net="10.23.0"
  49. net_rev="0.23.10"
  50. fi
  51. trap "tst_brkm TBROK 'test interrupted'" INT
  52. tst_tmpdir
  53. ip6_opt=
  54. [ "$TST_IPV6" ] && ip6_opt="listen-on-v6 { any; };"
  55. ip_zone_opt="in-addr"
  56. [ "$TST_IPV6" ] && ip_zone_opt="ip6"
  57. cat << EOD > named.conf
  58. options {
  59. directory "$(pwd)";
  60. pid-file "named.pid";
  61. recursion no;
  62. $ip6_opt
  63. };
  64. zone "$DOMAIN" {
  65. type master;
  66. file "ltp-ns.zone";
  67. };
  68. zone "$net_rev.$ip_zone_opt.arpa" {
  69. type master;
  70. file "ltp-ns.rev";
  71. };
  72. EOD
  73. # zone file
  74. cat << EOD > ltp-ns.zone
  75. \$TTL 10
  76. @ IN SOA dns.$DOMAIN. root.$DOMAIN. (
  77. 2005092701 ; serial
  78. 3600 ; dummy value
  79. 900 ; dummy value
  80. 604800 ; dummy value
  81. 86400 ; dummy value
  82. )
  83. IN NS dns.$DOMAIN.
  84. EOD
  85. }
  86. setup_4()
  87. {
  88. printf "dns\tIN\tA\t$net.1\n" >> ltp-ns.zone
  89. local id=$MIN_ID
  90. while [ $id -le $MAX_ID ]; do
  91. printf "node$id\tIN\tA\t$net.$id\n" >> ltp-ns.zone
  92. id=$(($id + 1))
  93. done
  94. # reverse zone file
  95. cat << EOD > ltp-ns.rev
  96. \$TTL 10
  97. @ IN SOA $DOMAIN. root.$DOMAIN. (
  98. 2005092701 ; serial
  99. 3600 ; dummy value
  100. 900 ; dummy value
  101. 604800 ; dummy value
  102. 86400 ; dummy value
  103. )
  104. IN NS dns.$DOMAIN.
  105. EOD
  106. id=$MIN_ID
  107. while [ $id -le $MAX_ID ]; do
  108. printf "$id\tIN\tPTR\tnode$id.$DOMAIN.\n" >> ltp-ns.rev
  109. id=$(($id + 1))
  110. done
  111. }
  112. setup_6()
  113. {
  114. printf "dns\tIN\tAAAA\t$net::1\n" >> ltp-ns.zone
  115. local id=$MIN_ID
  116. while [ $id -le $MAX_ID ]; do
  117. printf "node$id\tIN\tAAAA\t$net::%x\n" $id >> ltp-ns.zone
  118. id=$(($id + 1))
  119. done
  120. # reverse zone file
  121. cat << EOD > ltp-ns.rev
  122. \$TTL 10
  123. @ IN SOA $DOMAIN. root.$DOMAIN. (
  124. 2005092701 ; serial
  125. 3600 ; dummy value
  126. 900 ; dummy value
  127. 604800 ; dummy value
  128. 86400 ; dummy value
  129. )
  130. IN NS dns.$DOMAIN.
  131. EOD
  132. id=$MIN_ID
  133. local rev_ip="0.0.0.0.0.0.0.0.0.0.0.0.0.0"
  134. while [ $id -le $MAX_ID ]; do
  135. printf "%x.%x.$rev_ip\tIN\tPTR\tnode$id.$DOMAIN.\n" \
  136. $(($id % 16)) $(($id / 16)) >> ltp-ns.rev
  137. id=$(($id + 1))
  138. done
  139. }
  140. start_named()
  141. {
  142. chmod 770 .
  143. chmod 660 ./*
  144. port=$(tst_get_unused_port ipv${TST_IPVER} dgram)
  145. tst_resm TINFO "Start named daemon, port $port"
  146. named -$TST_IPVER -c named.conf -p $port || \
  147. tst_brkm TBROK "Failed to run named daemon"
  148. # Make sure named.pid is created.
  149. while true ; do
  150. test -s named.pid && break
  151. tst_sleep 100ms
  152. done
  153. }
  154. test01()
  155. {
  156. tst_resm TINFO "Handling name lookup queries '$NS_TIMES' times"
  157. tst_rhost_run -s -c "dns-stress01-rmt.sh $TST_IPVER $(tst_ipaddr) $port \
  158. $DOMAIN $MIN_ID $MAX_ID $NS_TIMES"
  159. tst_resm TPASS "Test is finished successfully"
  160. }
  161. test02()
  162. {
  163. tst_resm TINFO "Handling reverse lookup queries '$NS_TIMES' times"
  164. tst_rhost_run -s -c "dns-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) $port $net \
  165. $MIN_ID $MAX_ID $NS_TIMES"
  166. tst_resm TPASS "Test is finished successfully"
  167. }
  168. common_setup
  169. setup_$TST_IPVER
  170. start_named
  171. test01
  172. test02
  173. tst_exit