Annotation of embedaddon/strongswan/src/libcharon/plugins/load_tester/load_tester_listener.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2008 Martin Willi
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 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>.
! 9: *
! 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
! 13: * for more details.
! 14: */
! 15:
! 16: #include "load_tester_listener.h"
! 17:
! 18: #include <signal.h>
! 19:
! 20: #include <daemon.h>
! 21: #include <processing/jobs/delete_ike_sa_job.h>
! 22:
! 23: typedef struct private_load_tester_listener_t private_load_tester_listener_t;
! 24:
! 25: /**
! 26: * Private data of an load_tester_listener_t object
! 27: */
! 28: struct private_load_tester_listener_t {
! 29: /**
! 30: * Public part
! 31: */
! 32: load_tester_listener_t public;
! 33:
! 34: /**
! 35: * Delete IKE_SA after it has been established
! 36: */
! 37: bool delete_after_established;
! 38:
! 39: /**
! 40: * Number of established SAs
! 41: */
! 42: u_int established;
! 43:
! 44: /**
! 45: * Number of terminated SAs
! 46: */
! 47: u_int terminated;
! 48:
! 49: /**
! 50: * Shutdown the daemon if we have established this SA count
! 51: */
! 52: u_int shutdown_on;
! 53:
! 54: /**
! 55: * Configuration backend
! 56: */
! 57: load_tester_config_t *config;
! 58: };
! 59:
! 60: METHOD(listener_t, ike_updown, bool,
! 61: private_load_tester_listener_t *this, ike_sa_t *ike_sa, bool up)
! 62: {
! 63: if (up)
! 64: {
! 65: ike_sa_id_t *id = ike_sa->get_id(ike_sa);
! 66:
! 67: this->established++;
! 68:
! 69: if (this->delete_after_established)
! 70: {
! 71: lib->processor->queue_job(lib->processor,
! 72: (job_t*)delete_ike_sa_job_create(id, TRUE));
! 73: }
! 74:
! 75: if (id->is_initiator(id))
! 76: {
! 77: if (this->shutdown_on == this->established)
! 78: {
! 79: DBG1(DBG_CFG, "load-test complete, raising SIGTERM");
! 80: kill(0, SIGTERM);
! 81: }
! 82: }
! 83: }
! 84: else
! 85: {
! 86: this->terminated++;
! 87: }
! 88: return TRUE;
! 89: }
! 90:
! 91: METHOD(listener_t, ike_state_change, bool,
! 92: private_load_tester_listener_t *this, ike_sa_t *ike_sa, ike_sa_state_t state)
! 93: {
! 94: if (state == IKE_DESTROYING)
! 95: {
! 96: this->config->delete_ip(this->config, ike_sa->get_my_host(ike_sa));
! 97: }
! 98: return TRUE;
! 99: }
! 100:
! 101: METHOD(load_tester_listener_t, get_established, u_int,
! 102: private_load_tester_listener_t *this)
! 103: {
! 104: return this->established - this->terminated;
! 105: }
! 106:
! 107: METHOD(load_tester_listener_t, destroy, void,
! 108: private_load_tester_listener_t *this)
! 109: {
! 110: free(this);
! 111: }
! 112:
! 113: load_tester_listener_t *load_tester_listener_create(u_int shutdown_on,
! 114: load_tester_config_t *config)
! 115: {
! 116: private_load_tester_listener_t *this;
! 117:
! 118: INIT(this,
! 119: .public = {
! 120: .listener = {
! 121: .ike_updown = _ike_updown,
! 122: .ike_state_change = _ike_state_change,
! 123: },
! 124: .get_established = _get_established,
! 125: .destroy = _destroy,
! 126: },
! 127: .delete_after_established = lib->settings->get_bool(lib->settings,
! 128: "%s.plugins.load-tester.delete_after_established", FALSE,
! 129: lib->ns),
! 130: .shutdown_on = shutdown_on,
! 131: .config = config,
! 132: );
! 133:
! 134: return &this->public;
! 135: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>