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_solver.c
22 * @brief generic performance test for ATS solvers
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet-service-ats_addresses.h"
30 #include "gnunet-service-ats_normalization.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_ats_plugin.h"
33 #include "test_ats_api_common.h"
35 #define DEFAULT_UPDATE_PERCENTAGE 20
36 #define DEFAULT_PEERS_START 10
37 #define DEFAULT_PEERS_END 10
38 #define DEFAULT_ADDRESSES 10
39 #define DEFAULT_ATS_COUNT 2
41 #define GNUPLOT_PROP_TEMPLATE "#!/usr/bin/gnuplot \n" \
42 "set datafile separator ';' \n" \
43 "set title \"Execution time Proportional solver \" \n" \
44 "set xlabel \"Number of peers\" \n" \
45 "set ylabel \"Execution time in us\" \n" \
48 #define GNUPLOT_PROP_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
49 "set datafile separator ';' \n" \
50 "set title \"Execution time Proportional solver with updated problem\" \n" \
51 "set xlabel \"Number of peers\" \n" \
52 "set ylabel \"Execution time in us\" \n" \
55 #define GNUPLOT_MLP_TEMPLATE "#!/usr/bin/gnuplot \n" \
56 "set datafile separator ';' \n" \
57 "set title \"Execution time MLP solver \" \n" \
58 "set xlabel \"Number of peers\" \n" \
59 "set ylabel \"Execution time in us\" \n" \
62 #define GNUPLOT_MLP_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
63 "set datafile separator ';' \n" \
64 "set title \"Execution time MLP solver with updated problem\" \n" \
65 "set xlabel \"Number of peers\" \n" \
66 "set ylabel \"Execution time in us\" \n" \
69 #define GNUPLOT_RIL_TEMPLATE "#!/usr/bin/gnuplot \n" \
70 "set datafile separator ';' \n" \
71 "set title \"Execution time RIL solver \" \n" \
72 "set xlabel \"Number of peers\" \n" \
73 "set ylabel \"Execution time in us\" \n" \
76 #define GNUPLOT_RIL_UPDATE_TEMPLATE "#!/usr/bin/gnuplot \n" \
77 "set datafile separator ';' \n" \
78 "set title \"Execution time RIL solver with updated problem\" \n" \
79 "set xlabel \"Number of peers\" \n" \
80 "set ylabel \"Execution time in us\" \n" \
84 * Handle for ATS address component
91 struct PerfPeer *peers;
101 struct GNUNET_STATISTICS_Handle *stat;
104 * A multihashmap to store all addresses
106 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
111 struct GNUNET_ATS_PluginEnvironment env;
117 struct Result *current_result;
123 * Solver description as string
128 * Configured ATS solver
133 * #peers to start benchmarking with
138 * #peers to end benchmarking with
143 * #addresses to benchmarking with
148 * Percentage of peers to update
150 int opt_update_percent;
153 * Create gnuplot file
163 * Is a bulk operation running?
168 * Is a bulk operation running?
170 int expecting_solution;
182 enum GAS_Solver_Additional_Information info;
184 struct GNUNET_TIME_Relative d_setup;
185 struct GNUNET_TIME_Relative d_lp;
186 struct GNUNET_TIME_Relative d_mlp;
187 struct GNUNET_TIME_Relative d_total;
189 struct GNUNET_TIME_Absolute s_setup;
190 struct GNUNET_TIME_Absolute s_lp;
191 struct GNUNET_TIME_Absolute s_mlp;
192 struct GNUNET_TIME_Absolute s_total;
194 struct GNUNET_TIME_Absolute e_setup;
195 struct GNUNET_TIME_Absolute e_lp;
196 struct GNUNET_TIME_Absolute e_mlp;
197 struct GNUNET_TIME_Absolute e_total;
202 struct GNUNET_PeerIdentity id;
204 struct ATS_Address *head;
205 struct ATS_Address *tail;
208 static struct PerfHandle ph;
219 //static struct GNUNET_ATS_Information ats[2];
227 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
231 if (NULL != addresses)
233 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
234 GNUNET_CONTAINER_multihashmap_destroy (addresses);
237 if (NULL != ph.peers)
239 GNUNET_free(ph.peers);
242 GAS_normalization_stop ();
248 perf_create_peer (int cp)
251 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
252 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
254 GNUNET_i2s (&ph.peers[cp].id));
260 perf_update_address (struct ATS_Address *cur)
265 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
269 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
270 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
271 "Updating peer `%s' address %p type %s val %u\n",
272 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
273 ph.env.sf.s_address_update_property (ph.solver, cur,
274 GNUNET_ATS_QUALITY_NET_DELAY,
275 r_val, (double) (100 + r_val / 100));
278 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
281 "Updating peer `%s' address %p type %s val %u\n",
282 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
283 ph.env.sf.s_address_update_property (ph.solver, cur,
284 GNUNET_ATS_QUALITY_NET_DISTANCE,
285 r_val, (double) (100 + r_val) / 100);
290 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
296 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
298 if (0 == ntohl(address->assigned_bw_out.value__) &&
299 0 == ntohl(address->assigned_bw_in.value__))
302 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
303 "Bandwidth changed addresses %s %p to %llu Bps out / %llu Bps in\n",
304 GNUNET_i2s (&address->peer),
306 ntohl(address->assigned_bw_out.value__),
307 ntohl(address->assigned_bw_in.value__));
308 if (GNUNET_YES == ph.bulk_running)
314 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
316 return GAS_normalization_get_preferences_by_peer (id);
321 get_property_cb (void *cls, const struct ATS_Address *address)
323 return GAS_normalization_get_properties ((struct ATS_Address *) address);
327 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
328 uint32_t type, double prop_rel)
334 perf_address_initial_update (void *solver,
335 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
336 struct ATS_Address *address)
338 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
340 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
343 ph.env.sf.s_address_update_property (solver, address,
344 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
345 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
350 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
352 struct ATS_Address *cur_address;
361 count = cp * ((double) percentage_peers / 100);
362 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
363 "Updating %u of %u peers \n", count, cp);
365 for (c_peer = 0; c_peer < cp; c_peer++)
370 while (c_select < count)
372 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
376 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
377 "Updating peer [%u] \n", r);
381 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
385 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
386 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
387 "Updating peer [%u] address [%u]\n", c_cur_p, r);
390 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next)
393 perf_update_address (cur_address);
402 static struct ATS_Address *
403 perf_create_address (int cp, int ca)
405 struct ATS_Address *a;
406 a = create_address (&ph.peers[cp].id,
407 "Test 1", "test 1", strlen ("test 1") + 1, 0);
408 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
409 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
410 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
415 solver_info_cb (void *cls,
416 enum GAS_Solver_Operation op,
417 enum GAS_Solver_Status stat,
418 enum GAS_Solver_Additional_Information add)
423 add_info = "GAS_INFO_NONE";
426 add_info = "GAS_INFO_MLP_FULL";
428 case GAS_INFO_UPDATED:
429 add_info = "GAS_INFO_MLP_UPDATED";
431 case GAS_INFO_PROP_ALL:
432 add_info = "GAS_INFO_PROP_ALL";
434 case GAS_INFO_PROP_SINGLE:
435 add_info = "GAS_INFO_PROP_SINGLE";
438 add_info = "INVALID";
445 case GAS_OP_SOLVE_START:
446 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
447 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
448 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
449 if (GNUNET_NO == ph.expecting_solution)
451 /* We do not expect a solution at the moment */
456 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
458 /* Create new result */
459 tmp = GNUNET_malloc (sizeof (struct Result));
460 ph.current_result = tmp;
461 GNUNET_CONTAINER_DLL_insert_tail(ph.head, ph.tail, tmp);
462 ph.current_result->addresses = ph.current_a;
463 ph.current_result->peers = ph.current_p;
464 ph.current_result->s_total = GNUNET_TIME_absolute_get();
465 ph.current_result->d_total = GNUNET_TIME_UNIT_FOREVER_REL;
466 ph.current_result->d_setup = GNUNET_TIME_UNIT_FOREVER_REL;
467 ph.current_result->d_lp = GNUNET_TIME_UNIT_FOREVER_REL;
468 ph.current_result->d_mlp = GNUNET_TIME_UNIT_FOREVER_REL;
469 ph.current_result->info = add;
470 if (add == GAS_INFO_UPDATED)
471 ph.current_result->update = GNUNET_YES;
473 ph.current_result->update = GNUNET_NO;
476 case GAS_OP_SOLVE_STOP:
477 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
478 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
479 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
480 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
482 /* We do not expect a solution at the moment */
486 if (NULL != ph.current_result)
488 /* Finalize result */
489 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
490 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
491 ph.current_result->s_total, ph.current_result->e_total);
493 ph.current_result = NULL;
496 case GAS_OP_SOLVE_SETUP_START:
497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
498 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
499 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
500 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
505 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
508 case GAS_OP_SOLVE_SETUP_STOP:
509 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
510 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
511 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
512 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
517 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
518 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
519 ph.current_result->s_setup, ph.current_result->e_setup);
522 case GAS_OP_SOLVE_MLP_LP_START:
523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
524 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
525 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
526 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
531 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
533 case GAS_OP_SOLVE_MLP_LP_STOP:
534 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
535 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
536 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
537 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
542 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
543 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
544 ph.current_result->s_lp, ph.current_result->e_lp);
547 case GAS_OP_SOLVE_MLP_MLP_START:
548 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
549 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
550 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
551 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
556 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
558 case GAS_OP_SOLVE_MLP_MLP_STOP:
559 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
560 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
561 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
562 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
567 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
568 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
569 ph.current_result->s_mlp, ph.current_result->e_mlp);
571 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
572 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
573 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
574 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
576 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
578 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
579 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
587 write_gnuplot_script (char * data_fn, int full)
589 struct GNUNET_DISK_FileHandle *f;
595 switch (ph.ats_mode) {
596 case MODE_PROPORTIONAL:
597 if (GNUNET_YES == full)
598 template = GNUPLOT_PROP_TEMPLATE;
600 template = GNUPLOT_PROP_UPDATE_TEMPLATE;
603 if (GNUNET_YES == full)
604 template = GNUPLOT_MLP_TEMPLATE;
606 template = GNUPLOT_MLP_UPDATE_TEMPLATE;
609 if (GNUNET_YES == full)
610 template = GNUPLOT_RIL_TEMPLATE;
612 template = GNUPLOT_RIL_UPDATE_TEMPLATE;
619 if (GNUNET_YES == full)
620 GNUNET_asprintf (&gfn, "perf_%s_full_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
622 GNUNET_asprintf (&gfn, "perf_%s_update_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
624 f = GNUNET_DISK_file_open (gfn,
625 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
626 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
634 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
638 if (MODE_PROPORTIONAL == ph.ats_mode)
640 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
644 else if (MODE_MLP == ph.ats_mode)
646 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
647 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
648 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
649 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
656 else if (MODE_RIL == ph.ats_mode)
658 GNUNET_asprintf (&data,
659 "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
664 if ((NULL != data) &&
665 (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen(data))))
666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 "Cannot write data to plot file `%s'\n",
669 GNUNET_free_non_null (data);
671 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
673 "Cannot close gnuplot file `%s'\n",
676 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
677 "Data successfully written to plot file `%s'\n",
687 struct GNUNET_DISK_FileHandle *f_full;
688 struct GNUNET_DISK_FileHandle *f_update;
690 char * data_fn_update;
706 GNUNET_asprintf (&data_fn_full,
707 "perf_%s_full_%u_%u_%u.data",
712 f_full = GNUNET_DISK_file_open (data_fn_full,
713 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
714 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
718 "Cannot open gnuplot file `%s'\n",
720 GNUNET_free (data_fn_full);
723 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
724 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
725 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
726 "Cannot write data to log file `%s'\n",
728 write_gnuplot_script (data_fn_full, GNUNET_YES);
731 data_fn_update = NULL;
732 if ((ph.create_plot) && (GNUNET_YES == ph.measure_updates))
734 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u_%u_%u.data", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
735 f_update = GNUNET_DISK_file_open (data_fn_update,
736 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
737 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
738 if (NULL == f_update)
740 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
741 "Cannot open gnuplot file `%s'\n", data_fn_update);
742 GNUNET_free (data_fn_update);
744 GNUNET_DISK_file_close (f_full);
745 GNUNET_free (data_fn_full);
748 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
749 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
751 "Cannot write data to log file `%s'\n",
753 write_gnuplot_script (data_fn_update, GNUNET_NO);
757 while (NULL != (cur = next))
766 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
769 "Total time to solve %s for %u peers %u addresses: %llu us\n",
770 (GNUNET_YES == cur->update) ? "updated" : "full",
771 cur->peers, cur->addresses, (unsigned long long) cur->d_total.rel_value_us);
772 GNUNET_asprintf(&str_d_total,
774 (unsigned long long) cur->d_total.rel_value_us);
777 GNUNET_asprintf(&str_d_total, "-1");
778 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
780 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n",
781 (GNUNET_YES == cur->update) ? "updated" : "full",
782 cur->peers, cur->addresses, (unsigned long long )cur->d_setup.rel_value_us);
783 GNUNET_asprintf(&str_d_setup, "%llu", (unsigned long long )cur->d_setup.rel_value_us);
786 GNUNET_asprintf(&str_d_setup, "-1");
787 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
790 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
791 (GNUNET_YES == cur->update) ? "updated" : "full",
794 (unsigned long long )cur->d_lp.rel_value_us);
795 GNUNET_asprintf (&str_d_lp,
797 (unsigned long long )cur->d_lp.rel_value_us);
800 GNUNET_asprintf (&str_d_lp, "-1");
801 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
803 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
804 (GNUNET_YES == cur->update) ? "updated" : "full",
805 cur->peers, cur->addresses, (unsigned long long )cur->d_mlp.rel_value_us);
806 GNUNET_asprintf (&str_d_mlp,
808 (unsigned long long )cur->d_mlp.rel_value_us);
811 GNUNET_asprintf (&str_d_mlp, "-1");
814 if (GNUNET_YES == ph.create_plot)
817 GNUNET_asprintf (&data,
818 "%u;%u;%s;%s;%s;%s\n",
819 cur->peers, cur->addresses,
824 if (cur->update == GNUNET_NO)
826 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
827 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
828 "Cannot write data to log file `%s'\n",
831 if ((cur->update == GNUNET_YES) && (NULL != f_update))
833 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
835 "Cannot write data to log file `%s'\n",
840 GNUNET_free_non_null (str_d_total);
841 GNUNET_free_non_null (str_d_setup);
842 GNUNET_free_non_null (str_d_lp);
843 GNUNET_free_non_null (str_d_mlp);
845 GNUNET_CONTAINER_DLL_remove (ph.head, ph.tail, cur);
849 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
850 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
852 GNUNET_free_non_null (data_fn_full);
854 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
855 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
857 GNUNET_free_non_null (data_fn_update);
864 struct ATS_Address *cur;
865 struct ATS_Address *next;
868 int count_p = ph.N_peers_end;
869 int count_a = ph.N_address;
870 struct ATS_Address * cur_addr;
873 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
875 for (cp = 0; cp < count_p; cp++)
876 perf_create_peer (cp);
877 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
878 "Added %u peers\n", cp);
880 for (cp = 0; cp < count_p; cp++)
882 if (GNUNET_NO == ph.bulk_running)
884 ph.bulk_running = GNUNET_YES;
885 ph.env.sf.s_bulk_start (ph.solver);
887 ph.current_p = cp + 1;
888 for (ca = 0; ca < count_a; ca++)
890 cur_addr = perf_create_address (cp, ca);
892 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount));
893 ph.current_a = ca + 1;
894 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
895 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
896 "Adding address for peer %u address %u\n", cp, ca);
898 /* Notify solver about request */
899 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
901 if (cp + 1 >= ph.N_peers_start)
903 /* Disable bulk to solve the problem */
904 if (GNUNET_YES == ph.bulk_running)
906 ph.expecting_solution = GNUNET_YES;
907 ph.bulk_running = GNUNET_NO;
908 ph.env.sf.s_bulk_stop (ph.solver);
915 /* Problem is solved by the solver here due to unlocking */
916 ph.expecting_solution = GNUNET_NO;
918 /* Update the problem */
919 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
922 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
923 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
925 ph.expecting_solution = GNUNET_YES;
926 if (GNUNET_NO == ph.bulk_running)
928 ph.bulk_running = GNUNET_YES;
929 ph.env.sf.s_bulk_start (ph.solver);
931 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
932 ph.bulk_running = GNUNET_NO;
933 ph.env.sf.s_bulk_stop (ph.solver);
934 /* Problem is solved by the solver here due to unlocking */
935 ph.expecting_solution = GNUNET_NO;
937 GNUNET_assert (GNUNET_NO == ph.bulk_running);
941 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
942 "Done, cleaning up addresses\n");
943 if (GNUNET_NO == ph.bulk_running)
945 ph.env.sf.s_bulk_start (ph.solver);
946 ph.bulk_running = GNUNET_YES;
949 for (cp = 0; cp < count_p; cp++)
951 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
953 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
954 "Deleting addresses for peer %u\n", cp);
955 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
956 &ph.peers[cp].id, cur));
957 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
959 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
964 GNUNET_free(ph.peers);
971 run (void *cls, char * const *args, const char *cfgfile,
972 const struct GNUNET_CONFIGURATION_Handle *cfg)
974 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
976 char *src_filename = GNUNET_strdup (__FILE__);
977 char *test_filename = cls;
980 struct GNUNET_CONFIGURATION_Handle *solver_cfg;
981 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
982 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
985 /* Extract test name */
986 if (NULL == (sep = (strstr (src_filename,".c"))))
988 GNUNET_free (src_filename);
995 if (NULL != (sep = strstr (test_filename, ".exe")))
998 if (NULL == (solver = strstr (test_filename, src_filename)))
1000 GNUNET_free (src_filename);
1005 solver += strlen (src_filename) +1;
1007 if (0 == strcmp(solver, "proportional"))
1009 ph.ats_mode = MODE_PROPORTIONAL;
1010 ph.ats_string = "proportional";
1012 else if (0 == strcmp(solver, "mlp"))
1014 ph.ats_mode = MODE_MLP;
1015 ph.ats_string = "mlp";
1017 else if ((0 == strcmp(solver, "ril")))
1019 ph.ats_mode = MODE_RIL;
1020 ph.ats_string = "ril";
1024 GNUNET_free (src_filename);
1029 GNUNET_free (src_filename);
1031 /* Calculcate peers */
1032 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1034 ph.N_peers_start = DEFAULT_PEERS_START;
1035 ph.N_peers_end = DEFAULT_PEERS_END;
1037 if (0 == ph.N_address)
1038 ph.N_address = DEFAULT_ADDRESSES;
1040 if (ph.N_peers_start != ph.N_peers_end)
1041 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses\n",
1042 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
1044 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses\n",
1045 ph.ats_string, ph.N_peers_end, ph.N_address);
1047 if (0 == ph.opt_update_percent)
1048 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1051 solver_cfg = GNUNET_CONFIGURATION_create();
1052 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1058 if (GNUNET_ATS_NetworkTypeCount != load_quotas (solver_cfg,
1059 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1067 ph.env.cfg = solver_cfg;
1068 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1069 ph.env.stats = ph.stat;
1070 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1071 ph.env.addresses = ph.addresses;
1072 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1073 ph.env.get_preferences = &get_preferences_cb;
1074 ph.env.get_property = &get_property_cb;
1075 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1076 ph.env.info_cb = &solver_info_cb;
1077 ph.env.info_cb_cls = NULL;
1079 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1080 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1082 ph.env.networks[c] = networks[c];
1083 ph.env.out_quota[c] = quotas_out[c];
1084 ph.env.in_quota[c] = quotas_in[c];
1085 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
1086 GNUNET_ATS_print_network_type(ph.env.networks[c]),
1087 ph.env.out_quota[c],
1088 ph.env.in_quota[c]);
1090 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1092 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1093 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
1094 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
1096 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
1105 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1106 GNUNET_PLUGIN_unload (plugin, ph.solver);
1107 GNUNET_free (plugin);
1108 GNUNET_CONFIGURATION_destroy (solver_cfg);
1113 main (int argc, char *argv[])
1115 /* extract command line arguments */
1116 ph.opt_update_percent = 0;
1117 ph.N_peers_start = 0;
1120 ph.ats_string = NULL;
1121 ph.create_plot = GNUNET_NO;
1122 ph.measure_updates = GNUNET_NO;
1124 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1125 { 'a', "addresses", NULL,
1126 gettext_noop ("addresses to use"),
1127 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
1128 { 's', "start", NULL,
1129 gettext_noop ("start with peer"),
1130 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
1132 gettext_noop ("end with peer"),
1133 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
1134 { 'p', "percentage", NULL,
1135 gettext_noop ("update a fix percentage of addresses"),
1136 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
1137 { 'g', "gnuplot", NULL,
1138 gettext_noop ("create GNUplot file"),
1139 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
1140 { 'u', "update", NULL,
1141 gettext_noop ("measure updates"),
1142 0, &GNUNET_GETOPT_set_one, &ph.measure_updates},
1143 GNUNET_GETOPT_OPTION_END
1146 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1151 /* end of file perf_ats_solver.c */