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_diffie_hellman.h"
27 #include <processing/jobs/callback_job.h>
28 #include <threading/condvar.h>
29 #include <threading/mutex.h>
31 typedef struct private_load_tester_plugin_t private_load_tester_plugin_t
;
34 * private data of load_tester plugin
36 struct private_load_tester_plugin_t
{
39 * implements plugin interface
41 load_tester_plugin_t
public;
44 * load_tester configuration backend
46 load_tester_config_t
*config
;
49 * load_tester credential set implementation
51 load_tester_creds_t
*creds
;
54 * event handler, listens on bus
56 load_tester_listener_t
*listener
;
59 * number of iterations per thread
64 * number desired initiator threads
69 * currently running initiators
74 * delay between initiations, in ms
79 * Throttle initiation if half-open IKE_SA count reached
84 * mutex to lock running field
89 * condvar to wait for initiators
97 static job_requeue_t
do_load_test(private_load_tester_plugin_t
*this)
101 this->mutex
->lock(this->mutex
);
103 this->mutex
->unlock(this->mutex
);
106 s
= this->delay
/ 1000;
107 ms
= this->delay
% 1000;
110 for (i
= 0; this->iterations
== 0 || i
< this->iterations
; i
++)
112 peer_cfg_t
*peer_cfg
;
113 child_cfg_t
*child_cfg
= NULL
;
114 enumerator_t
*enumerator
;
116 if (this->init_limit
)
118 while ((charon
->ike_sa_manager
->get_count(charon
->ike_sa_manager
) -
119 this->listener
->get_established(this->listener
)) >
133 peer_cfg
= charon
->backends
->get_peer_cfg_by_name(charon
->backends
,
139 enumerator
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
140 if (!enumerator
->enumerate(enumerator
, &child_cfg
))
142 enumerator
->destroy(enumerator
);
145 enumerator
->destroy(enumerator
);
147 charon
->controller
->initiate(charon
->controller
,
148 peer_cfg
, child_cfg
->get_ref(child_cfg
),
159 this->mutex
->lock(this->mutex
);
161 this->condvar
->signal(this->condvar
);
162 this->mutex
->unlock(this->mutex
);
163 return JOB_REQUEUE_NONE
;
166 METHOD(plugin_t
, get_name
, char*,
167 private_load_tester_plugin_t
*this)
169 return "load-tester";
173 * Register load_tester plugin features
175 static bool register_load_tester(private_load_tester_plugin_t
*this,
176 plugin_feature_t
*feature
, bool reg
, void *data
)
180 u_int i
, shutdown_on
= 0;
182 this->config
= load_tester_config_create();
183 this->creds
= load_tester_creds_create();
185 charon
->backends
->add_backend(charon
->backends
, &this->config
->backend
);
186 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->credential_set
);
188 if (lib
->settings
->get_bool(lib
->settings
,
189 "%s.plugins.load-tester.shutdown_when_complete", 0, charon
->name
))
191 shutdown_on
= this->iterations
* this->initiators
;
193 this->listener
= load_tester_listener_create(shutdown_on
);
194 charon
->bus
->add_listener(charon
->bus
, &this->listener
->listener
);
196 if (lib
->settings
->get_bool(lib
->settings
,
197 "%s.plugins.load-tester.fake_kernel", FALSE
, charon
->name
))
199 hydra
->kernel_interface
->add_ipsec_interface(hydra
->kernel_interface
,
200 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
202 for (i
= 0; i
< this->initiators
; i
++)
204 lib
->processor
->queue_job(lib
->processor
, (job_t
*)
205 callback_job_create_with_prio((callback_job_cb_t
)do_load_test
,
206 this, NULL
, NULL
, JOB_PRIO_CRITICAL
));
211 this->iterations
= -1;
212 this->mutex
->lock(this->mutex
);
213 while (this->running
)
215 this->condvar
->wait(this->condvar
, this->mutex
);
217 this->mutex
->unlock(this->mutex
);
218 hydra
->kernel_interface
->remove_ipsec_interface(hydra
->kernel_interface
,
219 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
220 charon
->backends
->remove_backend(charon
->backends
, &this->config
->backend
);
221 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->credential_set
);
222 charon
->bus
->remove_listener(charon
->bus
, &this->listener
->listener
);
223 this->config
->destroy(this->config
);
224 this->creds
->destroy(this->creds
);
225 this->listener
->destroy(this->listener
);
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_SDEPEND(PRIVKEY
, KEY_RSA
),
240 PLUGIN_SDEPEND(CERT_DECODE
, CERT_ANY
),
241 PLUGIN_SDEPEND(CERT_DECODE
, CERT_X509
),
247 METHOD(plugin_t
, destroy
, void,
248 private_load_tester_plugin_t
*this)
250 this->mutex
->destroy(this->mutex
);
251 this->condvar
->destroy(this->condvar
);
258 plugin_t
*load_tester_plugin_create()
260 private_load_tester_plugin_t
*this;
262 if (!lib
->settings
->get_bool(lib
->settings
,
263 "%s.plugins.load-tester.enable", FALSE
, charon
->name
))
265 DBG1(DBG_CFG
, "disabling load-tester plugin, not configured");
272 .get_name
= _get_name
,
273 .get_features
= _get_features
,
274 .reload
= (void*)return_false
,
278 .delay
= lib
->settings
->get_int(lib
->settings
,
279 "%s.plugins.load-tester.delay", 0, charon
->name
),
280 .iterations
= lib
->settings
->get_int(lib
->settings
,
281 "%s.plugins.load-tester.iterations", 1, charon
->name
),
282 .initiators
= lib
->settings
->get_int(lib
->settings
,
283 "%s.plugins.load-tester.initiators", 0, charon
->name
),
284 .init_limit
= lib
->settings
->get_int(lib
->settings
,
285 "%s.plugins.load-tester.init_limit", 0, charon
->name
),
286 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
287 .condvar
= condvar_create(CONDVAR_TYPE_DEFAULT
),
289 return &this->public.plugin
;