PageRenderTime 40ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 149 lines | 85 code | 17 blank | 47 comment | 20 complexity | a7b280f9f6c693344273b36c4d1d4730 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) 2010, Oracle and/or its affiliates. All rights reserved.
  24. #
  25. #
  26. # Test sctp:::state-change and sctp:::{send,receive} by connecting to
  27. # the remote http service.
  28. # A number of state transition events along with sctp send and receive
  29. # events for the message should result.
  30. #
  31. # This may fail due to:
  32. #
  33. # 1. A change to the ip stack breaking expected probe behavior,
  34. # which is the reason we are testing.
  35. # 2. The lo0 interface missing or not up.
  36. # 3. The remote ssh service is not online.
  37. # 4. An unlikely race causes the unlocked global send/receive
  38. # variables to be corrupted.
  39. #
  40. # This test performs a SCTP association to the http service (port 80) and
  41. # checks that at least the following packet counts were traced:
  42. #
  43. # 4 x ip:::send (2 during setup, 2 during teardown)
  44. # 4 x sctp:::send (2 during setup, 2 during teardown)
  45. # 3 x ip:::receive (2 during setup, 1 during teardown)
  46. # 3 x sctp:::receive (2 during setup, 1 during teardown)
  47. #
  48. if (( $# != 1 )); then
  49. print -u2 "expected one argument: <dtrace-path>"
  50. exit 2
  51. fi
  52. dtrace=$1
  53. getaddr=./get.ipv4remote.pl
  54. sctpport=80
  55. DIR=/var/tmp/dtest.$$
  56. if [[ ! -x $getaddr ]]; then
  57. print -u2 "could not find or execute sub program: $getaddr"
  58. exit 3
  59. fi
  60. $getaddr $sctpport sctp | read source dest
  61. if (( $? != 0 )); then
  62. exit 4
  63. fi
  64. mkdir $DIR
  65. cd $DIR
  66. cat > test.pl <<-EOPERL
  67. use IO::Socket;
  68. my \$s = IO::Socket::INET->new(
  69. Type => SOCK_STREAM,
  70. Proto => "sctp",
  71. LocalAddr => "$source",
  72. PeerAddr => "$dest",
  73. PeerPort => $sctpport,
  74. Timeout => 3);
  75. die "Could not connect to host $dest port $sctpport \$@" unless \$s;
  76. close \$s;
  77. sleep(2);
  78. EOPERL
  79. $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
  80. BEGIN
  81. {
  82. ipsend = sctpsend = ipreceive = sctpreceive = 0;
  83. }
  84. ip:::send
  85. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
  86. args[4]->ipv4_protocol == IPPROTO_SCTP/
  87. {
  88. ipsend++;
  89. }
  90. sctp:::send
  91. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
  92. args[4]->sctp_dport == $sctpport/
  93. {
  94. sctpsend++;
  95. }
  96. ip:::receive
  97. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
  98. args[4]->ipv4_protocol == IPPROTO_SCTP/
  99. {
  100. ipreceive++;
  101. }
  102. sctp:::receive
  103. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
  104. args[4]->sctp_sport == $sctpport/
  105. {
  106. sctpreceive++;
  107. }
  108. sctp:::state-change
  109. {
  110. state_event[args[3]->sctps_state]++;
  111. }
  112. END
  113. {
  114. printf("Minimum SCTP events seen\n\n");
  115. printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
  116. printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no");
  117. printf("sctp:::send - %s\n", sctpsend >= 4 ? "yes" : "no");
  118. printf("sctp:::receive - %s\n", sctpreceive >= 3 ? "yes" : "no");
  119. printf("sctp:::state-change to cookie-wait - %s\n",
  120. state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no");
  121. printf("sctp:::state-change to cookie-echoed - %s\n",
  122. state_event[SCTP_STATE_COOKIE_ECHOED] >= 1 ? "yes" : "no");
  123. printf("sctp:::state-change to established - %s\n",
  124. state_event[SCTP_STATE_ESTABLISHED] >= 1 ? "yes" : "no");
  125. printf("sctp:::state-change to shutdown-sent - %s\n",
  126. state_event[SCTP_STATE_SHUTDOWN-SENT] >= 1 ? "yes" : "no");
  127. }
  128. EODTRACE
  129. status=$?
  130. cd /
  131. /bin/rm -rf $DIR
  132. exit $status