2 This file is part of GNUnet.
3 Copyright (C) 2008--2013 GNUnet e.V.
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.
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.
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.
22 * @file testbed/gnunet-testbed-profiler.c
23 * @brief Profiling driver for the testbed.
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "testbed_api_hosts.h"
33 * Generic loggins shorthand
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
40 * Handle to global configuration
42 struct GNUNET_CONFIGURATION_Handle *cfg;
45 * Peer linking - topology operation
47 struct GNUNET_TESTBED_Operation *topology_op;
50 * Name of the file with the hosts to run the test over (configuration option).
51 * It will be NULL if ENABLE_LL is set
53 static char *hosts_file;
56 * Abort task identifier
58 static struct GNUNET_SCHEDULER_Task *abort_task;
61 * Global event mask for all testbed events
66 * Number of peers to be started by the profiler
68 static unsigned int num_peers;
71 * Number of timeout failures to tolerate
73 static unsigned int num_cont_fails;
76 * Continuous failures during overlay connect operations
78 static unsigned int cont_fails;
81 * Links which are successfully established
83 static unsigned int established_links;
86 * Links which are not successfully established
88 static unsigned int failed_links;
91 * Global testing status
96 * Are we running non interactively
98 static int noninteractive;
107 do_shutdown (void *cls)
109 if (NULL != abort_task)
111 GNUNET_SCHEDULER_cancel (abort_task);
116 GNUNET_CONFIGURATION_destroy (cfg);
123 * abort task to run on test timed out
131 LOG (GNUNET_ERROR_TYPE_WARNING,
133 result = GNUNET_SYSERR;
134 GNUNET_SCHEDULER_shutdown ();
139 * Function to print summary about how many overlay links we have made and how
143 print_overlay_links_summary ()
145 static int printed_already;
147 if (GNUNET_YES == printed_already)
149 printed_already = GNUNET_YES;
150 printf ("%u links succeeded\n", established_links);
151 printf ("%u links failed due to timeouts\n", failed_links);
156 * Controller event callback
159 * @param event the controller event
162 controller_event_cb (void *cls,
163 const struct GNUNET_TESTBED_EventInformation *event)
167 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
168 /* Control reaches here when a peer linking operation fails */
169 if (NULL != event->details.operation_finished.emsg)
174 if (++cont_fails > num_cont_fails)
176 printf ("\nAborting due to very high failure rate\n");
177 print_overlay_links_summary ();
178 GNUNET_SCHEDULER_shutdown ();
183 case GNUNET_TESTBED_ET_CONNECT:
187 if (0 == established_links)
188 printf ("Establishing links. Please wait\n");
201 * Signature of a main function for a testcase.
204 * @param h the run handle
205 * @param num_peers number of peers in 'peers'
206 * @param peers handle to peers run in the testbed
207 * @param links_succeeded the number of overlay link connection attempts that
209 * @param links_failed the number of overlay link
213 struct GNUNET_TESTBED_RunHandle *h,
214 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
215 unsigned int links_succeeded,
216 unsigned int links_failed)
219 fprintf (stdout, "\n");
220 print_overlay_links_summary ();
221 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
224 GNUNET_SCHEDULER_cancel (abort_task);
228 #if (!ENABLE_SUPERMUC)
229 fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
233 fprintf (stdout, "Shutting down. Please wait\n");
235 GNUNET_SCHEDULER_shutdown ();
240 * Main function that will be run by the scheduler.
243 * @param args remaining command-line arguments
244 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
245 * @param config configuration
248 run (void *cls, char *const *args, const char *cfgfile,
249 const struct GNUNET_CONFIGURATION_Handle *config)
253 LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
257 cfg = GNUNET_CONFIGURATION_dup (config);
259 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
260 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
261 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
262 &controller_event_cb, NULL,
265 GNUNET_SCHEDULER_add_shutdown (&do_abort,
273 * @return 0 on success
276 main (int argc, char *const *argv)
278 struct GNUNET_GETOPT_CommandLineOption options[] = {
280 GNUNET_GETOPT_option_uint ('p',
283 gettext_noop ("create COUNT number of peers"),
286 GNUNET_GETOPT_option_uint ('e',
289 gettext_noop ("tolerate COUNT number of continious timeout failures"),
292 GNUNET_GETOPT_option_flag ('n',
294 gettext_noop ("run profiler in non-interactive mode where upon "
295 "testbed setup the profiler does not wait for a "
296 "keystroke but continues to run until a termination "
297 "signal is received"),
301 GNUNET_GETOPT_option_string ('H',
304 gettext_noop ("name of the file with the login information for the testbed"),
307 GNUNET_GETOPT_OPTION_END
309 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
312 unsetenv ("XDG_DATA_HOME");
313 unsetenv ("XDG_CONFIG_HOME");
314 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
316 result = GNUNET_SYSERR;
318 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
319 options, &run, NULL);
320 GNUNET_free ((void *) argv);
321 if (GNUNET_OK != ret)
323 if (GNUNET_OK != result)