added delete_after_established option

This commit is contained in:
Martin Willi
2008-11-06 14:07:46 +00:00
parent ebf0e20ae7
commit a70df08c9b
4 changed files with 140 additions and 1 deletions
+2 -1
View File
@@ -9,7 +9,8 @@ libstrongswan_load_tester_la_SOURCES = \
load_tester_plugin.c load_tester_plugin.h \
load_tester_config.c load_tester_config.h \
load_tester_creds.c load_tester_creds.h \
load_tester_ipsec.c load_tester_ipsec.h
load_tester_ipsec.c load_tester_ipsec.h \
load_tester_listener.c load_tester_listener.h
libstrongswan_load_tester_la_LDFLAGS = -module
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* $Id$
*/
#include "load_tester_listener.h"
#include <daemon.h>
#include <processing/jobs/delete_ike_sa_job.h>
typedef struct private_load_tester_listener_t private_load_tester_listener_t;
/**
* Private data of an load_tester_listener_t object
*/
struct private_load_tester_listener_t {
/**
* Public part
*/
load_tester_listener_t public;
/**
* Delete IKE_SA after it has been established
*/
bool delete_after_established;
};
/**
* Implementation of listener_t.ike_state_change
*/
static bool ike_state_change(private_load_tester_listener_t *this,
ike_sa_t *ike_sa, ike_sa_state_t state)
{
if (this->delete_after_established && state == IKE_ESTABLISHED)
{
charon->processor->queue_job(charon->processor,
(job_t*)delete_ike_sa_job_create(ike_sa->get_id(ike_sa), TRUE));
}
return TRUE;
}
/**
* Implementation of load_tester_listener_t.destroy
*/
static void destroy(private_load_tester_listener_t *this)
{
free(this);
}
load_tester_listener_t *load_tester_listener_create()
{
private_load_tester_listener_t *this = malloc_thing(private_load_tester_listener_t);
memset(&this->public.listener, 0, sizeof(listener_t));
this->public.listener.ike_state_change = (void*)ike_state_change;
this->public.destroy = (void(*) (load_tester_listener_t*))destroy;
this->delete_after_established = lib->settings->get_bool(lib->settings,
"charon.plugins.load_tester.delete_after_established", FALSE);
return &this->public;
}
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* $Id$
*/
/**
* @defgroup load_tester_listener_t load_tester_listener
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_LISTENER_H_
#define LOAD_TESTER_LISTENER_H_
#include <bus/bus.h>
typedef struct load_tester_listener_t load_tester_listener_t;
/**
* Provide hard-coded credentials for load testing.
*/
struct load_tester_listener_t {
/**
* Implements listener set interface.
*/
listener_t listener;
/**
* Destroy the backend.
*/
void (*destroy)(load_tester_listener_t *this);
};
/**
* Create a listener to handle special events during load test
*
* @return listener
*/
load_tester_listener_t *load_tester_listener_create();
#endif /* LOAD_TESTER_LISTENER_H_ @}*/
@@ -19,6 +19,7 @@
#include "load_tester_config.h"
#include "load_tester_creds.h"
#include "load_tester_ipsec.h"
#include "load_tester_listener.h"
#include <unistd.h>
@@ -47,6 +48,11 @@ struct private_load_tester_plugin_t {
*/
load_tester_creds_t *creds;
/**
* event handler, listens on bus
*/
load_tester_listener_t *listener;
/**
* number of iterations per thread
*/
@@ -122,8 +128,10 @@ static void destroy(private_load_tester_plugin_t *this)
(kernel_ipsec_constructor_t)load_tester_ipsec_create);
charon->backends->remove_backend(charon->backends, &this->config->backend);
charon->credentials->remove_set(charon->credentials, &this->creds->credential_set);
charon->bus->remove_listener(charon->bus, &this->listener->listener);
this->config->destroy(this->config);
this->creds->destroy(this->creds);
this->listener->destroy(this->listener);
free(this);
}
@@ -139,8 +147,10 @@ plugin_t *plugin_create()
this->config = load_tester_config_create();
this->creds = load_tester_creds_create();
this->listener = load_tester_listener_create();
charon->backends->add_backend(charon->backends, &this->config->backend);
charon->credentials->add_set(charon->credentials, &this->creds->credential_set);
charon->bus->add_listener(charon->bus, &this->listener->listener);
if (lib->settings->get_bool(lib->settings,
"charon.plugins.load_tester.fake_kernel", FALSE))