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.
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.
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]
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
28 # Test sctp:::state-change and sctp:::{send,receive} by connecting to
29 # the local discard service.
30 # A number of state transition events along with SCTP send and
31 # receive events for the message should result.
33 # This may fail due to:
35 # 1. A change to the ip stack breaking expected probe behavior,
36 # which is the reason we are testing.
37 # 2. The lo0 interface missing or not up.
38 # 3. An unlikely race causes the unlocked global send/receive
39 # variables to be corrupted.
41 # This test performs a SCTP connection and checks that at least the
42 # following packet counts were traced:
44 # 7 x ip:::send (4 during the setup, 3 during the teardown)
45 # 7 x sctp:::send (4 during the setup, 3 during the teardown)
46 # 7 x ip:::receive (4 during the setup, 3 during the teardown)
47 # 7 x sctp:::receive (4 during the setup, 3 during the teardown)
49 # The actual count tested is 7 each way, since we are tracing both
50 # source and destination events.
53 if (( $# != 1 )); then
54 print -u2 "expected one argument: <dtrace-path>"
68 cat > client.pl <<-EOPERL
70 my \$s = IO::Socket::INET->new(
73 LocalAddr => "$local",
75 PeerPort => \$ARGV[0],
77 die "Could not connect to host $local port \$ARGV[0] \$@" unless \$s;
82 while [ $sctpport -lt $bound ]; do
83 perl client.pl $sctpport 0 2>&- || break
84 sctpport=$(($sctpport + 1))
86 if [ $sctpport -eq $bound ]; then
87 echo "couldn't find an available SCTP port"
91 cat > server.pl <<-EOPERL
93 my \$l = IO::Socket::INET->new(
96 LocalAddr => "$local",
97 LocalPort => $sctpport,
100 die "Could not listen on $local port $sctpport \$@" unless \$l;
101 my \$c = \$l->accept();
109 $dtrace -c "perl client.pl $sctpport 2" -qs /dev/stdin <<EODTRACE
112 ipsend = sctpsend = ipreceive = sctpreceive = 0;
116 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
117 args[4]->ipv4_protocol == IPPROTO_SCTP/
123 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
124 (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
130 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
131 args[4]->ipv4_protocol == IPPROTO_SCTP/
137 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
138 (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
145 state_event[args[3]->sctps_state]++;
150 printf("Minimum SCTP events seen\n\n");
151 printf("ip:::send - %s\n", ipsend >= 7 ? "yes" : "no");
152 printf("ip:::receive - %s\n", ipreceive >= 7 ? "yes" : "no");
153 printf("sctp:::send - %s\n", sctpsend >= 7 ? "yes" : "no");
154 printf("sctp:::receive - %s\n", sctpreceive >= 7 ? "yes" : "no");
155 printf("sctp:::state-change to cookie-wait - %s\n",
156 state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no");
157 printf("sctp:::state-change to cookie-echoed - %s\n",
158 state_event[SCTP_STATE_COOKIE_ECHOED] >=1 ? "yes" : "no");
159 printf("sctp:::state-change to established - %s\n",
160 state_event[SCTP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
161 printf("sctp:::state-change to shutdown-sent - %s\n",
162 state_event[SCTP_STATE_SHUTDOWN_SENT] >= 1 ? "yes" : "no");
163 printf("sctp:::state-change to shutdown-received - %s\n",
164 state_event[SCTP_STATE_SHUTDOWN_RECEIVED] >= 1 ? "yes" : "no");
165 printf("sctp:::state-change to shutdown-ack-sent - %s\n",
166 state_event[SCTP_STATE_SHUTDOWN_ACK_SENT] >= 1 ? "yes" : "no");