1*2be1a816SJohn Birrell# 2*2be1a816SJohn Birrell# CDDL HEADER START 3*2be1a816SJohn Birrell# 4*2be1a816SJohn Birrell# The contents of this file are subject to the terms of the 5*2be1a816SJohn Birrell# Common Development and Distribution License (the "License"). 6*2be1a816SJohn Birrell# You may not use this file except in compliance with the License. 7*2be1a816SJohn Birrell# 8*2be1a816SJohn Birrell# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*2be1a816SJohn Birrell# or http://www.opensolaris.org/os/licensing. 10*2be1a816SJohn Birrell# See the License for the specific language governing permissions 11*2be1a816SJohn Birrell# and limitations under the License. 12*2be1a816SJohn Birrell# 13*2be1a816SJohn Birrell# When distributing Covered Code, include this CDDL HEADER in each 14*2be1a816SJohn Birrell# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*2be1a816SJohn Birrell# If applicable, add the following below this CDDL HEADER, with the 16*2be1a816SJohn Birrell# fields enclosed by brackets "[]" replaced with your own identifying 17*2be1a816SJohn Birrell# information: Portions Copyright [yyyy] [name of copyright owner] 18*2be1a816SJohn Birrell# 19*2be1a816SJohn Birrell# CDDL HEADER END 20*2be1a816SJohn Birrell# 21*2be1a816SJohn Birrell 22*2be1a816SJohn Birrell# 23*2be1a816SJohn Birrell# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*2be1a816SJohn Birrell# Use is subject to license terms. 25*2be1a816SJohn Birrell# 26*2be1a816SJohn Birrell# ident "%Z%%M% %I% %E% SMI" 27*2be1a816SJohn Birrell 28*2be1a816SJohn Birrell# 29*2be1a816SJohn Birrell# This script tests that several of the the mib:::tcp* probes fire and fire 30*2be1a816SJohn Birrell# with a valid args[0]. 31*2be1a816SJohn Birrell# 32*2be1a816SJohn Birrell 33*2be1a816SJohn Birrellif [ $# != 1 ]; then 34*2be1a816SJohn Birrell echo expected one argument: '<'dtrace-path'>' 35*2be1a816SJohn Birrell exit 2 36*2be1a816SJohn Birrellfi 37*2be1a816SJohn Birrell 38*2be1a816SJohn Birrelldtrace=$1 39*2be1a816SJohn Birrelldtraceout=/tmp/dtrace.out.$$ 40*2be1a816SJohn Birrelltimeout=15 41*2be1a816SJohn Birrellport=2000 42*2be1a816SJohn Birrell 43*2be1a816SJohn Birrellif [ -f $dtraceout ]; then 44*2be1a816SJohn Birrell rm -f $dtraceout 45*2be1a816SJohn Birrellfi 46*2be1a816SJohn Birrell 47*2be1a816SJohn Birrellscript() 48*2be1a816SJohn Birrell{ 49*2be1a816SJohn Birrell $dtrace -o $dtraceout -s /dev/stdin <<EOF 50*2be1a816SJohn Birrell mib:::tcpActiveOpens 51*2be1a816SJohn Birrell { 52*2be1a816SJohn Birrell opens = args[0]; 53*2be1a816SJohn Birrell } 54*2be1a816SJohn Birrell 55*2be1a816SJohn Birrell mib:::tcpOutDataBytes 56*2be1a816SJohn Birrell { 57*2be1a816SJohn Birrell bytes = args[0]; 58*2be1a816SJohn Birrell } 59*2be1a816SJohn Birrell 60*2be1a816SJohn Birrell mib:::tcpOutDataSegs 61*2be1a816SJohn Birrell { 62*2be1a816SJohn Birrell segs = args[0]; 63*2be1a816SJohn Birrell } 64*2be1a816SJohn Birrell 65*2be1a816SJohn Birrell profile:::tick-10msec 66*2be1a816SJohn Birrell /opens && bytes && segs/ 67*2be1a816SJohn Birrell { 68*2be1a816SJohn Birrell exit(0); 69*2be1a816SJohn Birrell } 70*2be1a816SJohn Birrell 71*2be1a816SJohn Birrell profile:::tick-1s 72*2be1a816SJohn Birrell /n++ >= 10/ 73*2be1a816SJohn Birrell { 74*2be1a816SJohn Birrell exit(1); 75*2be1a816SJohn Birrell } 76*2be1a816SJohn BirrellEOF 77*2be1a816SJohn Birrell} 78*2be1a816SJohn Birrell 79*2be1a816SJohn Birrellserver() 80*2be1a816SJohn Birrell{ 81*2be1a816SJohn Birrell perl /dev/stdin /dev/stdout << EOF 82*2be1a816SJohn Birrell use strict; 83*2be1a816SJohn Birrell use Socket; 84*2be1a816SJohn Birrell 85*2be1a816SJohn Birrell socket(S, AF_INET, SOCK_STREAM, getprotobyname('tcp')) 86*2be1a816SJohn Birrell or die "socket() failed: \$!"; 87*2be1a816SJohn Birrell 88*2be1a816SJohn Birrell setsockopt(S, SOL_SOCKET, SO_REUSEADDR, 1) 89*2be1a816SJohn Birrell or die "setsockopt() failed: \$!"; 90*2be1a816SJohn Birrell 91*2be1a816SJohn Birrell my \$addr = sockaddr_in($port, INADDR_ANY); 92*2be1a816SJohn Birrell bind(S, \$addr) or die "bind() failed: \$!"; 93*2be1a816SJohn Birrell listen(S, SOMAXCONN) or die "listen() failed: \$!"; 94*2be1a816SJohn Birrell 95*2be1a816SJohn Birrell while (1) { 96*2be1a816SJohn Birrell next unless my \$raddr = accept(SESSION, S); 97*2be1a816SJohn Birrell 98*2be1a816SJohn Birrell while (<SESSION>) { 99*2be1a816SJohn Birrell } 100*2be1a816SJohn Birrell 101*2be1a816SJohn Birrell close SESSION; 102*2be1a816SJohn Birrell } 103*2be1a816SJohn BirrellEOF 104*2be1a816SJohn Birrell} 105*2be1a816SJohn Birrell 106*2be1a816SJohn Birrellclient() 107*2be1a816SJohn Birrell{ 108*2be1a816SJohn Birrell perl /dev/stdin /dev/stdout <<EOF 109*2be1a816SJohn Birrell use strict; 110*2be1a816SJohn Birrell use Socket; 111*2be1a816SJohn Birrell 112*2be1a816SJohn Birrell my \$peer = sockaddr_in($port, INADDR_ANY); 113*2be1a816SJohn Birrell 114*2be1a816SJohn Birrell socket(S, AF_INET, SOCK_STREAM, getprotobyname('tcp')) 115*2be1a816SJohn Birrell or die "socket() failed: \$!"; 116*2be1a816SJohn Birrell 117*2be1a816SJohn Birrell connect(S, \$peer) or die "connect failed: \$!"; 118*2be1a816SJohn Birrell 119*2be1a816SJohn Birrell for (my \$i = 0; \$i < 10; \$i++) { 120*2be1a816SJohn Birrell send(S, "There!", 0) or die "send() failed: \$!"; 121*2be1a816SJohn Birrell sleep (1); 122*2be1a816SJohn Birrell } 123*2be1a816SJohn BirrellEOF 124*2be1a816SJohn Birrell} 125*2be1a816SJohn Birrell 126*2be1a816SJohn Birrellscript & 127*2be1a816SJohn Birrelldtrace_pid=$! 128*2be1a816SJohn Birrell 129*2be1a816SJohn Birrell# 130*2be1a816SJohn Birrell# Sleep while the above script fires into life. To guard against dtrace dying 131*2be1a816SJohn Birrell# and us sleeping forever we allow 15 secs for this to happen. This should be 132*2be1a816SJohn Birrell# enough for even the slowest systems. 133*2be1a816SJohn Birrell# 134*2be1a816SJohn Birrellwhile [ ! -f $dtraceout ]; do 135*2be1a816SJohn Birrell sleep 1 136*2be1a816SJohn Birrell timeout=$(($timeout-1)) 137*2be1a816SJohn Birrell if [ $timeout -eq 0 ]; then 138*2be1a816SJohn Birrell echo "dtrace failed to start. Exiting." 139*2be1a816SJohn Birrell exit 1 140*2be1a816SJohn Birrell fi 141*2be1a816SJohn Birrelldone 142*2be1a816SJohn Birrell 143*2be1a816SJohn Birrellserver & 144*2be1a816SJohn Birrellserver_pid=$! 145*2be1a816SJohn Birrellsleep 2 146*2be1a816SJohn Birrellclient & 147*2be1a816SJohn Birrellclient_pid=$! 148*2be1a816SJohn Birrell 149*2be1a816SJohn Birrellwait $dtrace_pid 150*2be1a816SJohn Birrellstatus=$? 151*2be1a816SJohn Birrell 152*2be1a816SJohn Birrellkill $server_pid 153*2be1a816SJohn Birrellkill $client_pid 154*2be1a816SJohn Birrell 155*2be1a816SJohn Birrellexit $status 156