client-test 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/sh
  2. #
  3. # $Id: client-test,v 1.2 2006/02/13 23:50:44 quozl Exp $
  4. #
  5. # client-test, PPTP lab test script
  6. # Copyright (C) 2005 James Cameron (quozl@us.netrek.org)
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. #
  22. # --
  23. #
  24. # Creates many tunnels from a test client to a single server.
  25. # Test sequence is as follows
  26. #
  27. # 1. on server ... set it to listen on chosen network address
  28. # ip addr add 10.9.0.3/16 dev eth0
  29. # and edit /etc/hosts.allow to cover range "ALL: 10.9.0.0/16"
  30. #
  31. # 2. on client ... run pptpconfig to define a tunnel named test
  32. #
  33. # 3. run "./client-test start" to create the tunnels
  34. #
  35. # 4. run "./client-test status" to test the tunnels with ping
  36. #
  37. # 5. run "./client-test stop" to stop the tunnels
  38. #
  39. # number of sets of tunnels to create
  40. MAX_C=10
  41. # number of tunnels in each set
  42. MAX_D=100
  43. # network address prefix for test network
  44. PREFIX=10.9
  45. # address of server on test network
  46. SERVER=10.9.0.3
  47. # create a virtual interface for the address
  48. function if_up {
  49. ip addr add ${PREFIX}.${2}.${3}/16 dev eth0 && echo -n .
  50. }
  51. # delete the virtual interface
  52. function if_down {
  53. ip addr del ${PREFIX}.${2}.${3}/16 dev eth0 2>/dev/null && echo -n .
  54. # expected error on 2.6.8 ...
  55. # RTNETLINK answers: Cannot assign requested address
  56. }
  57. # create a tunnel from the virtual interface to the server
  58. function tu_up {
  59. pppd call test updetach linkname test-${1} \
  60. pty "pptp ${SERVER} --nolaunchpppd --localbind=${PREFIX}.${2}.${3}"
  61. }
  62. # create a tunnel from the virtual interface to the server
  63. function tu_up_fast {
  64. pppd call test linkname test-${1} \
  65. pty "pptp ${SERVER} --nolaunchpppd --localbind=${PREFIX}.${2}.${3}"
  66. echo -n .
  67. sleep 0.1
  68. }
  69. # delete a tunnel previously created
  70. function tu_down {
  71. if test -f /var/run/ppp-test-${1}.pid; then
  72. kill `head -1 /var/run/ppp-test-${1}.pid` && echo -n .
  73. fi
  74. }
  75. # start tunnels rapidly and fill up available memory until swap free
  76. # starts to be scarce
  77. function filler {
  78. if_up $1 $2 $3
  79. tu_up_fast $1 $2 $3
  80. swapfree=`grep SwapFree /proc/meminfo |awk '{print $2}'`
  81. until test ${swapfree} -gt 4096; do
  82. echo -n -
  83. sleep 1
  84. done
  85. }
  86. # check the state of a tunnel slot
  87. function state {
  88. echo -n "slot ${1} "
  89. if ! test -f /var/run/ppp-test-${1}.pid; then
  90. echo -n "(missing) "
  91. else
  92. pid=`head -1 /var/run/ppp-test-${1}.pid`
  93. echo -n "pid ${pid} "
  94. if ! kill -0 ${pid} 2>/dev/null; then
  95. echo -n "(missing) "
  96. fi
  97. iface=`tail -1 /var/run/ppp-test-${1}.pid`
  98. echo -n "iface ${iface} "
  99. if ! ip addr show dev ${iface} 1>/dev/null 2>/dev/null; then
  100. echo -n "(missing) "
  101. fi
  102. inet=`ip addr show dev ${iface}|egrep --only-matching "inet [0-9.]*"|awk '{print $2}'`
  103. echo -n "inet ${inet} "
  104. peer=`ip addr show dev ${iface}|egrep --only-matching "peer [0-9.]*"|awk '{print $2}'`
  105. echo -n "peer ${peer} "
  106. avg=`/bin/ping -c 1 ${peer} 2>/dev/null | grep "rtt min" | cut -f6 -d/`
  107. if test -z "${avg}"; then
  108. echo -n "ping (missing) "
  109. else
  110. echo -n "ping ${avg} "
  111. fi
  112. fi
  113. echo
  114. }
  115. # general purpose iteration function to call a handler (above) once
  116. # for each slot in the test set. Handler receives slot number, then
  117. # the fragments of IP address a.b.C.D.
  118. function iterate {
  119. x=1
  120. for c in `seq ${MAX_C}`; do
  121. for d in `seq ${MAX_D}`; do
  122. ${1} ${x} ${c} ${d}
  123. x=`expr ${x} + 1`
  124. done
  125. done
  126. }
  127. # start the test
  128. function start {
  129. iterate if_up
  130. echo
  131. iterate tu_up
  132. echo
  133. }
  134. # start slow test
  135. function fill {
  136. iterate filler
  137. echo
  138. }
  139. # stop the test
  140. function stop {
  141. iterate tu_down
  142. echo
  143. sleep 10
  144. iterate if_down
  145. echo
  146. }
  147. # check status of test
  148. function status {
  149. iterate state
  150. }
  151. # main dispatcher
  152. case "$1" in
  153. start)
  154. start
  155. break
  156. ;;
  157. fill)
  158. fill
  159. break
  160. ;;
  161. stop)
  162. stop
  163. break
  164. ;;
  165. restart)
  166. stop
  167. start
  168. break
  169. ;;
  170. status)
  171. status
  172. break
  173. ;;
  174. *)
  175. echo "Usage: ${0} start|fill|stop|restart|status" 1>&2
  176. exit 1
  177. ;;
  178. esac