Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Getting rid of network_links.
[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_dict_free(&random_data_list);
233   xbt_dict_free(&set_list);
234
235 }
236
237 void STag_surfxml_host(void)
238 {
239   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
240 }
241
242 void ETag_surfxml_host(void)
243 {
244   surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
245 }
246
247 void STag_surfxml_router(void)
248 {
249   surfxml_call_cb_functions(STag_surfxml_router_cb_list);
250 }
251
252 void ETag_surfxml_router(void)
253 {
254   surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
255 }
256
257 void STag_surfxml_link(void)
258 {
259   surfxml_call_cb_functions(STag_surfxml_link_cb_list);
260 }
261
262 void ETag_surfxml_link(void)
263 {
264   surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
265 }
266
267 void STag_surfxml_route(void)
268 {
269   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
270 }
271
272 void ETag_surfxml_route(void)
273 {
274   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
275 }
276
277 void STag_surfxml_link_c_ctn(void)
278 {
279   surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
280 }
281
282 void ETag_surfxml_link_c_ctn(void)
283 {
284   surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
285 }
286
287 void STag_surfxml_process(void)
288 {
289   surfxml_call_cb_functions(STag_surfxml_process_cb_list);
290 }
291
292 void ETag_surfxml_process(void)
293 {
294   surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
295 }
296
297 void STag_surfxml_argument(void)
298 {
299   surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
300 }
301
302 void ETag_surfxml_argument(void)
303 {
304   surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
305 }
306
307 void STag_surfxml_prop(void)
308 {
309   surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
310 }
311 void ETag_surfxml_prop(void)
312 {
313   surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
314 }
315
316 void STag_surfxml_set(void)
317 {
318   surfxml_call_cb_functions(STag_surfxml_set_cb_list);
319 }
320
321 void ETag_surfxml_set(void)
322 {
323   surfxml_call_cb_functions(ETag_surfxml_set_cb_list);
324 }
325
326 void STag_surfxml_foreach(void)
327 {
328   /* Save the current buffer */
329   old_buff = surfxml_bufferstack;
330   surfxml_call_cb_functions(STag_surfxml_foreach_cb_list);
331 }
332
333 void ETag_surfxml_foreach(void)
334
335   surfxml_call_cb_functions(ETag_surfxml_foreach_cb_list);
336
337   /* free the temporary dynar and restore original */
338   xbt_dynar_free(&STag_surfxml_host_cb_list);
339   xbt_dynar_free(&ETag_surfxml_host_cb_list);
340
341   STag_surfxml_host_cb_list = main_STag_surfxml_host_cb_list;
342   ETag_surfxml_host_cb_list = main_ETag_surfxml_host_cb_list;
343
344   /* free the temporary dynar and restore original */
345   xbt_dynar_free(&STag_surfxml_link_cb_list);
346   xbt_dynar_free(&ETag_surfxml_link_cb_list);
347
348   STag_surfxml_link_cb_list = main_STag_surfxml_link_cb_list;
349   ETag_surfxml_link_cb_list = main_ETag_surfxml_link_cb_list;
350
351 }
352
353 void STag_surfxml_route_c_multi(void)
354 {
355   surfxml_call_cb_functions(STag_surfxml_route_c_multi_cb_list);
356 }
357
358 void ETag_surfxml_route_c_multi(void)
359 {
360   surfxml_call_cb_functions(ETag_surfxml_route_c_multi_cb_list);
361 }
362
363 void STag_surfxml_cluster(void)
364 {
365   surfxml_call_cb_functions(STag_surfxml_cluster_cb_list);
366 }
367
368 void ETag_surfxml_cluster(void)
369 {
370   surfxml_call_cb_functions(ETag_surfxml_cluster_cb_list);
371 }
372
373 void STag_surfxml_trace(void)
374 {
375   surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
376 }
377
378 void ETag_surfxml_trace(void)
379 {
380   surfxml_call_cb_functions(ETag_surfxml_trace_cb_list);
381 }
382
383 void STag_surfxml_trace_c_connect(void)
384 {
385   surfxml_call_cb_functions(STag_surfxml_trace_c_connect_cb_list);
386 }
387
388 void ETag_surfxml_trace_c_connect(void)
389 {
390   surfxml_call_cb_functions(ETag_surfxml_trace_c_connect_cb_list);
391 }
392
393 void STag_surfxml_random(void)
394 {
395   surfxml_call_cb_functions(STag_surfxml_random_cb_list);
396 }
397
398 void ETag_surfxml_random(void)
399 {
400   surfxml_call_cb_functions(ETag_surfxml_random_cb_list);
401 }
402
403 void surf_parse_open(const char *file)
404 {
405   static int warned = 0;        /* warn only once */
406   if (!file) {
407     if (!warned) {
408       WARN0
409           ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
410       warned = 1;
411     }
412     return;
413   }
414   if (!surf_input_buffer_stack)
415     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
416   if (!surf_file_to_parse_stack)
417     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
418
419   surf_file_to_parse = surf_fopen(file, "r");
420   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
421   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
422   surf_parse__switch_to_buffer(surf_input_buffer);
423   surf_parse_lineno = 1;
424 }
425
426 void surf_parse_close(void)
427 {
428   if (surf_input_buffer_stack)
429     xbt_dynar_free(&surf_input_buffer_stack);
430   if (surf_file_to_parse_stack)
431     xbt_dynar_free(&surf_file_to_parse_stack);
432
433   if (surf_file_to_parse) {
434     surf_parse__delete_buffer(surf_input_buffer);
435     fclose(surf_file_to_parse);
436   }
437 }
438
439
440 static int _surf_parse(void)
441 {
442   return surf_parse_lex();
443 }
444
445 int_f_void_t surf_parse = _surf_parse;
446
447 void surf_parse_get_double(double *value, const char *string)
448 {
449   int ret = 0;
450
451   ret = sscanf(string, "%lg", value);
452   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
453               surf_parse_lineno, string);
454 }
455
456 void surf_parse_get_int(int *value, const char *string)
457 {
458   int ret = 0;
459
460   ret = sscanf(string, "%d", value);
461   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
462               surf_parse_lineno, string);
463 }
464
465 void surf_parse_get_trace(tmgr_trace_t * trace, const char *string)
466 {
467   if ((!string) || (strcmp(string, "") == 0))
468     *trace = NULL;
469   else
470     *trace = tmgr_trace_new(string);
471 }
472
473 void parse_properties(void)
474 {
475   char *value = NULL;
476
477   if(!current_property_set) current_property_set = xbt_dict_new();
478
479    value = xbt_strdup(A_surfxml_prop_value);  
480    xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
481 }
482
483 void free_string(void *d)
484 {
485   free(*(void**)d);
486 }
487
488 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
489 {
490   xbt_dynar_push(cb_list, &function);
491 }
492
493 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
494 {
495   unsigned int iterator;
496   void_f_void_t fun;
497   xbt_dynar_foreach(cb_list, iterator, fun){
498        DEBUG2("call %p %p",fun,*fun);
499        (*fun)();
500     }
501 }
502
503 void init_data(void)
504 {
505   xbt_dict_free(&route_table);
506   xbt_dynar_free(&route_link_list);
507   route_table = xbt_dict_new();
508
509   route_multi_table = xbt_dict_new();
510   route_multi_elements = xbt_dynar_new(sizeof(char*), NULL);
511   traces_set_list = xbt_dict_new();
512    
513   trace_connect_list_host_avail = xbt_dict_new();
514   trace_connect_list_power = xbt_dict_new();
515   trace_connect_list_link_avail = xbt_dict_new();
516   trace_connect_list_bandwidth = xbt_dict_new();
517   trace_connect_list_latency = xbt_dict_new();
518
519   random_data_list = xbt_dict_new();
520 }
521
522 void parse_platform_file(const char* file)
523 {
524   surf_parse_open(file);
525   xbt_assert1((!(*surf_parse)()), "Parse error in %s", file);
526   surf_parse_close();
527 }
528
529 /* Functions to bypass route, host and link tags. Used by the foreach and route:multi tags */
530
531 static void parse_make_temporary_route(const char *src, const char *dst, int action)
532 {
533   int AX_ptr = 0;
534   surfxml_bufferstack = xbt_new0(char, 2048);
535   
536   A_surfxml_route_action = action;
537   SURFXML_BUFFER_SET(route_src,                     src);
538   SURFXML_BUFFER_SET(route_dst,                     dst);
539 }
540
541 static void parse_change_cpu_data(const char* hostName, const char* surfxml_host_power, const char* surfxml_host_availability,
542                                         const char* surfxml_host_availability_file, const char* surfxml_host_state_file)
543 {
544   int AX_ptr = 0;
545   surfxml_bufferstack = xbt_new0(char, 2048);
546  
547   SURFXML_BUFFER_SET(host_id,                     hostName);
548   SURFXML_BUFFER_SET(host_power,                  surfxml_host_power /*hostPower*/);
549   SURFXML_BUFFER_SET(host_availability,           surfxml_host_availability);
550   SURFXML_BUFFER_SET(host_availability_file,      surfxml_host_availability_file);
551   SURFXML_BUFFER_SET(host_state_file,             surfxml_host_state_file);
552 }
553
554 static void parse_change_link_data(const char* linkName, const char* surfxml_link_bandwidth, const char* surfxml_link_bandwidth_file,
555                                         const char* surfxml_link_latency, const char* surfxml_link_latency_file, const char* surfxml_link_state_file)
556 {
557   int AX_ptr = 0;
558   surfxml_bufferstack = xbt_new0(char, 2048);
559  
560   SURFXML_BUFFER_SET(link_id,                linkName);
561   SURFXML_BUFFER_SET(link_bandwidth,         surfxml_link_bandwidth);
562   SURFXML_BUFFER_SET(link_bandwidth_file,    surfxml_link_bandwidth_file);
563   SURFXML_BUFFER_SET(link_latency,           surfxml_link_latency);
564   SURFXML_BUFFER_SET(link_latency_file,      surfxml_link_latency_file);
565   SURFXML_BUFFER_SET(link_state_file,        surfxml_link_state_file);
566 }
567
568 /**
569 * \brief Restores the original surfxml buffer
570 */
571 static void parse_restore_original_buffer(void)
572 {
573   free(surfxml_bufferstack);
574   surfxml_bufferstack = old_buff;
575 }
576
577 /* Functions for the sets and foreach tags */
578
579 void parse_sets(void)
580 {
581   char *id, *suffix, *prefix, *radical;
582   int start, end;
583   xbt_dynar_t radical_ends;
584   xbt_dynar_t current_set;
585   char *value;
586   int i;
587
588   id = xbt_strdup(A_surfxml_set_id);
589   prefix = xbt_strdup(A_surfxml_set_prefix);
590   suffix = xbt_strdup(A_surfxml_set_suffix);
591   radical = xbt_strdup(A_surfxml_set_radical);
592   
593   xbt_assert1(!xbt_dict_get_or_null(set_list, id),
594               "Set '%s' declared several times in the platform file.",id);  
595   radical_ends = xbt_str_split(radical, "-");
596   xbt_assert1((xbt_dynar_length(radical_ends)==2), "Radical must be in the form lvalue-rvalue! Provided value: %s", radical);
597
598   surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char*));
599   surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char*));
600
601   current_set = xbt_dynar_new(sizeof(char*), NULL);
602
603   
604   for (i=start; i<end; i++) {
605      value = bprintf("%s%d%s", prefix, i, suffix);
606      xbt_dynar_push(current_set, &value);
607   } 
608   
609   xbt_dict_set(set_list, id, current_set, NULL);
610 }
611
612 static const char* surfxml_host_power;
613 static const char* surfxml_host_availability;
614 static const char* surfxml_host_availability_file;
615 static const char* surfxml_host_state_file;
616
617 static void parse_host_foreach(void)
618 {
619   surfxml_host_power = A_surfxml_host_power;
620   surfxml_host_availability = A_surfxml_host_availability;
621   surfxml_host_availability_file = A_surfxml_host_availability_file;
622   surfxml_host_state_file = A_surfxml_host_state_file;
623 }
624
625 static void finalize_host_foreach(void)
626 {
627   xbt_dynar_t names = NULL;
628   unsigned int cpt = 0;
629   char *name;
630   xbt_dict_cursor_t cursor = NULL;
631   char *key,*data; 
632
633   xbt_dict_t cluster_host_props = current_property_set;
634   
635   xbt_assert1((names = xbt_dict_get_or_null(set_list, foreach_set_name)),
636               "Set name '%s' reffered by foreach tag not found.", foreach_set_name);  
637
638   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);
639
640         
641   /* foreach name in set call the main host callback */
642   xbt_dynar_foreach (names, cpt, name) {
643     parse_change_cpu_data(name, surfxml_host_power, surfxml_host_availability,
644                                         surfxml_host_availability_file, surfxml_host_state_file);
645     surfxml_call_cb_functions(main_STag_surfxml_host_cb_list);
646
647     xbt_dict_foreach(cluster_host_props,cursor,key,data) {
648            xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data), free);
649     }
650
651     surfxml_call_cb_functions(main_ETag_surfxml_host_cb_list);
652     free(surfxml_bufferstack);
653   }
654
655   current_property_set = xbt_dict_new();
656
657   surfxml_bufferstack = old_buff;
658   
659 }
660
661 static const char* surfxml_link_bandwidth;
662 static const char* surfxml_link_bandwidth_file;
663 static const char* surfxml_link_latency;
664 static const char* surfxml_link_latency_file;
665 static const char* surfxml_link_state_file;
666
667 static void parse_link_foreach(void)
668 {
669   surfxml_link_bandwidth = A_surfxml_link_bandwidth;
670   surfxml_link_bandwidth_file = A_surfxml_link_bandwidth_file;
671   surfxml_link_latency = A_surfxml_link_latency;
672   surfxml_link_latency_file = A_surfxml_link_latency_file;
673   surfxml_link_state_file = A_surfxml_link_state_file;
674 }
675
676 static void finalize_link_foreach(void)
677 {
678   xbt_dynar_t names = NULL;
679   unsigned int cpt = 0;
680   char *name;
681   xbt_dict_cursor_t cursor = NULL;
682   char *key,*data; 
683
684   xbt_dict_t cluster_link_props = current_property_set;
685
686   xbt_assert1((names = xbt_dict_get_or_null(set_list, foreach_set_name)),
687               "Set name '%s' reffered by foreach tag not found.", foreach_set_name); 
688
689   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);
690
691
692   /* for each name in set call the main link callback */
693   xbt_dynar_foreach (names, cpt, name) {
694     parse_change_link_data(name, surfxml_link_bandwidth, surfxml_link_bandwidth_file,
695                                         surfxml_link_latency, surfxml_link_latency_file, surfxml_link_state_file);
696     surfxml_call_cb_functions(main_STag_surfxml_link_cb_list);
697
698     xbt_dict_foreach(cluster_link_props,cursor,key,data) {
699            xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data), free);
700     }
701
702     surfxml_call_cb_functions(main_ETag_surfxml_link_cb_list);
703    free(surfxml_bufferstack);
704
705   }
706
707   current_property_set = xbt_dict_new();
708
709   surfxml_bufferstack = old_buff;
710 }
711
712 void parse_foreach(void)
713 {
714   /* save the host & link callbacks */
715   main_STag_surfxml_host_cb_list = STag_surfxml_host_cb_list;
716   main_ETag_surfxml_host_cb_list = ETag_surfxml_host_cb_list;
717   main_STag_surfxml_link_cb_list = STag_surfxml_link_cb_list;
718   main_ETag_surfxml_link_cb_list = ETag_surfxml_link_cb_list;
719
720   /* define host & link callbacks to be used only by the foreach tag */
721   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
722   ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
723   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
724   ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
725
726   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_host_foreach);
727   surfxml_add_callback(ETag_surfxml_host_cb_list, &finalize_host_foreach);
728   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_foreach);
729   surfxml_add_callback(ETag_surfxml_link_cb_list, &finalize_link_foreach);
730
731   /* get set name */
732   foreach_set_name = xbt_strdup(A_surfxml_foreach_set_id); 
733 }
734
735 /* Route:multi functions */
736
737 static int route_multi_size=0;
738 static char* src_name, *dst_name;
739 static int is_symmetric_route;
740
741 void parse_route_elem(void)
742 {
743   char *val;
744
745   val = xbt_strdup(A_surfxml_link_c_ctn_id);
746   
747   xbt_dynar_push(route_link_list, &val);
748 }
749
750 void parse_route_multi_set_endpoints(void)
751 {
752   src_name = xbt_strdup(A_surfxml_route_c_multi_src); 
753   dst_name = xbt_strdup(A_surfxml_route_c_multi_dst); 
754   route_action = A_surfxml_route_c_multi_action;
755   is_symmetric_route = A_surfxml_route_c_multi_symmetric;
756   route_multi_size++;
757
758   route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
759 }
760
761 static int contains(xbt_dynar_t list, const char* value)
762 {
763  unsigned int cpt;
764  char * val;
765  xbt_dynar_foreach(list, cpt, val) {
766    if (strcmp(val, value) == 0)
767       return 1;
768   }
769   return 0;
770 }
771
772 /* 
773    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.
774    The decision is based upon the value of action specified in the xml route:multi attribute action
775  */
776 void manage_route(xbt_dict_t routing_table, const char *route_name, int action, int isMultiRoute)
777 {
778   unsigned int cpt;
779   xbt_dynar_t links;
780   char *value;
781
782   /* get already existing list if it exists */
783   links = xbt_dict_get_or_null(routing_table, route_name);
784   DEBUG1("ROUTE: %s", route_name);
785   if (links != NULL) {
786      switch (action) {
787         case A_surfxml_route_action_PREPEND: /* add existing links at the end; route_link_list + links */
788                                     xbt_dynar_foreach(links, cpt, value) {      
789                                        xbt_dynar_push(route_link_list,&value);
790                                     }
791                                     break;
792         case A_surfxml_route_action_POSTPEND: /* add existing links in front; links + route_link_list */ 
793                                     xbt_dynar_foreach(route_link_list, cpt, value) {
794                                        xbt_dynar_push(links,&value);
795                                     }
796                                     route_link_list = links;
797                                     break;
798         case A_surfxml_route_action_OVERRIDE:
799                                     break;
800         default:break;
801      }
802   }
803   /* this is the final route; do not add if name is a set; add only if name is in set list */
804   if (!isMultiRoute){    
805     xbt_dict_set(routing_table, route_name, route_link_list, NULL);
806   }
807 }
808
809 void parse_route_multi_set_route(void)
810 {
811   char* route_name;
812
813   route_name = bprintf("%s#%s#%d#%d#%d", src_name, dst_name, route_action, is_symmetric_route, route_multi_size);
814
815   xbt_dynar_push(route_multi_elements, &route_name);
816
817   /* Add route */
818   xbt_dict_set(route_multi_table, route_name, route_link_list, NULL);
819   /* add symmetric if it is the case */ 
820   if (is_symmetric_route == 1) {
821     char * symmetric_name = bprintf("%s#%s#%d#%d#%d", dst_name, src_name, route_action, !is_symmetric_route, route_multi_size);
822   
823     xbt_dict_set(route_multi_table, symmetric_name, route_link_list, NULL);
824     xbt_dynar_push(route_multi_elements, &symmetric_name);
825     is_symmetric_route = 0;
826   }
827   free(src_name);
828   free(dst_name);
829 }
830
831 static void add_multi_links(const char* src, const char* dst, xbt_dynar_t links, const char* src_name, const char* dst_name)
832 {
833   unsigned int cpt;
834   char* value, *val;
835    parse_make_temporary_route(src_name, dst_name, route_action);
836    surfxml_call_cb_functions(STag_surfxml_route_cb_list);
837    DEBUG2("\tADDING ROUTE: %s -> %s", src_name, dst_name);
838    /* Build link list */ 
839    xbt_dynar_foreach(links, cpt, value) {
840      if (strcmp(value, src) == 0)
841        val =  xbt_strdup(src_name);
842      else if (strcmp(value, dst) == 0)
843        val = xbt_strdup(dst_name);
844      else if (strcmp(value, "$dst") == 0)
845        val = xbt_strdup(dst_name);
846      else if (strcmp(value, "$src") == 0)
847        val = xbt_strdup(src_name);
848      else
849        val = xbt_strdup(value);
850      DEBUG1("\t\tELEMENT: %s", val);
851      xbt_dynar_push(route_link_list, &val);
852    }    
853    surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
854    free(surfxml_bufferstack);
855 }
856
857 static void convert_route_multi_to_routes(void)
858 {
859   xbt_dict_cursor_t cursor_w;
860   int symmetric;
861   unsigned int cpt, cpt2, cursor;
862   char *src_host_name, *dst_host_name, *key, *src, *dst, *val, *key_w, *data_w; 
863   const char* sep="#";
864   xbt_dict_t set;
865   xbt_dynar_t src_names = NULL, dst_names = NULL, links;
866
867   if (!route_multi_elements) return;
868
869   set = cpu_set;
870   DEBUG1("%d", xbt_dict_length(workstation_set));                               
871   if (workstation_set != NULL && xbt_dict_length(workstation_set) > 0)
872      set = workstation_set;
873   
874
875   old_buff = surfxml_bufferstack;
876   /* Get all routes in the exact order they were entered in the platform file */
877   xbt_dynar_foreach(route_multi_elements, cursor, key) {
878      /* Get links for the route */     
879      links = (xbt_dynar_t)xbt_dict_get_or_null(route_multi_table, key);
880      keys = xbt_str_split_str(key, sep);
881      /* Get route ends */
882      src = xbt_dynar_get_as(keys, 0, char*);
883      dst = xbt_dynar_get_as(keys, 1, char*);
884      route_action = atoi(xbt_dynar_get_as(keys, 2, char*));
885      symmetric = atoi(xbt_dynar_get_as(keys, 3, char*));
886
887     /* Create the dynar of src and dst hosts for the new routes */ 
888     /* NOTE: src and dst can be either set names or simple host names */
889     src_names = (xbt_dynar_t)xbt_dict_get_or_null(set_list, src);
890     dst_names = (xbt_dynar_t)xbt_dict_get_or_null(set_list, dst);
891     /* Add to dynar even if they are simple names */
892     if (src_names == NULL) {
893        src_names = xbt_dynar_new(sizeof(char *), &free_string);
894        val = xbt_strdup(src);
895        xbt_dynar_push(src_names, &val);
896        if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
897          THROW3(unknown_error,0,"(In route:multi (%s -> %s) source %s does not exist (not a set or a host)", src, dst, src);
898     }
899     if (dst_names == NULL) {
900        dst_names = xbt_dynar_new(sizeof(char *), &free_string);
901        val = xbt_strdup(dst);
902        if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
903          THROW3(unknown_error,0,"(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)", src, dst, dst);
904        xbt_dynar_push(dst_names, &val);
905     }
906
907     /* Build the routes */
908     DEBUG2("ADDING MULTI ROUTE: %s -> %s", xbt_dynar_get_as(keys, 0, char*), xbt_dynar_get_as(keys, 1, char*));
909     xbt_dynar_foreach(src_names, cpt, src_host_name) {
910       xbt_dynar_foreach(dst_names, cpt2, dst_host_name) {
911         /* If dst is $* then set this route to have its dst point to all hosts */
912         if (strcmp(src_host_name,"$*") != 0 && strcmp(dst_host_name,"$*") == 0){
913                   xbt_dict_foreach(set, cursor_w, key_w, data_w) {
914                           //int n = xbt_dynar_member(src_names, (char*)key_w);
915                             add_multi_links(src, dst, links, src_host_name, key_w);               
916                   }
917         }
918         /* If src is $* then set this route to have its dst point to all hosts */
919         if (strcmp(src_host_name,"$*") == 0 && strcmp(dst_host_name,"$*") != 0){
920                   xbt_dict_foreach(set, cursor_w, key_w, data_w) {
921                      // if (!symmetric || (symmetric && !contains(dst_names, key_w)))
922                         add_multi_links(src, dst, links, key_w, dst_host_name);               
923                 }
924         }
925         /* if none of them are equal to $* */
926         if (strcmp(src_host_name,"$*") != 0 && strcmp(dst_host_name,"$*") != 0) {
927                         add_multi_links(src, dst, links, src_host_name, dst_host_name);               
928         }     
929       }
930     }
931   }  
932   surfxml_bufferstack = old_buff;
933   xbt_dict_free(&route_multi_table);
934   xbt_dynar_free(&route_multi_elements);
935 }
936
937 /* Cluster tag functions */
938
939 void parse_cluster(void)
940 {  
941    static int AX_ptr = 0;
942    static int surfxml_bufferstack_size = 2048;
943  
944    char* cluster_id = A_surfxml_cluster_id;
945    char* cluster_prefix = A_surfxml_cluster_prefix;
946    char* cluster_suffix = A_surfxml_cluster_suffix;
947    char* cluster_radical = A_surfxml_cluster_radical;
948    char* cluster_power = A_surfxml_cluster_power;
949    char* cluster_bw = A_surfxml_cluster_bw;
950    char* cluster_lat = A_surfxml_cluster_lat;
951    char* cluster_bb_bw = A_surfxml_cluster_bb_bw;
952    char* cluster_bb_lat = A_surfxml_cluster_bb_lat;
953  
954    char* saved_buff = surfxml_bufferstack;
955
956    char * backbone_name;
957
958    surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
959
960    /* Make set */
961    SURFXML_BUFFER_SET(set_id, cluster_id);
962    SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
963    SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
964    SURFXML_BUFFER_SET(set_radical, cluster_radical);
965   
966    SURFXML_START_TAG(set);
967    SURFXML_END_TAG(set);
968
969    /* Make foreach */
970    SURFXML_BUFFER_SET(foreach_set_id, cluster_id);
971
972    SURFXML_START_TAG(foreach);
973
974      /* Make host for the foreach */
975      parse_change_cpu_data("$1", cluster_power, "1.0", "", "");
976      A_surfxml_host_state = A_surfxml_host_state_ON;
977
978      SURFXML_START_TAG(host);
979      SURFXML_END_TAG(host);
980
981      /* Make link for the foreach */
982      parse_change_link_data("$1", cluster_bw, "", cluster_lat, "", "");
983      A_surfxml_link_state = A_surfxml_link_state_ON;
984      A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
985  
986      SURFXML_START_TAG(link);
987      SURFXML_END_TAG(link);
988
989    SURFXML_END_TAG(foreach);
990
991    /* Make backbone link */
992    backbone_name = bprintf("%s_bb", cluster_id);
993    parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "", "");
994    A_surfxml_link_state = A_surfxml_link_state_ON;
995    A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
996  
997    SURFXML_START_TAG(link);
998    SURFXML_END_TAG(link);
999
1000    /* Make route multi with the outside world, i.e. cluster->$* */
1001    SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1002    SURFXML_BUFFER_SET(route_c_multi_dst, "$*");
1003    A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1004    A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_OVERRIDE;
1005    
1006    SURFXML_START_TAG(route_c_multi);
1007
1008      SURFXML_BUFFER_SET(link_c_ctn_id, "$src");
1009     
1010      SURFXML_START_TAG(link_c_ctn);
1011      SURFXML_END_TAG(link_c_ctn);
1012
1013    SURFXML_END_TAG(route_c_multi);
1014
1015    /* Make route multi between cluster hosts, i.e. cluster->cluster */
1016    SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1017    SURFXML_BUFFER_SET(route_c_multi_dst, cluster_id);
1018    A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_POSTPEND;
1019    A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1020    
1021    SURFXML_START_TAG(route_c_multi);
1022     
1023      SURFXML_BUFFER_SET(link_c_ctn_id, backbone_name);
1024     
1025      SURFXML_START_TAG(link_c_ctn);
1026      SURFXML_END_TAG(link_c_ctn);
1027     
1028    SURFXML_END_TAG(route_c_multi);
1029
1030
1031    /* Restore buff */
1032    free(surfxml_bufferstack);
1033    surfxml_bufferstack = saved_buff;
1034 }
1035
1036 /* Trace management functions */
1037
1038 static double trace_periodicity = -1.0;
1039 static char* trace_file = NULL;
1040 static char* trace_id;
1041
1042 void parse_trace_init(void)
1043 {
1044    trace_id = strdup(A_surfxml_trace_id);
1045    trace_file = strdup(A_surfxml_trace_file);
1046    surf_parse_get_double(&trace_periodicity, A_surfxml_trace_periodicity);
1047 }
1048
1049 void parse_trace_finalize(void)
1050 {
1051   tmgr_trace_t trace;
1052   if (!trace_file || strcmp(trace_file,"") != 0) {
1053     surf_parse_get_trace(&trace, trace_file);
1054   }
1055   else {
1056     if (strcmp(surfxml_pcdata, "") == 0) trace = NULL;
1057     else
1058       trace = tmgr_trace_new_from_string(trace_id, surfxml_pcdata, trace_periodicity);  
1059   }
1060   xbt_dict_set(traces_set_list, trace_id, (void *)trace, NULL);
1061 }
1062
1063 void parse_trace_c_connect(void)
1064 {
1065    xbt_assert2(xbt_dict_get_or_null(traces_set_list, A_surfxml_trace_c_connect_trace),
1066               "Cannot connect trace %s to %s: trace unknown", A_surfxml_trace_c_connect_trace,A_surfxml_trace_c_connect_element);
1067    
1068    switch (A_surfxml_trace_c_connect_kind) {
1069     case A_surfxml_trace_c_connect_kind_HOST_AVAIL:
1070       xbt_dict_set(trace_connect_list_host_avail, A_surfxml_trace_c_connect_element, xbt_strdup(A_surfxml_trace_c_connect_trace), free);
1071       break;
1072     case A_surfxml_trace_c_connect_kind_POWER:
1073       xbt_dict_set(trace_connect_list_power, A_surfxml_trace_c_connect_element, xbt_strdup(A_surfxml_trace_c_connect_trace), free);
1074       break;
1075     case A_surfxml_trace_c_connect_kind_LINK_AVAIL:
1076       xbt_dict_set(trace_connect_list_link_avail, A_surfxml_trace_c_connect_element, xbt_strdup(A_surfxml_trace_c_connect_trace), free);
1077       break;
1078     case A_surfxml_trace_c_connect_kind_BANDWIDTH:
1079       xbt_dict_set(trace_connect_list_bandwidth, A_surfxml_trace_c_connect_element, xbt_strdup(A_surfxml_trace_c_connect_trace), free);
1080       break;
1081     case A_surfxml_trace_c_connect_kind_LATENCY:
1082       xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_c_connect_element, xbt_strdup(A_surfxml_trace_c_connect_trace), free);
1083       break;
1084     default:
1085       xbt_die("kind of trace unknown");
1086    }   
1087 }
1088
1089 /* Random tag functions */
1090
1091 double get_cpu_power(const char *power)
1092
1093   double power_scale = 0.0;
1094   const char *p, *q;
1095   char *generator;
1096   random_data_t random = NULL; 
1097   /* randomness is inserted like this: power="$rand(my_random)" */
1098   if (((p = strstr(power, "$rand(")) != NULL) && ((q = strstr(power, ")")) != NULL)) {
1099      if (p < q) {
1100        generator = xbt_malloc(q - (p + 6) + 1);
1101        memcpy(generator, p + 6, q - (p + 6)); 
1102        generator[q - (p + 6)] = '\0';
1103        xbt_assert1((random = xbt_dict_get_or_null(random_data_list, generator)),
1104               "Random generator %s undefined", generator);
1105        power_scale = random_generate(random);
1106      }
1107   }
1108   else {
1109     surf_parse_get_double(&power_scale, power);
1110   }
1111   return power_scale;
1112 }
1113
1114 int random_min, random_max, random_mean, random_std_deviation, random_generator;
1115 char *random_id;
1116
1117 void init_randomness(void)
1118 {
1119   random_id = A_surfxml_random_id;
1120   surf_parse_get_int(&random_min, A_surfxml_random_min);
1121   surf_parse_get_int(&random_max, A_surfxml_random_max);
1122   surf_parse_get_int(&random_mean, A_surfxml_random_mean);
1123   surf_parse_get_int(&random_std_deviation, A_surfxml_random_std_deviation);
1124   random_generator = A_surfxml_random_generator;
1125 }
1126
1127 void add_randomness(void)
1128 {
1129    /* If needed aditional properties can be added by using the prop tag */
1130   random_data_t random = random_new(random_generator, 0, random_min, random_max, random_mean, random_std_deviation);
1131    xbt_dict_set(random_data_list, random_id, (void *)random, NULL);
1132 }
1133