From 2debb60e6a2c3cafab0c9095944d316672a8b4a0 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 3 Feb 2014 09:44:09 +0000 Subject: [PATCH] experiment parsing + test.exp containing different examples --- src/ats-tests/ats-testing-experiment.c | 131 +++++++++++++++++++------ src/ats-tests/ats-testing.h | 11 ++- src/ats-tests/experiments/test.exp | 36 ++++--- 3 files changed, 132 insertions(+), 46 deletions(-) diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c index 12858f2aa..1ab1342c5 100644 --- a/src/ats-tests/ats-testing-experiment.c +++ b/src/ats-tests/ats-testing-experiment.c @@ -94,14 +94,15 @@ load_episode (struct Experiment *e, struct Episode *cur, char *sec_name; char *op_name; char *op; - int ep_counter = 0; + char *type; + int op_counter = 0; fprintf (stderr, "Parsing episode %u\n",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)) { @@ -128,72 +129,140 @@ load_episode (struct Experiment *e, struct Episode *cur, 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); 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); return GNUNET_SYSERR; } if (o->src_id > e->num_masters) { 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); 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); return GNUNET_SYSERR; } if (o->dest_id > e->num_slaves) { 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); 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)) { - fprintf (stderr, "Missing value in operation %u `%s' in episode %u\n", - ep_counter, op, cur->id); - GNUNET_free (op); - return GNUNET_SYSERR; + break; } - if (o->dest_id > e->num_slaves) + + if (STOP_SEND != o->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; + /* Load arguments for set_rate, start_send, set_preference */ + if (0 == strcmp (type, "constant")) + { + o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT; + } + else if (0 == strcmp (type, "linear")) + { + o->tg_type = GNUNET_ATS_TEST_TG_LINEAR; + } + else if (0 == strcmp (type, "sinus")) + { + o->tg_type = GNUNET_ATS_TEST_TG_SINUS; + } + else if (0 == strcmp (type, "random")) + { + o->tg_type = GNUNET_ATS_TEST_TG_RANDOM; + } + else + { + fprintf (stderr, "Invalid type %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + 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 (op); + GNUNET_free (op_name); + 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->tg_type) || + (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) || + (GNUNET_ATS_TEST_TG_SINUS == o->tg_type)) + { + fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + 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); + } } - 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); + 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, type, o->base_rate, o->max_rate, + GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES)); GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o); - GNUNET_free (op_name); - ep_counter++; + op_counter++; } GNUNET_free (sec_name); @@ -300,7 +369,7 @@ static void enforce_episode (struct Episode *ep) { 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); diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h index 7d543e328..56e114bf5 100644 --- a/src/ats-tests/ats-testing.h +++ b/src/ats-tests/ats-testing.h @@ -453,14 +453,23 @@ typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) ( typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success); +/** + * An operation in an experiment + */ struct Operation { struct Operation *next; struct Operation *prev; + long long unsigned int src_id; long long unsigned int dest_id; - long long unsigned int value; + + long long unsigned int base_rate; + long long unsigned int max_rate; + struct GNUNET_TIME_Relative period; + enum OperationType type; + enum TrafficGeneratorType tg_type; }; struct Episode diff --git a/src/ats-tests/experiments/test.exp b/src/ats-tests/experiments/test.exp index 7c02f41cc..3ecfc63d4 100644 --- a/src/ats-tests/experiments/test.exp +++ b/src/ats-tests/experiments/test.exp @@ -1,7 +1,7 @@ [experiment] name = test masters = 1 - slaves = 3 + slaves = 4 max_duration = 10 s cfg_file = gnunet_ats_sim_default.conf @@ -9,24 +9,32 @@ # operations = set_rate, start_send, stop_send, set_preference duration = 2 s op-0-operation = set_rate -op-0-value = 10000 op-0-src = 0 op-0-dest = 1 +op-0-type = constant +op-0-base-rate= 10000 +op-0-max-rate = 10000 op-1-operation = set_rate -op-1-value = 1000 op-1-src = 0 op-1-dest = 2 +op-1-type = sinus +op-1-period = 1 s +op-1-base-rate= 10000 +op-1-max-rate = 20000 +op-2-operation = set_rate +op-2-src = 0 +op-2-dest = 3 +op-2-type = random +op-2-period = 1 s +op-2-base-rate= 10000 +op-2-max-rate = 20000 -[episode-1] -duration = 2 s -op-0-operation = set_preference -op-0-value = 10000 -op-0-src = 0 -op-0-dest = 1 - -op-1-operation = set_preference -op-1-value = 10000 -op-1-src = 0 -op-1-dest = 2 +op-3-operation = set_rate +op-3-src = 0 +op-3-dest = 2 +op-3-type = linear +op-3-period = 1 s +op-3-base-rate= 10000 +op-3-max-rate = 20000 \ No newline at end of file -- 2.25.1