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_process_cb_list = NULL;
68 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
69 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
70 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
72 /* The default current property receiver. Setup in the corresponding opening callbacks. */
73 xbt_dict_t current_property_set = NULL;
74 /* dictionary of random generator data */
75 xbt_dict_t random_data_list = NULL;
77 /* Call all the callbacks of a specific SAX event */
78 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
80 YY_BUFFER_STATE surf_input_buffer;
81 FILE *surf_file_to_parse = NULL;
83 static void init_randomness(void);
84 static void add_randomness(void);
87 * Stuff relative to storage
89 void STag_surfxml_storage(void)
91 XBT_DEBUG("STag_surfxml_storage");
93 void ETag_surfxml_storage(void)
95 s_sg_platf_storage_cbarg_t storage;
96 memset(&storage,0,sizeof(storage));
98 storage.id = A_surfxml_storage_id;
99 storage.type_id = A_surfxml_storage_typeId;
100 storage.content = A_surfxml_storage_content;
101 sg_platf_new_storage(&storage);
103 void STag_surfxml_storage_type(void)
105 XBT_DEBUG("STag_surfxml_storage_type");
106 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
108 void ETag_surfxml_storage_type(void)
110 s_sg_platf_storage_type_cbarg_t storage_type;
111 memset(&storage_type,0,sizeof(storage_type));
113 storage_type.content = A_surfxml_storage_type_content;
114 storage_type.id = A_surfxml_storage_type_id;
115 storage_type.model = A_surfxml_storage_type_model;
116 storage_type.properties = current_property_set;
117 storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
118 sg_platf_new_storage_type(&storage_type);
119 current_property_set = NULL;
121 void STag_surfxml_mstorage(void)
123 XBT_DEBUG("STag_surfxml_mstorage");
125 void ETag_surfxml_mstorage(void)
127 s_sg_platf_mstorage_cbarg_t mstorage;
128 memset(&mstorage,0,sizeof(mstorage));
130 mstorage.name = A_surfxml_mstorage_name;
131 mstorage.type_id = A_surfxml_mstorage_typeId;
132 sg_platf_new_mstorage(&mstorage);
134 void STag_surfxml_mount(void)
136 XBT_DEBUG("STag_surfxml_mount");
138 void ETag_surfxml_mount(void)
140 s_sg_platf_mount_cbarg_t mount;
141 memset(&mount,0,sizeof(mount));
143 mount.name = A_surfxml_mount_name;
144 mount.id = A_surfxml_mount_id;
145 sg_platf_new_mount(&mount);
149 * Stuff relative to the <include> tag
151 static xbt_dynar_t surf_input_buffer_stack = NULL;
152 static xbt_dynar_t surf_file_to_parse_stack = NULL;
153 static xbt_dynar_t surf_parsed_filename_stack = NULL;
155 void STag_surfxml_include(void)
157 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
158 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
159 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
161 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
163 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
164 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
165 A_surfxml_include_file);
166 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
167 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
168 surf_parse_push_buffer_state(surf_input_buffer);
173 void ETag_surfxml_include(void) {
174 /* Nothing to do when done with reading the include tag.
175 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
178 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
180 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
181 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
182 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
183 * error message in that case.
185 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
186 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
187 * on a line. One day maybe, if the maya allow it.
189 int ETag_surfxml_include_state(void)
192 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
194 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
197 // Yeah, we were in an <include> Restore state and proceed.
198 fclose(surf_file_to_parse);
199 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
200 surf_parse_pop_buffer_state();
201 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
203 // Restore the filename for error messages
204 free(surf_parsed_filename);
205 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
211 void surf_parse_init_callbacks(void)
213 sg_platf_init(); // FIXME: move to a proper place?
214 STag_surfxml_process_cb_list =
215 xbt_dynar_new(sizeof(void_f_void_t), NULL);
216 ETag_surfxml_process_cb_list =
217 xbt_dynar_new(sizeof(void_f_void_t), NULL);
218 STag_surfxml_argument_cb_list =
219 xbt_dynar_new(sizeof(void_f_void_t), NULL);
220 ETag_surfxml_argument_cb_list =
221 xbt_dynar_new(sizeof(void_f_void_t), NULL);
224 void surf_parse_reset_callbacks(void)
226 surf_parse_free_callbacks();
227 surf_parse_init_callbacks();
230 void surf_parse_free_callbacks(void)
232 sg_platf_exit(); // FIXME: better place?
234 xbt_dynar_free(&STag_surfxml_process_cb_list);
235 xbt_dynar_free(&ETag_surfxml_process_cb_list);
236 xbt_dynar_free(&STag_surfxml_argument_cb_list);
237 xbt_dynar_free(&ETag_surfxml_argument_cb_list);
240 /* Stag and Etag parse functions */
242 void STag_surfxml_platform(void) {
243 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
245 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
246 "You're using an ancient XML file.\n"
247 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
248 "instead of MBytes, MFlops and seconds.\n"
250 "Use simgrid_update_xml to update your file automatically. "
251 "This program is installed automatically with SimGrid, or "
252 "available in the tools/ directory of the source archive.\n"
254 "Please check also out the SURF section of the ChangeLog for "
255 "the 3.1 version for more information. \n"
257 "Last, do not forget to also update your values for "
258 "the calls to MSG_task_create (if any).");
259 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
260 "You're using an old XML file.\n"
261 "Use simgrid_update_xml to update your file automatically. "
262 "This program is installed automatically with SimGrid, or "
263 "available in the tools/ directory of the source archive.");
267 void ETag_surfxml_platform(void){
271 void STag_surfxml_host(void){
272 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
275 void STag_surfxml_prop(void)
277 if (!current_property_set)
278 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
280 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
283 void ETag_surfxml_host(void) {
284 s_sg_platf_host_cbarg_t host;
285 memset(&host,0,sizeof(host));
287 host.properties = current_property_set;
289 host.id = A_surfxml_host_id;
290 host.power_peak = get_cpu_power(A_surfxml_host_power);
291 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
292 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
293 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
294 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
295 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
296 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
297 if (A_surfxml_host_state == A_surfxml_host_state_ON)
298 host.initial_state = SURF_RESOURCE_ON;
299 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
300 host.initial_state = SURF_RESOURCE_OFF;
301 host.coord = A_surfxml_host_coordinates;
303 sg_platf_new_host(&host);
304 current_property_set = NULL;
307 void STag_surfxml_host_link(void){
308 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host_link_id);
309 s_sg_platf_host_link_cbarg_t host_link;
310 memset(&host_link,0,sizeof(host_link));
312 host_link.id = A_surfxml_host_link_id;
313 host_link.link_up = A_surfxml_host_link_up;
314 host_link.link_down = A_surfxml_host_link_down;
315 sg_platf_new_host_link(&host_link);
318 void STag_surfxml_router(void){
319 s_sg_platf_router_cbarg_t router;
320 memset(&router, 0, sizeof(router));
322 router.id = A_surfxml_router_id;
323 router.coord = A_surfxml_router_coordinates;
325 sg_platf_new_router(&router);
328 void STag_surfxml_cluster(void){
329 s_sg_platf_cluster_cbarg_t cluster;
330 memset(&cluster,0,sizeof(cluster));
331 cluster.id = A_surfxml_cluster_id;
332 cluster.prefix = A_surfxml_cluster_prefix;
333 cluster.suffix = A_surfxml_cluster_suffix;
334 cluster.radical = A_surfxml_cluster_radical;
335 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
336 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
337 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
338 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
339 if(strcmp(A_surfxml_cluster_bb_bw,""))
340 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
341 if(strcmp(A_surfxml_cluster_bb_lat,""))
342 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
343 cluster.router_id = A_surfxml_cluster_router_id;
345 switch (AX_surfxml_cluster_sharing_policy) {
346 case A_surfxml_cluster_sharing_policy_SHARED:
347 cluster.sharing_policy = SURF_LINK_SHARED;
349 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
350 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
352 case A_surfxml_cluster_sharing_policy_FATPIPE:
353 cluster.sharing_policy = SURF_LINK_FATPIPE;
356 surf_parse_error("Invalid cluster sharing policy for cluster %s",
360 switch (AX_surfxml_cluster_bb_sharing_policy) {
361 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
362 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
364 case A_surfxml_cluster_bb_sharing_policy_SHARED:
365 cluster.bb_sharing_policy = SURF_LINK_SHARED;
368 surf_parse_error("Invalid bb sharing policy in cluster %s",
373 cluster.availability_trace = A_surfxml_cluster_availability_file;
374 cluster.state_trace = A_surfxml_cluster_state_file;
375 sg_platf_new_cluster(&cluster);
378 void STag_surfxml_cabinet(void){
379 s_sg_platf_cabinet_cbarg_t cabinet;
380 memset(&cabinet,0,sizeof(cabinet));
381 cabinet.id = A_surfxml_cabinet_id;
382 cabinet.prefix = A_surfxml_cabinet_prefix;
383 cabinet.suffix = A_surfxml_cabinet_suffix;
384 cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power);
385 cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw);
386 cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat);
387 cabinet.radical = A_surfxml_cabinet_radical;
389 sg_platf_new_cabinet(&cabinet);
392 void STag_surfxml_peer(void){
393 s_sg_platf_peer_cbarg_t peer;
394 memset(&peer,0,sizeof(peer));
395 peer.id = A_surfxml_peer_id;
396 peer.power = surf_parse_get_double(A_surfxml_peer_power);
397 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
398 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
399 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
400 peer.coord = A_surfxml_peer_coordinates;
401 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
402 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
404 sg_platf_new_peer(&peer);
407 void STag_surfxml_link(void){
408 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
411 void ETag_surfxml_link(void){
412 s_sg_platf_link_cbarg_t link;
413 memset(&link,0,sizeof(link));
415 link.properties = current_property_set;
417 link.id = A_surfxml_link_id;
418 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
419 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
420 link.latency = surf_parse_get_double(A_surfxml_link_latency);
421 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
423 switch (A_surfxml_link_state) {
424 case A_surfxml_link_state_ON:
425 link.state = SURF_RESOURCE_ON;
427 case A_surfxml_link_state_OFF:
428 link.state = SURF_RESOURCE_OFF;
431 surf_parse_error("invalid state for link %s", link.id);
434 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
436 switch (A_surfxml_link_sharing_policy) {
437 case A_surfxml_link_sharing_policy_SHARED:
438 link.policy = SURF_LINK_SHARED;
440 case A_surfxml_link_sharing_policy_FATPIPE:
441 link.policy = SURF_LINK_FATPIPE;
443 case A_surfxml_link_sharing_policy_FULLDUPLEX:
444 link.policy = SURF_LINK_FULLDUPLEX;
447 surf_parse_error("Invalid sharing policy in link %s", link.id);
451 sg_platf_new_link(&link);
453 current_property_set = NULL;
456 void STag_surfxml_link_ctn(void){
457 s_sg_platf_linkctn_cbarg_t linkctn;
458 memset(&linkctn,0,sizeof(linkctn));
460 linkctn.id = A_surfxml_link_ctn_id;
462 switch (A_surfxml_link_ctn_direction) {
463 case AU_surfxml_link_ctn_direction:
464 case A_surfxml_link_ctn_direction_NONE:
465 linkctn.direction = SURF_LINK_DIRECTION_NONE;
467 case A_surfxml_link_ctn_direction_UP:
468 linkctn.direction = SURF_LINK_DIRECTION_UP;
470 case A_surfxml_link_ctn_direction_DOWN:
471 linkctn.direction = SURF_LINK_DIRECTION_DOWN;
474 sg_platf_new_linkctn(&linkctn);
478 void ETag_surfxml_backbone(void){
479 s_sg_platf_link_cbarg_t link;
480 memset(&link,0,sizeof(link));
482 link.properties = NULL;
484 link.id = A_surfxml_backbone_id;
485 link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth);
486 link.latency = surf_parse_get_double(A_surfxml_backbone_latency);
487 link.state = SURF_RESOURCE_ON;
488 link.policy = SURF_LINK_SHARED;
490 sg_platf_new_link(&link);
491 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
492 current_property_set = NULL;
495 void STag_surfxml_route(void){
496 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
497 "Missing end-points while defining route \"%s\"->\"%s\"",
498 A_surfxml_route_src, A_surfxml_route_dst);
500 void STag_surfxml_ASroute(void){
501 xbt_assert(strlen(A_surfxml_ASroute_src) > 0 || strlen(A_surfxml_ASroute_dst) > 0
502 || strlen(A_surfxml_ASroute_gw_src) > 0 || strlen(A_surfxml_ASroute_gw_dst) > 0,
503 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
504 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
505 A_surfxml_ASroute_gw_src,A_surfxml_ASroute_gw_dst);
507 void STag_surfxml_bypassRoute(void){
508 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0 || strlen(A_surfxml_bypassRoute_dst) > 0,
509 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
510 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
512 void STag_surfxml_bypassASroute(void){
513 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0 || strlen(A_surfxml_bypassASroute_dst) > 0
514 || strlen(A_surfxml_bypassASroute_gw_src) > 0 || strlen(A_surfxml_bypassASroute_gw_dst) > 0,
515 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
516 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
517 A_surfxml_bypassASroute_gw_src,A_surfxml_bypassASroute_gw_dst);
520 void ETag_surfxml_route(void){
521 s_sg_platf_route_cbarg_t route;
522 memset(&route,0,sizeof(route));
524 route.src = A_surfxml_route_src;
525 route.dst = A_surfxml_route_dst;
527 switch (A_surfxml_route_symmetrical) {
528 case AU_surfxml_route_symmetrical:
529 case A_surfxml_route_symmetrical_YES:
530 route.symmetrical = TRUE;
532 case A_surfxml_route_symmetrical_NO:
533 route.symmetrical = FALSE;;
537 sg_platf_new_route(&route);
540 void ETag_surfxml_ASroute(void){
541 s_sg_platf_ASroute_cbarg_t ASroute;
542 memset(&ASroute,0,sizeof(ASroute));
544 ASroute.src = A_surfxml_ASroute_src;
545 ASroute.dst = A_surfxml_ASroute_dst;
546 ASroute.gw_src = A_surfxml_ASroute_gw_src;
547 ASroute.gw_dst = A_surfxml_ASroute_gw_dst;
549 switch (A_surfxml_ASroute_symmetrical) {
550 case AU_surfxml_ASroute_symmetrical:
551 case A_surfxml_ASroute_symmetrical_YES:
552 ASroute.symmetrical = TRUE;
554 case A_surfxml_ASroute_symmetrical_NO:
555 ASroute.symmetrical = FALSE;;
559 sg_platf_new_ASroute(&ASroute);
562 void ETag_surfxml_bypassRoute(void){
563 s_sg_platf_bypassRoute_cbarg_t route;
564 memset(&route,0,sizeof(route));
566 route.src = A_surfxml_bypassRoute_src;
567 route.dst = A_surfxml_bypassRoute_dst;
569 sg_platf_new_bypassRoute(&route);
572 void ETag_surfxml_bypassASroute(void){
573 s_sg_platf_bypassASroute_cbarg_t ASroute;
574 memset(&ASroute,0,sizeof(ASroute));
576 ASroute.src = A_surfxml_bypassASroute_src;
577 ASroute.dst = A_surfxml_bypassASroute_dst;
578 ASroute.gw_src = A_surfxml_bypassASroute_gw_src;
579 ASroute.gw_dst = A_surfxml_bypassASroute_gw_dst;
581 sg_platf_new_bypassASroute(&ASroute);
584 void ETag_surfxml_trace(void){
585 s_sg_platf_trace_cbarg_t trace;
586 memset(&trace,0,sizeof(trace));
588 trace.id = A_surfxml_trace_id;
589 trace.file = A_surfxml_trace_file;
590 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
591 trace.pc_data = surfxml_pcdata;
593 sg_platf_new_trace(&trace);
596 void STag_surfxml_trace_connect(void){
597 s_sg_platf_trace_connect_cbarg_t trace_connect;
598 memset(&trace_connect,0,sizeof(trace_connect));
600 trace_connect.element = A_surfxml_trace_connect_element;
601 trace_connect.trace = A_surfxml_trace_connect_trace;
603 switch (A_surfxml_trace_connect_kind) {
604 case AU_surfxml_trace_connect_kind:
605 case A_surfxml_trace_connect_kind_POWER:
606 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
608 case A_surfxml_trace_connect_kind_BANDWIDTH:
609 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
611 case A_surfxml_trace_connect_kind_HOST_AVAIL:
612 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
614 case A_surfxml_trace_connect_kind_LATENCY:
615 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
617 case A_surfxml_trace_connect_kind_LINK_AVAIL:
618 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
621 sg_platf_new_trace_connect(&trace_connect);
624 void STag_surfxml_AS(void){
625 sg_platf_new_AS_begin(A_surfxml_AS_id, (int)A_surfxml_AS_routing);
627 void ETag_surfxml_AS(void){
628 sg_platf_new_AS_end();
631 void STag_surfxml_config(void){
632 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
633 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
635 void ETag_surfxml_config(void){
636 xbt_dict_cursor_t cursor = NULL;
640 xbt_dict_foreach(current_property_set, cursor, key, elem) {
641 cfg = bprintf("%s:%s",key,elem);
642 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
643 xbt_cfg_set_parse(_surf_cfg_set, cfg);
645 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
648 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
649 xbt_dict_free(¤t_property_set);
652 /* nothing to do in those functions */
653 void ETag_surfxml_prop(void){}
654 void STag_surfxml_random(void){}
655 void ETag_surfxml_random(void){}
656 void ETag_surfxml_trace_connect(void){}
657 void STag_surfxml_trace(void){}
658 void ETag_surfxml_router(void){}
659 void ETag_surfxml_host_link(void){}
660 void ETag_surfxml_cluster(void){}
661 void ETag_surfxml_cabinet(void){}
662 void ETag_surfxml_peer(void){}
663 void STag_surfxml_backbone(void){}
664 void ETag_surfxml_link_ctn(void){}
666 // FIXME should not call surfxml_call_cb_functions
667 void STag_surfxml_process(void){
668 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
670 void STag_surfxml_argument(void){
671 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
674 #define parse_method(type,name) \
675 void type##Tag_surfxml_##name(void) \
676 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); } \
677 void type##Tag_surfxml_##name(void)
679 parse_method(E, process);
680 parse_method(E, argument);
682 /* Open and Close parse file */
684 void surf_parse_open(const char *file)
686 static int warned = 0; /* warn only once */
690 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
691 "If it is not what you want, go fix your code.");
697 if (!surf_input_buffer_stack)
698 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
699 if (!surf_file_to_parse_stack)
700 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
702 if (!surf_parsed_filename_stack)
703 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
704 surf_parsed_filename = xbt_strdup(file);
706 surf_file_to_parse = surf_fopen(file, "r");
707 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
708 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
709 surf_parse__switch_to_buffer(surf_input_buffer);
710 surf_parse_lineno = 1;
713 void surf_parse_close(void)
715 xbt_dynar_free(&surf_input_buffer_stack);
716 xbt_dynar_free(&surf_file_to_parse_stack);
717 xbt_dynar_free(&surf_parsed_filename_stack);
719 free(surf_parsed_filename);
721 if (surf_file_to_parse) {
722 surf_parse__delete_buffer(surf_input_buffer);
723 fclose(surf_file_to_parse);
724 surf_file_to_parse = NULL; //Must be reset for Bypass
728 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
730 static int _surf_parse(void) {
731 return surf_parse_lex();
733 int_f_void_t surf_parse = _surf_parse;
736 /* Aux parse functions */
738 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
740 xbt_dynar_push(cb_list, &function);
743 void surfxml_del_callback(xbt_dynar_t cb_list, void_f_void_t function)
747 void_f_void_t null_f=NULL;
750 it = xbt_dynar_search(cb_list,&function);
753 if (e.category == not_found_error) {
755 xbt_die("Trying to remove a callback that is not here! This should not happen");
760 xbt_dynar_replace(cb_list, it,&null_f);
763 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
765 unsigned int iterator;
767 xbt_dynar_foreach(cb_list, iterator, fun) {
773 /* Prop tag functions */
779 /* Random tag functions */
781 double get_cpu_power(const char *power)
783 double power_scale = 0.0;
786 random_data_t random = NULL;
787 /* randomness is inserted like this: power="$rand(my_random)" */
788 if (((p = strstr(power, "$rand(")) != NULL)
789 && ((q = strstr(power, ")")) != NULL)) {
791 generator = xbt_malloc(q - (p + 6) + 1);
792 memcpy(generator, p + 6, q - (p + 6));
793 generator[q - (p + 6)] = '\0';
794 random = xbt_dict_get_or_null(random_data_list, generator);
795 xbt_assert(random, "Random generator %s undefined", generator);
796 power_scale = random_generate(random);
799 power_scale = surf_parse_get_double(power);
804 double random_min, random_max, random_mean, random_std_deviation;
805 e_random_generator_t random_generator;
808 static void init_randomness(void)
810 random_id = A_surfxml_random_id;
811 random_min = surf_parse_get_double(A_surfxml_random_min);
812 random_max = surf_parse_get_double(A_surfxml_random_max);
813 random_mean = surf_parse_get_double(A_surfxml_random_mean);
814 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
815 switch (A_surfxml_random_generator) {
816 case AU_surfxml_random_generator:
817 case A_surfxml_random_generator_NONE:
818 random_generator = NONE;
820 case A_surfxml_random_generator_DRAND48:
821 random_generator = DRAND48;
823 case A_surfxml_random_generator_RAND:
824 random_generator = RAND;
826 case A_surfxml_random_generator_RNGSTREAM:
827 random_generator = RNGSTREAM;
830 surf_parse_error("Invalid random generator");
835 static void add_randomness(void)
837 /* If needed aditional properties can be added by using the prop tag */
838 random_data_t random =
839 random_new(random_generator, 0, random_min, random_max, random_mean,
840 random_std_deviation);
841 xbt_dict_set(random_data_list, random_id, (void *) random,