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>"
64 while [ $sctpport -lt $bound ]; do
65 ncat --sctp -z $local $sctpport > /dev/null || break
66 sctpport=$(($sctpport + 1))
68 if [ $sctpport -eq $bound ]; then
69 echo "couldn't find an available SCTP port"
76 # ncat will exit when the association is closed.
77 ncat --sctp --listen $local $sctpport &
79 cat > test.pl <<-EOPERL
81 my \$s = IO::Socket::INET->new(
84 LocalAddr => "$local",
86 PeerPort => $sctpport,
88 die "Could not connect to host $local port $sctpport \$@" unless \$s;
93 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
96 ipsend = sctpsend = ipreceive = sctpreceive = 0;
100 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
101 args[4]->ipv4_protocol == IPPROTO_SCTP/
107 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
108 (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
114 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
115 args[4]->ipv4_protocol == IPPROTO_SCTP/
121 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
122 (args[4]->sctp_sport == $sctpport || args[4]->sctp_dport == $sctpport)/
129 state_event[args[3]->sctps_state]++;
134 printf("Minimum SCTP events seen\n\n");
135 printf("ip:::send - %s\n", ipsend >= 7 ? "yes" : "no");
136 printf("ip:::receive - %s\n", ipreceive >= 7 ? "yes" : "no");
137 printf("sctp:::send - %s\n", sctpsend >= 7 ? "yes" : "no");
138 printf("sctp:::receive - %s\n", sctpreceive >= 7 ? "yes" : "no");
139 printf("sctp:::state-change to cookie-wait - %s\n",
140 state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no");
141 printf("sctp:::state-change to cookie-echoed - %s\n",
142 state_event[SCTP_STATE_COOKIE_ECHOED] >=1 ? "yes" : "no");
143 printf("sctp:::state-change to established - %s\n",
144 state_event[SCTP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
145 printf("sctp:::state-change to shutdown-sent - %s\n",
146 state_event[SCTP_STATE_SHUTDOWN_SENT] >= 1 ? "yes" : "no");
147 printf("sctp:::state-change to shutdown-received - %s\n",
148 state_event[SCTP_STATE_SHUTDOWN_RECEIVED] >= 1 ? "yes" : "no");
149 printf("sctp:::state-change to shutdown-ack-sent - %s\n",
150 state_event[SCTP_STATE_SHUTDOWN_ACK_SENT] >= 1 ? "yes" : "no");