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 /* RX Authentication Stress test: server side code. */
12 #include <afs/param.h>
14 #include <sys/types.h>
19 #include <netinet/in.h>
25 #include <afs/com_err.h>
30 #include "stress_internal.h"
31 #include "rx/rx_globals.h"
32 #ifdef AFS_PTHREAD_ENV
41 static int StringToAuth (authname)
45 if (strcmp (authname, "rxkad") == 0) return rxkad_clear;
46 if (strcmp (authname, "rxkad_")) {
47 if (strncmp (authname, "rxkad_", 6) == 0)
48 nonoauth++, authname += 6;
49 if (strcmp (authname, "clear") == 0) return rxkad_clear;
50 if (strcmp (authname, "auth") == 0) return rxkad_auth;
51 if (strcmp (authname, "crypt") == 0) return rxkad_crypt;
52 if (strcmp (authname, "null") == 0) return -1;
53 if (strcmp (authname, "none") == 0) return -1;
54 if (strncmp (authname, "noauth", 6) == 0) return -1;
55 if (strncmp (authname, "unauth", 6) == 0) return -1;
59 "Unknown authentication name %s, using rxkad_clear by default\n",
70 #define aCOPIOUSCALLS 6
72 #define aPRINTTIMING 8
77 #define aHIJACKTEST 13
78 #define aAUTHENTICATION 14
79 #define aMINSERVERAUTH 15
80 #define aREPEATINTERVAL 16
81 #define aREPEATCOUNT 17
82 #define aSTOPSERVER 18
89 static int CommandProc (as, arock)
91 struct cmd_syndesc *as;
94 int startServer = (as->parms[aSERVER].items != 0);
95 int startClient = (as->parms[aCLIENT].items != 0);
96 #ifndef AFS_PTHREAD_ENV
99 struct serverParms *sParms;
100 struct clientParms *cParms;
102 sParms = (struct serverParms *) osi_Alloc (sizeof(*sParms));
103 cParms = (struct clientParms *) osi_Alloc (sizeof(*cParms));
104 bzero (sParms, sizeof(*sParms));
105 bzero (cParms, sizeof(*cParms));
106 sParms->whoami = cParms->whoami = whoami;
108 if (!(startServer || startClient)) {
109 /* Default to "-server -client <localhost>" */
110 gethostname(cParms->server, sizeof(cParms->server));
111 startServer = startClient = 1;
115 cParms->printStats = (as->parms[aPRINTSTATS].items != 0);
116 cParms->printTiming = (as->parms[aPRINTTIMING].items != 0);
117 cParms->noExit = (as->parms[aNOEXIT].items != 0);
118 cParms->callTest = (as->parms[aCALLTEST].items != 0);
119 cParms->hijackTest = (as->parms[aHIJACKTEST].items != 0);
120 cParms->stopServer = (as->parms[aSTOPSERVER].items != 0);
122 if (as->parms[aMELT1b].items)
124 if (as->parms[aRECLAIM].items)
126 if (as->parms[a2DCHOICE].items)
130 if (as->parms[aTRACE].items) {
131 extern char rxi_tracename[];
132 strcpy (rxi_tracename, as->parms[aTRACE].items->data);
135 /* These options not compatible with -server */
136 if (cParms->stopServer) {
137 code = RXKST_BADARGS;
138 com_err (whoami, code, "stop server not compatible with -client");
142 /* process -server options */
143 sParms->threads = 3; /* one less than channels/conn */
144 if (as->parms[aSTHREADS].items)
145 sParms->threads = atoi (as->parms[aSTHREADS].items->data);
146 sParms->authentication = 0;
147 if (as->parms[aMINSERVERAUTH].items)
148 sParms->authentication =
149 StringToAuth (as->parms[aMINSERVERAUTH].items->data);
151 #ifdef AFS_PTHREAD_ENV
154 pthread_attr_t tattr;
156 code = pthread_attr_init(&tattr);
158 com_err (whoami, code, "can't pthread_attr_init server process");
162 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
164 com_err (whoami, code, "can't pthread_attr_setdetachstate server process");
168 code = pthread_create(&serverID, &tattr, rxkst_StartServer,
172 code = LWP_CreateProcess(rxkst_StartServer, 16000, LWP_NORMAL_PRIORITY,
173 (opaque) sParms, "Server Process", &pid);
176 com_err (whoami, code, "can't create server process");
180 /* check for server-only args */
184 u_long calls; /* default number of calls */
186 /* process -client options */
187 if (as->parms[aCLIENT].items)
188 lcstring (cParms->server, as->parms[aCLIENT].items->data,
189 sizeof(cParms->server));
190 cParms->threads = 6; /* 150% of channels/conn */
191 if (as->parms[aCTHREADS].items)
192 cParms->threads = atoi (as->parms[aCTHREADS].items->data);
193 if (cParms->callTest || cParms->hijackTest ||
194 cParms->printTiming || cParms->stopServer)
197 cParms->fastCalls = cParms->slowCalls = cParms->copiousCalls = calls;
199 cParms->sendLen = cParms->recvLen = 10000;
200 if (as->parms[aSENDLEN].items)
201 cParms->sendLen = atoi (as->parms[aSENDLEN].items->data);
202 if (as->parms[aRECVLEN].items)
203 cParms->recvLen = atoi (as->parms[aRECVLEN].items->data);
204 if (as->parms[aFASTCALLS].items)
205 cParms->fastCalls = atoi (as->parms[aFASTCALLS].items->data);
206 if (as->parms[aSLOWCALLS].items)
207 cParms->slowCalls = atoi (as->parms[aSLOWCALLS].items->data);
208 if (as->parms[aCOPIOUSCALLS].items)
209 cParms->copiousCalls = atoi (as->parms[aCOPIOUSCALLS].items->data);
210 cParms->repeatInterval = cParms->repeatCount = 0;
211 if (as->parms[aREPEATINTERVAL].items)
212 cParms->repeatInterval =
213 atoi (as->parms[aREPEATINTERVAL].items->data);
214 if (as->parms[aREPEATCOUNT].items)
215 cParms->repeatCount =
216 atoi (as->parms[aREPEATCOUNT].items->data);
217 if (as->parms[aMAXSKEW].items) {
219 atoi (as->parms[aMAXSKEW].items->data);
221 printf("Minimum allowed maxSkew is 1, resetting.\n");
226 cParms->authentication = 0;
227 if (as->parms[aAUTHENTICATION].items)
228 cParms->authentication =
229 StringToAuth (as->parms[aAUTHENTICATION].items->data);
231 code = rxkst_StartClient (cParms);
233 com_err (whoami, code, "StartClient returned");
237 if (as->parms[aSENDLEN].items || as->parms[aRECVLEN].items ||
238 as->parms[aFASTCALLS].items || as->parms[aSLOWCALLS].items ||
239 as->parms[aCOPIOUSCALLS].items) {
240 code = RXKST_BADARGS;
241 com_err (whoami, code, "send/recv len and # calls are client options");
245 /* donate this LWP to server-side */
252 void main (argc, argv)
257 #ifndef AFS_PTHREAD_ENV
258 PROCESS initialProcess;
260 struct cmd_syndesc *ts;
264 initialize_rxk_error_table();
265 initialize_rks_error_table();
266 initialize_cmd_error_table();
269 rx_SetRxDeadTime(120);
271 com_err (whoami, code, "can't init Rx");
274 #ifndef AFS_PTHREAD_ENV
276 code = LWP_CurrentProcess (&initialProcess);
278 com_err (whoami, code, "LWP initialization failed");
282 ts = cmd_CreateSyntax((char *) 0, CommandProc, 0, "run Rx authentication stress test");
283 cmd_AddParm (ts, "-server", CMD_FLAG, CMD_OPTIONAL, "start server");
284 cmd_AddParm (ts, "-client", CMD_SINGLE, CMD_OPTIONAL, "start client");
285 cmd_AddParm (ts, "-sendlen", CMD_SINGLE, CMD_OPTIONAL, "bytes to send to server in Copious call");
286 cmd_AddParm (ts, "-recvlen", CMD_SINGLE, CMD_OPTIONAL, "bytes to request from server in Copious call");
287 cmd_AddParm (ts, "-fastcalls", CMD_SINGLE, CMD_OPTIONAL, "number of fast calls to make");
288 cmd_AddParm (ts, "-slowcalls", CMD_SINGLE, CMD_OPTIONAL, "number of slow calls to make (one second)");
289 cmd_AddParm (ts, "-copiouscalls", CMD_SINGLE, CMD_OPTIONAL, "number of fast calls to make");
290 cmd_AddParm (ts, "-printstatistics", CMD_FLAG, CMD_OPTIONAL, "print statistics before exiting");
291 cmd_AddParm (ts, "-printtimings", CMD_FLAG, CMD_OPTIONAL, "print timing information for calls");
292 cmd_AddParm (ts, "-noexit", CMD_FLAG, CMD_OPTIONAL, "don't exit after successful finish");
293 cmd_AddParm (ts, "-sthreads", CMD_SINGLE, CMD_OPTIONAL, "number server threads");
294 cmd_AddParm (ts, "-cthreads", CMD_SINGLE, CMD_OPTIONAL, "number client threads");
295 cmd_AddParm (ts, "-calltest", CMD_FLAG, CMD_OPTIONAL, "check server's call number verification (this takes about 30 seconds)");
296 cmd_AddParm (ts, "-hijacktest", CMD_FLAG, CMD_OPTIONAL, "check hijack prevention measures by making various modifications to incoming/outgoing packets");
297 cmd_AddParm (ts, "-authentication", CMD_SINGLE, CMD_OPTIONAL, "type of authentication to use; one of: none, clear, auth, crypt");
298 cmd_AddParm (ts, "-minserverauth", CMD_SINGLE, CMD_OPTIONAL, "minimum level of authentication permitted by server");
299 cmd_AddParm (ts, "-repeatinterval", CMD_SINGLE, CMD_OPTIONAL, "seconds between load test activity");
300 cmd_AddParm (ts, "-repeatcount", CMD_SINGLE, CMD_OPTIONAL, "repetitions of load test activity");
301 cmd_AddParm (ts, "-stopserver", CMD_FLAG, CMD_OPTIONAL, "send RPC to cause server to exit");
302 cmd_AddParm (ts, "-trace", CMD_SINGLE, CMD_OPTIONAL, "file for per-call trace info");
303 cmd_AddParm (ts, "-nomd1pkt", CMD_FLAG, CMD_OPTIONAL, "dont prefer one-packet calls");
304 cmd_AddParm (ts, "-noreclaim", CMD_FLAG, CMD_OPTIONAL, "dont aggressively reclaim packets");
305 cmd_AddParm (ts, "-no2dchoice", CMD_FLAG, CMD_OPTIONAL, "disable rx_getcall 2d choice code");
306 cmd_AddParm (ts, "-maxskew", CMD_SINGLE, CMD_OPTIONAL, "max client server skew in seconds");
308 code = cmd_Dispatch (argc, argv);