From 7401d20fe0d587ca704228d4b1474666cad3df12 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 23 Jan 2014 16:03:53 +0000 Subject: [PATCH] implementing operations, episodes... --- src/ats-tests/ats-testing-experiment.c | 147 ++++++++++++++++++++++++- src/ats-tests/ats-testing.h | 41 +++++-- src/ats-tests/gnunet-ats-sim.c | 14 ++- 3 files changed, 184 insertions(+), 18 deletions(-) diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c index fca374324..03e5efd02 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 () { @@ -58,6 +77,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 +216,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 +250,8 @@ 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); + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), + GNUNET_SYSERR); } static void @@ -131,7 +272,7 @@ 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; } @@ -152,6 +293,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, @@ -168,6 +310,7 @@ GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, } + struct Experiment * GNUNET_ATS_TEST_experimentation_load (char *filename) { diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h index 028789d69..a2937d51d 100644 --- a/src/ats-tests/ats-testing.h +++ b/src/ats-tests/ats-testing.h @@ -385,15 +385,43 @@ struct GNUNET_ATS_TEST_Topology void *done_cb_cls; }; -struct Experiment; +enum OperationType +{ + START_SEND, + STOP_SEND, + SET_RATE, + SET_PREFERENCE +}; struct Episode; +struct Experiment; + typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) ( struct Episode *e); -typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) ( - struct Experiment *e, int success); +typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, + struct GNUNET_TIME_Relative duration,int success); + +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; + enum OperationType type; +}; + +struct Episode +{ + int id; + struct Episode *next; + struct GNUNET_TIME_Relative duration; + + struct Operation *head; + struct Operation *tail; +}; struct Experiment @@ -416,13 +444,6 @@ struct Experiment GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb; }; -struct Episode -{ - int id; - struct Episode *next; - struct GNUNET_TIME_Relative duration; -}; - void GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c index e06ca8887..a15afa639 100644 --- a/src/ats-tests/gnunet-ats-sim.c +++ b/src/ats-tests/gnunet-ats-sim.c @@ -43,7 +43,7 @@ struct Experiment *e; struct LoggingHandle *l; static void -evaluate () +evaluate (struct GNUNET_TIME_Relative duration_total) { int c_m; int c_s; @@ -57,7 +57,8 @@ evaluate () double kb_recv_percent; unsigned int rtt; - duration = (TEST_TIMEOUT.rel_value_us / (1000 * 1000)); + + duration = (duration_total.rel_value_us / (1000 * 1000)); for (c_m = 0; c_m < e->num_masters; c_m++) { mp = &masters_p[c_m]; @@ -135,12 +136,13 @@ log_request__cb (void *cls, const struct GNUNET_HELLO_Address *address, } static void -experiment_done_cb (struct Experiment *e, int success) +experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success) { if (GNUNET_OK == success) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment `%s' done successful\n", e->name); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); else - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment `%s' failed \n", e->name); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); if (GNUNET_SCHEDULER_NO_TASK != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); @@ -148,7 +150,7 @@ experiment_done_cb (struct Experiment *e, int success) } /* Stop logging */ GNUNET_ATS_TEST_logging_stop (l); - evaluate (); + evaluate (duration); /* Stop traffic generation */ GNUNET_ATS_TEST_generate_traffic_stop_all(); -- 2.25.1