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;
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  {
226  GNUNET_SCHEDULER_cancel(abort_task);
227  abort_task = NULL;
228  return;
229  }
230 #if (!ENABLE_SUPERMUC)
231  fprintf(stdout, "Testbed running, waiting for keystroke to shut down\n");
232  fflush(stdout);
233  (void)getc(stdin);
234 #endif
235  fprintf(stdout, "Shutting down. Please wait\n");
236  fflush(stdout);
238 }
239 
240 
249 static void
250 run(void *cls, char *const *args, const char *cfgfile,
251  const struct GNUNET_CONFIGURATION_Handle *config)
252 {
253  if (0 == num_peers)
254  {
255  LOG(GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
256  num_peers);
257  return;
258  }
259  cfg = GNUNET_CONFIGURATION_dup(config);
260  event_mask = 0;
264  &controller_event_cb, NULL,
265  &test_run, NULL);
266  abort_task =
268  NULL);
269 }
270 
271 
277 int
278 main(int argc, char *const *argv)
279 {
280  struct GNUNET_GETOPT_CommandLineOption options[] = {
282  "num-peers",
283  "COUNT",
284  gettext_noop("create COUNT number of peers"),
285  &num_peers),
287  "num-errors",
288  "COUNT",
289  gettext_noop("tolerate COUNT number of continious timeout failures"),
290  &num_cont_fails),
292  "non-interactive",
293  gettext_noop("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),
298 #if !ENABLE_SUPERMUC
300  "hosts",
301  "FILENAME",
302  gettext_noop("name of the file with the login information for the testbed"),
303  &hosts_file),
304 #endif
306  };
307  const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
308  int ret;
309 
310  unsetenv("XDG_DATA_HOME");
311  unsetenv("XDG_CONFIG_HOME");
312  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
313  return 2;
315  ret =
316  GNUNET_PROGRAM_run(argc, argv, "gnunet-testbed-profiler", binaryHelp,
317  options, &run, NULL);
318  GNUNET_free((void *)argv);
319  if (GNUNET_OK != ret)
320  return ret;
321  if (GNUNET_OK != result)
322  return 1;
323  return 0;
324 }
#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:1284
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
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:75
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:517
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:181
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:76
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:83
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:131
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:367
#define GNUNET_YES
Definition: gnunet_common.h:77
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:956