2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
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"
30 int pass_count, fail_count;
33 static void request_handler(struct cldap_request *req)
35 struct cldap_netlogon io;
36 struct bench_state *state = talloc_get_type(req->async.private_data, struct bench_state);
38 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
40 status = cldap_netlogon_recv(req, tmp_ctx, &io);
41 if (NT_STATUS_IS_OK(status)) {
52 static bool bench_cldap(struct torture_context *tctx, const char *address)
54 struct cldap_socket *cldap;
56 struct timeval tv = timeval_current();
58 int timelimit = torture_setting_int(tctx, "timelimit", 10);
59 struct cldap_netlogon search;
60 struct bench_state *state;
62 cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
64 state = talloc_zero(tctx, struct bench_state);
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;
72 printf("Running 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);
78 req->async.private_data = state;
79 req->async.fn = request_handler;
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),
91 event_loop_once(cldap->event_ctx);
94 while (num_sent != (state->pass_count + state->fail_count)) {
95 event_loop_once(cldap->event_ctx);
98 printf("%.1f queries per second (%d failures) \n",
99 state->pass_count / timeval_elapsed(&tv),
108 benchmark how fast a CLDAP server can respond to a series of parallel
111 bool torture_bench_cldap(struct torture_context *torture)
114 struct nbt_name name;
118 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
120 /* do an initial name resolution to find its IP */
121 status = resolve_name(lp_resolve_context(torture->lp_ctx), &name, torture, &address, torture->ev);
122 if (!NT_STATUS_IS_OK(status)) {
123 printf("Failed to resolve %s - %s\n",
124 name.name, nt_errstr(status));
128 ret &= bench_cldap(torture, address);