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_PEERS_START 10
36 #define DEFAULT_PEERS_END 10
37 #define DEFAULT_ADDRESSES 10
38 #define DEFAULT_ATS_COUNT 2
40 #define GNUPLOT_PROP_TEMPLATE "#!/usr/bin/gnuplot \n" \
41 "set datafile separator ';' \n" \
42 "set title \"Execution time Proportional solver \" \n" \
43 "set xlabel \"Number of peers\" \n" \
44 "set ylabel \"Execution time in us\" \n" \
47 #define GNUPLOT_MLP_TEMPLATE "#!/usr/bin/gnuplot \n" \
48 "set datafile separator ';' \n" \
49 "set title \"Execution time MLP solver \" \n" \
50 "set xlabel \"Number of peers\" \n" \
51 "set ylabel \"Execution time in us\" \n" \
54 #define GNUPLOT_RIL_TEMPLATE "#!/usr/bin/gnuplot \n" \
55 "set datafile separator ';' \n" \
56 "set title \"Execution time RIL solver \" \n" \
57 "set xlabel \"Number of peers\" \n" \
58 "set ylabel \"Execution time in us\" \n" \
62 * Handle for ATS address component
69 struct PerfPeer *peers;
79 struct GNUNET_STATISTICS_Handle *stat;
82 * A multihashmap to store all addresses
84 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
89 struct GNUNET_ATS_PluginEnvironment env;
95 struct Result *current_result;
101 * Solver description as string
106 * Configured ATS solver
111 * #peers to start benchmarking with
116 * #peers to end benchmarking with
121 * #addresses to benchmarking with
126 * Percentage of peers to update
128 int opt_update_percent;
131 * Number of peers to update
133 int opt_update_quantity;
136 * Create gnuplot file
141 * Is a bulk operation running?
146 * Is a bulk operation running?
148 int expecting_solution;
159 struct GNUNET_TIME_Relative d_setup;
160 struct GNUNET_TIME_Relative d_lp;
161 struct GNUNET_TIME_Relative d_mlp;
162 struct GNUNET_TIME_Relative d_total;
164 struct GNUNET_TIME_Absolute s_setup;
165 struct GNUNET_TIME_Absolute s_lp;
166 struct GNUNET_TIME_Absolute s_mlp;
167 struct GNUNET_TIME_Absolute s_total;
169 struct GNUNET_TIME_Absolute e_setup;
170 struct GNUNET_TIME_Absolute e_lp;
171 struct GNUNET_TIME_Absolute e_mlp;
172 struct GNUNET_TIME_Absolute e_total;
177 struct GNUNET_PeerIdentity id;
179 struct ATS_Address *head;
180 struct ATS_Address *tail;
183 static struct PerfHandle ph;
194 //static struct GNUNET_ATS_Information ats[2];
202 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
206 if (NULL != addresses)
208 GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, NULL);
209 GNUNET_CONTAINER_multihashmap_destroy (addresses);
212 if (NULL != ph.peers)
214 GNUNET_free(ph.peers);
217 GAS_normalization_stop ();
223 perf_create_peer (int cp)
226 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
227 &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
228 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
229 GNUNET_i2s (&ph.peers[cp].id));
235 perf_update_address (struct ATS_Address *cur)
240 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
244 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
246 "Updating peer `%s' address %p type %s val %u\n",
247 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val);
248 ph.env.sf.s_address_update_property (ph.solver, cur,
249 GNUNET_ATS_QUALITY_NET_DELAY,
250 r_val, (double) (100 + r_val / 100));
253 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
255 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
256 "Updating peer `%s' address %p type %s val %u\n",
257 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val);
258 ph.env.sf.s_address_update_property (ph.solver, cur,
259 GNUNET_ATS_QUALITY_NET_DISTANCE,
260 r_val, (double) (100 + r_val) / 100);
265 ph.env.sf.s_address_update_inuse (ph.solver, cur, GNUNET_YES);
271 bandwidth_changed_cb (void *cls, struct ATS_Address *address)
273 if (0 == ntohl(address->assigned_bw_out.value__) &&
274 0 == ntohl(address->assigned_bw_in.value__))
277 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
278 "Bandwidth changed addresses %s %p to %llu Bps out / %llu Bps in\n",
279 GNUNET_i2s (&address->peer),
281 ntohl(address->assigned_bw_out.value__),
282 ntohl(address->assigned_bw_in.value__));
283 if (GNUNET_YES == ph.bulk_running)
289 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
291 return GAS_normalization_get_preferences (id);
296 get_property_cb (void *cls, const struct ATS_Address *address)
298 return GAS_normalization_get_properties ((struct ATS_Address *) address);
302 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
303 uint32_t type, double prop_rel)
309 perf_address_initial_update (void *solver,
310 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
311 struct ATS_Address *address)
313 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
315 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
318 ph.env.sf.s_address_update_property (solver, address,
319 GNUNET_ATS_QUALITY_NET_DISTANCE, 10,
320 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100))
325 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int up_q)
327 struct ATS_Address *cur;
333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
334 "Updating addresses %u addresses per peer \n", up_q);
337 for (c_peer = 0; c_peer < cp; c_peer++)
339 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s'\n",
340 GNUNET_i2s (&ph.peers[c_peer].id));
341 for (c_select = 0; c_select < ca; c_select++)
344 while (c_select < ph.opt_update_quantity)
346 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
355 for (cur = ph.peers[c_peer].head; NULL != cur; cur = cur->next)
358 perf_update_address (cur);
365 static struct ATS_Address *
366 perf_create_address (int cp, int ca)
368 struct ATS_Address *a;
369 a = create_address (&ph.peers[cp].id,
370 "Test 1", "test 1", strlen ("test 1") + 1, 0);
371 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
372 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
373 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
378 solver_info_cb (void *cls,
379 enum GAS_Solver_Operation op,
380 enum GAS_Solver_Status stat,
381 enum GAS_Solver_Additional_Information add)
387 case GAS_OP_SOLVE_START:
388 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
389 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_START",
390 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
391 if (GNUNET_NO == ph.expecting_solution)
393 /* We do not expect a solution at the moment */
397 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
399 /* Create new result */
400 tmp = GNUNET_malloc (sizeof (struct Result));
401 ph.current_result = tmp;
402 GNUNET_CONTAINER_DLL_insert_tail(ph.head, ph.tail, tmp);
403 ph.current_result->addresses = ph.current_a;
404 ph.current_result->peers = ph.current_p;
405 ph.current_result->s_total = GNUNET_TIME_absolute_get ();
406 ph.current_result->d_total = GNUNET_TIME_relative_get_forever_ ();
407 ph.current_result->d_setup = GNUNET_TIME_relative_get_forever_ ();
408 ph.current_result->d_lp = GNUNET_TIME_relative_get_forever_ ();
409 ph.current_result->d_mlp = GNUNET_TIME_relative_get_forever_ ();
412 case GAS_OP_SOLVE_STOP:
413 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
414 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
415 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
416 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
418 /* We do not expect a solution at the moment */
422 if (NULL != ph.current_result)
424 /* Finalize result */
425 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
426 ph.current_result->d_total = GNUNET_TIME_absolute_get_difference (
427 ph.current_result->s_total, ph.current_result->e_total);
429 ph.current_result = NULL;
432 case GAS_OP_SOLVE_SETUP_START:
433 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
434 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
435 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
436 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
441 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
444 case GAS_OP_SOLVE_SETUP_STOP:
445 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
446 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
447 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
448 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
453 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
454 ph.current_result->d_setup = GNUNET_TIME_absolute_get_difference (
455 ph.current_result->s_setup, ph.current_result->e_setup);
458 case GAS_OP_SOLVE_LP_START:
459 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
460 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
461 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
462 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
467 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
469 case GAS_OP_SOLVE_LP_STOP:
470 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
471 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
472 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
473 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
478 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
479 ph.current_result->d_lp = GNUNET_TIME_absolute_get_difference (
480 ph.current_result->s_lp, ph.current_result->e_lp);
483 case GAS_OP_SOLVE_MLP_START:
484 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
485 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
486 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
487 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
492 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
494 case GAS_OP_SOLVE_MLP_STOP:
495 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
496 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
497 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
498 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
503 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
504 ph.current_result->d_mlp = GNUNET_TIME_absolute_get_difference (
505 ph.current_result->s_mlp, ph.current_result->e_mlp);
514 write_gnuplot_script (char * data_fn)
516 struct GNUNET_DISK_FileHandle *f;
521 GNUNET_asprintf (&gfn, "perf_%s_%u_%u_%u.gnuplot", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
522 f = GNUNET_DISK_file_open (gfn,
523 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
524 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
533 switch (ph.ats_mode) {
534 case MODE_PROPORTIONAL:
535 template = GNUPLOT_PROP_TEMPLATE;
538 template = GNUPLOT_MLP_TEMPLATE;
541 template = GNUPLOT_RIL_TEMPLATE;
546 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, template, strlen(template)))
547 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
549 if (MODE_PROPORTIONAL == ph.ats_mode)
551 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
555 if (MODE_MLP == ph.ats_mode)
557 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve',\\\n" \
558 "'%s' using 1:%u with lines title 'Time to setup',\\\n"
559 "'%s' using 1:%u with lines title 'Time to solve LP',\\\n"
560 "'%s' using 1:%u with lines title 'Total time to solve MLP'\n" \
567 if (MODE_RIL == ph.ats_mode)
569 GNUNET_asprintf (&data, "plot '%s' using 1:%u with lines title 'Total time to solve'\n" \
574 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
578 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
579 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
590 struct GNUNET_DISK_FileHandle *f;
602 GNUNET_asprintf (&data_fn, "perf_%s_%u_%u_%u.data", ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
603 f = GNUNET_DISK_file_open (data_fn,
604 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
605 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", data_fn);
611 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
612 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", data_fn);
614 write_gnuplot_script (data_fn);
618 while (NULL != (cur = next))
623 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
625 fprintf (stderr, "Total time to solve for %u peers %u addresses: %llu us\n",
626 cur->peers, cur->addresses, (unsigned long long )cur->d_total.rel_value_us);
627 GNUNET_asprintf(&str_d_total, "%llu", (unsigned long long )cur->d_total.rel_value_us);
630 GNUNET_asprintf(&str_d_total, "-1");
631 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
633 fprintf (stderr, "Total time to setup %u peers %u addresses: %llu us\n",
634 cur->peers, cur->addresses, (unsigned long long )cur->d_setup.rel_value_us);
635 GNUNET_asprintf(&str_d_setup, "%llu", (unsigned long long )cur->d_setup.rel_value_us);
638 GNUNET_asprintf(&str_d_setup, "-1");
639 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
641 fprintf (stderr, "Total time to solve LP for %u peers %u addresses: %llu us\n",
642 cur->peers, cur->addresses, (unsigned long long )cur->d_lp.rel_value_us);
643 GNUNET_asprintf(&str_d_lp, "%llu", (unsigned long long )cur->d_lp.rel_value_us);
646 GNUNET_asprintf(&str_d_lp, "-1");
647 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
649 fprintf (stderr, "Total time to solve MLP for %u peers %u addresses: %llu us\n",
650 cur->peers, cur->addresses, (unsigned long long )cur->d_mlp.rel_value_us);
651 GNUNET_asprintf(&str_d_mlp, "%llu", (unsigned long long )cur->d_mlp.rel_value_us);
654 GNUNET_asprintf(&str_d_mlp, "-1");
656 if (GNUNET_YES == ph.create_plot)
659 GNUNET_asprintf(&data,"%u;%u;%s;%s;%s;%s\n",
660 cur->peers, cur->addresses,
666 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
667 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", data_fn);
668 GNUNET_free (str_d_total);
669 GNUNET_free (str_d_setup);
670 GNUNET_free (str_d_lp);
671 GNUNET_free (str_d_mlp);
674 GNUNET_CONTAINER_DLL_remove (ph.head, ph.tail, cur);
678 if (GNUNET_YES == ph.create_plot)
680 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", data_fn);
682 GNUNET_free (data_fn);
689 struct ATS_Address *cur;
690 struct ATS_Address *next;
693 int count_p = ph.N_peers_end;
694 int count_a = ph.N_address;
695 struct ATS_Address * cur_addr;
698 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
700 for (cp = 0; cp < count_p; cp++)
701 perf_create_peer (cp);
702 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
703 "Added %u peers\n", cp);
705 /* Set initial bulk start to not solve */
706 ph.env.sf.s_bulk_start (ph.solver);
707 ph.bulk_running = GNUNET_YES;
709 for (cp = 0; cp < count_p; cp++)
711 ph.current_p = cp + 1;
712 for (ca = 0; ca < count_a; ca++)
714 cur_addr = perf_create_address (cp, ca);
716 ph.env.sf.s_add (ph.solver, cur_addr, GNUNET_ATS_NET_LAN);
717 ph.current_a = ca + 1;
718 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
719 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
720 "Adding address for peer %u address %u\n", cp, ca);
722 /* Notify solver about request */
723 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
725 if (cp + 1 >= ph.N_peers_start)
727 /* Disable bulk to solve the problem */
728 if (GNUNET_YES == ph.bulk_running)
730 ph.bulk_running = GNUNET_NO;
731 ph.expecting_solution = GNUNET_YES;
732 ph.env.sf.s_bulk_stop (ph.solver);
739 /* Problem is solved by the solver here due to unlocking */
741 ph.expecting_solution = GNUNET_NO;
742 /* Disable bulk to solve the problem */
743 if (GNUNET_NO == ph.bulk_running)
745 ph.env.sf.s_bulk_start (ph.solver);
746 ph.bulk_running = GNUNET_YES;
749 if ((0 < ph.opt_update_quantity) || (0 < ph.opt_update_percent))
752 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
753 "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
754 //ph.env.sf.s_bulk_start (ph.solver);
755 //update_addresses (cp + 1, ca, ph.opt_update_quantity);
756 //ph.env.sf.s_bulk_stop (ph.solver);
761 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
762 "Done, cleaning up addresses\n");
763 if (GNUNET_NO == ph.bulk_running)
765 ph.env.sf.s_bulk_start (ph.solver);
766 ph.bulk_running = GNUNET_YES;
769 for (cp = 0; cp < count_p; cp++)
771 for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
774 "Deleting addresses for peer %u\n", cp);
775 GNUNET_CONTAINER_multipeermap_remove (ph.addresses, &ph.peers[cp].id, cur);
776 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
778 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
783 GNUNET_free(ph.peers);
790 run (void *cls, char * const *args, const char *cfgfile,
791 const struct GNUNET_CONFIGURATION_Handle *cfg)
793 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
795 char *src_filename = GNUNET_strdup (__FILE__);
796 char *test_filename = cls;
799 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
800 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
803 /* Extract test name */
804 if (NULL == (sep = (strstr (src_filename,".c"))))
812 if (NULL != (sep = strstr (test_filename, ".exe")))
815 if (NULL == (solver = strstr (test_filename, src_filename)))
821 solver += strlen (src_filename) +1;
823 if (0 == strcmp(solver, "proportional"))
825 ph.ats_mode = MODE_PROPORTIONAL;
826 ph.ats_string = "proportional";
828 else if (0 == strcmp(solver, "mlp"))
830 ph.ats_mode = MODE_MLP;
831 ph.ats_string = "mlp";
833 else if ((0 == strcmp(solver, "ril")))
835 ph.ats_mode = MODE_RIL;
836 ph.ats_string = "ril";
840 GNUNET_free (src_filename);
845 GNUNET_free (src_filename);
847 /* Calculcate peers */
848 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
850 ph.N_peers_start = DEFAULT_PEERS_START;
851 ph.N_peers_end = DEFAULT_PEERS_END;
853 if (0 == ph.N_address)
854 ph.N_address = DEFAULT_ADDRESSES;
856 if (ph.opt_update_quantity > ph.N_address)
859 _("Trying to update more addresses than we have per peer! (%u vs %u)"),
860 ph.opt_update_quantity, ph.N_address);
864 if (ph.N_peers_start != ph.N_peers_end)
865 fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses\n",
866 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address);
868 fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses\n",
869 ph.ats_string, ph.N_peers_end, ph.N_address);
872 if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg,
873 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
882 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
883 ph.env.stats = ph.stat;
884 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
885 ph.env.addresses = ph.addresses;
886 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
887 ph.env.get_preferences = &get_preferences_cb;
888 ph.env.get_property = &get_property_cb;
889 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
890 ph.env.info_cb = &solver_info_cb;
891 ph.env.info_cb_cls = NULL;
893 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
894 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
896 ph.env.networks[c] = networks[c];
897 ph.env.out_quota[c] = quotas_out[c];
898 ph.env.in_quota[c] = quotas_in[c];
899 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
900 GNUNET_ATS_print_network_type(ph.env.networks[c]),
904 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
906 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
907 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string);
908 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
910 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin);
919 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
920 GNUNET_PLUGIN_unload (plugin, ph.solver);
921 GNUNET_free (plugin);
926 main (int argc, char *argv[])
928 /* extract command line arguments */
929 ph.opt_update_quantity = 0;
930 ph.opt_update_percent = 0;
931 ph.N_peers_start = 0;
934 ph.ats_string = NULL;
935 ph.create_plot = GNUNET_NO;
937 static struct GNUNET_GETOPT_CommandLineOption options[] = {
938 { 'a', "addresses", NULL,
939 gettext_noop ("addresses to use"),
940 1, &GNUNET_GETOPT_set_uint, &ph.N_address },
941 { 's', "start", NULL,
942 gettext_noop ("start with peer"),
943 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_start },
945 gettext_noop ("end with peer"),
946 1, &GNUNET_GETOPT_set_uint, &ph.N_peers_end },
947 { 'p', "percentage", NULL,
948 gettext_noop ("update a fix percentage of addresses"),
949 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_percent },
950 { 'q', "quantity", NULL,
951 gettext_noop ("update a fix quantity of addresses"),
952 1, &GNUNET_GETOPT_set_uint, &ph.opt_update_quantity },
953 { 'g', "gnuplot", NULL,
954 gettext_noop ("create GNUplot file"),
955 0, &GNUNET_GETOPT_set_one, &ph.create_plot},
956 GNUNET_GETOPT_OPTION_END
959 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
964 /* end of file perf_ats_solver.c */