added delete_after_established option
authorMartin Willi <martin@strongswan.org>
Thu, 6 Nov 2008 14:07:46 +0000 (14:07 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 6 Nov 2008 14:07:46 +0000 (14:07 -0000)
src/charon/plugins/load_tester/Makefile.am
src/charon/plugins/load_tester/load_tester_listener.c [new file with mode: 0644]
src/charon/plugins/load_tester/load_tester_listener.h [new file with mode: 0644]
src/charon/plugins/load_tester/load_tester_plugin.c

index 7e539dd..88a6b68 100644 (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
 
diff --git a/src/charon/plugins/load_tester/load_tester_listener.c b/src/charon/plugins/load_tester/load_tester_listener.c
new file mode 100644 (file)
index 0000000..991408a
--- /dev/null
@@ -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;
+}
+
diff --git a/src/charon/plugins/load_tester/load_tester_listener.h b/src/charon/plugins/load_tester/load_tester_listener.h
new file mode 100644 (file)
index 0000000..28bb57d
--- /dev/null
@@ -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_ @}*/
index 9dbfcd6..88b240a 100644 (file)
@@ -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>
 
@@ -48,6 +49,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
         */
        int iterations;
@@ -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))