2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet-ats-solver-eval.h"
31 #define BIG_M_STRING "unlimited"
33 static struct Experiment *e;
35 static struct GNUNET_ATS_TESTING_SolverHandle *sh;
38 * cmd option -e: experiment file
40 static char *opt_exp_file;
42 static char *opt_solver;
45 * cmd option -l: enable logging
50 * cmd option -p: enable plots
55 * cmd option -v: verbose logs
57 static int opt_verbose;
69 print_op (enum OperationType op)
72 case SOLVER_OP_ADD_ADDRESS:
74 case SOLVER_OP_DEL_ADDRESS:
76 case SOLVER_OP_START_SET_PREFERENCE:
77 return "START_SET_PREFERENCE";
78 case SOLVER_OP_STOP_SET_PREFERENCE:
79 return "STOP_STOP_PREFERENCE";
80 case SOLVER_OP_START_SET_PROPERTY:
81 return "START_SET_PROPERTY";
82 case SOLVER_OP_STOP_SET_PROPERTY:
83 return "STOP_SET_PROPERTY";
91 static struct Experiment *
95 e = GNUNET_new (struct Experiment);
100 e->total_duration = GNUNET_TIME_UNIT_ZERO;
105 free_experiment (struct Experiment *e)
108 struct Episode *next;
109 struct GNUNET_ATS_TEST_Operation *cur_o;
110 struct GNUNET_ATS_TEST_Operation *next_o;
113 for (cur = next; NULL != cur; cur = next)
118 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
120 next_o = cur_o->next;
121 GNUNET_free_non_null (cur_o->address);
122 GNUNET_free_non_null (cur_o->plugin);
128 GNUNET_free_non_null (e->name);
129 GNUNET_free_non_null (e->cfg_file);
135 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
139 const struct GNUNET_CONFIGURATION_Handle *cfg)
144 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
145 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
146 sec_name, op_name, &o->peer_id))
148 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
149 op_counter, "ADD_ADDRESS", op_name);
150 GNUNET_free (op_name);
151 return GNUNET_SYSERR;
153 GNUNET_free (op_name);
156 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
157 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
158 sec_name, op_name, &o->address_id))
160 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
161 op_counter, "ADD_ADDRESS", op_name);
162 GNUNET_free (op_name);
163 return GNUNET_SYSERR;
165 GNUNET_free (op_name);
168 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
169 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
170 sec_name, op_name, &o->plugin))
172 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
173 op_counter, "ADD_ADDRESS", op_name);
174 GNUNET_free (op_name);
175 return GNUNET_SYSERR;
177 GNUNET_free (op_name);
180 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
181 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
182 sec_name, op_name, &o->address))
184 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
185 op_counter, "ADD_ADDRESS", op_name);
186 GNUNET_free (op_name);
187 return GNUNET_SYSERR;
189 GNUNET_free (op_name);
192 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
193 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
194 sec_name, op_name, &o->address_session))
196 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
197 op_counter, "ADD_ADDRESS", op_name);
198 GNUNET_free (op_name);
199 return GNUNET_SYSERR;
201 GNUNET_free (op_name);
204 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
205 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
206 sec_name, op_name, &o->address_network))
208 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
209 op_counter, "ADD_ADDRESS", op_name);
210 GNUNET_free (op_name);
211 return GNUNET_SYSERR;
213 GNUNET_free (op_name);
216 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
217 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
223 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
227 const struct GNUNET_CONFIGURATION_Handle *cfg)
232 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
233 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
234 sec_name, op_name, &o->peer_id))
236 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
237 op_counter, "DEL_ADDRESS", op_name);
238 GNUNET_free (op_name);
239 return GNUNET_SYSERR;
241 GNUNET_free (op_name);
244 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
245 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
246 sec_name, op_name, &o->address_id))
248 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
249 op_counter, "DEL_ADDRESS", op_name);
250 GNUNET_free (op_name);
251 return GNUNET_SYSERR;
253 GNUNET_free (op_name);
256 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
257 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
258 sec_name, op_name, &o->plugin))
260 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
261 op_counter, "DEL_ADDRESS", op_name);
262 GNUNET_free (op_name);
263 return GNUNET_SYSERR;
265 GNUNET_free (op_name);
268 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
269 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
270 sec_name, op_name, &o->address))
272 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
273 op_counter, "DEL_ADDRESS", op_name);
274 GNUNET_free (op_name);
275 return GNUNET_SYSERR;
277 GNUNET_free (op_name);
280 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
281 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
282 sec_name, op_name, &o->address_session))
284 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
285 op_counter, "DEL_ADDRESS", op_name);
286 GNUNET_free (op_name);
287 return GNUNET_SYSERR;
289 GNUNET_free (op_name);
292 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
293 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
294 sec_name, op_name, &o->address_network))
296 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
297 op_counter, "DEL_ADDRESS", op_name);
298 GNUNET_free (op_name);
299 return GNUNET_SYSERR;
301 GNUNET_free (op_name);
304 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
305 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
310 static enum GNUNET_ATS_Property
311 parse_preference_string (const char * str)
314 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
316 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
317 if (0 == strcmp(str, props[c]))
323 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
327 const struct GNUNET_CONFIGURATION_Handle *cfg)
334 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
335 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
336 sec_name, op_name, &o->peer_id))
338 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
339 op_counter, "START_SET_PREFERENCE", op_name);
340 GNUNET_free (op_name);
341 return GNUNET_SYSERR;
343 GNUNET_free (op_name);
346 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
347 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
348 sec_name, op_name, &o->address_id))
350 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
351 op_counter, "START_SET_PREFERENCE", op_name);
352 GNUNET_free (op_name);
353 return GNUNET_SYSERR;
355 GNUNET_free (op_name);
358 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
359 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
360 sec_name, op_name, &type)) )
362 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
363 op_counter, "START_SET_PREFERENCE", op_name);
364 GNUNET_free (op_name);
365 return GNUNET_SYSERR;
368 /* Load arguments for set_rate, start_send, set_preference */
369 if (0 == strcmp (type, "constant"))
371 o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
373 else if (0 == strcmp (type, "linear"))
375 o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
377 else if (0 == strcmp (type, "sinus"))
379 o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
381 else if (0 == strcmp (type, "random"))
383 o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
387 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
388 op_counter, op_name, e->id);
390 GNUNET_free (op_name);
391 return GNUNET_SYSERR;
394 GNUNET_free (op_name);
398 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
399 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
400 sec_name, op_name, &o->base_rate))
402 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
403 op_counter, op_name, e->id);
404 GNUNET_free (op_name);
405 return GNUNET_SYSERR;
407 GNUNET_free (op_name);
411 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
412 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
413 sec_name, op_name, &o->max_rate))
415 if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
416 (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
417 (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
419 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
420 op_counter, op_name, e->id);
421 GNUNET_free (op_name);
422 return GNUNET_SYSERR;
425 GNUNET_free (op_name);
428 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
429 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
430 sec_name, op_name, &o->period))
432 o->period = e->duration;
434 GNUNET_free (op_name);
437 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
438 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
439 sec_name, op_name, &o->frequency))
441 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
442 op_counter, op_name, e->id);
443 GNUNET_free (op_name);
444 return GNUNET_SYSERR;
446 GNUNET_free (op_name);
449 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
450 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
451 sec_name, op_name, &pref))
453 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
454 op_counter, op_name, e->id);
455 GNUNET_free (op_name);
456 return GNUNET_SYSERR;
459 if (0 == (o->pref_type = parse_preference_string(pref)))
461 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
462 op_counter, op_name, e->id);
463 GNUNET_free (op_name);
465 return GNUNET_SYSERR;
468 GNUNET_free (op_name);
471 "Found operation %s: [%llu:%llu]: %s = %llu\n",
472 "START_SET_PREFERENCE", o->peer_id, o->address_id,
473 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
479 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
483 const struct GNUNET_CONFIGURATION_Handle *cfg)
489 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
490 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
491 sec_name, op_name, &o->peer_id))
493 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
494 op_counter, "STOP_SET_PREFERENCE", op_name);
495 GNUNET_free (op_name);
496 return GNUNET_SYSERR;
498 GNUNET_free (op_name);
501 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
502 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
503 sec_name, op_name, &o->address_id))
505 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
506 op_counter, "STOP_SET_PREFERENCE", op_name);
507 GNUNET_free (op_name);
508 return GNUNET_SYSERR;
510 GNUNET_free (op_name);
513 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
514 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
515 sec_name, op_name, &pref))
517 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
518 op_counter, "STOP_SET_PREFERENCE", op_name);
519 GNUNET_free (op_name);
520 return GNUNET_SYSERR;
523 if (0 == (o->pref_type = parse_preference_string(pref)))
525 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
526 op_counter, op_name, e->id);
527 GNUNET_free (op_name);
529 return GNUNET_SYSERR;
532 GNUNET_free (op_name);
535 "Found operation %s: [%llu:%llu]: %s\n",
536 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
537 GNUNET_ATS_print_preference_type(o->pref_type));
541 static enum GNUNET_ATS_Property
542 parse_property_string (const char * str)
545 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
547 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
548 if (0 == strcmp(str, props[c]))
554 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
558 const struct GNUNET_CONFIGURATION_Handle *cfg)
565 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
566 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
567 sec_name, op_name, &o->peer_id))
569 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
570 op_counter, "START_SET_PROPERTY", op_name);
571 GNUNET_free (op_name);
572 return GNUNET_SYSERR;
574 GNUNET_free (op_name);
577 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
578 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
579 sec_name, op_name, &o->address_id))
581 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
582 op_counter, "START_SET_PROPERTY", op_name);
583 GNUNET_free (op_name);
584 return GNUNET_SYSERR;
586 GNUNET_free (op_name);
589 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
590 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
591 sec_name, op_name, &type)) )
593 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
594 op_counter, "START_SET_PROPERTY", op_name);
595 GNUNET_free (op_name);
596 return GNUNET_SYSERR;
599 /* Load arguments for set_rate, start_send, set_preference */
600 if (0 == strcmp (type, "constant"))
602 o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
604 else if (0 == strcmp (type, "linear"))
606 o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
608 else if (0 == strcmp (type, "sinus"))
610 o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
612 else if (0 == strcmp (type, "random"))
614 o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
618 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
619 op_counter, op_name, e->id);
621 GNUNET_free (op_name);
622 return GNUNET_SYSERR;
625 GNUNET_free (op_name);
629 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
630 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
631 sec_name, op_name, &o->base_rate))
633 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
634 op_counter, op_name, e->id);
635 GNUNET_free (op_name);
636 return GNUNET_SYSERR;
638 GNUNET_free (op_name);
642 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
643 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
644 sec_name, op_name, &o->max_rate))
646 if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
647 (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
648 (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
650 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
651 op_counter, op_name, e->id);
652 GNUNET_free (op_name);
653 return GNUNET_SYSERR;
656 GNUNET_free (op_name);
659 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
660 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
661 sec_name, op_name, &o->period))
663 o->period = e->duration;
665 GNUNET_free (op_name);
668 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
669 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
670 sec_name, op_name, &o->frequency))
672 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
673 op_counter, op_name, e->id);
674 GNUNET_free (op_name);
675 return GNUNET_SYSERR;
677 GNUNET_free (op_name);
680 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
681 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
682 sec_name, op_name, &prop))
684 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
685 op_counter, op_name, e->id);
686 GNUNET_free (op_name);
687 GNUNET_free_non_null (prop);
688 return GNUNET_SYSERR;
691 if (0 == (o->prop_type = parse_property_string(prop)))
693 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
694 op_counter, op_name, e->id);
695 GNUNET_free (op_name);
697 return GNUNET_SYSERR;
701 GNUNET_free (op_name);
704 "Found operation %s: [%llu:%llu] %s = %llu\n",
705 "START_SET_PROPERTY", o->peer_id, o->address_id,
706 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
712 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
716 const struct GNUNET_CONFIGURATION_Handle *cfg)
722 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
723 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
724 sec_name, op_name, &o->peer_id))
726 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
727 op_counter, "STOP_SET_PROPERTY", op_name);
728 GNUNET_free (op_name);
729 return GNUNET_SYSERR;
731 GNUNET_free (op_name);
734 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
735 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
736 sec_name, op_name, &o->address_id))
738 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
739 op_counter, "STOP_SET_PROPERTY", op_name);
740 GNUNET_free (op_name);
741 return GNUNET_SYSERR;
743 GNUNET_free (op_name);
746 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
747 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
748 sec_name, op_name, &pref))
750 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
751 op_counter, "STOP_SET_PROPERTY", op_name);
752 GNUNET_free (op_name);
753 GNUNET_free_non_null (pref);
754 return GNUNET_SYSERR;
757 if (0 == (o->prop_type = parse_property_string(pref)))
759 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
760 op_counter, op_name, e->id);
761 GNUNET_free (op_name);
763 GNUNET_free_non_null (pref);
764 return GNUNET_SYSERR;
768 GNUNET_free (op_name);
771 "Found operation %s: [%llu:%llu] %s\n",
772 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
773 GNUNET_ATS_print_property_type (o->prop_type));
779 load_episode (struct Experiment *e, struct Episode *cur,
780 struct GNUNET_CONFIGURATION_Handle *cfg)
782 struct GNUNET_ATS_TEST_Operation *o;
787 fprintf (stderr, "Parsing episode %u\n",cur->id);
788 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
793 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
794 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
795 sec_name, op_name, &op))
797 GNUNET_free (op_name);
800 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
801 /* operations = set_rate, start_send, stop_send, set_preference */
802 if (0 == strcmp (op, "address_add"))
804 o->type = SOLVER_OP_ADD_ADDRESS;
805 if (GNUNET_SYSERR == load_op_add_address (o, cur,
806 op_counter, sec_name, cfg))
810 GNUNET_free (op_name);
811 GNUNET_free (sec_name);
812 return GNUNET_SYSERR;
815 else if (0 == strcmp (op, "address_del"))
817 o->type = SOLVER_OP_DEL_ADDRESS;
818 if (GNUNET_SYSERR == load_op_del_address (o, cur,
819 op_counter, sec_name, cfg))
823 GNUNET_free (op_name);
824 GNUNET_free (sec_name);
825 return GNUNET_SYSERR;
828 else if (0 == strcmp (op, "start_set_property"))
830 o->type = SOLVER_OP_START_SET_PROPERTY;
831 if (GNUNET_SYSERR == load_op_start_set_property (o, cur,
832 op_counter, sec_name, cfg))
836 GNUNET_free (op_name);
837 GNUNET_free (sec_name);
838 return GNUNET_SYSERR;
841 else if (0 == strcmp (op, "stop_set_property"))
843 o->type = SOLVER_OP_STOP_SET_PROPERTY;
844 if (GNUNET_SYSERR == load_op_stop_set_property (o, cur,
845 op_counter, sec_name, cfg))
849 GNUNET_free (op_name);
850 GNUNET_free (sec_name);
851 return GNUNET_SYSERR;
854 else if (0 == strcmp (op, "start_set_preference"))
856 o->type = SOLVER_OP_START_SET_PREFERENCE;
857 if (GNUNET_SYSERR == load_op_start_set_preference (o, cur,
858 op_counter, sec_name, cfg))
862 GNUNET_free (op_name);
863 GNUNET_free (sec_name);
864 return GNUNET_SYSERR;
867 else if (0 == strcmp (op, "stop_set_preference"))
869 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
870 if (GNUNET_SYSERR == load_op_stop_set_preference (o, cur,
871 op_counter, sec_name, cfg))
875 GNUNET_free (op_name);
876 GNUNET_free (sec_name);
877 return GNUNET_SYSERR;
882 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
883 op_counter, op, cur->id);
886 GNUNET_free (op_name);
887 GNUNET_free (sec_name);
888 return GNUNET_SYSERR;
891 GNUNET_free (op_name);
893 GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
896 GNUNET_free (sec_name);
901 GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
902 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
903 sec_name, op_name, &o->src_id))
905 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
906 op_counter, op, cur->id);
908 GNUNET_free (op_name);
909 return GNUNET_SYSERR;
911 if (o->src_id > (e->num_masters - 1))
913 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
914 o->src_id, op_counter, op, cur->id);
916 GNUNET_free (op_name);
917 return GNUNET_SYSERR;
919 GNUNET_free (op_name);
921 /* Get destination */
922 GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
923 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
924 sec_name, op_name, &o->dest_id))
926 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
927 op_counter, op, cur->id);
929 GNUNET_free (op_name);
930 return GNUNET_SYSERR;
932 if (o->dest_id > (e->num_slaves - 1))
934 fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
935 o->dest_id, op_counter, op, cur->id);
937 GNUNET_free (op_name);
938 return GNUNET_SYSERR;
940 GNUNET_free (op_name);
942 GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
943 if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
944 sec_name, op_name, &type)) &&
945 ((STOP_SEND != o->type) || (STOP_PREFERENCE != o->type)))
947 /* Load arguments for set_rate, start_send, set_preference */
948 if (0 == strcmp (type, "constant"))
950 o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
952 else if (0 == strcmp (type, "linear"))
954 o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
956 else if (0 == strcmp (type, "sinus"))
958 o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
960 else if (0 == strcmp (type, "random"))
962 o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
966 fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
967 op_counter, op, cur->id);
970 GNUNET_free (op_name);
971 return GNUNET_SYSERR;
973 GNUNET_free (op_name);
976 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
977 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
978 sec_name, op_name, &o->base_rate))
980 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
981 op_counter, op, cur->id);
984 GNUNET_free (op_name);
985 return GNUNET_SYSERR;
987 GNUNET_free (op_name);
990 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
991 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
992 sec_name, op_name, &o->max_rate))
994 if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
995 (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
996 (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
998 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
999 op_counter, op, cur->id);
1001 GNUNET_free (op_name);
1003 return GNUNET_SYSERR;
1006 GNUNET_free (op_name);
1009 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1010 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1011 sec_name, op_name, &o->period))
1013 o->period = cur->duration;
1015 GNUNET_free (op_name);
1017 if (START_PREFERENCE == o->type)
1020 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1021 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1022 sec_name, op_name, &o->frequency))
1024 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1025 op_counter, op, cur->id);
1027 GNUNET_free (op_name);
1029 return GNUNET_SYSERR;
1031 GNUNET_free (op_name);
1033 /* Get preference */
1034 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1035 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1036 sec_name, op_name, &pref))
1038 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1039 op_counter, op, cur->id);
1041 GNUNET_free (op_name);
1043 GNUNET_free_non_null (pref);
1044 return GNUNET_SYSERR;
1047 if (0 == strcmp(pref, "bandwidth"))
1048 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
1049 else if (0 == strcmp(pref, "latency"))
1050 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
1053 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1054 op_counter, op, cur->id);
1056 GNUNET_free (op_name);
1059 GNUNET_free_non_null (pref);
1060 return GNUNET_SYSERR;
1063 GNUNET_free (op_name);
1068 if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
1069 (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
1071 if ((o->max_rate - o->base_rate) > o->base_rate)
1073 /* This will cause an underflow */
1076 fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
1079 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
1080 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
1081 op_counter, cur->id, print_op (o->type), o->src_id,
1082 o->dest_id, (NULL != type) ? type : "",
1083 o->base_rate, o->max_rate,
1084 GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
1086 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
1087 op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
1089 GNUNET_free_non_null (type);
1097 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1101 struct GNUNET_TIME_Relative e_duration;
1102 struct Episode *cur;
1103 struct Episode *last;
1109 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1110 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1111 sec_name, "duration", &e_duration))
1113 GNUNET_free (sec_name);
1117 cur = GNUNET_new (struct Episode);
1118 cur->duration = e_duration;
1119 cur->id = e_counter;
1121 if (GNUNET_OK != load_episode (e, cur, cfg))
1123 GNUNET_free (sec_name);
1125 return GNUNET_SYSERR;
1128 fprintf (stderr, "Found episode %u with duration %s \n",
1130 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1132 /* Update experiment */
1134 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1135 /* Put in linked list */
1141 GNUNET_free (sec_name);
1149 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1151 struct Experiment *e = cls;
1152 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1153 fprintf (stderr, "Experiment timeout!\n");
1155 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1157 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1158 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1161 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
1166 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
1169 struct BenchmarkPeer *peer;
1170 struct BenchmarkPartner *partner;
1172 peer = GNUNET_ATS_TEST_get_peer (op->src_id);
1179 partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1180 if (NULL == partner)
1186 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1188 if (NULL != partner->tg)
1190 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
1191 GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
1195 partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
1196 op->tg_type, op->base_rate, op->max_rate, op->period,
1197 GNUNET_TIME_UNIT_FOREVER_REL);
1202 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
1205 struct BenchmarkPartner *p;
1206 p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1213 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1217 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
1218 op->src_id, op->dest_id);
1219 GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
1226 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
1232 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
1238 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
1241 struct BenchmarkPeer *peer;
1242 struct BenchmarkPartner *partner;
1244 peer = GNUNET_ATS_TEST_get_peer (op->src_id);
1251 partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1252 if (NULL == partner)
1258 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1260 if (NULL != partner->pg)
1262 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
1263 op->src_id, op->dest_id);
1264 GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
1268 partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
1269 op->tg_type, op->base_rate, op->max_rate, op->period, op->frequency,
1275 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
1278 struct BenchmarkPartner *p;
1279 p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
1286 fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
1290 fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
1291 op->src_id, op->dest_id);
1292 GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
1298 static void enforce_episode (struct Episode *ep)
1300 struct GNUNET_ATS_TEST_Operation *cur;
1301 for (cur = ep->head; NULL != cur; cur = cur->next)
1303 switch (cur->type) {
1304 case SOLVER_OP_ADD_ADDRESS:
1305 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1306 print_op (cur->type), cur->peer_id, cur->address_id);
1307 enforce_add_address (cur);
1309 case SOLVER_OP_DEL_ADDRESS:
1310 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
1311 print_op (cur->type), cur->peer_id, cur->address_id);
1312 enforce_del_address (cur);
1314 case SOLVER_OP_START_SET_PROPERTY:
1315 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1316 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1317 enforce_start_property (cur);
1319 case SOLVER_OP_STOP_SET_PROPERTY:
1320 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1321 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1322 enforce_stop_property (cur);
1324 case SOLVER_OP_START_SET_PREFERENCE:
1325 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1326 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1327 enforce_start_preference (cur);
1329 case SOLVER_OP_STOP_SET_PREFERENCE:
1330 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
1331 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
1332 enforce_stop_preference (cur);
1341 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
1343 struct Experiment *e = cls;
1344 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1345 if (NULL != e->ep_done_cb)
1346 e->ep_done_cb (e->cur);
1348 /* Scheduling next */
1349 e->cur = e->cur->next;
1353 fprintf (stderr, "Last episode done!\n");
1354 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1356 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1357 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1359 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
1363 fprintf (stderr, "Running episode %u with timeout %s\n",
1365 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1366 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1367 &timeout_episode, e);
1368 enforce_episode(e->cur);
1375 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
1376 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
1377 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
1379 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
1380 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
1381 e->e_done_cb = e_done_cb;
1382 e->ep_done_cb = ep_done_cb;
1383 e->start_time = GNUNET_TIME_absolute_get();
1385 /* Start total time out */
1386 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
1387 &timeout_experiment, e);
1391 if (NULL == e->start)
1397 fprintf (stderr, "Running episode %u with timeout %s\n",
1399 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
1400 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
1401 &timeout_episode, e);
1402 enforce_episode(e->cur);
1407 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
1409 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
1411 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
1412 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1414 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
1416 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
1417 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
1421 GNUNET_CONFIGURATION_destroy(e->cfg);
1424 free_experiment (e);
1429 GNUNET_ATS_solvers_experimentation_load (char *filename)
1431 struct Experiment *e;
1432 struct GNUNET_CONFIGURATION_Handle *cfg;
1435 cfg = GNUNET_CONFIGURATION_create();
1436 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
1438 fprintf (stderr, "Failed to load `%s'\n", filename);
1439 GNUNET_CONFIGURATION_destroy (cfg);
1443 e = create_experiment ();
1445 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
1448 fprintf (stderr, "Invalid %s", "name");
1449 free_experiment (e);
1453 fprintf (stderr, "Experiment name: `%s'\n", e->name);
1455 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
1456 "cfg_file", &e->cfg_file))
1458 fprintf (stderr, "Invalid %s", "cfg_file");
1459 free_experiment (e);
1464 fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
1465 e->cfg = GNUNET_CONFIGURATION_create();
1466 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
1468 fprintf (stderr, "Invalid configuration %s", "cfg_file");
1469 free_experiment (e);
1475 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
1476 "masters", &e->num_masters))
1478 fprintf (stderr, "Invalid %s", "masters");
1479 free_experiment (e);
1483 fprintf (stderr, "Experiment masters: `%llu'\n",
1486 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
1487 "slaves", &e->num_slaves))
1489 fprintf (stderr, "Invalid %s", "slaves");
1490 free_experiment (e);
1494 fprintf (stderr, "Experiment slaves: `%llu'\n",
1497 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
1498 "log_freq", &e->log_freq))
1500 fprintf (stderr, "Invalid %s", "log_freq");
1501 free_experiment (e);
1505 fprintf (stderr, "Experiment logging frequency: `%s'\n",
1506 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
1508 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
1509 "max_duration", &e->max_duration))
1511 fprintf (stderr, "Invalid %s", "max_duration");
1512 free_experiment (e);
1516 fprintf (stderr, "Experiment duration: `%s'\n",
1517 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
1519 if (GNUNET_SYSERR == load_episodes (e, cfg))
1521 GNUNET_ATS_solvers_experimentation_stop (e);
1522 GNUNET_CONFIGURATION_destroy (cfg);
1524 fprintf (stderr, "Failed to load experiment\n");
1527 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
1529 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
1531 GNUNET_CONFIGURATION_destroy (cfg);
1544 struct GNUNET_ATS_TESTING_SolverHandle
1547 struct GNUNET_ATS_PluginEnvironment env;
1549 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
1552 enum GNUNET_ATS_Solvers
1554 GNUNET_ATS_SOLVER_PROPORTIONAL,
1555 GNUNET_ATS_SOLVER_MLP,
1556 GNUNET_ATS_SOLVER_RIL,
1560 GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
1562 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
1564 GNUNET_CONTAINER_multipeermap_destroy(sh->env.addresses);
1565 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
1566 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
1567 GNUNET_free (sh->plugin);
1572 * Load quotas for networks from configuration
1574 * @param cfg configuration handle
1575 * @param out_dest where to write outbound quotas
1576 * @param in_dest where to write inbound quotas
1577 * @param dest_length length of inbound and outbound arrays
1578 * @return number of networks loaded
1581 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
1582 unsigned long long *out_dest,
1583 unsigned long long *in_dest,
1586 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
1587 char * entry_in = NULL;
1588 char * entry_out = NULL;
1589 char * quota_out_str;
1590 char * quota_in_str;
1594 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
1598 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
1599 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
1602 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
1605 if (0 == strcmp(quota_out_str, BIG_M_STRING))
1607 out_dest[c] = GNUNET_ATS_MaxBandwidth;
1610 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
1612 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
1615 if (GNUNET_NO == res)
1617 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
1618 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
1619 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
1624 network_str[c], out_dest[c]);
1626 GNUNET_free (quota_out_str);
1630 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
1631 network_str[c], GNUNET_ATS_DefaultBandwidth);
1632 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
1636 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
1639 if (0 == strcmp(quota_in_str, BIG_M_STRING))
1641 in_dest[c] = GNUNET_ATS_MaxBandwidth;
1644 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
1646 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
1649 if (GNUNET_NO == res)
1651 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
1652 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
1653 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
1657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
1658 network_str[c], in_dest[c]);
1660 GNUNET_free (quota_in_str);
1664 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
1665 network_str[c], GNUNET_ATS_DefaultBandwidth);
1666 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
1669 GNUNET_free (entry_out);
1670 GNUNET_free (entry_in);
1672 return GNUNET_ATS_NetworkTypeCount;
1676 * Information callback for the solver
1678 * @param op the solver operation
1679 * @param stat status of the solver operation
1680 * @param add additional solver information
1683 solver_info_cb (void *cls,
1684 enum GAS_Solver_Operation op,
1685 enum GAS_Solver_Status stat,
1686 enum GAS_Solver_Additional_Information add)
1691 add_info = "GAS_INFO_NONE";
1694 add_info = "GAS_INFO_MLP_FULL";
1696 case GAS_INFO_UPDATED:
1697 add_info = "GAS_INFO_MLP_UPDATED";
1699 case GAS_INFO_PROP_ALL:
1700 add_info = "GAS_INFO_PROP_ALL";
1702 case GAS_INFO_PROP_SINGLE:
1703 add_info = "GAS_INFO_PROP_SINGLE";
1706 add_info = "INVALID";
1712 case GAS_OP_SOLVE_START:
1713 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1714 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
1715 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
1717 case GAS_OP_SOLVE_STOP:
1718 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1719 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
1720 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
1723 case GAS_OP_SOLVE_SETUP_START:
1724 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1725 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
1726 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1729 case GAS_OP_SOLVE_SETUP_STOP:
1730 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1731 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
1732 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1735 case GAS_OP_SOLVE_MLP_LP_START:
1736 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1737 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
1738 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1740 case GAS_OP_SOLVE_MLP_LP_STOP:
1741 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1742 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
1743 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1746 case GAS_OP_SOLVE_MLP_MLP_START:
1747 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1748 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
1749 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1751 case GAS_OP_SOLVE_MLP_MLP_STOP:
1752 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1753 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
1754 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1756 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
1757 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1758 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
1759 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1761 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
1762 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1763 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
1764 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
1772 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1774 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
1775 (0 == ntohl (address->assigned_bw_in.value__)) )
1778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1779 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
1780 GNUNET_i2s (&address->peer),
1782 (unsigned int) ntohl (address->assigned_bw_out.value__),
1783 (unsigned int) ntohl (address->assigned_bw_in.value__));
1784 /*if (GNUNET_YES == ph.bulk_running)
1790 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
1792 return GAS_normalization_get_preferences_by_peer (id);
1797 get_property_cb (void *cls, const struct ATS_Address *address)
1799 return GAS_normalization_get_properties ((struct ATS_Address *) address);
1803 normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
1804 uint32_t type, double prop_rel)
1810 struct GNUNET_ATS_TESTING_SolverHandle *
1811 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
1813 struct GNUNET_ATS_TESTING_SolverHandle *sh;
1815 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
1816 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
1819 case GNUNET_ATS_SOLVER_PROPORTIONAL:
1820 solver_str = "proportional";
1822 case GNUNET_ATS_SOLVER_MLP:
1825 case GNUNET_ATS_SOLVER_RIL:
1834 sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
1835 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
1837 /* setup environment */
1838 sh->env.cfg = e->cfg;
1839 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
1840 sh->env.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1841 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
1842 sh->env.get_preferences = &get_preferences_cb;
1843 sh->env.get_property = &get_property_cb;
1844 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
1845 sh->env.info_cb = &solver_info_cb;
1846 sh->env.info_cb_cls = NULL;
1848 /* start normalization */
1849 GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
1852 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
1853 quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
1856 GNUNET_free (sh->plugin);
1862 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
1863 if (NULL == sh->solver)
1865 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
1867 GNUNET_free (sh->plugin);
1873 sh->addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1881 /* Clean up experiment */
1882 GNUNET_ATS_solvers_experimentation_stop (e);
1891 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
1893 if (GNUNET_OK == success)
1894 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
1895 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
1897 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
1900 // GNUNET_ATS_TEST_logging_stop (l);
1902 /* Stop traffic generation */
1903 // GNUNET_ATS_TEST_generate_traffic_stop_all();
1905 /* Stop all preference generations */
1906 // GNUNET_ATS_TEST_generate_preferences_stop_all ();
1909 evaluate (duration);
1911 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
1915 GNUNET_ATS_TEST_logging_stop (l);
1916 GNUNET_ATS_TEST_logging_clean_up (l);
1920 GNUNET_SCHEDULER_add_now (&done, NULL);
1924 episode_done_cb (struct Episode *ep)
1926 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
1939 GNUNET_ATS_solvers_experimentation_stop (e);
1944 GNUNET_ATS_solvers_solver_stop (sh);
1950 run (void *cls, char * const *args, const char *cfgfile,
1951 const struct GNUNET_CONFIGURATION_Handle *cfg)
1953 enum GNUNET_ATS_Solvers solver;
1955 if (NULL == opt_exp_file)
1957 fprintf (stderr, "No experiment given ...\n");
1963 if (NULL == opt_solver)
1965 fprintf (stderr, "No solver given ...\n");
1971 if (0 == strcmp(opt_solver, "mlp"))
1973 solver = GNUNET_ATS_SOLVER_MLP;
1975 else if (0 == strcmp(opt_solver, "proportional"))
1977 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
1979 else if (0 == strcmp(opt_solver, "ril"))
1981 solver = GNUNET_ATS_SOLVER_RIL;
1985 fprintf (stderr, "No solver given ...");
1991 /* load experiment */
1992 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
1995 fprintf (stderr, "Failed to load experiment ...\n");
2003 sh = GNUNET_ATS_solvers_solver_start (solver);
2006 fprintf (stderr, "Failed to start solver ...\n");
2015 /* run experiment */
2016 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
2017 experiment_done_cb);
2024 * Main function of the benchmark
2026 * @param argc argument count
2027 * @param argv argument values
2030 main (int argc, char *argv[])
2032 opt_exp_file = NULL;
2034 opt_log = GNUNET_NO;
2035 opt_plot = GNUNET_NO;
2039 static struct GNUNET_GETOPT_CommandLineOption options[] =
2041 { 's', "solver", NULL,
2042 gettext_noop ("solver to use"),
2043 1, &GNUNET_GETOPT_set_string, &opt_solver},
2044 { 'e', "experiment", NULL,
2045 gettext_noop ("experiment to use"),
2046 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
2047 { 'e', "experiment", NULL,
2048 gettext_noop ("experiment to use"),
2049 1, &GNUNET_GETOPT_set_one, &opt_verbose},
2050 GNUNET_GETOPT_OPTION_END
2053 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
2057 /* end of file ats-testing-experiment.c*/