1 /* $NetBSD: spray.c,v 1.5 1997/10/17 13:39:12 lukem Exp $ */
4 * Copyright (c) 1993 Winning Strategies, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Winning Strategies, Inc.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: spray.c,v 1.5 1997/10/17 13:39:12 lukem Exp $");
43 #include <rpcsvc/spray.h>
46 #define SPRAYOVERHEAD 86
49 int main
__P((int, char **));
50 void print_xferstats
__P((int, int, double));
51 void usage
__P((void));
54 char spray_buffer
[SPRAYMAX
];
57 struct timeval NO_DEFAULT
= { -1, -1 };
58 struct timeval ONE_WAY
= { 0, 0 };
59 struct timeval TIMEOUT
= { 25, 0 };
67 spraycumul host_stats
;
75 double xmit_time
; /* time to receive data */
78 while ((c
= getopt(argc
, argv
, "c:d:l:")) != -1) {
87 length
= atoi(optarg
);
103 /* Correct packet length. */
104 if (length
> SPRAYMAX
) {
106 } else if (length
< SPRAYOVERHEAD
) {
107 length
= SPRAYOVERHEAD
;
109 /* The RPC portion of the packet is a multiple of 32 bits. */
110 length
-= SPRAYOVERHEAD
- 3;
112 length
+= SPRAYOVERHEAD
;
117 * The default value of count is the number of packets required
118 * to make the total stream size 100000 bytes.
121 count
= 100000 / length
;
124 /* Initialize spray argument */
125 host_array
.sprayarr_len
= length
- SPRAYOVERHEAD
;
126 host_array
.sprayarr_val
= spray_buffer
;
129 /* create connection with server */
130 cl
= clnt_create(*argv
, SPRAYPROG
, SPRAYVERS
, "udp");
132 clnt_pcreateerror(progname
);
138 * For some strange reason, RPC 4.0 sets the default timeout,
139 * thus timeouts specified in clnt_call() are always ignored.
141 * The following (undocumented) hack resets the internal state
142 * of the client handle.
144 clnt_control(cl
, CLSET_TIMEOUT
, (caddr_t
)&NO_DEFAULT
);
147 /* Clear server statistics */
148 if (clnt_call(cl
, SPRAYPROC_CLEAR
, xdr_void
, NULL
, xdr_void
, NULL
, TIMEOUT
) != RPC_SUCCESS
) {
149 clnt_perror(cl
, progname
);
154 /* Spray server with packets */
155 printf ("sending %d packets of lnth %d to %s ...", count
, length
, *argv
);
158 for (i
= 0; i
< count
; i
++) {
159 clnt_call(cl
, SPRAYPROC_SPRAY
, xdr_sprayarr
, &host_array
, xdr_void
, NULL
, ONE_WAY
);
167 /* Collect statistics from server */
168 if (clnt_call(cl
, SPRAYPROC_GET
, xdr_void
, NULL
, xdr_spraycumul
, &host_stats
, TIMEOUT
) != RPC_SUCCESS
) {
169 clnt_perror(cl
, progname
);
173 xmit_time
= host_stats
.clock
.sec
+
174 (host_stats
.clock
.usec
/ 1000000.0);
176 printf ("\n\tin %.2f seconds elapsed time\n", xmit_time
);
179 /* report dropped packets */
180 if (host_stats
.counter
!= (unsigned)count
) {
181 int packets_dropped
= count
- host_stats
.counter
;
183 printf("\t%d packets (%.2f%%) dropped\n",
185 100.0 * packets_dropped
/ count
);
187 printf("\tno packets dropped\n");
191 print_xferstats(count
, length
, xmit_time
);
194 print_xferstats(host_stats
.counter
, length
, xmit_time
);
201 print_xferstats(packets
, packetlen
, xfertime
)
207 double pps
; /* packets per second */
208 double bps
; /* bytes per second */
210 datalen
= packets
* packetlen
;
211 pps
= packets
/ xfertime
;
212 bps
= datalen
/ xfertime
;
214 printf("\t%.0f packets/sec, ", pps
);
217 printf ("%.1fK ", bps
/ 1024);
219 printf ("%.0f ", bps
);
221 printf("bytes/sec\n");
228 fprintf(stderr
, "usage: spray [-c count] [-l length] [-d delay] host\n");