diff options
author | Martin Willi <martin@revosec.ch> | 2011-05-05 12:40:53 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-05-16 15:24:15 +0200 |
commit | c8972da7571718d40cbf48b66f14d5003a3aea31 (patch) | |
tree | 93a451ce35dfca56d30523bc9ceec873f70e069e /src/libcharon | |
parent | 86067256762ee8660c04c9b3db45c2351dc5d5c8 (diff) | |
download | strongswan-c8972da7571718d40cbf48b66f14d5003a3aea31.tar.bz2 strongswan-c8972da7571718d40cbf48b66f14d5003a3aea31.tar.xz |
Added a load tester strongswan.conf option to throttle initiation
Diffstat (limited to 'src/libcharon')
3 files changed, 51 insertions, 6 deletions
diff --git a/src/libcharon/plugins/load_tester/load_tester_listener.c b/src/libcharon/plugins/load_tester/load_tester_listener.c index 328b5510a..2aa95a7af 100644 --- a/src/libcharon/plugins/load_tester/load_tester_listener.c +++ b/src/libcharon/plugins/load_tester/load_tester_listener.c @@ -47,12 +47,15 @@ struct private_load_tester_listener_t { u_int shutdown_on; }; -METHOD(listener_t, ike_state_change, bool, - private_load_tester_listener_t *this, ike_sa_t *ike_sa, ike_sa_state_t state) +METHOD(listener_t, ike_updown, bool, + private_load_tester_listener_t *this, ike_sa_t *ike_sa, bool up) { - if (state == IKE_ESTABLISHED) + if (up) { - ike_sa_id_t *id = ike_sa->get_id(ike_sa); + ike_sa_id_t *id; + + this->established++; + id = ike_sa->get_id(ike_sa); if (this->delete_after_established) { @@ -62,16 +65,26 @@ METHOD(listener_t, ike_state_change, bool, if (id->is_initiator(id)) { - if (this->shutdown_on == ++this->established) + if (this->shutdown_on == this->established) { DBG1(DBG_CFG, "load-test complete, raising SIGTERM"); kill(0, SIGTERM); } } } + else + { + this->established--; + } return TRUE; } +METHOD(load_tester_listener_t, get_established, u_int, + private_load_tester_listener_t *this) +{ + return this->established; +} + METHOD(load_tester_listener_t, destroy, void, private_load_tester_listener_t *this) { @@ -85,8 +98,9 @@ load_tester_listener_t *load_tester_listener_create(u_int shutdown_on) INIT(this, .public = { .listener = { - .ike_state_change = _ike_state_change, + .ike_updown = _ike_updown, }, + .get_established = _get_established, .destroy = _destroy, }, .delete_after_established = lib->settings->get_bool(lib->settings, diff --git a/src/libcharon/plugins/load_tester/load_tester_listener.h b/src/libcharon/plugins/load_tester/load_tester_listener.h index b9599294c..2621798c8 100644 --- a/src/libcharon/plugins/load_tester/load_tester_listener.h +++ b/src/libcharon/plugins/load_tester/load_tester_listener.h @@ -36,6 +36,13 @@ struct load_tester_listener_t { listener_t listener; /** + * Get the number of established IKE_SAs. + * + * @return number of SAs currently established + */ + u_int (*get_established)(load_tester_listener_t *this); + + /** * Destroy the backend. */ void (*destroy)(load_tester_listener_t *this); diff --git a/src/libcharon/plugins/load_tester/load_tester_plugin.c b/src/libcharon/plugins/load_tester/load_tester_plugin.c index dbdf96f82..f97b4c4a9 100644 --- a/src/libcharon/plugins/load_tester/load_tester_plugin.c +++ b/src/libcharon/plugins/load_tester/load_tester_plugin.c @@ -78,6 +78,11 @@ struct private_load_tester_plugin_t { int delay; /** + * Throttle initiation if half-open IKE_SA count reached + */ + int init_limit; + + /** * mutex to lock running field */ mutex_t *mutex; @@ -113,6 +118,23 @@ static job_requeue_t do_load_test(private_load_tester_plugin_t *this) child_cfg_t *child_cfg = NULL; enumerator_t *enumerator; + if (this->init_limit) + { + while ((charon->ike_sa_manager->get_count(charon->ike_sa_manager) - + this->listener->get_established(this->listener)) > + this->init_limit) + { + if (s) + { + sleep(s); + } + if (ms) + { + usleep(ms * 1000); + } + } + } + peer_cfg = charon->backends->get_peer_cfg_by_name(charon->backends, "load-test"); if (!peer_cfg) @@ -206,6 +228,8 @@ plugin_t *load_tester_plugin_create() "charon.plugins.load-tester.iterations", 1), .initiators = lib->settings->get_int(lib->settings, "charon.plugins.load-tester.initiators", 0), + .init_limit = lib->settings->get_int(lib->settings, + "charon.plugins.load-tester.init_limit", 0), .mutex = mutex_create(MUTEX_TYPE_DEFAULT), .condvar = condvar_create(CONDVAR_TYPE_DEFAULT), .config = load_tester_config_create(), |