Logo AND Algorithmique Numérique Distribuée

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