]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/ip/tst.ipv4remotesctp.ksh
MFV r357712: file 5.38.
[FreeBSD/FreeBSD.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / ip / tst.ipv4remotesctp.ksh
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 #
24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 #
26
27 #
28 # Test {sctp,ip}:::{send,receive} of IPv4 SCTP to a remote host.
29 #
30 # This may fail due to:
31 #
32 # 1. A change to the ip stack breaking expected probe behavior,
33 #    which is the reason we are testing.
34 # 2. No physical network interface is plumbed and up.
35 # 3. No other hosts on this subnet are reachable and listening on ssh.
36 # 4. An unlikely race causes the unlocked global send/receive
37 #    variables to be corrupted.
38 #
39 # This test performs an SCTP association and checks that at least the
40 # following packet counts were traced:
41 #
42 # 4 x ip:::send (2 during setup, 2 during teardown)
43 # 4 x sctp:::send (2 during connection setup, 2 during connection teardown)
44 # 3 x ip:::receive (2 during setup, 1 during  teardown)
45 # 3 x sctp:::receive (2 during setup, 1 during  teardown)
46
47 if (( $# != 1 )); then
48         print -u2 "expected one argument: <dtrace-path>"
49         exit 2
50 fi
51
52 dtrace=$1
53 getaddr=./get.ipv4remote.pl
54 sctpport=80
55 DIR=/var/tmp/dtest.$$
56
57 if [[ ! -x $getaddr ]]; then
58         print -u2 "could not find or execute sub program: $getaddr"
59         exit 3
60 fi
61 $getaddr $sctpport sctp | read source dest
62 if (( $? != 0 )); then
63         exit 4
64 fi
65
66 mkdir $DIR
67 cd $DIR
68
69 cat > test.pl <<-EOPERL
70         use IO::Socket;
71         my \$s = IO::Socket::INET->new(
72             Type => SOCK_STREAM,
73             Proto => "sctp",
74             LocalAddr => "$source",
75             PeerAddr => "$dest",
76             PeerPort => $sctpport,
77             Timeout => 3);
78         die "Could not connect to host $dest port $sctpport \$@" unless \$s;
79         close \$s;
80         sleep(2);
81 EOPERL
82
83 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
84 BEGIN
85 {
86         ipsend = sctpsend = ipreceive = sctpreceive = 0;
87 }
88
89 ip:::send
90 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" &&
91     args[4]->ipv4_protocol == IPPROTO_SCTP/
92 {
93         ipsend++;
94 }
95
96 sctp:::send
97 /args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest"/
98 {
99         sctpsend++;
100 }
101
102 ip:::receive
103 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" &&
104     args[4]->ipv4_protocol == IPPROTO_SCTP/
105 {
106         ipreceive++;
107 }
108
109 sctp:::receive
110 /args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source"/
111 {
112         sctpreceive++;
113 }
114
115 END
116 {
117         printf("Minimum SCTP events seen\n\n");
118         printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no");
119         printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no");
120         printf("sctp:::send - %s\n", sctpsend >= 4 ? "yes" : "no");
121         printf("sctp:::receive - %s\n", sctpreceive >= 3 ? "yes" : "no");
122 }
123 EODTRACE
124
125 status=$?
126
127 cd /
128 /bin/rm -rf $DIR
129
130 exit $status