ssh-stress03-rmt.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. # Copyright (c) 2015 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. #
  21. TCID="ssh_stress03_rmt"
  22. TST_TOTAL=1
  23. . test.sh
  24. # Check the arguments
  25. if [ $# -ne 5 ]; then
  26. tst_brkm TBROK "Usage: $0 ipver rhost config port requests"
  27. fi
  28. ip_ver="$1"
  29. server_ipaddr="$2"
  30. ssh_config="$3"
  31. rport="$4"
  32. requests="$5"
  33. ssh -$ip_ver -F $ssh_config $server_ipaddr \
  34. "true < /dev/null > /dev/null 2>&1" > /dev/null
  35. [ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
  36. lport=$(tst_get_unused_port ipv${ip_ver} stream)
  37. # Set the ssh port-forwarding
  38. case $ip_ver in
  39. 4)
  40. localhost="127.0.0.1"
  41. ssh -4 -f -N -L $lport:$server_ipaddr:$rport \
  42. root@$server_ipaddr -F $ssh_config
  43. ;;
  44. 6)
  45. localhost="::1"
  46. ssh -6 -f -N -L $lport:[$server_ipaddr]:$rport \
  47. root@$server_ipaddr -F $ssh_config
  48. ;;
  49. esac
  50. # Start the TCP traffic clients
  51. netstress -r $requests -l -H $localhost -g $lport > /dev/null
  52. ret=$?
  53. # Stop the ssh port forwarding
  54. all_conn=$(ps auxw | grep -Fv grep | \
  55. grep "ssh[[:blank:]].*${ssh_config}" | awk '{print $2}')
  56. for ssh_pid in $all_conn ; do
  57. kill $ssh_pid
  58. done
  59. [ $ret -ne 0 ] && tst_brkm TBROK "TCP traffic client is dead"
  60. # Check the connectivity again
  61. ssh -$ip_ver -F $ssh_config $server_ipaddr \
  62. "true < /dev/null > /dev/null 2>&1" > /dev/null
  63. [ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
  64. tst_exit