11e88cc8bSMichael Tuexen#!/usr/bin/env ksh93 21e88cc8bSMichael Tuexen# 31e88cc8bSMichael Tuexen# CDDL HEADER START 41e88cc8bSMichael Tuexen# 51e88cc8bSMichael Tuexen# The contents of this file are subject to the terms of the 61e88cc8bSMichael Tuexen# Common Development and Distribution License (the "License"). 71e88cc8bSMichael Tuexen# You may not use this file except in compliance with the License. 81e88cc8bSMichael Tuexen# 91e88cc8bSMichael Tuexen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 101e88cc8bSMichael Tuexen# or http://www.opensolaris.org/os/licensing. 111e88cc8bSMichael Tuexen# See the License for the specific language governing permissions 121e88cc8bSMichael Tuexen# and limitations under the License. 131e88cc8bSMichael Tuexen# 141e88cc8bSMichael Tuexen# When distributing Covered Code, include this CDDL HEADER in each 151e88cc8bSMichael Tuexen# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 161e88cc8bSMichael Tuexen# If applicable, add the following below this CDDL HEADER, with the 171e88cc8bSMichael Tuexen# fields enclosed by brackets "[]" replaced with your own identifying 181e88cc8bSMichael Tuexen# information: Portions Copyright [yyyy] [name of copyright owner] 191e88cc8bSMichael Tuexen# 201e88cc8bSMichael Tuexen# CDDL HEADER END 211e88cc8bSMichael Tuexen# 221e88cc8bSMichael Tuexen 231e88cc8bSMichael Tuexen# 241e88cc8bSMichael Tuexen# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 251e88cc8bSMichael Tuexen# 261e88cc8bSMichael Tuexen 271e88cc8bSMichael Tuexen# 281e88cc8bSMichael Tuexen# Test sctp:::state-change and sctp:::{send,receive} by connecting to 291e88cc8bSMichael Tuexen# the remote http service. 301e88cc8bSMichael Tuexen# A number of state transition events along with sctp send and receive 311e88cc8bSMichael Tuexen# events for the message should result. 321e88cc8bSMichael Tuexen# 331e88cc8bSMichael Tuexen# This may fail due to: 341e88cc8bSMichael Tuexen# 351e88cc8bSMichael Tuexen# 1. A change to the ip stack breaking expected probe behavior, 361e88cc8bSMichael Tuexen# which is the reason we are testing. 371e88cc8bSMichael Tuexen# 2. The lo0 interface missing or not up. 381e88cc8bSMichael Tuexen# 3. The remote ssh service is not online. 391e88cc8bSMichael Tuexen# 4. An unlikely race causes the unlocked global send/receive 401e88cc8bSMichael Tuexen# variables to be corrupted. 411e88cc8bSMichael Tuexen# 421e88cc8bSMichael Tuexen# This test performs a SCTP association to the http service (port 80) and 431e88cc8bSMichael Tuexen# checks that at least the following packet counts were traced: 441e88cc8bSMichael Tuexen# 451e88cc8bSMichael Tuexen# 4 x ip:::send (2 during setup, 2 during teardown) 461e88cc8bSMichael Tuexen# 4 x sctp:::send (2 during setup, 2 during teardown) 471e88cc8bSMichael Tuexen# 3 x ip:::receive (2 during setup, 1 during teardown) 481e88cc8bSMichael Tuexen# 3 x sctp:::receive (2 during setup, 1 during teardown) 491e88cc8bSMichael Tuexen# 501e88cc8bSMichael Tuexen 511e88cc8bSMichael Tuexenif (( $# != 1 )); then 521e88cc8bSMichael Tuexen print -u2 "expected one argument: <dtrace-path>" 531e88cc8bSMichael Tuexen exit 2 541e88cc8bSMichael Tuexenfi 551e88cc8bSMichael Tuexen 561e88cc8bSMichael Tuexendtrace=$1 571e88cc8bSMichael Tuexengetaddr=./get.ipv4remote.pl 581e88cc8bSMichael Tuexensctpport=80 591e88cc8bSMichael TuexenDIR=/var/tmp/dtest.$$ 601e88cc8bSMichael Tuexen 611e88cc8bSMichael Tuexenif [[ ! -x $getaddr ]]; then 621e88cc8bSMichael Tuexen print -u2 "could not find or execute sub program: $getaddr" 631e88cc8bSMichael Tuexen exit 3 641e88cc8bSMichael Tuexenfi 651e88cc8bSMichael Tuexen$getaddr $sctpport sctp | read source dest 661e88cc8bSMichael Tuexenif (( $? != 0 )); then 671e88cc8bSMichael Tuexen exit 4 681e88cc8bSMichael Tuexenfi 691e88cc8bSMichael Tuexen 701e88cc8bSMichael Tuexenmkdir $DIR 711e88cc8bSMichael Tuexencd $DIR 721e88cc8bSMichael Tuexen 731e88cc8bSMichael Tuexencat > test.pl <<-EOPERL 741e88cc8bSMichael Tuexen use IO::Socket; 751e88cc8bSMichael Tuexen my \$s = IO::Socket::INET->new( 761e88cc8bSMichael Tuexen Type => SOCK_STREAM, 771e88cc8bSMichael Tuexen Proto => "sctp", 781e88cc8bSMichael Tuexen LocalAddr => "$source", 791e88cc8bSMichael Tuexen PeerAddr => "$dest", 801e88cc8bSMichael Tuexen PeerPort => $sctpport, 811e88cc8bSMichael Tuexen Timeout => 3); 821e88cc8bSMichael Tuexen die "Could not connect to host $dest port $sctpport \$@" unless \$s; 831e88cc8bSMichael Tuexen close \$s; 841e88cc8bSMichael Tuexen sleep(2); 851e88cc8bSMichael TuexenEOPERL 861e88cc8bSMichael Tuexen 871e88cc8bSMichael Tuexen$dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE 881e88cc8bSMichael TuexenBEGIN 891e88cc8bSMichael Tuexen{ 901e88cc8bSMichael Tuexen ipsend = sctpsend = ipreceive = sctpreceive = 0; 911e88cc8bSMichael Tuexen} 921e88cc8bSMichael Tuexen 931e88cc8bSMichael Tuexenip:::send 941e88cc8bSMichael Tuexen/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 951e88cc8bSMichael Tuexen args[4]->ipv4_protocol == IPPROTO_SCTP/ 961e88cc8bSMichael Tuexen{ 971e88cc8bSMichael Tuexen ipsend++; 981e88cc8bSMichael Tuexen} 991e88cc8bSMichael Tuexen 1001e88cc8bSMichael Tuexensctp:::send 1011e88cc8bSMichael Tuexen/args[2]->ip_saddr == "$source" && args[2]->ip_daddr == "$dest" && 1021e88cc8bSMichael Tuexen args[4]->sctp_dport == $sctpport/ 1031e88cc8bSMichael Tuexen{ 1041e88cc8bSMichael Tuexen sctpsend++; 1051e88cc8bSMichael Tuexen} 1061e88cc8bSMichael Tuexen 1071e88cc8bSMichael Tuexenip:::receive 1081e88cc8bSMichael Tuexen/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 1091e88cc8bSMichael Tuexen args[4]->ipv4_protocol == IPPROTO_SCTP/ 1101e88cc8bSMichael Tuexen{ 1111e88cc8bSMichael Tuexen ipreceive++; 1121e88cc8bSMichael Tuexen} 1131e88cc8bSMichael Tuexen 1141e88cc8bSMichael Tuexensctp:::receive 1151e88cc8bSMichael Tuexen/args[2]->ip_saddr == "$dest" && args[2]->ip_daddr == "$source" && 1161e88cc8bSMichael Tuexen args[4]->sctp_sport == $sctpport/ 1171e88cc8bSMichael Tuexen{ 1181e88cc8bSMichael Tuexen sctpreceive++; 1191e88cc8bSMichael Tuexen} 1201e88cc8bSMichael Tuexen 1211e88cc8bSMichael Tuexensctp:::state-change 1221e88cc8bSMichael Tuexen{ 1231e88cc8bSMichael Tuexen state_event[args[3]->sctps_state]++; 1241e88cc8bSMichael Tuexen} 1251e88cc8bSMichael Tuexen 1261e88cc8bSMichael TuexenEND 1271e88cc8bSMichael Tuexen{ 1281e88cc8bSMichael Tuexen printf("Minimum SCTP events seen\n\n"); 1291e88cc8bSMichael Tuexen printf("ip:::send - %s\n", ipsend >= 4 ? "yes" : "no"); 1301e88cc8bSMichael Tuexen printf("ip:::receive - %s\n", ipreceive >= 3 ? "yes" : "no"); 1311e88cc8bSMichael Tuexen printf("sctp:::send - %s\n", sctpsend >= 4 ? "yes" : "no"); 1321e88cc8bSMichael Tuexen printf("sctp:::receive - %s\n", sctpreceive >= 3 ? "yes" : "no"); 1331e88cc8bSMichael Tuexen printf("sctp:::state-change to cookie-wait - %s\n", 1341e88cc8bSMichael Tuexen state_event[SCTP_STATE_COOKIE_WAIT] >=1 ? "yes" : "no"); 1351e88cc8bSMichael Tuexen printf("sctp:::state-change to cookie-echoed - %s\n", 1361e88cc8bSMichael Tuexen state_event[SCTP_STATE_COOKIE_ECHOED] >= 1 ? "yes" : "no"); 1371e88cc8bSMichael Tuexen printf("sctp:::state-change to established - %s\n", 1381e88cc8bSMichael Tuexen state_event[SCTP_STATE_ESTABLISHED] >= 1 ? "yes" : "no"); 1391e88cc8bSMichael Tuexen printf("sctp:::state-change to shutdown-sent - %s\n", 1401e88cc8bSMichael Tuexen state_event[SCTP_STATE_SHUTDOWN-SENT] >= 1 ? "yes" : "no"); 1411e88cc8bSMichael Tuexen} 1421e88cc8bSMichael TuexenEODTRACE 1431e88cc8bSMichael Tuexen 1441e88cc8bSMichael Tuexenstatus=$? 1451e88cc8bSMichael Tuexen 1461e88cc8bSMichael Tuexencd / 1471e88cc8bSMichael Tuexen/bin/rm -rf $DIR 1481e88cc8bSMichael Tuexen 1491e88cc8bSMichael Tuexenexit $status 150