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. */
7 #include <stdarg.h> /* va_arg */
13 #include "surf/surfxml_parse.h"
14 #include "surf/surf_private.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
17 "Logging specific to the SURF parsing module");
19 int ETag_surfxml_include_state(void);
21 #include "simgrid_dtd.c"
23 char* surf_parsed_filename = NULL; // to locate parse error messages
28 void surf_parse_error(const char *fmt, ...) {
31 char *msg = bvprintf(fmt,va);
33 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
35 void surf_parse_warn(const char *fmt, ...) {
38 char *msg = bvprintf(fmt,va);
40 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
44 double surf_parse_get_double(const char *string) {
46 int ret = sscanf(string, "%lg", &res);
48 surf_parse_error("%s is not a double", string);
52 int surf_parse_get_int(const char *string) {
54 int ret = sscanf(string, "%d", &res);
56 surf_parse_error("%s is not an integer", string);
62 * All the callback lists that can be overridden anywhere.
63 * (this list should probably be reduced to the bare minimum to allow the models to work)
66 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
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_peer_cb_list = NULL;
78 xbt_dynar_t ETag_surfxml_peer_cb_list = NULL;
79 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
80 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
81 xbt_dynar_t STag_surfxml_trace_connect_cb_list = NULL;
82 xbt_dynar_t ETag_surfxml_trace_connect_cb_list = NULL;
83 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
84 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
85 xbt_dynar_t STag_surfxml_ASroute_cb_list = NULL;
86 xbt_dynar_t ETag_surfxml_ASroute_cb_list = NULL;
87 xbt_dynar_t STag_surfxml_bypassRoute_cb_list = NULL;
88 xbt_dynar_t ETag_surfxml_bypassRoute_cb_list = NULL;
89 xbt_dynar_t STag_surfxml_bypassASroute_cb_list = NULL;
90 xbt_dynar_t ETag_surfxml_bypassASroute_cb_list = NULL;
91 xbt_dynar_t STag_surfxml_include_cb_list = NULL;
92 xbt_dynar_t ETag_surfxml_include_cb_list = NULL;
94 xbt_dynar_t STag_surfxml_storage_cb_list = NULL;
95 xbt_dynar_t ETag_surfxml_storage_cb_list = NULL;
96 xbt_dynar_t STag_surfxml_storage_type_cb_list = NULL;
97 xbt_dynar_t ETag_surfxml_storage_type_cb_list = NULL;
98 xbt_dynar_t STag_surfxml_mount_cb_list = NULL;
99 xbt_dynar_t ETag_surfxml_mount_cb_list = NULL;
100 xbt_dynar_t STag_surfxml_mstorage_cb_list = NULL;
101 xbt_dynar_t ETag_surfxml_mstorage_cb_list = NULL;
103 /* The default current property receiver. Setup in the corresponding opening callbacks. */
104 xbt_dict_t current_property_set = NULL;
105 /* dictionary of random generator data */
106 xbt_dict_t random_data_list = NULL;
108 /* Call all the callbacks of a specific SAX event */
109 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
111 YY_BUFFER_STATE surf_input_buffer;
112 FILE *surf_file_to_parse = NULL;
114 static void init_randomness(void);
115 static void add_randomness(void);
118 * Stuff relative to storage
120 void STag_surfxml_storage(void)
122 XBT_DEBUG("STag_surfxml_storage");
124 void ETag_surfxml_storage(void)
126 s_sg_platf_storage_cbarg_t storage;
127 memset(&storage,0,sizeof(storage));
129 storage.id = A_surfxml_storage_id;
130 storage.type_id = A_surfxml_storage_typeId;
131 sg_platf_new_storage(&storage);
133 void STag_surfxml_storage_type(void)
135 XBT_DEBUG("STag_surfxml_storage_type");
136 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
138 void ETag_surfxml_storage_type(void)
140 s_sg_platf_storage_type_cbarg_t storage_type;
141 memset(&storage_type,0,sizeof(storage_type));
143 storage_type.content = A_surfxml_storage_type_content;
144 storage_type.id = A_surfxml_storage_type_id;
145 storage_type.model = A_surfxml_storage_type_model;
146 storage_type.properties = current_property_set;
147 sg_platf_new_storage_type(&storage_type);
148 current_property_set = NULL;
150 void STag_surfxml_mstorage(void)
152 XBT_DEBUG("STag_surfxml_mstorage");
154 void ETag_surfxml_mstorage(void)
156 s_sg_platf_mstorage_cbarg_t mstorage;
157 memset(&mstorage,0,sizeof(mstorage));
159 mstorage.name = A_surfxml_mstorage_name;
160 mstorage.type_id = A_surfxml_mstorage_typeId;
161 sg_platf_new_mstorage(&mstorage);
163 void STag_surfxml_mount(void)
165 XBT_DEBUG("STag_surfxml_mount");
167 void ETag_surfxml_mount(void)
169 s_sg_platf_mount_cbarg_t mount;
170 memset(&mount,0,sizeof(mount));
172 mount.name = A_surfxml_mount_name;
173 mount.id = A_surfxml_mount_id;
174 sg_platf_new_mount(&mount);
178 * Stuff relative to the <include> tag
180 static xbt_dynar_t surf_input_buffer_stack = NULL;
181 static xbt_dynar_t surf_file_to_parse_stack = NULL;
182 static xbt_dynar_t surf_parsed_filename_stack = NULL;
184 void STag_surfxml_include(void)
186 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
187 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
188 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
190 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
192 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
193 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
194 A_surfxml_include_file);
195 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
196 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
197 surf_parse_push_buffer_state(surf_input_buffer);
202 void ETag_surfxml_include(void) {
203 /* Nothing to do when done with reading the include tag.
204 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
207 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
209 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
210 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
211 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
212 * error message in that case.
214 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
215 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
216 * on a line. One day maybe, if the maya allow it.
218 int ETag_surfxml_include_state(void)
221 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
223 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
226 // Yeah, we were in an <include> Restore state and proceed.
227 fclose(surf_file_to_parse);
228 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
229 surf_parse_pop_buffer_state();
230 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
232 // Restore the filename for error messages
233 free(surf_parsed_filename);
234 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
240 void surf_parse_init_callbacks(void)
242 sg_platf_init(); // FIXME: move to a proper place?
244 STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
245 ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
246 STag_surfxml_link_ctn_cb_list =
247 xbt_dynar_new(sizeof(void_f_void_t), NULL);
248 ETag_surfxml_link_ctn_cb_list =
249 xbt_dynar_new(sizeof(void_f_void_t), NULL);
250 STag_surfxml_process_cb_list =
251 xbt_dynar_new(sizeof(void_f_void_t), NULL);
252 ETag_surfxml_process_cb_list =
253 xbt_dynar_new(sizeof(void_f_void_t), NULL);
254 STag_surfxml_argument_cb_list =
255 xbt_dynar_new(sizeof(void_f_void_t), NULL);
256 ETag_surfxml_argument_cb_list =
257 xbt_dynar_new(sizeof(void_f_void_t), NULL);
258 STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
259 ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
260 STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
261 ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
262 STag_surfxml_trace_connect_cb_list =
263 xbt_dynar_new(sizeof(void_f_void_t), NULL);
264 ETag_surfxml_trace_connect_cb_list =
265 xbt_dynar_new(sizeof(void_f_void_t), NULL);
266 STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
267 ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
268 STag_surfxml_ASroute_cb_list =
269 xbt_dynar_new(sizeof(void_f_void_t), NULL);
270 ETag_surfxml_ASroute_cb_list =
271 xbt_dynar_new(sizeof(void_f_void_t), NULL);
272 STag_surfxml_bypassRoute_cb_list =
273 xbt_dynar_new(sizeof(void_f_void_t), NULL);
274 ETag_surfxml_bypassRoute_cb_list =
275 xbt_dynar_new(sizeof(void_f_void_t), NULL);
276 STag_surfxml_bypassASroute_cb_list =
277 xbt_dynar_new(sizeof(void_f_void_t), NULL);
278 ETag_surfxml_bypassASroute_cb_list =
279 xbt_dynar_new(sizeof(void_f_void_t), NULL);
280 STag_surfxml_peer_cb_list =
281 xbt_dynar_new(sizeof(void_f_void_t), NULL);
282 ETag_surfxml_peer_cb_list =
283 xbt_dynar_new(sizeof(void_f_void_t), NULL);
284 STag_surfxml_include_cb_list =
285 xbt_dynar_new(sizeof(void_f_void_t), NULL);
286 ETag_surfxml_include_cb_list =
287 xbt_dynar_new(sizeof(void_f_void_t), NULL);
289 STag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
290 ETag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
291 STag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
292 ETag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
293 STag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
294 ETag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
295 STag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
296 ETag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
299 void surf_parse_reset_callbacks(void)
301 surf_parse_free_callbacks();
302 surf_parse_init_callbacks();
305 void surf_parse_free_callbacks(void)
307 sg_platf_exit(); // FIXME: better place?
309 xbt_dynar_free(&STag_surfxml_route_cb_list);
310 xbt_dynar_free(&ETag_surfxml_route_cb_list);
311 xbt_dynar_free(&STag_surfxml_link_ctn_cb_list);
312 xbt_dynar_free(&ETag_surfxml_link_ctn_cb_list);
313 xbt_dynar_free(&STag_surfxml_process_cb_list);
314 xbt_dynar_free(&ETag_surfxml_process_cb_list);
315 xbt_dynar_free(&STag_surfxml_argument_cb_list);
316 xbt_dynar_free(&ETag_surfxml_argument_cb_list);
317 xbt_dynar_free(&STag_surfxml_prop_cb_list);
318 xbt_dynar_free(&ETag_surfxml_prop_cb_list);
319 xbt_dynar_free(&STag_surfxml_trace_cb_list);
320 xbt_dynar_free(&ETag_surfxml_trace_cb_list);
321 xbt_dynar_free(&STag_surfxml_trace_connect_cb_list);
322 xbt_dynar_free(&ETag_surfxml_trace_connect_cb_list);
323 xbt_dynar_free(&STag_surfxml_random_cb_list);
324 xbt_dynar_free(&ETag_surfxml_random_cb_list);
325 xbt_dynar_free(&STag_surfxml_ASroute_cb_list);
326 xbt_dynar_free(&ETag_surfxml_ASroute_cb_list);
327 xbt_dynar_free(&STag_surfxml_bypassRoute_cb_list);
328 xbt_dynar_free(&ETag_surfxml_bypassRoute_cb_list);
329 xbt_dynar_free(&STag_surfxml_bypassASroute_cb_list);
330 xbt_dynar_free(&ETag_surfxml_bypassASroute_cb_list);
331 xbt_dynar_free(&STag_surfxml_peer_cb_list);
332 xbt_dynar_free(&ETag_surfxml_peer_cb_list);
333 xbt_dynar_free(&STag_surfxml_include_cb_list);
334 xbt_dynar_free(&ETag_surfxml_include_cb_list);
336 xbt_dynar_free(&STag_surfxml_storage_cb_list);
337 xbt_dynar_free(&ETag_surfxml_storage_cb_list);
338 xbt_dynar_free(&STag_surfxml_mstorage_cb_list);
339 xbt_dynar_free(&ETag_surfxml_mstorage_cb_list);
340 xbt_dynar_free(&STag_surfxml_mount_cb_list);
341 xbt_dynar_free(&ETag_surfxml_mount_cb_list);
342 xbt_dynar_free(&STag_surfxml_storage_type_cb_list);
343 xbt_dynar_free(&ETag_surfxml_storage_type_cb_list);
346 /* Stag and Etag parse functions */
347 void ETag_surfxml_router(void) { /* ignored -- do not add content here */ }
349 void STag_surfxml_platform(void) {
350 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
352 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
353 "You're using an ancient XML file.\n"
354 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
355 "instead of MBytes, MFlops and seconds.\n"
357 "Use simgrid_update_xml to update your file automatically. "
358 "This program is installed automatically with SimGrid, or "
359 "available in the tools/ directory of the source archive.\n"
361 "Please check also out the SURF section of the ChangeLog for "
362 "the 3.1 version for more information. \n"
364 "Last, do not forget to also update your values for "
365 "the calls to MSG_task_create (if any).");
366 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
367 "You're using an old XML file.\n"
368 "Use simgrid_update_xml to update your file automatically. "
369 "This program is installed automatically with SimGrid, or "
370 "available in the tools/ directory of the source archive.");
374 void ETag_surfxml_platform(void){
378 void STag_surfxml_host(void){
379 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
382 void ETag_surfxml_host(void) {
383 s_sg_platf_host_cbarg_t host;
384 memset(&host,0,sizeof(host));
386 host.properties = current_property_set;
388 host.id = A_surfxml_host_id;
389 host.power_peak = get_cpu_power(A_surfxml_host_power);
390 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
391 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
392 host.power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
393 host.state_trace = tmgr_trace_new(A_surfxml_host_state_file);
394 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
395 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
396 if (A_surfxml_host_state == A_surfxml_host_state_ON)
397 host.initial_state = SURF_RESOURCE_ON;
398 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
399 host.initial_state = SURF_RESOURCE_OFF;
400 host.coord = A_surfxml_host_coordinates;
402 sg_platf_new_host(&host);
403 current_property_set = NULL;
406 void STag_surfxml_router(void){
407 s_sg_platf_router_cbarg_t router;
408 memset(&router, 0, sizeof(router));
410 router.id = A_surfxml_router_id;
411 router.coord = A_surfxml_router_coordinates;
413 sg_platf_new_router(&router);
416 void STag_surfxml_cluster(void){
417 s_sg_platf_cluster_cbarg_t cluster;
418 memset(&cluster,0,sizeof(cluster));
419 cluster.id = A_surfxml_cluster_id;
420 cluster.prefix = A_surfxml_cluster_prefix;
421 cluster.suffix = A_surfxml_cluster_suffix;
422 cluster.radical = A_surfxml_cluster_radical;
423 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
424 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
425 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
426 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
427 if(strcmp(A_surfxml_cluster_bb_bw,""))
428 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
429 if(strcmp(A_surfxml_cluster_bb_lat,""))
430 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
431 cluster.router_id = A_surfxml_cluster_router_id;
433 switch (AX_surfxml_cluster_sharing_policy) {
434 case A_surfxml_cluster_sharing_policy_SHARED:
435 cluster.sharing_policy = SURF_LINK_SHARED;
437 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
438 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
440 case A_surfxml_cluster_sharing_policy_FATPIPE:
441 cluster.sharing_policy = SURF_LINK_FATPIPE;
444 surf_parse_error("Invalid cluster sharing policy for cluster %s",
448 switch (AX_surfxml_cluster_bb_sharing_policy) {
449 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
450 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
452 case A_surfxml_cluster_bb_sharing_policy_SHARED:
453 cluster.bb_sharing_policy = SURF_LINK_SHARED;
456 surf_parse_error("Invalid bb sharing policy in cluster %s",
461 cluster.availability_trace = A_surfxml_cluster_availability_file;
462 cluster.state_trace = A_surfxml_cluster_state_file;
463 sg_platf_new_cluster(&cluster);
465 void ETag_surfxml_cluster(void){
466 /* nothing I can think of */
469 void STag_surfxml_peer(void){
470 s_sg_platf_peer_cbarg_t peer;
471 memset(&peer,0,sizeof(peer));
472 peer.id = A_surfxml_peer_id;
473 peer.power = surf_parse_get_double(A_surfxml_peer_power);
474 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
475 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
476 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
477 peer.coord = A_surfxml_peer_coordinates;
478 peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
479 peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
481 surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
482 sg_platf_new_peer(&peer);
484 void ETag_surfxml_peer(void){
485 /* nothing to do here */
487 void STag_surfxml_link(void){
488 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
490 void ETag_surfxml_link(void){
491 s_sg_platf_link_cbarg_t link;
492 memset(&link,0,sizeof(link));
494 link.properties = current_property_set;
496 link.id = A_surfxml_link_id;
497 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
498 link.bandwidth_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
499 link.latency = surf_parse_get_double(A_surfxml_link_latency);
500 link.latency_trace = tmgr_trace_new(A_surfxml_link_latency_file);
502 switch (A_surfxml_link_state) {
503 case A_surfxml_link_state_ON:
504 link.state = SURF_RESOURCE_ON;
506 case A_surfxml_link_state_OFF:
507 link.state = SURF_RESOURCE_OFF;
510 surf_parse_error("invalid state for link %s", link.id);
513 link.state_trace = tmgr_trace_new(A_surfxml_link_state_file);
515 switch (A_surfxml_link_sharing_policy) {
516 case A_surfxml_link_sharing_policy_SHARED:
517 link.policy = SURF_LINK_SHARED;
519 case A_surfxml_link_sharing_policy_FATPIPE:
520 link.policy = SURF_LINK_FATPIPE;
522 case A_surfxml_link_sharing_policy_FULLDUPLEX:
523 link.policy = SURF_LINK_FULLDUPLEX;
526 surf_parse_error("Invalid sharing policy in link %s", link.id);
530 sg_platf_new_link(&link);
532 current_property_set = NULL;
535 void STag_surfxml_route(void){
536 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
538 void STag_surfxml_link_ctn(void){
539 surfxml_call_cb_functions(STag_surfxml_link_ctn_cb_list);
541 void STag_surfxml_process(void){
542 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
544 void STag_surfxml_argument(void){
545 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
547 void STag_surfxml_prop(void){
548 surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
550 void STag_surfxml_trace(void){
551 surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
553 void STag_surfxml_trace_connect(void){
554 surfxml_call_cb_functions(STag_surfxml_trace_connect_cb_list);
556 void STag_surfxml_AS(void){
557 sg_platf_new_AS_begin(A_surfxml_AS_id,A_surfxml_AS_routing);
559 void ETag_surfxml_AS(void){
560 sg_platf_new_AS_end();
562 void STag_surfxml_ASroute(void){
563 surfxml_call_cb_functions(STag_surfxml_ASroute_cb_list);
565 void STag_surfxml_bypassRoute(void){
566 surfxml_call_cb_functions(STag_surfxml_bypassRoute_cb_list);
568 void STag_surfxml_bypassASroute(void){
569 surfxml_call_cb_functions(STag_surfxml_bypassASroute_cb_list);
571 void STag_surfxml_config(void){
572 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
573 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
575 void ETag_surfxml_config(void){
576 xbt_dict_cursor_t cursor = NULL;
580 xbt_dict_foreach(current_property_set, cursor, key, elem) {
581 cfg = bprintf("%s:%s",key,elem);
582 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
583 xbt_cfg_set_parse(_surf_cfg_set, cfg);
585 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
588 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
589 xbt_dict_free(¤t_property_set);
591 void STag_surfxml_random(void){
592 surfxml_call_cb_functions(STag_surfxml_random_cb_list);
595 #define parse_method(type,name) \
596 void type##Tag_surfxml_##name(void) \
597 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
598 parse_method(E, route)
599 parse_method(E, link_ctn)
600 parse_method(E, process)
601 parse_method(E, argument)
602 parse_method(E, prop)
603 parse_method(E, trace)
604 parse_method(E, trace_connect)
605 parse_method(E, random)
606 parse_method(E, ASroute)
607 parse_method(E, bypassRoute)
608 parse_method(E, bypassASroute)
610 /* Open and Close parse file */
612 void surf_parse_open(const char *file)
614 static int warned = 0; /* warn only once */
618 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
619 "If it is not what you want, go fix your code.");
625 if (!surf_input_buffer_stack)
626 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
627 if (!surf_file_to_parse_stack)
628 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
630 if (!surf_parsed_filename_stack)
631 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
632 surf_parsed_filename = xbt_strdup(file);
634 surf_file_to_parse = surf_fopen(file, "r");
635 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
636 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
637 surf_parse__switch_to_buffer(surf_input_buffer);
638 surf_parse_lineno = 1;
641 void surf_parse_close(void)
643 xbt_dynar_free(&surf_input_buffer_stack);
644 xbt_dynar_free(&surf_file_to_parse_stack);
645 xbt_dynar_free(&surf_parsed_filename_stack);
647 free(surf_parsed_filename);
649 if (surf_file_to_parse) {
650 surf_parse__delete_buffer(surf_input_buffer);
651 fclose(surf_file_to_parse);
652 surf_file_to_parse = NULL; //Must be reset for Bypass
656 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
658 static int _surf_parse(void) {
659 return surf_parse_lex();
661 int_f_void_t surf_parse = _surf_parse;
664 /* Aux parse functions */
666 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
668 xbt_dynar_push(cb_list, &function);
671 void surfxml_del_callback(xbt_dynar_t cb_list, void_f_void_t function)
675 void_f_void_t null_f=NULL;
678 it = xbt_dynar_search(cb_list,&function);
681 if (e.category == not_found_error) {
683 xbt_die("Trying to remove a callback that is not here! This should not happen");
688 xbt_dynar_replace(cb_list, it,&null_f);
691 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
693 unsigned int iterator;
695 xbt_dynar_foreach(cb_list, iterator, fun) {
701 /* Prop tag functions */
706 void parse_properties(void)
708 if (!current_property_set)
709 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
711 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
715 /* Random tag functions */
717 double get_cpu_power(const char *power)
719 double power_scale = 0.0;
722 random_data_t random = NULL;
723 /* randomness is inserted like this: power="$rand(my_random)" */
724 if (((p = strstr(power, "$rand(")) != NULL)
725 && ((q = strstr(power, ")")) != NULL)) {
727 generator = xbt_malloc(q - (p + 6) + 1);
728 memcpy(generator, p + 6, q - (p + 6));
729 generator[q - (p + 6)] = '\0';
730 random = xbt_dict_get_or_null(random_data_list, generator);
731 xbt_assert(random, "Random generator %s undefined", generator);
732 power_scale = random_generate(random);
735 power_scale = surf_parse_get_double(power);
740 double random_min, random_max, random_mean, random_std_deviation;
741 e_random_generator_t random_generator;
744 static void init_randomness(void)
746 random_id = A_surfxml_random_id;
747 random_min = surf_parse_get_double(A_surfxml_random_min);
748 random_max = surf_parse_get_double(A_surfxml_random_max);
749 random_mean = surf_parse_get_double(A_surfxml_random_mean);
750 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
751 switch (A_surfxml_random_generator) {
752 case AU_surfxml_random_generator:
753 case A_surfxml_random_generator_NONE:
754 random_generator = NONE;
756 case A_surfxml_random_generator_DRAND48:
757 random_generator = DRAND48;
759 case A_surfxml_random_generator_RAND:
760 random_generator = RAND;
762 case A_surfxml_random_generator_RNGSTREAM:
763 random_generator = RNGSTREAM;
766 surf_parse_error("Invalid random generator");
771 static void add_randomness(void)
773 /* If needed aditional properties can be added by using the prop tag */
774 random_data_t random =
775 random_new(random_generator, 0, random_min, random_max, random_mean,
776 random_std_deviation);
777 xbt_dict_set(random_data_list, random_id, (void *) random,