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
40 #define DEF_ATS_VALUES 2
41 #define DEF_ATS_MAX_DELAY 30
42 #define DEF_ATS_MAX_DISTANCE 3
44 static unsigned int peers;
45 static unsigned int addresses;
46 static unsigned int numeric;
47 static unsigned int update_percentage;
52 struct PeerContext *p;
53 struct ATS_Address *a;
57 struct GNUNET_CONTAINER_MultiHashMap * amap;
59 struct GAS_MLP_Handle *mlp;
64 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
68 struct GNUNET_PeerIdentity id;
81 struct GNUNET_ATS_Information *ats;
88 do_shutdown (void *cls,
89 const struct GNUNET_SCHEDULER_TaskContext *tc)
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
103 for (ca=0; ca < (peers * addresses); ca++)
105 GNUNET_free (a[ca].plugin);
106 GNUNET_free (a[ca].ats);
111 GNUNET_CONTAINER_multihashmap_destroy(amap);
112 GNUNET_free_non_null (a);
113 GNUNET_free_non_null (p);
118 update_addresses (struct ATS_Address * a, unsigned int addrs, unsigned int percentage)
123 unsigned int ua = (addrs) * ((float) percentage / 100);
124 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updating %u of %u addresses per peer\n", ua, addrs);
126 unsigned int updated[addrs];
127 unsigned int u_types[DEF_ATS_VALUES];
128 unsigned int updates = 0;
129 unsigned int u_type = 0;
130 unsigned int u_val = 0;
131 unsigned int cur = 0;
136 for (cur = 0; cur < addrs; cur ++)
144 cur = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, addrs);
145 if (0 == updated[cur])
147 u_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_VALUES);
152 u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY);
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DELAY from %u to %u\n",a[cur].ats[u_type].value, u_val);
155 while (a[cur].ats[u_type].value == u_val);
160 u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE);
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DISTANCE from %u to %u\n",a[cur].ats[u_type].value, u_val);
163 while (a[cur].ats[u_type].value == u_val);
171 a[cur].ats[u_type].value = u_val;
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated %u delay and %u distance values\n", u_types[0], u_types[1]);
182 check (void *cls, char *const *args, const char *cfgfile,
183 const struct GNUNET_CONFIGURATION_Handle *cfg)
188 int update = GNUNET_NO;
189 int range = GNUNET_NO;
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
200 mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n");
205 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
206 GNUNET_SCHEDULER_cancel(shutdown_task);
207 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
213 addresses = DEF_ADDRESSES_PER_PEER;
215 p = GNUNET_malloc (peers * sizeof (struct ATS_Peer));
216 a = GNUNET_malloc (peers * addresses * sizeof (struct ATS_Address));
218 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
220 mlp->auto_solve = GNUNET_NO;
225 if ((start != -1) && (end != -1))
227 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem starting from %u to %u\n", start , end);
231 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem for %u peers\n", peers);
233 if ((update_percentage >= 0) && (update_percentage <= 100))
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Benchmarking with existing presolution and %u \% updated addresses\n", update_percentage);
238 else if ((update_percentage > 100) && (update_percentage != UINT_MAX))
240 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Invalid percentage: %u\n", update_percentage);
245 for (c=0; c < peers; c++)
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c);
248 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, &p[c].id.hashPubKey);
250 for (c2=0; c2 < addresses; c2++)
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u for peer %u\n", c2, c);
253 /* Setting required information */
254 a[ca].mlp_information = NULL;
258 /* Setting address */
259 a[ca].peer = p[c].id;
260 a[ca].plugin = strdup("test");
261 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
263 a[ca].ats = GNUNET_malloc (DEF_ATS_VALUES * sizeof (struct GNUNET_ATS_Information));
264 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
265 a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY);
266 a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
267 a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE);
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
270 GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
271 GAS_mlp_address_update(mlp, amap, &a[ca]);
275 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
277 if (((GNUNET_YES == range) && (((start >= 0) && ((c+1) >= start)) && (c <= end))) || ((c+1) == peers))
279 GNUNET_assert ((c+1) == mlp->c_p);
280 GNUNET_assert ((c+1) * addresses == mlp->addr_in_problem);
282 /* Solving the problem */
283 struct GAS_MLP_SolutionContext ctx;
285 res = GAS_mlp_solve_problem(mlp, &ctx);
287 if (GNUNET_NO == update)
289 if (GNUNET_OK == res)
291 GNUNET_assert (GNUNET_OK == ctx.lp_result);
292 GNUNET_assert (GNUNET_OK == ctx.mlp_result);
293 if (GNUNET_YES == numeric)
294 printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value);
296 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem solved for %u peers with %u address successfully (LP: %llu ms / MLP: %llu ms)\n",
297 mlp->c_p, mlp->addr_in_problem, ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value);
300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", c, c2);
304 struct GAS_MLP_SolutionContext uctx;
305 /* Update addresses */
306 update_addresses (a, (c+1) * c2, update_percentage);
309 res = GAS_mlp_solve_problem(mlp, &uctx);
311 if (GNUNET_OK == res)
313 GNUNET_assert (GNUNET_OK == uctx.lp_result);
314 GNUNET_assert (GNUNET_OK == uctx.mlp_result);
315 if (GNUNET_YES == numeric)
316 printf ("%u;%u;%llu;%llu;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem,
317 (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value,
318 (long long unsigned int) uctx.lp_duration.rel_value, (long long unsigned int) uctx.mlp_duration.rel_value);
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated problem solved for %u peers with %u address successfully (Initial: LP/MLP: %llu/%llu ms, Update: %llu/%llu ms)\n",
321 mlp->c_p, mlp->addr_in_problem,
322 (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value,
323 (long long unsigned int) uctx.lp_duration.rel_value, (long long unsigned int) uctx.mlp_duration.rel_value);
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving updated problem with %u peers and %u addresses failed\n", c, c2);
331 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
332 GNUNET_SCHEDULER_cancel(shutdown_task);
333 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
339 main (int argc, char *argv[])
342 update_percentage = UINT_MAX;
343 static struct GNUNET_GETOPT_CommandLineOption options[] = {
344 {'a', "addresses", NULL,
345 gettext_noop ("addresses per peer"), 1,
346 &GNUNET_GETOPT_set_uint, &addresses},
348 gettext_noop ("peers"), 1,
349 &GNUNET_GETOPT_set_uint, &peers},
350 {'n', "numeric", NULL,
351 gettext_noop ("numeric output only"), 0,
352 &GNUNET_GETOPT_set_one, &numeric},
354 gettext_noop ("end solving problem"), 1,
355 &GNUNET_GETOPT_set_uint, &end},
357 gettext_noop ("start solving problem"), 1,
358 &GNUNET_GETOPT_set_uint, &start},
359 {'u', "update", NULL,
360 gettext_noop ("benchmark with existing solution (address updates)"), 1,
361 &GNUNET_GETOPT_set_uint, &update_percentage},
362 GNUNET_GETOPT_OPTION_END
366 GNUNET_PROGRAM_run (argc, argv,
367 "perf_ats_mlp", "nohelp", options,
374 /* end of file perf_ats_mlp.c */