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>
16 #include <sys/types.h>
24 #include <netinet/in.h>
32 #include "rx_globals.h"
35 #include <afs/afsutil.h>
38 #define osi_Alloc(n) (char *) malloc(n)
42 int print = 1, eventlog = 0, rxlog = 0;
45 struct clock burstTime;
46 struct clock retryTime;
49 struct clock waitTime, computeTime;
60 quitSignal(int ignore)
62 static int quitCount = 0;
64 Quit("rx_ctest: second quit signal, aborting");
65 rx_debugFile = debugFile = fopen("rx_ctest.db", "w");
67 rx_PrintStats(debugFile);
70 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
72 test_syscall(a3, a4, a5)
79 old = signal(SIGSYS, SIG_IGN);
81 syscall(31 /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3, a4, a5);
92 struct hostent *hostent;
95 struct rx_connection *conn;
98 int nCalls = 1, nBytes = 1;
99 int bufferSize = 4000000;
105 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
107 rxi_syscallp = test_syscall;
113 while (argc && **argv == '-') {
114 if (strcmp(*argv, "-silent") == 0)
116 if (strcmp(*argv, "-jumbo") == 0)
118 else if (strcmp(*argv, "-nc") == 0)
119 nCalls = atoi(*++argv), argc--;
120 else if (strcmp(*argv, "-nb") == 0)
121 nBytes = atoi(*++argv), argc--;
122 else if (strcmp(*argv, "-np") == 0)
123 rx_nPackets = atoi(*++argv), argc--;
124 else if (!strcmp(*argv, "-nsf"))
125 rxi_nSendFrags = atoi(*++argv), argc--;
126 else if (!strcmp(*argv, "-nrf"))
127 rxi_nRecvFrags = atoi(*++argv), argc--;
128 else if (strcmp(*argv, "-twind") == 0)
129 rx_initSendWindow = atoi(*++argv), argc--;
130 else if (strcmp(*argv, "-rwind") == 0)
131 rx_initReceiveWindow = atoi(*++argv), argc--;
132 else if (strcmp(*argv, "-rxlog") == 0)
134 else if (strcmp(*argv, "-logstdout") == 0)
136 else if (strcmp(*argv, "-eventlog") == 0)
138 else if (strcmp(*argv, "-drop") == 0) {
140 rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
142 fprintf(stderr, "ERROR: Compiled without RXDEBUG\n");
145 else if (strcmp(*argv, "-burst") == 0) {
146 burst = atoi(*++argv), argc--;
147 burstTime.sec = atoi(*++argv), argc--;
148 burstTime.usec = atoi(*++argv), argc--;
149 } else if (strcmp(*argv, "-retry") == 0) {
150 retryTime.sec = atoi(*++argv), argc--;
151 retryTime.usec = atoi(*++argv), argc--;
152 } else if (strcmp(*argv, "-timeout") == 0)
153 timeout = atoi(*++argv), argc--;
154 else if (strcmp(*argv, "-fill") == 0)
156 else if (strcmp(*argv, "-file") == 0)
157 sendFile = *++argv, argc--;
158 else if (strcmp(*argv, "-timereadvs") == 0)
160 else if (strcmp(*argv, "-wait") == 0) {
161 /* Wait time between calls--to test lastack code */
162 waitTime.sec = atoi(*++argv), argc--;
163 waitTime.usec = atoi(*++argv), argc--;
164 } else if (strcmp(*argv, "-compute") == 0) {
165 /* Simulated "compute" time for each call--to test acknowledgement protocol. This is simulated by doing an iomgr_select: imperfect, admittedly. */
166 computeTime.sec = atoi(*++argv), argc--;
167 computeTime.usec = atoi(*++argv), argc--;
168 } else if (strcmp(*argv, "-fd") == 0) {
169 /* Open at least this many fd's. */
170 setFD = atoi(*++argv), argc--;
177 if (err || argc != 1)
178 Quit("usage: rx_ctest [-silent] [-rxlog] [-eventlog] [-nc NCALLS] [-np NPACKETS] hostname");
179 hostname = *argv++, argc--;
181 if (rxlog || eventlog) {
185 debugFile = fopen("rx_ctest.db", "w");
186 if (debugFile == NULL)
187 Quit("Couldn't open rx_ctest.db");
189 rx_debugFile = debugFile;
191 rxevent_debugFile = debugFile;
194 signal(SIGINT, intSignal); /*Changed to sigquit since dbx is broken right now */
196 signal(SIGQUIT, quitSignal);
200 if (afs_winsockInit() < 0) {
201 printf("Can't initialize winsock.\n");
204 rx_EnableHotThread();
207 rx_SetUdpBufSize(256 * 1024);
212 hostent = gethostbyname(hostname);
214 Abort("host %s not found", hostname);
215 if (hostent->h_length != 4)
216 Abort("host address is disagreeable length (%d)", hostent->h_length);
217 memcpy((char *)&host, hostent->h_addr, sizeof(host));
220 if (rx_Init(0) != 0) {
221 printf("RX failed to initialize, exiting.\n");
225 printf("rx_socket=%d\n", rx_socket);
228 printf("Using %d packet buffers\n", rx_nPackets);
231 rx_NewConnection(host, htons(2500), 3,
232 rxnull_NewClientSecurityObject(), 0);
235 Abort("unable to make a new connection");
237 /* Set initial parameters. This is (currently) not the approved interface */
239 conn->peer->burstSize = conn->peer->burst = burst;
240 if (!clock_IsZero(&burstTime))
241 conn->peer->burstWait = burstTime;
242 if (!clock_IsZero(&retryTime))
243 conn->peer->timeout = retryTime;
246 SendFile(sendFile, conn);
248 buffer = (char *)osi_Alloc(bufferSize);
250 struct clock startTime;
256 call = rx_NewCall(conn);
258 Abort("unable to make a new call");
260 clock_GetTime(&startTime);
261 for (bytesSent = 0; bytesSent < nBytes; bytesSent += nSent) {
265 nBytes - bytesSent) ? nBytes - bytesSent : bufferSize;
266 nSent = rx_Write(call, buffer, tryCount);
271 for (bytesRead = 0; nbytes = rx_Read(call, buffer, bufferSize);
272 bytesRead += nbytes) {
275 printf("Received %d characters in response\n", bytesRead);
276 err = rx_EndCall(call, 0);
278 printf("Error %d returned from rpc call\n", err);
280 struct clock totalTime;
282 clock_GetTime(&totalTime);
283 clock_Sub(&totalTime, &startTime);
284 elapsedTime = clock_Float(&totalTime);
286 "Sent %d bytes in %0.3f seconds: %0.0f bytes per second\n",
287 bytesSent, elapsedTime, bytesSent / elapsedTime);
289 if (!clock_IsZero(&computeTime)) {
290 t.tv_sec = computeTime.sec;
291 t.tv_usec = computeTime.usec;
292 if (select(0, 0, 0, 0, &t) != 0)
293 Quit("Select didn't return 0");
295 if (!clock_IsZero(&waitTime)) {
297 t.tv_sec = waitTime.sec;
298 t.tv_usec = waitTime.usec;
299 #ifdef AFS_PTHREAD_ENV
300 select(0, 0, 0, 0, &t);
302 IOMGR_Sleep(t.tv_sec);
306 rx_PrintPeerStats(debugFile, rx_PeerOf(conn));
307 rx_PrintPeerStats(stdout, rx_PeerOf(conn));
310 Quit("testclient: done!\n");
313 int SendFile(file, conn)
315 struct rx_connection *conn;
317 struct rx_call *call;
320 int blockSize, bytesLeft;
324 struct clock startTime;
325 int receivedStore = 0;
326 struct clock totalReadvDelay;
330 #include <sys/statfs.h>
331 struct statfs tstatfs;
336 clock_Zero(&totalReadvDelay);
338 fd = open(file, O_RDONLY, 0);
340 Abort("Couldn't open %s\n", file);
346 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the stat structure!! */
347 fstatfs(fd, &tstatfs);
348 blockSize = tstatfs.f_bsize;
350 blockSize = status.st_blksize;
353 buf = (char *)osi_Alloc(blockSize);
354 bytesLeft = status.st_size;
355 clock_GetTime(&startTime);
356 call = rx_NewCall(conn);
358 if (!receivedStore && rx_GetRemoteStatus(call) == 79) {
361 "Remote status indicates file accepted (\"received store\")\n");
363 nbytes = (bytesLeft > blockSize ? blockSize : bytesLeft);
365 code = read(fd, buf, nbytes);
366 if (code != nbytes) {
367 Abort("Only read %d bytes of %d, errno=%d\n", code, nbytes,
370 code = rx_Write(call, buf, nbytes);
371 if (code != nbytes) {
372 Abort("Only wrote %d bytes of %d\n", code, nbytes);
376 while ((nbytes = rx_Read(call, buf, sizeof(buf))) > 0) {
383 if ((err = rx_EndCall(call, 0)) != 0) {
384 fprintf(stderr, "rx_Endcall returned error %d\n", err);
386 struct clock totalTime;
388 clock_GetTime(&totalTime);
389 clock_Sub(&totalTime, &startTime);
390 elapsedTime = totalTime.sec + totalTime.usec / 1e6;
392 "Sent %d bytes in %0.3f seconds: %0.0f bytes per second\n",
393 status.st_size, elapsedTime, status.st_size / elapsedTime);
395 float delay = clock_Float(&totalReadvDelay) / nReadvs;
396 fprintf(stderr, "%d readvs, average delay of %0.4f seconds\n",
405 Abort(msg, a, b, c, d, e)
407 printf((char *)msg, a, b, c, d, e);
410 rx_PrintStats(debugFile);
417 Quit(char *msg, int a, int b, int c, int d, int e)
419 printf((char *)msg, a, b, c, d, e);
422 rx_PrintStats(debugFile);
425 rx_PrintStats(stdout);
431 * Open file descriptors until file descriptor n or higher is returned.
433 #include <sys/stat.h>
443 for (i = 0; i < n; i++) {
444 if (fstat(i, &sbuf) == 0)
446 if ((fd = open("/dev/null", 0, 0)) < 0) {