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;
42 * cmd option -e: experiment file
44 static char *opt_exp_file;
46 static char *opt_solver;
49 * cmd option -l: enable logging
54 * cmd option -p: enable plots
59 * cmd option -v: verbose logs
61 static int opt_verbose;
69 print_generator_type (enum GeneratorType g)
72 case GNUNET_ATS_TEST_TG_CONSTANT:
74 case GNUNET_ATS_TEST_TG_LINEAR:
76 case GNUNET_ATS_TEST_TG_RANDOM:
78 case GNUNET_ATS_TEST_TG_SINUS:
91 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 struct LoggingHandle *l = cls;
95 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
97 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
99 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
103 struct LoggingHandle *
104 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
106 struct LoggingHandle *l;
107 l = GNUNET_new (struct LoggingHandle);
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
110 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
112 /* Iterate over peers */
115 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
121 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
123 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
127 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
129 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
130 GNUNET_SCHEDULER_cancel (l->logging_task);
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
134 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
138 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
144 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
146 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
147 GNUNET_SCHEDULER_cancel (l->logging_task);
148 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
153 * Property Generators
156 static struct PropertyGenerator *prop_gen_head;
157 static struct PropertyGenerator *prop_gen_tail;
160 get_property (struct PropertyGenerator *pg)
162 struct GNUNET_TIME_Relative time_delta;
166 /* Calculate the current preference value */
168 case GNUNET_ATS_TEST_TG_CONSTANT:
169 pref_value = pg->base_value;
171 case GNUNET_ATS_TEST_TG_LINEAR:
172 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
173 /* Calculate point of time in the current period */
174 time_delta.rel_value_us = time_delta.rel_value_us %
175 pg->duration_period.rel_value_us;
176 delta_value = ((double) time_delta.rel_value_us /
177 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
178 if ((pg->max_value < pg->base_value) &&
179 ((pg->max_value - pg->base_value) > pg->base_value))
181 /* This will cause an underflow */
184 pref_value = pg->base_value + delta_value;
186 case GNUNET_ATS_TEST_TG_RANDOM:
187 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
188 10000 * (pg->max_value - pg->base_value)) / 10000;
189 pref_value = pg->base_value + delta_value;
191 case GNUNET_ATS_TEST_TG_SINUS:
192 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
193 /* Calculate point of time in the current period */
194 time_delta.rel_value_us = time_delta.rel_value_us %
195 pg->duration_period.rel_value_us;
196 if ((pg->max_value - pg->base_value) > pg->base_value)
198 /* This will cause an underflow for second half of sinus period,
199 * will be detected in general when experiments are loaded */
202 delta_value = (pg->max_value - pg->base_value) *
203 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
204 time_delta.rel_value_us);
205 pref_value = pg->base_value + delta_value;
211 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
218 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
220 struct PropertyGenerator *pg = cls;
222 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
224 pref_value = get_property (pg);
226 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
227 "Setting property for peer [%u] address [%u] for %s to %f\n",
228 pg->peer, pg->address_id,
229 GNUNET_ATS_print_property_type (pg->ats_property), pref_value);
231 /* set performance here!
232 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
233 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
236 switch (pg->ats_property) {
237 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
238 //p->pref_bandwidth = pref_value;
240 case GNUNET_ATS_PREFERENCE_LATENCY:
241 //p->pref_delay = pref_value;
247 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
252 static struct PropertyGenerator *
253 find_prop_gen (unsigned int peer, unsigned int address,
254 uint32_t ats_property)
256 struct PropertyGenerator *cur;
257 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
258 if ((cur->peer == peer) && (cur->address_id == address) &&
259 (cur->ats_property == ats_property))
265 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
267 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
269 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
271 GNUNET_SCHEDULER_cancel (pg->set_task);
272 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
275 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
276 pg->peer, pg->address_id,
277 GNUNET_ATS_print_property_type(pg->ats_property));
284 * Generate between the source master and the partner and set preferences with a
285 * value depending on the generator.
288 * @param dest partner
289 * @param type type of preferences to generate
290 * @param base_rate traffic base rate to send data with
291 * @param max_rate traffic maximum rate to send data with
292 * @param period duration of a period of traffic generation (~ 1/frequency)
293 * @param duration how long to generate traffic
294 * @return the traffic generator
296 struct PropertyGenerator *
297 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
298 unsigned int address_id,
299 enum GeneratorType type,
302 struct GNUNET_TIME_Relative period,
303 struct GNUNET_TIME_Relative frequency,
304 uint32_t ats_property)
306 struct PropertyGenerator *pg;
308 pg = GNUNET_new (struct PropertyGenerator);
309 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
312 pg->address_id = address_id;
313 pg->ats_property = ats_property;
314 pg->base_value = base_value;
315 pg->max_value = value_rate;
316 pg->duration_period = period;
317 pg->frequency = frequency;
318 pg->time_start = GNUNET_TIME_absolute_get();
321 case GNUNET_ATS_TEST_TG_CONSTANT:
322 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
323 "Setting up %s property generator peer [%u] address [%u] `%s'"\
325 print_generator_type(type), pg->peer, pg->address_id,
326 GNUNET_ATS_print_property_type (ats_property),
329 case GNUNET_ATS_TEST_TG_LINEAR:
330 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
331 "Setting up %s property generator peer [%u] address [%u] `%s' " \
332 "min %u Bips max %u Bips\n",
333 print_generator_type(type), pg->peer, pg->address_id,
334 GNUNET_ATS_print_property_type(ats_property),
335 base_value, value_rate);
337 case GNUNET_ATS_TEST_TG_SINUS:
338 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
339 "Setting up %s property generator peer [%u] address [%u] `%s' "\
340 "baserate %u Bips, amplitude %u Bps\n",
341 print_generator_type(type), pg->peer, pg->address_id,
342 GNUNET_ATS_print_property_type(ats_property),
343 base_value, value_rate);
345 case GNUNET_ATS_TEST_TG_RANDOM:
346 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
347 "Setting up %s property generator peer [%u] address [%u] `%s' "\
348 "min %u Bips max %u Bps\n",
349 print_generator_type(type), pg->peer, pg->address_id,
350 GNUNET_ATS_print_property_type(ats_property),
351 base_value, value_rate);
357 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
364 * Stop all preferences generators
367 GNUNET_ATS_solver_generate_property_stop_all ()
369 struct PropertyGenerator *cur;
370 struct PropertyGenerator *next;
371 next = prop_gen_head;
372 for (cur = next; NULL != cur; cur = next)
375 GNUNET_ATS_solver_generate_property_stop (cur);
381 * Preference Generators
384 static struct PreferenceGenerator *pref_gen_head;
385 static struct PreferenceGenerator *pref_gen_tail;
388 get_preference (struct PreferenceGenerator *pg)
390 struct GNUNET_TIME_Relative time_delta;
394 /* Calculate the current preference value */
396 case GNUNET_ATS_TEST_TG_CONSTANT:
397 pref_value = pg->base_value;
399 case GNUNET_ATS_TEST_TG_LINEAR:
400 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
401 /* Calculate point of time in the current period */
402 time_delta.rel_value_us = time_delta.rel_value_us %
403 pg->duration_period.rel_value_us;
404 delta_value = ((double) time_delta.rel_value_us /
405 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
406 if ((pg->max_value < pg->base_value) &&
407 ((pg->max_value - pg->base_value) > pg->base_value))
409 /* This will cause an underflow */
412 pref_value = pg->base_value + delta_value;
414 case GNUNET_ATS_TEST_TG_RANDOM:
415 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
416 10000 * (pg->max_value - pg->base_value)) / 10000;
417 pref_value = pg->base_value + delta_value;
419 case GNUNET_ATS_TEST_TG_SINUS:
420 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
421 /* Calculate point of time in the current period */
422 time_delta.rel_value_us = time_delta.rel_value_us %
423 pg->duration_period.rel_value_us;
424 if ((pg->max_value - pg->base_value) > pg->base_value)
426 /* This will cause an underflow for second half of sinus period,
427 * will be detected in general when experiments are loaded */
430 delta_value = (pg->max_value - pg->base_value) *
431 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
432 time_delta.rel_value_us);
433 pref_value = pg->base_value + delta_value;
439 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
446 set_pref_task (void *cls,
447 const struct GNUNET_SCHEDULER_TaskContext *tc)
449 struct PreferenceGenerator *pg = cls;
451 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
453 pref_value = get_preference (pg);
455 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
456 "Setting preference for peer [%u] address [%u] for %s to %f\n",
457 pg->peer, pg->address_id,
458 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
460 /* set performance here!
461 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
462 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
466 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
467 //p->pref_bandwidth = pref_value;
469 case GNUNET_ATS_PREFERENCE_LATENCY:
470 //p->pref_delay = pref_value;
476 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
481 static struct PreferenceGenerator *
482 find_pref_gen (unsigned int peer, unsigned int address,
483 enum GNUNET_ATS_PreferenceKind kind)
485 struct PreferenceGenerator *cur;
486 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
487 if ((cur->peer == peer) && (cur->address_id == address) && (cur->kind == kind))
493 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
495 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
497 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
499 GNUNET_SCHEDULER_cancel (pg->set_task);
500 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
502 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
503 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
504 pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(pg->kind));
511 * Generate between the source master and the partner and set preferences with a
512 * value depending on the generator.
515 * @param dest partner
516 * @param type type of preferences to generate
517 * @param base_rate traffic base rate to send data with
518 * @param max_rate traffic maximum rate to send data with
519 * @param period duration of a period of traffic generation (~ 1/frequency)
520 * @param duration how long to generate traffic
521 * @return the traffic generator
523 struct PreferenceGenerator *
524 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
525 unsigned int address_id,
526 enum GeneratorType type,
529 struct GNUNET_TIME_Relative period,
530 struct GNUNET_TIME_Relative frequency,
531 enum GNUNET_ATS_PreferenceKind kind)
533 struct PreferenceGenerator *pg;
535 pg = GNUNET_new (struct PreferenceGenerator);
536 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
539 pg->address_id = address_id;
541 pg->base_value = base_value;
542 pg->max_value = value_rate;
543 pg->duration_period = period;
544 pg->frequency = frequency;
545 pg->time_start = GNUNET_TIME_absolute_get();
548 case GNUNET_ATS_TEST_TG_CONSTANT:
549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
550 "Setting up %s preference generator peer [%u] address [%u] `%s' max %u Bips\n",
551 print_generator_type (type), pg->peer, pg->address_id,
552 GNUNET_ATS_print_preference_type(kind),
555 case GNUNET_ATS_TEST_TG_LINEAR:
556 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
557 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
558 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
559 base_value, value_rate);
561 case GNUNET_ATS_TEST_TG_SINUS:
562 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
563 "Setting up %s preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
564 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
565 base_value, value_rate);
567 case GNUNET_ATS_TEST_TG_RANDOM:
568 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
569 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
570 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
571 base_value, value_rate);
577 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
584 * Stop all preferences generators
587 GNUNET_ATS_solver_generate_preferences_stop_all ()
589 struct PreferenceGenerator *cur;
590 struct PreferenceGenerator *next;
591 next = pref_gen_head;
592 for (cur = next; NULL != cur; cur = next)
595 GNUNET_ATS_solver_generate_preferences_stop(cur);
606 print_op (enum OperationType op)
609 case SOLVER_OP_ADD_ADDRESS:
610 return "ADD_ADDRESS";
611 case SOLVER_OP_DEL_ADDRESS:
612 return "DEL_ADDRESS";
613 case SOLVER_OP_START_SET_PREFERENCE:
614 return "START_SET_PREFERENCE";
615 case SOLVER_OP_STOP_SET_PREFERENCE:
616 return "STOP_STOP_PREFERENCE";
617 case SOLVER_OP_START_SET_PROPERTY:
618 return "START_SET_PROPERTY";
619 case SOLVER_OP_STOP_SET_PROPERTY:
620 return "STOP_SET_PROPERTY";
621 case SOLVER_OP_START_REQUEST:
622 return "START_REQUEST";
623 case SOLVER_OP_STOP_REQUEST:
624 return "STOP_REQUEST";
631 static struct Experiment *
634 struct Experiment *e;
635 e = GNUNET_new (struct Experiment);
640 e->total_duration = GNUNET_TIME_UNIT_ZERO;
645 free_experiment (struct Experiment *e)
648 struct Episode *next;
649 struct GNUNET_ATS_TEST_Operation *cur_o;
650 struct GNUNET_ATS_TEST_Operation *next_o;
653 for (cur = next; NULL != cur; cur = next)
658 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
660 next_o = cur_o->next;
661 GNUNET_free_non_null (cur_o->address);
662 GNUNET_free_non_null (cur_o->plugin);
668 GNUNET_free_non_null (e->name);
669 GNUNET_free_non_null (e->cfg_file);
675 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
679 const struct GNUNET_CONFIGURATION_Handle *cfg)
684 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
685 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
686 sec_name, op_name, &o->peer_id))
688 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
689 op_counter, "ADD_ADDRESS", op_name);
690 GNUNET_free (op_name);
691 return GNUNET_SYSERR;
693 GNUNET_free (op_name);
696 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
697 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
698 sec_name, op_name, &o->address_id))
700 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
701 op_counter, "ADD_ADDRESS", op_name);
702 GNUNET_free (op_name);
703 return GNUNET_SYSERR;
705 GNUNET_free (op_name);
708 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
709 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
710 sec_name, op_name, &o->plugin))
712 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
713 op_counter, "ADD_ADDRESS", op_name);
714 GNUNET_free (op_name);
715 return GNUNET_SYSERR;
717 GNUNET_free (op_name);
720 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
721 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
722 sec_name, op_name, &o->address))
724 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
725 op_counter, "ADD_ADDRESS", op_name);
726 GNUNET_free (op_name);
727 return GNUNET_SYSERR;
729 GNUNET_free (op_name);
732 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
733 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
734 sec_name, op_name, &o->address_session))
736 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
737 op_counter, "ADD_ADDRESS", op_name);
738 GNUNET_free (op_name);
739 return GNUNET_SYSERR;
741 GNUNET_free (op_name);
744 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
745 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
746 sec_name, op_name, &o->address_network))
748 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
749 op_counter, "ADD_ADDRESS", op_name);
750 GNUNET_free (op_name);
751 return GNUNET_SYSERR;
753 GNUNET_free (op_name);
756 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
757 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
763 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
767 const struct GNUNET_CONFIGURATION_Handle *cfg)
772 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
773 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
774 sec_name, op_name, &o->peer_id))
776 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
777 op_counter, "DEL_ADDRESS", op_name);
778 GNUNET_free (op_name);
779 return GNUNET_SYSERR;
781 GNUNET_free (op_name);
784 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
785 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
786 sec_name, op_name, &o->address_id))
788 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
789 op_counter, "DEL_ADDRESS", op_name);
790 GNUNET_free (op_name);
791 return GNUNET_SYSERR;
793 GNUNET_free (op_name);
796 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
797 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
798 sec_name, op_name, &o->plugin))
800 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
801 op_counter, "DEL_ADDRESS", op_name);
802 GNUNET_free (op_name);
803 return GNUNET_SYSERR;
805 GNUNET_free (op_name);
808 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
809 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
810 sec_name, op_name, &o->address))
812 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
813 op_counter, "DEL_ADDRESS", op_name);
814 GNUNET_free (op_name);
815 return GNUNET_SYSERR;
817 GNUNET_free (op_name);
820 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
821 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
822 sec_name, op_name, &o->address_session))
824 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
825 op_counter, "DEL_ADDRESS", op_name);
826 GNUNET_free (op_name);
827 return GNUNET_SYSERR;
829 GNUNET_free (op_name);
832 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
833 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
834 sec_name, op_name, &o->address_network))
836 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
837 op_counter, "DEL_ADDRESS", op_name);
838 GNUNET_free (op_name);
839 return GNUNET_SYSERR;
841 GNUNET_free (op_name);
844 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
845 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
850 static enum GNUNET_ATS_Property
851 parse_preference_string (const char * str)
854 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
856 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
857 if (0 == strcmp(str, props[c]))
863 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
867 const struct GNUNET_CONFIGURATION_Handle *cfg)
874 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
875 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
876 sec_name, op_name, &o->peer_id))
878 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
879 op_counter, "START_SET_PREFERENCE", op_name);
880 GNUNET_free (op_name);
881 return GNUNET_SYSERR;
883 GNUNET_free (op_name);
886 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
887 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
888 sec_name, op_name, &o->address_id))
890 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
891 op_counter, "START_SET_PREFERENCE", op_name);
892 GNUNET_free (op_name);
893 return GNUNET_SYSERR;
895 GNUNET_free (op_name);
898 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
899 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
900 sec_name, op_name, &type)) )
902 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
903 op_counter, "START_SET_PREFERENCE", op_name);
904 GNUNET_free (op_name);
905 return GNUNET_SYSERR;
908 /* Load arguments for set_rate, start_send, set_preference */
909 if (0 == strcmp (type, "constant"))
911 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
913 else if (0 == strcmp (type, "linear"))
915 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
917 else if (0 == strcmp (type, "sinus"))
919 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
921 else if (0 == strcmp (type, "random"))
923 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
927 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
928 op_counter, op_name, e->id);
930 GNUNET_free (op_name);
931 return GNUNET_SYSERR;
934 GNUNET_free (op_name);
938 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
939 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
940 sec_name, op_name, &o->base_rate))
942 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
943 op_counter, op_name, e->id);
944 GNUNET_free (op_name);
945 return GNUNET_SYSERR;
947 GNUNET_free (op_name);
951 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
952 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
953 sec_name, op_name, &o->max_rate))
955 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
956 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
957 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
959 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
960 op_counter, op_name, e->id);
961 GNUNET_free (op_name);
962 return GNUNET_SYSERR;
965 GNUNET_free (op_name);
968 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
969 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
970 sec_name, op_name, &o->period))
972 o->period = e->duration;
974 GNUNET_free (op_name);
977 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
978 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
979 sec_name, op_name, &o->frequency))
981 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
982 op_counter, op_name, e->id);
983 GNUNET_free (op_name);
984 return GNUNET_SYSERR;
986 GNUNET_free (op_name);
989 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
990 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
991 sec_name, op_name, &pref))
993 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
994 op_counter, op_name, e->id);
995 GNUNET_free (op_name);
996 return GNUNET_SYSERR;
999 if (0 == (o->pref_type = parse_preference_string(pref)))
1001 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1002 op_counter, op_name, e->id);
1003 GNUNET_free (op_name);
1005 return GNUNET_SYSERR;
1008 GNUNET_free (op_name);
1011 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1012 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1013 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1019 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1023 const struct GNUNET_CONFIGURATION_Handle *cfg)
1029 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1030 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1031 sec_name, op_name, &o->peer_id))
1033 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1034 op_counter, "STOP_SET_PREFERENCE", op_name);
1035 GNUNET_free (op_name);
1036 return GNUNET_SYSERR;
1038 GNUNET_free (op_name);
1041 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1042 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1043 sec_name, op_name, &o->address_id))
1045 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1046 op_counter, "STOP_SET_PREFERENCE", op_name);
1047 GNUNET_free (op_name);
1048 return GNUNET_SYSERR;
1050 GNUNET_free (op_name);
1052 /* Get preference */
1053 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1054 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1055 sec_name, op_name, &pref))
1057 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1058 op_counter, "STOP_SET_PREFERENCE", op_name);
1059 GNUNET_free (op_name);
1060 return GNUNET_SYSERR;
1063 if (0 == (o->pref_type = parse_preference_string(pref)))
1065 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1066 op_counter, op_name, e->id);
1067 GNUNET_free (op_name);
1069 return GNUNET_SYSERR;
1072 GNUNET_free (op_name);
1075 "Found operation %s: [%llu:%llu]: %s\n",
1076 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1077 GNUNET_ATS_print_preference_type(o->pref_type));
1081 static enum GNUNET_ATS_Property
1082 parse_property_string (const char * str)
1085 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1087 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1088 if (0 == strcmp(str, props[c]))
1094 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1098 const struct GNUNET_CONFIGURATION_Handle *cfg)
1105 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1106 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1107 sec_name, op_name, &o->peer_id))
1109 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1110 op_counter, "START_SET_PROPERTY", op_name);
1111 GNUNET_free (op_name);
1112 return GNUNET_SYSERR;
1114 GNUNET_free (op_name);
1117 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1118 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1119 sec_name, op_name, &o->address_id))
1121 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1122 op_counter, "START_SET_PROPERTY", op_name);
1123 GNUNET_free (op_name);
1124 return GNUNET_SYSERR;
1126 GNUNET_free (op_name);
1129 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1130 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1131 sec_name, op_name, &type)) )
1133 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1134 op_counter, "START_SET_PROPERTY", op_name);
1135 GNUNET_free (op_name);
1136 return GNUNET_SYSERR;
1139 /* Load arguments for set_rate, start_send, set_preference */
1140 if (0 == strcmp (type, "constant"))
1142 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1144 else if (0 == strcmp (type, "linear"))
1146 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1148 else if (0 == strcmp (type, "sinus"))
1150 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1152 else if (0 == strcmp (type, "random"))
1154 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1158 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1159 op_counter, op_name, e->id);
1161 GNUNET_free (op_name);
1162 return GNUNET_SYSERR;
1165 GNUNET_free (op_name);
1169 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1170 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1171 sec_name, op_name, &o->base_rate))
1173 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1174 op_counter, op_name, e->id);
1175 GNUNET_free (op_name);
1176 return GNUNET_SYSERR;
1178 GNUNET_free (op_name);
1182 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1183 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1184 sec_name, op_name, &o->max_rate))
1186 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1187 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1188 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1190 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1191 op_counter, op_name, e->id);
1192 GNUNET_free (op_name);
1193 return GNUNET_SYSERR;
1196 GNUNET_free (op_name);
1199 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1200 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1201 sec_name, op_name, &o->period))
1203 o->period = e->duration;
1205 GNUNET_free (op_name);
1208 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1209 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1210 sec_name, op_name, &o->frequency))
1212 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1213 op_counter, op_name, e->id);
1214 GNUNET_free (op_name);
1215 return GNUNET_SYSERR;
1217 GNUNET_free (op_name);
1219 /* Get preference */
1220 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1221 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1222 sec_name, op_name, &prop))
1224 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1225 op_counter, op_name, e->id);
1226 GNUNET_free (op_name);
1227 GNUNET_free_non_null (prop);
1228 return GNUNET_SYSERR;
1231 if (0 == (o->prop_type = parse_property_string(prop)))
1233 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1234 op_counter, op_name, e->id);
1235 GNUNET_free (op_name);
1237 return GNUNET_SYSERR;
1241 GNUNET_free (op_name);
1244 "Found operation %s: [%llu:%llu] %s = %llu\n",
1245 "START_SET_PROPERTY", o->peer_id, o->address_id,
1246 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1252 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1256 const struct GNUNET_CONFIGURATION_Handle *cfg)
1262 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1263 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1264 sec_name, op_name, &o->peer_id))
1266 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1267 op_counter, "STOP_SET_PROPERTY", op_name);
1268 GNUNET_free (op_name);
1269 return GNUNET_SYSERR;
1271 GNUNET_free (op_name);
1274 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1275 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1276 sec_name, op_name, &o->address_id))
1278 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1279 op_counter, "STOP_SET_PROPERTY", op_name);
1280 GNUNET_free (op_name);
1281 return GNUNET_SYSERR;
1283 GNUNET_free (op_name);
1286 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1287 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1288 sec_name, op_name, &pref))
1290 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1291 op_counter, "STOP_SET_PROPERTY", op_name);
1292 GNUNET_free (op_name);
1293 GNUNET_free_non_null (pref);
1294 return GNUNET_SYSERR;
1297 if (0 == (o->prop_type = parse_property_string(pref)))
1299 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1300 op_counter, op_name, e->id);
1301 GNUNET_free (op_name);
1303 GNUNET_free_non_null (pref);
1304 return GNUNET_SYSERR;
1308 GNUNET_free (op_name);
1311 "Found operation %s: [%llu:%llu] %s\n",
1312 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1313 GNUNET_ATS_print_property_type (o->prop_type));
1320 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1324 const struct GNUNET_CONFIGURATION_Handle *cfg)
1329 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1330 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1331 sec_name, op_name, &o->peer_id))
1333 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1334 op_counter, "START_REQUEST", op_name);
1335 GNUNET_free (op_name);
1336 return GNUNET_SYSERR;
1338 GNUNET_free (op_name);
1343 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1347 const struct GNUNET_CONFIGURATION_Handle *cfg)
1352 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1353 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1354 sec_name, op_name, &o->peer_id))
1356 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1357 op_counter, "STOP_REQUEST", op_name);
1358 GNUNET_free (op_name);
1359 return GNUNET_SYSERR;
1361 GNUNET_free (op_name);
1367 load_episode (struct Experiment *e, struct Episode *cur,
1368 struct GNUNET_CONFIGURATION_Handle *cfg)
1370 struct GNUNET_ATS_TEST_Operation *o;
1376 fprintf (stderr, "Parsing episode %u\n",cur->id);
1377 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1381 /* Load operation */
1382 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1383 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1384 sec_name, op_name, &op))
1386 GNUNET_free (op_name);
1389 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1390 /* operations = set_rate, start_send, stop_send, set_preference */
1391 if (0 == strcmp (op, "address_add"))
1393 o->type = SOLVER_OP_ADD_ADDRESS;
1394 res = load_op_add_address (o, cur,
1395 op_counter, sec_name, cfg);
1397 else if (0 == strcmp (op, "address_del"))
1399 o->type = SOLVER_OP_DEL_ADDRESS;
1400 res = load_op_del_address (o, cur,
1401 op_counter, sec_name, cfg);
1403 else if (0 == strcmp (op, "start_set_property"))
1405 o->type = SOLVER_OP_START_SET_PROPERTY;
1406 res = load_op_start_set_property (o, cur,
1407 op_counter, sec_name, cfg);
1409 else if (0 == strcmp (op, "stop_set_property"))
1411 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1412 res = load_op_stop_set_property (o, cur,
1413 op_counter, sec_name, cfg);
1415 else if (0 == strcmp (op, "start_set_preference"))
1417 o->type = SOLVER_OP_START_SET_PREFERENCE;
1418 res = load_op_start_set_preference (o, cur,
1419 op_counter, sec_name, cfg);
1422 else if (0 == strcmp (op, "stop_set_preference"))
1424 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1425 res = load_op_stop_set_preference (o, cur,
1426 op_counter, sec_name, cfg);
1428 else if (0 == strcmp (op, "start_request"))
1430 o->type = SOLVER_OP_START_REQUEST;
1431 res = load_op_start_request (o, cur,
1432 op_counter, sec_name, cfg);
1434 else if (0 == strcmp (op, "stop_request"))
1436 o->type = SOLVER_OP_STOP_REQUEST;
1437 res = load_op_stop_request(o, cur,
1438 op_counter, sec_name, cfg);
1442 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1443 op_counter, op, cur->id);
1444 res = GNUNET_SYSERR;
1448 GNUNET_free (op_name);
1450 if (GNUNET_SYSERR == res)
1453 GNUNET_free (sec_name);
1454 return GNUNET_SYSERR;
1457 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1460 GNUNET_free (sec_name);
1465 GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
1466 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1467 sec_name, op_name, &o->src_id))
1469 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
1470 op_counter, op, cur->id);
1472 GNUNET_free (op_name);
1473 return GNUNET_SYSERR;
1475 if (o->src_id > (e->num_masters - 1))
1477 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
1478 o->src_id, op_counter, op, cur->id);
1480 GNUNET_free (op_name);
1481 return GNUNET_SYSERR;
1483 GNUNET_free (op_name);
1485 /* Get destination */
1486 GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
1487 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1488 sec_name, op_name, &o->dest_id))
1490 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
1491 op_counter, op, cur->id);
1493 GNUNET_free (op_name);
1494 return GNUNET_SYSERR;
1496 if (o->dest_id > (e->num_slaves - 1))
1498 fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
1499 o->dest_id, op_counter, op, cur->id);
1501 GNUNET_free (op_name);
1502 return GNUNET_SYSERR;
1504 GNUNET_free (op_name);
1506 GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
1507 if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
1508 sec_name, op_name, &type)) &&
1509 ((STOP_SEND != o->type) || (STOP_PREFERENCE != o->type)))
1511 /* Load arguments for set_rate, start_send, set_preference */
1512 if (0 == strcmp (type, "constant"))
1514 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1516 else if (0 == strcmp (type, "linear"))
1518 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1520 else if (0 == strcmp (type, "sinus"))
1522 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1524 else if (0 == strcmp (type, "random"))
1526 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1530 fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
1531 op_counter, op, cur->id);
1534 GNUNET_free (op_name);
1535 return GNUNET_SYSERR;
1537 GNUNET_free (op_name);
1540 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1541 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1542 sec_name, op_name, &o->base_rate))
1544 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1545 op_counter, op, cur->id);
1548 GNUNET_free (op_name);
1549 return GNUNET_SYSERR;
1551 GNUNET_free (op_name);
1554 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1555 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1556 sec_name, op_name, &o->max_rate))
1558 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1559 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1560 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1562 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1563 op_counter, op, cur->id);
1565 GNUNET_free (op_name);
1567 return GNUNET_SYSERR;
1570 GNUNET_free (op_name);
1573 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1574 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1575 sec_name, op_name, &o->period))
1577 o->period = cur->duration;
1579 GNUNET_free (op_name);
1581 if (START_PREFERENCE == o->type)
1584 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1585 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1586 sec_name, op_name, &o->frequency))
1588 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1589 op_counter, op, cur->id);
1591 GNUNET_free (op_name);
1593 return GNUNET_SYSERR;
1595 GNUNET_free (op_name);
1597 /* Get preference */
1598 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1599 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1600 sec_name, op_name, &pref))
1602 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1603 op_counter, op, cur->id);
1605 GNUNET_free (op_name);
1607 GNUNET_free_non_null (pref);
1608 return GNUNET_SYSERR;
1611 if (0 == strcmp(pref, "bandwidth"))
1612 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
1613 else if (0 == strcmp(pref, "latency"))
1614 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
1617 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1618 op_counter, op, cur->id);
1620 GNUNET_free (op_name);
1623 GNUNET_free_non_null (pref);
1624 return GNUNET_SYSERR;
1627 GNUNET_free (op_name);
1632 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1633 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1635 if ((o->max_rate - o->base_rate) > o->base_rate)
1637 /* This will cause an underflow */
1640 fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
1643 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
1644 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
1645 op_counter, cur->id, print_op (o->type), o->src_id,
1646 o->dest_id, (NULL != type) ? type : "",
1647 o->base_rate, o->max_rate,
1648 GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
1650 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
1651 op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
1653 GNUNET_free_non_null (type);
1661 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1665 struct GNUNET_TIME_Relative e_duration;
1666 struct Episode *cur;
1667 struct Episode *last;
1673 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1674 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1675 sec_name, "duration", &e_duration))
1677 GNUNET_free (sec_name);
1681 cur = GNUNET_new (struct Episode);
1682 cur->duration = e_duration;
1683 cur->id = e_counter;
1685 if (GNUNET_OK != load_episode (e, cur, cfg))
1687 GNUNET_free (sec_name);
1689 return GNUNET_SYSERR;
1692 fprintf (stderr, "Found episode %u with duration %s \n",
1694 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1696 /* Update experiment */
1698 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1699 /* Put in linked list */
1705 GNUNET_free (sec_name);
1713 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1715 struct Experiment *e = cls;
1716 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1717 fprintf (stderr, "Experiment timeout!\n");
1719 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1721 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1722 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1725 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1729 static struct TestPeer *
1730 find_peer_by_id (int id)
1732 struct TestPeer *cur;
1733 for (cur = peer_head; NULL != cur; cur = cur->next)
1739 struct ATS_Address *
1740 create_ats_address (const struct GNUNET_PeerIdentity *peer,
1741 const char *plugin_name,
1742 const void *plugin_addr, size_t plugin_addr_len,
1743 uint32_t session_id)
1745 struct ATS_Address *aa = NULL;
1747 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
1749 aa->addr_len = plugin_addr_len;
1751 aa->plugin = (char *) &aa[1] + plugin_addr_len;
1752 memcpy (&aa[1], plugin_addr, plugin_addr_len);
1753 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
1754 aa->session_id = session_id;
1755 aa->active = GNUNET_NO;
1756 aa->used = GNUNET_NO;
1757 aa->solver_information = NULL;
1758 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
1759 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
1764 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1766 struct ATS_Address *addr;
1769 if (NULL == (p = find_peer_by_id (op->peer_id)))
1771 p = GNUNET_new (struct TestPeer);
1772 p->id = op->peer_id;
1773 memset (&p->peer_id, '0', sizeof (p->peer_id));
1774 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
1777 addr = create_ats_address (&p->peer_id, op->plugin, op->address,
1778 strlen (op->address) + 1, op->address_session);
1780 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, addr,
1781 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1783 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u\n",
1784 op->address_id, op->peer_id);
1786 sh->env.sf.s_add (sh->solver, addr, op->address_network);
1790 struct AddressLookupCtx
1792 struct ATS_Address *res;
1793 struct GNUNET_ATS_TEST_Operation *op;
1796 int find_address_it (void *cls,
1797 const struct GNUNET_PeerIdentity *key,
1800 struct AddressLookupCtx *ctx = cls;
1801 struct ATS_Address *addr = value;
1803 if ( (0 == strcmp (ctx->op->plugin, addr->plugin)) &&
1804 (0 == strcmp (ctx->op->address, addr->addr)) )
1813 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1816 struct AddressLookupCtx ctx;
1818 if (NULL == (p = find_peer_by_id (op->peer_id)))
1821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1822 "Deleting address for unknown peer %u\n", op->peer_id);
1828 GNUNET_CONTAINER_multipeermap_get_multiple (sh->addresses, &p->peer_id,
1829 find_address_it, &ctx);
1830 if (NULL == ctx.res)
1833 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1834 "Deleting unknown address for peer %u\n", op->peer_id);
1838 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, ctx.res);
1840 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
1841 op->address_id, op->peer_id);
1843 sh->env.sf.s_del (sh->solver, ctx.res, GNUNET_NO);
1847 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1849 struct PropertyGenerator *pg;
1850 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
1852 GNUNET_ATS_solver_generate_property_stop (pg);
1856 GNUNET_ATS_solver_generate_property_start (op->peer_id,
1867 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1869 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
1872 GNUNET_ATS_solver_generate_property_stop (pg);
1876 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1878 struct PreferenceGenerator *pg;
1879 if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type)))
1881 GNUNET_ATS_solver_generate_preferences_stop (pg);
1885 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
1896 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1898 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, op->address_id,
1901 GNUNET_ATS_solver_generate_preferences_stop (pg);
1906 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
1909 const struct ATS_Address *res;
1911 if (NULL == (p = find_peer_by_id (op->peer_id)))
1914 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1915 "Requesting address for unknown peer %u\n", op->peer_id);
1919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
1922 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
1931 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
1935 if (NULL == (p = find_peer_by_id (op->peer_id)))
1938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1939 "Requesting address for unknown peer %u\n", op->peer_id);
1943 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
1946 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
1949 static void enforce_episode (struct Episode *ep)
1951 struct GNUNET_ATS_TEST_Operation *cur;
1952 for (cur = ep->head; NULL != cur; cur = cur->next)
1954 switch (cur->type) {
1955 case SOLVER_OP_ADD_ADDRESS:
1956 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1957 print_op (cur->type), cur->peer_id, cur->address_id);
1958 enforce_add_address (cur);
1960 case SOLVER_OP_DEL_ADDRESS:
1961 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1962 print_op (cur->type), cur->peer_id, cur->address_id);
1963 enforce_del_address (cur);
1965 case SOLVER_OP_START_SET_PROPERTY:
1966 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1967 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1968 enforce_start_property (cur);
1970 case SOLVER_OP_STOP_SET_PROPERTY:
1971 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1972 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1973 enforce_stop_property (cur);
1975 case SOLVER_OP_START_SET_PREFERENCE:
1976 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1977 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1978 enforce_start_preference (cur);
1980 case SOLVER_OP_STOP_SET_PREFERENCE:
1981 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1982 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1983 enforce_stop_preference (cur);
1985 case SOLVER_OP_START_REQUEST:
1986 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1987 print_op (cur->type), cur->peer_id);
1988 enforce_start_request (cur);
1990 case SOLVER_OP_STOP_REQUEST:
1991 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1992 print_op (cur->type), cur->peer_id);
1993 enforce_stop_request (cur);
2002 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2004 struct Experiment *e = cls;
2005 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2006 if (NULL != e->ep_done_cb)
2007 e->ep_done_cb (e->cur);
2009 /* Scheduling next */
2010 e->cur = e->cur->next;
2014 fprintf (stderr, "Last episode done!\n");
2015 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2017 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2018 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2020 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2024 fprintf (stderr, "Running episode %u with timeout %s\n",
2026 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2027 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2028 &timeout_episode, e);
2029 enforce_episode(e->cur);
2036 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2037 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2038 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2040 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2041 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2042 e->e_done_cb = e_done_cb;
2043 e->ep_done_cb = ep_done_cb;
2044 e->start_time = GNUNET_TIME_absolute_get();
2046 /* Start total time out */
2047 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2048 &timeout_experiment, e);
2052 if (NULL == e->start)
2058 fprintf (stderr, "Running episode %u with timeout %s\n",
2060 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2061 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2062 &timeout_episode, e);
2063 enforce_episode(e->cur);
2068 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2070 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2072 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2073 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2075 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2077 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2078 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2082 GNUNET_CONFIGURATION_destroy(e->cfg);
2085 free_experiment (e);
2090 GNUNET_ATS_solvers_experimentation_load (char *filename)
2092 struct Experiment *e;
2093 struct GNUNET_CONFIGURATION_Handle *cfg;
2096 cfg = GNUNET_CONFIGURATION_create();
2097 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2099 fprintf (stderr, "Failed to load `%s'\n", filename);
2100 GNUNET_CONFIGURATION_destroy (cfg);
2104 e = create_experiment ();
2106 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2109 fprintf (stderr, "Invalid %s", "name");
2110 free_experiment (e);
2114 fprintf (stderr, "Experiment name: `%s'\n", e->name);
2116 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2117 "cfg_file", &e->cfg_file))
2119 fprintf (stderr, "Invalid %s", "cfg_file");
2120 free_experiment (e);
2125 fprintf (stderr, "Experiment configuration: `%s'\n", e->cfg_file);
2126 e->cfg = GNUNET_CONFIGURATION_create();
2127 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2129 fprintf (stderr, "Invalid configuration %s", "cfg_file");
2130 free_experiment (e);
2136 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2137 "masters", &e->num_masters))
2139 fprintf (stderr, "Invalid %s", "masters");
2140 free_experiment (e);
2144 fprintf (stderr, "Experiment masters: `%llu'\n",
2147 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2148 "slaves", &e->num_slaves))
2150 fprintf (stderr, "Invalid %s", "slaves");
2151 free_experiment (e);
2155 fprintf (stderr, "Experiment slaves: `%llu'\n",
2158 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2159 "log_freq", &e->log_freq))
2161 fprintf (stderr, "Invalid %s", "log_freq");
2162 free_experiment (e);
2166 fprintf (stderr, "Experiment logging frequency: `%s'\n",
2167 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2169 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2170 "max_duration", &e->max_duration))
2172 fprintf (stderr, "Invalid %s", "max_duration");
2173 free_experiment (e);
2177 fprintf (stderr, "Experiment duration: `%s'\n",
2178 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2180 if (GNUNET_SYSERR == load_episodes (e, cfg))
2182 GNUNET_ATS_solvers_experimentation_stop (e);
2183 GNUNET_CONFIGURATION_destroy (cfg);
2185 fprintf (stderr, "Failed to load experiment\n");
2188 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
2190 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2192 GNUNET_CONFIGURATION_destroy (cfg);
2201 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2203 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2205 GNUNET_CONTAINER_multipeermap_destroy(sh->env.addresses);
2206 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2207 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2208 GNUNET_free (sh->plugin);
2213 * Load quotas for networks from configuration
2215 * @param cfg configuration handle
2216 * @param out_dest where to write outbound quotas
2217 * @param in_dest where to write inbound quotas
2218 * @param dest_length length of inbound and outbound arrays
2219 * @return number of networks loaded
2222 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2223 unsigned long long *out_dest,
2224 unsigned long long *in_dest,
2227 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2228 char * entry_in = NULL;
2229 char * entry_out = NULL;
2230 char * quota_out_str;
2231 char * quota_in_str;
2235 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2239 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2240 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2243 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2246 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2248 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2251 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2253 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2256 if (GNUNET_NO == res)
2258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2259 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2260 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2265 network_str[c], out_dest[c]);
2267 GNUNET_free (quota_out_str);
2271 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2272 network_str[c], GNUNET_ATS_DefaultBandwidth);
2273 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2277 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2280 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2282 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2285 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2287 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2290 if (GNUNET_NO == res)
2292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2293 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2294 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2299 network_str[c], in_dest[c]);
2301 GNUNET_free (quota_in_str);
2305 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2306 network_str[c], GNUNET_ATS_DefaultBandwidth);
2307 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2309 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]);
2310 GNUNET_free (entry_out);
2311 GNUNET_free (entry_in);
2313 return GNUNET_ATS_NetworkTypeCount;
2317 * Information callback for the solver
2319 * @param op the solver operation
2320 * @param stat status of the solver operation
2321 * @param add additional solver information
2324 solver_info_cb (void *cls,
2325 enum GAS_Solver_Operation op,
2326 enum GAS_Solver_Status stat,
2327 enum GAS_Solver_Additional_Information add)
2332 add_info = "GAS_INFO_NONE";
2335 add_info = "GAS_INFO_MLP_FULL";
2337 case GAS_INFO_UPDATED:
2338 add_info = "GAS_INFO_MLP_UPDATED";
2340 case GAS_INFO_PROP_ALL:
2341 add_info = "GAS_INFO_PROP_ALL";
2343 case GAS_INFO_PROP_SINGLE:
2344 add_info = "GAS_INFO_PROP_SINGLE";
2347 add_info = "INVALID";
2353 case GAS_OP_SOLVE_START:
2354 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2355 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2356 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2358 case GAS_OP_SOLVE_STOP:
2359 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2360 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2361 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2364 case GAS_OP_SOLVE_SETUP_START:
2365 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2366 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2367 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2370 case GAS_OP_SOLVE_SETUP_STOP:
2371 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2372 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2373 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2376 case GAS_OP_SOLVE_MLP_LP_START:
2377 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2378 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2379 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2381 case GAS_OP_SOLVE_MLP_LP_STOP:
2382 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2383 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2384 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2387 case GAS_OP_SOLVE_MLP_MLP_START:
2388 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2389 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2390 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2392 case GAS_OP_SOLVE_MLP_MLP_STOP:
2393 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2394 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2395 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2397 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2398 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2399 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2400 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2402 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2403 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2404 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2405 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2413 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2415 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2416 (0 == ntohl (address->assigned_bw_in.value__)) )
2418 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2419 "Solver notified to disconnect peer `%s'\n",
2420 GNUNET_i2s (&address->peer));
2424 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2425 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2426 GNUNET_i2s (&address->peer),
2428 (unsigned int) ntohl (address->assigned_bw_out.value__),
2429 (unsigned int) ntohl (address->assigned_bw_in.value__));
2430 /*if (GNUNET_YES == ph.bulk_running)
2436 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2438 return GAS_normalization_get_preferences_by_peer (id);
2443 get_property_cb (void *cls, const struct ATS_Address *address)
2445 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2449 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
2450 uint32_t type, double prop_rel)
2456 struct SolverHandle *
2457 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2459 struct SolverHandle *sh;
2463 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2464 solver_str = "proportional";
2466 case GNUNET_ATS_SOLVER_MLP:
2469 case GNUNET_ATS_SOLVER_RIL:
2478 sh = GNUNET_new (struct SolverHandle);
2479 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2481 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2482 /* setup environment */
2483 sh->env.cfg = e->cfg;
2484 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2485 sh->env.addresses = sh->addresses;
2486 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2487 sh->env.get_preferences = &get_preferences_cb;
2488 sh->env.get_property = &get_property_cb;
2489 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2490 sh->env.info_cb = &solver_info_cb;
2491 sh->env.info_cb_cls = NULL;
2494 /* start normalization */
2495 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
2498 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2499 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2502 GNUNET_free (sh->plugin);
2508 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2509 if (NULL == sh->solver)
2511 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2513 GNUNET_free (sh->plugin);
2524 /* Clean up experiment */
2525 GNUNET_ATS_solver_generate_preferences_stop_all ();
2529 GNUNET_ATS_solvers_experimentation_stop (e);
2535 GNUNET_ATS_solver_logging_free (l);
2545 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
2547 if (GNUNET_OK == success)
2548 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
2549 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
2551 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
2554 GNUNET_ATS_solver_logging_stop (l);
2556 /* Stop traffic generation */
2557 // GNUNET_ATS_TEST_generate_traffic_stop_all();
2559 /* Stop all preference generations */
2560 GNUNET_ATS_solver_generate_preferences_stop_all ();
2563 evaluate (duration);
2565 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
2569 GNUNET_ATS_TEST_logging_stop (l);
2570 GNUNET_ATS_TEST_logging_clean_up (l);
2574 GNUNET_SCHEDULER_add_now (&done, NULL);
2578 episode_done_cb (struct Episode *ep)
2580 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
2593 GNUNET_ATS_solvers_experimentation_stop (e);
2598 GNUNET_ATS_solvers_solver_stop (sh);
2604 run (void *cls, char * const *args, const char *cfgfile,
2605 const struct GNUNET_CONFIGURATION_Handle *cfg)
2607 enum GNUNET_ATS_Solvers solver;
2609 if (NULL == opt_exp_file)
2611 fprintf (stderr, "No experiment given ...\n");
2617 if (NULL == opt_solver)
2619 fprintf (stderr, "No solver given ...\n");
2625 if (0 == strcmp(opt_solver, "mlp"))
2627 solver = GNUNET_ATS_SOLVER_MLP;
2629 else if (0 == strcmp(opt_solver, "proportional"))
2631 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
2633 else if (0 == strcmp(opt_solver, "ril"))
2635 solver = GNUNET_ATS_SOLVER_RIL;
2639 fprintf (stderr, "No solver given ...");
2645 /* load experiment */
2646 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
2649 fprintf (stderr, "Failed to load experiment ...\n");
2656 sh = GNUNET_ATS_solvers_solver_start (solver);
2659 fprintf (stderr, "Failed to start solver ...\n");
2666 l = GNUNET_ATS_solver_logging_start (e->log_freq);
2668 /* run experiment */
2669 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2670 experiment_done_cb);
2677 * Main function of the benchmark
2679 * @param argc argument count
2680 * @param argv argument values
2683 main (int argc, char *argv[])
2685 opt_exp_file = NULL;
2687 opt_log = GNUNET_NO;
2688 opt_plot = GNUNET_NO;
2692 static struct GNUNET_GETOPT_CommandLineOption options[] =
2694 { 's', "solver", NULL,
2695 gettext_noop ("solver to use"),
2696 1, &GNUNET_GETOPT_set_string, &opt_solver},
2697 { 'e', "experiment", NULL,
2698 gettext_noop ("experiment to use"),
2699 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2700 { 'e', "experiment", NULL,
2701 gettext_noop ("experiment to use"),
2702 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2703 GNUNET_GETOPT_OPTION_END
2706 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
2707 NULL, options, &run, argv[0]);
2711 /* end of file ats-testing-experiment.c*/