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 */
68 /* The default current property receiver. Setup in the corresponding opening callbacks. */
69 xbt_dict_t current_property_set = NULL;
70 /* dictionary of random generator data */
71 xbt_dict_t random_data_list = NULL;
73 /* Call all the callbacks of a specific SAX event */
74 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
76 YY_BUFFER_STATE surf_input_buffer;
77 FILE *surf_file_to_parse = NULL;
79 static void init_randomness(void);
80 static void add_randomness(void);
83 * Stuff relative to storage
85 void STag_surfxml_storage(void)
87 XBT_DEBUG("STag_surfxml_storage");
89 void ETag_surfxml_storage(void)
91 s_sg_platf_storage_cbarg_t storage;
92 memset(&storage,0,sizeof(storage));
94 storage.id = A_surfxml_storage_id;
95 storage.type_id = A_surfxml_storage_typeId;
96 storage.content = A_surfxml_storage_content;
97 sg_platf_new_storage(&storage);
99 void STag_surfxml_storage_type(void)
101 XBT_DEBUG("STag_surfxml_storage_type");
102 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
104 void ETag_surfxml_storage_type(void)
106 s_sg_platf_storage_type_cbarg_t storage_type;
107 memset(&storage_type,0,sizeof(storage_type));
109 storage_type.content = A_surfxml_storage_type_content;
110 storage_type.id = A_surfxml_storage_type_id;
111 storage_type.model = A_surfxml_storage_type_model;
112 storage_type.properties = current_property_set;
113 storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
114 sg_platf_new_storage_type(&storage_type);
115 current_property_set = NULL;
117 void STag_surfxml_mstorage(void)
119 XBT_DEBUG("STag_surfxml_mstorage");
121 void ETag_surfxml_mstorage(void)
123 s_sg_platf_mstorage_cbarg_t mstorage;
124 memset(&mstorage,0,sizeof(mstorage));
126 mstorage.name = A_surfxml_mstorage_name;
127 mstorage.type_id = A_surfxml_mstorage_typeId;
128 sg_platf_new_mstorage(&mstorage);
130 void STag_surfxml_mount(void)
132 XBT_DEBUG("STag_surfxml_mount");
134 void ETag_surfxml_mount(void)
136 s_sg_platf_mount_cbarg_t mount;
137 memset(&mount,0,sizeof(mount));
139 mount.name = A_surfxml_mount_name;
140 mount.id = A_surfxml_mount_id;
141 sg_platf_new_mount(&mount);
145 * Stuff relative to the <include> tag
147 static xbt_dynar_t surf_input_buffer_stack = NULL;
148 static xbt_dynar_t surf_file_to_parse_stack = NULL;
149 static xbt_dynar_t surf_parsed_filename_stack = NULL;
151 void STag_surfxml_include(void)
153 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
154 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
155 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
157 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
159 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
160 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
161 A_surfxml_include_file);
162 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
163 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
164 surf_parse_push_buffer_state(surf_input_buffer);
169 void ETag_surfxml_include(void) {
170 /* Nothing to do when done with reading the include tag.
171 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
174 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
176 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
177 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
178 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
179 * error message in that case.
181 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
182 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
183 * on a line. One day maybe, if the maya allow it.
185 int ETag_surfxml_include_state(void)
188 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
190 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
193 // Yeah, we were in an <include> Restore state and proceed.
194 fclose(surf_file_to_parse);
195 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
196 surf_parse_pop_buffer_state();
197 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
199 // Restore the filename for error messages
200 free(surf_parsed_filename);
201 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
207 void surf_parse_init_callbacks(void)
212 void surf_parse_reset_callbacks(void)
214 surf_parse_free_callbacks();
215 surf_parse_init_callbacks();
218 void surf_parse_free_callbacks(void)
223 /* Stag and Etag parse functions */
225 void STag_surfxml_platform(void) {
226 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
228 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
229 "You're using an ancient XML file.\n"
230 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
231 "instead of MBytes, MFlops and seconds.\n"
233 "Use simgrid_update_xml to update your file automatically. "
234 "This program is installed automatically with SimGrid, or "
235 "available in the tools/ directory of the source archive.\n"
237 "Please check also out the SURF section of the ChangeLog for "
238 "the 3.1 version for more information. \n"
240 "Last, do not forget to also update your values for "
241 "the calls to MSG_task_create (if any).");
242 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
243 "You're using an old XML file.\n"
244 "Use simgrid_update_xml to update your file automatically. "
245 "This program is installed automatically with SimGrid, or "
246 "available in the tools/ directory of the source archive.");
250 void ETag_surfxml_platform(void){
254 void STag_surfxml_host(void){
255 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
258 void STag_surfxml_prop(void)
260 if (!current_property_set)
261 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
263 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
266 void ETag_surfxml_host(void) {
267 s_sg_platf_host_cbarg_t host;
268 memset(&host,0,sizeof(host));
270 host.properties = current_property_set;
272 host.id = A_surfxml_host_id;
273 host.power_peak = get_cpu_power(A_surfxml_host_power);
274 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
275 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
276 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
277 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
278 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
279 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
280 if (A_surfxml_host_state == A_surfxml_host_state_ON)
281 host.initial_state = SURF_RESOURCE_ON;
282 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
283 host.initial_state = SURF_RESOURCE_OFF;
284 host.coord = A_surfxml_host_coordinates;
286 sg_platf_new_host(&host);
287 current_property_set = NULL;
290 void STag_surfxml_host_link(void){
291 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host_link_id);
292 s_sg_platf_host_link_cbarg_t host_link;
293 memset(&host_link,0,sizeof(host_link));
295 host_link.id = A_surfxml_host_link_id;
296 host_link.link_up = A_surfxml_host_link_up;
297 host_link.link_down = A_surfxml_host_link_down;
298 sg_platf_new_host_link(&host_link);
301 void STag_surfxml_router(void){
302 s_sg_platf_router_cbarg_t router;
303 memset(&router, 0, sizeof(router));
305 router.id = A_surfxml_router_id;
306 router.coord = A_surfxml_router_coordinates;
308 sg_platf_new_router(&router);
311 void STag_surfxml_cluster(void){
312 s_sg_platf_cluster_cbarg_t cluster;
313 memset(&cluster,0,sizeof(cluster));
314 cluster.id = A_surfxml_cluster_id;
315 cluster.prefix = A_surfxml_cluster_prefix;
316 cluster.suffix = A_surfxml_cluster_suffix;
317 cluster.radical = A_surfxml_cluster_radical;
318 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
319 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
320 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
321 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
322 if(strcmp(A_surfxml_cluster_bb_bw,""))
323 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
324 if(strcmp(A_surfxml_cluster_bb_lat,""))
325 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
326 cluster.router_id = A_surfxml_cluster_router_id;
328 switch (AX_surfxml_cluster_sharing_policy) {
329 case A_surfxml_cluster_sharing_policy_SHARED:
330 cluster.sharing_policy = SURF_LINK_SHARED;
332 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
333 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
335 case A_surfxml_cluster_sharing_policy_FATPIPE:
336 cluster.sharing_policy = SURF_LINK_FATPIPE;
339 surf_parse_error("Invalid cluster sharing policy for cluster %s",
343 switch (AX_surfxml_cluster_bb_sharing_policy) {
344 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
345 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
347 case A_surfxml_cluster_bb_sharing_policy_SHARED:
348 cluster.bb_sharing_policy = SURF_LINK_SHARED;
351 surf_parse_error("Invalid bb sharing policy in cluster %s",
356 cluster.availability_trace = A_surfxml_cluster_availability_file;
357 cluster.state_trace = A_surfxml_cluster_state_file;
358 sg_platf_new_cluster(&cluster);
361 void STag_surfxml_cabinet(void){
362 s_sg_platf_cabinet_cbarg_t cabinet;
363 memset(&cabinet,0,sizeof(cabinet));
364 cabinet.id = A_surfxml_cabinet_id;
365 cabinet.prefix = A_surfxml_cabinet_prefix;
366 cabinet.suffix = A_surfxml_cabinet_suffix;
367 cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power);
368 cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw);
369 cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat);
370 cabinet.radical = A_surfxml_cabinet_radical;
372 sg_platf_new_cabinet(&cabinet);
375 void STag_surfxml_peer(void){
376 s_sg_platf_peer_cbarg_t peer;
377 memset(&peer,0,sizeof(peer));
378 peer.id = A_surfxml_peer_id;
379 peer.power = surf_parse_get_double(A_surfxml_peer_power);
380 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
381 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
382 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
383 peer.coord = A_surfxml_peer_coordinates;
384 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
385 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
387 sg_platf_new_peer(&peer);
390 void STag_surfxml_link(void){
391 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
394 void ETag_surfxml_link(void){
395 s_sg_platf_link_cbarg_t link;
396 memset(&link,0,sizeof(link));
398 link.properties = current_property_set;
400 link.id = A_surfxml_link_id;
401 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
402 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
403 link.latency = surf_parse_get_double(A_surfxml_link_latency);
404 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
406 switch (A_surfxml_link_state) {
407 case A_surfxml_link_state_ON:
408 link.state = SURF_RESOURCE_ON;
410 case A_surfxml_link_state_OFF:
411 link.state = SURF_RESOURCE_OFF;
414 surf_parse_error("invalid state for link %s", link.id);
417 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
419 switch (A_surfxml_link_sharing_policy) {
420 case A_surfxml_link_sharing_policy_SHARED:
421 link.policy = SURF_LINK_SHARED;
423 case A_surfxml_link_sharing_policy_FATPIPE:
424 link.policy = SURF_LINK_FATPIPE;
426 case A_surfxml_link_sharing_policy_FULLDUPLEX:
427 link.policy = SURF_LINK_FULLDUPLEX;
430 surf_parse_error("Invalid sharing policy in link %s", link.id);
434 sg_platf_new_link(&link);
436 current_property_set = NULL;
439 void STag_surfxml_link_ctn(void){
440 s_sg_platf_linkctn_cbarg_t linkctn;
441 memset(&linkctn,0,sizeof(linkctn));
443 linkctn.id = A_surfxml_link_ctn_id;
445 switch (A_surfxml_link_ctn_direction) {
446 case AU_surfxml_link_ctn_direction:
447 case A_surfxml_link_ctn_direction_NONE:
448 linkctn.direction = SURF_LINK_DIRECTION_NONE;
450 case A_surfxml_link_ctn_direction_UP:
451 linkctn.direction = SURF_LINK_DIRECTION_UP;
453 case A_surfxml_link_ctn_direction_DOWN:
454 linkctn.direction = SURF_LINK_DIRECTION_DOWN;
457 sg_platf_new_linkctn(&linkctn);
461 void ETag_surfxml_backbone(void){
462 s_sg_platf_link_cbarg_t link;
463 memset(&link,0,sizeof(link));
465 link.properties = NULL;
467 link.id = A_surfxml_backbone_id;
468 link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth);
469 link.latency = surf_parse_get_double(A_surfxml_backbone_latency);
470 link.state = SURF_RESOURCE_ON;
471 link.policy = SURF_LINK_SHARED;
473 sg_platf_new_link(&link);
474 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
475 current_property_set = NULL;
478 void STag_surfxml_route(void){
479 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
480 "Missing end-points while defining route \"%s\"->\"%s\"",
481 A_surfxml_route_src, A_surfxml_route_dst);
483 void STag_surfxml_ASroute(void){
484 xbt_assert(strlen(A_surfxml_ASroute_src) > 0 || strlen(A_surfxml_ASroute_dst) > 0
485 || strlen(A_surfxml_ASroute_gw_src) > 0 || strlen(A_surfxml_ASroute_gw_dst) > 0,
486 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
487 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
488 A_surfxml_ASroute_gw_src,A_surfxml_ASroute_gw_dst);
490 void STag_surfxml_bypassRoute(void){
491 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0 || strlen(A_surfxml_bypassRoute_dst) > 0,
492 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
493 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
495 void STag_surfxml_bypassASroute(void){
496 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0 || strlen(A_surfxml_bypassASroute_dst) > 0
497 || strlen(A_surfxml_bypassASroute_gw_src) > 0 || strlen(A_surfxml_bypassASroute_gw_dst) > 0,
498 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
499 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
500 A_surfxml_bypassASroute_gw_src,A_surfxml_bypassASroute_gw_dst);
503 void ETag_surfxml_route(void){
504 s_sg_platf_route_cbarg_t route;
505 memset(&route,0,sizeof(route));
507 route.src = A_surfxml_route_src;
508 route.dst = A_surfxml_route_dst;
510 switch (A_surfxml_route_symmetrical) {
511 case AU_surfxml_route_symmetrical:
512 case A_surfxml_route_symmetrical_YES:
513 route.symmetrical = TRUE;
515 case A_surfxml_route_symmetrical_NO:
516 route.symmetrical = FALSE;;
520 sg_platf_new_route(&route);
523 void ETag_surfxml_ASroute(void){
524 s_sg_platf_ASroute_cbarg_t ASroute;
525 memset(&ASroute,0,sizeof(ASroute));
527 ASroute.src = A_surfxml_ASroute_src;
528 ASroute.dst = A_surfxml_ASroute_dst;
529 ASroute.gw_src = A_surfxml_ASroute_gw_src;
530 ASroute.gw_dst = A_surfxml_ASroute_gw_dst;
532 switch (A_surfxml_ASroute_symmetrical) {
533 case AU_surfxml_ASroute_symmetrical:
534 case A_surfxml_ASroute_symmetrical_YES:
535 ASroute.symmetrical = TRUE;
537 case A_surfxml_ASroute_symmetrical_NO:
538 ASroute.symmetrical = FALSE;;
542 sg_platf_new_ASroute(&ASroute);
545 void ETag_surfxml_bypassRoute(void){
546 s_sg_platf_bypassRoute_cbarg_t route;
547 memset(&route,0,sizeof(route));
549 route.src = A_surfxml_bypassRoute_src;
550 route.dst = A_surfxml_bypassRoute_dst;
552 sg_platf_new_bypassRoute(&route);
555 void ETag_surfxml_bypassASroute(void){
556 s_sg_platf_bypassASroute_cbarg_t ASroute;
557 memset(&ASroute,0,sizeof(ASroute));
559 ASroute.src = A_surfxml_bypassASroute_src;
560 ASroute.dst = A_surfxml_bypassASroute_dst;
561 ASroute.gw_src = A_surfxml_bypassASroute_gw_src;
562 ASroute.gw_dst = A_surfxml_bypassASroute_gw_dst;
564 sg_platf_new_bypassASroute(&ASroute);
567 void ETag_surfxml_trace(void){
568 s_sg_platf_trace_cbarg_t trace;
569 memset(&trace,0,sizeof(trace));
571 trace.id = A_surfxml_trace_id;
572 trace.file = A_surfxml_trace_file;
573 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
574 trace.pc_data = surfxml_pcdata;
576 sg_platf_new_trace(&trace);
579 void STag_surfxml_trace_connect(void){
580 s_sg_platf_trace_connect_cbarg_t trace_connect;
581 memset(&trace_connect,0,sizeof(trace_connect));
583 trace_connect.element = A_surfxml_trace_connect_element;
584 trace_connect.trace = A_surfxml_trace_connect_trace;
586 switch (A_surfxml_trace_connect_kind) {
587 case AU_surfxml_trace_connect_kind:
588 case A_surfxml_trace_connect_kind_POWER:
589 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
591 case A_surfxml_trace_connect_kind_BANDWIDTH:
592 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
594 case A_surfxml_trace_connect_kind_HOST_AVAIL:
595 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
597 case A_surfxml_trace_connect_kind_LATENCY:
598 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
600 case A_surfxml_trace_connect_kind_LINK_AVAIL:
601 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
604 sg_platf_new_trace_connect(&trace_connect);
607 void STag_surfxml_AS(void){
608 sg_platf_new_AS_begin(A_surfxml_AS_id, (int)A_surfxml_AS_routing);
610 void ETag_surfxml_AS(void){
611 sg_platf_new_AS_end();
614 void STag_surfxml_config(void){
615 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
616 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
618 void ETag_surfxml_config(void){
619 xbt_dict_cursor_t cursor = NULL;
623 xbt_dict_foreach(current_property_set, cursor, key, elem) {
624 cfg = bprintf("%s:%s",key,elem);
625 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
626 xbt_cfg_set_parse(_surf_cfg_set, cfg);
628 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
631 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
632 xbt_dict_free(¤t_property_set);
638 void STag_surfxml_process(void){
640 argv = xbt_new(char *, 1);
641 argv[0] = xbt_strdup(A_surfxml_process_function);
644 void ETag_surfxml_process(void){
645 s_sg_platf_process_cbarg_t process;
646 memset(&process,0,sizeof(process));
649 process.argv = (const char **)argv;
650 process.properties = current_property_set;
651 process.host = A_surfxml_process_host;
652 process.function = A_surfxml_process_function;
653 process.start_time = surf_parse_get_double(A_surfxml_process_start_time);
654 process.kill_time = surf_parse_get_double(A_surfxml_process_kill_time);
656 switch (A_surfxml_process_on_failure) {
657 case AU_surfxml_process_on_failure:
658 case A_surfxml_process_on_failure_DIE:
659 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
661 case A_surfxml_process_on_failure_RESTART:
662 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
666 sg_platf_new_process(&process);
667 current_property_set = NULL;
670 void STag_surfxml_argument(void){
672 argv = xbt_realloc(argv, (argc) * sizeof(char *));
673 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
676 /* nothing to do in those functions */
677 void ETag_surfxml_prop(void){}
678 void STag_surfxml_random(void){}
679 void ETag_surfxml_random(void){}
680 void ETag_surfxml_trace_connect(void){}
681 void STag_surfxml_trace(void){}
682 void ETag_surfxml_router(void){}
683 void ETag_surfxml_host_link(void){}
684 void ETag_surfxml_cluster(void){}
685 void ETag_surfxml_cabinet(void){}
686 void ETag_surfxml_peer(void){}
687 void STag_surfxml_backbone(void){}
688 void ETag_surfxml_link_ctn(void){}
689 void ETag_surfxml_argument(void){}
691 /* Open and Close parse file */
693 void surf_parse_open(const char *file)
695 static int warned = 0; /* warn only once */
699 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
700 "If it is not what you want, go fix your code.");
706 if (!surf_input_buffer_stack)
707 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
708 if (!surf_file_to_parse_stack)
709 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
711 if (!surf_parsed_filename_stack)
712 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
713 surf_parsed_filename = xbt_strdup(file);
715 surf_file_to_parse = surf_fopen(file, "r");
716 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
717 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
718 surf_parse__switch_to_buffer(surf_input_buffer);
719 surf_parse_lineno = 1;
722 void surf_parse_close(void)
724 xbt_dynar_free(&surf_input_buffer_stack);
725 xbt_dynar_free(&surf_file_to_parse_stack);
726 xbt_dynar_free(&surf_parsed_filename_stack);
728 free(surf_parsed_filename);
730 if (surf_file_to_parse) {
731 surf_parse__delete_buffer(surf_input_buffer);
732 fclose(surf_file_to_parse);
733 surf_file_to_parse = NULL; //Must be reset for Bypass
737 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
739 static int _surf_parse(void) {
740 return surf_parse_lex();
742 int_f_void_t surf_parse = _surf_parse;
745 /* Prop tag functions */
751 /* Random tag functions */
753 double get_cpu_power(const char *power)
755 double power_scale = 0.0;
758 random_data_t random = NULL;
759 /* randomness is inserted like this: power="$rand(my_random)" */
760 if (((p = strstr(power, "$rand(")) != NULL)
761 && ((q = strstr(power, ")")) != NULL)) {
763 generator = xbt_malloc(q - (p + 6) + 1);
764 memcpy(generator, p + 6, q - (p + 6));
765 generator[q - (p + 6)] = '\0';
766 random = xbt_dict_get_or_null(random_data_list, generator);
767 xbt_assert(random, "Random generator %s undefined", generator);
768 power_scale = random_generate(random);
771 power_scale = surf_parse_get_double(power);
776 double random_min, random_max, random_mean, random_std_deviation;
777 e_random_generator_t random_generator;
780 static void init_randomness(void)
782 random_id = A_surfxml_random_id;
783 random_min = surf_parse_get_double(A_surfxml_random_min);
784 random_max = surf_parse_get_double(A_surfxml_random_max);
785 random_mean = surf_parse_get_double(A_surfxml_random_mean);
786 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
787 switch (A_surfxml_random_generator) {
788 case AU_surfxml_random_generator:
789 case A_surfxml_random_generator_NONE:
790 random_generator = NONE;
792 case A_surfxml_random_generator_DRAND48:
793 random_generator = DRAND48;
795 case A_surfxml_random_generator_RAND:
796 random_generator = RAND;
798 case A_surfxml_random_generator_RNGSTREAM:
799 random_generator = RNGSTREAM;
802 surf_parse_error("Invalid random generator");
807 static void add_randomness(void)
809 /* If needed aditional properties can be added by using the prop tag */
810 random_data_t random =
811 random_new(random_generator, 0, random_min, random_max, random_mean,
812 random_std_deviation);
813 xbt_dict_set(random_data_list, random_id, (void *) random,