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 it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @file testbed/gnunet-testbed-profiler.c
18 * @brief Profiling driver for the testbed.
19 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testbed_service.h"
25 #include "testbed_api_hosts.h"
28 * Generic loggins shorthand
30 #define LOG(kind,...) \
31 GNUNET_log (kind, __VA_ARGS__)
35 * Handle to global configuration
37 struct GNUNET_CONFIGURATION_Handle *cfg;
40 * Peer linking - topology operation
42 struct GNUNET_TESTBED_Operation *topology_op;
45 * Name of the file with the hosts to run the test over (configuration option).
46 * It will be NULL if ENABLE_LL is set
48 static char *hosts_file;
51 * Abort task identifier
53 static struct GNUNET_SCHEDULER_Task *abort_task;
56 * Global event mask for all testbed events
61 * Number of peers to be started by the profiler
63 static unsigned int num_peers;
66 * Number of timeout failures to tolerate
68 static unsigned int num_cont_fails;
71 * Continuous failures during overlay connect operations
73 static unsigned int cont_fails;
76 * Links which are successfully established
78 static unsigned int established_links;
81 * Links which are not successfully established
83 static unsigned int failed_links;
86 * Global testing status
91 * Are we running non interactively
93 static int noninteractive;
102 do_shutdown (void *cls)
104 if (NULL != abort_task)
106 GNUNET_SCHEDULER_cancel (abort_task);
111 GNUNET_CONFIGURATION_destroy (cfg);
118 * abort task to run on test timed out
126 LOG (GNUNET_ERROR_TYPE_WARNING,
128 result = GNUNET_SYSERR;
129 GNUNET_SCHEDULER_shutdown ();
134 * Function to print summary about how many overlay links we have made and how
138 print_overlay_links_summary ()
140 static int printed_already;
142 if (GNUNET_YES == printed_already)
144 printed_already = GNUNET_YES;
145 printf ("%u links succeeded\n", established_links);
146 printf ("%u links failed due to timeouts\n", failed_links);
151 * Controller event callback
154 * @param event the controller event
157 controller_event_cb (void *cls,
158 const struct GNUNET_TESTBED_EventInformation *event)
162 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
163 /* Control reaches here when a peer linking operation fails */
164 if (NULL != event->details.operation_finished.emsg)
169 if (++cont_fails > num_cont_fails)
171 printf ("\nAborting due to very high failure rate\n");
172 print_overlay_links_summary ();
173 GNUNET_SCHEDULER_shutdown ();
178 case GNUNET_TESTBED_ET_CONNECT:
182 if (0 == established_links)
183 printf ("Establishing links. Please wait\n");
196 * Signature of a main function for a testcase.
199 * @param h the run handle
200 * @param num_peers number of peers in 'peers'
201 * @param peers handle to peers run in the testbed
202 * @param links_succeeded the number of overlay link connection attempts that
204 * @param links_failed the number of overlay link
208 struct GNUNET_TESTBED_RunHandle *h,
209 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
210 unsigned int links_succeeded,
211 unsigned int links_failed)
214 fprintf (stdout, "\n");
215 print_overlay_links_summary ();
216 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
219 GNUNET_SCHEDULER_cancel (abort_task);
223 #if (!ENABLE_SUPERMUC)
224 fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
228 fprintf (stdout, "Shutting down. Please wait\n");
230 GNUNET_SCHEDULER_shutdown ();
235 * Main function that will be run by the scheduler.
238 * @param args remaining command-line arguments
239 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
240 * @param config configuration
243 run (void *cls, char *const *args, const char *cfgfile,
244 const struct GNUNET_CONFIGURATION_Handle *config)
248 LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
252 cfg = GNUNET_CONFIGURATION_dup (config);
254 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
255 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
256 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
257 &controller_event_cb, NULL,
260 GNUNET_SCHEDULER_add_shutdown (&do_abort,
268 * @return 0 on success
271 main (int argc, char *const *argv)
273 struct GNUNET_GETOPT_CommandLineOption options[] = {
275 GNUNET_GETOPT_option_uint ('p',
278 gettext_noop ("create COUNT number of peers"),
281 GNUNET_GETOPT_option_uint ('e',
284 gettext_noop ("tolerate COUNT number of continious timeout failures"),
287 GNUNET_GETOPT_option_flag ('n',
289 gettext_noop ("run profiler in non-interactive mode where upon "
290 "testbed setup the profiler does not wait for a "
291 "keystroke but continues to run until a termination "
292 "signal is received"),
296 GNUNET_GETOPT_option_string ('H',
299 gettext_noop ("name of the file with the login information for the testbed"),
302 GNUNET_GETOPT_OPTION_END
304 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
307 unsetenv ("XDG_DATA_HOME");
308 unsetenv ("XDG_CONFIG_HOME");
309 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
311 result = GNUNET_SYSERR;
313 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
314 options, &run, NULL);
315 GNUNET_free ((void *) argv);
316 if (GNUNET_OK != ret)
318 if (GNUNET_OK != result)