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"
31 #define BIG_M_STRING "unlimited"
33 static struct Experiment *e;
35 static struct LoggingHandle *l;
37 static struct GNUNET_ATS_TESTING_SolverHandle *sh;
40 * cmd option -e: experiment file
42 static char *opt_exp_file;
44 static char *opt_solver;
47 * cmd option -l: enable logging
52 * cmd option -p: enable plots
57 * cmd option -v: verbose logs
59 static int opt_verbose;
67 print_generator_type (enum GeneratorType g)
70 case GNUNET_ATS_TEST_TG_CONSTANT:
72 case GNUNET_ATS_TEST_TG_LINEAR:
74 case GNUNET_ATS_TEST_TG_RANDOM:
76 case GNUNET_ATS_TEST_TG_SINUS:
89 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 struct LoggingHandle *l = cls;
93 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
95 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
97 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
101 struct LoggingHandle *
102 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
104 struct LoggingHandle *l;
105 l = GNUNET_new (struct LoggingHandle);
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
108 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
110 /* Iterate over peers */
113 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
119 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
121 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
125 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
127 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
128 GNUNET_SCHEDULER_cancel (l->logging_task);
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
132 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
136 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
142 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
144 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
145 GNUNET_SCHEDULER_cancel (l->logging_task);
146 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
151 * Property Generators
154 static struct PropertyGenerator *prop_gen_head;
155 static struct PropertyGenerator *prop_gen_tail;
158 get_property (struct PropertyGenerator *pg)
160 struct GNUNET_TIME_Relative time_delta;
164 /* Calculate the current preference value */
166 case GNUNET_ATS_TEST_TG_CONSTANT:
167 pref_value = pg->base_value;
169 case GNUNET_ATS_TEST_TG_LINEAR:
170 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
171 /* Calculate point of time in the current period */
172 time_delta.rel_value_us = time_delta.rel_value_us %
173 pg->duration_period.rel_value_us;
174 delta_value = ((double) time_delta.rel_value_us /
175 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
176 if ((pg->max_value < pg->base_value) &&
177 ((pg->max_value - pg->base_value) > pg->base_value))
179 /* This will cause an underflow */
182 pref_value = pg->base_value + delta_value;
184 case GNUNET_ATS_TEST_TG_RANDOM:
185 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
186 10000 * (pg->max_value - pg->base_value)) / 10000;
187 pref_value = pg->base_value + delta_value;
189 case GNUNET_ATS_TEST_TG_SINUS:
190 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
191 /* Calculate point of time in the current period */
192 time_delta.rel_value_us = time_delta.rel_value_us %
193 pg->duration_period.rel_value_us;
194 if ((pg->max_value - pg->base_value) > pg->base_value)
196 /* This will cause an underflow for second half of sinus period,
197 * will be detected in general when experiments are loaded */
200 delta_value = (pg->max_value - pg->base_value) *
201 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
202 time_delta.rel_value_us);
203 pref_value = pg->base_value + delta_value;
209 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
216 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
218 struct PropertyGenerator *pg = cls;
220 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
222 pref_value = get_property (pg);
224 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
225 "Setting property for peer [%u] address [%u] for %s to %f\n",
226 pg->peer, pg->address_id,
227 GNUNET_ATS_print_property_type (pg->ats_property), pref_value);
229 /* set performance here!
230 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
231 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
234 switch (pg->ats_property) {
235 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
236 //p->pref_bandwidth = pref_value;
238 case GNUNET_ATS_PREFERENCE_LATENCY:
239 //p->pref_delay = pref_value;
245 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
250 static struct PropertyGenerator *
251 find_prop_gen (unsigned int peer, unsigned int address,
252 uint32_t ats_property)
254 struct PropertyGenerator *cur;
255 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
256 if ((cur->peer == peer) && (cur->address_id == address) &&
257 (cur->ats_property == ats_property))
263 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
265 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
267 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
269 GNUNET_SCHEDULER_cancel (pg->set_task);
270 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
273 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
274 pg->peer, pg->address_id,
275 GNUNET_ATS_print_property_type(pg->ats_property));
282 * Generate between the source master and the partner and set preferences with a
283 * value depending on the generator.
286 * @param dest partner
287 * @param type type of preferences to generate
288 * @param base_rate traffic base rate to send data with
289 * @param max_rate traffic maximum rate to send data with
290 * @param period duration of a period of traffic generation (~ 1/frequency)
291 * @param duration how long to generate traffic
292 * @return the traffic generator
294 struct PropertyGenerator *
295 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
296 unsigned int address_id,
297 enum GeneratorType type,
300 struct GNUNET_TIME_Relative period,
301 struct GNUNET_TIME_Relative frequency,
302 uint32_t ats_property)
304 struct PropertyGenerator *pg;
306 pg = GNUNET_new (struct PropertyGenerator);
307 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
310 pg->address_id = address_id;
311 pg->ats_property = ats_property;
312 pg->base_value = base_value;
313 pg->max_value = value_rate;
314 pg->duration_period = period;
315 pg->frequency = frequency;
316 pg->time_start = GNUNET_TIME_absolute_get();
319 case GNUNET_ATS_TEST_TG_CONSTANT:
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
321 "Setting up %s property generator peer [%u] address [%u] `%s'"\
323 print_generator_type(type), pg->peer, pg->address_id,
324 GNUNET_ATS_print_property_type (ats_property),
327 case GNUNET_ATS_TEST_TG_LINEAR:
328 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
329 "Setting up %s property generator peer [%u] address [%u] `%s' " \
330 "min %u Bips max %u Bips\n",
331 print_generator_type(type), pg->peer, pg->address_id,
332 GNUNET_ATS_print_property_type(ats_property),
333 base_value, value_rate);
335 case GNUNET_ATS_TEST_TG_SINUS:
336 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
337 "Setting up %s property generator peer [%u] address [%u] `%s' "\
338 "baserate %u Bips, amplitude %u Bps\n",
339 print_generator_type(type), pg->peer, pg->address_id,
340 GNUNET_ATS_print_property_type(ats_property),
341 base_value, value_rate);
343 case GNUNET_ATS_TEST_TG_RANDOM:
344 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
345 "Setting up %s property generator peer [%u] address [%u] `%s' "\
346 "min %u Bips max %u Bps\n",
347 print_generator_type(type), pg->peer, pg->address_id,
348 GNUNET_ATS_print_property_type(ats_property),
349 base_value, value_rate);
355 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
362 * Stop all preferences generators
365 GNUNET_ATS_solver_generate_property_stop_all ()
367 struct PropertyGenerator *cur;
368 struct PropertyGenerator *next;
369 next = prop_gen_head;
370 for (cur = next; NULL != cur; cur = next)
373 GNUNET_ATS_solver_generate_property_stop (cur);
379 * Preference Generators
382 static struct PreferenceGenerator *pref_gen_head;
383 static struct PreferenceGenerator *pref_gen_tail;
386 get_preference (struct PreferenceGenerator *pg)
388 struct GNUNET_TIME_Relative time_delta;
392 /* Calculate the current preference value */
394 case GNUNET_ATS_TEST_TG_CONSTANT:
395 pref_value = pg->base_value;
397 case GNUNET_ATS_TEST_TG_LINEAR:
398 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
399 /* Calculate point of time in the current period */
400 time_delta.rel_value_us = time_delta.rel_value_us %
401 pg->duration_period.rel_value_us;
402 delta_value = ((double) time_delta.rel_value_us /
403 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
404 if ((pg->max_value < pg->base_value) &&
405 ((pg->max_value - pg->base_value) > pg->base_value))
407 /* This will cause an underflow */
410 pref_value = pg->base_value + delta_value;
412 case GNUNET_ATS_TEST_TG_RANDOM:
413 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
414 10000 * (pg->max_value - pg->base_value)) / 10000;
415 pref_value = pg->base_value + delta_value;
417 case GNUNET_ATS_TEST_TG_SINUS:
418 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
419 /* Calculate point of time in the current period */
420 time_delta.rel_value_us = time_delta.rel_value_us %
421 pg->duration_period.rel_value_us;
422 if ((pg->max_value - pg->base_value) > pg->base_value)
424 /* This will cause an underflow for second half of sinus period,
425 * will be detected in general when experiments are loaded */
428 delta_value = (pg->max_value - pg->base_value) *
429 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
430 time_delta.rel_value_us);
431 pref_value = pg->base_value + delta_value;
437 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
444 set_pref_task (void *cls,
445 const struct GNUNET_SCHEDULER_TaskContext *tc)
447 struct PreferenceGenerator *pg = cls;
449 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
451 pref_value = get_preference (pg);
453 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
454 "Setting preference for peer [%u] address [%u] for %s to %f\n",
455 pg->peer, pg->address_id,
456 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
458 /* set performance here!
459 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
460 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
464 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
465 //p->pref_bandwidth = pref_value;
467 case GNUNET_ATS_PREFERENCE_LATENCY:
468 //p->pref_delay = pref_value;
474 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
479 static struct PreferenceGenerator *
480 find_pref_gen (unsigned int peer, unsigned int address,
481 enum GNUNET_ATS_PreferenceKind kind)
483 struct PreferenceGenerator *cur;
484 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
485 if ((cur->peer == peer) && (cur->address_id == address) && (cur->kind == kind))
491 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
493 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
495 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
497 GNUNET_SCHEDULER_cancel (pg->set_task);
498 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
500 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
501 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
502 pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(pg->kind));
509 * Generate between the source master and the partner and set preferences with a
510 * value depending on the generator.
513 * @param dest partner
514 * @param type type of preferences to generate
515 * @param base_rate traffic base rate to send data with
516 * @param max_rate traffic maximum rate to send data with
517 * @param period duration of a period of traffic generation (~ 1/frequency)
518 * @param duration how long to generate traffic
519 * @return the traffic generator
521 struct PreferenceGenerator *
522 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
523 unsigned int address_id,
524 enum GeneratorType type,
527 struct GNUNET_TIME_Relative period,
528 struct GNUNET_TIME_Relative frequency,
529 enum GNUNET_ATS_PreferenceKind kind)
531 struct PreferenceGenerator *pg;
533 pg = GNUNET_new (struct PreferenceGenerator);
534 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
537 pg->address_id = address_id;
539 pg->base_value = base_value;
540 pg->max_value = value_rate;
541 pg->duration_period = period;
542 pg->frequency = frequency;
543 pg->time_start = GNUNET_TIME_absolute_get();
546 case GNUNET_ATS_TEST_TG_CONSTANT:
547 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
548 "Setting up %s preference generator peer [%u] address [%u] `%s' max %u Bips\n",
549 print_generator_type (type), pg->peer, pg->address_id,
550 GNUNET_ATS_print_preference_type(kind),
553 case GNUNET_ATS_TEST_TG_LINEAR:
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
556 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
557 base_value, value_rate);
559 case GNUNET_ATS_TEST_TG_SINUS:
560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
561 "Setting up %s preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
562 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
563 base_value, value_rate);
565 case GNUNET_ATS_TEST_TG_RANDOM:
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
568 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
569 base_value, value_rate);
575 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
582 * Stop all preferences generators
585 GNUNET_ATS_solver_generate_preferences_stop_all ()
587 struct PreferenceGenerator *cur;
588 struct PreferenceGenerator *next;
589 next = pref_gen_head;
590 for (cur = next; NULL != cur; cur = next)
593 GNUNET_ATS_solver_generate_preferences_stop(cur);
604 print_op (enum OperationType op)
607 case SOLVER_OP_ADD_ADDRESS:
608 return "ADD_ADDRESS";
609 case SOLVER_OP_DEL_ADDRESS:
610 return "DEL_ADDRESS";
611 case SOLVER_OP_START_SET_PREFERENCE:
612 return "START_SET_PREFERENCE";
613 case SOLVER_OP_STOP_SET_PREFERENCE:
614 return "STOP_STOP_PREFERENCE";
615 case SOLVER_OP_START_SET_PROPERTY:
616 return "START_SET_PROPERTY";
617 case SOLVER_OP_STOP_SET_PROPERTY:
618 return "STOP_SET_PROPERTY";
619 case SOLVER_OP_START_REQUEST:
620 return "START_REQUEST";
621 case SOLVER_OP_STOP_REQUEST:
622 return "STOP_REQUEST";
629 static struct Experiment *
632 struct Experiment *e;
633 e = GNUNET_new (struct Experiment);
638 e->total_duration = GNUNET_TIME_UNIT_ZERO;
643 free_experiment (struct Experiment *e)
646 struct Episode *next;
647 struct GNUNET_ATS_TEST_Operation *cur_o;
648 struct GNUNET_ATS_TEST_Operation *next_o;
651 for (cur = next; NULL != cur; cur = next)
656 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
658 next_o = cur_o->next;
659 GNUNET_free_non_null (cur_o->address);
660 GNUNET_free_non_null (cur_o->plugin);
666 GNUNET_free_non_null (e->name);
667 GNUNET_free_non_null (e->cfg_file);
673 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
677 const struct GNUNET_CONFIGURATION_Handle *cfg)
682 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
683 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
684 sec_name, op_name, &o->peer_id))
686 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
687 op_counter, "ADD_ADDRESS", op_name);
688 GNUNET_free (op_name);
689 return GNUNET_SYSERR;
691 GNUNET_free (op_name);
694 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
695 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
696 sec_name, op_name, &o->address_id))
698 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
699 op_counter, "ADD_ADDRESS", op_name);
700 GNUNET_free (op_name);
701 return GNUNET_SYSERR;
703 GNUNET_free (op_name);
706 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
707 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
708 sec_name, op_name, &o->plugin))
710 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
711 op_counter, "ADD_ADDRESS", op_name);
712 GNUNET_free (op_name);
713 return GNUNET_SYSERR;
715 GNUNET_free (op_name);
718 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
719 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
720 sec_name, op_name, &o->address))
722 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
723 op_counter, "ADD_ADDRESS", op_name);
724 GNUNET_free (op_name);
725 return GNUNET_SYSERR;
727 GNUNET_free (op_name);
730 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
731 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
732 sec_name, op_name, &o->address_session))
734 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
735 op_counter, "ADD_ADDRESS", op_name);
736 GNUNET_free (op_name);
737 return GNUNET_SYSERR;
739 GNUNET_free (op_name);
742 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
743 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
744 sec_name, op_name, &o->address_network))
746 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
747 op_counter, "ADD_ADDRESS", op_name);
748 GNUNET_free (op_name);
749 return GNUNET_SYSERR;
751 GNUNET_free (op_name);
754 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
755 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
761 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
765 const struct GNUNET_CONFIGURATION_Handle *cfg)
770 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
771 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
772 sec_name, op_name, &o->peer_id))
774 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
775 op_counter, "DEL_ADDRESS", op_name);
776 GNUNET_free (op_name);
777 return GNUNET_SYSERR;
779 GNUNET_free (op_name);
782 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
783 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
784 sec_name, op_name, &o->address_id))
786 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
787 op_counter, "DEL_ADDRESS", op_name);
788 GNUNET_free (op_name);
789 return GNUNET_SYSERR;
791 GNUNET_free (op_name);
794 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
795 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
796 sec_name, op_name, &o->plugin))
798 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
799 op_counter, "DEL_ADDRESS", op_name);
800 GNUNET_free (op_name);
801 return GNUNET_SYSERR;
803 GNUNET_free (op_name);
806 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
807 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
808 sec_name, op_name, &o->address))
810 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
811 op_counter, "DEL_ADDRESS", op_name);
812 GNUNET_free (op_name);
813 return GNUNET_SYSERR;
815 GNUNET_free (op_name);
818 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
819 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
820 sec_name, op_name, &o->address_session))
822 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
823 op_counter, "DEL_ADDRESS", op_name);
824 GNUNET_free (op_name);
825 return GNUNET_SYSERR;
827 GNUNET_free (op_name);
830 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
831 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
832 sec_name, op_name, &o->address_network))
834 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
835 op_counter, "DEL_ADDRESS", op_name);
836 GNUNET_free (op_name);
837 return GNUNET_SYSERR;
839 GNUNET_free (op_name);
842 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
843 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
848 static enum GNUNET_ATS_Property
849 parse_preference_string (const char * str)
852 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
854 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
855 if (0 == strcmp(str, props[c]))
861 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
865 const struct GNUNET_CONFIGURATION_Handle *cfg)
872 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
873 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
874 sec_name, op_name, &o->peer_id))
876 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
877 op_counter, "START_SET_PREFERENCE", op_name);
878 GNUNET_free (op_name);
879 return GNUNET_SYSERR;
881 GNUNET_free (op_name);
884 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
885 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
886 sec_name, op_name, &o->address_id))
888 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
889 op_counter, "START_SET_PREFERENCE", op_name);
890 GNUNET_free (op_name);
891 return GNUNET_SYSERR;
893 GNUNET_free (op_name);
896 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
897 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
898 sec_name, op_name, &type)) )
900 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
901 op_counter, "START_SET_PREFERENCE", op_name);
902 GNUNET_free (op_name);
903 return GNUNET_SYSERR;
906 /* Load arguments for set_rate, start_send, set_preference */
907 if (0 == strcmp (type, "constant"))
909 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
911 else if (0 == strcmp (type, "linear"))
913 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
915 else if (0 == strcmp (type, "sinus"))
917 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
919 else if (0 == strcmp (type, "random"))
921 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
925 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
926 op_counter, op_name, e->id);
928 GNUNET_free (op_name);
929 return GNUNET_SYSERR;
932 GNUNET_free (op_name);
936 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
937 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
938 sec_name, op_name, &o->base_rate))
940 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
941 op_counter, op_name, e->id);
942 GNUNET_free (op_name);
943 return GNUNET_SYSERR;
945 GNUNET_free (op_name);
949 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
950 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
951 sec_name, op_name, &o->max_rate))
953 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
954 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
955 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
957 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
958 op_counter, op_name, e->id);
959 GNUNET_free (op_name);
960 return GNUNET_SYSERR;
963 GNUNET_free (op_name);
966 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
967 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
968 sec_name, op_name, &o->period))
970 o->period = e->duration;
972 GNUNET_free (op_name);
975 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
976 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
977 sec_name, op_name, &o->frequency))
979 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
980 op_counter, op_name, e->id);
981 GNUNET_free (op_name);
982 return GNUNET_SYSERR;
984 GNUNET_free (op_name);
987 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
988 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
989 sec_name, op_name, &pref))
991 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
992 op_counter, op_name, e->id);
993 GNUNET_free (op_name);
994 return GNUNET_SYSERR;
997 if (0 == (o->pref_type = parse_preference_string(pref)))
999 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1000 op_counter, op_name, e->id);
1001 GNUNET_free (op_name);
1003 return GNUNET_SYSERR;
1006 GNUNET_free (op_name);
1009 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1010 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1011 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1017 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1021 const struct GNUNET_CONFIGURATION_Handle *cfg)
1027 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1028 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1029 sec_name, op_name, &o->peer_id))
1031 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1032 op_counter, "STOP_SET_PREFERENCE", op_name);
1033 GNUNET_free (op_name);
1034 return GNUNET_SYSERR;
1036 GNUNET_free (op_name);
1039 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1040 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1041 sec_name, op_name, &o->address_id))
1043 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1044 op_counter, "STOP_SET_PREFERENCE", op_name);
1045 GNUNET_free (op_name);
1046 return GNUNET_SYSERR;
1048 GNUNET_free (op_name);
1050 /* Get preference */
1051 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1052 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1053 sec_name, op_name, &pref))
1055 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1056 op_counter, "STOP_SET_PREFERENCE", op_name);
1057 GNUNET_free (op_name);
1058 return GNUNET_SYSERR;
1061 if (0 == (o->pref_type = parse_preference_string(pref)))
1063 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1064 op_counter, op_name, e->id);
1065 GNUNET_free (op_name);
1067 return GNUNET_SYSERR;
1070 GNUNET_free (op_name);
1073 "Found operation %s: [%llu:%llu]: %s\n",
1074 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1075 GNUNET_ATS_print_preference_type(o->pref_type));
1079 static enum GNUNET_ATS_Property
1080 parse_property_string (const char * str)
1083 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1085 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1086 if (0 == strcmp(str, props[c]))
1092 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1096 const struct GNUNET_CONFIGURATION_Handle *cfg)
1103 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1104 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1105 sec_name, op_name, &o->peer_id))
1107 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1108 op_counter, "START_SET_PROPERTY", op_name);
1109 GNUNET_free (op_name);
1110 return GNUNET_SYSERR;
1112 GNUNET_free (op_name);
1115 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1116 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1117 sec_name, op_name, &o->address_id))
1119 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1120 op_counter, "START_SET_PROPERTY", op_name);
1121 GNUNET_free (op_name);
1122 return GNUNET_SYSERR;
1124 GNUNET_free (op_name);
1127 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1128 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1129 sec_name, op_name, &type)) )
1131 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1132 op_counter, "START_SET_PROPERTY", op_name);
1133 GNUNET_free (op_name);
1134 return GNUNET_SYSERR;
1137 /* Load arguments for set_rate, start_send, set_preference */
1138 if (0 == strcmp (type, "constant"))
1140 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1142 else if (0 == strcmp (type, "linear"))
1144 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1146 else if (0 == strcmp (type, "sinus"))
1148 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1150 else if (0 == strcmp (type, "random"))
1152 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1156 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1157 op_counter, op_name, e->id);
1159 GNUNET_free (op_name);
1160 return GNUNET_SYSERR;
1163 GNUNET_free (op_name);
1167 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1168 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1169 sec_name, op_name, &o->base_rate))
1171 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1172 op_counter, op_name, e->id);
1173 GNUNET_free (op_name);
1174 return GNUNET_SYSERR;
1176 GNUNET_free (op_name);
1180 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1181 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1182 sec_name, op_name, &o->max_rate))
1184 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1185 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1186 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1188 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1189 op_counter, op_name, e->id);
1190 GNUNET_free (op_name);
1191 return GNUNET_SYSERR;
1194 GNUNET_free (op_name);
1197 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1198 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1199 sec_name, op_name, &o->period))
1201 o->period = e->duration;
1203 GNUNET_free (op_name);
1206 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1207 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1208 sec_name, op_name, &o->frequency))
1210 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1211 op_counter, op_name, e->id);
1212 GNUNET_free (op_name);
1213 return GNUNET_SYSERR;
1215 GNUNET_free (op_name);
1217 /* Get preference */
1218 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1219 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1220 sec_name, op_name, &prop))
1222 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1223 op_counter, op_name, e->id);
1224 GNUNET_free (op_name);
1225 GNUNET_free_non_null (prop);
1226 return GNUNET_SYSERR;
1229 if (0 == (o->prop_type = parse_property_string(prop)))
1231 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1232 op_counter, op_name, e->id);
1233 GNUNET_free (op_name);
1235 return GNUNET_SYSERR;
1239 GNUNET_free (op_name);
1242 "Found operation %s: [%llu:%llu] %s = %llu\n",
1243 "START_SET_PROPERTY", o->peer_id, o->address_id,
1244 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1250 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1254 const struct GNUNET_CONFIGURATION_Handle *cfg)
1260 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1261 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1262 sec_name, op_name, &o->peer_id))
1264 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1265 op_counter, "STOP_SET_PROPERTY", op_name);
1266 GNUNET_free (op_name);
1267 return GNUNET_SYSERR;
1269 GNUNET_free (op_name);
1272 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1273 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1274 sec_name, op_name, &o->address_id))
1276 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1277 op_counter, "STOP_SET_PROPERTY", op_name);
1278 GNUNET_free (op_name);
1279 return GNUNET_SYSERR;
1281 GNUNET_free (op_name);
1284 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1285 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1286 sec_name, op_name, &pref))
1288 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1289 op_counter, "STOP_SET_PROPERTY", op_name);
1290 GNUNET_free (op_name);
1291 GNUNET_free_non_null (pref);
1292 return GNUNET_SYSERR;
1295 if (0 == (o->prop_type = parse_property_string(pref)))
1297 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1298 op_counter, op_name, e->id);
1299 GNUNET_free (op_name);
1301 GNUNET_free_non_null (pref);
1302 return GNUNET_SYSERR;
1306 GNUNET_free (op_name);
1309 "Found operation %s: [%llu:%llu] %s\n",
1310 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1311 GNUNET_ATS_print_property_type (o->prop_type));
1318 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1322 const struct GNUNET_CONFIGURATION_Handle *cfg)
1327 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1328 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1329 sec_name, op_name, &o->peer_id))
1331 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1332 op_counter, "START_REQUEST", op_name);
1333 GNUNET_free (op_name);
1334 return GNUNET_SYSERR;
1336 GNUNET_free (op_name);
1341 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1345 const struct GNUNET_CONFIGURATION_Handle *cfg)
1350 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1351 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1352 sec_name, op_name, &o->peer_id))
1354 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1355 op_counter, "STOP_REQUEST", op_name);
1356 GNUNET_free (op_name);
1357 return GNUNET_SYSERR;
1359 GNUNET_free (op_name);
1365 load_episode (struct Experiment *e, struct Episode *cur,
1366 struct GNUNET_CONFIGURATION_Handle *cfg)
1368 struct GNUNET_ATS_TEST_Operation *o;
1374 fprintf (stderr, "Parsing episode %u\n",cur->id);
1375 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1379 /* Load operation */
1380 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1381 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1382 sec_name, op_name, &op))
1384 GNUNET_free (op_name);
1387 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1388 /* operations = set_rate, start_send, stop_send, set_preference */
1389 if (0 == strcmp (op, "address_add"))
1391 o->type = SOLVER_OP_ADD_ADDRESS;
1392 res = load_op_add_address (o, cur,
1393 op_counter, sec_name, cfg);
1395 else if (0 == strcmp (op, "address_del"))
1397 o->type = SOLVER_OP_DEL_ADDRESS;
1398 res = load_op_del_address (o, cur,
1399 op_counter, sec_name, cfg);
1401 else if (0 == strcmp (op, "start_set_property"))
1403 o->type = SOLVER_OP_START_SET_PROPERTY;
1404 res = load_op_start_set_property (o, cur,
1405 op_counter, sec_name, cfg);
1407 else if (0 == strcmp (op, "stop_set_property"))
1409 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1410 res = load_op_stop_set_property (o, cur,
1411 op_counter, sec_name, cfg);
1413 else if (0 == strcmp (op, "start_set_preference"))
1415 o->type = SOLVER_OP_START_SET_PREFERENCE;
1416 res = load_op_start_set_preference (o, cur,
1417 op_counter, sec_name, cfg);
1420 else if (0 == strcmp (op, "stop_set_preference"))
1422 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1423 res = load_op_stop_set_preference (o, cur,
1424 op_counter, sec_name, cfg);
1426 else if (0 == strcmp (op, "start_request"))
1428 o->type = SOLVER_OP_START_REQUEST;
1429 res = load_op_start_request (o, cur,
1430 op_counter, sec_name, cfg);
1432 else if (0 == strcmp (op, "stop_request"))
1434 o->type = SOLVER_OP_STOP_REQUEST;
1435 res = load_op_stop_request(o, cur,
1436 op_counter, sec_name, cfg);
1440 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1441 op_counter, op, cur->id);
1442 res = GNUNET_SYSERR;
1446 GNUNET_free (op_name);
1448 if (GNUNET_SYSERR == res)
1451 GNUNET_free (sec_name);
1452 return GNUNET_SYSERR;
1455 GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
1458 GNUNET_free (sec_name);
1463 GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
1464 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1465 sec_name, op_name, &o->src_id))
1467 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
1468 op_counter, op, cur->id);
1470 GNUNET_free (op_name);
1471 return GNUNET_SYSERR;
1473 if (o->src_id > (e->num_masters - 1))
1475 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
1476 o->src_id, op_counter, op, cur->id);
1478 GNUNET_free (op_name);
1479 return GNUNET_SYSERR;
1481 GNUNET_free (op_name);
1483 /* Get destination */
1484 GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
1485 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1486 sec_name, op_name, &o->dest_id))
1488 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
1489 op_counter, op, cur->id);
1491 GNUNET_free (op_name);
1492 return GNUNET_SYSERR;
1494 if (o->dest_id > (e->num_slaves - 1))
1496 fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
1497 o->dest_id, op_counter, op, cur->id);
1499 GNUNET_free (op_name);
1500 return GNUNET_SYSERR;
1502 GNUNET_free (op_name);
1504 GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
1505 if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
1506 sec_name, op_name, &type)) &&
1507 ((STOP_SEND != o->type) || (STOP_PREFERENCE != o->type)))
1509 /* Load arguments for set_rate, start_send, set_preference */
1510 if (0 == strcmp (type, "constant"))
1512 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1514 else if (0 == strcmp (type, "linear"))
1516 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1518 else if (0 == strcmp (type, "sinus"))
1520 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1522 else if (0 == strcmp (type, "random"))
1524 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1528 fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
1529 op_counter, op, cur->id);
1532 GNUNET_free (op_name);
1533 return GNUNET_SYSERR;
1535 GNUNET_free (op_name);
1538 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1539 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1540 sec_name, op_name, &o->base_rate))
1542 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1543 op_counter, op, cur->id);
1546 GNUNET_free (op_name);
1547 return GNUNET_SYSERR;
1549 GNUNET_free (op_name);
1552 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1553 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1554 sec_name, op_name, &o->max_rate))
1556 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1557 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1558 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1560 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1561 op_counter, op, cur->id);
1563 GNUNET_free (op_name);
1565 return GNUNET_SYSERR;
1568 GNUNET_free (op_name);
1571 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1572 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1573 sec_name, op_name, &o->period))
1575 o->period = cur->duration;
1577 GNUNET_free (op_name);
1579 if (START_PREFERENCE == o->type)
1582 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1583 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1584 sec_name, op_name, &o->frequency))
1586 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1587 op_counter, op, cur->id);
1589 GNUNET_free (op_name);
1591 return GNUNET_SYSERR;
1593 GNUNET_free (op_name);
1595 /* Get preference */
1596 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1597 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1598 sec_name, op_name, &pref))
1600 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1601 op_counter, op, cur->id);
1603 GNUNET_free (op_name);
1605 GNUNET_free_non_null (pref);
1606 return GNUNET_SYSERR;
1609 if (0 == strcmp(pref, "bandwidth"))
1610 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
1611 else if (0 == strcmp(pref, "latency"))
1612 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
1615 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1616 op_counter, op, cur->id);
1618 GNUNET_free (op_name);
1621 GNUNET_free_non_null (pref);
1622 return GNUNET_SYSERR;
1625 GNUNET_free (op_name);
1630 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1631 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1633 if ((o->max_rate - o->base_rate) > o->base_rate)
1635 /* This will cause an underflow */
1638 fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
1641 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
1642 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
1643 op_counter, cur->id, print_op (o->type), o->src_id,
1644 o->dest_id, (NULL != type) ? type : "",
1645 o->base_rate, o->max_rate,
1646 GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
1648 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
1649 op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
1651 GNUNET_free_non_null (type);
1659 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1663 struct GNUNET_TIME_Relative e_duration;
1664 struct Episode *cur;
1665 struct Episode *last;
1671 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1672 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1673 sec_name, "duration", &e_duration))
1675 GNUNET_free (sec_name);
1679 cur = GNUNET_new (struct Episode);
1680 cur->duration = e_duration;
1681 cur->id = e_counter;
1683 if (GNUNET_OK != load_episode (e, cur, cfg))
1685 GNUNET_free (sec_name);
1687 return GNUNET_SYSERR;
1690 fprintf (stderr, "Found episode %u with duration %s \n",
1692 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1694 /* Update experiment */
1696 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1697 /* Put in linked list */
1703 GNUNET_free (sec_name);
1711 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1713 struct Experiment *e = cls;
1714 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1715 fprintf (stderr, "Experiment timeout!\n");
1717 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1719 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1720 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1723 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1728 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1731 struct BenchmarkPeer *peer;
1732 struct BenchmarkPartner *partner;
1734 peer = GNUNET_ATS_TEST_get_peer (op->src_id);
1741 partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1742 if (NULL == partner)
1748 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1750 if (NULL != partner->tg)
1752 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
1753 GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
1757 partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
1758 op->tg_type, op->base_rate, op->max_rate, op->period,
1759 GNUNET_TIME_UNIT_FOREVER_REL);
1764 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1767 struct BenchmarkPartner *p;
1768 p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1775 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1779 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
1780 op->src_id, op->dest_id);
1781 GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
1788 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1790 struct PropertyGenerator *pg;
1791 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
1793 GNUNET_ATS_solver_generate_property_stop (pg);
1797 GNUNET_ATS_solver_generate_property_start (op->peer_id,
1808 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1810 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
1813 GNUNET_ATS_solver_generate_property_stop (pg);
1817 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1819 struct PreferenceGenerator *pg;
1820 if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type)))
1822 GNUNET_ATS_solver_generate_preferences_stop (pg);
1826 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
1837 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1839 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, op->address_id,
1842 GNUNET_ATS_solver_generate_preferences_stop (pg);
1847 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
1849 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
1854 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
1856 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
1860 static void enforce_episode (struct Episode *ep)
1862 struct GNUNET_ATS_TEST_Operation *cur;
1863 for (cur = ep->head; NULL != cur; cur = cur->next)
1865 switch (cur->type) {
1866 case SOLVER_OP_ADD_ADDRESS:
1867 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1868 print_op (cur->type), cur->peer_id, cur->address_id);
1869 enforce_add_address (cur);
1871 case SOLVER_OP_DEL_ADDRESS:
1872 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1873 print_op (cur->type), cur->peer_id, cur->address_id);
1874 enforce_del_address (cur);
1876 case SOLVER_OP_START_SET_PROPERTY:
1877 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1878 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1879 enforce_start_property (cur);
1881 case SOLVER_OP_STOP_SET_PROPERTY:
1882 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1883 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1884 enforce_stop_property (cur);
1886 case SOLVER_OP_START_SET_PREFERENCE:
1887 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1888 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1889 enforce_start_preference (cur);
1891 case SOLVER_OP_STOP_SET_PREFERENCE:
1892 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1893 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1894 enforce_stop_preference (cur);
1896 case SOLVER_OP_START_REQUEST:
1897 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1898 print_op (cur->type), cur->peer_id);
1899 enforce_start_request (cur);
1901 case SOLVER_OP_STOP_REQUEST:
1902 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1903 print_op (cur->type), cur->peer_id);
1904 enforce_stop_request (cur);
1913 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1915 struct Experiment *e = cls;
1916 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1917 if (NULL != e->ep_done_cb)
1918 e->ep_done_cb (e->cur);
1920 /* Scheduling next */
1921 e->cur = e->cur->next;
1925 fprintf (stderr, "Last episode done!\n");
1926 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1928 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1929 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1931 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
1935 fprintf (stderr, "Running episode %u with timeout %s\n",
1937 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1938 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1939 &timeout_episode, e);
1940 enforce_episode(e->cur);
1947 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1948 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
1949 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
1951 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
1952 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
1953 e->e_done_cb = e_done_cb;
1954 e->ep_done_cb = ep_done_cb;
1955 e->start_time = GNUNET_TIME_absolute_get();
1957 /* Start total time out */
1958 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
1959 &timeout_experiment, e);
1963 if (NULL == e->start)
1969 fprintf (stderr, "Running episode %u with timeout %s\n",
1971 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1972 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1973 &timeout_episode, e);
1974 enforce_episode(e->cur);
1979 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1981 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1983 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1984 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1986 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1988 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1989 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1993 GNUNET_CONFIGURATION_destroy(e->cfg);
1996 free_experiment (e);
2001 GNUNET_ATS_solvers_experimentation_load (char *filename)
2003 struct Experiment *e;
2004 struct GNUNET_CONFIGURATION_Handle *cfg;
2007 cfg = GNUNET_CONFIGURATION_create();
2008 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2010 fprintf (stderr, "Failed to load `%s'\n", filename);
2011 GNUNET_CONFIGURATION_destroy (cfg);
2015 e = create_experiment ();
2017 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2020 fprintf (stderr, "Invalid %s", "name");
2021 free_experiment (e);
2025 fprintf (stderr, "Experiment name: `%s'\n", e->name);
2027 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2028 "cfg_file", &e->cfg_file))
2030 fprintf (stderr, "Invalid %s", "cfg_file");
2031 free_experiment (e);
2036 fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
2037 e->cfg = GNUNET_CONFIGURATION_create();
2038 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2040 fprintf (stderr, "Invalid configuration %s", "cfg_file");
2041 free_experiment (e);
2047 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2048 "masters", &e->num_masters))
2050 fprintf (stderr, "Invalid %s", "masters");
2051 free_experiment (e);
2055 fprintf (stderr, "Experiment masters: `%llu'\n",
2058 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2059 "slaves", &e->num_slaves))
2061 fprintf (stderr, "Invalid %s", "slaves");
2062 free_experiment (e);
2066 fprintf (stderr, "Experiment slaves: `%llu'\n",
2069 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2070 "log_freq", &e->log_freq))
2072 fprintf (stderr, "Invalid %s", "log_freq");
2073 free_experiment (e);
2077 fprintf (stderr, "Experiment logging frequency: `%s'\n",
2078 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2080 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2081 "max_duration", &e->max_duration))
2083 fprintf (stderr, "Invalid %s", "max_duration");
2084 free_experiment (e);
2088 fprintf (stderr, "Experiment duration: `%s'\n",
2089 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2091 if (GNUNET_SYSERR == load_episodes (e, cfg))
2093 GNUNET_ATS_solvers_experimentation_stop (e);
2094 GNUNET_CONFIGURATION_destroy (cfg);
2096 fprintf (stderr, "Failed to load experiment\n");
2099 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
2101 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2103 GNUNET_CONFIGURATION_destroy (cfg);
2111 struct GNUNET_ATS_TESTING_SolverHandle
2114 struct GNUNET_ATS_PluginEnvironment env;
2116 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
2119 enum GNUNET_ATS_Solvers
2121 GNUNET_ATS_SOLVER_PROPORTIONAL,
2122 GNUNET_ATS_SOLVER_MLP,
2123 GNUNET_ATS_SOLVER_RIL,
2128 GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
2130 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2132 GNUNET_CONTAINER_multipeermap_destroy(sh->env.addresses);
2133 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2134 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2135 GNUNET_free (sh->plugin);
2140 * Load quotas for networks from configuration
2142 * @param cfg configuration handle
2143 * @param out_dest where to write outbound quotas
2144 * @param in_dest where to write inbound quotas
2145 * @param dest_length length of inbound and outbound arrays
2146 * @return number of networks loaded
2149 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2150 unsigned long long *out_dest,
2151 unsigned long long *in_dest,
2154 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2155 char * entry_in = NULL;
2156 char * entry_out = NULL;
2157 char * quota_out_str;
2158 char * quota_in_str;
2162 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2166 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2167 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2170 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2173 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2175 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2178 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2180 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2183 if (GNUNET_NO == res)
2185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2186 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2187 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2192 network_str[c], out_dest[c]);
2194 GNUNET_free (quota_out_str);
2198 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2199 network_str[c], GNUNET_ATS_DefaultBandwidth);
2200 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2204 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2207 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2209 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2212 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2214 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2217 if (GNUNET_NO == res)
2219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2220 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2221 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2226 network_str[c], in_dest[c]);
2228 GNUNET_free (quota_in_str);
2232 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2233 network_str[c], GNUNET_ATS_DefaultBandwidth);
2234 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
2237 GNUNET_free (entry_out);
2238 GNUNET_free (entry_in);
2240 return GNUNET_ATS_NetworkTypeCount;
2244 * Information callback for the solver
2246 * @param op the solver operation
2247 * @param stat status of the solver operation
2248 * @param add additional solver information
2251 solver_info_cb (void *cls,
2252 enum GAS_Solver_Operation op,
2253 enum GAS_Solver_Status stat,
2254 enum GAS_Solver_Additional_Information add)
2259 add_info = "GAS_INFO_NONE";
2262 add_info = "GAS_INFO_MLP_FULL";
2264 case GAS_INFO_UPDATED:
2265 add_info = "GAS_INFO_MLP_UPDATED";
2267 case GAS_INFO_PROP_ALL:
2268 add_info = "GAS_INFO_PROP_ALL";
2270 case GAS_INFO_PROP_SINGLE:
2271 add_info = "GAS_INFO_PROP_SINGLE";
2274 add_info = "INVALID";
2280 case GAS_OP_SOLVE_START:
2281 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2282 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2283 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2285 case GAS_OP_SOLVE_STOP:
2286 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2287 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2288 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2291 case GAS_OP_SOLVE_SETUP_START:
2292 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2293 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2294 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2297 case GAS_OP_SOLVE_SETUP_STOP:
2298 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2299 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2300 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2303 case GAS_OP_SOLVE_MLP_LP_START:
2304 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2305 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2306 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2308 case GAS_OP_SOLVE_MLP_LP_STOP:
2309 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2310 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2311 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2314 case GAS_OP_SOLVE_MLP_MLP_START:
2315 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2316 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2317 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2319 case GAS_OP_SOLVE_MLP_MLP_STOP:
2320 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2321 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2322 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2324 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2325 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2326 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2327 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2329 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2330 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2331 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2332 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2340 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2342 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2343 (0 == ntohl (address->assigned_bw_in.value__)) )
2346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2347 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2348 GNUNET_i2s (&address->peer),
2350 (unsigned int) ntohl (address->assigned_bw_out.value__),
2351 (unsigned int) ntohl (address->assigned_bw_in.value__));
2352 /*if (GNUNET_YES == ph.bulk_running)
2358 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2360 return GAS_normalization_get_preferences_by_peer (id);
2365 get_property_cb (void *cls, const struct ATS_Address *address)
2367 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2371 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
2372 uint32_t type, double prop_rel)
2378 struct GNUNET_ATS_TESTING_SolverHandle *
2379 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2381 struct GNUNET_ATS_TESTING_SolverHandle *sh;
2383 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
2384 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
2387 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2388 solver_str = "proportional";
2390 case GNUNET_ATS_SOLVER_MLP:
2393 case GNUNET_ATS_SOLVER_RIL:
2402 sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
2403 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2405 /* setup environment */
2406 sh->env.cfg = e->cfg;
2407 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2408 sh->env.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2409 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2410 sh->env.get_preferences = &get_preferences_cb;
2411 sh->env.get_property = &get_property_cb;
2412 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2413 sh->env.info_cb = &solver_info_cb;
2414 sh->env.info_cb_cls = NULL;
2416 /* start normalization */
2417 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
2420 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2421 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
2424 GNUNET_free (sh->plugin);
2430 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2431 if (NULL == sh->solver)
2433 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2435 GNUNET_free (sh->plugin);
2441 sh->addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
2449 /* Clean up experiment */
2450 GNUNET_ATS_solver_generate_preferences_stop_all ();
2454 GNUNET_ATS_solvers_experimentation_stop (e);
2460 GNUNET_ATS_solver_logging_free (l);
2470 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
2472 if (GNUNET_OK == success)
2473 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
2474 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
2476 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
2479 GNUNET_ATS_solver_logging_stop (l);
2481 /* Stop traffic generation */
2482 // GNUNET_ATS_TEST_generate_traffic_stop_all();
2484 /* Stop all preference generations */
2485 GNUNET_ATS_solver_generate_preferences_stop_all ();
2488 evaluate (duration);
2490 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
2494 GNUNET_ATS_TEST_logging_stop (l);
2495 GNUNET_ATS_TEST_logging_clean_up (l);
2499 GNUNET_SCHEDULER_add_now (&done, NULL);
2503 episode_done_cb (struct Episode *ep)
2505 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
2518 GNUNET_ATS_solvers_experimentation_stop (e);
2523 GNUNET_ATS_solvers_solver_stop (sh);
2529 run (void *cls, char * const *args, const char *cfgfile,
2530 const struct GNUNET_CONFIGURATION_Handle *cfg)
2532 enum GNUNET_ATS_Solvers solver;
2534 if (NULL == opt_exp_file)
2536 fprintf (stderr, "No experiment given ...\n");
2542 if (NULL == opt_solver)
2544 fprintf (stderr, "No solver given ...\n");
2550 if (0 == strcmp(opt_solver, "mlp"))
2552 solver = GNUNET_ATS_SOLVER_MLP;
2554 else if (0 == strcmp(opt_solver, "proportional"))
2556 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
2558 else if (0 == strcmp(opt_solver, "ril"))
2560 solver = GNUNET_ATS_SOLVER_RIL;
2564 fprintf (stderr, "No solver given ...");
2570 /* load experiment */
2571 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
2574 fprintf (stderr, "Failed to load experiment ...\n");
2581 sh = GNUNET_ATS_solvers_solver_start (solver);
2584 fprintf (stderr, "Failed to start solver ...\n");
2591 l = GNUNET_ATS_solver_logging_start (e->log_freq);
2593 /* run experiment */
2594 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2595 experiment_done_cb);
2602 * Main function of the benchmark
2604 * @param argc argument count
2605 * @param argv argument values
2608 main (int argc, char *argv[])
2610 opt_exp_file = NULL;
2612 opt_log = GNUNET_NO;
2613 opt_plot = GNUNET_NO;
2617 static struct GNUNET_GETOPT_CommandLineOption options[] =
2619 { 's', "solver", NULL,
2620 gettext_noop ("solver to use"),
2621 1, &GNUNET_GETOPT_set_string, &opt_solver},
2622 { 'e', "experiment", NULL,
2623 gettext_noop ("experiment to use"),
2624 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2625 { 'e', "experiment", NULL,
2626 gettext_noop ("experiment to use"),
2627 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2628 GNUNET_GETOPT_OPTION_END
2631 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
2632 NULL, options, &run, argv[0]);
2636 /* end of file ats-testing-experiment.c*/