GNUnet  0.19.4
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  {
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;
183 
185  {
186  if (0 != cont_fails)
187  cont_fails--;
188  if (0 == established_links)
189  printf ("Establishing links. Please wait\n");
190  printf (".");
191  fflush (stdout);
193  }
194  break;
195 
196  default:
197  GNUNET_break (0);
198  }
199 }
200 
201 
213 static void
214 test_run (void *cls,
215  struct GNUNET_TESTBED_RunHandle *h,
216  unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
217  unsigned int links_succeeded,
218  unsigned int links_failed)
219 {
220  result = GNUNET_OK;
221  fprintf (stdout, "\n");
224  if (noninteractive)
225  {
227  abort_task = NULL;
228  return;
229  }
230  fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
231  fflush (stdout);
232  (void) getc (stdin);
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  }
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 {
280  "num-peers",
281  "COUNT",
282  gettext_noop ("create COUNT number of peers"),
283  &num_peers),
285  "num-errors",
286  "COUNT",
287  gettext_noop (
288  "tolerate COUNT number of continuous timeout failures"),
289  &num_cont_fails),
291  "non-interactive",
292  gettext_noop (
293  "run profiler in non-interactive mode where upon "
294  "testbed setup the profiler does not wait for a "
295  "keystroke but continues to run until a termination "
296  "signal is received"),
297  &noninteractive),
299  "hosts",
300  "FILENAME",
301  gettext_noop (
302  "name of the file with the login information for the testbed"),
303  &hosts_file),
305  };
306  const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
307  int ret;
308 
309  unsetenv ("XDG_DATA_HOME");
310  unsetenv ("XDG_CONFIG_HOME");
311  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
312  return 2;
314  ret =
315  GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
316  options, &run, NULL);
317  GNUNET_free_nz ((void *) argv);
318  if (GNUNET_OK != ret)
319  return ret;
320  if (GNUNET_OK != result)
321  return 1;
322  return 0;
323 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct CadetPeer * peers
Operation to get peer ids.
static const struct GNUNET_CONFIGURATION_Handle * config
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
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.
static void controller_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Controller event callback.
static unsigned int num_cont_fails
Number of timeout failures to tolerate.
static void do_abort(void *cls)
abort task to run on test timed out
struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
static void do_shutdown(void *cls)
Shutdown nicely.
uint64_t event_mask
Global event mask for all testbed events.
static char * hosts_file
Name of the file with the hosts to run the test over (configuration option).
static int result
Global testing status.
static int noninteractive
Are we running non interactively.
static unsigned int cont_fails
Continuous failures during overlay connect operations.
struct GNUNET_TESTBED_Operation * topology_op
Peer linking - topology operation.
static unsigned int failed_links
Links which are not successfully established.
static void print_overlay_links_summary()
Function to print summary about how many overlay links we have made and how many failed.
#define LOG(kind,...)
Generic loggins shorthand.
int main(int argc, char *const *argv)
Main function.
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 unsigned int num_peers
Number of peers to be started by the profiler.
static unsigned int established_links
Links which are successfully established.
API for writing tests and creating large-scale emulation testbeds for GNUnet.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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.
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.
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.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
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,...
Definition: scheduler.c:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
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.
@ GNUNET_TESTBED_ET_CONNECT
A connection between two peers was established.
@ GNUNET_TESTBED_ET_OPERATION_FINISHED
A requested testbed operation has been completed.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Definition of a command line option.
Entry in list of pending tasks.
Definition: scheduler.c:136
Argument to GNUNET_TESTBED_ControllerCallback with details about the event.
enum GNUNET_TESTBED_EventType type
Type of the event.
union GNUNET_TESTBED_EventInformation::@43 details
Details about the event.
struct GNUNET_TESTBED_EventInformation::@43::@48 operation_finished
Details about an operation finished event.
Opaque handle to an abstract operation to be executed by the testing framework.
A peer controlled by the testing framework.
internal API to access the 'hosts' subsystem