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:
86 struct AddressLookupCtx
88 struct ATS_Address *res;
94 int find_address_it (void *cls,
95 const struct GNUNET_PeerIdentity *key,
98 struct AddressLookupCtx *ctx = cls;
99 struct ATS_Address *addr = value;
101 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
102 (0 == strcmp (ctx->addr, addr->addr)) )
110 static struct TestPeer *
111 find_peer_by_id (int id)
113 struct TestPeer *cur;
114 for (cur = peer_head; NULL != cur; cur = cur->next)
120 static struct TestAddress *
121 find_address_by_id (struct TestPeer *peer, int aid)
123 struct TestAddress *cur;
124 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
137 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
139 struct LoggingHandle *l = cls;
141 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
145 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
149 struct LoggingHandle *
150 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
152 struct LoggingHandle *l;
153 l = GNUNET_new (struct LoggingHandle);
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
156 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
158 /* Iterate over peers */
161 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
167 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
173 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
175 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
176 GNUNET_SCHEDULER_cancel (l->logging_task);
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
180 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
184 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
190 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
192 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
193 GNUNET_SCHEDULER_cancel (l->logging_task);
194 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
199 * Property Generators
202 static struct PropertyGenerator *prop_gen_head;
203 static struct PropertyGenerator *prop_gen_tail;
206 get_property (struct PropertyGenerator *pg)
208 struct GNUNET_TIME_Relative time_delta;
212 /* Calculate the current preference value */
214 case GNUNET_ATS_TEST_TG_CONSTANT:
215 pref_value = pg->base_value;
217 case GNUNET_ATS_TEST_TG_LINEAR:
218 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
219 /* Calculate point of time in the current period */
220 time_delta.rel_value_us = time_delta.rel_value_us %
221 pg->duration_period.rel_value_us;
222 delta_value = ((double) time_delta.rel_value_us /
223 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
224 if ((pg->max_value < pg->base_value) &&
225 ((pg->max_value - pg->base_value) > pg->base_value))
227 /* This will cause an underflow */
230 pref_value = pg->base_value + delta_value;
232 case GNUNET_ATS_TEST_TG_RANDOM:
233 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
234 10000 * (pg->max_value - pg->base_value)) / 10000;
235 pref_value = pg->base_value + delta_value;
237 case GNUNET_ATS_TEST_TG_SINUS:
238 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
239 /* Calculate point of time in the current period */
240 time_delta.rel_value_us = time_delta.rel_value_us %
241 pg->duration_period.rel_value_us;
242 if ((pg->max_value - pg->base_value) > pg->base_value)
244 /* This will cause an underflow for second half of sinus period,
245 * will be detected in general when experiments are loaded */
248 delta_value = (pg->max_value - pg->base_value) *
249 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
250 time_delta.rel_value_us);
251 pref_value = pg->base_value + delta_value;
257 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
264 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
266 struct PropertyGenerator *pg = cls;
268 struct GNUNET_ATS_Information atsi;
270 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
272 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
273 &pg->test_peer->peer_id, pg->test_address->ats_addr))
276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
277 "Setting property generation for unknown address %u\n", pg->address_id);
281 pref_value = get_property (pg);
283 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
284 "Setting property for peer [%u] address [%u] for %s to %f\n",
285 pg->peer, pg->address_id,
286 GNUNET_ATS_print_property_type (pg->ats_property), pref_value);
289 atsi.type = pg->ats_property;
290 atsi.value = (uint32_t) pref_value;
292 /* set performance here! */
293 sh->env.sf.s_bulk_start (sh->solver);
294 GAS_normalization_normalize_property (sh->addresses,
295 pg->test_address->ats_addr, &atsi, 1);
296 sh->env.sf.s_bulk_stop (sh->solver);
299 switch (pg->ats_property) {
300 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
301 //p->pref_bandwidth = pref_value;
303 case GNUNET_ATS_PREFERENCE_LATENCY:
304 //p->pref_delay = pref_value;
310 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
315 static struct PropertyGenerator *
316 find_prop_gen (unsigned int peer, unsigned int address,
317 uint32_t ats_property)
319 struct PropertyGenerator *cur;
320 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
321 if ((cur->peer == peer) && (cur->address_id == address) &&
322 (cur->ats_property == ats_property))
328 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
330 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
332 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
334 GNUNET_SCHEDULER_cancel (pg->set_task);
335 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
338 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
339 pg->peer, pg->address_id,
340 GNUNET_ATS_print_property_type(pg->ats_property));
347 * Generate between the source master and the partner and set preferences with a
348 * value depending on the generator.
351 * @param dest partner
352 * @param type type of preferences to generate
353 * @param base_rate traffic base rate to send data with
354 * @param max_rate traffic maximum rate to send data with
355 * @param period duration of a period of traffic generation (~ 1/frequency)
356 * @param duration how long to generate traffic
357 * @return the traffic generator
359 struct PropertyGenerator *
360 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
361 unsigned int address_id,
362 struct TestPeer *test_peer,
363 struct TestAddress *test_address,
364 enum GeneratorType type,
367 struct GNUNET_TIME_Relative period,
368 struct GNUNET_TIME_Relative frequency,
369 uint32_t ats_property)
371 struct PropertyGenerator *pg;
373 pg = GNUNET_new (struct PropertyGenerator);
374 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
377 pg->test_address = test_address;
378 pg->test_peer = test_peer;
379 pg->address_id = address_id;
380 pg->ats_property = ats_property;
381 pg->base_value = base_value;
382 pg->max_value = value_rate;
383 pg->duration_period = period;
384 pg->frequency = frequency;
385 pg->time_start = GNUNET_TIME_absolute_get();
388 case GNUNET_ATS_TEST_TG_CONSTANT:
389 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
390 "Setting up %s property generator peer [%u] address [%u] `%s'"\
392 print_generator_type(type), pg->peer, pg->address_id,
393 GNUNET_ATS_print_property_type (ats_property),
396 case GNUNET_ATS_TEST_TG_LINEAR:
397 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
398 "Setting up %s property generator peer [%u] address [%u] `%s' " \
399 "min %u Bips max %u Bips\n",
400 print_generator_type(type), pg->peer, pg->address_id,
401 GNUNET_ATS_print_property_type(ats_property),
402 base_value, value_rate);
404 case GNUNET_ATS_TEST_TG_SINUS:
405 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
406 "Setting up %s property generator peer [%u] address [%u] `%s' "\
407 "baserate %u Bips, amplitude %u Bps\n",
408 print_generator_type(type), pg->peer, pg->address_id,
409 GNUNET_ATS_print_property_type(ats_property),
410 base_value, value_rate);
412 case GNUNET_ATS_TEST_TG_RANDOM:
413 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
414 "Setting up %s property generator peer [%u] address [%u] `%s' "\
415 "min %u Bips max %u Bps\n",
416 print_generator_type(type), pg->peer, pg->address_id,
417 GNUNET_ATS_print_property_type(ats_property),
418 base_value, value_rate);
424 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
431 * Stop all preferences generators
434 GNUNET_ATS_solver_generate_property_stop_all ()
436 struct PropertyGenerator *cur;
437 struct PropertyGenerator *next;
438 next = prop_gen_head;
439 for (cur = next; NULL != cur; cur = next)
442 GNUNET_ATS_solver_generate_property_stop (cur);
448 * Preference Generators
451 static struct PreferenceGenerator *pref_gen_head;
452 static struct PreferenceGenerator *pref_gen_tail;
455 get_preference (struct PreferenceGenerator *pg)
457 struct GNUNET_TIME_Relative time_delta;
461 /* Calculate the current preference value */
463 case GNUNET_ATS_TEST_TG_CONSTANT:
464 pref_value = pg->base_value;
466 case GNUNET_ATS_TEST_TG_LINEAR:
467 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
468 /* Calculate point of time in the current period */
469 time_delta.rel_value_us = time_delta.rel_value_us %
470 pg->duration_period.rel_value_us;
471 delta_value = ((double) time_delta.rel_value_us /
472 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
473 if ((pg->max_value < pg->base_value) &&
474 ((pg->max_value - pg->base_value) > pg->base_value))
476 /* This will cause an underflow */
479 pref_value = pg->base_value + delta_value;
481 case GNUNET_ATS_TEST_TG_RANDOM:
482 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
483 10000 * (pg->max_value - pg->base_value)) / 10000;
484 pref_value = pg->base_value + delta_value;
486 case GNUNET_ATS_TEST_TG_SINUS:
487 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
488 /* Calculate point of time in the current period */
489 time_delta.rel_value_us = time_delta.rel_value_us %
490 pg->duration_period.rel_value_us;
491 if ((pg->max_value - pg->base_value) > pg->base_value)
493 /* This will cause an underflow for second half of sinus period,
494 * will be detected in general when experiments are loaded */
497 delta_value = (pg->max_value - pg->base_value) *
498 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
499 time_delta.rel_value_us);
500 pref_value = pg->base_value + delta_value;
506 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
513 set_pref_task (void *cls,
514 const struct GNUNET_SCHEDULER_TaskContext *tc)
516 struct PreferenceGenerator *pg = cls;
518 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
520 pref_value = get_preference (pg);
522 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
523 "Setting preference for peer [%u] address [%u] for %s to %f\n",
524 pg->peer, pg->address_id,
525 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
527 /* set performance here!
528 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
529 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
533 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
534 //p->pref_bandwidth = pref_value;
536 case GNUNET_ATS_PREFERENCE_LATENCY:
537 //p->pref_delay = pref_value;
543 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
548 static struct PreferenceGenerator *
549 find_pref_gen (unsigned int peer, unsigned int address,
550 enum GNUNET_ATS_PreferenceKind kind)
552 struct PreferenceGenerator *cur;
553 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
554 if ((cur->peer == peer) && (cur->address_id == address) && (cur->kind == kind))
560 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
562 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
564 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
566 GNUNET_SCHEDULER_cancel (pg->set_task);
567 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
570 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
571 pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(pg->kind));
578 * Generate between the source master and the partner and set preferences with a
579 * value depending on the generator.
582 * @param dest partner
583 * @param type type of preferences to generate
584 * @param base_rate traffic base rate to send data with
585 * @param max_rate traffic maximum rate to send data with
586 * @param period duration of a period of traffic generation (~ 1/frequency)
587 * @param duration how long to generate traffic
588 * @return the traffic generator
590 struct PreferenceGenerator *
591 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
592 unsigned int address_id,
593 enum GeneratorType type,
596 struct GNUNET_TIME_Relative period,
597 struct GNUNET_TIME_Relative frequency,
598 enum GNUNET_ATS_PreferenceKind kind)
600 struct PreferenceGenerator *pg;
602 pg = GNUNET_new (struct PreferenceGenerator);
603 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
606 pg->address_id = address_id;
608 pg->base_value = base_value;
609 pg->max_value = value_rate;
610 pg->duration_period = period;
611 pg->frequency = frequency;
612 pg->time_start = GNUNET_TIME_absolute_get();
615 case GNUNET_ATS_TEST_TG_CONSTANT:
616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
617 "Setting up %s preference generator peer [%u] address [%u] `%s' max %u Bips\n",
618 print_generator_type (type), pg->peer, pg->address_id,
619 GNUNET_ATS_print_preference_type(kind),
622 case GNUNET_ATS_TEST_TG_LINEAR:
623 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
625 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
626 base_value, value_rate);
628 case GNUNET_ATS_TEST_TG_SINUS:
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 "Setting up %s preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
631 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
632 base_value, value_rate);
634 case GNUNET_ATS_TEST_TG_RANDOM:
635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
636 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
637 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
638 base_value, value_rate);
644 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
651 * Stop all preferences generators
654 GNUNET_ATS_solver_generate_preferences_stop_all ()
656 struct PreferenceGenerator *cur;
657 struct PreferenceGenerator *next;
658 next = pref_gen_head;
659 for (cur = next; NULL != cur; cur = next)
662 GNUNET_ATS_solver_generate_preferences_stop(cur);
673 print_op (enum OperationType op)
676 case SOLVER_OP_ADD_ADDRESS:
677 return "ADD_ADDRESS";
678 case SOLVER_OP_DEL_ADDRESS:
679 return "DEL_ADDRESS";
680 case SOLVER_OP_START_SET_PREFERENCE:
681 return "START_SET_PREFERENCE";
682 case SOLVER_OP_STOP_SET_PREFERENCE:
683 return "STOP_STOP_PREFERENCE";
684 case SOLVER_OP_START_SET_PROPERTY:
685 return "START_SET_PROPERTY";
686 case SOLVER_OP_STOP_SET_PROPERTY:
687 return "STOP_SET_PROPERTY";
688 case SOLVER_OP_START_REQUEST:
689 return "START_REQUEST";
690 case SOLVER_OP_STOP_REQUEST:
691 return "STOP_REQUEST";
698 static struct Experiment *
701 struct Experiment *e;
702 e = GNUNET_new (struct Experiment);
707 e->total_duration = GNUNET_TIME_UNIT_ZERO;
712 free_experiment (struct Experiment *e)
715 struct Episode *next;
716 struct GNUNET_ATS_TEST_Operation *cur_o;
717 struct GNUNET_ATS_TEST_Operation *next_o;
720 for (cur = next; NULL != cur; cur = next)
725 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
727 next_o = cur_o->next;
728 GNUNET_free_non_null (cur_o->address);
729 GNUNET_free_non_null (cur_o->plugin);
735 GNUNET_free_non_null (e->name);
736 GNUNET_free_non_null (e->cfg_file);
742 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
746 const struct GNUNET_CONFIGURATION_Handle *cfg)
751 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
752 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
753 sec_name, op_name, &o->peer_id))
755 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
756 op_counter, "ADD_ADDRESS", op_name);
757 GNUNET_free (op_name);
758 return GNUNET_SYSERR;
760 GNUNET_free (op_name);
763 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
764 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
765 sec_name, op_name, &o->address_id))
767 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
768 op_counter, "ADD_ADDRESS", op_name);
769 GNUNET_free (op_name);
770 return GNUNET_SYSERR;
772 GNUNET_free (op_name);
775 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
776 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
777 sec_name, op_name, &o->plugin))
779 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
780 op_counter, "ADD_ADDRESS", op_name);
781 GNUNET_free (op_name);
782 return GNUNET_SYSERR;
784 GNUNET_free (op_name);
787 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
788 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
789 sec_name, op_name, &o->address))
791 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
792 op_counter, "ADD_ADDRESS", op_name);
793 GNUNET_free (op_name);
794 return GNUNET_SYSERR;
796 GNUNET_free (op_name);
799 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
800 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
801 sec_name, op_name, &o->address_session))
803 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
804 op_counter, "ADD_ADDRESS", op_name);
805 GNUNET_free (op_name);
806 return GNUNET_SYSERR;
808 GNUNET_free (op_name);
811 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
812 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
813 sec_name, op_name, &o->address_network))
815 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
816 op_counter, "ADD_ADDRESS", op_name);
817 GNUNET_free (op_name);
818 return GNUNET_SYSERR;
820 GNUNET_free (op_name);
823 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
824 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
830 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
834 const struct GNUNET_CONFIGURATION_Handle *cfg)
839 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
840 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
841 sec_name, op_name, &o->peer_id))
843 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
844 op_counter, "DEL_ADDRESS", op_name);
845 GNUNET_free (op_name);
846 return GNUNET_SYSERR;
848 GNUNET_free (op_name);
851 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
852 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
853 sec_name, op_name, &o->address_id))
855 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
856 op_counter, "DEL_ADDRESS", op_name);
857 GNUNET_free (op_name);
858 return GNUNET_SYSERR;
860 GNUNET_free (op_name);
863 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
864 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
865 sec_name, op_name, &o->plugin))
867 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
868 op_counter, "DEL_ADDRESS", op_name);
869 GNUNET_free (op_name);
870 return GNUNET_SYSERR;
872 GNUNET_free (op_name);
875 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
876 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
877 sec_name, op_name, &o->address))
879 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
880 op_counter, "DEL_ADDRESS", op_name);
881 GNUNET_free (op_name);
882 return GNUNET_SYSERR;
884 GNUNET_free (op_name);
887 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
888 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
889 sec_name, op_name, &o->address_session))
891 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
892 op_counter, "DEL_ADDRESS", op_name);
893 GNUNET_free (op_name);
894 return GNUNET_SYSERR;
896 GNUNET_free (op_name);
899 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
900 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
901 sec_name, op_name, &o->address_network))
903 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
904 op_counter, "DEL_ADDRESS", op_name);
905 GNUNET_free (op_name);
906 return GNUNET_SYSERR;
908 GNUNET_free (op_name);
911 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
912 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
917 static enum GNUNET_ATS_Property
918 parse_preference_string (const char * str)
921 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
923 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
924 if (0 == strcmp(str, props[c]))
930 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
934 const struct GNUNET_CONFIGURATION_Handle *cfg)
941 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
942 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
943 sec_name, op_name, &o->peer_id))
945 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
946 op_counter, "START_SET_PREFERENCE", op_name);
947 GNUNET_free (op_name);
948 return GNUNET_SYSERR;
950 GNUNET_free (op_name);
953 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
954 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
955 sec_name, op_name, &o->address_id))
957 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
958 op_counter, "START_SET_PREFERENCE", op_name);
959 GNUNET_free (op_name);
960 return GNUNET_SYSERR;
962 GNUNET_free (op_name);
965 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
966 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
967 sec_name, op_name, &type)) )
969 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
970 op_counter, "START_SET_PREFERENCE", op_name);
971 GNUNET_free (op_name);
972 return GNUNET_SYSERR;
975 /* Load arguments for set_rate, start_send, set_preference */
976 if (0 == strcmp (type, "constant"))
978 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
980 else if (0 == strcmp (type, "linear"))
982 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
984 else if (0 == strcmp (type, "sinus"))
986 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
988 else if (0 == strcmp (type, "random"))
990 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
994 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
995 op_counter, op_name, e->id);
997 GNUNET_free (op_name);
998 return GNUNET_SYSERR;
1001 GNUNET_free (op_name);
1005 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1006 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1007 sec_name, op_name, &o->base_rate))
1009 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1010 op_counter, op_name, e->id);
1011 GNUNET_free (op_name);
1012 return GNUNET_SYSERR;
1014 GNUNET_free (op_name);
1018 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1019 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1020 sec_name, op_name, &o->max_rate))
1022 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1023 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1024 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1026 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1027 op_counter, op_name, e->id);
1028 GNUNET_free (op_name);
1029 return GNUNET_SYSERR;
1032 GNUNET_free (op_name);
1035 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1036 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1037 sec_name, op_name, &o->period))
1039 o->period = e->duration;
1041 GNUNET_free (op_name);
1044 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1045 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1046 sec_name, op_name, &o->frequency))
1048 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1049 op_counter, op_name, e->id);
1050 GNUNET_free (op_name);
1051 return GNUNET_SYSERR;
1053 GNUNET_free (op_name);
1055 /* Get preference */
1056 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1057 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1058 sec_name, op_name, &pref))
1060 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1061 op_counter, op_name, e->id);
1062 GNUNET_free (op_name);
1063 return GNUNET_SYSERR;
1066 if (0 == (o->pref_type = parse_preference_string(pref)))
1068 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1069 op_counter, op_name, e->id);
1070 GNUNET_free (op_name);
1072 return GNUNET_SYSERR;
1075 GNUNET_free (op_name);
1078 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1079 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1080 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1086 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1090 const struct GNUNET_CONFIGURATION_Handle *cfg)
1096 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1097 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1098 sec_name, op_name, &o->peer_id))
1100 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1101 op_counter, "STOP_SET_PREFERENCE", op_name);
1102 GNUNET_free (op_name);
1103 return GNUNET_SYSERR;
1105 GNUNET_free (op_name);
1108 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1109 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1110 sec_name, op_name, &o->address_id))
1112 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1113 op_counter, "STOP_SET_PREFERENCE", op_name);
1114 GNUNET_free (op_name);
1115 return GNUNET_SYSERR;
1117 GNUNET_free (op_name);
1119 /* Get preference */
1120 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1121 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1122 sec_name, op_name, &pref))
1124 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1125 op_counter, "STOP_SET_PREFERENCE", op_name);
1126 GNUNET_free (op_name);
1127 return GNUNET_SYSERR;
1130 if (0 == (o->pref_type = parse_preference_string(pref)))
1132 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1133 op_counter, op_name, e->id);
1134 GNUNET_free (op_name);
1136 return GNUNET_SYSERR;
1139 GNUNET_free (op_name);
1142 "Found operation %s: [%llu:%llu]: %s\n",
1143 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1144 GNUNET_ATS_print_preference_type(o->pref_type));
1148 static enum GNUNET_ATS_Property
1149 parse_property_string (const char * str)
1152 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1154 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1155 if (0 == strcmp(str, props[c]))
1161 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1165 const struct GNUNET_CONFIGURATION_Handle *cfg)
1172 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1173 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1174 sec_name, op_name, &o->peer_id))
1176 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1177 op_counter, "START_SET_PROPERTY", op_name);
1178 GNUNET_free (op_name);
1179 return GNUNET_SYSERR;
1181 GNUNET_free (op_name);
1184 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1185 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1186 sec_name, op_name, &o->address_id))
1188 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1189 op_counter, "START_SET_PROPERTY", op_name);
1190 GNUNET_free (op_name);
1191 return GNUNET_SYSERR;
1193 GNUNET_free (op_name);
1196 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1197 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1198 sec_name, op_name, &type)) )
1200 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1201 op_counter, "START_SET_PROPERTY", op_name);
1202 GNUNET_free (op_name);
1203 return GNUNET_SYSERR;
1206 /* Load arguments for set_rate, start_send, set_preference */
1207 if (0 == strcmp (type, "constant"))
1209 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1211 else if (0 == strcmp (type, "linear"))
1213 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1215 else if (0 == strcmp (type, "sinus"))
1217 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1219 else if (0 == strcmp (type, "random"))
1221 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1225 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1226 op_counter, op_name, e->id);
1228 GNUNET_free (op_name);
1229 return GNUNET_SYSERR;
1232 GNUNET_free (op_name);
1236 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1237 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1238 sec_name, op_name, &o->base_rate))
1240 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1241 op_counter, op_name, e->id);
1242 GNUNET_free (op_name);
1243 return GNUNET_SYSERR;
1245 GNUNET_free (op_name);
1249 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1250 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1251 sec_name, op_name, &o->max_rate))
1253 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1254 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1255 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1257 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1258 op_counter, op_name, e->id);
1259 GNUNET_free (op_name);
1260 return GNUNET_SYSERR;
1263 GNUNET_free (op_name);
1266 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1267 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1268 sec_name, op_name, &o->period))
1270 o->period = e->duration;
1272 GNUNET_free (op_name);
1275 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1276 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1277 sec_name, op_name, &o->frequency))
1279 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1280 op_counter, op_name, e->id);
1281 GNUNET_free (op_name);
1282 return GNUNET_SYSERR;
1284 GNUNET_free (op_name);
1286 /* Get preference */
1287 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1288 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1289 sec_name, op_name, &prop))
1291 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1292 op_counter, op_name, e->id);
1293 GNUNET_free (op_name);
1294 GNUNET_free_non_null (prop);
1295 return GNUNET_SYSERR;
1298 if (0 == (o->prop_type = parse_property_string(prop)))
1300 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1301 op_counter, op_name, e->id);
1302 GNUNET_free (op_name);
1304 return GNUNET_SYSERR;
1308 GNUNET_free (op_name);
1311 "Found operation %s: [%llu:%llu] %s = %llu\n",
1312 "START_SET_PROPERTY", o->peer_id, o->address_id,
1313 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1319 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1323 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, "STOP_SET_PROPERTY", op_name);
1335 GNUNET_free (op_name);
1336 return GNUNET_SYSERR;
1338 GNUNET_free (op_name);
1341 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1342 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1343 sec_name, op_name, &o->address_id))
1345 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1346 op_counter, "STOP_SET_PROPERTY", op_name);
1347 GNUNET_free (op_name);
1348 return GNUNET_SYSERR;
1350 GNUNET_free (op_name);
1353 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1354 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1355 sec_name, op_name, &pref))
1357 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1358 op_counter, "STOP_SET_PROPERTY", op_name);
1359 GNUNET_free (op_name);
1360 GNUNET_free_non_null (pref);
1361 return GNUNET_SYSERR;
1364 if (0 == (o->prop_type = parse_property_string(pref)))
1366 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1367 op_counter, op_name, e->id);
1368 GNUNET_free (op_name);
1370 GNUNET_free_non_null (pref);
1371 return GNUNET_SYSERR;
1375 GNUNET_free (op_name);
1378 "Found operation %s: [%llu:%llu] %s\n",
1379 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1380 GNUNET_ATS_print_property_type (o->prop_type));
1387 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1391 const struct GNUNET_CONFIGURATION_Handle *cfg)
1396 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1397 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1398 sec_name, op_name, &o->peer_id))
1400 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1401 op_counter, "START_REQUEST", op_name);
1402 GNUNET_free (op_name);
1403 return GNUNET_SYSERR;
1405 GNUNET_free (op_name);
1410 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1414 const struct GNUNET_CONFIGURATION_Handle *cfg)
1419 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1420 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1421 sec_name, op_name, &o->peer_id))
1423 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1424 op_counter, "STOP_REQUEST", op_name);
1425 GNUNET_free (op_name);
1426 return GNUNET_SYSERR;
1428 GNUNET_free (op_name);
1434 load_episode (struct Experiment *e, struct Episode *cur,
1435 struct GNUNET_CONFIGURATION_Handle *cfg)
1437 struct GNUNET_ATS_TEST_Operation *o;
1443 fprintf (stderr, "Parsing episode %u\n",cur->id);
1444 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1448 /* Load operation */
1449 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1450 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1451 sec_name, op_name, &op))
1453 GNUNET_free (op_name);
1456 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1457 /* operations = set_rate, start_send, stop_send, set_preference */
1458 if (0 == strcmp (op, "address_add"))
1460 o->type = SOLVER_OP_ADD_ADDRESS;
1461 res = load_op_add_address (o, cur,
1462 op_counter, sec_name, cfg);
1464 else if (0 == strcmp (op, "address_del"))
1466 o->type = SOLVER_OP_DEL_ADDRESS;
1467 res = load_op_del_address (o, cur,
1468 op_counter, sec_name, cfg);
1470 else if (0 == strcmp (op, "start_set_property"))
1472 o->type = SOLVER_OP_START_SET_PROPERTY;
1473 res = load_op_start_set_property (o, cur,
1474 op_counter, sec_name, cfg);
1476 else if (0 == strcmp (op, "stop_set_property"))
1478 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1479 res = load_op_stop_set_property (o, cur,
1480 op_counter, sec_name, cfg);
1482 else if (0 == strcmp (op, "start_set_preference"))
1484 o->type = SOLVER_OP_START_SET_PREFERENCE;
1485 res = load_op_start_set_preference (o, cur,
1486 op_counter, sec_name, cfg);
1489 else if (0 == strcmp (op, "stop_set_preference"))
1491 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1492 res = load_op_stop_set_preference (o, cur,
1493 op_counter, sec_name, cfg);
1495 else if (0 == strcmp (op, "start_request"))
1497 o->type = SOLVER_OP_START_REQUEST;
1498 res = load_op_start_request (o, cur,
1499 op_counter, sec_name, cfg);
1501 else if (0 == strcmp (op, "stop_request"))
1503 o->type = SOLVER_OP_STOP_REQUEST;
1504 res = load_op_stop_request(o, cur,
1505 op_counter, sec_name, cfg);
1509 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1510 op_counter, op, cur->id);
1511 res = GNUNET_SYSERR;
1515 GNUNET_free (op_name);
1517 if (GNUNET_SYSERR == res)
1520 GNUNET_free (sec_name);
1521 return GNUNET_SYSERR;
1524 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1527 GNUNET_free (sec_name);
1532 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1536 struct GNUNET_TIME_Relative e_duration;
1537 struct Episode *cur;
1538 struct Episode *last;
1544 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1545 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1546 sec_name, "duration", &e_duration))
1548 GNUNET_free (sec_name);
1552 cur = GNUNET_new (struct Episode);
1553 cur->duration = e_duration;
1554 cur->id = e_counter;
1556 if (GNUNET_OK != load_episode (e, cur, cfg))
1558 GNUNET_free (sec_name);
1560 return GNUNET_SYSERR;
1563 fprintf (stderr, "Found episode %u with duration %s \n",
1565 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1567 /* Update experiment */
1569 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1570 /* Put in linked list */
1576 GNUNET_free (sec_name);
1584 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1586 struct Experiment *e = cls;
1587 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1588 fprintf (stderr, "Experiment timeout!\n");
1590 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1592 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1593 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1596 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1600 struct ATS_Address *
1601 create_ats_address (const struct GNUNET_PeerIdentity *peer,
1602 const char *plugin_name,
1603 const void *plugin_addr, size_t plugin_addr_len,
1604 uint32_t session_id)
1606 struct ATS_Address *aa = NULL;
1608 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
1610 aa->addr_len = plugin_addr_len;
1612 aa->plugin = (char *) &aa[1] + plugin_addr_len;
1613 memcpy (&aa[1], plugin_addr, plugin_addr_len);
1614 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
1615 aa->session_id = session_id;
1616 aa->active = GNUNET_NO;
1617 aa->used = GNUNET_NO;
1618 aa->solver_information = NULL;
1619 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
1620 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
1627 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1630 struct TestAddress *a;
1632 if (NULL == (p = find_peer_by_id (op->peer_id)))
1634 p = GNUNET_new (struct TestPeer);
1635 p->id = op->peer_id;
1636 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
1637 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
1640 if (NULL != (a = find_address_by_id (p, op->address_id)))
1642 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
1643 op->address_id, op->peer_id);
1646 a = GNUNET_new (struct TestAddress);
1647 a->aid = op->address_id;
1648 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
1649 strlen (op->address) + 1, op->address_session);
1650 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
1651 GNUNET_CONTAINER_DLL_insert (p->addr_head, p->addr_tail, a);
1653 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
1654 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1656 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u\n",
1657 op->address_id, op->peer_id);
1659 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
1665 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1668 struct TestAddress *a;
1669 struct AddressLookupCtx ctx;
1671 if (NULL == (p = find_peer_by_id (op->peer_id)))
1674 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1675 "Deleting address for unknown peer %u\n", op->peer_id);
1679 ctx.plugin = op->plugin;
1680 ctx.addr = op->address;
1682 GNUNET_CONTAINER_multipeermap_get_multiple (sh->addresses, &p->peer_id,
1683 find_address_it, &ctx);
1684 if (NULL == ctx.res)
1687 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1688 "Deleting unknown address for peer %u\n", op->peer_id);
1692 if (NULL == (a = find_address_by_id (p, op->address_id)))
1695 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1696 "Deleting address for unknown peer %u\n", op->peer_id);
1699 GNUNET_CONTAINER_DLL_remove (p->addr_head, p->addr_tail, a);
1701 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, ctx.res);
1703 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
1704 op->address_id, op->peer_id);
1706 sh->env.sf.s_del (sh->solver, ctx.res, GNUNET_NO);
1707 GNUNET_free (ctx.res);
1712 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1714 struct PropertyGenerator *pg;
1716 struct TestAddress *a;
1718 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
1720 GNUNET_ATS_solver_generate_property_stop (pg);
1724 if (NULL == (p = find_peer_by_id (op->peer_id)))
1727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1728 "Starting property generation for unknown peer %u\n", op->peer_id);
1732 if (NULL == (a = find_address_by_id (p, op->address_id)))
1735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1736 "Setting proprterty for unknown address %u\n", op->peer_id);
1740 GNUNET_ATS_solver_generate_property_start (op->peer_id,
1752 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1754 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
1757 GNUNET_ATS_solver_generate_property_stop (pg);
1761 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1763 struct PreferenceGenerator *pg;
1764 if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type)))
1766 GNUNET_ATS_solver_generate_preferences_stop (pg);
1770 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
1781 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1783 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, op->address_id,
1786 GNUNET_ATS_solver_generate_preferences_stop (pg);
1791 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
1794 const struct ATS_Address *res;
1796 if (NULL == (p = find_peer_by_id (op->peer_id)))
1799 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1800 "Requesting address for unknown peer %u\n", op->peer_id);
1804 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
1807 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
1816 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
1820 if (NULL == (p = find_peer_by_id (op->peer_id)))
1823 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1824 "Requesting address for unknown peer %u\n", op->peer_id);
1828 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
1831 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
1834 static void enforce_episode (struct Episode *ep)
1836 struct GNUNET_ATS_TEST_Operation *cur;
1837 for (cur = ep->head; NULL != cur; cur = cur->next)
1839 switch (cur->type) {
1840 case SOLVER_OP_ADD_ADDRESS:
1841 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1842 print_op (cur->type), cur->peer_id, cur->address_id);
1843 enforce_add_address (cur);
1845 case SOLVER_OP_DEL_ADDRESS:
1846 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1847 print_op (cur->type), cur->peer_id, cur->address_id);
1848 enforce_del_address (cur);
1850 case SOLVER_OP_START_SET_PROPERTY:
1851 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1852 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1853 enforce_start_property (cur);
1855 case SOLVER_OP_STOP_SET_PROPERTY:
1856 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1857 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1858 enforce_stop_property (cur);
1860 case SOLVER_OP_START_SET_PREFERENCE:
1861 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1862 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1863 enforce_start_preference (cur);
1865 case SOLVER_OP_STOP_SET_PREFERENCE:
1866 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1867 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1868 enforce_stop_preference (cur);
1870 case SOLVER_OP_START_REQUEST:
1871 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1872 print_op (cur->type), cur->peer_id);
1873 enforce_start_request (cur);
1875 case SOLVER_OP_STOP_REQUEST:
1876 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1877 print_op (cur->type), cur->peer_id);
1878 enforce_stop_request (cur);
1887 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1889 struct Experiment *e = cls;
1890 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1891 if (NULL != e->ep_done_cb)
1892 e->ep_done_cb (e->cur);
1894 /* Scheduling next */
1895 e->cur = e->cur->next;
1899 fprintf (stderr, "Last episode done!\n");
1900 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1902 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1903 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1905 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
1909 fprintf (stderr, "Running episode %u with timeout %s\n",
1911 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1912 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1913 &timeout_episode, e);
1914 enforce_episode(e->cur);
1921 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1922 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
1923 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
1925 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
1926 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
1927 e->e_done_cb = e_done_cb;
1928 e->ep_done_cb = ep_done_cb;
1929 e->start_time = GNUNET_TIME_absolute_get();
1931 /* Start total time out */
1932 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
1933 &timeout_experiment, e);
1937 if (NULL == e->start)
1943 fprintf (stderr, "Running episode %u with timeout %s\n",
1945 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1946 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1947 &timeout_episode, e);
1948 enforce_episode(e->cur);
1953 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1955 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1957 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1958 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1960 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1962 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1963 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1967 GNUNET_CONFIGURATION_destroy(e->cfg);
1970 free_experiment (e);
1975 GNUNET_ATS_solvers_experimentation_load (char *filename)
1977 struct Experiment *e;
1978 struct GNUNET_CONFIGURATION_Handle *cfg;
1981 cfg = GNUNET_CONFIGURATION_create();
1982 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
1984 fprintf (stderr, "Failed to load `%s'\n", filename);
1985 GNUNET_CONFIGURATION_destroy (cfg);
1989 e = create_experiment ();
1991 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
1994 fprintf (stderr, "Invalid %s", "name");
1995 free_experiment (e);
1999 fprintf (stderr, "Experiment name: `%s'\n", e->name);
2001 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2002 "cfg_file", &e->cfg_file))
2004 fprintf (stderr, "Invalid %s", "cfg_file");
2005 free_experiment (e);
2010 fprintf (stderr, "Experiment configuration: `%s'\n", e->cfg_file);
2011 e->cfg = GNUNET_CONFIGURATION_create();
2012 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2014 fprintf (stderr, "Invalid configuration %s", "cfg_file");
2015 free_experiment (e);
2021 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2022 "masters", &e->num_masters))
2024 fprintf (stderr, "Invalid %s", "masters");
2025 free_experiment (e);
2029 fprintf (stderr, "Experiment masters: `%llu'\n",
2032 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
2033 "slaves", &e->num_slaves))
2035 fprintf (stderr, "Invalid %s", "slaves");
2036 free_experiment (e);
2040 fprintf (stderr, "Experiment slaves: `%llu'\n",
2043 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2044 "log_freq", &e->log_freq))
2046 fprintf (stderr, "Invalid %s", "log_freq");
2047 free_experiment (e);
2051 fprintf (stderr, "Experiment logging frequency: `%s'\n",
2052 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2054 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2055 "max_duration", &e->max_duration))
2057 fprintf (stderr, "Invalid %s", "max_duration");
2058 free_experiment (e);
2062 fprintf (stderr, "Experiment duration: `%s'\n",
2063 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2065 if (GNUNET_SYSERR == load_episodes (e, cfg))
2067 GNUNET_ATS_solvers_experimentation_stop (e);
2068 GNUNET_CONFIGURATION_destroy (cfg);
2070 fprintf (stderr, "Failed to load experiment\n");
2073 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
2075 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2077 GNUNET_CONFIGURATION_destroy (cfg);
2086 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2088 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2090 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2091 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2092 GNUNET_free (sh->plugin);
2097 * Load quotas for networks from configuration
2099 * @param cfg configuration handle
2100 * @param out_dest where to write outbound quotas
2101 * @param in_dest where to write inbound quotas
2102 * @param dest_length length of inbound and outbound arrays
2103 * @return number of networks loaded
2106 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2107 unsigned long long *out_dest,
2108 unsigned long long *in_dest,
2111 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2112 char * entry_in = NULL;
2113 char * entry_out = NULL;
2114 char * quota_out_str;
2115 char * quota_in_str;
2119 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2123 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2124 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2127 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2130 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2132 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2135 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2137 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2140 if (GNUNET_NO == res)
2142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2143 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2144 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2149 network_str[c], out_dest[c]);
2151 GNUNET_free (quota_out_str);
2155 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2156 network_str[c], GNUNET_ATS_DefaultBandwidth);
2157 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2161 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2164 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2166 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2169 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2171 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2174 if (GNUNET_NO == res)
2176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2177 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2178 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2183 network_str[c], in_dest[c]);
2185 GNUNET_free (quota_in_str);
2189 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2190 network_str[c], GNUNET_ATS_DefaultBandwidth);
2191 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2193 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]);
2194 GNUNET_free (entry_out);
2195 GNUNET_free (entry_in);
2197 return GNUNET_ATS_NetworkTypeCount;
2201 * Information callback for the solver
2203 * @param op the solver operation
2204 * @param stat status of the solver operation
2205 * @param add additional solver information
2208 solver_info_cb (void *cls,
2209 enum GAS_Solver_Operation op,
2210 enum GAS_Solver_Status stat,
2211 enum GAS_Solver_Additional_Information add)
2216 add_info = "GAS_INFO_NONE";
2219 add_info = "GAS_INFO_MLP_FULL";
2221 case GAS_INFO_UPDATED:
2222 add_info = "GAS_INFO_MLP_UPDATED";
2224 case GAS_INFO_PROP_ALL:
2225 add_info = "GAS_INFO_PROP_ALL";
2227 case GAS_INFO_PROP_SINGLE:
2228 add_info = "GAS_INFO_PROP_SINGLE";
2231 add_info = "INVALID";
2237 case GAS_OP_SOLVE_START:
2238 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2239 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2240 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2242 case GAS_OP_SOLVE_STOP:
2243 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2244 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2245 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2248 case GAS_OP_SOLVE_SETUP_START:
2249 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2250 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2251 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2254 case GAS_OP_SOLVE_SETUP_STOP:
2255 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2256 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2257 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2260 case GAS_OP_SOLVE_MLP_LP_START:
2261 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2262 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2263 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2265 case GAS_OP_SOLVE_MLP_LP_STOP:
2266 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2267 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2268 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2271 case GAS_OP_SOLVE_MLP_MLP_START:
2272 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2273 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2274 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2276 case GAS_OP_SOLVE_MLP_MLP_STOP:
2277 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2278 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2279 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2281 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2282 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2283 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2284 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2286 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2287 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2288 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2289 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2297 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2299 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2300 (0 == ntohl (address->assigned_bw_in.value__)) )
2302 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2303 "Solver notified to disconnect peer `%s'\n",
2304 GNUNET_i2s (&address->peer));
2308 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2309 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2310 GNUNET_i2s (&address->peer),
2312 (unsigned int) ntohl (address->assigned_bw_out.value__),
2313 (unsigned int) ntohl (address->assigned_bw_in.value__));
2314 /*if (GNUNET_YES == ph.bulk_running)
2320 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2322 return GAS_normalization_get_preferences_by_peer (id);
2327 get_property_cb (void *cls, const struct ATS_Address *address)
2329 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2333 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
2334 uint32_t type, double prop_rel)
2340 struct SolverHandle *
2341 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2343 struct SolverHandle *sh;
2347 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2348 solver_str = "proportional";
2350 case GNUNET_ATS_SOLVER_MLP:
2353 case GNUNET_ATS_SOLVER_RIL:
2362 sh = GNUNET_new (struct SolverHandle);
2363 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2365 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2366 /* setup environment */
2367 sh->env.cfg = e->cfg;
2368 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2369 sh->env.addresses = sh->addresses;
2370 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2371 sh->env.get_preferences = &get_preferences_cb;
2372 sh->env.get_property = &get_property_cb;
2373 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2374 sh->env.info_cb = &solver_info_cb;
2375 sh->env.info_cb_cls = NULL;
2378 /* start normalization */
2379 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
2382 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2383 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2386 GNUNET_free (sh->plugin);
2392 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2393 if (NULL == sh->solver)
2395 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2397 GNUNET_free (sh->plugin);
2406 free_all_it (void *cls,
2407 const struct GNUNET_PeerIdentity *key,
2410 struct ATS_Address *address = value;
2411 GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses, key, value);
2412 GNUNET_free (address);
2420 struct TestPeer *cur;
2421 struct TestPeer *next;
2422 /* Clean up experiment */
2423 GNUNET_ATS_solver_generate_preferences_stop_all ();
2424 GNUNET_ATS_solver_generate_property_stop_all ();
2428 GNUNET_ATS_solvers_experimentation_stop (e);
2434 GNUNET_ATS_solver_logging_free (l);
2439 while (NULL != (cur = next))
2442 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
2443 GNUNET_CONTAINER_multipeermap_iterate (sh->env.addresses, &free_all_it, NULL);
2453 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
2455 if (GNUNET_OK == success)
2456 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
2457 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
2459 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
2462 GNUNET_ATS_solver_logging_stop (l);
2464 /* Stop traffic generation */
2465 // GNUNET_ATS_TEST_generate_traffic_stop_all();
2467 /* Stop all preference generations */
2468 GNUNET_ATS_solver_generate_preferences_stop_all ();
2471 evaluate (duration);
2473 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
2477 GNUNET_ATS_TEST_logging_stop (l);
2478 GNUNET_ATS_TEST_logging_clean_up (l);
2482 GNUNET_SCHEDULER_add_now (&done, NULL);
2486 episode_done_cb (struct Episode *ep)
2488 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
2501 GNUNET_ATS_solvers_experimentation_stop (e);
2506 GNUNET_ATS_solvers_solver_stop (sh);
2512 run (void *cls, char * const *args, const char *cfgfile,
2513 const struct GNUNET_CONFIGURATION_Handle *cfg)
2515 enum GNUNET_ATS_Solvers solver;
2517 if (NULL == opt_exp_file)
2519 fprintf (stderr, "No experiment given ...\n");
2525 if (NULL == opt_solver)
2527 fprintf (stderr, "No solver given ...\n");
2533 if (0 == strcmp(opt_solver, "mlp"))
2535 solver = GNUNET_ATS_SOLVER_MLP;
2537 else if (0 == strcmp(opt_solver, "proportional"))
2539 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
2541 else if (0 == strcmp(opt_solver, "ril"))
2543 solver = GNUNET_ATS_SOLVER_RIL;
2547 fprintf (stderr, "No solver given ...");
2553 /* load experiment */
2554 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
2557 fprintf (stderr, "Failed to load experiment ...\n");
2564 sh = GNUNET_ATS_solvers_solver_start (solver);
2567 fprintf (stderr, "Failed to start solver ...\n");
2574 l = GNUNET_ATS_solver_logging_start (e->log_freq);
2576 /* run experiment */
2577 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2578 experiment_done_cb);
2585 * Main function of the benchmark
2587 * @param argc argument count
2588 * @param argv argument values
2591 main (int argc, char *argv[])
2593 opt_exp_file = NULL;
2595 opt_log = GNUNET_NO;
2596 opt_plot = GNUNET_NO;
2600 static struct GNUNET_GETOPT_CommandLineOption options[] =
2602 { 's', "solver", NULL,
2603 gettext_noop ("solver to use"),
2604 1, &GNUNET_GETOPT_set_string, &opt_solver},
2605 { 'e', "experiment", NULL,
2606 gettext_noop ("experiment to use"),
2607 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2608 { 'e', "experiment", NULL,
2609 gettext_noop ("experiment to use"),
2610 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2611 GNUNET_GETOPT_OPTION_END
2614 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
2615 NULL, options, &run, argv[0]);
2619 /* end of file ats-testing-experiment.c*/