Logo AND Algorithmique Numérique Distribuée

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