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;
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;
66 static struct TEST_result results[MEASUREMENTS];
68 struct GNUNET_STATISTICS_GetHandle * s_solution;
69 struct GNUNET_STATISTICS_GetHandle * s_time;
70 struct GNUNET_STATISTICS_GetHandle * s_peers;
71 struct GNUNET_STATISTICS_GetHandle * s_mechs;
72 struct GNUNET_STATISTICS_GetHandle * s_duration;
75 * Check whether peers successfully shut down.
78 shutdown_callback (void *cls, const char *emsg)
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "All peers successfully shut down!\n");
94 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
100 static void shutdown_peers()
102 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
104 GNUNET_SCHEDULER_cancel(shutdown_task);
105 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
107 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
109 GNUNET_SCHEDULER_cancel(stats_task);
110 stats_task = GNUNET_SCHEDULER_NO_TASK;
115 GNUNET_STATISTICS_get_cancel(s_time);
120 GNUNET_STATISTICS_get_cancel(s_peers);
125 GNUNET_STATISTICS_get_cancel(s_mechs);
128 if (s_solution != NULL)
130 GNUNET_STATISTICS_get_cancel(s_solution);
133 if (s_duration != NULL)
135 GNUNET_STATISTICS_get_cancel(s_duration);
140 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
143 static void evaluate_measurements()
146 char * output = NULL;
150 double measure = MEASUREMENTS;
151 for (c=0; c<MEASUREMENTS;c++)
153 average += (double) results[c].duration;
154 GNUNET_asprintf(&temp, "%s ,%i,%llu,%llu,%llu,%llu,", (output==NULL) ? "" : output, c, results[c].peers, results[c].mechs, results[c].duration, results[c].solution);
155 GNUNET_free_non_null (output);
160 for (c=0; c<MEASUREMENTS;c++)
162 stddev += (results[c].duration - average) * (results[c].duration - average);
165 stddev = sqrt (stddev);
167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"%s,avg,%f,stddev,%f\n",output,average,stddev);
168 /* only log benchmark time for 10 peers */
170 if (results[c].peers == (10))
172 GAUGER ("TRANSPORT", "ATS execution time 10 peers", (int) average , "ms");
178 int stats_cb (void *cls,
179 const char *subsystem,
184 if (0 == strcmp (name,"ATS solution"))
189 if (0 == strcmp (name,"ATS peers"))
194 if (0 == strcmp (name,"ATS mechanisms"))
199 if (0 == strcmp (name,"ATS duration"))
203 if (0 == strcmp (name,"ATS timestamp"))
208 if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == peers-1))
210 measurement_started = GNUNET_YES;
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
214 if (measurement_started == GNUNET_YES)
216 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
217 if (0 == strcmp (name,"ATS timestamp"))
219 if (results[r_index].timestamp == 0)
220 results[r_index].timestamp = value;
221 if (results[r_index].timestamp != value)
224 if (r_index >= MEASUREMENTS)
226 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
228 GNUNET_SCHEDULER_cancel(stats_task);
229 stats_task = GNUNET_SCHEDULER_NO_TASK;
231 evaluate_measurements();
234 results[r_index].timestamp = value;
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238 "[%i] ATS solution: %s %llu \n", r_index, name, value);
241 if (0 == strcmp (name,"ATS solution"))
243 results[r_index].solution = value;
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "[%i] ATS solution: %s %llu \n", r_index, name, value);
248 if (0 == strcmp (name,"ATS peers"))
250 results[r_index].peers = value;
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "[%i] ATS peers: %s %llu \n", r_index, name, value);
255 if (0 == strcmp (name,"ATS mechanisms"))
257 results[r_index].mechs = value;
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS mechanisms: %s %llu \n", r_index, name, value);
261 if (0 == strcmp (name,"ATS duration"))
263 results[r_index].duration = value;
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS duration: %s %llu \n", r_index, name, value);
272 stats_get_task (void *cls,
273 const struct GNUNET_SCHEDULER_TaskContext *tc)
275 stats_task = GNUNET_SCHEDULER_NO_TASK;
276 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
279 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
280 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
281 s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL);
282 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
283 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
285 stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), &stats_get_task, NULL);
290 const struct GNUNET_SCHEDULER_TaskContext *tc)
292 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
293 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
302 static void connect_peers()
304 shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
308 void daemon_connect_cb(void *cls,
309 const struct GNUNET_PeerIdentity *first,
310 const struct GNUNET_PeerIdentity *second,
312 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
313 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
314 struct GNUNET_TESTING_Daemon *first_daemon,
315 struct GNUNET_TESTING_Daemon *second_daemon,
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s': `%s' \n", GNUNET_i2s(first), GNUNET_i2s(second), (emsg==NULL) ? "OK" : emsg);
321 void cont_cb (void *cls, int success)
323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
324 "STATS cont_cb: %i\n", success);
328 daemon_start_cb (void *cls,
329 const struct GNUNET_PeerIdentity *id,
330 const struct GNUNET_CONFIGURATION_Handle *cfg,
331 struct GNUNET_TESTING_Daemon *d, const char *emsg)
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Start callback called with error (too long starting peers), aborting test!\n");
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
339 if (failed_peers == peers_left)
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
342 "Too many peers failed, ending test!\n");
350 if (master_deamon == NULL)
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
355 stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
356 GNUNET_assert (stats != NULL);
357 stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
362 GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "All peers started successfully!\n");
372 else if (failed_peers == peers_left)
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Too many peers failed, ending test!\n");
376 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
385 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
388 measurement_started = GNUNET_NO;
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", NUM_PEERS);
393 pg = GNUNET_TESTING_daemons_start (cfg,
394 peers_left, /* Total number of peers */
395 peers_left, /* Number of outstanding connections */
396 peers_left, /* Number of parallel ssh connections, or peers being started at once */
399 &daemon_start_cb, NULL, NULL, NULL, NULL);
400 GNUNET_assert (pg != NULL);
406 char *const argv[] = { "test-testing",
408 "test_transport_ats.conf",
414 struct GNUNET_GETOPT_CommandLineOption options[] = {
415 GNUNET_GETOPT_OPTION_END
417 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
418 argv, "test-testing-group", "nohelp",
424 main (int argc, char *argv[])
428 GNUNET_log_setup ("test-transport-ats",
439 peers = atoi(argv[1]);
446 * Still need to remove the base testing directory here,
447 * because group starts will create subdirectories under this
448 * main dir. However, we no longer need to sleep, as the
449 * shutdown sequence won't return until everything is cleaned
452 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
456 /* end of test_transport_ats.c*/