PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 131 lines | 70 code | 16 blank | 45 comment | 18 complexity | 05fcce605f566862e4d262f44c9b44b8 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 {tcp,ip}:::{send,receive} of IPv4 TCP 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 a TCP connection and checks that at least the
  38. # following packet counts were traced:
  39. #
  40. # 4 x ip:::send (2 during connection setup, 2 during connection teardown)
  41. # 4 x tcp:::send (2 during connection setup, 2 during connection teardown)
  42. # 5 x ip:::receive (1 during connection setup, the response, 1 window update,
  43. # 1 banner line, 2 during connection teardown)
  44. # 5 x tcp:::receive (1 during connection setup, the response, 1 window update,
  45. # 1 banner line, 2 during connection teardown)
  46. if (( $# != 1 )); then
  47. print -u2 "expected one argument: <dtrace-path>"
  48. exit 2
  49. fi
  50. dtrace=$1
  51. getaddr=./get.ipv4remote.pl
  52. tcpport=22
  53. DIR=/var/tmp/dtest.$$
  54. if [[ ! -x $getaddr ]]; then
  55. print -u2 "could not find or execute sub program: $getaddr"
  56. exit 3
  57. fi
  58. $getaddr $tcpport | read source dest
  59. if (( $? != 0 )); then
  60. exit 4
  61. fi
  62. mkdir $DIR
  63. cd $DIR
  64. cat > test.pl <<-EOPERL
  65. use IO::Socket;
  66. my \$s = IO::Socket::INET->new(
  67. Proto => "tcp",
  68. PeerAddr => "$dest",
  69. PeerPort => $tcpport,
  70. Timeout => 3);
  71. die "Could not connect to host $dest port $tcpport" unless \$s;
  72. readline \$s;
  73. close \$s;
  74. sleep(2);
  75. EOPERL
  76. $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
  77. BEGIN
  78. {
  79. ipsend = tcpsend = ipreceive = tcpreceive = 0;
  80. }
  81. ip:::send
  82. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
  83. args[4]->ipv4_protocol == IPPROTO_TCP/
  84. {
  85. ipsend++;
  86. }
  87. tcp:::send
  88. /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/
  89. {
  90. tcpsend++;
  91. }
  92. ip:::receive
  93. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
  94. args[4]->ipv4_protocol == IPPROTO_TCP/
  95. {
  96. ipreceive++;
  97. }
  98. tcp:::receive
  99. /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/
  100. {
  101. tcpreceive++;
  102. }
  103. END
  104. {
  105. printf("Minimum TCP events seen\n\n");
  106. printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
  107. printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
  108. printf("tcp:::send - %s\n", tcpsend >= 4 ? "yes" : "no");
  109. printf("tcp:::receive - %s\n", tcpreceive >= 5 ? "yes" : "no");
  110. }
  111. EODTRACE
  112. status=$?
  113. cd /
  114. /bin/rm -rf $DIR
  115. exit $status