2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "load_tester_plugin.h"
17 #include "load_tester_config.h"
18 #include "load_tester_creds.h"
19 #include "load_tester_ipsec.h"
20 #include "load_tester_listener.h"
21 #include "load_tester_control.h"
22 #include "load_tester_diffie_hellman.h"
28 #include <processing/jobs/callback_job.h>
29 #include <threading/condvar.h>
30 #include <threading/mutex.h>
32 typedef struct private_load_tester_plugin_t private_load_tester_plugin_t
;
35 * private data of load_tester plugin
37 struct private_load_tester_plugin_t
{
40 * implements plugin interface
42 load_tester_plugin_t
public;
45 * load_tester configuration backend
47 load_tester_config_t
*config
;
50 * load_tester credential set implementation
52 load_tester_creds_t
*creds
;
55 * Unix control socket to initiate load-tests
57 load_tester_control_t
*control
;
60 * event handler, listens on bus
62 load_tester_listener_t
*listener
;
65 * number of iterations per thread
70 * number desired initiator threads
75 * currently running initiators
80 * delay between initiations, in ms
85 * Throttle initiation if half-open IKE_SA count reached
90 * mutex to lock running field
95 * condvar to wait for initiators
101 * Begin the load test
103 static job_requeue_t
do_load_test(private_load_tester_plugin_t
*this)
105 int i
, s
= 0, ms
= 0;
107 this->mutex
->lock(this->mutex
);
109 this->mutex
->unlock(this->mutex
);
112 s
= this->delay
/ 1000;
113 ms
= this->delay
% 1000;
116 for (i
= 0; this->iterations
== 0 || i
< this->iterations
; i
++)
118 peer_cfg_t
*peer_cfg
;
119 child_cfg_t
*child_cfg
= NULL
;
120 enumerator_t
*enumerator
;
122 if (this->init_limit
)
124 while ((charon
->ike_sa_manager
->get_count(charon
->ike_sa_manager
) -
125 this->listener
->get_established(this->listener
)) >
139 peer_cfg
= charon
->backends
->get_peer_cfg_by_name(charon
->backends
,
145 enumerator
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
146 if (!enumerator
->enumerate(enumerator
, &child_cfg
))
148 enumerator
->destroy(enumerator
);
151 enumerator
->destroy(enumerator
);
153 charon
->controller
->initiate(charon
->controller
,
154 peer_cfg
, child_cfg
->get_ref(child_cfg
),
165 this->mutex
->lock(this->mutex
);
167 this->condvar
->signal(this->condvar
);
168 this->mutex
->unlock(this->mutex
);
169 return JOB_REQUEUE_NONE
;
172 METHOD(plugin_t
, get_name
, char*,
173 private_load_tester_plugin_t
*this)
175 return "load-tester";
179 * Register load_tester plugin features
181 static bool register_load_tester(private_load_tester_plugin_t
*this,
182 plugin_feature_t
*feature
, bool reg
, void *data
)
186 u_int i
, shutdown_on
= 0;
188 this->config
= load_tester_config_create();
189 this->creds
= load_tester_creds_create();
190 this->control
= load_tester_control_create();
192 charon
->backends
->add_backend(charon
->backends
, &this->config
->backend
);
193 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->credential_set
);
195 if (lib
->settings
->get_bool(lib
->settings
,
196 "%s.plugins.load-tester.shutdown_when_complete", 0, lib
->ns
))
198 shutdown_on
= this->iterations
* this->initiators
;
200 this->listener
= load_tester_listener_create(shutdown_on
, this->config
);
201 charon
->bus
->add_listener(charon
->bus
, &this->listener
->listener
);
203 for (i
= 0; i
< this->initiators
; i
++)
205 lib
->processor
->queue_job(lib
->processor
, (job_t
*)
206 callback_job_create_with_prio((callback_job_cb_t
)do_load_test
,
207 this, NULL
, NULL
, JOB_PRIO_CRITICAL
));
212 this->iterations
= -1;
213 this->mutex
->lock(this->mutex
);
214 while (this->running
)
216 this->condvar
->wait(this->condvar
, this->mutex
);
218 this->mutex
->unlock(this->mutex
);
219 charon
->backends
->remove_backend(charon
->backends
, &this->config
->backend
);
220 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->credential_set
);
221 charon
->bus
->remove_listener(charon
->bus
, &this->listener
->listener
);
222 this->config
->destroy(this->config
);
223 this->creds
->destroy(this->creds
);
224 this->listener
->destroy(this->listener
);
225 this->control
->destroy(this->control
);
230 METHOD(plugin_t
, get_features
, int,
231 private_load_tester_plugin_t
*this, plugin_feature_t
*features
[])
233 static plugin_feature_t f
[] = {
234 PLUGIN_REGISTER(DH
, load_tester_diffie_hellman_create
),
235 PLUGIN_PROVIDE(DH
, MODP_NULL
),
236 PLUGIN_DEPENDS(CUSTOM
, "load-tester"),
237 PLUGIN_CALLBACK((plugin_feature_callback_t
)register_load_tester
, NULL
),
238 PLUGIN_PROVIDE(CUSTOM
, "load-tester"),
239 PLUGIN_DEPENDS(CUSTOM
, "kernel-net"),
240 PLUGIN_SDEPEND(PRIVKEY
, KEY_RSA
),
241 PLUGIN_SDEPEND(CERT_DECODE
, CERT_ANY
),
242 PLUGIN_SDEPEND(CERT_DECODE
, CERT_X509
),
248 METHOD(plugin_t
, destroy
, void,
249 private_load_tester_plugin_t
*this)
251 hydra
->kernel_interface
->remove_ipsec_interface(hydra
->kernel_interface
,
252 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
253 this->mutex
->destroy(this->mutex
);
254 this->condvar
->destroy(this->condvar
);
261 plugin_t
*load_tester_plugin_create()
263 private_load_tester_plugin_t
*this;
265 if (!lib
->settings
->get_bool(lib
->settings
, "%s.plugins.load-tester.enable",
268 DBG1(DBG_CFG
, "disabling load-tester plugin, not configured");
275 .get_name
= _get_name
,
276 .get_features
= _get_features
,
277 .reload
= (void*)return_false
,
281 .delay
= lib
->settings
->get_int(lib
->settings
,
282 "%s.plugins.load-tester.delay", 0, lib
->ns
),
283 .iterations
= lib
->settings
->get_int(lib
->settings
,
284 "%s.plugins.load-tester.iterations", 1, lib
->ns
),
285 .initiators
= lib
->settings
->get_int(lib
->settings
,
286 "%s.plugins.load-tester.initiators", 0, lib
->ns
),
287 .init_limit
= lib
->settings
->get_int(lib
->settings
,
288 "%s.plugins.load-tester.init_limit", 0, lib
->ns
),
289 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
290 .condvar
= condvar_create(CONDVAR_TYPE_DEFAULT
),
293 if (lib
->settings
->get_bool(lib
->settings
,
294 "%s.plugins.load-tester.fake_kernel", FALSE
, lib
->ns
))
296 hydra
->kernel_interface
->add_ipsec_interface(hydra
->kernel_interface
,
297 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
299 return &this->public.plugin
;