2 This file is part of GNUnet.
3 (C) 2010-2013 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-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet-ats-solver-eval.h"
30 #define BIG_M_STRING "unlimited"
32 static struct Experiment *e;
34 static struct LoggingHandle *l;
36 static struct SolverHandle *sh;
38 static struct TestPeer *peer_head;
39 static struct TestPeer *peer_tail;
41 static double default_properties[GNUNET_ATS_PropertyCount];
42 static double default_preferences[GNUNET_ATS_PreferenceCount];
45 * cmd option -e: experiment file
47 static char *opt_exp_file;
49 static char *opt_solver;
52 * cmd option -l: enable logging
57 * cmd option -p: enable plots
62 * cmd option -v: verbose logs
64 static int opt_verbose;
67 * cmd option -p: print logs
72 * cmd option -d: disable normalization
74 static int opt_disable_normalization;
83 print_generator_type (enum GeneratorType g)
86 case GNUNET_ATS_TEST_TG_CONSTANT:
88 case GNUNET_ATS_TEST_TG_LINEAR:
90 case GNUNET_ATS_TEST_TG_RANDOM:
92 case GNUNET_ATS_TEST_TG_SINUS:
100 struct AddressLookupCtx
102 struct ATS_Address *res;
108 int find_address_it (void *cls,
109 const struct GNUNET_PeerIdentity *key,
112 struct AddressLookupCtx *ctx = cls;
113 struct ATS_Address *addr = value;
115 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
116 (0 == strcmp (ctx->addr, addr->addr)) )
124 static struct TestPeer *
125 find_peer_by_id (int id)
127 struct TestPeer *cur;
128 for (cur = peer_head; NULL != cur; cur = cur->next)
134 static struct TestPeer *
135 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
137 struct TestPeer *cur;
138 for (cur = peer_head; NULL != cur; cur = cur->next)
139 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
144 static struct TestAddress *
145 find_address_by_id (struct TestPeer *peer, int aid)
147 struct TestAddress *cur;
148 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
155 static struct TestAddress *
156 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
158 struct TestAddress *cur;
159 for (cur = p->addr_head; NULL != cur; cur = cur->next)
160 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
161 (cur->ats_addr->addr_len == addr->addr_len) &&
162 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
173 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
175 struct LoggingTimeStep *lts;
176 struct TestPeer *cur;
177 struct TestAddress *cur_addr;
178 struct LoggingPeer *log_p;
179 struct LoggingAddress *log_a;
182 lts = GNUNET_new (struct LoggingTimeStep);
183 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
184 lts->timestamp = GNUNET_TIME_absolute_get();
185 if (NULL == lts->prev)
186 lts->delta = GNUNET_TIME_UNIT_ZERO;
188 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
191 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
194 /* Store logging data here */
195 for (cur = peer_head; NULL != cur; cur = cur->next)
197 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
199 log_p = GNUNET_new (struct LoggingPeer);
201 log_p->peer_id = cur->peer_id;
202 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
204 log_p->pref_abs[c] = cur->pref_abs[c];
205 log_p->pref_norm[c] = cur->pref_norm[c];
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
207 GNUNET_ATS_print_preference_type(c),
208 log_p->pref_abs[c], log_p->pref_norm[c]);
210 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
212 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
215 cur->id, cur_addr->aid);
216 log_a = GNUNET_new (struct LoggingAddress);
217 log_a->aid = cur_addr->aid;
218 log_a->active = cur_addr->ats_addr->active;
219 log_a->network = cur_addr->network;
220 log_a->used = cur_addr->ats_addr->used;
221 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
222 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
223 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
225 log_a->prop_abs[c] = cur_addr->prop_abs[c];
226 log_a->prop_norm[c] = cur_addr->prop_norm[c];
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
228 GNUNET_ATS_print_property_type(c),
229 log_a->prop_abs[c], log_a->prop_norm[c]);
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", ntohl(log_a->assigned_bw_in.value__));
233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", ntohl(log_a->assigned_bw_out.value__));
235 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
241 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
243 struct LoggingHandle *l = cls;
244 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
246 GNUNET_ATS_solver_logging_now (l);
248 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
252 struct LoggingHandle *
253 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
255 struct LoggingHandle *l;
256 l = GNUNET_new (struct LoggingHandle);
258 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
259 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
261 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
266 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
268 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
269 GNUNET_SCHEDULER_cancel (l->logging_task);
271 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
273 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
276 static struct LoggingFileHandle *
277 find_logging_file_handle (struct LoggingFileHandle *lf_head,
278 struct LoggingFileHandle *lf_tail,
279 int peer_id, int address_id)
281 struct LoggingFileHandle *res;
283 for (res = lf_head; NULL != res; res = res->next)
284 if ((res->pid == peer_id) && (res->aid == address_id))
291 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
294 struct LoggingTimeStep *lts;
295 struct LoggingPeer *log_p;
296 struct LoggingAddress *log_a;
297 struct LoggingFileHandle *lf_head;
298 struct LoggingFileHandle *lf_tail;
299 struct LoggingFileHandle *cur;
300 struct LoggingFileHandle *next;
304 char * propstring_tmp;
306 char * prefstring_tmp;
311 if (NULL != output_dir)
313 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
315 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
320 fprintf (stderr, "Created directory `%s'\n", output_dir);
321 use_dir = GNUNET_YES;
328 for (lts = l->head; NULL != lts; lts = lts->next)
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
332 (long long unsigned int) lts->timestamp.abs_value_us);
334 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
336 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
339 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
343 cur = GNUNET_new (struct LoggingFileHandle);
344 cur->aid = log_a->aid;
345 cur->pid = log_p->id;
347 if (GNUNET_YES == add_time_stamp)
348 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
349 (GNUNET_YES == use_dir) ? output_dir : "",
350 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
355 l->head->timestamp.abs_value_us);
357 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
358 (GNUNET_YES == use_dir) ? output_dir : "",
359 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
365 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
366 cur->pid, cur->aid, filename);
369 cur->f_hd = GNUNET_DISK_file_open (filename,
370 GNUNET_DISK_OPEN_READWRITE |
371 GNUNET_DISK_OPEN_CREATE |
372 GNUNET_DISK_OPEN_TRUNCATE,
373 GNUNET_DISK_PERM_USER_READ |
374 GNUNET_DISK_PERM_USER_WRITE |
375 GNUNET_DISK_PERM_GROUP_READ |
376 GNUNET_DISK_PERM_OTHER_READ);
377 if (NULL == cur->f_hd)
379 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
380 GNUNET_free (filename);
383 GNUNET_free (filename);
384 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
386 GNUNET_asprintf(&datastring,"#time delta;log duration; addr net; addr_active; bw in; bw out; " \
387 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
388 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
390 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
391 "COST_WLAN; COST_WLAN; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
392 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
393 GNUNET_free (datastring);
397 prefstring = GNUNET_strdup("");
398 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
401 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
402 GNUNET_ATS_print_preference_type(c),
403 log_p->pref_abs[c], log_p->pref_norm[c]);
405 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
406 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
409 GNUNET_free (prefstring);
410 prefstring = GNUNET_strdup(prefstring_tmp);
411 GNUNET_free (prefstring_tmp);
415 propstring = GNUNET_strdup("");
416 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
418 if (GNUNET_ATS_NETWORK_TYPE == c)
421 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
422 GNUNET_ATS_print_property_type(c),
423 log_a->prop_abs[c], log_a->prop_norm[c]);*/
424 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
425 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
426 GNUNET_free (propstring);
427 propstring = GNUNET_strdup(propstring_tmp);
428 GNUNET_free (propstring_tmp);
431 GNUNET_asprintf(&datastring,"%llu;%llu;%u;%i;%u;%u;%s;%s\n",
432 GNUNET_TIME_absolute_get_difference(l->head->timestamp, lts->timestamp).rel_value_us / 1000,
436 ntohl (log_a->assigned_bw_in.value__),
437 ntohl (log_a->assigned_bw_out.value__),
438 propstring, prefstring);
440 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
441 GNUNET_free (datastring);
442 GNUNET_free (prefstring);
443 GNUNET_free (propstring);
450 for (cur = next; NULL != cur; cur = next)
453 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
454 if (NULL != cur->f_hd)
455 GNUNET_DISK_file_close (cur->f_hd);
462 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
464 struct LoggingTimeStep *lts;
465 struct LoggingPeer *log_p;
466 struct LoggingAddress *log_a;
469 for (lts = l->head; NULL != lts; lts = lts->next)
471 fprintf (stderr, "Log step %llu %llu: \n",
472 (long long unsigned int) lts->timestamp.abs_value_us,
473 (long long unsigned int) lts->delta.rel_value_us);
475 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
477 fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
478 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
480 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
481 GNUNET_ATS_print_preference_type(c),
482 log_p->pref_abs[c], log_p->pref_norm[c]);
485 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
487 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
488 log_p->id, log_a->aid, log_a->active,
489 ntohl(log_a->assigned_bw_in.value__),
490 ntohl(log_a->assigned_bw_out.value__));
492 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
494 if (GNUNET_ATS_NETWORK_TYPE == c)
496 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
497 GNUNET_ATS_print_property_type(c),
498 log_a->prop_abs[c], log_a->prop_norm[c]);
506 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
508 struct LoggingTimeStep *lts_cur;
509 struct LoggingTimeStep *lts_next;
510 struct LoggingPeer *log_p_cur;
511 struct LoggingPeer *log_p_next;
512 struct LoggingAddress *log_a_cur;
513 struct LoggingAddress *log_a_next;
515 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
516 GNUNET_SCHEDULER_cancel (l->logging_task);
517 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
520 while (NULL != (lts_cur = lts_next))
522 lts_next = lts_cur->next;
524 log_p_next = lts_cur->head;
525 while (NULL != (log_p_cur = log_p_next))
527 log_p_next = log_p_cur->next;
529 log_a_next = log_p_cur->addr_head;
530 while (NULL != (log_a_cur = log_a_next))
532 log_a_next = log_a_cur->next;
534 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
535 GNUNET_free (log_a_cur);
538 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
539 GNUNET_free (log_p_cur);
542 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
543 GNUNET_free (lts_cur);
550 * Property Generators
553 static struct PropertyGenerator *prop_gen_head;
554 static struct PropertyGenerator *prop_gen_tail;
557 get_property (struct PropertyGenerator *pg)
559 struct GNUNET_TIME_Relative time_delta;
563 /* Calculate the current preference value */
565 case GNUNET_ATS_TEST_TG_CONSTANT:
566 pref_value = pg->base_value;
568 case GNUNET_ATS_TEST_TG_LINEAR:
569 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
570 /* Calculate point of time in the current period */
571 time_delta.rel_value_us = time_delta.rel_value_us %
572 pg->duration_period.rel_value_us;
573 delta_value = ((double) time_delta.rel_value_us /
574 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
575 if ((pg->max_value < pg->base_value) &&
576 ((pg->max_value - pg->base_value) > pg->base_value))
578 /* This will cause an underflow */
581 pref_value = pg->base_value + delta_value;
583 case GNUNET_ATS_TEST_TG_RANDOM:
584 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
585 10000 * (pg->max_value - pg->base_value)) / 10000;
586 pref_value = pg->base_value + delta_value;
588 case GNUNET_ATS_TEST_TG_SINUS:
589 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
590 /* Calculate point of time in the current period */
591 time_delta.rel_value_us = time_delta.rel_value_us %
592 pg->duration_period.rel_value_us;
593 if ((pg->max_value - pg->base_value) > pg->base_value)
595 /* This will cause an underflow for second half of sinus period,
596 * will be detected in general when experiments are loaded */
599 delta_value = (pg->max_value - pg->base_value) *
600 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
601 time_delta.rel_value_us);
602 pref_value = pg->base_value + delta_value;
608 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
615 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
617 struct PropertyGenerator *pg = cls;
619 struct TestAddress *a;
621 struct GNUNET_ATS_Information atsi;
623 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
625 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
626 &pg->test_peer->peer_id, pg->test_address->ats_addr))
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 "Setting property generation for unknown address [%u:%u]\n",
631 pg->peer, pg->address_id);
634 if (NULL == (p = find_peer_by_id (pg->peer)))
636 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
637 "Setting property generation for unknown peer %u\n",
640 if (NULL == (a = find_address_by_id (p, pg->address_id)))
642 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
643 "Setting property generation for unknown peer %u\n",
647 prop_value = get_property (pg);
648 a->prop_abs[pg->ats_property] = prop_value;
650 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
651 "Setting property for peer [%u] address [%u] for %s to %f\n",
652 pg->peer, pg->address_id,
653 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
655 atsi.type = htonl (pg->ats_property);
656 atsi.value = htonl ((uint32_t) prop_value);
658 /* set performance here! */
659 sh->env.sf.s_bulk_start (sh->solver);
660 if (GNUNET_YES == opt_disable_normalization)
662 a->prop_abs[pg->ats_property] = prop_value;
663 a->prop_norm[pg->ats_property] = prop_value;
664 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
665 pg->ats_property, prop_value, prop_value);
668 GAS_normalization_normalize_property (sh->addresses,
669 pg->test_address->ats_addr, &atsi, 1);
670 sh->env.sf.s_bulk_stop (sh->solver);
672 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
678 * Set ats_property to 0 to find all pgs
681 static struct PropertyGenerator *
682 find_prop_gen (unsigned int peer, unsigned int address,
683 uint32_t ats_property)
685 struct PropertyGenerator *cur;
686 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
687 if ((cur->peer == peer) && (cur->address_id == address))
689 if ((cur->ats_property == ats_property) || (0 == ats_property))
696 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
698 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
700 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
702 GNUNET_SCHEDULER_cancel (pg->set_task);
703 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
705 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
706 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
707 pg->peer, pg->address_id,
708 GNUNET_ATS_print_property_type(pg->ats_property));
715 * Generate between the source master and the partner and set property with a
716 * value depending on the generator.
719 * @param address_id partner
720 * @param test_peer the peer
721 * @param test_address the address
722 * @param type type of generator
723 * @param base_value base value
724 * @param value_rate maximum value
725 * @param period duration of a period of generation (~ 1/frequency)
726 * @param frequency how long to generate property
727 * @param ats_property ATS property to generate
728 * @return the property generator
730 struct PropertyGenerator *
731 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
732 unsigned int address_id,
733 struct TestPeer *test_peer,
734 struct TestAddress *test_address,
735 enum GeneratorType type,
738 struct GNUNET_TIME_Relative period,
739 struct GNUNET_TIME_Relative frequency,
740 uint32_t ats_property)
742 struct PropertyGenerator *pg;
744 pg = GNUNET_new (struct PropertyGenerator);
745 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
748 pg->test_address = test_address;
749 pg->test_peer = test_peer;
750 pg->address_id = address_id;
751 pg->ats_property = ats_property;
752 pg->base_value = base_value;
753 pg->max_value = value_rate;
754 pg->duration_period = period;
755 pg->frequency = frequency;
756 pg->time_start = GNUNET_TIME_absolute_get();
759 case GNUNET_ATS_TEST_TG_CONSTANT:
760 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
761 "Setting up %s property generator peer [%u] address [%u] `%s'"\
763 print_generator_type(type), pg->peer, pg->address_id,
764 GNUNET_ATS_print_property_type (ats_property),
767 case GNUNET_ATS_TEST_TG_LINEAR:
768 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
769 "Setting up %s property generator peer [%u] address [%u] `%s' " \
770 "min %u Bips max %u Bips\n",
771 print_generator_type(type), pg->peer, pg->address_id,
772 GNUNET_ATS_print_property_type(ats_property),
773 base_value, value_rate);
775 case GNUNET_ATS_TEST_TG_SINUS:
776 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
777 "Setting up %s property generator peer [%u] address [%u] `%s' "\
778 "baserate %u Bips, amplitude %u Bps\n",
779 print_generator_type(type), pg->peer, pg->address_id,
780 GNUNET_ATS_print_property_type(ats_property),
781 base_value, value_rate);
783 case GNUNET_ATS_TEST_TG_RANDOM:
784 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
785 "Setting up %s property generator peer [%u] address [%u] `%s' "\
786 "min %u Bips max %u Bps\n",
787 print_generator_type(type), pg->peer, pg->address_id,
788 GNUNET_ATS_print_property_type(ats_property),
789 base_value, value_rate);
795 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
802 * Stop all preferences generators
805 GNUNET_ATS_solver_generate_property_stop_all ()
807 struct PropertyGenerator *cur;
808 struct PropertyGenerator *next;
809 next = prop_gen_head;
810 for (cur = next; NULL != cur; cur = next)
813 GNUNET_ATS_solver_generate_property_stop (cur);
819 * Preference Generators
822 static struct PreferenceGenerator *pref_gen_head;
823 static struct PreferenceGenerator *pref_gen_tail;
826 get_preference (struct PreferenceGenerator *pg)
828 struct GNUNET_TIME_Relative time_delta;
832 /* Calculate the current preference value */
834 case GNUNET_ATS_TEST_TG_CONSTANT:
835 pref_value = pg->base_value;
837 case GNUNET_ATS_TEST_TG_LINEAR:
838 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
839 /* Calculate point of time in the current period */
840 time_delta.rel_value_us = time_delta.rel_value_us %
841 pg->duration_period.rel_value_us;
842 delta_value = ((double) time_delta.rel_value_us /
843 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
844 if ((pg->max_value < pg->base_value) &&
845 ((pg->max_value - pg->base_value) > pg->base_value))
847 /* This will cause an underflow */
850 pref_value = pg->base_value + delta_value;
852 case GNUNET_ATS_TEST_TG_RANDOM:
853 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
854 10000 * (pg->max_value - pg->base_value)) / 10000;
855 pref_value = pg->base_value + delta_value;
857 case GNUNET_ATS_TEST_TG_SINUS:
858 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
859 /* Calculate point of time in the current period */
860 time_delta.rel_value_us = time_delta.rel_value_us %
861 pg->duration_period.rel_value_us;
862 if ((pg->max_value - pg->base_value) > pg->base_value)
864 /* This will cause an underflow for second half of sinus period,
865 * will be detected in general when experiments are loaded */
868 delta_value = (pg->max_value - pg->base_value) *
869 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
870 time_delta.rel_value_us);
871 pref_value = pg->base_value + delta_value;
877 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
884 set_pref_task (void *cls,
885 const struct GNUNET_SCHEDULER_TaskContext *tc)
887 struct PreferenceGenerator *pg = cls;
890 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
892 if (NULL == (p = find_peer_by_id (pg->peer)))
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
896 "Setting preference for unknown peer %u\n", pg->peer);
900 pref_value = get_preference (pg);
901 p->pref_abs[pg->kind] = pref_value;
903 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
904 "Setting preference for peer [%u] for client %p pref %s to %f\n",
905 pg->peer, NULL + (pg->client_id),
906 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
908 sh->env.sf.s_bulk_start (sh->solver);
909 if (GNUNET_YES == opt_disable_normalization)
911 p->pref_abs[pg->kind] = pref_value;
912 p->pref_norm[pg->kind] = pref_value;
913 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
916 GAS_normalization_normalize_preference (NULL + (pg->client_id),
917 &p->peer_id, pg->kind, pref_value);
918 sh->env.sf.s_bulk_stop (sh->solver);
921 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
922 //p->pref_bandwidth = pref_value;
924 case GNUNET_ATS_PREFERENCE_LATENCY:
925 //p->pref_delay = pref_value;
931 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
936 static struct PreferenceGenerator *
937 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
939 struct PreferenceGenerator *cur;
940 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
941 if (cur->peer == peer)
943 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
950 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
952 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
954 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
956 GNUNET_SCHEDULER_cancel (pg->set_task);
957 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
959 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
960 "Removing old up preference generator peer [%u] `%s'\n",
961 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
968 * Generate between the source master and the partner and set property with a
969 * value depending on the generator.
972 * @param address_id partner
973 * @param client_id the client
974 * @param type type of generator
975 * @param base_value base value
976 * @param value_rate maximum value
977 * @param period duration of a period of generation (~ 1/frequency)
978 * @param frequency how long to generate property
979 * @param kind ATS preference to generate
980 * @return the preference generator
982 struct PreferenceGenerator *
983 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
984 unsigned int address_id,
985 unsigned int client_id,
986 enum GeneratorType type,
989 struct GNUNET_TIME_Relative period,
990 struct GNUNET_TIME_Relative frequency,
991 enum GNUNET_ATS_PreferenceKind kind)
993 struct PreferenceGenerator *pg;
995 pg = GNUNET_new (struct PreferenceGenerator);
996 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
999 pg->client_id = client_id;
1001 pg->base_value = base_value;
1002 pg->max_value = value_rate;
1003 pg->duration_period = period;
1004 pg->frequency = frequency;
1005 pg->time_start = GNUNET_TIME_absolute_get();
1008 case GNUNET_ATS_TEST_TG_CONSTANT:
1009 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1010 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1011 print_generator_type (type), pg->peer,
1012 GNUNET_ATS_print_preference_type(kind),
1015 case GNUNET_ATS_TEST_TG_LINEAR:
1016 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1017 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1018 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1019 base_value, value_rate);
1021 case GNUNET_ATS_TEST_TG_SINUS:
1022 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1023 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1024 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1025 base_value, value_rate);
1027 case GNUNET_ATS_TEST_TG_RANDOM:
1028 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1029 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1030 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1031 base_value, value_rate);
1037 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1044 * Stop all preferences generators
1047 GNUNET_ATS_solver_generate_preferences_stop_all ()
1049 struct PreferenceGenerator *cur;
1050 struct PreferenceGenerator *next;
1051 next = pref_gen_head;
1052 for (cur = next; NULL != cur; cur = next)
1055 GNUNET_ATS_solver_generate_preferences_stop(cur);
1066 print_op (enum OperationType op)
1069 case SOLVER_OP_ADD_ADDRESS:
1070 return "ADD_ADDRESS";
1071 case SOLVER_OP_DEL_ADDRESS:
1072 return "DEL_ADDRESS";
1073 case SOLVER_OP_START_SET_PREFERENCE:
1074 return "START_SET_PREFERENCE";
1075 case SOLVER_OP_STOP_SET_PREFERENCE:
1076 return "STOP_STOP_PREFERENCE";
1077 case SOLVER_OP_START_SET_PROPERTY:
1078 return "START_SET_PROPERTY";
1079 case SOLVER_OP_STOP_SET_PROPERTY:
1080 return "STOP_SET_PROPERTY";
1081 case SOLVER_OP_START_REQUEST:
1082 return "START_REQUEST";
1083 case SOLVER_OP_STOP_REQUEST:
1084 return "STOP_REQUEST";
1091 static struct Experiment *
1092 create_experiment ()
1094 struct Experiment *e;
1095 e = GNUNET_new (struct Experiment);
1098 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1103 free_experiment (struct Experiment *e)
1105 struct Episode *cur;
1106 struct Episode *next;
1107 struct GNUNET_ATS_TEST_Operation *cur_o;
1108 struct GNUNET_ATS_TEST_Operation *next_o;
1111 for (cur = next; NULL != cur; cur = next)
1116 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1118 next_o = cur_o->next;
1119 GNUNET_free_non_null (cur_o->address);
1120 GNUNET_free_non_null (cur_o->plugin);
1121 GNUNET_free (cur_o);
1126 GNUNET_free_non_null (e->name);
1127 GNUNET_free_non_null (e->log_prefix);
1128 GNUNET_free_non_null (e->log_output_dir);
1129 GNUNET_free_non_null (e->cfg_file);
1135 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1139 const struct GNUNET_CONFIGURATION_Handle *cfg)
1145 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1146 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1147 sec_name, op_name, &o->peer_id))
1149 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1150 op_counter, "ADD_ADDRESS", op_name);
1151 GNUNET_free (op_name);
1152 return GNUNET_SYSERR;
1154 GNUNET_free (op_name);
1157 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1158 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1159 sec_name, op_name, &o->address_id))
1161 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1162 op_counter, "ADD_ADDRESS", op_name);
1163 GNUNET_free (op_name);
1164 return GNUNET_SYSERR;
1166 GNUNET_free (op_name);
1169 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1170 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1171 sec_name, op_name, &o->plugin))
1173 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1174 op_counter, "ADD_ADDRESS", op_name);
1175 GNUNET_free (op_name);
1176 return GNUNET_SYSERR;
1178 GNUNET_free (op_name);
1181 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1182 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1183 sec_name, op_name, &o->address))
1185 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1186 op_counter, "ADD_ADDRESS", op_name);
1187 GNUNET_free (op_name);
1188 return GNUNET_SYSERR;
1190 GNUNET_free (op_name);
1193 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1194 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1195 sec_name, op_name, &o->address_session))
1197 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1198 op_counter, "ADD_ADDRESS", op_name);
1199 GNUNET_free (op_name);
1200 return GNUNET_SYSERR;
1202 GNUNET_free (op_name);
1205 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1206 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1207 sec_name, op_name, &op_network))
1209 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1210 op_counter, "ADD_ADDRESS", op_name);
1211 GNUNET_free (op_name);
1212 return GNUNET_SYSERR;
1216 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1217 if (0 == strcmp(op_network, "UNSPECIFIED"))
1219 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1221 else if (0 == strcmp(op_network, "LOOPBACK"))
1223 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1225 else if (0 == strcmp(op_network, "LAN"))
1227 o->address_network = GNUNET_ATS_NET_LAN;
1229 else if (0 == strcmp(op_network, "WAN"))
1231 o->address_network = GNUNET_ATS_NET_WAN;
1233 else if (0 == strcmp(op_network, "WLAN"))
1235 o->address_network = GNUNET_ATS_NET_WLAN;
1237 else if (0 == strcmp(op_network, "BT"))
1239 o->address_network = GNUNET_ATS_NET_BT;
1243 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1244 op_counter, "ADD_ADDRESS", op_name, op_network);
1245 GNUNET_free (op_network);
1246 GNUNET_free (op_name);
1247 return GNUNET_SYSERR;
1250 GNUNET_free (op_network);
1251 GNUNET_free (op_name);
1253 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1254 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1255 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1261 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1265 const struct GNUNET_CONFIGURATION_Handle *cfg)
1271 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1272 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1273 sec_name, op_name, &o->peer_id))
1275 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1276 op_counter, "DEL_ADDRESS", op_name);
1277 GNUNET_free (op_name);
1278 return GNUNET_SYSERR;
1280 GNUNET_free (op_name);
1283 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1284 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1285 sec_name, op_name, &o->address_id))
1287 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1288 op_counter, "DEL_ADDRESS", op_name);
1289 GNUNET_free (op_name);
1290 return GNUNET_SYSERR;
1292 GNUNET_free (op_name);
1296 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1297 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1298 sec_name, op_name, &o->plugin))
1300 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1301 op_counter, "DEL_ADDRESS", op_name);
1302 GNUNET_free (op_name);
1303 return GNUNET_SYSERR;
1305 GNUNET_free (op_name);
1308 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1309 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1310 sec_name, op_name, &o->address))
1312 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1313 op_counter, "DEL_ADDRESS", op_name);
1314 GNUNET_free (op_name);
1315 return GNUNET_SYSERR;
1317 GNUNET_free (op_name);
1320 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1321 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1322 sec_name, op_name, &o->address_session))
1324 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1325 op_counter, "DEL_ADDRESS", op_name);
1326 GNUNET_free (op_name);
1327 return GNUNET_SYSERR;
1329 GNUNET_free (op_name);
1332 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1333 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1334 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1339 static enum GNUNET_ATS_Property
1340 parse_preference_string (const char * str)
1343 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1345 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1346 if (0 == strcmp(str, props[c]))
1352 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1356 const struct GNUNET_CONFIGURATION_Handle *cfg)
1363 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1364 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1365 sec_name, op_name, &o->peer_id))
1367 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1368 op_counter, "START_SET_PREFERENCE", op_name);
1369 GNUNET_free (op_name);
1370 return GNUNET_SYSERR;
1372 GNUNET_free (op_name);
1375 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1376 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1377 sec_name, op_name, &o->client_id))
1379 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1380 op_counter, "START_SET_PREFERENCE", op_name);
1381 GNUNET_free (op_name);
1382 return GNUNET_SYSERR;
1384 GNUNET_free (op_name);
1387 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1388 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1389 sec_name, op_name, &type)) )
1391 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1392 op_counter, "START_SET_PREFERENCE", op_name);
1393 GNUNET_free (op_name);
1394 return GNUNET_SYSERR;
1397 /* Load arguments for set_rate, start_send, set_preference */
1398 if (0 == strcmp (type, "constant"))
1400 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1402 else if (0 == strcmp (type, "linear"))
1404 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1406 else if (0 == strcmp (type, "sinus"))
1408 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1410 else if (0 == strcmp (type, "random"))
1412 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1416 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1417 op_counter, op_name, e->id);
1419 GNUNET_free (op_name);
1420 return GNUNET_SYSERR;
1423 GNUNET_free (op_name);
1427 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1428 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1429 sec_name, op_name, &o->base_rate))
1431 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1432 op_counter, op_name, e->id);
1433 GNUNET_free (op_name);
1434 return GNUNET_SYSERR;
1436 GNUNET_free (op_name);
1440 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1441 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1442 sec_name, op_name, &o->max_rate))
1444 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1445 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1446 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1448 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1449 op_counter, op_name, e->id);
1450 GNUNET_free (op_name);
1451 return GNUNET_SYSERR;
1454 GNUNET_free (op_name);
1457 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1458 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1459 sec_name, op_name, &o->period))
1461 o->period = e->duration;
1463 GNUNET_free (op_name);
1466 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1467 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1468 sec_name, op_name, &o->frequency))
1470 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1471 op_counter, op_name, e->id);
1472 GNUNET_free (op_name);
1473 return GNUNET_SYSERR;
1475 GNUNET_free (op_name);
1477 /* Get preference */
1478 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1479 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1480 sec_name, op_name, &pref))
1482 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1483 op_counter, op_name, e->id);
1484 GNUNET_free (op_name);
1485 return GNUNET_SYSERR;
1488 if (0 == (o->pref_type = parse_preference_string(pref)))
1490 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1491 op_counter, op_name, e->id);
1492 GNUNET_free (op_name);
1494 return GNUNET_SYSERR;
1497 GNUNET_free (op_name);
1499 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1500 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1501 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1502 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1508 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1512 const struct GNUNET_CONFIGURATION_Handle *cfg)
1518 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1519 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1520 sec_name, op_name, &o->peer_id))
1522 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1523 op_counter, "STOP_SET_PREFERENCE", op_name);
1524 GNUNET_free (op_name);
1525 return GNUNET_SYSERR;
1527 GNUNET_free (op_name);
1530 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1531 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1532 sec_name, op_name, &o->address_id))
1534 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1535 op_counter, "STOP_SET_PREFERENCE", op_name);
1536 GNUNET_free (op_name);
1537 return GNUNET_SYSERR;
1539 GNUNET_free (op_name);
1541 /* Get preference */
1542 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1543 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1544 sec_name, op_name, &pref))
1546 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1547 op_counter, "STOP_SET_PREFERENCE", op_name);
1548 GNUNET_free (op_name);
1549 return GNUNET_SYSERR;
1552 if (0 == (o->pref_type = parse_preference_string(pref)))
1554 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1555 op_counter, op_name, e->id);
1556 GNUNET_free (op_name);
1558 return GNUNET_SYSERR;
1561 GNUNET_free (op_name);
1563 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1564 "Found operation %s: [%llu:%llu]: %s\n",
1565 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1566 GNUNET_ATS_print_preference_type(o->pref_type));
1570 static enum GNUNET_ATS_Property
1571 parse_property_string (const char * str)
1574 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1576 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1577 if (0 == strcmp(str, props[c]))
1583 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1587 const struct GNUNET_CONFIGURATION_Handle *cfg)
1594 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1595 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1596 sec_name, op_name, &o->peer_id))
1598 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1599 op_counter, "START_SET_PROPERTY", op_name);
1600 GNUNET_free (op_name);
1601 return GNUNET_SYSERR;
1603 GNUNET_free (op_name);
1606 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1607 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1608 sec_name, op_name, &o->address_id))
1610 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1611 op_counter, "START_SET_PROPERTY", op_name);
1612 GNUNET_free (op_name);
1613 return GNUNET_SYSERR;
1615 GNUNET_free (op_name);
1618 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1619 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1620 sec_name, op_name, &type)) )
1622 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1623 op_counter, "START_SET_PROPERTY", op_name);
1624 GNUNET_free (op_name);
1625 return GNUNET_SYSERR;
1628 /* Load arguments for set_rate, start_send, set_preference */
1629 if (0 == strcmp (type, "constant"))
1631 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1633 else if (0 == strcmp (type, "linear"))
1635 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1637 else if (0 == strcmp (type, "sinus"))
1639 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1641 else if (0 == strcmp (type, "random"))
1643 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1647 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1648 op_counter, op_name, e->id);
1650 GNUNET_free (op_name);
1651 return GNUNET_SYSERR;
1654 GNUNET_free (op_name);
1658 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1659 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1660 sec_name, op_name, &o->base_rate))
1662 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1663 op_counter, op_name, e->id);
1664 GNUNET_free (op_name);
1665 return GNUNET_SYSERR;
1667 GNUNET_free (op_name);
1671 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1672 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1673 sec_name, op_name, &o->max_rate))
1675 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1676 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1677 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1679 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1680 op_counter, op_name, e->id);
1681 GNUNET_free (op_name);
1682 return GNUNET_SYSERR;
1685 GNUNET_free (op_name);
1688 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1689 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1690 sec_name, op_name, &o->period))
1692 o->period = e->duration;
1694 GNUNET_free (op_name);
1697 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1698 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1699 sec_name, op_name, &o->frequency))
1701 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1702 op_counter, op_name, e->id);
1703 GNUNET_free (op_name);
1704 return GNUNET_SYSERR;
1706 GNUNET_free (op_name);
1708 /* Get preference */
1709 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1710 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1711 sec_name, op_name, &prop))
1713 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1714 op_counter, op_name, e->id);
1715 GNUNET_free (op_name);
1716 GNUNET_free_non_null (prop);
1717 return GNUNET_SYSERR;
1720 if (0 == (o->prop_type = parse_property_string(prop)))
1722 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1723 op_counter, op_name, e->id);
1724 GNUNET_free (op_name);
1726 return GNUNET_SYSERR;
1730 GNUNET_free (op_name);
1732 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1733 "Found operation %s: [%llu:%llu] %s = %llu\n",
1734 "START_SET_PROPERTY", o->peer_id, o->address_id,
1735 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1741 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1745 const struct GNUNET_CONFIGURATION_Handle *cfg)
1751 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1752 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1753 sec_name, op_name, &o->peer_id))
1755 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1756 op_counter, "STOP_SET_PROPERTY", op_name);
1757 GNUNET_free (op_name);
1758 return GNUNET_SYSERR;
1760 GNUNET_free (op_name);
1763 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1764 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1765 sec_name, op_name, &o->address_id))
1767 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1768 op_counter, "STOP_SET_PROPERTY", op_name);
1769 GNUNET_free (op_name);
1770 return GNUNET_SYSERR;
1772 GNUNET_free (op_name);
1775 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1776 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1777 sec_name, op_name, &pref))
1779 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1780 op_counter, "STOP_SET_PROPERTY", op_name);
1781 GNUNET_free (op_name);
1782 GNUNET_free_non_null (pref);
1783 return GNUNET_SYSERR;
1786 if (0 == (o->prop_type = parse_property_string(pref)))
1788 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1789 op_counter, op_name, e->id);
1790 GNUNET_free (op_name);
1791 GNUNET_free_non_null (pref);
1792 return GNUNET_SYSERR;
1796 GNUNET_free (op_name);
1798 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1799 "Found operation %s: [%llu:%llu] %s\n",
1800 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1801 GNUNET_ATS_print_property_type (o->prop_type));
1808 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1812 const struct GNUNET_CONFIGURATION_Handle *cfg)
1817 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1818 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1819 sec_name, op_name, &o->peer_id))
1821 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1822 op_counter, "START_REQUEST", op_name);
1823 GNUNET_free (op_name);
1824 return GNUNET_SYSERR;
1826 GNUNET_free (op_name);
1831 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1835 const struct GNUNET_CONFIGURATION_Handle *cfg)
1840 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1841 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1842 sec_name, op_name, &o->peer_id))
1844 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1845 op_counter, "STOP_REQUEST", op_name);
1846 GNUNET_free (op_name);
1847 return GNUNET_SYSERR;
1849 GNUNET_free (op_name);
1855 load_episode (struct Experiment *e, struct Episode *cur,
1856 struct GNUNET_CONFIGURATION_Handle *cfg)
1858 struct GNUNET_ATS_TEST_Operation *o;
1864 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
1865 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1869 /* Load operation */
1870 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1871 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1872 sec_name, op_name, &op))
1874 GNUNET_free (op_name);
1877 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1878 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
1881 /* operations = set_rate, start_send, stop_send, set_preference */
1882 if (0 == strcmp (op, "address_add"))
1884 o->type = SOLVER_OP_ADD_ADDRESS;
1885 res = load_op_add_address (o, cur,
1886 op_counter, sec_name, cfg);
1888 else if (0 == strcmp (op, "address_del"))
1890 o->type = SOLVER_OP_DEL_ADDRESS;
1891 res = load_op_del_address (o, cur,
1892 op_counter, sec_name, cfg);
1894 else if (0 == strcmp (op, "start_set_property"))
1896 o->type = SOLVER_OP_START_SET_PROPERTY;
1897 res = load_op_start_set_property (o, cur,
1898 op_counter, sec_name, cfg);
1900 else if (0 == strcmp (op, "stop_set_property"))
1902 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1903 res = load_op_stop_set_property (o, cur,
1904 op_counter, sec_name, cfg);
1906 else if (0 == strcmp (op, "start_set_preference"))
1908 o->type = SOLVER_OP_START_SET_PREFERENCE;
1909 res = load_op_start_set_preference (o, cur,
1910 op_counter, sec_name, cfg);
1912 else if (0 == strcmp (op, "stop_set_preference"))
1914 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1915 res = load_op_stop_set_preference (o, cur,
1916 op_counter, sec_name, cfg);
1918 else if (0 == strcmp (op, "start_request"))
1920 o->type = SOLVER_OP_START_REQUEST;
1921 res = load_op_start_request (o, cur,
1922 op_counter, sec_name, cfg);
1924 else if (0 == strcmp (op, "stop_request"))
1926 o->type = SOLVER_OP_STOP_REQUEST;
1927 res = load_op_stop_request(o, cur,
1928 op_counter, sec_name, cfg);
1932 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1933 op_counter, op, cur->id);
1934 res = GNUNET_SYSERR;
1938 GNUNET_free (op_name);
1940 if (GNUNET_SYSERR == res)
1943 GNUNET_free (sec_name);
1944 return GNUNET_SYSERR;
1947 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1950 GNUNET_free (sec_name);
1955 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1959 struct GNUNET_TIME_Relative e_duration;
1960 struct Episode *cur;
1961 struct Episode *last;
1967 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1968 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1969 sec_name, "duration", &e_duration))
1971 GNUNET_free (sec_name);
1975 cur = GNUNET_new (struct Episode);
1976 cur->duration = e_duration;
1977 cur->id = e_counter;
1979 if (GNUNET_OK != load_episode (e, cur, cfg))
1981 GNUNET_free (sec_name);
1983 return GNUNET_SYSERR;
1986 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
1988 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1990 /* Update experiment */
1992 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1993 /* Put in linked list */
1999 GNUNET_free (sec_name);
2007 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2009 struct Experiment *e = cls;
2010 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2011 fprintf (stderr, "Experiment timeout!\n");
2013 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2015 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2016 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2019 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2023 struct ATS_Address *
2024 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2025 const char *plugin_name,
2026 const void *plugin_addr,
2027 size_t plugin_addr_len,
2028 uint32_t session_id,
2031 struct ATS_Address *aa = NULL;
2033 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2034 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2035 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2036 aa->atsi[0].value = htonl (network);
2040 aa->addr_len = plugin_addr_len;
2042 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2043 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2044 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2045 aa->session_id = session_id;
2046 aa->active = GNUNET_NO;
2047 aa->used = GNUNET_NO;
2048 aa->solver_information = NULL;
2049 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
2050 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
2058 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2061 struct TestAddress *a;
2064 if (NULL == (p = find_peer_by_id (op->peer_id)))
2066 p = GNUNET_new (struct TestPeer);
2067 p->id = op->peer_id;
2068 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2069 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2071 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2072 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2075 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2078 if (NULL != (find_address_by_id (p, op->address_id)))
2080 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2081 op->address_id, op->peer_id);
2085 a = GNUNET_new (struct TestAddress);
2086 a->aid = op->address_id;
2087 a->network = op->address_network;
2088 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2089 strlen (op->address) + 1, op->address_session, op->address_network);
2090 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2091 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2093 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2094 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2096 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2097 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2099 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2100 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2102 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2108 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2111 struct TestAddress *a;
2112 struct PropertyGenerator *pg;
2114 if (NULL == (p = find_peer_by_id (op->peer_id)))
2117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2118 "Deleting address for unknown peer %u\n", op->peer_id);
2122 if (NULL == (a =find_address_by_id (p, op->address_id)))
2125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2126 "Deleting address for unknown peer %u\n", op->peer_id);
2130 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2132 GNUNET_ATS_solver_generate_property_stop (pg);
2135 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, a->ats_addr);
2137 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
2138 op->address_id, op->peer_id);
2140 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2144 GNUNET_ATS_solver_logging_now (l);
2146 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2148 GNUNET_free_non_null(a->ats_addr->atsi);
2149 GNUNET_free (a->ats_addr);
2155 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2157 struct PropertyGenerator *pg;
2159 struct TestAddress *a;
2161 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2163 GNUNET_ATS_solver_generate_property_stop (pg);
2167 if (NULL == (p = find_peer_by_id (op->peer_id)))
2170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2171 "Starting property generation for unknown peer %u\n", op->peer_id);
2175 if (NULL == (a = find_address_by_id (p, op->address_id)))
2178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2179 "Setting property for unknown address %u\n", op->peer_id);
2183 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2195 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2197 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2201 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2202 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2204 GNUNET_ATS_solver_generate_property_stop (pg);
2208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2209 "Cannot find preference generator for peer %u address %u\n",
2210 op->peer_id, op->address_id);
2216 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2218 struct PreferenceGenerator *pg;
2219 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2221 GNUNET_ATS_solver_generate_preferences_stop (pg);
2225 if (NULL == (find_peer_by_id (op->peer_id)))
2228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2229 "Starting preference generation for unknown peer %u\n", op->peer_id);
2233 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2245 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2247 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2251 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2252 "Stopping property generation for peer %u address %u\n", op->peer_id,
2254 GNUNET_ATS_solver_generate_preferences_stop (pg);
2258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2259 "Cannot find preference generator for peer %u address %u\n",
2260 op->peer_id, op->address_id);
2267 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2270 const struct ATS_Address *res;
2272 if (NULL == (p = find_peer_by_id (op->peer_id)))
2275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2276 "Requesting address for unknown peer %u\n", op->peer_id);
2280 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2283 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2286 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2288 ntohl(res->assigned_bw_in.value__),
2289 ntohl(res->assigned_bw_out.value__));
2291 GNUNET_ATS_solver_logging_now (l);
2296 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2300 if (NULL == (p = find_peer_by_id (op->peer_id)))
2303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2304 "Requesting address for unknown peer %u\n", op->peer_id);
2308 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2311 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2315 GNUNET_ATS_solver_logging_now (l);
2320 static void enforce_episode (struct Episode *ep)
2322 struct GNUNET_ATS_TEST_Operation *cur;
2323 for (cur = ep->head; NULL != cur; cur = cur->next)
2325 switch (cur->type) {
2326 case SOLVER_OP_ADD_ADDRESS:
2327 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2328 print_op (cur->type), cur->peer_id, cur->address_id);
2329 enforce_add_address (cur);
2331 case SOLVER_OP_DEL_ADDRESS:
2332 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2333 print_op (cur->type), cur->peer_id, cur->address_id);
2334 enforce_del_address (cur);
2336 case SOLVER_OP_START_SET_PROPERTY:
2337 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2338 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2339 enforce_start_property (cur);
2341 case SOLVER_OP_STOP_SET_PROPERTY:
2342 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2343 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2344 enforce_stop_property (cur);
2346 case SOLVER_OP_START_SET_PREFERENCE:
2347 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2348 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2349 enforce_start_preference (cur);
2351 case SOLVER_OP_STOP_SET_PREFERENCE:
2352 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2353 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2354 enforce_stop_preference (cur);
2356 case SOLVER_OP_START_REQUEST:
2357 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2358 print_op (cur->type), cur->peer_id);
2359 enforce_start_request (cur);
2361 case SOLVER_OP_STOP_REQUEST:
2362 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2363 print_op (cur->type), cur->peer_id);
2364 enforce_stop_request (cur);
2373 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2375 struct Experiment *e = cls;
2376 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2377 if (NULL != e->ep_done_cb)
2378 e->ep_done_cb (e->cur);
2380 /* Scheduling next */
2381 e->cur = e->cur->next;
2385 fprintf (stderr, "Last episode done!\n");
2386 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2388 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2389 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2391 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2395 fprintf (stderr, "Running episode %u with timeout %s\n",
2397 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2398 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2399 &timeout_episode, e);
2400 enforce_episode(e->cur);
2407 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2408 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2409 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2411 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2412 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2413 e->e_done_cb = e_done_cb;
2414 e->ep_done_cb = ep_done_cb;
2415 e->start_time = GNUNET_TIME_absolute_get();
2417 /* Start total time out */
2418 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2419 &timeout_experiment, e);
2422 if (NULL == e->start)
2429 fprintf (stderr, "Running episode %u with timeout %s\n",
2431 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2432 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2433 &timeout_episode, e);
2434 enforce_episode(e->cur);
2439 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2441 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2443 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2444 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2446 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2448 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2449 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2453 GNUNET_CONFIGURATION_destroy(e->cfg);
2456 free_experiment (e);
2461 GNUNET_ATS_solvers_experimentation_load (char *filename)
2463 struct Experiment *e;
2464 struct GNUNET_CONFIGURATION_Handle *cfg;
2467 cfg = GNUNET_CONFIGURATION_create();
2468 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2470 fprintf (stderr, "Failed to load `%s'\n", filename);
2471 GNUNET_CONFIGURATION_destroy (cfg);
2475 e = create_experiment ();
2477 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2480 fprintf (stderr, "Invalid %s \n", "name");
2481 free_experiment (e);
2485 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2487 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2488 "log_prefix", &e->log_prefix))
2490 fprintf (stderr, "Invalid %s \n", "log_prefix");
2491 free_experiment (e);
2495 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2498 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2499 "log_output_dir", &e->log_output_dir))
2501 e->log_output_dir = NULL;
2504 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2508 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2509 "experiment", "log_append_time_stamp")))
2510 e->log_append_time_stamp = GNUNET_YES;
2511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2512 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2515 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2516 "cfg_file", &e->cfg_file))
2518 fprintf (stderr, "Invalid %s \n", "cfg_file");
2519 free_experiment (e);
2524 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2525 e->cfg = GNUNET_CONFIGURATION_create();
2526 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2528 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2529 free_experiment (e);
2535 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2536 "log_freq", &e->log_freq))
2538 fprintf (stderr, "Invalid %s \n", "log_freq");
2539 free_experiment (e);
2543 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2544 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2546 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2547 "max_duration", &e->max_duration))
2549 fprintf (stderr, "Invalid %s", "max_duration");
2550 free_experiment (e);
2554 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2555 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2557 if (GNUNET_SYSERR == load_episodes (e, cfg))
2559 GNUNET_ATS_solvers_experimentation_stop (e);
2560 GNUNET_CONFIGURATION_destroy (cfg);
2562 fprintf (stderr, "Failed to load experiment\n");
2565 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2567 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2569 GNUNET_CONFIGURATION_destroy (cfg);
2580 free_all_it (void *cls,
2581 const struct GNUNET_PeerIdentity *key,
2584 struct ATS_Address *address = value;
2585 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2587 GNUNET_free (address);
2593 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2595 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2597 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2599 GAS_normalization_stop();
2601 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2602 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2603 GNUNET_free (sh->plugin);
2608 * Load quotas for networks from configuration
2610 * @param cfg configuration handle
2611 * @param out_dest where to write outbound quotas
2612 * @param in_dest where to write inbound quotas
2613 * @param dest_length length of inbound and outbound arrays
2614 * @return number of networks loaded
2617 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2618 unsigned long long *out_dest,
2619 unsigned long long *in_dest,
2622 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2623 char * entry_in = NULL;
2624 char * entry_out = NULL;
2625 char * quota_out_str;
2626 char * quota_in_str;
2630 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2634 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2635 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2638 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2641 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2643 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2646 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2648 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2651 if (GNUNET_NO == res)
2653 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2654 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2655 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2660 network_str[c], out_dest[c]);
2662 GNUNET_free (quota_out_str);
2666 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2667 network_str[c], GNUNET_ATS_DefaultBandwidth);
2668 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2672 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2675 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2677 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2680 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2682 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2685 if (GNUNET_NO == res)
2687 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2688 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2689 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2694 network_str[c], in_dest[c]);
2696 GNUNET_free (quota_in_str);
2700 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2701 network_str[c], GNUNET_ATS_DefaultBandwidth);
2702 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2704 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
2705 GNUNET_free (entry_out);
2706 GNUNET_free (entry_in);
2708 return GNUNET_ATS_NetworkTypeCount;
2712 * Information callback for the solver
2714 * @param cls the closure
2715 * @param op the solver operation
2716 * @param stat status of the solver operation
2717 * @param add additional solver information
2720 solver_info_cb (void *cls,
2721 enum GAS_Solver_Operation op,
2722 enum GAS_Solver_Status stat,
2723 enum GAS_Solver_Additional_Information add)
2728 add_info = "GAS_INFO_NONE";
2731 add_info = "GAS_INFO_MLP_FULL";
2733 case GAS_INFO_UPDATED:
2734 add_info = "GAS_INFO_MLP_UPDATED";
2736 case GAS_INFO_PROP_ALL:
2737 add_info = "GAS_INFO_PROP_ALL";
2739 case GAS_INFO_PROP_SINGLE:
2740 add_info = "GAS_INFO_PROP_SINGLE";
2743 add_info = "INVALID";
2749 case GAS_OP_SOLVE_START:
2750 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2751 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2752 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2754 case GAS_OP_SOLVE_STOP:
2755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2756 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2757 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2760 case GAS_OP_SOLVE_SETUP_START:
2761 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2762 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2763 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2766 case GAS_OP_SOLVE_SETUP_STOP:
2767 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2768 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2769 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2772 case GAS_OP_SOLVE_MLP_LP_START:
2773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2774 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2775 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2777 case GAS_OP_SOLVE_MLP_LP_STOP:
2778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2779 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2780 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2783 case GAS_OP_SOLVE_MLP_MLP_START:
2784 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2785 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2786 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2788 case GAS_OP_SOLVE_MLP_MLP_STOP:
2789 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2790 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2791 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2793 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2794 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2795 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2796 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2798 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2799 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2800 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2801 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2809 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2811 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2812 (0 == ntohl (address->assigned_bw_in.value__)) )
2814 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2815 "Solver notified to disconnect peer `%s'\n",
2816 GNUNET_i2s (&address->peer));
2820 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2821 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2822 GNUNET_i2s (&address->peer),
2824 (unsigned int) ntohl (address->assigned_bw_out.value__),
2825 (unsigned int) ntohl (address->assigned_bw_in.value__));
2826 /*if (GNUNET_YES == ph.bulk_running)
2829 GNUNET_ATS_solver_logging_now (l);
2835 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2838 if (GNUNET_YES == opt_disable_normalization)
2840 if (NULL == (p = find_peer_by_pid (id)))
2845 return GAS_normalization_get_preferences_by_peer (id);
2850 get_property_cb (void *cls, const struct ATS_Address *address)
2853 struct TestAddress *a;
2855 if (GNUNET_YES == opt_disable_normalization)
2857 p = find_peer_by_pid (&address->peer);
2858 a = find_address_by_ats_address (p, address);
2862 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2866 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
2869 struct TestAddress *a;
2871 if (NULL == (p = find_peer_by_pid (&address->peer)))
2877 if (NULL == (a = find_address_by_ats_address (p, address)))
2882 a->prop_norm[type] = prop_rel;
2883 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
2888 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
2889 uint32_t type, double prop_rel)
2891 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2892 "Normalized property %s for peer `%s' changed to %.3f \n",
2893 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
2896 set_updated_property (address, type, prop_rel);
2900 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
2901 enum GNUNET_ATS_PreferenceKind kind,
2906 if (NULL == (p = find_peer_by_pid (peer)))
2912 p->pref_norm[kind] = pref_rel;
2913 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
2918 normalized_preference_changed_cb (void *cls,
2919 const struct GNUNET_PeerIdentity *peer,
2920 enum GNUNET_ATS_PreferenceKind kind,
2923 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2924 "Normalized preference %s for peer `%s' changed to %.3f \n",
2925 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
2928 set_updated_preference(peer, kind, pref_rel);
2932 struct SolverHandle *
2933 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2935 struct SolverHandle *sh;
2940 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2941 solver_str = "proportional";
2943 case GNUNET_ATS_SOLVER_MLP:
2946 case GNUNET_ATS_SOLVER_RIL:
2955 sh = GNUNET_new (struct SolverHandle);
2956 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2958 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2959 /* setup environment */
2960 sh->env.cfg = e->cfg;
2961 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2962 sh->env.addresses = sh->addresses;
2963 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2964 sh->env.get_preferences = &get_preferences_cb;
2965 sh->env.get_property = &get_property_cb;
2966 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2967 sh->env.info_cb = &solver_info_cb;
2968 sh->env.info_cb_cls = NULL;
2969 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2970 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
2971 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
2972 sh->env.networks[c] = networks[c];
2975 /* start normalization */
2976 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
2977 &normalized_property_changed_cb, NULL );
2980 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2981 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2984 GNUNET_free (sh->plugin);
2990 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2991 if (NULL == sh->solver)
2993 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2995 GNUNET_free (sh->plugin);
3006 struct TestPeer *cur;
3007 struct TestPeer *next;
3009 struct TestAddress *cur_a;
3010 struct TestAddress *next_a;
3013 GNUNET_ATS_solver_logging_stop (l);
3015 /* Stop all preference generation */
3016 GNUNET_ATS_solver_generate_preferences_stop_all ();
3018 /* Stop all property generation */
3019 GNUNET_ATS_solver_generate_property_stop_all ();
3023 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3024 GNUNET_ATS_solver_logging_eval (l);
3028 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3029 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3035 GNUNET_ATS_solver_logging_free (l);
3039 /* Clean up experiment */
3042 GNUNET_ATS_solvers_experimentation_stop (e);
3047 while (NULL != (cur = next))
3050 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3051 next_a = cur->addr_head;
3052 while (NULL != (cur_a = next_a))
3054 next_a = cur_a->next;
3055 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3056 GNUNET_free (cur_a);
3062 GNUNET_ATS_solvers_solver_stop (sh);
3071 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3073 if (GNUNET_OK == success)
3074 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3075 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3077 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3079 GNUNET_SCHEDULER_add_now (&done, NULL);
3083 episode_done_cb (struct Episode *ep)
3085 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3098 GNUNET_ATS_solvers_experimentation_stop (e);
3103 GNUNET_ATS_solvers_solver_stop (sh);
3109 run (void *cls, char * const *args, const char *cfgfile,
3110 const struct GNUNET_CONFIGURATION_Handle *cfg)
3112 enum GNUNET_ATS_Solvers solver;
3115 if (NULL == opt_exp_file)
3117 fprintf (stderr, "No experiment given ...\n");
3123 if (NULL == opt_solver)
3125 fprintf (stderr, "No solver given ...\n");
3131 if (0 == strcmp(opt_solver, "mlp"))
3133 solver = GNUNET_ATS_SOLVER_MLP;
3135 else if (0 == strcmp(opt_solver, "proportional"))
3137 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3139 else if (0 == strcmp(opt_solver, "ril"))
3141 solver = GNUNET_ATS_SOLVER_RIL;
3145 fprintf (stderr, "No solver given ...");
3151 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3152 default_properties[c] = DEFAULT_REL_QUALITY;
3154 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3155 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3157 /* load experiment */
3158 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3159 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3162 fprintf (stderr, "Failed to load experiment ...\n");
3169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3170 sh = GNUNET_ATS_solvers_solver_start (solver);
3173 fprintf (stderr, "Failed to start solver ...\n");
3180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3181 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3183 /* run experiment */
3184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3185 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3186 experiment_done_cb);
3193 * Main function of the benchmark
3195 * @param argc argument count
3196 * @param argv argument values
3199 main (int argc, char *argv[])
3201 opt_exp_file = NULL;
3203 opt_log = GNUNET_NO;
3204 opt_save = GNUNET_NO;
3208 static struct GNUNET_GETOPT_CommandLineOption options[] =
3210 { 's', "solver", NULL,
3211 gettext_noop ("solver to use"),
3212 1, &GNUNET_GETOPT_set_string, &opt_solver},
3213 { 'e', "experiment", NULL,
3214 gettext_noop ("experiment to use"),
3215 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3216 { 'V', "verbose", NULL,
3217 gettext_noop ("be verbose"),
3218 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3219 { 'p', "print", NULL,
3220 gettext_noop ("print logging"),
3221 0, &GNUNET_GETOPT_set_one, &opt_print},
3222 { 'f', "file", NULL,
3223 gettext_noop ("save logging to disk"),
3224 0, &GNUNET_GETOPT_set_one, &opt_save},
3226 gettext_noop ("disable normalization"),
3227 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3228 GNUNET_GETOPT_OPTION_END
3231 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3232 NULL, options, &run, argv[0]);
3236 /* end of file ats-testing-experiment.c*/