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
18 #include "load_tester_plugin.h"
19 #include "load_tester_config.h"
20 #include "load_tester_creds.h"
21 #include "load_tester_ipsec.h"
22 #include "load_tester_listener.h"
23 #include "load_tester_diffie_hellman.h"
28 #include <processing/jobs/callback_job.h>
29 #include <utils/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 * currenly running initiators
74 * delay between initiations, in ms
79 * mutex to lock running field
84 * condvar to wait for initiators
92 static job_requeue_t
do_load_test(private_load_tester_plugin_t
*this)
95 child_cfg_t
*child_cfg
= NULL
;;
96 enumerator_t
*enumerator
;
99 this->mutex
->lock(this->mutex
);
102 this->running
= this->initiators
;
104 this->mutex
->unlock(this->mutex
);
107 s
= this->delay
/ 1000;
108 ms
= this->delay
% 1000;
110 peer_cfg
= charon
->backends
->get_peer_cfg_by_name(charon
->backends
,
114 enumerator
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
115 if (enumerator
->enumerate(enumerator
, &child_cfg
))
117 child_cfg
->get_ref(child_cfg
);
119 enumerator
->destroy(enumerator
);
123 for (i
= 0; this->iterations
== 0 || i
< this->iterations
; i
++)
125 charon
->controller
->initiate(charon
->controller
,
126 peer_cfg
->get_ref(peer_cfg
), child_cfg
->get_ref(child_cfg
),
138 child_cfg
->destroy(child_cfg
);
140 peer_cfg
->destroy(peer_cfg
);
142 this->mutex
->lock(this->mutex
);
144 this->mutex
->unlock(this->mutex
);
145 this->condvar
->signal(this->condvar
);
146 return JOB_REQUEUE_NONE
;
150 * Implementation of plugin_t.destroy
152 static void destroy(private_load_tester_plugin_t
*this)
154 this->iterations
= -1;
155 this->mutex
->lock(this->mutex
);
156 while (this->running
)
158 this->condvar
->wait(this->condvar
, this->mutex
);
160 this->mutex
->unlock(this->mutex
);
161 charon
->kernel_interface
->remove_ipsec_interface(charon
->kernel_interface
,
162 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
163 charon
->backends
->remove_backend(charon
->backends
, &this->config
->backend
);
164 charon
->credentials
->remove_set(charon
->credentials
, &this->creds
->credential_set
);
165 charon
->bus
->remove_listener(charon
->bus
, &this->listener
->listener
);
166 this->config
->destroy(this->config
);
167 this->creds
->destroy(this->creds
);
168 this->listener
->destroy(this->listener
);
169 lib
->crypto
->remove_dh(lib
->crypto
,
170 (dh_constructor_t
)load_tester_diffie_hellman_create
);
171 this->mutex
->destroy(this->mutex
);
172 this->condvar
->destroy(this->condvar
);
179 plugin_t
*plugin_create()
181 private_load_tester_plugin_t
*this = malloc_thing(private_load_tester_plugin_t
);
184 this->public.plugin
.destroy
= (void(*)(plugin_t
*))destroy
;
186 lib
->crypto
->add_dh(lib
->crypto
, MODP_NULL
,
187 (dh_constructor_t
)load_tester_diffie_hellman_create
);
189 this->mutex
= mutex_create(MUTEX_DEFAULT
);
190 this->condvar
= condvar_create(CONDVAR_DEFAULT
);
191 this->config
= load_tester_config_create();
192 this->creds
= load_tester_creds_create();
193 this->listener
= load_tester_listener_create();
194 charon
->backends
->add_backend(charon
->backends
, &this->config
->backend
);
195 charon
->credentials
->add_set(charon
->credentials
, &this->creds
->credential_set
);
196 charon
->bus
->add_listener(charon
->bus
, &this->listener
->listener
);
198 if (lib
->settings
->get_bool(lib
->settings
,
199 "charon.plugins.load_tester.fake_kernel", FALSE
))
201 charon
->kernel_interface
->add_ipsec_interface(charon
->kernel_interface
,
202 (kernel_ipsec_constructor_t
)load_tester_ipsec_create
);
204 this->delay
= lib
->settings
->get_int(lib
->settings
,
205 "charon.plugins.load_tester.delay", 0);
206 this->iterations
= lib
->settings
->get_int(lib
->settings
,
207 "charon.plugins.load_tester.iterations", 1);
208 this->initiators
= lib
->settings
->get_int(lib
->settings
,
209 "charon.plugins.load_tester.initiators", 0);
211 for (i
= 0; i
< this->initiators
; i
++)
213 charon
->processor
->queue_job(charon
->processor
,
214 (job_t
*)callback_job_create((callback_job_cb_t
)do_load_test
,
217 return &this->public.plugin
;