Debian Codegraph @

source4/torture/ldap/cldapbench.c

raw
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 "libcli/cldap/cldap.h"
24 #include "source3/libads/netlogon_ping.h"
25 #include "libcli/resolve/resolve.h"
26 #include "libcli/ldap/ldap_client.h"
27 #include "torture/torture.h"
28 #include "torture/ldap/proto.h"
29 #include "param/param.h"
30 #include "../lib/tsocket/tsocket.h"
31
32 #define CHECK_VAL(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
33
34 struct bench_state {
35 struct torture_context *tctx;
36 int pass_count, fail_count;
37 };
38
39 static void request_netlogon_handler(struct tevent_req *req)
40 {
41 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
42 NTSTATUS status;
43 struct netlogon_samlogon_response **responses = NULL;
44 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
45 status = netlogon_pings_recv(req, tmp_ctx, &responses);
46 talloc_free(req);
47 if (NT_STATUS_IS_OK(status)) {
48 state->pass_count++;
49 } else {
50 state->fail_count++;
51 }
52 talloc_free(tmp_ctx);
53 }
54
55 /*
56 benchmark cldap netlogon calls
57 */
58 static bool bench_cldap_netlogon(struct torture_context *tctx, const char *address)
59 {
60 int num_sent=0;
61 struct timeval tv = timeval_current();
62 int timelimit = torture_setting_int(tctx, "timelimit", 10);
63 struct bench_state *state;
64 struct tsocket_address *dest_addr;
65 int ret;
66
67 ret = tsocket_address_inet_from_strings(
68 tctx, "ip", address, 389, &dest_addr);
69 CHECK_VAL(ret, 0);
70
71 state = talloc_zero(tctx, struct bench_state);
72 state->tctx = tctx;
73
74 printf("Running CLDAP/netlogon for %d seconds\n", timelimit);
75 while (timeval_elapsed(&tv) < timelimit) {
76 while (num_sent - (state->pass_count+state->fail_count) < 10) {
77 struct tevent_req *req;
78 req = netlogon_pings_send(
79 state,
80 tctx->ev,
81 lpcfg_client_netlogon_ping_protocol(
82 tctx->lp_ctx),
83 &dest_addr,
84 1,
85 (struct netlogon_ping_filter){
86 .ntversion = 6,
87 .acct_ctrl = -1,
88 },
89 1,
90 tevent_timeval_current_ofs(2, 0));
91
92 tevent_req_set_callback(req, request_netlogon_handler, state);
93
94 num_sent++;
95 if (num_sent % 50 == 0) {
96 if (torture_setting_bool(tctx, "progress", true)) {
97 printf("%.1f queries per second (%d failures) \r",
98 state->pass_count / timeval_elapsed(&tv),
99 state->fail_count);
100 fflush(stdout);
101 }
102 }
103 }
104
105 tevent_loop_once(tctx->ev);
106 }
107
108 while (num_sent != (state->pass_count + state->fail_count)) {
109 tevent_loop_once(tctx->ev);
110 }
111
112 printf("%.1f queries per second (%d failures) \n",
113 state->pass_count / timeval_elapsed(&tv),
114 state->fail_count);
115
116 return true;
117 }
118
119 static void request_rootdse_handler(struct tevent_req *req)
120 {
121 struct cldap_search io;
122 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
123 NTSTATUS status;
124 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
125 status = cldap_search_recv(req, tmp_ctx, &io);
126 talloc_free(req);
127 if (NT_STATUS_IS_OK(status)) {
128 state->pass_count++;
129 } else {
130 state->fail_count++;
131 }
132 talloc_free(tmp_ctx);
133 }
134
135 /*
136 benchmark cldap netlogon calls
137 */
138 static bool bench_cldap_rootdse(struct torture_context *tctx, const char *address)
139 {
140 struct cldap_socket *cldap;
141 int num_sent=0;
142 struct timeval tv = timeval_current();
143 int timelimit = torture_setting_int(tctx, "timelimit", 10);
144 struct cldap_search search;
145 struct bench_state *state;
146 NTSTATUS status;
147 struct tsocket_address *dest_addr;
148 int ret;
149
150 ret = tsocket_address_inet_from_strings(
151 tctx, "ip", address, 389, &dest_addr);
152 CHECK_VAL(ret, 0);
153
154 /* cldap_socket_init should now know about the dest. address */
155 status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
156 torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
157
158 state = talloc_zero(tctx, struct bench_state);
159
160 ZERO_STRUCT(search);
161 search.in.dest_address = NULL;
162 search.in.dest_port = 0;
163 search.in.filter = "(objectClass=*)";
164 search.in.timeout = 2;
165 search.in.retries = 1;
166
167 printf("Running CLDAP/rootdse for %d seconds\n", timelimit);
168 while (timeval_elapsed(&tv) < timelimit) {
169 while (num_sent - (state->pass_count+state->fail_count) < 10) {
170 struct tevent_req *req;
171 req = cldap_search_send(state, tctx->ev, cldap, &search);
172
173 tevent_req_set_callback(req, request_rootdse_handler, state);
174
175 num_sent++;
176 if (num_sent % 50 == 0) {
177 if (torture_setting_bool(tctx, "progress", true)) {
178 printf("%.1f queries per second (%d failures) \r",
179 state->pass_count / timeval_elapsed(&tv),
180 state->fail_count);
181 fflush(stdout);
182 }
183 }
184 }
185
186 tevent_loop_once(tctx->ev);
187 }
188
189 while (num_sent != (state->pass_count + state->fail_count)) {
190 tevent_loop_once(tctx->ev);
191 }
192
193 printf("%.1f queries per second (%d failures) \n",
194 state->pass_count / timeval_elapsed(&tv),
195 state->fail_count);
196
197 talloc_free(cldap);
198 return true;
199 }
200
201 /*
202 benchmark how fast a CLDAP server can respond to a series of parallel
203 requests
204 */
205 bool torture_bench_cldap(struct torture_context *torture)
206 {
207 const char *address;
208 struct nbt_name name;
209 NTSTATUS status;
210 bool ret = true;
211
212 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
213
214 /* do an initial name resolution to find its IP */
215 status = resolve_name_ex(lpcfg_resolve_context(torture->lp_ctx),
216 0, 0, &name, torture, &address, torture->ev);
217 if (!NT_STATUS_IS_OK(status)) {
218 printf("Failed to resolve %s - %s\n",
219 name.name, nt_errstr(status));
220 return false;
221 }
222
223 ret &= bench_cldap_netlogon(torture, address);
224 ret &= bench_cldap_rootdse(torture, address);
225
226 return ret;
227 }