mc_commo.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) International Business Machines Corp., 2000
  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. # TEST DESCRIPTION:
  20. # To verify that IP Multicast can be used to send UDP datagrams
  21. # between two or more nodes on the same subnetwork using
  22. # a specific IP Multicast group and a specific port address.
  23. #
  24. # Authors:
  25. # Robbie Williamson (robbiew@us.ibm.com)
  26. # Michael Reed mreedltp@vnet.ibm.com
  27. TTL=10
  28. OUTFILE=mc_commo_out
  29. TCID=mc_commo
  30. TST_TOTAL=2
  31. TST_USE_LEGACY_API=1
  32. . tst_net.sh
  33. do_setup()
  34. {
  35. tst_require_cmds netstat pgrep
  36. OCTET=$(ps -ewf | grep [m]c_commo | wc -l | awk '{print $1}')
  37. GROUP_ADDR=224.0.0.$OCTET
  38. PORT=$(tst_get_unused_port ipv4 dgram)
  39. tst_tmpdir
  40. }
  41. do_test()
  42. {
  43. # Run setsockopt/getsockopt test
  44. # Start up the recv on local host
  45. tst_resm TINFO "Start mc_recv $GROUP_ADDR $(tst_ipaddr) $PORT"
  46. mc_recv $GROUP_ADDR $(tst_ipaddr) $PORT >> $OUTFILE &
  47. SERVER_PID=$!
  48. sleep 5
  49. pgrep -x mc_recv > /dev/null || \
  50. tst_brkm TFAIL "Could NOT start mc_recv on $(tst_ipaddr)"
  51. grep -q "cannot join group" $OUTFILE && \
  52. tst_brkm TFAIL "Membership NOT set"
  53. netstat -ng | grep -q $GROUP_ADDR || \
  54. tst_brkm TFAIL "membership not set for $GROUP_ADDR"
  55. tst_resm TINFO "Start on $RHOST mc_send $GROUP_ADDR" \
  56. "$(tst_ipaddr rhost) $PORT $TTL"
  57. tst_rhost_run -b -c "mc_send $GROUP_ADDR $(tst_ipaddr rhost) $PORT $TTL"
  58. sleep 10
  59. tst_rhost_run -s -c "pgrep -x mc_send > /dev/null"
  60. tst_resm TINFO "Waiting for 100 sec.! Do not interrupt."
  61. sleep 100 #wait until datagrams are received in $STATUS
  62. #test if datagrams has been sent
  63. grep -q "$(tst_ipaddr rhost) [0-9] [0-9]" $OUTFILE || \
  64. tst_brkm TFAIL "NO Datagrams received from $RHOST"
  65. tst_resm TPASS "Test Successful"
  66. }
  67. do_cleanup()
  68. {
  69. ps -p $SERVER_PID > /dev/null 2>&1
  70. if [ $? -eq 0 ]; then
  71. kill -9 $SERVER_PID
  72. fi
  73. tst_rmdir
  74. }
  75. do_setup
  76. TST_CLEANUP=do_cleanup
  77. for i in $(seq 1 $TST_TOTAL); do
  78. do_test
  79. done
  80. tst_exit