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 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1469 struct GNUNET_TIME_Relative e_duration;
1470 struct Episode *cur;
1471 struct Episode *last;
1477 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1478 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1479 sec_name, "duration", &e_duration))
1481 GNUNET_free (sec_name);
1485 cur = GNUNET_new (struct Episode);
1486 cur->duration = e_duration;
1487 cur->id = e_counter;
1489 if (GNUNET_OK != load_episode (e, cur, cfg))
1491 GNUNET_free (sec_name);
1493 return GNUNET_SYSERR;
1496 fprintf (stderr, "Found episode %u with duration %s \n",
1498 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1500 /* Update experiment */
1502 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1503 /* Put in linked list */
1509 GNUNET_free (sec_name);
1517 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1519 struct Experiment *e = cls;
1520 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1521 fprintf (stderr, "Experiment timeout!\n");
1523 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1525 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1526 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1529 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1533 static struct TestPeer *
1534 find_peer_by_id (int id)
1536 struct TestPeer *cur;
1537 for (cur = peer_head; NULL != cur; cur = cur->next)
1543 struct ATS_Address *
1544 create_ats_address (const struct GNUNET_PeerIdentity *peer,
1545 const char *plugin_name,
1546 const void *plugin_addr, size_t plugin_addr_len,
1547 uint32_t session_id)
1549 struct ATS_Address *aa = NULL;
1551 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
1553 aa->addr_len = plugin_addr_len;
1555 aa->plugin = (char *) &aa[1] + plugin_addr_len;
1556 memcpy (&aa[1], plugin_addr, plugin_addr_len);
1557 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
1558 aa->session_id = session_id;
1559 aa->active = GNUNET_NO;
1560 aa->used = GNUNET_NO;
1561 aa->solver_information = NULL;
1562 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
1563 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
1568 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1570 struct ATS_Address *addr;
1573 if (NULL == (p = find_peer_by_id (op->peer_id)))
1575 p = GNUNET_new (struct TestPeer);
1576 p->id = op->peer_id;
1577 memset (&p->peer_id, '0', sizeof (p->peer_id));
1578 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
1581 addr = create_ats_address (&p->peer_id, op->plugin, op->address,
1582 strlen (op->address) + 1, op->address_session);
1584 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, addr,
1585 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1587 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u\n",
1588 op->address_id, op->peer_id);
1590 sh->env.sf.s_add (sh->solver, addr, op->address_network);
1594 struct AddressLookupCtx
1596 struct ATS_Address *res;
1597 struct GNUNET_ATS_TEST_Operation *op;
1600 int find_address_it (void *cls,
1601 const struct GNUNET_PeerIdentity *key,
1604 struct AddressLookupCtx *ctx = cls;
1605 struct ATS_Address *addr = value;
1607 if ( (0 == strcmp (ctx->op->plugin, addr->plugin)) &&
1608 (0 == strcmp (ctx->op->address, addr->addr)) )
1617 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1620 struct AddressLookupCtx ctx;
1622 if (NULL == (p = find_peer_by_id (op->peer_id)))
1625 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1626 "Deleting address for unknown peer %u\n", op->peer_id);
1632 GNUNET_CONTAINER_multipeermap_get_multiple (sh->addresses, &p->peer_id,
1633 find_address_it, &ctx);
1634 if (NULL == ctx.res)
1637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1638 "Deleting unknown address for peer %u\n", op->peer_id);
1642 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, ctx.res);
1644 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
1645 op->address_id, op->peer_id);
1647 sh->env.sf.s_del (sh->solver, ctx.res, GNUNET_NO);
1648 GNUNET_free (ctx.res);
1653 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1655 struct PropertyGenerator *pg;
1656 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
1658 GNUNET_ATS_solver_generate_property_stop (pg);
1662 GNUNET_ATS_solver_generate_property_start (op->peer_id,
1673 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1675 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
1678 GNUNET_ATS_solver_generate_property_stop (pg);
1682 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1684 struct PreferenceGenerator *pg;
1685 if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type)))
1687 GNUNET_ATS_solver_generate_preferences_stop (pg);
1691 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
1702 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1704 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, op->address_id,
1707 GNUNET_ATS_solver_generate_preferences_stop (pg);
1712 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
1715 const struct ATS_Address *res;
1717 if (NULL == (p = find_peer_by_id (op->peer_id)))
1720 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1721 "Requesting address for unknown peer %u\n", op->peer_id);
1725 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
1728 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
1737 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
1741 if (NULL == (p = find_peer_by_id (op->peer_id)))
1744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1745 "Requesting address for unknown peer %u\n", op->peer_id);
1749 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
1752 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
1755 static void enforce_episode (struct Episode *ep)
1757 struct GNUNET_ATS_TEST_Operation *cur;
1758 for (cur = ep->head; NULL != cur; cur = cur->next)
1760 switch (cur->type) {
1761 case SOLVER_OP_ADD_ADDRESS:
1762 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1763 print_op (cur->type), cur->peer_id, cur->address_id);
1764 enforce_add_address (cur);
1766 case SOLVER_OP_DEL_ADDRESS:
1767 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1768 print_op (cur->type), cur->peer_id, cur->address_id);
1769 enforce_del_address (cur);
1771 case SOLVER_OP_START_SET_PROPERTY:
1772 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1773 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1774 enforce_start_property (cur);
1776 case SOLVER_OP_STOP_SET_PROPERTY:
1777 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1778 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1779 enforce_stop_property (cur);
1781 case SOLVER_OP_START_SET_PREFERENCE:
1782 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1783 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1784 enforce_start_preference (cur);
1786 case SOLVER_OP_STOP_SET_PREFERENCE:
1787 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1788 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1789 enforce_stop_preference (cur);
1791 case SOLVER_OP_START_REQUEST:
1792 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1793 print_op (cur->type), cur->peer_id);
1794 enforce_start_request (cur);
1796 case SOLVER_OP_STOP_REQUEST:
1797 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1798 print_op (cur->type), cur->peer_id);
1799 enforce_stop_request (cur);
1808 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1810 struct Experiment *e = cls;
1811 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1812 if (NULL != e->ep_done_cb)
1813 e->ep_done_cb (e->cur);
1815 /* Scheduling next */
1816 e->cur = e->cur->next;
1820 fprintf (stderr, "Last episode done!\n");
1821 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1823 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1824 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1826 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
1830 fprintf (stderr, "Running episode %u with timeout %s\n",
1832 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1833 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1834 &timeout_episode, e);
1835 enforce_episode(e->cur);
1842 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1843 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
1844 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
1846 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
1847 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
1848 e->e_done_cb = e_done_cb;
1849 e->ep_done_cb = ep_done_cb;
1850 e->start_time = GNUNET_TIME_absolute_get();
1852 /* Start total time out */
1853 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
1854 &timeout_experiment, e);
1858 if (NULL == e->start)
1864 fprintf (stderr, "Running episode %u with timeout %s\n",
1866 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1867 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1868 &timeout_episode, e);
1869 enforce_episode(e->cur);
1874 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1876 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1878 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1879 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1881 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1883 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1884 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1888 GNUNET_CONFIGURATION_destroy(e->cfg);
1891 free_experiment (e);
1896 GNUNET_ATS_solvers_experimentation_load (char *filename)
1898 struct Experiment *e;
1899 struct GNUNET_CONFIGURATION_Handle *cfg;
1902 cfg = GNUNET_CONFIGURATION_create();
1903 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
1905 fprintf (stderr, "Failed to load `%s'\n", filename);
1906 GNUNET_CONFIGURATION_destroy (cfg);
1910 e = create_experiment ();
1912 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
1915 fprintf (stderr, "Invalid %s", "name");
1916 free_experiment (e);
1920 fprintf (stderr, "Experiment name: `%s'\n", e->name);
1922 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
1923 "cfg_file", &e->cfg_file))
1925 fprintf (stderr, "Invalid %s", "cfg_file");
1926 free_experiment (e);
1931 fprintf (stderr, "Experiment configuration: `%s'\n", e->cfg_file);
1932 e->cfg = GNUNET_CONFIGURATION_create();
1933 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
1935 fprintf (stderr, "Invalid configuration %s", "cfg_file");
1936 free_experiment (e);
1942 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
1943 "masters", &e->num_masters))
1945 fprintf (stderr, "Invalid %s", "masters");
1946 free_experiment (e);
1950 fprintf (stderr, "Experiment masters: `%llu'\n",
1953 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
1954 "slaves", &e->num_slaves))
1956 fprintf (stderr, "Invalid %s", "slaves");
1957 free_experiment (e);
1961 fprintf (stderr, "Experiment slaves: `%llu'\n",
1964 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
1965 "log_freq", &e->log_freq))
1967 fprintf (stderr, "Invalid %s", "log_freq");
1968 free_experiment (e);
1972 fprintf (stderr, "Experiment logging frequency: `%s'\n",
1973 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
1975 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
1976 "max_duration", &e->max_duration))
1978 fprintf (stderr, "Invalid %s", "max_duration");
1979 free_experiment (e);
1983 fprintf (stderr, "Experiment duration: `%s'\n",
1984 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
1986 if (GNUNET_SYSERR == load_episodes (e, cfg))
1988 GNUNET_ATS_solvers_experimentation_stop (e);
1989 GNUNET_CONFIGURATION_destroy (cfg);
1991 fprintf (stderr, "Failed to load experiment\n");
1994 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
1996 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
1998 GNUNET_CONFIGURATION_destroy (cfg);
2007 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2009 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2011 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2012 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2013 GNUNET_free (sh->plugin);
2018 * Load quotas for networks from configuration
2020 * @param cfg configuration handle
2021 * @param out_dest where to write outbound quotas
2022 * @param in_dest where to write inbound quotas
2023 * @param dest_length length of inbound and outbound arrays
2024 * @return number of networks loaded
2027 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2028 unsigned long long *out_dest,
2029 unsigned long long *in_dest,
2032 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2033 char * entry_in = NULL;
2034 char * entry_out = NULL;
2035 char * quota_out_str;
2036 char * quota_in_str;
2040 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2044 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2045 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2048 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2051 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2053 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2056 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2058 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2061 if (GNUNET_NO == res)
2063 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2064 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2065 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2070 network_str[c], out_dest[c]);
2072 GNUNET_free (quota_out_str);
2076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2077 network_str[c], GNUNET_ATS_DefaultBandwidth);
2078 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2082 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2085 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2087 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2090 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2092 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2095 if (GNUNET_NO == res)
2097 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2098 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2099 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2104 network_str[c], in_dest[c]);
2106 GNUNET_free (quota_in_str);
2110 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2111 network_str[c], GNUNET_ATS_DefaultBandwidth);
2112 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2114 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]);
2115 GNUNET_free (entry_out);
2116 GNUNET_free (entry_in);
2118 return GNUNET_ATS_NetworkTypeCount;
2122 * Information callback for the solver
2124 * @param op the solver operation
2125 * @param stat status of the solver operation
2126 * @param add additional solver information
2129 solver_info_cb (void *cls,
2130 enum GAS_Solver_Operation op,
2131 enum GAS_Solver_Status stat,
2132 enum GAS_Solver_Additional_Information add)
2137 add_info = "GAS_INFO_NONE";
2140 add_info = "GAS_INFO_MLP_FULL";
2142 case GAS_INFO_UPDATED:
2143 add_info = "GAS_INFO_MLP_UPDATED";
2145 case GAS_INFO_PROP_ALL:
2146 add_info = "GAS_INFO_PROP_ALL";
2148 case GAS_INFO_PROP_SINGLE:
2149 add_info = "GAS_INFO_PROP_SINGLE";
2152 add_info = "INVALID";
2158 case GAS_OP_SOLVE_START:
2159 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2160 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2161 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2163 case GAS_OP_SOLVE_STOP:
2164 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2165 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2166 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2169 case GAS_OP_SOLVE_SETUP_START:
2170 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2171 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2172 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2175 case GAS_OP_SOLVE_SETUP_STOP:
2176 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2177 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2178 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2181 case GAS_OP_SOLVE_MLP_LP_START:
2182 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2183 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2184 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2186 case GAS_OP_SOLVE_MLP_LP_STOP:
2187 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2188 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2189 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2192 case GAS_OP_SOLVE_MLP_MLP_START:
2193 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2194 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2195 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2197 case GAS_OP_SOLVE_MLP_MLP_STOP:
2198 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2199 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2200 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2202 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2203 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2204 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2205 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2207 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2208 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2209 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2210 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2218 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2220 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2221 (0 == ntohl (address->assigned_bw_in.value__)) )
2223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2224 "Solver notified to disconnect peer `%s'\n",
2225 GNUNET_i2s (&address->peer));
2229 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2230 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2231 GNUNET_i2s (&address->peer),
2233 (unsigned int) ntohl (address->assigned_bw_out.value__),
2234 (unsigned int) ntohl (address->assigned_bw_in.value__));
2235 /*if (GNUNET_YES == ph.bulk_running)
2241 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2243 return GAS_normalization_get_preferences_by_peer (id);
2248 get_property_cb (void *cls, const struct ATS_Address *address)
2250 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2254 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
2255 uint32_t type, double prop_rel)
2261 struct SolverHandle *
2262 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2264 struct SolverHandle *sh;
2268 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2269 solver_str = "proportional";
2271 case GNUNET_ATS_SOLVER_MLP:
2274 case GNUNET_ATS_SOLVER_RIL:
2283 sh = GNUNET_new (struct SolverHandle);
2284 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2286 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2287 /* setup environment */
2288 sh->env.cfg = e->cfg;
2289 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2290 sh->env.addresses = sh->addresses;
2291 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2292 sh->env.get_preferences = &get_preferences_cb;
2293 sh->env.get_property = &get_property_cb;
2294 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2295 sh->env.info_cb = &solver_info_cb;
2296 sh->env.info_cb_cls = NULL;
2299 /* start normalization */
2300 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
2303 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2304 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2307 GNUNET_free (sh->plugin);
2313 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2314 if (NULL == sh->solver)
2316 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2318 GNUNET_free (sh->plugin);
2327 free_all_it (void *cls,
2328 const struct GNUNET_PeerIdentity *key,
2331 struct ATS_Address *address = value;
2332 GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses, key, value);
2333 GNUNET_free (address);
2341 struct TestPeer *cur;
2342 struct TestPeer *next;
2343 /* Clean up experiment */
2344 GNUNET_ATS_solver_generate_preferences_stop_all ();
2345 GNUNET_ATS_solver_generate_property_stop_all ();
2349 GNUNET_ATS_solvers_experimentation_stop (e);
2355 GNUNET_ATS_solver_logging_free (l);
2360 while (NULL != (cur = next))
2363 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
2365 GNUNET_CONTAINER_multipeermap_iterate (sh->env.addresses, &free_all_it, NULL);
2375 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
2377 if (GNUNET_OK == success)
2378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
2379 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
2381 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
2384 GNUNET_ATS_solver_logging_stop (l);
2386 /* Stop traffic generation */
2387 // GNUNET_ATS_TEST_generate_traffic_stop_all();
2389 /* Stop all preference generations */
2390 GNUNET_ATS_solver_generate_preferences_stop_all ();
2393 evaluate (duration);
2395 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
2399 GNUNET_ATS_TEST_logging_stop (l);
2400 GNUNET_ATS_TEST_logging_clean_up (l);
2404 GNUNET_SCHEDULER_add_now (&done, NULL);
2408 episode_done_cb (struct Episode *ep)
2410 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
2423 GNUNET_ATS_solvers_experimentation_stop (e);
2428 GNUNET_ATS_solvers_solver_stop (sh);
2434 run (void *cls, char * const *args, const char *cfgfile,
2435 const struct GNUNET_CONFIGURATION_Handle *cfg)
2437 enum GNUNET_ATS_Solvers solver;
2439 if (NULL == opt_exp_file)
2441 fprintf (stderr, "No experiment given ...\n");
2447 if (NULL == opt_solver)
2449 fprintf (stderr, "No solver given ...\n");
2455 if (0 == strcmp(opt_solver, "mlp"))
2457 solver = GNUNET_ATS_SOLVER_MLP;
2459 else if (0 == strcmp(opt_solver, "proportional"))
2461 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
2463 else if (0 == strcmp(opt_solver, "ril"))
2465 solver = GNUNET_ATS_SOLVER_RIL;
2469 fprintf (stderr, "No solver given ...");
2475 /* load experiment */
2476 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
2479 fprintf (stderr, "Failed to load experiment ...\n");
2486 sh = GNUNET_ATS_solvers_solver_start (solver);
2489 fprintf (stderr, "Failed to start solver ...\n");
2496 l = GNUNET_ATS_solver_logging_start (e->log_freq);
2498 /* run experiment */
2499 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2500 experiment_done_cb);
2507 * Main function of the benchmark
2509 * @param argc argument count
2510 * @param argv argument values
2513 main (int argc, char *argv[])
2515 opt_exp_file = NULL;
2517 opt_log = GNUNET_NO;
2518 opt_plot = GNUNET_NO;
2522 static struct GNUNET_GETOPT_CommandLineOption options[] =
2524 { 's', "solver", NULL,
2525 gettext_noop ("solver to use"),
2526 1, &GNUNET_GETOPT_set_string, &opt_solver},
2527 { 'e', "experiment", NULL,
2528 gettext_noop ("experiment to use"),
2529 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2530 { 'e', "experiment", NULL,
2531 gettext_noop ("experiment to use"),
2532 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2533 GNUNET_GETOPT_OPTION_END
2536 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
2537 NULL, options, &run, argv[0]);
2541 /* end of file ats-testing-experiment.c*/