Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compilation broken.
[simgrid.git] / src / surf / surfxml_parse.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13 #include "surf/surf.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 int surfxml_bufferstack_size = 2048;
33 static char *old_buff = NULL;
34 static void surf_parse_error(char *msg);
35
36 void surfxml_bufferstack_push(int new)
37 {
38   if (!new)
39     old_buff = surfxml_bufferstack;
40   else {
41     xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
42     surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
43   }
44 }
45
46 void surfxml_bufferstack_pop(int new)
47 {
48   if (!new)
49     surfxml_bufferstack = old_buff;
50   else {
51     free(surfxml_bufferstack);
52     xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
53   }
54 }
55
56 /* Stores the set name reffered to by the foreach tag */
57 static char *foreach_set_name;
58 static xbt_dynar_t main_STag_surfxml_host_cb_list = NULL;
59 static xbt_dynar_t main_STag_surfxml_link_cb_list = NULL;
60
61 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
62 xbt_dynar_t STag_surfxml_platform_cb_list = NULL;
63 xbt_dynar_t ETag_surfxml_platform_cb_list = NULL;
64 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
65 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
66 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
67 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
68 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
69 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
70 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
71 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
72 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL;
73 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL;
74 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
75 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
76 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
77 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
78 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
79 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
80 xbt_dynar_t STag_surfxml_set_cb_list = NULL;
81 xbt_dynar_t ETag_surfxml_set_cb_list = NULL;
82 xbt_dynar_t STag_surfxml_foreach_cb_list = NULL;
83 xbt_dynar_t ETag_surfxml_foreach_cb_list = NULL;
84 xbt_dynar_t STag_surfxml_route_c_multi_cb_list = NULL;
85 xbt_dynar_t ETag_surfxml_route_c_multi_cb_list = NULL;
86 xbt_dynar_t STag_surfxml_cluster_cb_list = NULL;
87 xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL;
88 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
89 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
90 xbt_dynar_t STag_surfxml_trace_c_connect_cb_list = NULL;
91 xbt_dynar_t ETag_surfxml_trace_c_connect_cb_list = NULL;
92 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
93 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
94
95 /* Stores the sets defined in the XML */
96 xbt_dict_t set_list = NULL;
97
98 xbt_dict_t current_property_set = NULL;
99
100 /* For the route:multi tag */
101 xbt_dict_t route_table = NULL;
102 xbt_dict_t route_multi_table = NULL;
103 xbt_dynar_t route_multi_elements = NULL;
104 static xbt_dynar_t route_link_list = NULL;
105 xbt_dynar_t links = NULL;
106 xbt_dynar_t keys = NULL;
107
108 xbt_dict_t random_data_list = NULL;
109
110 static xbt_dynar_t surf_input_buffer_stack = NULL;
111 static xbt_dynar_t surf_file_to_parse_stack = NULL;
112
113 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
114
115 YY_BUFFER_STATE surf_input_buffer;
116 FILE *surf_file_to_parse = NULL;
117
118 static void convert_route_multi_to_routes(void);
119 static void parse_route_elem(void);
120 static void parse_Stag_foreach(void);
121 static void parse_sets(void);
122 static void parse_Stag_route_multi(void);
123 static void parse_Etag_route_multi(void);
124 static void parse_Stag_trace(void);
125 static void parse_Etag_trace(void);
126 static void parse_Stag_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 =
180     xbt_dynar_new(sizeof(void_f_void_t), NULL);
181   ETag_surfxml_link_c_ctn_cb_list =
182     xbt_dynar_new(sizeof(void_f_void_t), NULL);
183   STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
184   ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
185   STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
186   ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
187   STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
188   ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
189   STag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
190   ETag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
191   STag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
192   ETag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
193   STag_surfxml_route_c_multi_cb_list =
194     xbt_dynar_new(sizeof(void_f_void_t), NULL);
195   ETag_surfxml_route_c_multi_cb_list =
196     xbt_dynar_new(sizeof(void_f_void_t), NULL);
197   STag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
198   ETag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
199   STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
200   ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
201   STag_surfxml_trace_c_connect_cb_list =
202     xbt_dynar_new(sizeof(void_f_void_t), NULL);
203   ETag_surfxml_trace_c_connect_cb_list =
204     xbt_dynar_new(sizeof(void_f_void_t), NULL);
205   STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
206   ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
207 }
208
209 void STag_surfxml_include(void)
210 {
211   xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
212   xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
213
214   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
215   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
216               A_surfxml_include_file);
217   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
218   surf_parse__switch_to_buffer(surf_input_buffer);
219   printf("STAG\n");
220   fflush(NULL);
221 }
222
223 void ETag_surfxml_include(void)
224 {
225   printf("ETAG\n");
226   fflush(NULL);
227   surf_parse__delete_buffer(surf_input_buffer);
228   fclose(surf_file_to_parse);
229   xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
230   xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
231 }
232
233 void STag_surfxml_platform(void)
234 {
235   double version = 0.0;
236
237   sscanf(A_surfxml_platform_version, "%lg", &version);
238
239   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
240               "You're using an ancient XML file. "
241               "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
242               "instead of MBytes, MFlops and seconds. "
243               "A script (surfxml_update.pl) to help you convert your old "
244               "platform files "
245               "is available in the contrib/platform_generation directory "
246               "of the simgrid repository. Please check also out the "
247               "SURF section of the ChangeLog for the 3.1 version. "
248               "Last, do not forget to also update your values for "
249               "the calls to MSG_task_create (if any).");
250   xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n "
251               "You're using an old XML file. "
252               "A script (surfxml_update.pl) to help you convert your old "
253               "platform files "
254               "is available in the contrib/platform_generation directory "
255               "of the simgrid repository.");
256
257   surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
258
259 }
260
261 void ETag_surfxml_platform(void)
262 {
263   convert_route_multi_to_routes();
264
265   surfxml_call_cb_functions(ETag_surfxml_platform_cb_list);
266
267   xbt_dict_free(&random_data_list);
268 }
269
270 void STag_surfxml_host(void)
271 {
272   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
273
274 }
275
276 void ETag_surfxml_host(void)
277 {
278   surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
279 }
280
281 void STag_surfxml_router(void)
282 {
283   surfxml_call_cb_functions(STag_surfxml_router_cb_list);
284 }
285
286 void ETag_surfxml_router(void)
287 {
288   surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
289 }
290
291 void STag_surfxml_link(void)
292 {
293   surfxml_call_cb_functions(STag_surfxml_link_cb_list);
294 }
295
296 void ETag_surfxml_link(void)
297 {
298   surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
299 }
300
301 void STag_surfxml_route(void)
302 {
303   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
304 }
305
306 void ETag_surfxml_route(void)
307 {
308   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
309 }
310
311 void STag_surfxml_link_c_ctn(void)
312 {
313   surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
314 }
315
316 void ETag_surfxml_link_c_ctn(void)
317 {
318   surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
319 }
320
321 void STag_surfxml_process(void)
322 {
323   surfxml_call_cb_functions(STag_surfxml_process_cb_list);
324 }
325
326 void ETag_surfxml_process(void)
327 {
328   surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
329 }
330
331 void STag_surfxml_argument(void)
332 {
333   surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
334 }
335
336 void ETag_surfxml_argument(void)
337 {
338   surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
339 }
340
341 void STag_surfxml_prop(void)
342 {
343   surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
344 }
345
346 void ETag_surfxml_prop(void)
347 {
348   surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
349 }
350
351 void STag_surfxml_set(void)
352 {
353   surfxml_call_cb_functions(STag_surfxml_set_cb_list);
354 }
355
356 void ETag_surfxml_set(void)
357 {
358   surfxml_call_cb_functions(ETag_surfxml_set_cb_list);
359 }
360
361 void STag_surfxml_foreach(void)
362 {
363   /* Save the current buffer */
364   surfxml_bufferstack_push(0);
365   surfxml_call_cb_functions(STag_surfxml_foreach_cb_list);
366 }
367
368 void ETag_surfxml_foreach(void)
369 {
370   surfxml_call_cb_functions(ETag_surfxml_foreach_cb_list);
371
372   /* free the temporary dynar and restore original */
373   xbt_dynar_free(&STag_surfxml_host_cb_list);
374   STag_surfxml_host_cb_list = main_STag_surfxml_host_cb_list;
375
376   /* free the temporary dynar and restore original */
377   xbt_dynar_free(&STag_surfxml_link_cb_list);
378   STag_surfxml_link_cb_list = main_STag_surfxml_link_cb_list;
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   surf_file_to_parse = surf_fopen(file, "r");
443   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
444
445   if (!surf_input_buffer_stack)
446     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
447   if (!surf_file_to_parse_stack)
448     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
449
450   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
451   surf_parse__switch_to_buffer(surf_input_buffer);
452   surf_parse_lineno = 1;
453 }
454
455 void surf_parse_close(void)
456 {
457   if (surf_input_buffer_stack)
458     xbt_dynar_free(&surf_input_buffer_stack);
459   if (surf_file_to_parse_stack)
460     xbt_dynar_free(&surf_file_to_parse_stack);
461
462   if (surf_file_to_parse) {
463     surf_parse__delete_buffer(surf_input_buffer);
464     fclose(surf_file_to_parse);
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_error(char *msg)
476 {
477   fprintf(stderr, "Parse error on line %d: %s\n", surf_parse_lineno, msg);
478   abort();
479 }
480
481
482 void surf_parse_get_double(double *value, const char *string)
483 {
484   int ret = 0;
485
486   ret = sscanf(string, "%lg", value);
487   if (ret != 1)
488     surf_parse_error(bprintf("%s is not a double", string));
489 }
490
491 void surf_parse_get_int(int *value, const char *string)
492 {
493   int ret = 0;
494
495   ret = sscanf(string, "%d", value);
496   if (ret != 1)
497     surf_parse_error(bprintf("%s is not an integer", string));
498 }
499
500 void parse_properties(void)
501 {
502   char *value = NULL;
503
504   if (!current_property_set)
505     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     (*fun) ();
522   }
523 }
524
525 static void parse_route_set_endpoints(void)
526 {
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)
542     set_list = xbt_dict_new();
543
544   trace_connect_list_host_avail = xbt_dict_new();
545   trace_connect_list_power = xbt_dict_new();
546   trace_connect_list_link_avail = xbt_dict_new();
547   trace_connect_list_bandwidth = xbt_dict_new();
548   trace_connect_list_latency = xbt_dict_new();
549
550   random_data_list = xbt_dict_new();
551   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
552   surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
553   surfxml_add_callback(STag_surfxml_route_cb_list,
554                        &parse_route_set_endpoints);
555   surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
556   surfxml_add_callback(STag_surfxml_route_c_multi_cb_list,
557                        &parse_Stag_route_multi);
558   surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list,
559                        &parse_Etag_route_multi);
560   surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_Stag_foreach);
561   surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace);
562   surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace);
563   surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list,
564                        &parse_Stag_trace_c_connect);
565   surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness);
566   surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness);
567 }
568
569 static void free_data(void)
570 {
571   char *key, *data;
572   xbt_dict_cursor_t cursor = NULL;
573   char *name;
574   unsigned int cpt = 0;
575
576   xbt_dict_foreach(route_table, cursor, key, data) {
577     xbt_dynar_t links = (xbt_dynar_t) data;
578     char *name;
579     unsigned int cpt = 0;
580
581     xbt_dynar_foreach(links, cpt, name) free(name);
582     xbt_dynar_free(&links);
583   }
584   xbt_dict_free(&route_table);
585   route_link_list = NULL;
586
587   xbt_dict_free(&route_multi_table);
588
589   xbt_dynar_foreach(route_multi_elements, cpt, name) free(name);
590   xbt_dynar_free(&route_multi_elements);
591
592   xbt_dict_foreach(set_list, cursor, key, data) {
593     xbt_dynar_t set = (xbt_dynar_t) data;
594
595     xbt_dynar_foreach(set, cpt, name) free(name);
596     xbt_dynar_free(&set);
597   }
598   xbt_dict_free(&set_list);
599
600   xbt_dynar_free(&surfxml_bufferstack_stack);
601
602   xbt_dict_free(&traces_set_list);
603   xbt_dict_free(&trace_connect_list_host_avail);
604   xbt_dict_free(&trace_connect_list_power);
605   xbt_dict_free(&trace_connect_list_link_avail);
606   xbt_dict_free(&trace_connect_list_bandwidth);
607   xbt_dict_free(&trace_connect_list_latency);
608   xbt_dict_free(&traces_set_list);
609 }
610
611 void parse_platform_file(const char *file)
612 {
613   int parse_status;
614   surf_parse_open(file);
615   init_data();
616   parse_status = surf_parse();
617   free_data();
618   surf_parse_close();
619   if (parse_status)
620     xbt_dict_free(&random_data_list);
621   xbt_assert1(!parse_status, "Parse error in %s", file);
622 }
623
624 /* Functions to bypass route tag. Used by the route:multi tag */
625
626 static void parse_make_temporary_route(const char *src, const char *dst,
627                                        int action)
628 {
629   int AX_ptr = 0;
630
631   A_surfxml_route_action = action;
632   SURFXML_BUFFER_SET(route_src, src);
633   SURFXML_BUFFER_SET(route_dst, dst);
634 }
635
636 /* Functions for the sets and foreach tags */
637
638 static void parse_sets(void)
639 {
640   char *id, *suffix, *prefix, *radical;
641   int start, end;
642   xbt_dynar_t radical_elements;
643   xbt_dynar_t radical_ends;
644   xbt_dynar_t current_set;
645   char *value, *groups;
646   int i;
647   unsigned int iter;
648
649   id = xbt_strdup(A_surfxml_set_id);
650   prefix = xbt_strdup(A_surfxml_set_prefix);
651   suffix = xbt_strdup(A_surfxml_set_suffix);
652   radical = xbt_strdup(A_surfxml_set_radical);
653
654   if (xbt_dict_get_or_null(set_list, id))
655     surf_parse_error(bprintf
656                      ("Set '%s' declared several times in the platform file.",
657                       id));
658
659   current_set = xbt_dynar_new(sizeof(char *), NULL);
660
661   radical_elements = xbt_str_split(radical, ",");
662   xbt_dynar_foreach(radical_elements, iter, groups) {
663
664     radical_ends = xbt_str_split(groups, "-");
665     switch (xbt_dynar_length(radical_ends)) {
666     case 1:
667       surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
668       value = bprintf("%s%d%s", prefix, start, suffix);
669       xbt_dynar_push(current_set, &value);
670       break;
671
672     case 2:
673
674       surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
675       surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
676
677
678       for (i = start; i <= end; i++) {
679         value = bprintf("%s%d%s", prefix, i, suffix);
680         xbt_dynar_push(current_set, &value);
681       }
682       break;
683
684     default:
685       surf_parse_error(xbt_strdup("Malformed radical"));
686     }
687
688     xbt_dynar_free(&radical_ends);
689   }
690
691   xbt_dict_set(set_list, id, current_set, NULL);
692
693   xbt_dynar_free(&radical_elements);
694   free(radical);
695   free(suffix);
696   free(prefix);
697   free(id);
698 }
699
700 static void parse_host_foreach(void){
701
702   xbt_dynar_t names = NULL;
703   unsigned int cpt = 0;
704   char *name;
705   xbt_dict_cursor_t cursor = NULL;
706   char *key, *data;
707
708   const char *surfxml_host_power = A_surfxml_host_power;
709   const char *surfxml_host_availability = A_surfxml_host_availability;
710   const char *surfxml_host_availability_file = A_surfxml_host_availability_file;
711   const char *surfxml_host_state_file = A_surfxml_host_state_file;
712
713   xbt_dict_t cluster_host_props = current_property_set;
714
715   names = xbt_dict_get_or_null(set_list, foreach_set_name);
716   if (!names)
717     surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
718                              foreach_set_name));
719   if (strcmp(A_surfxml_host_id, "$1"))
720     surf_parse_error(bprintf
721                      ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
722                       A_surfxml_host_id));
723
724
725   /* foreach name in set call the main host callback */
726   xbt_dynar_foreach(names, cpt, name) {
727     int AX_ptr = 0; /* needed by the SURFXML_BUFFER_SET macro */
728
729     surfxml_bufferstack_push(1);
730
731     SURFXML_BUFFER_SET(host_id, name);
732     SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
733     SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
734     SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
735     SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
736
737     surfxml_call_cb_functions(main_STag_surfxml_host_cb_list);
738
739     xbt_dict_foreach(cluster_host_props, cursor, key, data) {
740       xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
741                    free);
742     }
743
744     /* Call the (unmodified) callbacks of </host>, if any */
745     surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
746     surfxml_bufferstack_pop(1);
747   }
748
749   current_property_set = xbt_dict_new();
750
751   surfxml_bufferstack_pop(0);
752 }
753
754 static void parse_link_foreach(void) {
755   const char *surfxml_link_bandwidth = A_surfxml_link_bandwidth;
756   const char *surfxml_link_bandwidth_file = A_surfxml_link_bandwidth_file;
757   const char *surfxml_link_latency = A_surfxml_link_latency;
758   const char *surfxml_link_latency_file = A_surfxml_link_latency_file;
759   const char *surfxml_link_state_file = A_surfxml_link_state_file;
760
761   xbt_dynar_t names = NULL;
762   unsigned int cpt = 0;
763   char *name;
764   xbt_dict_cursor_t cursor = NULL;
765   char *key, *data;
766
767   xbt_dict_t cluster_link_props = current_property_set;
768
769   names = xbt_dict_get_or_null(set_list, foreach_set_name);
770   if (!names)
771     surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
772                              foreach_set_name));
773   if (strcmp(A_surfxml_link_id, "$1"))
774     surf_parse_error(bprintf
775                      ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
776                       A_surfxml_link_id));
777
778   /* for each name in set call the main link callback */
779   xbt_dynar_foreach(names, cpt, name) {
780     int AX_ptr = 0; /* needed by the SURFXML_BUFFER_SET */
781
782     surfxml_bufferstack_push(1);
783
784     SURFXML_BUFFER_SET(link_id, name);
785     SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
786     SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
787     SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
788     SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
789     SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
790
791     surfxml_call_cb_functions(main_STag_surfxml_link_cb_list);
792
793     xbt_dict_foreach(cluster_link_props, cursor, key, data) {
794       xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
795                    free);
796     }
797
798     /* Call the (unmodified) callbacks of </link>, if any */
799     surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
800     surfxml_bufferstack_pop(1);
801   }
802
803   current_property_set = xbt_dict_new();
804
805   surfxml_bufferstack_pop(0);
806   free(foreach_set_name);
807   foreach_set_name = NULL;
808 }
809
810 static void parse_Stag_foreach(void)
811 {
812   /* save the host & link callbacks */
813   main_STag_surfxml_host_cb_list = STag_surfxml_host_cb_list;
814   main_STag_surfxml_link_cb_list = STag_surfxml_link_cb_list;
815
816   /* redefine host & link callbacks to be used only by the foreach tag */
817   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
818   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
819
820   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_host_foreach);
821   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_foreach);
822
823   /* get set name */
824   foreach_set_name = xbt_strdup(A_surfxml_foreach_set_id);
825 }
826
827 /* Route:multi functions */
828
829 static int route_multi_size = 0;
830 static char *src_name, *dst_name;
831 static int is_symmetric_route;
832
833 static void parse_route_elem(void)
834 {
835   char *val;
836
837   val = xbt_strdup(A_surfxml_link_c_ctn_id);
838
839   xbt_dynar_push(route_link_list, &val);
840   //INFO2("Push %s (size now:%ld)",val,xbt_dynar_length(route_link_list));
841 }
842
843 static void parse_Stag_route_multi(void)
844 {
845   src_name = xbt_strdup(A_surfxml_route_c_multi_src);
846   dst_name = xbt_strdup(A_surfxml_route_c_multi_dst);
847   route_action = A_surfxml_route_c_multi_action;
848   is_symmetric_route = A_surfxml_route_c_multi_symmetric;
849   route_multi_size++;
850
851   route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
852 }
853
854 /*
855    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.
856    The decision is based upon the value of action specified in the xml route:multi attribute action
857  */
858 void manage_route(xbt_dict_t routing_table, const char *route_name,
859                   int action, int isMultiRoute)
860 {
861   unsigned int cpt;
862   xbt_dynar_t links;
863   char *value;
864
865   /* get already existing list if it exists */
866   links = xbt_dict_get_or_null(routing_table, route_name);
867   DEBUG3("ROUTE: %s (action:%s; len:%ld)", route_name,
868       (action==A_surfxml_route_action_OVERRIDE?"override":(
869           action==A_surfxml_route_action_PREPEND?"prepend":"postpend")),
870        (links?xbt_dynar_length(links):0));
871
872   if (links != NULL) {
873     switch (action) {
874     case A_surfxml_route_action_PREPEND:       /* add existing links at the end; route_link_list + links */
875       xbt_dynar_foreach(links, cpt, value) {
876         xbt_dynar_push(route_link_list, &value);
877       }
878       xbt_dynar_free(&links);
879       break;
880     case A_surfxml_route_action_POSTPEND:      /* add existing links in front; links + route_link_list */
881         xbt_dynar_foreach(route_link_list, cpt, value) {
882         xbt_dynar_push(links, &value);
883       }
884       xbt_dynar_free(&route_link_list);
885       route_link_list = links;
886       break;
887     case A_surfxml_route_action_OVERRIDE:
888       xbt_dynar_free(&links);
889       break;
890     default:
891       xbt_die(bprintf("While dealing with routes of %s, got action=%d. Please report this bug.",
892           route_name,action));
893       break;
894     }
895
896   }
897   /* this is the final route; do not add if name is a set; add only if name is in set list */
898   if (!isMultiRoute) {
899     xbt_dict_set(routing_table, route_name, route_link_list, NULL);
900   }
901 }
902
903 static void parse_Etag_route_multi(void)
904 {
905   char *route_name;
906
907   route_name =
908     bprintf("%s#%s#%d#%d#%d", src_name, dst_name, route_action,
909             is_symmetric_route, route_multi_size);
910
911   xbt_dynar_push(route_multi_elements, &route_name);
912
913   /* Add route */
914   xbt_dict_set(route_multi_table, route_name, route_link_list, NULL);
915   /* add symmetric if it is the case */
916   if (is_symmetric_route == 1) {
917     char *symmetric_name =
918       bprintf("%s#%s#%d#%d#%d", dst_name, src_name, route_action,
919               !is_symmetric_route, route_multi_size);
920
921     xbt_dict_set(route_multi_table, symmetric_name, route_link_list, NULL);
922     xbt_dynar_push(route_multi_elements, &symmetric_name);
923     is_symmetric_route = 0;
924   }
925   free(src_name);
926   free(dst_name);
927 }
928
929 static void add_multi_links(const char *src, const char *dst,
930                             xbt_dynar_t links, const char *src_name,
931                             const char *dst_name)
932 {
933   unsigned int cpt;
934   char *value, *val;
935
936   surfxml_bufferstack_push(1);
937
938   parse_make_temporary_route(src_name, dst_name, route_action);
939   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
940   DEBUG2("\tADDING ROUTE: %s -> %s", src_name, dst_name);
941   /* Build link list */
942   xbt_dynar_foreach(links, cpt, value) {
943     if (strcmp(value, src) == 0)
944       val = xbt_strdup(src_name);
945     else if (strcmp(value, dst) == 0)
946       val = xbt_strdup(dst_name);
947     else if (strcmp(value, "$dst") == 0)
948       val = xbt_strdup(dst_name);
949     else if (strcmp(value, "$src") == 0)
950       val = xbt_strdup(src_name);
951     else
952       val = xbt_strdup(value);
953     DEBUG1("\t\tELEMENT: %s", val);
954     xbt_dynar_push(route_link_list, &val);
955   }
956   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
957   surfxml_bufferstack_pop(1);
958 }
959
960 static void convert_route_multi_to_routes(void)
961 {
962   xbt_dict_cursor_t cursor_w;
963   int symmetric;
964   unsigned int cpt, cpt2, cursor;
965   char *src_host_name, *dst_host_name, *key, *src, *dst, *val, *key_w,
966     *data_w;
967   const char *sep = "#";
968   xbt_dict_t set = NULL;
969   xbt_dynar_t src_names = NULL, dst_names = NULL, links;
970
971   if (!route_multi_elements)
972     return;
973
974   if (surf_cpu_model)
975     set = surf_model_resource_set(surf_cpu_model);
976   if (surf_workstation_model != NULL &&
977       surf_model_resource_set(surf_workstation_model) != NULL &&
978       xbt_dict_length(surf_model_resource_set(surf_workstation_model)) > 0)
979     set = surf_model_resource_set(surf_workstation_model);
980
981
982   surfxml_bufferstack_push(0);
983   /* Get all routes in the exact order they were entered in the platform file */
984   xbt_dynar_foreach(route_multi_elements, cursor, key) {
985     /* Get links for the route */
986     links = (xbt_dynar_t) xbt_dict_get_or_null(route_multi_table, key);
987     keys = xbt_str_split_str(key, sep);
988     /* Get route ends */
989     src = xbt_dynar_get_as(keys, 0, char *);
990     dst = xbt_dynar_get_as(keys, 1, char *);
991     route_action = atoi(xbt_dynar_get_as(keys, 2, char *));
992     symmetric = atoi(xbt_dynar_get_as(keys, 3, char *));
993
994     /* Create the dynar of src and dst hosts for the new routes */
995     /* NOTE: src and dst can be either set names or simple host names */
996     src_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, src);
997     dst_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, dst);
998     /* Add to dynar even if they are simple names */
999     if (src_names == NULL) {
1000       src_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1001       val = xbt_strdup(src);
1002       xbt_dynar_push(src_names, &val);
1003       if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1004         THROW3(unknown_error, 0,
1005                "(In route:multi (%s -> %s) source %s does not exist (not a set or a host)",
1006                src, dst, src);
1007     }
1008     if (dst_names == NULL) {
1009       dst_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1010       val = xbt_strdup(dst);
1011       if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1012         THROW3(unknown_error, 0,
1013                "(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)",
1014                src, dst, dst);
1015       xbt_dynar_push(dst_names, &val);
1016     }
1017
1018     /* Build the routes */
1019     DEBUG2("ADDING MULTI ROUTE: %s -> %s", xbt_dynar_get_as(keys, 0, char *),
1020            xbt_dynar_get_as(keys, 1, char *));
1021     xbt_dynar_foreach(src_names, cpt, src_host_name) {
1022       xbt_dynar_foreach(dst_names, cpt2, dst_host_name) {
1023         /* If dst is $* then set this route to have its dst point to all hosts */
1024         if (strcmp(src_host_name, "$*") != 0
1025             && strcmp(dst_host_name, "$*") == 0) {
1026           xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1027             //int n = xbt_dynar_member(src_names, (char*)key_w);
1028             add_multi_links(src, dst, links, src_host_name, key_w);
1029           }
1030         }
1031         /* If src is $* then set this route to have its dst point to all hosts */
1032         if (strcmp(src_host_name, "$*") == 0
1033             && strcmp(dst_host_name, "$*") != 0) {
1034           xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1035             // if (!symmetric || (symmetric && !contains(dst_names, key_w)))
1036             add_multi_links(src, dst, links, key_w, dst_host_name);
1037           }
1038         }
1039         /* if none of them are equal to $* */
1040         if (strcmp(src_host_name, "$*") != 0
1041             && strcmp(dst_host_name, "$*") != 0) {
1042           add_multi_links(src, dst, links, src_host_name, dst_host_name);
1043         }
1044       }
1045     }
1046     xbt_dynar_free(&keys);
1047   }
1048   surfxml_bufferstack_pop(0);
1049 }
1050
1051
1052 /* Trace management functions */
1053
1054 static double trace_periodicity = -1.0;
1055 static char *trace_file = NULL;
1056 static char *trace_id;
1057
1058 static void parse_Stag_trace(void)
1059 {
1060   trace_id = strdup(A_surfxml_trace_id);
1061   trace_file = strdup(A_surfxml_trace_file);
1062   surf_parse_get_double(&trace_periodicity, A_surfxml_trace_periodicity);
1063 }
1064
1065 static void parse_Etag_trace(void)
1066 {
1067   tmgr_trace_t trace;
1068   if (!trace_file || strcmp(trace_file, "") != 0) {
1069     trace = tmgr_trace_new(trace_file);
1070   } else {
1071     if (strcmp(surfxml_pcdata, "") == 0)
1072       trace = NULL;
1073     else
1074       trace =
1075         tmgr_trace_new_from_string(trace_id, surfxml_pcdata,
1076                                    trace_periodicity);
1077   }
1078   xbt_dict_set(traces_set_list, trace_id, (void *) trace, NULL);
1079 }
1080
1081 static void parse_Stag_trace_c_connect(void)
1082 {
1083   xbt_assert2(xbt_dict_get_or_null
1084               (traces_set_list, A_surfxml_trace_c_connect_trace),
1085               "Cannot connect trace %s to %s: trace unknown",
1086               A_surfxml_trace_c_connect_trace,
1087               A_surfxml_trace_c_connect_element);
1088
1089   switch (A_surfxml_trace_c_connect_kind) {
1090   case A_surfxml_trace_c_connect_kind_HOST_AVAIL:
1091     xbt_dict_set(trace_connect_list_host_avail,
1092                  A_surfxml_trace_c_connect_trace,
1093                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1094     break;
1095   case A_surfxml_trace_c_connect_kind_POWER:
1096     xbt_dict_set(trace_connect_list_power, A_surfxml_trace_c_connect_trace,
1097                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1098     break;
1099   case A_surfxml_trace_c_connect_kind_LINK_AVAIL:
1100     xbt_dict_set(trace_connect_list_link_avail,
1101                  A_surfxml_trace_c_connect_trace,
1102                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1103     break;
1104   case A_surfxml_trace_c_connect_kind_BANDWIDTH:
1105     xbt_dict_set(trace_connect_list_bandwidth,
1106                  A_surfxml_trace_c_connect_trace,
1107                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1108     break;
1109   case A_surfxml_trace_c_connect_kind_LATENCY:
1110     xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_c_connect_trace,
1111                  xbt_strdup(A_surfxml_trace_c_connect_element), free);
1112     break;
1113   default:
1114     xbt_die(bprintf("Cannot connect trace %s to %s: kind of trace unknown",
1115                     A_surfxml_trace_c_connect_trace,
1116                     A_surfxml_trace_c_connect_element));
1117   }
1118 }
1119
1120 /* Random tag functions */
1121
1122 double get_cpu_power(const char *power)
1123 {
1124   double power_scale = 0.0;
1125   const char *p, *q;
1126   char *generator;
1127   random_data_t random = NULL;
1128   /* randomness is inserted like this: power="$rand(my_random)" */
1129   if (((p = strstr(power, "$rand(")) != NULL)
1130       && ((q = strstr(power, ")")) != NULL)) {
1131     if (p < q) {
1132       generator = xbt_malloc(q - (p + 6) + 1);
1133       memcpy(generator, p + 6, q - (p + 6));
1134       generator[q - (p + 6)] = '\0';
1135       xbt_assert1((random =
1136                    xbt_dict_get_or_null(random_data_list, generator)),
1137                   "Random generator %s undefined", generator);
1138       power_scale = random_generate(random);
1139     }
1140   } else {
1141     surf_parse_get_double(&power_scale, power);
1142   }
1143   return power_scale;
1144 }
1145
1146 double random_min, random_max, random_mean, random_std_deviation,
1147   random_generator;
1148 char *random_id;
1149
1150 static void init_randomness(void)
1151 {
1152   random_id = A_surfxml_random_id;
1153   surf_parse_get_double(&random_min, A_surfxml_random_min);
1154   surf_parse_get_double(&random_max, A_surfxml_random_max);
1155   surf_parse_get_double(&random_mean, A_surfxml_random_mean);
1156   surf_parse_get_double(&random_std_deviation,
1157                         A_surfxml_random_std_deviation);
1158   random_generator = A_surfxml_random_generator;
1159 }
1160
1161 static void add_randomness(void)
1162 {
1163   /* If needed aditional properties can be added by using the prop tag */
1164   random_data_t random =
1165     random_new(random_generator, 0, random_min, random_max, random_mean,
1166                random_std_deviation);
1167   xbt_dict_set(random_data_list, random_id, (void *) random, NULL);
1168 }
1169
1170 /**
1171  * create CPU resource via CPU Model
1172  */
1173 void surf_host_create_resource(char *name, double power_peak,
1174         double power_scale,
1175         tmgr_trace_t power_trace,
1176         e_surf_resource_state_t state_initial,
1177         tmgr_trace_t state_trace,
1178         xbt_dict_t cpu_properties)
1179 {
1180         return surf_cpu_model->extension.cpu.
1181                 create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties);
1182 }
1183
1184 /*
1185  * create CPU resource via worsktation_ptask_L07 model
1186  */
1187
1188 void surf_wsL07_host_create_resource(char *name, double power_peak,
1189         double power_scale,
1190         tmgr_trace_t power_trace,
1191         e_surf_resource_state_t state_initial,
1192         tmgr_trace_t state_trace,
1193         xbt_dict_t cpu_properties)
1194 {
1195         surf_workstation_model->extension.workstation.
1196                 cpu_create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties);
1197 }
1198 /*
1199  * create link resource via network Model
1200  */
1201 void surf_link_create_resource(char *name,
1202         double bw_initial,
1203         tmgr_trace_t bw_trace,
1204         double lat_initial,
1205         tmgr_trace_t lat_trace,
1206         e_surf_resource_state_t
1207         state_initial,
1208         tmgr_trace_t state_trace,
1209         e_surf_link_sharing_policy_t policy,
1210         xbt_dict_t properties)
1211 {
1212         return surf_network_model->extension.network.
1213              create_resource(name,bw_initial,bw_trace,lat_initial,lat_trace,
1214                          state_initial,state_trace,policy,properties);
1215
1216 }
1217
1218 /*
1219  * create link resource via workstation_ptask_L07 model
1220  */
1221
1222 void surf_wsL07_link_create_resource(char *name,
1223                   double bw_initial,
1224                   tmgr_trace_t bw_trace,
1225                   double lat_initial,
1226                   tmgr_trace_t lat_trace,
1227                   e_surf_resource_state_t
1228                   state_initial,
1229                   tmgr_trace_t state_trace,
1230                   e_surf_link_sharing_policy_t
1231                   policy, xbt_dict_t properties)
1232 {
1233         return surf_workstation_model->extension.workstation.
1234         link_create_resource(name,bw_initial,bw_trace,lat_initial,lat_trace,
1235                                                 state_initial,state_trace,policy,properties);
1236 }
1237
1238
1239 /**
1240  * Route: add route element bypassing the parser :
1241  * same job as parse_route_elem
1242  */
1243
1244 void surf_add_route_element(char* link_ctn_id)
1245 {
1246         char *val;
1247         val = xbt_strdup(link_ctn_id);
1248         xbt_dynar_push(route_link_list,&val);
1249 }
1250 /**
1251  * set route
1252  */
1253 void surf_route_set_resource(char *source_id,char *destination_id,xbt_dynar_t links_id,int action)
1254 {
1255         route_link_list = xbt_dynar_new(sizeof(char *), NULL);
1256         routing_add_route(source_id,destination_id,links_id,action);
1257
1258 }
1259
1260 /**
1261  * add host to routing host list
1262  */
1263 void surf_route_add_host(char *host_id)
1264 {
1265         routing_add_host(host_id);
1266 }
1267
1268 /*
1269  * Add Traces
1270  */
1271 void surf_add_host_traces(void)
1272 {
1273         return surf_cpu_model->extension.cpu.
1274                      add_traces();
1275 }
1276
1277 void surf_add_link_traces(void)
1278 {
1279         return surf_network_model->extension.network.
1280                          add_traces();
1281 }
1282
1283 void surf_wsL07_add_traces(void)
1284 {
1285         return surf_workstation_model->extension.workstation.
1286                         add_traces();
1287 }
1288 /**
1289  * set routes
1290  */
1291 void surf_set_routes(void)
1292 {
1293         routing_set_routes();
1294 }
1295