PageRenderTime 627ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 175 lines | 118 code | 8 blank | 49 comment | 4 complexity | 4dcf1de86ef8e4d318851a475c2a71d3 MD5 | raw file
  1. #!/usr/bin/env ksh
  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 local discard service.
  28. # A number of state transition events along with SCTP send and
  29. # receive 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. An unlikely race causes the unlocked global send/receive
  37. # variables to be corrupted.
  38. #
  39. # This test performs a SCTP connection and checks that at least the
  40. # following packet counts were traced:
  41. #
  42. # 7 x ip:::send (4 during the setup, 3 during the teardown)
  43. # 7 x sctp:::send (4 during the setup, 3 during the teardown)
  44. # 7 x ip:::receive (4 during the setup, 3 during the teardown)
  45. # 7 x sctp:::receive (4 during the setup, 3 during the teardown)
  46. #
  47. # The actual count tested is 7 each way, since we are tracing both
  48. # source and destination events.
  49. #
  50. if (( $# != 1 )); then
  51. print -u2 "expected one argument: <dtrace-path>"
  52. exit 2
  53. fi
  54. dtrace=$1
  55. local=127.0.0.1
  56. DIR=/var/tmp/dtest.$$
  57. sctpport=1024
  58. bound=5000
  59. mkdir $DIR
  60. cd $DIR
  61. cat > client.pl <<-EOPERL
  62. use IO::Socket;
  63. my \$s = IO::Socket::INET->new(
  64. Type => SOCK_STREAM,
  65. Proto => "sctp",
  66. LocalAddr => "$local",
  67. PeerAddr => "$local",
  68. PeerPort => \$ARGV[0],
  69. Timeout => 3);
  70. die "Could not connect to host $local port \$ARGV[0] \$@" unless \$s;
  71. close \$s;
  72. sleep(\$ARGV[1]);
  73. EOPERL
  74. while [ $sctpport -lt $bound ]; do
  75. perl client.pl $sctpport 0 2>&- || break
  76. sctpport=$(($sctpport + 1))
  77. done
  78. if [ $sctpport -eq $bound ]; then
  79. echo "couldn't find an available SCTP port"
  80. exit 1
  81. fi
  82. cat > server.pl <<-EOPERL
  83. use IO::Socket;
  84. my \$l = IO::Socket::INET->new(
  85. Type => SOCK_STREAM,
  86. Proto => "sctp",
  87. LocalAddr => "$local",
  88. LocalPort => $sctpport,
  89. Listen => 1,
  90. Reuse => 1);
  91. die "Could not listen on $local port $sctpport \$@" unless \$l;
  92. my \$c = \$l->accept();
  93. close \$l;
  94. while (<\$c>) {};
  95. close \$c;
  96. EOPERL
  97. perl server.pl &
  98. $dtrace -c "perl client.pl $sctpport 2" -qs /dev/stdin <<EODTRACE
  99. BEGIN
  100. {
  101. ipsend = sctpsend = ipreceive = sctpreceive = 0;
  102. }
  103. ip:::send
  104. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  105. args[4]->ipv4_protocol == IPPROTO_SCTP/
  106. {
  107. ipsend++;
  108. }
  109. sctp:::send
  110. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  111. (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
  112. {
  113. sctpsend++;
  114. }
  115. ip:::receive
  116. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  117. args[4]->ipv4_protocol == IPPROTO_SCTP/
  118. {
  119. ipreceive++;
  120. }
  121. sctp:::receive
  122. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  123. (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
  124. {
  125. sctpreceive++;
  126. }
  127. sctp:::state-change
  128. {
  129. state_event[args[3]->sctps_state]++;
  130. }
  131. END
  132. {
  133. printf("Minimum SCTP events seen\n\n");
  134. printf("ip:::send - %s\n", ipsend >= 7 ? "yes" : "no");
  135. printf("ip:::receive - %s\n", ipreceive >= 7 ? "yes" : "no");
  136. printf("sctp:::send - %s\n", sctpsend >= 7 ? "yes" : "no");
  137. printf("sctp:::receive - %s\n", sctpreceive >= 7 ? "yes" : "no");
  138. printf("sctp:::state-change to cookie-wait - %s\n",
  139. state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no");
  140. printf("sctp:::state-change to cookie-echoed - %s\n",
  141. state_event[SCTP_STATE_COOKIE_ECHOED] >=1 ? "yes" : "no");
  142. printf("sctp:::state-change to established - %s\n",
  143. state_event[SCTP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
  144. printf("sctp:::state-change to shutdown-sent - %s\n",
  145. state_event[SCTP_STATE_SHUTDOWN_SENT] >= 1 ? "yes" : "no");
  146. printf("sctp:::state-change to shutdown-received - %s\n",
  147. state_event[SCTP_STATE_SHUTDOWN_RECEIVED] >= 1 ? "yes" : "no");
  148. printf("sctp:::state-change to shutdown-ack-sent - %s\n",
  149. state_event[SCTP_STATE_SHUTDOWN_ACK_SENT] >= 1 ? "yes" : "no");
  150. }
  151. EODTRACE
  152. status=$?
  153. cd /
  154. /bin/rm -rf $DIR
  155. exit $status