GNUnet  0.10.x
gnunet-testbed-profiler.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2008--2013 GNUnet e.V.
4 
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.
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  Affero General Public License for more details.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "testbed_api_hosts.h"
31 
35 #define LOG(kind,...) \
36  GNUNET_log (kind, __VA_ARGS__)
37 
38 
43 
48 
53 static char *hosts_file;
54 
59 
63 uint64_t event_mask;
64 
68 static unsigned int num_peers;
69 
73 static unsigned int num_cont_fails;
74 
78 static unsigned int cont_fails;
79 
83 static unsigned int established_links;
84 
88 static unsigned int failed_links;
89 
93 static int result;
94 
98 static int noninteractive;
99 
100 
106 static void
107 do_shutdown (void *cls)
108 {
109  if (NULL != abort_task)
110  {
111  GNUNET_SCHEDULER_cancel (abort_task);
112  abort_task = NULL;
113  }
114  if (NULL != cfg)
115  {
117  cfg = NULL;
118  }
119 }
120 
121 
127 static void
128 do_abort (void *cls)
129 {
130  abort_task = NULL;
132  "Aborting\n");
135 }
136 
137 
142 static void
144 {
145  static int printed_already;
146 
147  if (GNUNET_YES == printed_already)
148  return;
149  printed_already = GNUNET_YES;
150  printf ("%u links succeeded\n", established_links);
151  printf ("%u links failed due to timeouts\n", failed_links);
152 }
153 
154 
161 static void
163  const struct GNUNET_TESTBED_EventInformation *event)
164 {
165  switch (event->type)
166  {
168  /* Control reaches here when a peer linking operation fails */
169  if (NULL != event->details.operation_finished.emsg)
170  {
171  printf ("F");
172  fflush (stdout);
173  failed_links++;
174  if (++cont_fails > num_cont_fails)
175  {
176  printf ("\nAborting due to very high failure rate\n");
179  return;
180  }
181  }
182  break;
184  {
185  if (0 != cont_fails)
186  cont_fails--;
187  if (0 == established_links)
188  printf ("Establishing links. Please wait\n");
189  printf (".");
190  fflush (stdout);
192  }
193  break;
194  default:
195  GNUNET_break (0);
196  }
197 }
198 
199 
211 static void
212 test_run (void *cls,
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)
217 {
218  result = GNUNET_OK;
219  fprintf (stdout, "\n");
222  if (noninteractive)
223  {
224  GNUNET_SCHEDULER_cancel (abort_task);
225  abort_task = NULL;
226  return;
227  }
228 #if (!ENABLE_SUPERMUC)
229  fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
230  fflush (stdout);
231  (void) getc (stdin);
232 #endif
233  fprintf (stdout, "Shutting down. Please wait\n");
234  fflush (stdout);
236 }
237 
238 
247 static void
248 run (void *cls, char *const *args, const char *cfgfile,
249  const struct GNUNET_CONFIGURATION_Handle *config)
250 {
251  if (0 == num_peers)
252  {
253  LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
254  num_peers);
255  return;
256  }
257  cfg = GNUNET_CONFIGURATION_dup (config);
258  event_mask = 0;
262  &controller_event_cb, NULL,
263  &test_run, NULL);
264  abort_task =
266  NULL);
267 }
268 
269 
275 int
276 main (int argc, char *const *argv)
277 {
278  struct GNUNET_GETOPT_CommandLineOption options[] = {
280  "num-peers",
281  "COUNT",
282  gettext_noop ("create COUNT number of peers"),
283  &num_peers),
285  "num-errors",
286  "COUNT",
287  gettext_noop ("tolerate COUNT number of continious timeout failures"),
288  &num_cont_fails),
290  "non-interactive",
291  gettext_noop ("run profiler in non-interactive mode where upon "
292  "testbed setup the profiler does not wait for a "
293  "keystroke but continues to run until a termination "
294  "signal is received"),
295  &noninteractive),
296 #if !ENABLE_SUPERMUC
298  "hosts",
299  "FILENAME",
300  gettext_noop ("name of the file with the login information for the testbed"),
301  &hosts_file),
302 #endif
304  };
305  const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
306  int ret;
307 
308  unsetenv ("XDG_DATA_HOME");
309  unsetenv ("XDG_CONFIG_HOME");
310  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
311  return 2;
313  ret =
314  GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
315  options, &run, NULL);
316  GNUNET_free ((void *) argv);
317  if (GNUNET_OK != ret)
318  return ret;
319  if (GNUNET_OK != result)
320  return 1;
321  return 0;
322 }
#define LOG(kind,...)
Generic loggins shorthand.
static void controller_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Controller event callback.
static unsigned int failed_links
Links which are not successfully established.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main function that will be run by the scheduler.
static int noninteractive
Are we running non interactively.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
enum GNUNET_TESTBED_EventType type
Type of the event.
Definition of a command line option.
struct GNUNET_TESTBED_Operation * topology_op
Peer linking - topology operation.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static int ret
Final status code.
Definition: gnunet-arm.c:89
static void print_overlay_links_summary()
Function to print summary about how many overlay links we have made and how many failed.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Opaque handle to an abstract operation to be executed by the testing framework.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static unsigned int established_links
Links which are successfully established.
static int result
Global testing status.
A requested testbed operation has been completed.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static const struct GNUNET_CONFIGURATION_Handle * config
static unsigned int num_peers
Number of peers to be started by the profiler.
static void do_abort(void *cls)
abort task to run on test timed out
void GNUNET_TESTBED_run(const char *host_filename, const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a testbed with a single call.
struct GNUNET_TESTBED_EventInformation::@58::@63 operation_finished
Details about an operation finished event.
static unsigned int cont_fails
Continuous failures during overlay connect operations.
uint64_t event_mask
Global event mask for all testbed events.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
union GNUNET_TESTBED_EventInformation::@58 details
Details about the event.
int main(int argc, char *const *argv)
Main function.
A connection between two peers was established.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
configuration data
Definition: configuration.c:85
static struct CadetPeer * peers
Operation to get peer ids.
static void test_run(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
Signature of a main function for a testcase.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
static char * hosts_file
Name of the file with the hosts to run the test over (configuration option).
Entry in list of pending tasks.
Definition: scheduler.c:134
static unsigned int num_cont_fails
Number of timeout failures to tolerate.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
#define GNUNET_YES
Definition: gnunet_common.h:80
internal API to access the &#39;hosts&#39; subsystem
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
static void do_shutdown(void *cls)
Shutdown nicely.
A peer controlled by the testing framework.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965