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_listener.h"
23 #include <processing/jobs/delete_ike_sa_job.h>
25 typedef struct private_load_tester_listener_t private_load_tester_listener_t
;
28 * Private data of an load_tester_listener_t object
30 struct private_load_tester_listener_t
{
34 load_tester_listener_t
public;
37 * Delete IKE_SA after it has been established
39 bool delete_after_established
;
42 * Number of established SAs
47 * Shutdown the daemon if we have established this SA count
53 * Implementation of listener_t.ike_state_change
55 static bool ike_state_change(private_load_tester_listener_t
*this,
56 ike_sa_t
*ike_sa
, ike_sa_state_t state
)
58 if (state
== IKE_ESTABLISHED
)
60 ike_sa_id_t
*id
= ike_sa
->get_id(ike_sa
);
62 if (this->delete_after_established
)
64 charon
->processor
->queue_job(charon
->processor
,
65 (job_t
*)delete_ike_sa_job_create(id
, TRUE
));
68 if (id
->is_initiator(id
))
70 if (this->shutdown_on
== ++this->established
)
72 DBG1(DBG_CFG
, "load-test complete, raising SIGTERM");
73 pthread_kill(charon
->main_thread_id
, SIGTERM
);
81 * Implementation of load_tester_listener_t.destroy
83 static void destroy(private_load_tester_listener_t
*this)
88 load_tester_listener_t
*load_tester_listener_create(u_int shutdown_on
)
90 private_load_tester_listener_t
*this = malloc_thing(private_load_tester_listener_t
);
92 memset(&this->public.listener
, 0, sizeof(listener_t
));
93 this->public.listener
.ike_state_change
= (void*)ike_state_change
;
94 this->public.destroy
= (void(*) (load_tester_listener_t
*))destroy
;
96 this->delete_after_established
= lib
->settings
->get_bool(lib
->settings
,
97 "charon.plugins.load_tester.delete_after_established", FALSE
);
99 this->shutdown_on
= shutdown_on
;
100 this->established
= 0;
102 return &this->public;