aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-experiment.c
blob: db5f411dd1b54c1c95222a8e86a5530c3a0dadbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*
   This file is part of GNUnet.
   Copyright (C) 2010-2013 GNUnet e.V.

   GNUnet is free software: you can redistribute it and/or modify it
   under the terms of the GNU Affero General Public License as published
   by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.

   GNUnet is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

     SPDX-License-Identifier: AGPL3.0-or-later
 */
/**
 * @file ats-tests/ats-testing-experiment.c
 * @brief ats benchmark: controlled experiment execution
 * @author Christian Grothoff
 * @author Matthias Wachs
 */
#include "platform.h"
#include "gnunet_util_lib.h"
#include "ats-testing.h"

const char *
print_op(enum OperationType op)
{
  switch (op)
    {
    case START_SEND:
      return "START_SEND";

    case STOP_SEND:
      return "STOP_SEND";

    case START_PREFERENCE:
      return "START_PREFERENCE";

    case STOP_PREFERENCE:
      return "STOP_PREFERENCE";

    default:
      break;
    }
  return "";
}


static struct Experiment *
create_experiment()
{
  struct Experiment *e;

  e = GNUNET_new(struct Experiment);
  e->name = NULL;
  e->num_masters = 0;
  e->num_slaves = 0;
  e->start = NULL;
  e->total_duration = GNUNET_TIME_UNIT_ZERO;
  return e;
}

static void
free_experiment(struct Experiment *e)
{
  struct Episode *cur;
  struct Episode *next;
  struct GNUNET_ATS_TEST_Operation *cur_o;
  struct GNUNET_ATS_TEST_Operation *next_o;

  next = e->start;
  for (cur = next; NULL != cur; cur = next)
    {
      next = cur->next;

      next_o = cur->head;
      for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
        {
          next_o = cur_o->next;
          GNUNET_free(cur_o);
        }
      GNUNET_free(cur);
    }

  GNUNET_free_non_null(e->name);
  GNUNET_free_non_null(e->cfg_file);
  GNUNET_free(e);
}


static int
load_episode(struct Experiment *e,
             struct Episode *cur,
             struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_ATS_TEST_Operation *o;
  char *sec_name;
  char *op_name;
  char *op;
  char *type;
  char *pref;
  int op_counter = 0;

  fprintf(stderr, "Parsing episode %u\n", cur->id);
  GNUNET_asprintf(&sec_name, "episode-%u", cur->id);

  while (1)
    {
      /* Load operation */
      GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
                                                                 sec_name, op_name, &op))
        {
          GNUNET_free(op_name);
          break;
        }
      o = GNUNET_new(struct GNUNET_ATS_TEST_Operation);
      /* operations = set_rate, start_send, stop_send, set_preference */
      if (0 == strcmp(op, "start_send"))
        {
          o->type = START_SEND;
        }
      else if (0 == strcmp(op, "stop_send"))
        {
          o->type = STOP_SEND;
        }
      else if (0 == strcmp(op, "start_preference"))
        {
          o->type = START_PREFERENCE;
        }
      else if (0 == strcmp(op, "stop_preference"))
        {
          o->type = STOP_PREFERENCE;
        }
      else
        {
          fprintf(stderr, "Invalid operation %u `%s' in episode %u\n",
                  op_counter, op, cur->id);
          GNUNET_free(op);
          GNUNET_free(op_name);
          GNUNET_free(o);
          GNUNET_free(sec_name);
          return GNUNET_SYSERR;
        }
      GNUNET_free(op_name);

      /* Get source */
      GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
                                                                 sec_name, op_name, &o->src_id))
        {
          fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n",
                  op_counter, op, cur->id);
          GNUNET_free(op);
          GNUNET_free(op_name);
          GNUNET_free(o);
          GNUNET_free(sec_name);
          return GNUNET_SYSERR;
        }
      if (o->src_id > (e->num_masters - 1))
        {
          fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
                  o->src_id, op_counter, op, cur->id);
          GNUNET_free(op);
          GNUNET_free(op_name);
          GNUNET_free(o);
          GNUNET_free(sec_name);
          return GNUNET_SYSERR;
        }
      GNUNET_free(op_name);

      /* Get destination */
      GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
                                                                 sec_name, op_name, &o->dest_id))
        {
          fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n",
                  op_counter, op, cur->id);
          GNUNET_free(op);
          GNUNET_free(op_name);
          GNUNET_free(o);
          GNUNET_free(sec_name);
          return GNUNET_SYSERR;
        }
      if (o->dest_id > (e->num_slaves - 1))
        {
          fprintf(stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
                  o->dest_id, op_counter, op, cur->id);
          GNUNET_free(op);
          GNUNET_free(op_name);
          GNUNET_free(o);
          GNUNET_free(sec_name);
          return GNUNET_SYSERR;
        }
      GNUNET_free(op_name);

      GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
      if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
                                                                  sec_name, op_name, &type)) &&
          (STOP_SEND != o->type) &&
          (STOP_PREFERENCE != o->type))
        {
          /* Load arguments for set_rate, start_send, set_preference */
          if (0 == strcmp(type, "constant"))
            {
              o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
            }
          else if (0 == strcmp(type, "linear"))
            {
              o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
            }
          else if (0 == strcmp(type, "sinus"))
            {
              o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
            }
          else if (0 == strcmp(type, "random"))
            {
              o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
            }
          else
            {
              fprintf(stderr, "Invalid type %u `%s' in episode %u\n",
                      op_counter, op, cur->id);
              GNUNET_free(type);
              GNUNET_free(op);
              GNUNET_free(op_name);
              GNUNET_free(sec_name);
              GNUNET_free(o);
              return GNUNET_SYSERR;
            }
          GNUNET_free(op_name);

          /* Get base rate */
          GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
                                                                     sec_name, op_name, &o->base_rate))
            {
              fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n",
                      op_counter, op, cur->id);
              GNUNET_free(type);
              GNUNET_free(op);
              GNUNET_free(op_name);
              GNUNET_free(sec_name);
              GNUNET_free(o);
              return GNUNET_SYSERR;
            }
          GNUNET_free(op_name);

          /* Get max rate */
          GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
                                                                     sec_name, op_name, &o->max_rate))
            {
              if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
                  (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
                  (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
                {
                  fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n",
                          op_counter, op, cur->id);
                  GNUNET_free(type);
                  GNUNET_free(op_name);
                  GNUNET_free(op);
                  GNUNET_free(o);
                  GNUNET_free(sec_name);
                  return GNUNET_SYSERR;
                }
            }
          GNUNET_free(op_name);

          /* Get period */
          GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
          if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
                                                                   sec_name, op_name, &o->period))
            {
              o->period = cur->duration;
            }
          GNUNET_free(op_name);

          if (START_PREFERENCE == o->type)
            {
              /* Get frequency */
              GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
              if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
                                                                       sec_name, op_name, &o->frequency))
                {
                  fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n",
                          op_counter, op, cur->id);
                  GNUNET_free(type);
                  GNUNET_free(op_name);
                  GNUNET_free(op);
                  GNUNET_free(o);
                  GNUNET_free(sec_name);
                  return GNUNET_SYSERR;
                }
              GNUNET_free(op_name);

              /* Get preference */
              GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
              if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
                                                                         sec_name, op_name, &pref))
                {
                  fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n",
                          op_counter, op, cur->id);
                  GNUNET_free(type);
                  GNUNET_free(op_name);
                  GNUNET_free(op);
                  GNUNET_free_non_null(pref);
                  GNUNET_free(o);
                  GNUNET_free(sec_name);
                  return GNUNET_SYSERR;
                }

              if (0 == strcmp(pref, "bandwidth"))
                o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
              else if (0 == strcmp(pref, "latency"))
                o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
              else
                {
                  fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n",
                          op_counter, op, cur->id);
                  GNUNET_free(type);
                  GNUNET_free(op_name);
                  GNUNET_free(op);
                  GNUNET_free_non_null(pref);
                  GNUNET_free(o);
                  GNUNET_free(sec_name);
                  return GNUNET_SYSERR;
                }
              GNUNET_free(pref);
              GNUNET_free(op_name);
            }
        }

      /* Safety checks */
      if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
          (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
        {
          if ((o->max_rate - o->base_rate) > o->base_rate)
            {
              /* This will cause an underflow */
              GNUNET_break(0);
            }
          fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
        }

      if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
        fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
                op_counter, cur->id, print_op(o->type), o->src_id,
                o->dest_id, (NULL != type) ? type : "",
                o->base_rate, o->max_rate,
                GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES));
      else
        fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
                op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id);

      GNUNET_free_non_null(type);
      GNUNET_free(op);

      GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o);
      op_counter++;
    }
  GNUNET_free(sec_name);

  return GNUNET_OK;
}


static int
load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
{
  int e_counter = 0;
  char *sec_name;
  struct GNUNET_TIME_Relative e_duration;
  struct Episode *cur;
  struct Episode *last;

  e_counter = 0;
  last = NULL;
  while (1)
    {
      GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
      if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
                                                               sec_name, "duration", &e_duration))
        {
          GNUNET_free(sec_name);
          break;
        }

      cur = GNUNET_new(struct Episode);
      cur->duration = e_duration;
      cur->id = e_counter;

      if (GNUNET_OK != load_episode(e, cur, cfg))
        {
          GNUNET_free(sec_name);
          GNUNET_free(cur);
          return GNUNET_SYSERR;
        }

      fprintf(stderr, "Found episode %u with duration %s \n",
              e_counter,
              GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));

      /* Update experiment */
      e->num_episodes++;
      e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
      /* Put in linked list */
      if (NULL == last)
        e->start = cur;
      else
        last->next = cur;

      GNUNET_free(sec_name);
      e_counter++;
      last = cur;
    }
  return e_counter;
}


static void
timeout_experiment(void *cls)
{
  struct Experiment *e = cls;

  e->experiment_timeout_task = NULL;
  fprintf(stderr, "Experiment timeout!\n");

  if (NULL != e->episode_timeout_task)
    {
      GNUNET_SCHEDULER_cancel(e->episode_timeout_task);
      e->episode_timeout_task = NULL;
    }

  e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time),
               GNUNET_SYSERR);
}


static void
enforce_start_send(struct GNUNET_ATS_TEST_Operation *op)
{
  struct BenchmarkPeer *peer;
  struct BenchmarkPartner *partner;

  peer = GNUNET_ATS_TEST_get_peer(op->src_id);
  if (NULL == peer)
    {
      GNUNET_break(0);
      return;
    }

  partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
  if (NULL == partner)
    {
      GNUNET_break(0);
      return;
    }

  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);

  if (NULL != partner->tg)
    {
      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", op->src_id, op->dest_id);
      GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
      partner->tg = NULL;
    }

  partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
                                                       op->gen_type, op->base_rate, op->max_rate, op->period,
                                                       GNUNET_TIME_UNIT_FOREVER_REL);
}

static void
enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op)
{
  struct BenchmarkPartner *p;

  p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
  if (NULL == p)
    {
      GNUNET_break(0);
      return;
    }

  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);

  if (NULL != p->tg)
    {
      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n",
              op->src_id, op->dest_id);
      GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
      p->tg = NULL;
    }
}


static void
enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op)
{
  struct BenchmarkPeer *peer;
  struct BenchmarkPartner *partner;

  peer = GNUNET_ATS_TEST_get_peer(op->src_id);
  if (NULL == peer)
    {
      GNUNET_break(0);
      return;
    }

  partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
  if (NULL == partner)
    {
      GNUNET_break(0);
      return;
    }

  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);

  if (NULL != partner->pg)
    {
      fprintf(stderr, "Stopping traffic between master %llu slave %llu\n",
              op->src_id, op->dest_id);
      GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
      partner->pg = NULL;
    }

  partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
                                                           op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency,
                                                           op->pref_type);
}

static void
enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op)
{
  struct BenchmarkPartner *p;

  p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id);
  if (NULL == p)
    {
      GNUNET_break(0);
      return;
    }

  fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);

  if (NULL != p->pg)
    {
      fprintf(stderr, "Stopping preference between master %llu slave %llu\n",
              op->src_id, op->dest_id);
      GNUNET_ATS_TEST_generate_preferences_stop(p->pg);
      p->pg = NULL;
    }
}

static void enforce_episode(struct Episode *ep)
{
  struct GNUNET_ATS_TEST_Operation *cur;

  for (cur = ep->head; NULL != cur; cur = cur->next)
    {
      fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
              print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate);
      switch (cur->type)
        {
        case START_SEND:
          enforce_start_send(cur);
          break;

        case STOP_SEND:
          enforce_stop_send(cur);
          break;

        case START_PREFERENCE:
          enforce_start_preference(cur);
          break;

        case STOP_PREFERENCE:
          enforce_stop_preference(cur);
          break;

        default:
          break;
        }
    }
}


static void
timeout_episode(void *cls)
{
  struct Experiment *e = cls;

  e->episode_timeout_task = NULL;
  if (NULL != e->ep_done_cb)
    e->ep_done_cb(e->cur);

  /* Scheduling next */
  e->cur = e->cur->next;
  if (NULL == e->cur)
    {
      /* done */
      fprintf(stderr, "Last episode done!\n");
      if (NULL != e->experiment_timeout_task)
        {
          GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
          e->experiment_timeout_task = NULL;
        }
      e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
      return;
    }

  fprintf(stderr, "Running episode %u with timeout %s\n",
          e->cur->id,
          GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
  enforce_episode(e->cur);

  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration,
                                                         &timeout_episode, e);
}


void
GNUNET_ATS_TEST_experimentation_run(struct Experiment *e,
                                    GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
                                    GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
{
  fprintf(stderr, "Running experiment `%s'  with timeout %s\n", e->name,
          GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
  e->e_done_cb = e_done_cb;
  e->ep_done_cb = ep_done_cb;
  e->start_time = GNUNET_TIME_absolute_get();

  /* Start total time out */
  e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration,
                                                            &timeout_experiment, e);

  /* Start */
  e->cur = e->start;
  fprintf(stderr, "Running episode %u with timeout %s\n",
          e->cur->id,
          GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
  enforce_episode(e->cur);
  e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration,
                                                         &timeout_episode, e);
}


struct Experiment *
GNUNET_ATS_TEST_experimentation_load(const char *filename)
{
  struct Experiment *e;
  struct GNUNET_CONFIGURATION_Handle *cfg;

  e = NULL;

  cfg = GNUNET_CONFIGURATION_create();
  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename))
    {
      fprintf(stderr, "Failed to load `%s'\n", filename);
      GNUNET_CONFIGURATION_destroy(cfg);
      return NULL;
    }

  e = create_experiment();

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
                                                             "name", &e->name))
    {
      fprintf(stderr, "Invalid %s", "name");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment name: `%s'\n", e->name);

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment",
                                                               "cfg_file", &e->cfg_file))
    {
      fprintf(stderr, "Invalid %s", "cfg_file");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file);

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
                                                             "masters", &e->num_masters))
    {
      fprintf(stderr, "Invalid %s", "masters");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment masters: `%llu'\n",
            e->num_masters);

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
                                                             "slaves", &e->num_slaves))
    {
      fprintf(stderr, "Invalid %s", "slaves");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment slaves: `%llu'\n",
            e->num_slaves);

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
                                                           "log_freq", &e->log_freq))
    {
      fprintf(stderr, "Invalid %s", "log_freq");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment logging frequency: `%s'\n",
            GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES));

  if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
                                                           "max_duration", &e->max_duration))
    {
      fprintf(stderr, "Invalid %s", "max_duration");
      free_experiment(e);
      return NULL;
    }
  else
    fprintf(stderr, "Experiment duration: `%s'\n",
            GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));

  load_episodes(e, cfg);
  fprintf(stderr, "Loaded %u episodes with total duration %s\n",
          e->num_episodes,
          GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES));

  GNUNET_CONFIGURATION_destroy(cfg);
  return e;
}

void
GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e)
{
  if (NULL != e->experiment_timeout_task)
    {
      GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
      e->experiment_timeout_task = NULL;
    }
  if (NULL != e->episode_timeout_task)
    {
      GNUNET_SCHEDULER_cancel(e->episode_timeout_task);
      e->episode_timeout_task = NULL;
    }
  free_experiment(e);
}

/* end of file ats-testing-experiment.c*/