/*
This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ 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
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., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file ats-tests/ats-testing-experiment.c
return "START_SEND";
case STOP_SEND:
return "STOP_SEND";
- case SET_RATE:
- return "SET_RATE";
- case SET_PREFERENCE:
- return "SET_PREFERENCE";
+ case START_PREFERENCE:
+ return "START_PREFERENCE";
+ case STOP_PREFERENCE:
+ return "STOP_PREFERENCE";
default:
break;
}
{
struct Episode *cur;
struct Episode *next;
- struct Operation *cur_o;
- struct Operation *next_o;
+ struct GNUNET_ATS_TEST_Operation *cur_o;
+ struct GNUNET_ATS_TEST_Operation *next_o;
next = e->start;
for (cur = next; NULL != cur; cur = next)
GNUNET_free (e);
}
+
static int
-load_episode (struct Experiment *e, struct Episode *cur,
- struct GNUNET_CONFIGURATION_Handle *cfg)
+load_episode (struct Experiment *e,
+ struct Episode *cur,
+ struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct Operation *o;
+ struct GNUNET_ATS_TEST_Operation *o;
char *sec_name;
char *op_name;
char *op;
- int ep_counter = 0;
+ char *type;
+ char *pref;
+ int op_counter = 0;
+
fprintf (stderr, "Parsing episode %u\n",cur->id);
- GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
+ GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
while (1)
{
-
- GNUNET_asprintf(&op_name, "op-%u-operation", ep_counter);
+ /* 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 Operation);
+ 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 = STOP_SEND;
}
- else if (0 == strcmp (op, "set_rate"))
+ else if (0 == strcmp (op, "start_preference"))
{
- o->type = SET_RATE;
+ o->type = START_PREFERENCE;
}
- else if (0 == strcmp (op, "set_preference"))
+ else if (0 == strcmp (op, "stop_preference"))
{
- o->type = SET_PREFERENCE;
+ o->type = STOP_PREFERENCE;
}
else
{
fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
- ep_counter, op, cur->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-src", ep_counter);
+
+ /* 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",
- ep_counter, op, cur->id);
+ 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)
+ if (o->src_id > (e->num_masters - 1))
{
fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
- o->src_id, ep_counter, op, cur->id);
+ 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);
- GNUNET_asprintf(&op_name, "op-%u-dest", ep_counter);
+
+ /* 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",
- ep_counter, op, cur->id);
+ 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)
+ if (o->dest_id > (e->num_slaves - 1))
{
fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
- o->dest_id, ep_counter, op, cur->id);
+ 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-value", ep_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->value))
+
+ 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)))
{
- fprintf (stderr, "Missing value in operation %u `%s' in episode %u\n",
- ep_counter, op, cur->id);
- GNUNET_free (op);
- return GNUNET_SYSERR;
+ /* 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);
+ }
}
- if (o->dest_id > e->num_slaves)
+
+ /* Safety checks */
+ if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
+ (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
{
- fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
- o->dest_id, ep_counter, op, cur->id);
- GNUNET_free (op);
- return GNUNET_SYSERR;
+ 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");
}
- fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %llu\n",
- ep_counter, cur->id, print_op (o->type), o->src_id, o->dest_id, o->value);
+ 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);
- GNUNET_free (op_name);
- ep_counter++;
+ op_counter++;
}
GNUNET_free (sec_name);
return GNUNET_OK;
}
+
static int
load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
{
return e_counter;
}
+
static void
-timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
+timeout_experiment (void *cls)
{
struct Experiment *e = cls;
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->experiment_timeout_task = NULL;
fprintf (stderr, "Experiment timeout!\n");
- if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
+ if (NULL != e->episode_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = GNUNET_SCHEDULER_NO_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 Operation *op)
+enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
{
- GNUNET_break (0);
+ 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 Operation *op)
+enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
{
- GNUNET_break (0);
+ 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_set_rate (struct Operation *op)
+enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
{
- GNUNET_break (0);
+ 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_set_preference (struct Operation *op)
+enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
{
- GNUNET_break (0);
+ 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 Operation *cur;
+ 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->value);
+ print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
switch (cur->type) {
case START_SEND:
enforce_start_send (cur);
case STOP_SEND:
enforce_stop_send (cur);
break;
- case SET_RATE:
- enforce_set_rate (cur);
+ case START_PREFERENCE:
+ enforce_start_preference (cur);
break;
- case SET_PREFERENCE:
- enforce_set_preference (cur);
+ case STOP_PREFERENCE:
+ enforce_stop_preference (cur);
break;
default:
break;
}
}
+
static void
-timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
+timeout_episode (void *cls)
{
struct Experiment *e = cls;
- e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+
+ e->episode_timeout_task = NULL;
if (NULL != e->ep_done_cb)
e->ep_done_cb (e->cur);
{
/* done */
fprintf (stderr, "Last episode done!\n");
- if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
+ if (NULL != e->experiment_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->experiment_timeout_task = NULL;
}
e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
return;
struct Experiment *
-GNUNET_ATS_TEST_experimentation_load (char *filename)
+GNUNET_ATS_TEST_experimentation_load (const char *filename)
{
struct Experiment *e;
struct GNUNET_CONFIGURATION_Handle *cfg;
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))
{
void
GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
{
- if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
+ if (NULL != e->experiment_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_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*/
-