Added a load tester strongswan.conf option to throttle initiation
authorMartin Willi <martin@revosec.ch>
Thu, 5 May 2011 10:40:53 +0000 (12:40 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:24:15 +0000 (15:24 +0200)
src/libcharon/plugins/load_tester/load_tester_listener.c
src/libcharon/plugins/load_tester/load_tester_listener.h
src/libcharon/plugins/load_tester/load_tester_plugin.c

index 328b551..2aa95a7 100644 (file)
@@ -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,
index b959929..2621798 100644 (file)
@@ -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);
index dbdf96f..f97b4c4 100644 (file)
@@ -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(),