1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * Copyright 1985 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 29*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 30*7c478bd9Sstevel@tonic-gate * All Rights Reserved 31*7c478bd9Sstevel@tonic-gate * 32*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 33*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 34*7c478bd9Sstevel@tonic-gate * contributors. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 40*7c478bd9Sstevel@tonic-gate #include <stdio.h> 41*7c478bd9Sstevel@tonic-gate #include <ctype.h> 42*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 43*7c478bd9Sstevel@tonic-gate #include <rpcsvc/spray.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/poll.h> 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate enum clnt_stat sprayproc_spray_1nd(/*argp, clnt*/); 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define DEFBYTES 100000 /* default numbers of bytes to send */ 49*7c478bd9Sstevel@tonic-gate #define MAXPACKETLEN 1514 50*7c478bd9Sstevel@tonic-gate #define SPRAYOVERHEAD 86 /* size of rpc packet when size=0 */ 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate main(argc, argv) 53*7c478bd9Sstevel@tonic-gate int argc; 54*7c478bd9Sstevel@tonic-gate char **argv; 55*7c478bd9Sstevel@tonic-gate { 56*7c478bd9Sstevel@tonic-gate int c; 57*7c478bd9Sstevel@tonic-gate extern char *optarg; 58*7c478bd9Sstevel@tonic-gate extern int optind; 59*7c478bd9Sstevel@tonic-gate register CLIENT *clnt; 60*7c478bd9Sstevel@tonic-gate unsigned int i; 61*7c478bd9Sstevel@tonic-gate int delay = 0; 62*7c478bd9Sstevel@tonic-gate unsigned int psec, bsec; 63*7c478bd9Sstevel@tonic-gate int buf[SPRAYMAX/4]; 64*7c478bd9Sstevel@tonic-gate char msgbuf[256]; 65*7c478bd9Sstevel@tonic-gate unsigned int lnth, cnt; 66*7c478bd9Sstevel@tonic-gate sprayarr arr; 67*7c478bd9Sstevel@tonic-gate spraycumul cumul; 68*7c478bd9Sstevel@tonic-gate spraycumul *co; 69*7c478bd9Sstevel@tonic-gate char *host = NULL; 70*7c478bd9Sstevel@tonic-gate char *type; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate if (argc < 2) 73*7c478bd9Sstevel@tonic-gate usage(); 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate cnt = 0; 76*7c478bd9Sstevel@tonic-gate lnth = SPRAYOVERHEAD; 77*7c478bd9Sstevel@tonic-gate type = "netpath"; 78*7c478bd9Sstevel@tonic-gate while (optind < argc) { 79*7c478bd9Sstevel@tonic-gate if (argv[optind][0] == '-') { 80*7c478bd9Sstevel@tonic-gate if ((c = getopt(argc, argv, "d:c:t:l:")) == EOF) { 81*7c478bd9Sstevel@tonic-gate break; 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate switch (c) { 84*7c478bd9Sstevel@tonic-gate case 'd': 85*7c478bd9Sstevel@tonic-gate delay = atoi(optarg); 86*7c478bd9Sstevel@tonic-gate break; 87*7c478bd9Sstevel@tonic-gate case 'c': 88*7c478bd9Sstevel@tonic-gate cnt = (unsigned int) atoi(optarg); 89*7c478bd9Sstevel@tonic-gate break; 90*7c478bd9Sstevel@tonic-gate case 't': 91*7c478bd9Sstevel@tonic-gate type = optarg; 92*7c478bd9Sstevel@tonic-gate break; 93*7c478bd9Sstevel@tonic-gate case 'l': 94*7c478bd9Sstevel@tonic-gate lnth = (unsigned int) atoi(optarg); 95*7c478bd9Sstevel@tonic-gate break; 96*7c478bd9Sstevel@tonic-gate default: 97*7c478bd9Sstevel@tonic-gate usage(); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate } else { 100*7c478bd9Sstevel@tonic-gate host = argv[optind++]; 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate if (host == NULL) 104*7c478bd9Sstevel@tonic-gate usage(); 105*7c478bd9Sstevel@tonic-gate clnt = clnt_create(host, SPRAYPROG, SPRAYVERS, type); 106*7c478bd9Sstevel@tonic-gate if (clnt == (CLIENT *)NULL) { 107*7c478bd9Sstevel@tonic-gate sprintf(msgbuf, "spray: cannot clnt_create %s:%s", host, type); 108*7c478bd9Sstevel@tonic-gate clnt_pcreateerror(msgbuf); 109*7c478bd9Sstevel@tonic-gate exit(1); 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate if (cnt == 0) 112*7c478bd9Sstevel@tonic-gate cnt = DEFBYTES/lnth; 113*7c478bd9Sstevel@tonic-gate if (lnth < SPRAYOVERHEAD) 114*7c478bd9Sstevel@tonic-gate lnth = SPRAYOVERHEAD; 115*7c478bd9Sstevel@tonic-gate else if (lnth >= SPRAYMAX) 116*7c478bd9Sstevel@tonic-gate lnth = SPRAYMAX; 117*7c478bd9Sstevel@tonic-gate if (lnth <= MAXPACKETLEN && lnth % 4 != 2) 118*7c478bd9Sstevel@tonic-gate lnth = ((lnth + 5) / 4) * 4 - 2; 119*7c478bd9Sstevel@tonic-gate arr.sprayarr_len = lnth - SPRAYOVERHEAD; 120*7c478bd9Sstevel@tonic-gate arr.sprayarr_val = (char *) buf; 121*7c478bd9Sstevel@tonic-gate printf("sending %u packets of length %u to %s ...", cnt, lnth, host); 122*7c478bd9Sstevel@tonic-gate fflush(stdout); 123*7c478bd9Sstevel@tonic-gate if (sprayproc_clear_1(NULL, clnt) == NULL) { 124*7c478bd9Sstevel@tonic-gate clnt_perror(clnt, "SPRAYPROC_CLEAR "); 125*7c478bd9Sstevel@tonic-gate exit(1); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate for (i = 0; i < cnt; i++) { 128*7c478bd9Sstevel@tonic-gate sprayproc_spray_1nd(&arr, clnt); 129*7c478bd9Sstevel@tonic-gate if (delay > 0) 130*7c478bd9Sstevel@tonic-gate slp(delay); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate if ((co = sprayproc_get_1(NULL, clnt)) == NULL) { 133*7c478bd9Sstevel@tonic-gate clnt_perror(clnt, "SPRAYPROC_GET "); 134*7c478bd9Sstevel@tonic-gate exit(1); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate cumul = *co; 137*7c478bd9Sstevel@tonic-gate if (cumul.counter < cnt) 138*7c478bd9Sstevel@tonic-gate printf("\n\t%d packets (%.3f%%) dropped by %s\n", 139*7c478bd9Sstevel@tonic-gate cnt - cumul.counter, 140*7c478bd9Sstevel@tonic-gate 100.0 * (cnt - cumul.counter)/cnt, host); 141*7c478bd9Sstevel@tonic-gate else 142*7c478bd9Sstevel@tonic-gate printf("\n\tno packets dropped by %s\n", host); 143*7c478bd9Sstevel@tonic-gate psec = (1000000.0 * cumul.counter) 144*7c478bd9Sstevel@tonic-gate / (1000000.0 * cumul.clock.sec + cumul.clock.usec); 145*7c478bd9Sstevel@tonic-gate bsec = (lnth * 1000000.0 * cumul.counter)/ 146*7c478bd9Sstevel@tonic-gate (1000000.0 * cumul.clock.sec + cumul.clock.usec); 147*7c478bd9Sstevel@tonic-gate printf("\t%u packets/sec, %u bytes/sec\n", psec, bsec); 148*7c478bd9Sstevel@tonic-gate exit(0); 149*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* 153*7c478bd9Sstevel@tonic-gate * A special call, where the TIMEOUT is 0. So, every call times-out. 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate static struct timeval TIMEOUT = { 0, 0 }; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate enum clnt_stat 158*7c478bd9Sstevel@tonic-gate sprayproc_spray_1nd(argp, clnt) 159*7c478bd9Sstevel@tonic-gate sprayarr *argp; 160*7c478bd9Sstevel@tonic-gate CLIENT *clnt; 161*7c478bd9Sstevel@tonic-gate { 162*7c478bd9Sstevel@tonic-gate return (clnt_call(clnt, SPRAYPROC_SPRAY, xdr_sprayarr, (caddr_t)argp, 163*7c478bd9Sstevel@tonic-gate xdr_void, NULL, TIMEOUT)); 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate /* A cheap milliseconds sleep call */ 167*7c478bd9Sstevel@tonic-gate slp(usecs) 168*7c478bd9Sstevel@tonic-gate { 169*7c478bd9Sstevel@tonic-gate static struct pollfd pfds[1] = { 170*7c478bd9Sstevel@tonic-gate 0, POLLIN, 0 171*7c478bd9Sstevel@tonic-gate }; 172*7c478bd9Sstevel@tonic-gate pfds[0].fd = fileno(stdout); 173*7c478bd9Sstevel@tonic-gate poll(pfds, 1, usecs/1000); 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate usage() 177*7c478bd9Sstevel@tonic-gate { 178*7c478bd9Sstevel@tonic-gate printf("spray host [-t nettype] [-l lnth] [-c cnt] [-d delay]\n"); 179*7c478bd9Sstevel@tonic-gate exit(1); 180*7c478bd9Sstevel@tonic-gate } 181