aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-nse-profiler.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-18 17:03:57 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-18 17:03:57 +0000
commitcb7ec932e36aec4b8c00bb8c71dc3068dc368865 (patch)
treedfdbe0d9f65176480899de2c785c304e38b3f7eb /src/nse/gnunet-nse-profiler.c
parent6cc556bed0898dcdb168248658574862920818da (diff)
downloadgnunet-cb7ec932e36aec4b8c00bb8c71dc3068dc368865.tar.gz
gnunet-cb7ec932e36aec4b8c00bb8c71dc3068dc368865.zip
use testbed helper functions and lose old code
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r--src/nse/gnunet-nse-profiler.c586
1 files changed, 220 insertions, 366 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index cd1e147ad..5777916a0 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -34,6 +34,18 @@
34#include "gnunet_testbed_service.h" 34#include "gnunet_testbed_service.h"
35#include "gnunet_nse_service.h" 35#include "gnunet_nse_service.h"
36 36
37/**
38 * Generic loggins shorthand
39 */
40#define LOG(kind,...) \
41 GNUNET_log (kind, __VA_ARGS__)
42
43/**
44 * Debug logging shorthand
45 */
46#define LOG_DEBUG(...) \
47 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
48
37 49
38/** 50/**
39 * Information we track for a peer in the testbed. 51 * Information we track for a peer in the testbed.
@@ -60,20 +72,6 @@ struct NSEPeer
60 */ 72 */
61 struct GNUNET_TESTBED_Operation *nse_op; 73 struct GNUNET_TESTBED_Operation *nse_op;
62 74
63 /**
64 * Handle to statistics service of the peer.
65 */
66 struct GNUNET_STATISTICS_Handle *stats;
67
68 /**
69 * Testbed operation to connect to statistics service.
70 */
71 struct GNUNET_TESTBED_Operation *stats_op;
72
73 /**
74 * Task scheduled to get statistics from this peer.
75 */
76 GNUNET_SCHEDULER_TaskIdentifier stats_task;
77}; 75};
78 76
79 77
@@ -111,6 +109,29 @@ struct StatsContext
111 109
112 110
113/** 111/**
112 * Operation map entry
113 */
114struct OpListEntry
115{
116 /**
117 * DLL next ptr
118 */
119 struct OpListEntry *next;
120
121 /**
122 * DLL prev ptr
123 */
124 struct OpListEntry *prev;
125
126 /**
127 * The testbed operation
128 */
129 struct GNUNET_TESTBED_Operation *op;
130
131};
132
133
134/**
114 * Head of DLL of peers we monitor closely. 135 * Head of DLL of peers we monitor closely.
115 */ 136 */
116static struct NSEPeer *peer_head; 137static struct NSEPeer *peer_head;
@@ -136,11 +157,6 @@ static int verbose;
136static char *hosts_file; 157static char *hosts_file;
137 158
138/** 159/**
139 * IP address of this system, as seen by the rest of the system (configuration option)
140 */
141static char *controller_ip;
142
143/**
144 * Maximum number of peers in the test. 160 * Maximum number of peers in the test.
145 */ 161 */
146static unsigned int num_peers; 162static unsigned int num_peers;
@@ -217,41 +233,19 @@ static char *data_filename;
217static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 }; 233static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 };
218 234
219/** 235/**
220 * How often do we query for statistics during a round? 236 * DLL head for operation list
221 * Default: 1 s.
222 */
223static struct GNUNET_TIME_Relative interval = { 1000 };
224
225/**
226 * Name of the file where we write the topology for each round; NULL for
227 * none.
228 */ 237 */
229static char *topology_file; 238static struct OpListEntry *oplist_head;
230 239
231/** 240/**
232 * List of hosts we use for the testbed. 241 * DLL tail for operation list
233 */ 242 */
234static struct GNUNET_TESTBED_Host **hosts; 243static struct OpListEntry *oplist_tail;
235 244
236/** 245/**
237 * Size of the 'hosts' array. 246 * The get stats operation
238 */ 247 */
239static unsigned int num_hosts; 248static struct GNUNET_TESTBED_Operation *get_stats_op;
240
241/**
242 * Handle to the master controller.
243 */
244static struct GNUNET_TESTBED_Controller *controller;
245
246/**
247 * Controller start handle.
248 */
249static struct GNUNET_TESTBED_ControllerProc *copro;
250
251/* /\** */
252/* * Testbed handle. */
253/* *\/ */
254/* static struct GNUNET_TESTBED_Testbed *testbed; */
255 249
256 250
257/** 251/**
@@ -262,18 +256,21 @@ static void
262close_monitor_connections () 256close_monitor_connections ()
263{ 257{
264 struct NSEPeer *pos; 258 struct NSEPeer *pos;
259 struct OpListEntry *oplist_entry;
265 260
266 while (NULL != (pos = peer_head)) 261 while (NULL != (pos = peer_head))
267 { 262 {
268 if (NULL != pos->nse_op) 263 if (NULL != pos->nse_op)
269 GNUNET_TESTBED_operation_done (pos->nse_op); 264 GNUNET_TESTBED_operation_done (pos->nse_op);
270 if (NULL != pos->stats_op)
271 GNUNET_TESTBED_operation_done (pos->stats_op);
272 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos); 265 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
273 if (GNUNET_SCHEDULER_NO_TASK != pos->stats_task)
274 GNUNET_SCHEDULER_cancel (pos->stats_task);
275 GNUNET_free (pos); 266 GNUNET_free (pos);
276 } 267 }
268 while (NULL != (oplist_entry = oplist_head))
269 {
270 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry);
271 GNUNET_TESTBED_operation_done (oplist_entry->op);
272 GNUNET_free (oplist_entry);
273 }
277} 274}
278 275
279 276
@@ -288,15 +285,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288{ 285{
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
290 close_monitor_connections (); 287 close_monitor_connections ();
291 /* if (NULL != testbed) */ 288 if (NULL != get_stats_op)
292 /* GNUNET_TESTBED_destroy (testbed); */ 289 {
293 if (NULL != controller) 290 GNUNET_TESTBED_operation_done (get_stats_op);
294 GNUNET_TESTBED_controller_disconnect (controller); 291 get_stats_op = NULL;
295 if (NULL != copro) 292 }
296 GNUNET_TESTBED_controller_stop (copro); 293 // FIXME: what about closing other files!?
297 while (0 < num_hosts)
298 GNUNET_TESTBED_host_destroy (hosts[--num_hosts]);
299 // FIXME: what about closing other files!?
300 if (NULL != data_file) 294 if (NULL != data_file)
301 GNUNET_DISK_file_close (data_file); 295 GNUNET_DISK_file_close (data_file);
302 if (NULL != testing_cfg) 296 if (NULL != testing_cfg)
@@ -345,184 +339,6 @@ handle_estimate (void *cls,
345 339
346 340
347/** 341/**
348 * Process core statistic values.
349 *
350 * @param cls closure
351 * @param subsystem name of subsystem that created the statistic
352 * @param name the name of the datum
353 * @param value the current value
354 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
355 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
356 */
357static int
358core_stats_iterator (void *cls, const char *subsystem, const char *name,
359 uint64_t value, int is_persistent)
360{
361 struct NSEPeer *peer = cls;
362 char output_buffer[512];
363 size_t size;
364
365 if (NULL == output_file)
366 {
367 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
368 "%p -> %s [%s]: %llu\n",
369 peer, subsystem, name, value);
370 return GNUNET_OK;
371 }
372 size =
373 GNUNET_snprintf (output_buffer,
374 sizeof (output_buffer),
375 "%p [%s] %s %llu\n",
376 peer,
377 subsystem, name, value);
378 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
379 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
380 return GNUNET_OK;
381}
382
383
384/**
385 * Continuation called by "get_stats" function once we are done.
386 *
387 * @param cls closure
388 * @param success GNUNET_OK if statistics were
389 * successfully obtained, GNUNET_SYSERR if not.
390 */
391static void
392core_stats_cont (void *cls, int success);
393
394
395/**
396 * Function invoked periodically to get the statistics.
397 *
398 * @param cls 'struct NSEPeer' to get stats from
399 * @param tc scheduler context
400 */
401static void
402core_get_stats (void *cls,
403 const struct GNUNET_SCHEDULER_TaskContext *tc)
404{
405 struct NSEPeer *peer = cls;
406
407 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
408 {
409 GNUNET_TESTBED_operation_done (peer->stats_op);
410 peer->stats = NULL;
411 peer->stats_op = NULL;
412 return;
413 }
414 /* FIXME: code duplication! */
415 GNUNET_STATISTICS_get (peer->stats, "core", NULL,
416 GNUNET_TIME_UNIT_FOREVER_REL,
417 &core_stats_cont,
418 &core_stats_iterator, peer);
419 GNUNET_STATISTICS_get (peer->stats, "transport", NULL,
420 GNUNET_TIME_UNIT_FOREVER_REL,
421 NULL,
422 &core_stats_iterator, peer);
423 GNUNET_STATISTICS_get (peer->stats, "nse", NULL,
424 GNUNET_TIME_UNIT_FOREVER_REL,
425 NULL,
426 &core_stats_iterator, peer);
427 peer->stats_task = GNUNET_SCHEDULER_NO_TASK;
428}
429
430
431/**
432 * Continuation called by "get_stats" function.
433 *
434 * @param cls closure
435 * @param success GNUNET_OK if statistics were
436 * successfully obtained, GNUNET_SYSERR if not.
437 */
438static void
439core_stats_cont (void *cls,
440 int success)
441{
442 struct NSEPeer *peer = cls;
443
444 if (GNUNET_OK != success)
445 return;
446 peer->stats_task = GNUNET_SCHEDULER_add_delayed (interval,
447 &core_get_stats, peer);
448}
449
450
451/**
452 * Adapter function called to establish a connection to
453 * statistics service.
454 *
455 * @param cls closure
456 * @param cfg configuration of the peer to connect to; will be available until
457 * GNUNET_TESTBED_operation_done() is called on the operation returned
458 * from GNUNET_TESTBED_service_connect()
459 * @return service handle to return in 'op_result', NULL on error
460 */
461static void *
462statistics_connect_adapter (void *cls,
463 const struct GNUNET_CONFIGURATION_Handle *cfg)
464{
465 return GNUNET_STATISTICS_create ("<driver>",
466 cfg);
467}
468
469
470/**
471 * Adapter function called to destroy a connection to
472 * statistics service.
473 *
474 * @param cls closure
475 * @param op_result service handle returned from the connect adapter
476 */
477static void
478statistics_disconnect_adapter (void *cls,
479 void *op_result)
480{
481 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
482}
483
484
485/**
486 * Function called by testbed once we are connected to stats service.
487 *
488 * @param cls the 'struct NSEPeer' for which we connected to stats
489 * @param op connect operation handle
490 * @param ca_result handle to stats service
491 * @param emsg error message on failure
492 */
493static void
494stat_run (void *cls,
495 struct GNUNET_TESTBED_Operation *op,
496 void *ca_result,
497 const char *emsg)
498{
499 struct NSEPeer *current_peer = cls;
500
501 if (NULL == ca_result)
502 {
503 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
504 "Failed to connect to statistics service: %s\n",
505 emsg);
506 GNUNET_SCHEDULER_shutdown ();
507 return;
508 }
509 current_peer->stats = ca_result;
510 GNUNET_STATISTICS_get (current_peer->stats, "core", NULL,
511 GNUNET_TIME_UNIT_FOREVER_REL,
512 &core_stats_cont,
513 &core_stats_iterator, current_peer);
514 GNUNET_STATISTICS_get (current_peer->stats, "transport", NULL,
515 GNUNET_TIME_UNIT_FOREVER_REL,
516 NULL,
517 &core_stats_iterator, current_peer);
518 GNUNET_STATISTICS_get (current_peer->stats, "nse", NULL,
519 GNUNET_TIME_UNIT_FOREVER_REL,
520 NULL,
521 &core_stats_iterator, current_peer);
522}
523
524
525/**
526 * Adapter function called to establish a connection to 342 * Adapter function called to establish a connection to
527 * NSE service. 343 * NSE service.
528 * 344 *
@@ -579,21 +395,13 @@ connect_nse_service ()
579 current_peer = GNUNET_malloc (sizeof (struct NSEPeer)); 395 current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
580 current_peer->daemon = daemons[i]; 396 current_peer->daemon = daemons[i];
581 current_peer->nse_op 397 current_peer->nse_op
582 = GNUNET_TESTBED_service_connect (NULL, 398 = GNUNET_TESTBED_service_connect (NULL,
583 current_peer->daemon, 399 current_peer->daemon,
584 "nse", 400 "nse",
585 NULL, NULL, 401 NULL, NULL,
586 &nse_connect_adapter, 402 &nse_connect_adapter,
587 &nse_disconnect_adapter, 403 &nse_disconnect_adapter,
588 current_peer); 404 current_peer);
589 current_peer->stats_op
590 = GNUNET_TESTBED_service_connect (NULL,
591 current_peer->daemon,
592 "statistics",
593 &stat_run, current_peer,
594 &statistics_connect_adapter,
595 &statistics_disconnect_adapter,
596 NULL);
597 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 405 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
598 } 406 }
599} 407}
@@ -629,6 +437,8 @@ stats_finished_callback (void *cls,
629 char buf[512]; 437 char buf[512];
630 size_t buf_len; 438 size_t buf_len;
631 439
440 GNUNET_TESTBED_operation_done (get_stats_op);
441 get_stats_op = NULL;
632 if (NULL != emsg) 442 if (NULL != emsg)
633 { 443 {
634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -696,36 +506,63 @@ statistics_iterator (void *cls,
696{ 506{
697 struct StatsContext *stats_context = cls; 507 struct StatsContext *stats_context = cls;
698 char buf[512]; 508 char buf[512];
509 const char *const sections[] = {"core", "transport", "nse"};
699 size_t buf_len; 510 size_t buf_len;
511 unsigned int cnt;
512 unsigned int nsections;
700 513
514 nsections = sizeof (sections) / sizeof (char *);
515 for (cnt = 0; cnt < nsections; cnt++)
516 if (0 == strcmp (subsystem, sections[cnt]))
517 break;
518 if (cnt == nsections)
519 return GNUNET_OK;
520
521 if (NULL == data_file)
522 {
523 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
524 "%p -> %s [%s]: %llu\n",
525 peer, subsystem, name, value);
526 }
527 else
528 {
529 buf_len =
530 GNUNET_snprintf (buf,
531 sizeof (buf),
532 "%p [%s] %s %llu\n",
533 peer,
534 subsystem, name, value);
535 if (buf_len != GNUNET_DISK_file_write (data_file, buf, buf_len))
536 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
537 }
701 if (0 != strcmp (subsystem, "nse")) 538 if (0 != strcmp (subsystem, "nse"))
702 return GNUNET_OK; 539 return GNUNET_OK;
703 if (0 == strcmp (name, "# flood messages received")) 540 if (0 == strcmp (name, "# flood messages received"))
541 {
542 stats_context->total_nse_received_messages += value;
543 if ( (verbose > 1) &&
544 (NULL != data_file) )
704 { 545 {
705 stats_context->total_nse_received_messages += value; 546 buf_len =
706 if ( (verbose > 1) && 547 GNUNET_snprintf (buf, sizeof (buf),
707 (NULL != data_file) ) 548 "%p %u RECEIVED\n",
708 { 549 peer, value);
709 buf_len = 550 GNUNET_DISK_file_write (data_file, buf, buf_len);
710 GNUNET_snprintf (buf, sizeof (buf),
711 "%p %u RECEIVED\n",
712 peer, value);
713 GNUNET_DISK_file_write (data_file, buf, buf_len);
714 }
715 } 551 }
552 }
716 if (0 == strcmp (name, "# flood messages transmitted")) 553 if (0 == strcmp (name, "# flood messages transmitted"))
554 {
555 stats_context->total_nse_transmitted_messages += value;
556 if ( (verbose > 1) &&
557 (NULL != data_file) )
717 { 558 {
718 stats_context->total_nse_transmitted_messages += value; 559 buf_len =
719 if ( (verbose > 1) && 560 GNUNET_snprintf (buf, sizeof (buf),
720 (NULL != data_file) ) 561 "%p %u TRANSMITTED\n",
721 { 562 peer, value);
722 buf_len = 563 GNUNET_DISK_file_write (data_file, buf, buf_len);
723 GNUNET_snprintf (buf, sizeof (buf),
724 "%p %u TRANSMITTED\n",
725 peer, value);
726 GNUNET_DISK_file_write (data_file, buf, buf_len);
727 }
728 } 564 }
565 }
729 if (0 == strcmp (name, "# cross messages")) 566 if (0 == strcmp (name, "# cross messages"))
730 stats_context->total_nse_cross += value; 567 stats_context->total_nse_cross += value;
731 if (0 == strcmp (name, "# extra messages")) 568 if (0 == strcmp (name, "# extra messages"))
@@ -737,26 +574,6 @@ statistics_iterator (void *cls,
737 574
738 575
739/** 576/**
740 * Function called upon completion of the node start/stop operations
741 * for the current round. Writes the new topology to disk.
742 */
743static void
744write_topology ()
745{
746 char temp_output_file[1024];
747
748 if (NULL != topology_file)
749 {
750 GNUNET_snprintf (temp_output_file, sizeof (temp_output_file),
751 "%s_%llu.dot",
752 topology_file, current_round);
753 GNUNET_TESTBED_overlay_write_topology_to_file (controller,
754 temp_output_file);
755 }
756}
757
758
759/**
760 * We're at the end of a round. Stop monitoring, write total 577 * We're at the end of a round. Stop monitoring, write total
761 * number of connections to log and get full stats. Then trigger 578 * number of connections to log and get full stats. Then trigger
762 * the next round. 579 * the next round.
@@ -784,11 +601,12 @@ finish_round (void *cls,
784 } 601 }
785 close_monitor_connections (); 602 close_monitor_connections ();
786 stats_context = GNUNET_malloc (sizeof (struct StatsContext)); 603 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
787 GNUNET_TESTBED_get_statistics (num_peers_in_round[current_round], 604 get_stats_op =
788 daemons, 605 GNUNET_TESTBED_get_statistics (num_peers_in_round[current_round],
789 &statistics_iterator, 606 daemons,
790 &stats_finished_callback, 607 &statistics_iterator,
791 stats_context); 608 &stats_finished_callback,
609 stats_context);
792} 610}
793 611
794 612
@@ -800,7 +618,7 @@ finish_round (void *cls,
800static void 618static void
801run_round () 619run_round ()
802{ 620{
803 write_topology (); 621 LOG_DEBUG ("Running round %u\n", current_round);
804 connect_nse_service (); 622 connect_nse_service ();
805 GNUNET_SCHEDULER_add_delayed (wait_time, 623 GNUNET_SCHEDULER_add_delayed (wait_time,
806 &finish_round, 624 &finish_round,
@@ -809,6 +627,69 @@ run_round ()
809 627
810 628
811/** 629/**
630 * Creates an oplist entry and adds it to the oplist DLL
631 */
632static struct OpListEntry *
633make_oplist_entry ()
634{
635 struct OpListEntry *entry;
636
637 entry = GNUNET_malloc (sizeof (struct OpListEntry));
638 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
639 return entry;
640}
641
642
643/**
644 * Functions of this signature are called when a peer has been successfully
645 * started or stopped.
646 *
647 * @param cls NULL
648 * @param emsg NULL on success; otherwise an error description
649 */
650static void
651peer_churn_cb (void *cls, const char *emsg)
652{
653 struct OpListEntry *entry = cls;
654
655 GNUNET_TESTBED_operation_done (entry->op);
656 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
657 GNUNET_free (entry);
658}
659
660
661/**
662 * Adjust the number of running peers to match the required number of running
663 * peers for the round
664 *
665 * @param
666 * @return
667 */
668static void
669adjust_running_peers ()
670{
671 struct OpListEntry *entry;
672 unsigned int i;
673
674 /* start peers if we have too few */
675 for (i=peers_running;i<num_peers_in_round[current_round];i++)
676 {
677 entry = make_oplist_entry ();
678 entry->op = GNUNET_TESTBED_peer_start (NULL, daemons[i],
679 &peer_churn_cb, entry);
680 }
681
682 /* stop peers if we have too many */
683 for (i=num_peers_in_round[current_round];i<peers_running;i++)
684 {
685 entry = make_oplist_entry ();
686 entry->op = GNUNET_TESTBED_peer_stop (NULL, daemons[i],
687 &peer_churn_cb, entry);
688 }
689}
690
691
692/**
812 * Task run at the end of a round. Disconnect from all monitored 693 * Task run at the end of a round. Disconnect from all monitored
813 * peers; then get statistics from *all* peers. 694 * peers; then get statistics from *all* peers.
814 * 695 *
@@ -819,7 +700,6 @@ static void
819next_round (void *cls, 700next_round (void *cls,
820 const struct GNUNET_SCHEDULER_TaskContext *tc) 701 const struct GNUNET_SCHEDULER_TaskContext *tc)
821{ 702{
822 unsigned int i;
823 703
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n"); 704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
825 current_round++; 705 current_round++;
@@ -836,14 +716,7 @@ next_round (void *cls,
836 run_round (); 716 run_round ();
837 return; 717 return;
838 } 718 }
839 719 adjust_running_peers ();
840 /* start peers if we have too few */
841 for (i=peers_running;i<num_peers_in_round[current_round];i++)
842 GNUNET_TESTBED_peer_start (NULL, daemons[i], NULL, NULL);
843
844 /* stop peers if we have too many */
845 for (i=num_peers_in_round[current_round];i<peers_running;i++)
846 GNUNET_TESTBED_peer_stop (NULL, daemons[i], NULL, NULL);
847} 720}
848 721
849 722
@@ -882,38 +755,29 @@ master_controller_cb (void *cls,
882} 755}
883 756
884 757
885static void 758/**
886controller_start_cb (void *cls, 759 * Signature of a main function for a testcase.
887 const struct GNUNET_CONFIGURATION_Handle *cfg, 760 *
888 int status) 761 * @param cls NULL
762 * @param num_peers_ number of peers in 'peers'
763 * @param peers handle to peers run in the testbed. NULL upon timeout (see
764 * GNUNET_TESTBED_test_run()).
765 */
766static void
767test_master (void *cls,
768 unsigned int num_peers_,
769 struct GNUNET_TESTBED_Peer **peers)
889{ 770{
890 if (GNUNET_OK != status) 771 daemons = peers;
891 { 772 GNUNET_break (num_peers_ == num_peers);
892 copro = NULL; 773 peers_running = num_peers;
893 GNUNET_SCHEDULER_shutdown (); 774 if (num_peers_in_round[current_round] == peers_running)
894 return; 775 {
895 } 776 /* no need to churn, just run next round */
896 num_hosts = GNUNET_TESTBED_hosts_load_from_file (hosts_file, 777 run_round ();
897 testing_cfg, 778 return;
898 &hosts); 779 }
899 if (0 == num_hosts) 780 adjust_running_peers ();
900 {
901 fprintf (stderr,
902 "Failed to read host information from `%s'\n",
903 hosts_file);
904 return;
905 }
906 controller = GNUNET_TESTBED_controller_connect (cfg,
907 NULL,
908 0 /* mask */,
909 &master_controller_cb, NULL);
910
911 /* testbed = GNUNET_TESTBED_create (controller, */
912 /* num_hosts, hosts, */
913 /* num_peers, */
914 /* cfg, */
915 /* 0 /\* FIXME: topology *\/, */
916 /* NULL /\* FIXME: topology options *\/); */
917} 781}
918 782
919 783
@@ -930,14 +794,12 @@ run (void *cls, char *const *args, const char *cfgfile,
930 const struct GNUNET_CONFIGURATION_Handle *cfg) 794 const struct GNUNET_CONFIGURATION_Handle *cfg)
931{ 795{
932 char *tok; 796 char *tok;
933 unsigned int num; 797 uint64_t event_mask;
798 unsigned int num;
934 799
935 ok = 1; 800 ok = 1;
936 testing_cfg = GNUNET_CONFIGURATION_dup (cfg); 801 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
938 if (verbose)
939 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
940 "use_progressbars", "YES");
941 if (NULL == num_peer_spec) 803 if (NULL == num_peer_spec)
942 { 804 {
943 fprintf (stderr, "You need to specify the number of peers to run\n"); 805 fprintf (stderr, "You need to specify the number of peers to run\n");
@@ -963,7 +825,6 @@ run (void *cls, char *const *args, const char *cfgfile,
963 fprintf (stderr, "Refusing to run a testbed with no rounds\n"); 825 fprintf (stderr, "Refusing to run a testbed with no rounds\n");
964 return; 826 return;
965 } 827 }
966 daemons = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer*) * num_peers);
967 if ( (NULL != data_filename) && 828 if ( (NULL != data_filename) &&
968 (NULL == (data_file = 829 (NULL == (data_file =
969 GNUNET_DISK_file_open (data_filename, 830 GNUNET_DISK_file_open (data_filename,
@@ -985,16 +846,19 @@ run (void *cls, char *const *args, const char *cfgfile,
985 GNUNET_DISK_PERM_USER_WRITE))) ) 846 GNUNET_DISK_PERM_USER_WRITE))) )
986 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", 847 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
987 output_filename); 848 output_filename);
988 849 event_mask = 0LL;
989 if (NULL == 850 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
990 (copro = GNUNET_TESTBED_controller_start (controller_ip, NULL, 851 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
991 cfg, 852 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
992 &controller_start_cb, NULL))) 853 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
993 { 854 GNUNET_TESTBED_run (hosts_file,
994 fprintf (stderr, 855 cfg,
995 "Failed to start controller\n"); 856 num_peers,
996 return; 857 event_mask,
997 } 858 master_controller_cb,
859 NULL, /* master_controller_cb cls */
860 &test_master,
861 NULL); /* test_master cls */
998 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 862 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
999 &shutdown_task, NULL); 863 &shutdown_task, NULL);
1000} 864}
@@ -1017,19 +881,10 @@ main (int argc, char *const *argv)
1017 1, &GNUNET_GETOPT_set_string, &data_filename}, 881 1, &GNUNET_GETOPT_set_string, &data_filename},
1018 {'H', "hosts", "FILENAME", 882 {'H', "hosts", "FILENAME",
1019 gettext_noop ("name of the file with the login information for the testbed"), 883 gettext_noop ("name of the file with the login information for the testbed"),
1020 1, &GNUNET_GETOPT_set_string, &hosts_file}, 884 0, &GNUNET_GETOPT_set_string, &hosts_file},
1021 {'i', "ip", "CONTROLLER_IP",
1022 gettext_noop ("IP address of this system as seen by the rest of the testbed"),
1023 1, &GNUNET_GETOPT_set_string, &controller_ip},
1024 {'I', "interval", "DELAY",
1025 gettext_noop ("delay between queries to statistics during a round"),
1026 1, &GNUNET_GETOPT_set_relative_time, &interval},
1027 {'t', "topology", "FILENAME",
1028 gettext_noop ("prefix of the filenames we use for writing the topology for each round"),
1029 1, &GNUNET_GETOPT_set_string, &topology_file},
1030 {'o', "output", "FILENAME", 885 {'o', "output", "FILENAME",
1031 gettext_noop ("name of the file for writing the main results"), 886 gettext_noop ("name of the file for writing the main results"),
1032 1, &GNUNET_GETOPT_set_string, &output_filename}, 887 0, &GNUNET_GETOPT_set_string, &output_filename},
1033 {'p', "peers", "NETWORKSIZESPEC", 888 {'p', "peers", "NETWORKSIZESPEC",
1034 gettext_noop ("Number of peers to run in each round, separated by commas"), 889 gettext_noop ("Number of peers to run in each round, separated by commas"),
1035 1, &GNUNET_GETOPT_set_string, &num_peer_spec}, 890 1, &GNUNET_GETOPT_set_string, &num_peer_spec},
@@ -1043,7 +898,6 @@ main (int argc, char *const *argv)
1043 }; 898 };
1044 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 899 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1045 return 2; 900 return 2;
1046 GNUNET_log_setup ("nse-profiler", "WARNING", NULL);
1047 if (GNUNET_OK != 901 if (GNUNET_OK !=
1048 GNUNET_PROGRAM_run (argc, argv, "nse-profiler", 902 GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
1049 gettext_noop 903 gettext_noop