3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
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. */
12 #include "surf/surfxml_parse_private.h"
13 #include "surf/surf_private.h"
15 #define NO_IMPLICIT_ROUTES
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
18 "Logging specific to the SURF parsing module");
20 #include "simgrid_dtd.c"
22 /* Initialize the parsing globals */
24 xbt_dict_t traces_set_list = NULL;
25 //xbt_dynar_t traces_connect_list = NULL;
26 xbt_dict_t trace_connect_list_host_avail = NULL;
27 xbt_dict_t trace_connect_list_power = NULL;
28 xbt_dict_t trace_connect_list_link_avail = NULL;
29 xbt_dict_t trace_connect_list_bandwidth = NULL;
30 xbt_dict_t trace_connect_list_latency = NULL;
32 /* This buffer is used to store the original buffer before substituing it by out own buffer. Usefull for the foreach tag */
33 static xbt_dynar_t surfxml_bufferstack_stack = NULL;
34 static int surfxml_bufferstack_size = 2048;
35 static char *old_buff = NULL;
36 static void surf_parse_error(char *msg);
38 static void push_surfxml_bufferstack(int new)
41 old_buff = surfxml_bufferstack;
43 xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
44 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
48 static void pop_surfxml_bufferstack(int new)
51 surfxml_bufferstack = old_buff;
53 free(surfxml_bufferstack);
54 xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
58 /* Stores the set name reffered to by the foreach tag */
59 static char *foreach_set_name;
60 static xbt_dynar_t main_STag_surfxml_host_cb_list = NULL;
61 static xbt_dynar_t main_ETag_surfxml_host_cb_list = NULL;
62 static xbt_dynar_t main_STag_surfxml_link_cb_list = NULL;
63 static xbt_dynar_t main_ETag_surfxml_link_cb_list = NULL;
65 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
66 xbt_dynar_t STag_surfxml_platform_cb_list = NULL;
67 xbt_dynar_t ETag_surfxml_platform_cb_list = NULL;
68 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
69 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
70 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
71 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
72 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
73 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
74 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
75 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
76 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL;
77 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL;
78 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
79 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
80 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
81 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
82 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
83 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
84 xbt_dynar_t STag_surfxml_set_cb_list = NULL;
85 xbt_dynar_t ETag_surfxml_set_cb_list = NULL;
86 xbt_dynar_t STag_surfxml_foreach_cb_list = NULL;
87 xbt_dynar_t ETag_surfxml_foreach_cb_list = NULL;
88 xbt_dynar_t STag_surfxml_route_c_multi_cb_list = NULL;
89 xbt_dynar_t ETag_surfxml_route_c_multi_cb_list = NULL;
90 xbt_dynar_t STag_surfxml_cluster_cb_list = NULL;
91 xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL;
92 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
93 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
94 xbt_dynar_t STag_surfxml_trace_c_connect_cb_list = NULL;
95 xbt_dynar_t ETag_surfxml_trace_c_connect_cb_list = NULL;
96 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
97 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
99 /* Stores the sets defined in the XML */
100 xbt_dict_t set_list = NULL;
102 xbt_dict_t current_property_set = NULL;
104 /* For the route:multi tag */
105 xbt_dict_t route_table = NULL;
106 xbt_dict_t route_multi_table = NULL;
107 xbt_dynar_t route_multi_elements = NULL;
108 static xbt_dynar_t route_link_list = NULL;
109 xbt_dynar_t links = NULL;
110 xbt_dynar_t keys = NULL;
112 xbt_dict_t random_data_list = NULL;
114 static xbt_dynar_t surf_input_buffer_stack = NULL;
115 static xbt_dynar_t surf_file_to_parse_stack = NULL;
117 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
119 YY_BUFFER_STATE surf_input_buffer;
120 FILE *surf_file_to_parse = NULL;
122 static void convert_route_multi_to_routes(void);
123 static void parse_route_elem(void);
124 static void parse_foreach(void);
125 static void parse_sets(void);
126 static void parse_route_multi_set_endpoints(void);
127 static void parse_route_multi_set_route(void);
128 static void parse_cluster(void);
129 static void parse_trace_init(void);
130 static void parse_trace_finalize(void);
131 static void parse_trace_c_connect(void);
132 static void init_randomness(void);
133 static void add_randomness(void);
135 void surf_parse_free_callbacks(void)
137 xbt_dynar_free(&STag_surfxml_platform_cb_list);
138 xbt_dynar_free(&ETag_surfxml_platform_cb_list);
139 xbt_dynar_free(&STag_surfxml_host_cb_list);
140 xbt_dynar_free(&ETag_surfxml_host_cb_list);
141 xbt_dynar_free(&STag_surfxml_router_cb_list);
142 xbt_dynar_free(&ETag_surfxml_router_cb_list);
143 xbt_dynar_free(&STag_surfxml_link_cb_list);
144 xbt_dynar_free(&ETag_surfxml_link_cb_list);
145 xbt_dynar_free(&STag_surfxml_route_cb_list);
146 xbt_dynar_free(&ETag_surfxml_route_cb_list);
147 xbt_dynar_free(&STag_surfxml_link_c_ctn_cb_list);
148 xbt_dynar_free(&ETag_surfxml_link_c_ctn_cb_list);
149 xbt_dynar_free(&STag_surfxml_process_cb_list);
150 xbt_dynar_free(&ETag_surfxml_process_cb_list);
151 xbt_dynar_free(&STag_surfxml_argument_cb_list);
152 xbt_dynar_free(&ETag_surfxml_argument_cb_list);
153 xbt_dynar_free(&STag_surfxml_prop_cb_list);
154 xbt_dynar_free(&ETag_surfxml_prop_cb_list);
155 xbt_dynar_free(&STag_surfxml_set_cb_list);
156 xbt_dynar_free(&ETag_surfxml_set_cb_list);
157 xbt_dynar_free(&STag_surfxml_foreach_cb_list);
158 xbt_dynar_free(&ETag_surfxml_foreach_cb_list);
159 xbt_dynar_free(&STag_surfxml_route_c_multi_cb_list);
160 xbt_dynar_free(&ETag_surfxml_route_c_multi_cb_list);
161 xbt_dynar_free(&STag_surfxml_cluster_cb_list);
162 xbt_dynar_free(&ETag_surfxml_cluster_cb_list);
163 xbt_dynar_free(&STag_surfxml_trace_cb_list);
164 xbt_dynar_free(&ETag_surfxml_trace_cb_list);
165 xbt_dynar_free(&STag_surfxml_trace_c_connect_cb_list);
166 xbt_dynar_free(&ETag_surfxml_trace_c_connect_cb_list);
167 xbt_dynar_free(&STag_surfxml_random_cb_list);
168 xbt_dynar_free(&ETag_surfxml_random_cb_list);
171 void surf_parse_reset_parser(void)
173 surf_parse_free_callbacks();
174 STag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
175 ETag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
176 STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
177 ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
178 STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
179 ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
180 STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
181 ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
182 STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
183 ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
184 STag_surfxml_link_c_ctn_cb_list =
185 xbt_dynar_new(sizeof(void_f_void_t), NULL);
186 ETag_surfxml_link_c_ctn_cb_list =
187 xbt_dynar_new(sizeof(void_f_void_t), NULL);
188 STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
189 ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
190 STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
191 ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
192 STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
193 ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
194 STag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
195 ETag_surfxml_set_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
196 STag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
197 ETag_surfxml_foreach_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
198 STag_surfxml_route_c_multi_cb_list =
199 xbt_dynar_new(sizeof(void_f_void_t), NULL);
200 ETag_surfxml_route_c_multi_cb_list =
201 xbt_dynar_new(sizeof(void_f_void_t), NULL);
202 STag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
203 ETag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
204 STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
205 ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
206 STag_surfxml_trace_c_connect_cb_list =
207 xbt_dynar_new(sizeof(void_f_void_t), NULL);
208 ETag_surfxml_trace_c_connect_cb_list =
209 xbt_dynar_new(sizeof(void_f_void_t), NULL);
210 STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
211 ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
214 void STag_surfxml_include(void)
216 xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
217 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
219 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
220 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
221 A_surfxml_include_file);
222 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
223 surf_parse__switch_to_buffer(surf_input_buffer);
228 void ETag_surfxml_include(void)
232 surf_parse__delete_buffer(surf_input_buffer);
233 fclose(surf_file_to_parse);
234 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
235 xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
238 void STag_surfxml_platform(void)
240 double version = 0.0;
242 sscanf(A_surfxml_platform_version, "%lg", &version);
244 xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
245 "You're using an ancient XML file. "
246 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
247 "instead of MBytes, MFlops and seconds. "
248 "A script (surfxml_update.pl) to help you convert your old "
250 "is available in the contrib/platform_generation directory "
251 "of the simgrid repository. Please check also out the "
252 "SURF section of the ChangeLog for the 3.1 version. "
253 "Last, do not forget to also update your values for "
254 "the calls to MSG_task_create (if any).");
255 xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n "
256 "You're using an old XML file. "
257 "A script (surfxml_update.pl) to help you convert your old "
259 "is available in the contrib/platform_generation directory "
260 "of the simgrid repository.");
262 surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
266 void ETag_surfxml_platform(void)
268 convert_route_multi_to_routes();
270 surfxml_call_cb_functions(ETag_surfxml_platform_cb_list);
272 xbt_dict_free(&random_data_list);
275 void STag_surfxml_host(void)
277 surfxml_call_cb_functions(STag_surfxml_host_cb_list);
280 void ETag_surfxml_host(void)
282 surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
285 void STag_surfxml_router(void)
287 surfxml_call_cb_functions(STag_surfxml_router_cb_list);
290 void ETag_surfxml_router(void)
292 surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
295 void STag_surfxml_link(void)
297 surfxml_call_cb_functions(STag_surfxml_link_cb_list);
300 void ETag_surfxml_link(void)
302 surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
305 void STag_surfxml_route(void)
307 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
310 void ETag_surfxml_route(void)
312 surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
315 void STag_surfxml_link_c_ctn(void)
317 surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
320 void ETag_surfxml_link_c_ctn(void)
322 surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
325 void STag_surfxml_process(void)
327 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
330 void ETag_surfxml_process(void)
332 surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
335 void STag_surfxml_argument(void)
337 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
340 void ETag_surfxml_argument(void)
342 surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
345 void STag_surfxml_prop(void)
347 surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
350 void ETag_surfxml_prop(void)
352 surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
355 void STag_surfxml_set(void)
357 surfxml_call_cb_functions(STag_surfxml_set_cb_list);
360 void ETag_surfxml_set(void)
362 surfxml_call_cb_functions(ETag_surfxml_set_cb_list);
365 void STag_surfxml_foreach(void)
367 /* Save the current buffer */
368 push_surfxml_bufferstack(0);
369 surfxml_call_cb_functions(STag_surfxml_foreach_cb_list);
372 void ETag_surfxml_foreach(void)
374 surfxml_call_cb_functions(ETag_surfxml_foreach_cb_list);
376 /* free the temporary dynar and restore original */
377 xbt_dynar_free(&STag_surfxml_host_cb_list);
378 xbt_dynar_free(&ETag_surfxml_host_cb_list);
380 STag_surfxml_host_cb_list = main_STag_surfxml_host_cb_list;
381 ETag_surfxml_host_cb_list = main_ETag_surfxml_host_cb_list;
383 /* free the temporary dynar and restore original */
384 xbt_dynar_free(&STag_surfxml_link_cb_list);
385 xbt_dynar_free(&ETag_surfxml_link_cb_list);
387 STag_surfxml_link_cb_list = main_STag_surfxml_link_cb_list;
388 ETag_surfxml_link_cb_list = main_ETag_surfxml_link_cb_list;
392 void STag_surfxml_route_c_multi(void)
394 surfxml_call_cb_functions(STag_surfxml_route_c_multi_cb_list);
397 void ETag_surfxml_route_c_multi(void)
399 surfxml_call_cb_functions(ETag_surfxml_route_c_multi_cb_list);
402 void STag_surfxml_cluster(void)
404 surfxml_call_cb_functions(STag_surfxml_cluster_cb_list);
407 void ETag_surfxml_cluster(void)
409 surfxml_call_cb_functions(ETag_surfxml_cluster_cb_list);
412 void STag_surfxml_trace(void)
414 surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
417 void ETag_surfxml_trace(void)
419 surfxml_call_cb_functions(ETag_surfxml_trace_cb_list);
422 void STag_surfxml_trace_c_connect(void)
424 surfxml_call_cb_functions(STag_surfxml_trace_c_connect_cb_list);
427 void ETag_surfxml_trace_c_connect(void)
429 surfxml_call_cb_functions(ETag_surfxml_trace_c_connect_cb_list);
432 void STag_surfxml_random(void)
434 surfxml_call_cb_functions(STag_surfxml_random_cb_list);
437 void ETag_surfxml_random(void)
439 surfxml_call_cb_functions(ETag_surfxml_random_cb_list);
442 void surf_parse_open(const char *file)
444 static int warned = 0; /* warn only once */
448 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
453 if (!surf_input_buffer_stack)
454 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
455 if (!surf_file_to_parse_stack)
456 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
458 surf_file_to_parse = surf_fopen(file, "r");
459 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
460 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
461 surf_parse__switch_to_buffer(surf_input_buffer);
462 surf_parse_lineno = 1;
465 void surf_parse_close(void)
467 if (surf_input_buffer_stack)
468 xbt_dynar_free(&surf_input_buffer_stack);
469 if (surf_file_to_parse_stack)
470 xbt_dynar_free(&surf_file_to_parse_stack);
472 if (surf_file_to_parse) {
473 surf_parse__delete_buffer(surf_input_buffer);
474 fclose(surf_file_to_parse);
479 static int _surf_parse(void)
481 return surf_parse_lex();
484 int_f_void_t surf_parse = _surf_parse;
486 void surf_parse_error(char *msg)
488 fprintf(stderr, "Parse error on line %d: %s\n", surf_parse_lineno, msg);
493 void surf_parse_get_double(double *value, const char *string)
497 ret = sscanf(string, "%lg", value);
499 surf_parse_error(bprintf("%s is not a double", string));
502 void surf_parse_get_int(int *value, const char *string)
506 ret = sscanf(string, "%d", value);
508 surf_parse_error(bprintf("%s is not an integer", string));
511 void parse_properties(void)
515 if (!current_property_set)
516 current_property_set = xbt_dict_new();
518 value = xbt_strdup(A_surfxml_prop_value);
519 xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
522 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
524 xbt_dynar_push(cb_list, &function);
527 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
529 unsigned int iterator;
531 xbt_dynar_foreach(cb_list, iterator, fun) {
532 DEBUG2("call %p %p", fun, *fun);
537 static void parse_route_set_endpoints(void)
539 route_link_list = xbt_dynar_new(sizeof(char *), NULL);
542 static void init_data(void)
544 xbt_dict_free(&route_table);
545 xbt_dynar_free(&route_link_list);
546 route_table = xbt_dict_new();
548 if (!surfxml_bufferstack_stack)
549 surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
550 route_multi_table = xbt_dict_new();
551 route_multi_elements = xbt_dynar_new(sizeof(char *), NULL);
552 traces_set_list = xbt_dict_new();
553 if (set_list == NULL)
554 set_list = xbt_dict_new();
556 trace_connect_list_host_avail = xbt_dict_new();
557 trace_connect_list_power = xbt_dict_new();
558 trace_connect_list_link_avail = xbt_dict_new();
559 trace_connect_list_bandwidth = xbt_dict_new();
560 trace_connect_list_latency = xbt_dict_new();
562 random_data_list = xbt_dict_new();
563 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
564 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
565 surfxml_add_callback(STag_surfxml_route_cb_list,
566 &parse_route_set_endpoints);
567 surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
568 surfxml_add_callback(STag_surfxml_route_c_multi_cb_list,
569 &parse_route_multi_set_endpoints);
570 surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list,
571 &parse_route_multi_set_route);
572 surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_foreach);
573 surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_cluster);
574 surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_trace_init);
575 surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_trace_finalize);
576 surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list,
577 &parse_trace_c_connect);
578 surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness);
579 surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness);
582 static void free_data(void)
585 xbt_dict_cursor_t cursor = NULL;
587 unsigned int cpt = 0;
589 xbt_dict_foreach(route_table, cursor, key, data) {
590 xbt_dynar_t links = (xbt_dynar_t) data;
592 unsigned int cpt = 0;
594 xbt_dynar_foreach(links, cpt, name) free(name);
595 xbt_dynar_free(&links);
597 xbt_dict_free(&route_table);
598 route_link_list = NULL;
600 xbt_dict_free(&route_multi_table);
602 xbt_dynar_foreach(route_multi_elements, cpt, name) free(name);
603 xbt_dynar_free(&route_multi_elements);
605 xbt_dict_foreach(set_list, cursor, key, data) {
606 xbt_dynar_t set = (xbt_dynar_t) data;
608 xbt_dynar_foreach(set, cpt, name) free(name);
609 xbt_dynar_free(&set);
611 xbt_dict_free(&set_list);
613 xbt_dynar_free(&surfxml_bufferstack_stack);
615 xbt_dict_free(&traces_set_list);
616 xbt_dict_free(&trace_connect_list_host_avail);
617 xbt_dict_free(&trace_connect_list_power);
618 xbt_dict_free(&trace_connect_list_link_avail);
619 xbt_dict_free(&trace_connect_list_bandwidth);
620 xbt_dict_free(&trace_connect_list_latency);
621 xbt_dict_free(&traces_set_list);
624 void parse_platform_file(const char *file)
626 surf_parse_open(file);
628 xbt_assert1((!(*surf_parse) ()), "Parse error in %s", file);
633 /* Functions to bypass route, host and link tags. Used by the foreach and route:multi tags */
635 static void parse_make_temporary_route(const char *src, const char *dst,
640 A_surfxml_route_action = action;
641 SURFXML_BUFFER_SET(route_src, src);
642 SURFXML_BUFFER_SET(route_dst, dst);
645 static void parse_change_cpu_data(const char *hostName,
646 const char *surfxml_host_power,
647 const char *surfxml_host_availability,
648 const char *surfxml_host_availability_file,
649 const char *surfxml_host_state_file)
653 SURFXML_BUFFER_SET(host_id, hostName);
654 SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
655 SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
656 SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
657 SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
660 static void parse_change_link_data(const char *linkName,
661 const char *surfxml_link_bandwidth,
662 const char *surfxml_link_bandwidth_file,
663 const char *surfxml_link_latency,
664 const char *surfxml_link_latency_file,
665 const char *surfxml_link_state_file)
669 SURFXML_BUFFER_SET(link_id, linkName);
670 SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
671 SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
672 SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
673 SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
674 SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
677 /* Functions for the sets and foreach tags */
679 static void parse_sets(void)
681 char *id, *suffix, *prefix, *radical;
683 xbt_dynar_t radical_elements;
684 xbt_dynar_t radical_ends;
685 xbt_dynar_t current_set;
686 char *value, *groups;
690 id = xbt_strdup(A_surfxml_set_id);
691 prefix = xbt_strdup(A_surfxml_set_prefix);
692 suffix = xbt_strdup(A_surfxml_set_suffix);
693 radical = xbt_strdup(A_surfxml_set_radical);
695 if (xbt_dict_get_or_null(set_list, id))
696 surf_parse_error(bprintf
697 ("Set '%s' declared several times in the platform file.",
700 current_set = xbt_dynar_new(sizeof(char *), NULL);
702 radical_elements = xbt_str_split(radical, ",");
703 xbt_dynar_foreach(radical_elements, iter, groups) {
705 radical_ends = xbt_str_split(groups, "-");
706 switch (xbt_dynar_length(radical_ends)) {
708 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
709 value = bprintf("%s%d%s", prefix, start, suffix);
710 xbt_dynar_push(current_set, &value);
715 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
716 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
719 for (i = start; i <= end; i++) {
720 value = bprintf("%s%d%s", prefix, i, suffix);
721 xbt_dynar_push(current_set, &value);
726 surf_parse_error(xbt_strdup("Malformed radical"));
729 xbt_dynar_free(&radical_ends);
732 xbt_dict_set(set_list, id, current_set, NULL);
734 xbt_dynar_free(&radical_elements);
741 static const char *surfxml_host_power;
742 static const char *surfxml_host_availability;
743 static const char *surfxml_host_availability_file;
744 static const char *surfxml_host_state_file;
746 static void parse_host_foreach(void)
748 surfxml_host_power = A_surfxml_host_power;
749 surfxml_host_availability = A_surfxml_host_availability;
750 surfxml_host_availability_file = A_surfxml_host_availability_file;
751 surfxml_host_state_file = A_surfxml_host_state_file;
754 static void finalize_host_foreach(void)
756 xbt_dynar_t names = NULL;
757 unsigned int cpt = 0;
759 xbt_dict_cursor_t cursor = NULL;
762 xbt_dict_t cluster_host_props = current_property_set;
764 names = xbt_dict_get_or_null(set_list, foreach_set_name);
766 surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
768 if (strcmp(A_surfxml_host_id, "$1"))
769 surf_parse_error(bprintf
770 ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
774 /* foreach name in set call the main host callback */
775 xbt_dynar_foreach(names, cpt, name) {
776 push_surfxml_bufferstack(1);
777 parse_change_cpu_data(name, surfxml_host_power, surfxml_host_availability,
778 surfxml_host_availability_file,
779 surfxml_host_state_file);
780 surfxml_call_cb_functions(main_STag_surfxml_host_cb_list);
782 xbt_dict_foreach(cluster_host_props, cursor, key, data) {
783 xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
787 surfxml_call_cb_functions(main_ETag_surfxml_host_cb_list);
788 pop_surfxml_bufferstack(1);
791 current_property_set = xbt_dict_new();
793 pop_surfxml_bufferstack(0);
796 static const char *surfxml_link_bandwidth;
797 static const char *surfxml_link_bandwidth_file;
798 static const char *surfxml_link_latency;
799 static const char *surfxml_link_latency_file;
800 static const char *surfxml_link_state_file;
802 static void parse_link_foreach(void)
804 surfxml_link_bandwidth = A_surfxml_link_bandwidth;
805 surfxml_link_bandwidth_file = A_surfxml_link_bandwidth_file;
806 surfxml_link_latency = A_surfxml_link_latency;
807 surfxml_link_latency_file = A_surfxml_link_latency_file;
808 surfxml_link_state_file = A_surfxml_link_state_file;
811 static void finalize_link_foreach(void)
813 xbt_dynar_t names = NULL;
814 unsigned int cpt = 0;
816 xbt_dict_cursor_t cursor = NULL;
819 xbt_dict_t cluster_link_props = current_property_set;
821 names = xbt_dict_get_or_null(set_list, foreach_set_name);
823 surf_parse_error(bprintf("Set name '%s' used in <foreach> not found.",
825 if (strcmp(A_surfxml_link_id, "$1"))
826 surf_parse_error(bprintf
827 ("The host id within <foreach> should point to the foreach set_id (use $1 instead of %s)",
830 /* for each name in set call the main link callback */
831 xbt_dynar_foreach(names, cpt, name) {
832 push_surfxml_bufferstack(1);
833 parse_change_link_data(name, surfxml_link_bandwidth,
834 surfxml_link_bandwidth_file, surfxml_link_latency,
835 surfxml_link_latency_file,
836 surfxml_link_state_file);
837 surfxml_call_cb_functions(main_STag_surfxml_link_cb_list);
839 xbt_dict_foreach(cluster_link_props, cursor, key, data) {
840 xbt_dict_set(current_property_set, xbt_strdup(key), xbt_strdup(data),
844 surfxml_call_cb_functions(main_ETag_surfxml_link_cb_list);
845 pop_surfxml_bufferstack(1);
848 current_property_set = xbt_dict_new();
850 pop_surfxml_bufferstack(0);
851 free(foreach_set_name);
852 foreach_set_name = NULL;
855 static void parse_foreach(void)
857 /* save the host & link callbacks */
858 main_STag_surfxml_host_cb_list = STag_surfxml_host_cb_list;
859 main_ETag_surfxml_host_cb_list = ETag_surfxml_host_cb_list;
860 main_STag_surfxml_link_cb_list = STag_surfxml_link_cb_list;
861 main_ETag_surfxml_link_cb_list = ETag_surfxml_link_cb_list;
863 /* define host & link callbacks to be used only by the foreach tag */
864 STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
865 ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
866 STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
867 ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
869 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_host_foreach);
870 surfxml_add_callback(ETag_surfxml_host_cb_list, &finalize_host_foreach);
871 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_foreach);
872 surfxml_add_callback(ETag_surfxml_link_cb_list, &finalize_link_foreach);
875 foreach_set_name = xbt_strdup(A_surfxml_foreach_set_id);
878 /* Route:multi functions */
880 static int route_multi_size = 0;
881 static char *src_name, *dst_name;
882 static int is_symmetric_route;
884 static void parse_route_elem(void)
888 val = xbt_strdup(A_surfxml_link_c_ctn_id);
890 xbt_dynar_push(route_link_list, &val);
893 static void parse_route_multi_set_endpoints(void)
895 src_name = xbt_strdup(A_surfxml_route_c_multi_src);
896 dst_name = xbt_strdup(A_surfxml_route_c_multi_dst);
897 route_action = A_surfxml_route_c_multi_action;
898 is_symmetric_route = A_surfxml_route_c_multi_symmetric;
901 route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
904 static int contains(xbt_dynar_t list, const char *value)
908 xbt_dynar_foreach(list, cpt, val) {
909 if (strcmp(val, value) == 0)
916 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.
917 The decision is based upon the value of action specified in the xml route:multi attribute action
919 void manage_route(xbt_dict_t routing_table, const char *route_name,
920 int action, int isMultiRoute)
926 /* get already existing list if it exists */
927 links = xbt_dict_get_or_null(routing_table, route_name);
928 DEBUG1("ROUTE: %s", route_name);
931 case A_surfxml_route_action_PREPEND: /* add existing links at the end; route_link_list + links */
932 xbt_dynar_foreach(links, cpt, value) {
933 xbt_dynar_push(route_link_list, &value);
935 xbt_dynar_free(&links);
937 case A_surfxml_route_action_POSTPEND: /* add existing links in front; links + route_link_list */
938 xbt_dynar_foreach(route_link_list, cpt, value) {
939 xbt_dynar_push(links, &value);
941 xbt_dynar_free(&route_link_list);
942 route_link_list = links;
944 case A_surfxml_route_action_OVERRIDE:
945 xbt_dynar_free(&links);
951 /* this is the final route; do not add if name is a set; add only if name is in set list */
953 xbt_dict_set(routing_table, route_name, route_link_list, NULL);
957 static void parse_route_multi_set_route(void)
962 bprintf("%s#%s#%d#%d#%d", src_name, dst_name, route_action,
963 is_symmetric_route, route_multi_size);
965 xbt_dynar_push(route_multi_elements, &route_name);
968 xbt_dict_set(route_multi_table, route_name, route_link_list, NULL);
969 /* add symmetric if it is the case */
970 if (is_symmetric_route == 1) {
971 char *symmetric_name =
972 bprintf("%s#%s#%d#%d#%d", dst_name, src_name, route_action,
973 !is_symmetric_route, route_multi_size);
975 xbt_dict_set(route_multi_table, symmetric_name, route_link_list, NULL);
976 xbt_dynar_push(route_multi_elements, &symmetric_name);
977 is_symmetric_route = 0;
983 static void add_multi_links(const char *src, const char *dst,
984 xbt_dynar_t links, const char *src_name,
985 const char *dst_name)
990 push_surfxml_bufferstack(1);
992 parse_make_temporary_route(src_name, dst_name, route_action);
993 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
994 DEBUG2("\tADDING ROUTE: %s -> %s", src_name, dst_name);
995 /* Build link list */
996 xbt_dynar_foreach(links, cpt, value) {
997 if (strcmp(value, src) == 0)
998 val = xbt_strdup(src_name);
999 else if (strcmp(value, dst) == 0)
1000 val = xbt_strdup(dst_name);
1001 else if (strcmp(value, "$dst") == 0)
1002 val = xbt_strdup(dst_name);
1003 else if (strcmp(value, "$src") == 0)
1004 val = xbt_strdup(src_name);
1006 val = xbt_strdup(value);
1007 DEBUG1("\t\tELEMENT: %s", val);
1008 xbt_dynar_push(route_link_list, &val);
1010 surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
1011 pop_surfxml_bufferstack(1);
1014 static void convert_route_multi_to_routes(void)
1016 xbt_dict_cursor_t cursor_w;
1018 unsigned int cpt, cpt2, cursor;
1019 char *src_host_name, *dst_host_name, *key, *src, *dst, *val, *key_w,
1021 const char *sep = "#";
1022 xbt_dict_t set = NULL;
1023 xbt_dynar_t src_names = NULL, dst_names = NULL, links;
1025 if (!route_multi_elements)
1029 set = surf_model_resource_set(surf_cpu_model);
1030 if (surf_workstation_model != NULL &&
1031 surf_model_resource_set(surf_workstation_model) != NULL &&
1032 xbt_dict_length(surf_model_resource_set(surf_workstation_model)) > 0)
1033 set = surf_model_resource_set(surf_workstation_model);
1036 push_surfxml_bufferstack(0);
1037 /* Get all routes in the exact order they were entered in the platform file */
1038 xbt_dynar_foreach(route_multi_elements, cursor, key) {
1039 /* Get links for the route */
1040 links = (xbt_dynar_t) xbt_dict_get_or_null(route_multi_table, key);
1041 keys = xbt_str_split_str(key, sep);
1042 /* Get route ends */
1043 src = xbt_dynar_get_as(keys, 0, char *);
1044 dst = xbt_dynar_get_as(keys, 1, char *);
1045 route_action = atoi(xbt_dynar_get_as(keys, 2, char *));
1046 symmetric = atoi(xbt_dynar_get_as(keys, 3, char *));
1048 /* Create the dynar of src and dst hosts for the new routes */
1049 /* NOTE: src and dst can be either set names or simple host names */
1050 src_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, src);
1051 dst_names = (xbt_dynar_t) xbt_dict_get_or_null(set_list, dst);
1052 /* Add to dynar even if they are simple names */
1053 if (src_names == NULL) {
1054 src_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1055 val = xbt_strdup(src);
1056 xbt_dynar_push(src_names, &val);
1057 if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1058 THROW3(unknown_error, 0,
1059 "(In route:multi (%s -> %s) source %s does not exist (not a set or a host)",
1062 if (dst_names == NULL) {
1063 dst_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1064 val = xbt_strdup(dst);
1065 if (strcmp(val, "$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
1066 THROW3(unknown_error, 0,
1067 "(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)",
1069 xbt_dynar_push(dst_names, &val);
1072 /* Build the routes */
1073 DEBUG2("ADDING MULTI ROUTE: %s -> %s", xbt_dynar_get_as(keys, 0, char *),
1074 xbt_dynar_get_as(keys, 1, char *));
1075 xbt_dynar_foreach(src_names, cpt, src_host_name) {
1076 xbt_dynar_foreach(dst_names, cpt2, dst_host_name) {
1077 /* If dst is $* then set this route to have its dst point to all hosts */
1078 if (strcmp(src_host_name, "$*") != 0
1079 && strcmp(dst_host_name, "$*") == 0) {
1080 xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1081 //int n = xbt_dynar_member(src_names, (char*)key_w);
1082 add_multi_links(src, dst, links, src_host_name, key_w);
1085 /* If src is $* then set this route to have its dst point to all hosts */
1086 if (strcmp(src_host_name, "$*") == 0
1087 && strcmp(dst_host_name, "$*") != 0) {
1088 xbt_dict_foreach(set, cursor_w, key_w, data_w) {
1089 // if (!symmetric || (symmetric && !contains(dst_names, key_w)))
1090 add_multi_links(src, dst, links, key_w, dst_host_name);
1093 /* if none of them are equal to $* */
1094 if (strcmp(src_host_name, "$*") != 0
1095 && strcmp(dst_host_name, "$*") != 0) {
1096 add_multi_links(src, dst, links, src_host_name, dst_host_name);
1100 xbt_dynar_free(&keys);
1102 pop_surfxml_bufferstack(0);
1105 /* Cluster tag functions */
1107 static void parse_cluster(void)
1109 static int AX_ptr = 0;
1111 char *cluster_id = A_surfxml_cluster_id;
1112 char *cluster_prefix = A_surfxml_cluster_prefix;
1113 char *cluster_suffix = A_surfxml_cluster_suffix;
1114 char *cluster_radical = A_surfxml_cluster_radical;
1115 char *cluster_power = A_surfxml_cluster_power;
1116 #if !defined NO_IMPLICIT_ROUTES
1117 char *cluster_bw = A_surfxml_cluster_bw;
1118 char *cluster_lat = A_surfxml_cluster_lat;
1120 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1121 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1122 char *backbone_name;
1124 push_surfxml_bufferstack(1);
1127 SURFXML_BUFFER_SET(set_id, cluster_id);
1128 SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1129 SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1130 SURFXML_BUFFER_SET(set_radical, cluster_radical);
1132 SURFXML_START_TAG(set);
1133 SURFXML_END_TAG(set);
1136 SURFXML_BUFFER_SET(foreach_set_id, cluster_id);
1138 SURFXML_START_TAG(foreach);
1140 /* Make host for the foreach */
1141 parse_change_cpu_data("$1", cluster_power, "1.0", "", "");
1142 A_surfxml_host_state = A_surfxml_host_state_ON;
1144 SURFXML_START_TAG(host);
1145 SURFXML_END_TAG(host);
1146 #ifndef NO_IMPLICIT_ROUTES
1147 /* Make link for the foreach */
1148 parse_change_link_data("$1", cluster_bw, "", cluster_lat, "", "");
1149 A_surfxml_link_state = A_surfxml_link_state_ON;
1150 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1152 SURFXML_START_TAG(link);
1153 SURFXML_END_TAG(link);
1155 SURFXML_END_TAG(foreach);
1157 /* Make backbone link */
1158 backbone_name = bprintf("%s_bb", cluster_id);
1159 parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1161 A_surfxml_link_state = A_surfxml_link_state_ON;
1162 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1164 SURFXML_START_TAG(link);
1165 SURFXML_END_TAG(link);
1166 #ifndef NO_IMPLICIT_ROUTES
1167 /* Make route multi with the outside world, i.e. cluster->$* */
1168 SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1169 SURFXML_BUFFER_SET(route_c_multi_dst, "$*");
1170 A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1171 A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_OVERRIDE;
1173 SURFXML_START_TAG(route_c_multi);
1175 SURFXML_BUFFER_SET(link_c_ctn_id, "$src");
1177 SURFXML_START_TAG(link_c_ctn);
1178 SURFXML_END_TAG(link_c_ctn);
1180 SURFXML_END_TAG(route_c_multi);
1182 /* Make route multi between cluster hosts, i.e. cluster->cluster */
1183 SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1184 SURFXML_BUFFER_SET(route_c_multi_dst, cluster_id);
1185 A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_POSTPEND;
1186 A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1188 SURFXML_START_TAG(route_c_multi);
1190 SURFXML_BUFFER_SET(link_c_ctn_id, backbone_name);
1192 SURFXML_START_TAG(link_c_ctn);
1193 SURFXML_END_TAG(link_c_ctn);
1195 SURFXML_END_TAG(route_c_multi);
1198 free(backbone_name);
1201 pop_surfxml_bufferstack(1);
1204 /* Trace management functions */
1206 static double trace_periodicity = -1.0;
1207 static char *trace_file = NULL;
1208 static char *trace_id;
1210 static void parse_trace_init(void)
1212 trace_id = strdup(A_surfxml_trace_id);
1213 trace_file = strdup(A_surfxml_trace_file);
1214 surf_parse_get_double(&trace_periodicity, A_surfxml_trace_periodicity);
1217 static void parse_trace_finalize(void)
1220 if (!trace_file || strcmp(trace_file, "") != 0) {
1221 trace = tmgr_trace_new(trace_file);
1223 if (strcmp(surfxml_pcdata, "") == 0)
1227 tmgr_trace_new_from_string(trace_id, surfxml_pcdata,
1230 xbt_dict_set(traces_set_list, trace_id, (void *) trace, NULL);
1233 static void parse_trace_c_connect(void)
1235 xbt_assert2(xbt_dict_get_or_null
1236 (traces_set_list, A_surfxml_trace_c_connect_trace),
1237 "Cannot connect trace %s to %s: trace unknown",
1238 A_surfxml_trace_c_connect_trace,
1239 A_surfxml_trace_c_connect_element);
1241 switch (A_surfxml_trace_c_connect_kind) {
1242 case A_surfxml_trace_c_connect_kind_HOST_AVAIL:
1243 xbt_dict_set(trace_connect_list_host_avail,
1244 A_surfxml_trace_c_connect_trace,
1245 xbt_strdup(A_surfxml_trace_c_connect_element), free);
1247 case A_surfxml_trace_c_connect_kind_POWER:
1248 xbt_dict_set(trace_connect_list_power, A_surfxml_trace_c_connect_trace,
1249 xbt_strdup(A_surfxml_trace_c_connect_element), free);
1251 case A_surfxml_trace_c_connect_kind_LINK_AVAIL:
1252 xbt_dict_set(trace_connect_list_link_avail,
1253 A_surfxml_trace_c_connect_trace,
1254 xbt_strdup(A_surfxml_trace_c_connect_element), free);
1256 case A_surfxml_trace_c_connect_kind_BANDWIDTH:
1257 xbt_dict_set(trace_connect_list_bandwidth,
1258 A_surfxml_trace_c_connect_trace,
1259 xbt_strdup(A_surfxml_trace_c_connect_element), free);
1261 case A_surfxml_trace_c_connect_kind_LATENCY:
1262 xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_c_connect_trace,
1263 xbt_strdup(A_surfxml_trace_c_connect_element), free);
1266 xbt_die(bprintf("Cannot connect trace %s to %s: kind of trace unknown",
1267 A_surfxml_trace_c_connect_trace,
1268 A_surfxml_trace_c_connect_element));
1272 /* Random tag functions */
1274 double get_cpu_power(const char *power)
1276 double power_scale = 0.0;
1279 random_data_t random = NULL;
1280 /* randomness is inserted like this: power="$rand(my_random)" */
1281 if (((p = strstr(power, "$rand(")) != NULL)
1282 && ((q = strstr(power, ")")) != NULL)) {
1284 generator = xbt_malloc(q - (p + 6) + 1);
1285 memcpy(generator, p + 6, q - (p + 6));
1286 generator[q - (p + 6)] = '\0';
1287 xbt_assert1((random =
1288 xbt_dict_get_or_null(random_data_list, generator)),
1289 "Random generator %s undefined", generator);
1290 power_scale = random_generate(random);
1293 surf_parse_get_double(&power_scale, power);
1298 double random_min, random_max, random_mean, random_std_deviation,
1302 static void init_randomness(void)
1304 random_id = A_surfxml_random_id;
1305 surf_parse_get_double(&random_min, A_surfxml_random_min);
1306 surf_parse_get_double(&random_max, A_surfxml_random_max);
1307 surf_parse_get_double(&random_mean, A_surfxml_random_mean);
1308 surf_parse_get_double(&random_std_deviation,
1309 A_surfxml_random_std_deviation);
1310 random_generator = A_surfxml_random_generator;
1313 static void add_randomness(void)
1315 /* If needed aditional properties can be added by using the prop tag */
1316 random_data_t random =
1317 random_new(random_generator, 0, random_min, random_max, random_mean,
1318 random_std_deviation);
1319 xbt_dict_set(random_data_list, random_id, (void *) random, NULL);