2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file testing/test_transport_ats.c
22 * @brief testcase for ats functionality
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_scheduler_lib.h"
29 #define VERBOSE GNUNET_NO
32 #define MEASUREMENTS 5
34 #define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
40 static int peers_left;
42 static int failed_peers;
44 static int measurement_started = GNUNET_NO;
46 static struct GNUNET_TESTING_PeerGroup *pg;
48 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
49 static GNUNET_SCHEDULER_TaskIdentifier stats_task;
50 struct GNUNET_TESTING_Daemon * master_deamon;
52 struct GNUNET_STATISTICS_Handle * stats;
64 //static int measurements;
68 static struct TEST_result results[MEASUREMENTS];
70 static struct GNUNET_STATISTICS_GetHandle * s_solution;
71 static struct GNUNET_STATISTICS_GetHandle * s_time;
72 static struct GNUNET_STATISTICS_GetHandle * s_peers;
73 static struct GNUNET_STATISTICS_GetHandle * s_mechs;
74 static struct GNUNET_STATISTICS_GetHandle * s_duration;
75 static struct GNUNET_STATISTICS_GetHandle * s_invalid;
78 * Check whether peers successfully shut down.
81 shutdown_callback (void *cls, const char *emsg)
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
95 "All peers successfully shut down!\n");
97 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
103 static void shutdown_peers()
105 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
107 GNUNET_SCHEDULER_cancel(shutdown_task);
108 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
110 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
112 GNUNET_SCHEDULER_cancel(stats_task);
113 stats_task = GNUNET_SCHEDULER_NO_TASK;
118 GNUNET_STATISTICS_get_cancel(s_time);
123 GNUNET_STATISTICS_get_cancel(s_peers);
128 GNUNET_STATISTICS_get_cancel(s_mechs);
131 if (s_solution != NULL)
133 GNUNET_STATISTICS_get_cancel(s_solution);
136 if (s_duration != NULL)
138 GNUNET_STATISTICS_get_cancel(s_duration);
141 if (s_invalid != NULL)
143 GNUNET_STATISTICS_get_cancel(s_invalid);
147 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
150 static void evaluate_measurements()
153 char * output = NULL;
157 double measure = MEASUREMENTS;
158 for (c=0; c<MEASUREMENTS;c++)
160 average += (double) results[c].duration;
161 GNUNET_asprintf(&temp, "%sm%i,%llu,%llu,%llu,%llu,", (output==NULL) ? "" : output, c, results[c].peers, results[c].mechs, results[c].duration, results[c].solution);
162 GNUNET_free_non_null (output);
167 for (c=0; c<MEASUREMENTS;c++)
169 stddev += (results[c].duration - average) * (results[c].duration - average);
172 stddev = sqrt (stddev);
174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"%savg,%f,stddev,%f\n",output,average,stddev);
175 /* only log benchmark time for 10 peers */
176 if (results[MEASUREMENTS-1].peers == (10))
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Send data to gauger: %f \n", average);
179 GAUGER ("TRANSPORT", "ATS execution time 10 peers", average , "ms");
184 int stats_cb (void *cls,
185 const char *subsystem,
190 if (0 == strcmp (name,"ATS invalid solutions"))
192 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
194 GNUNET_SCHEDULER_cancel(stats_task);
195 stats_task = GNUNET_SCHEDULER_NO_TASK;
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu result(s)!\n", value);
199 return GNUNET_SYSERR;
202 if (0 == strcmp (name,"ATS solution"))
207 if (0 == strcmp (name,"ATS peers"))
212 if (0 == strcmp (name,"ATS mechanisms"))
217 if (0 == strcmp (name,"ATS duration"))
221 if (0 == strcmp (name,"ATS timestamp"))
226 if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == peers-1))
228 measurement_started = GNUNET_YES;
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
233 if (measurement_started == GNUNET_YES)
235 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
236 if (0 == strcmp (name,"ATS timestamp"))
238 if (results[r_index].timestamp == 0)
239 results[r_index].timestamp = value;
240 if (results[r_index].timestamp != value)
243 fprintf(stdout, "(%i/%i)", r_index, MEASUREMENTS);
244 if (r_index >= MEASUREMENTS)
246 fprintf(stdout, "\n");
247 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
249 GNUNET_SCHEDULER_cancel(stats_task);
250 stats_task = GNUNET_SCHEDULER_NO_TASK;
252 evaluate_measurements();
253 return GNUNET_SYSERR;
255 fprintf(stdout, "..");
257 results[r_index].timestamp = value;
262 if (0 == strcmp (name,"ATS solution"))
264 results[r_index].solution = value;
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS solution: %s %llu \n", r_index, name, value);
268 if (0 == strcmp (name,"ATS peers"))
270 results[r_index].peers = value;
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS peers: %s %llu \n", r_index, name, value);
274 if (0 == strcmp (name,"ATS mechanisms"))
276 results[r_index].mechs = value;
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS mechanisms: %s %llu \n", r_index, name, value);
280 if (0 == strcmp (name,"ATS duration"))
282 results[r_index].duration = value;
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS duration: %s %llu \n", r_index, name, value);
291 stats_get_task (void *cls,
292 const struct GNUNET_SCHEDULER_TaskContext *tc)
294 stats_task = GNUNET_SCHEDULER_NO_TASK;
295 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
298 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
299 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
300 s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL);
301 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
302 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
303 s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", TIMEOUT, NULL, &stats_cb, NULL);
306 stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), &stats_get_task, NULL);
311 const struct GNUNET_SCHEDULER_TaskContext *tc)
313 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
314 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
318 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
323 static void connect_peers()
325 shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
329 void daemon_connect_cb(void *cls,
330 const struct GNUNET_PeerIdentity *first,
331 const struct GNUNET_PeerIdentity *second,
333 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
334 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
335 struct GNUNET_TESTING_Daemon *first_daemon,
336 struct GNUNET_TESTING_Daemon *second_daemon,
339 char * firstc = strdup(GNUNET_i2s(first));
340 char * secondc = strdup(GNUNET_i2s(second));
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s' (%i/%i)\n", firstc, secondc, connected, peers-1);
344 GNUNET_free(secondc);
347 void cont_cb (void *cls, int success)
349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
350 "STATS cont_cb: %i\n", success);
354 daemon_start_cb (void *cls,
355 const struct GNUNET_PeerIdentity *id,
356 const struct GNUNET_CONFIGURATION_Handle *cfg,
357 struct GNUNET_TESTING_Daemon *d, const char *emsg)
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Start callback called with error (too long starting peers), aborting test!\n");
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
365 if (failed_peers == peers_left)
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "Too many peers failed, ending test!\n");
376 if (master_deamon == NULL)
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
381 stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
382 GNUNET_assert (stats != NULL);
383 stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
388 GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "All peers started successfully!\n");
398 else if (failed_peers == peers_left)
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "Too many peers failed, ending test!\n");
411 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
414 measurement_started = GNUNET_NO;
416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
419 pg = GNUNET_TESTING_daemons_start (cfg,
420 peers_left, /* Total number of peers */
421 peers_left, /* Number of outstanding connections */
422 peers_left, /* Number of parallel ssh connections, or peers being started at once */
425 &daemon_start_cb, NULL, NULL, NULL, NULL);
426 GNUNET_assert (pg != NULL);
432 char *const argv[] = { "test-testing",
434 "test_transport_ats.conf",
440 struct GNUNET_GETOPT_CommandLineOption options[] = {
441 GNUNET_GETOPT_OPTION_END
443 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
444 argv, "test-transport-ats", "nohelp",
450 main (int argc, char *argv[])
454 GNUNET_log_setup ("test-transport-ats",
461 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
466 peers = atoi(argv[1]);
472 * Still need to remove the base testing directory here,
473 * because group starts will create subdirectories under this
474 * main dir. However, we no longer need to sleep, as the
475 * shutdown sequence won't return until everything is cleaned
478 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
482 /* end of test_transport_ats.c*/