1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "surf/surfxml_parse.h"
12 #include "surf/surf_private.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
15 "Logging specific to the SURF parsing module");
17 int ETag_surfxml_include_state(void);
19 #include "simgrid_dtd.c"
21 char* surf_parsed_filename = NULL; // to locate parse error messages
26 void surf_parse_error(const char *msg) {
27 xbt_die("Parse error at %s:%d: %s\n", surf_parsed_filename, surf_parse_lineno, msg);
30 double surf_parse_get_double(const char *string) {
32 int ret = sscanf(string, "%lg", &res);
34 surf_parse_error(bprintf("%s is not a double", string));
38 int surf_parse_get_int(const char *string) {
40 int ret = sscanf(string, "%d", &res);
42 surf_parse_error(bprintf("%s is not an integer", string));
48 * All the callback lists that can be overiden anywhere.
49 * (this list should probably be reduced to the bare minimum to allow the models to work)
52 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
53 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
54 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
55 xbt_dynar_t STag_surfxml_link_ctn_cb_list = NULL;
56 xbt_dynar_t ETag_surfxml_link_ctn_cb_list = NULL;
57 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
58 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
59 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
60 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
61 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
62 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
63 xbt_dynar_t STag_surfxml_peer_cb_list = NULL;
64 xbt_dynar_t ETag_surfxml_peer_cb_list = NULL;
65 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
66 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
67 xbt_dynar_t STag_surfxml_trace_connect_cb_list = NULL;
68 xbt_dynar_t ETag_surfxml_trace_connect_cb_list = NULL;
69 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
70 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
71 xbt_dynar_t STag_surfxml_ASroute_cb_list = NULL;
72 xbt_dynar_t ETag_surfxml_ASroute_cb_list = NULL;
73 xbt_dynar_t STag_surfxml_bypassRoute_cb_list = NULL;
74 xbt_dynar_t ETag_surfxml_bypassRoute_cb_list = NULL;
75 xbt_dynar_t STag_surfxml_include_cb_list = NULL;
76 xbt_dynar_t ETag_surfxml_include_cb_list = NULL;
78 /* The default current property receiver. Setup in the corresponding opening callbacks. */
79 xbt_dict_t current_property_set = NULL;
80 /* dictionary of random generator data */
81 xbt_dict_t random_data_list = NULL;
83 /* Call all the callbacks of a specific SAX event */
84 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
86 YY_BUFFER_STATE surf_input_buffer;
87 FILE *surf_file_to_parse = NULL;
89 static void init_randomness(void);
90 static void add_randomness(void);
93 * Stuff relative to the <include> tag
95 static xbt_dynar_t surf_input_buffer_stack = NULL;
96 static xbt_dynar_t surf_file_to_parse_stack = NULL;
97 static xbt_dynar_t surf_parsed_filename_stack = NULL;
99 void STag_surfxml_include(void)
101 XBT_INFO("STag_surfxml_include '%s'",A_surfxml_include_file);
102 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
103 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
105 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
107 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
108 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
109 A_surfxml_include_file);
110 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
111 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
112 surf_parse_push_buffer_state(surf_input_buffer);
117 void ETag_surfxml_include(void) {
118 /* Nothing to do when done with reading the include tag.
119 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
122 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
124 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
125 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
126 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
127 * error message in that case.
129 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
130 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
131 * on a line. One day maybe, if the maya allow it.
133 int ETag_surfxml_include_state(void)
136 XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
138 if(!xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
141 // Yeah, we were in an <include> Restore state and proceed.
142 fclose(surf_file_to_parse);
143 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
144 surf_parse_pop_buffer_state();
145 xbt_dynar_pop(surf_input_buffer_stack,surf_input_buffer);
147 // Restore the filename for error messages
148 free(surf_parsed_filename);
149 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
155 void surf_parse_init_callbacks(void)
157 sg_platf_init(); // FIXME: move to a proper place?
159 STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
160 ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
161 STag_surfxml_link_ctn_cb_list =
162 xbt_dynar_new(sizeof(void_f_void_t), NULL);
163 ETag_surfxml_link_ctn_cb_list =
164 xbt_dynar_new(sizeof(void_f_void_t), NULL);
165 STag_surfxml_process_cb_list =
166 xbt_dynar_new(sizeof(void_f_void_t), NULL);
167 ETag_surfxml_process_cb_list =
168 xbt_dynar_new(sizeof(void_f_void_t), NULL);
169 STag_surfxml_argument_cb_list =
170 xbt_dynar_new(sizeof(void_f_void_t), NULL);
171 ETag_surfxml_argument_cb_list =
172 xbt_dynar_new(sizeof(void_f_void_t), NULL);
173 STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
174 ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
175 STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
176 ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
177 STag_surfxml_trace_connect_cb_list =
178 xbt_dynar_new(sizeof(void_f_void_t), NULL);
179 ETag_surfxml_trace_connect_cb_list =
180 xbt_dynar_new(sizeof(void_f_void_t), NULL);
181 STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
182 ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
183 STag_surfxml_ASroute_cb_list =
184 xbt_dynar_new(sizeof(void_f_void_t), NULL);
185 ETag_surfxml_ASroute_cb_list =
186 xbt_dynar_new(sizeof(void_f_void_t), NULL);
187 STag_surfxml_bypassRoute_cb_list =
188 xbt_dynar_new(sizeof(void_f_void_t), NULL);
189 ETag_surfxml_bypassRoute_cb_list =
190 xbt_dynar_new(sizeof(void_f_void_t), NULL);
191 STag_surfxml_peer_cb_list =
192 xbt_dynar_new(sizeof(void_f_void_t), NULL);
193 ETag_surfxml_peer_cb_list =
194 xbt_dynar_new(sizeof(void_f_void_t), NULL);
195 STag_surfxml_include_cb_list =
196 xbt_dynar_new(sizeof(void_f_void_t), NULL);
197 ETag_surfxml_include_cb_list =
198 xbt_dynar_new(sizeof(void_f_void_t), NULL);
201 void surf_parse_reset_callbacks(void)
203 surf_parse_free_callbacks();
204 surf_parse_init_callbacks();
207 void surf_parse_free_callbacks(void)
209 sg_platf_exit(); // FIXME: better place?
211 xbt_dynar_free(&STag_surfxml_route_cb_list);
212 xbt_dynar_free(&ETag_surfxml_route_cb_list);
213 xbt_dynar_free(&STag_surfxml_link_ctn_cb_list);
214 xbt_dynar_free(&ETag_surfxml_link_ctn_cb_list);
215 xbt_dynar_free(&STag_surfxml_process_cb_list);
216 xbt_dynar_free(&ETag_surfxml_process_cb_list);
217 xbt_dynar_free(&STag_surfxml_argument_cb_list);
218 xbt_dynar_free(&ETag_surfxml_argument_cb_list);
219 xbt_dynar_free(&STag_surfxml_prop_cb_list);
220 xbt_dynar_free(&ETag_surfxml_prop_cb_list);
221 xbt_dynar_free(&STag_surfxml_trace_cb_list);
222 xbt_dynar_free(&ETag_surfxml_trace_cb_list);
223 xbt_dynar_free(&STag_surfxml_trace_connect_cb_list);
224 xbt_dynar_free(&ETag_surfxml_trace_connect_cb_list);
225 xbt_dynar_free(&STag_surfxml_random_cb_list);
226 xbt_dynar_free(&ETag_surfxml_random_cb_list);
227 xbt_dynar_free(&STag_surfxml_ASroute_cb_list);
228 xbt_dynar_free(&ETag_surfxml_ASroute_cb_list);
229 xbt_dynar_free(&STag_surfxml_bypassRoute_cb_list);
230 xbt_dynar_free(&ETag_surfxml_bypassRoute_cb_list);
231 xbt_dynar_free(&STag_surfxml_peer_cb_list);
232 xbt_dynar_free(&ETag_surfxml_peer_cb_list);
233 xbt_dynar_free(&STag_surfxml_include_cb_list);
234 xbt_dynar_free(&ETag_surfxml_include_cb_list);
237 /* Stag and Etag parse functions */
238 void ETag_surfxml_router(void) { /* ignored -- do not add content here */ }
240 void STag_surfxml_platform(void) {
241 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
243 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
244 "You're using an ancient XML file.\n"
245 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
246 "instead of MBytes, MFlops and seconds.\n"
248 "Use simgrid_update_xml to update your file automatically. "
249 "This program is installed automatically with SimGrid, or "
250 "available in the tools/ directory of the source archive.\n"
252 "Please check also out the SURF section of the ChangeLog for "
253 "the 3.1 version for more information. \n"
255 "Last, do not forget to also update your values for "
256 "the calls to MSG_task_create (if any).");
257 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
258 "You're using an old XML file.\n"
259 "Use simgrid_update_xml to update your file automatically. "
260 "This program is installed automatically with SimGrid, or "
261 "available in the tools/ directory of the source archive.");
265 void ETag_surfxml_platform(void){
269 void STag_surfxml_host(void){
270 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
273 void ETag_surfxml_host(void) {
274 s_sg_platf_host_cbarg_t host;
275 memset(&host,0,sizeof(host));
277 host.properties = current_property_set;
279 host.id = A_surfxml_host_id;
280 host.power_peak = get_cpu_power(A_surfxml_host_power);
281 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
282 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
283 host.power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
284 host.state_trace = tmgr_trace_new(A_surfxml_host_state_file);
285 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
286 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
287 if (A_surfxml_host_state == A_surfxml_host_state_ON)
288 host.initial_state = SURF_RESOURCE_ON;
289 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
290 host.initial_state = SURF_RESOURCE_OFF;
291 host.coord = A_surfxml_host_coordinates;
293 sg_platf_new_host(&host);
294 current_property_set = NULL;
297 void STag_surfxml_router(void){
298 s_sg_platf_router_cbarg_t router;
299 memset(&router, 0, sizeof(router));
301 router.id = A_surfxml_router_id;
302 router.coord = A_surfxml_router_coordinates;
304 sg_platf_new_router(&router);
307 void STag_surfxml_cluster(void){
308 s_sg_platf_cluster_cbarg_t cluster;
309 memset(&cluster,0,sizeof(cluster));
310 cluster.id = A_surfxml_cluster_id;
311 cluster.prefix = A_surfxml_cluster_prefix;
312 cluster.suffix = A_surfxml_cluster_suffix;
313 cluster.radical = A_surfxml_cluster_radical;
314 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
315 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
316 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
317 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
318 if(strcmp(A_surfxml_cluster_bb_bw,""))
319 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
320 if(strcmp(A_surfxml_cluster_bb_lat,""))
321 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
322 cluster.router_id = A_surfxml_cluster_router_id;
324 switch (AX_surfxml_cluster_sharing_policy) {
325 case A_surfxml_cluster_sharing_policy_SHARED:
326 cluster.sharing_policy = SURF_LINK_SHARED;
328 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
329 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
331 case A_surfxml_cluster_sharing_policy_FATPIPE:
332 cluster.sharing_policy = SURF_LINK_FATPIPE;
335 surf_parse_error(bprintf
336 ("Invalid cluster sharing policy for cluster %s",
340 switch (AX_surfxml_cluster_bb_sharing_policy) {
341 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
342 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
344 case A_surfxml_cluster_bb_sharing_policy_SHARED:
345 cluster.bb_sharing_policy = SURF_LINK_SHARED;
348 surf_parse_error(bprintf
349 ("Invalid bb sharing policy in cluster %s",
354 cluster.availability_trace = A_surfxml_cluster_availability_file;
355 cluster.state_trace = A_surfxml_cluster_state_file;
356 sg_platf_new_cluster(&cluster);
358 void ETag_surfxml_cluster(void){
359 /* nothing I can think of */
362 void STag_surfxml_peer(void){
363 s_sg_platf_peer_cbarg_t peer;
364 memset(&peer,0,sizeof(peer));
365 peer.id = A_surfxml_peer_id;
366 peer.power = surf_parse_get_double(A_surfxml_peer_power);
367 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
368 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
369 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
370 peer.coord = A_surfxml_peer_coordinates;
371 peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
372 peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
374 surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
375 sg_platf_new_peer(&peer);
377 void ETag_surfxml_peer(void){
378 /* nothing to do here */
380 void STag_surfxml_link(void){
381 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
383 void ETag_surfxml_link(void){
384 s_sg_platf_link_cbarg_t link;
385 memset(&link,0,sizeof(link));
387 link.properties = current_property_set;
389 link.id = A_surfxml_link_id;
390 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
391 link.bandwidth_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
392 link.latency = surf_parse_get_double(A_surfxml_link_latency);
393 link.latency_trace = tmgr_trace_new(A_surfxml_link_latency_file);
395 switch (A_surfxml_link_state) {
396 case A_surfxml_link_state_ON:
397 link.state = SURF_RESOURCE_ON;
399 case A_surfxml_link_state_OFF:
400 link.state = SURF_RESOURCE_OFF;
403 surf_parse_error(bprintf("invalid state for link %s",link.id));
406 link.state_trace = tmgr_trace_new(A_surfxml_link_state_file);
408 switch (A_surfxml_link_sharing_policy) {
409 case A_surfxml_link_sharing_policy_SHARED:
410 link.policy = SURF_LINK_SHARED;
412 case A_surfxml_link_sharing_policy_FATPIPE:
413 link.policy = SURF_LINK_FATPIPE;
415 case A_surfxml_link_sharing_policy_FULLDUPLEX:
416 link.policy = SURF_LINK_FULLDUPLEX;
419 surf_parse_error(bprintf("Invalid sharing policy in link %s",link.id));
423 sg_platf_new_link(&link);
425 current_property_set = NULL;
428 void STag_surfxml_route(void){
429 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
431 void STag_surfxml_link_ctn(void){
432 surfxml_call_cb_functions(STag_surfxml_link_ctn_cb_list);
434 void STag_surfxml_process(void){
435 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
437 void STag_surfxml_argument(void){
438 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
440 void STag_surfxml_prop(void){
441 surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
443 void STag_surfxml_trace(void){
444 surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
446 void STag_surfxml_trace_connect(void){
447 surfxml_call_cb_functions(STag_surfxml_trace_connect_cb_list);
449 void STag_surfxml_AS(void){
450 sg_platf_new_AS_begin(A_surfxml_AS_id,A_surfxml_AS_routing);
452 void ETag_surfxml_AS(void){
453 sg_platf_new_AS_end();
455 void STag_surfxml_ASroute(void){
456 surfxml_call_cb_functions(STag_surfxml_ASroute_cb_list);
458 void STag_surfxml_bypassRoute(void){
459 surfxml_call_cb_functions(STag_surfxml_bypassRoute_cb_list);
461 void STag_surfxml_config(void){
462 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
463 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
465 void ETag_surfxml_config(void){
466 xbt_dict_cursor_t cursor = NULL;
470 xbt_dict_foreach(current_property_set, cursor, key, elem) {
471 cfg = bprintf("%s:%s",key,elem);
472 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
473 xbt_cfg_set_parse(_surf_cfg_set, cfg);
475 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
478 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
479 xbt_dict_free(¤t_property_set);
481 void STag_surfxml_random(void){
482 surfxml_call_cb_functions(STag_surfxml_random_cb_list);
485 #define parse_method(type,name) \
486 void type##Tag_surfxml_##name(void) \
487 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
488 parse_method(E, route);
489 parse_method(E, link_ctn);
490 parse_method(E, process);
491 parse_method(E, argument);
492 parse_method(E, prop);
493 parse_method(E, trace);
494 parse_method(E, trace_connect);
495 parse_method(E, random);
496 parse_method(E, ASroute);
497 parse_method(E, bypassRoute);
499 /* Open and Close parse file */
501 void surf_parse_open(const char *file)
503 static int warned = 0; /* warn only once */
507 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
508 "If it is not what you want, go fix your code.");
514 if (!surf_input_buffer_stack)
515 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
516 if (!surf_file_to_parse_stack)
517 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
519 if (!surf_file_to_parse_stack)
520 surf_parsed_filename_stack = xbt_dynar_new(sizeof(FILE *), xbt_free_f);
521 surf_parsed_filename = xbt_strdup(file);
523 surf_file_to_parse = surf_fopen(file, "r");
524 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
525 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
526 surf_parse__switch_to_buffer(surf_input_buffer);
527 surf_parse_lineno = 1;
530 void surf_parse_close(void)
532 xbt_dynar_free(&surf_input_buffer_stack);
533 xbt_dynar_free(&surf_file_to_parse_stack);
534 xbt_dynar_free(&surf_parsed_filename_stack);
536 free(surf_parsed_filename);
538 if (surf_file_to_parse) {
539 surf_parse__delete_buffer(surf_input_buffer);
540 fclose(surf_file_to_parse);
541 surf_file_to_parse = NULL; //Must be reset for Bypass
545 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
547 static int _surf_parse(void) {
548 return surf_parse_lex();
550 int_f_void_t surf_parse = _surf_parse;
553 /* Aux parse functions */
555 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
557 xbt_dynar_push(cb_list, &function);
560 void surfxml_del_callback(xbt_dynar_t cb_list, void_f_void_t function)
564 void_f_void_t null_f=NULL;
567 it = xbt_dynar_search(cb_list,&function);
570 if (e.category == not_found_error) {
572 xbt_die("Trying to remove a callback that is not here! This should not happen");
577 xbt_dynar_replace(cb_list, it,&null_f);
580 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
582 unsigned int iterator;
584 xbt_dynar_foreach(cb_list, iterator, fun) {
590 /* Prop tag functions */
595 void parse_properties(void)
597 if (!current_property_set)
598 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
600 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
604 /* Random tag functions */
606 double get_cpu_power(const char *power)
608 double power_scale = 0.0;
611 random_data_t random = NULL;
612 /* randomness is inserted like this: power="$rand(my_random)" */
613 if (((p = strstr(power, "$rand(")) != NULL)
614 && ((q = strstr(power, ")")) != NULL)) {
616 generator = xbt_malloc(q - (p + 6) + 1);
617 memcpy(generator, p + 6, q - (p + 6));
618 generator[q - (p + 6)] = '\0';
619 random = xbt_dict_get_or_null(random_data_list, generator);
620 xbt_assert(random, "Random generator %s undefined", generator);
621 power_scale = random_generate(random);
624 power_scale = surf_parse_get_double(power);
629 double random_min, random_max, random_mean, random_std_deviation,
633 static void init_randomness(void)
635 random_id = A_surfxml_random_id;
636 random_min = surf_parse_get_double(A_surfxml_random_min);
637 random_max = surf_parse_get_double(A_surfxml_random_max);
638 random_mean = surf_parse_get_double(A_surfxml_random_mean);
639 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
640 random_generator = A_surfxml_random_generator;
643 static void add_randomness(void)
645 /* If needed aditional properties can be added by using the prop tag */
646 random_data_t random =
647 random_new(random_generator, 0, random_min, random_max, random_mean,
648 random_std_deviation);
649 xbt_dict_set(random_data_list, random_id, (void *) random,