diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-01 21:12:56 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-01 21:12:56 +0000 |
commit | 55966806a86ad5f28be24407648e0e707e8fef80 (patch) | |
tree | afa04daf3e127d274bff5f06630a4140d6cd7307 /src/testbed/testbed_api_testbed.c | |
parent | 13361222d8b8d47611d67c240ae2329cdc999a7e (diff) | |
download | gnunet-55966806a86ad5f28be24407648e0e707e8fef80.tar.gz gnunet-55966806a86ad5f28be24407648e0e707e8fef80.zip |
topology option support for GNUNET_TESTBED_run() via configuration
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 165 |
1 files changed, 156 insertions, 9 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index a8f12f361..0987d9eb5 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -87,9 +87,11 @@ enum State | |||
87 | RC_INIT = 0, | 87 | RC_INIT = 0, |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Peers have been started | 90 | * The testbed run is ready and the master callback can be called now. At this |
91 | * time the peers are all started and if a topology is provided in the | ||
92 | * configuration the topology would have been attempted | ||
91 | */ | 93 | */ |
92 | RC_PEERS_STARTED, | 94 | RC_READY, |
93 | 95 | ||
94 | /** | 96 | /** |
95 | * Peers are stopped | 97 | * Peers are stopped |
@@ -159,6 +161,12 @@ struct RunContext | |||
159 | struct GNUNET_TESTBED_Peer **peers; | 161 | struct GNUNET_TESTBED_Peer **peers; |
160 | 162 | ||
161 | /** | 163 | /** |
164 | * The topology generation operation. Will be null if no topology is set in | ||
165 | * the configuration | ||
166 | */ | ||
167 | struct GNUNET_TESTBED_Operation *topology_operation; | ||
168 | |||
169 | /** | ||
162 | * The event mask for the controller | 170 | * The event mask for the controller |
163 | */ | 171 | */ |
164 | uint64_t event_mask; | 172 | uint64_t event_mask; |
@@ -169,6 +177,11 @@ struct RunContext | |||
169 | enum State state; | 177 | enum State state; |
170 | 178 | ||
171 | /** | 179 | /** |
180 | * The topology which has to be achieved with the peers started in this context | ||
181 | */ | ||
182 | enum GNUNET_TESTBED_TopologyOption topology; | ||
183 | |||
184 | /** | ||
172 | * Current peer count for an operation; Set this to 0 and increment for each | 185 | * Current peer count for an operation; Set this to 0 and increment for each |
173 | * successful operation on a peer | 186 | * successful operation on a peer |
174 | */ | 187 | */ |
@@ -179,6 +192,17 @@ struct RunContext | |||
179 | */ | 192 | */ |
180 | unsigned int num_peers; | 193 | unsigned int num_peers; |
181 | 194 | ||
195 | /** | ||
196 | * counter to count overlay connect attempts. This counter includes both | ||
197 | * successful and failed overlay connects | ||
198 | */ | ||
199 | unsigned int oc_count; | ||
200 | |||
201 | /** | ||
202 | * Expected overlay connects. Should be zero if no topology is relavant | ||
203 | */ | ||
204 | unsigned int num_oc; | ||
205 | |||
182 | }; | 206 | }; |
183 | 207 | ||
184 | 208 | ||
@@ -281,6 +305,28 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
281 | 305 | ||
282 | 306 | ||
283 | /** | 307 | /** |
308 | * Task to call master task | ||
309 | * | ||
310 | * @param cls the run context | ||
311 | * @param tc the task context | ||
312 | */ | ||
313 | static void | ||
314 | call_master (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
315 | { | ||
316 | struct RunContext *rc = cls; | ||
317 | |||
318 | if (NULL != rc->topology_operation) | ||
319 | { | ||
320 | GNUNET_TESTBED_operation_done (rc->topology_operation); | ||
321 | rc->topology_operation = NULL; | ||
322 | } | ||
323 | if (NULL != rc->master) | ||
324 | GNUNET_SCHEDULER_add_continuation (rc->master, rc->master_cls, | ||
325 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
284 | * Signature of the event handler function called by the | 330 | * Signature of the event handler function called by the |
285 | * respective event controller. | 331 | * respective event controller. |
286 | * | 332 | * |
@@ -294,7 +340,25 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
294 | struct DLLOperation *dll_op; | 340 | struct DLLOperation *dll_op; |
295 | unsigned int peer_id; | 341 | unsigned int peer_id; |
296 | 342 | ||
297 | 343 | if (NULL != rc->topology_operation) | |
344 | { | ||
345 | switch (event->type) | ||
346 | { | ||
347 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
348 | case GNUNET_TESTBED_ET_CONNECT: | ||
349 | rc->oc_count++; | ||
350 | break; | ||
351 | default: | ||
352 | GNUNET_assert (0); | ||
353 | } | ||
354 | if (rc->oc_count == rc->num_oc) | ||
355 | { | ||
356 | rc->state = RC_READY; | ||
357 | GNUNET_SCHEDULER_add_continuation (&call_master, rc, | ||
358 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
359 | } | ||
360 | return; | ||
361 | } | ||
298 | if ((RC_INIT != rc->state) && | 362 | if ((RC_INIT != rc->state) && |
299 | ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) || | 363 | ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) || |
300 | (GNUNET_TESTBED_ET_PEER_STOP == event->type))) | 364 | (GNUNET_TESTBED_ET_PEER_STOP == event->type))) |
@@ -318,7 +382,7 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
318 | return; | 382 | return; |
319 | switch (rc->state) | 383 | switch (rc->state) |
320 | { | 384 | { |
321 | case RC_PEERS_STARTED: | 385 | case RC_READY: |
322 | rc->state = RC_PEERS_STOPPED; | 386 | rc->state = RC_PEERS_STOPPED; |
323 | rc->peer_count = 0; | 387 | rc->peer_count = 0; |
324 | for (peer_id = 0; peer_id < rc->num_peers; peer_id++) | 388 | for (peer_id = 0; peer_id < rc->num_peers; peer_id++) |
@@ -359,10 +423,32 @@ call_cc: | |||
359 | if (rc->peer_count < rc->num_peers) | 423 | if (rc->peer_count < rc->num_peers) |
360 | return; | 424 | return; |
361 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers started successfully\n"); | 425 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers started successfully\n"); |
362 | rc->state = RC_PEERS_STARTED; | 426 | if (GNUNET_TESTBED_TOPOLOGY_OPTION_END != rc->topology) |
363 | if (NULL != rc->master) | 427 | { |
364 | GNUNET_SCHEDULER_add_continuation (rc->master, rc->master_cls, | 428 | if (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology) |
365 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 429 | rc->topology_operation = |
430 | GNUNET_TESTBED_overlay_configure_topology (dll_op, | ||
431 | rc->num_peers, | ||
432 | rc->peers, | ||
433 | rc->topology, | ||
434 | rc->num_oc, | ||
435 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
436 | else | ||
437 | rc->topology_operation = | ||
438 | GNUNET_TESTBED_overlay_configure_topology (dll_op, | ||
439 | rc->num_peers, | ||
440 | rc->peers, | ||
441 | rc->topology, | ||
442 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
443 | if (NULL == rc->topology_operation) | ||
444 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
445 | "Not generating topology. Check number of peers\n"); | ||
446 | else | ||
447 | return; | ||
448 | } | ||
449 | rc->state = RC_READY; | ||
450 | GNUNET_SCHEDULER_add_continuation (&call_master, rc, | ||
451 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
366 | } | 452 | } |
367 | 453 | ||
368 | 454 | ||
@@ -393,6 +479,8 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
393 | event_mask = rc->event_mask; | 479 | event_mask = rc->event_mask; |
394 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 480 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
395 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 481 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
482 | if (rc->topology < GNUNET_TESTBED_TOPOLOGY_OPTION_END) | ||
483 | event_mask |= GNUNET_TESTBED_ET_CONNECT; | ||
396 | rc->c = | 484 | rc->c = |
397 | GNUNET_TESTBED_controller_connect (cfg, rc->h, event_mask, &event_cb, rc); | 485 | GNUNET_TESTBED_controller_connect (cfg, rc->h, event_mask, &event_cb, rc); |
398 | rc->peers = | 486 | rc->peers = |
@@ -427,6 +515,13 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
427 | { | 515 | { |
428 | if (NULL != rc->peers) | 516 | if (NULL != rc->peers) |
429 | { | 517 | { |
518 | if (NULL != rc->topology_operation) | ||
519 | { | ||
520 | GNUNET_TESTBED_operation_done (rc->topology_operation); | ||
521 | rc->topology_operation = NULL; | ||
522 | } | ||
523 | if (RC_INIT == rc->state) | ||
524 | rc->state = RC_READY; /* Even though we haven't called the master callback */ | ||
430 | rc->peer_count = 0; | 525 | rc->peer_count = 0; |
431 | /* Check if some peers are stopped */ | 526 | /* Check if some peers are stopped */ |
432 | for (peer = 0; peer < rc->num_peers; peer++) | 527 | for (peer = 0; peer < rc->num_peers; peer++) |
@@ -506,6 +601,8 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
506 | GNUNET_SCHEDULER_Task master, void *master_cls) | 601 | GNUNET_SCHEDULER_Task master, void *master_cls) |
507 | { | 602 | { |
508 | struct RunContext *rc; | 603 | struct RunContext *rc; |
604 | char *topology; | ||
605 | unsigned long long random_links; | ||
509 | 606 | ||
510 | GNUNET_break (NULL == host_filename); /* Currently we do not support host | 607 | GNUNET_break (NULL == host_filename); /* Currently we do not support host |
511 | * files */ | 608 | * files */ |
@@ -527,6 +624,49 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
527 | rc->master = master; | 624 | rc->master = master; |
528 | rc->master_cls = master_cls; | 625 | rc->master_cls = master_cls; |
529 | rc->state = RC_INIT; | 626 | rc->state = RC_INIT; |
627 | rc->topology = GNUNET_TESTBED_TOPOLOGY_OPTION_END; | ||
628 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", | ||
629 | "OVERLAY_TOPOLOGY", | ||
630 | &topology)) | ||
631 | { | ||
632 | if (0 == strcmp (topology, "RANDOM")) | ||
633 | { | ||
634 | rc->topology = GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI; | ||
635 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed", | ||
636 | "OVERLAY_RANDOM_LINKS", | ||
637 | &random_links)) | ||
638 | { | ||
639 | /* OVERLAY option RANDOM requires OVERLAY_RANDOM_LINKS option to */ | ||
640 | /* be set to the number of random links to be established */ | ||
641 | GNUNET_break (0); | ||
642 | GNUNET_free (rc); | ||
643 | GNUNET_free (topology); | ||
644 | return; | ||
645 | } | ||
646 | if (random_links > UINT32_MAX) | ||
647 | { | ||
648 | GNUNET_break (0); /* Too big number */ | ||
649 | GNUNET_free (rc); | ||
650 | GNUNET_free (topology); | ||
651 | return; | ||
652 | } | ||
653 | rc->num_oc = (unsigned int) random_links; | ||
654 | } | ||
655 | else if (0 == strcasecmp (topology, "CLIQUE")) | ||
656 | { | ||
657 | rc->topology = GNUNET_TESTBED_TOPOLOGY_CLIQUE; | ||
658 | rc->num_oc = num_peers * (num_peers - 1); | ||
659 | } | ||
660 | else if (0 == strcasecmp (topology, "LINE")) | ||
661 | { | ||
662 | rc->topology = GNUNET_TESTBED_TOPOLOGY_LINE; | ||
663 | rc->num_oc = num_peers - 1; | ||
664 | } | ||
665 | else | ||
666 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
667 | "Unknown topology %s given in configuration\n", topology); | ||
668 | GNUNET_free (topology); | ||
669 | } | ||
530 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 670 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
531 | &shutdown_run_task, rc); | 671 | &shutdown_run_task, rc); |
532 | } | 672 | } |
@@ -558,6 +698,7 @@ GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, | |||
558 | enum GNUNET_TESTBED_TopologyOption underlay_topology, | 698 | enum GNUNET_TESTBED_TopologyOption underlay_topology, |
559 | va_list va) | 699 | va_list va) |
560 | { | 700 | { |
701 | GNUNET_assert (underlay_topology < GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
561 | GNUNET_break (0); | 702 | GNUNET_break (0); |
562 | return NULL; | 703 | return NULL; |
563 | } | 704 | } |
@@ -588,7 +729,13 @@ GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller, | |||
588 | enum GNUNET_TESTBED_TopologyOption underlay_topology, | 729 | enum GNUNET_TESTBED_TopologyOption underlay_topology, |
589 | ...) | 730 | ...) |
590 | { | 731 | { |
591 | GNUNET_break (0); | 732 | struct GNUNET_TESTBED_Testbed *testbed; |
733 | va_list vargs; | ||
734 | |||
735 | va_start (vargs, underlay_topology); | ||
736 | testbed = GNUNET_TESTBED_create_va (controller, num_hosts, hosts, num_peers, | ||
737 | peer_cfg, underlay_topology, vargs); | ||
738 | va_end (vargs); | ||
592 | return NULL; | 739 | return NULL; |
593 | } | 740 | } |
594 | 741 | ||