Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Now tag config is available.
[simgrid.git] / src / surf / surfxml_parse.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
15                                 "Logging specific to the SURF parsing module");
16 #undef CLEANUP
17 #include "simgrid_dtd.c"
18
19 /* Initialize the parsing globals */
20 xbt_dict_t traces_set_list = NULL;
21 xbt_dict_t trace_connect_list_host_avail = NULL;
22 xbt_dict_t trace_connect_list_power = NULL;
23 xbt_dict_t trace_connect_list_link_avail = NULL;
24 xbt_dict_t trace_connect_list_bandwidth = NULL;
25 xbt_dict_t trace_connect_list_latency = NULL;
26
27 /* This buffer is used to store the original buffer before substituting it by out own buffer. Useful for the foreach tag */
28 static xbt_dynar_t surfxml_bufferstack_stack = NULL;
29 int surfxml_bufferstack_size = 2048;
30
31 static char *old_buff = NULL;
32 static void surf_parse_error(char *msg);
33
34 unsigned int surfxml_buffer_stack_stack_ptr;
35 unsigned int surfxml_buffer_stack_stack[1024];
36
37
38 void surfxml_bufferstack_push(int new)
39 {
40   if (!new)
41     old_buff = surfxml_bufferstack;
42   else {
43     xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
44     surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
45   }
46 }
47
48 void surfxml_bufferstack_pop(int new)
49 {
50   if (!new)
51     surfxml_bufferstack = old_buff;
52   else {
53     free(surfxml_bufferstack);
54     xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
55   }
56 }
57
58 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
59 xbt_dynar_t STag_surfxml_platform_cb_list = NULL;
60 xbt_dynar_t ETag_surfxml_platform_cb_list = NULL;
61 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
62 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
63 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
64 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
65 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
66 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
67 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
68 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
69 xbt_dynar_t STag_surfxml_link_ctn_cb_list = NULL;
70 xbt_dynar_t ETag_surfxml_link_ctn_cb_list = NULL;
71 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
72 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
73 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
74 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
75 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
76 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
77 xbt_dynar_t STag_surfxml_cluster_cb_list = NULL;
78 xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL;
79 xbt_dynar_t STag_surfxml_peer_cb_list = NULL;
80 xbt_dynar_t ETag_surfxml_peer_cb_list = NULL;
81 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
82 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
83 xbt_dynar_t STag_surfxml_trace_connect_cb_list = NULL;
84 xbt_dynar_t ETag_surfxml_trace_connect_cb_list = NULL;
85 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
86 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
87 xbt_dynar_t STag_surfxml_AS_cb_list = NULL;
88 xbt_dynar_t ETag_surfxml_AS_cb_list = NULL;
89 xbt_dynar_t STag_surfxml_ASroute_cb_list = NULL;
90 xbt_dynar_t ETag_surfxml_ASroute_cb_list = NULL;
91 xbt_dynar_t STag_surfxml_bypassRoute_cb_list = NULL;
92 xbt_dynar_t ETag_surfxml_bypassRoute_cb_list = NULL;
93 xbt_dynar_t STag_surfxml_config_cb_list = NULL;
94 xbt_dynar_t ETag_surfxml_config_cb_list = NULL;
95
96 /* store the current property set for any tag */
97 xbt_dict_t current_property_set = NULL;
98 /* dictionary of random generator data */
99 xbt_dict_t random_data_list = NULL;
100
101 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
102
103 YY_BUFFER_STATE surf_input_buffer;
104 FILE *surf_file_to_parse = NULL;
105
106 static void surf_parse_error(char *msg);
107
108 static void parse_Stag_trace(void);
109 static void parse_Etag_trace(void);
110 static void parse_Stag_trace_connect(void);
111
112 static void init_randomness(void);
113 static void add_randomness(void);
114
115 void surf_parse_free_callbacks(void)
116 {
117   xbt_dynar_free(&STag_surfxml_platform_cb_list);
118   xbt_dynar_free(&ETag_surfxml_platform_cb_list);
119   xbt_dynar_free(&STag_surfxml_host_cb_list);
120   xbt_dynar_free(&ETag_surfxml_host_cb_list);
121   xbt_dynar_free(&STag_surfxml_router_cb_list);
122   xbt_dynar_free(&ETag_surfxml_router_cb_list);
123   xbt_dynar_free(&STag_surfxml_link_cb_list);
124   xbt_dynar_free(&ETag_surfxml_link_cb_list);
125   xbt_dynar_free(&STag_surfxml_route_cb_list);
126   xbt_dynar_free(&ETag_surfxml_route_cb_list);
127   xbt_dynar_free(&STag_surfxml_link_ctn_cb_list);
128   xbt_dynar_free(&ETag_surfxml_link_ctn_cb_list);
129   xbt_dynar_free(&STag_surfxml_process_cb_list);
130   xbt_dynar_free(&ETag_surfxml_process_cb_list);
131   xbt_dynar_free(&STag_surfxml_argument_cb_list);
132   xbt_dynar_free(&ETag_surfxml_argument_cb_list);
133   xbt_dynar_free(&STag_surfxml_prop_cb_list);
134   xbt_dynar_free(&ETag_surfxml_prop_cb_list);
135   xbt_dynar_free(&STag_surfxml_trace_cb_list);
136   xbt_dynar_free(&ETag_surfxml_trace_cb_list);
137   xbt_dynar_free(&STag_surfxml_trace_connect_cb_list);
138   xbt_dynar_free(&ETag_surfxml_trace_connect_cb_list);
139   xbt_dynar_free(&STag_surfxml_random_cb_list);
140   xbt_dynar_free(&ETag_surfxml_random_cb_list);
141   xbt_dynar_free(&STag_surfxml_AS_cb_list);
142   xbt_dynar_free(&ETag_surfxml_AS_cb_list);
143   xbt_dynar_free(&STag_surfxml_ASroute_cb_list);
144   xbt_dynar_free(&ETag_surfxml_ASroute_cb_list);
145   xbt_dynar_free(&STag_surfxml_bypassRoute_cb_list);
146   xbt_dynar_free(&ETag_surfxml_bypassRoute_cb_list);
147   xbt_dynar_free(&STag_surfxml_cluster_cb_list);
148   xbt_dynar_free(&ETag_surfxml_cluster_cb_list);
149   xbt_dynar_free(&STag_surfxml_peer_cb_list);
150   xbt_dynar_free(&ETag_surfxml_peer_cb_list);
151   xbt_dynar_free(&STag_surfxml_config_cb_list);
152   xbt_dynar_free(&ETag_surfxml_config_cb_list);
153 }
154
155 void surf_parse_reset_parser(void)
156 {
157   surf_parse_free_callbacks();
158   STag_surfxml_platform_cb_list =
159       xbt_dynar_new(sizeof(void_f_void_t), NULL);
160   ETag_surfxml_platform_cb_list =
161       xbt_dynar_new(sizeof(void_f_void_t), NULL);
162   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
163   ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
164   STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
165   ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
166   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
167   ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
168   STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
169   ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
170   STag_surfxml_link_ctn_cb_list =
171       xbt_dynar_new(sizeof(void_f_void_t), NULL);
172   ETag_surfxml_link_ctn_cb_list =
173       xbt_dynar_new(sizeof(void_f_void_t), NULL);
174   STag_surfxml_process_cb_list =
175       xbt_dynar_new(sizeof(void_f_void_t), NULL);
176   ETag_surfxml_process_cb_list =
177       xbt_dynar_new(sizeof(void_f_void_t), NULL);
178   STag_surfxml_argument_cb_list =
179       xbt_dynar_new(sizeof(void_f_void_t), NULL);
180   ETag_surfxml_argument_cb_list =
181       xbt_dynar_new(sizeof(void_f_void_t), NULL);
182   STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
183   ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
184   STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
185   ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
186   STag_surfxml_trace_connect_cb_list =
187       xbt_dynar_new(sizeof(void_f_void_t), NULL);
188   ETag_surfxml_trace_connect_cb_list =
189       xbt_dynar_new(sizeof(void_f_void_t), NULL);
190   STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
191   ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
192   STag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
193   ETag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
194   STag_surfxml_ASroute_cb_list =
195       xbt_dynar_new(sizeof(void_f_void_t), NULL);
196   ETag_surfxml_ASroute_cb_list =
197       xbt_dynar_new(sizeof(void_f_void_t), NULL);
198   STag_surfxml_bypassRoute_cb_list =
199       xbt_dynar_new(sizeof(void_f_void_t), NULL);
200   ETag_surfxml_bypassRoute_cb_list =
201       xbt_dynar_new(sizeof(void_f_void_t), NULL);
202   STag_surfxml_cluster_cb_list =
203       xbt_dynar_new(sizeof(void_f_void_t), NULL);
204   ETag_surfxml_cluster_cb_list =
205       xbt_dynar_new(sizeof(void_f_void_t), NULL);
206   STag_surfxml_peer_cb_list =
207       xbt_dynar_new(sizeof(void_f_void_t), NULL);
208   ETag_surfxml_peer_cb_list =
209       xbt_dynar_new(sizeof(void_f_void_t), NULL);
210   STag_surfxml_config_cb_list =
211                   xbt_dynar_new(sizeof(void_f_void_t), NULL);
212   ETag_surfxml_config_cb_list =
213                   xbt_dynar_new(sizeof(void_f_void_t), NULL);
214 }
215
216 /* Stag and Etag parse functions */
217
218 void STag_surfxml_platform(void)
219 {
220   double version = 0.0;
221
222   sscanf(A_surfxml_platform_version, "%lg", &version);
223
224   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
225       "You're using an ancient XML file.\n"
226       "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
227       "instead of MBytes, MFlops and seconds.\n"
228
229       "Use simgrid_update_xml to update your file automatically. "
230       "This program is installed automatically with SimGrid, or "
231       "available in the tools/ directory of the source archive.\n"
232
233       "Please check also out the SURF section of the ChangeLog for "
234       "the 3.1 version for more information. \n"
235
236       "Last, do not forget to also update your values for "
237       "the calls to MSG_task_create (if any).");
238   xbt_assert0((version >= 3.0), "******* BIG FAT WARNING *********\n "
239       "You're using an old XML file.\n"
240       "Use simgrid_update_xml to update your file automatically. "
241       "This program is installed automatically with SimGrid, or "
242       "available in the tools/ directory of the source archive.");
243
244   surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
245
246 }
247
248 #define parse_method(type,name) \
249 void type##Tag_surfxml_##name(void) \
250 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
251
252 parse_method(E, platform);
253 parse_method(S, host);
254 parse_method(E, host);
255 parse_method(S, router);
256 parse_method(E, router);
257 parse_method(S, link);
258 parse_method(E, link);
259 parse_method(S, route);
260 parse_method(E, route);
261 parse_method(S, link_ctn);
262 parse_method(E, link_ctn);
263 parse_method(S, process);
264 parse_method(E, process);
265 parse_method(S, argument);
266 parse_method(E, argument);
267 parse_method(S, prop);
268 parse_method(E, prop);
269 parse_method(S, trace);
270 parse_method(E, trace);
271 parse_method(S, trace_connect);
272 parse_method(E, trace_connect);
273 parse_method(S, random);
274 parse_method(E, random);
275 parse_method(S, AS);
276 parse_method(E, AS);
277 parse_method(S, ASroute);
278 parse_method(E, ASroute);
279 parse_method(S, bypassRoute);
280 parse_method(E, bypassRoute);
281 parse_method(S, cluster);
282 parse_method(E, cluster);
283 parse_method(S, peer);
284 parse_method(E, peer);
285 parse_method(S, config);
286 parse_method(E, config);
287
288 /* Open and Close parse file */
289
290 void surf_parse_open(const char *file)
291 {
292   static int warned = 0;        /* warn only once */
293   if (!file) {
294     if (!warned) {
295       WARN0
296           ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
297       warned = 1;
298     }
299     return;
300   }
301   surf_file_to_parse = surf_fopen(file, "r");
302   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
303   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
304   surf_parse__switch_to_buffer(surf_input_buffer);
305   surf_parse_lineno = 1;
306 }
307
308 void surf_parse_close(void)
309 {
310   if (surf_file_to_parse) {
311     surf_parse__delete_buffer(surf_input_buffer);
312     fclose(surf_file_to_parse);
313     surf_file_to_parse = NULL; //Must be reset for Bypass
314   }
315 }
316
317 /* Parse Function */
318
319 static int _surf_parse(void)
320 {
321   return surf_parse_lex();
322 }
323
324 int_f_void_t surf_parse = _surf_parse;
325
326 void surf_parse_error(char *msg)
327 {
328   fprintf(stderr, "Parse error on line %d: %s\n", surf_parse_lineno, msg);
329   abort();
330 }
331
332 void surf_parse_get_double(double *value, const char *string)
333 {
334   int ret = 0;
335   ret = sscanf(string, "%lg", value);
336   if (ret != 1)
337     surf_parse_error(bprintf("%s is not a double", string));
338 }
339
340 void surf_parse_get_int(int *value, const char *string)
341 {
342   int ret = 0;
343   ret = sscanf(string, "%d", value);
344   if (ret != 1)
345     surf_parse_error(bprintf("%s is not an integer", string));
346 }
347
348 /* Aux parse functions */
349
350 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
351 {
352   xbt_dynar_push(cb_list, &function);
353 }
354
355 void surfxml_del_callback(xbt_dynar_t * p_cb_list, void_f_void_t function)
356 {
357   xbt_dynar_t new_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
358   unsigned int it;
359   void_f_void_t func;
360   xbt_dynar_foreach(*p_cb_list, it, func) {
361     if (func != function)
362       xbt_dynar_push(new_cb_list, &func);
363   }
364   xbt_dynar_free(p_cb_list);
365   *p_cb_list = new_cb_list;
366 }
367
368 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
369 {
370   unsigned int iterator;
371   void_f_void_t fun;
372   xbt_dynar_foreach(cb_list, iterator, fun) {
373     (*fun) ();
374   }
375 }
376
377 /* Init and free parse data */
378
379 static void init_data(void)
380 {
381   if (!surfxml_bufferstack_stack)
382     surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
383
384   random_data_list = xbt_dict_new();
385   traces_set_list = xbt_dict_new();
386   trace_connect_list_host_avail = xbt_dict_new();
387   trace_connect_list_power = xbt_dict_new();
388   trace_connect_list_link_avail = xbt_dict_new();
389   trace_connect_list_bandwidth = xbt_dict_new();
390   trace_connect_list_latency = xbt_dict_new();
391
392   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
393   if(xbt_dynar_is_empty(STag_surfxml_config_cb_list))
394   {
395           surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness);
396           surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness);
397           surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace);
398           surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace);
399           surfxml_add_callback(STag_surfxml_trace_connect_cb_list,
400                                                    &parse_Stag_trace_connect);
401   }
402 }
403
404 static void free_data(void)
405 {
406   xbt_dict_free(&trace_connect_list_host_avail);
407   xbt_dict_free(&trace_connect_list_power);
408   xbt_dict_free(&trace_connect_list_link_avail);
409   xbt_dict_free(&trace_connect_list_bandwidth);
410   xbt_dict_free(&trace_connect_list_latency);
411   xbt_dict_free(&traces_set_list);
412   xbt_dict_free(&random_data_list);
413   xbt_dynar_free(&surfxml_bufferstack_stack);
414 }
415
416 /* Here start parse */
417 void parse_platform_file(const char *file)
418 {
419   int parse_status;
420
421   surfxml_buffer_stack_stack_ptr = 1;
422   surfxml_buffer_stack_stack[0] = 0;
423
424   surf_parse_open(file);
425   init_data();
426   parse_status = surf_parse();
427   free_data();
428   surf_parse_close();
429   xbt_assert1(!parse_status, "Parse error in %s", file);
430 }
431
432 /* Prop tag functions */
433
434 void parse_properties(void)
435 {
436   char *value = NULL;
437   if (!current_property_set)
438     current_property_set = xbt_dict_new();      // Maybe, it should be make a error
439   value = xbt_strdup(A_surfxml_prop_value);
440   xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
441 }
442
443 /* Trace management functions */
444
445 static double trace_periodicity = -1.0;
446 static char *trace_file = NULL;
447 static char *trace_id = NULL;
448
449 static void parse_Stag_trace(void)
450 {
451   trace_id = xbt_strdup(A_surfxml_trace_id);
452   trace_file = xbt_strdup(A_surfxml_trace_file);
453   surf_parse_get_double(&trace_periodicity, A_surfxml_trace_periodicity);
454 }
455
456 static void parse_Etag_trace(void)
457 {
458   tmgr_trace_t trace;
459   if (!trace_file || strcmp(trace_file, "") != 0) {
460     trace = tmgr_trace_new(trace_file);
461   } else {
462     if (strcmp(surfxml_pcdata, "") == 0)
463       trace = NULL;
464     else
465       trace =
466           tmgr_trace_new_from_string(trace_id, surfxml_pcdata,
467                                      trace_periodicity);
468   }
469   xbt_dict_set(traces_set_list, trace_id, (void *) trace, NULL);
470   xbt_free(trace_file);
471   trace_file = NULL;
472   xbt_free(trace_id);
473   trace_id = NULL;
474 }
475
476 static void parse_Stag_trace_connect(void)
477 {
478   xbt_assert2(xbt_dict_get_or_null
479               (traces_set_list, A_surfxml_trace_connect_trace),
480               "Cannot connect trace %s to %s: trace unknown",
481               A_surfxml_trace_connect_trace,
482               A_surfxml_trace_connect_element);
483
484   switch (A_surfxml_trace_connect_kind) {
485   case A_surfxml_trace_connect_kind_HOST_AVAIL:
486     xbt_dict_set(trace_connect_list_host_avail,
487                  A_surfxml_trace_connect_trace,
488                  xbt_strdup(A_surfxml_trace_connect_element), free);
489     break;
490   case A_surfxml_trace_connect_kind_POWER:
491     xbt_dict_set(trace_connect_list_power, A_surfxml_trace_connect_trace,
492                  xbt_strdup(A_surfxml_trace_connect_element), free);
493     break;
494   case A_surfxml_trace_connect_kind_LINK_AVAIL:
495     xbt_dict_set(trace_connect_list_link_avail,
496                  A_surfxml_trace_connect_trace,
497                  xbt_strdup(A_surfxml_trace_connect_element), free);
498     break;
499   case A_surfxml_trace_connect_kind_BANDWIDTH:
500     xbt_dict_set(trace_connect_list_bandwidth,
501                  A_surfxml_trace_connect_trace,
502                  xbt_strdup(A_surfxml_trace_connect_element), free);
503     break;
504   case A_surfxml_trace_connect_kind_LATENCY:
505     xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_connect_trace,
506                  xbt_strdup(A_surfxml_trace_connect_element), free);
507     break;
508   default:
509     xbt_die(bprintf("Cannot connect trace %s to %s: kind of trace unknown",
510                     A_surfxml_trace_connect_trace,
511                     A_surfxml_trace_connect_element));
512   }
513 }
514
515 /* Random tag functions */
516
517 double get_cpu_power(const char *power)
518 {
519   double power_scale = 0.0;
520   const char *p, *q;
521   char *generator;
522   random_data_t random = NULL;
523   /* randomness is inserted like this: power="$rand(my_random)" */
524   if (((p = strstr(power, "$rand(")) != NULL)
525       && ((q = strstr(power, ")")) != NULL)) {
526     if (p < q) {
527       generator = xbt_malloc(q - (p + 6) + 1);
528       memcpy(generator, p + 6, q - (p + 6));
529       generator[q - (p + 6)] = '\0';
530       xbt_assert1((random =
531                    xbt_dict_get_or_null(random_data_list, generator)),
532                   "Random generator %s undefined", generator);
533       power_scale = random_generate(random);
534     }
535   } else {
536     surf_parse_get_double(&power_scale, power);
537   }
538   return power_scale;
539 }
540
541 double random_min, random_max, random_mean, random_std_deviation,
542     random_generator;
543 char *random_id;
544
545 static void init_randomness(void)
546 {
547   random_id = A_surfxml_random_id;
548   surf_parse_get_double(&random_min, A_surfxml_random_min);
549   surf_parse_get_double(&random_max, A_surfxml_random_max);
550   surf_parse_get_double(&random_mean, A_surfxml_random_mean);
551   surf_parse_get_double(&random_std_deviation,
552                         A_surfxml_random_std_deviation);
553   random_generator = A_surfxml_random_generator;
554 }
555
556 static void add_randomness(void)
557 {
558   /* If needed aditional properties can be added by using the prop tag */
559   random_data_t random =
560       random_new(random_generator, 0, random_min, random_max, random_mean,
561                  random_std_deviation);
562   xbt_dict_set(random_data_list, random_id, (void *) random,
563                &xbt_free_ref);
564 }
565
566 /**
567  * create CPU resource via CPU Model
568  */
569 void surf_host_create_resource(char *name, double power_peak,
570                                double power_scale,
571                                tmgr_trace_t power_trace, int core,
572                                e_surf_resource_state_t state_initial,
573                                tmgr_trace_t state_trace,
574                                xbt_dict_t cpu_properties)
575 {
576   return surf_cpu_model->extension.cpu.create_resource(name, power_peak,
577                                                        power_scale,
578                                                        power_trace,
579                                                        core,
580                                                        state_initial,
581                                                        state_trace,
582                                                        cpu_properties);
583 }
584
585 /**
586  * create CPU resource via worsktation_ptask_L07 model
587  */
588
589 void surf_wsL07_host_create_resource(char *name, double power_peak,
590                                      double power_scale,
591                                      tmgr_trace_t power_trace,
592                                      e_surf_resource_state_t state_initial,
593                                      tmgr_trace_t state_trace,
594                                      xbt_dict_t cpu_properties)
595 {
596   surf_workstation_model->extension.workstation.cpu_create_resource(name,
597                                                                     power_peak,
598                                                                     power_scale,
599                                                                     power_trace,
600                                                                     state_initial,
601                                                                     state_trace,
602                                                                     cpu_properties);
603 }
604
605 /**
606  * create link resource via network Model
607  */
608 void surf_link_create_resource(char *name,
609                                double bw_initial,
610                                tmgr_trace_t bw_trace,
611                                double lat_initial,
612                                tmgr_trace_t lat_trace,
613                                e_surf_resource_state_t
614                                state_initial,
615                                tmgr_trace_t state_trace,
616                                e_surf_link_sharing_policy_t policy,
617                                xbt_dict_t properties)
618 {
619   return surf_network_model->extension.network.create_resource(name,
620                                                                bw_initial,
621                                                                bw_trace,
622                                                                lat_initial,
623                                                                lat_trace,
624                                                                state_initial,
625                                                                state_trace,
626                                                                policy,
627                                                                properties);
628 }
629
630 /**
631  * create link resource via workstation_ptask_L07 model
632  */
633
634 void surf_wsL07_link_create_resource(char *name,
635                                      double bw_initial,
636                                      tmgr_trace_t bw_trace,
637                                      double lat_initial,
638                                      tmgr_trace_t lat_trace,
639                                      e_surf_resource_state_t
640                                      state_initial,
641                                      tmgr_trace_t state_trace,
642                                      e_surf_link_sharing_policy_t
643                                      policy, xbt_dict_t properties)
644 {
645   return surf_workstation_model->extension.workstation.
646       link_create_resource(name, bw_initial, bw_trace, lat_initial,
647                            lat_trace, state_initial, state_trace, policy,
648                            properties);
649 }
650
651 /**
652  *
653  *init new routing model component
654  */
655
656 void surf_AS_new(const char *AS_id, const char *AS_mode)
657 {
658   routing_AS_init(AS_id, AS_mode);
659 }
660
661 void surf_AS_finalize(const char *AS_id)
662 {
663   routing_AS_end(AS_id);
664 }
665
666 /*
667  * add host to the network element list
668  */
669 void surf_route_add_host(const char *host_id)
670 {
671   routing_add_host(host_id);
672 }
673
674 /**
675  * set route
676  */
677 void surf_routing_add_route(const char *src_id, const char *dst_id,
678                             xbt_dynar_t links_id)
679 {
680   unsigned int i;
681   const char *link_id;
682   routing_set_route(src_id, dst_id);
683   xbt_dynar_foreach(links_id, i, link_id) {
684     routing_add_link(link_id);
685   }
686
687   //store the route
688   routing_store_route();
689 }
690
691 /**
692  * Add Traces
693  */
694 void surf_add_host_traces(void)
695 {
696   return surf_cpu_model->extension.cpu.add_traces();
697 }
698
699 void surf_add_link_traces(void)
700 {
701   return surf_network_model->extension.network.add_traces();
702 }
703
704 void surf_wsL07_add_traces(void)
705 {
706   return surf_workstation_model->extension.workstation.add_traces();
707 }