glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / ats-tests / ats-testing-experiment.c
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013 GNUnet e.V.
4
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9
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  Affero General Public License for more details.
14  */
15 /**
16  * @file ats-tests/ats-testing-experiment.c
17  * @brief ats benchmark: controlled experiment execution
18  * @author Christian Grothoff
19  * @author Matthias Wachs
20  */
21 #include "platform.h"
22 #include "gnunet_util_lib.h"
23 #include "ats-testing.h"
24
25 const char *
26 print_op (enum OperationType op)
27 {
28   switch (op) {
29     case START_SEND:
30       return "START_SEND";
31     case STOP_SEND:
32       return "STOP_SEND";
33     case START_PREFERENCE:
34       return "START_PREFERENCE";
35     case STOP_PREFERENCE:
36       return "STOP_PREFERENCE";
37     default:
38       break;
39   }
40   return "";
41 }
42
43
44 static struct Experiment *
45 create_experiment ()
46 {
47   struct Experiment *e;
48   e = GNUNET_new (struct Experiment);
49   e->name = NULL;
50   e->num_masters = 0;
51   e->num_slaves = 0;
52   e->start = NULL;
53   e->total_duration = GNUNET_TIME_UNIT_ZERO;
54   return e;
55 }
56
57 static void
58 free_experiment (struct Experiment *e)
59 {
60   struct Episode *cur;
61   struct Episode *next;
62   struct GNUNET_ATS_TEST_Operation *cur_o;
63   struct GNUNET_ATS_TEST_Operation *next_o;
64
65   next = e->start;
66   for (cur = next; NULL != cur; cur = next)
67   {
68     next = cur->next;
69
70     next_o = cur->head;
71     for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
72     {
73       next_o = cur_o->next;
74       GNUNET_free (cur_o);
75     }
76     GNUNET_free (cur);
77   }
78
79   GNUNET_free_non_null (e->name);
80   GNUNET_free_non_null (e->cfg_file);
81   GNUNET_free (e);
82 }
83
84
85 static int
86 load_episode (struct Experiment *e,
87               struct Episode *cur,
88               struct GNUNET_CONFIGURATION_Handle *cfg)
89 {
90   struct GNUNET_ATS_TEST_Operation *o;
91   char *sec_name;
92   char *op_name;
93   char *op;
94   char *type;
95   char *pref;
96   int op_counter = 0;
97
98   fprintf (stderr, "Parsing episode %u\n",cur->id);
99   GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
100
101   while (1)
102   {
103     /* Load operation */
104     GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
105     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
106         sec_name, op_name, &op))
107     {
108       GNUNET_free (op_name);
109       break;
110     }
111     o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
112     /* operations = set_rate, start_send, stop_send, set_preference */
113     if (0 == strcmp (op, "start_send"))
114     {
115       o->type = START_SEND;
116     }
117     else if (0 == strcmp (op, "stop_send"))
118     {
119       o->type = STOP_SEND;
120     }
121     else if (0 == strcmp (op, "start_preference"))
122     {
123       o->type = START_PREFERENCE;
124     }
125     else if (0 == strcmp (op, "stop_preference"))
126     {
127       o->type = STOP_PREFERENCE;
128     }
129     else
130     {
131       fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
132           op_counter, op, cur->id);
133       GNUNET_free (op);
134       GNUNET_free (op_name);
135       GNUNET_free (o);
136       GNUNET_free (sec_name);
137       return GNUNET_SYSERR;
138     }
139     GNUNET_free (op_name);
140
141     /* Get source */
142     GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
143     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
144         sec_name, op_name, &o->src_id))
145     {
146       fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
147           op_counter, op, cur->id);
148       GNUNET_free (op);
149       GNUNET_free (op_name);
150       GNUNET_free (o);
151       GNUNET_free (sec_name);
152       return GNUNET_SYSERR;
153     }
154     if (o->src_id > (e->num_masters - 1))
155     {
156       fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
157           o->src_id, op_counter, op, cur->id);
158       GNUNET_free (op);
159       GNUNET_free (op_name);
160       GNUNET_free (o);
161       GNUNET_free (sec_name);
162       return GNUNET_SYSERR;
163     }
164     GNUNET_free (op_name);
165
166     /* Get destination */
167     GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
168     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
169         sec_name, op_name, &o->dest_id))
170     {
171       fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
172           op_counter, op, cur->id);
173       GNUNET_free (op);
174       GNUNET_free (op_name);
175       GNUNET_free (o);
176       GNUNET_free (sec_name);
177       return GNUNET_SYSERR;
178     }
179     if (o->dest_id > (e->num_slaves - 1))
180     {
181       fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
182           o->dest_id, op_counter, op, cur->id);
183       GNUNET_free (op);
184       GNUNET_free (op_name);
185       GNUNET_free (o);
186       GNUNET_free (sec_name);
187       return GNUNET_SYSERR;
188     }
189     GNUNET_free (op_name);
190
191     GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
192     if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
193             sec_name, op_name, &type)) &&
194          (STOP_SEND != o->type) &&
195          (STOP_PREFERENCE != o->type) )
196     {
197       /* Load arguments for set_rate, start_send, set_preference */
198       if (0 == strcmp (type, "constant"))
199       {
200         o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
201       }
202       else if (0 == strcmp (type, "linear"))
203       {
204         o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
205       }
206       else if (0 == strcmp (type, "sinus"))
207       {
208         o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
209       }
210       else if (0 == strcmp (type, "random"))
211       {
212         o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
213       }
214       else
215       {
216         fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
217             op_counter, op, cur->id);
218         GNUNET_free (type);
219         GNUNET_free (op);
220         GNUNET_free (op_name);
221         GNUNET_free (sec_name);
222         GNUNET_free (o);
223         return GNUNET_SYSERR;
224       }
225       GNUNET_free (op_name);
226
227       /* Get base rate */
228       GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
229       if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
230           sec_name, op_name, &o->base_rate))
231       {
232         fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
233             op_counter, op, cur->id);
234         GNUNET_free (type);
235         GNUNET_free (op);
236         GNUNET_free (op_name);
237         GNUNET_free (sec_name);
238         GNUNET_free (o);
239         return GNUNET_SYSERR;
240       }
241       GNUNET_free (op_name);
242
243       /* Get max rate */
244       GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
245       if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
246           sec_name, op_name, &o->max_rate))
247       {
248         if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
249             (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
250             (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
251         {
252           fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
253               op_counter, op, cur->id);
254           GNUNET_free (type);
255           GNUNET_free (op_name);
256           GNUNET_free (op);
257           GNUNET_free (o);
258           GNUNET_free (sec_name);
259           return GNUNET_SYSERR;
260         }
261       }
262       GNUNET_free (op_name);
263
264       /* Get period */
265       GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
266       if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
267           sec_name, op_name, &o->period))
268       {
269         o->period = cur->duration;
270       }
271       GNUNET_free (op_name);
272
273       if (START_PREFERENCE == o->type)
274       {
275           /* Get frequency */
276           GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
277           if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
278               sec_name, op_name, &o->frequency))
279           {
280               fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
281                   op_counter, op, cur->id);
282               GNUNET_free (type);
283               GNUNET_free (op_name);
284               GNUNET_free (op);
285               GNUNET_free (o);
286               GNUNET_free (sec_name);
287               return GNUNET_SYSERR;
288           }
289           GNUNET_free (op_name);
290
291           /* Get preference */
292           GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
293           if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
294               sec_name, op_name, &pref))
295           {
296               fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
297                   op_counter, op, cur->id);
298               GNUNET_free (type);
299               GNUNET_free (op_name);
300               GNUNET_free (op);
301               GNUNET_free_non_null (pref);
302               GNUNET_free (o);
303               GNUNET_free (sec_name);
304               return GNUNET_SYSERR;
305           }
306
307           if (0 == strcmp(pref, "bandwidth"))
308             o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
309           else if (0 == strcmp(pref, "latency"))
310             o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
311           else
312           {
313               fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
314                   op_counter, op, cur->id);
315               GNUNET_free (type);
316               GNUNET_free (op_name);
317               GNUNET_free (op);
318               GNUNET_free_non_null (pref);
319               GNUNET_free (o);
320               GNUNET_free (sec_name);
321               return GNUNET_SYSERR;
322           }
323           GNUNET_free (pref);
324           GNUNET_free (op_name);
325       }
326     }
327
328     /* Safety checks */
329     if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
330         (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
331     {
332       if ((o->max_rate - o->base_rate) > o->base_rate)
333       {
334         /* This will cause an underflow */
335         GNUNET_break (0);
336       }
337       fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
338     }
339
340     if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
341       fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
342         op_counter, cur->id, print_op (o->type), o->src_id,
343         o->dest_id, (NULL != type) ? type : "",
344         o->base_rate, o->max_rate,
345         GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
346     else
347       fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
348         op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
349
350     GNUNET_free_non_null (type);
351     GNUNET_free (op);
352
353     GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
354     op_counter++;
355   }
356   GNUNET_free (sec_name);
357
358   return GNUNET_OK;
359 }
360
361
362 static int
363 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
364 {
365   int e_counter = 0;
366   char *sec_name;
367   struct GNUNET_TIME_Relative e_duration;
368   struct Episode *cur;
369   struct Episode *last;
370
371   e_counter = 0;
372   last = NULL;
373   while (1)
374   {
375     GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
376     if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
377         sec_name, "duration", &e_duration))
378     {
379       GNUNET_free (sec_name);
380       break;
381     }
382
383     cur = GNUNET_new (struct Episode);
384     cur->duration = e_duration;
385     cur->id = e_counter;
386
387     if (GNUNET_OK != load_episode (e, cur, cfg))
388     {
389       GNUNET_free (sec_name);
390       GNUNET_free (cur);
391       return GNUNET_SYSERR;
392     }
393
394     fprintf (stderr, "Found episode %u with duration %s \n",
395         e_counter,
396         GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
397
398     /* Update experiment */
399     e->num_episodes ++;
400     e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
401     /* Put in linked list */
402     if (NULL == last)
403       e->start = cur;
404     else
405     last->next = cur;
406
407     GNUNET_free (sec_name);
408     e_counter ++;
409     last = cur;
410   }
411   return e_counter;
412 }
413
414
415 static void
416 timeout_experiment (void *cls)
417 {
418   struct Experiment *e = cls;
419   e->experiment_timeout_task = NULL;
420   fprintf (stderr, "Experiment timeout!\n");
421
422   if (NULL != e->episode_timeout_task)
423   {
424     GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
425     e->episode_timeout_task = NULL;
426   }
427
428   e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
429       GNUNET_SYSERR);
430 }
431
432
433 static void
434 enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
435 {
436   struct BenchmarkPeer *peer;
437   struct BenchmarkPartner *partner;
438
439   peer = GNUNET_ATS_TEST_get_peer (op->src_id);
440   if (NULL == peer)
441   {
442     GNUNET_break (0);
443     return;
444   }
445
446   partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
447   if (NULL == partner)
448   {
449     GNUNET_break (0);
450     return;
451   }
452
453   fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
454
455   if (NULL != partner->tg)
456   {
457     fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
458     GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
459     partner->tg = NULL;
460   }
461
462   partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
463       op->gen_type, op->base_rate, op->max_rate, op->period,
464       GNUNET_TIME_UNIT_FOREVER_REL);
465 }
466
467 static void
468 enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
469 {
470   struct BenchmarkPartner *p;
471   p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
472   if (NULL == p)
473   {
474     GNUNET_break (0);
475     return;
476   }
477
478   fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
479
480   if (NULL != p->tg)
481   {
482     fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
483         op->src_id, op->dest_id);
484     GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
485     p->tg = NULL;
486   }
487 }
488
489
490 static void
491 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
492 {
493   struct BenchmarkPeer *peer;
494   struct BenchmarkPartner *partner;
495
496   peer = GNUNET_ATS_TEST_get_peer (op->src_id);
497   if (NULL == peer)
498   {
499     GNUNET_break (0);
500     return;
501   }
502
503   partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
504   if (NULL == partner)
505   {
506     GNUNET_break (0);
507     return;
508   }
509
510   fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
511
512   if (NULL != partner->pg)
513   {
514     fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
515         op->src_id, op->dest_id);
516     GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
517     partner->pg = NULL;
518   }
519
520   partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
521       op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency,
522       op->pref_type);
523 }
524
525 static void
526 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
527 {
528   struct BenchmarkPartner *p;
529   p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
530   if (NULL == p)
531   {
532     GNUNET_break (0);
533     return;
534   }
535
536   fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
537
538   if (NULL != p->pg)
539   {
540     fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
541         op->src_id, op->dest_id);
542     GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
543     p->pg = NULL;
544   }
545 }
546
547 static void enforce_episode (struct Episode *ep)
548 {
549   struct GNUNET_ATS_TEST_Operation *cur;
550   for (cur = ep->head; NULL != cur; cur = cur->next)
551   {
552
553     fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
554         print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
555     switch (cur->type) {
556       case START_SEND:
557         enforce_start_send (cur);
558         break;
559       case STOP_SEND:
560         enforce_stop_send (cur);
561         break;
562       case START_PREFERENCE:
563         enforce_start_preference (cur);
564         break;
565       case STOP_PREFERENCE:
566         enforce_stop_preference (cur);
567         break;
568       default:
569         break;
570     }
571   }
572 }
573
574
575 static void
576 timeout_episode (void *cls)
577 {
578   struct Experiment *e = cls;
579
580   e->episode_timeout_task = NULL;
581   if (NULL != e->ep_done_cb)
582     e->ep_done_cb (e->cur);
583
584   /* Scheduling next */
585   e->cur = e->cur->next;
586   if (NULL == e->cur)
587   {
588     /* done */
589     fprintf (stderr, "Last episode done!\n");
590     if (NULL != e->experiment_timeout_task)
591     {
592       GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
593       e->experiment_timeout_task = NULL;
594     }
595     e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
596     return;
597   }
598
599   fprintf (stderr, "Running episode %u with timeout %s\n",
600       e->cur->id,
601       GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
602   enforce_episode(e->cur);
603
604   e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
605       &timeout_episode, e);
606 }
607
608
609 void
610 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
611     GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
612     GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
613 {
614   fprintf (stderr, "Running experiment `%s'  with timeout %s\n", e->name,
615       GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
616   e->e_done_cb = e_done_cb;
617   e->ep_done_cb = ep_done_cb;
618   e->start_time = GNUNET_TIME_absolute_get();
619
620   /* Start total time out */
621   e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
622       &timeout_experiment, e);
623
624   /* Start */
625   e->cur = e->start;
626   fprintf (stderr, "Running episode %u with timeout %s\n",
627       e->cur->id,
628       GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
629   enforce_episode(e->cur);
630   e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
631       &timeout_episode, e);
632
633
634 }
635
636
637 struct Experiment *
638 GNUNET_ATS_TEST_experimentation_load (const char *filename)
639 {
640   struct Experiment *e;
641   struct GNUNET_CONFIGURATION_Handle *cfg;
642   e = NULL;
643
644   cfg = GNUNET_CONFIGURATION_create();
645   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
646   {
647     fprintf (stderr, "Failed to load `%s'\n", filename);
648     GNUNET_CONFIGURATION_destroy (cfg);
649     return NULL;
650   }
651
652   e = create_experiment ();
653
654   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
655       "name", &e->name))
656   {
657     fprintf (stderr, "Invalid %s", "name");
658     free_experiment (e);
659     return NULL;
660   }
661   else
662     fprintf (stderr, "Experiment name: `%s'\n", e->name);
663
664   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
665       "cfg_file", &e->cfg_file))
666   {
667     fprintf (stderr, "Invalid %s", "cfg_file");
668     free_experiment (e);
669     return NULL;
670   }
671   else
672     fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
673
674   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
675       "masters", &e->num_masters))
676   {
677     fprintf (stderr, "Invalid %s", "masters");
678     free_experiment (e);
679     return NULL;
680   }
681   else
682     fprintf (stderr, "Experiment masters: `%llu'\n",
683         e->num_masters);
684
685   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
686       "slaves", &e->num_slaves))
687   {
688     fprintf (stderr, "Invalid %s", "slaves");
689     free_experiment (e);
690     return NULL;
691   }
692   else
693     fprintf (stderr, "Experiment slaves: `%llu'\n",
694         e->num_slaves);
695
696   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
697       "log_freq", &e->log_freq))
698   {
699     fprintf (stderr, "Invalid %s", "log_freq");
700     free_experiment (e);
701     return NULL;
702   }
703   else
704     fprintf (stderr, "Experiment logging frequency: `%s'\n",
705         GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
706
707   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
708       "max_duration", &e->max_duration))
709   {
710     fprintf (stderr, "Invalid %s", "max_duration");
711     free_experiment (e);
712     return NULL;
713   }
714   else
715     fprintf (stderr, "Experiment duration: `%s'\n",
716         GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
717
718   load_episodes (e, cfg);
719   fprintf (stderr, "Loaded %u episodes with total duration %s\n",
720       e->num_episodes,
721       GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
722
723   GNUNET_CONFIGURATION_destroy (cfg);
724   return e;
725 }
726
727 void
728 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
729 {
730   if (NULL != e->experiment_timeout_task)
731   {
732     GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
733     e->experiment_timeout_task = NULL;
734   }
735   if (NULL != e->episode_timeout_task)
736   {
737     GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
738     e->episode_timeout_task = NULL;
739   }
740   free_experiment (e);
741 }
742
743 /* end of file ats-testing-experiment.c*/