aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/ats-tests
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/ats-tests')
-rw-r--r--src/ats-tests/ats-testing-experiment.c1088
-rw-r--r--src/ats-tests/ats-testing-log.c1023
-rw-r--r--src/ats-tests/ats-testing-preferences.c277
-rw-r--r--src/ats-tests/ats-testing-traffic.c412
-rw-r--r--src/ats-tests/ats-testing.c1052
-rw-r--r--src/ats-tests/ats-testing.h102
-rw-r--r--src/ats-tests/gnunet-ats-sim.c386
-rw-r--r--src/ats-tests/gnunet-solver-eval.c1147
-rw-r--r--src/ats-tests/perf_ats.c570
-rw-r--r--src/ats-tests/perf_ats.h23
-rw-r--r--src/ats-tests/perf_ats_logging.c713
11 files changed, 3539 insertions, 3254 deletions
diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c
index db5f411dd..676021926 100644
--- a/src/ats-tests/ats-testing-experiment.c
+++ b/src/ats-tests/ats-testing-experiment.c
@@ -28,35 +28,35 @@
28#include "ats-testing.h" 28#include "ats-testing.h"
29 29
30const char * 30const char *
31print_op(enum OperationType op) 31print_op (enum OperationType op)
32{ 32{
33 switch (op) 33 switch (op)
34 { 34 {
35 case START_SEND: 35 case START_SEND:
36 return "START_SEND"; 36 return "START_SEND";
37 37
38 case STOP_SEND: 38 case STOP_SEND:
39 return "STOP_SEND"; 39 return "STOP_SEND";
40 40
41 case START_PREFERENCE: 41 case START_PREFERENCE:
42 return "START_PREFERENCE"; 42 return "START_PREFERENCE";
43 43
44 case STOP_PREFERENCE: 44 case STOP_PREFERENCE:
45 return "STOP_PREFERENCE"; 45 return "STOP_PREFERENCE";
46 46
47 default: 47 default:
48 break; 48 break;
49 } 49 }
50 return ""; 50 return "";
51} 51}
52 52
53 53
54static struct Experiment * 54static struct Experiment *
55create_experiment() 55create_experiment ()
56{ 56{
57 struct Experiment *e; 57 struct Experiment *e;
58 58
59 e = GNUNET_new(struct Experiment); 59 e = GNUNET_new (struct Experiment);
60 e->name = NULL; 60 e->name = NULL;
61 e->num_masters = 0; 61 e->num_masters = 0;
62 e->num_slaves = 0; 62 e->num_slaves = 0;
@@ -66,7 +66,7 @@ create_experiment()
66} 66}
67 67
68static void 68static void
69free_experiment(struct Experiment *e) 69free_experiment (struct Experiment *e)
70{ 70{
71 struct Episode *cur; 71 struct Episode *cur;
72 struct Episode *next; 72 struct Episode *next;
@@ -75,28 +75,28 @@ free_experiment(struct Experiment *e)
75 75
76 next = e->start; 76 next = e->start;
77 for (cur = next; NULL != cur; cur = next) 77 for (cur = next; NULL != cur; cur = next)
78 { 78 {
79 next = cur->next; 79 next = cur->next;
80 80
81 next_o = cur->head; 81 next_o = cur->head;
82 for (cur_o = next_o; NULL != cur_o; cur_o = next_o) 82 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
83 { 83 {
84 next_o = cur_o->next; 84 next_o = cur_o->next;
85 GNUNET_free(cur_o); 85 GNUNET_free (cur_o);
86 }
87 GNUNET_free(cur);
88 } 86 }
87 GNUNET_free (cur);
88 }
89 89
90 GNUNET_free_non_null(e->name); 90 GNUNET_free_non_null (e->name);
91 GNUNET_free_non_null(e->cfg_file); 91 GNUNET_free_non_null (e->cfg_file);
92 GNUNET_free(e); 92 GNUNET_free (e);
93} 93}
94 94
95 95
96static int 96static int
97load_episode(struct Experiment *e, 97load_episode (struct Experiment *e,
98 struct Episode *cur, 98 struct Episode *cur,
99 struct GNUNET_CONFIGURATION_Handle *cfg) 99 struct GNUNET_CONFIGURATION_Handle *cfg)
100{ 100{
101 struct GNUNET_ATS_TEST_Operation *o; 101 struct GNUNET_ATS_TEST_Operation *o;
102 char *sec_name; 102 char *sec_name;
@@ -106,272 +106,297 @@ load_episode(struct Experiment *e,
106 char *pref; 106 char *pref;
107 int op_counter = 0; 107 int op_counter = 0;
108 108
109 fprintf(stderr, "Parsing episode %u\n", cur->id); 109 fprintf (stderr, "Parsing episode %u\n", cur->id);
110 GNUNET_asprintf(&sec_name, "episode-%u", cur->id); 110 GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
111 111
112 while (1) 112 while (1)
113 {
114 /* Load operation */
115 GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
116 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
117 sec_name,
118 op_name, &op))
113 { 119 {
114 /* Load operation */ 120 GNUNET_free (op_name);
115 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); 121 break;
116 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 122 }
117 sec_name, op_name, &op)) 123 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
118 { 124 /* operations = set_rate, start_send, stop_send, set_preference */
119 GNUNET_free(op_name); 125 if (0 == strcmp (op, "start_send"))
120 break; 126 {
121 } 127 o->type = START_SEND;
122 o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); 128 }
123 /* operations = set_rate, start_send, stop_send, set_preference */ 129 else if (0 == strcmp (op, "stop_send"))
124 if (0 == strcmp(op, "start_send")) 130 {
125 { 131 o->type = STOP_SEND;
126 o->type = START_SEND; 132 }
127 } 133 else if (0 == strcmp (op, "start_preference"))
128 else if (0 == strcmp(op, "stop_send")) 134 {
129 { 135 o->type = START_PREFERENCE;
130 o->type = STOP_SEND; 136 }
131 } 137 else if (0 == strcmp (op, "stop_preference"))
132 else if (0 == strcmp(op, "start_preference")) 138 {
133 { 139 o->type = STOP_PREFERENCE;
134 o->type = START_PREFERENCE; 140 }
135 } 141 else
136 else if (0 == strcmp(op, "stop_preference")) 142 {
137 { 143 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
138 o->type = STOP_PREFERENCE; 144 op_counter, op, cur->id);
139 } 145 GNUNET_free (op);
146 GNUNET_free (op_name);
147 GNUNET_free (o);
148 GNUNET_free (sec_name);
149 return GNUNET_SYSERR;
150 }
151 GNUNET_free (op_name);
152
153 /* Get source */
154 GNUNET_asprintf (&op_name, "op-%u-src", op_counter);
155 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
156 sec_name,
157 op_name,
158 &o->src_id))
159 {
160 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
161 op_counter, op, cur->id);
162 GNUNET_free (op);
163 GNUNET_free (op_name);
164 GNUNET_free (o);
165 GNUNET_free (sec_name);
166 return GNUNET_SYSERR;
167 }
168 if (o->src_id > (e->num_masters - 1))
169 {
170 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
171 o->src_id, op_counter, op, cur->id);
172 GNUNET_free (op);
173 GNUNET_free (op_name);
174 GNUNET_free (o);
175 GNUNET_free (sec_name);
176 return GNUNET_SYSERR;
177 }
178 GNUNET_free (op_name);
179
180 /* Get destination */
181 GNUNET_asprintf (&op_name, "op-%u-dest", op_counter);
182 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
183 sec_name,
184 op_name,
185 &o->dest_id))
186 {
187 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
188 op_counter, op, cur->id);
189 GNUNET_free (op);
190 GNUNET_free (op_name);
191 GNUNET_free (o);
192 GNUNET_free (sec_name);
193 return GNUNET_SYSERR;
194 }
195 if (o->dest_id > (e->num_slaves - 1))
196 {
197 fprintf (stderr,
198 "Invalid destination %llu in operation %u `%s' in episode %u\n",
199 o->dest_id, op_counter, op, cur->id);
200 GNUNET_free (op);
201 GNUNET_free (op_name);
202 GNUNET_free (o);
203 GNUNET_free (sec_name);
204 return GNUNET_SYSERR;
205 }
206 GNUNET_free (op_name);
207
208 GNUNET_asprintf (&op_name, "op-%u-type", op_counter);
209 if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string (cfg,
210 sec_name,
211 op_name,
212 &type)) &&
213 (STOP_SEND != o->type) &&
214 (STOP_PREFERENCE != o->type))
215 {
216 /* Load arguments for set_rate, start_send, set_preference */
217 if (0 == strcmp (type, "constant"))
218 {
219 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
220 }
221 else if (0 == strcmp (type, "linear"))
222 {
223 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
224 }
225 else if (0 == strcmp (type, "sinus"))
226 {
227 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
228 }
229 else if (0 == strcmp (type, "random"))
230 {
231 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
232 }
140 else 233 else
234 {
235 fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
236 op_counter, op, cur->id);
237 GNUNET_free (type);
238 GNUNET_free (op);
239 GNUNET_free (op_name);
240 GNUNET_free (sec_name);
241 GNUNET_free (o);
242 return GNUNET_SYSERR;
243 }
244 GNUNET_free (op_name);
245
246 /* Get base rate */
247 GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
248 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
249 sec_name,
250 op_name,
251 &o->base_rate))
252 {
253 fprintf (stderr,
254 "Missing base rate in operation %u `%s' in episode %u\n",
255 op_counter, op, cur->id);
256 GNUNET_free (type);
257 GNUNET_free (op);
258 GNUNET_free (op_name);
259 GNUNET_free (sec_name);
260 GNUNET_free (o);
261 return GNUNET_SYSERR;
262 }
263 GNUNET_free (op_name);
264
265 /* Get max rate */
266 GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
267 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
268 sec_name,
269 op_name,
270 &o->max_rate))
271 {
272 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
273 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
274 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
141 { 275 {
142 fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", 276 fprintf (stderr,
143 op_counter, op, cur->id); 277 "Missing max rate in operation %u `%s' in episode %u\n",
144 GNUNET_free(op); 278 op_counter, op, cur->id);
145 GNUNET_free(op_name); 279 GNUNET_free (type);
146 GNUNET_free(o); 280 GNUNET_free (op_name);
147 GNUNET_free(sec_name); 281 GNUNET_free (op);
282 GNUNET_free (o);
283 GNUNET_free (sec_name);
148 return GNUNET_SYSERR; 284 return GNUNET_SYSERR;
149 } 285 }
150 GNUNET_free(op_name); 286 }
151 287 GNUNET_free (op_name);
152 /* Get source */ 288
153 GNUNET_asprintf(&op_name, "op-%u-src", op_counter); 289 /* Get period */
154 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 290 GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
155 sec_name, op_name, &o->src_id)) 291 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
292 sec_name,
293 op_name,
294 &o->period))
295 {
296 o->period = cur->duration;
297 }
298 GNUNET_free (op_name);
299
300 if (START_PREFERENCE == o->type)
301 {
302 /* Get frequency */
303 GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
304 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
305 sec_name,
306 op_name,
307 &o->frequency))
156 { 308 {
157 fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", 309 fprintf (stderr,
158 op_counter, op, cur->id); 310 "Missing frequency in operation %u `%s' in episode %u\n",
159 GNUNET_free(op); 311 op_counter, op, cur->id);
160 GNUNET_free(op_name); 312 GNUNET_free (type);
161 GNUNET_free(o); 313 GNUNET_free (op_name);
162 GNUNET_free(sec_name); 314 GNUNET_free (op);
315 GNUNET_free (o);
316 GNUNET_free (sec_name);
163 return GNUNET_SYSERR; 317 return GNUNET_SYSERR;
164 } 318 }
165 if (o->src_id > (e->num_masters - 1)) 319 GNUNET_free (op_name);
320
321 /* Get preference */
322 GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
323 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
324 sec_name,
325 op_name,
326 &pref))
166 { 327 {
167 fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", 328 fprintf (stderr,
168 o->src_id, op_counter, op, cur->id); 329 "Missing preference in operation %u `%s' in episode %u\n",
169 GNUNET_free(op); 330 op_counter, op, cur->id);
170 GNUNET_free(op_name); 331 GNUNET_free (type);
171 GNUNET_free(o); 332 GNUNET_free (op_name);
172 GNUNET_free(sec_name); 333 GNUNET_free (op);
334 GNUNET_free_non_null (pref);
335 GNUNET_free (o);
336 GNUNET_free (sec_name);
173 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
174 } 338 }
175 GNUNET_free(op_name);
176 339
177 /* Get destination */ 340 if (0 == strcmp (pref, "bandwidth"))
178 GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); 341 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
179 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 342 else if (0 == strcmp (pref, "latency"))
180 sec_name, op_name, &o->dest_id)) 343 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
344 else
181 { 345 {
182 fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", 346 fprintf (stderr,
183 op_counter, op, cur->id); 347 "Invalid preference in operation %u `%s' in episode %u\n",
184 GNUNET_free(op); 348 op_counter, op, cur->id);
185 GNUNET_free(op_name); 349 GNUNET_free (type);
186 GNUNET_free(o); 350 GNUNET_free (op_name);
187 GNUNET_free(sec_name); 351 GNUNET_free (op);
352 GNUNET_free_non_null (pref);
353 GNUNET_free (o);
354 GNUNET_free (sec_name);
188 return GNUNET_SYSERR; 355 return GNUNET_SYSERR;
189 } 356 }
190 if (o->dest_id > (e->num_slaves - 1)) 357 GNUNET_free (pref);
191 { 358 GNUNET_free (op_name);
192 fprintf(stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n", 359 }
193 o->dest_id, op_counter, op, cur->id); 360 }
194 GNUNET_free(op);
195 GNUNET_free(op_name);
196 GNUNET_free(o);
197 GNUNET_free(sec_name);
198 return GNUNET_SYSERR;
199 }
200 GNUNET_free(op_name);
201
202 GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
203 if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
204 sec_name, op_name, &type)) &&
205 (STOP_SEND != o->type) &&
206 (STOP_PREFERENCE != o->type))
207 {
208 /* Load arguments for set_rate, start_send, set_preference */
209 if (0 == strcmp(type, "constant"))
210 {
211 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
212 }
213 else if (0 == strcmp(type, "linear"))
214 {
215 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
216 }
217 else if (0 == strcmp(type, "sinus"))
218 {
219 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
220 }
221 else if (0 == strcmp(type, "random"))
222 {
223 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
224 }
225 else
226 {
227 fprintf(stderr, "Invalid type %u `%s' in episode %u\n",
228 op_counter, op, cur->id);
229 GNUNET_free(type);
230 GNUNET_free(op);
231 GNUNET_free(op_name);
232 GNUNET_free(sec_name);
233 GNUNET_free(o);
234 return GNUNET_SYSERR;
235 }
236 GNUNET_free(op_name);
237
238 /* Get base rate */
239 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
240 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
241 sec_name, op_name, &o->base_rate))
242 {
243 fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n",
244 op_counter, op, cur->id);
245 GNUNET_free(type);
246 GNUNET_free(op);
247 GNUNET_free(op_name);
248 GNUNET_free(sec_name);
249 GNUNET_free(o);
250 return GNUNET_SYSERR;
251 }
252 GNUNET_free(op_name);
253
254 /* Get max rate */
255 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
256 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
257 sec_name, op_name, &o->max_rate))
258 {
259 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
260 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
261 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
262 {
263 fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n",
264 op_counter, op, cur->id);
265 GNUNET_free(type);
266 GNUNET_free(op_name);
267 GNUNET_free(op);
268 GNUNET_free(o);
269 GNUNET_free(sec_name);
270 return GNUNET_SYSERR;
271 }
272 }
273 GNUNET_free(op_name);
274
275 /* Get period */
276 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
277 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
278 sec_name, op_name, &o->period))
279 {
280 o->period = cur->duration;
281 }
282 GNUNET_free(op_name);
283
284 if (START_PREFERENCE == o->type)
285 {
286 /* Get frequency */
287 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
288 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
289 sec_name, op_name, &o->frequency))
290 {
291 fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n",
292 op_counter, op, cur->id);
293 GNUNET_free(type);
294 GNUNET_free(op_name);
295 GNUNET_free(op);
296 GNUNET_free(o);
297 GNUNET_free(sec_name);
298 return GNUNET_SYSERR;
299 }
300 GNUNET_free(op_name);
301
302 /* Get preference */
303 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
304 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
305 sec_name, op_name, &pref))
306 {
307 fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n",
308 op_counter, op, cur->id);
309 GNUNET_free(type);
310 GNUNET_free(op_name);
311 GNUNET_free(op);
312 GNUNET_free_non_null(pref);
313 GNUNET_free(o);
314 GNUNET_free(sec_name);
315 return GNUNET_SYSERR;
316 }
317
318 if (0 == strcmp(pref, "bandwidth"))
319 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
320 else if (0 == strcmp(pref, "latency"))
321 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
322 else
323 {
324 fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n",
325 op_counter, op, cur->id);
326 GNUNET_free(type);
327 GNUNET_free(op_name);
328 GNUNET_free(op);
329 GNUNET_free_non_null(pref);
330 GNUNET_free(o);
331 GNUNET_free(sec_name);
332 return GNUNET_SYSERR;
333 }
334 GNUNET_free(pref);
335 GNUNET_free(op_name);
336 }
337 }
338
339 /* Safety checks */
340 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
341 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
342 {
343 if ((o->max_rate - o->base_rate) > o->base_rate)
344 {
345 /* This will cause an underflow */
346 GNUNET_break(0);
347 }
348 fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
349 }
350
351 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
352 fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
353 op_counter, cur->id, print_op(o->type), o->src_id,
354 o->dest_id, (NULL != type) ? type : "",
355 o->base_rate, o->max_rate,
356 GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES));
357 else
358 fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
359 op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id);
360
361 GNUNET_free_non_null(type);
362 GNUNET_free(op);
363 361
364 GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o); 362 /* Safety checks */
365 op_counter++; 363 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
364 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
365 {
366 if ((o->max_rate - o->base_rate) > o->base_rate)
367 {
368 /* This will cause an underflow */
369 GNUNET_break (0);
370 }
371 fprintf (stderr,
372 "Selected max rate and base rate cannot be used for desired traffic form!\n");
366 } 373 }
367 GNUNET_free(sec_name); 374
375 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
376 fprintf (stderr,
377 "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
378 op_counter, cur->id, print_op (o->type), o->src_id,
379 o->dest_id, (NULL != type) ? type : "",
380 o->base_rate, o->max_rate,
381 GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
382 else
383 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
384 op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
385
386 GNUNET_free_non_null (type);
387 GNUNET_free (op);
388
389 GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o);
390 op_counter++;
391 }
392 GNUNET_free (sec_name);
368 393
369 return GNUNET_OK; 394 return GNUNET_OK;
370} 395}
371 396
372 397
373static int 398static int
374load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) 399load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
375{ 400{
376 int e_counter = 0; 401 int e_counter = 0;
377 char *sec_name; 402 char *sec_name;
@@ -382,380 +407,407 @@ load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
382 e_counter = 0; 407 e_counter = 0;
383 last = NULL; 408 last = NULL;
384 while (1) 409 while (1)
410 {
411 GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
412 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
413 sec_name,
414 "duration",
415 &e_duration))
385 { 416 {
386 GNUNET_asprintf(&sec_name, "episode-%u", e_counter); 417 GNUNET_free (sec_name);
387 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 418 break;
388 sec_name, "duration", &e_duration)) 419 }
389 {
390 GNUNET_free(sec_name);
391 break;
392 }
393
394 cur = GNUNET_new(struct Episode);
395 cur->duration = e_duration;
396 cur->id = e_counter;
397
398 if (GNUNET_OK != load_episode(e, cur, cfg))
399 {
400 GNUNET_free(sec_name);
401 GNUNET_free(cur);
402 return GNUNET_SYSERR;
403 }
404
405 fprintf(stderr, "Found episode %u with duration %s \n",
406 e_counter,
407 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
408 420
409 /* Update experiment */ 421 cur = GNUNET_new (struct Episode);
410 e->num_episodes++; 422 cur->duration = e_duration;
411 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); 423 cur->id = e_counter;
412 /* Put in linked list */
413 if (NULL == last)
414 e->start = cur;
415 else
416 last->next = cur;
417 424
418 GNUNET_free(sec_name); 425 if (GNUNET_OK != load_episode (e, cur, cfg))
419 e_counter++; 426 {
420 last = cur; 427 GNUNET_free (sec_name);
428 GNUNET_free (cur);
429 return GNUNET_SYSERR;
421 } 430 }
431
432 fprintf (stderr, "Found episode %u with duration %s \n",
433 e_counter,
434 GNUNET_STRINGS_relative_time_to_string (cur->duration,
435 GNUNET_YES));
436
437 /* Update experiment */
438 e->num_episodes++;
439 e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
440 cur->duration);
441 /* Put in linked list */
442 if (NULL == last)
443 e->start = cur;
444 else
445 last->next = cur;
446
447 GNUNET_free (sec_name);
448 e_counter++;
449 last = cur;
450 }
422 return e_counter; 451 return e_counter;
423} 452}
424 453
425 454
426static void 455static void
427timeout_experiment(void *cls) 456timeout_experiment (void *cls)
428{ 457{
429 struct Experiment *e = cls; 458 struct Experiment *e = cls;
430 459
431 e->experiment_timeout_task = NULL; 460 e->experiment_timeout_task = NULL;
432 fprintf(stderr, "Experiment timeout!\n"); 461 fprintf (stderr, "Experiment timeout!\n");
433 462
434 if (NULL != e->episode_timeout_task) 463 if (NULL != e->episode_timeout_task)
435 { 464 {
436 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 465 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
437 e->episode_timeout_task = NULL; 466 e->episode_timeout_task = NULL;
438 } 467 }
439 468
440 e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), 469 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
441 GNUNET_SYSERR); 470 GNUNET_SYSERR);
442} 471}
443 472
444 473
445static void 474static void
446enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) 475enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
447{ 476{
448 struct BenchmarkPeer *peer; 477 struct BenchmarkPeer *peer;
449 struct BenchmarkPartner *partner; 478 struct BenchmarkPartner *partner;
450 479
451 peer = GNUNET_ATS_TEST_get_peer(op->src_id); 480 peer = GNUNET_ATS_TEST_get_peer (op->src_id);
452 if (NULL == peer) 481 if (NULL == peer)
453 { 482 {
454 GNUNET_break(0); 483 GNUNET_break (0);
455 return; 484 return;
456 } 485 }
457 486
458 partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); 487 partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
459 if (NULL == partner) 488 if (NULL == partner)
460 { 489 {
461 GNUNET_break(0); 490 GNUNET_break (0);
462 return; 491 return;
463 } 492 }
464 493
465 fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); 494 fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
466 495
467 if (NULL != partner->tg) 496 if (NULL != partner->tg)
468 { 497 {
469 fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", op->src_id, op->dest_id); 498 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
470 GNUNET_ATS_TEST_generate_traffic_stop(partner->tg); 499 op->src_id, op->dest_id);
471 partner->tg = NULL; 500 GNUNET_ATS_TEST_generate_traffic_stop (partner->tg);
472 } 501 partner->tg = NULL;
473 502 }
474 partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner, 503
475 op->gen_type, op->base_rate, op->max_rate, op->period, 504 partner->tg = GNUNET_ATS_TEST_generate_traffic_start (peer, partner,
476 GNUNET_TIME_UNIT_FOREVER_REL); 505 op->gen_type,
506 op->base_rate,
507 op->max_rate,
508 op->period,
509 GNUNET_TIME_UNIT_FOREVER_REL);
477} 510}
478 511
479static void 512static void
480enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) 513enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
481{ 514{
482 struct BenchmarkPartner *p; 515 struct BenchmarkPartner *p;
483 516
484 p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); 517 p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
485 if (NULL == p) 518 if (NULL == p)
486 { 519 {
487 GNUNET_break(0); 520 GNUNET_break (0);
488 return; 521 return;
489 } 522 }
490 523
491 fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); 524 fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
492 525
493 if (NULL != p->tg) 526 if (NULL != p->tg)
494 { 527 {
495 fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", 528 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
496 op->src_id, op->dest_id); 529 op->src_id, op->dest_id);
497 GNUNET_ATS_TEST_generate_traffic_stop(p->tg); 530 GNUNET_ATS_TEST_generate_traffic_stop (p->tg);
498 p->tg = NULL; 531 p->tg = NULL;
499 } 532 }
500} 533}
501 534
502 535
503static void 536static void
504enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) 537enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
505{ 538{
506 struct BenchmarkPeer *peer; 539 struct BenchmarkPeer *peer;
507 struct BenchmarkPartner *partner; 540 struct BenchmarkPartner *partner;
508 541
509 peer = GNUNET_ATS_TEST_get_peer(op->src_id); 542 peer = GNUNET_ATS_TEST_get_peer (op->src_id);
510 if (NULL == peer) 543 if (NULL == peer)
511 { 544 {
512 GNUNET_break(0); 545 GNUNET_break (0);
513 return; 546 return;
514 } 547 }
515 548
516 partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); 549 partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
517 if (NULL == partner) 550 if (NULL == partner)
518 { 551 {
519 GNUNET_break(0); 552 GNUNET_break (0);
520 return; 553 return;
521 } 554 }
522 555
523 fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); 556 fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
524 557
525 if (NULL != partner->pg) 558 if (NULL != partner->pg)
526 { 559 {
527 fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", 560 fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
528 op->src_id, op->dest_id); 561 op->src_id, op->dest_id);
529 GNUNET_ATS_TEST_generate_preferences_stop(partner->pg); 562 GNUNET_ATS_TEST_generate_preferences_stop (partner->pg);
530 partner->pg = NULL; 563 partner->pg = NULL;
531 } 564 }
532 565
533 partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner, 566 partner->pg = GNUNET_ATS_TEST_generate_preferences_start (peer, partner,
534 op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency, 567 op->gen_type,
535 op->pref_type); 568 op->base_rate,
569 op->max_rate,
570 op->period,
571 op->frequency,
572 op->pref_type);
536} 573}
537 574
538static void 575static void
539enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) 576enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
540{ 577{
541 struct BenchmarkPartner *p; 578 struct BenchmarkPartner *p;
542 579
543 p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); 580 p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
544 if (NULL == p) 581 if (NULL == p)
545 { 582 {
546 GNUNET_break(0); 583 GNUNET_break (0);
547 return; 584 return;
548 } 585 }
549 586
550 fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); 587 fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id);
551 588
552 if (NULL != p->pg) 589 if (NULL != p->pg)
553 { 590 {
554 fprintf(stderr, "Stopping preference between master %llu slave %llu\n", 591 fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
555 op->src_id, op->dest_id); 592 op->src_id, op->dest_id);
556 GNUNET_ATS_TEST_generate_preferences_stop(p->pg); 593 GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
557 p->pg = NULL; 594 p->pg = NULL;
558 } 595 }
559} 596}
560 597
561static void enforce_episode(struct Episode *ep) 598static void enforce_episode (struct Episode *ep)
562{ 599{
563 struct GNUNET_ATS_TEST_Operation *cur; 600 struct GNUNET_ATS_TEST_Operation *cur;
564 601
565 for (cur = ep->head; NULL != cur; cur = cur->next) 602 for (cur = ep->head; NULL != cur; cur = cur->next)
603 {
604 fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
605 print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
606 switch (cur->type)
566 { 607 {
567 fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", 608 case START_SEND:
568 print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate); 609 enforce_start_send (cur);
569 switch (cur->type) 610 break;
570 {
571 case START_SEND:
572 enforce_start_send(cur);
573 break;
574 611
575 case STOP_SEND: 612 case STOP_SEND:
576 enforce_stop_send(cur); 613 enforce_stop_send (cur);
577 break; 614 break;
578 615
579 case START_PREFERENCE: 616 case START_PREFERENCE:
580 enforce_start_preference(cur); 617 enforce_start_preference (cur);
581 break; 618 break;
582 619
583 case STOP_PREFERENCE: 620 case STOP_PREFERENCE:
584 enforce_stop_preference(cur); 621 enforce_stop_preference (cur);
585 break; 622 break;
586 623
587 default: 624 default:
588 break; 625 break;
589 }
590 } 626 }
627 }
591} 628}
592 629
593 630
594static void 631static void
595timeout_episode(void *cls) 632timeout_episode (void *cls)
596{ 633{
597 struct Experiment *e = cls; 634 struct Experiment *e = cls;
598 635
599 e->episode_timeout_task = NULL; 636 e->episode_timeout_task = NULL;
600 if (NULL != e->ep_done_cb) 637 if (NULL != e->ep_done_cb)
601 e->ep_done_cb(e->cur); 638 e->ep_done_cb (e->cur);
602 639
603 /* Scheduling next */ 640 /* Scheduling next */
604 e->cur = e->cur->next; 641 e->cur = e->cur->next;
605 if (NULL == e->cur) 642 if (NULL == e->cur)
643 {
644 /* done */
645 fprintf (stderr, "Last episode done!\n");
646 if (NULL != e->experiment_timeout_task)
606 { 647 {
607 /* done */ 648 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
608 fprintf(stderr, "Last episode done!\n"); 649 e->experiment_timeout_task = NULL;
609 if (NULL != e->experiment_timeout_task)
610 {
611 GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
612 e->experiment_timeout_task = NULL;
613 }
614 e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
615 return;
616 } 650 }
617 651 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
618 fprintf(stderr, "Running episode %u with timeout %s\n", 652 GNUNET_OK);
619 e->cur->id, 653 return;
620 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 654 }
621 enforce_episode(e->cur); 655
622 656 fprintf (stderr, "Running episode %u with timeout %s\n",
623 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 657 e->cur->id,
624 &timeout_episode, e); 658 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
659 GNUNET_YES));
660 enforce_episode (e->cur);
661
662 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
663 &timeout_episode, e);
625} 664}
626 665
627 666
628void 667void
629GNUNET_ATS_TEST_experimentation_run(struct Experiment *e, 668GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
630 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, 669 GNUNET_ATS_TESTING_EpisodeDoneCallback
631 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) 670 ep_done_cb,
671 GNUNET_ATS_TESTING_ExperimentDoneCallback
672 e_done_cb)
632{ 673{
633 fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, 674 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
634 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 675 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
676 GNUNET_YES));
635 e->e_done_cb = e_done_cb; 677 e->e_done_cb = e_done_cb;
636 e->ep_done_cb = ep_done_cb; 678 e->ep_done_cb = ep_done_cb;
637 e->start_time = GNUNET_TIME_absolute_get(); 679 e->start_time = GNUNET_TIME_absolute_get ();
638 680
639 /* Start total time out */ 681 /* Start total time out */
640 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, 682 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
641 &timeout_experiment, e); 683 &timeout_experiment,
684 e);
642 685
643 /* Start */ 686 /* Start */
644 e->cur = e->start; 687 e->cur = e->start;
645 fprintf(stderr, "Running episode %u with timeout %s\n", 688 fprintf (stderr, "Running episode %u with timeout %s\n",
646 e->cur->id, 689 e->cur->id,
647 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 690 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
648 enforce_episode(e->cur); 691 GNUNET_YES));
649 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 692 enforce_episode (e->cur);
650 &timeout_episode, e); 693 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
694 &timeout_episode, e);
651} 695}
652 696
653 697
654struct Experiment * 698struct Experiment *
655GNUNET_ATS_TEST_experimentation_load(const char *filename) 699GNUNET_ATS_TEST_experimentation_load (const char *filename)
656{ 700{
657 struct Experiment *e; 701 struct Experiment *e;
658 struct GNUNET_CONFIGURATION_Handle *cfg; 702 struct GNUNET_CONFIGURATION_Handle *cfg;
659 703
660 e = NULL; 704 e = NULL;
661 705
662 cfg = GNUNET_CONFIGURATION_create(); 706 cfg = GNUNET_CONFIGURATION_create ();
663 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) 707 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
664 { 708 {
665 fprintf(stderr, "Failed to load `%s'\n", filename); 709 fprintf (stderr, "Failed to load `%s'\n", filename);
666 GNUNET_CONFIGURATION_destroy(cfg); 710 GNUNET_CONFIGURATION_destroy (cfg);
667 return NULL; 711 return NULL;
668 } 712 }
669 713
670 e = create_experiment(); 714 e = create_experiment ();
671 715
672 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", 716 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
673 "name", &e->name)) 717 "name", &e->name))
674 { 718 {
675 fprintf(stderr, "Invalid %s", "name"); 719 fprintf (stderr, "Invalid %s", "name");
676 free_experiment(e); 720 free_experiment (e);
677 return NULL; 721 return NULL;
678 } 722 }
679 else 723 else
680 fprintf(stderr, "Experiment name: `%s'\n", e->name); 724 fprintf (stderr, "Experiment name: `%s'\n", e->name);
681 725
682 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", 726 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
683 "cfg_file", &e->cfg_file)) 727 "experiment",
684 { 728 "cfg_file",
685 fprintf(stderr, "Invalid %s", "cfg_file"); 729 &e->cfg_file))
686 free_experiment(e); 730 {
687 return NULL; 731 fprintf (stderr, "Invalid %s", "cfg_file");
688 } 732 free_experiment (e);
733 return NULL;
734 }
689 else 735 else
690 fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file); 736 fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
691 737
692 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", 738 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
693 "masters", &e->num_masters)) 739 "masters",
694 { 740 &e->num_masters))
695 fprintf(stderr, "Invalid %s", "masters"); 741 {
696 free_experiment(e); 742 fprintf (stderr, "Invalid %s", "masters");
697 return NULL; 743 free_experiment (e);
698 } 744 return NULL;
745 }
699 else 746 else
700 fprintf(stderr, "Experiment masters: `%llu'\n", 747 fprintf (stderr, "Experiment masters: `%llu'\n",
701 e->num_masters); 748 e->num_masters);
702 749
703 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", 750 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
704 "slaves", &e->num_slaves)) 751 "slaves",
705 { 752 &e->num_slaves))
706 fprintf(stderr, "Invalid %s", "slaves"); 753 {
707 free_experiment(e); 754 fprintf (stderr, "Invalid %s", "slaves");
708 return NULL; 755 free_experiment (e);
709 } 756 return NULL;
757 }
710 else 758 else
711 fprintf(stderr, "Experiment slaves: `%llu'\n", 759 fprintf (stderr, "Experiment slaves: `%llu'\n",
712 e->num_slaves); 760 e->num_slaves);
713 761
714 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", 762 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
715 "log_freq", &e->log_freq)) 763 "log_freq",
716 { 764 &e->log_freq))
717 fprintf(stderr, "Invalid %s", "log_freq"); 765 {
718 free_experiment(e); 766 fprintf (stderr, "Invalid %s", "log_freq");
719 return NULL; 767 free_experiment (e);
720 } 768 return NULL;
769 }
721 else 770 else
722 fprintf(stderr, "Experiment logging frequency: `%s'\n", 771 fprintf (stderr, "Experiment logging frequency: `%s'\n",
723 GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); 772 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
724 773
725 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", 774 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
726 "max_duration", &e->max_duration)) 775 "max_duration",
727 { 776 &e->max_duration))
728 fprintf(stderr, "Invalid %s", "max_duration"); 777 {
729 free_experiment(e); 778 fprintf (stderr, "Invalid %s", "max_duration");
730 return NULL; 779 free_experiment (e);
731 } 780 return NULL;
781 }
732 else 782 else
733 fprintf(stderr, "Experiment duration: `%s'\n", 783 fprintf (stderr, "Experiment duration: `%s'\n",
734 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 784 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
785 GNUNET_YES));
735 786
736 load_episodes(e, cfg); 787 load_episodes (e, cfg);
737 fprintf(stderr, "Loaded %u episodes with total duration %s\n", 788 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
738 e->num_episodes, 789 e->num_episodes,
739 GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); 790 GNUNET_STRINGS_relative_time_to_string (e->total_duration,
791 GNUNET_YES));
740 792
741 GNUNET_CONFIGURATION_destroy(cfg); 793 GNUNET_CONFIGURATION_destroy (cfg);
742 return e; 794 return e;
743} 795}
744 796
745void 797void
746GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e) 798GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
747{ 799{
748 if (NULL != e->experiment_timeout_task) 800 if (NULL != e->experiment_timeout_task)
749 { 801 {
750 GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); 802 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
751 e->experiment_timeout_task = NULL; 803 e->experiment_timeout_task = NULL;
752 } 804 }
753 if (NULL != e->episode_timeout_task) 805 if (NULL != e->episode_timeout_task)
754 { 806 {
755 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 807 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
756 e->episode_timeout_task = NULL; 808 e->episode_timeout_task = NULL;
757 } 809 }
758 free_experiment(e); 810 free_experiment (e);
759} 811}
760 812
761/* end of file ats-testing-experiment.c*/ 813/* end of file ats-testing-experiment.c*/
diff --git a/src/ats-tests/ats-testing-log.c b/src/ats-tests/ats-testing-log.c
index a362955d2..12a08ffda 100644
--- a/src/ats-tests/ats-testing-log.c
+++ b/src/ats-tests/ats-testing-log.c
@@ -72,7 +72,8 @@
72/** 72/**
73 * A single logging time step for a partner 73 * A single logging time step for a partner
74 */ 74 */
75struct PartnerLoggingTimestep { 75struct PartnerLoggingTimestep
76{
76 /** 77 /**
77 * Peer 78 * Peer
78 */ 79 */
@@ -142,7 +143,8 @@ struct PartnerLoggingTimestep {
142/** 143/**
143 * A single logging time step for a peer 144 * A single logging time step for a peer
144 */ 145 */
145struct PeerLoggingTimestep { 146struct PeerLoggingTimestep
147{
146 /** 148 /**
147 * Next in DLL 149 * Next in DLL
148 */ 150 */
@@ -197,7 +199,8 @@ struct PeerLoggingTimestep {
197/** 199/**
198 * Entry for a benchmark peer 200 * Entry for a benchmark peer
199 */ 201 */
200struct LoggingPeer { 202struct LoggingPeer
203{
201 /** 204 /**
202 * Peer 205 * Peer
203 */ 206 */
@@ -219,7 +222,8 @@ struct LoggingPeer {
219 struct PeerLoggingTimestep *tail; 222 struct PeerLoggingTimestep *tail;
220}; 223};
221 224
222struct LoggingHandle { 225struct LoggingHandle
226{
223 /** 227 /**
224 * Logging task 228 * Logging task
225 */ 229 */
@@ -244,179 +248,205 @@ struct LoggingHandle {
244 248
245 249
246static void 250static void
247write_throughput_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) 251write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs,
252 int slaves)
248{ 253{
249 struct GNUNET_DISK_FileHandle *f; 254 struct GNUNET_DISK_FileHandle *f;
250 char * gfn; 255 char *gfn;
251 char *data; 256 char *data;
252 int c_s; 257 int c_s;
253 258
254 GNUNET_asprintf(&gfn, "gnuplot_throughput_%s", fn); 259 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn);
255 fprintf(stderr, "Writing throughput plot for master %u and %u slaves to `%s'\n", 260 fprintf (stderr,
256 lp->peer->no, slaves, gfn); 261 "Writing throughput plot for master %u and %u slaves to `%s'\n",
262 lp->peer->no, slaves, gfn);
257 263
258 f = GNUNET_DISK_file_open(gfn, 264 f = GNUNET_DISK_file_open (gfn,
259 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 265 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
260 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | 266 GNUNET_DISK_PERM_USER_EXEC
261 GNUNET_DISK_PERM_USER_WRITE); 267 | GNUNET_DISK_PERM_USER_READ
268 | GNUNET_DISK_PERM_USER_WRITE);
262 if (NULL == f) 269 if (NULL == f)
263 { 270 {
264 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
265 GNUNET_free(gfn); 272 gfn);
266 return; 273 GNUNET_free (gfn);
267 } 274 return;
275 }
268 276
269 /* Write header */ 277 /* Write header */
270 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, 278 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE,
271 strlen(THROUGHPUT_TEMPLATE))) 279 strlen (THROUGHPUT_TEMPLATE)))
272 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
273 "Cannot write data to plot file `%s'\n", gfn); 281 "Cannot write data to plot file `%s'\n", gfn);
274 282
275 /* Write master data */ 283 /* Write master data */
276 GNUNET_asprintf(&data, 284 GNUNET_asprintf (&data,
277 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ 285 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
278 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", 286 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
279 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, 287 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
280 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); 288 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
281 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 289 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
282 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 290 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
283 GNUNET_free(data); 291 "Cannot write data to plot file `%s'\n", gfn);
292 GNUNET_free (data);
284 293
285 for (c_s = 0; c_s < slaves; c_s++) 294 for (c_s = 0; c_s < slaves; c_s++)
286 { 295 {
287 GNUNET_asprintf(&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ 296 GNUNET_asprintf (&data,
288 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", 297 "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
289 fs[c_s], 298 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
290 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, 299 fs[c_s],
291 lp->peer->no, 300 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT,
292 lp->peer->partners[c_s].dest->no, 301 lp->peer->no,
293 fs[c_s], 302 lp->peer->partners[c_s].dest->no,
294 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, 303 fs[c_s],
295 lp->peer->no, 304 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV,
296 lp->peer->partners[c_s].dest->no, 305 lp->peer->no,
297 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 306 lp->peer->partners[c_s].dest->no,
298 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 307 (c_s < lp->peer->num_partners - 1) ? ", \\" :
299 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 308 "\n pause -1");
300 GNUNET_free(data); 309 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
301 } 310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
302 311 "Cannot write data to plot file `%s'\n", gfn);
303 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 312 GNUNET_free (data);
304 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 313 }
305 "Cannot close gnuplot file `%s'\n", gfn); 314
315 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
316 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
317 "Cannot close gnuplot file `%s'\n", gfn);
306 else 318 else
307 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 319 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
308 "Data successfully written to plot file `%s'\n", gfn); 320 "Data successfully written to plot file `%s'\n", gfn);
309 GNUNET_free(gfn); 321 GNUNET_free (gfn);
310} 322}
311 323
312 324
313static void 325static void
314write_rtt_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) 326write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
327 slaves)
315{ 328{
316 struct GNUNET_DISK_FileHandle *f; 329 struct GNUNET_DISK_FileHandle *f;
317 char * gfn; 330 char *gfn;
318 char *data; 331 char *data;
319 int c_s; 332 int c_s;
320 333
321 GNUNET_asprintf(&gfn, "gnuplot_rtt_%s", fn); 334 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn);
322 fprintf(stderr, "Writing rtt plot for master %u to `%s'\n", 335 fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
323 lp->peer->no, gfn); 336 lp->peer->no, gfn);
324 337
325 f = GNUNET_DISK_file_open(gfn, 338 f = GNUNET_DISK_file_open (gfn,
326 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 339 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
327 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | 340 GNUNET_DISK_PERM_USER_EXEC
328 GNUNET_DISK_PERM_USER_WRITE); 341 | GNUNET_DISK_PERM_USER_READ
342 | GNUNET_DISK_PERM_USER_WRITE);
329 if (NULL == f) 343 if (NULL == f)
330 { 344 {
331 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
332 GNUNET_free(gfn); 346 gfn);
333 return; 347 GNUNET_free (gfn);
334 } 348 return;
349 }
335 350
336 /* Write header */ 351 /* Write header */
337 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE))) 352 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen (
338 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 353 RTT_TEMPLATE)))
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 "Cannot write data to plot file `%s'\n", gfn);
339 356
340 for (c_s = 0; c_s < slaves; c_s++) 357 for (c_s = 0; c_s < slaves; c_s++)
341 { 358 {
342 GNUNET_asprintf(&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", 359 GNUNET_asprintf (&data,
343 (0 == c_s) ? "plot " : "", 360 "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
344 fs[c_s], 361 (0 == c_s) ? "plot " : "",
345 LOG_ITEMS_TIME + LOG_ITEM_APP_RTT, 362 fs[c_s],
346 lp->peer->no, 363 LOG_ITEMS_TIME + LOG_ITEM_APP_RTT,
347 lp->peer->partners[c_s].dest->no, 364 lp->peer->no,
348 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 365 lp->peer->partners[c_s].dest->no,
349 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 366 (c_s < lp->peer->num_partners - 1) ? ", \\" :
350 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 367 "\n pause -1");
351 GNUNET_free(data); 368 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
352 } 369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
353 370 "Cannot write data to plot file `%s'\n", gfn);
354 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 371 GNUNET_free (data);
355 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); 372 }
373
374 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
376 gfn);
356 else 377 else
357 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); 378 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
358 GNUNET_free(gfn); 379 "Data successfully written to plot file `%s'\n", gfn);
380 GNUNET_free (gfn);
359} 381}
360 382
361static void 383static void
362write_bw_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) 384write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
385 slaves)
363{ 386{
364 struct GNUNET_DISK_FileHandle *f; 387 struct GNUNET_DISK_FileHandle *f;
365 char * gfn; 388 char *gfn;
366 char *data; 389 char *data;
367 int c_s; 390 int c_s;
368 391
369 GNUNET_asprintf(&gfn, "gnuplot_bw_%s", fn); 392 GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn);
370 fprintf(stderr, "Writing bandwidth plot for master %u to `%s'\n", 393 fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
371 lp->peer->no, gfn); 394 lp->peer->no, gfn);
372 395
373 f = GNUNET_DISK_file_open(gfn, 396 f = GNUNET_DISK_file_open (gfn,
374 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 397 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
375 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | 398 GNUNET_DISK_PERM_USER_EXEC
376 GNUNET_DISK_PERM_USER_WRITE); 399 | GNUNET_DISK_PERM_USER_READ
400 | GNUNET_DISK_PERM_USER_WRITE);
377 if (NULL == f) 401 if (NULL == f)
378 { 402 {
379 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
380 GNUNET_free(gfn); 404 gfn);
381 return; 405 GNUNET_free (gfn);
382 } 406 return;
407 }
383 408
384 /* Write header */ 409 /* Write header */
385 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE))) 410 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen (
386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 411 BW_TEMPLATE)))
387 "Cannot write data to plot file `%s'\n", gfn); 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
413 "Cannot write data to plot file `%s'\n", gfn);
388 414
389 for (c_s = 0; c_s < slaves; c_s++) 415 for (c_s = 0; c_s < slaves; c_s++)
390 { 416 {
391 GNUNET_asprintf(&data, "%s" \ 417 GNUNET_asprintf (&data, "%s" \
392 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ 418 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
393 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \ 419 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
394 "%s\n", 420 "%s\n",
395 (0 == c_s) ? "plot " : "", 421 (0 == c_s) ? "plot " : "",
396 fs[c_s], 422 fs[c_s],
397 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT, 423 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT,
398 lp->peer->no, c_s, 424 lp->peer->no, c_s,
399 fs[c_s], 425 fs[c_s],
400 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN, 426 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN,
401 lp->peer->no, c_s, 427 lp->peer->no, c_s,
402 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 428 (c_s < lp->peer->num_partners - 1) ? ", \\" :
403 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 429 "\n pause -1");
404 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 430 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
405 GNUNET_free(data); 431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406 } 432 "Cannot write data to plot file `%s'\n", gfn);
407 433 GNUNET_free (data);
408 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 434 }
409 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); 435
436 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
438 gfn);
410 else 439 else
411 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); 440 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
412 GNUNET_free(gfn); 441 "Data successfully written to plot file `%s'\n", gfn);
442 GNUNET_free (gfn);
413} 443}
414 444
415 445
416void 446void
417GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, 447GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
418 const char *experiment_name, 448 const char *experiment_name,
419 int plots) 449 int plots)
420{ 450{
421 struct GNUNET_DISK_FileHandle *f[l->num_slaves]; 451 struct GNUNET_DISK_FileHandle *f[l->num_slaves];
422 struct GNUNET_DISK_FileHandle *f_m; 452 struct GNUNET_DISK_FileHandle *f_m;
@@ -431,182 +461,207 @@ GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l,
431 int c_s; 461 int c_s;
432 462
433 463
434 timestamp = GNUNET_TIME_absolute_get(); 464 timestamp = GNUNET_TIME_absolute_get ();
435 465
436 tmp_exp_name = experiment_name; 466 tmp_exp_name = experiment_name;
437 for (c_m = 0; c_m < l->num_masters; c_m++) 467 for (c_m = 0; c_m < l->num_masters; c_m++)
468 {
469 GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s",
470 experiment_name, timestamp.abs_value_us, c_m, l->name);
471 fprintf (stderr, "Writing data for master %u to file `%s'\n",
472 c_m, filename_master);
473
474 f_m = GNUNET_DISK_file_open (filename_master,
475 GNUNET_DISK_OPEN_WRITE
476 | GNUNET_DISK_OPEN_CREATE,
477 GNUNET_DISK_PERM_USER_READ
478 | GNUNET_DISK_PERM_USER_WRITE);
479 if (NULL == f_m)
438 { 480 {
439 GNUNET_asprintf(&filename_master, "%s_%llu_master%u_%s", 481 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
440 experiment_name, timestamp.abs_value_us, c_m, l->name); 482 filename_master);
441 fprintf(stderr, "Writing data for master %u to file `%s'\n", 483 GNUNET_free (filename_master);
442 c_m, filename_master); 484 return;
443 485 }
444 f_m = GNUNET_DISK_file_open(filename_master,
445 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
446 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
447 if (NULL == f_m)
448 {
449 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_master);
450 GNUNET_free(filename_master);
451 return;
452 }
453 486
454 GNUNET_asprintf(&data, "# master %u; experiment : %s\n" 487 GNUNET_asprintf (&data, "# master %u; experiment : %s\n"
455 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n", 488 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n",
456 c_m, experiment_name); 489 c_m, experiment_name);
457 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data))) 490 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
458 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
459 "Cannot write data to log file `%s'\n", filename_master); 492 "Cannot write data to log file `%s'\n", filename_master);
460 GNUNET_free(data); 493 GNUNET_free (data);
461 494
462 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) 495 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
463 { 496 {
464 GNUNET_asprintf(&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s", 497 GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s",
465 tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name); 498 tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name);
466 499
467 fprintf(stderr, "Writing data for master %u slave %u to file `%s'\n", 500 fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n",
468 c_m, c_s, filename_slaves[c_s]); 501 c_m, c_s, filename_slaves[c_s]);
469 502
470 f[c_s] = GNUNET_DISK_file_open(filename_slaves[c_s], 503 f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s],
471 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 504 GNUNET_DISK_OPEN_WRITE
472 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 505 | GNUNET_DISK_OPEN_CREATE,
473 if (NULL == f[c_s]) 506 GNUNET_DISK_PERM_USER_READ
474 { 507 | GNUNET_DISK_PERM_USER_WRITE);
475 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_slaves[c_s]); 508 if (NULL == f[c_s])
476 GNUNET_free(filename_slaves[c_s]); 509 {
477 GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(f_m)); 510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
478 GNUNET_free(filename_master); 511 filename_slaves[c_s]);
479 return; 512 GNUNET_free (filename_slaves[c_s]);
480 } 513 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (f_m));
481 514 GNUNET_free (filename_master);
482 /* Header */ 515 return;
483 GNUNET_asprintf(&data, "# master %u; slave %u ; experiment : %s\n" 516 }
484 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \ 517
485 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \ 518 /* Header */
486 "pref bandwidth; pref delay\n", 519 GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
487 c_m, c_s, experiment_name); 520 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
488 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data))) 521 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
489 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 522 "pref bandwidth; pref delay\n",
490 "Cannot write data to log file `%s'\n", filename_slaves[c_s]); 523 c_m, c_s, experiment_name);
491 GNUNET_free(data); 524 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (data)))
492 } 525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 "Cannot write data to log file `%s'\n",
527 filename_slaves[c_s]);
528 GNUNET_free (data);
529 }
530
531 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
532 {
533 if (l->verbose)
534 fprintf (stderr,
535 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
536 l->lp[c_m].peer->no,
537 (long long unsigned int) cur_lt->timestamp.abs_value_us,
538 (long long unsigned int) GNUNET_TIME_absolute_get_difference (
539 l->lp[c_m].start,
540 cur_lt
541 ->timestamp).rel_value_us / 1000,
542 cur_lt->total_messages_sent,
543 cur_lt->total_bytes_sent,
544 cur_lt->total_throughput_send,
545 cur_lt->total_messages_received,
546 cur_lt->total_bytes_received,
547 cur_lt->total_throughput_recv);
548
549 /* Assembling master string */
550 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
551 (long long unsigned int) cur_lt->timestamp.abs_value_us,
552 (long long unsigned
553 int) GNUNET_TIME_absolute_get_difference (
554 l->lp[c_m].start,
555 cur_lt
556 ->timestamp).
557 rel_value_us / 1000,
558 cur_lt->total_messages_sent,
559 cur_lt->total_bytes_sent,
560 cur_lt->total_throughput_send,
561 cur_lt->total_messages_received,
562 cur_lt->total_bytes_received,
563 cur_lt->total_throughput_recv);
564
565 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 "Cannot write data to master file %u\n", c_m);
568 GNUNET_free (data);
493 569
494 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
495 {
496 if (l->verbose)
497 fprintf(stderr,
498 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
499 l->lp[c_m].peer->no,
500 (long long unsigned int)cur_lt->timestamp.abs_value_us,
501 (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
502 cur_lt->timestamp).rel_value_us / 1000,
503 cur_lt->total_messages_sent,
504 cur_lt->total_bytes_sent,
505 cur_lt->total_throughput_send,
506 cur_lt->total_messages_received,
507 cur_lt->total_bytes_received,
508 cur_lt->total_throughput_recv);
509
510 /* Assembling master string */
511 GNUNET_asprintf(&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
512 (long long unsigned int)cur_lt->timestamp.abs_value_us,
513 (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
514 cur_lt->timestamp).rel_value_us / 1000,
515 cur_lt->total_messages_sent,
516 cur_lt->total_bytes_sent,
517 cur_lt->total_throughput_send,
518 cur_lt->total_messages_received,
519 cur_lt->total_bytes_received,
520 cur_lt->total_throughput_recv);
521
522 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
523 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
524 "Cannot write data to master file %u\n", c_m);
525 GNUNET_free(data);
526
527
528 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
529 {
530 plt = &cur_lt->slaves_log[c_s];
531 /* Log partners */
532
533 /* Assembling slave string */
534 GNUNET_asprintf(&data,
535 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
536 (long long unsigned int)cur_lt->timestamp.abs_value_us,
537 (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
538 cur_lt->timestamp).rel_value_us / 1000,
539 plt->total_messages_sent,
540 plt->total_bytes_sent,
541 plt->throughput_sent,
542 plt->total_messages_received,
543 plt->total_bytes_received,
544 plt->throughput_recv,
545 (double)plt->app_rtt / 1000,
546 plt->bandwidth_in,
547 plt->bandwidth_out,
548 plt->ats_delay,
549 plt->ats_distance,
550 plt->ats_network_type,
551 plt->ats_utilization_out,
552 plt->ats_utilization_in,
553 plt->pref_bandwidth,
554 plt->pref_delay);
555
556 if (l->verbose)
557 fprintf(stderr,
558 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n",
559 plt->slave->no,
560 plt->total_messages_sent,
561 plt->total_bytes_sent,
562 plt->throughput_sent,
563 plt->total_messages_received,
564 plt->total_bytes_received,
565 plt->throughput_recv,
566 plt->app_rtt,
567 (long long unsigned int)plt->ats_delay.rel_value_us,
568 plt->bandwidth_in,
569 plt->bandwidth_out);
570
571 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
572 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
573 "Cannot write data to log file `%s'\n", filename_slaves[c_s]);
574 GNUNET_free(data);
575 }
576 }
577 570
578 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) 571 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
579 { 572 {
580 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f[c_s])) 573 plt = &cur_lt->slaves_log[c_s];
581 { 574 /* Log partners */
582 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 575
583 "Cannot close log file for master[%u] slave[%u]\n", c_m, c_s); 576 /* Assembling slave string */
584 continue; 577 GNUNET_asprintf (&data,
585 } 578 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
586 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 579 (long long unsigned
587 "Data file successfully written to log file for `%s'\n", 580 int) cur_lt->timestamp.abs_value_us,
588 filename_slaves[c_s]); 581 (long long unsigned
589 } 582 int) GNUNET_TIME_absolute_get_difference (
583 l->lp[c_m].start,
584 cur_lt
585 ->timestamp)
586 .rel_value_us / 1000,
587 plt->total_messages_sent,
588 plt->total_bytes_sent,
589 plt->throughput_sent,
590 plt->total_messages_received,
591 plt->total_bytes_received,
592 plt->throughput_recv,
593 (double) plt->app_rtt / 1000,
594 plt->bandwidth_in,
595 plt->bandwidth_out,
596 plt->ats_delay,
597 plt->ats_distance,
598 plt->ats_network_type,
599 plt->ats_utilization_out,
600 plt->ats_utilization_in,
601 plt->pref_bandwidth,
602 plt->pref_delay);
603
604 if (l->verbose)
605 fprintf (stderr,
606 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n",
607 plt->slave->no,
608 plt->total_messages_sent,
609 plt->total_bytes_sent,
610 plt->throughput_sent,
611 plt->total_messages_received,
612 plt->total_bytes_received,
613 plt->throughput_recv,
614 plt->app_rtt,
615 (long long unsigned int) plt->ats_delay.rel_value_us,
616 plt->bandwidth_in,
617 plt->bandwidth_out);
618
619 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (
620 data)))
621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
622 "Cannot write data to log file `%s'\n",
623 filename_slaves[c_s]);
624 GNUNET_free (data);
625 }
626 }
590 627
591 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f_m)) 628 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
592 { 629 {
593 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, 630 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f[c_s]))
594 "close", 631 {
595 filename_master); 632 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
596 GNUNET_free(filename_master); 633 "Cannot close log file for master[%u] slave[%u]\n", c_m,
597 return; 634 c_s);
598 } 635 continue;
599 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 636 }
600 "Data file successfully written to log file for master `%s'\n", filename_master); 637 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
638 "Data file successfully written to log file for `%s'\n",
639 filename_slaves[c_s]);
640 }
601 641
602 if (GNUNET_YES == plots) 642 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f_m))
603 { 643 {
604 write_throughput_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); 644 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
605 write_rtt_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); 645 "close",
606 write_bw_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); 646 filename_master);
607 } 647 GNUNET_free (filename_master);
648 return;
608 } 649 }
609 GNUNET_free(filename_master); 650 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
651 "Data file successfully written to log file for master `%s'\n",
652 filename_master);
653
654 if (GNUNET_YES == plots)
655 {
656 write_throughput_gnuplot_script (filename_master, &l->lp[c_m],
657 filename_slaves, l->num_slaves);
658 write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
659 l->num_slaves);
660 write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
661 l->num_slaves);
662 }
663 }
664 GNUNET_free (filename_master);
610} 665}
611 666
612/** 667/**
@@ -615,7 +670,7 @@ GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l,
615 * @param l logging handle to use 670 * @param l logging handle to use
616 */ 671 */
617void 672void
618GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l) 673GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
619{ 674{
620 struct LoggingPeer *bp; 675 struct LoggingPeer *bp;
621 struct PeerLoggingTimestep *mlt; 676 struct PeerLoggingTimestep *mlt;
@@ -633,180 +688,188 @@ GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l)
633 return; 688 return;
634 689
635 for (c_m = 0; c_m < l->num_masters; c_m++) 690 for (c_m = 0; c_m < l->num_masters; c_m++)
691 {
692 bp = &l->lp[c_m];
693 mlt = GNUNET_new (struct PeerLoggingTimestep);
694 GNUNET_CONTAINER_DLL_insert_tail (l->lp[c_m].head, l->lp[c_m].tail, mlt);
695 prev_log_mlt = mlt->prev;
696
697 /* Collect data */
698 /* Current master state */
699 mlt->timestamp = GNUNET_TIME_absolute_get ();
700 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
701 mlt->total_messages_sent = bp->peer->total_messages_sent;
702 mlt->total_bytes_received = bp->peer->total_bytes_received;
703 mlt->total_messages_received = bp->peer->total_messages_received;
704
705 /* Throughput */
706 if (NULL == prev_log_mlt)
707 {
708 /* Get difference to start */
709 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start,
710 mlt->timestamp);
711 }
712 else
713 {
714 /* Get difference to last timestep */
715 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp,
716 mlt->timestamp);
717 }
718
719 /* Multiplication factor for throughput calculation */
720 mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us
721 / (delta.rel_value_us);
722
723 /* Total throughput */
724 if (NULL != prev_log_mlt)
725 {
726 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
727 {
728 mlt->total_throughput_send = mult * (mlt->total_bytes_sent
729 - mlt->prev->total_bytes_sent);
730 }
731 else
732 {
733 mlt->total_throughput_send = 0;
734 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
735 }
736
737 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
738 {
739 mlt->total_throughput_recv = mult * (mlt->total_bytes_received
740 - mlt->prev->total_bytes_received);
741 }
742 else
743 {
744 mlt->total_throughput_recv = 0;
745 // mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
746 }
747 }
748 else
749 {
750 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
751 mlt->total_throughput_recv = mult * mlt->total_bytes_received;
752 }
753
754 if (GNUNET_YES == l->verbose)
755 {
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
758 c_m,
759 (unsigned long long) delta.rel_value_us,
760 mlt->total_bytes_sent,
761 mlt->total_bytes_received,
762 mlt->total_throughput_send,
763 mlt->total_throughput_recv);
764 }
765
766 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners
767 * sizeof(struct PartnerLoggingTimestep));
768
769 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
636 { 770 {
637 bp = &l->lp[c_m]; 771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
638 mlt = GNUNET_new(struct PeerLoggingTimestep); 772 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
639 GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt); 773
640 prev_log_mlt = mlt->prev; 774 p = &bp->peer->partners[c_s];
641 775 slt = &mlt->slaves_log[c_s];
642 /* Collect data */ 776
643 /* Current master state */ 777 slt->slave = p->dest;
644 mlt->timestamp = GNUNET_TIME_absolute_get(); 778 /* Bytes sent from master to this slave */
645 mlt->total_bytes_sent = bp->peer->total_bytes_sent; 779 slt->total_bytes_sent = p->bytes_sent;
646 mlt->total_messages_sent = bp->peer->total_messages_sent; 780 /* Messages sent from master to this slave */
647 mlt->total_bytes_received = bp->peer->total_bytes_received; 781 slt->total_messages_sent = p->messages_sent;
648 mlt->total_messages_received = bp->peer->total_messages_received; 782 /* Bytes master received from this slave */
649 783 slt->total_bytes_received = p->bytes_received;
650 /* Throughput */ 784 /* Messages master received from this slave */
785 slt->total_messages_received = p->messages_received;
786 slt->total_app_rtt = p->total_app_rtt;
787 /* ats performance information */
788 slt->ats_delay = p->props.delay;
789 slt->ats_distance = p->props.distance;
790 slt->ats_network_type = p->props.scope;
791 slt->ats_utilization_in = p->props.utilization_out;
792 slt->ats_utilization_out = p->props.utilization_out;
793 slt->bandwidth_in = p->bandwidth_in;
794 slt->bandwidth_out = p->bandwidth_out;
795 slt->pref_bandwidth = p->pref_bandwidth;
796 slt->pref_delay = p->pref_delay;
797
798 /* Total application level rtt */
651 if (NULL == prev_log_mlt) 799 if (NULL == prev_log_mlt)
652 { 800 {
653 /* Get difference to start */ 801 if (0 != slt->total_messages_sent)
654 delta = GNUNET_TIME_absolute_get_difference(l->lp[c_m].start, mlt->timestamp); 802 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
655 } 803 else
804 app_rtt = 0;
805 }
656 else 806 else
807 {
808 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
809 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
810 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt)
811 / (slt->total_messages_sent
812 - prev_log_slt->total_messages_sent);
813 else
657 { 814 {
658 /* Get difference to last timestep */ 815 app_rtt = prev_log_slt->app_rtt; /* No messages were */
659 delta = GNUNET_TIME_absolute_get_difference(mlt->prev->timestamp, mlt->timestamp);
660 } 816 }
817 }
818 slt->app_rtt = app_rtt;
661 819
662 /* Multiplication factor for throughput calculation */ 820 /* Partner throughput */
663 mult = (double)GNUNET_TIME_UNIT_SECONDS.rel_value_us / (delta.rel_value_us);
664
665 /* Total throughput */
666 if (NULL != prev_log_mlt) 821 if (NULL != prev_log_mlt)
667 { 822 {
668 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0) 823 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
669 { 824 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
670 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent); 825 slt->throughput_sent = mult * (slt->total_bytes_sent
671 } 826 - prev_log_slt->total_bytes_sent);
672 else 827 else
673 { 828 slt->throughput_sent = 0;
674 mlt->total_throughput_send = 0; 829
675 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */ 830 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
676 } 831 slt->throughput_recv = mult
677 832 * (slt->total_bytes_received
678 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0) 833 - prev_log_slt->total_bytes_received);
679 { 834 else
680 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received); 835 slt->throughput_recv = 0;
681 } 836 }
682 else
683 {
684 mlt->total_throughput_recv = 0;
685 //mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
686 }
687 }
688 else 837 else
689 { 838 {
690 mlt->total_throughput_send = mult * mlt->total_bytes_sent; 839 slt->throughput_sent = mult * slt->total_bytes_sent;
691 mlt->total_throughput_recv = mult * mlt->total_bytes_received; 840 slt->throughput_recv = mult * slt->total_bytes_received;
692 } 841 }
693 842
694 if (GNUNET_YES == l->verbose) 843 if (GNUNET_YES == l->verbose)
695 { 844 {
696 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 845 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
697 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", 846 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
698 c_m, 847 c_m, c_s,
699 (unsigned long long)delta.rel_value_us, 848 (unsigned long long) delta.rel_value_us,
700 mlt->total_bytes_sent, 849 mlt->total_bytes_sent,
701 mlt->total_bytes_received, 850 mlt->total_bytes_received,
702 mlt->total_throughput_send, 851 slt->throughput_sent,
703 mlt->total_throughput_recv); 852 slt->throughput_recv);
704 } 853 }
705 854 else
706 mlt->slaves_log = GNUNET_malloc(bp->peer->num_partners * 855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 sizeof(struct PartnerLoggingTimestep)); 856 "Master [%u]: slave [%u]\n",
708 857 bp->peer->no, p->dest->no);
709 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
710 {
711 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
712 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
713
714 p = &bp->peer->partners[c_s];
715 slt = &mlt->slaves_log[c_s];
716
717 slt->slave = p->dest;
718 /* Bytes sent from master to this slave */
719 slt->total_bytes_sent = p->bytes_sent;
720 /* Messages sent from master to this slave */
721 slt->total_messages_sent = p->messages_sent;
722 /* Bytes master received from this slave */
723 slt->total_bytes_received = p->bytes_received;
724 /* Messages master received from this slave */
725 slt->total_messages_received = p->messages_received;
726 slt->total_app_rtt = p->total_app_rtt;
727 /* ats performance information */
728 slt->ats_delay = p->props.delay;
729 slt->ats_distance = p->props.distance;
730 slt->ats_network_type = p->props.scope;
731 slt->ats_utilization_in = p->props.utilization_out;
732 slt->ats_utilization_out = p->props.utilization_out;
733 slt->bandwidth_in = p->bandwidth_in;
734 slt->bandwidth_out = p->bandwidth_out;
735 slt->pref_bandwidth = p->pref_bandwidth;
736 slt->pref_delay = p->pref_delay;
737
738 /* Total application level rtt */
739 if (NULL == prev_log_mlt)
740 {
741 if (0 != slt->total_messages_sent)
742 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
743 else
744 app_rtt = 0;
745 }
746 else
747 {
748 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
749 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
750 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
751 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
752 else
753 {
754 app_rtt = prev_log_slt->app_rtt; /* No messages were */
755 }
756 }
757 slt->app_rtt = app_rtt;
758
759 /* Partner throughput */
760 if (NULL != prev_log_mlt)
761 {
762 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
763 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
764 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
765 else
766 slt->throughput_sent = 0;
767
768 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
769 slt->throughput_recv = mult *
770 (slt->total_bytes_received - prev_log_slt->total_bytes_received);
771 else
772 slt->throughput_recv = 0;
773 }
774 else
775 {
776 slt->throughput_sent = mult * slt->total_bytes_sent;
777 slt->throughput_recv = mult * slt->total_bytes_received;
778 }
779
780 if (GNUNET_YES == l->verbose)
781 {
782 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
783 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
784 c_m, c_s,
785 (unsigned long long)delta.rel_value_us,
786 mlt->total_bytes_sent,
787 mlt->total_bytes_received,
788 slt->throughput_sent,
789 slt->throughput_recv);
790 }
791 else
792 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
793 "Master [%u]: slave [%u]\n",
794 bp->peer->no, p->dest->no);
795 }
796 } 858 }
859 }
797} 860}
798 861
799 862
800static void 863static void
801collect_log_task(void *cls) 864collect_log_task (void *cls)
802{ 865{
803 struct LoggingHandle *l = cls; 866 struct LoggingHandle *l = cls;
804 867
805 l->log_task = NULL; 868 l->log_task = NULL;
806 GNUNET_ATS_TEST_logging_now(l); 869 GNUNET_ATS_TEST_logging_now (l);
807 l->log_task = GNUNET_SCHEDULER_add_delayed(l->frequency, 870 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
808 &collect_log_task, 871 &collect_log_task,
809 l); 872 l);
810} 873}
811 874
812 875
@@ -816,20 +879,20 @@ collect_log_task(void *cls)
816 * @param l the logging handle 879 * @param l the logging handle
817 */ 880 */
818void 881void
819GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l) 882GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
820{ 883{
821 if (GNUNET_YES != l->running) 884 if (GNUNET_YES != l->running)
822 return; 885 return;
823 886
824 if (NULL != l->log_task) 887 if (NULL != l->log_task)
825 { 888 {
826 GNUNET_SCHEDULER_cancel(l->log_task); 889 GNUNET_SCHEDULER_cancel (l->log_task);
827 l->log_task = NULL; 890 l->log_task = NULL;
828 } 891 }
829 l->running = GNUNET_NO; 892 l->running = GNUNET_NO;
830 893
831 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 894 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
832 _("Stop logging\n")); 895 _ ("Stop logging\n"));
833} 896}
834 897
835/** 898/**
@@ -838,26 +901,26 @@ GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l)
838 * @param l the logging handle 901 * @param l the logging handle
839 */ 902 */
840void 903void
841GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l) 904GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
842{ 905{
843 int c_m; 906 int c_m;
844 struct PeerLoggingTimestep *cur; 907 struct PeerLoggingTimestep *cur;
845 908
846 if (GNUNET_YES == l->running) 909 if (GNUNET_YES == l->running)
847 GNUNET_ATS_TEST_logging_stop(l); 910 GNUNET_ATS_TEST_logging_stop (l);
848 911
849 for (c_m = 0; c_m < l->num_masters; c_m++) 912 for (c_m = 0; c_m < l->num_masters; c_m++)
913 {
914 while (NULL != (cur = l->lp[c_m].head))
850 { 915 {
851 while (NULL != (cur = l->lp[c_m].head)) 916 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
852 { 917 GNUNET_free (cur->slaves_log);
853 GNUNET_CONTAINER_DLL_remove(l->lp[c_m].head, l->lp[c_m].tail, cur); 918 GNUNET_free (cur);
854 GNUNET_free(cur->slaves_log);
855 GNUNET_free(cur);
856 }
857 } 919 }
920 }
858 921
859 GNUNET_free(l->lp); 922 GNUNET_free (l->lp);
860 GNUNET_free(l); 923 GNUNET_free (l);
861} 924}
862 925
863 926
@@ -873,35 +936,35 @@ GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l)
873 * @return the logging handle or NULL on error 936 * @return the logging handle or NULL on error
874 */ 937 */
875struct LoggingHandle * 938struct LoggingHandle *
876GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency, 939GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
877 const char *testname, 940 const char *testname,
878 struct BenchmarkPeer *masters, 941 struct BenchmarkPeer *masters,
879 int num_masters, 942 int num_masters,
880 int num_slaves, 943 int num_slaves,
881 int verbose) 944 int verbose)
882{ 945{
883 struct LoggingHandle *l; 946 struct LoggingHandle *l;
884 int c_m; 947 int c_m;
885 948
886 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 949 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
887 _("Start logging `%s'\n"), testname); 950 _ ("Start logging `%s'\n"), testname);
888 951
889 l = GNUNET_new(struct LoggingHandle); 952 l = GNUNET_new (struct LoggingHandle);
890 l->num_masters = num_masters; 953 l->num_masters = num_masters;
891 l->num_slaves = num_slaves; 954 l->num_slaves = num_slaves;
892 l->name = testname; 955 l->name = testname;
893 l->frequency = log_frequency; 956 l->frequency = log_frequency;
894 l->verbose = verbose; 957 l->verbose = verbose;
895 l->lp = GNUNET_malloc(num_masters * sizeof(struct LoggingPeer)); 958 l->lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer));
896 959
897 for (c_m = 0; c_m < num_masters; c_m++) 960 for (c_m = 0; c_m < num_masters; c_m++)
898 { 961 {
899 l->lp[c_m].peer = &masters[c_m]; 962 l->lp[c_m].peer = &masters[c_m];
900 l->lp[c_m].start = GNUNET_TIME_absolute_get(); 963 l->lp[c_m].start = GNUNET_TIME_absolute_get ();
901 } 964 }
902 965
903 /* Schedule logging task */ 966 /* Schedule logging task */
904 l->log_task = GNUNET_SCHEDULER_add_now(&collect_log_task, l); 967 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
905 l->running = GNUNET_YES; 968 l->running = GNUNET_YES;
906 969
907 return l; 970 return l;
diff --git a/src/ats-tests/ats-testing-preferences.c b/src/ats-tests/ats-testing-preferences.c
index a14e66736..8138b18bb 100644
--- a/src/ats-tests/ats-testing-preferences.c
+++ b/src/ats-tests/ats-testing-preferences.c
@@ -33,7 +33,7 @@ static struct PreferenceGenerator *pg_tail;
33extern struct GNUNET_ATS_TEST_Topology *top; 33extern struct GNUNET_ATS_TEST_Topology *top;
34 34
35static double 35static double
36get_preference(struct PreferenceGenerator *pg) 36get_preference (struct PreferenceGenerator *pg)
37{ 37{
38 struct GNUNET_TIME_Relative time_delta; 38 struct GNUNET_TIME_Relative time_delta;
39 double delta_value; 39 double delta_value;
@@ -41,97 +41,101 @@ get_preference(struct PreferenceGenerator *pg)
41 41
42 /* Calculate the current preference value */ 42 /* Calculate the current preference value */
43 switch (pg->type) 43 switch (pg->type)
44 {
45 case GNUNET_ATS_TEST_TG_CONSTANT:
46 pref_value = pg->base_value;
47 break;
48
49 case GNUNET_ATS_TEST_TG_LINEAR:
50 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
51 /* Calculate point of time in the current period */
52 time_delta.rel_value_us = time_delta.rel_value_us
53 % pg->duration_period.rel_value_us;
54 delta_value = ((double) time_delta.rel_value_us
55 / pg->duration_period.rel_value_us) * (pg->max_value
56 - pg->base_value);
57 if ((pg->max_value < pg->base_value) &&
58 ((pg->max_value - pg->base_value) > pg->base_value))
44 { 59 {
45 case GNUNET_ATS_TEST_TG_CONSTANT: 60 /* This will cause an underflow */
46 pref_value = pg->base_value; 61 GNUNET_break (0);
47 break;
48
49 case GNUNET_ATS_TEST_TG_LINEAR:
50 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
51 /* Calculate point of time in the current period */
52 time_delta.rel_value_us = time_delta.rel_value_us %
53 pg->duration_period.rel_value_us;
54 delta_value = ((double)time_delta.rel_value_us /
55 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
56 if ((pg->max_value < pg->base_value) &&
57 ((pg->max_value - pg->base_value) > pg->base_value))
58 {
59 /* This will cause an underflow */
60 GNUNET_break(0);
61 }
62 pref_value = pg->base_value + delta_value;
63 break;
64
65 case GNUNET_ATS_TEST_TG_RANDOM:
66 delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
67 10000 * (pg->max_value - pg->base_value)) / 10000;
68 pref_value = pg->base_value + delta_value;
69 break;
70
71 case GNUNET_ATS_TEST_TG_SINUS:
72 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
73 /* Calculate point of time in the current period */
74 time_delta.rel_value_us = time_delta.rel_value_us %
75 pg->duration_period.rel_value_us;
76 if ((pg->max_value - pg->base_value) > pg->base_value)
77 {
78 /* This will cause an underflow for second half of sinus period,
79 * will be detected in general when experiments are loaded */
80 GNUNET_break(0);
81 }
82 delta_value = (pg->max_value - pg->base_value) *
83 sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) *
84 time_delta.rel_value_us);
85 pref_value = pg->base_value + delta_value;
86 break;
87
88 default:
89 pref_value = 0.0;
90 break;
91 } 62 }
92 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", 63 pref_value = pg->base_value + delta_value;
93 pref_value); 64 break;
65
66 case GNUNET_ATS_TEST_TG_RANDOM:
67 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
68 10000 * (pg->max_value
69 - pg->base_value))
70 / 10000;
71 pref_value = pg->base_value + delta_value;
72 break;
73
74 case GNUNET_ATS_TEST_TG_SINUS:
75 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
76 /* Calculate point of time in the current period */
77 time_delta.rel_value_us = time_delta.rel_value_us
78 % pg->duration_period.rel_value_us;
79 if ((pg->max_value - pg->base_value) > pg->base_value)
80 {
81 /* This will cause an underflow for second half of sinus period,
82 * will be detected in general when experiments are loaded */
83 GNUNET_break (0);
84 }
85 delta_value = (pg->max_value - pg->base_value)
86 * sin ((2 * M_PI)
87 / ((double) pg->duration_period.rel_value_us)
88 * time_delta.rel_value_us);
89 pref_value = pg->base_value + delta_value;
90 break;
91
92 default:
93 pref_value = 0.0;
94 break;
95 }
96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
97 pref_value);
94 return pref_value; 98 return pref_value;
95} 99}
96 100
97 101
98static void 102static void
99set_pref_task(void *cls) 103set_pref_task (void *cls)
100{ 104{
101 struct BenchmarkPartner *p = cls; 105 struct BenchmarkPartner *p = cls;
102 double pref_value; 106 double pref_value;
103 107
104 p->pg->set_task = NULL; 108 p->pg->set_task = NULL;
105 109
106 pref_value = get_preference(p->pg); 110 pref_value = get_preference (p->pg);
107 111
108 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 112 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
109 "Setting preference for master [%u] and slave [%u] for %s to %f\n", 113 "Setting preference for master [%u] and slave [%u] for %s to %f\n",
110 p->me->no, p->dest->no, 114 p->me->no, p->dest->no,
111 GNUNET_ATS_print_preference_type(p->pg->kind), pref_value); 115 GNUNET_ATS_print_preference_type (p->pg->kind), pref_value);
112 116
113 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle, 117 GNUNET_ATS_performance_change_preference (p->me->ats_perf_handle,
114 &p->dest->id, 118 &p->dest->id,
115 p->pg->kind, 119 p->pg->kind,
116 pref_value, 120 pref_value,
117 GNUNET_ATS_PREFERENCE_END); 121 GNUNET_ATS_PREFERENCE_END);
118 122
119 switch (p->pg->kind) 123 switch (p->pg->kind)
120 { 124 {
121 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 125 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
122 p->pref_bandwidth = pref_value; 126 p->pref_bandwidth = pref_value;
123 break; 127 break;
124 128
125 case GNUNET_ATS_PREFERENCE_LATENCY: 129 case GNUNET_ATS_PREFERENCE_LATENCY:
126 p->pref_delay = pref_value; 130 p->pref_delay = pref_value;
127 break; 131 break;
128 132
129 default: 133 default:
130 break; 134 break;
131 } 135 }
132 136
133 p->pg->set_task = GNUNET_SCHEDULER_add_delayed(p->pg->frequency, 137 p->pg->set_task = GNUNET_SCHEDULER_add_delayed (p->pg->frequency,
134 set_pref_task, p); 138 set_pref_task, p);
135} 139}
136 140
137 141
@@ -150,25 +154,26 @@ set_pref_task(void *cls)
150 * @return the preference generator 154 * @return the preference generator
151 */ 155 */
152struct PreferenceGenerator * 156struct PreferenceGenerator *
153GNUNET_ATS_TEST_generate_preferences_start(struct BenchmarkPeer *src, 157GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
154 struct BenchmarkPartner *dest, 158 struct BenchmarkPartner *dest,
155 enum GeneratorType type, 159 enum GeneratorType type,
156 unsigned int base_value, 160 unsigned int base_value,
157 unsigned int value_rate, 161 unsigned int value_rate,
158 struct GNUNET_TIME_Relative period, 162 struct GNUNET_TIME_Relative period,
159 struct GNUNET_TIME_Relative frequency, 163 struct GNUNET_TIME_Relative
160 enum GNUNET_ATS_PreferenceKind kind) 164 frequency,
165 enum GNUNET_ATS_PreferenceKind kind)
161{ 166{
162 struct PreferenceGenerator *pg; 167 struct PreferenceGenerator *pg;
163 168
164 if (NULL != dest->pg) 169 if (NULL != dest->pg)
165 { 170 {
166 GNUNET_break(0); 171 GNUNET_break (0);
167 return NULL; 172 return NULL;
168 } 173 }
169 174
170 pg = GNUNET_new(struct PreferenceGenerator); 175 pg = GNUNET_new (struct PreferenceGenerator);
171 GNUNET_CONTAINER_DLL_insert(pg_head, pg_tail, pg); 176 GNUNET_CONTAINER_DLL_insert (pg_head, pg_tail, pg);
172 pg->type = type; 177 pg->type = type;
173 pg->src = src; 178 pg->src = src;
174 pg->dest = dest; 179 pg->dest = dest;
@@ -177,65 +182,65 @@ GNUNET_ATS_TEST_generate_preferences_start(struct BenchmarkPeer *src,
177 pg->max_value = value_rate; 182 pg->max_value = value_rate;
178 pg->duration_period = period; 183 pg->duration_period = period;
179 pg->frequency = frequency; 184 pg->frequency = frequency;
180 pg->time_start = GNUNET_TIME_absolute_get(); 185 pg->time_start = GNUNET_TIME_absolute_get ();
181 186
182 switch (type) 187 switch (type)
183 { 188 {
184 case GNUNET_ATS_TEST_TG_CONSTANT: 189 case GNUNET_ATS_TEST_TG_CONSTANT:
185 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
186 "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", 191 "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
187 dest->me->no, GNUNET_i2s(&dest->me->id), 192 dest->me->no, GNUNET_i2s (&dest->me->id),
188 dest->dest->no, GNUNET_i2s(&dest->dest->id), 193 dest->dest->no, GNUNET_i2s (&dest->dest->id),
189 base_value); 194 base_value);
190 break; 195 break;
191 196
192 case GNUNET_ATS_TEST_TG_LINEAR: 197 case GNUNET_ATS_TEST_TG_LINEAR:
193 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 198 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
194 "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", 199 "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
195 dest->me->no, GNUNET_i2s(&dest->me->id), 200 dest->me->no, GNUNET_i2s (&dest->me->id),
196 dest->dest->no, GNUNET_i2s(&dest->dest->id), 201 dest->dest->no, GNUNET_i2s (&dest->dest->id),
197 base_value, value_rate); 202 base_value, value_rate);
198 break; 203 break;
199 204
200 case GNUNET_ATS_TEST_TG_SINUS: 205 case GNUNET_ATS_TEST_TG_SINUS:
201 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 206 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
202 "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", 207 "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
203 dest->me->no, GNUNET_i2s(&dest->me->id), 208 dest->me->no, GNUNET_i2s (&dest->me->id),
204 dest->dest->no, GNUNET_i2s(&dest->dest->id), 209 dest->dest->no, GNUNET_i2s (&dest->dest->id),
205 base_value, value_rate); 210 base_value, value_rate);
206 break; 211 break;
207 212
208 case GNUNET_ATS_TEST_TG_RANDOM: 213 case GNUNET_ATS_TEST_TG_RANDOM:
209 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
210 "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", 215 "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
211 dest->me->no, GNUNET_i2s(&dest->me->id), 216 dest->me->no, GNUNET_i2s (&dest->me->id),
212 dest->dest->no, GNUNET_i2s(&dest->dest->id), 217 dest->dest->no, GNUNET_i2s (&dest->dest->id),
213 base_value, value_rate); 218 base_value, value_rate);
214 break; 219 break;
215 220
216 default: 221 default:
217 break; 222 break;
218 } 223 }
219 224
220 dest->pg = pg; 225 dest->pg = pg;
221 pg->set_task = GNUNET_SCHEDULER_add_now(&set_pref_task, dest); 226 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, dest);
222 return pg; 227 return pg;
223} 228}
224 229
225 230
226void 231void
227GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg) 232GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
228{ 233{
229 GNUNET_CONTAINER_DLL_remove(pg_head, pg_tail, pg); 234 GNUNET_CONTAINER_DLL_remove (pg_head, pg_tail, pg);
230 pg->dest->pg = NULL; 235 pg->dest->pg = NULL;
231 236
232 if (NULL != pg->set_task) 237 if (NULL != pg->set_task)
233 { 238 {
234 GNUNET_SCHEDULER_cancel(pg->set_task); 239 GNUNET_SCHEDULER_cancel (pg->set_task);
235 pg->set_task = NULL; 240 pg->set_task = NULL;
236 } 241 }
237 242
238 GNUNET_free(pg); 243 GNUNET_free (pg);
239} 244}
240 245
241 246
@@ -243,17 +248,17 @@ GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg)
243 * Stop all preferences generators 248 * Stop all preferences generators
244 */ 249 */
245void 250void
246GNUNET_ATS_TEST_generate_preferences_stop_all() 251GNUNET_ATS_TEST_generate_preferences_stop_all ()
247{ 252{
248 struct PreferenceGenerator *cur; 253 struct PreferenceGenerator *cur;
249 struct PreferenceGenerator *next; 254 struct PreferenceGenerator *next;
250 255
251 next = pg_head; 256 next = pg_head;
252 for (cur = next; NULL != cur; cur = next) 257 for (cur = next; NULL != cur; cur = next)
253 { 258 {
254 next = cur->next; 259 next = cur->next;
255 GNUNET_ATS_TEST_generate_preferences_stop(cur); 260 GNUNET_ATS_TEST_generate_preferences_stop (cur);
256 } 261 }
257} 262}
258 263
259/* end of file ats-testing-preferences.c */ 264/* end of file ats-testing-preferences.c */
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
index 01462980c..14a8fe327 100644
--- a/src/ats-tests/ats-testing-traffic.c
+++ b/src/ats-tests/ats-testing-traffic.c
@@ -33,7 +33,7 @@ static struct TrafficGenerator *tg_tail;
33extern struct GNUNET_ATS_TEST_Topology *top; 33extern struct GNUNET_ATS_TEST_Topology *top;
34 34
35static struct GNUNET_TIME_Relative 35static struct GNUNET_TIME_Relative
36get_delay(struct TrafficGenerator *tg) 36get_delay (struct TrafficGenerator *tg)
37{ 37{
38 struct GNUNET_TIME_Relative delay; 38 struct GNUNET_TIME_Relative delay;
39 struct GNUNET_TIME_Relative time_delta; 39 struct GNUNET_TIME_Relative time_delta;
@@ -44,69 +44,78 @@ get_delay(struct TrafficGenerator *tg)
44 44
45 /* Calculate the current transmission rate based on the type of traffic */ 45 /* Calculate the current transmission rate based on the type of traffic */
46 switch (tg->type) 46 switch (tg->type)
47 {
48 case GNUNET_ATS_TEST_TG_CONSTANT:
49 if (UINT32_MAX == tg->base_rate)
50 return GNUNET_TIME_UNIT_ZERO;
51 cur_rate = tg->base_rate;
52 break;
53
54 case GNUNET_ATS_TEST_TG_LINEAR:
55 time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
56 /* Calculate point of time in the current period */
57 time_delta.rel_value_us = time_delta.rel_value_us
58 % tg->duration_period.rel_value_us;
59 delta_rate = ((double) time_delta.rel_value_us
60 / tg->duration_period.rel_value_us)
61 * (tg->max_rate - tg->base_rate);
62 if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) >
63 tg->base_rate))
47 { 64 {
48 case GNUNET_ATS_TEST_TG_CONSTANT: 65 /* This will cause an underflow */
49 if (UINT32_MAX == tg->base_rate) 66 GNUNET_break (0);
50 return GNUNET_TIME_UNIT_ZERO;
51 cur_rate = tg->base_rate;
52 break;
53
54 case GNUNET_ATS_TEST_TG_LINEAR:
55 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
56 /* Calculate point of time in the current period */
57 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
58 delta_rate = ((double)time_delta.rel_value_us / tg->duration_period.rel_value_us) *
59 (tg->max_rate - tg->base_rate);
60 if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > tg->base_rate))
61 {
62 /* This will cause an underflow */
63 GNUNET_break(0);
64 }
65 cur_rate = tg->base_rate + delta_rate;
66 break;
67
68 case GNUNET_ATS_TEST_TG_RANDOM:
69 cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
70 tg->max_rate - tg->base_rate);
71 break;
72
73 case GNUNET_ATS_TEST_TG_SINUS:
74 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
75 /* Calculate point of time in the current period */
76 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
77 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
78 {
79 /* This will cause an underflow for second half of sinus period,
80 * will be detected in general when experiments are loaded */
81 GNUNET_break(0);
82 }
83 delta_rate = (tg->max_rate - tg->base_rate) *
84 sin((2 * M_PI) / ((double)tg->duration_period.rel_value_us) * time_delta.rel_value_us);
85 cur_rate = tg->base_rate + delta_rate;
86 break;
87
88 default:
89 return delay;
90 break;
91 } 67 }
92 68 cur_rate = tg->base_rate + delta_rate;
93 if (cur_rate < 0) 69 break;
70
71 case GNUNET_ATS_TEST_TG_RANDOM:
72 cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32 (
73 GNUNET_CRYPTO_QUALITY_WEAK,
74 tg->max_rate
75 - tg->base_rate);
76 break;
77
78 case GNUNET_ATS_TEST_TG_SINUS:
79 time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
80 /* Calculate point of time in the current period */
81 time_delta.rel_value_us = time_delta.rel_value_us
82 % tg->duration_period.rel_value_us;
83 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
94 { 84 {
95 cur_rate = 1; 85 /* This will cause an underflow for second half of sinus period,
86 * will be detected in general when experiments are loaded */
87 GNUNET_break (0);
96 } 88 }
89 delta_rate = (tg->max_rate - tg->base_rate)
90 * sin ((2 * M_PI)
91 / ((double) tg->duration_period.rel_value_us)
92 * time_delta.rel_value_us);
93 cur_rate = tg->base_rate + delta_rate;
94 break;
95
96 default:
97 return delay;
98 break;
99 }
100
101 if (cur_rate < 0)
102 {
103 cur_rate = 1;
104 }
97 /* Calculate the delay for the next message based on the current delay */ 105 /* Calculate the delay for the next message based on the current delay */
98 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate; 106 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us
107 * TEST_MESSAGE_SIZE / cur_rate;
99 108
100 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
101 "Current rate is %lld, calculated delay is %llu\n", 110 "Current rate is %lld, calculated delay is %llu\n",
102 cur_rate, 111 cur_rate,
103 (unsigned long long)delay.rel_value_us); 112 (unsigned long long) delay.rel_value_us);
104 return delay; 113 return delay;
105} 114}
106 115
107 116
108static void 117static void
109update_ping_data(void *cls) 118update_ping_data (void *cls)
110{ 119{
111 struct BenchmarkPartner *p = cls; 120 struct BenchmarkPartner *p = cls;
112 struct GNUNET_TIME_Relative delay; 121 struct GNUNET_TIME_Relative delay;
@@ -117,49 +126,49 @@ update_ping_data(void *cls)
117 p->me->total_bytes_sent += TEST_MESSAGE_SIZE; 126 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
118 127
119 if (NULL == p->tg) 128 if (NULL == p->tg)
120 { 129 {
121 GNUNET_break(0); 130 GNUNET_break (0);
122 return; 131 return;
123 } 132 }
124 delay = get_delay(p->tg); 133 delay = get_delay (p->tg);
125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
126 "Delay for next transmission %s\n", 135 "Delay for next transmission %s\n",
127 GNUNET_STRINGS_relative_time_to_string(delay, 136 GNUNET_STRINGS_relative_time_to_string (delay,
128 GNUNET_YES)); 137 GNUNET_YES));
129 p->tg->next_ping_transmission 138 p->tg->next_ping_transmission
130 = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 139 = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
131 delay); 140 delay);
132} 141}
133 142
134 143
135static void 144static void
136comm_schedule_send(void *cls) 145comm_schedule_send (void *cls)
137{ 146{
138 struct BenchmarkPartner *p = cls; 147 struct BenchmarkPartner *p = cls;
139 struct TestMessage *msg; 148 struct TestMessage *msg;
140 struct GNUNET_MQ_Envelope *env; 149 struct GNUNET_MQ_Envelope *env;
141 150
142 p->tg->send_task = NULL; 151 p->tg->send_task = NULL;
143 p->last_message_sent = GNUNET_TIME_absolute_get(); 152 p->last_message_sent = GNUNET_TIME_absolute_get ();
144 env = GNUNET_MQ_msg(msg, 153 env = GNUNET_MQ_msg (msg,
145 TEST_MESSAGE_TYPE_PING); 154 TEST_MESSAGE_TYPE_PING);
146 memset(msg->padding, 155 memset (msg->padding,
147 'a', 156 'a',
148 sizeof(msg->padding)); 157 sizeof(msg->padding));
149 GNUNET_MQ_notify_sent(env, 158 GNUNET_MQ_notify_sent (env,
150 &update_ping_data, 159 &update_ping_data,
151 p); 160 p);
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Master [%u]: Sending PING to [%u]\n", 162 "Master [%u]: Sending PING to [%u]\n",
154 p->me->no, 163 p->me->no,
155 p->dest->no); 164 p->dest->no);
156 GNUNET_MQ_send(p->mq, 165 GNUNET_MQ_send (p->mq,
157 env); 166 env);
158} 167}
159 168
160 169
161static void 170static void
162update_pong_data(void *cls) 171update_pong_data (void *cls)
163{ 172{
164 struct BenchmarkPartner *p = cls; 173 struct BenchmarkPartner *p = cls;
165 174
@@ -171,74 +180,79 @@ update_pong_data(void *cls)
171 180
172 181
173void 182void
174GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p) 183GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
175{ 184{
176 struct TestMessage *msg; 185 struct TestMessage *msg;
177 struct GNUNET_MQ_Envelope *env; 186 struct GNUNET_MQ_Envelope *env;
178 187
179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Slave [%u]: Received PING from [%u], sending PONG\n", 189 "Slave [%u]: Received PING from [%u], sending PONG\n",
181 p->me->no, 190 p->me->no,
182 p->dest->no); 191 p->dest->no);
183 p->messages_received++; 192 p->messages_received++;
184 p->bytes_received += TEST_MESSAGE_SIZE; 193 p->bytes_received += TEST_MESSAGE_SIZE;
185 p->me->total_messages_received++; 194 p->me->total_messages_received++;
186 p->me->total_bytes_received += TEST_MESSAGE_SIZE; 195 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
187 196
188 197
189 env = GNUNET_MQ_msg(msg, 198 env = GNUNET_MQ_msg (msg,
190 TEST_MESSAGE_TYPE_PING); 199 TEST_MESSAGE_TYPE_PING);
191 memset(msg->padding, 200 memset (msg->padding,
192 'a', 201 'a',
193 sizeof(msg->padding)); 202 sizeof(msg->padding));
194 GNUNET_MQ_notify_sent(env, 203 GNUNET_MQ_notify_sent (env,
195 &update_pong_data, 204 &update_pong_data,
196 p); 205 p);
197 GNUNET_MQ_send(p->mq, 206 GNUNET_MQ_send (p->mq,
198 env); 207 env);
199} 208}
200 209
201 210
202void 211void
203GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p) 212GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
204{ 213{
205 struct GNUNET_TIME_Relative left; 214 struct GNUNET_TIME_Relative left;
206 215
207 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Master [%u]: Received PONG from [%u], next message\n", 217 "Master [%u]: Received PONG from [%u], next message\n",
209 p->me->no, 218 p->me->no,
210 p->dest->no); 219 p->dest->no);
211 220
212 p->messages_received++; 221 p->messages_received++;
213 p->bytes_received += TEST_MESSAGE_SIZE; 222 p->bytes_received += TEST_MESSAGE_SIZE;
214 p->me->total_messages_received++; 223 p->me->total_messages_received++;
215 p->me->total_bytes_received += TEST_MESSAGE_SIZE; 224 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
216 p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent, 225 p->total_app_rtt += GNUNET_TIME_absolute_get_difference (p->last_message_sent,
217 GNUNET_TIME_absolute_get()).rel_value_us; 226 GNUNET_TIME_absolute_get ())
227 .rel_value_us;
218 228
219 /* Schedule next send event */ 229 /* Schedule next send event */
220 if (NULL == p->tg) 230 if (NULL == p->tg)
221 return; 231 return;
222 232
223 left = GNUNET_TIME_absolute_get_remaining(p->tg->next_ping_transmission); 233 left = GNUNET_TIME_absolute_get_remaining (p->tg->next_ping_transmission);
224 if (UINT32_MAX == p->tg->base_rate) 234 if (UINT32_MAX == p->tg->base_rate)
225 { 235 {
226 p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); 236 p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
227 } 237 }
228 else if (0 == left.rel_value_us) 238 else if (0 == left.rel_value_us)
229 { 239 {
230 p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); 240 p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
231 } 241 }
232 else 242 else
233 { 243 {
234 /* Enforce minimum transmission rate 1 msg / sec */ 244 /* Enforce minimum transmission rate 1 msg / sec */
235 if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = GNUNET_TIME_relative_min(left, GNUNET_TIME_UNIT_SECONDS)).rel_value_us) 245 if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left =
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 246 GNUNET_TIME_relative_min (
237 "Enforcing minimum send rate between master [%u] and slave [%u]\n", 247 left,
238 p->me->no, p->dest->no); 248 GNUNET_TIME_UNIT_SECONDS))
239 p->tg->send_task = GNUNET_SCHEDULER_add_delayed(left, 249 .rel_value_us)
240 &comm_schedule_send, p); 250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
241 } 251 "Enforcing minimum send rate between master [%u] and slave [%u]\n",
252 p->me->no, p->dest->no);
253 p->tg->send_task = GNUNET_SCHEDULER_add_delayed (left,
254 &comm_schedule_send, p);
255 }
242} 256}
243 257
244 258
@@ -256,105 +270,105 @@ GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p)
256 * @return the traffic generator 270 * @return the traffic generator
257 */ 271 */
258struct TrafficGenerator * 272struct TrafficGenerator *
259GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, 273GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
260 struct BenchmarkPartner *dest, 274 struct BenchmarkPartner *dest,
261 enum GeneratorType type, 275 enum GeneratorType type,
262 unsigned int base_rate, 276 unsigned int base_rate,
263 unsigned int max_rate, 277 unsigned int max_rate,
264 struct GNUNET_TIME_Relative period, 278 struct GNUNET_TIME_Relative period,
265 struct GNUNET_TIME_Relative duration) 279 struct GNUNET_TIME_Relative duration)
266{ 280{
267 struct TrafficGenerator *tg; 281 struct TrafficGenerator *tg;
268 282
269 if (NULL != dest->tg) 283 if (NULL != dest->tg)
270 { 284 {
271 GNUNET_break(0); 285 GNUNET_break (0);
272 return NULL; 286 return NULL;
273 } 287 }
274 288
275 tg = GNUNET_new(struct TrafficGenerator); 289 tg = GNUNET_new (struct TrafficGenerator);
276 GNUNET_CONTAINER_DLL_insert(tg_head, 290 GNUNET_CONTAINER_DLL_insert (tg_head,
277 tg_tail, 291 tg_tail,
278 tg); 292 tg);
279 tg->type = type; 293 tg->type = type;
280 tg->src = src; 294 tg->src = src;
281 tg->dest = dest; 295 tg->dest = dest;
282 tg->base_rate = base_rate; 296 tg->base_rate = base_rate;
283 tg->max_rate = max_rate; 297 tg->max_rate = max_rate;
284 tg->duration_period = period; 298 tg->duration_period = period;
285 tg->time_start = GNUNET_TIME_absolute_get(); 299 tg->time_start = GNUNET_TIME_absolute_get ();
286 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; 300 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
287 301
288 switch (type) 302 switch (type)
289 { 303 {
290 case GNUNET_ATS_TEST_TG_CONSTANT: 304 case GNUNET_ATS_TEST_TG_CONSTANT:
291 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 305 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
292 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", 306 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
293 dest->me->no, 307 dest->me->no,
294 GNUNET_i2s(&dest->me->id), 308 GNUNET_i2s (&dest->me->id),
295 dest->dest->no, 309 dest->dest->no,
296 GNUNET_i2s(&dest->dest->id), 310 GNUNET_i2s (&dest->dest->id),
297 base_rate); 311 base_rate);
298 break; 312 break;
299 313
300 case GNUNET_ATS_TEST_TG_LINEAR: 314 case GNUNET_ATS_TEST_TG_LINEAR:
301 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
302 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", 316 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
303 dest->me->no, 317 dest->me->no,
304 GNUNET_i2s(&dest->me->id), 318 GNUNET_i2s (&dest->me->id),
305 dest->dest->no, 319 dest->dest->no,
306 GNUNET_i2s(&dest->dest->id), 320 GNUNET_i2s (&dest->dest->id),
307 base_rate, 321 base_rate,
308 max_rate); 322 max_rate);
309 break; 323 break;
310 324
311 case GNUNET_ATS_TEST_TG_SINUS: 325 case GNUNET_ATS_TEST_TG_SINUS:
312 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 326 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
313 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", 327 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
314 dest->me->no, 328 dest->me->no,
315 GNUNET_i2s(&dest->me->id), 329 GNUNET_i2s (&dest->me->id),
316 dest->dest->no, 330 dest->dest->no,
317 GNUNET_i2s(&dest->dest->id), 331 GNUNET_i2s (&dest->dest->id),
318 base_rate, 332 base_rate,
319 max_rate); 333 max_rate);
320 break; 334 break;
321 335
322 case GNUNET_ATS_TEST_TG_RANDOM: 336 case GNUNET_ATS_TEST_TG_RANDOM:
323 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
324 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", 338 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
325 dest->me->no, 339 dest->me->no,
326 GNUNET_i2s(&dest->me->id), 340 GNUNET_i2s (&dest->me->id),
327 dest->dest->no, 341 dest->dest->no,
328 GNUNET_i2s(&dest->dest->id), 342 GNUNET_i2s (&dest->dest->id),
329 base_rate, 343 base_rate,
330 max_rate); 344 max_rate);
331 break; 345 break;
332 346
333 default: 347 default:
334 break; 348 break;
335 } 349 }
336 350
337 dest->tg = tg; 351 dest->tg = tg;
338 tg->send_task 352 tg->send_task
339 = GNUNET_SCHEDULER_add_now(&comm_schedule_send, 353 = GNUNET_SCHEDULER_add_now (&comm_schedule_send,
340 dest); 354 dest);
341 return tg; 355 return tg;
342} 356}
343 357
344 358
345void 359void
346GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg) 360GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
347{ 361{
348 GNUNET_CONTAINER_DLL_remove(tg_head, 362 GNUNET_CONTAINER_DLL_remove (tg_head,
349 tg_tail, 363 tg_tail,
350 tg); 364 tg);
351 tg->dest->tg = NULL; 365 tg->dest->tg = NULL;
352 if (NULL != tg->send_task) 366 if (NULL != tg->send_task)
353 { 367 {
354 GNUNET_SCHEDULER_cancel(tg->send_task); 368 GNUNET_SCHEDULER_cancel (tg->send_task);
355 tg->send_task = NULL; 369 tg->send_task = NULL;
356 } 370 }
357 GNUNET_free(tg); 371 GNUNET_free (tg);
358} 372}
359 373
360 374
@@ -362,17 +376,17 @@ GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg)
362 * Stop all traffic generators 376 * Stop all traffic generators
363 */ 377 */
364void 378void
365GNUNET_ATS_TEST_generate_traffic_stop_all() 379GNUNET_ATS_TEST_generate_traffic_stop_all ()
366{ 380{
367 struct TrafficGenerator *cur; 381 struct TrafficGenerator *cur;
368 struct TrafficGenerator *next; 382 struct TrafficGenerator *next;
369 383
370 next = tg_head; 384 next = tg_head;
371 for (cur = next; NULL != cur; cur = next) 385 for (cur = next; NULL != cur; cur = next)
372 { 386 {
373 next = cur->next; 387 next = cur->next;
374 GNUNET_ATS_TEST_generate_traffic_stop(cur); 388 GNUNET_ATS_TEST_generate_traffic_stop (cur);
375 } 389 }
376} 390}
377 391
378/* end of file ats-testing-traffic.c */ 392/* end of file ats-testing-traffic.c */
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c
index 696deb4bd..88c1729a6 100644
--- a/src/ats-tests/ats-testing.c
+++ b/src/ats-tests/ats-testing.c
@@ -30,7 +30,8 @@
30/** 30/**
31 * Connect peers with testbed 31 * Connect peers with testbed
32 */ 32 */
33struct TestbedConnectOperation { 33struct TestbedConnectOperation
34{
34 /** 35 /**
35 * The benchmarking master initiating this connection 36 * The benchmarking master initiating this connection
36 */ 37 */
@@ -58,7 +59,7 @@ struct GNUNET_ATS_TEST_Topology *top;
58 * @param cls NULL 59 * @param cls NULL
59 */ 60 */
60static void 61static void
61do_shutdown(void *cls) 62do_shutdown (void *cls)
62{ 63{
63 int c_m; 64 int c_m;
64 int c_s; 65 int c_s;
@@ -67,118 +68,118 @@ do_shutdown(void *cls)
67 68
68 top->state.benchmarking = GNUNET_NO; 69 top->state.benchmarking = GNUNET_NO;
69 70
70 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 71 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
71 "Benchmarking done\n"); 72 "Benchmarking done\n");
72 73
73 GNUNET_ATS_TEST_generate_traffic_stop_all(); 74 GNUNET_ATS_TEST_generate_traffic_stop_all ();
74 75
75 for (c_m = 0; c_m < top->num_masters; c_m++) 76 for (c_m = 0; c_m < top->num_masters; c_m++)
77 {
78 p = &top->mps[c_m];
79 if (NULL != top->mps[c_m].peer_id_op)
80 {
81 GNUNET_TESTBED_operation_done (p->peer_id_op);
82 p->peer_id_op = NULL;
83 }
84
85 if (NULL != p->ats_task)
86 GNUNET_SCHEDULER_cancel (p->ats_task);
87 p->ats_task = NULL;
88
89 for (c_op = 0; c_op < p->num_partners; c_op++)
90 {
91 if ((NULL != p->core_connect_ops) &&
92 (NULL != p->core_connect_ops[c_op].connect_op))
93 {
94 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
95 "Failed to connect peer 0 and %u\n",
96 c_op);
97 GNUNET_TESTBED_operation_done (p->core_connect_ops[c_op].connect_op);
98 p->core_connect_ops[c_op].connect_op = NULL;
99 }
100 }
101
102 if (NULL != p->ats_perf_op)
103 {
104 GNUNET_TESTBED_operation_done (p->ats_perf_op);
105 p->ats_perf_op = NULL;
106 }
107
108 if (NULL != p->comm_op)
76 { 109 {
77 p = &top->mps[c_m]; 110 GNUNET_TESTBED_operation_done (p->comm_op);
78 if (NULL != top->mps[c_m].peer_id_op) 111 p->comm_op = NULL;
79 {
80 GNUNET_TESTBED_operation_done(p->peer_id_op);
81 p->peer_id_op = NULL;
82 }
83
84 if (NULL != p->ats_task)
85 GNUNET_SCHEDULER_cancel(p->ats_task);
86 p->ats_task = NULL;
87
88 for (c_op = 0; c_op < p->num_partners; c_op++)
89 {
90 if ((NULL != p->core_connect_ops) &&
91 (NULL != p->core_connect_ops[c_op].connect_op))
92 {
93 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
94 "Failed to connect peer 0 and %u\n",
95 c_op);
96 GNUNET_TESTBED_operation_done(p->core_connect_ops[c_op].connect_op);
97 p->core_connect_ops[c_op].connect_op = NULL;
98 }
99 }
100
101 if (NULL != p->ats_perf_op)
102 {
103 GNUNET_TESTBED_operation_done(p->ats_perf_op);
104 p->ats_perf_op = NULL;
105 }
106
107 if (NULL != p->comm_op)
108 {
109 GNUNET_TESTBED_operation_done(p->comm_op);
110 p->comm_op = NULL;
111 }
112 GNUNET_free_non_null(p->core_connect_ops);
113 GNUNET_free(p->partners);
114 p->partners = NULL;
115 } 112 }
113 GNUNET_free_non_null (p->core_connect_ops);
114 GNUNET_free (p->partners);
115 p->partners = NULL;
116 }
116 117
117 for (c_s = 0; c_s < top->num_slaves; c_s++) 118 for (c_s = 0; c_s < top->num_slaves; c_s++)
119 {
120 p = &top->sps[c_s];
121 if (NULL != p->peer_id_op)
118 { 122 {
119 p = &top->sps[c_s]; 123 GNUNET_TESTBED_operation_done (p->peer_id_op);
120 if (NULL != p->peer_id_op) 124 p->peer_id_op = NULL;
121 {
122 GNUNET_TESTBED_operation_done(p->peer_id_op);
123 p->peer_id_op = NULL;
124 }
125 if (NULL != p->ats_perf_op)
126 {
127 GNUNET_TESTBED_operation_done(p->ats_perf_op);
128 p->ats_perf_op = NULL;
129 }
130 if (NULL != p->comm_op)
131 {
132 GNUNET_TESTBED_operation_done(p->comm_op);
133 p->comm_op = NULL;
134 }
135 GNUNET_free(p->partners);
136 p->partners = NULL;
137 } 125 }
138 GNUNET_SCHEDULER_shutdown(); 126 if (NULL != p->ats_perf_op)
139 GNUNET_free(top); 127 {
128 GNUNET_TESTBED_operation_done (p->ats_perf_op);
129 p->ats_perf_op = NULL;
130 }
131 if (NULL != p->comm_op)
132 {
133 GNUNET_TESTBED_operation_done (p->comm_op);
134 p->comm_op = NULL;
135 }
136 GNUNET_free (p->partners);
137 p->partners = NULL;
138 }
139 GNUNET_SCHEDULER_shutdown ();
140 GNUNET_free (top);
140 top = NULL; 141 top = NULL;
141} 142}
142 143
143 144
144static struct BenchmarkPartner * 145static struct BenchmarkPartner *
145find_partner(struct BenchmarkPeer *me, 146find_partner (struct BenchmarkPeer *me,
146 const struct GNUNET_PeerIdentity *peer) 147 const struct GNUNET_PeerIdentity *peer)
147{ 148{
148 int c_m; 149 int c_m;
149 150
150 for (c_m = 0; c_m < me->num_partners; c_m++) 151 for (c_m = 0; c_m < me->num_partners; c_m++)
152 {
153 /* Find a partner with other as destination */
154 if (0 == GNUNET_memcmp (peer,
155 &me->partners[c_m].dest->id))
151 { 156 {
152 /* Find a partner with other as destination */ 157 return &me->partners[c_m];
153 if (0 == GNUNET_memcmp(peer,
154 &me->partners[c_m].dest->id))
155 {
156 return &me->partners[c_m];
157 }
158 } 158 }
159 }
159 160
160 return NULL; 161 return NULL;
161} 162}
162 163
163 164
164static struct BenchmarkPeer * 165static struct BenchmarkPeer *
165find_peer(const struct GNUNET_PeerIdentity * peer) 166find_peer (const struct GNUNET_PeerIdentity *peer)
166{ 167{
167 int c_p; 168 int c_p;
168 169
169 for (c_p = 0; c_p < top->num_masters; c_p++) 170 for (c_p = 0; c_p < top->num_masters; c_p++)
170 { 171 {
171 if (0 == GNUNET_memcmp(&top->mps[c_p].id, 172 if (0 == GNUNET_memcmp (&top->mps[c_p].id,
172 peer)) 173 peer))
173 return &top->mps[c_p]; 174 return &top->mps[c_p];
174 } 175 }
175 176
176 for (c_p = 0; c_p < top->num_slaves; c_p++) 177 for (c_p = 0; c_p < top->num_slaves; c_p++)
177 { 178 {
178 if (0 == GNUNET_memcmp(&top->sps[c_p].id, 179 if (0 == GNUNET_memcmp (&top->sps[c_p].id,
179 peer)) 180 peer))
180 return &top->sps[c_p]; 181 return &top->sps[c_p];
181 } 182 }
182 return NULL; 183 return NULL;
183} 184}
184 185
@@ -192,9 +193,9 @@ find_peer(const struct GNUNET_PeerIdentity * peer)
192 * @return the `struct BenchmarkPartner` of @a peer 193 * @return the `struct BenchmarkPartner` of @a peer
193 */ 194 */
194static void * 195static void *
195comm_connect_cb(void *cls, 196comm_connect_cb (void *cls,
196 const struct GNUNET_PeerIdentity *peer, 197 const struct GNUNET_PeerIdentity *peer,
197 struct GNUNET_MQ_Handle *mq) 198 struct GNUNET_MQ_Handle *mq)
198{ 199{
199 struct BenchmarkPeer *me = cls; 200 struct BenchmarkPeer *me = cls;
200 struct BenchmarkPeer *remote; 201 struct BenchmarkPeer *remote;
@@ -203,60 +204,60 @@ comm_connect_cb(void *cls,
203 int c; 204 int c;
204 int completed; 205 int completed;
205 206
206 remote = find_peer(peer); 207 remote = find_peer (peer);
207 if (NULL == remote) 208 if (NULL == remote)
208 { 209 {
209 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 210 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
210 "Unknown peer connected: `%s'\n", 211 "Unknown peer connected: `%s'\n",
211 GNUNET_i2s(peer)); 212 GNUNET_i2s (peer));
212 GNUNET_break(0); 213 GNUNET_break (0);
213 return NULL; 214 return NULL;
214 } 215 }
215 216
216 id = GNUNET_strdup(GNUNET_i2s(&me->id)); 217 id = GNUNET_strdup (GNUNET_i2s (&me->id));
217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "%s [%u] `%s' connected to %s [%u] %s\n", 219 "%s [%u] `%s' connected to %s [%u] %s\n",
219 (me->master == GNUNET_YES) ? "Master" : "Slave", 220 (me->master == GNUNET_YES) ? "Master" : "Slave",
220 me->no, 221 me->no,
221 id, 222 id,
222 (remote->master == GNUNET_YES) ? "Master" : "Slave", 223 (remote->master == GNUNET_YES) ? "Master" : "Slave",
223 remote->no, 224 remote->no,
224 GNUNET_i2s(peer)); 225 GNUNET_i2s (peer));
225 226
226 me->core_connections++; 227 me->core_connections++;
227 if ((GNUNET_YES == me->master) && 228 if ((GNUNET_YES == me->master) &&
228 (GNUNET_NO == remote->master) && 229 (GNUNET_NO == remote->master) &&
229 (GNUNET_NO == top->state.connected_CORE)) 230 (GNUNET_NO == top->state.connected_CORE))
231 {
232 me->core_slave_connections++;
233
234 if (me->core_slave_connections == top->num_slaves)
235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
237 "Master [%u] connected all slaves\n",
238 me->no);
239 }
240 completed = GNUNET_YES;
241 for (c = 0; c < top->num_masters; c++)
230 { 242 {
231 me->core_slave_connections++; 243 if (top->mps[c].core_slave_connections != top->num_slaves)
232 244 completed = GNUNET_NO;
233 if (me->core_slave_connections == top->num_slaves)
234 {
235 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
236 "Master [%u] connected all slaves\n",
237 me->no);
238 }
239 completed = GNUNET_YES;
240 for (c = 0; c < top->num_masters; c++)
241 {
242 if (top->mps[c].core_slave_connections != top->num_slaves)
243 completed = GNUNET_NO;
244 }
245 if (GNUNET_YES == completed)
246 {
247 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
248 "All master peers connected all slave peers\n");
249 top->state.connected_CORE = GNUNET_YES;
250 /* Notify about setup done */
251 if (NULL != top->done_cb)
252 top->done_cb(top->done_cb_cls,
253 top->mps,
254 top->sps);
255 }
256 } 245 }
257 GNUNET_free(id); 246 if (GNUNET_YES == completed)
258 p = find_partner(me, 247 {
259 peer); 248 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
249 "All master peers connected all slave peers\n");
250 top->state.connected_CORE = GNUNET_YES;
251 /* Notify about setup done */
252 if (NULL != top->done_cb)
253 top->done_cb (top->done_cb_cls,
254 top->mps,
255 top->sps);
256 }
257 }
258 GNUNET_free (id);
259 p = find_partner (me,
260 peer);
260 if (NULL != p) 261 if (NULL != p)
261 p->mq = mq; 262 p->mq = mq;
262 return p; 263 return p;
@@ -269,9 +270,9 @@ comm_connect_cb(void *cls,
269 * @param internal_cls the `struct BenchmarkPartner` of @a peer 270 * @param internal_cls the `struct BenchmarkPartner` of @a peer
270 */ 271 */
271static void 272static void
272comm_disconnect_cb(void *cls, 273comm_disconnect_cb (void *cls,
273 const struct GNUNET_PeerIdentity *peer, 274 const struct GNUNET_PeerIdentity *peer,
274 void *internal_cls) 275 void *internal_cls)
275{ 276{
276 struct BenchmarkPeer *me = cls; 277 struct BenchmarkPeer *me = cls;
277 struct BenchmarkPartner *p = internal_cls; 278 struct BenchmarkPartner *p = internal_cls;
@@ -280,170 +281,170 @@ comm_disconnect_cb(void *cls,
280 if (NULL == p) 281 if (NULL == p)
281 return; 282 return;
282 283
283 id = GNUNET_strdup(GNUNET_i2s(&me->id)); 284 id = GNUNET_strdup (GNUNET_i2s (&me->id));
284 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "%s disconnected from %s\n", 286 "%s disconnected from %s\n",
286 id, 287 id,
287 GNUNET_i2s(peer)); 288 GNUNET_i2s (peer));
288 GNUNET_assert(me->core_connections > 0); 289 GNUNET_assert (me->core_connections > 0);
289 me->core_connections--; 290 me->core_connections--;
290 291
291 if ((GNUNET_YES == top->state.benchmarking) && 292 if ((GNUNET_YES == top->state.benchmarking) &&
292 ((GNUNET_YES == me->master) || 293 ((GNUNET_YES == me->master) ||
293 (GNUNET_YES == p->dest->master))) 294 (GNUNET_YES == p->dest->master)))
294 { 295 {
295 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
296 "%s disconnected from %s while benchmarking\n", 297 "%s disconnected from %s while benchmarking\n",
297 id, 298 id,
298 GNUNET_i2s(peer)); 299 GNUNET_i2s (peer));
299 } 300 }
300 GNUNET_free(id); 301 GNUNET_free (id);
301} 302}
302 303
303 304
304static void 305static void
305handle_pong(void *cls, 306handle_pong (void *cls,
306 const struct TestMessage *message) 307 const struct TestMessage *message)
307{ 308{
308 struct BenchmarkPartner *p = cls; 309 struct BenchmarkPartner *p = cls;
309 310
310 GNUNET_ATS_TEST_traffic_handle_pong(p); 311 GNUNET_ATS_TEST_traffic_handle_pong (p);
311} 312}
312 313
313 314
314static void 315static void
315handle_ping(void *cls, 316handle_ping (void *cls,
316 const struct TestMessage *message) 317 const struct TestMessage *message)
317{ 318{
318 struct BenchmarkPartner *p = cls; 319 struct BenchmarkPartner *p = cls;
319 320
320 GNUNET_ATS_TEST_traffic_handle_ping(p); 321 GNUNET_ATS_TEST_traffic_handle_ping (p);
321} 322}
322 323
323 324
324static void * 325static void *
325transport_connect_adapter(void *cls, 326transport_connect_adapter (void *cls,
326 const struct GNUNET_CONFIGURATION_Handle *cfg) 327 const struct GNUNET_CONFIGURATION_Handle *cfg)
327{ 328{
328 struct BenchmarkPeer *me = cls; 329 struct BenchmarkPeer *me = cls;
329 struct GNUNET_MQ_MessageHandler handlers[] = { 330 struct GNUNET_MQ_MessageHandler handlers[] = {
330 GNUNET_MQ_hd_fixed_size(ping, 331 GNUNET_MQ_hd_fixed_size (ping,
331 TEST_MESSAGE_TYPE_PING, 332 TEST_MESSAGE_TYPE_PING,
332 struct TestMessage, 333 struct TestMessage,
333 me), 334 me),
334 GNUNET_MQ_hd_fixed_size(pong, 335 GNUNET_MQ_hd_fixed_size (pong,
335 TEST_MESSAGE_TYPE_PONG, 336 TEST_MESSAGE_TYPE_PONG,
336 struct TestMessage, 337 struct TestMessage,
337 me), 338 me),
338 GNUNET_MQ_handler_end() 339 GNUNET_MQ_handler_end ()
339 }; 340 };
340 341
341 me->th = GNUNET_TRANSPORT_core_connect(cfg, 342 me->th = GNUNET_TRANSPORT_core_connect (cfg,
342 &me->id, 343 &me->id,
343 handlers, 344 handlers,
344 me, 345 me,
345 &comm_connect_cb, 346 &comm_connect_cb,
346 &comm_disconnect_cb, 347 &comm_disconnect_cb,
347 NULL); 348 NULL);
348 if (NULL == me->th) 349 if (NULL == me->th)
349 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
350 "Failed to create transport connection \n"); 351 "Failed to create transport connection \n");
351 return me->th; 352 return me->th;
352} 353}
353 354
354 355
355static void 356static void
356transport_disconnect_adapter(void *cls, 357transport_disconnect_adapter (void *cls,
357 void *op_result) 358 void *op_result)
358{ 359{
359 struct BenchmarkPeer *me = cls; 360 struct BenchmarkPeer *me = cls;
360 361
361 GNUNET_TRANSPORT_core_disconnect(me->th); 362 GNUNET_TRANSPORT_core_disconnect (me->th);
362 me->th = NULL; 363 me->th = NULL;
363} 364}
364 365
365 366
366static void * 367static void *
367core_connect_adapter(void *cls, 368core_connect_adapter (void *cls,
368 const struct GNUNET_CONFIGURATION_Handle *cfg) 369 const struct GNUNET_CONFIGURATION_Handle *cfg)
369{ 370{
370 struct BenchmarkPeer *me = cls; 371 struct BenchmarkPeer *me = cls;
371 struct GNUNET_MQ_MessageHandler handlers[] = { 372 struct GNUNET_MQ_MessageHandler handlers[] = {
372 GNUNET_MQ_hd_fixed_size(ping, 373 GNUNET_MQ_hd_fixed_size (ping,
373 TEST_MESSAGE_TYPE_PING, 374 TEST_MESSAGE_TYPE_PING,
374 struct TestMessage, 375 struct TestMessage,
375 me), 376 me),
376 GNUNET_MQ_hd_fixed_size(pong, 377 GNUNET_MQ_hd_fixed_size (pong,
377 TEST_MESSAGE_TYPE_PONG, 378 TEST_MESSAGE_TYPE_PONG,
378 struct TestMessage, 379 struct TestMessage,
379 me), 380 me),
380 GNUNET_MQ_handler_end() 381 GNUNET_MQ_handler_end ()
381 }; 382 };
382 383
383 me->ch = GNUNET_CORE_connect(cfg, 384 me->ch = GNUNET_CORE_connect (cfg,
384 me, 385 me,
385 NULL, 386 NULL,
386 &comm_connect_cb, 387 &comm_connect_cb,
387 &comm_disconnect_cb, 388 &comm_disconnect_cb,
388 handlers); 389 handlers);
389 if (NULL == me->ch) 390 if (NULL == me->ch)
390 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 391 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
391 "Failed to create core connection \n"); 392 "Failed to create core connection \n");
392 return me->ch; 393 return me->ch;
393} 394}
394 395
395 396
396static void 397static void
397core_disconnect_adapter(void *cls, 398core_disconnect_adapter (void *cls,
398 void *op_result) 399 void *op_result)
399{ 400{
400 struct BenchmarkPeer *me = cls; 401 struct BenchmarkPeer *me = cls;
401 402
402 GNUNET_CORE_disconnect(me->ch); 403 GNUNET_CORE_disconnect (me->ch);
403 me->ch = NULL; 404 me->ch = NULL;
404} 405}
405 406
406 407
407static void 408static void
408connect_completion_callback(void *cls, 409connect_completion_callback (void *cls,
409 struct GNUNET_TESTBED_Operation *op, 410 struct GNUNET_TESTBED_Operation *op,
410 const char *emsg) 411 const char *emsg)
411{ 412{
412 struct TestbedConnectOperation *cop = cls; 413 struct TestbedConnectOperation *cop = cls;
413 static int ops = 0; 414 static int ops = 0;
414 int c; 415 int c;
415 416
416 if (NULL == emsg) 417 if (NULL == emsg)
417 { 418 {
418 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 419 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
419 _("Connected master [%u] with slave [%u]\n"), 420 _ ("Connected master [%u] with slave [%u]\n"),
420 cop->master->no, 421 cop->master->no,
421 cop->slave->no); 422 cop->slave->no);
422 } 423 }
423 else 424 else
424 { 425 {
425 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
426 _("Failed to connect master peer [%u] with slave [%u]\n"), 427 _ ("Failed to connect master peer [%u] with slave [%u]\n"),
427 cop->master->no, cop->slave->no); 428 cop->master->no, cop->slave->no);
428 GNUNET_break(0); 429 GNUNET_break (0);
429 GNUNET_SCHEDULER_shutdown(); 430 GNUNET_SCHEDULER_shutdown ();
430 } 431 }
431 GNUNET_TESTBED_operation_done(op); 432 GNUNET_TESTBED_operation_done (op);
432 ops++; 433 ops++;
433 for (c = 0; c < top->num_slaves; c++) 434 for (c = 0; c < top->num_slaves; c++)
434 { 435 {
435 if (cop == &cop->master->core_connect_ops[c]) 436 if (cop == &cop->master->core_connect_ops[c])
436 cop->master->core_connect_ops[c].connect_op = NULL; 437 cop->master->core_connect_ops[c].connect_op = NULL;
437 } 438 }
438 if (ops == top->num_masters * top->num_slaves) 439 if (ops == top->num_masters * top->num_slaves)
439 { 440 {
440 top->state.connected_PEERS = GNUNET_YES; 441 top->state.connected_PEERS = GNUNET_YES;
441 } 442 }
442} 443}
443 444
444 445
445static void 446static void
446do_connect_peers(void *cls) 447do_connect_peers (void *cls)
447{ 448{
448 int c_m; 449 int c_m;
449 int c_s; 450 int c_s;
@@ -453,143 +454,144 @@ do_connect_peers(void *cls)
453 (top->state.connected_COMM_service == GNUNET_NO)) 454 (top->state.connected_COMM_service == GNUNET_NO))
454 return; 455 return;
455 456
456 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 457 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
457 "Connecting peers on CORE level\n"); 458 "Connecting peers on CORE level\n");
458 for (c_m = 0; c_m < top->num_masters; c_m++) 459 for (c_m = 0; c_m < top->num_masters; c_m++)
460 {
461 p = &top->mps[c_m];
462 p->core_connect_ops = GNUNET_malloc (top->num_slaves
463 * sizeof(struct
464 TestbedConnectOperation));
465
466 for (c_s = 0; c_s < top->num_slaves; c_s++)
459 { 467 {
460 p = &top->mps[c_m]; 468 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
461 p->core_connect_ops = GNUNET_malloc(top->num_slaves * 469 "Connecting master [%u] with slave [%u]\n",
462 sizeof(struct TestbedConnectOperation)); 470 p->no,
463 471 top->sps[c_s].no);
464 for (c_s = 0; c_s < top->num_slaves; c_s++) 472 p->core_connect_ops[c_s].master = p;
465 { 473 p->core_connect_ops[c_s].slave = &top->sps[c_s];
466 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 474 p->core_connect_ops[c_s].connect_op
467 "Connecting master [%u] with slave [%u]\n", 475 = GNUNET_TESTBED_overlay_connect (NULL,
468 p->no, 476 &connect_completion_callback,
469 top->sps[c_s].no); 477 &p->core_connect_ops[c_s],
470 p->core_connect_ops[c_s].master = p; 478 top->sps[c_s].peer,
471 p->core_connect_ops[c_s].slave = &top->sps[c_s]; 479 p->peer);
472 p->core_connect_ops[c_s].connect_op 480 if (NULL == p->core_connect_ops[c_s].connect_op)
473 = GNUNET_TESTBED_overlay_connect(NULL, 481 {
474 &connect_completion_callback, 482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
475 &p->core_connect_ops[c_s], 483 "Could not connect master [%u] and slave [%u]\n",
476 top->sps[c_s].peer, 484 p->no,
477 p->peer); 485 top->sps[c_s].no);
478 if (NULL == p->core_connect_ops[c_s].connect_op) 486 GNUNET_break (0);
479 { 487 GNUNET_SCHEDULER_shutdown ();
480 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 488 return;
481 "Could not connect master [%u] and slave [%u]\n", 489 }
482 p->no,
483 top->sps[c_s].no);
484 GNUNET_break(0);
485 GNUNET_SCHEDULER_shutdown();
486 return;
487 }
488 }
489 } 490 }
491 }
490} 492}
491 493
492 494
493static void 495static void
494comm_connect_completion_cb(void *cls, 496comm_connect_completion_cb (void *cls,
495 struct GNUNET_TESTBED_Operation *op, 497 struct GNUNET_TESTBED_Operation *op,
496 void *ca_result, 498 void *ca_result,
497 const char *emsg) 499 const char *emsg)
498{ 500{
499 static int comm_done = 0; 501 static int comm_done = 0;
500 502
501 if ((NULL != emsg) || (NULL == ca_result)) 503 if ((NULL != emsg) || (NULL == ca_result))
502 { 504 {
503 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 505 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
504 "Initialization failed, shutdown\n"); 506 "Initialization failed, shutdown\n");
505 GNUNET_break(0); 507 GNUNET_break (0);
506 GNUNET_SCHEDULER_shutdown(); 508 GNUNET_SCHEDULER_shutdown ();
507 return; 509 return;
508 } 510 }
509 comm_done++; 511 comm_done++;
510 512
511 if (comm_done == top->num_slaves + top->num_masters) 513 if (comm_done == top->num_slaves + top->num_masters)
512 { 514 {
513 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 515 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
514 "Connected to all %s services\n", 516 "Connected to all %s services\n",
515 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); 517 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
516 top->state.connected_COMM_service = GNUNET_YES; 518 top->state.connected_COMM_service = GNUNET_YES;
517 GNUNET_SCHEDULER_add_now(&do_connect_peers, 519 GNUNET_SCHEDULER_add_now (&do_connect_peers,
518 NULL); 520 NULL);
519 } 521 }
520} 522}
521 523
522 524
523static void 525static void
524do_comm_connect(void *cls) 526do_comm_connect (void *cls)
525{ 527{
526 int c_s; 528 int c_s;
527 int c_m; 529 int c_m;
528 530
529 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 531 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
530 "Connecting to all %s services\n", 532 "Connecting to all %s services\n",
531 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); 533 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
532 for (c_m = 0; c_m < top->num_masters; c_m++) 534 for (c_m = 0; c_m < top->num_masters; c_m++)
535 {
536 if (GNUNET_YES == top->test_core)
537 top->mps[c_m].comm_op
538 = GNUNET_TESTBED_service_connect (NULL,
539 top->mps[c_m].peer,
540 "core",
541 &comm_connect_completion_cb,
542 NULL,
543 &core_connect_adapter,
544 &core_disconnect_adapter,
545 &top->mps[c_m]);
546 else
533 { 547 {
534 if (GNUNET_YES == top->test_core) 548 top->mps[c_m].comm_op
535 top->mps[c_m].comm_op 549 = GNUNET_TESTBED_service_connect (NULL,
536 = GNUNET_TESTBED_service_connect(NULL, 550 top->mps[c_m].peer,
537 top->mps[c_m].peer, 551 "transport",
538 "core", 552 &comm_connect_completion_cb,
539 &comm_connect_completion_cb, 553 NULL,
540 NULL, 554 &transport_connect_adapter,
541 &core_connect_adapter, 555 &transport_disconnect_adapter,
542 &core_disconnect_adapter, 556 &top->mps[c_m]);
543 &top->mps[c_m]);
544 else
545 {
546 top->mps[c_m].comm_op
547 = GNUNET_TESTBED_service_connect(NULL,
548 top->mps[c_m].peer,
549 "transport",
550 &comm_connect_completion_cb,
551 NULL,
552 &transport_connect_adapter,
553 &transport_disconnect_adapter,
554 &top->mps[c_m]);
555 }
556 } 557 }
558 }
557 559
558 for (c_s = 0; c_s < top->num_slaves; c_s++) 560 for (c_s = 0; c_s < top->num_slaves; c_s++)
561 {
562 if (GNUNET_YES == top->test_core)
563 top->sps[c_s].comm_op
564 = GNUNET_TESTBED_service_connect (NULL,
565 top->sps[c_s].peer,
566 "core",
567 &comm_connect_completion_cb,
568 NULL,
569 &core_connect_adapter,
570 &core_disconnect_adapter,
571 &top->sps[c_s]);
572 else
559 { 573 {
560 if (GNUNET_YES == top->test_core) 574 top->sps[c_s].comm_op
561 top->sps[c_s].comm_op 575 = GNUNET_TESTBED_service_connect (NULL,
562 = GNUNET_TESTBED_service_connect(NULL, 576 top->sps[c_s].peer,
563 top->sps[c_s].peer, 577 "transport",
564 "core", 578 &comm_connect_completion_cb,
565 &comm_connect_completion_cb, 579 NULL,
566 NULL, 580 &transport_connect_adapter,
567 &core_connect_adapter, 581 &transport_disconnect_adapter,
568 &core_disconnect_adapter, 582 &top->sps[c_s]);
569 &top->sps[c_s]);
570 else
571 {
572 top->sps[c_s].comm_op
573 = GNUNET_TESTBED_service_connect(NULL,
574 top->sps[c_s].peer,
575 "transport",
576 &comm_connect_completion_cb,
577 NULL,
578 &transport_connect_adapter,
579 &transport_disconnect_adapter,
580 &top->sps[c_s]);
581 }
582 } 583 }
584 }
583} 585}
584 586
585 587
586static void 588static void
587ats_performance_info_cb(void *cls, 589ats_performance_info_cb (void *cls,
588 const struct GNUNET_HELLO_Address *address, 590 const struct GNUNET_HELLO_Address *address,
589 int address_active, 591 int address_active,
590 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 592 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
591 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 593 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
592 const struct GNUNET_ATS_Properties *ats_prop) 594 const struct GNUNET_ATS_Properties *ats_prop)
593{ 595{
594 struct BenchmarkPeer *me = cls; 596 struct BenchmarkPeer *me = cls;
595 struct BenchmarkPartner *p; 597 struct BenchmarkPartner *p;
@@ -597,36 +599,36 @@ ats_performance_info_cb(void *cls,
597 char *peer_id; 599 char *peer_id;
598 600
599 if (NULL == address) 601 if (NULL == address)
600 { 602 {
601 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
602 "Peer %u: ATS Service disconnected!\n", 604 "Peer %u: ATS Service disconnected!\n",
603 me->no); 605 me->no);
604 return; 606 return;
605 } 607 }
606 608
607 p = find_partner(me, 609 p = find_partner (me,
608 &address->peer); 610 &address->peer);
609 if (NULL == p) 611 if (NULL == p)
610 { 612 {
611 /* This is not one of my partners 613 /* This is not one of my partners
612 * Will happen since the peers will connect to each other due to gossiping 614 * Will happen since the peers will connect to each other due to gossiping
613 */ 615 */
614 return; 616 return;
615 } 617 }
616 peer_id = GNUNET_strdup(GNUNET_i2s(&me->id)); 618 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
617 619
618 log = GNUNET_NO; 620 log = GNUNET_NO;
619 if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) || 621 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
620 (p->bandwidth_out != ntohl(bandwidth_out.value__))) 622 (p->bandwidth_out != ntohl (bandwidth_out.value__)))
621 log = GNUNET_YES; 623 log = GNUNET_YES;
622 p->bandwidth_in = ntohl(bandwidth_in.value__); 624 p->bandwidth_in = ntohl (bandwidth_in.value__);
623 p->bandwidth_out = ntohl(bandwidth_out.value__); 625 p->bandwidth_out = ntohl (bandwidth_out.value__);
624 626
625 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
626 "%s [%u] received ATS information: %s\n", 628 "%s [%u] received ATS information: %s\n",
627 (GNUNET_YES == p->me->master) ? "Master" : "Slave", 629 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
628 p->me->no, 630 p->me->no,
629 GNUNET_i2s(&p->dest->id)); 631 GNUNET_i2s (&p->dest->id));
630 632
631 p->props.utilization_out = ats_prop->utilization_out; 633 p->props.utilization_out = ats_prop->utilization_out;
632 p->props.utilization_in = ats_prop->utilization_in; 634 p->props.utilization_in = ats_prop->utilization_in;
@@ -635,137 +637,137 @@ ats_performance_info_cb(void *cls,
635 p->props.distance = ats_prop->distance; 637 p->props.distance = ats_prop->distance;
636 638
637 if (GNUNET_YES == log) 639 if (GNUNET_YES == log)
638 top->ats_perf_cb(cls, address, 640 top->ats_perf_cb (cls, address,
639 address_active, 641 address_active,
640 bandwidth_out, 642 bandwidth_out,
641 bandwidth_in, 643 bandwidth_in,
642 ats_prop); 644 ats_prop);
643 GNUNET_free(peer_id); 645 GNUNET_free (peer_id);
644} 646}
645 647
646 648
647static void * 649static void *
648ats_perf_connect_adapter(void *cls, 650ats_perf_connect_adapter (void *cls,
649 const struct GNUNET_CONFIGURATION_Handle *cfg) 651 const struct GNUNET_CONFIGURATION_Handle *cfg)
650{ 652{
651 struct BenchmarkPeer *me = cls; 653 struct BenchmarkPeer *me = cls;
652 654
653 me->ats_perf_handle 655 me->ats_perf_handle
654 = GNUNET_ATS_performance_init(cfg, 656 = GNUNET_ATS_performance_init (cfg,
655 &ats_performance_info_cb, 657 &ats_performance_info_cb,
656 me); 658 me);
657 if (NULL == me->ats_perf_handle) 659 if (NULL == me->ats_perf_handle)
658 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 660 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
659 "Failed to create ATS performance handle \n"); 661 "Failed to create ATS performance handle \n");
660 return me->ats_perf_handle; 662 return me->ats_perf_handle;
661} 663}
662 664
663 665
664static void 666static void
665ats_perf_disconnect_adapter(void *cls, 667ats_perf_disconnect_adapter (void *cls,
666 void *op_result) 668 void *op_result)
667{ 669{
668 struct BenchmarkPeer *me = cls; 670 struct BenchmarkPeer *me = cls;
669 671
670 GNUNET_ATS_performance_done(me->ats_perf_handle); 672 GNUNET_ATS_performance_done (me->ats_perf_handle);
671 me->ats_perf_handle = NULL; 673 me->ats_perf_handle = NULL;
672} 674}
673 675
674 676
675static void 677static void
676ats_connect_completion_cb(void *cls, 678ats_connect_completion_cb (void *cls,
677 struct GNUNET_TESTBED_Operation *op, 679 struct GNUNET_TESTBED_Operation *op,
678 void *ca_result, 680 void *ca_result,
679 const char *emsg) 681 const char *emsg)
680{ 682{
681 static int op_done = 0; 683 static int op_done = 0;
682 684
683 if ((NULL != emsg) || (NULL == ca_result)) 685 if ((NULL != emsg) || (NULL == ca_result))
684 { 686 {
685 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 687 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
686 "Initialization failed, shutdown\n"); 688 "Initialization failed, shutdown\n");
687 GNUNET_break(0); 689 GNUNET_break (0);
688 GNUNET_SCHEDULER_shutdown(); 690 GNUNET_SCHEDULER_shutdown ();
689 return; 691 return;
690 } 692 }
691 op_done++; 693 op_done++;
692 if (op_done == (top->num_masters + top->num_slaves)) 694 if (op_done == (top->num_masters + top->num_slaves))
693 { 695 {
694 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 696 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
695 "Connected to all ATS services\n"); 697 "Connected to all ATS services\n");
696 top->state.connected_ATS_service = GNUNET_YES; 698 top->state.connected_ATS_service = GNUNET_YES;
697 GNUNET_SCHEDULER_add_now(&do_comm_connect, 699 GNUNET_SCHEDULER_add_now (&do_comm_connect,
698 NULL); 700 NULL);
699 } 701 }
700} 702}
701 703
702 704
703static void 705static void
704do_connect_ats(void *cls) 706do_connect_ats (void *cls)
705{ 707{
706 int c_m; 708 int c_m;
707 int c_s; 709 int c_s;
708 710
709 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 711 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
710 "Connecting to all ATS services\n"); 712 "Connecting to all ATS services\n");
711 for (c_m = 0; c_m < top->num_masters; c_m++) 713 for (c_m = 0; c_m < top->num_masters; c_m++)
712 { 714 {
713 top->mps[c_m].ats_perf_op 715 top->mps[c_m].ats_perf_op
714 = GNUNET_TESTBED_service_connect(NULL, 716 = GNUNET_TESTBED_service_connect (NULL,
715 top->mps[c_m].peer, 717 top->mps[c_m].peer,
716 "ats", 718 "ats",
717 &ats_connect_completion_cb, 719 &ats_connect_completion_cb,
718 NULL, 720 NULL,
719 &ats_perf_connect_adapter, 721 &ats_perf_connect_adapter,
720 &ats_perf_disconnect_adapter, 722 &ats_perf_disconnect_adapter,
721 &top->mps[c_m]); 723 &top->mps[c_m]);
722 } 724 }
723 725
724 for (c_s = 0; c_s < top->num_slaves; c_s++) 726 for (c_s = 0; c_s < top->num_slaves; c_s++)
725 { 727 {
726 top->sps[c_s].ats_perf_op 728 top->sps[c_s].ats_perf_op
727 = GNUNET_TESTBED_service_connect(NULL, 729 = GNUNET_TESTBED_service_connect (NULL,
728 top->sps[c_s].peer, 730 top->sps[c_s].peer,
729 "ats", 731 "ats",
730 &ats_connect_completion_cb, 732 &ats_connect_completion_cb,
731 NULL, 733 NULL,
732 &ats_perf_connect_adapter, 734 &ats_perf_connect_adapter,
733 &ats_perf_disconnect_adapter, 735 &ats_perf_disconnect_adapter,
734 &top->sps[c_s]); 736 &top->sps[c_s]);
735 } 737 }
736} 738}
737 739
738 740
739 741
740static void 742static void
741peerinformation_cb(void *cb_cls, 743peerinformation_cb (void *cb_cls,
742 struct GNUNET_TESTBED_Operation *op, 744 struct GNUNET_TESTBED_Operation *op,
743 const struct GNUNET_TESTBED_PeerInformation *pinfo, 745 const struct GNUNET_TESTBED_PeerInformation *pinfo,
744 const char *emsg) 746 const char *emsg)
745{ 747{
746 struct BenchmarkPeer *p = cb_cls; 748 struct BenchmarkPeer *p = cb_cls;
747 static int done = 0; 749 static int done = 0;
748 750
749 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); 751 GNUNET_assert (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
750 752
751 p->id = *pinfo->result.id; 753 p->id = *pinfo->result.id;
752 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 754 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
753 "%s [%u] has peer id `%s'\n", 755 "%s [%u] has peer id `%s'\n",
754 (p->master == GNUNET_YES) ? "Master" : "Slave", 756 (p->master == GNUNET_YES) ? "Master" : "Slave",
755 p->no, 757 p->no,
756 GNUNET_i2s(&p->id)); 758 GNUNET_i2s (&p->id));
757 759
758 GNUNET_TESTBED_operation_done(op); 760 GNUNET_TESTBED_operation_done (op);
759 p->peer_id_op = NULL; 761 p->peer_id_op = NULL;
760 done++; 762 done++;
761 763
762 if (done == top->num_slaves + top->num_masters) 764 if (done == top->num_slaves + top->num_masters)
763 { 765 {
764 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 766 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
765 "Retrieved all peer ID, connect to ATS\n"); 767 "Retrieved all peer ID, connect to ATS\n");
766 GNUNET_SCHEDULER_add_now(&do_connect_ats, 768 GNUNET_SCHEDULER_add_now (&do_connect_ats,
767 NULL); 769 NULL);
768 } 770 }
769} 771}
770 772
771 773
@@ -782,85 +784,85 @@ peerinformation_cb(void *cb_cls,
782 * failed 784 * failed
783 */ 785 */
784static void 786static void
785main_run(void *cls, 787main_run (void *cls,
786 struct GNUNET_TESTBED_RunHandle *h, 788 struct GNUNET_TESTBED_RunHandle *h,
787 unsigned int num_peers, 789 unsigned int num_peers,
788 struct GNUNET_TESTBED_Peer **peers_, 790 struct GNUNET_TESTBED_Peer **peers_,
789 unsigned int links_succeeded, 791 unsigned int links_succeeded,
790 unsigned int links_failed) 792 unsigned int links_failed)
791{ 793{
792 int c_m; 794 int c_m;
793 int c_s; 795 int c_s;
794 796
795 GNUNET_assert(NULL == cls); 797 GNUNET_assert (NULL == cls);
796 GNUNET_assert(top->num_masters + top->num_slaves == num_peers); 798 GNUNET_assert (top->num_masters + top->num_slaves == num_peers);
797 GNUNET_assert(NULL != peers_); 799 GNUNET_assert (NULL != peers_);
798 800
799 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 801 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
800 top); 802 top);
801 803
802 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 804 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
803 "Setting up %u masters and %u slaves\n", 805 "Setting up %u masters and %u slaves\n",
804 top->num_masters, 806 top->num_masters,
805 top->num_slaves); 807 top->num_slaves);
806 808
807 /* Setup master peers */ 809 /* Setup master peers */
808 for (c_m = 0; c_m < top->num_masters; c_m++) 810 for (c_m = 0; c_m < top->num_masters; c_m++)
811 {
812 GNUNET_assert (NULL != peers_[c_m]);
813 top->mps[c_m].peer = peers_[c_m];
814 top->mps[c_m].no = c_m;
815 top->mps[c_m].master = GNUNET_YES;
816 top->mps[c_m].pref_partner = &top->sps[c_m];
817 top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
818 top->mps[c_m].partners =
819 GNUNET_malloc (top->num_slaves * sizeof(struct BenchmarkPartner));
820 top->mps[c_m].num_partners = top->num_slaves;
821 /* Initialize partners */
822 for (c_s = 0; c_s < top->num_slaves; c_s++)
809 { 823 {
810 GNUNET_assert(NULL != peers_[c_m]); 824 top->mps[c_m].partners[c_s].me = &top->mps[c_m];
811 top->mps[c_m].peer = peers_[c_m]; 825 top->mps[c_m].partners[c_s].dest = &top->sps[c_s];
812 top->mps[c_m].no = c_m;
813 top->mps[c_m].master = GNUNET_YES;
814 top->mps[c_m].pref_partner = &top->sps[c_m];
815 top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
816 top->mps[c_m].partners =
817 GNUNET_malloc(top->num_slaves * sizeof(struct BenchmarkPartner));
818 top->mps[c_m].num_partners = top->num_slaves;
819 /* Initialize partners */
820 for (c_s = 0; c_s < top->num_slaves; c_s++)
821 {
822 top->mps[c_m].partners[c_s].me = &top->mps[c_m];
823 top->mps[c_m].partners[c_s].dest = &top->sps[c_s];
824 }
825 /* Get configuration */
826 top->mps[c_m].peer_id_op
827 = GNUNET_TESTBED_peer_get_information(top->mps[c_m].peer,
828 GNUNET_TESTBED_PIT_IDENTITY,
829 &peerinformation_cb,
830 &top->mps[c_m]);
831 } 826 }
827 /* Get configuration */
828 top->mps[c_m].peer_id_op
829 = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer,
830 GNUNET_TESTBED_PIT_IDENTITY,
831 &peerinformation_cb,
832 &top->mps[c_m]);
833 }
832 834
833 /* Setup slave peers */ 835 /* Setup slave peers */
834 for (c_s = 0; c_s < top->num_slaves; c_s++) 836 for (c_s = 0; c_s < top->num_slaves; c_s++)
837 {
838 GNUNET_assert (NULL != peers_[c_s + top->num_masters]);
839 top->sps[c_s].peer = peers_[c_s + top->num_masters];
840 top->sps[c_s].no = c_s + top->num_masters;
841 top->sps[c_s].master = GNUNET_NO;
842 top->sps[c_s].partners =
843 GNUNET_new_array (top->num_masters,
844 struct BenchmarkPartner);
845 top->sps[c_s].num_partners = top->num_masters;
846 /* Initialize partners */
847 for (c_m = 0; c_m < top->num_masters; c_m++)
835 { 848 {
836 GNUNET_assert(NULL != peers_[c_s + top->num_masters]); 849 top->sps[c_s].partners[c_m].me = &top->sps[c_s];
837 top->sps[c_s].peer = peers_[c_s + top->num_masters]; 850 top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
838 top->sps[c_s].no = c_s + top->num_masters; 851
839 top->sps[c_s].master = GNUNET_NO; 852 /* Initialize properties */
840 top->sps[c_s].partners = 853 top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO;
841 GNUNET_new_array(top->num_masters, 854 top->sps[c_s].partners[c_m].props.distance = 0;
842 struct BenchmarkPartner); 855 top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED;
843 top->sps[c_s].num_partners = top->num_masters; 856 top->sps[c_s].partners[c_m].props.utilization_in = 0;
844 /* Initialize partners */ 857 top->sps[c_s].partners[c_m].props.utilization_out = 0;
845 for (c_m = 0; c_m < top->num_masters; c_m++)
846 {
847 top->sps[c_s].partners[c_m].me = &top->sps[c_s];
848 top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
849
850 /* Initialize properties */
851 top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO;
852 top->sps[c_s].partners[c_m].props.distance = 0;
853 top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED;
854 top->sps[c_s].partners[c_m].props.utilization_in = 0;
855 top->sps[c_s].partners[c_m].props.utilization_out = 0;
856 }
857 /* Get configuration */
858 top->sps[c_s].peer_id_op
859 = GNUNET_TESTBED_peer_get_information(top->sps[c_s].peer,
860 GNUNET_TESTBED_PIT_IDENTITY,
861 &peerinformation_cb,
862 &top->sps[c_s]);
863 } 858 }
859 /* Get configuration */
860 top->sps[c_s].peer_id_op
861 = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer,
862 GNUNET_TESTBED_PIT_IDENTITY,
863 &peerinformation_cb,
864 &top->sps[c_s]);
865 }
864} 866}
865 867
866 868
@@ -871,26 +873,26 @@ main_run(void *cls,
871 * @param event the controller event 873 * @param event the controller event
872 */ 874 */
873static void 875static void
874controller_event_cb(void *cls, 876controller_event_cb (void *cls,
875 const struct GNUNET_TESTBED_EventInformation *event) 877 const struct GNUNET_TESTBED_EventInformation *event)
876{ 878{
877 switch (event->type) 879 switch (event->type)
878 { 880 {
879 case GNUNET_TESTBED_ET_CONNECT: 881 case GNUNET_TESTBED_ET_CONNECT:
880 break; 882 break;
881 883
882 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 884 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
883 break; 885 break;
884 886
885 default: 887 default:
886 GNUNET_break(0); 888 GNUNET_break (0);
887 GNUNET_SCHEDULER_shutdown(); 889 GNUNET_SCHEDULER_shutdown ();
888 } 890 }
889} 891}
890 892
891 893
892struct BenchmarkPeer * 894struct BenchmarkPeer *
893GNUNET_ATS_TEST_get_peer(int src) 895GNUNET_ATS_TEST_get_peer (int src)
894{ 896{
895 if (src > top->num_masters) 897 if (src > top->num_masters)
896 return NULL; 898 return NULL;
@@ -899,8 +901,8 @@ GNUNET_ATS_TEST_get_peer(int src)
899 901
900 902
901struct BenchmarkPartner * 903struct BenchmarkPartner *
902GNUNET_ATS_TEST_get_partner(int src, 904GNUNET_ATS_TEST_get_partner (int src,
903 int dest) 905 int dest)
904{ 906{
905 if (src > top->num_masters) 907 if (src > top->num_masters)
906 return NULL; 908 return NULL;
@@ -923,37 +925,39 @@ GNUNET_ATS_TEST_get_partner(int src,
923 * @param log_request_cb callback to call when logging is required 925 * @param log_request_cb callback to call when logging is required
924 */ 926 */
925void 927void
926GNUNET_ATS_TEST_create_topology(char *name, char *cfg_file, 928GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
927 unsigned int num_slaves, 929 unsigned int num_slaves,
928 unsigned int num_masters, 930 unsigned int num_masters,
929 int test_core, 931 int test_core,
930 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, 932 GNUNET_ATS_TEST_TopologySetupDoneCallback
931 void *done_cb_cls, 933 done_cb,
932 GNUNET_ATS_AddressInformationCallback log_request_cb) 934 void *done_cb_cls,
935 GNUNET_ATS_AddressInformationCallback
936 log_request_cb)
933{ 937{
934 top = GNUNET_new(struct GNUNET_ATS_TEST_Topology); 938 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
935 top->num_masters = num_masters; 939 top->num_masters = num_masters;
936 top->num_slaves = num_slaves; 940 top->num_slaves = num_slaves;
937 top->done_cb = done_cb; 941 top->done_cb = done_cb;
938 top->done_cb_cls = done_cb_cls; 942 top->done_cb_cls = done_cb_cls;
939 top->test_core = test_core; 943 top->test_core = test_core;
940 top->ats_perf_cb = log_request_cb; 944 top->ats_perf_cb = log_request_cb;
941 top->mps = GNUNET_new_array(num_masters, 945 top->mps = GNUNET_new_array (num_masters,
942 struct BenchmarkPeer); 946 struct BenchmarkPeer);
943 top->sps = GNUNET_new_array(num_slaves, 947 top->sps = GNUNET_new_array (num_slaves,
944 struct BenchmarkPeer); 948 struct BenchmarkPeer);
945 949
946 /* Start topology */ 950 /* Start topology */
947 uint64_t event_mask; 951 uint64_t event_mask;
948 event_mask = 0; 952 event_mask = 0;
949 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 953 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
950 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 954 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
951 (void)GNUNET_TESTBED_test_run(name, 955 (void) GNUNET_TESTBED_test_run (name,
952 cfg_file, 956 cfg_file,
953 num_slaves + num_masters, 957 num_slaves + num_masters,
954 event_mask, 958 event_mask,
955 &controller_event_cb, NULL, 959 &controller_event_cb, NULL,
956 &main_run, NULL); 960 &main_run, NULL);
957} 961}
958 962
959 963
@@ -961,11 +965,11 @@ GNUNET_ATS_TEST_create_topology(char *name, char *cfg_file,
961 * Shutdown topology 965 * Shutdown topology
962 */ 966 */
963void 967void
964GNUNET_ATS_TEST_shutdown_topology(void) 968GNUNET_ATS_TEST_shutdown_topology (void)
965{ 969{
966 if (NULL == top) 970 if (NULL == top)
967 return; 971 return;
968 GNUNET_SCHEDULER_shutdown(); 972 GNUNET_SCHEDULER_shutdown ();
969} 973}
970 974
971 975
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h
index ff3a40837..017ffef4f 100644
--- a/src/ats-tests/ats-testing.h
+++ b/src/ats-tests/ats-testing.h
@@ -48,7 +48,8 @@
48#define TEST_MESSAGE_SIZE 100 48#define TEST_MESSAGE_SIZE 100
49 49
50 50
51struct TestMessage { 51struct TestMessage
52{
52 struct GNUNET_MessageHeader header; 53 struct GNUNET_MessageHeader header;
53 54
54 uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)]; 55 uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)];
@@ -65,7 +66,8 @@ struct TrafficGenerator;
65 66
66struct LoggingHandle; 67struct LoggingHandle;
67 68
68enum GeneratorType { 69enum GeneratorType
70{
69 GNUNET_ATS_TEST_TG_LINEAR, 71 GNUNET_ATS_TEST_TG_LINEAR,
70 GNUNET_ATS_TEST_TG_CONSTANT, 72 GNUNET_ATS_TEST_TG_CONSTANT,
71 GNUNET_ATS_TEST_TG_RANDOM, 73 GNUNET_ATS_TEST_TG_RANDOM,
@@ -106,7 +108,8 @@ typedef void (*GNUNET_ATS_TEST_LogRequest) (
106/** 108/**
107 * Information we track for a peer in the testbed. 109 * Information we track for a peer in the testbed.
108 */ 110 */
109struct BenchmarkPeer { 111struct BenchmarkPeer
112{
110 /** 113 /**
111 * Handle with testbed. 114 * Handle with testbed.
112 */ 115 */
@@ -224,7 +227,8 @@ struct BenchmarkPeer {
224 unsigned int total_bytes_received; 227 unsigned int total_bytes_received;
225}; 228};
226 229
227struct TrafficGenerator { 230struct TrafficGenerator
231{
228 struct TrafficGenerator *prev; 232 struct TrafficGenerator *prev;
229 struct TrafficGenerator *next; 233 struct TrafficGenerator *next;
230 234
@@ -243,7 +247,8 @@ struct TrafficGenerator {
243}; 247};
244 248
245 249
246struct PreferenceGenerator { 250struct PreferenceGenerator
251{
247 struct PreferenceGenerator *prev; 252 struct PreferenceGenerator *prev;
248 struct PreferenceGenerator *next; 253 struct PreferenceGenerator *next;
249 254
@@ -267,7 +272,8 @@ struct PreferenceGenerator {
267/** 272/**
268 * Information about a benchmarking partner 273 * Information about a benchmarking partner
269 */ 274 */
270struct BenchmarkPartner { 275struct BenchmarkPartner
276{
271 /** 277 /**
272 * The peer itself this partner belongs to 278 * The peer itself this partner belongs to
273 */ 279 */
@@ -353,7 +359,8 @@ struct BenchmarkPartner {
353/** 359/**
354 * Overall state of the performance benchmark 360 * Overall state of the performance benchmark
355 */ 361 */
356struct BenchmarkState { 362struct BenchmarkState
363{
357 /** 364 /**
358 * Are we connected to ATS service of all peers: GNUNET_YES/NO 365 * Are we connected to ATS service of all peers: GNUNET_YES/NO
359 */ 366 */
@@ -381,7 +388,8 @@ struct BenchmarkState {
381}; 388};
382 389
383 390
384struct GNUNET_ATS_TEST_Topology { 391struct GNUNET_ATS_TEST_Topology
392{
385 /** 393 /**
386 * Progress task 394 * Progress task
387 */ 395 */
@@ -459,7 +467,8 @@ struct GNUNET_ATS_TEST_Topology {
459 void *done_cb_cls; 467 void *done_cb_cls;
460}; 468};
461 469
462enum OperationType { 470enum OperationType
471{
463 START_SEND, 472 START_SEND,
464 STOP_SEND, 473 STOP_SEND,
465 START_PREFERENCE, 474 START_PREFERENCE,
@@ -480,7 +489,8 @@ typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (
480/** 489/**
481 * An operation in an experiment 490 * An operation in an experiment
482 */ 491 */
483struct GNUNET_ATS_TEST_Operation { 492struct GNUNET_ATS_TEST_Operation
493{
484 struct GNUNET_ATS_TEST_Operation *next; 494 struct GNUNET_ATS_TEST_Operation *next;
485 struct GNUNET_ATS_TEST_Operation *prev; 495 struct GNUNET_ATS_TEST_Operation *prev;
486 496
@@ -497,7 +507,8 @@ struct GNUNET_ATS_TEST_Operation {
497 enum GNUNET_ATS_PreferenceKind pref_type; 507 enum GNUNET_ATS_PreferenceKind pref_type;
498}; 508};
499 509
500struct Episode { 510struct Episode
511{
501 int id; 512 int id;
502 struct Episode *next; 513 struct Episode *next;
503 struct GNUNET_TIME_Relative duration; 514 struct GNUNET_TIME_Relative duration;
@@ -507,7 +518,8 @@ struct Episode {
507}; 518};
508 519
509 520
510struct Experiment { 521struct Experiment
522{
511 char *name; 523 char *name;
512 char *cfg_file; 524 char *cfg_file;
513 unsigned long long int num_masters; 525 unsigned long long int num_masters;
@@ -538,7 +550,7 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg;
538 * @param e_done_cb the experiment is completed 550 * @param e_done_cb the experiment is completed
539 */ 551 */
540void 552void
541GNUNET_ATS_TEST_experimentation_run( 553GNUNET_ATS_TEST_experimentation_run (
542 struct Experiment *e, 554 struct Experiment *e,
543 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, 555 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
544 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb); 556 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb);
@@ -551,7 +563,7 @@ GNUNET_ATS_TEST_experimentation_run(
551 * @return the Experiment or NULL on failure 563 * @return the Experiment or NULL on failure
552 */ 564 */
553struct Experiment * 565struct Experiment *
554GNUNET_ATS_TEST_experimentation_load(const char *filename); 566GNUNET_ATS_TEST_experimentation_load (const char *filename);
555 567
556 568
557/** 569/**
@@ -560,15 +572,15 @@ GNUNET_ATS_TEST_experimentation_load(const char *filename);
560 * @param e the experiment 572 * @param e the experiment
561 */ 573 */
562void 574void
563GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e); 575GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e);
564 576
565 577
566void 578void
567GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p); 579GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p);
568 580
569 581
570void 582void
571GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p); 583GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
572 584
573 585
574/** 586/**
@@ -585,24 +597,24 @@ GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p);
585 * @return the traffic generator 597 * @return the traffic generator
586 */ 598 */
587struct TrafficGenerator * 599struct TrafficGenerator *
588GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, 600GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
589 struct BenchmarkPartner *dest, 601 struct BenchmarkPartner *dest,
590 enum GeneratorType type, 602 enum GeneratorType type,
591 unsigned int base_rate, 603 unsigned int base_rate,
592 unsigned int max_rate, 604 unsigned int max_rate,
593 struct GNUNET_TIME_Relative period, 605 struct GNUNET_TIME_Relative period,
594 struct GNUNET_TIME_Relative duration); 606 struct GNUNET_TIME_Relative duration);
595 607
596 608
597void 609void
598GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg); 610GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
599 611
600 612
601/** 613/**
602 * Stop all traffic generators 614 * Stop all traffic generators
603 */ 615 */
604void 616void
605GNUNET_ATS_TEST_generate_traffic_stop_all(void); 617GNUNET_ATS_TEST_generate_traffic_stop_all (void);
606 618
607 619
608/** 620/**
@@ -620,7 +632,7 @@ GNUNET_ATS_TEST_generate_traffic_stop_all(void);
620 * @return the traffic generator 632 * @return the traffic generator
621 */ 633 */
622struct PreferenceGenerator * 634struct PreferenceGenerator *
623GNUNET_ATS_TEST_generate_preferences_start( 635GNUNET_ATS_TEST_generate_preferences_start (
624 struct BenchmarkPeer *src, 636 struct BenchmarkPeer *src,
625 struct BenchmarkPartner *dest, 637 struct BenchmarkPartner *dest,
626 enum GeneratorType type, 638 enum GeneratorType type,
@@ -632,11 +644,11 @@ GNUNET_ATS_TEST_generate_preferences_start(
632 644
633 645
634void 646void
635GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg); 647GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
636 648
637 649
638void 650void
639GNUNET_ATS_TEST_generate_preferences_stop_all(void); 651GNUNET_ATS_TEST_generate_preferences_stop_all (void);
640 652
641 653
642/** 654/**
@@ -651,12 +663,12 @@ GNUNET_ATS_TEST_generate_preferences_stop_all(void);
651 * @return the logging handle or NULL on error 663 * @return the logging handle or NULL on error
652 */ 664 */
653struct LoggingHandle * 665struct LoggingHandle *
654GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency, 666GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
655 const char *testname, 667 const char *testname,
656 struct BenchmarkPeer *masters, 668 struct BenchmarkPeer *masters,
657 int num_masters, 669 int num_masters,
658 int num_slaves, 670 int num_slaves,
659 int verbose); 671 int verbose);
660 672
661 673
662/** 674/**
@@ -665,7 +677,7 @@ GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
665 * @param l the logging handle 677 * @param l the logging handle
666 */ 678 */
667void 679void
668GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l); 680GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l);
669 681
670 682
671/** 683/**
@@ -674,7 +686,7 @@ GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l);
674 * @param l the logging handle 686 * @param l the logging handle
675 */ 687 */
676void 688void
677GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l); 689GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l);
678 690
679 691
680/** 692/**
@@ -683,7 +695,7 @@ GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l);
683 * @param l logging handle to use 695 * @param l logging handle to use
684 */ 696 */
685void 697void
686GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l); 698GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l);
687 699
688 700
689/** 701/**
@@ -694,20 +706,20 @@ GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l);
694 * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO 706 * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO
695 */ 707 */
696void 708void
697GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, 709GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
698 const char *test_name, 710 const char *test_name,
699 int plots); 711 int plots);
700 712
701 713
702/** 714/**
703 * Topology related functions 715 * Topology related functions
704 */ 716 */
705struct BenchmarkPeer * 717struct BenchmarkPeer *
706GNUNET_ATS_TEST_get_peer(int src); 718GNUNET_ATS_TEST_get_peer (int src);
707 719
708 720
709struct BenchmarkPartner * 721struct BenchmarkPartner *
710GNUNET_ATS_TEST_get_partner(int src, int dest); 722GNUNET_ATS_TEST_get_partner (int src, int dest);
711 723
712 724
713/** 725/**
@@ -724,7 +736,7 @@ GNUNET_ATS_TEST_get_partner(int src, int dest);
724 * @param log_request_cb callback to call when logging is required 736 * @param log_request_cb callback to call when logging is required
725 */ 737 */
726void 738void
727GNUNET_ATS_TEST_create_topology( 739GNUNET_ATS_TEST_create_topology (
728 char *name, 740 char *name,
729 char *cfg_file, 741 char *cfg_file,
730 unsigned int num_slaves, 742 unsigned int num_slaves,
@@ -739,7 +751,7 @@ GNUNET_ATS_TEST_create_topology(
739 * Shutdown topology 751 * Shutdown topology
740 */ 752 */
741void 753void
742GNUNET_ATS_TEST_shutdown_topology(void); 754GNUNET_ATS_TEST_shutdown_topology (void);
743 755
744 756
745/* end of file ats-testing.h */ 757/* end of file ats-testing.h */
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index d6168d388..c9e7a6d9f 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -32,7 +32,8 @@
32#include "gnunet_core_service.h" 32#include "gnunet_core_service.h"
33#include "ats-testing.h" 33#include "ats-testing.h"
34 34
35#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 35#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
36 10)
36 37
37static struct BenchmarkPeer *masters_p; 38static struct BenchmarkPeer *masters_p;
38static struct BenchmarkPeer *slaves_p; 39static struct BenchmarkPeer *slaves_p;
@@ -65,7 +66,7 @@ static struct LoggingHandle *l;
65 66
66 67
67static void 68static void
68evaluate(struct GNUNET_TIME_Relative duration_total) 69evaluate (struct GNUNET_TIME_Relative duration_total)
69{ 70{
70 int c_m; 71 int c_m;
71 int c_s; 72 int c_s;
@@ -84,166 +85,168 @@ evaluate(struct GNUNET_TIME_Relative duration_total)
84 if (0 == duration) 85 if (0 == duration)
85 duration = 1; 86 duration = 1;
86 for (c_m = 0; c_m < e->num_masters; c_m++) 87 for (c_m = 0; c_m < e->num_masters; c_m++)
88 {
89 mp = &masters_p[c_m];
90 fprintf (stderr,
91 _ (
92 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
93 mp->no, mp->total_bytes_sent / 1024,
94 duration,
95 (mp->total_bytes_sent / 1024) / duration,
96 mp->total_bytes_received / 1024,
97 duration,
98 (mp->total_bytes_received / 1024) / duration);
99
100 for (c_s = 0; c_s < e->num_slaves; c_s++)
87 { 101 {
88 mp = &masters_p[c_m]; 102 p = &mp->partners[c_s];
89 fprintf(stderr, 103
90 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), 104 b_sent_sec = 0;
91 mp->no, mp->total_bytes_sent / 1024, 105 b_recv_sec = 0;
92 duration, 106 kb_sent_percent = 0.0;
93 (mp->total_bytes_sent / 1024) / duration, 107 kb_recv_percent = 0.0;
94 mp->total_bytes_received / 1024, 108 rtt = 0;
95 duration, 109
96 (mp->total_bytes_received / 1024) / duration); 110 if (duration > 0)
97 111 {
98 for (c_s = 0; c_s < e->num_slaves; c_s++) 112 b_sent_sec = p->bytes_sent / duration;
99 { 113 b_recv_sec = p->bytes_received / duration;
100 p = &mp->partners[c_s]; 114 }
101 115
102 b_sent_sec = 0; 116 if (mp->total_bytes_sent > 0)
103 b_recv_sec = 0; 117 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
104 kb_sent_percent = 0.0; 118 if (mp->total_bytes_received > 0)
105 kb_recv_percent = 0.0; 119 kb_recv_percent = ((double) p->bytes_received * 100)
106 rtt = 0; 120 / mp->total_bytes_received;
107 121 if (1000 * p->messages_sent > 0)
108 if (duration > 0) 122 rtt = p->total_app_rtt / (1000 * p->messages_sent);
109 { 123 fprintf (stderr,
110 b_sent_sec = p->bytes_sent / duration; 124 "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
111 b_recv_sec = p->bytes_received / duration; 125 (mp->pref_partner == p->dest) ? '*' : ' ',
112 } 126 mp->no, p->dest->no,
113 127 b_sent_sec, kb_sent_percent,
114 if (mp->total_bytes_sent > 0) 128 b_recv_sec, kb_recv_percent);
115 kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent; 129 fprintf (stderr,
116 if (mp->total_bytes_received > 0) 130 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
117 kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received; 131 (mp->pref_partner == p->dest) ? '*' : ' ',
118 if (1000 * p->messages_sent > 0) 132 mp->no, p->dest->no, rtt);
119 rtt = p->total_app_rtt / (1000 * p->messages_sent);
120 fprintf(stderr,
121 "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
122 (mp->pref_partner == p->dest) ? '*' : ' ',
123 mp->no, p->dest->no,
124 b_sent_sec, kb_sent_percent,
125 b_recv_sec, kb_recv_percent);
126 fprintf(stderr,
127 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
128 (mp->pref_partner == p->dest) ? '*' : ' ',
129 mp->no, p->dest->no, rtt);
130 }
131 } 133 }
134 }
132} 135}
133 136
134 137
135static void 138static void
136do_shutdown(void *cls) 139do_shutdown (void *cls)
137{ 140{
138 fprintf(stderr, "Shutdown\n"); 141 fprintf (stderr, "Shutdown\n");
139 if (NULL != timeout_task) 142 if (NULL != timeout_task)
140 { 143 {
141 GNUNET_SCHEDULER_cancel(timeout_task); 144 GNUNET_SCHEDULER_cancel (timeout_task);
142 timeout_task = NULL; 145 timeout_task = NULL;
143 } 146 }
144 if (NULL != l) 147 if (NULL != l)
145 { 148 {
146 GNUNET_ATS_TEST_logging_stop(l); 149 GNUNET_ATS_TEST_logging_stop (l);
147 GNUNET_ATS_TEST_logging_clean_up(l); 150 GNUNET_ATS_TEST_logging_clean_up (l);
148 l = NULL; 151 l = NULL;
149 } 152 }
150 153
151 /* Stop traffic generation */ 154 /* Stop traffic generation */
152 GNUNET_ATS_TEST_generate_traffic_stop_all(); 155 GNUNET_ATS_TEST_generate_traffic_stop_all ();
153 156
154 /* Stop all preference generations */ 157 /* Stop all preference generations */
155 GNUNET_ATS_TEST_generate_preferences_stop_all(); 158 GNUNET_ATS_TEST_generate_preferences_stop_all ();
156 159
157 if (NULL != e) 160 if (NULL != e)
158 { 161 {
159 GNUNET_ATS_TEST_experimentation_stop(e); 162 GNUNET_ATS_TEST_experimentation_stop (e);
160 e = NULL; 163 e = NULL;
161 } 164 }
162 GNUNET_ATS_TEST_shutdown_topology(); 165 GNUNET_ATS_TEST_shutdown_topology ();
163} 166}
164 167
165 168
166static void 169static void
167do_timeout(void *cls) 170do_timeout (void *cls)
168{ 171{
169 timeout_task = NULL; 172 timeout_task = NULL;
170 GNUNET_SCHEDULER_shutdown(); 173 GNUNET_SCHEDULER_shutdown ();
171} 174}
172 175
173 176
174static void 177static void
175log_request__cb(void *cls, 178log_request__cb (void *cls,
176 const struct GNUNET_HELLO_Address *address, 179 const struct GNUNET_HELLO_Address *address,
177 int address_active, 180 int address_active,
178 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 181 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
179 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 182 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
180 const struct GNUNET_ATS_Properties *ats) 183 const struct GNUNET_ATS_Properties *ats)
181{ 184{
182 if (NULL != l) 185 if (NULL != l)
183 { 186 {
184 //GNUNET_break (0); 187 // GNUNET_break (0);
185 //GNUNET_ATS_TEST_logging_now (l); 188 // GNUNET_ATS_TEST_logging_now (l);
186 } 189 }
187} 190}
188 191
189 192
190static void 193static void
191experiment_done_cb(struct Experiment *e, 194experiment_done_cb (struct Experiment *e,
192 struct GNUNET_TIME_Relative duration, 195 struct GNUNET_TIME_Relative duration,
193 int success) 196 int success)
194{ 197{
195 if (GNUNET_OK == success) 198 if (GNUNET_OK == success)
196 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 199 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
197 "Experiment done successful in %s\n", 200 "Experiment done successful in %s\n",
198 GNUNET_STRINGS_relative_time_to_string(duration, 201 GNUNET_STRINGS_relative_time_to_string (duration,
199 GNUNET_YES)); 202 GNUNET_YES));
200 else 203 else
201 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
202 205
203 /* Stop logging */ 206 /* Stop logging */
204 GNUNET_ATS_TEST_logging_stop(l); 207 GNUNET_ATS_TEST_logging_stop (l);
205 208
206 /* Stop traffic generation */ 209 /* Stop traffic generation */
207 GNUNET_ATS_TEST_generate_traffic_stop_all(); 210 GNUNET_ATS_TEST_generate_traffic_stop_all ();
208 211
209 /* Stop all preference generations */ 212 /* Stop all preference generations */
210 GNUNET_ATS_TEST_generate_preferences_stop_all(); 213 GNUNET_ATS_TEST_generate_preferences_stop_all ();
211 214
212 evaluate(duration); 215 evaluate (duration);
213 if (opt_log) 216 if (opt_log)
214 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); 217 GNUNET_ATS_TEST_logging_write_to_file (l, opt_exp_file, opt_plot);
215 GNUNET_SCHEDULER_shutdown(); 218 GNUNET_SCHEDULER_shutdown ();
216} 219}
217 220
218 221
219static void 222static void
220episode_done_cb(struct Episode *ep) 223episode_done_cb (struct Episode *ep)
221{ 224{
222 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 225 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
223 "Episode %u done\n", 226 "Episode %u done\n",
224 ep->id); 227 ep->id);
225} 228}
226 229
227 230
228static void 231static void
229topology_setup_done(void *cls, 232topology_setup_done (void *cls,
230 struct BenchmarkPeer *masters, 233 struct BenchmarkPeer *masters,
231 struct BenchmarkPeer *slaves) 234 struct BenchmarkPeer *slaves)
232{ 235{
233 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 236 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
234 "Topology setup complete!\n"); 237 "Topology setup complete!\n");
235 238
236 masters_p = masters; 239 masters_p = masters;
237 slaves_p = slaves; 240 slaves_p = slaves;
238 241
239 l = GNUNET_ATS_TEST_logging_start(e->log_freq, 242 l = GNUNET_ATS_TEST_logging_start (e->log_freq,
240 e->name, 243 e->name,
241 masters_p, 244 masters_p,
242 e->num_masters, e->num_slaves, 245 e->num_masters, e->num_slaves,
243 opt_verbose); 246 opt_verbose);
244 GNUNET_ATS_TEST_experimentation_run(e, 247 GNUNET_ATS_TEST_experimentation_run (e,
245 &episode_done_cb, 248 &episode_done_cb,
246 &experiment_done_cb); 249 &experiment_done_cb);
247/* 250/*
248 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0], 251 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
249 GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS, 252 GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
@@ -275,58 +278,59 @@ topology_setup_done(void *cls,
275 int c_m; 278 int c_m;
276 int c_s; 279 int c_s;
277 for (c_m = 0; c_m < e->num_masters; c_m++) 280 for (c_m = 0; c_m < e->num_masters; c_m++)
281 {
282 for (c_s = 0; c_s < e->num_slaves; c_s++)
278 { 283 {
279 for (c_s = 0; c_s < e->num_slaves; c_s++) 284 /* Generate maximum traffic to all peers */
280 { 285 /* Example: Generate traffic with constant 10,000 Bytes/s */
281 /* Generate maximum traffic to all peers */ 286 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
282 /* Example: Generate traffic with constant 10,000 Bytes/s */ 287 &masters[c_m].partners[c_s],
283 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 288 GNUNET_ATS_TEST_TG_CONSTANT,
284 &masters[c_m].partners[c_s], 289 10000,
285 GNUNET_ATS_TEST_TG_CONSTANT, 290 GNUNET_TIME_UNIT_FOREVER_REL);
286 10000, 291 /* Example: Generate traffic with an increasing rate from 1000 to 2000
287 GNUNET_TIME_UNIT_FOREVER_REL); 292 * Bytes/s with in a minute */
288 /* Example: Generate traffic with an increasing rate from 1000 to 2000 293 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
289 * Bytes/s with in a minute */ 294 &masters[c_m].partners[c_s],
290 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 295 GNUNET_ATS_TEST_TG_LINEAR,
291 &masters[c_m].partners[c_s], 296 1000,
292 GNUNET_ATS_TEST_TG_LINEAR, 297 2000,
293 1000, 298 GNUNET_TIME_UNIT_MINUTES,
294 2000, 299 GNUNET_TIME_UNIT_FOREVER_REL);
295 GNUNET_TIME_UNIT_MINUTES, 300 /* Example: Generate traffic with a random rate between 1000 to 2000
296 GNUNET_TIME_UNIT_FOREVER_REL); 301 * Bytes/s */
297 /* Example: Generate traffic with a random rate between 1000 to 2000 302 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
298 * Bytes/s */ 303 &masters[c_m].partners[c_s],
299 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 304 GNUNET_ATS_TEST_TG_RANDOM,
300 &masters[c_m].partners[c_s], 305 1000,
301 GNUNET_ATS_TEST_TG_RANDOM, 306 2000,
302 1000, 307 GNUNET_TIME_UNIT_FOREVER_REL,
303 2000, 308 GNUNET_TIME_UNIT_FOREVER_REL);
304 GNUNET_TIME_UNIT_FOREVER_REL, 309 /* Example: Generate traffic with a sinus form, a base rate of
305 GNUNET_TIME_UNIT_FOREVER_REL); 310 * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
306 /* Example: Generate traffic with a sinus form, a base rate of 311 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
307 * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */ 312 &masters[c_m].partners[c_s],
308 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 313 GNUNET_ATS_TEST_TG_SINUS,
309 &masters[c_m].partners[c_s], 314 1000,
310 GNUNET_ATS_TEST_TG_SINUS, 315 2000,
311 1000, 316 GNUNET_TIME_UNIT_MINUTES,
312 2000, 317 GNUNET_TIME_UNIT_FOREVER_REL);
313 GNUNET_TIME_UNIT_MINUTES,
314 GNUNET_TIME_UNIT_FOREVER_REL);
315 }
316 } 318 }
319 }
317#endif 320#endif
318 321
319 timeout_task 322 timeout_task
320 = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_add(GNUNET_TIME_UNIT_MINUTES, 323 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (
321 e->max_duration), 324 GNUNET_TIME_UNIT_MINUTES,
322 &do_timeout, 325 e->max_duration),
323 NULL); 326 &do_timeout,
324 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 327 NULL);
328 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
325} 329}
326 330
327 331
328static void 332static void
329parse_args(int argc, char *argv[]) 333parse_args (int argc, char *argv[])
330{ 334{
331 int c; 335 int c;
332 336
@@ -335,62 +339,62 @@ parse_args(int argc, char *argv[])
335 opt_plot = GNUNET_NO; 339 opt_plot = GNUNET_NO;
336 340
337 for (c = 0; c < argc; c++) 341 for (c = 0; c < argc; c++)
342 {
343 if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e")))
344 {
345 GNUNET_free_non_null (opt_exp_file);
346 opt_exp_file = GNUNET_strdup (argv[c + 1]);
347 }
348 if (0 == strcmp (argv[c], "-l"))
338 { 349 {
339 if ((c < (argc - 1)) && (0 == strcmp(argv[c], "-e"))) 350 opt_log = GNUNET_YES;
340 {
341 GNUNET_free_non_null(opt_exp_file);
342 opt_exp_file = GNUNET_strdup(argv[c + 1]);
343 }
344 if (0 == strcmp(argv[c], "-l"))
345 {
346 opt_log = GNUNET_YES;
347 }
348 if (0 == strcmp(argv[c], "-p"))
349 {
350 opt_plot = GNUNET_YES;
351 }
352 if (0 == strcmp(argv[c], "-v"))
353 {
354 opt_verbose = GNUNET_YES;
355 }
356 } 351 }
352 if (0 == strcmp (argv[c], "-p"))
353 {
354 opt_plot = GNUNET_YES;
355 }
356 if (0 == strcmp (argv[c], "-v"))
357 {
358 opt_verbose = GNUNET_YES;
359 }
360 }
357} 361}
358 362
359 363
360int 364int
361main(int argc, char *argv[]) 365main (int argc, char *argv[])
362{ 366{
363 GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL); 367 GNUNET_log_setup ("gnunet-ats-sim", "INFO", NULL);
364 368
365 parse_args(argc, argv); 369 parse_args (argc, argv);
366 if (NULL == opt_exp_file) 370 if (NULL == opt_exp_file)
367 { 371 {
368 fprintf(stderr, "No experiment given...\n"); 372 fprintf (stderr, "No experiment given...\n");
369 return 1; 373 return 1;
370 } 374 }
371 375
372 fprintf(stderr, "Loading experiment `%s' \n", opt_exp_file); 376 fprintf (stderr, "Loading experiment `%s' \n", opt_exp_file);
373 e = GNUNET_ATS_TEST_experimentation_load(opt_exp_file); 377 e = GNUNET_ATS_TEST_experimentation_load (opt_exp_file);
374 if (NULL == e) 378 if (NULL == e)
375 { 379 {
376 fprintf(stderr, "Invalid experiment\n"); 380 fprintf (stderr, "Invalid experiment\n");
377 return 1; 381 return 1;
378 } 382 }
379 if (0 == e->num_episodes) 383 if (0 == e->num_episodes)
380 { 384 {
381 fprintf(stderr, "No episodes included\n"); 385 fprintf (stderr, "No episodes included\n");
382 return 1; 386 return 1;
383 } 387 }
384 388
385 /* Setup a topology with */ 389 /* Setup a topology with */
386 GNUNET_ATS_TEST_create_topology("gnunet-ats-sim", e->cfg_file, 390 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
387 e->num_slaves, 391 e->num_slaves,
388 e->num_masters, 392 e->num_masters,
389 GNUNET_NO, 393 GNUNET_NO,
390 &topology_setup_done, 394 &topology_setup_done,
391 NULL, 395 NULL,
392 &log_request__cb); 396 &log_request__cb);
393 GNUNET_free(opt_exp_file); 397 GNUNET_free (opt_exp_file);
394 return 0; 398 return 0;
395} 399}
396/* end of file gnunet-ats-sim.c */ 400/* end of file gnunet-ats-sim.c */
diff --git a/src/ats-tests/gnunet-solver-eval.c b/src/ats-tests/gnunet-solver-eval.c
index b5e00bd6f..bc6a3c435 100644
--- a/src/ats-tests/gnunet-solver-eval.c
+++ b/src/ats-tests/gnunet-solver-eval.c
@@ -34,35 +34,35 @@
34 * Experiments 34 * Experiments
35 */ 35 */
36const char * 36const char *
37print_op(enum OperationType op) 37print_op (enum OperationType op)
38{ 38{
39 switch (op) 39 switch (op)
40 { 40 {
41 case START_SEND: 41 case START_SEND:
42 return "START_SEND"; 42 return "START_SEND";
43 43
44 case STOP_SEND: 44 case STOP_SEND:
45 return "STOP_SEND"; 45 return "STOP_SEND";
46 46
47 case START_PREFERENCE: 47 case START_PREFERENCE:
48 return "START_PREFERENCE"; 48 return "START_PREFERENCE";
49 49
50 case STOP_PREFERENCE: 50 case STOP_PREFERENCE:
51 return "STOP_PREFERENCE"; 51 return "STOP_PREFERENCE";
52 52
53 default: 53 default:
54 break; 54 break;
55 } 55 }
56 return ""; 56 return "";
57} 57}
58 58
59 59
60static struct Experiment * 60static struct Experiment *
61create_experiment() 61create_experiment ()
62{ 62{
63 struct Experiment *e; 63 struct Experiment *e;
64 64
65 e = GNUNET_new(struct Experiment); 65 e = GNUNET_new (struct Experiment);
66 e->name = NULL; 66 e->name = NULL;
67 e->num_masters = 0; 67 e->num_masters = 0;
68 e->num_slaves = 0; 68 e->num_slaves = 0;
@@ -73,7 +73,7 @@ create_experiment()
73 73
74 74
75static void 75static void
76free_experiment(struct Experiment *e) 76free_experiment (struct Experiment *e)
77{ 77{
78 struct Episode *cur; 78 struct Episode *cur;
79 struct Episode *next; 79 struct Episode *next;
@@ -82,28 +82,28 @@ free_experiment(struct Experiment *e)
82 82
83 next = e->start; 83 next = e->start;
84 for (cur = next; NULL != cur; cur = next) 84 for (cur = next; NULL != cur; cur = next)
85 { 85 {
86 next = cur->next; 86 next = cur->next;
87 87
88 next_o = cur->head; 88 next_o = cur->head;
89 for (cur_o = next_o; NULL != cur_o; cur_o = next_o) 89 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
90 { 90 {
91 next_o = cur_o->next; 91 next_o = cur_o->next;
92 GNUNET_free(cur_o); 92 GNUNET_free (cur_o);
93 }
94 GNUNET_free(cur);
95 } 93 }
94 GNUNET_free (cur);
95 }
96 96
97 GNUNET_free_non_null(e->name); 97 GNUNET_free_non_null (e->name);
98 GNUNET_free_non_null(e->cfg_file); 98 GNUNET_free_non_null (e->cfg_file);
99 GNUNET_free(e); 99 GNUNET_free (e);
100} 100}
101 101
102 102
103static int 103static int
104load_episode(struct Experiment *e, 104load_episode (struct Experiment *e,
105 struct Episode *cur, 105 struct Episode *cur,
106 struct GNUNET_CONFIGURATION_Handle *cfg) 106 struct GNUNET_CONFIGURATION_Handle *cfg)
107{ 107{
108 struct GNUNET_ATS_TEST_Operation *o; 108 struct GNUNET_ATS_TEST_Operation *o;
109 char *sec_name; 109 char *sec_name;
@@ -113,284 +113,303 @@ load_episode(struct Experiment *e,
113 char *pref; 113 char *pref;
114 int op_counter = 0; 114 int op_counter = 0;
115 115
116 fprintf(stderr, "Parsing episode %u\n", cur->id); 116 fprintf (stderr, "Parsing episode %u\n", cur->id);
117 GNUNET_asprintf(&sec_name, "episode-%u", cur->id); 117 GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
118 118
119 while (1) 119 while (1)
120 {
121 /* Load operation */
122 GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
123 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
124 sec_name,
125 op_name, &op))
120 { 126 {
121 /* Load operation */ 127 GNUNET_free (op_name);
122 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); 128 break;
123 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 129 }
124 sec_name, op_name, &op)) 130 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
125 { 131 /* operations = set_rate, start_send, stop_send, set_preference */
126 GNUNET_free(op_name); 132 if (0 == strcmp (op, "start_send"))
127 break; 133 {
128 } 134 o->type = START_SEND;
129 o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); 135 }
130 /* operations = set_rate, start_send, stop_send, set_preference */ 136 else if (0 == strcmp (op, "stop_send"))
131 if (0 == strcmp(op, "start_send")) 137 {
132 { 138 o->type = STOP_SEND;
133 o->type = START_SEND; 139 }
134 } 140 else if (0 == strcmp (op, "start_preference"))
135 else if (0 == strcmp(op, "stop_send")) 141 {
136 { 142 o->type = START_PREFERENCE;
137 o->type = STOP_SEND; 143 }
138 } 144 else if (0 == strcmp (op, "stop_preference"))
139 else if (0 == strcmp(op, "start_preference")) 145 {
140 { 146 o->type = STOP_PREFERENCE;
141 o->type = START_PREFERENCE; 147 }
142 } 148 else
143 else if (0 == strcmp(op, "stop_preference")) 149 {
144 { 150 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
145 o->type = STOP_PREFERENCE; 151 op_counter, op, cur->id);
146 } 152 GNUNET_free (op);
153 GNUNET_free (op_name);
154 GNUNET_free (sec_name);
155 GNUNET_free (o);
156 return GNUNET_SYSERR;
157 }
158 GNUNET_free (op_name);
159
160 /* Get source */
161 GNUNET_asprintf (&op_name, "op-%u-src", op_counter);
162 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
163 sec_name,
164 op_name,
165 &o->src_id))
166 {
167 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
168 op_counter, op, cur->id);
169 GNUNET_free (op);
170 GNUNET_free (op_name);
171 GNUNET_free (sec_name);
172 GNUNET_free (o);
173 return GNUNET_SYSERR;
174 }
175 if (o->src_id > (e->num_masters - 1))
176 {
177 fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
178 o->src_id, op_counter, op, cur->id);
179 GNUNET_free (op);
180 GNUNET_free (op_name);
181 GNUNET_free (sec_name);
182 GNUNET_free (o);
183 return GNUNET_SYSERR;
184 }
185 GNUNET_free (op_name);
186
187 /* Get destination */
188 GNUNET_asprintf (&op_name, "op-%u-dest", op_counter);
189 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
190 sec_name,
191 op_name,
192 &o->dest_id))
193 {
194 fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
195 op_counter, op, cur->id);
196 GNUNET_free (op);
197 GNUNET_free (op_name);
198 GNUNET_free (sec_name);
199 GNUNET_free (o);
200 return GNUNET_SYSERR;
201 }
202 if (o->dest_id > (e->num_slaves - 1))
203 {
204 fprintf (stderr,
205 "Invalid destination %llu in operation %u `%s' in episode %u\n",
206 o->dest_id,
207 op_counter,
208 op,
209 cur->id);
210 GNUNET_free (op);
211 GNUNET_free (op_name);
212 GNUNET_free (sec_name);
213 GNUNET_free (o);
214 return GNUNET_SYSERR;
215 }
216 GNUNET_free (op_name);
217
218 GNUNET_asprintf (&op_name, "op-%u-type", op_counter);
219 if ((GNUNET_SYSERR !=
220 GNUNET_CONFIGURATION_get_value_string (cfg,
221 sec_name,
222 op_name,
223 &type)) &&
224 (STOP_SEND != o->type) &&
225 (STOP_PREFERENCE != o->type))
226 {
227 /* Load arguments for set_rate, start_send, set_preference */
228 if (0 == strcmp (type, "constant"))
229 {
230 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
231 }
232 else if (0 == strcmp (type, "linear"))
233 {
234 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
235 }
236 else if (0 == strcmp (type, "sinus"))
237 {
238 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
239 }
240 else if (0 == strcmp (type, "random"))
241 {
242 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
243 }
147 else 244 else
245 {
246 fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
247 op_counter, op, cur->id);
248 GNUNET_free (type);
249 GNUNET_free (op);
250 GNUNET_free (op_name);
251 GNUNET_free (sec_name);
252 GNUNET_free (o);
253 return GNUNET_SYSERR;
254 }
255 GNUNET_free (op_name);
256
257 /* Get base rate */
258 GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
259 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
260 sec_name,
261 op_name,
262 &o->base_rate))
263 {
264 fprintf (stderr,
265 "Missing base rate in operation %u `%s' in episode %u\n",
266 op_counter, op, cur->id);
267 GNUNET_free (type);
268 GNUNET_free (op);
269 GNUNET_free (op_name);
270 GNUNET_free (sec_name);
271 GNUNET_free (o);
272 return GNUNET_SYSERR;
273 }
274 GNUNET_free (op_name);
275
276 /* Get max rate */
277 GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
278 if (GNUNET_SYSERR ==
279 GNUNET_CONFIGURATION_get_value_number (cfg,
280 sec_name,
281 op_name,
282 &o->max_rate))
283 {
284 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
285 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
286 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
148 { 287 {
149 fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", 288 fprintf (stderr,
150 op_counter, op, cur->id); 289 "Missing max rate in operation %u `%s' in episode %u\n",
151 GNUNET_free(op); 290 op_counter, op, cur->id);
152 GNUNET_free(op_name); 291 GNUNET_free (type);
153 GNUNET_free(sec_name); 292 GNUNET_free (op_name);
154 GNUNET_free(o); 293 GNUNET_free (op);
294 GNUNET_free (sec_name);
295 GNUNET_free (o);
155 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
156 } 297 }
157 GNUNET_free(op_name); 298 }
158 299 GNUNET_free (op_name);
159 /* Get source */ 300
160 GNUNET_asprintf(&op_name, "op-%u-src", op_counter); 301 /* Get period */
161 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 302 GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
162 sec_name, op_name, &o->src_id)) 303 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
304 sec_name,
305 op_name,
306 &o->period))
307 {
308 o->period = cur->duration;
309 }
310 GNUNET_free (op_name);
311
312 if (START_PREFERENCE == o->type)
313 {
314 /* Get frequency */
315 GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
316 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
317 sec_name,
318 op_name,
319 &o->frequency))
163 { 320 {
164 fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", 321 fprintf (stderr,
165 op_counter, op, cur->id); 322 "Missing frequency in operation %u `%s' in episode %u\n",
166 GNUNET_free(op); 323 op_counter, op, cur->id);
167 GNUNET_free(op_name); 324 GNUNET_free (type);
168 GNUNET_free(sec_name); 325 GNUNET_free (op_name);
169 GNUNET_free(o); 326 GNUNET_free (op);
327 GNUNET_free (sec_name);
328 GNUNET_free (o);
170 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
171 } 330 }
172 if (o->src_id > (e->num_masters - 1)) 331 GNUNET_free (op_name);
332
333 /* Get preference */
334 GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
335 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
336 sec_name,
337 op_name,
338 &pref))
173 { 339 {
174 fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", 340 fprintf (stderr,
175 o->src_id, op_counter, op, cur->id); 341 "Missing preference in operation %u `%s' in episode %u\n",
176 GNUNET_free(op); 342 op_counter, op, cur->id);
177 GNUNET_free(op_name); 343 GNUNET_free (type);
178 GNUNET_free(sec_name); 344 GNUNET_free (op_name);
179 GNUNET_free(o); 345 GNUNET_free (op);
346 GNUNET_free (sec_name);
347 GNUNET_free_non_null (pref);
348 GNUNET_free (o);
180 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
181 } 350 }
182 GNUNET_free(op_name);
183 351
184 /* Get destination */ 352 if (0 == strcmp (pref, "bandwidth"))
185 GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); 353 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
186 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 354 else if (0 == strcmp (pref, "latency"))
187 sec_name, op_name, &o->dest_id)) 355 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
356 else
188 { 357 {
189 fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", 358 fprintf (stderr,
190 op_counter, op, cur->id); 359 "Invalid preference in operation %u `%s' in episode %u\n",
191 GNUNET_free(op); 360 op_counter,
192 GNUNET_free(op_name); 361 op,
193 GNUNET_free(sec_name); 362 cur->id);
194 GNUNET_free(o); 363 GNUNET_free (type);
364 GNUNET_free (op_name);
365 GNUNET_free (op);
366 GNUNET_free (sec_name);
367 GNUNET_free_non_null (pref);
368 GNUNET_free (o);
195 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
196 } 370 }
197 if (o->dest_id > (e->num_slaves - 1)) 371 GNUNET_free (pref);
198 { 372 GNUNET_free (op_name);
199 fprintf(stderr, 373 }
200 "Invalid destination %llu in operation %u `%s' in episode %u\n", 374 }
201 o->dest_id,
202 op_counter,
203 op,
204 cur->id);
205 GNUNET_free(op);
206 GNUNET_free(op_name);
207 GNUNET_free(sec_name);
208 GNUNET_free(o);
209 return GNUNET_SYSERR;
210 }
211 GNUNET_free(op_name);
212
213 GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
214 if ((GNUNET_SYSERR !=
215 GNUNET_CONFIGURATION_get_value_string(cfg,
216 sec_name,
217 op_name,
218 &type)) &&
219 (STOP_SEND != o->type) &&
220 (STOP_PREFERENCE != o->type))
221 {
222 /* Load arguments for set_rate, start_send, set_preference */
223 if (0 == strcmp(type, "constant"))
224 {
225 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
226 }
227 else if (0 == strcmp(type, "linear"))
228 {
229 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
230 }
231 else if (0 == strcmp(type, "sinus"))
232 {
233 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
234 }
235 else if (0 == strcmp(type, "random"))
236 {
237 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
238 }
239 else
240 {
241 fprintf(stderr, "Invalid type %u `%s' in episode %u\n",
242 op_counter, op, cur->id);
243 GNUNET_free(type);
244 GNUNET_free(op);
245 GNUNET_free(op_name);
246 GNUNET_free(sec_name);
247 GNUNET_free(o);
248 return GNUNET_SYSERR;
249 }
250 GNUNET_free(op_name);
251
252 /* Get base rate */
253 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
254 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg,
255 sec_name, op_name, &o->base_rate))
256 {
257 fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n",
258 op_counter, op, cur->id);
259 GNUNET_free(type);
260 GNUNET_free(op);
261 GNUNET_free(op_name);
262 GNUNET_free(sec_name);
263 GNUNET_free(o);
264 return GNUNET_SYSERR;
265 }
266 GNUNET_free(op_name);
267
268 /* Get max rate */
269 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
270 if (GNUNET_SYSERR ==
271 GNUNET_CONFIGURATION_get_value_number(cfg,
272 sec_name,
273 op_name,
274 &o->max_rate))
275 {
276 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
277 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
278 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
279 {
280 fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n",
281 op_counter, op, cur->id);
282 GNUNET_free(type);
283 GNUNET_free(op_name);
284 GNUNET_free(op);
285 GNUNET_free(sec_name);
286 GNUNET_free(o);
287 return GNUNET_SYSERR;
288 }
289 }
290 GNUNET_free(op_name);
291
292 /* Get period */
293 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
294 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
295 sec_name, op_name, &o->period))
296 {
297 o->period = cur->duration;
298 }
299 GNUNET_free(op_name);
300
301 if (START_PREFERENCE == o->type)
302 {
303 /* Get frequency */
304 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
305 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
306 sec_name, op_name, &o->frequency))
307 {
308 fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n",
309 op_counter, op, cur->id);
310 GNUNET_free(type);
311 GNUNET_free(op_name);
312 GNUNET_free(op);
313 GNUNET_free(sec_name);
314 GNUNET_free(o);
315 return GNUNET_SYSERR;
316 }
317 GNUNET_free(op_name);
318
319 /* Get preference */
320 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
321 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
322 sec_name, op_name, &pref))
323 {
324 fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n",
325 op_counter, op, cur->id);
326 GNUNET_free(type);
327 GNUNET_free(op_name);
328 GNUNET_free(op);
329 GNUNET_free(sec_name);
330 GNUNET_free_non_null(pref);
331 GNUNET_free(o);
332 return GNUNET_SYSERR;
333 }
334
335 if (0 == strcmp(pref, "bandwidth"))
336 o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
337 else if (0 == strcmp(pref, "latency"))
338 o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
339 else
340 {
341 fprintf(stderr,
342 "Invalid preference in operation %u `%s' in episode %u\n",
343 op_counter,
344 op,
345 cur->id);
346 GNUNET_free(type);
347 GNUNET_free(op_name);
348 GNUNET_free(op);
349 GNUNET_free(sec_name);
350 GNUNET_free_non_null(pref);
351 GNUNET_free(o);
352 return GNUNET_SYSERR;
353 }
354 GNUNET_free(pref);
355 GNUNET_free(op_name);
356 }
357 }
358
359 /* Safety checks */
360 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
361 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
362 {
363 if ((o->max_rate - o->base_rate) > o->base_rate)
364 {
365 /* This will cause an underflow */
366 GNUNET_break(0);
367 }
368 fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
369 }
370
371 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
372 fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
373 op_counter, cur->id, print_op(o->type), o->src_id,
374 o->dest_id, (NULL != type) ? type : "",
375 o->base_rate, o->max_rate,
376 GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES));
377 else
378 fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
379 op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id);
380
381 GNUNET_free_non_null(type);
382 GNUNET_free(op);
383 375
384 GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o); 376 /* Safety checks */
385 op_counter++; 377 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
378 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
379 {
380 if ((o->max_rate - o->base_rate) > o->base_rate)
381 {
382 /* This will cause an underflow */
383 GNUNET_break (0);
384 }
385 fprintf (stderr,
386 "Selected max rate and base rate cannot be used for desired traffic form!\n");
386 } 387 }
387 GNUNET_free(sec_name); 388
389 if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
390 fprintf (stderr,
391 "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
392 op_counter, cur->id, print_op (o->type), o->src_id,
393 o->dest_id, (NULL != type) ? type : "",
394 o->base_rate, o->max_rate,
395 GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
396 else
397 fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
398 op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
399
400 GNUNET_free_non_null (type);
401 GNUNET_free (op);
402
403 GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o);
404 op_counter++;
405 }
406 GNUNET_free (sec_name);
388 407
389 return GNUNET_OK; 408 return GNUNET_OK;
390} 409}
391 410
392static int 411static int
393load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) 412load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
394{ 413{
395 int e_counter = 0; 414 int e_counter = 0;
396 char *sec_name; 415 char *sec_name;
@@ -401,68 +420,72 @@ load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
401 e_counter = 0; 420 e_counter = 0;
402 last = NULL; 421 last = NULL;
403 while (1) 422 while (1)
423 {
424 GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
425 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
426 sec_name,
427 "duration",
428 &e_duration))
404 { 429 {
405 GNUNET_asprintf(&sec_name, "episode-%u", e_counter); 430 GNUNET_free (sec_name);
406 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 431 break;
407 sec_name, "duration", &e_duration)) 432 }
408 {
409 GNUNET_free(sec_name);
410 break;
411 }
412
413 cur = GNUNET_new(struct Episode);
414 cur->duration = e_duration;
415 cur->id = e_counter;
416
417 if (GNUNET_OK != load_episode(e, cur, cfg))
418 {
419 GNUNET_free(sec_name);
420 GNUNET_free(cur);
421 return GNUNET_SYSERR;
422 }
423
424 fprintf(stderr, "Found episode %u with duration %s \n",
425 e_counter,
426 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
427 433
428 /* Update experiment */ 434 cur = GNUNET_new (struct Episode);
429 e->num_episodes++; 435 cur->duration = e_duration;
430 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); 436 cur->id = e_counter;
431 /* Put in linked list */
432 if (NULL == last)
433 e->start = cur;
434 else
435 last->next = cur;
436 437
437 GNUNET_free(sec_name); 438 if (GNUNET_OK != load_episode (e, cur, cfg))
438 e_counter++; 439 {
439 last = cur; 440 GNUNET_free (sec_name);
441 GNUNET_free (cur);
442 return GNUNET_SYSERR;
440 } 443 }
444
445 fprintf (stderr, "Found episode %u with duration %s \n",
446 e_counter,
447 GNUNET_STRINGS_relative_time_to_string (cur->duration,
448 GNUNET_YES));
449
450 /* Update experiment */
451 e->num_episodes++;
452 e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
453 cur->duration);
454 /* Put in linked list */
455 if (NULL == last)
456 e->start = cur;
457 else
458 last->next = cur;
459
460 GNUNET_free (sec_name);
461 e_counter++;
462 last = cur;
463 }
441 return e_counter; 464 return e_counter;
442} 465}
443 466
444 467
445static void 468static void
446timeout_experiment(void *cls) 469timeout_experiment (void *cls)
447{ 470{
448 struct Experiment *e = cls; 471 struct Experiment *e = cls;
449 472
450 e->experiment_timeout_task = NULL; 473 e->experiment_timeout_task = NULL;
451 fprintf(stderr, "Experiment timeout!\n"); 474 fprintf (stderr, "Experiment timeout!\n");
452 475
453 if (NULL != e->episode_timeout_task) 476 if (NULL != e->episode_timeout_task)
454 { 477 {
455 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 478 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
456 e->episode_timeout_task = NULL; 479 e->episode_timeout_task = NULL;
457 } 480 }
458 481
459 e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), 482 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
460 GNUNET_SYSERR); 483 GNUNET_SYSERR);
461} 484}
462 485
463 486
464static void 487static void
465enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) 488enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
466{ 489{
467 /* 490 /*
468 struct BenchmarkPeer *peer; 491 struct BenchmarkPeer *peer;
@@ -498,7 +521,7 @@ enforce_start_send(struct GNUNET_ATS_TEST_Operation *op)
498} 521}
499 522
500static void 523static void
501enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) 524enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
502{ 525{
503 /* 526 /*
504 struct BenchmarkPartner *p; 527 struct BenchmarkPartner *p;
@@ -523,7 +546,7 @@ enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op)
523 546
524 547
525static void 548static void
526enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) 549enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
527{ 550{
528 /* 551 /*
529 struct BenchmarkPeer *peer; 552 struct BenchmarkPeer *peer;
@@ -560,7 +583,7 @@ enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op)
560} 583}
561 584
562static void 585static void
563enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) 586enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
564{ 587{
565 /* 588 /*
566 struct BenchmarkPartner *p; 589 struct BenchmarkPartner *p;
@@ -583,264 +606,281 @@ enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op)
583 */ 606 */
584} 607}
585 608
586static void enforce_episode(struct Episode *ep) 609static void enforce_episode (struct Episode *ep)
587{ 610{
588 struct GNUNET_ATS_TEST_Operation *cur; 611 struct GNUNET_ATS_TEST_Operation *cur;
589 612
590 for (cur = ep->head; NULL != cur; cur = cur->next) 613 for (cur = ep->head; NULL != cur; cur = cur->next)
614 {
615 fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
616 print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
617 switch (cur->type)
591 { 618 {
592 fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", 619 case START_SEND:
593 print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate); 620 enforce_start_send (cur);
594 switch (cur->type) 621 break;
595 {
596 case START_SEND:
597 enforce_start_send(cur);
598 break;
599 622
600 case STOP_SEND: 623 case STOP_SEND:
601 enforce_stop_send(cur); 624 enforce_stop_send (cur);
602 break; 625 break;
603 626
604 case START_PREFERENCE: 627 case START_PREFERENCE:
605 enforce_start_preference(cur); 628 enforce_start_preference (cur);
606 break; 629 break;
607 630
608 case STOP_PREFERENCE: 631 case STOP_PREFERENCE:
609 enforce_stop_preference(cur); 632 enforce_stop_preference (cur);
610 break; 633 break;
611 634
612 default: 635 default:
613 break; 636 break;
614 }
615 } 637 }
638 }
616} 639}
617 640
618 641
619static void 642static void
620timeout_episode(void *cls) 643timeout_episode (void *cls)
621{ 644{
622 struct Experiment *e = cls; 645 struct Experiment *e = cls;
623 646
624 e->episode_timeout_task = NULL; 647 e->episode_timeout_task = NULL;
625 if (NULL != e->ep_done_cb) 648 if (NULL != e->ep_done_cb)
626 e->ep_done_cb(e->cur); 649 e->ep_done_cb (e->cur);
627 650
628 /* Scheduling next */ 651 /* Scheduling next */
629 e->cur = e->cur->next; 652 e->cur = e->cur->next;
630 if (NULL == e->cur) 653 if (NULL == e->cur)
654 {
655 /* done */
656 fprintf (stderr, "Last episode done!\n");
657 if (NULL != e->experiment_timeout_task)
631 { 658 {
632 /* done */ 659 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
633 fprintf(stderr, "Last episode done!\n"); 660 e->experiment_timeout_task = NULL;
634 if (NULL != e->experiment_timeout_task)
635 {
636 GNUNET_SCHEDULER_cancel(e->experiment_timeout_task);
637 e->experiment_timeout_task = NULL;
638 }
639 e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
640 return;
641 } 661 }
642 662 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
643 fprintf(stderr, "Running episode %u with timeout %s\n", 663 GNUNET_OK);
644 e->cur->id, 664 return;
645 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 665 }
646 enforce_episode(e->cur); 666
647 667 fprintf (stderr, "Running episode %u with timeout %s\n",
648 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 668 e->cur->id,
649 &timeout_episode, e); 669 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
670 GNUNET_YES));
671 enforce_episode (e->cur);
672
673 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
674 &timeout_episode, e);
650} 675}
651 676
652 677
653void 678void
654GNUNET_ATS_solvers_experimentation_run(struct Experiment *e, 679GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
655 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, 680 GNUNET_ATS_TESTING_EpisodeDoneCallback
656 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) 681 ep_done_cb,
682 GNUNET_ATS_TESTING_ExperimentDoneCallback
683 e_done_cb)
657{ 684{
658 fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, 685 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
659 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 686 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
687 GNUNET_YES));
660 e->e_done_cb = e_done_cb; 688 e->e_done_cb = e_done_cb;
661 e->ep_done_cb = ep_done_cb; 689 e->ep_done_cb = ep_done_cb;
662 e->start_time = GNUNET_TIME_absolute_get(); 690 e->start_time = GNUNET_TIME_absolute_get ();
663 691
664 /* Start total time out */ 692 /* Start total time out */
665 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, 693 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
666 &timeout_experiment, e); 694 &timeout_experiment,
695 e);
667 696
668 /* Start */ 697 /* Start */
669 e->cur = e->start; 698 e->cur = e->start;
670 fprintf(stderr, "Running episode %u with timeout %s\n", 699 fprintf (stderr, "Running episode %u with timeout %s\n",
671 e->cur->id, 700 e->cur->id,
672 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 701 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
673 enforce_episode(e->cur); 702 GNUNET_YES));
674 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 703 enforce_episode (e->cur);
675 &timeout_episode, e); 704 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
705 &timeout_episode, e);
676} 706}
677 707
678 708
679struct Experiment * 709struct Experiment *
680GNUNET_ATS_solvers_experimentation_load(char *filename) 710GNUNET_ATS_solvers_experimentation_load (char *filename)
681{ 711{
682 struct Experiment *e; 712 struct Experiment *e;
683 struct GNUNET_CONFIGURATION_Handle *cfg; 713 struct GNUNET_CONFIGURATION_Handle *cfg;
684 714
685 e = NULL; 715 e = NULL;
686 716
687 cfg = GNUNET_CONFIGURATION_create(); 717 cfg = GNUNET_CONFIGURATION_create ();
688 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) 718 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
689 { 719 {
690 fprintf(stderr, "Failed to load `%s'\n", filename); 720 fprintf (stderr, "Failed to load `%s'\n", filename);
691 GNUNET_CONFIGURATION_destroy(cfg); 721 GNUNET_CONFIGURATION_destroy (cfg);
692 return NULL; 722 return NULL;
693 } 723 }
694 724
695 e = create_experiment(); 725 e = create_experiment ();
696 726
697 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", 727 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
698 "name", &e->name)) 728 "name", &e->name))
699 { 729 {
700 fprintf(stderr, "Invalid %s", "name"); 730 fprintf (stderr, "Invalid %s", "name");
701 free_experiment(e); 731 free_experiment (e);
702 return NULL; 732 return NULL;
703 } 733 }
704 else 734 else
705 fprintf(stderr, "Experiment name: `%s'\n", e->name); 735 fprintf (stderr, "Experiment name: `%s'\n", e->name);
706 736
707 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", 737 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
708 "cfg_file", &e->cfg_file)) 738 "experiment",
709 { 739 "cfg_file",
710 fprintf(stderr, "Invalid %s", "cfg_file"); 740 &e->cfg_file))
711 free_experiment(e); 741 {
712 return NULL; 742 fprintf (stderr, "Invalid %s", "cfg_file");
713 } 743 free_experiment (e);
744 return NULL;
745 }
714 else 746 else
715 fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file); 747 fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
716 748
717 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", 749 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
718 "masters", &e->num_masters)) 750 "masters",
719 { 751 &e->num_masters))
720 fprintf(stderr, "Invalid %s", "masters"); 752 {
721 free_experiment(e); 753 fprintf (stderr, "Invalid %s", "masters");
722 return NULL; 754 free_experiment (e);
723 } 755 return NULL;
756 }
724 else 757 else
725 fprintf(stderr, "Experiment masters: `%llu'\n", 758 fprintf (stderr, "Experiment masters: `%llu'\n",
726 e->num_masters); 759 e->num_masters);
727 760
728 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", 761 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
729 "slaves", &e->num_slaves)) 762 "slaves",
730 { 763 &e->num_slaves))
731 fprintf(stderr, "Invalid %s", "slaves"); 764 {
732 free_experiment(e); 765 fprintf (stderr, "Invalid %s", "slaves");
733 return NULL; 766 free_experiment (e);
734 } 767 return NULL;
768 }
735 else 769 else
736 fprintf(stderr, "Experiment slaves: `%llu'\n", 770 fprintf (stderr, "Experiment slaves: `%llu'\n",
737 e->num_slaves); 771 e->num_slaves);
738 772
739 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", 773 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
740 "log_freq", &e->log_freq)) 774 "log_freq",
741 { 775 &e->log_freq))
742 fprintf(stderr, "Invalid %s", "log_freq"); 776 {
743 free_experiment(e); 777 fprintf (stderr, "Invalid %s", "log_freq");
744 return NULL; 778 free_experiment (e);
745 } 779 return NULL;
780 }
746 else 781 else
747 fprintf(stderr, "Experiment logging frequency: `%s'\n", 782 fprintf (stderr, "Experiment logging frequency: `%s'\n",
748 GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); 783 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
749 784
750 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", 785 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
751 "max_duration", &e->max_duration)) 786 "max_duration",
752 { 787 &e->max_duration))
753 fprintf(stderr, "Invalid %s", "max_duration"); 788 {
754 free_experiment(e); 789 fprintf (stderr, "Invalid %s", "max_duration");
755 return NULL; 790 free_experiment (e);
756 } 791 return NULL;
792 }
757 else 793 else
758 fprintf(stderr, "Experiment duration: `%s'\n", 794 fprintf (stderr, "Experiment duration: `%s'\n",
759 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 795 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
796 GNUNET_YES));
760 797
761 load_episodes(e, cfg); 798 load_episodes (e, cfg);
762 fprintf(stderr, "Loaded %u episodes with total duration %s\n", 799 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
763 e->num_episodes, 800 e->num_episodes,
764 GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); 801 GNUNET_STRINGS_relative_time_to_string (e->total_duration,
802 GNUNET_YES));
765 803
766 GNUNET_CONFIGURATION_destroy(cfg); 804 GNUNET_CONFIGURATION_destroy (cfg);
767 return e; 805 return e;
768} 806}
769 807
770void 808void
771GNUNET_ATS_solvers_experimentation_stop(struct Experiment *e) 809GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
772{ 810{
773 if (NULL != e->experiment_timeout_task) 811 if (NULL != e->experiment_timeout_task)
774 { 812 {
775 GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); 813 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
776 e->experiment_timeout_task = NULL; 814 e->experiment_timeout_task = NULL;
777 } 815 }
778 if (NULL != e->episode_timeout_task) 816 if (NULL != e->episode_timeout_task)
779 { 817 {
780 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 818 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
781 e->episode_timeout_task = NULL; 819 e->episode_timeout_task = NULL;
782 } 820 }
783 free_experiment(e); 821 free_experiment (e);
784} 822}
785 823
786/** 824/**
787 * Solver 825 * Solver
788 */ 826 */
789 827
790struct GNUNET_ATS_TESTING_SolverHandle { 828struct GNUNET_ATS_TESTING_SolverHandle
791 char * plugin; 829{
830 char *plugin;
792 struct GNUNET_ATS_PluginEnvironment env; 831 struct GNUNET_ATS_PluginEnvironment env;
793 void *solver; 832 void *solver;
794}; 833};
795 834
796enum GNUNET_ATS_Solvers { 835enum GNUNET_ATS_Solvers
836{
797 GNUNET_ATS_SOLVER_PROPORTIONAL, 837 GNUNET_ATS_SOLVER_PROPORTIONAL,
798 GNUNET_ATS_SOLVER_MLP, 838 GNUNET_ATS_SOLVER_MLP,
799 GNUNET_ATS_SOLVER_RIL, 839 GNUNET_ATS_SOLVER_RIL,
800}; 840};
801 841
802void 842void
803GNUNET_ATS_solvers_solver_stop(struct GNUNET_ATS_TESTING_SolverHandle *sh) 843GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
804{ 844{
805 GNUNET_PLUGIN_unload(sh->plugin, sh->solver); 845 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
806 GNUNET_free(sh->plugin); 846 GNUNET_free (sh->plugin);
807 GNUNET_free(sh); 847 GNUNET_free (sh);
808} 848}
809 849
810struct GNUNET_ATS_TESTING_SolverHandle * 850struct GNUNET_ATS_TESTING_SolverHandle *
811GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type) 851GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
812{ 852{
813 struct GNUNET_ATS_TESTING_SolverHandle *sh; 853 struct GNUNET_ATS_TESTING_SolverHandle *sh;
814 char * solver_str; 854 char *solver_str;
815 855
816 switch (type) 856 switch (type)
817 { 857 {
818 case GNUNET_ATS_SOLVER_PROPORTIONAL: 858 case GNUNET_ATS_SOLVER_PROPORTIONAL:
819 solver_str = "proportional"; 859 solver_str = "proportional";
820 break; 860 break;
821 861
822 case GNUNET_ATS_SOLVER_MLP: 862 case GNUNET_ATS_SOLVER_MLP:
823 solver_str = "mlp"; 863 solver_str = "mlp";
824 break; 864 break;
825 865
826 case GNUNET_ATS_SOLVER_RIL: 866 case GNUNET_ATS_SOLVER_RIL:
827 solver_str = "ril"; 867 solver_str = "ril";
828 break; 868 break;
829 869
830 default: 870 default:
831 GNUNET_break(0); 871 GNUNET_break (0);
832 return NULL; 872 return NULL;
833 break; 873 break;
834 } 874 }
835 875
836 sh = GNUNET_new(struct GNUNET_ATS_TESTING_SolverHandle); 876 sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
837 GNUNET_asprintf(&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); 877 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
838 //sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); 878 // sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
839 if (NULL == sh->solver) 879 if (NULL == sh->solver)
840 { 880 {
841 fprintf(stderr, "Failed to load solver `%s'\n", sh->plugin); 881 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
842 exit(1); 882 exit (1);
843 } 883 }
844 884
845 return sh; 885 return sh;
846} 886}
@@ -872,56 +912,56 @@ static int opt_plot;
872static int opt_verbose; 912static int opt_verbose;
873 913
874static void 914static void
875run(void *cls, char * const *args, const char *cfgfile, 915run (void *cls, char *const *args, const char *cfgfile,
876 const struct GNUNET_CONFIGURATION_Handle *cfg) 916 const struct GNUNET_CONFIGURATION_Handle *cfg)
877{ 917{
878 enum GNUNET_ATS_Solvers solver; 918 enum GNUNET_ATS_Solvers solver;
879 919
880 if (NULL == opt_exp_file) 920 if (NULL == opt_exp_file)
881 { 921 {
882 fprintf(stderr, "No experiment given ...\n"); 922 fprintf (stderr, "No experiment given ...\n");
883 exit(1); 923 exit (1);
884 } 924 }
885 925
886 if (NULL == opt_solver) 926 if (NULL == opt_solver)
887 { 927 {
888 fprintf(stderr, "No solver given ...\n"); 928 fprintf (stderr, "No solver given ...\n");
889 exit(1); 929 exit (1);
890 } 930 }
891 931
892 if (0 == strcmp(opt_solver, "mlp")) 932 if (0 == strcmp (opt_solver, "mlp"))
893 { 933 {
894 solver = GNUNET_ATS_SOLVER_MLP; 934 solver = GNUNET_ATS_SOLVER_MLP;
895 } 935 }
896 else if (0 == strcmp(opt_solver, "proportional")) 936 else if (0 == strcmp (opt_solver, "proportional"))
897 { 937 {
898 solver = GNUNET_ATS_SOLVER_PROPORTIONAL; 938 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
899 } 939 }
900 else if (0 == strcmp(opt_solver, "ril")) 940 else if (0 == strcmp (opt_solver, "ril"))
901 { 941 {
902 solver = GNUNET_ATS_SOLVER_RIL; 942 solver = GNUNET_ATS_SOLVER_RIL;
903 } 943 }
904 else 944 else
905 { 945 {
906 fprintf(stderr, "No solver given ..."); 946 fprintf (stderr, "No solver given ...");
907 return; 947 return;
908 } 948 }
909 949
910 /* load experiment */ 950 /* load experiment */
911 e = GNUNET_ATS_solvers_experimentation_load(opt_exp_file); 951 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
912 if (NULL == e) 952 if (NULL == e)
913 { 953 {
914 fprintf(stderr, "Failed to load experiment ...\n"); 954 fprintf (stderr, "Failed to load experiment ...\n");
915 return; 955 return;
916 } 956 }
917 957
918 /* load solver */ 958 /* load solver */
919 sh = GNUNET_ATS_solvers_solver_start(solver); 959 sh = GNUNET_ATS_solvers_solver_start (solver);
920 if (NULL == sh) 960 if (NULL == sh)
921 { 961 {
922 fprintf(stderr, "Failed to start solver ...\n"); 962 fprintf (stderr, "Failed to start solver ...\n");
923 return; 963 return;
924 } 964 }
925 965
926 /* start logging */ 966 /* start logging */
927 967
@@ -938,40 +978,39 @@ run(void *cls, char * const *args, const char *cfgfile,
938 * @param argv argument values 978 * @param argv argument values
939 */ 979 */
940int 980int
941main(int argc, char *argv[]) 981main (int argc, char *argv[])
942{ 982{
943 opt_exp_file = NULL; 983 opt_exp_file = NULL;
944 opt_solver = NULL; 984 opt_solver = NULL;
945 opt_log = GNUNET_NO; 985 opt_log = GNUNET_NO;
946 opt_plot = GNUNET_NO; 986 opt_plot = GNUNET_NO;
947 987
948 struct GNUNET_GETOPT_CommandLineOption options[] = 988 struct GNUNET_GETOPT_CommandLineOption options[] = {
949 { 989 GNUNET_GETOPT_option_string ('s',
950 GNUNET_GETOPT_option_string('s', 990 "solver",
951 "solver", 991 NULL,
952 NULL, 992 gettext_noop ("solver to use"),
953 gettext_noop("solver to use"), 993 &opt_solver),
954 &opt_solver), 994
955 995 GNUNET_GETOPT_option_string ('e',
956 GNUNET_GETOPT_option_string('e', 996 "experiment",
957 "experiment", 997 NULL,
958 NULL, 998 gettext_noop ("experiment to use"),
959 gettext_noop("experiment to use"), 999 &opt_exp_file),
960 &opt_exp_file), 1000
961 1001 GNUNET_GETOPT_option_flag ('e',
962 GNUNET_GETOPT_option_flag('e', 1002 "experiment",
963 "experiment", 1003 gettext_noop ("experiment to use"),
964 gettext_noop("experiment to use"), 1004 &opt_verbose),
965 &opt_verbose),
966 GNUNET_GETOPT_OPTION_END 1005 GNUNET_GETOPT_OPTION_END
967 }; 1006 };
968 1007
969 if (GNUNET_OK != 1008 if (GNUNET_OK !=
970 GNUNET_PROGRAM_run(argc, 1009 GNUNET_PROGRAM_run (argc,
971 argv, argv[0], 1010 argv, argv[0],
972 NULL, 1011 NULL,
973 options, 1012 options,
974 &run, argv[0])) 1013 &run, argv[0]))
975 return 1; 1014 return 1;
976 1015
977 return 0; 1016 return 0;
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
index c31e8a1c4..470c687fc 100644
--- a/src/ats-tests/perf_ats.c
+++ b/src/ats-tests/perf_ats.c
@@ -31,15 +31,20 @@
31#include "ats-testing.h" 31#include "ats-testing.h"
32 32
33 33
34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \
35 GNUNET_TIME_UNIT_SECONDS, 1)
35#define TEST_ATS_PREFRENCE_START 1.0 36#define TEST_ATS_PREFRENCE_START 1.0
36#define TEST_ATS_PREFRENCE_DELTA 1.0 37#define TEST_ATS_PREFRENCE_DELTA 1.0
37 38
38#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 39#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \
40 GNUNET_TIME_UNIT_SECONDS, 1)
39 41
40#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 42#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
41#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 43 120)
42#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) 44#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \
45 GNUNET_TIME_UNIT_SECONDS, 10)
46#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \
47 GNUNET_TIME_UNIT_MILLISECONDS, 500)
43#define TESTNAME_PREFIX "perf_ats_" 48#define TESTNAME_PREFIX "perf_ats_"
44#define DEFAULT_SLAVES_NUM 2 49#define DEFAULT_SLAVES_NUM 2
45#define DEFAULT_MASTERS_NUM 1 50#define DEFAULT_MASTERS_NUM 1
@@ -123,7 +128,7 @@ static struct LoggingHandle *l;
123 128
124 129
125static void 130static void
126evaluate() 131evaluate ()
127{ 132{
128 int c_m; 133 int c_m;
129 int c_s; 134 int c_s;
@@ -139,48 +144,49 @@ evaluate()
139 144
140 duration = 1 + (perf_duration.rel_value_us / (1000 * 1000)); 145 duration = 1 + (perf_duration.rel_value_us / (1000 * 1000));
141 for (c_m = 0; c_m < num_masters; c_m++) 146 for (c_m = 0; c_m < num_masters; c_m++)
147 {
148 mp = &mps[c_m];
149 fprintf (stderr,
150 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n",
151 mp->no, mp->total_bytes_sent / 1024, duration,
152 (mp->total_bytes_sent / 1024) / duration,
153 mp->total_bytes_received / 1024, duration,
154 (mp->total_bytes_received / 1024) / duration);
155
156 for (c_s = 0; c_s < num_slaves; c_s++)
142 { 157 {
143 mp = &mps[c_m]; 158 p = &mp->partners[c_s];
144 fprintf(stderr, 159 kb_sent_sec = 0;
145 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n", 160 kb_recv_sec = 0;
146 mp->no, mp->total_bytes_sent / 1024, duration, 161 kb_sent_percent = 0.0;
147 (mp->total_bytes_sent / 1024) / duration, 162 kb_recv_percent = 0.0;
148 mp->total_bytes_received / 1024, duration, 163 rtt = 0;
149 (mp->total_bytes_received / 1024) / duration); 164
150 165 if (duration > 0)
151 for (c_s = 0; c_s < num_slaves; c_s++) 166 {
152 { 167 kb_sent_sec = (p->bytes_sent / 1024) / duration;
153 p = &mp->partners[c_s]; 168 kb_recv_sec = (p->bytes_received / 1024) / duration;
154 kb_sent_sec = 0; 169 }
155 kb_recv_sec = 0; 170
156 kb_sent_percent = 0.0; 171 if (mp->total_bytes_sent > 0)
157 kb_recv_percent = 0.0; 172 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
158 rtt = 0; 173 if (mp->total_bytes_received > 0)
159 174 kb_recv_percent = ((double) p->bytes_received * 100)
160 if (duration > 0) 175 / mp->total_bytes_received;
161 { 176 if (1000 * p->messages_sent > 0)
162 kb_sent_sec = (p->bytes_sent / 1024) / duration; 177 rtt = p->total_app_rtt / (1000 * p->messages_sent);
163 kb_recv_sec = (p->bytes_received / 1024) / duration; 178 fprintf (stderr,
164 } 179 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
165 180 (mp->pref_partner == p->dest) ? '*' : ' ',
166 if (mp->total_bytes_sent > 0) 181 mp->no, p->dest->no,
167 kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent; 182 kb_sent_sec, kb_sent_percent,
168 if (mp->total_bytes_received > 0) 183 kb_recv_sec, kb_recv_percent);
169 kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received; 184 fprintf (stderr,
170 if (1000 * p->messages_sent > 0) 185 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
171 rtt = p->total_app_rtt / (1000 * p->messages_sent); 186 (mp->pref_partner == p->dest) ? '*' : ' ',
172 fprintf(stderr, 187 mp->no, p->dest->no, rtt);
173 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
174 (mp->pref_partner == p->dest) ? '*' : ' ',
175 mp->no, p->dest->no,
176 kb_sent_sec, kb_sent_percent,
177 kb_recv_sec, kb_recv_percent);
178 fprintf(stderr,
179 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
180 (mp->pref_partner == p->dest) ? '*' : ' ',
181 mp->no, p->dest->no, rtt);
182 }
183 } 188 }
189 }
184} 190}
185 191
186 192
@@ -190,24 +196,24 @@ evaluate()
190 * @param cls NULL 196 * @param cls NULL
191 */ 197 */
192static void 198static void
193do_shutdown(void *cls) 199do_shutdown (void *cls)
194{ 200{
195 if (GNUNET_YES == logging) 201 if (GNUNET_YES == logging)
196 GNUNET_ATS_TEST_logging_clean_up(l); 202 GNUNET_ATS_TEST_logging_clean_up (l);
197 if (NULL != timeout_task) 203 if (NULL != timeout_task)
198 { 204 {
199 GNUNET_SCHEDULER_cancel(timeout_task); 205 GNUNET_SCHEDULER_cancel (timeout_task);
200 timeout_task = NULL; 206 timeout_task = NULL;
201 } 207 }
202 if (NULL != progress_task) 208 if (NULL != progress_task)
203 { 209 {
204 fprintf(stderr, "0\n"); 210 fprintf (stderr, "0\n");
205 GNUNET_SCHEDULER_cancel(progress_task); 211 GNUNET_SCHEDULER_cancel (progress_task);
206 progress_task = NULL; 212 progress_task = NULL;
207 } 213 }
208 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
209 "Benchmarking done\n"); 215 "Benchmarking done\n");
210 GNUNET_ATS_TEST_shutdown_topology(); 216 GNUNET_ATS_TEST_shutdown_topology ();
211} 217}
212 218
213 219
@@ -217,163 +223,166 @@ do_shutdown(void *cls)
217 * @param cls NULL 223 * @param cls NULL
218 */ 224 */
219static void 225static void
220do_timeout(void *cls) 226do_timeout (void *cls)
221{ 227{
222 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 228 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
223 "Terminating with timeout\n"); 229 "Terminating with timeout\n");
224 timeout_task = NULL; 230 timeout_task = NULL;
225 evaluate(); 231 evaluate ();
226 GNUNET_SCHEDULER_shutdown(); 232 GNUNET_SCHEDULER_shutdown ();
227} 233}
228 234
229 235
230static void 236static void
231print_progress(void *cls) 237print_progress (void *cls)
232{ 238{
233 static int calls; 239 static int calls;
234 240
235 progress_task = NULL; 241 progress_task = NULL;
236 fprintf(stderr, 242 fprintf (stderr,
237 "%llu..", 243 "%llu..",
238 (long long unsigned)perf_duration.rel_value_us / (1000 * 1000) - calls); 244 (long long unsigned) perf_duration.rel_value_us / (1000 * 1000)
245 - calls);
239 calls++; 246 calls++;
240 247
241 progress_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 248 progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
242 &print_progress, 249 &print_progress,
243 NULL); 250 NULL);
244} 251}
245 252
246 253
247static void 254static void
248ats_pref_task(void *cls) 255ats_pref_task (void *cls)
249{ 256{
250 struct BenchmarkPeer *me = cls; 257 struct BenchmarkPeer *me = cls;
251 258
252 me->ats_task = NULL; 259 me->ats_task = NULL;
253 260
254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n", 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 me->no, me->pref_partner->no, me->pref_value); 262 " Master [%u] set preference for slave [%u] to %f\n",
256 GNUNET_ATS_performance_change_preference(me->ats_perf_handle, 263 me->no, me->pref_partner->no, me->pref_value);
257 &me->pref_partner->id, 264 GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
258 pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END); 265 &me->pref_partner->id,
266 pref_val, me->pref_value,
267 GNUNET_ATS_PREFERENCE_END);
259 me->pref_value += TEST_ATS_PREFRENCE_DELTA; 268 me->pref_value += TEST_ATS_PREFRENCE_DELTA;
260 me->ats_task = GNUNET_SCHEDULER_add_delayed(TEST_ATS_PREFRENCE_FREQUENCY, 269 me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
261 &ats_pref_task, cls); 270 &ats_pref_task, cls);
262} 271}
263 272
264 273
265static void 274static void
266start_benchmark(void *cls) 275start_benchmark (void *cls)
267{ 276{
268 int c_m; 277 int c_m;
269 int c_s; 278 int c_s;
270 279
271 progress_task = GNUNET_SCHEDULER_add_now(&print_progress, 280 progress_task = GNUNET_SCHEDULER_add_now (&print_progress,
272 NULL); 281 NULL);
273 282
274 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 283 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
275 "Topology connected, start benchmarking...\n"); 284 "Topology connected, start benchmarking...\n");
276 285
277 /* Start sending test messages */ 286 /* Start sending test messages */
278 for (c_m = 0; c_m < num_masters; c_m++) 287 for (c_m = 0; c_m < num_masters; c_m++)
288 {
289 for (c_s = 0; c_s < num_slaves; c_s++)
279 { 290 {
280 for (c_s = 0; c_s < num_slaves; c_s++) 291 GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m],
281 { 292 &mps[c_m].partners[c_s],
282 GNUNET_ATS_TEST_generate_traffic_start(&mps[c_m], 293 GNUNET_ATS_TEST_TG_LINEAR,
283 &mps[c_m].partners[c_s], 294 UINT32_MAX,
284 GNUNET_ATS_TEST_TG_LINEAR, 295 UINT32_MAX,
285 UINT32_MAX, 296 GNUNET_TIME_UNIT_MINUTES,
286 UINT32_MAX, 297 GNUNET_TIME_UNIT_FOREVER_REL);
287 GNUNET_TIME_UNIT_MINUTES,
288 GNUNET_TIME_UNIT_FOREVER_REL);
289 }
290 if (pref_val != GNUNET_ATS_PREFERENCE_END)
291 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task,
292 &mps[c_m]);
293 } 298 }
299 if (pref_val != GNUNET_ATS_PREFERENCE_END)
300 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task,
301 &mps[c_m]);
302 }
294 303
295 if (GNUNET_YES == logging) 304 if (GNUNET_YES == logging)
296 l = GNUNET_ATS_TEST_logging_start(log_frequency, 305 l = GNUNET_ATS_TEST_logging_start (log_frequency,
297 testname, mps, 306 testname, mps,
298 num_masters, num_slaves, 307 num_masters, num_slaves,
299 GNUNET_NO); 308 GNUNET_NO);
300} 309}
301 310
302 311
303static void 312static void
304do_benchmark(void *cls, 313do_benchmark (void *cls,
305 struct BenchmarkPeer *masters, 314 struct BenchmarkPeer *masters,
306 struct BenchmarkPeer *slaves) 315 struct BenchmarkPeer *slaves)
307{ 316{
308 mps = masters; 317 mps = masters;
309 sps = slaves; 318 sps = slaves;
310 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 319 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
311 NULL); 320 NULL);
312 timeout_task = GNUNET_SCHEDULER_add_delayed(perf_duration, 321 timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
313 &do_timeout, 322 &do_timeout,
314 NULL); 323 NULL);
315 progress_task = GNUNET_SCHEDULER_add_now(&start_benchmark, 324 progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark,
316 NULL); 325 NULL);
317} 326}
318 327
319 328
320static struct BenchmarkPartner * 329static struct BenchmarkPartner *
321find_partner(struct BenchmarkPeer *me, 330find_partner (struct BenchmarkPeer *me,
322 const struct GNUNET_PeerIdentity *peer) 331 const struct GNUNET_PeerIdentity *peer)
323{ 332{
324 int c_m; 333 int c_m;
325 334
326 GNUNET_assert(NULL != me); 335 GNUNET_assert (NULL != me);
327 GNUNET_assert(NULL != peer); 336 GNUNET_assert (NULL != peer);
328 337
329 for (c_m = 0; c_m < me->num_partners; c_m++) 338 for (c_m = 0; c_m < me->num_partners; c_m++)
339 {
340 /* Find a partner with other as destination */
341 if (0 == GNUNET_memcmp (peer, &me->partners[c_m].dest->id))
330 { 342 {
331 /* Find a partner with other as destination */ 343 return &me->partners[c_m];
332 if (0 == GNUNET_memcmp(peer, &me->partners[c_m].dest->id))
333 {
334 return &me->partners[c_m];
335 }
336 } 344 }
345 }
337 return NULL; 346 return NULL;
338} 347}
339 348
340 349
341static void 350static void
342log_request_cb(void *cls, 351log_request_cb (void *cls,
343 const struct GNUNET_HELLO_Address *address, 352 const struct GNUNET_HELLO_Address *address,
344 int address_active, 353 int address_active,
345 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 354 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
346 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 355 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
347 const struct GNUNET_ATS_Properties *ats) 356 const struct GNUNET_ATS_Properties *ats)
348{ 357{
349 struct BenchmarkPeer *me = cls; 358 struct BenchmarkPeer *me = cls;
350 struct BenchmarkPartner *p; 359 struct BenchmarkPartner *p;
351 char *peer_id; 360 char *peer_id;
352 361
353 p = find_partner(me, &address->peer); 362 p = find_partner (me, &address->peer);
354 if (NULL == p) 363 if (NULL == p)
355 { 364 {
356 /* This is not one of my partners 365 /* This is not one of my partners
357 * Will happen since the peers will connect to each other due to gossiping 366 * Will happen since the peers will connect to each other due to gossiping
358 */ 367 */
359 return; 368 return;
360 } 369 }
361 peer_id = GNUNET_strdup(GNUNET_i2s(&me->id)); 370 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
362 371
363 if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) || 372 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
364 (p->bandwidth_out != ntohl(bandwidth_out.value__))) 373 (p->bandwidth_out != ntohl (bandwidth_out.value__)))
365 p->bandwidth_in = ntohl(bandwidth_in.value__); 374 p->bandwidth_in = ntohl (bandwidth_in.value__);
366 p->bandwidth_out = ntohl(bandwidth_out.value__); 375 p->bandwidth_out = ntohl (bandwidth_out.value__);
367 376
368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "%s [%u] received ATS information for peers `%s'\n", 378 "%s [%u] received ATS information for peers `%s'\n",
370 (GNUNET_YES == p->me->master) ? "Master" : "Slave", 379 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
371 p->me->no, 380 p->me->no,
372 GNUNET_i2s(&p->dest->id)); 381 GNUNET_i2s (&p->dest->id));
373 382
374 GNUNET_free(peer_id); 383 GNUNET_free (peer_id);
375 if (NULL != l) 384 if (NULL != l)
376 GNUNET_ATS_TEST_logging_now(l); 385 GNUNET_ATS_TEST_logging_now (l);
377} 386}
378 387
379 388
@@ -381,7 +390,7 @@ log_request_cb(void *cls,
381 * Start the performance test case 390 * Start the performance test case
382 */ 391 */
383int 392int
384main(int argc, char *argv[]) 393main (int argc, char *argv[])
385{ 394{
386 char *tmp; 395 char *tmp;
387 char *tmp_sep; 396 char *tmp_sep;
@@ -398,187 +407,192 @@ main(int argc, char *argv[])
398 * perf_ats_<solver>_<transport>_<preference>[.exe]*/ 407 * perf_ats_<solver>_<transport>_<preference>[.exe]*/
399 408
400 /* Find test prefix, store in temp */ 409 /* Find test prefix, store in temp */
401 tmp = strstr(argv[0], TESTNAME_PREFIX); 410 tmp = strstr (argv[0], TESTNAME_PREFIX);
402 if (NULL == tmp) 411 if (NULL == tmp)
403 { 412 {
404 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); 413 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
405 return GNUNET_SYSERR; 414 return GNUNET_SYSERR;
406 } 415 }
407 416
408 /* Set tmp to end of test name prefix */ 417 /* Set tmp to end of test name prefix */
409 tmp += strlen(TESTNAME_PREFIX); 418 tmp += strlen (TESTNAME_PREFIX);
410 419
411 /* Determine solver name */ 420 /* Determine solver name */
412 solver = GNUNET_strdup(tmp); 421 solver = GNUNET_strdup (tmp);
413 /* Remove .exe prefix */ 422 /* Remove .exe prefix */
414 if (NULL != (dotexe = strstr(solver, ".exe")) && dotexe[4] == '\0') 423 if ((NULL != (dotexe = strstr (solver, ".exe")))&&(dotexe[4] == '\0'))
415 dotexe[0] = '\0'; 424 dotexe[0] = '\0';
416 425
417 /* Determine first '_' after solver */ 426 /* Determine first '_' after solver */
418 tmp_sep = strchr(solver, '_'); 427 tmp_sep = strchr (solver, '_');
419 if (NULL == tmp_sep) 428 if (NULL == tmp_sep)
420 { 429 {
421 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); 430 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
422 GNUNET_free(solver); 431 GNUNET_free (solver);
423 return GNUNET_SYSERR; 432 return GNUNET_SYSERR;
424 } 433 }
425 tmp_sep[0] = '\0'; 434 tmp_sep[0] = '\0';
426 comm_name = GNUNET_strdup(&tmp_sep[1]); 435 comm_name = GNUNET_strdup (&tmp_sep[1]);
427 tmp_sep = strchr(comm_name, '_'); 436 tmp_sep = strchr (comm_name, '_');
428 if (NULL == tmp_sep) 437 if (NULL == tmp_sep)
429 { 438 {
430 fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); 439 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
431 GNUNET_free(solver); 440 GNUNET_free (solver);
432 return GNUNET_SYSERR; 441 return GNUNET_SYSERR;
433 } 442 }
434 tmp_sep[0] = '\0'; 443 tmp_sep[0] = '\0';
435 for (c = 0; c <= strlen(comm_name); c++) 444 for (c = 0; c <= strlen (comm_name); c++)
436 comm_name[c] = toupper(comm_name[c]); 445 comm_name[c] = toupper (comm_name[c]);
437 if (0 == strcmp(comm_name, "CORE")) 446 if (0 == strcmp (comm_name, "CORE"))
438 test_core = GNUNET_YES; 447 test_core = GNUNET_YES;
439 else if (0 == strcmp(comm_name, "TRANSPORT")) 448 else if (0 == strcmp (comm_name, "TRANSPORT"))
440 test_core = GNUNET_NO; 449 test_core = GNUNET_NO;
441 else 450 else
442 { 451 {
443 GNUNET_free(comm_name); 452 GNUNET_free (comm_name);
444 GNUNET_free(solver); 453 GNUNET_free (solver);
445 return GNUNET_SYSERR; 454 return GNUNET_SYSERR;
446 } 455 }
447 456
448 pref_str = GNUNET_strdup(tmp_sep + 1); 457 pref_str = GNUNET_strdup (tmp_sep + 1);
449 458
450 GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, 459 GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
451 pref_str); 460 pref_str);
452 GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str); 461 GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
453 462
454 for (c = 0; c <= strlen(pref_str); c++) 463 for (c = 0; c <= strlen (pref_str); c++)
455 pref_str[c] = toupper(pref_str[c]); 464 pref_str[c] = toupper (pref_str[c]);
456 pref_val = -1; 465 pref_val = -1;
457 466
458 if (0 != strcmp(pref_str, "NONE")) 467 if (0 != strcmp (pref_str, "NONE"))
468 {
469 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
459 { 470 {
460 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) 471 if (0 == strcmp (pref_str, prefs[c]))
461 { 472 {
462 if (0 == strcmp(pref_str, prefs[c])) 473 pref_val = c;
463 { 474 break;
464 pref_val = c; 475 }
465 break;
466 }
467 }
468 } 476 }
477 }
469 else 478 else
470 { 479 {
471 /* abuse terminator to indicate no pref */ 480 /* abuse terminator to indicate no pref */
472 pref_val = GNUNET_ATS_PREFERENCE_END; 481 pref_val = GNUNET_ATS_PREFERENCE_END;
473 } 482 }
474 if (-1 == pref_val) 483 if (-1 == pref_val)
475 { 484 {
476 fprintf(stderr, "Unknown preference: `%s'\n", pref_str); 485 fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
477 GNUNET_free(solver); 486 GNUNET_free (solver);
478 GNUNET_free(pref_str); 487 GNUNET_free (pref_str);
479 GNUNET_free(comm_name); 488 GNUNET_free (comm_name);
480 return -1; 489 return -1;
481 } 490 }
482 491
483 for (c = 0; c < (argc - 1); c++) 492 for (c = 0; c < (argc - 1); c++)
484 { 493 {
485 if (0 == strcmp(argv[c], "-d")) 494 if (0 == strcmp (argv[c], "-d"))
486 break; 495 break;
487 } 496 }
488 if (c < argc - 1) 497 if (c < argc - 1)
489 { 498 {
490 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &perf_duration)) 499 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1],
491 fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]); 500 &perf_duration))
492 } 501 fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
502 }
493 else 503 else
494 { 504 {
495 perf_duration = BENCHMARK_DURATION; 505 perf_duration = BENCHMARK_DURATION;
496 } 506 }
497 fprintf(stderr, "Running benchmark for %llu secs\n", (unsigned long long)(perf_duration.rel_value_us) / (1000 * 1000)); 507 fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long
508 long) (perf_duration.
509 rel_value_us)
510 / (1000 * 1000));
498 511
499 for (c = 0; c < (argc - 1); c++) 512 for (c = 0; c < (argc - 1); c++)
500 { 513 {
501 if (0 == strcmp(argv[c], "-s")) 514 if (0 == strcmp (argv[c], "-s"))
502 break; 515 break;
503 } 516 }
504 if (c < argc - 1) 517 if (c < argc - 1)
505 { 518 {
506 if ((0L != (num_slaves = strtol(argv[c + 1], NULL, 10))) 519 if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
507 && (num_slaves >= 1)) 520 && (num_slaves >= 1))
508 fprintf(stderr, "Starting %u slave peers\n", num_slaves); 521 fprintf (stderr, "Starting %u slave peers\n", num_slaves);
509 else 522 else
510 num_slaves = DEFAULT_SLAVES_NUM; 523 num_slaves = DEFAULT_SLAVES_NUM;
511 } 524 }
512 else 525 else
513 num_slaves = DEFAULT_SLAVES_NUM; 526 num_slaves = DEFAULT_SLAVES_NUM;
514 527
515 for (c = 0; c < (argc - 1); c++) 528 for (c = 0; c < (argc - 1); c++)
516 { 529 {
517 if (0 == strcmp(argv[c], "-m")) 530 if (0 == strcmp (argv[c], "-m"))
518 break; 531 break;
519 } 532 }
520 if (c < argc - 1) 533 if (c < argc - 1)
521 { 534 {
522 if ((0L != (num_masters = strtol(argv[c + 1], NULL, 10))) 535 if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
523 && (num_masters >= 2)) 536 && (num_masters >= 2))
524 fprintf(stderr, "Starting %u master peers\n", num_masters); 537 fprintf (stderr, "Starting %u master peers\n", num_masters);
525 else 538 else
526 num_masters = DEFAULT_MASTERS_NUM; 539 num_masters = DEFAULT_MASTERS_NUM;
527 } 540 }
528 else 541 else
529 num_masters = DEFAULT_MASTERS_NUM; 542 num_masters = DEFAULT_MASTERS_NUM;
530 543
531 logging = GNUNET_NO; 544 logging = GNUNET_NO;
532 for (c = 0; c < argc; c++) 545 for (c = 0; c < argc; c++)
533 { 546 {
534 if (0 == strcmp(argv[c], "-l")) 547 if (0 == strcmp (argv[c], "-l"))
535 logging = GNUNET_YES; 548 logging = GNUNET_YES;
536 } 549 }
537 550
538 if (GNUNET_YES == logging) 551 if (GNUNET_YES == logging)
552 {
553 for (c = 0; c < (argc - 1); c++)
554 {
555 if (0 == strcmp (argv[c], "-f"))
556 break;
557 }
558 if (c < argc - 1)
559 {
560 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1],
561 &log_frequency))
562 fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
563 }
564 else
539 { 565 {
540 for (c = 0; c < (argc - 1); c++) 566 log_frequency = LOGGING_FREQUENCY;
541 {
542 if (0 == strcmp(argv[c], "-f"))
543 break;
544 }
545 if (c < argc - 1)
546 {
547 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &log_frequency))
548 fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
549 }
550 else
551 {
552 log_frequency = LOGGING_FREQUENCY;
553 }
554 fprintf(stderr, "Using log frequency %llu ms\n",
555 (unsigned long long)(log_frequency.rel_value_us) / (1000));
556 } 567 }
568 fprintf (stderr, "Using log frequency %llu ms\n",
569 (unsigned long long) (log_frequency.rel_value_us) / (1000));
570 }
557 571
558 GNUNET_asprintf(&testname, "%s_%s_%s", solver, comm_name, pref_str); 572 GNUNET_asprintf (&testname, "%s_%s_%s", solver, comm_name, pref_str);
559 573
560 if (num_slaves < num_masters) 574 if (num_slaves < num_masters)
561 { 575 {
562 fprintf(stderr, 576 fprintf (stderr,
563 "Number of master peers is lower than slaves! exit...\n"); 577 "Number of master peers is lower than slaves! exit...\n");
564 GNUNET_free(test_name); 578 GNUNET_free (test_name);
565 GNUNET_free(solver); 579 GNUNET_free (solver);
566 GNUNET_free(pref_str); 580 GNUNET_free (pref_str);
567 GNUNET_free(comm_name); 581 GNUNET_free (comm_name);
568 return GNUNET_SYSERR; 582 return GNUNET_SYSERR;
569 } 583 }
570 584
571 /** 585 /**
572 * Setup the topology 586 * Setup the topology
573 */ 587 */
574 GNUNET_ATS_TEST_create_topology("perf-ats", 588 GNUNET_ATS_TEST_create_topology ("perf-ats",
575 conf_name, 589 conf_name,
576 num_slaves, 590 num_slaves,
577 num_masters, 591 num_masters,
578 test_core, 592 test_core,
579 &do_benchmark, 593 &do_benchmark,
580 NULL, 594 NULL,
581 &log_request_cb); 595 &log_request_cb);
582 596
583 return result; 597 return result;
584} 598}
diff --git a/src/ats-tests/perf_ats.h b/src/ats-tests/perf_ats.h
index 2d552a5d7..6460aa098 100644
--- a/src/ats-tests/perf_ats.h
+++ b/src/ats-tests/perf_ats.h
@@ -30,26 +30,32 @@
30#include "gnunet_core_service.h" 30#include "gnunet_core_service.h"
31#include "ats-testing.h" 31#include "ats-testing.h"
32 32
33#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 33#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
34#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 34 120)
35#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) 35#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \
36 GNUNET_TIME_UNIT_SECONDS, 10)
37#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \
38 GNUNET_TIME_UNIT_MILLISECONDS, 500)
36#define TESTNAME_PREFIX "perf_ats_" 39#define TESTNAME_PREFIX "perf_ats_"
37#define DEFAULT_SLAVES_NUM 2 40#define DEFAULT_SLAVES_NUM 2
38#define DEFAULT_MASTERS_NUM 1 41#define DEFAULT_MASTERS_NUM 1
39 42
40#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 43#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \
44 GNUNET_TIME_UNIT_SECONDS, 1)
41#define TEST_ATS_PREFRENCE_START 1.0 45#define TEST_ATS_PREFRENCE_START 1.0
42#define TEST_ATS_PREFRENCE_DELTA 1.0 46#define TEST_ATS_PREFRENCE_DELTA 1.0
43 47
44#define TEST_MESSAGE_TYPE_PING 12345 48#define TEST_MESSAGE_TYPE_PING 12345
45#define TEST_MESSAGE_TYPE_PONG 12346 49#define TEST_MESSAGE_TYPE_PONG 12346
46#define TEST_MESSAGE_SIZE 1000 50#define TEST_MESSAGE_SIZE 1000
47#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 51#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \
52 GNUNET_TIME_UNIT_SECONDS, 1)
48 53
49/** 54/**
50 * Information about a benchmarking partner 55 * Information about a benchmarking partner
51 */ 56 */
52struct BenchmarkPartner { 57struct BenchmarkPartner
58{
53 /** 59 /**
54 * The peer itself this partner belongs to 60 * The peer itself this partner belongs to
55 */ 61 */
@@ -127,7 +133,8 @@ struct BenchmarkPartner {
127/** 133/**
128 * Information we track for a peer in the testbed. 134 * Information we track for a peer in the testbed.
129 */ 135 */
130struct BenchmarkPeer { 136struct BenchmarkPeer
137{
131 /** 138 /**
132 * Handle with testbed. 139 * Handle with testbed.
133 */ 140 */
@@ -194,7 +201,7 @@ struct BenchmarkPeer {
194 * Masters only 201 * Masters only
195 * Progress task 202 * Progress task
196 */ 203 */
197 struct GNUNET_SCHEDULER_Task * ats_task; 204 struct GNUNET_SCHEDULER_Task *ats_task;
198 205
199 /** 206 /**
200 * Masters only 207 * Masters only
diff --git a/src/ats-tests/perf_ats_logging.c b/src/ats-tests/perf_ats_logging.c
index e0f192ae4..41c50ea6e 100644
--- a/src/ats-tests/perf_ats_logging.c
+++ b/src/ats-tests/perf_ats_logging.c
@@ -72,7 +72,7 @@
72/** 72/**
73 * Logging task 73 * Logging task
74 */ 74 */
75static struct GNUNET_SCHEDULER_Task * log_task; 75static struct GNUNET_SCHEDULER_Task *log_task;
76 76
77/** 77/**
78 * Reference to perf_ats' masters 78 * Reference to perf_ats' masters
@@ -85,7 +85,8 @@ static struct GNUNET_TIME_Relative frequency;
85/** 85/**
86 * A single logging time step for a partner 86 * A single logging time step for a partner
87 */ 87 */
88struct PartnerLoggingTimestep { 88struct PartnerLoggingTimestep
89{
89 /** 90 /**
90 * Peer 91 * Peer
91 */ 92 */
@@ -158,7 +159,8 @@ struct PartnerLoggingTimestep {
158/** 159/**
159 * A single logging time step for a peer 160 * A single logging time step for a peer
160 */ 161 */
161struct PeerLoggingTimestep { 162struct PeerLoggingTimestep
163{
162 /** 164 /**
163 * Next in DLL 165 * Next in DLL
164 */ 166 */
@@ -213,7 +215,8 @@ struct PeerLoggingTimestep {
213/** 215/**
214 * Entry for a benchmark peer 216 * Entry for a benchmark peer
215 */ 217 */
216struct LoggingPeer { 218struct LoggingPeer
219{
217 /** 220 /**
218 * Peer 221 * Peer
219 */ 222 */
@@ -242,164 +245,200 @@ static struct LoggingPeer *lp;
242 245
243 246
244static void 247static void
245write_throughput_gnuplot_script(char * fn, struct LoggingPeer *lp) 248write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp)
246{ 249{
247 struct GNUNET_DISK_FileHandle *f; 250 struct GNUNET_DISK_FileHandle *f;
248 char * gfn; 251 char *gfn;
249 char *data; 252 char *data;
250 int c_s; 253 int c_s;
251 int peer_index; 254 int peer_index;
252 255
253 GNUNET_asprintf(&gfn, "gnuplot_throughput_%s", fn); 256 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn);
254 f = GNUNET_DISK_file_open(gfn, 257 f = GNUNET_DISK_file_open (gfn,
255 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 258 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
256 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 259 GNUNET_DISK_PERM_USER_EXEC
260 | GNUNET_DISK_PERM_USER_READ
261 | GNUNET_DISK_PERM_USER_WRITE);
257 if (NULL == f) 262 if (NULL == f)
258 { 263 {
259 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
260 GNUNET_free(gfn); 265 gfn);
261 return; 266 GNUNET_free (gfn);
262 } 267 return;
268 }
263 269
264 /* Write header */ 270 /* Write header */
265 271
266 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, strlen(THROUGHPUT_TEMPLATE))) 272 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE, strlen (
267 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 273 THROUGHPUT_TEMPLATE)))
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
275 "Cannot write data to plot file `%s'\n", gfn);
268 276
269 /* Write master data */ 277 /* Write master data */
270 peer_index = LOG_ITEMS_TIME; 278 peer_index = LOG_ITEMS_TIME;
271 GNUNET_asprintf(&data, "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ 279 GNUNET_asprintf (&data,
272 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", 280 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
273 fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, 281 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
274 fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); 282 fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
275 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 283 fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 284 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
277 GNUNET_free(data); 285 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286 "Cannot write data to plot file `%s'\n", gfn);
287 GNUNET_free (data);
278 288
279 peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; 289 peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
280 for (c_s = 0; c_s < lp->peer->num_partners; c_s++) 290 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
281 { 291 {
282 GNUNET_asprintf(&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ 292 GNUNET_asprintf (&data,
283 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", 293 "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
284 fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, lp->peer->partners[c_s].dest->no, 294 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
285 fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, lp->peer->partners[c_s].dest->no, 295 fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
286 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 296 lp->peer->partners[c_s].dest->no,
287 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 297 fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no,
288 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 298 lp->peer->partners[c_s].dest->no,
289 GNUNET_free(data); 299 (c_s < lp->peer->num_partners - 1) ? ", \\" :
290 peer_index += LOG_ITEMS_PER_PEER; 300 "\n pause -1");
291 } 301 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
292 302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
293 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 303 "Cannot write data to plot file `%s'\n", gfn);
294 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); 304 GNUNET_free (data);
305 peer_index += LOG_ITEMS_PER_PEER;
306 }
307
308 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
310 gfn);
295 else 311 else
296 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); 312 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
313 "Data successfully written to plot file `%s'\n", gfn);
297 314
298 GNUNET_free(gfn); 315 GNUNET_free (gfn);
299} 316}
300 317
301 318
302static void 319static void
303write_rtt_gnuplot_script(char * fn, struct LoggingPeer *lp) 320write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp)
304{ 321{
305 struct GNUNET_DISK_FileHandle *f; 322 struct GNUNET_DISK_FileHandle *f;
306 char * gfn; 323 char *gfn;
307 char *data; 324 char *data;
308 int c_s; 325 int c_s;
309 int index; 326 int index;
310 327
311 GNUNET_asprintf(&gfn, "gnuplot_rtt_%s", fn); 328 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn);
312 f = GNUNET_DISK_file_open(gfn, 329 f = GNUNET_DISK_file_open (gfn,
313 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 330 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
314 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 331 GNUNET_DISK_PERM_USER_EXEC
332 | GNUNET_DISK_PERM_USER_READ
333 | GNUNET_DISK_PERM_USER_WRITE);
315 if (NULL == f) 334 if (NULL == f)
316 { 335 {
317 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
318 GNUNET_free(gfn); 337 gfn);
319 return; 338 GNUNET_free (gfn);
320 } 339 return;
340 }
321 341
322 /* Write header */ 342 /* Write header */
323 343
324 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE))) 344 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen (
325 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 345 RTT_TEMPLATE)))
346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
347 "Cannot write data to plot file `%s'\n", gfn);
326 348
327 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; 349 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
328 for (c_s = 0; c_s < lp->peer->num_partners; c_s++) 350 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
329 { 351 {
330 GNUNET_asprintf(&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", 352 GNUNET_asprintf (&data,
331 (0 == c_s) ? "plot " : "", 353 "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
332 fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no, 354 (0 == c_s) ? "plot " : "",
333 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 355 fn, index + LOG_ITEM_APP_RTT, lp->peer->no,
334 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 356 lp->peer->partners[c_s].dest->no,
335 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 357 (c_s < lp->peer->num_partners - 1) ? ", \\" :
336 GNUNET_free(data); 358 "\n pause -1");
337 index += LOG_ITEMS_PER_PEER; 359 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
338 } 360 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
339 361 "Cannot write data to plot file `%s'\n", gfn);
340 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 362 GNUNET_free (data);
341 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); 363 index += LOG_ITEMS_PER_PEER;
364 }
365
366 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
368 gfn);
342 else 369 else
343 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); 370 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
344 GNUNET_free(gfn); 371 "Data successfully written to plot file `%s'\n", gfn);
372 GNUNET_free (gfn);
345} 373}
346 374
347static void 375static void
348write_bw_gnuplot_script(char * fn, struct LoggingPeer *lp) 376write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp)
349{ 377{
350 struct GNUNET_DISK_FileHandle *f; 378 struct GNUNET_DISK_FileHandle *f;
351 char * gfn; 379 char *gfn;
352 char *data; 380 char *data;
353 int c_s; 381 int c_s;
354 int index; 382 int index;
355 383
356 GNUNET_asprintf(&gfn, "gnuplot_bw_%s", fn); 384 GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn);
357 f = GNUNET_DISK_file_open(gfn, 385 f = GNUNET_DISK_file_open (gfn,
358 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 386 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
359 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 387 GNUNET_DISK_PERM_USER_EXEC
388 | GNUNET_DISK_PERM_USER_READ
389 | GNUNET_DISK_PERM_USER_WRITE);
360 if (NULL == f) 390 if (NULL == f)
361 { 391 {
362 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); 392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
363 GNUNET_free(gfn); 393 gfn);
364 return; 394 GNUNET_free (gfn);
365 } 395 return;
396 }
366 397
367 /* Write header */ 398 /* Write header */
368 399
369 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE))) 400 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen (
370 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 401 BW_TEMPLATE)))
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
403 "Cannot write data to plot file `%s'\n", gfn);
371 404
372 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; 405 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
373 for (c_s = 0; c_s < lp->peer->num_partners; c_s++) 406 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
374 { 407 {
375 GNUNET_asprintf(&data, "%s" \ 408 GNUNET_asprintf (&data, "%s" \
376 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ 409 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
377 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \ 410 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
378 "%s\n", 411 "%s\n",
379 (0 == c_s) ? "plot " : "", 412 (0 == c_s) ? "plot " : "",
380 fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no, lp->peer->partners[c_s].dest->no, 413 fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no,
381 fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no, lp->peer->partners[c_s].dest->no, 414 lp->peer->partners[c_s].dest->no,
382 (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); 415 fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no,
383 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) 416 lp->peer->partners[c_s].dest->no,
384 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); 417 (c_s < lp->peer->num_partners - 1) ? ", \\" :
385 GNUNET_free(data); 418 "\n pause -1");
386 index += LOG_ITEMS_PER_PEER; 419 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
387 } 420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 421 "Cannot write data to plot file `%s'\n", gfn);
389 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) 422 GNUNET_free (data);
390 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); 423 index += LOG_ITEMS_PER_PEER;
424 }
425
426 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
428 gfn);
391 else 429 else
392 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); 430 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
393 GNUNET_free(gfn); 431 "Data successfully written to plot file `%s'\n", gfn);
432 GNUNET_free (gfn);
394} 433}
395 434
396 435
397static void 436static void
398write_to_file() 437write_to_file ()
399{ 438{
400 struct GNUNET_DISK_FileHandle *f; 439 struct GNUNET_DISK_FileHandle *f;
401 440
402 char * filename; 441 char *filename;
403 char *data; 442 char *data;
404 char *slave_string; 443 char *slave_string;
405 char *slave_string_tmp; 444 char *slave_string_tmp;
@@ -409,88 +448,112 @@ write_to_file()
409 int c_s; 448 int c_s;
410 449
411 for (c_m = 0; c_m < num_peers; c_m++) 450 for (c_m = 0; c_m < num_peers; c_m++)
451 {
452 GNUNET_asprintf (&filename, "%llu_master_%u_%s_%s.data",
453 GNUNET_TIME_absolute_get ().abs_value_us,
454 lp[c_m].peer->no, GNUNET_i2s (&lp[c_m].peer->id), name);
455
456 f = GNUNET_DISK_file_open (filename,
457 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
458 GNUNET_DISK_PERM_USER_READ
459 | GNUNET_DISK_PERM_USER_WRITE);
460 if (NULL == f)
412 { 461 {
413 GNUNET_asprintf(&filename, "%llu_master_%u_%s_%s.data", GNUNET_TIME_absolute_get().abs_value_us, 462 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
414 lp[c_m].peer->no, GNUNET_i2s(&lp[c_m].peer->id), name); 463 filename);
415 464 GNUNET_free (filename);
416 f = GNUNET_DISK_file_open(filename, 465 return;
417 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
418 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
419 if (NULL == f)
420 {
421 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
422 GNUNET_free(filename);
423 return;
424 }
425
426 for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
427 {
428 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
429 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
430 cur_lt->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
431 cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
432 cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv);
433
434 slave_string = GNUNET_strdup(";");
435 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
436 {
437 plt = &cur_lt->slaves_log[c_s];
438 /* Log partners */
439
440 /* Assembling slave string */
441 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
442 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n", plt->slave->no,
443 plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
444 plt->total_messages_received, plt->total_bytes_received, plt->throughput_recv,
445 plt->app_rtt, plt->ats_delay,
446 plt->bandwidth_in, plt->bandwidth_out);
447
448 GNUNET_asprintf(&slave_string_tmp, "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;", slave_string,
449 plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
450 plt->total_messages_received, plt->total_bytes_received, plt->throughput_sent,
451 (double)plt->app_rtt / 1000,
452 plt->bandwidth_in, plt->bandwidth_out,
453 plt->ats_cost_lan, plt->ats_cost_wan, plt->ats_cost_wlan,
454 plt->ats_delay, plt->ats_distance, plt->ats_network_type,
455 plt->ats_utilization_up, plt->ats_utilization_down);
456 GNUNET_free(slave_string);
457 slave_string = slave_string_tmp;
458 }
459 /* Assembling master string */
460
461
462
463 GNUNET_asprintf(&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
464 cur_lt->timestamp,
465 GNUNET_TIME_absolute_get_difference(lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
466 cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
467 cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv,
468 slave_string);
469 GNUNET_free(slave_string);
470
471 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
472 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
473 GNUNET_free(data);
474 }
475 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
476 {
477 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
478 GNUNET_free(filename);
479 return;
480 }
481
482 write_throughput_gnuplot_script(filename, lp);
483 write_rtt_gnuplot_script(filename, lp);
484 write_bw_gnuplot_script(filename, lp);
485
486 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
487 GNUNET_free(filename);
488 } 466 }
467
468 for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
469 {
470 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
471 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
472 lp[c_m].peer->no,
473 cur_lt->timestamp, GNUNET_TIME_absolute_get_difference (
474 lp[c_m].start, cur_lt->timestamp).rel_value_us / 1000,
475 cur_lt->total_messages_sent, cur_lt->total_bytes_sent,
476 cur_lt->total_throughput_send,
477 cur_lt->total_messages_received, cur_lt->total_bytes_received,
478 cur_lt->total_throughput_recv);
479
480 slave_string = GNUNET_strdup (";");
481 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
482 {
483 plt = &cur_lt->slaves_log[c_s];
484 /* Log partners */
485
486 /* Assembling slave string */
487 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
488 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n",
489 plt->slave->no,
490 plt->total_messages_sent, plt->total_bytes_sent,
491 plt->throughput_sent,
492 plt->total_messages_received, plt->total_bytes_received,
493 plt->throughput_recv,
494 plt->app_rtt, plt->ats_delay,
495 plt->bandwidth_in, plt->bandwidth_out);
496
497 GNUNET_asprintf (&slave_string_tmp,
498 "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
499 slave_string,
500 plt->total_messages_sent, plt->total_bytes_sent,
501 plt->throughput_sent,
502 plt->total_messages_received,
503 plt->total_bytes_received, plt->throughput_sent,
504 (double) plt->app_rtt / 1000,
505 plt->bandwidth_in, plt->bandwidth_out,
506 plt->ats_cost_lan, plt->ats_cost_wan,
507 plt->ats_cost_wlan,
508 plt->ats_delay, plt->ats_distance,
509 plt->ats_network_type,
510 plt->ats_utilization_up, plt->ats_utilization_down);
511 GNUNET_free (slave_string);
512 slave_string = slave_string_tmp;
513 }
514 /* Assembling master string */
515
516
517
518 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
519 cur_lt->timestamp,
520 GNUNET_TIME_absolute_get_difference (lp[c_m].start,
521 cur_lt->timestamp).
522 rel_value_us / 1000,
523 cur_lt->total_messages_sent, cur_lt->total_bytes_sent,
524 cur_lt->total_throughput_send,
525 cur_lt->total_messages_received,
526 cur_lt->total_bytes_received,
527 cur_lt->total_throughput_recv,
528 slave_string);
529 GNUNET_free (slave_string);
530
531 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Cannot write data to log file `%s'\n", filename);
534 GNUNET_free (data);
535 }
536 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
537 {
538 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
539 filename);
540 GNUNET_free (filename);
541 return;
542 }
543
544 write_throughput_gnuplot_script (filename, lp);
545 write_rtt_gnuplot_script (filename, lp);
546 write_bw_gnuplot_script (filename, lp);
547
548 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
549 "Data file successfully written to log file `%s'\n", filename);
550 GNUNET_free (filename);
551 }
489} 552}
490 553
491 554
492void 555void
493collect_log_now(void) 556collect_log_now (void)
494{ 557{
495 struct LoggingPeer *bp; 558 struct LoggingPeer *bp;
496 struct PeerLoggingTimestep *mlt; 559 struct PeerLoggingTimestep *mlt;
@@ -508,143 +571,150 @@ collect_log_now(void)
508 return; 571 return;
509 572
510 for (c_m = 0; c_m < num_peers; c_m++) 573 for (c_m = 0; c_m < num_peers; c_m++)
574 {
575 bp = &lp[c_m];
576 mlt = GNUNET_new (struct PeerLoggingTimestep);
577 GNUNET_CONTAINER_DLL_insert_tail (bp->head, bp->tail, mlt);
578 prev_log_mlt = mlt->prev;
579
580 /* Collect data */
581
582 /* Current master state */
583 mlt->timestamp = GNUNET_TIME_absolute_get ();
584 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
585 mlt->total_messages_sent = bp->peer->total_messages_sent;
586 mlt->total_bytes_received = bp->peer->total_bytes_received;
587 mlt->total_messages_received = bp->peer->total_messages_received;
588
589 /* Throughput */
590 if (NULL == prev_log_mlt)
591 {
592 /* Get difference to start */
593 delta = GNUNET_TIME_absolute_get_difference (lp[c_m].start,
594 mlt->timestamp);
595 }
596 else
511 { 597 {
512 bp = &lp[c_m]; 598 /* Get difference to last timestep */
513 mlt = GNUNET_new(struct PeerLoggingTimestep); 599 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp,
514 GNUNET_CONTAINER_DLL_insert_tail(bp->head, bp->tail, mlt); 600 mlt->timestamp);
515 prev_log_mlt = mlt->prev; 601 }
516 602
517 /* Collect data */ 603 /* Multiplication factor for throughput calculation */
604 mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
518 605
519 /* Current master state */ 606 /* Total throughput */
520 mlt->timestamp = GNUNET_TIME_absolute_get(); 607 if (NULL != prev_log_mlt)
521 mlt->total_bytes_sent = bp->peer->total_bytes_sent; 608 {
522 mlt->total_messages_sent = bp->peer->total_messages_sent; 609 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
523 mlt->total_bytes_received = bp->peer->total_bytes_received; 610 mlt->total_throughput_send = mult * (mlt->total_bytes_sent
524 mlt->total_messages_received = bp->peer->total_messages_received; 611 - mlt->prev->total_bytes_sent);
612 else
613 mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
525 614
526 /* Throughput */ 615 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
527 if (NULL == prev_log_mlt) 616 mlt->total_throughput_recv = mult * (mlt->total_bytes_received
528 { 617 - mlt->prev->total_bytes_received);
529 /* Get difference to start */
530 delta = GNUNET_TIME_absolute_get_difference(lp[c_m].start, mlt->timestamp);
531 }
532 else 618 else
533 { 619 mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
534 /* Get difference to last timestep */ 620 }
535 delta = GNUNET_TIME_absolute_get_difference(mlt->prev->timestamp, mlt->timestamp); 621 else
536 } 622 {
623 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
624 mlt->total_throughput_send = mult * mlt->total_bytes_received;
625 }
537 626
538 /* Multiplication factor for throughput calculation */ 627 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners
539 mult = (1.0 * 1000 * 1000) / (delta.rel_value_us); 628 * sizeof(struct PartnerLoggingTimestep));
540 629
541 /* Total throughput */ 630 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
631 {
632 p = &bp->peer->partners[c_s];
633 slt = &mlt->slaves_log[c_s];
634
635 slt->slave = p->dest;
636 /* Bytes sent from master to this slave */
637 slt->total_bytes_sent = p->bytes_sent;
638 /* Messages sent from master to this slave */
639 slt->total_messages_sent = p->messages_sent;
640 /* Bytes master received from this slave */
641 slt->total_bytes_received = p->bytes_received;
642 /* Messages master received from this slave */
643 slt->total_messages_received = p->messages_received;
644 slt->total_app_rtt = p->total_app_rtt;
645 /* ats performance information */
646 slt->ats_cost_lan = p->ats_cost_lan;
647 slt->ats_cost_wan = p->ats_cost_wan;
648 slt->ats_cost_wlan = p->ats_cost_wlan;
649 slt->ats_delay = p->ats_delay;
650 slt->ats_distance = p->ats_distance;
651 slt->ats_network_type = p->ats_network_type;
652 slt->ats_utilization_down = p->ats_utilization_down;
653 slt->ats_utilization_up = p->ats_utilization_up;
654 slt->bandwidth_in = p->bandwidth_in;
655 slt->bandwidth_out = p->bandwidth_out;
656
657 /* Total application level rtt */
658 if (NULL == prev_log_mlt)
659 {
660 if (0 != slt->total_messages_sent)
661 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
662 else
663 app_rtt = 0;
664 }
665 else
666 {
667 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
668 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
669 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt)
670 / (slt->total_messages_sent
671 - prev_log_slt->total_messages_sent);
672 else
673 app_rtt = prev_log_slt->app_rtt; /* No messages were */
674 }
675 slt->app_rtt = app_rtt;
676
677 /* Partner throughput */
542 if (NULL != prev_log_mlt) 678 if (NULL != prev_log_mlt)
543 { 679 {
544 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0) 680 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
545 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent); 681 if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
546 else 682 slt->throughput_sent = mult * (slt->total_bytes_sent
547 mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */ 683 - prev_log_slt->total_bytes_sent);
548 684 else
549 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0) 685 slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
550 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received); 686
551 else 687 if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
552 mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */ 688 slt->throughput_recv = mult * (slt->total_bytes_received
553 } 689 - prev_log_slt->total_bytes_received);
690 else
691 slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
692 }
554 else 693 else
555 { 694 {
556 mlt->total_throughput_send = mult * mlt->total_bytes_sent; 695 slt->throughput_sent = mult * slt->total_bytes_sent;
557 mlt->total_throughput_send = mult * mlt->total_bytes_received; 696 slt->throughput_sent = mult * slt->total_bytes_received;
558 } 697 }
559 698
560 mlt->slaves_log = GNUNET_malloc(bp->peer->num_partners * 699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 sizeof(struct PartnerLoggingTimestep)); 700 "Master [%u]: slave [%u]\n",
562 701 bp->peer->no, p->dest->no);
563 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
564 {
565 p = &bp->peer->partners[c_s];
566 slt = &mlt->slaves_log[c_s];
567
568 slt->slave = p->dest;
569 /* Bytes sent from master to this slave */
570 slt->total_bytes_sent = p->bytes_sent;
571 /* Messages sent from master to this slave */
572 slt->total_messages_sent = p->messages_sent;
573 /* Bytes master received from this slave */
574 slt->total_bytes_received = p->bytes_received;
575 /* Messages master received from this slave */
576 slt->total_messages_received = p->messages_received;
577 slt->total_app_rtt = p->total_app_rtt;
578 /* ats performance information */
579 slt->ats_cost_lan = p->ats_cost_lan;
580 slt->ats_cost_wan = p->ats_cost_wan;
581 slt->ats_cost_wlan = p->ats_cost_wlan;
582 slt->ats_delay = p->ats_delay;
583 slt->ats_distance = p->ats_distance;
584 slt->ats_network_type = p->ats_network_type;
585 slt->ats_utilization_down = p->ats_utilization_down;
586 slt->ats_utilization_up = p->ats_utilization_up;
587 slt->bandwidth_in = p->bandwidth_in;
588 slt->bandwidth_out = p->bandwidth_out;
589
590 /* Total application level rtt */
591 if (NULL == prev_log_mlt)
592 {
593 if (0 != slt->total_messages_sent)
594 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
595 else
596 app_rtt = 0;
597 }
598 else
599 {
600 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
601 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
602 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
603 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
604 else
605 app_rtt = prev_log_slt->app_rtt; /* No messages were */
606 }
607 slt->app_rtt = app_rtt;
608
609 /* Partner throughput */
610 if (NULL != prev_log_mlt)
611 {
612 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
613 if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
614 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
615 else
616 slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
617
618 if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
619 slt->throughput_recv = mult * (slt->total_bytes_received - prev_log_slt->total_bytes_received);
620 else
621 slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
622 }
623 else
624 {
625 slt->throughput_sent = mult * slt->total_bytes_sent;
626 slt->throughput_sent = mult * slt->total_bytes_received;
627 }
628
629 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
630 "Master [%u]: slave [%u]\n",
631 bp->peer->no, p->dest->no);
632 }
633 } 702 }
703 }
634} 704}
635 705
636static void 706static void
637collect_log_task(void *cls) 707collect_log_task (void *cls)
638{ 708{
639 log_task = NULL; 709 log_task = NULL;
640 collect_log_now(); 710 collect_log_now ();
641 log_task = GNUNET_SCHEDULER_add_delayed(frequency, 711 log_task = GNUNET_SCHEDULER_add_delayed (frequency,
642 &collect_log_task, NULL); 712 &collect_log_task, NULL);
643} 713}
644 714
645 715
646void 716void
647perf_logging_stop() 717perf_logging_stop ()
648{ 718{
649 int c_m; 719 int c_m;
650 struct PeerLoggingTimestep *cur; 720 struct PeerLoggingTimestep *cur;
@@ -653,54 +723,55 @@ perf_logging_stop()
653 return; 723 return;
654 724
655 if (NULL != log_task) 725 if (NULL != log_task)
656 { 726 {
657 GNUNET_SCHEDULER_cancel(log_task); 727 GNUNET_SCHEDULER_cancel (log_task);
658 log_task = NULL; 728 log_task = NULL;
659 } 729 }
660 collect_log_task(NULL); 730 collect_log_task (NULL);
661 731
662 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 732 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
663 _("Stop logging\n")); 733 _ ("Stop logging\n"));
664 734
665 write_to_file(); 735 write_to_file ();
666 736
667 for (c_m = 0; c_m < num_peers; c_m++) 737 for (c_m = 0; c_m < num_peers; c_m++)
738 {
739 while (NULL != (cur = lp[c_m].head))
668 { 740 {
669 while (NULL != (cur = lp[c_m].head)) 741 GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
670 { 742 GNUNET_free (cur->slaves_log);
671 GNUNET_CONTAINER_DLL_remove(lp[c_m].head, lp[c_m].tail, cur); 743 GNUNET_free (cur);
672 GNUNET_free(cur->slaves_log);
673 GNUNET_free(cur);
674 }
675 } 744 }
745 }
676 746
677 GNUNET_free(lp); 747 GNUNET_free (lp);
678} 748}
679 749
680 750
681void 751void
682perf_logging_start(struct GNUNET_TIME_Relative log_frequency, 752perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
683 char * testname, struct BenchmarkPeer *masters, int num_masters) 753 char *testname, struct BenchmarkPeer *masters, int
754 num_masters)
684{ 755{
685 int c_m; 756 int c_m;
686 757
687 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 758 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
688 _("Start logging `%s'\n"), testname); 759 _ ("Start logging `%s'\n"), testname);
689 760
690 num_peers = num_masters; 761 num_peers = num_masters;
691 name = testname; 762 name = testname;
692 frequency = log_frequency; 763 frequency = log_frequency;
693 764
694 lp = GNUNET_malloc(num_masters * sizeof(struct LoggingPeer)); 765 lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer));
695 766
696 for (c_m = 0; c_m < num_masters; c_m++) 767 for (c_m = 0; c_m < num_masters; c_m++)
697 { 768 {
698 lp[c_m].peer = &masters[c_m]; 769 lp[c_m].peer = &masters[c_m];
699 lp[c_m].start = GNUNET_TIME_absolute_get(); 770 lp[c_m].start = GNUNET_TIME_absolute_get ();
700 } 771 }
701 772
702 /* Schedule logging task */ 773 /* Schedule logging task */
703 log_task = GNUNET_SCHEDULER_add_now(&collect_log_task, NULL); 774 log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
704 running = GNUNET_YES; 775 running = GNUNET_YES;
705} 776}
706/* end of file perf_ats_logging.c */ 777/* end of file perf_ats_logging.c */