/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/ip/tst.ipv4remotesctp.ksh

https://bitbucket.org/freebsd/freebsd-base · Korn Shell · 130 lines · 71 code · 16 blank · 43 comment · 18 complexity · 9f6298d11da14d67424e6d2d217c5635 MD5 · raw file

  1. #!/usr/bin/env ksh93
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. #
  23. # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24. #
  25. #
  26. # Test {sctp,ip}:::{send,receive} of IPv4 SCTP to a remote host.
  27. #
  28. # This may fail due to:
  29. #
  30. # 1. A change to the ip stack breaking expected probe behavior,
  31. # which is the reason we are testing.
  32. # 2. No physical network interface is plumbed and up.
  33. # 3. No other hosts on this subnet are reachable and listening on ssh.
  34. # 4. An unlikely race causes the unlocked global send/receive
  35. # variables to be corrupted.
  36. #
  37. # This test performs an SCTP association and checks that at least the
  38. # following packet counts were traced:
  39. #
  40. # 4 x ip:::send (2 during setup, 2 during teardown)
  41. # 4 x sctp:::send (2 during connection setup, 2 during connection teardown)
  42. # 3 x ip:::receive (2 during setup, 1 during teardown)
  43. # 3 x sctp:::receive (2 during setup, 1 during teardown)
  44. if (( $# != 1 )); then
  45. print -u2 "expected one argument: <dtrace-path>"
  46. exit 2
  47. fi
  48. dtrace=$1
  49. getaddr=./get.ipv4remote.pl
  50. sctpport=80
  51. DIR=/var/tmp/dtest.$$
  52. if [[ ! -x $getaddr ]]; then
  53. print -u2 "could not find or execute sub program: $getaddr"
  54. exit 3
  55. fi
  56. $getaddr $sctpport sctp | read source dest
  57. if (( $? != 0 )); then
  58. exit 4
  59. fi
  60. mkdir $DIR
  61. cd $DIR
  62. cat > test.pl <<-EOPERL
  63. use IO::Socket;
  64. my \$s = IO::Socket::INET->new(
  65. Type => SOCK_STREAM,
  66. Proto => "sctp",
  67. LocalAddr => "$source",
  68. PeerAddr => "$dest",
  69. PeerPort => $sctpport,
  70. Timeout => 3);
  71. die "Could not connect to host $dest port $sctpport \$@" unless \$s;
  72. close \$s;
  73. sleep(2);
  74. EOPERL
  75. $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
  76. BEGIN
  77. {
  78. ipsend = sctpsend = ipreceive = sctpreceive = 0;
  79. }
  80. ip:::send
  81. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
  82. args[4]->ipv4_protocol == IPPROTO_SCTP/
  83. {
  84. ipsend++;
  85. }
  86. sctp:::send
  87. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/
  88. {
  89. sctpsend++;
  90. }
  91. ip:::receive
  92. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
  93. args[4]->ipv4_protocol == IPPROTO_SCTP/
  94. {
  95. ipreceive++;
  96. }
  97. sctp:::receive
  98. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/
  99. {
  100. sctpreceive++;
  101. }
  102. END
  103. {
  104. printf("Minimum SCTP events seen\n\n");
  105. printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
  106. printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no");
  107. printf("sctp:::send - %s\n", sctpsend >= 4 ? "yes" : "no");
  108. printf("sctp:::receive - %s\n", sctpreceive >= 3 ? "yes" : "no");
  109. }
  110. EODTRACE
  111. status=$?
  112. cd /
  113. /bin/rm -rf $DIR
  114. exit $status