Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rx / test / kctest.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
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
8 */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include <sys/types.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <stdio.h>
18 #include <signal.h>
19 #include "xdr.h"
20 #include "rx.h"
21 #include "rx_globals.h"
22 #include "rx_null.h"
23 #if RX_VAB_EXISTS
24 #include "rx_vab.h"
25 #endif
26
27 static long host;
28 static short port;
29 static short count;
30 static short secLevel = 0;
31 static short stats = 0;
32
33 #if RX_VAB_EXISTS
34 static
35 MakeVTest(akey, aticket, asession)
36 struct rxvab_EncryptionKey *akey, *asession;
37 struct rxvab_Ticket *aticket;
38 {
39 aticket->ViceId = htonl(71);
40 memcpy(&aticket->HandShakeKey, "testkeyx", 8);
41 memcpy(asession, "testkeyx", 8);
42 bcrypt_encrypt(aticket, aticket, sizeof(struct rxvab_Ticket), akey);
43 return 0;
44 }
45 #else
46 #define MakeVTest(a,b,c) (printf ("rx_vab support removed\n"), exit (-1))
47 #endif
48
49 void
50 SigInt(int ignore)
51 {
52 if (rx_debugFile) {
53 rx_PrintStats(rx_debugFile);
54 fflush(rx_debugFile);
55 }
56 if (stats)
57 rx_PrintStats(stdout);
58 rx_Finalize();
59 exit(1);
60 }
61
62 static
63 ParseCmd(argc, argv)
64 int argc;
65 char **argv;
66 {
67 int i;
68 struct hostent *th;
69 for (i = 1; i < argc; i++) {
70 if (!strcmp(argv[i], "-port")) {
71 port = atoi(argv[i + 1]);
72 i++;
73 } else if (!strcmp(argv[i], "-host")) {
74 th = gethostbyname(argv[i + 1]);
75 if (!th) {
76 printf("could not find host '%s' in host table\n",
77 argv[i + 1]);
78 return -1;
79 }
80 memcpy(&host, th->h_addr, sizeof(long));
81 i++;
82 } else if (!strcmp(argv[i], "-count")) {
83 count = atoi(argv[i + 1]);
84 i++;
85 } else if (!strcmp(argv[i], "-security")) {
86 secLevel = atoi(argv[i + 1]);
87 i++;
88 } else if (!strcmp(argv[i], "-log")) {
89 rx_debugFile = fopen("kctest.log", "w");
90 if (rx_debugFile == NULL)
91 printf("Couldn't open rx_stest.db");
92 signal(SIGINT, SigInt);
93 } else if (!strcmp(argv[i], "-stats"))
94 stats = 1;
95 else {
96 printf("unrecognized switch '%s'\n", argv[i]);
97 return -1;
98 }
99 }
100 return 0;
101 }
102
103 nowms()
104 {
105 struct timeval tv;
106 long temp;
107
108 gettimeofday(&tv, NULL);
109 temp = ((tv.tv_sec & 0xffff) * 1000) + (tv.tv_usec / 1000);
110 return temp;
111 }
112
113 main(argc, argv)
114 int argc;
115 char **argv;
116 {
117 struct rx_securityClass *so;
118 struct rx_connection *tconn;
119 struct rx_call *tcall;
120 XDR xdr;
121 int i, startms, endms;
122 long temp;
123 #if RX_VAB_EXISTS
124 struct rxvab_Ticket ticket;
125 struct rxvab_EncryptionKey session;
126 #endif
127
128 host = htonl(0x7f000001);
129 port = htons(10000);
130 count = 1;
131 if (ParseCmd(argc, argv) != 0) {
132 printf("error parsing commands\n");
133 exit(1);
134 }
135 rx_Init(0);
136 if (secLevel == 0)
137 so = rxnull_NewClientSecurityObject();
138 else if (secLevel == 1) {
139 MakeVTest((struct rxvab_EncryptionKey *)"applexxx", &ticket,
140 &session);
141 #if RX_VAB_EXISTS
142 so = rxvab_NewClientSecurityObject(&session, &ticket, 0);
143 #endif
144 } else if (secLevel == 2) {
145 MakeVTest((struct rxvab_EncryptionKey *)"applexxx", &ticket,
146 &session);
147 #if RX_VAB_EXISTS
148 so = rxvab_NewClientSecurityObject(&session, &ticket, 1);
149 #endif
150 } else {
151 printf("bad security index\n");
152 exit(1);
153 }
154 if (!so) {
155 printf("failed to create security obj\n");
156 exit(1);
157 }
158 tconn = rx_NewConnection(host, port, 1, so, secLevel);
159 printf("conn is %x\n", tconn);
160
161 startms = nowms();
162 for (i = 0; i < count; i++) {
163 tcall = rx_NewCall(tconn);
164 /* fill in data */
165 xdrrx_create(&xdr, tcall, XDR_ENCODE);
166 temp = 1988;
167 xdr_long(&xdr, &temp);
168 xdr.x_op = XDR_DECODE;
169 xdr_long(&xdr, &temp);
170 if (temp != 1989)
171 printf("wrong value returned (%d)\n", temp);
172 rx_EndCall(tcall, 0);
173 }
174 endms = nowms();
175 printf("That was %d ms per call.\n", (endms - startms) / count);
176 printf("Done.\n");
177 #ifdef RXDEBUG
178 if (stats)
179 rx_PrintStats(stdout);
180 #endif
181 SigInt(0);
182 }