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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file testbed/gnunet-testbed-profiler.c
21 * @brief Profiling driver for the testbed.
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testbed_service.h"
28 #include "testbed_api_hosts.h"
31 * Generic loggins shorthand
33 #define LOG(kind,...) \
34 GNUNET_log (kind, __VA_ARGS__)
38 * Handle to global configuration
40 struct GNUNET_CONFIGURATION_Handle *cfg;
43 * Peer linking - topology operation
45 struct GNUNET_TESTBED_Operation *topology_op;
48 * Name of the file with the hosts to run the test over (configuration option).
49 * It will be NULL if ENABLE_LL is set
51 static char *hosts_file;
54 * Abort task identifier
56 static struct GNUNET_SCHEDULER_Task *abort_task;
59 * Global event mask for all testbed events
64 * Number of peers to be started by the profiler
66 static unsigned int num_peers;
69 * Number of timeout failures to tolerate
71 static unsigned int num_cont_fails;
74 * Continuous failures during overlay connect operations
76 static unsigned int cont_fails;
79 * Links which are successfully established
81 static unsigned int established_links;
84 * Links which are not successfully established
86 static unsigned int failed_links;
89 * Global testing status
94 * Are we running non interactively
96 static int noninteractive;
105 do_shutdown (void *cls)
107 if (NULL != abort_task)
109 GNUNET_SCHEDULER_cancel (abort_task);
114 GNUNET_CONFIGURATION_destroy (cfg);
121 * abort task to run on test timed out
129 LOG (GNUNET_ERROR_TYPE_WARNING,
131 result = GNUNET_SYSERR;
132 GNUNET_SCHEDULER_shutdown ();
137 * Function to print summary about how many overlay links we have made and how
141 print_overlay_links_summary ()
143 static int printed_already;
145 if (GNUNET_YES == printed_already)
147 printed_already = GNUNET_YES;
148 printf ("%u links succeeded\n", established_links);
149 printf ("%u links failed due to timeouts\n", failed_links);
154 * Controller event callback
157 * @param event the controller event
160 controller_event_cb (void *cls,
161 const struct GNUNET_TESTBED_EventInformation *event)
165 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
166 /* Control reaches here when a peer linking operation fails */
167 if (NULL != event->details.operation_finished.emsg)
172 if (++cont_fails > num_cont_fails)
174 printf ("\nAborting due to very high failure rate\n");
175 print_overlay_links_summary ();
176 GNUNET_SCHEDULER_shutdown ();
181 case GNUNET_TESTBED_ET_CONNECT:
185 if (0 == established_links)
186 printf ("Establishing links. Please wait\n");
199 * Signature of a main function for a testcase.
202 * @param h the run handle
203 * @param num_peers number of peers in 'peers'
204 * @param peers handle to peers run in the testbed
205 * @param links_succeeded the number of overlay link connection attempts that
207 * @param links_failed the number of overlay link
211 struct GNUNET_TESTBED_RunHandle *h,
212 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
213 unsigned int links_succeeded,
214 unsigned int links_failed)
217 fprintf (stdout, "\n");
218 print_overlay_links_summary ();
219 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
222 GNUNET_SCHEDULER_cancel (abort_task);
226 #if (!ENABLE_SUPERMUC)
227 fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
231 fprintf (stdout, "Shutting down. Please wait\n");
233 GNUNET_SCHEDULER_shutdown ();
238 * Main function that will be run by the scheduler.
241 * @param args remaining command-line arguments
242 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
243 * @param config configuration
246 run (void *cls, char *const *args, const char *cfgfile,
247 const struct GNUNET_CONFIGURATION_Handle *config)
251 LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
255 cfg = GNUNET_CONFIGURATION_dup (config);
257 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
258 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
259 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
260 &controller_event_cb, NULL,
263 GNUNET_SCHEDULER_add_shutdown (&do_abort,
271 * @return 0 on success
274 main (int argc, char *const *argv)
276 struct GNUNET_GETOPT_CommandLineOption options[] = {
278 GNUNET_GETOPT_option_uint ('p',
281 gettext_noop ("create COUNT number of peers"),
284 GNUNET_GETOPT_option_uint ('e',
287 gettext_noop ("tolerate COUNT number of continious timeout failures"),
290 GNUNET_GETOPT_option_flag ('n',
292 gettext_noop ("run profiler in non-interactive mode where upon "
293 "testbed setup the profiler does not wait for a "
294 "keystroke but continues to run until a termination "
295 "signal is received"),
299 GNUNET_GETOPT_option_string ('H',
302 gettext_noop ("name of the file with the login information for the testbed"),
305 GNUNET_GETOPT_OPTION_END
307 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
310 unsetenv ("XDG_DATA_HOME");
311 unsetenv ("XDG_CONFIG_HOME");
312 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
314 result = GNUNET_SYSERR;
316 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
317 options, &run, NULL);
318 GNUNET_free ((void *) argv);
319 if (GNUNET_OK != ret)
321 if (GNUNET_OK != result)