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