aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-15 09:37:18 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-15 09:37:18 +0000
commitb92fefc699df523441c3b24d6d59cdc016af6bac (patch)
tree6710e2c32918af8d0f780f655acd5a1727f1fffa /src/testbed/testbed_api_testbed.c
parentfef4792abec19870be63c7922ada0ebd4397a7c1 (diff)
downloadgnunet-b92fefc699df523441c3b24d6d59cdc016af6bac.tar.gz
gnunet-b92fefc699df523441c3b24d6d59cdc016af6bac.zip
Call TestMaster callback upon timeout set through configuration
fixes #2833
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r--src/testbed/testbed_api_testbed.c72
1 files changed, 56 insertions, 16 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 3bd6f1db8..96be90e83 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -45,6 +45,11 @@
45 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 45 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
46 46
47/** 47/**
48 * The default setup timeout in seconds
49 */
50#define DEFAULT_SETUP_TIMEOUT 300
51
52/**
48 * DLL of operations 53 * DLL of operations
49 */ 54 */
50struct DLLOperation 55struct DLLOperation
@@ -229,6 +234,11 @@ struct RunContext
229 GNUNET_SCHEDULER_TaskIdentifier shutdown_run_task; 234 GNUNET_SCHEDULER_TaskIdentifier shutdown_run_task;
230 235
231 /** 236 /**
237 * Task to be run of a timeout
238 */
239 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
240
241 /**
232 * The event mask for the controller 242 * The event mask for the controller
233 */ 243 */
234 uint64_t event_mask; 244 uint64_t event_mask;
@@ -457,6 +467,11 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
457 GNUNET_SCHEDULER_cancel (rc->register_hosts_task); 467 GNUNET_SCHEDULER_cancel (rc->register_hosts_task);
458 rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK; 468 rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
459 } 469 }
470 if (GNUNET_SCHEDULER_NO_TASK != rc->timeout_task)
471 {
472 GNUNET_SCHEDULER_cancel (rc->timeout_task);
473 rc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
474 }
460 if (NULL != rc->reg_handle) 475 if (NULL != rc->reg_handle)
461 { 476 {
462 GNUNET_TESTBED_cancel_registration (rc->reg_handle); 477 GNUNET_TESTBED_cancel_registration (rc->reg_handle);
@@ -499,22 +514,16 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
499 514
500 515
501/** 516/**
502 * Task to call master task 517 * call test master callback
503 * 518 *
504 * @param cls the run context 519 * @param cls the run context
505 * @param tc the task context 520 * @param tc the task context
506 */ 521 */
507static void 522static void
508call_master (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 523call_master (struct RunContext *rc)
509{ 524{
510 struct RunContext *rc = cls; 525 GNUNET_SCHEDULER_cancel (rc->timeout_task);
511 526 rc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
512 if (NULL != rc->topology_operation)
513 {
514 DEBUG ("Overlay topology generated in %s\n", prof_time (rc));
515 GNUNET_TESTBED_operation_done (rc->topology_operation);
516 rc->topology_operation = NULL;
517 }
518 if (NULL != rc->test_master) 527 if (NULL != rc->test_master)
519 rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers); 528 rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers);
520} 529}
@@ -535,9 +544,11 @@ topology_completion_callback (void *cls, unsigned int nsuccess,
535{ 544{
536 struct RunContext *rc = cls; 545 struct RunContext *rc = cls;
537 546
547 DEBUG ("Overlay topology generated in %s\n", prof_time (rc));
548 GNUNET_TESTBED_operation_done (rc->topology_operation);
549 rc->topology_operation = NULL;
538 rc->state = RC_READY; 550 rc->state = RC_READY;
539 GNUNET_SCHEDULER_add_continuation (&call_master, rc, 551 call_master (rc);
540 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
541} 552}
542 553
543 554
@@ -706,8 +717,7 @@ call_cc:
706 } 717 }
707 } 718 }
708 rc->state = RC_READY; 719 rc->state = RC_READY;
709 GNUNET_SCHEDULER_add_continuation (&call_master, rc, 720 call_master (rc);
710 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
711} 721}
712 722
713 723
@@ -800,8 +810,8 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
800 810
801 if (status != GNUNET_OK) 811 if (status != GNUNET_OK)
802 { 812 {
803 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 813 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
804 "Controller crash detected. Shutting down.\n"); 814 _("Controller crash detected. Shutting down.\n"));
805 rc->cproc = NULL; 815 rc->cproc = NULL;
806 if (NULL != rc->peers) 816 if (NULL != rc->peers)
807 { 817 {
@@ -949,6 +959,26 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host,
949 959
950 960
951/** 961/**
962 * Task run upon timeout while setting up the testbed
963 *
964 * @param cls the RunContext
965 * @param tc the task context
966 */
967static void
968timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
969{
970 struct RunContext *rc = cls;
971
972 rc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
973 LOG (GNUNET_ERROR_TYPE_ERROR, _("Shutting down testbed due to timeout while setup.\n"));
974 shutdown_now (rc);
975 if (NULL != rc->test_master)
976 rc->test_master (rc->test_master_cls, 0, NULL);
977 rc->test_master = NULL;
978}
979
980
981/**
952 * Convenience method for running a testbed with 982 * Convenience method for running a testbed with
953 * a single call. Underlay and overlay topology 983 * a single call. Underlay and overlay topology
954 * are configured using the "UNDERLAY" and "OVERLAY" 984 * are configured using the "UNDERLAY" and "OVERLAY"
@@ -985,6 +1015,7 @@ GNUNET_TESTBED_run (const char *host_filename,
985{ 1015{
986 struct RunContext *rc; 1016 struct RunContext *rc;
987 char *topology; 1017 char *topology;
1018 struct GNUNET_TIME_Relative timeout;
988 unsigned long long random_links; 1019 unsigned long long random_links;
989 unsigned int hid; 1020 unsigned int hid;
990 unsigned int nhost; 1021 unsigned int nhost;
@@ -1106,6 +1137,15 @@ GNUNET_TESTBED_run (const char *host_filename,
1106 rc->cproc = 1137 rc->cproc =
1107 GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, rc->cfg, 1138 GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, rc->cfg,
1108 &controller_status_cb, rc); 1139 &controller_status_cb, rc);
1140 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
1141 "SETUP_TIMEOUT",
1142 &timeout))
1143 {
1144 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1145 DEFAULT_SETUP_TIMEOUT);
1146 }
1147 rc->timeout_task =
1148 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
1109 rc->shutdown_run_task = 1149 rc->shutdown_run_task =
1110 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_run, 1150 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_run,
1111 rc); 1151 rc);