Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[From Arnaud Giersch] Fix memory leak when MSG_create_environment() or
[simgrid.git] / src / surf / surfxml_parse.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
15                                 "Logging specific to the SURF parsing module");
16 #undef CLEANUP
17 #include "simgrid_dtd.c"
18
19 /* Initialize the parsing globals */
20 int route_action = 0;
21 xbt_dict_t traces_set_list = NULL;
22 //xbt_dynar_t traces_connect_list = NULL;
23 xbt_dict_t trace_connect_list_host_avail = NULL;
24 xbt_dict_t trace_connect_list_power = NULL;
25 xbt_dict_t trace_connect_list_link_avail = NULL;
26 xbt_dict_t trace_connect_list_bandwidth = NULL;
27 xbt_dict_t trace_connect_list_latency = NULL;
28
29 /* This buffer is used to store the original buffer before substituing it by out own buffer. Usefull for the foreach tag */
30 static xbt_dynar_t surfxml_bufferstack_stack = NULL;
31 int surfxml_bufferstack_size = 2048;
32 static char *old_buff = NULL;
33 static void surf_parse_error(char *msg);
34
35 void surfxml_bufferstack_push(int new)
36 {
37   if (!new)
38     old_buff = surfxml_bufferstack;
39   else {
40     xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
41     surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
42   }
43 }
44
45 void surfxml_bufferstack_pop(int new)
46 {
47   if (!new)
48     surfxml_bufferstack = old_buff;
49   else {
50     free(surfxml_bufferstack);
51     xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
52   }
53 }
54
55 /* Stores the set name reffered to by the foreach tag */
56 static char *foreach_set_name;
57 static xbt_dynar_t main_STag_surfxml_host_cb_list = NULL;
58 static xbt_dynar_t main_STag_surfxml_link_cb_list = NULL;
59
60 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
61 xbt_dynar_t STag_surfxml_platform_cb_list = NULL;
62 xbt_dynar_t ETag_surfxml_platform_cb_list = NULL;
63 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
64 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
65 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
66 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
67 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
68 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
69 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
70 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
71 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL;
72 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL;
73 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
74 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
75 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
76 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
77 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
78 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
79 xbt_dynar_t STag_surfxml_set_cb_list = NULL;
80 xbt_dynar_t ETag_surfxml_set_cb_list = NULL;
81 xbt_dynar_t STag_surfxml_foreach_cb_list = NULL;
82 xbt_dynar_t ETag_surfxml_foreach_cb_list = NULL;
83 xbt_dynar_t STag_surfxml_route_c_multi_cb_list = NULL;
84 xbt_dynar_t ETag_surfxml_route_c_multi_cb_list = NULL;
85 xbt_dynar_t STag_surfxml_cluster_cb_list = NULL;
86 xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL;
87 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
88 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
89 xbt_dynar_t STag_surfxml_trace_c_connect_cb_list = NULL;
90 xbt_dynar_t ETag_surfxml_trace_c_connect_cb_list = NULL;
91 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
92 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
93
94 /* Stores the sets defined in the XML */
95 xbt_dict_t set_list = NULL;
96
97 xbt_dict_t current_property_set = NULL;
98
99 /* For the route:multi tag */
100 xbt_dict_t route_table = NULL;
101 xbt_dict_t route_multi_table = NULL;
102 xbt_dynar_t route_multi_elements = NULL;
103 static xbt_dynar_t route_link_list = NULL;
104 xbt_dynar_t links = NULL;
105 xbt_dynar_t keys = NULL;
106
107 xbt_dict_t random_data_list = NULL;
108
109 static xbt_dynar_t surf_input_buffer_stack = NULL;
110 static xbt_dynar_t surf_file_to_parse_stack = NULL;
111
112 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
113
114 YY_BUFFER_STATE surf_input_buffer;
115 FILE *surf_file_to_parse = NULL;
116
117 static void convert_route_multi_to_routes(void);
118 static void parse_route_elem(void);
119 static void parse_Stag_foreach(void);
120 static void parse_sets(void);
121 static void parse_Stag_route_multi(void);
122 static void parse_Etag_route_multi(void);
123 static void parse_Stag_trace(void);
124 static void parse_Etag_trace(void);
125 static void parse_Stag_trace_c_connect(void);
126 static void init_randomness(void);
127 static void add_randomness(void);
128
129 void surf_parse_free_callbacks(void)
130 {
131   xbt_dynar_free(&STag_surfxml_platform_cb_list);
132   xbt_dynar_free(&ETag_surfxml_platform_cb_list);
133   xbt_dynar_free(&STag_surfxml_host_cb_list);
134   xbt_dynar_free(&ETag_surfxml_host_cb_list);
135   xbt_dynar_free(&STag_surfxml_router_cb_list);
136   xbt_dynar_free(&ETag_surfxml_router_cb_list);
137   xbt_dynar_free(&STag_surfxml_link_cb_list);
138   xbt_dynar_free(&ETag_surfxml_link_cb_list);
139   xbt_dynar_free(&STag_surfxml_route_cb_list);
140   xbt_dynar_free(&ETag_surfxml_route_cb_list);
141   xbt_dynar_free(&STag_surfxml_link_c_ctn_cb_list);
142   xbt_dynar_free(&ETag_surfxml_link_c_ctn_cb_list);
143   xbt_dynar_free(&STag_surfxml_process_cb_list);
144   xbt_dynar_free(&ETag_surfxml_process_cb_list);
145   xbt_dynar_free(&STag_surfxml_argument_cb_list);
146   xbt_dynar_free(&ETag_surfxml_argument_cb_list);
147   xbt_dynar_free(&STag_surfxml_prop_cb_list);
148   xbt_dynar_free(&ETag_surfxml_prop_cb_list);
149   xbt_dynar_free(&STag_surfxml_set_cb_list);
150   xbt_dynar_free(&ETag_surfxml_set_cb_list);
151   xbt_dynar_free(&STag_surfxml_foreach_cb_list);
152   xbt_dynar_free(&ETag_surfxml_foreach_cb_list);
153   xbt_dynar_free(&STag_surfxml_route_c_multi_cb_list);
154   xbt_dynar_free(&ETag_surfxml_route_c_multi_cb_list);
155   xbt_dynar_free(&STag_surfxml_cluster_cb_list);
156   xbt_dynar_free(&ETag_surfxml_cluster_cb_list);
157   xbt_dynar_free(&STag_surfxml_trace_cb_list);
158   xbt_dynar_free(&ETag_surfxml_trace_cb_list);
159   xbt_dynar_free(&STag_surfxml_trace_c_connect_cb_list);
160   xbt_dynar_free(&ETag_surfxml_trace_c_connect_cb_list);
161   xbt_dynar_free(&STag_surfxml_random_cb_list);
162   xbt_dynar_free(&ETag_surfxml_random_cb_list);
163 }
164
165 void surf_parse_reset_parser(void)
166 {
167   surf_parse_free_callbacks();
168   STag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
169   ETag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
170   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
171   ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
172   STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
173   ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
174   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
175   ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
176   STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
177   ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
178   STag_surfxml_link_c_ctn_cb_list =
179     xbt_dynar_new(sizeof(void_f_void_t), NULL);
180   ETag_surfxml_link_c_ctn_cb_list =
181     xbt_dynar_new(sizeof(void_f_void_t), NULL);
182   STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
183   ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
184   STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
185   ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
186   STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
187   ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
188   STag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
189   ETag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
190   STag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
191   ETag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
192   STag_surfxml_route_c_multi_cb_list =
193     xbt_dynar_new(sizeof(void_f_void_t), NULL);
194   ETag_surfxml_route_c_multi_cb_list =
195     xbt_dynar_new(sizeof(void_f_void_t), NULL);
196   STag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
197   ETag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
198   STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
199   ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
200   STag_surfxml_trace_c_connect_cb_list =
201     xbt_dynar_new(sizeof(void_f_void_t), NULL);
202   ETag_surfxml_trace_c_connect_cb_list =
203     xbt_dynar_new(sizeof(void_f_void_t), NULL);
204   STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
205   ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
206 }
207
208 void STag_surfxml_include(void)
209 {
210   xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
211   xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
212
213   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
214   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
215               A_surfxml_include_file);
216   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
217   surf_parse__switch_to_buffer(surf_input_buffer);
218   printf("STAG\n");
219   fflush(NULL);
220 }
221
222 void ETag_surfxml_include(void)
223 {
224   printf("ETAG\n");
225   fflush(NULL);
226   surf_parse__delete_buffer(surf_input_buffer);
227   fclose(surf_file_to_parse);
228   xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
229   xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
230 }
231
232 void STag_surfxml_platform(void)
233 {
234   double version = 0.0;
235
236   sscanf(A_surfxml_platform_version, "%lg", &version);
237
238   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
239               "You're using an ancient XML file. "
240               "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
241               "instead of MBytes, MFlops and seconds. "
242               "A script (surfxml_update.pl) to help you convert your old "
243               "platform files "
244               "is available in the contrib/platform_generation directory "
245               "of the simgrid repository. Please check also out the "
246               "SURF section of the ChangeLog for the 3.1 version. "
247               "Last, do not forget to also update your values for "
248               "the calls to MSG_task_create (if any).");
249   xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n "
250               "You're using an old XML file. "
251               "A script (surfxml_update.pl) to help you convert your old "
252               "platform files "
253               "is available in the contrib/platform_generation directory "
254               "of the simgrid repository.");
255
256   surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
257
258 }
259
260 void ETag_surfxml_platform(void)
261 {
262   convert_route_multi_to_routes();
263
264   surfxml_call_cb_functions(ETag_surfxml_platform_cb_list);
265
266   xbt_dict_free(&random_data_list);
267 }
268
269 void STag_surfxml_host(void)
270 {
271   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
272 }
273
274 void ETag_surfxml_host(void)
275 {
276   surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
277 }
278
279 void STag_surfxml_router(void)
280 {
281   surfxml_call_cb_functions(STag_surfxml_router_cb_list);
282 }
283
284 void ETag_surfxml_router(void)
285 {
286   surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
287 }
288
289 void STag_surfxml_link(void)
290 {
291   surfxml_call_cb_functions(STag_surfxml_link_cb_list);
292 }
293
294 void ETag_surfxml_link(void)
295 {
296   surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
297 }
298
299 void STag_surfxml_route(void)
300 {
301   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
302 }
303
304 void ETag_surfxml_route(void)
305 {
306   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
307 }
308
309 void STag_surfxml_link_c_ctn(void)
310 {
311   surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
312 }
313
314 void ETag_surfxml_link_c_ctn(void)
315 {
316   surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
317 }
318
319 void STag_surfxml_process(void)
320 {
321   surfxml_call_cb_functions(STag_surfxml_process_cb_list);
322 }
323
324 void ETag_surfxml_process(void)
325 {
326   surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
327 }
328
329 void STag_surfxml_argument(void)
330 {
331   surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
332 }
333
334 void ETag_surfxml_argument(void)
335 {
336   surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
337 }
338
339 void STag_surfxml_prop(void)
340 {
341   surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
342 }
343
344 void ETag_surfxml_prop(void)
345 {
346   surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
347 }
348
349 void STag_surfxml_set(void)
350 {
351   surfxml_call_cb_functions(STag_surfxml_set_cb_list);
352 }
353
354 void ETag_surfxml_set(void)
355 {
356   surfxml_call_cb_functions(ETag_surfxml_set_cb_list);
357 }
358
359 void STag_surfxml_foreach(void)
360 {
361   /* Save the current buffer */
362   surfxml_bufferstack_push(0);
363   surfxml_call_cb_functions(STag_surfxml_foreach_cb_list);
364 }
365
366 void ETag_surfxml_foreach(void)
367 {
368   surfxml_call_cb_functions(ETag_surfxml_foreach_cb_list);
369
370   /* free the temporary dynar and restore original */
371   xbt_dynar_free(&STag_surfxml_host_cb_list);
372   STag_surfxml_host_cb_list = main_STag_surfxml_host_cb_list;
373
374   /* free the temporary dynar and restore original */
375   xbt_dynar_free(&STag_surfxml_link_cb_list);
376   STag_surfxml_link_cb_list = main_STag_surfxml_link_cb_list;
377 }
378
379 void STag_surfxml_route_c_multi(void)
380 {
381   surfxml_call_cb_functions(STag_surfxml_route_c_multi_cb_list);
382 }
383
384 void ETag_surfxml_route_c_multi(void)
385 {
386   surfxml_call_cb_functions(ETag_surfxml_route_c_multi_cb_list);
387 }
388
389 void STag_surfxml_cluster(void)
390 {
391   surfxml_call_cb_functions(STag_surfxml_cluster_cb_list);
392 }
393
394 void ETag_surfxml_cluster(void)
395 {
396   surfxml_call_cb_functions(ETag_surfxml_cluster_cb_list);
397 }
398
399 void STag_surfxml_trace(void)
400 {
401   surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
402 }
403
404 void ETag_surfxml_trace(void)
405 {
406   surfxml_call_cb_functions(ETag_surfxml_trace_cb_list);
407 }
408
409 void STag_surfxml_trace_c_connect(void)
410 {
411   surfxml_call_cb_functions(STag_surfxml_trace_c_connect_cb_list);
412 }
413
414 void ETag_surfxml_trace_c_connect(void)
415 {
416   surfxml_call_cb_functions(ETag_surfxml_trace_c_connect_cb_list);
417 }
418
419 void STag_surfxml_random(void)
420 {
421   surfxml_call_cb_functions(STag_surfxml_random_cb_list);
422 }
423
424 void ETag_surfxml_random(void)
425 {
426   surfxml_call_cb_functions(ETag_surfxml_random_cb_list);
427 }
428
429 void surf_parse_open(const char *file)
430 {
431   static int warned = 0;        /* warn only once */
432   if (!file) {
433     if (!warned) {
434       WARN0
435         ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
436       warned = 1;
437     }
438     return;
439   }
440   surf_file_to_parse = surf_fopen(file, "r");
441   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
442
443   if (!surf_input_buffer_stack)
444     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
445   if (!surf_file_to_parse_stack)
446     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
447
448   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
449   surf_parse__switch_to_buffer(surf_input_buffer);
450   surf_parse_lineno = 1;
451 }
452
453 void surf_parse_close(void)
454 {
455   if (surf_input_buffer_stack)
456     xbt_dynar_free(&surf_input_buffer_stack);
457   if (surf_file_to_parse_stack)
458     xbt_dynar_free(&surf_file_to_parse_stack);
459
460   if (surf_file_to_parse) {
461     surf_parse__delete_buffer(surf_input_buffer);
462     fclose(surf_file_to_parse);
463   }
464 }
465
466
467 static int _surf_parse(void)
468 {
469   return surf_parse_lex();
470 }
471
472 int_f_void_t surf_parse = _surf_parse;
473
474 void surf_parse_error(char *msg)
475 {
476   fprintf(stderr, "Parse error on line %d: %s\n", surf_parse_lineno, msg);
477   abort();
478 }
479
480
481 void surf_parse_get_double(double *value, const char *string)
482 {
483   int ret = 0;
484
485   ret = sscanf(string, "%lg", value);
486   if (ret != 1)
487     surf_parse_error(bprintf("%s is not a double", string));
488 }
489
490 void surf_parse_get_int(int *value, const char *string)
491 {
492   int ret = 0;
493
494   ret = sscanf(string, "%d", value);
495   if (ret != 1)
496     surf_parse_error(bprintf("%s is not an integer", string));
497 }
498
499 void parse_properties(void)
500 {
501   char *value = NULL;
502
503   if (!current_property_set)
504     current_property_set = xbt_dict_new();
505
506   value = xbt_strdup(A_surfxml_prop_value);
507   xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
508 }
509
510 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
511 {
512   xbt_dynar_push(cb_list, &function);
513 }
514
515 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
516 {
517   unsigned int iterator;
518   void_f_void_t fun;
519   xbt_dynar_foreach(cb_list, iterator, fun) {
520     (*fun) ();
521   }
522 }
523
524 static void parse_route_set_endpoints(void)
525 {
526   route_link_list = xbt_dynar_new(sizeof(char *), NULL);
527 }
528
529 static void init_data(void)
530 {
531   xbt_dict_free(&route_table);
532   xbt_dynar_free(&route_link_list);
533   route_table = xbt_dict_new();
534
535   if (!surfxml_bufferstack_stack)
536     surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
537   route_multi_table = xbt_dict_new();
538   route_multi_elements = xbt_dynar_new(sizeof(char *), NULL);
539   traces_set_list = xbt_dict_new();
540   if (set_list == NULL)
541     set_list = xbt_dict_new();
542
543   trace_connect_list_host_avail = xbt_dict_new();
544   trace_connect_list_power = xbt_dict_new();
545   trace_connect_list_link_avail = xbt_dict_new();
546   trace_connect_list_bandwidth = xbt_dict_new();
547   trace_connect_list_latency = xbt_dict_new();
548
549   random_data_list = xbt_dict_new();
550   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
551   surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
552   surfxml_add_callback(STag_surfxml_route_cb_list,
553                        &parse_route_set_endpoints);
554   surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
555   surfxml_add_callback(STag_surfxml_route_c_multi_cb_list,
556                        &parse_Stag_route_multi);
557   surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list,
558                        &parse_Etag_route_multi);
559   surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_Stag_foreach);
560   surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace);
561   surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace);
562   surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list,
563                        &parse_Stag_trace_c_connect);
564   surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness);
565   surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness);
566 }
567
568 static void free_data(void)
569 {
570   char *key, *data;
571   xbt_dict_cursor_t cursor = NULL;
572   char *name;
573   unsigned int cpt = 0;
574
575   xbt_dict_foreach(route_table, cursor, key, data) {
576     xbt_dynar_t links = (xbt_dynar_t) data;
577     char *name;
578     unsigned int cpt = 0;
579
580     xbt_dynar_foreach(links, cpt, name) free(name);
581     xbt_dynar_free(&links);
582   }
583   xbt_dict_free(&route_table);
584   route_link_list = NULL;
585
586   xbt_dict_free(&route_multi_table);
587
588   xbt_dynar_foreach(route_multi_elements, cpt, name) free(name);
589   xbt_dynar_free(&route_multi_elements);
590
591   xbt_dict_foreach(set_list, cursor, key, data) {
592     xbt_dynar_t set = (xbt_dynar_t) data;
593
594     xbt_dynar_foreach(set, cpt, name) free(name);
595     xbt_dynar_free(&set);
596   }
597   xbt_dict_free(&set_list);
598
599   xbt_dynar_free(&surfxml_bufferstack_stack);
600
601   xbt_dict_free(&traces_set_list);
602   xbt_dict_free(&trace_connect_list_host_avail);
603   xbt_dict_free(&trace_connect_list_power);
604   xbt_dict_free(&trace_connect_list_link_avail);
605   xbt_dict_free(&trace_connect_list_bandwidth);
606   xbt_dict_free(&trace_connect_list_latency);
607   xbt_dict_free(&traces_set_list);
608 }
609
610 void parse_platform_file(const char *file)
611 {
612   int parse_status;
613   surf_parse_open(file);
614   init_data();
615   parse_status = surf_parse();
616   free_data();
617   surf_parse_close();
618   if (parse_status)
619     xbt_dict_free(&random_data_list);
620   xbt_assert1(!parse_status, "Parse error in %s", file);
621 }
622
623 /* Functions to bypass route tag. Used by the route:multi tag */
624
625 static void parse_make_temporary_route(const char *src, const char *dst,
626                                        int action)
627 {
628   int AX_ptr = 0;
629
630   A_surfxml_route_action = action;
631   SURFXML_BUFFER_SET(route_src, src);
632   SURFXML_BUFFER_SET(route_dst, dst);
633 }
634
635 /* Functions for the sets and foreach tags */
636
637 static void parse_sets(void)
638 {
639   char *id, *suffix, *prefix, *radical;
640   int start, end;
641   xbt_dynar_t radical_elements;
642   xbt_dynar_t radical_ends;
643   xbt_dynar_t current_set;
644   char *value, *groups;
645   int i;
646   unsigned int iter;
647
648   id = xbt_strdup(A_surfxml_set_id);
649   prefix = xbt_strdup(A_surfxml_set_prefix);
650   suffix = xbt_strdup(A_surfxml_set_suffix);
651   radical = xbt_strdup(A_surfxml_set_radical);
652
653   if (xbt_dict_get_or_null(set_list, id))
654     surf_parse_error(bprintf
655                      ("Set '%s' declared several times in the platform file.",
656                       id));
657
658   current_set = xbt_dynar_new(sizeof(char *), NULL);
659
660   radical_elements = xbt_str_split(radical, ",");
661   xbt_dynar_foreach(radical_elements, iter, groups) {
662
663     radical_ends = xbt_str_split(groups, "-");
664     switch (xbt_dynar_length(radical_ends)) {
665     case 1:
666       surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
667       value = bprintf("%s%d%s", prefix, start, suffix);
668       xbt_dynar_push(current_set, &value);
669       break;
670
671     case 2:
672
673       surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
674       surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
675
676
677       for (i = start; i <= end; i++) {
678         value = bprintf("%s%d%s", prefix, i, suffix);
679         xbt_dynar_push(current_set, &value);
680       }
681       break;
682
683     default:
684       surf_parse_error(xbt_strdup("Malformed radical"));
685     }
686
687     xbt_dynar_free(&radical_ends);
688   }
689
690   xbt_dict_set(set_list, id, current_set, NULL);
691
692   xbt_dynar_free(&radical_elements);
693   free(radical);
694   free(suffix);
695   free(prefix);
696   free(id);
697 }
698
699 static void parse_host_foreach(void){
700   xbt_dynar_t names = NULL;
701   unsigned int cpt = 0;
702   char *name;
703   xbt_dict_cursor_t cursor = NULL;
704   char *key, *data;
705
706   const char *surfxml_host_power = A_surfxml_host_power;
707   const char *surfxml_host_availability = A_surfxml_host_availability;
708   const char *surfxml_host_availability_file = A_surfxml_host_availability_file;
709   const char *surfxml_host_state_file = A_surfxml_host_state_file;
710
711
712   xbt_dict_t cluster_host_props = current_property_set;
713
714   names = xbt_dict_get_or_null(set_list, foreach_set_name);
715   if (!names)
716     surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
717                              foreach_set_name));
718   if (strcmp(A_surfxml_host_id, "$1"))
719     surf_parse_error(bprintf
720                      ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
721                       A_surfxml_host_id));
722
723
724   /* foreach name in set call the main host callback */
725   xbt_dynar_foreach(names, cpt, name) {
726     int AX_ptr = 0; /* needed by the SURFXML_BUFFER_SET macro */
727
728     surfxml_bufferstack_push(1);
729
730     SURFXML_BUFFER_SET(host_id, name);
731     SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
732     SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
733     SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
734     SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
735
736     surfxml_call_cb_functions(main_STag_surfxml_host_cb_list);
737
738     xbt_dict_foreach(cluster_host_props, cursor, key, data) {
739       xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
740                    free);
741     }
742
743     /* Call the (unmodified) callbacks of </host>, if any */
744     surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
745     surfxml_bufferstack_pop(1);
746   }
747
748   current_property_set = xbt_dict_new();
749
750   surfxml_bufferstack_pop(0);
751 }
752
753 static void parse_link_foreach(void) {
754   const char *surfxml_link_bandwidth = A_surfxml_link_bandwidth;
755   const char *surfxml_link_bandwidth_file = A_surfxml_link_bandwidth_file;
756   const char *surfxml_link_latency = A_surfxml_link_latency;
757   const char *surfxml_link_latency_file = A_surfxml_link_latency_file;
758   const char *surfxml_link_state_file = A_surfxml_link_state_file;
759
760   xbt_dynar_t names = NULL;
761   unsigned int cpt = 0;
762   char *name;
763   xbt_dict_cursor_t cursor = NULL;
764   char *key, *data;
765
766   xbt_dict_t cluster_link_props = current_property_set;
767
768   names = xbt_dict_get_or_null(set_list, foreach_set_name);
769   if (!names)
770     surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
771                              foreach_set_name));
772   if (strcmp(A_surfxml_link_id, "$1"))
773     surf_parse_error(bprintf
774                      ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
775                       A_surfxml_link_id));
776
777   /* for each name in set call the main link callback */
778   xbt_dynar_foreach(names, cpt, name) {
779     int AX_ptr = 0; /* needed by the SURFXML_BUFFER_SET */
780
781     surfxml_bufferstack_push(1);
782
783     SURFXML_BUFFER_SET(link_id, name);
784     SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
785     SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
786     SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
787     SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
788     SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
789
790     surfxml_call_cb_functions(main_STag_surfxml_link_cb_list);
791
792     xbt_dict_foreach(cluster_link_props, cursor, key, data) {
793       xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
794                    free);
795     }
796
797     /* Call the (unmodified) callbacks of </link>, if any */
798     surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
799     surfxml_bufferstack_pop(1);
800   }
801
802   current_property_set = xbt_dict_new();
803
804   surfxml_bufferstack_pop(0);
805   free(foreach_set_name);
806   foreach_set_name = NULL;
807 }
808
809 static void parse_Stag_foreach(void)
810 {
811   /* save the host & link callbacks */
812   main_STag_surfxml_host_cb_list = STag_surfxml_host_cb_list;
813   main_STag_surfxml_link_cb_list = STag_surfxml_link_cb_list;
814
815   /* redefine host & link callbacks to be used only by the foreach tag */
816   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
817   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
818
819   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_host_foreach);
820   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_foreach);
821
822   /* get set name */
823   foreach_set_name = xbt_strdup(A_surfxml_foreach_set_id);
824 }
825
826 /* Route:multi functions */
827
828 static int route_multi_size = 0;
829 static char *src_name, *dst_name;
830 static int is_symmetric_route;
831
832 static void parse_route_elem(void)
833 {
834   char *val;
835
836   val = xbt_strdup(A_surfxml_link_c_ctn_id);
837
838   xbt_dynar_push(route_link_list, &val);
839   //INFO2("Push %s (size now:%ld)",val,xbt_dynar_length(route_link_list));
840 }
841
842 static void parse_Stag_route_multi(void)
843 {
844   src_name = xbt_strdup(A_surfxml_route_c_multi_src);
845   dst_name = xbt_strdup(A_surfxml_route_c_multi_dst);
846   route_action = A_surfxml_route_c_multi_action;
847   is_symmetric_route = A_surfxml_route_c_multi_symmetric;
848   route_multi_size++;
849
850   route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
851 }
852
853 /*
854    This function is used to append or override the contents of an already existing route in the case a new one with its name is found.
855    The decision is based upon the value of action specified in the xml route:multi attribute action
856  */
857 void manage_route(xbt_dict_t routing_table, const char *route_name,
858                   int action, int isMultiRoute)
859 {
860   unsigned int cpt;
861   xbt_dynar_t links;
862   char *value;
863
864   /* get already existing list if it exists */
865   links = xbt_dict_get_or_null(routing_table, route_name);
866   DEBUG3("ROUTE: %s (action:%s; len:%ld)", route_name,
867       (action==A_surfxml_route_action_OVERRIDE?"override":(
868           action==A_surfxml_route_action_PREPEND?"prepend":"postpend")),
869        (links?xbt_dynar_length(links):0));
870
871   if (links != NULL) {
872     switch (action) {
873     case A_surfxml_route_action_PREPEND:       /* add existing links at the end; route_link_list + links */
874       xbt_dynar_foreach(links, cpt, value) {
875         xbt_dynar_push(route_link_list, &value);
876       }
877       xbt_dynar_free(&links);
878       break;
879     case A_surfxml_route_action_POSTPEND:      /* add existing links in front; links + route_link_list */
880       xbt_dynar_foreach(route_link_list, cpt, value) {
881         xbt_dynar_push(links, &value);
882       }
883       xbt_dynar_free(&route_link_list);
884       route_link_list = links;
885       break;
886     case A_surfxml_route_action_OVERRIDE:
887       xbt_dynar_free(&links);
888       break;
889     default:
890       xbt_die(bprintf("While dealing with routes of %s, got action=%d. Please report this bug.",
891           route_name,action));
892       break;
893     }
894   }
895   /* this is the final route; do not add if name is a set; add only if name is in set list */
896   if (!isMultiRoute) {
897     xbt_dict_set(routing_table, route_name, route_link_list, NULL);
898   }
899 }
900
901 static void parse_Etag_route_multi(void)
902 {
903   char *route_name;
904
905   route_name =
906     bprintf("%s#%s#%d#%d#%d", src_name, dst_name, route_action,
907             is_symmetric_route, route_multi_size);
908
909   xbt_dynar_push(route_multi_elements, &route_name);
910
911   /* Add route */
912   xbt_dict_set(route_multi_table, route_name, route_link_list, NULL);
913   /* add symmetric if it is the case */
914   if (is_symmetric_route == 1) {
915     char *symmetric_name =
916       bprintf("%s#%s#%d#%d#%d", dst_name, src_name, route_action,
917               !is_symmetric_route, route_multi_size);
918
919     xbt_dict_set(route_multi_table, symmetric_name, route_link_list, NULL);
920     xbt_dynar_push(route_multi_elements, &symmetric_name);
921     is_symmetric_route = 0;
922   }
923   free(src_name);
924   free(dst_name);
925 }
926
927 static void add_multi_links(const char *src, const char *dst,
928                             xbt_dynar_t links, const char *src_name,
929                             const char *dst_name)
930 {
931   unsigned int cpt;
932   char *value, *val;
933
934   surfxml_bufferstack_push(1);
935
936   parse_make_temporary_route(src_name, dst_name, route_action);
937   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
938   DEBUG2("\tADDING ROUTE: %s -> %s", src_name, dst_name);
939   /* Build link list */
940   xbt_dynar_foreach(links, cpt, value) {
941     if (strcmp(value, src) == 0)
942       val = xbt_strdup(src_name);
943     else if (strcmp(value, dst) == 0)
944       val = xbt_strdup(dst_name);
945     else if (strcmp(value, "$dst") == 0)
946       val = xbt_strdup(dst_name);
947     else if (strcmp(value, "$src") == 0)
948       val = xbt_strdup(src_name);
949     else
950       val = xbt_strdup(value);
951     DEBUG1("\t\tELEMENT: %s", val);
952     xbt_dynar_push(route_link_list, &val);
953   }
954   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
955   surfxml_bufferstack_pop(1);
956 }
957
958 static void convert_route_multi_to_routes(void)
959 {
960   xbt_dict_cursor_t cursor_w;
961   int symmetric;
962   unsigned int cpt, cpt2, cursor;
963   char *src_host_name, *dst_host_name, *key, *src, *dst, *val, *key_w,
964     *data_w;
965   const char *sep = "#";
966   xbt_dict_t set = NULL;
967   xbt_dynar_t src_names = NULL, dst_names = NULL, links;
968
969   if (!route_multi_elements)
970     return;
971
972   if (surf_cpu_model)
973     set = surf_model_resource_set(surf_cpu_model);
974   if (surf_workstation_model != NULL &&
975       surf_model_resource_set(surf_workstation_model) != NULL &&
976       xbt_dict_length(surf_model_resource_set(surf_workstation_model)) > 0)
977     set = surf_model_resource_set(surf_workstation_model);
978
979
980   surfxml_bufferstack_push(0);
981   /* Get all routes in the exact order they were entered in the platform file */
982   xbt_dynar_foreach(route_multi_elements, cursor, key) {
983     /* Get links for the route */
984     links = (xbt_dynar_t) xbt_dict_get_or_null(route_multi_table, key);
985     keys = xbt_str_split_str(key, sep);
986     /* Get route ends */
987     src = xbt_dynar_get_as(keys, 0, char *);
988     dst = xbt_dynar_get_as(keys, 1, char *);
989     route_action = atoi(xbt_dynar_get_as(keys, 2, char *));
990     symmetric = atoi(xbt_dynar_get_as(keys, 3, char *));
991
992     /* Create the dynar of src and dst hosts for the new routes */
993     /* NOTE: src and dst can be either set names or simple host names */
994     src_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, src);
995     dst_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, dst);
996     /* Add to dynar even if they are simple names */
997     if (src_names == NULL) {
998       src_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
999       val = xbt_strdup(src);
1000       xbt_dynar_push(src_names, &val);
1001       if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1002         THROW3(unknown_error, 0,
1003                "(In route:multi (%s -> %s) source %s does not exist (not a set or a host)",
1004                src, dst, src);
1005     }
1006     if (dst_names == NULL) {
1007       dst_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1008       val = xbt_strdup(dst);
1009       if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1010         THROW3(unknown_error, 0,
1011                "(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)",
1012                src, dst, dst);
1013       xbt_dynar_push(dst_names, &val);
1014     }
1015
1016     /* Build the routes */
1017     DEBUG2("ADDING MULTI ROUTE: %s -> %s", xbt_dynar_get_as(keys, 0, char *),
1018            xbt_dynar_get_as(keys, 1, char *));
1019     xbt_dynar_foreach(src_names, cpt, src_host_name) {
1020       xbt_dynar_foreach(dst_names, cpt2, dst_host_name) {
1021         /* If dst is $* then set this route to have its dst point to all hosts */
1022         if (strcmp(src_host_name, "$*") != 0
1023             && strcmp(dst_host_name, "$*") == 0) {
1024           xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1025             //int n = xbt_dynar_member(src_names, (char*)key_w);
1026             add_multi_links(src, dst, links, src_host_name, key_w);
1027           }
1028         }
1029         /* If src is $* then set this route to have its dst point to all hosts */
1030         if (strcmp(src_host_name, "$*") == 0
1031             && strcmp(dst_host_name, "$*") != 0) {
1032           xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1033             // if (!symmetric || (symmetric && !contains(dst_names, key_w)))
1034             add_multi_links(src, dst, links, key_w, dst_host_name);
1035           }
1036         }
1037         /* if none of them are equal to $* */
1038         if (strcmp(src_host_name, "$*") != 0
1039             && strcmp(dst_host_name, "$*") != 0) {
1040           add_multi_links(src, dst, links, src_host_name, dst_host_name);
1041         }
1042       }
1043     }
1044     xbt_dynar_free(&keys);
1045   }
1046   surfxml_bufferstack_pop(0);
1047 }
1048
1049
1050 /* Trace management functions */
1051
1052 static double trace_periodicity = -1.0;
1053 static char *trace_file = NULL;
1054 static char *trace_id;
1055
1056 static void parse_Stag_trace(void)
1057 {
1058   trace_id = strdup(A_surfxml_trace_id);
1059   trace_file = strdup(A_surfxml_trace_file);
1060   surf_parse_get_double(&trace_periodicity, A_surfxml_trace_periodicity);
1061 }
1062
1063 static void parse_Etag_trace(void)
1064 {
1065   tmgr_trace_t trace;
1066   if (!trace_file || strcmp(trace_file, "") != 0) {
1067     trace = tmgr_trace_new(trace_file);
1068   } else {
1069     if (strcmp(surfxml_pcdata, "") == 0)
1070       trace = NULL;
1071     else
1072       trace =
1073         tmgr_trace_new_from_string(trace_id, surfxml_pcdata,
1074                                    trace_periodicity);
1075   }
1076   xbt_dict_set(traces_set_list, trace_id, (void *) trace, NULL);
1077 }
1078
1079 static void parse_Stag_trace_c_connect(void)
1080 {
1081   xbt_assert2(xbt_dict_get_or_null
1082               (traces_set_list, A_surfxml_trace_c_connect_trace),
1083               "Cannot connect trace %s to %s: trace unknown",
1084               A_surfxml_trace_c_connect_trace,
1085               A_surfxml_trace_c_connect_element);
1086
1087   switch (A_surfxml_trace_c_connect_kind) {
1088   case A_surfxml_trace_c_connect_kind_HOST_AVAIL:
1089     xbt_dict_set(trace_connect_list_host_avail,
1090                  A_surfxml_trace_c_connect_trace,
1091                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1092     break;
1093   case A_surfxml_trace_c_connect_kind_POWER:
1094     xbt_dict_set(trace_connect_list_power, A_surfxml_trace_c_connect_trace,
1095                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1096     break;
1097   case A_surfxml_trace_c_connect_kind_LINK_AVAIL:
1098     xbt_dict_set(trace_connect_list_link_avail,
1099                  A_surfxml_trace_c_connect_trace,
1100                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1101     break;
1102   case A_surfxml_trace_c_connect_kind_BANDWIDTH:
1103     xbt_dict_set(trace_connect_list_bandwidth,
1104                  A_surfxml_trace_c_connect_trace,
1105                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1106     break;
1107   case A_surfxml_trace_c_connect_kind_LATENCY:
1108     xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_c_connect_trace,
1109                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1110     break;
1111   default:
1112     xbt_die(bprintf("Cannot connect trace %s to %s: kind of trace unknown",
1113                     A_surfxml_trace_c_connect_trace,
1114                     A_surfxml_trace_c_connect_element));
1115   }
1116 }
1117
1118 /* Random tag functions */
1119
1120 double get_cpu_power(const char *power)
1121 {
1122   double power_scale = 0.0;
1123   const char *p, *q;
1124   char *generator;
1125   random_data_t random = NULL;
1126   /* randomness is inserted like this: power="$rand(my_random)" */
1127   if (((p = strstr(power, "$rand(")) != NULL)
1128       && ((q = strstr(power, ")")) != NULL)) {
1129     if (p < q) {
1130       generator = xbt_malloc(q - (p + 6) + 1);
1131       memcpy(generator, p + 6, q - (p + 6));
1132       generator[q - (p + 6)] = '\0';
1133       xbt_assert1((random =
1134                    xbt_dict_get_or_null(random_data_list, generator)),
1135                   "Random generator %s undefined", generator);
1136       power_scale = random_generate(random);
1137     }
1138   } else {
1139     surf_parse_get_double(&power_scale, power);
1140   }
1141   return power_scale;
1142 }
1143
1144 double random_min, random_max, random_mean, random_std_deviation,
1145   random_generator;
1146 char *random_id;
1147
1148 static void init_randomness(void)
1149 {
1150   random_id = A_surfxml_random_id;
1151   surf_parse_get_double(&random_min, A_surfxml_random_min);
1152   surf_parse_get_double(&random_max, A_surfxml_random_max);
1153   surf_parse_get_double(&random_mean, A_surfxml_random_mean);
1154   surf_parse_get_double(&random_std_deviation,
1155                         A_surfxml_random_std_deviation);
1156   random_generator = A_surfxml_random_generator;
1157 }
1158
1159 static void add_randomness(void)
1160 {
1161   /* If needed aditional properties can be added by using the prop tag */
1162   random_data_t random =
1163     random_new(random_generator, 0, random_min, random_max, random_mean,
1164                random_std_deviation);
1165   xbt_dict_set(random_data_list, random_id, (void *) random, NULL);
1166 }