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:%u]\n",
278 pg->peer, pg->address_id);
282 pref_value = get_property (pg);
284 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
285 "Setting property for peer [%u] address [%u] for %s to %f\n",
286 pg->peer, pg->address_id,
287 GNUNET_ATS_print_property_type (pg->ats_property), pref_value);
290 atsi.type = htonl (pg->ats_property);
291 atsi.value = htonl ((uint32_t) pref_value);
293 /* set performance here! */
294 sh->env.sf.s_bulk_start (sh->solver);
295 GAS_normalization_normalize_property (sh->addresses,
296 pg->test_address->ats_addr, &atsi, 1);
297 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;
519 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
521 if (NULL == (p = find_peer_by_id (pg->peer)))
524 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
525 "Setting preference for unknown peer %u\n", pg->peer);
529 pref_value = get_preference (pg);
531 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
532 "Setting preference for peer [%u] address [%u] for client %p pref %s to %f\n",
533 pg->peer, pg->address_id, NULL + (pg->client_id),
534 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
536 sh->env.sf.s_bulk_start (sh->solver);
537 GAS_normalization_normalize_preference (NULL + (pg->client_id), &p->peer_id,
538 pg->kind, pref_value);
539 sh->env.sf.s_bulk_stop (sh->solver);
542 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
543 //p->pref_bandwidth = pref_value;
545 case GNUNET_ATS_PREFERENCE_LATENCY:
546 //p->pref_delay = pref_value;
552 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
557 static struct PreferenceGenerator *
558 find_pref_gen (unsigned int peer, unsigned int address,
559 enum GNUNET_ATS_PreferenceKind kind)
561 struct PreferenceGenerator *cur;
562 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
563 if ((cur->peer == peer) && (cur->address_id == address) && (cur->kind == kind))
569 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
571 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
573 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
575 GNUNET_SCHEDULER_cancel (pg->set_task);
576 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
579 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
580 pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(pg->kind));
587 * Generate between the source master and the partner and set preferences with a
588 * value depending on the generator.
591 * @param dest partner
592 * @param type type of preferences to generate
593 * @param base_rate traffic base rate to send data with
594 * @param max_rate traffic maximum rate to send data with
595 * @param period duration of a period of traffic generation (~ 1/frequency)
596 * @param duration how long to generate traffic
597 * @return the traffic generator
599 struct PreferenceGenerator *
600 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
601 unsigned int address_id,
602 unsigned int client_id,
603 enum GeneratorType type,
606 struct GNUNET_TIME_Relative period,
607 struct GNUNET_TIME_Relative frequency,
608 enum GNUNET_ATS_PreferenceKind kind)
610 struct PreferenceGenerator *pg;
612 pg = GNUNET_new (struct PreferenceGenerator);
613 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
616 pg->address_id = address_id;
617 pg->client_id = client_id;
619 pg->base_value = base_value;
620 pg->max_value = value_rate;
621 pg->duration_period = period;
622 pg->frequency = frequency;
623 pg->time_start = GNUNET_TIME_absolute_get();
626 case GNUNET_ATS_TEST_TG_CONSTANT:
627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
628 "Setting up %s preference generator peer [%u] address [%u] `%s' max %u Bips\n",
629 print_generator_type (type), pg->peer, pg->address_id,
630 GNUNET_ATS_print_preference_type(kind),
633 case GNUNET_ATS_TEST_TG_LINEAR:
634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
635 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
636 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
637 base_value, value_rate);
639 case GNUNET_ATS_TEST_TG_SINUS:
640 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
641 "Setting up %s preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
642 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
643 base_value, value_rate);
645 case GNUNET_ATS_TEST_TG_RANDOM:
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
648 print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
649 base_value, value_rate);
655 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
662 * Stop all preferences generators
665 GNUNET_ATS_solver_generate_preferences_stop_all ()
667 struct PreferenceGenerator *cur;
668 struct PreferenceGenerator *next;
669 next = pref_gen_head;
670 for (cur = next; NULL != cur; cur = next)
673 GNUNET_ATS_solver_generate_preferences_stop(cur);
684 print_op (enum OperationType op)
687 case SOLVER_OP_ADD_ADDRESS:
688 return "ADD_ADDRESS";
689 case SOLVER_OP_DEL_ADDRESS:
690 return "DEL_ADDRESS";
691 case SOLVER_OP_START_SET_PREFERENCE:
692 return "START_SET_PREFERENCE";
693 case SOLVER_OP_STOP_SET_PREFERENCE:
694 return "STOP_STOP_PREFERENCE";
695 case SOLVER_OP_START_SET_PROPERTY:
696 return "START_SET_PROPERTY";
697 case SOLVER_OP_STOP_SET_PROPERTY:
698 return "STOP_SET_PROPERTY";
699 case SOLVER_OP_START_REQUEST:
700 return "START_REQUEST";
701 case SOLVER_OP_STOP_REQUEST:
702 return "STOP_REQUEST";
709 static struct Experiment *
712 struct Experiment *e;
713 e = GNUNET_new (struct Experiment);
716 e->total_duration = GNUNET_TIME_UNIT_ZERO;
721 free_experiment (struct Experiment *e)
724 struct Episode *next;
725 struct GNUNET_ATS_TEST_Operation *cur_o;
726 struct GNUNET_ATS_TEST_Operation *next_o;
729 for (cur = next; NULL != cur; cur = next)
734 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
736 next_o = cur_o->next;
737 GNUNET_free_non_null (cur_o->address);
738 GNUNET_free_non_null (cur_o->plugin);
744 GNUNET_free_non_null (e->name);
745 GNUNET_free_non_null (e->cfg_file);
751 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
755 const struct GNUNET_CONFIGURATION_Handle *cfg)
760 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
761 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
762 sec_name, op_name, &o->peer_id))
764 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
765 op_counter, "ADD_ADDRESS", op_name);
766 GNUNET_free (op_name);
767 return GNUNET_SYSERR;
769 GNUNET_free (op_name);
772 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
773 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
774 sec_name, op_name, &o->address_id))
776 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
777 op_counter, "ADD_ADDRESS", op_name);
778 GNUNET_free (op_name);
779 return GNUNET_SYSERR;
781 GNUNET_free (op_name);
784 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
785 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
786 sec_name, op_name, &o->plugin))
788 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
789 op_counter, "ADD_ADDRESS", op_name);
790 GNUNET_free (op_name);
791 return GNUNET_SYSERR;
793 GNUNET_free (op_name);
796 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
797 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
798 sec_name, op_name, &o->address))
800 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
801 op_counter, "ADD_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-session", op_counter);
809 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
810 sec_name, op_name, &o->address_session))
812 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
813 op_counter, "ADD_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-network", op_counter);
821 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
822 sec_name, op_name, &o->address_network))
824 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
825 op_counter, "ADD_ADDRESS", op_name);
826 GNUNET_free (op_name);
827 return GNUNET_SYSERR;
829 GNUNET_free (op_name);
832 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
833 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
839 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
843 const struct GNUNET_CONFIGURATION_Handle *cfg)
848 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
849 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
850 sec_name, op_name, &o->peer_id))
852 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
853 op_counter, "DEL_ADDRESS", op_name);
854 GNUNET_free (op_name);
855 return GNUNET_SYSERR;
857 GNUNET_free (op_name);
860 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
861 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
862 sec_name, op_name, &o->address_id))
864 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
865 op_counter, "DEL_ADDRESS", op_name);
866 GNUNET_free (op_name);
867 return GNUNET_SYSERR;
869 GNUNET_free (op_name);
872 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
873 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
874 sec_name, op_name, &o->plugin))
876 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
877 op_counter, "DEL_ADDRESS", op_name);
878 GNUNET_free (op_name);
879 return GNUNET_SYSERR;
881 GNUNET_free (op_name);
884 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
885 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
886 sec_name, op_name, &o->address))
888 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
889 op_counter, "DEL_ADDRESS", op_name);
890 GNUNET_free (op_name);
891 return GNUNET_SYSERR;
893 GNUNET_free (op_name);
896 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
897 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
898 sec_name, op_name, &o->address_session))
900 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
901 op_counter, "DEL_ADDRESS", op_name);
902 GNUNET_free (op_name);
903 return GNUNET_SYSERR;
905 GNUNET_free (op_name);
908 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
909 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
910 sec_name, op_name, &o->address_network))
912 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
913 op_counter, "DEL_ADDRESS", op_name);
914 GNUNET_free (op_name);
915 return GNUNET_SYSERR;
917 GNUNET_free (op_name);
920 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
921 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
926 static enum GNUNET_ATS_Property
927 parse_preference_string (const char * str)
930 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
932 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
933 if (0 == strcmp(str, props[c]))
939 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
943 const struct GNUNET_CONFIGURATION_Handle *cfg)
950 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
951 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
952 sec_name, op_name, &o->peer_id))
954 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
955 op_counter, "START_SET_PREFERENCE", op_name);
956 GNUNET_free (op_name);
957 return GNUNET_SYSERR;
959 GNUNET_free (op_name);
962 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
963 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
964 sec_name, op_name, &o->address_id))
966 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
967 op_counter, "START_SET_PREFERENCE", op_name);
968 GNUNET_free (op_name);
969 return GNUNET_SYSERR;
971 GNUNET_free (op_name);
974 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
975 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
976 sec_name, op_name, &o->client_id))
978 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
979 op_counter, "START_SET_PREFERENCE", op_name);
980 GNUNET_free (op_name);
981 return GNUNET_SYSERR;
983 GNUNET_free (op_name);
986 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
987 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
988 sec_name, op_name, &type)) )
990 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
991 op_counter, "START_SET_PREFERENCE", op_name);
992 GNUNET_free (op_name);
993 return GNUNET_SYSERR;
996 /* Load arguments for set_rate, start_send, set_preference */
997 if (0 == strcmp (type, "constant"))
999 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1001 else if (0 == strcmp (type, "linear"))
1003 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1005 else if (0 == strcmp (type, "sinus"))
1007 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1009 else if (0 == strcmp (type, "random"))
1011 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1015 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1016 op_counter, op_name, e->id);
1018 GNUNET_free (op_name);
1019 return GNUNET_SYSERR;
1022 GNUNET_free (op_name);
1026 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1027 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1028 sec_name, op_name, &o->base_rate))
1030 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1031 op_counter, op_name, e->id);
1032 GNUNET_free (op_name);
1033 return GNUNET_SYSERR;
1035 GNUNET_free (op_name);
1039 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1040 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1041 sec_name, op_name, &o->max_rate))
1043 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1044 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1045 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1047 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1048 op_counter, op_name, e->id);
1049 GNUNET_free (op_name);
1050 return GNUNET_SYSERR;
1053 GNUNET_free (op_name);
1056 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1057 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1058 sec_name, op_name, &o->period))
1060 o->period = e->duration;
1062 GNUNET_free (op_name);
1065 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1066 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1067 sec_name, op_name, &o->frequency))
1069 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1070 op_counter, op_name, e->id);
1071 GNUNET_free (op_name);
1072 return GNUNET_SYSERR;
1074 GNUNET_free (op_name);
1076 /* Get preference */
1077 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1078 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1079 sec_name, op_name, &pref))
1081 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1082 op_counter, op_name, e->id);
1083 GNUNET_free (op_name);
1084 return GNUNET_SYSERR;
1087 if (0 == (o->pref_type = parse_preference_string(pref)))
1089 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1090 op_counter, op_name, e->id);
1091 GNUNET_free (op_name);
1093 return GNUNET_SYSERR;
1096 GNUNET_free (op_name);
1099 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1100 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1101 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1107 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1111 const struct GNUNET_CONFIGURATION_Handle *cfg)
1117 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1118 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1119 sec_name, op_name, &o->peer_id))
1121 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1122 op_counter, "STOP_SET_PREFERENCE", op_name);
1123 GNUNET_free (op_name);
1124 return GNUNET_SYSERR;
1126 GNUNET_free (op_name);
1129 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1130 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1131 sec_name, op_name, &o->address_id))
1133 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1134 op_counter, "STOP_SET_PREFERENCE", op_name);
1135 GNUNET_free (op_name);
1136 return GNUNET_SYSERR;
1138 GNUNET_free (op_name);
1140 /* Get preference */
1141 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1142 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1143 sec_name, op_name, &pref))
1145 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1146 op_counter, "STOP_SET_PREFERENCE", op_name);
1147 GNUNET_free (op_name);
1148 return GNUNET_SYSERR;
1151 if (0 == (o->pref_type = parse_preference_string(pref)))
1153 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1154 op_counter, op_name, e->id);
1155 GNUNET_free (op_name);
1157 return GNUNET_SYSERR;
1160 GNUNET_free (op_name);
1163 "Found operation %s: [%llu:%llu]: %s\n",
1164 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1165 GNUNET_ATS_print_preference_type(o->pref_type));
1169 static enum GNUNET_ATS_Property
1170 parse_property_string (const char * str)
1173 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1175 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1176 if (0 == strcmp(str, props[c]))
1182 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1186 const struct GNUNET_CONFIGURATION_Handle *cfg)
1193 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1194 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1195 sec_name, op_name, &o->peer_id))
1197 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1198 op_counter, "START_SET_PROPERTY", op_name);
1199 GNUNET_free (op_name);
1200 return GNUNET_SYSERR;
1202 GNUNET_free (op_name);
1205 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1206 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1207 sec_name, op_name, &o->address_id))
1209 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1210 op_counter, "START_SET_PROPERTY", op_name);
1211 GNUNET_free (op_name);
1212 return GNUNET_SYSERR;
1214 GNUNET_free (op_name);
1217 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1218 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1219 sec_name, op_name, &type)) )
1221 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1222 op_counter, "START_SET_PROPERTY", op_name);
1223 GNUNET_free (op_name);
1224 return GNUNET_SYSERR;
1227 /* Load arguments for set_rate, start_send, set_preference */
1228 if (0 == strcmp (type, "constant"))
1230 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1232 else if (0 == strcmp (type, "linear"))
1234 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1236 else if (0 == strcmp (type, "sinus"))
1238 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1240 else if (0 == strcmp (type, "random"))
1242 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1246 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1247 op_counter, op_name, e->id);
1249 GNUNET_free (op_name);
1250 return GNUNET_SYSERR;
1253 GNUNET_free (op_name);
1257 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1258 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1259 sec_name, op_name, &o->base_rate))
1261 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1262 op_counter, op_name, e->id);
1263 GNUNET_free (op_name);
1264 return GNUNET_SYSERR;
1266 GNUNET_free (op_name);
1270 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1271 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1272 sec_name, op_name, &o->max_rate))
1274 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1275 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1276 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1278 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1279 op_counter, op_name, e->id);
1280 GNUNET_free (op_name);
1281 return GNUNET_SYSERR;
1284 GNUNET_free (op_name);
1287 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1288 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1289 sec_name, op_name, &o->period))
1291 o->period = e->duration;
1293 GNUNET_free (op_name);
1296 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1297 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1298 sec_name, op_name, &o->frequency))
1300 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1301 op_counter, op_name, e->id);
1302 GNUNET_free (op_name);
1303 return GNUNET_SYSERR;
1305 GNUNET_free (op_name);
1307 /* Get preference */
1308 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1309 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1310 sec_name, op_name, &prop))
1312 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1313 op_counter, op_name, e->id);
1314 GNUNET_free (op_name);
1315 GNUNET_free_non_null (prop);
1316 return GNUNET_SYSERR;
1319 if (0 == (o->prop_type = parse_property_string(prop)))
1321 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1322 op_counter, op_name, e->id);
1323 GNUNET_free (op_name);
1325 return GNUNET_SYSERR;
1329 GNUNET_free (op_name);
1332 "Found operation %s: [%llu:%llu] %s = %llu\n",
1333 "START_SET_PROPERTY", o->peer_id, o->address_id,
1334 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1340 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1344 const struct GNUNET_CONFIGURATION_Handle *cfg)
1350 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1351 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1352 sec_name, op_name, &o->peer_id))
1354 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1355 op_counter, "STOP_SET_PROPERTY", op_name);
1356 GNUNET_free (op_name);
1357 return GNUNET_SYSERR;
1359 GNUNET_free (op_name);
1362 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1363 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1364 sec_name, op_name, &o->address_id))
1366 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1367 op_counter, "STOP_SET_PROPERTY", op_name);
1368 GNUNET_free (op_name);
1369 return GNUNET_SYSERR;
1371 GNUNET_free (op_name);
1374 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1375 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1376 sec_name, op_name, &pref))
1378 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1379 op_counter, "STOP_SET_PROPERTY", op_name);
1380 GNUNET_free (op_name);
1381 GNUNET_free_non_null (pref);
1382 return GNUNET_SYSERR;
1385 if (0 == (o->prop_type = parse_property_string(pref)))
1387 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1388 op_counter, op_name, e->id);
1389 GNUNET_free (op_name);
1391 GNUNET_free_non_null (pref);
1392 return GNUNET_SYSERR;
1396 GNUNET_free (op_name);
1399 "Found operation %s: [%llu:%llu] %s\n",
1400 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1401 GNUNET_ATS_print_property_type (o->prop_type));
1408 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1412 const struct GNUNET_CONFIGURATION_Handle *cfg)
1417 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1418 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1419 sec_name, op_name, &o->peer_id))
1421 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1422 op_counter, "START_REQUEST", op_name);
1423 GNUNET_free (op_name);
1424 return GNUNET_SYSERR;
1426 GNUNET_free (op_name);
1431 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1435 const struct GNUNET_CONFIGURATION_Handle *cfg)
1440 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1441 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1442 sec_name, op_name, &o->peer_id))
1444 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1445 op_counter, "STOP_REQUEST", op_name);
1446 GNUNET_free (op_name);
1447 return GNUNET_SYSERR;
1449 GNUNET_free (op_name);
1455 load_episode (struct Experiment *e, struct Episode *cur,
1456 struct GNUNET_CONFIGURATION_Handle *cfg)
1458 struct GNUNET_ATS_TEST_Operation *o;
1464 fprintf (stderr, "Parsing episode %u\n",cur->id);
1465 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1469 /* Load operation */
1470 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1471 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1472 sec_name, op_name, &op))
1474 GNUNET_free (op_name);
1477 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1478 /* operations = set_rate, start_send, stop_send, set_preference */
1479 if (0 == strcmp (op, "address_add"))
1481 o->type = SOLVER_OP_ADD_ADDRESS;
1482 res = load_op_add_address (o, cur,
1483 op_counter, sec_name, cfg);
1485 else if (0 == strcmp (op, "address_del"))
1487 o->type = SOLVER_OP_DEL_ADDRESS;
1488 res = load_op_del_address (o, cur,
1489 op_counter, sec_name, cfg);
1491 else if (0 == strcmp (op, "start_set_property"))
1493 o->type = SOLVER_OP_START_SET_PROPERTY;
1494 res = load_op_start_set_property (o, cur,
1495 op_counter, sec_name, cfg);
1497 else if (0 == strcmp (op, "stop_set_property"))
1499 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1500 res = load_op_stop_set_property (o, cur,
1501 op_counter, sec_name, cfg);
1503 else if (0 == strcmp (op, "start_set_preference"))
1505 o->type = SOLVER_OP_START_SET_PREFERENCE;
1506 res = load_op_start_set_preference (o, cur,
1507 op_counter, sec_name, cfg);
1509 else if (0 == strcmp (op, "stop_set_preference"))
1511 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1512 res = load_op_stop_set_preference (o, cur,
1513 op_counter, sec_name, cfg);
1515 else if (0 == strcmp (op, "start_request"))
1517 o->type = SOLVER_OP_START_REQUEST;
1518 res = load_op_start_request (o, cur,
1519 op_counter, sec_name, cfg);
1521 else if (0 == strcmp (op, "stop_request"))
1523 o->type = SOLVER_OP_STOP_REQUEST;
1524 res = load_op_stop_request(o, cur,
1525 op_counter, sec_name, cfg);
1529 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1530 op_counter, op, cur->id);
1531 res = GNUNET_SYSERR;
1535 GNUNET_free (op_name);
1537 if (GNUNET_SYSERR == res)
1540 GNUNET_free (sec_name);
1541 return GNUNET_SYSERR;
1544 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1547 GNUNET_free (sec_name);
1552 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1556 struct GNUNET_TIME_Relative e_duration;
1557 struct Episode *cur;
1558 struct Episode *last;
1564 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1565 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1566 sec_name, "duration", &e_duration))
1568 fprintf (stderr, "Missing duration in episode %u \n",e_counter);
1569 GNUNET_free (sec_name);
1573 cur = GNUNET_new (struct Episode);
1574 cur->duration = e_duration;
1575 cur->id = e_counter;
1577 if (GNUNET_OK != load_episode (e, cur, cfg))
1579 GNUNET_free (sec_name);
1581 return GNUNET_SYSERR;
1584 fprintf (stderr, "Found episode %u with duration %s \n",
1586 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1588 /* Update experiment */
1590 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1591 /* Put in linked list */
1597 GNUNET_free (sec_name);
1605 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1607 struct Experiment *e = cls;
1608 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1609 fprintf (stderr, "Experiment timeout!\n");
1611 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1613 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1614 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1617 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1621 struct ATS_Address *
1622 create_ats_address (const struct GNUNET_PeerIdentity *peer,
1623 const char *plugin_name,
1624 const void *plugin_addr, size_t plugin_addr_len,
1625 uint32_t session_id)
1627 struct ATS_Address *aa = NULL;
1629 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
1631 aa->addr_len = plugin_addr_len;
1633 aa->plugin = (char *) &aa[1] + plugin_addr_len;
1634 memcpy (&aa[1], plugin_addr, plugin_addr_len);
1635 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
1636 aa->session_id = session_id;
1637 aa->active = GNUNET_NO;
1638 aa->used = GNUNET_NO;
1639 aa->solver_information = NULL;
1640 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
1641 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
1648 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1651 struct TestAddress *a;
1653 if (NULL == (p = find_peer_by_id (op->peer_id)))
1655 p = GNUNET_new (struct TestPeer);
1656 p->id = op->peer_id;
1657 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
1658 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
1661 if (NULL != (a = find_address_by_id (p, op->address_id)))
1663 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
1664 op->address_id, op->peer_id);
1667 a = GNUNET_new (struct TestAddress);
1668 a->aid = op->address_id;
1669 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
1670 strlen (op->address) + 1, op->address_session);
1671 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
1672 GNUNET_CONTAINER_DLL_insert (p->addr_head, p->addr_tail, a);
1674 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
1675 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1677 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u\n",
1678 op->address_id, op->peer_id);
1680 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
1686 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1689 struct TestAddress *a;
1690 struct AddressLookupCtx ctx;
1692 if (NULL == (p = find_peer_by_id (op->peer_id)))
1695 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1696 "Deleting address for unknown peer %u\n", op->peer_id);
1700 ctx.plugin = op->plugin;
1701 ctx.addr = op->address;
1703 GNUNET_CONTAINER_multipeermap_get_multiple (sh->addresses, &p->peer_id,
1704 find_address_it, &ctx);
1705 if (NULL == ctx.res)
1708 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1709 "Deleting unknown address for peer %u\n", op->peer_id);
1713 if (NULL == (a = find_address_by_id (p, op->address_id)))
1716 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1717 "Deleting address for unknown peer %u\n", op->peer_id);
1720 GNUNET_CONTAINER_DLL_remove (p->addr_head, p->addr_tail, a);
1722 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, ctx.res);
1724 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
1725 op->address_id, op->peer_id);
1727 sh->env.sf.s_del (sh->solver, ctx.res, GNUNET_NO);
1728 GNUNET_free (ctx.res);
1733 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1735 struct PropertyGenerator *pg;
1737 struct TestAddress *a;
1739 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
1741 GNUNET_ATS_solver_generate_property_stop (pg);
1745 if (NULL == (p = find_peer_by_id (op->peer_id)))
1748 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1749 "Starting property generation for unknown peer %u\n", op->peer_id);
1753 if (NULL == (a = find_address_by_id (p, op->address_id)))
1756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1757 "Setting property for unknown address %u\n", op->peer_id);
1761 GNUNET_ATS_solver_generate_property_start (op->peer_id,
1773 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1775 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
1778 GNUNET_ATS_solver_generate_property_stop (pg);
1782 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1784 struct PreferenceGenerator *pg;
1786 if (NULL != (pg = find_pref_gen (op->peer_id, op->address_id, op->pref_type)))
1788 GNUNET_ATS_solver_generate_preferences_stop (pg);
1792 if (NULL == (p = find_peer_by_id (op->peer_id)))
1795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1796 "Starting preference generation for unknown peer %u\n", op->peer_id);
1800 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
1812 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1814 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, op->address_id,
1817 GNUNET_ATS_solver_generate_preferences_stop (pg);
1822 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
1825 const struct ATS_Address *res;
1827 if (NULL == (p = find_peer_by_id (op->peer_id)))
1830 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1831 "Requesting address for unknown peer %u\n", op->peer_id);
1835 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
1838 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
1847 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
1851 if (NULL == (p = find_peer_by_id (op->peer_id)))
1854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1855 "Requesting address for unknown peer %u\n", op->peer_id);
1859 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
1862 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
1865 static void enforce_episode (struct Episode *ep)
1867 struct GNUNET_ATS_TEST_Operation *cur;
1868 for (cur = ep->head; NULL != cur; cur = cur->next)
1870 switch (cur->type) {
1871 case SOLVER_OP_ADD_ADDRESS:
1872 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1873 print_op (cur->type), cur->peer_id, cur->address_id);
1874 enforce_add_address (cur);
1876 case SOLVER_OP_DEL_ADDRESS:
1877 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1878 print_op (cur->type), cur->peer_id, cur->address_id);
1879 enforce_del_address (cur);
1881 case SOLVER_OP_START_SET_PROPERTY:
1882 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1883 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1884 enforce_start_property (cur);
1886 case SOLVER_OP_STOP_SET_PROPERTY:
1887 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1888 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1889 enforce_stop_property (cur);
1891 case SOLVER_OP_START_SET_PREFERENCE:
1892 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1893 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1894 enforce_start_preference (cur);
1896 case SOLVER_OP_STOP_SET_PREFERENCE:
1897 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1898 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1899 enforce_stop_preference (cur);
1901 case SOLVER_OP_START_REQUEST:
1902 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1903 print_op (cur->type), cur->peer_id);
1904 enforce_start_request (cur);
1906 case SOLVER_OP_STOP_REQUEST:
1907 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
1908 print_op (cur->type), cur->peer_id);
1909 enforce_stop_request (cur);
1918 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1920 struct Experiment *e = cls;
1921 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1922 if (NULL != e->ep_done_cb)
1923 e->ep_done_cb (e->cur);
1925 /* Scheduling next */
1926 e->cur = e->cur->next;
1930 fprintf (stderr, "Last episode done!\n");
1931 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1933 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1934 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1936 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
1940 fprintf (stderr, "Running episode %u with timeout %s\n",
1942 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1943 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1944 &timeout_episode, e);
1945 enforce_episode(e->cur);
1952 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1953 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
1954 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
1956 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
1957 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
1958 e->e_done_cb = e_done_cb;
1959 e->ep_done_cb = ep_done_cb;
1960 e->start_time = GNUNET_TIME_absolute_get();
1962 /* Start total time out */
1963 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
1964 &timeout_experiment, e);
1968 if (NULL == e->start)
1974 fprintf (stderr, "Running episode %u with timeout %s\n",
1976 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1977 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1978 &timeout_episode, e);
1979 enforce_episode(e->cur);
1984 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1986 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1988 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1989 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1991 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1993 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1994 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1998 GNUNET_CONFIGURATION_destroy(e->cfg);
2001 free_experiment (e);
2006 GNUNET_ATS_solvers_experimentation_load (char *filename)
2008 struct Experiment *e;
2009 struct GNUNET_CONFIGURATION_Handle *cfg;
2012 cfg = GNUNET_CONFIGURATION_create();
2013 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2015 fprintf (stderr, "Failed to load `%s'\n", filename);
2016 GNUNET_CONFIGURATION_destroy (cfg);
2020 e = create_experiment ();
2022 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2025 fprintf (stderr, "Invalid %s", "name");
2026 free_experiment (e);
2030 fprintf (stderr, "Experiment name: `%s'\n", e->name);
2032 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2033 "cfg_file", &e->cfg_file))
2035 fprintf (stderr, "Invalid %s", "cfg_file");
2036 free_experiment (e);
2041 fprintf (stderr, "Experiment configuration: `%s'\n", e->cfg_file);
2042 e->cfg = GNUNET_CONFIGURATION_create();
2043 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2045 fprintf (stderr, "Invalid configuration %s", "cfg_file");
2046 free_experiment (e);
2052 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2053 "log_freq", &e->log_freq))
2055 fprintf (stderr, "Invalid %s", "log_freq");
2056 free_experiment (e);
2060 fprintf (stderr, "Experiment logging frequency: `%s'\n",
2061 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2063 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2064 "max_duration", &e->max_duration))
2066 fprintf (stderr, "Invalid %s", "max_duration");
2067 free_experiment (e);
2071 fprintf (stderr, "Experiment duration: `%s'\n",
2072 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2074 if (GNUNET_SYSERR == load_episodes (e, cfg))
2076 GNUNET_ATS_solvers_experimentation_stop (e);
2077 GNUNET_CONFIGURATION_destroy (cfg);
2079 fprintf (stderr, "Failed to load experiment\n");
2082 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
2084 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2086 GNUNET_CONFIGURATION_destroy (cfg);
2097 free_all_it (void *cls,
2098 const struct GNUNET_PeerIdentity *key,
2101 struct ATS_Address *address = value;
2102 GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses, key, value);
2103 GNUNET_free (address);
2109 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2111 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2113 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2114 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2115 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2116 GNUNET_free (sh->plugin);
2121 * Load quotas for networks from configuration
2123 * @param cfg configuration handle
2124 * @param out_dest where to write outbound quotas
2125 * @param in_dest where to write inbound quotas
2126 * @param dest_length length of inbound and outbound arrays
2127 * @return number of networks loaded
2130 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2131 unsigned long long *out_dest,
2132 unsigned long long *in_dest,
2135 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2136 char * entry_in = NULL;
2137 char * entry_out = NULL;
2138 char * quota_out_str;
2139 char * quota_in_str;
2143 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2147 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2148 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2151 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2154 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2156 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2159 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2161 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2164 if (GNUNET_NO == res)
2166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2167 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2168 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2173 network_str[c], out_dest[c]);
2175 GNUNET_free (quota_out_str);
2179 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2180 network_str[c], GNUNET_ATS_DefaultBandwidth);
2181 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2185 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2188 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2190 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2193 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2195 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2198 if (GNUNET_NO == res)
2200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2201 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2202 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2207 network_str[c], in_dest[c]);
2209 GNUNET_free (quota_in_str);
2213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2214 network_str[c], GNUNET_ATS_DefaultBandwidth);
2215 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2217 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]);
2218 GNUNET_free (entry_out);
2219 GNUNET_free (entry_in);
2221 return GNUNET_ATS_NetworkTypeCount;
2225 * Information callback for the solver
2227 * @param op the solver operation
2228 * @param stat status of the solver operation
2229 * @param add additional solver information
2232 solver_info_cb (void *cls,
2233 enum GAS_Solver_Operation op,
2234 enum GAS_Solver_Status stat,
2235 enum GAS_Solver_Additional_Information add)
2240 add_info = "GAS_INFO_NONE";
2243 add_info = "GAS_INFO_MLP_FULL";
2245 case GAS_INFO_UPDATED:
2246 add_info = "GAS_INFO_MLP_UPDATED";
2248 case GAS_INFO_PROP_ALL:
2249 add_info = "GAS_INFO_PROP_ALL";
2251 case GAS_INFO_PROP_SINGLE:
2252 add_info = "GAS_INFO_PROP_SINGLE";
2255 add_info = "INVALID";
2261 case GAS_OP_SOLVE_START:
2262 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2263 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2264 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2266 case GAS_OP_SOLVE_STOP:
2267 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2268 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2269 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2272 case GAS_OP_SOLVE_SETUP_START:
2273 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2274 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2275 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2278 case GAS_OP_SOLVE_SETUP_STOP:
2279 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2280 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2281 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2284 case GAS_OP_SOLVE_MLP_LP_START:
2285 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2286 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2287 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2289 case GAS_OP_SOLVE_MLP_LP_STOP:
2290 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2291 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2292 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2295 case GAS_OP_SOLVE_MLP_MLP_START:
2296 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2297 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2298 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2300 case GAS_OP_SOLVE_MLP_MLP_STOP:
2301 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2302 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2303 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2305 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2306 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2307 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2308 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2310 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2311 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2312 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2313 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2321 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2323 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2324 (0 == ntohl (address->assigned_bw_in.value__)) )
2326 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2327 "Solver notified to disconnect peer `%s'\n",
2328 GNUNET_i2s (&address->peer));
2332 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2333 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2334 GNUNET_i2s (&address->peer),
2336 (unsigned int) ntohl (address->assigned_bw_out.value__),
2337 (unsigned int) ntohl (address->assigned_bw_in.value__));
2338 /*if (GNUNET_YES == ph.bulk_running)
2344 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2346 return GAS_normalization_get_preferences_by_peer (id);
2351 get_property_cb (void *cls, const struct ATS_Address *address)
2353 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2357 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
2358 uint32_t type, double prop_rel)
2360 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2361 "Normalized property %s for peer `%s' changed to %.3f \n",
2362 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
2365 sh->env.sf.s_address_update_property (sh->solver, address, type, 0, prop_rel);
2370 normalized_preference_changed_cb (void *cls,
2371 const struct GNUNET_PeerIdentity *peer,
2372 enum GNUNET_ATS_PreferenceKind kind,
2375 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2376 "Normalized preference %s for peer `%s' changed to %.3f \n",
2377 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
2380 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
2384 struct SolverHandle *
2385 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2387 struct SolverHandle *sh;
2391 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2392 solver_str = "proportional";
2394 case GNUNET_ATS_SOLVER_MLP:
2397 case GNUNET_ATS_SOLVER_RIL:
2406 sh = GNUNET_new (struct SolverHandle);
2407 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2409 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2410 /* setup environment */
2411 sh->env.cfg = e->cfg;
2412 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2413 sh->env.addresses = sh->addresses;
2414 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2415 sh->env.get_preferences = &get_preferences_cb;
2416 sh->env.get_property = &get_property_cb;
2417 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2418 sh->env.info_cb = &solver_info_cb;
2419 sh->env.info_cb_cls = NULL;
2422 /* start normalization */
2423 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
2424 &normalized_property_changed_cb, NULL );
2427 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2428 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2431 GNUNET_free (sh->plugin);
2437 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2438 if (NULL == sh->solver)
2440 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2442 GNUNET_free (sh->plugin);
2453 struct TestPeer *cur;
2454 struct TestPeer *next;
2456 struct TestAddress *cur_a;
2457 struct TestAddress *next_a;
2460 GNUNET_ATS_solver_logging_stop (l);
2462 /* Stop all preference generation */
2463 GNUNET_ATS_solver_generate_preferences_stop_all ();
2465 /* Stop all property generation */
2466 GNUNET_ATS_solver_generate_property_stop_all ();
2468 /* Clean up experiment */
2471 GNUNET_ATS_solvers_experimentation_stop (e);
2477 GNUNET_ATS_solver_logging_free (l);
2482 while (NULL != (cur = next))
2485 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
2486 next_a = cur->addr_head;
2487 while (NULL != (cur_a = next_a))
2489 next_a = cur_a->next;
2490 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
2491 GNUNET_free (cur_a);
2498 GNUNET_ATS_solvers_solver_stop (sh);
2507 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
2509 if (GNUNET_OK == success)
2510 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
2511 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
2513 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
2517 evaluate (duration);
2519 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
2523 GNUNET_ATS_TEST_logging_stop (l);
2524 GNUNET_ATS_TEST_logging_clean_up (l);
2528 GNUNET_SCHEDULER_add_now (&done, NULL);
2532 episode_done_cb (struct Episode *ep)
2534 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
2547 GNUNET_ATS_solvers_experimentation_stop (e);
2552 GNUNET_ATS_solvers_solver_stop (sh);
2558 run (void *cls, char * const *args, const char *cfgfile,
2559 const struct GNUNET_CONFIGURATION_Handle *cfg)
2561 enum GNUNET_ATS_Solvers solver;
2563 if (NULL == opt_exp_file)
2565 fprintf (stderr, "No experiment given ...\n");
2571 if (NULL == opt_solver)
2573 fprintf (stderr, "No solver given ...\n");
2579 if (0 == strcmp(opt_solver, "mlp"))
2581 solver = GNUNET_ATS_SOLVER_MLP;
2583 else if (0 == strcmp(opt_solver, "proportional"))
2585 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
2587 else if (0 == strcmp(opt_solver, "ril"))
2589 solver = GNUNET_ATS_SOLVER_RIL;
2593 fprintf (stderr, "No solver given ...");
2599 /* load experiment */
2600 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
2603 fprintf (stderr, "Failed to load experiment ...\n");
2610 sh = GNUNET_ATS_solvers_solver_start (solver);
2613 fprintf (stderr, "Failed to start solver ...\n");
2620 l = GNUNET_ATS_solver_logging_start (e->log_freq);
2622 /* run experiment */
2623 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2624 experiment_done_cb);
2631 * Main function of the benchmark
2633 * @param argc argument count
2634 * @param argv argument values
2637 main (int argc, char *argv[])
2639 opt_exp_file = NULL;
2641 opt_log = GNUNET_NO;
2642 opt_plot = GNUNET_NO;
2646 static struct GNUNET_GETOPT_CommandLineOption options[] =
2648 { 's', "solver", NULL,
2649 gettext_noop ("solver to use"),
2650 1, &GNUNET_GETOPT_set_string, &opt_solver},
2651 { 'e', "experiment", NULL,
2652 gettext_noop ("experiment to use"),
2653 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2654 { 'e', "experiment", NULL,
2655 gettext_noop ("experiment to use"),
2656 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2657 GNUNET_GETOPT_OPTION_END
2660 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
2661 NULL, options, &run, argv[0]);
2665 /* end of file ats-testing-experiment.c*/