/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- request_netlogon_handler
- bench_cldap_netlogon
- request_rootdse_handler
- bench_cldap_rootdse
- torture_bench_cldap
1 /*
2 Unix SMB/CIFS implementation.
3
4 CLDAP benchmark test
5
6 Copyright (C) Andrew Tridgell 2005
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "lib/events/events.h"
24 #include "libcli/cldap/cldap.h"
25 #include "libcli/resolve/resolve.h"
26 #include "torture/torture.h"
27 #include "param/param.h"
28
29 struct bench_state {
30 int pass_count, fail_count;
31 };
32
33 static void request_netlogon_handler(struct cldap_request *req)
/* [<][>][^][v][top][bottom][index][help] */
34 {
35 struct cldap_netlogon io;
36 struct bench_state *state = talloc_get_type(req->async.private_data, struct bench_state);
37 NTSTATUS status;
38 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
39 io.in.version = 6;
40 status = cldap_netlogon_recv(req, tmp_ctx, &io);
41 if (NT_STATUS_IS_OK(status)) {
42 state->pass_count++;
43 } else {
44 state->fail_count++;
45 }
46 talloc_free(tmp_ctx);
47 }
48
49 /*
50 benchmark cldap netlogon calls
51 */
52 static bool bench_cldap_netlogon(struct torture_context *tctx, const char *address)
/* [<][>][^][v][top][bottom][index][help] */
53 {
54 struct cldap_socket *cldap;
55 int num_sent=0;
56 struct timeval tv = timeval_current();
57 bool ret = true;
58 int timelimit = torture_setting_int(tctx, "timelimit", 10);
59 struct cldap_netlogon search;
60 struct bench_state *state;
61
62 cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
63
64 state = talloc_zero(tctx, struct bench_state);
65
66 ZERO_STRUCT(search);
67 search.in.dest_address = address;
68 search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
69 search.in.acct_control = -1;
70 search.in.version = 6;
71
72 printf("Running CLDAP/netlogon for %d seconds\n", timelimit);
73 while (timeval_elapsed(&tv) < timelimit) {
74 while (num_sent - (state->pass_count+state->fail_count) < 10) {
75 struct cldap_request *req;
76 req = cldap_netlogon_send(cldap, &search);
77
78 req->async.private_data = state;
79 req->async.fn = request_netlogon_handler;
80 num_sent++;
81 if (num_sent % 50 == 0) {
82 if (torture_setting_bool(tctx, "progress", true)) {
83 printf("%.1f queries per second (%d failures) \r",
84 state->pass_count / timeval_elapsed(&tv),
85 state->fail_count);
86 fflush(stdout);
87 }
88 }
89 }
90
91 event_loop_once(cldap->event_ctx);
92 }
93
94 while (num_sent != (state->pass_count + state->fail_count)) {
95 event_loop_once(cldap->event_ctx);
96 }
97
98 printf("%.1f queries per second (%d failures) \n",
99 state->pass_count / timeval_elapsed(&tv),
100 state->fail_count);
101
102 talloc_free(cldap);
103 return ret;
104 }
105
106 static void request_rootdse_handler(struct cldap_request *req)
/* [<][>][^][v][top][bottom][index][help] */
107 {
108 struct cldap_search io;
109 struct bench_state *state = talloc_get_type(req->async.private_data, struct bench_state);
110 NTSTATUS status;
111 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
112 status = cldap_search_recv(req, tmp_ctx, &io);
113 if (NT_STATUS_IS_OK(status)) {
114 state->pass_count++;
115 } else {
116 state->fail_count++;
117 }
118 talloc_free(tmp_ctx);
119 }
120
121 /*
122 benchmark cldap netlogon calls
123 */
124 static bool bench_cldap_rootdse(struct torture_context *tctx, const char *address)
/* [<][>][^][v][top][bottom][index][help] */
125 {
126 struct cldap_socket *cldap;
127 int num_sent=0;
128 struct timeval tv = timeval_current();
129 bool ret = true;
130 int timelimit = torture_setting_int(tctx, "timelimit", 10);
131 struct cldap_search search;
132 struct bench_state *state;
133
134 cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
135
136 state = talloc_zero(tctx, struct bench_state);
137
138 ZERO_STRUCT(search);
139 search.in.dest_address = address;
140 search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
141 search.in.filter = "(objectClass=*)";
142 search.in.timeout = 2;
143 search.in.retries = 1;
144
145 printf("Running CLDAP/rootdse for %d seconds\n", timelimit);
146 while (timeval_elapsed(&tv) < timelimit) {
147 while (num_sent - (state->pass_count+state->fail_count) < 10) {
148 struct cldap_request *req;
149 req = cldap_search_send(cldap, &search);
150
151 req->async.private_data = state;
152 req->async.fn = request_rootdse_handler;
153 num_sent++;
154 if (num_sent % 50 == 0) {
155 if (torture_setting_bool(tctx, "progress", true)) {
156 printf("%.1f queries per second (%d failures) \r",
157 state->pass_count / timeval_elapsed(&tv),
158 state->fail_count);
159 fflush(stdout);
160 }
161 }
162 }
163
164 tevent_loop_once(tctx->ev);
165 }
166
167 while (num_sent != (state->pass_count + state->fail_count)) {
168 tevent_loop_once(tctx->ev);
169 }
170
171 printf("%.1f queries per second (%d failures) \n",
172 state->pass_count / timeval_elapsed(&tv),
173 state->fail_count);
174
175 talloc_free(cldap);
176 return ret;
177 }
178
179 /*
180 benchmark how fast a CLDAP server can respond to a series of parallel
181 requests
182 */
183 bool torture_bench_cldap(struct torture_context *torture)
/* [<][>][^][v][top][bottom][index][help] */
184 {
185 const char *address;
186 struct nbt_name name;
187 NTSTATUS status;
188 bool ret = true;
189
190 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
191
192 /* do an initial name resolution to find its IP */
193 status = resolve_name(lp_resolve_context(torture->lp_ctx), &name, torture, &address, torture->ev);
194 if (!NT_STATUS_IS_OK(status)) {
195 printf("Failed to resolve %s - %s\n",
196 name.name, nt_errstr(status));
197 return false;
198 }
199
200 ret &= bench_cldap_netlogon(torture, address);
201 ret &= bench_cldap_rootdse(torture, address);
202
203 return ret;
204 }