2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Client test program */
12 #include <afsconfig.h>
13 #include <afs/param.h>
17 #include <sys/types.h>
25 #include <netinet/in.h>
33 #include "rx_globals.h"
36 #include <afs/afsutil.h>
39 #define osi_Alloc(n) (char *) malloc(n)
43 int print = 1, eventlog = 0, rxlog = 0;
45 int burst; struct clock burstTime;
46 struct clock retryTime;
47 extern int rx_initSendWindow, rx_initReceiveWindow;
48 extern int rxi_nSendFrags, rxi_nRecvFrags;
49 extern rx_intentionallyDroppedPacketsPer100;
50 extern int (*rxi_syscallp)();
53 struct clock waitTime, computeTime;
57 void intSignal(int ignore) {
61 void quitSignal(int ignore) {
62 static int quitCount = 0;
63 if (++quitCount > 1) Quit("rx_ctest: second quit signal, aborting");
64 rx_debugFile = debugFile = fopen("rx_ctest.db", "w");
65 if (debugFile) rx_PrintStats(debugFile);
68 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
69 int test_syscall(a3, a4, a5)
76 old = signal(SIGSYS, SIG_IGN);
77 rcode = syscall (31 /* AFS_SYSCALL */, 28 /* AFSCALL_CALL */, a3, a4, a5);
88 struct hostent *hostent;
91 struct rx_connection *conn;
94 int nCalls = 1, nBytes = 1;
95 int bufferSize = 2000;
100 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
102 rxi_syscallp = test_syscall;
107 while (argc && **argv == '-') {
108 if (strcmp(*argv, "-silent") == 0) print = 0;
109 else if (strcmp(*argv, "-nc") == 0) nCalls = atoi(*++argv), argc--;
110 else if (strcmp(*argv, "-nb") == 0) nBytes = atoi(*++argv), argc--;
111 else if (strcmp(*argv, "-npb") == 0) rx_nPackets = atoi(*++argv), argc--;
112 else if (!strcmp(*argv, "-nsf"))
113 rxi_nSendFrags = atoi(*++argv), argc--;
114 else if (!strcmp(*argv, "-nrf"))
115 rxi_nRecvFrags = atoi(*++argv), argc--;
116 else if (strcmp(*argv, "-twind") == 0)
117 rx_initSendWindow = atoi(*++argv), argc--;
118 else if (strcmp(*argv, "-rwind") == 0)
119 rx_initReceiveWindow = atoi(*++argv), argc--;
120 else if (strcmp(*argv, "-rxlog") == 0) rxlog = 1;
121 else if (strcmp(*argv, "-logstdout") == 0) logstdout = 1;
122 else if (strcmp(*argv, "-eventlog") == 0) eventlog = 1;
123 else if (strcmp(*argv, "-drop") == 0) rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
124 else if (strcmp(*argv, "-burst") == 0) {
125 burst = atoi(*++argv), argc--;
126 burstTime.sec = atoi(*++argv), argc--;
127 burstTime.usec = atoi(*++argv), argc--;
129 else if (strcmp(*argv, "-retry") == 0) {
130 retryTime.sec = atoi(*++argv), argc--;
131 retryTime.usec = atoi(*++argv), argc--;
133 else if (strcmp(*argv, "-timeout") == 0) timeout = atoi(*++argv), argc--;
134 else if (strcmp(*argv, "-fill") == 0) fillPackets++;
135 else if (strcmp(*argv, "-file") == 0) sendFile = *++argv, argc--;
136 else if (strcmp(*argv, "-timereadvs") == 0) timeReadvs = 1;
137 else if (strcmp(*argv, "-wait") == 0) {
138 /* Wait time between calls--to test lastack code */
139 waitTime.sec = atoi(*++argv), argc--;
140 waitTime.usec = atoi(*++argv), argc--;
142 else if (strcmp(*argv, "-compute") == 0) {
143 /* Simulated "compute" time for each call--to test acknowledgement protocol. This is simulated by doing an iomgr_select: imperfect, admittedly. */
144 computeTime.sec = atoi(*++argv), argc--;
145 computeTime.usec = atoi(*++argv), argc--;
147 else if (strcmp(*argv, "-fd") == 0) {
148 /* Open at least this many fd's. */
149 setFD = atoi(*++argv), argc--;
151 else {err = 1;break;}
154 if (err || argc != 1)
155 Quit("usage: rx_ctest [-silent] [-rxlog] [-eventlog] [-nc NCALLS] [-np NPACKETS] hostname");
156 hostname = *argv++, argc--;
158 if (rxlog || eventlog) {
159 if (logstdout) debugFile = stdout;
160 else debugFile = fopen("rx_ctest.db", "w");
161 if (debugFile == NULL) Quit("Couldn't open rx_ctest.db");
162 if (rxlog) rx_debugFile = debugFile;
163 if (eventlog) rxevent_debugFile = debugFile;
166 signal(SIGINT, intSignal);/*Changed to sigquit since dbx is broken right now */
168 signal(SIGQUIT, quitSignal);
172 if (afs_winsockInit()<0) {
173 printf("Can't initialize winsock.\n");
178 hostent = gethostbyname(hostname);
179 if (!hostent) Abort("host %s not found", hostname);
180 if (hostent->h_length != 4)
181 Abort("host address is disagreeable length (%d)", hostent->h_length);
182 memcpy((char *)&host, hostent->h_addr, sizeof(host));
185 if (rx_Init(0) != 0) {
186 printf("RX failed to initialize, exiting.\n");
190 printf("rx_socket=%d\n", rx_socket);
193 printf("Using %d packet buffers\n", rx_nPackets);
195 conn = rx_NewConnection(host, htons(2500), 3, rxnull_NewClientSecurityObject(), 0);
197 if (!conn) Abort("unable to make a new connection");
199 /* Set initial parameters. This is (currently) not the approved interface */
200 if (burst) conn->peer->burstSize = conn->peer->burst = burst;
201 if (!clock_IsZero(&burstTime)) conn->peer->burstWait = burstTime;
202 if (!clock_IsZero(&retryTime)) conn->peer->timeout = retryTime;
204 if (sendFile) SendFile(sendFile, conn);
206 buffer = (char *) osi_Alloc(bufferSize);
208 struct clock startTime;
214 call = rx_NewCall(conn);
215 if (!call) Abort("unable to make a new call");
217 clock_GetTime(&startTime);
218 for (bytesSent = 0; bytesSent < nBytes; bytesSent += nSent) {
220 tryCount = (bufferSize > nBytes - bytesSent)? nBytes - bytesSent: bufferSize;
221 nSent = rx_Write(call, buffer, tryCount);
222 if (nSent == 0) break;
225 for (bytesRead = 0; nbytes = rx_Read(call, buffer, bufferSize); bytesRead += nbytes) {};
226 if (print) printf("Received %d characters in response\n", bytesRead);
227 err = rx_EndCall(call, 0);
228 if (err) printf("Error %d returned from rpc call\n", err);
230 struct clock totalTime;
232 clock_GetTime(&totalTime);
233 clock_Sub(&totalTime, &startTime);
234 elapsedTime = clock_Float(&totalTime);
235 fprintf(stderr, "Sent %d bytes in %0.3f seconds: %0.0f bytes per second\n",
236 bytesSent, elapsedTime, bytesSent/elapsedTime);
238 if (!clock_IsZero(&computeTime)) {
239 t.tv_sec = computeTime.sec;
240 t.tv_usec = computeTime.usec;
241 if (select(0, 0, 0, 0, &t) != 0) Quit("Select didn't return 0");
243 if (!clock_IsZero(&waitTime)) {
245 t.tv_sec = waitTime.sec;
246 t.tv_usec = waitTime.usec;
247 #ifdef AFS_PTHREAD_ENV
250 IOMGR_Sleep(t.tv_sec);
254 if (debugFile) rx_PrintPeerStats(debugFile, rx_PeerOf(conn));
255 rx_PrintPeerStats(stdout, rx_PeerOf(conn));
257 Quit("testclient: done!\n");
262 struct rx_connection *conn;
264 struct rx_call *call;
267 int blockSize, bytesLeft;
271 struct clock startTime;
272 int receivedStore = 0;
273 struct clock totalReadvDelay;
277 #include <sys/statfs.h>
278 struct statfs tstatfs;
283 clock_Zero(&totalReadvDelay);
285 fd = open(file, O_RDONLY, 0);
286 if (fd < 0) Abort("Couldn't open %s\n", file);
292 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the stat structure!! */
293 fstatfs(fd, &tstatfs);
294 blockSize = tstatfs.f_bsize;
296 blockSize = status.st_blksize;
299 buf = (char *) osi_Alloc(blockSize);
300 bytesLeft = status.st_size;
301 clock_GetTime(&startTime);
302 call = rx_NewCall(conn);
304 if (!receivedStore && rx_GetRemoteStatus(call) == 79) {
306 fprintf(stderr, "Remote status indicates file accepted (\"received store\")\n");
308 nbytes = (bytesLeft > blockSize? blockSize: bytesLeft);
310 code = read(fd, buf, nbytes);
311 if (code != nbytes) {
312 Abort("Only read %d bytes of %d, errno=%d\n", code, nbytes, errno);
314 code = rx_Write(call, buf, nbytes);
315 if (code != nbytes) {
316 Abort("Only wrote %d bytes of %d\n", code, nbytes);
320 while ((nbytes = rx_Read(call, buf, sizeof(buf))) > 0) {
322 while (nbytes--) {putchar(*p); *p++;}
324 if ((err = rx_EndCall(call, 0)) != 0) {
325 fprintf(stderr, "rx_Endcall returned error %d\n", err);
327 struct clock totalTime;
329 clock_GetTime(&totalTime);
330 clock_Sub(&totalTime, &startTime);
331 elapsedTime = totalTime.sec + totalTime.usec/1e6;
332 fprintf(stderr, "Sent %d bytes in %0.3f seconds: %0.0f bytes per second\n",
333 status.st_size, elapsedTime, status.st_size/elapsedTime);
335 float delay = clock_Float(&totalReadvDelay) / nReadvs;
336 fprintf(stderr, "%d readvs, average delay of %0.4f seconds\n", nReadvs, delay);
342 Abort(msg,a,b,c,d,e) {
343 printf((char *) msg, a, b, c, d, e);
346 rx_PrintStats(debugFile);
353 Quit(msg, a,b,c,d,e) {
354 printf((char *) msg, a,b,c,d,e);
357 rx_PrintStats(debugFile);
360 rx_PrintStats(stdout);
366 * Open file descriptors until file descriptor n or higher is returned.
368 #include <sys/stat.h>
377 for (i=0; i<n; i++) {
378 if (fstat(i, &sbuf) == 0)
380 if ((fd = open("/dev/null", 0, 0)) < 0) {