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
29 This file is part of GNUnet.
30 (C) 2010,2011 Christian Grothoff (and other contributing authors)
32 GNUnet is free software; you can redistribute it and/or modify
33 it under the terms of the GNU General Public License as published
34 by the Free Software Foundation; either version 3, or (at your
35 option) any later version.
37 GNUnet is distributed in the hope that it will be useful, but
38 WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 General Public License for more details.
42 You should have received a copy of the GNU General Public License
43 along with GNUnet; see the file COPYING. If not, write to the
44 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
45 Boston, MA 02111-1307, USA.
48 * @file ats/test_ats_mlp.c
49 * @brief basic test for the MLP solver
50 * @author Christian Grothoff
51 * @author Matthias Wachs
55 #include "gnunet_util_lib.h"
56 #include "gnunet_statistics_service.h"
57 #include "gnunet_ats_service.h"
58 #include "gnunet-service-ats_addresses_mlp.h"
59 #include "gnunet-service-ats_normalization.h"
60 #include "test_ats_api_common.h"
62 #define PEERS_START 100
73 struct GNUNET_PeerIdentity id;
75 struct ATS_Address *head;
76 struct ATS_Address *tail;
80 static int opt_numeric;
82 static int opt_update_percent;
83 static int opt_update_quantity;
85 static int N_peers_start;
86 static int N_peers_end;
92 struct GNUNET_STATISTICS_Handle * stats;
97 struct GAS_MLP_Handle *mlp;
100 * Hashmap containing addresses
102 struct GNUNET_CONTAINER_MultiHashMap * addresses;
105 struct GNUNET_ATS_Information ats[2];
107 struct PerfPeer *peers;
114 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
118 if (NULL != addresses)
120 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
121 GNUNET_CONTAINER_multihashmap_destroy (addresses);
133 GAS_normalization_stop();
139 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
145 perf_create_peer (int cp)
147 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &peers[cp].id.hashPubKey);
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, GNUNET_i2s (&peers[cp].id));
151 static struct ATS_Address *
152 perf_create_address (int cp, int ca)
154 struct ATS_Address *a;
155 a = create_address (&peers[cp].id, "Test 1", "test 1", strlen ("test 1") + 1, 0);
156 GNUNET_CONTAINER_DLL_insert (peers[cp].head, peers[cp].tail, a);
157 GNUNET_CONTAINER_multihashmap_put (addresses, &peers[cp].id.hashPubKey, a, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
162 address_initial_update (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
164 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
165 ats[0].value = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100));
167 ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
168 ats[1].value = htonl (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10));
170 GAS_mlp_address_update (mlp, addresses, address, 0, GNUNET_YES, ats, 2);
175 update_single_addresses (struct ATS_Address *cur)
180 r_type = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
183 r_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100);
184 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
185 ats[0].value = htonl (r_val);
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' address %p type %s val %u\n",
187 GNUNET_i2s (&cur->peer), cur,
188 "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
191 r_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10);
192 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
193 ats[0].value = htonl (r_val);
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' address %p type %s val %u\n",
195 GNUNET_i2s (&cur->peer), cur,
196 "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
201 GAS_mlp_address_update (mlp, addresses, cur, 0, GNUNET_YES, ats, 1);
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, "Updating addresses %u addresses per peer \n", up_q);
216 for (c_peer = 0; c_peer < cp; c_peer++)
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n", GNUNET_i2s (&peers[c_peer].id));
219 for (c_select = 0; c_select < ca; c_select++)
222 while (c_select < opt_update_quantity)
224 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, ca);
233 for (cur = peers[c_peer].head; NULL != cur; cur = cur->next)
236 update_single_addresses (cur);
244 check (void *cls, char *const *args, const char *cfgfile,
245 const struct GNUNET_CONFIGURATION_Handle *cfg)
247 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
248 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
249 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
252 struct ATS_Address * cur_addr;
257 int full_mip_presolv;
258 struct GNUNET_TIME_Relative full_build_dur;
259 struct GNUNET_TIME_Relative full_lp_dur;
260 struct GNUNET_TIME_Relative full_mip_dur;
264 int update_lp_presolv;
265 int update_mip_presolv;
266 struct GNUNET_TIME_Relative update_build_dur;
267 struct GNUNET_TIME_Relative update_lp_dur;
268 struct GNUNET_TIME_Relative update_mip_dur;
270 stats = GNUNET_STATISTICS_create("ats", cfg);
277 GAS_normalization_start (NULL, NULL);
279 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
280 GNUNET_ATS_NetworkTypeCount))
287 GNUNET_assert (N_peers_end >= N_peers_start);
288 GNUNET_assert (N_address >= 0);
290 fprintf (stderr, "Solving problem for %u..%u peers with %u addresses\n",
291 N_peers_start, N_peers_end, N_address);
293 count_p = N_peers_end;
295 peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
296 /* Setup address hashmap */
297 addresses = GNUNET_CONTAINER_multihashmap_create (N_address, GNUNET_NO);
299 /* Init MLP solver */
300 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
301 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
308 mlp->mlp_auto_solve = GNUNET_NO;
309 mlp->write_mip_mps = opt_dump;
310 mlp->write_mip_sol = opt_dump;
312 for (cp = 0; cp < count_p; cp++)
313 perf_create_peer (cp);
315 if (GNUNET_YES == opt_numeric)
316 fprintf (stderr, "#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");
318 for (cp = 0; cp < count_p; cp++)
320 for (ca = 0; ca < count_a; ca++)
322 cur_addr = perf_create_address(cp, ca);
324 GAS_mlp_address_add (mlp, addresses, cur_addr, GNUNET_ATS_NET_UNSPECIFIED);
325 address_initial_update (mlp, addresses, cur_addr);
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer %u address %u: \n", cp, ca);
328 GAS_mlp_get_preferred_address( mlp, addresses, &peers[cp].id);
330 if (cp + 1 >= N_peers_start)
332 /* Solve the full problem */
333 GAS_mlp_solve_problem (mlp, addresses);
334 full_lp_res = mlp->ps.lp_res;
335 full_mip_res = mlp->ps.mip_res;
336 full_lp_presolv = mlp->ps.lp_presolv;
337 full_mip_presolv = mlp->ps.mip_presolv;
338 full_build_dur = mlp->ps.build_dur;
339 full_lp_dur = mlp->ps.lp_dur;
340 full_mip_dur = mlp->ps.mip_dur;
342 /* Update and solve the problem */
343 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
346 update_addresses (cp + 1, ca, opt_update_quantity);
347 GAS_mlp_solve_problem (mlp, addresses);
348 GAS_mlp_solve_problem (mlp, addresses);
349 update_lp_res = mlp->ps.lp_res;
350 update_mip_res = mlp->ps.mip_res;
351 update_lp_presolv = mlp->ps.lp_presolv;
352 update_mip_presolv = mlp->ps.mip_presolv;
353 update_build_dur = mlp->ps.build_dur;
354 update_lp_dur = mlp->ps.lp_dur;
355 update_mip_dur = mlp->ps.mip_dur;
358 if (GNUNET_NO == opt_numeric)
360 fprintf (stderr, "Rebuild: %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in ms) %04llu / %04llu / %04llu\n",
362 (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
363 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
364 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
365 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
366 (unsigned long long) full_build_dur.rel_value, (unsigned long long) full_lp_dur.rel_value, (unsigned long long) full_mip_dur.rel_value);
367 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
368 fprintf (stderr, "Update : %03u peers each %02u addresses; rebuild: LP/MIP state [%3s/%3s] presolv [%3s/%3s], (build/LP/MIP in ms) %04llu / %04llu / %04llu\n",
370 (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
371 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
372 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
373 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
374 (unsigned long long) update_build_dur.rel_value, (unsigned long long) update_lp_dur.rel_value, (unsigned long long) update_mip_dur.rel_value);
378 fprintf (stderr, "Rebuild;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
380 (GNUNET_OK == full_lp_res) ? "OK" : "FAIL",
381 (GNUNET_OK == full_mip_res) ? "OK" : "FAIL",
382 (GLP_YES == full_lp_presolv) ? "YES" : "NO",
383 (GNUNET_OK == full_mip_presolv) ? "YES" : "NO",
384 (unsigned long long) full_build_dur.rel_value, (unsigned long long) full_lp_dur.rel_value, (unsigned long long) full_mip_dur.rel_value);
385 if ((0 < opt_update_quantity) || (0 < opt_update_percent))
386 fprintf (stderr, "Update;%u;%u;%s;%s;%s;%s;%04llu;%04llu;%04llu\n",
388 (GNUNET_OK == update_lp_res) ? "OK" : "FAIL",
389 (GNUNET_OK == update_mip_res) ? "OK" : "FAIL",
390 (GLP_YES == update_lp_presolv) ? "YES" : "NO",
391 (GNUNET_OK == update_mip_presolv) ? "YES" : "NO",
392 (unsigned long long) update_build_dur.rel_value, (unsigned long long) update_lp_dur.rel_value, (unsigned long long) update_mip_dur.rel_value);
398 struct ATS_Address *cur;
399 struct ATS_Address *next;
400 for (cp = 0; cp < count_p; cp++)
402 for (cur = peers[cp].head; cur != NULL; cur = next)
404 GAS_mlp_address_delete (mlp, addresses, cur, GNUNET_NO);
406 GNUNET_CONTAINER_DLL_remove (peers[cp].head, peers[cp].tail, cur);
417 main (int argc, char *argv[])
420 static char *const argv2[] = { "perf_ats_mlp",
427 opt_dump = GNUNET_NO;
428 opt_update_quantity = 0;
429 opt_update_percent = 0;
435 for (c = 0; c < argc; c++)
437 if ((0 == strcmp (argv[c], "-z")) && (c < (argc - 1)))
439 if (0 != atoi(argv[c+1]))
441 N_peers_start = atoi(argv[c+1]);
444 if ((0 == strcmp (argv[c], "-x")) && (c < (argc - 1)))
446 if (0 != atoi(argv[c+1]))
448 N_peers_end = atoi(argv[c+1]);
451 if ((0 == strcmp (argv[c], "-c")) && (c < (argc - 1)))
453 if (0 != atoi(argv[c+1]))
455 N_address = atoi(argv[c+1]);
458 if ((0 == strcmp (argv[c], "-n")))
460 opt_numeric = GNUNET_YES;
462 if ((0 == strcmp (argv[c], "-d")))
464 opt_dump = GNUNET_YES;
466 if ((0 == strcmp (argv[c], "-p")) && (c < (argc - 1)))
468 if (0 != atoi(argv[c+1]))
470 /* Update a fix "p"ercentage of addresses */
471 opt_update_percent = atoi(argv[c+1]);
472 if ((0 <= opt_update_percent) && (100 <= opt_update_percent))
474 fprintf (stderr, _("Percentage has to be: 0 <= p <= 100 "));
479 if ((0 == strcmp (argv[c], "-q")) && (c < (argc - 1)))
481 if (0 != atoi(argv[c+1]))
483 /* Update a fix "q"uantity of addresses */
484 opt_update_quantity = atoi(argv[c+1]);
485 if (0 >= opt_update_quantity)
487 fprintf (stderr, _("Quantity has to be: p => 0 "));
494 if ((0 == N_peers_start) && (0 == N_peers_end))
496 N_peers_start = PEERS_START;
497 N_peers_end = PEERS_END;
500 N_address = ADDRESSES;
502 if (opt_update_quantity > N_address)
504 fprintf (stderr, _("Trying to update more addresses than we have per peer! (%u vs %u)"), opt_update_quantity, N_address);
508 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
509 GNUNET_GETOPT_OPTION_END
513 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
514 "perf_ats_mlp", "nohelp", options,
521 /* end of file perf_ats_mlp.c */