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_ats_service.h"
31 #include "gnunet-service-ats-solver_mlp.h"
32 #include "gnunet-service-ats_normalization.h"
33 #include "test_ats_api_common.h"
35 #define PEERS_START 100
45 struct GNUNET_PeerIdentity id;
47 struct ATS_Address *head;
48 struct ATS_Address *tail;
52 static int opt_numeric;
54 static int opt_update_percent;
55 static int opt_update_quantity;
57 static int N_peers_start;
58 static int N_peers_end;
64 struct GNUNET_STATISTICS_Handle * stats;
69 struct GAS_MLP_Handle *mlp;
72 * Hashmap containing addresses
74 struct GNUNET_CONTAINER_MultiHashMap * addresses;
77 struct GNUNET_ATS_Information ats[2];
79 struct PerfPeer *peers;
86 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
90 if (NULL != addresses)
92 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
93 GNUNET_CONTAINER_multihashmap_destroy (addresses);
105 GAS_normalization_stop ();
110 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
116 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
117 uint32_t type, double prop_rel)
123 get_property_cb (void *cls, const struct ATS_Address *address)
125 return GAS_normalization_get_properties ((struct ATS_Address *) address);
128 static const double *
129 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
131 return GAS_normalization_get_preferences (id);
135 perf_create_peer (int cp)
137 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
138 &peers[cp].id.hashPubKey);
139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
140 GNUNET_i2s (&peers[cp].id));
143 static struct ATS_Address *
144 perf_create_address (int cp, int ca)
146 struct ATS_Address *a;
147 a = create_address (&peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1,
149 GNUNET_CONTAINER_DLL_insert(peers[cp].head, peers[cp].tail, a);
150 GNUNET_CONTAINER_multihashmap_put (addresses, &peers[cp].id.hashPubKey, a,
151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
156 address_initial_update (void *solver,
157 struct GNUNET_CONTAINER_MultiHashMap * addresses,
158 struct ATS_Address *address)
160 GAS_mlp_address_property_changed (mlp, address, GNUNET_ATS_QUALITY_NET_DELAY,
162 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
165 GAS_mlp_address_property_changed (mlp, address,
166 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
167 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
172 update_single_addresses (struct ATS_Address *cur)
177 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
181 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
183 "Updating peer `%s' address %p type %s val %u\n",
184 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
185 GAS_mlp_address_property_changed (mlp, cur, GNUNET_ATS_QUALITY_NET_DELAY,
186 r_val, (double) (100 + r_val / 100));
189 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
191 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
192 "Updating peer `%s' address %p type %s val %u\n",
193 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
194 GAS_mlp_address_property_changed (mlp, cur, GNUNET_ATS_QUALITY_NET_DISTANCE,
195 r_val, (double) (100 + r_val) / 100);
200 GAS_mlp_address_inuse_changed (mlp, cur, GNUNET_YES);
205 update_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
207 struct ATS_Address *cur;
213 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
214 "Updating addresses %u addresses per peer \n", up_q);
217 for (c_peer = 0; c_peer < cp; c_peer++)
219 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n",
220 GNUNET_i2s (&peers[c_peer].id));
221 for (c_select = 0; c_select < ca; c_select++)
224 while (c_select < opt_update_quantity)
226 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
235 for (cur = peers[c_peer].head; NULL != cur; cur = cur->next)
238 update_single_addresses (cur);
245 check (void *cls, char * const *args, const char *cfgfile,
246 const struct GNUNET_CONFIGURATION_Handle *cfg)
248 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
249 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
250 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
253 struct ATS_Address * cur_addr;
258 int full_mip_presolv;
259 struct GNUNET_TIME_Relative full_build_dur;
260 struct GNUNET_TIME_Relative full_lp_dur;
261 struct GNUNET_TIME_Relative full_mip_dur;
265 int update_lp_presolv;
266 int update_mip_presolv;
267 struct GNUNET_TIME_Relative update_build_dur;
268 struct GNUNET_TIME_Relative update_lp_dur;
269 struct GNUNET_TIME_Relative update_mip_dur;
271 stats = GNUNET_STATISTICS_create ("ats", cfg);
278 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
280 if (GNUNET_ATS_NetworkTypeCount
281 != load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
288 GNUNET_assert(N_peers_end >= N_peers_start);
289 GNUNET_assert(N_address >= 0);
291 fprintf (stderr, "Solving problem for %u..%u peers with %u addresses\n",
292 N_peers_start, N_peers_end, N_address);
294 count_p = N_peers_end;
296 peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
297 /* Setup address hashmap */
298 addresses = GNUNET_CONTAINER_multihashmap_create (N_address, GNUNET_NO);
300 /* Init MLP solver */
301 mlp = GAS_mlp_init (cfg, stats, addresses, quotas, quotas_out, quotas_in,
302 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL,
303 &get_preferences_cb, NULL, &get_property_cb, NULL );
310 mlp->mlp_auto_solve = GNUNET_NO;
311 mlp->write_mip_mps = opt_dump;
312 mlp->write_mip_sol = opt_dump;
314 for (cp = 0; cp < count_p; cp++)
315 perf_create_peer (cp);
317 if (GNUNET_YES == opt_numeric)
319 "#peers;#addresses per peer;LP/MIP state;presolv;exec build in ms;exec LP in ms; exec MIP in ms;#cols;#rows;#nonzero elements\n");
321 for (cp = 0; cp < count_p; cp++)
323 for (ca = 0; ca < count_a; ca++)
325 cur_addr = perf_create_address (cp, ca);
327 GAS_mlp_address_add (mlp, cur_addr, GNUNET_ATS_NET_UNSPECIFIED);
328 address_initial_update (mlp, addresses, cur_addr);
329 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
330 "Adding address for peer %u address %u: \n", cp, ca);
332 GAS_mlp_get_preferred_address (mlp, &peers[cp].id);
334 if (cp + 1 >= N_peers_start)
337 update_mip_dur = GNUNET_TIME_UNIT_FOREVER_REL;
338 update_lp_dur = GNUNET_TIME_UNIT_FOREVER_REL;
339 update_build_dur = GNUNET_TIME_UNIT_FOREVER_REL;
340 update_mip_presolv = GNUNET_SYSERR;
341 update_lp_presolv = GNUNET_SYSERR;
342 update_mip_res = GNUNET_SYSERR;
343 update_lp_res = GNUNET_SYSERR;
344 /* Solve the full problem */
345 GAS_mlp_solve_problem (mlp);
346 full_lp_res = mlp->ps.lp_res;
347 full_mip_res = mlp->ps.mip_res;
348 full_lp_presolv = mlp->ps.lp_presolv;
349 full_mip_presolv = mlp->ps.mip_presolv;
350 full_build_dur = mlp->ps.build_dur;
351 full_lp_dur = mlp->ps.lp_dur;
352 full_mip_dur = mlp->ps.mip_dur;
354 /* Update and solve the problem */
355 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
358 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
359 update_addresses (cp + 1, ca, opt_update_quantity);
360 GAS_mlp_solve_problem (mlp);
361 GAS_mlp_solve_problem (mlp);
362 update_lp_res = mlp->ps.lp_res;
363 update_mip_res = mlp->ps.mip_res;
364 update_lp_presolv = mlp->ps.lp_presolv;
365 update_mip_presolv = mlp->ps.mip_presolv;
366 update_build_dur = mlp->ps.build_dur;
367 update_lp_dur = mlp->ps.lp_dur;
368 update_mip_dur = mlp->ps.mip_dur;
371 if (GNUNET_NO == opt_numeric)
374 "Rebuild: %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in us) %04llu / %04llu / %04llu\n",
375 cp + 1, ca, (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
376 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
377 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
378 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
379 (unsigned long long) full_build_dur.rel_value_us,
380 (unsigned long long) full_lp_dur.rel_value_us,
381 (unsigned long long) full_mip_dur.rel_value_us);
382 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
384 "Update: %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in us) %04llu / %04llu / %04llu\n",
385 cp + 1, ca, (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
386 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
387 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
388 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
389 (unsigned long long) update_build_dur.rel_value_us,
390 (unsigned long long) update_lp_dur.rel_value_us,
391 (unsigned long long) update_mip_dur.rel_value_us);
395 fprintf (stderr, "Rebuild;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
396 cp + 1, ca, (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
397 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
398 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
399 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
400 (unsigned long long) full_build_dur.rel_value_us,
401 (unsigned long long) full_lp_dur.rel_value_us,
402 (unsigned long long) full_mip_dur.rel_value_us);
403 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
404 fprintf (stderr, "Update;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
405 cp + 1, ca, (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
406 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
407 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
408 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
409 (unsigned long long) update_build_dur.rel_value_us,
410 (unsigned long long) update_lp_dur.rel_value_us,
411 (unsigned long long) update_mip_dur.rel_value_us);
416 struct ATS_Address *cur;
417 struct ATS_Address *next;
418 for (cp = 0; cp < count_p; cp++)
420 for (cur = peers[cp].head; cur != NULL ; cur = next)
422 GAS_mlp_address_delete (mlp, cur, GNUNET_NO);
424 GNUNET_CONTAINER_DLL_remove(peers[cp].head, peers[cp].tail, cur);
434 main (int argc, char *argv[])
437 static char * const argv2[] = { "perf_ats_mlp", "-c", "test_ats_mlp.conf",
438 "-L", "WARNING", NULL };
440 opt_dump = GNUNET_NO;
441 opt_update_quantity = 0;
442 opt_update_percent = 0;
448 for (c = 0; c < argc; c++)
450 if ((0 == strcmp (argv[c], "-z")) && (c < (argc - 1)))
452 if (0 != atoi (argv[c + 1]))
454 N_peers_start = atoi (argv[c + 1]);
457 if ((0 == strcmp (argv[c], "-x")) && (c < (argc - 1)))
459 if (0 != atoi (argv[c + 1]))
461 N_peers_end = atoi (argv[c + 1]);
464 if ((0 == strcmp (argv[c], "-c")) && (c < (argc - 1)))
466 if (0 != atoi (argv[c + 1]))
468 N_address = atoi (argv[c + 1]);
471 if ((0 == strcmp (argv[c], "-n")))
473 opt_numeric = GNUNET_YES;
475 if ((0 == strcmp (argv[c], "-d")))
477 opt_dump = GNUNET_YES;
479 if ((0 == strcmp (argv[c], "-p")) && (c < (argc - 1)))
481 if (0 != atoi (argv[c + 1]))
483 /* Update a fix "p"ercentage of addresses */
484 opt_update_percent = atoi (argv[c + 1]);
485 if ((0 <= opt_update_percent) && (100 <= opt_update_percent))
487 fprintf (stderr, _("Percentage has to be: 0 <= p <= 100 ") );
492 if ((0 == strcmp (argv[c], "-q")) && (c < (argc - 1)))
494 if (0 != atoi (argv[c + 1]))
496 /* Update a fix "q"uantity of addresses */
497 opt_update_quantity = atoi (argv[c + 1]);
498 if (0 >= opt_update_quantity)
500 fprintf (stderr, _("Quantity has to be: p => 0 ") );
507 if ((0 == N_peers_start) && (0 == N_peers_end))
509 N_peers_start = PEERS_START;
510 N_peers_end = PEERS_END;
513 N_address = ADDRESSES;
515 if (opt_update_quantity > N_address)
518 _("Trying to update more addresses than we have per peer! (%u vs %u)"),
519 opt_update_quantity, N_address);
523 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
524 GNUNET_GETOPT_OPTION_END };
526 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
527 "perf_ats_mlp", "nohelp", options, &check, NULL );
532 /* end of file perf_ats_mlp.c */