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 "libcli/cldap/cldap.h"
24 #include "libcli/resolve/resolve.h"
25 #include "torture/torture.h"
26 #include "param/param.h"
27 #include "../lib/tsocket/tsocket.h"
29 #define CHECK_VAL(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
32 struct torture_context *tctx;
33 int pass_count, fail_count;
36 static void request_netlogon_handler(struct tevent_req *req)
38 struct cldap_netlogon io;
39 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
41 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
43 status = cldap_netlogon_recv(req, tmp_ctx, &io);
45 if (NT_STATUS_IS_OK(status)) {
47 } else if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
50 printf("error: %s\n", nt_errstr(status));
58 benchmark cldap netlogon calls
60 static bool bench_cldap_netlogon(struct torture_context *tctx, const char *address)
62 struct cldap_socket *cldap;
64 struct timeval tv = timeval_current();
65 int timelimit = torture_setting_int(tctx, "timelimit", 10);
66 struct cldap_netlogon search;
67 struct bench_state *state;
69 struct tsocket_address *dest_addr;
72 ret = tsocket_address_inet_from_strings(tctx, "ip",
74 lpcfg_cldap_port(tctx->lp_ctx),
78 status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
79 torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
81 state = talloc_zero(tctx, struct bench_state);
85 search.in.dest_address = NULL;
86 search.in.dest_port = 0;
87 search.in.acct_control = -1;
88 search.in.version = 6;
90 printf("Running CLDAP/netlogon for %d seconds\n", timelimit);
91 while (timeval_elapsed(&tv) < timelimit) {
92 while (num_sent - (state->pass_count+state->fail_count) < 10) {
93 struct tevent_req *req;
94 req = cldap_netlogon_send(state, tctx->ev,
97 tevent_req_set_callback(req, request_netlogon_handler, state);
100 if (num_sent % 50 == 0) {
101 if (torture_setting_bool(tctx, "progress", true)) {
102 printf("%.1f queries per second (%d failures) \r",
103 state->pass_count / timeval_elapsed(&tv),
110 tevent_loop_once(tctx->ev);
113 while (num_sent != (state->pass_count + state->fail_count)) {
114 tevent_loop_once(tctx->ev);
117 printf("%.1f queries per second (%d failures) \n",
118 state->pass_count / timeval_elapsed(&tv),
125 static void request_rootdse_handler(struct tevent_req *req)
127 struct cldap_search io;
128 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
130 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
131 status = cldap_search_recv(req, tmp_ctx, &io);
133 if (NT_STATUS_IS_OK(status)) {
135 } else if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
138 printf("error: %s\n", nt_errstr(status));
142 talloc_free(tmp_ctx);
146 benchmark cldap netlogon calls
148 static bool bench_cldap_rootdse(struct torture_context *tctx, const char *address)
150 struct cldap_socket *cldap;
152 struct timeval tv = timeval_current();
153 int timelimit = torture_setting_int(tctx, "timelimit", 10);
154 struct cldap_search search;
155 struct bench_state *state;
157 struct tsocket_address *dest_addr;
160 ret = tsocket_address_inet_from_strings(tctx, "ip",
162 lpcfg_cldap_port(tctx->lp_ctx),
166 /* cldap_socket_init should now know about the dest. address */
167 status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
168 torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
170 state = talloc_zero(tctx, struct bench_state);
173 search.in.dest_address = NULL;
174 search.in.dest_port = 0;
175 search.in.filter = "(objectClass=*)";
176 search.in.timeout = 2;
177 search.in.retries = 1;
179 printf("Running CLDAP/rootdse for %d seconds\n", timelimit);
180 while (timeval_elapsed(&tv) < timelimit) {
181 while (num_sent - (state->pass_count+state->fail_count) < 10) {
182 struct tevent_req *req;
183 req = cldap_search_send(state, tctx->ev, cldap, &search);
185 tevent_req_set_callback(req, request_rootdse_handler, state);
188 if (num_sent % 50 == 0) {
189 if (torture_setting_bool(tctx, "progress", true)) {
190 printf("%.1f queries per second (%d failures) \r",
191 state->pass_count / timeval_elapsed(&tv),
198 tevent_loop_once(tctx->ev);
201 while (num_sent != (state->pass_count + state->fail_count)) {
202 tevent_loop_once(tctx->ev);
205 printf("%.1f queries per second (%d failures) \n",
206 state->pass_count / timeval_elapsed(&tv),
214 benchmark how fast a CLDAP server can respond to a series of parallel
217 bool torture_bench_cldap(struct torture_context *torture)
220 struct nbt_name name;
224 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
226 /* do an initial name resolution to find its IP */
227 status = resolve_name_ex(lpcfg_resolve_context(torture->lp_ctx),
228 0, 0, &name, torture, &address, torture->ev);
229 if (!NT_STATUS_IS_OK(status)) {
230 printf("Failed to resolve %s - %s\n",
231 name.name, nt_errstr(status));
235 // ret &= bench_cldap_netlogon(torture, address);
236 ret &= bench_cldap_rootdse(torture, address);