PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 153 lines | 99 code | 9 blank | 45 comment | 4 complexity | 50a305e2482442050aaca1ff14009729 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24. #
  25. #
  26. # Test {ip,sctp}:::{send,receive} of IPv4 SCTP to local 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. The lo0 interface missing or not up.
  33. # 3. An unlikely race causes the unlocked global send/receive
  34. # variables to be corrupted.
  35. #
  36. # This test performs a SCTP association and checks that at least the
  37. # following packet counts were traced:
  38. #
  39. # 7 x ip:::send (4 during the setup, 3 during the teardown)
  40. # 7 x sctp:::send (4 during the setup, 3 during the teardown)
  41. # 7 x ip:::receive (4 during the setup, 3 during the teardown)
  42. # 7 x sctp:::receive (4 during the setup, 3 during the teardown)
  43. # The actual count tested is 7 each way, since we are tracing both
  44. # source and destination events.
  45. #
  46. if (( $# != 1 )); then
  47. print -u2 "expected one argument: <dtrace-path>"
  48. exit 2
  49. fi
  50. dtrace=$1
  51. local=127.0.0.1
  52. DIR=/var/tmp/dtest.$$
  53. sctpport=1024
  54. bound=5000
  55. mkdir $DIR
  56. cd $DIR
  57. cat > client.pl <<-EOPERL
  58. use IO::Socket;
  59. my \$s = IO::Socket::INET->new(
  60. Type => SOCK_STREAM,
  61. Proto => "sctp",
  62. LocalAddr => "$local",
  63. PeerAddr => "$local",
  64. PeerPort => \$ARGV[0],
  65. Timeout => 3);
  66. die "Could not connect to host $local port \$ARGV[0] \$@" unless \$s;
  67. close \$s;
  68. sleep(\$ARGV[1]);
  69. EOPERL
  70. while [ $sctpport -lt $bound ]; do
  71. perl client.pl $sctpport 0 2>&- || break
  72. sctpport=$(($sctpport + 1))
  73. done
  74. if [ $sctpport -eq $bound ]; then
  75. echo "couldn't find an available SCTP port"
  76. exit 1
  77. fi
  78. cat > server.pl <<-EOPERL
  79. use IO::Socket;
  80. my \$l = IO::Socket::INET->new(
  81. Type => SOCK_STREAM,
  82. Proto => "sctp",
  83. LocalAddr => "$local",
  84. LocalPort => $sctpport,
  85. Listen => 1,
  86. Reuse => 1);
  87. die "Could not listen on $local port $sctpport \$@" unless \$l;
  88. my \$c = \$l->accept();
  89. close \$l;
  90. while (<\$c>) {};
  91. close \$c;
  92. EOPERL
  93. perl server.pl &
  94. $dtrace -c "perl client.pl $sctpport 2" -qs /dev/stdin <<EODTRACE
  95. BEGIN
  96. {
  97. ipsend = sctpsend = ipreceive = sctpreceive = 0;
  98. }
  99. ip:::send
  100. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  101. args[4]->ipv4_protocol == IPPROTO_SCTP/
  102. {
  103. ipsend++;
  104. }
  105. sctp:::send
  106. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
  107. {
  108. sctpsend++;
  109. }
  110. ip:::receive
  111. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
  112. args[4]->ipv4_protocol == IPPROTO_SCTP/
  113. {
  114. ipreceive++;
  115. }
  116. sctp:::receive
  117. /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
  118. {
  119. sctpreceive++;
  120. }
  121. END
  122. {
  123. printf("Minimum SCTP events seen\n\n");
  124. printf("ip:::send - %s\n", ipsend >= 7 ? "yes" : "no");
  125. printf("ip:::receive - %s\n", ipreceive >= 7 ? "yes" : "no");
  126. printf("sctp:::send - %s\n", sctpsend >= 7 ? "yes" : "no");
  127. printf("sctp:::receive - %s\n", sctpreceive >= 7 ? "yes" : "no");
  128. }
  129. EODTRACE
  130. status=$?
  131. cd /
  132. /bin/rm -rf $DIR
  133. exit $status