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 static const char *plugin_name
= "load_tester";
33 typedef struct private_load_tester_plugin_t private_load_tester_plugin_t
;
36 * private data of load_tester plugin
38 struct private_load_tester_plugin_t
{
41 * implements plugin interface
43 load_tester_plugin_t
public;
46 * load_tester configuration backend
48 load_tester_config_t
*config
;
51 * load_tester credential set implementation
53 load_tester_creds_t
*creds
;
56 * event handler, listens on bus
58 load_tester_listener_t
*listener
;
61 * number of iterations per thread
66 * number desired initiator threads
71 * currenly running initiators
76 * delay between initiations, in ms
81 * Throttle initiation if half-open IKE_SA count reached
86 * mutex to lock running field
91 * condvar to wait for initiators
99 static job_requeue_t
do_load_test(private_load_tester_plugin_t
*this)
101 int i
, s
= 0, ms
= 0;
103 this->mutex
->lock(this->mutex
);
105 this->mutex
->unlock(this->mutex
);
108 s
= this->delay
/ 1000;
109 ms
= this->delay
% 1000;
112 for (i
= 0; this->iterations
== 0 || i
< this->iterations
; i
++)
114 peer_cfg_t
*peer_cfg
;
115 child_cfg_t
*child_cfg
= NULL
;
116 enumerator_t
*enumerator
;
118 if (this->init_limit
)
120 while ((charon
->ike_sa_manager
->get_count(charon
->ike_sa_manager
) -
121 this->listener
->get_established(this->listener
)) >
135 peer_cfg
= charon
->backends
->get_peer_cfg_by_name(charon
->backends
,
141 enumerator
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
142 if (!enumerator
->enumerate(enumerator
, &child_cfg
))
144 enumerator
->destroy(enumerator
);
147 enumerator
->destroy(enumerator
);
149 charon
->controller
->initiate(charon
->controller
,
150 peer_cfg
, child_cfg
->get_ref(child_cfg
),
161 this->mutex
->lock(this->mutex
);
163 this->condvar
->signal(this->condvar
);
164 this->mutex
->unlock(this->mutex
);
165 return JOB_REQUEUE_NONE
;
168 METHOD(plugin_t
, get_name
, char*,
169 private_load_tester_plugin_t
*this)
171 return "load-tester";
174 METHOD(plugin_t
, destroy
, void,
175 private_load_tester_plugin_t
*this)
177 this->iterations
= -1;
178 this->mutex
->lock(this->mutex
);
179 while (this->running
)
181 this->condvar
->wait(this->condvar
, this->mutex
);
183 this->mutex
->unlock(this->mutex
);
184 hydra
->kernel_interface
->remove_ipsec_interface(hydra
->kernel_interface
,
185 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
186 charon
->backends
->remove_backend(charon
->backends
, &this->config
->backend
);
187 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->credential_set
);
188 charon
->bus
->remove_listener(charon
->bus
, &this->listener
->listener
);
189 this->config
->destroy(this->config
);
190 this->creds
->destroy(this->creds
);
191 this->listener
->destroy(this->listener
);
192 lib
->crypto
->remove_dh(lib
->crypto
,
193 (dh_constructor_t
)load_tester_diffie_hellman_create
);
194 this->mutex
->destroy(this->mutex
);
195 this->condvar
->destroy(this->condvar
);
202 plugin_t
*load_tester_plugin_create()
204 private_load_tester_plugin_t
*this;
205 u_int i
, shutdown_on
= 0;
207 if (!lib
->settings
->get_bool(lib
->settings
,
208 "charon.plugins.load-tester.enable", FALSE
))
210 DBG1(DBG_CFG
, "disabling load-tester plugin, not configured");
217 .get_name
= _get_name
,
218 .reload
= (void*)return_false
,
222 .delay
= lib
->settings
->get_int(lib
->settings
,
223 "charon.plugins.load-tester.delay", 0),
224 .iterations
= lib
->settings
->get_int(lib
->settings
,
225 "charon.plugins.load-tester.iterations", 1),
226 .initiators
= lib
->settings
->get_int(lib
->settings
,
227 "charon.plugins.load-tester.initiators", 0),
228 .init_limit
= lib
->settings
->get_int(lib
->settings
,
229 "charon.plugins.load-tester.init_limit", 0),
230 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
231 .condvar
= condvar_create(CONDVAR_TYPE_DEFAULT
),
232 .config
= load_tester_config_create(),
233 .creds
= load_tester_creds_create(),
236 lib
->crypto
->add_dh(lib
->crypto
, MODP_NULL
, plugin_name
,
237 (dh_constructor_t
)load_tester_diffie_hellman_create
);
238 charon
->backends
->add_backend(charon
->backends
, &this->config
->backend
);
239 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->credential_set
);
241 if (lib
->settings
->get_bool(lib
->settings
,
242 "charon.plugins.load-tester.shutdown_when_complete", 0))
244 shutdown_on
= this->iterations
* this->initiators
;
246 this->listener
= load_tester_listener_create(shutdown_on
);
247 charon
->bus
->add_listener(charon
->bus
, &this->listener
->listener
);
249 if (lib
->settings
->get_bool(lib
->settings
,
250 "charon.plugins.load-tester.fake_kernel", FALSE
))
252 hydra
->kernel_interface
->add_ipsec_interface(hydra
->kernel_interface
,
253 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
255 for (i
= 0; i
< this->initiators
; i
++)
257 lib
->processor
->queue_job(lib
->processor
, (job_t
*)
258 callback_job_create_with_prio((callback_job_cb_t
)do_load_test
,
259 this, NULL
, NULL
, JOB_PRIO_CRITICAL
));
261 return &this->public.plugin
;