aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-experiment.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-23 16:03:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-23 16:03:53 +0000
commit7401d20fe0d587ca704228d4b1474666cad3df12 (patch)
tree02a53cb537d0f7e72dcc6d616f27a72e351d42b0 /src/ats-tests/ats-testing-experiment.c
parentd10f54d435d545b4fdafd4ffa278f786b5f500dc (diff)
downloadgnunet-7401d20fe0d587ca704228d4b1474666cad3df12.tar.gz
gnunet-7401d20fe0d587ca704228d4b1474666cad3df12.zip
implementing operations, episodes...
Diffstat (limited to 'src/ats-tests/ats-testing-experiment.c')
-rw-r--r--src/ats-tests/ats-testing-experiment.c147
1 files changed, 145 insertions, 2 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 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "ats-testing.h" 28#include "ats-testing.h"
29 29
30const char *
31print_op (enum OperationType op)
32{
33 switch (op) {
34 case START_SEND:
35 return "START_SEND";
36 case STOP_SEND:
37 return "STOP_SEND";
38 case SET_RATE:
39 return "SET_RATE";
40 case SET_PREFERENCE:
41 return "SET_PREFERENCE";
42 default:
43 break;
44 }
45 return "";
46}
47
48
30static struct Experiment * 49static struct Experiment *
31create_experiment () 50create_experiment ()
32{ 51{
@@ -59,6 +78,120 @@ free_experiment (struct Experiment *e)
59} 78}
60 79
61static int 80static int
81load_episode (struct Experiment *e, struct Episode *cur,
82 struct GNUNET_CONFIGURATION_Handle *cfg)
83{
84 struct Operation *o;
85 char *sec_name;
86 char *op_name;
87 char *op;
88 int ep_counter = 0;
89 fprintf (stderr, "Parsing episode %u\n",cur->id);
90 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
91
92 while (1)
93 {
94
95 GNUNET_asprintf(&op_name, "op-%u-operation", ep_counter);
96 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
97 sec_name, op_name, &op))
98 {
99 break;
100 }
101 o = GNUNET_new (struct Operation);
102 /* operations = set_rate, start_send, stop_send, set_preference */
103 if (0 == strcmp (op, "start_send"))
104 {
105 o->type = START_SEND;
106 }
107 else if (0 == strcmp (op, "stop_send"))
108 {
109 o->type = STOP_SEND;
110 }
111 else if (0 == strcmp (op, "set_rate"))
112 {
113 o->type = SET_RATE;
114 }
115 else if (0 == strcmp (op, "set_preference "))
116 {
117 o->type = SET_PREFERENCE;
118 }
119 else
120 {
121 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
122 ep_counter, op, cur->id);
123 GNUNET_free (op);
124 return GNUNET_SYSERR;
125 }
126
127 GNUNET_free (op_name);
128 GNUNET_asprintf(&op_name, "op-%u-src", ep_counter);
129 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
130 sec_name, op_name, &o->src_id))
131 {
132 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
133 ep_counter, op, cur->id);
134 GNUNET_free (op);
135 return GNUNET_SYSERR;
136 }
137 if (o->src_id > e->num_masters)
138 {
139 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
140 o->src_id, ep_counter, op, cur->id);
141 GNUNET_free (op);
142 return GNUNET_SYSERR;
143 }
144
145 GNUNET_free (op_name);
146 GNUNET_asprintf(&op_name, "op-%u-dest", ep_counter);
147 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
148 sec_name, op_name, &o->dest_id))
149 {
150 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
151 ep_counter, op, cur->id);
152 GNUNET_free (op);
153 return GNUNET_SYSERR;
154 }
155 if (o->dest_id > e->num_slaves)
156 {
157 fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
158 o->dest_id, ep_counter, op, cur->id);
159 GNUNET_free (op);
160 return GNUNET_SYSERR;
161 }
162
163
164 GNUNET_free (op_name);
165 GNUNET_asprintf(&op_name, "op-%u-value", ep_counter);
166 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
167 sec_name, op_name, &o->value))
168 {
169 fprintf (stderr, "Missing value in operation %u `%s' in episode %u\n",
170 ep_counter, op, cur->id);
171 GNUNET_free (op);
172 return GNUNET_SYSERR;
173 }
174 if (o->dest_id > e->num_slaves)
175 {
176 fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
177 o->dest_id, ep_counter, op, cur->id);
178 GNUNET_free (op);
179 return GNUNET_SYSERR;
180 }
181
182 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %llu\n",
183 ep_counter, cur->id, print_op (o->type), o->src_id, o->dest_id, o->value);
184
185 GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
186 GNUNET_free (op_name);
187 ep_counter++;
188 }
189 GNUNET_free (sec_name);
190
191 return GNUNET_OK;
192}
193
194static int
62load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) 195load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
63{ 196{
64 int e_counter = 0; 197 int e_counter = 0;
@@ -83,6 +216,13 @@ load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
83 cur->duration = e_duration; 216 cur->duration = e_duration;
84 cur->id = e_counter; 217 cur->id = e_counter;
85 218
219 if (GNUNET_OK != load_episode (e, cur, cfg))
220 {
221 GNUNET_free (sec_name);
222 GNUNET_free (cur);
223 return GNUNET_SYSERR;
224 }
225
86 fprintf (stderr, "Found episode %u with duration %s \n", 226 fprintf (stderr, "Found episode %u with duration %s \n",
87 e_counter, 227 e_counter,
88 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); 228 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
@@ -110,7 +250,8 @@ timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
110 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK; 250 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
111 fprintf (stderr, "Experiment timeout!\n"); 251 fprintf (stderr, "Experiment timeout!\n");
112 252
113 e->e_done_cb (e, GNUNET_SYSERR); 253 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
254 GNUNET_SYSERR);
114} 255}
115 256
116static void 257static void
@@ -131,7 +272,7 @@ timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
131 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); 272 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
132 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK; 273 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
133 } 274 }
134 e->e_done_cb (e, GNUNET_OK); 275 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
135 return; 276 return;
136 } 277 }
137 278
@@ -152,6 +293,7 @@ GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
152 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 293 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
153 e->e_done_cb = e_done_cb; 294 e->e_done_cb = e_done_cb;
154 e->ep_done_cb = ep_done_cb; 295 e->ep_done_cb = ep_done_cb;
296 e->start_time = GNUNET_TIME_absolute_get();
155 297
156 /* Start total time out */ 298 /* Start total time out */
157 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration, 299 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
@@ -168,6 +310,7 @@ GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
168 310
169} 311}
170 312
313
171struct Experiment * 314struct Experiment *
172GNUNET_ATS_TEST_experimentation_load (char *filename) 315GNUNET_ATS_TEST_experimentation_load (char *filename)
173{ 316{