2 This file is part of GNUnet.
3 (C) 2010,2011 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 ats/perf_ats_mlp
22 * @brief performance test for the MLP solver
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet-service-ats_addresses_mlp.h"
32 #define VERBOSE GNUNET_YES
33 #define VERBOSE_ARM GNUNET_NO
35 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
36 #define MLP_MAX_ITERATIONS INT_MAX
39 #define DEF_ADDRESSES_PER_PEER 5
41 static unsigned int peers;
42 static unsigned int addresses;
43 static unsigned int numeric;
45 struct PeerContext *p;
46 struct ATS_Address *a;
50 struct GNUNET_STATISTICS_Handle * stats;
52 struct GNUNET_CONTAINER_MultiHashMap * amap;
54 struct GAS_MLP_Handle *mlp;
56 struct GNUNET_STATISTICS_Handle * stats;
58 struct GNUNET_OS_Process *stats_proc;
60 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
64 struct GNUNET_PeerIdentity id;
77 struct GNUNET_ATS_Information *ats;
84 do_shutdown (void *cls,
85 const struct GNUNET_SCHEDULER_TaskContext *tc)
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
99 for (ca=0; ca < (peers * addresses); ca++)
101 GNUNET_free (a[ca].plugin);
102 GNUNET_free (a[ca].ats);
107 GNUNET_CONTAINER_multihashmap_destroy(amap);
108 GNUNET_free_non_null (a);
109 GNUNET_free_non_null (p);
111 GNUNET_STATISTICS_destroy (stats,GNUNET_NO);
113 if (NULL != stats_proc)
115 if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM))
116 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
117 if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK)
118 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
119 GNUNET_OS_process_close (stats_proc);
124 int stat_lp_it (void *cls, const char *subsystem,
125 const char *name, uint64_t value,
128 static long long unsigned lp_time;
129 static long long unsigned mlp_time;
130 static long long unsigned lp_time_set;
131 static long long unsigned mlp_time_set;
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received: `%s' : %u \n", name, value);
135 if (0 == strcmp (name, "# LP execution time (ms)"))
138 lp_time_set = GNUNET_YES;
140 if (0 == strcmp (name, "# MLP execution time (ms)"))
143 mlp_time_set = GNUNET_YES;
146 if ((GNUNET_YES == lp_time_set) && (GNUNET_YES == mlp_time_set))
148 if (GNUNET_YES == numeric)
149 printf ("%u;%u;%llu;%llu\n",peers, addresses, lp_time, mlp_time);
150 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
151 GNUNET_SCHEDULER_cancel(shutdown_task);
152 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
157 int stat_ready_it (void *cls, const char *subsystem,
158 const char *name, uint64_t value,
164 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics service ready\n");
168 GNUNET_STATISTICS_watch (stats, "ats", "# LP execution time (ms)", &stat_lp_it, NULL);
169 GNUNET_STATISTICS_watch (stats, "ats", "# MLP execution time (ms)", &stat_lp_it, NULL);
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
173 mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n");
178 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
179 GNUNET_SCHEDULER_cancel(shutdown_task);
180 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
187 addresses = DEF_ADDRESSES_PER_PEER;
189 p = GNUNET_malloc (peers * sizeof (struct ATS_Peer));
190 a = GNUNET_malloc (peers * addresses * sizeof (struct ATS_Address));
192 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
194 mlp->auto_solve = GNUNET_NO;
195 for (c=0; c < peers; c++)
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c);
198 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey);
200 for (c2=0; c2 < addresses; c2++)
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u for peer %u\n", c2, c);
203 /* Setting required information */
204 a[ca].mlp_information = NULL;
208 /* Setting address */
209 a[ca].peer = p[c].id;
210 a[ca].plugin = strdup("test");
211 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
213 a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
214 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
215 a[ca].ats[0].value = 20;
216 a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
217 a[ca].ats[1].value = 2;
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
220 GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
221 GAS_mlp_address_update(mlp, amap, &a[ca]);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
227 GNUNET_assert (peers == mlp->c_p);
228 GNUNET_assert (peers * addresses == mlp->addr_in_problem);
230 /* Solving the problem */
231 if (GNUNET_OK == GAS_mlp_solve_problem(mlp))
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n");
234 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses);
236 GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, "Waiting for statistics\n");
243 check (void *cls, char *const *args, const char *cfgfile,
244 const struct GNUNET_CONFIGURATION_Handle *cfg)
247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
252 stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics",
253 "gnunet-service-statistics", NULL);
255 if (NULL == stats_proc)
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n");
259 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
260 GNUNET_SCHEDULER_cancel(shutdown_task);
261 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
265 stats = GNUNET_STATISTICS_create("ats", cfg);
267 GNUNET_STATISTICS_watch (stats, "ats", "watch", &stat_ready_it, (void *) cfg);
268 GNUNET_STATISTICS_set(stats, "watch", 1, GNUNET_NO);
274 main (int argc, char *argv[])
277 static struct GNUNET_GETOPT_CommandLineOption options[] = {
278 {'a', "addresses", NULL,
279 gettext_noop ("addresses per peer"), 1,
280 &GNUNET_GETOPT_set_uint, &addresses},
282 gettext_noop ("peers"), 1,
283 &GNUNET_GETOPT_set_uint, &peers},
284 {'n', "numeric", NULL,
285 gettext_noop ("numeric output only"), 0,
286 &GNUNET_GETOPT_set_one, &numeric},
287 GNUNET_GETOPT_OPTION_END
291 GNUNET_PROGRAM_run (argc, argv,
292 "perf_ats_mlp", "nohelp", options,
299 /* end of file perf_ats_mlp.c */