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;
67 static struct TEST_result results[MEASUREMENTS];
69 struct GNUNET_STATISTICS_GetHandle * s_solution;
70 struct GNUNET_STATISTICS_GetHandle * s_time;
71 struct GNUNET_STATISTICS_GetHandle * s_peers;
72 struct GNUNET_STATISTICS_GetHandle * s_mechs;
73 struct GNUNET_STATISTICS_GetHandle * s_duration;
74 struct GNUNET_STATISTICS_GetHandle * s_invalid;
77 * Check whether peers successfully shut down.
80 shutdown_callback (void *cls, const char *emsg)
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "All peers successfully shut down!\n");
96 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
102 static void shutdown_peers()
104 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
106 GNUNET_SCHEDULER_cancel(shutdown_task);
107 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
109 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
111 GNUNET_SCHEDULER_cancel(stats_task);
112 stats_task = GNUNET_SCHEDULER_NO_TASK;
117 GNUNET_STATISTICS_get_cancel(s_time);
122 GNUNET_STATISTICS_get_cancel(s_peers);
127 GNUNET_STATISTICS_get_cancel(s_mechs);
130 if (s_solution != NULL)
132 GNUNET_STATISTICS_get_cancel(s_solution);
135 if (s_duration != NULL)
137 GNUNET_STATISTICS_get_cancel(s_duration);
140 if (s_invalid != NULL)
142 GNUNET_STATISTICS_get_cancel(s_invalid);
146 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
149 static void evaluate_measurements()
152 char * output = NULL;
156 double measure = MEASUREMENTS;
157 for (c=0; c<MEASUREMENTS;c++)
159 average += (double) results[c].duration;
160 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);
161 GNUNET_free_non_null (output);
166 for (c=0; c<MEASUREMENTS;c++)
168 stddev += (results[c].duration - average) * (results[c].duration - average);
171 stddev = sqrt (stddev);
173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"%savg,%f,stddev,%f\n",output,average,stddev);
174 /* only log benchmark time for 10 peers */
175 if (results[MEASUREMENTS-1].peers == (10))
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Send data to gauger: %f \n", average);
178 GAUGER ("TRANSPORT", "ATS execution time 10 peers", average , "ms");
183 int stats_cb (void *cls,
184 const char *subsystem,
189 if (0 == strcmp (name,"ATS invalid solutions"))
191 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
193 GNUNET_SCHEDULER_cancel(stats_task);
194 stats_task = GNUNET_SCHEDULER_NO_TASK;
196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu result(s)!\n", value);
198 return GNUNET_SYSERR;
201 if (0 == strcmp (name,"ATS solution"))
206 if (0 == strcmp (name,"ATS peers"))
211 if (0 == strcmp (name,"ATS mechanisms"))
216 if (0 == strcmp (name,"ATS duration"))
220 if (0 == strcmp (name,"ATS timestamp"))
225 if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == peers-1))
227 measurement_started = GNUNET_YES;
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
232 if (measurement_started == GNUNET_YES)
234 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
235 if (0 == strcmp (name,"ATS timestamp"))
237 if (results[r_index].timestamp == 0)
238 results[r_index].timestamp = value;
239 if (results[r_index].timestamp != value)
242 fprintf(stderr, "(%i/%i)", r_index, MEASUREMENTS);
243 if (r_index >= MEASUREMENTS)
245 fprintf(stderr, "\n");
246 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
248 GNUNET_SCHEDULER_cancel(stats_task);
249 stats_task = GNUNET_SCHEDULER_NO_TASK;
251 evaluate_measurements();
252 return GNUNET_SYSERR;
254 fprintf(stderr, "..");
256 results[r_index].timestamp = value;
261 if (0 == strcmp (name,"ATS solution"))
263 results[r_index].solution = value;
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS solution: %s %llu \n", r_index, name, value);
267 if (0 == strcmp (name,"ATS peers"))
269 results[r_index].peers = value;
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS peers: %s %llu \n", r_index, name, value);
273 if (0 == strcmp (name,"ATS mechanisms"))
275 results[r_index].mechs = value;
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS mechanisms: %s %llu \n", r_index, name, value);
279 if (0 == strcmp (name,"ATS duration"))
281 results[r_index].duration = value;
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS duration: %s %llu \n", r_index, name, value);
290 stats_get_task (void *cls,
291 const struct GNUNET_SCHEDULER_TaskContext *tc)
293 stats_task = GNUNET_SCHEDULER_NO_TASK;
294 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
297 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
298 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
299 s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL);
300 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
301 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
302 s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", TIMEOUT, NULL, &stats_cb, NULL);
305 stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), &stats_get_task, NULL);
310 const struct GNUNET_SCHEDULER_TaskContext *tc)
312 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
313 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
322 static void connect_peers()
324 shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
328 void daemon_connect_cb(void *cls,
329 const struct GNUNET_PeerIdentity *first,
330 const struct GNUNET_PeerIdentity *second,
332 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
333 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
334 struct GNUNET_TESTING_Daemon *first_daemon,
335 struct GNUNET_TESTING_Daemon *second_daemon,
338 char * firstc = strdup(GNUNET_i2s(first));
339 char * secondc = strdup(GNUNET_i2s(second));
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s' (%i/%i)\n", firstc, secondc, connected, peers-1);
343 GNUNET_free(secondc);
346 void cont_cb (void *cls, int success)
348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
349 "STATS cont_cb: %i\n", success);
353 daemon_start_cb (void *cls,
354 const struct GNUNET_PeerIdentity *id,
355 const struct GNUNET_CONFIGURATION_Handle *cfg,
356 struct GNUNET_TESTING_Daemon *d, const char *emsg)
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
361 "Start callback called with error (too long starting peers), aborting test!\n");
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
364 if (failed_peers == peers_left)
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Too many peers failed, ending test!\n");
375 if (master_deamon == NULL)
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
380 stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
381 GNUNET_assert (stats != NULL);
382 stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
387 GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "All peers started successfully!\n");
397 else if (failed_peers == peers_left)
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Too many peers failed, ending test!\n");
410 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
413 measurement_started = GNUNET_NO;
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
418 pg = GNUNET_TESTING_daemons_start (cfg,
419 peers_left, /* Total number of peers */
420 peers_left, /* Number of outstanding connections */
421 peers_left, /* Number of parallel ssh connections, or peers being started at once */
424 &daemon_start_cb, NULL, NULL, NULL, NULL);
425 GNUNET_assert (pg != NULL);
431 char *const argv[] = { "test-testing",
433 "test_transport_ats.conf",
439 struct GNUNET_GETOPT_CommandLineOption options[] = {
440 GNUNET_GETOPT_OPTION_END
442 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
443 argv, "test-transport-ats", "nohelp",
449 main (int argc, char *argv[])
453 GNUNET_log_setup ("test-transport-ats",
460 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
465 peers = atoi(argv[1]);
470 * Still need to remove the base testing directory here,
471 * because group starts will create subdirectories under this
472 * main dir. However, we no longer need to sleep, as the
473 * shutdown sequence won't return until everything is cleaned
476 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
480 /* end of test_transport_ats.c*/