diff options
Diffstat (limited to 'src/ats-tests/gnunet-solver-eval.c')
-rw-r--r-- | src/ats-tests/gnunet-solver-eval.c | 1244 |
1 files changed, 629 insertions, 615 deletions
diff --git a/src/ats-tests/gnunet-solver-eval.c b/src/ats-tests/gnunet-solver-eval.c index cb1946448..b5e00bd6f 100644 --- a/src/ats-tests/gnunet-solver-eval.c +++ b/src/ats-tests/gnunet-solver-eval.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013 GNUnet e.V. | 3 | Copyright (C) 2010-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -34,29 +34,35 @@ | |||
34 | * Experiments | 34 | * Experiments |
35 | */ | 35 | */ |
36 | const char * | 36 | const char * |
37 | print_op (enum OperationType op) | 37 | print_op(enum OperationType op) |
38 | { | 38 | { |
39 | switch (op) { | 39 | switch (op) |
40 | { | ||
40 | case START_SEND: | 41 | case START_SEND: |
41 | return "START_SEND"; | 42 | return "START_SEND"; |
43 | |||
42 | case STOP_SEND: | 44 | case STOP_SEND: |
43 | return "STOP_SEND"; | 45 | return "STOP_SEND"; |
46 | |||
44 | case START_PREFERENCE: | 47 | case START_PREFERENCE: |
45 | return "START_PREFERENCE"; | 48 | return "START_PREFERENCE"; |
49 | |||
46 | case STOP_PREFERENCE: | 50 | case STOP_PREFERENCE: |
47 | return "STOP_PREFERENCE"; | 51 | return "STOP_PREFERENCE"; |
52 | |||
48 | default: | 53 | default: |
49 | break; | 54 | break; |
50 | } | 55 | } |
51 | return ""; | 56 | return ""; |
52 | } | 57 | } |
53 | 58 | ||
54 | 59 | ||
55 | static struct Experiment * | 60 | static struct Experiment * |
56 | create_experiment () | 61 | create_experiment() |
57 | { | 62 | { |
58 | struct Experiment *e; | 63 | struct Experiment *e; |
59 | e = GNUNET_new (struct Experiment); | 64 | |
65 | e = GNUNET_new(struct Experiment); | ||
60 | e->name = NULL; | 66 | e->name = NULL; |
61 | e->num_masters = 0; | 67 | e->num_masters = 0; |
62 | e->num_slaves = 0; | 68 | e->num_slaves = 0; |
@@ -67,7 +73,7 @@ create_experiment () | |||
67 | 73 | ||
68 | 74 | ||
69 | static void | 75 | static void |
70 | free_experiment (struct Experiment *e) | 76 | free_experiment(struct Experiment *e) |
71 | { | 77 | { |
72 | struct Episode *cur; | 78 | struct Episode *cur; |
73 | struct Episode *next; | 79 | struct Episode *next; |
@@ -76,28 +82,28 @@ free_experiment (struct Experiment *e) | |||
76 | 82 | ||
77 | next = e->start; | 83 | next = e->start; |
78 | for (cur = next; NULL != cur; cur = next) | 84 | for (cur = next; NULL != cur; cur = next) |
79 | { | ||
80 | next = cur->next; | ||
81 | |||
82 | next_o = cur->head; | ||
83 | for (cur_o = next_o; NULL != cur_o; cur_o = next_o) | ||
84 | { | 85 | { |
85 | next_o = cur_o->next; | 86 | next = cur->next; |
86 | GNUNET_free (cur_o); | 87 | |
88 | next_o = cur->head; | ||
89 | for (cur_o = next_o; NULL != cur_o; cur_o = next_o) | ||
90 | { | ||
91 | next_o = cur_o->next; | ||
92 | GNUNET_free(cur_o); | ||
93 | } | ||
94 | GNUNET_free(cur); | ||
87 | } | 95 | } |
88 | GNUNET_free (cur); | ||
89 | } | ||
90 | 96 | ||
91 | GNUNET_free_non_null (e->name); | 97 | GNUNET_free_non_null(e->name); |
92 | GNUNET_free_non_null (e->cfg_file); | 98 | GNUNET_free_non_null(e->cfg_file); |
93 | GNUNET_free (e); | 99 | GNUNET_free(e); |
94 | } | 100 | } |
95 | 101 | ||
96 | 102 | ||
97 | static int | 103 | static int |
98 | load_episode (struct Experiment *e, | 104 | load_episode(struct Experiment *e, |
99 | struct Episode *cur, | 105 | struct Episode *cur, |
100 | struct GNUNET_CONFIGURATION_Handle *cfg) | 106 | struct GNUNET_CONFIGURATION_Handle *cfg) |
101 | { | 107 | { |
102 | struct GNUNET_ATS_TEST_Operation *o; | 108 | struct GNUNET_ATS_TEST_Operation *o; |
103 | char *sec_name; | 109 | char *sec_name; |
@@ -106,284 +112,285 @@ load_episode (struct Experiment *e, | |||
106 | char *type; | 112 | char *type; |
107 | char *pref; | 113 | char *pref; |
108 | int op_counter = 0; | 114 | int op_counter = 0; |
109 | fprintf (stderr, "Parsing episode %u\n",cur->id); | 115 | |
116 | fprintf(stderr, "Parsing episode %u\n", cur->id); | ||
110 | GNUNET_asprintf(&sec_name, "episode-%u", cur->id); | 117 | GNUNET_asprintf(&sec_name, "episode-%u", cur->id); |
111 | 118 | ||
112 | while (1) | 119 | 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, op_name, &op)) | ||
118 | { | ||
119 | GNUNET_free (op_name); | ||
120 | break; | ||
121 | } | ||
122 | o = GNUNET_new (struct GNUNET_ATS_TEST_Operation); | ||
123 | /* operations = set_rate, start_send, stop_send, set_preference */ | ||
124 | if (0 == strcmp (op, "start_send")) | ||
125 | { | ||
126 | o->type = START_SEND; | ||
127 | } | ||
128 | else if (0 == strcmp (op, "stop_send")) | ||
129 | { | ||
130 | o->type = STOP_SEND; | ||
131 | } | ||
132 | else if (0 == strcmp (op, "start_preference")) | ||
133 | { | ||
134 | o->type = START_PREFERENCE; | ||
135 | } | ||
136 | else if (0 == strcmp (op, "stop_preference")) | ||
137 | { | ||
138 | o->type = STOP_PREFERENCE; | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", | ||
143 | op_counter, op, cur->id); | ||
144 | GNUNET_free (op); | ||
145 | GNUNET_free (op_name); | ||
146 | GNUNET_free (sec_name); | ||
147 | GNUNET_free (o); | ||
148 | return GNUNET_SYSERR; | ||
149 | } | ||
150 | GNUNET_free (op_name); | ||
151 | |||
152 | /* Get source */ | ||
153 | GNUNET_asprintf(&op_name, "op-%u-src", op_counter); | ||
154 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | ||
155 | sec_name, op_name, &o->src_id)) | ||
156 | { | ||
157 | fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", | ||
158 | op_counter, op, cur->id); | ||
159 | GNUNET_free (op); | ||
160 | GNUNET_free (op_name); | ||
161 | GNUNET_free (sec_name); | ||
162 | GNUNET_free (o); | ||
163 | return GNUNET_SYSERR; | ||
164 | } | ||
165 | if (o->src_id > (e->num_masters - 1)) | ||
166 | { | ||
167 | fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", | ||
168 | o->src_id, 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 | GNUNET_free (op_name); | ||
176 | |||
177 | /* Get destination */ | ||
178 | GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); | ||
179 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | ||
180 | sec_name, op_name, &o->dest_id)) | ||
181 | { | 120 | { |
182 | fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", | 121 | /* Load operation */ |
183 | op_counter, op, cur->id); | 122 | GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); |
184 | GNUNET_free (op); | 123 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
185 | GNUNET_free (op_name); | 124 | sec_name, op_name, &op)) |
186 | GNUNET_free (sec_name); | 125 | { |
187 | GNUNET_free (o); | 126 | GNUNET_free(op_name); |
188 | return GNUNET_SYSERR; | 127 | break; |
189 | } | 128 | } |
190 | if (o->dest_id > (e->num_slaves - 1)) | 129 | o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); |
191 | { | 130 | /* operations = set_rate, start_send, stop_send, set_preference */ |
192 | fprintf (stderr, | 131 | if (0 == strcmp(op, "start_send")) |
193 | "Invalid destination %llu in operation %u `%s' in episode %u\n", | 132 | { |
194 | o->dest_id, | 133 | o->type = START_SEND; |
195 | op_counter, | 134 | } |
196 | op, | 135 | else if (0 == strcmp(op, "stop_send")) |
197 | cur->id); | 136 | { |
198 | GNUNET_free (op); | 137 | o->type = STOP_SEND; |
199 | GNUNET_free (op_name); | 138 | } |
200 | GNUNET_free (sec_name); | 139 | else if (0 == strcmp(op, "start_preference")) |
201 | GNUNET_free (o); | 140 | { |
202 | return GNUNET_SYSERR; | 141 | o->type = START_PREFERENCE; |
203 | } | 142 | } |
204 | GNUNET_free (op_name); | 143 | else if (0 == strcmp(op, "stop_preference")) |
205 | 144 | { | |
206 | GNUNET_asprintf(&op_name, "op-%u-type", op_counter); | 145 | o->type = STOP_PREFERENCE; |
207 | if ( (GNUNET_SYSERR != | 146 | } |
208 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
209 | sec_name, | ||
210 | op_name, | ||
211 | &type)) && | ||
212 | (STOP_SEND != o->type) && | ||
213 | (STOP_PREFERENCE != o->type) ) | ||
214 | { | ||
215 | /* Load arguments for set_rate, start_send, set_preference */ | ||
216 | if (0 == strcmp (type, "constant")) | ||
217 | { | ||
218 | o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; | ||
219 | } | ||
220 | else if (0 == strcmp (type, "linear")) | ||
221 | { | ||
222 | o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; | ||
223 | } | ||
224 | else if (0 == strcmp (type, "sinus")) | ||
225 | { | ||
226 | o->gen_type = GNUNET_ATS_TEST_TG_SINUS; | ||
227 | } | ||
228 | else if (0 == strcmp (type, "random")) | ||
229 | { | ||
230 | o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; | ||
231 | } | ||
232 | else | 147 | else |
233 | { | ||
234 | fprintf (stderr, "Invalid type %u `%s' in episode %u\n", | ||
235 | op_counter, op, cur->id); | ||
236 | GNUNET_free (type); | ||
237 | GNUNET_free (op); | ||
238 | GNUNET_free (op_name); | ||
239 | GNUNET_free (sec_name); | ||
240 | GNUNET_free (o); | ||
241 | return GNUNET_SYSERR; | ||
242 | } | ||
243 | GNUNET_free (op_name); | ||
244 | |||
245 | /* Get base rate */ | ||
246 | GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); | ||
247 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | ||
248 | sec_name, op_name, &o->base_rate)) | ||
249 | { | ||
250 | fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n", | ||
251 | op_counter, op, cur->id); | ||
252 | GNUNET_free (type); | ||
253 | GNUNET_free (op); | ||
254 | GNUNET_free (op_name); | ||
255 | GNUNET_free (sec_name); | ||
256 | GNUNET_free (o); | ||
257 | return GNUNET_SYSERR; | ||
258 | } | ||
259 | GNUNET_free (op_name); | ||
260 | |||
261 | /* Get max rate */ | ||
262 | GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); | ||
263 | if (GNUNET_SYSERR == | ||
264 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
265 | sec_name, | ||
266 | op_name, | ||
267 | &o->max_rate)) | ||
268 | { | ||
269 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || | ||
270 | (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || | ||
271 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) | ||
272 | { | 148 | { |
273 | fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n", | 149 | fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", |
274 | op_counter, op, cur->id); | 150 | op_counter, op, cur->id); |
275 | GNUNET_free (type); | 151 | GNUNET_free(op); |
276 | GNUNET_free (op_name); | 152 | GNUNET_free(op_name); |
277 | GNUNET_free (op); | 153 | GNUNET_free(sec_name); |
278 | GNUNET_free (sec_name); | 154 | GNUNET_free(o); |
279 | GNUNET_free (o); | ||
280 | return GNUNET_SYSERR; | 155 | return GNUNET_SYSERR; |
281 | } | 156 | } |
282 | } | 157 | GNUNET_free(op_name); |
283 | GNUNET_free (op_name); | 158 | |
284 | 159 | /* Get source */ | |
285 | /* Get period */ | 160 | GNUNET_asprintf(&op_name, "op-%u-src", op_counter); |
286 | GNUNET_asprintf(&op_name, "op-%u-period", op_counter); | 161 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
287 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | 162 | sec_name, op_name, &o->src_id)) |
288 | sec_name, op_name, &o->period)) | 163 | { |
289 | { | 164 | fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", |
290 | o->period = cur->duration; | ||
291 | } | ||
292 | GNUNET_free (op_name); | ||
293 | |||
294 | if (START_PREFERENCE == o->type) | ||
295 | { | ||
296 | /* Get frequency */ | ||
297 | GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); | ||
298 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | ||
299 | sec_name, op_name, &o->frequency)) | ||
300 | { | ||
301 | fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n", | ||
302 | op_counter, op, cur->id); | 165 | op_counter, op, cur->id); |
303 | GNUNET_free (type); | 166 | GNUNET_free(op); |
304 | GNUNET_free (op_name); | 167 | GNUNET_free(op_name); |
305 | GNUNET_free (op); | 168 | GNUNET_free(sec_name); |
306 | GNUNET_free (sec_name); | 169 | GNUNET_free(o); |
307 | GNUNET_free (o); | 170 | return GNUNET_SYSERR; |
308 | return GNUNET_SYSERR; | 171 | } |
309 | } | 172 | if (o->src_id > (e->num_masters - 1)) |
310 | GNUNET_free (op_name); | 173 | { |
311 | 174 | fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", | |
312 | /* Get preference */ | 175 | o->src_id, op_counter, op, cur->id); |
313 | GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); | 176 | GNUNET_free(op); |
314 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 177 | GNUNET_free(op_name); |
315 | sec_name, op_name, &pref)) | 178 | GNUNET_free(sec_name); |
316 | { | 179 | GNUNET_free(o); |
317 | fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n", | 180 | return GNUNET_SYSERR; |
181 | } | ||
182 | GNUNET_free(op_name); | ||
183 | |||
184 | /* Get destination */ | ||
185 | GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); | ||
186 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, | ||
187 | sec_name, op_name, &o->dest_id)) | ||
188 | { | ||
189 | fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", | ||
318 | op_counter, op, cur->id); | 190 | op_counter, op, cur->id); |
319 | GNUNET_free (type); | 191 | GNUNET_free(op); |
320 | GNUNET_free (op_name); | 192 | GNUNET_free(op_name); |
321 | GNUNET_free (op); | 193 | GNUNET_free(sec_name); |
322 | GNUNET_free (sec_name); | 194 | GNUNET_free(o); |
323 | GNUNET_free_non_null (pref); | 195 | return GNUNET_SYSERR; |
324 | GNUNET_free (o); | 196 | } |
325 | return GNUNET_SYSERR; | 197 | if (o->dest_id > (e->num_slaves - 1)) |
326 | } | 198 | { |
199 | fprintf(stderr, | ||
200 | "Invalid destination %llu in operation %u `%s' in episode %u\n", | ||
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); | ||
327 | 212 | ||
328 | if (0 == strcmp(pref, "bandwidth")) | 213 | GNUNET_asprintf(&op_name, "op-%u-type", op_counter); |
329 | o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH; | 214 | if ((GNUNET_SYSERR != |
330 | else if (0 == strcmp(pref, "latency")) | 215 | GNUNET_CONFIGURATION_get_value_string(cfg, |
331 | o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY; | 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 | } | ||
332 | else | 239 | else |
333 | { | 240 | { |
334 | fprintf (stderr, | 241 | fprintf(stderr, "Invalid type %u `%s' in episode %u\n", |
335 | "Invalid preference in operation %u `%s' in episode %u\n", | 242 | op_counter, op, cur->id); |
336 | op_counter, | 243 | GNUNET_free(type); |
337 | op, | 244 | GNUNET_free(op); |
338 | cur->id); | 245 | GNUNET_free(op_name); |
339 | GNUNET_free (type); | 246 | GNUNET_free(sec_name); |
340 | GNUNET_free (op_name); | 247 | GNUNET_free(o); |
341 | GNUNET_free (op); | ||
342 | GNUNET_free (sec_name); | ||
343 | GNUNET_free_non_null (pref); | ||
344 | GNUNET_free (o); | ||
345 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
346 | } | 249 | } |
347 | GNUNET_free (pref); | 250 | GNUNET_free(op_name); |
348 | GNUNET_free (op_name); | 251 | |
349 | } | 252 | /* Get base rate */ |
350 | } | 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 | } | ||
351 | 358 | ||
352 | /* Safety checks */ | 359 | /* Safety checks */ |
353 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || | 360 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || |
354 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) | 361 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) |
355 | { | 362 | { |
356 | if ((o->max_rate - o->base_rate) > o->base_rate) | 363 | if ((o->max_rate - o->base_rate) > o->base_rate) |
357 | { | 364 | { |
358 | /* This will cause an underflow */ | 365 | /* This will cause an underflow */ |
359 | GNUNET_break (0); | 366 | GNUNET_break(0); |
360 | } | 367 | } |
361 | fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n"); | 368 | fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n"); |
362 | } | 369 | } |
363 | 370 | ||
364 | if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) | 371 | if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) |
365 | fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", | 372 | fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", |
366 | op_counter, cur->id, print_op (o->type), o->src_id, | 373 | op_counter, cur->id, print_op(o->type), o->src_id, |
367 | o->dest_id, (NULL != type) ? type : "", | 374 | o->dest_id, (NULL != type) ? type : "", |
368 | o->base_rate, o->max_rate, | 375 | o->base_rate, o->max_rate, |
369 | GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES)); | 376 | GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES)); |
370 | else | 377 | else |
371 | fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", | 378 | fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", |
372 | op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id); | 379 | op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id); |
373 | 380 | ||
374 | GNUNET_free_non_null (type); | 381 | GNUNET_free_non_null(type); |
375 | GNUNET_free (op); | 382 | GNUNET_free(op); |
376 | 383 | ||
377 | GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o); | 384 | GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o); |
378 | op_counter++; | 385 | op_counter++; |
379 | } | 386 | } |
380 | GNUNET_free (sec_name); | 387 | GNUNET_free(sec_name); |
381 | 388 | ||
382 | return GNUNET_OK; | 389 | return GNUNET_OK; |
383 | } | 390 | } |
384 | 391 | ||
385 | static int | 392 | static int |
386 | load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) | 393 | load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) |
387 | { | 394 | { |
388 | int e_counter = 0; | 395 | int e_counter = 0; |
389 | char *sec_name; | 396 | char *sec_name; |
@@ -394,438 +401,446 @@ load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
394 | e_counter = 0; | 401 | e_counter = 0; |
395 | last = NULL; | 402 | last = NULL; |
396 | while (1) | 403 | while (1) |
397 | { | ||
398 | GNUNET_asprintf(&sec_name, "episode-%u", e_counter); | ||
399 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, | ||
400 | sec_name, "duration", &e_duration)) | ||
401 | { | 404 | { |
402 | GNUNET_free (sec_name); | 405 | GNUNET_asprintf(&sec_name, "episode-%u", e_counter); |
403 | break; | 406 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
404 | } | 407 | sec_name, "duration", &e_duration)) |
408 | { | ||
409 | GNUNET_free(sec_name); | ||
410 | break; | ||
411 | } | ||
405 | 412 | ||
406 | cur = GNUNET_new (struct Episode); | 413 | cur = GNUNET_new(struct Episode); |
407 | cur->duration = e_duration; | 414 | cur->duration = e_duration; |
408 | cur->id = e_counter; | 415 | cur->id = e_counter; |
409 | 416 | ||
410 | if (GNUNET_OK != load_episode (e, cur, cfg)) | 417 | if (GNUNET_OK != load_episode(e, cur, cfg)) |
411 | { | 418 | { |
412 | GNUNET_free (sec_name); | 419 | GNUNET_free(sec_name); |
413 | GNUNET_free (cur); | 420 | GNUNET_free(cur); |
414 | return GNUNET_SYSERR; | 421 | return GNUNET_SYSERR; |
415 | } | 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 | |||
428 | /* Update experiment */ | ||
429 | e->num_episodes++; | ||
430 | e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); | ||
431 | /* Put in linked list */ | ||
432 | if (NULL == last) | ||
433 | e->start = cur; | ||
434 | else | ||
435 | last->next = cur; | ||
416 | 436 | ||
417 | fprintf (stderr, "Found episode %u with duration %s \n", | 437 | GNUNET_free(sec_name); |
418 | e_counter, | 438 | e_counter++; |
419 | GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); | 439 | last = cur; |
420 | 440 | } | |
421 | /* Update experiment */ | ||
422 | e->num_episodes ++; | ||
423 | e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); | ||
424 | /* Put in linked list */ | ||
425 | if (NULL == last) | ||
426 | e->start = cur; | ||
427 | else | ||
428 | last->next = cur; | ||
429 | |||
430 | GNUNET_free (sec_name); | ||
431 | e_counter ++; | ||
432 | last = cur; | ||
433 | } | ||
434 | return e_counter; | 441 | return e_counter; |
435 | } | 442 | } |
436 | 443 | ||
437 | 444 | ||
438 | static void | 445 | static void |
439 | timeout_experiment (void *cls) | 446 | timeout_experiment(void *cls) |
440 | { | 447 | { |
441 | struct Experiment *e = cls; | 448 | struct Experiment *e = cls; |
449 | |||
442 | e->experiment_timeout_task = NULL; | 450 | e->experiment_timeout_task = NULL; |
443 | fprintf (stderr, "Experiment timeout!\n"); | 451 | fprintf(stderr, "Experiment timeout!\n"); |
444 | 452 | ||
445 | if (NULL != e->episode_timeout_task) | 453 | if (NULL != e->episode_timeout_task) |
446 | { | 454 | { |
447 | GNUNET_SCHEDULER_cancel (e->episode_timeout_task); | 455 | GNUNET_SCHEDULER_cancel(e->episode_timeout_task); |
448 | e->episode_timeout_task = NULL; | 456 | e->episode_timeout_task = NULL; |
449 | } | 457 | } |
450 | 458 | ||
451 | e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), | 459 | e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), |
452 | GNUNET_SYSERR); | 460 | GNUNET_SYSERR); |
453 | } | 461 | } |
454 | 462 | ||
455 | 463 | ||
456 | static void | 464 | static void |
457 | enforce_start_send (struct GNUNET_ATS_TEST_Operation *op) | 465 | enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) |
458 | { | 466 | { |
459 | /* | 467 | /* |
460 | struct BenchmarkPeer *peer; | 468 | struct BenchmarkPeer *peer; |
461 | struct BenchmarkPartner *partner; | 469 | struct BenchmarkPartner *partner; |
462 | 470 | ||
463 | peer = GNUNET_ATS_TEST_get_peer (op->src_id); | 471 | peer = GNUNET_ATS_TEST_get_peer (op->src_id); |
464 | if (NULL == peer) | 472 | if (NULL == peer) |
465 | { | 473 | { |
466 | GNUNET_break (0); | 474 | GNUNET_break (0); |
467 | return; | 475 | return; |
468 | } | 476 | } |
469 | 477 | ||
470 | partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); | 478 | partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); |
471 | if (NULL == partner) | 479 | if (NULL == partner) |
472 | { | 480 | { |
473 | GNUNET_break (0); | 481 | GNUNET_break (0); |
474 | return; | 482 | return; |
475 | } | 483 | } |
476 | 484 | ||
477 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); | 485 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); |
478 | 486 | ||
479 | if (NULL != partner->tg) | 487 | if (NULL != partner->tg) |
480 | { | 488 | { |
481 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id); | 489 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id); |
482 | GNUNET_ATS_TEST_generate_traffic_stop(partner->tg); | 490 | GNUNET_ATS_TEST_generate_traffic_stop(partner->tg); |
483 | partner->tg = NULL; | 491 | partner->tg = NULL; |
484 | } | 492 | } |
485 | 493 | ||
486 | partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner, | 494 | partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner, |
487 | op->tg_type, op->base_rate, op->max_rate, op->period, | 495 | op->tg_type, op->base_rate, op->max_rate, op->period, |
488 | GNUNET_TIME_UNIT_FOREVER_REL); | 496 | GNUNET_TIME_UNIT_FOREVER_REL); |
489 | */ | 497 | */ |
490 | } | 498 | } |
491 | 499 | ||
492 | static void | 500 | static void |
493 | enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op) | 501 | enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) |
494 | { | 502 | { |
495 | /* | 503 | /* |
496 | struct BenchmarkPartner *p; | 504 | struct BenchmarkPartner *p; |
497 | p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); | 505 | p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); |
498 | if (NULL == p) | 506 | if (NULL == p) |
499 | { | 507 | { |
500 | GNUNET_break (0); | 508 | GNUNET_break (0); |
501 | return; | 509 | return; |
502 | } | 510 | } |
503 | 511 | ||
504 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); | 512 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); |
505 | 513 | ||
506 | if (NULL != p->tg) | 514 | if (NULL != p->tg) |
507 | { | 515 | { |
508 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", | 516 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", |
509 | op->src_id, op->dest_id); | 517 | op->src_id, op->dest_id); |
510 | GNUNET_ATS_TEST_generate_traffic_stop(p->tg); | 518 | GNUNET_ATS_TEST_generate_traffic_stop(p->tg); |
511 | p->tg = NULL; | 519 | p->tg = NULL; |
512 | } | 520 | } |
513 | */ | 521 | */ |
514 | } | 522 | } |
515 | 523 | ||
516 | 524 | ||
517 | static void | 525 | static void |
518 | enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) | 526 | enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) |
519 | { | 527 | { |
520 | /* | 528 | /* |
521 | struct BenchmarkPeer *peer; | 529 | struct BenchmarkPeer *peer; |
522 | struct BenchmarkPartner *partner; | 530 | struct BenchmarkPartner *partner; |
523 | 531 | ||
524 | peer = GNUNET_ATS_TEST_get_peer (op->src_id); | 532 | peer = GNUNET_ATS_TEST_get_peer (op->src_id); |
525 | if (NULL == peer) | 533 | if (NULL == peer) |
526 | { | 534 | { |
527 | GNUNET_break (0); | 535 | GNUNET_break (0); |
528 | return; | 536 | return; |
529 | } | 537 | } |
530 | 538 | ||
531 | partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); | 539 | partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); |
532 | if (NULL == partner) | 540 | if (NULL == partner) |
533 | { | 541 | { |
534 | GNUNET_break (0); | 542 | GNUNET_break (0); |
535 | return; | 543 | return; |
536 | } | 544 | } |
537 | 545 | ||
538 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); | 546 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); |
539 | 547 | ||
540 | if (NULL != partner->pg) | 548 | if (NULL != partner->pg) |
541 | { | 549 | { |
542 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", | 550 | fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", |
543 | op->src_id, op->dest_id); | 551 | op->src_id, op->dest_id); |
544 | GNUNET_ATS_TEST_generate_preferences_stop(partner->pg); | 552 | GNUNET_ATS_TEST_generate_preferences_stop(partner->pg); |
545 | partner->pg = NULL; | 553 | partner->pg = NULL; |
546 | } | 554 | } |
547 | 555 | ||
548 | partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner, | 556 | partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner, |
549 | op->tg_type, op->base_rate, op->max_rate, op->period, op->frequency, | 557 | op->tg_type, op->base_rate, op->max_rate, op->period, op->frequency, |
550 | op->pref_type); | 558 | op->pref_type); |
551 | */ | 559 | */ |
552 | } | 560 | } |
553 | 561 | ||
554 | static void | 562 | static void |
555 | enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op) | 563 | enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) |
556 | { | 564 | { |
557 | /* | 565 | /* |
558 | struct BenchmarkPartner *p; | 566 | struct BenchmarkPartner *p; |
559 | p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); | 567 | p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); |
560 | if (NULL == p) | 568 | if (NULL == p) |
561 | { | 569 | { |
562 | GNUNET_break (0); | 570 | GNUNET_break (0); |
563 | return; | 571 | return; |
564 | } | 572 | } |
565 | 573 | ||
566 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); | 574 | fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id); |
567 | 575 | ||
568 | if (NULL != p->pg) | 576 | if (NULL != p->pg) |
569 | { | 577 | { |
570 | fprintf (stderr, "Stopping preference between master %llu slave %llu\n", | 578 | fprintf (stderr, "Stopping preference between master %llu slave %llu\n", |
571 | op->src_id, op->dest_id); | 579 | op->src_id, op->dest_id); |
572 | GNUNET_ATS_TEST_generate_preferences_stop (p->pg); | 580 | GNUNET_ATS_TEST_generate_preferences_stop (p->pg); |
573 | p->pg = NULL; | 581 | p->pg = NULL; |
574 | } | 582 | } |
575 | */ | 583 | */ |
576 | } | 584 | } |
577 | 585 | ||
578 | static void enforce_episode (struct Episode *ep) | 586 | static void enforce_episode(struct Episode *ep) |
579 | { | 587 | { |
580 | struct GNUNET_ATS_TEST_Operation *cur; | 588 | struct GNUNET_ATS_TEST_Operation *cur; |
589 | |||
581 | for (cur = ep->head; NULL != cur; cur = cur->next) | 590 | for (cur = ep->head; NULL != cur; cur = cur->next) |
582 | { | 591 | { |
592 | fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", | ||
593 | print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate); | ||
594 | switch (cur->type) | ||
595 | { | ||
596 | case START_SEND: | ||
597 | enforce_start_send(cur); | ||
598 | break; | ||
599 | |||
600 | case STOP_SEND: | ||
601 | enforce_stop_send(cur); | ||
602 | break; | ||
583 | 603 | ||
584 | fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", | 604 | case START_PREFERENCE: |
585 | print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate); | 605 | enforce_start_preference(cur); |
586 | switch (cur->type) { | 606 | break; |
587 | case START_SEND: | 607 | |
588 | enforce_start_send (cur); | 608 | case STOP_PREFERENCE: |
589 | break; | 609 | enforce_stop_preference(cur); |
590 | case STOP_SEND: | 610 | break; |
591 | enforce_stop_send (cur); | 611 | |
592 | break; | 612 | default: |
593 | case START_PREFERENCE: | 613 | break; |
594 | enforce_start_preference (cur); | 614 | } |
595 | break; | ||
596 | case STOP_PREFERENCE: | ||
597 | enforce_stop_preference (cur); | ||
598 | break; | ||
599 | default: | ||
600 | break; | ||
601 | } | 615 | } |
602 | } | ||
603 | } | 616 | } |
604 | 617 | ||
605 | 618 | ||
606 | static void | 619 | static void |
607 | timeout_episode (void *cls) | 620 | timeout_episode(void *cls) |
608 | { | 621 | { |
609 | struct Experiment *e = cls; | 622 | struct Experiment *e = cls; |
623 | |||
610 | e->episode_timeout_task = NULL; | 624 | e->episode_timeout_task = NULL; |
611 | if (NULL != e->ep_done_cb) | 625 | if (NULL != e->ep_done_cb) |
612 | e->ep_done_cb (e->cur); | 626 | e->ep_done_cb(e->cur); |
613 | 627 | ||
614 | /* Scheduling next */ | 628 | /* Scheduling next */ |
615 | e->cur = e->cur->next; | 629 | e->cur = e->cur->next; |
616 | if (NULL == e->cur) | 630 | if (NULL == e->cur) |
617 | { | ||
618 | /* done */ | ||
619 | fprintf (stderr, "Last episode done!\n"); | ||
620 | if (NULL != e->experiment_timeout_task) | ||
621 | { | 631 | { |
622 | GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); | 632 | /* done */ |
623 | e->experiment_timeout_task = NULL; | 633 | fprintf(stderr, "Last episode done!\n"); |
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; | ||
624 | } | 641 | } |
625 | e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK); | ||
626 | return; | ||
627 | } | ||
628 | 642 | ||
629 | fprintf (stderr, "Running episode %u with timeout %s\n", | 643 | fprintf(stderr, "Running episode %u with timeout %s\n", |
630 | e->cur->id, | 644 | e->cur->id, |
631 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); | 645 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); |
632 | enforce_episode(e->cur); | 646 | enforce_episode(e->cur); |
633 | 647 | ||
634 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, | 648 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, |
635 | &timeout_episode, e); | 649 | &timeout_episode, e); |
636 | } | 650 | } |
637 | 651 | ||
638 | 652 | ||
639 | void | 653 | void |
640 | GNUNET_ATS_solvers_experimentation_run (struct Experiment *e, | 654 | GNUNET_ATS_solvers_experimentation_run(struct Experiment *e, |
641 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, | 655 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, |
642 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) | 656 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) |
643 | { | 657 | { |
644 | fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name, | 658 | fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, |
645 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); | 659 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); |
646 | e->e_done_cb = e_done_cb; | 660 | e->e_done_cb = e_done_cb; |
647 | e->ep_done_cb = ep_done_cb; | 661 | e->ep_done_cb = ep_done_cb; |
648 | e->start_time = GNUNET_TIME_absolute_get(); | 662 | e->start_time = GNUNET_TIME_absolute_get(); |
649 | 663 | ||
650 | /* Start total time out */ | 664 | /* Start total time out */ |
651 | e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration, | 665 | e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, |
652 | &timeout_experiment, e); | 666 | &timeout_experiment, e); |
653 | 667 | ||
654 | /* Start */ | 668 | /* Start */ |
655 | e->cur = e->start; | 669 | e->cur = e->start; |
656 | fprintf (stderr, "Running episode %u with timeout %s\n", | 670 | fprintf(stderr, "Running episode %u with timeout %s\n", |
657 | e->cur->id, | 671 | e->cur->id, |
658 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); | 672 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); |
659 | enforce_episode(e->cur); | 673 | enforce_episode(e->cur); |
660 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, | 674 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, |
661 | &timeout_episode, e); | 675 | &timeout_episode, e); |
662 | |||
663 | |||
664 | } | 676 | } |
665 | 677 | ||
666 | 678 | ||
667 | struct Experiment * | 679 | struct Experiment * |
668 | GNUNET_ATS_solvers_experimentation_load (char *filename) | 680 | GNUNET_ATS_solvers_experimentation_load(char *filename) |
669 | { | 681 | { |
670 | struct Experiment *e; | 682 | struct Experiment *e; |
671 | struct GNUNET_CONFIGURATION_Handle *cfg; | 683 | struct GNUNET_CONFIGURATION_Handle *cfg; |
684 | |||
672 | e = NULL; | 685 | e = NULL; |
673 | 686 | ||
674 | cfg = GNUNET_CONFIGURATION_create(); | 687 | cfg = GNUNET_CONFIGURATION_create(); |
675 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename)) | 688 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) |
676 | { | 689 | { |
677 | fprintf (stderr, "Failed to load `%s'\n", filename); | 690 | fprintf(stderr, "Failed to load `%s'\n", filename); |
678 | GNUNET_CONFIGURATION_destroy (cfg); | 691 | GNUNET_CONFIGURATION_destroy(cfg); |
679 | return NULL; | 692 | return NULL; |
680 | } | 693 | } |
681 | 694 | ||
682 | e = create_experiment (); | 695 | e = create_experiment(); |
683 | 696 | ||
684 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", | 697 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", |
685 | "name", &e->name)) | 698 | "name", &e->name)) |
686 | { | 699 | { |
687 | fprintf (stderr, "Invalid %s", "name"); | 700 | fprintf(stderr, "Invalid %s", "name"); |
688 | free_experiment (e); | 701 | free_experiment(e); |
689 | return NULL; | 702 | return NULL; |
690 | } | 703 | } |
691 | else | 704 | else |
692 | fprintf (stderr, "Experiment name: `%s'\n", e->name); | 705 | fprintf(stderr, "Experiment name: `%s'\n", e->name); |
693 | 706 | ||
694 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment", | 707 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", |
695 | "cfg_file", &e->cfg_file)) | 708 | "cfg_file", &e->cfg_file)) |
696 | { | 709 | { |
697 | fprintf (stderr, "Invalid %s", "cfg_file"); | 710 | fprintf(stderr, "Invalid %s", "cfg_file"); |
698 | free_experiment (e); | 711 | free_experiment(e); |
699 | return NULL; | 712 | return NULL; |
700 | } | 713 | } |
701 | else | 714 | else |
702 | fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file); | 715 | fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file); |
703 | 716 | ||
704 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", | 717 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", |
705 | "masters", &e->num_masters)) | 718 | "masters", &e->num_masters)) |
706 | { | 719 | { |
707 | fprintf (stderr, "Invalid %s", "masters"); | 720 | fprintf(stderr, "Invalid %s", "masters"); |
708 | free_experiment (e); | 721 | free_experiment(e); |
709 | return NULL; | 722 | return NULL; |
710 | } | 723 | } |
711 | else | 724 | else |
712 | fprintf (stderr, "Experiment masters: `%llu'\n", | 725 | fprintf(stderr, "Experiment masters: `%llu'\n", |
713 | e->num_masters); | 726 | e->num_masters); |
714 | 727 | ||
715 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", | 728 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", |
716 | "slaves", &e->num_slaves)) | 729 | "slaves", &e->num_slaves)) |
717 | { | 730 | { |
718 | fprintf (stderr, "Invalid %s", "slaves"); | 731 | fprintf(stderr, "Invalid %s", "slaves"); |
719 | free_experiment (e); | 732 | free_experiment(e); |
720 | return NULL; | 733 | return NULL; |
721 | } | 734 | } |
722 | else | 735 | else |
723 | fprintf (stderr, "Experiment slaves: `%llu'\n", | 736 | fprintf(stderr, "Experiment slaves: `%llu'\n", |
724 | e->num_slaves); | 737 | e->num_slaves); |
725 | 738 | ||
726 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", | 739 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", |
727 | "log_freq", &e->log_freq)) | 740 | "log_freq", &e->log_freq)) |
728 | { | 741 | { |
729 | fprintf (stderr, "Invalid %s", "log_freq"); | 742 | fprintf(stderr, "Invalid %s", "log_freq"); |
730 | free_experiment (e); | 743 | free_experiment(e); |
731 | return NULL; | 744 | return NULL; |
732 | } | 745 | } |
733 | else | 746 | else |
734 | fprintf (stderr, "Experiment logging frequency: `%s'\n", | 747 | fprintf(stderr, "Experiment logging frequency: `%s'\n", |
735 | GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES)); | 748 | GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); |
736 | 749 | ||
737 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", | 750 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", |
738 | "max_duration", &e->max_duration)) | 751 | "max_duration", &e->max_duration)) |
739 | { | 752 | { |
740 | fprintf (stderr, "Invalid %s", "max_duration"); | 753 | fprintf(stderr, "Invalid %s", "max_duration"); |
741 | free_experiment (e); | 754 | free_experiment(e); |
742 | return NULL; | 755 | return NULL; |
743 | } | 756 | } |
744 | else | 757 | else |
745 | fprintf (stderr, "Experiment duration: `%s'\n", | 758 | fprintf(stderr, "Experiment duration: `%s'\n", |
746 | GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES)); | 759 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); |
747 | 760 | ||
748 | load_episodes (e, cfg); | 761 | load_episodes(e, cfg); |
749 | fprintf (stderr, "Loaded %u episodes with total duration %s\n", | 762 | fprintf(stderr, "Loaded %u episodes with total duration %s\n", |
750 | e->num_episodes, | 763 | e->num_episodes, |
751 | GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES)); | 764 | GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); |
752 | 765 | ||
753 | GNUNET_CONFIGURATION_destroy (cfg); | 766 | GNUNET_CONFIGURATION_destroy(cfg); |
754 | return e; | 767 | return e; |
755 | } | 768 | } |
756 | 769 | ||
757 | void | 770 | void |
758 | GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e) | 771 | GNUNET_ATS_solvers_experimentation_stop(struct Experiment *e) |
759 | { | 772 | { |
760 | if (NULL != e->experiment_timeout_task) | 773 | if (NULL != e->experiment_timeout_task) |
761 | { | 774 | { |
762 | GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); | 775 | GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); |
763 | e->experiment_timeout_task = NULL; | 776 | e->experiment_timeout_task = NULL; |
764 | } | 777 | } |
765 | if (NULL != e->episode_timeout_task) | 778 | if (NULL != e->episode_timeout_task) |
766 | { | 779 | { |
767 | GNUNET_SCHEDULER_cancel (e->episode_timeout_task); | 780 | GNUNET_SCHEDULER_cancel(e->episode_timeout_task); |
768 | e->episode_timeout_task = NULL; | 781 | e->episode_timeout_task = NULL; |
769 | } | 782 | } |
770 | free_experiment (e); | 783 | free_experiment(e); |
771 | } | 784 | } |
772 | 785 | ||
773 | /** | 786 | /** |
774 | * Solver | 787 | * Solver |
775 | */ | 788 | */ |
776 | 789 | ||
777 | struct GNUNET_ATS_TESTING_SolverHandle | 790 | struct GNUNET_ATS_TESTING_SolverHandle { |
778 | { | ||
779 | char * plugin; | 791 | char * plugin; |
780 | struct GNUNET_ATS_PluginEnvironment env; | 792 | struct GNUNET_ATS_PluginEnvironment env; |
781 | void *solver; | 793 | void *solver; |
782 | }; | 794 | }; |
783 | 795 | ||
784 | enum GNUNET_ATS_Solvers | 796 | enum GNUNET_ATS_Solvers { |
785 | { | ||
786 | GNUNET_ATS_SOLVER_PROPORTIONAL, | 797 | GNUNET_ATS_SOLVER_PROPORTIONAL, |
787 | GNUNET_ATS_SOLVER_MLP, | 798 | GNUNET_ATS_SOLVER_MLP, |
788 | GNUNET_ATS_SOLVER_RIL, | 799 | GNUNET_ATS_SOLVER_RIL, |
789 | }; | 800 | }; |
790 | 801 | ||
791 | void | 802 | void |
792 | GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh) | 803 | GNUNET_ATS_solvers_solver_stop(struct GNUNET_ATS_TESTING_SolverHandle *sh) |
793 | { | 804 | { |
794 | GNUNET_PLUGIN_unload (sh->plugin, sh->solver); | 805 | GNUNET_PLUGIN_unload(sh->plugin, sh->solver); |
795 | GNUNET_free (sh->plugin); | 806 | GNUNET_free(sh->plugin); |
796 | GNUNET_free (sh); | 807 | GNUNET_free(sh); |
797 | } | 808 | } |
798 | 809 | ||
799 | struct GNUNET_ATS_TESTING_SolverHandle * | 810 | struct GNUNET_ATS_TESTING_SolverHandle * |
800 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | 811 | GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type) |
801 | { | 812 | { |
802 | struct GNUNET_ATS_TESTING_SolverHandle *sh; | 813 | struct GNUNET_ATS_TESTING_SolverHandle *sh; |
803 | char * solver_str; | 814 | char * solver_str; |
804 | 815 | ||
805 | switch (type) { | 816 | switch (type) |
817 | { | ||
806 | case GNUNET_ATS_SOLVER_PROPORTIONAL: | 818 | case GNUNET_ATS_SOLVER_PROPORTIONAL: |
807 | solver_str = "proportional"; | 819 | solver_str = "proportional"; |
808 | break; | 820 | break; |
821 | |||
809 | case GNUNET_ATS_SOLVER_MLP: | 822 | case GNUNET_ATS_SOLVER_MLP: |
810 | solver_str = "mlp"; | 823 | solver_str = "mlp"; |
811 | break; | 824 | break; |
825 | |||
812 | case GNUNET_ATS_SOLVER_RIL: | 826 | case GNUNET_ATS_SOLVER_RIL: |
813 | solver_str = "ril"; | 827 | solver_str = "ril"; |
814 | break; | 828 | break; |
829 | |||
815 | default: | 830 | default: |
816 | GNUNET_break (0); | 831 | GNUNET_break(0); |
817 | return NULL; | 832 | return NULL; |
818 | break; | 833 | break; |
819 | } | 834 | } |
820 | 835 | ||
821 | sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle); | 836 | sh = GNUNET_new(struct GNUNET_ATS_TESTING_SolverHandle); |
822 | GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); | 837 | GNUNET_asprintf(&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); |
823 | //sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); | 838 | //sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); |
824 | if (NULL == sh->solver) | 839 | if (NULL == sh->solver) |
825 | { | 840 | { |
826 | fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin); | 841 | fprintf(stderr, "Failed to load solver `%s'\n", sh->plugin); |
827 | exit (1); | 842 | exit(1); |
828 | } | 843 | } |
829 | 844 | ||
830 | return sh; | 845 | return sh; |
831 | } | 846 | } |
@@ -857,56 +872,56 @@ static int opt_plot; | |||
857 | static int opt_verbose; | 872 | static int opt_verbose; |
858 | 873 | ||
859 | static void | 874 | static void |
860 | run (void *cls, char * const *args, const char *cfgfile, | 875 | run(void *cls, char * const *args, const char *cfgfile, |
861 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 876 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
862 | { | 877 | { |
863 | enum GNUNET_ATS_Solvers solver; | 878 | enum GNUNET_ATS_Solvers solver; |
864 | 879 | ||
865 | if (NULL == opt_exp_file) | 880 | if (NULL == opt_exp_file) |
866 | { | 881 | { |
867 | fprintf (stderr, "No experiment given ...\n"); | 882 | fprintf(stderr, "No experiment given ...\n"); |
868 | exit (1); | 883 | exit(1); |
869 | } | 884 | } |
870 | 885 | ||
871 | if (NULL == opt_solver) | 886 | if (NULL == opt_solver) |
872 | { | 887 | { |
873 | fprintf (stderr, "No solver given ...\n"); | 888 | fprintf(stderr, "No solver given ...\n"); |
874 | exit (1); | 889 | exit(1); |
875 | } | 890 | } |
876 | 891 | ||
877 | if (0 == strcmp(opt_solver, "mlp")) | 892 | if (0 == strcmp(opt_solver, "mlp")) |
878 | { | 893 | { |
879 | solver = GNUNET_ATS_SOLVER_MLP; | 894 | solver = GNUNET_ATS_SOLVER_MLP; |
880 | } | 895 | } |
881 | else if (0 == strcmp(opt_solver, "proportional")) | 896 | else if (0 == strcmp(opt_solver, "proportional")) |
882 | { | 897 | { |
883 | solver = GNUNET_ATS_SOLVER_PROPORTIONAL; | 898 | solver = GNUNET_ATS_SOLVER_PROPORTIONAL; |
884 | } | 899 | } |
885 | else if (0 == strcmp(opt_solver, "ril")) | 900 | else if (0 == strcmp(opt_solver, "ril")) |
886 | { | 901 | { |
887 | solver = GNUNET_ATS_SOLVER_RIL; | 902 | solver = GNUNET_ATS_SOLVER_RIL; |
888 | } | 903 | } |
889 | else | 904 | else |
890 | { | 905 | { |
891 | fprintf (stderr, "No solver given ..."); | 906 | fprintf(stderr, "No solver given ..."); |
892 | return; | 907 | return; |
893 | } | 908 | } |
894 | 909 | ||
895 | /* load experiment */ | 910 | /* load experiment */ |
896 | e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file); | 911 | e = GNUNET_ATS_solvers_experimentation_load(opt_exp_file); |
897 | if (NULL == e) | 912 | if (NULL == e) |
898 | { | 913 | { |
899 | fprintf (stderr, "Failed to load experiment ...\n"); | 914 | fprintf(stderr, "Failed to load experiment ...\n"); |
900 | return; | 915 | return; |
901 | } | 916 | } |
902 | 917 | ||
903 | /* load solver */ | 918 | /* load solver */ |
904 | sh = GNUNET_ATS_solvers_solver_start (solver); | 919 | sh = GNUNET_ATS_solvers_solver_start(solver); |
905 | if (NULL == sh) | 920 | if (NULL == sh) |
906 | { | 921 | { |
907 | fprintf (stderr, "Failed to start solver ...\n"); | 922 | fprintf(stderr, "Failed to start solver ...\n"); |
908 | return; | 923 | return; |
909 | } | 924 | } |
910 | 925 | ||
911 | /* start logging */ | 926 | /* start logging */ |
912 | 927 | ||
@@ -923,9 +938,8 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
923 | * @param argv argument values | 938 | * @param argv argument values |
924 | */ | 939 | */ |
925 | int | 940 | int |
926 | main (int argc, char *argv[]) | 941 | main(int argc, char *argv[]) |
927 | { | 942 | { |
928 | |||
929 | opt_exp_file = NULL; | 943 | opt_exp_file = NULL; |
930 | opt_solver = NULL; | 944 | opt_solver = NULL; |
931 | opt_log = GNUNET_NO; | 945 | opt_log = GNUNET_NO; |
@@ -933,31 +947,31 @@ main (int argc, char *argv[]) | |||
933 | 947 | ||
934 | struct GNUNET_GETOPT_CommandLineOption options[] = | 948 | struct GNUNET_GETOPT_CommandLineOption options[] = |
935 | { | 949 | { |
936 | GNUNET_GETOPT_option_string ('s', | 950 | GNUNET_GETOPT_option_string('s', |
937 | "solver", | 951 | "solver", |
938 | NULL, | 952 | NULL, |
939 | gettext_noop ("solver to use"), | 953 | gettext_noop("solver to use"), |
940 | &opt_solver), | 954 | &opt_solver), |
941 | 955 | ||
942 | GNUNET_GETOPT_option_string ('e', | 956 | GNUNET_GETOPT_option_string('e', |
943 | "experiment", | 957 | "experiment", |
944 | NULL, | 958 | NULL, |
945 | gettext_noop ("experiment to use"), | 959 | gettext_noop("experiment to use"), |
946 | &opt_exp_file), | 960 | &opt_exp_file), |
947 | 961 | ||
948 | GNUNET_GETOPT_option_flag ('e', | 962 | GNUNET_GETOPT_option_flag('e', |
949 | "experiment", | 963 | "experiment", |
950 | gettext_noop ("experiment to use"), | 964 | gettext_noop("experiment to use"), |
951 | &opt_verbose), | 965 | &opt_verbose), |
952 | GNUNET_GETOPT_OPTION_END | 966 | GNUNET_GETOPT_OPTION_END |
953 | }; | 967 | }; |
954 | 968 | ||
955 | if (GNUNET_OK != | 969 | if (GNUNET_OK != |
956 | GNUNET_PROGRAM_run (argc, | 970 | GNUNET_PROGRAM_run(argc, |
957 | argv, argv[0], | 971 | argv, argv[0], |
958 | NULL, | 972 | NULL, |
959 | options, | 973 | options, |
960 | &run, argv[0])) | 974 | &run, argv[0])) |
961 | return 1; | 975 | return 1; |
962 | 976 | ||
963 | return 0; | 977 | return 0; |