rtpw_test.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/sh
  2. #
  3. # usage: rtpw_test <rtpw_commands>
  4. #
  5. # tests the rtpw sender and receiver functions
  6. #
  7. # Copyright (c) 2001-2017, Cisco Systems, Inc.
  8. # All rights reserved.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. #
  14. # Redistributions of source code must retain the above copyright
  15. # notice, this list of conditions and the following disclaimer.
  16. #
  17. # Redistributions in binary form must reproduce the above
  18. # copyright notice, this list of conditions and the following
  19. # disclaimer in the documentation and/or other materials provided
  20. # with the distribution.
  21. #
  22. # Neither the name of the Cisco Systems, Inc. nor the names of its
  23. # contributors may be used to endorse or promote products derived
  24. # from this software without specific prior written permission.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  31. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  37. # OF THE POSSIBILITY OF SUCH DAMAGE.
  38. #
  39. case $(uname -s) in
  40. *CYGWIN*|*MINGW*)
  41. EXE=".exe"
  42. ;;
  43. *Linux*)
  44. EXE=""
  45. export LD_LIBRARY_PATH=$CRYPTO_LIBDIR
  46. ;;
  47. *Darwin*)
  48. EXE=""
  49. export DYLD_LIBRARY_PATH=$CRYPTO_LIBDIR
  50. ;;
  51. esac
  52. RTPW=./rtpw$EXE
  53. DEST_PORT=9999
  54. DURATION=3
  55. key=Ky7cUDT2GnI0XKWYbXv9AYmqbcLsqzL9mvdN9t/G
  56. ARGS="-b $key -a -e 128"
  57. # First, we run "killall" to get rid of all existing rtpw processes.
  58. # This step also enables this script to clean up after itself; if this
  59. # script is interrupted after the rtpw processes are started but before
  60. # they are killed, those processes will linger. Re-running the script
  61. # will get rid of them.
  62. killall rtpw 2>/dev/null
  63. if test -x $RTPW; then
  64. echo $0 ": starting rtpw receiver process... "
  65. $RTPW $* $ARGS -r 0.0.0.0 $DEST_PORT &
  66. receiver_pid=$!
  67. echo $0 ": receiver PID = $receiver_pid"
  68. sleep 1
  69. # verify that the background job is running
  70. ps -e | grep -q $receiver_pid
  71. retval=$?
  72. echo $retval
  73. if [ $retval != 0 ]; then
  74. echo $0 ": error"
  75. exit 254
  76. fi
  77. echo $0 ": starting rtpw sender process..."
  78. $RTPW $* $ARGS -s 127.0.0.1 $DEST_PORT &
  79. sender_pid=$!
  80. echo $0 ": sender PID = $sender_pid"
  81. # verify that the background job is running
  82. ps -e | grep -q $sender_pid
  83. retval=$?
  84. echo $retval
  85. if [ $retval != 0 ]; then
  86. echo $0 ": error"
  87. exit 255
  88. fi
  89. sleep $DURATION
  90. kill $receiver_pid
  91. kill $sender_pid
  92. wait $receiver_pid 2>/dev/null
  93. wait $sender_pid 2>/dev/null
  94. key=033490ba9e82994fc21013395739038992b2edc5034f61a72345ca598d7bfd0189aa6dc2ecab32fd9af74df6dfc6
  95. ARGS="-k $key -a -e 256"
  96. echo $0 ": starting rtpw receiver process... "
  97. $RTPW $* $ARGS -r 0.0.0.0 $DEST_PORT &
  98. receiver_pid=$!
  99. echo $0 ": receiver PID = $receiver_pid"
  100. sleep 1
  101. # verify that the background job is running
  102. ps -e | grep -q $receiver_pid
  103. retval=$?
  104. echo $retval
  105. if [ $retval != 0 ]; then
  106. echo $0 ": error"
  107. exit 254
  108. fi
  109. echo $0 ": starting rtpw sender process..."
  110. $RTPW $* $ARGS -s 127.0.0.1 $DEST_PORT &
  111. sender_pid=$!
  112. echo $0 ": sender PID = $sender_pid"
  113. # verify that the background job is running
  114. ps -e | grep -q $sender_pid
  115. retval=$?
  116. echo $retval
  117. if [ $retval != 0 ]; then
  118. echo $0 ": error"
  119. exit 255
  120. fi
  121. sleep $DURATION
  122. kill $receiver_pid
  123. kill $sender_pid
  124. wait $receiver_pid 2>/dev/null
  125. wait $sender_pid 2>/dev/null
  126. echo $0 ": done (test passed)"
  127. else
  128. echo "error: can't find executable" $RTPW
  129. exit 1
  130. fi
  131. # EOF