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;
44 struct PeerContext *p;
45 struct ATS_Address *a;
49 struct GNUNET_STATISTICS_Handle * stats;
51 struct GNUNET_CONTAINER_MultiHashMap * amap;
53 struct GAS_MLP_Handle *mlp;
55 struct GNUNET_STATISTICS_Handle * stats;
57 struct GNUNET_OS_Process *stats_proc;
59 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
63 struct GNUNET_PeerIdentity id;
76 struct GNUNET_ATS_Information *ats;
83 do_shutdown (void *cls,
84 const struct GNUNET_SCHEDULER_TaskContext *tc)
87 for (ca=0; ca < (peers * addresses); ca++)
89 GNUNET_free (a[ca].plugin);
90 GNUNET_free (a[ca].ats);
92 GNUNET_CONTAINER_multihashmap_destroy(amap);
95 GNUNET_STATISTICS_destroy(stats,GNUNET_NO);
97 if (NULL != stats_proc)
99 if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM))
100 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
101 if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK)
102 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
103 GNUNET_OS_process_close (stats_proc);
109 int stat_it (void *cls, const char *subsystem,
110 const char *name, uint64_t value,
114 static long long unsigned lp_time;
115 static long long unsigned mlp_time;
117 if (0 == strcmp (name, "# LP execution time (ms)"))
119 if (0 == strcmp (name, "# MLP execution time (ms)"))
126 printf ("%u;%u;%llu;%llu\n",peers, addresses, lp_time, mlp_time);
127 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
128 GNUNET_SCHEDULER_cancel(shutdown_task);
129 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
135 check (void *cls, char *const *args, const char *cfgfile,
136 const struct GNUNET_CONFIGURATION_Handle *cfg)
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
147 stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics",
148 "gnunet-service-statistics", NULL);
150 if (NULL == stats_proc)
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n");
157 shutdown_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_HOURS, &do_shutdown, NULL);
162 addresses = DEF_ADDRESSES_PER_PEER;
164 p = GNUNET_malloc (peers * sizeof (struct ATS_Peer));
165 a = GNUNET_malloc (peers * addresses * sizeof (struct ATS_Address));
167 stats = GNUNET_STATISTICS_create("ats", cfg);
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
171 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
173 mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
174 mlp->auto_solve = GNUNET_NO;
175 for (c=0; c < peers; c++)
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c);
178 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey);
180 for (c2=0; c2 < addresses; c2++)
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u for peer %u\n", c2, c);
183 /* Setting required information */
184 a[ca].mlp_information = NULL;
188 /* Setting address */
189 a[ca].peer = p[c].id;
190 a[ca].plugin = strdup("test");
191 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
193 a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
194 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
195 a[ca].ats[0].value = 20;
196 a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
197 a[ca].ats[1].value = 2;
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
200 GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
201 GAS_mlp_address_update(mlp, amap, &a[ca]);
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
207 GNUNET_assert (peers == mlp->c_p);
208 GNUNET_assert (peers * addresses == mlp->addr_in_problem);
210 /* Solving the problem */
211 if (GNUNET_OK == GAS_mlp_solve_problem(mlp))
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n");
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses);
218 GNUNET_STATISTICS_get (stats, "ats", "# LP execution time (ms)", GNUNET_TIME_UNIT_MINUTES, NULL, &stat_it, NULL);
219 GNUNET_STATISTICS_get (stats, "ats", "# MLP execution time (ms)", GNUNET_TIME_UNIT_MINUTES, NULL, &stat_it, NULL);
225 main (int argc, char *argv[])
228 static struct GNUNET_GETOPT_CommandLineOption options[] = {
229 {'a', "addresses", NULL,
230 gettext_noop ("addresses per peer"), 1,
231 &GNUNET_GETOPT_set_uint, &addresses},
233 gettext_noop ("peers"), 1,
234 &GNUNET_GETOPT_set_uint, &peers},
235 GNUNET_GETOPT_OPTION_END
239 GNUNET_PROGRAM_run (argc, argv,
240 "perf_ats_mlp", "nohelp", options,
247 /* end of file perf_ats_mlp.c */