/*
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 General Public License as published
by the Free Software Foundation; either version 3, 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
* @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 "gnunet_ats_plugin.h"
#include "gnunet_ats_service.h"
#include "ats-testing.h"
/**
* Experiments
*/
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 (sec_name);
GNUNET_free (o);
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 (sec_name);
GNUNET_free (o);
return GNUNET_SYSERR;
}
if (o->src_id > (e->num_masters - 1))
{
fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u