adding DEBUG logic for #3863
[oweals/gnunet.git] / src / nse / gnunet-nse-profiler.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file nse/gnunet-nse-profiler.c
22  *
23  * @brief Profiling driver for the network size estimation service.
24  *        Generally, the profiler starts a given number of peers,
25  *        then churns some off, waits a certain amount of time, then
26  *        churns again, and repeats.
27  * @author Christian Grothoff
28  * @author Nathan Evans
29  * @author Sree Harsha Totakura
30  */
31
32 #include "platform.h"
33 #include "gnunet_testbed_service.h"
34 #include "gnunet_nse_service.h"
35
36 /**
37  * Generic loggins shorthand
38  */
39 #define LOG(kind,...)                                           \
40   GNUNET_log (kind, __VA_ARGS__)
41
42 /**
43  * Debug logging shorthand
44  */
45 #define LOG_DEBUG(...)                          \
46   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
47
48
49 /**
50  * Information we track for a peer in the testbed.
51  */
52 struct NSEPeer
53 {
54   /**
55    * Prev reference in DLL.
56    */
57   struct NSEPeer *prev;
58
59   /**
60    * Next reference in DLL.
61    */
62   struct NSEPeer *next;
63
64   /**
65    * Handle with testbed.
66    */
67   struct GNUNET_TESTBED_Peer *daemon;
68
69   /**
70    * Testbed operation to connect to NSE service.
71    */
72   struct GNUNET_TESTBED_Operation *nse_op;
73
74   /**
75    * Testbed operation to connect to statistics service
76    */
77   struct GNUNET_TESTBED_Operation *stat_op;
78
79   /**
80    * Handle to the statistics service
81    */
82   struct GNUNET_STATISTICS_Handle *sh;
83 };
84
85
86 /**
87  * Operation map entry
88  */
89 struct OpListEntry
90 {
91   /**
92    * DLL next ptr
93    */
94   struct OpListEntry *next;
95
96   /**
97    * DLL prev ptr
98    */
99   struct OpListEntry *prev;
100
101   /**
102    * The testbed operation
103    */
104   struct GNUNET_TESTBED_Operation *op;
105
106   /**
107    * Depending on whether we start or stop NSE service at the peer set this to 1
108    * or -1
109    */
110   int delta;
111 };
112
113
114 /**
115  * Head of DLL of peers we monitor closely.
116  */
117 static struct NSEPeer *peer_head;
118
119 /**
120  * Tail of DLL of peers we monitor closely.
121  */
122 static struct NSEPeer *peer_tail;
123
124 /**
125  * Return value from 'main' (0 == success)
126  */
127 static int ok;
128
129 /**
130  * Be verbose (configuration option)
131  */
132 static int verbose;
133
134 /**
135  * Name of the file with the hosts to run the test over (configuration option)
136  */
137 static char *hosts_file;
138
139 /**
140  * Maximum number of peers in the test.
141  */
142 static unsigned int num_peers;
143
144 /**
145  * Total number of rounds to execute.
146  */
147 static unsigned int num_rounds;
148
149 /**
150  * Current round we are in.
151  */
152 static unsigned int current_round;
153
154 /**
155  * Array of size 'num_rounds' with the requested number of peers in the given round.
156  */
157 static unsigned int *num_peers_in_round;
158
159 /**
160  * How many peers are running right now?
161  */
162 static unsigned int peers_running;
163
164 /**
165  * Specification for the numbers of peers to have in each round.
166  */
167 static char *num_peer_spec;
168
169 /**
170  * Handles to all of the running peers.
171  */
172 static struct GNUNET_TESTBED_Peer **daemons;
173
174 /**
175  * Global configuration file
176  */
177 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
178
179 /**
180  * The shutdown task
181  */
182 static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
183
184 /**
185  * Maximum number of connections to NSE services.
186  */
187 static unsigned int connection_limit;
188
189 /**
190  * Total number of connections in the whole network.
191  */
192 static unsigned int total_connections;
193
194 /**
195  * File to report results to.
196  */
197 static struct GNUNET_DISK_FileHandle *output_file;
198
199 /**
200  * Filename to log results to.
201  */
202 static char *output_filename;
203
204 /**
205  * File to log connection info, statistics to.
206  */
207 static struct GNUNET_DISK_FileHandle *data_file;
208
209 /**
210  * Filename to log connection info, statistics to.
211  */
212 static char *data_filename;
213
214 /**
215  * How long to wait before triggering next round?
216  * Default: 60 s.
217  */
218 static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 };
219
220 /**
221  * DLL head for operation list
222  */
223 static struct OpListEntry *oplist_head;
224
225 /**
226  * DLL tail for operation list
227  */
228 static struct OpListEntry *oplist_tail;
229
230 /**
231  * Are we shutting down
232  */
233 static int shutting_down;
234
235
236 /**
237  * Clean up all of the monitoring connections to NSE and
238  * STATISTICS that we keep to selected peers.
239  */
240 static void
241 close_monitor_connections ()
242 {
243   struct NSEPeer *pos;
244   struct OpListEntry *oplist_entry;
245
246   while (NULL != (pos = peer_head))
247   {
248     if (NULL != pos->nse_op)
249       GNUNET_TESTBED_operation_done (pos->nse_op);
250     if (NULL != pos->stat_op)
251       GNUNET_TESTBED_operation_done (pos->stat_op);
252     GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
253     GNUNET_free (pos);
254   }
255   while (NULL != (oplist_entry = oplist_head))
256   {
257     GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry);
258     GNUNET_TESTBED_operation_done (oplist_entry->op);
259     GNUNET_free (oplist_entry);
260   }
261 }
262
263
264 /**
265  * Task run on shutdown; cleans up everything.
266  *
267  * @param cls unused
268  * @param tc unused
269  */
270 static void
271 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
272 {
273   shutdown_task_id = NULL;
274   if (GNUNET_YES == shutting_down)
275     return;
276   shutting_down = GNUNET_YES;
277   LOG_DEBUG ("Ending test.\n");
278   close_monitor_connections ();
279   if (NULL != data_file)
280   {
281     GNUNET_DISK_file_close (data_file);
282     data_file = NULL;
283   }
284   if (NULL != output_file)
285   {
286     GNUNET_DISK_file_close (output_file);
287     output_file = NULL;
288   }
289   if (NULL != testing_cfg)
290     GNUNET_CONFIGURATION_destroy (testing_cfg);
291   testing_cfg = NULL;
292 }
293
294
295 /**
296  * Schedules shutdown task to be run now
297  */
298 static void
299 shutdown_now ()
300 {
301   if (NULL != shutdown_task_id)
302     GNUNET_SCHEDULER_cancel (shutdown_task_id);
303   shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
304 }
305
306
307 /**
308  * Callback to call when network size estimate is updated.
309  *
310  * @param cls closure with the 'struct NSEPeer' providing the update
311  * @param timestamp server timestamp
312  * @param estimate the value of the current network size estimate
313  * @param std_dev standard deviation (rounded down to nearest integer)
314  *                of the size estimation values seen
315  */
316 static void
317 handle_estimate (void *cls,
318                  struct GNUNET_TIME_Absolute timestamp,
319                  double estimate, double std_dev)
320 {
321   struct NSEPeer *peer = cls;
322   char output_buffer[512];
323   size_t size;
324
325   if (NULL == output_file)
326     {
327       FPRINTF (stderr,
328                "Received network size estimate from peer %p. Size: %f std.dev. %f\n",
329                peer, estimate, std_dev);
330       return;
331     }
332   size = GNUNET_snprintf (output_buffer,
333                           sizeof (output_buffer),
334                           "%p %llu %llu %f %f %f\n",
335                           peer, peers_running,
336                           (unsigned long long) timestamp.abs_value_us,
337                           GNUNET_NSE_log_estimate_to_n (estimate), estimate,
338                           std_dev);
339   if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
340     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
341                 "Unable to write to file!\n");
342 }
343
344
345 /**
346  * Adapter function called to establish a connection to
347  * NSE service.
348  *
349  * @param cls closure (the 'struct NSEPeer')
350  * @param cfg configuration of the peer to connect to; will be available until
351  *          GNUNET_TESTBED_operation_done() is called on the operation returned
352  *          from GNUNET_TESTBED_service_connect()
353  * @return service handle to return in 'op_result', NULL on error
354  */
355 static void *
356 nse_connect_adapter (void *cls,
357                      const struct GNUNET_CONFIGURATION_Handle *cfg)
358 {
359   struct NSEPeer *current_peer = cls;
360
361   return GNUNET_NSE_connect (cfg, &handle_estimate, current_peer);
362 }
363
364
365 /**
366  * Adapter function called to destroy a connection to
367  * NSE service.
368  *
369  * @param cls closure
370  * @param op_result service handle returned from the connect adapter
371  */
372 static void
373 nse_disconnect_adapter (void *cls,
374                         void *op_result)
375 {
376   GNUNET_NSE_disconnect (op_result);
377 }
378
379
380 /**
381  * Callback function to process statistic values.
382  *
383  * @param cls `struct NSEPeer`
384  * @param subsystem name of subsystem that created the statistic
385  * @param name the name of the datum
386  * @param value the current value
387  * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
388  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
389  */
390 static int
391 stat_iterator (void *cls,
392                const char *subsystem,
393                const char *name,
394                uint64_t value, int is_persistent)
395 {
396   char *output_buffer;
397   struct GNUNET_TIME_Absolute now;
398   size_t size;
399   unsigned int flag;
400
401   GNUNET_assert (NULL != data_file);
402   now = GNUNET_TIME_absolute_get ();
403   flag = strcasecmp (subsystem, "core");
404   if (0 != flag)
405     flag = 1;
406   size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
407                           now.abs_value_us / 1000LL / 1000LL,
408                           value, flag);
409   if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
410   {
411     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
412     GNUNET_free (output_buffer);
413     return GNUNET_SYSERR;
414   }
415   GNUNET_free (output_buffer);
416   return GNUNET_OK;
417 }
418
419
420 /**
421  * Called to open a connection to the peer's statistics
422  *
423  * @param cls peer context
424  * @param cfg configuration of the peer to connect to; will be available until
425  *          GNUNET_TESTBED_operation_done() is called on the operation returned
426  *          from GNUNET_TESTBED_service_connect()
427  * @return service handle to return in 'op_result', NULL on error
428  */
429 static void *
430 stat_connect_adapter (void *cls,
431                       const struct GNUNET_CONFIGURATION_Handle *cfg)
432 {
433   struct NSEPeer *peer = cls;
434
435   peer->sh = GNUNET_STATISTICS_create ("nse-profiler", cfg);
436   return peer->sh;
437 }
438
439
440 /**
441  * Called to disconnect from peer's statistics service
442  *
443  * @param cls peer context
444  * @param op_result service handle returned from the connect adapter
445  */
446 static void
447 stat_disconnect_adapter (void *cls, void *op_result)
448 {
449   struct NSEPeer *peer = cls;
450
451   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
452                 (peer->sh, "core", "# peers connected",
453                  stat_iterator, peer));
454   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
455                 (peer->sh, "nse", "# peers connected",
456                  stat_iterator, peer));
457   GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
458   peer->sh = NULL;
459 }
460
461
462 /**
463  * Called after successfully opening a connection to a peer's statistics
464  * service; we register statistics monitoring for CORE and NSE here.
465  *
466  * @param cls the callback closure from functions generating an operation
467  * @param op the operation that has been finished
468  * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
469  * @param emsg error message in case the operation has failed; will be NULL if
470  *          operation has executed successfully.
471  */
472 static void
473 stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
474               void *ca_result, const char *emsg )
475 {
476   struct GNUNET_STATISTICS_Handle *sh = ca_result;
477   struct NSEPeer *peer = cls;
478
479   if (NULL != emsg)
480   {
481     GNUNET_break (0);
482     return;
483   }
484   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
485                 (sh, "core", "# peers connected",
486                  stat_iterator, peer));
487   GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
488                 (sh, "nse", "# peers connected",
489                  stat_iterator, peer));
490 }
491
492
493 /**
494  * Task run to connect to the NSE and statistics services to a subset of
495  * all of the running peers.
496  */
497 static void
498 connect_nse_service ()
499 {
500   struct NSEPeer *current_peer;
501   unsigned int i;
502   unsigned int connections;
503
504   if (0 == connection_limit)
505     return;
506   LOG_DEBUG ("Connecting to nse service of peers\n");
507   connections = 0;
508   for (i = 0; i < num_peers_in_round[current_round]; i++)
509   {
510     if ((num_peers_in_round[current_round] > connection_limit) &&
511         (0 != (i % (num_peers_in_round[current_round] / connection_limit))))
512       continue;
513     LOG_DEBUG ("Connecting to nse service of peer %d\n", i);
514     current_peer = GNUNET_new (struct NSEPeer);
515     current_peer->daemon = daemons[i];
516     current_peer->nse_op
517         = GNUNET_TESTBED_service_connect (NULL,
518                                           current_peer->daemon,
519                                           "nse",
520                                           NULL, NULL,
521                                           &nse_connect_adapter,
522                                           &nse_disconnect_adapter,
523                                           current_peer);
524     if (NULL != data_file)
525       current_peer->stat_op
526           = GNUNET_TESTBED_service_connect (NULL,
527                                             current_peer->daemon,
528                                             "statistics",
529                                             stat_comp_cb,
530                                             current_peer,
531                                             &stat_connect_adapter,
532                                             &stat_disconnect_adapter,
533                                             current_peer);
534     GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
535     if (++connections == connection_limit)
536       break;
537   }
538 }
539
540
541 /**
542  * Task that starts/stops peers to move to the next round.
543  *
544  * @param cls NULL, unused
545  * @param tc scheduler context (unused)
546  */
547 static void
548 next_round (void *cls,
549             const struct GNUNET_SCHEDULER_TaskContext *tc);
550
551
552 /**
553  * We're at the end of a round.  Stop monitoring, write total
554  * number of connections to log and get full stats.  Then trigger
555  * the next round.
556  *
557  * @param cls unused, NULL
558  * @param tc unused
559  */
560 static void
561 finish_round (void *cls,
562               const struct GNUNET_SCHEDULER_TaskContext *tc)
563 {
564   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
565     return;
566   LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
567   close_monitor_connections ();
568   GNUNET_SCHEDULER_add_now (&next_round, NULL);
569 }
570
571
572 /**
573  * We have reached the desired number of peers for the current round.
574  * Run it (by connecting and monitoring a few peers and waiting the
575  * specified delay before finishing the round).
576  */
577 static void
578 run_round ()
579 {
580   LOG_DEBUG ("Running round %u\n", current_round);
581   connect_nse_service ();
582   GNUNET_SCHEDULER_add_delayed (wait_time,
583                                 &finish_round,
584                                 NULL);
585 }
586
587
588 /**
589  * Creates an oplist entry and adds it to the oplist DLL
590  */
591 static struct OpListEntry *
592 make_oplist_entry ()
593 {
594   struct OpListEntry *entry;
595
596   entry = GNUNET_new (struct OpListEntry);
597   GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
598   return entry;
599 }
600
601
602 /**
603  * Callback to be called when NSE service is started or stopped at peers
604  *
605  * @param cls NULL
606  * @param op the operation handle
607  * @param emsg NULL on success; otherwise an error description
608  */
609 static void
610 manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
611                    const char *emsg)
612 {
613   struct OpListEntry *entry = cls;
614
615   GNUNET_TESTBED_operation_done (entry->op);
616   if (NULL != emsg)
617   {
618     LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n");
619     GNUNET_SCHEDULER_shutdown ();
620     return;
621   }
622   GNUNET_assert (0 != entry->delta);
623   peers_running += entry->delta;
624   GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
625   GNUNET_free (entry);
626   if (num_peers_in_round[current_round] == peers_running)
627     run_round ();
628 }
629
630
631 /**
632  * Adjust the number of running peers to match the required number of running
633  * peers for the round
634  */
635 static void
636 adjust_running_peers ()
637 {
638   struct OpListEntry *entry;
639   unsigned int i;
640
641   /* start peers if we have too few */
642   for (i=peers_running;i<num_peers_in_round[current_round];i++)
643   {
644     entry = make_oplist_entry ();
645     entry->delta = 1;
646     entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
647                                                     daemons[i],
648                                                     "nse",
649                                                     &manage_service_cb,
650                                                     entry,
651                                                     1);
652   }
653   /* stop peers if we have too many */
654   for (i=num_peers_in_round[current_round];i<peers_running;i++)
655   {
656     entry = make_oplist_entry ();
657     entry->delta = -1;
658     entry->op =  GNUNET_TESTBED_peer_manage_service (NULL,
659                                                      daemons[i],
660                                                      "nse",
661                                                      &manage_service_cb,
662                                                      entry,
663                                                      0);
664   }
665 }
666
667
668 /**
669  * Task run at the end of a round.  Disconnect from all monitored
670  * peers; then get statistics from *all* peers.
671  *
672  * @param cls NULL, unused
673  * @param tc unused
674  */
675 static void
676 next_round (void *cls,
677             const struct GNUNET_SCHEDULER_TaskContext *tc)
678 {
679   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
680     return;
681   LOG_DEBUG ("Disconnecting nse service of peers\n");
682   current_round++;
683   if (current_round == num_rounds)
684     {
685       /* this was the last round, terminate */
686       ok = 0;
687       GNUNET_SCHEDULER_shutdown ();
688       return;
689     }
690   if (num_peers_in_round[current_round] == peers_running)
691     {
692       /* no need to churn, just run next round */
693       run_round ();
694       return;
695     }
696   adjust_running_peers ();
697 }
698
699
700 /**
701  * Function that will be called whenever something in the
702  * testbed changes.
703  *
704  * @param cls closure, NULL
705  * @param event information on what is happening
706  */
707 static void
708 master_controller_cb (void *cls,
709                       const struct GNUNET_TESTBED_EventInformation *event)
710 {
711   switch (event->type)
712     {
713     case GNUNET_TESTBED_ET_CONNECT:
714       total_connections++;
715       break;
716     case GNUNET_TESTBED_ET_DISCONNECT:
717       total_connections--;
718       break;
719     default:
720       break;
721     }
722 }
723
724
725 /**
726  * Signature of a main function for a testcase.
727  *
728  * @param cls NULL
729  * @param h the run handle
730  * @param num_peers_ number of peers in 'peers'
731  * @param peers handle to peers run in the testbed.  NULL upon timeout (see
732  *          GNUNET_TESTBED_test_run()).
733  * @param links_succeeded the number of overlay link connection attempts that
734  *          succeeded
735  * @param links_failed the number of overlay link connection attempts that
736  *          failed
737  */
738 static void
739 test_master (void *cls,
740              struct GNUNET_TESTBED_RunHandle *h,
741              unsigned int num_peers_,
742              struct GNUNET_TESTBED_Peer **peers,
743              unsigned int links_succeeded,
744              unsigned int links_failed)
745 {
746   if (NULL == peers)
747   {
748     shutdown_now ();
749     return;
750   }
751   daemons = peers;
752   GNUNET_break (num_peers_ == num_peers);
753   peers_running = num_peers;
754   if (num_peers_in_round[current_round] == peers_running)
755   {
756     /* no need to churn, just run the starting round */
757     run_round ();
758     return;
759   }
760   adjust_running_peers ();
761 }
762
763
764 /**
765  * Actual main function that runs the emulation.
766  *
767  * @param cls unused
768  * @param args remaining args, unused
769  * @param cfgfile name of the configuration
770  * @param cfg configuration handle
771  */
772 static void
773 run (void *cls, char *const *args, const char *cfgfile,
774      const struct GNUNET_CONFIGURATION_Handle *cfg)
775 {
776   char *tok;
777   uint64_t event_mask;
778   unsigned int num;
779
780   ok = 1;
781   testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
782   LOG_DEBUG ("Starting daemons.\n");
783   if (NULL == num_peer_spec)
784   {
785     fprintf (stderr, "You need to specify the number of peers to run\n");
786     return;
787   }
788   for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ","))
789     {
790       if (1 != sscanf (tok, "%u", &num))
791         {
792           fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
793           return;
794         }
795       if (0 == num)
796         {
797           fprintf (stderr, "Refusing to run a round with 0 peers\n");
798           return;
799         }
800       GNUNET_array_append (num_peers_in_round, num_rounds, num);
801       num_peers = GNUNET_MAX (num_peers, num);
802     }
803   if (0 == num_peers)
804     {
805       fprintf (stderr, "Refusing to run a testbed with no rounds\n");
806       return;
807     }
808   if ( (NULL != data_filename) &&
809        (NULL == (data_file =
810                  GNUNET_DISK_file_open (data_filename,
811                                         GNUNET_DISK_OPEN_READWRITE |
812                                         GNUNET_DISK_OPEN_TRUNCATE |
813                                         GNUNET_DISK_OPEN_CREATE,
814                                         GNUNET_DISK_PERM_USER_READ |
815                                         GNUNET_DISK_PERM_USER_WRITE))) )
816     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
817                               "open",
818                               data_filename);
819
820   if ( (NULL != output_filename) &&
821        (NULL == (output_file =
822                  GNUNET_DISK_file_open (output_filename,
823                                         GNUNET_DISK_OPEN_READWRITE |
824                                         GNUNET_DISK_OPEN_CREATE,
825                                         GNUNET_DISK_PERM_USER_READ |
826                                         GNUNET_DISK_PERM_USER_WRITE))) )
827     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
828                               output_filename);
829   event_mask = 0LL;
830   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
831   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
832   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
833   event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
834   GNUNET_TESTBED_run (hosts_file,
835                       cfg,
836                       num_peers,
837                       event_mask,
838                       master_controller_cb,
839                       NULL,     /* master_controller_cb cls */
840                       &test_master,
841                       NULL);    /* test_master cls */
842   shutdown_task_id =
843       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
844                                     &shutdown_task, NULL);
845 }
846
847
848 /**
849  * Main function.
850  *
851  * @return 0 on success
852  */
853 int
854 main (int argc, char *const *argv)
855 {
856   static struct GNUNET_GETOPT_CommandLineOption options[] = {
857     {'C', "connections", "COUNT",
858      gettext_noop ("limit to the number of connections to NSE services, 0 for none"),
859      1, &GNUNET_GETOPT_set_uint, &connection_limit},
860     {'d', "details", "FILENAME",
861      gettext_noop ("name of the file for writing connection information and statistics"),
862      1, &GNUNET_GETOPT_set_string, &data_filename},
863     {'H', "hosts", "FILENAME",
864      gettext_noop ("name of the file with the login information for the testbed"),
865      1, &GNUNET_GETOPT_set_string, &hosts_file},
866     {'o', "output", "FILENAME",
867      gettext_noop ("name of the file for writing the main results"),
868      1, &GNUNET_GETOPT_set_string, &output_filename},
869     {'p', "peers", "NETWORKSIZESPEC",
870      gettext_noop ("Number of peers to run in each round, separated by commas"),
871      1, &GNUNET_GETOPT_set_string, &num_peer_spec},
872     {'V', "verbose", NULL,
873      gettext_noop ("be verbose (print progress information)"),
874      0, &GNUNET_GETOPT_increment_value, &verbose},
875     {'w', "wait", "DELAY",
876      gettext_noop ("delay between rounds"),
877      1, &GNUNET_GETOPT_set_relative_time, &wait_time},
878     GNUNET_GETOPT_OPTION_END
879   };
880   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
881     return 2;
882   if (GNUNET_OK !=
883       GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
884                           gettext_noop
885                           ("Measure quality and performance of the NSE service."),
886                           options, &run, NULL))
887     ok = 1;
888   return ok;
889 }
890
891 /* end of nse-profiler.c */