X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats-tests%2Fats-testing-experiment.c;h=d55adc2d74e5d9ceb07c37fa1292c8902967af9a;hb=7067d8df58abce4636ff94cd3621aee9de1ab594;hp=fca3743248ee254be6cfd27f6129d43e07e0dcc6;hpb=ee1c5c74a2409a52af706e613bd86a26341abba8;p=oweals%2Fgnunet.git diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c index fca374324..d55adc2d7 100644 --- a/src/ats-tests/ats-testing-experiment.c +++ b/src/ats-tests/ats-testing-experiment.c @@ -27,6 +27,25 @@ #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 SET_RATE: + return "SET_RATE"; + case SET_PREFERENCE: + return "SET_PREFERENCE"; + default: + break; + } + return ""; +} + + static struct Experiment * create_experiment () { @@ -45,11 +64,20 @@ free_experiment (struct Experiment *e) { struct Episode *cur; struct Episode *next; + struct Operation *cur_o; + struct 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); } @@ -58,6 +86,120 @@ free_experiment (struct Experiment *e) GNUNET_free (e); } +static int +load_episode (struct Experiment *e, struct Episode *cur, + struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct Operation *o; + char *sec_name; + char *op_name; + char *op; + int ep_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); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, + sec_name, op_name, &op)) + { + break; + } + o = GNUNET_new (struct 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, "set_rate")) + { + o->type = SET_RATE; + } + else if (0 == strcmp (op, "set_preference")) + { + o->type = SET_PREFERENCE; + } + else + { + fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", + ep_counter, op, cur->id); + GNUNET_free (op); + return GNUNET_SYSERR; + } + + GNUNET_free (op_name); + GNUNET_asprintf(&op_name, "op-%u-src", ep_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); + GNUNET_free (op); + 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); + GNUNET_free (op); + return GNUNET_SYSERR; + } + + GNUNET_free (op_name); + GNUNET_asprintf(&op_name, "op-%u-dest", ep_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); + GNUNET_free (op); + 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); + GNUNET_free (op); + 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)) + { + fprintf (stderr, "Missing value in operation %u `%s' in episode %u\n", + ep_counter, op, cur->id); + GNUNET_free (op); + 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); + GNUNET_free (op); + return GNUNET_SYSERR; + } + + 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); + + GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o); + GNUNET_free (op_name); + ep_counter++; + } + GNUNET_free (sec_name); + + return GNUNET_OK; +} + static int load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) { @@ -83,6 +225,13 @@ load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) 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)); @@ -110,7 +259,65 @@ timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc) e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK; fprintf (stderr, "Experiment timeout!\n"); - e->e_done_cb (e, GNUNET_SYSERR); + if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task) + { + e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (e->episode_timeout_task); + } + + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), + GNUNET_SYSERR); +} + +static void +enforce_start_send (struct Operation *op) +{ + GNUNET_break (0); +} + +static void +enforce_stop_send (struct Operation *op) +{ + GNUNET_break (0); +} + +static void +enforce_set_rate (struct Operation *op) +{ + GNUNET_break (0); +} + +static void +enforce_set_preference (struct Operation *op) +{ + GNUNET_break (0); +} + +static void enforce_episode (struct Episode *ep) +{ + struct 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); + switch (cur->type) { + case START_SEND: + enforce_start_send (cur); + break; + case STOP_SEND: + enforce_stop_send (cur); + break; + case SET_RATE: + enforce_set_rate (cur); + break; + case SET_PREFERENCE: + enforce_set_preference (cur); + break; + default: + break; + } + } } static void @@ -118,7 +325,8 @@ timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { struct Experiment *e = cls; e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK; - e->ep_done_cb (e->cur); + if (NULL != e->ep_done_cb) + e->ep_done_cb (e->cur); /* Scheduling next */ e->cur = e->cur->next; @@ -131,13 +339,15 @@ timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc) GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK; } - e->e_done_cb (e, GNUNET_OK); + 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); } @@ -152,6 +362,7 @@ GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, 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, @@ -162,12 +373,14 @@ GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, 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 (char *filename) {