2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 GNUnet e.V.
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.
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.
17 * @file fs/perf_gnunet_service_fs_p2p.c
18 * @brief profile P2P routing using simple publish + download operation
19 * @author Christian Grothoff
22 #include "fs_test_lib.h"
23 #include "gnunet_testbed_service.h"
25 #define VERBOSE GNUNET_NO
28 * File-size we use for testing.
30 #define FILESIZE (1024 * 1024 * 10)
33 * How long until we give up on transmitting the message?
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
41 static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
45 static struct GNUNET_TIME_Absolute start_time;
47 static const char *progname;
49 static struct GNUNET_TIME_Absolute start_time;
53 * Master context for 'stat_run'.
57 struct GNUNET_STATISTICS_Handle *stat;
58 struct GNUNET_TESTBED_Operation *op;
65 const char *subsystem;
70 * Statistics we print out.
72 static struct StatValues stats[] = {
73 {"fs", "# queries forwarded"},
74 {"fs", "# replies received and matched"},
75 {"fs", "# results found locally"},
76 {"fs", "# requests forwarded due to high load"},
77 {"fs", "# requests done for free (low load)"},
78 {"fs", "# requests dropped, priority insufficient"},
79 {"fs", "# requests done for a price (normal load)"},
80 {"fs", "# requests dropped by datastore (queue length limit)"},
81 {"fs", "# P2P searches received"},
82 {"fs", "# P2P searches discarded (queue length bound)"},
83 {"fs", "# replies received for local clients"},
84 {"fs", "# queries retransmitted to same target"},
85 {"core", "# bytes decrypted"},
86 {"core", "# bytes encrypted"},
87 {"core", "# discarded CORE_SEND requests"},
88 {"core", "# discarded CORE_SEND request bytes"},
89 {"core", "# discarded lower priority CORE_SEND requests"},
90 {"core", "# discarded lower priority CORE_SEND request bytes"},
91 {"transport", "# bytes received via TCP"},
92 {"transport", "# bytes transmitted via TCP"},
93 {"datacache", "# bytes stored"},
99 * Callback function to process statistic values.
102 * @param subsystem name of subsystem that created the statistic
103 * @param name the name of the datum
104 * @param value the current value
105 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
106 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
109 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
112 struct StatMaster *sm = cls;
115 "Peer %2u: %12s/%50s = %12llu\n",
119 (unsigned long long) value);
125 * Function that gathers stats from all daemons.
129 struct GNUNET_TESTBED_Operation *op,
135 * Function called when GET operation on stats is done.
138 get_done (void *cls, int success)
140 struct StatMaster *sm = cls;
142 GNUNET_break (GNUNET_OK == success);
144 stat_run (sm, sm->op, sm->stat, NULL);
149 * Adapter function called to establish a connection to
150 * statistics service.
153 * @param cfg configuration of the peer to connect to; will be available until
154 * GNUNET_TESTBED_operation_done() is called on the operation returned
155 * from GNUNET_TESTBED_service_connect()
156 * @return service handle to return in 'op_result', NULL on error
159 statistics_connect_adapter (void *cls,
160 const struct GNUNET_CONFIGURATION_Handle *cfg)
162 return GNUNET_STATISTICS_create ("<driver>",
168 * Adapter function called to destroy a connection to
169 * statistics service.
172 * @param op_result service handle returned from the connect adapter
175 statistics_disconnect_adapter (void *cls,
178 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
183 * Function that gathers stats from all daemons.
187 struct GNUNET_TESTBED_Operation *op,
191 struct StatMaster *sm = cls;
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
196 "Failed to statistics service: %s\n",
198 GNUNET_SCHEDULER_shutdown ();
201 sm->stat = ca_result;
203 if (stats[sm->value].name != NULL)
205 GNUNET_STATISTICS_get (sm->stat,
209 stats[sm->value].subsystem, stats[sm->value].name,
211 &get_done, &print_stat,
215 GNUNET_TESTBED_operation_done (sm->op);
218 if (NUM_DAEMONS == sm->daemon)
221 GNUNET_SCHEDULER_shutdown ();
225 GNUNET_TESTBED_service_connect (NULL,
229 &statistics_connect_adapter,
230 &statistics_disconnect_adapter,
236 do_report (void *cls)
239 struct GNUNET_TIME_Relative del;
241 struct StatMaster *sm;
245 GNUNET_DISK_directory_remove (fn);
249 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
250 TIMEOUT)).rel_value_us)
252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
253 "Timeout during download, shutting down with error\n");
255 GNUNET_SCHEDULER_shutdown ();
259 del = GNUNET_TIME_absolute_get_duration (start_time);
260 if (del.rel_value_us == 0)
261 del.rel_value_us = 1;
263 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
264 1000000LL / del.rel_value_us);
266 "Download speed was %s/s\n",
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Finished download, shutting down\n");
271 sm = GNUNET_new (struct StatMaster);
273 GNUNET_TESTBED_service_connect (NULL,
277 &statistics_connect_adapter,
278 &statistics_disconnect_adapter,
284 do_download (void *cls,
285 const struct GNUNET_FS_Uri *uri,
292 GNUNET_SCHEDULER_shutdown ();
293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 "Timeout during upload attempt, shutting down with error\n");
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
299 (unsigned long long) FILESIZE);
300 start_time = GNUNET_TIME_absolute_get ();
301 if (NULL != strstr (progname, "dht"))
305 start_time = GNUNET_TIME_absolute_get ();
306 GNUNET_FS_TEST_download (daemons[0],
313 (NULL == fn) ? NULL : GNUNET_strdup (fn));
318 do_publish (void *cls,
319 struct GNUNET_TESTBED_RunHandle *h,
320 unsigned int num_peers,
321 struct GNUNET_TESTBED_Peer **peers,
322 unsigned int links_succeeded,
323 unsigned int links_failed)
329 GNUNET_assert (NUM_DAEMONS == num_peers);
330 for (i=0;i<num_peers;i++)
331 daemons[i] = peers[i];
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
333 (unsigned long long) FILESIZE);
334 if (NULL != strstr (progname, "index"))
335 do_index = GNUNET_YES;
337 do_index = GNUNET_NO;
338 if (NULL != strstr (progname, "dht"))
342 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
343 do_index, FILESIZE, SEED, VERBOSE, &do_download,
349 main (int argc, char *argv[])
352 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p",
353 "perf_gnunet_service_fs_p2p.conf",
357 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
361 /* end of perf_gnunet_service_fs_p2p.c */