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
25 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
30 void surf_parse_error(const char *fmt, ...) {
33 char *msg = bvprintf(fmt,va);
35 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
37 void surf_parse_warn(const char *fmt, ...) {
40 char *msg = bvprintf(fmt,va);
42 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
46 double surf_parse_get_double(const char *string) {
48 int ret = sscanf(string, "%lg", &res);
50 surf_parse_error("%s is not a double", string);
54 int surf_parse_get_int(const char *string) {
56 int ret = sscanf(string, "%d", &res);
58 surf_parse_error("%s is not an integer", string);
64 * All the callback lists that can be overridden anywhere.
65 * (this list should probably be reduced to the bare minimum to allow the models to work)
68 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
70 /* The default current property receiver. Setup in the corresponding opening callbacks. */
71 xbt_dict_t current_property_set = NULL;
72 /* dictionary of random generator data */
73 xbt_dict_t random_data_list = NULL;
75 /* Call all the callbacks of a specific SAX event */
76 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
78 YY_BUFFER_STATE surf_input_buffer;
79 FILE *surf_file_to_parse = NULL;
81 static void init_randomness(void);
82 static void add_randomness(void);
85 * Stuff relative to storage
87 void STag_surfxml_storage(void)
89 XBT_DEBUG("STag_surfxml_storage");
91 void ETag_surfxml_storage(void)
93 s_sg_platf_storage_cbarg_t storage;
94 memset(&storage,0,sizeof(storage));
96 storage.id = A_surfxml_storage_id;
97 storage.type_id = A_surfxml_storage_typeId;
98 storage.content = A_surfxml_storage_content;
99 sg_platf_new_storage(&storage);
101 void STag_surfxml_storage_type(void)
103 XBT_DEBUG("STag_surfxml_storage_type");
104 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
106 void ETag_surfxml_storage_type(void)
108 s_sg_platf_storage_type_cbarg_t storage_type;
109 memset(&storage_type,0,sizeof(storage_type));
111 storage_type.content = A_surfxml_storage_type_content;
112 storage_type.id = A_surfxml_storage_type_id;
113 storage_type.model = A_surfxml_storage_type_model;
114 storage_type.properties = current_property_set;
115 storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
116 sg_platf_new_storage_type(&storage_type);
117 current_property_set = NULL;
119 void STag_surfxml_mstorage(void)
121 XBT_DEBUG("STag_surfxml_mstorage");
123 void ETag_surfxml_mstorage(void)
125 s_sg_platf_mstorage_cbarg_t mstorage;
126 memset(&mstorage,0,sizeof(mstorage));
128 mstorage.name = A_surfxml_mstorage_name;
129 mstorage.type_id = A_surfxml_mstorage_typeId;
130 sg_platf_new_mstorage(&mstorage);
132 void STag_surfxml_mount(void)
134 XBT_DEBUG("STag_surfxml_mount");
136 void ETag_surfxml_mount(void)
138 s_sg_platf_mount_cbarg_t mount;
139 memset(&mount,0,sizeof(mount));
141 mount.name = A_surfxml_mount_name;
142 mount.id = A_surfxml_mount_id;
143 sg_platf_new_mount(&mount);
147 * Stuff relative to the <include> tag
149 static xbt_dynar_t surf_input_buffer_stack = NULL;
150 static xbt_dynar_t surf_file_to_parse_stack = NULL;
151 static xbt_dynar_t surf_parsed_filename_stack = NULL;
153 void STag_surfxml_include(void)
155 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
156 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
157 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
159 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
161 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
162 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
163 A_surfxml_include_file);
164 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
165 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
166 surf_parse_push_buffer_state(surf_input_buffer);
171 void ETag_surfxml_include(void) {
172 /* Nothing to do when done with reading the include tag.
173 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
176 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
178 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
179 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
180 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
181 * error message in that case.
183 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
184 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
185 * on a line. One day maybe, if the maya allow it.
187 int ETag_surfxml_include_state(void)
190 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
192 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
195 // Yeah, we were in an <include> Restore state and proceed.
196 fclose(surf_file_to_parse);
197 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
198 surf_parse_pop_buffer_state();
199 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
201 // Restore the filename for error messages
202 free(surf_parsed_filename);
203 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
209 void surf_parse_init_callbacks(void)
214 void surf_parse_reset_callbacks(void)
216 surf_parse_free_callbacks();
217 surf_parse_init_callbacks();
220 void surf_parse_free_callbacks(void)
225 /* Stag and Etag parse functions */
227 void STag_surfxml_platform(void) {
228 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
230 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
231 "You're using an ancient XML file.\n"
232 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
233 "instead of MBytes, MFlops and seconds.\n"
235 "Use simgrid_update_xml to update your file automatically. "
236 "This program is installed automatically with SimGrid, or "
237 "available in the tools/ directory of the source archive.\n"
239 "Please check also out the SURF section of the ChangeLog for "
240 "the 3.1 version for more information. \n"
242 "Last, do not forget to also update your values for "
243 "the calls to MSG_task_create (if any).");
244 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
245 "You're using an old XML file.\n"
246 "Use simgrid_update_xml to update your file automatically. "
247 "This program is installed automatically with SimGrid, or "
248 "available in the tools/ directory of the source archive.");
252 void ETag_surfxml_platform(void){
256 void STag_surfxml_host(void){
257 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
260 void STag_surfxml_prop(void)
262 if (!current_property_set)
263 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
265 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
268 void ETag_surfxml_host(void) {
269 s_sg_platf_host_cbarg_t host;
270 memset(&host,0,sizeof(host));
272 host.properties = current_property_set;
274 host.id = A_surfxml_host_id;
275 host.power_peak = get_cpu_power(A_surfxml_host_power);
276 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
277 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
278 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
279 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
280 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
281 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
282 if (A_surfxml_host_state == A_surfxml_host_state_ON)
283 host.initial_state = SURF_RESOURCE_ON;
284 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
285 host.initial_state = SURF_RESOURCE_OFF;
286 host.coord = A_surfxml_host_coordinates;
288 sg_platf_new_host(&host);
289 current_property_set = NULL;
292 void STag_surfxml_host_link(void){
293 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host_link_id);
294 s_sg_platf_host_link_cbarg_t host_link;
295 memset(&host_link,0,sizeof(host_link));
297 host_link.id = A_surfxml_host_link_id;
298 host_link.link_up = A_surfxml_host_link_up;
299 host_link.link_down = A_surfxml_host_link_down;
300 sg_platf_new_host_link(&host_link);
303 void STag_surfxml_router(void){
304 s_sg_platf_router_cbarg_t router;
305 memset(&router, 0, sizeof(router));
307 router.id = A_surfxml_router_id;
308 router.coord = A_surfxml_router_coordinates;
310 sg_platf_new_router(&router);
313 void STag_surfxml_cluster(void){
314 s_sg_platf_cluster_cbarg_t cluster;
315 memset(&cluster,0,sizeof(cluster));
316 cluster.id = A_surfxml_cluster_id;
317 cluster.prefix = A_surfxml_cluster_prefix;
318 cluster.suffix = A_surfxml_cluster_suffix;
319 cluster.radical = A_surfxml_cluster_radical;
320 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
321 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
322 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
323 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
324 if(strcmp(A_surfxml_cluster_bb_bw,""))
325 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
326 if(strcmp(A_surfxml_cluster_bb_lat,""))
327 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
328 cluster.router_id = A_surfxml_cluster_router_id;
330 switch (AX_surfxml_cluster_sharing_policy) {
331 case A_surfxml_cluster_sharing_policy_SHARED:
332 cluster.sharing_policy = SURF_LINK_SHARED;
334 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
335 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
337 case A_surfxml_cluster_sharing_policy_FATPIPE:
338 cluster.sharing_policy = SURF_LINK_FATPIPE;
341 surf_parse_error("Invalid cluster sharing policy for cluster %s",
345 switch (AX_surfxml_cluster_bb_sharing_policy) {
346 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
347 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
349 case A_surfxml_cluster_bb_sharing_policy_SHARED:
350 cluster.bb_sharing_policy = SURF_LINK_SHARED;
353 surf_parse_error("Invalid bb sharing policy in cluster %s",
358 cluster.availability_trace = A_surfxml_cluster_availability_file;
359 cluster.state_trace = A_surfxml_cluster_state_file;
360 sg_platf_new_cluster(&cluster);
363 void STag_surfxml_cabinet(void){
364 s_sg_platf_cabinet_cbarg_t cabinet;
365 memset(&cabinet,0,sizeof(cabinet));
366 cabinet.id = A_surfxml_cabinet_id;
367 cabinet.prefix = A_surfxml_cabinet_prefix;
368 cabinet.suffix = A_surfxml_cabinet_suffix;
369 cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power);
370 cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw);
371 cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat);
372 cabinet.radical = A_surfxml_cabinet_radical;
374 sg_platf_new_cabinet(&cabinet);
377 void STag_surfxml_peer(void){
378 s_sg_platf_peer_cbarg_t peer;
379 memset(&peer,0,sizeof(peer));
380 peer.id = A_surfxml_peer_id;
381 peer.power = surf_parse_get_double(A_surfxml_peer_power);
382 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
383 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
384 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
385 peer.coord = A_surfxml_peer_coordinates;
386 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
387 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
389 sg_platf_new_peer(&peer);
392 void STag_surfxml_link(void){
393 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
396 void ETag_surfxml_link(void){
397 s_sg_platf_link_cbarg_t link;
398 memset(&link,0,sizeof(link));
400 link.properties = current_property_set;
402 link.id = A_surfxml_link_id;
403 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
404 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
405 link.latency = surf_parse_get_double(A_surfxml_link_latency);
406 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
408 switch (A_surfxml_link_state) {
409 case A_surfxml_link_state_ON:
410 link.state = SURF_RESOURCE_ON;
412 case A_surfxml_link_state_OFF:
413 link.state = SURF_RESOURCE_OFF;
416 surf_parse_error("invalid state for link %s", link.id);
419 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
421 switch (A_surfxml_link_sharing_policy) {
422 case A_surfxml_link_sharing_policy_SHARED:
423 link.policy = SURF_LINK_SHARED;
425 case A_surfxml_link_sharing_policy_FATPIPE:
426 link.policy = SURF_LINK_FATPIPE;
428 case A_surfxml_link_sharing_policy_FULLDUPLEX:
429 link.policy = SURF_LINK_FULLDUPLEX;
432 surf_parse_error("Invalid sharing policy in link %s", link.id);
436 sg_platf_new_link(&link);
438 current_property_set = NULL;
441 void STag_surfxml_link_ctn(void){
444 switch (A_surfxml_link_ctn_direction) {
445 case AU_surfxml_link_ctn_direction:
446 case A_surfxml_link_ctn_direction_NONE:
447 link_id = xbt_strdup(A_surfxml_link_ctn_id);
449 case A_surfxml_link_ctn_direction_UP:
450 link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
452 case A_surfxml_link_ctn_direction_DOWN:
453 link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
457 // FIXME we should push the surf link object but it don't
458 // work because of model rulebased
459 xbt_dynar_push(parsed_link_list, &link_id);
462 void ETag_surfxml_backbone(void){
463 s_sg_platf_link_cbarg_t link;
464 memset(&link,0,sizeof(link));
466 link.properties = NULL;
468 link.id = A_surfxml_backbone_id;
469 link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth);
470 link.latency = surf_parse_get_double(A_surfxml_backbone_latency);
471 link.state = SURF_RESOURCE_ON;
472 link.policy = SURF_LINK_SHARED;
474 sg_platf_new_link(&link);
475 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
476 current_property_set = NULL;
479 void STag_surfxml_route(void){
480 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
481 "Missing end-points while defining route \"%s\"->\"%s\"",
482 A_surfxml_route_src, A_surfxml_route_dst);
483 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
485 void STag_surfxml_ASroute(void){
486 xbt_assert(strlen(A_surfxml_ASroute_src) > 0 || strlen(A_surfxml_ASroute_dst) > 0
487 || strlen(A_surfxml_ASroute_gw_src) > 0 || strlen(A_surfxml_ASroute_gw_dst) > 0,
488 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
489 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
490 A_surfxml_ASroute_gw_src,A_surfxml_ASroute_gw_dst);
491 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
493 void STag_surfxml_bypassRoute(void){
494 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0 || strlen(A_surfxml_bypassRoute_dst) > 0,
495 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
496 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
497 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
499 void STag_surfxml_bypassASroute(void){
500 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0 || strlen(A_surfxml_bypassASroute_dst) > 0
501 || strlen(A_surfxml_bypassASroute_gw_src) > 0 || strlen(A_surfxml_bypassASroute_gw_dst) > 0,
502 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
503 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
504 A_surfxml_bypassASroute_gw_src,A_surfxml_bypassASroute_gw_dst);
505 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
508 void ETag_surfxml_route(void){
509 s_sg_platf_route_cbarg_t route;
510 memset(&route,0,sizeof(route));
512 route.src = A_surfxml_route_src;
513 route.dst = A_surfxml_route_dst;
514 route.link_list = parsed_link_list;
516 switch (A_surfxml_route_symmetrical) {
517 case AU_surfxml_route_symmetrical:
518 case A_surfxml_route_symmetrical_YES:
519 route.symmetrical = TRUE;
521 case A_surfxml_route_symmetrical_NO:
522 route.symmetrical = FALSE;;
526 sg_platf_new_route(&route);
527 parsed_link_list = NULL;
530 void ETag_surfxml_ASroute(void){
531 s_sg_platf_ASroute_cbarg_t ASroute;
532 memset(&ASroute,0,sizeof(ASroute));
534 ASroute.src = A_surfxml_ASroute_src;
535 ASroute.dst = A_surfxml_ASroute_dst;
536 ASroute.gw_src = A_surfxml_ASroute_gw_src;
537 ASroute.gw_dst = A_surfxml_ASroute_gw_dst;
538 ASroute.link_list = parsed_link_list;
540 switch (A_surfxml_ASroute_symmetrical) {
541 case AU_surfxml_ASroute_symmetrical:
542 case A_surfxml_ASroute_symmetrical_YES:
543 ASroute.symmetrical = TRUE;
545 case A_surfxml_ASroute_symmetrical_NO:
546 ASroute.symmetrical = FALSE;;
550 sg_platf_new_ASroute(&ASroute);
551 parsed_link_list = NULL;
554 void ETag_surfxml_bypassRoute(void){
555 s_sg_platf_bypassRoute_cbarg_t route;
556 memset(&route,0,sizeof(route));
558 route.src = A_surfxml_bypassRoute_src;
559 route.dst = A_surfxml_bypassRoute_dst;
560 route.link_list = parsed_link_list;
562 sg_platf_new_bypassRoute(&route);
563 parsed_link_list = NULL;
566 void ETag_surfxml_bypassASroute(void){
567 s_sg_platf_bypassASroute_cbarg_t ASroute;
568 memset(&ASroute,0,sizeof(ASroute));
570 ASroute.src = A_surfxml_bypassASroute_src;
571 ASroute.dst = A_surfxml_bypassASroute_dst;
572 ASroute.gw_src = A_surfxml_bypassASroute_gw_src;
573 ASroute.gw_dst = A_surfxml_bypassASroute_gw_dst;
574 ASroute.link_list = parsed_link_list;
576 sg_platf_new_bypassASroute(&ASroute);
577 parsed_link_list = NULL;
580 void ETag_surfxml_trace(void){
581 s_sg_platf_trace_cbarg_t trace;
582 memset(&trace,0,sizeof(trace));
584 trace.id = A_surfxml_trace_id;
585 trace.file = A_surfxml_trace_file;
586 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
587 trace.pc_data = surfxml_pcdata;
589 sg_platf_new_trace(&trace);
592 void STag_surfxml_trace_connect(void){
593 s_sg_platf_trace_connect_cbarg_t trace_connect;
594 memset(&trace_connect,0,sizeof(trace_connect));
596 trace_connect.element = A_surfxml_trace_connect_element;
597 trace_connect.trace = A_surfxml_trace_connect_trace;
599 switch (A_surfxml_trace_connect_kind) {
600 case AU_surfxml_trace_connect_kind:
601 case A_surfxml_trace_connect_kind_POWER:
602 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
604 case A_surfxml_trace_connect_kind_BANDWIDTH:
605 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
607 case A_surfxml_trace_connect_kind_HOST_AVAIL:
608 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
610 case A_surfxml_trace_connect_kind_LATENCY:
611 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
613 case A_surfxml_trace_connect_kind_LINK_AVAIL:
614 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
617 sg_platf_new_trace_connect(&trace_connect);
620 void STag_surfxml_AS(void){
621 sg_platf_new_AS_begin(A_surfxml_AS_id, (int)A_surfxml_AS_routing);
623 void ETag_surfxml_AS(void){
624 sg_platf_new_AS_end();
627 void STag_surfxml_config(void){
628 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
629 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
631 void ETag_surfxml_config(void){
632 xbt_dict_cursor_t cursor = NULL;
636 xbt_dict_foreach(current_property_set, cursor, key, elem) {
637 cfg = bprintf("%s:%s",key,elem);
638 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
639 xbt_cfg_set_parse(_surf_cfg_set, cfg);
641 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
644 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
645 xbt_dict_free(¤t_property_set);
651 void STag_surfxml_process(void){
653 argv = xbt_new(char *, 1);
654 argv[0] = xbt_strdup(A_surfxml_process_function);
657 void ETag_surfxml_process(void){
658 s_sg_platf_process_cbarg_t process;
659 memset(&process,0,sizeof(process));
662 process.argv = (const char **)argv;
663 process.properties = current_property_set;
664 process.host = A_surfxml_process_host;
665 process.function = A_surfxml_process_function;
666 process.start_time = surf_parse_get_double(A_surfxml_process_start_time);
667 process.kill_time = surf_parse_get_double(A_surfxml_process_kill_time);
669 switch (A_surfxml_process_on_failure) {
670 case AU_surfxml_process_on_failure:
671 case A_surfxml_process_on_failure_DIE:
672 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
674 case A_surfxml_process_on_failure_RESTART:
675 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
679 sg_platf_new_process(&process);
680 current_property_set = NULL;
683 void STag_surfxml_argument(void){
685 argv = xbt_realloc(argv, (argc) * sizeof(char *));
686 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
689 /* nothing to do in those functions */
690 void ETag_surfxml_prop(void){}
691 void STag_surfxml_random(void){}
692 void ETag_surfxml_random(void){}
693 void ETag_surfxml_trace_connect(void){}
694 void STag_surfxml_trace(void){}
695 void ETag_surfxml_router(void){}
696 void ETag_surfxml_host_link(void){}
697 void ETag_surfxml_cluster(void){}
698 void ETag_surfxml_cabinet(void){}
699 void ETag_surfxml_peer(void){}
700 void STag_surfxml_backbone(void){}
701 void ETag_surfxml_link_ctn(void){}
702 void ETag_surfxml_argument(void){}
704 /* Open and Close parse file */
706 void surf_parse_open(const char *file)
708 static int warned = 0; /* warn only once */
712 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
713 "If it is not what you want, go fix your code.");
719 if (!surf_input_buffer_stack)
720 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
721 if (!surf_file_to_parse_stack)
722 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
724 if (!surf_parsed_filename_stack)
725 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
726 surf_parsed_filename = xbt_strdup(file);
728 surf_file_to_parse = surf_fopen(file, "r");
729 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
730 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
731 surf_parse__switch_to_buffer(surf_input_buffer);
732 surf_parse_lineno = 1;
735 void surf_parse_close(void)
737 xbt_dynar_free(&surf_input_buffer_stack);
738 xbt_dynar_free(&surf_file_to_parse_stack);
739 xbt_dynar_free(&surf_parsed_filename_stack);
741 free(surf_parsed_filename);
743 if (surf_file_to_parse) {
744 surf_parse__delete_buffer(surf_input_buffer);
745 fclose(surf_file_to_parse);
746 surf_file_to_parse = NULL; //Must be reset for Bypass
750 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
752 static int _surf_parse(void) {
753 return surf_parse_lex();
755 int_f_void_t surf_parse = _surf_parse;
758 /* Prop tag functions */
764 /* Random tag functions */
766 double get_cpu_power(const char *power)
768 double power_scale = 0.0;
771 random_data_t random = NULL;
772 /* randomness is inserted like this: power="$rand(my_random)" */
773 if (((p = strstr(power, "$rand(")) != NULL)
774 && ((q = strstr(power, ")")) != NULL)) {
776 generator = xbt_malloc(q - (p + 6) + 1);
777 memcpy(generator, p + 6, q - (p + 6));
778 generator[q - (p + 6)] = '\0';
779 random = xbt_dict_get_or_null(random_data_list, generator);
780 xbt_assert(random, "Random generator %s undefined", generator);
781 power_scale = random_generate(random);
784 power_scale = surf_parse_get_double(power);
789 double random_min, random_max, random_mean, random_std_deviation;
790 e_random_generator_t random_generator;
793 static void init_randomness(void)
795 random_id = A_surfxml_random_id;
796 random_min = surf_parse_get_double(A_surfxml_random_min);
797 random_max = surf_parse_get_double(A_surfxml_random_max);
798 random_mean = surf_parse_get_double(A_surfxml_random_mean);
799 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
800 switch (A_surfxml_random_generator) {
801 case AU_surfxml_random_generator:
802 case A_surfxml_random_generator_NONE:
803 random_generator = NONE;
805 case A_surfxml_random_generator_DRAND48:
806 random_generator = DRAND48;
808 case A_surfxml_random_generator_RAND:
809 random_generator = RAND;
811 case A_surfxml_random_generator_RNGSTREAM:
812 random_generator = RNGSTREAM;
815 surf_parse_error("Invalid random generator");
820 static void add_randomness(void)
822 /* If needed aditional properties can be added by using the prop tag */
823 random_data_t random =
824 random_new(random_generator, 0, random_min, random_max, random_mean,
825 random_std_deviation);
826 xbt_dict_set(random_data_list, random_id, (void *) random,