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"
15 #include "simgrid/sg_config.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
18 "Logging specific to the SURF parsing module");
20 int ETag_surfxml_include_state(void);
22 #include "simgrid_dtd.c"
24 char* surf_parsed_filename = NULL; // to locate parse error messages
26 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
27 extern AS_t current_routing;
31 void surf_parse_error(const char *fmt, ...) {
34 char *msg = bvprintf(fmt,va);
36 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
38 void surf_parse_warn(const char *fmt, ...) {
41 char *msg = bvprintf(fmt,va);
43 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
47 double surf_parse_get_double(const char *string) {
49 int ret = sscanf(string, "%lg", &res);
51 surf_parse_error("%s is not a double", string);
55 int surf_parse_get_int(const char *string) {
57 int ret = sscanf(string, "%d", &res);
59 surf_parse_error("%s is not an integer", string);
65 * All the callback lists that can be overridden anywhere.
66 * (this list should probably be reduced to the bare minimum to allow the models to work)
69 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
71 /* The default current property receiver. Setup in the corresponding opening callbacks. */
72 xbt_dict_t current_property_set = NULL;
73 xbt_dict_t as_current_property_set = NULL;
75 char* as_name_tab[1024];
76 void* as_dict_tab[1024];
80 /* dictionary of random generator data */
81 xbt_dict_t random_data_list = NULL;
83 YY_BUFFER_STATE surf_input_buffer;
84 FILE *surf_file_to_parse = NULL;
86 static void init_randomness(void);
87 static void add_randomness(void);
90 * Stuff relative to storage
92 void STag_surfxml_storage(void)
95 XBT_DEBUG("STag_surfxml_storage");
96 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
98 void ETag_surfxml_storage(void)
100 s_sg_platf_storage_cbarg_t storage;
101 memset(&storage,0,sizeof(storage));
103 storage.id = A_surfxml_storage_id;
104 storage.type_id = A_surfxml_storage_typeId;
105 storage.content = A_surfxml_storage_content;
106 storage.properties = current_property_set;
107 sg_platf_new_storage(&storage);
108 current_property_set = NULL;
110 void STag_surfxml_storage_type(void)
113 XBT_DEBUG("STag_surfxml_storage_type");
114 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
116 void ETag_surfxml_storage_type(void)
118 s_sg_platf_storage_type_cbarg_t storage_type;
119 memset(&storage_type,0,sizeof(storage_type));
121 storage_type.content = A_surfxml_storage_type_content;
122 storage_type.id = A_surfxml_storage_type_id;
123 storage_type.model = A_surfxml_storage_type_model;
124 storage_type.properties = current_property_set;
125 storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
126 sg_platf_new_storage_type(&storage_type);
127 current_property_set = NULL;
129 void STag_surfxml_mstorage(void)
131 XBT_DEBUG("STag_surfxml_mstorage");
133 void ETag_surfxml_mstorage(void)
135 s_sg_platf_mstorage_cbarg_t mstorage;
136 memset(&mstorage,0,sizeof(mstorage));
138 mstorage.name = A_surfxml_mstorage_name;
139 mstorage.type_id = A_surfxml_mstorage_typeId;
140 sg_platf_new_mstorage(&mstorage);
142 void STag_surfxml_mount(void)
144 XBT_DEBUG("STag_surfxml_mount");
146 void ETag_surfxml_mount(void)
148 s_sg_platf_mount_cbarg_t mount;
149 memset(&mount,0,sizeof(mount));
151 mount.name = A_surfxml_mount_name;
152 mount.id = A_surfxml_mount_id;
153 sg_platf_new_mount(&mount);
157 * Stuff relative to the <include> tag
159 static xbt_dynar_t surf_input_buffer_stack = NULL;
160 static xbt_dynar_t surf_file_to_parse_stack = NULL;
161 static xbt_dynar_t surf_parsed_filename_stack = NULL;
163 void STag_surfxml_include(void)
165 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
166 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
167 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
169 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
171 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
172 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
173 A_surfxml_include_file);
174 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
175 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
176 surf_parse_push_buffer_state(surf_input_buffer);
181 void ETag_surfxml_include(void) {
182 /* Nothing to do when done with reading the include tag.
183 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
186 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
188 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
189 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
190 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
191 * error message in that case.
193 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
194 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
195 * on a line. One day maybe, if the maya allow it.
197 int ETag_surfxml_include_state(void)
200 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
202 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
205 // Yeah, we were in an <include> Restore state and proceed.
206 fclose(surf_file_to_parse);
207 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
208 surf_parse_pop_buffer_state();
209 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
211 // Restore the filename for error messages
212 free(surf_parsed_filename);
213 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
219 void surf_parse_init_callbacks(void)
224 void surf_parse_reset_callbacks(void)
226 surf_parse_free_callbacks();
227 surf_parse_init_callbacks();
230 void surf_parse_free_callbacks(void)
235 /* Stag and Etag parse functions */
237 void STag_surfxml_platform(void) {
238 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
240 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
241 "You're using an ancient XML file.\n"
242 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
243 "instead of MBytes, MFlops and seconds.\n"
245 "Use simgrid_update_xml to update your file automatically. "
246 "This program is installed automatically with SimGrid, or "
247 "available in the tools/ directory of the source archive.\n"
249 "Please check also out the SURF section of the ChangeLog for "
250 "the 3.1 version for more information. \n"
252 "Last, do not forget to also update your values for "
253 "the calls to MSG_task_create (if any).");
254 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
255 "You're using an old XML file.\n"
256 "Use simgrid_update_xml to update your file automatically. "
257 "This program is installed automatically with SimGrid, or "
258 "available in the tools/ directory of the source archive.");
262 void ETag_surfxml_platform(void){
266 void STag_surfxml_host(void){
268 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
271 void STag_surfxml_prop(void)
274 if (!as_current_property_set){
275 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
276 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
277 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
278 as_dict_tab[as_prop_nb] = as_current_property_set;
279 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
282 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
285 if (!current_property_set)
286 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
287 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
291 void ETag_surfxml_host(void) {
292 s_sg_platf_host_cbarg_t host;
293 memset(&host,0,sizeof(host));
295 host.properties = current_property_set;
297 host.id = A_surfxml_host_id;
298 host.power_peak = get_cpu_power(A_surfxml_host_power);
299 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
300 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
301 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
302 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
303 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
304 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
305 if (A_surfxml_host_state == A_surfxml_host_state_ON)
306 host.initial_state = SURF_RESOURCE_ON;
307 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
308 host.initial_state = SURF_RESOURCE_OFF;
309 host.coord = A_surfxml_host_coordinates;
311 sg_platf_new_host(&host);
312 current_property_set = NULL;
315 void STag_surfxml_host_link(void){
316 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host_link_id);
317 s_sg_platf_host_link_cbarg_t host_link;
318 memset(&host_link,0,sizeof(host_link));
320 host_link.id = A_surfxml_host_link_id;
321 host_link.link_up = A_surfxml_host_link_up;
322 host_link.link_down = A_surfxml_host_link_down;
323 sg_platf_new_host_link(&host_link);
326 void STag_surfxml_router(void){
327 s_sg_platf_router_cbarg_t router;
328 memset(&router, 0, sizeof(router));
330 router.id = A_surfxml_router_id;
331 router.coord = A_surfxml_router_coordinates;
333 sg_platf_new_router(&router);
336 void STag_surfxml_cluster(void){
337 s_sg_platf_cluster_cbarg_t cluster;
338 memset(&cluster,0,sizeof(cluster));
339 cluster.id = A_surfxml_cluster_id;
340 cluster.prefix = A_surfxml_cluster_prefix;
341 cluster.suffix = A_surfxml_cluster_suffix;
342 cluster.radical = A_surfxml_cluster_radical;
343 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
344 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
345 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
346 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
347 if(strcmp(A_surfxml_cluster_bb_bw,""))
348 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
349 if(strcmp(A_surfxml_cluster_bb_lat,""))
350 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
351 cluster.router_id = A_surfxml_cluster_router_id;
353 switch (AX_surfxml_cluster_sharing_policy) {
354 case A_surfxml_cluster_sharing_policy_SHARED:
355 cluster.sharing_policy = SURF_LINK_SHARED;
357 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
358 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
360 case A_surfxml_cluster_sharing_policy_FATPIPE:
361 cluster.sharing_policy = SURF_LINK_FATPIPE;
364 surf_parse_error("Invalid cluster sharing policy for cluster %s",
368 switch (AX_surfxml_cluster_bb_sharing_policy) {
369 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
370 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
372 case A_surfxml_cluster_bb_sharing_policy_SHARED:
373 cluster.bb_sharing_policy = SURF_LINK_SHARED;
376 surf_parse_error("Invalid bb sharing policy in cluster %s",
381 cluster.availability_trace = A_surfxml_cluster_availability_file;
382 cluster.state_trace = A_surfxml_cluster_state_file;
383 sg_platf_new_cluster(&cluster);
386 void STag_surfxml_cabinet(void){
387 s_sg_platf_cabinet_cbarg_t cabinet;
388 memset(&cabinet,0,sizeof(cabinet));
389 cabinet.id = A_surfxml_cabinet_id;
390 cabinet.prefix = A_surfxml_cabinet_prefix;
391 cabinet.suffix = A_surfxml_cabinet_suffix;
392 cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power);
393 cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw);
394 cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat);
395 cabinet.radical = A_surfxml_cabinet_radical;
397 sg_platf_new_cabinet(&cabinet);
400 void STag_surfxml_peer(void){
401 s_sg_platf_peer_cbarg_t peer;
402 memset(&peer,0,sizeof(peer));
403 peer.id = A_surfxml_peer_id;
404 peer.power = surf_parse_get_double(A_surfxml_peer_power);
405 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
406 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
407 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
408 peer.coord = A_surfxml_peer_coordinates;
409 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
410 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
412 sg_platf_new_peer(&peer);
415 void STag_surfxml_link(void){
417 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
420 void ETag_surfxml_link(void){
421 s_sg_platf_link_cbarg_t link;
422 memset(&link,0,sizeof(link));
424 link.properties = current_property_set;
426 link.id = A_surfxml_link_id;
427 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
428 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
429 link.latency = surf_parse_get_double(A_surfxml_link_latency);
430 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
432 switch (A_surfxml_link_state) {
433 case A_surfxml_link_state_ON:
434 link.state = SURF_RESOURCE_ON;
436 case A_surfxml_link_state_OFF:
437 link.state = SURF_RESOURCE_OFF;
440 surf_parse_error("invalid state for link %s", link.id);
443 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
445 switch (A_surfxml_link_sharing_policy) {
446 case A_surfxml_link_sharing_policy_SHARED:
447 link.policy = SURF_LINK_SHARED;
449 case A_surfxml_link_sharing_policy_FATPIPE:
450 link.policy = SURF_LINK_FATPIPE;
452 case A_surfxml_link_sharing_policy_FULLDUPLEX:
453 link.policy = SURF_LINK_FULLDUPLEX;
456 surf_parse_error("Invalid sharing policy in link %s", link.id);
460 sg_platf_new_link(&link);
462 current_property_set = NULL;
465 void STag_surfxml_link_ctn(void){
468 switch (A_surfxml_link_ctn_direction) {
469 case AU_surfxml_link_ctn_direction:
470 case A_surfxml_link_ctn_direction_NONE:
471 link_id = xbt_strdup(A_surfxml_link_ctn_id);
473 case A_surfxml_link_ctn_direction_UP:
474 link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
476 case A_surfxml_link_ctn_direction_DOWN:
477 link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
481 // FIXME we should push the surf link object but it don't
482 // work because of model rulebased
483 xbt_dynar_push(parsed_link_list, &link_id);
486 void ETag_surfxml_backbone(void){
487 s_sg_platf_link_cbarg_t link;
488 memset(&link,0,sizeof(link));
490 link.properties = NULL;
492 link.id = A_surfxml_backbone_id;
493 link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth);
494 link.latency = surf_parse_get_double(A_surfxml_backbone_latency);
495 link.state = SURF_RESOURCE_ON;
496 link.policy = SURF_LINK_SHARED;
498 sg_platf_new_link(&link);
499 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
502 void STag_surfxml_route(void){
503 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
504 "Missing end-points while defining route \"%s\"->\"%s\"",
505 A_surfxml_route_src, A_surfxml_route_dst);
506 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
509 void STag_surfxml_ASroute(void){
510 xbt_assert(strlen(A_surfxml_ASroute_src) > 0 || strlen(A_surfxml_ASroute_dst) > 0
511 || strlen(A_surfxml_ASroute_gw_src) > 0 || strlen(A_surfxml_ASroute_gw_dst) > 0,
512 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
513 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
514 A_surfxml_ASroute_gw_src,A_surfxml_ASroute_gw_dst);
515 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
518 void STag_surfxml_bypassRoute(void){
519 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0 || strlen(A_surfxml_bypassRoute_dst) > 0,
520 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
521 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
522 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
525 void STag_surfxml_bypassASroute(void){
526 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0 || strlen(A_surfxml_bypassASroute_dst) > 0
527 || strlen(A_surfxml_bypassASroute_gw_src) > 0 || strlen(A_surfxml_bypassASroute_gw_dst) > 0,
528 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
529 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
530 A_surfxml_bypassASroute_gw_src,A_surfxml_bypassASroute_gw_dst);
531 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
534 void ETag_surfxml_route(void){
535 s_sg_platf_route_cbarg_t route;
536 memset(&route,0,sizeof(route));
538 route.src = A_surfxml_route_src;
539 route.dst = A_surfxml_route_dst;
542 route.link_list = parsed_link_list;
544 switch (A_surfxml_route_symmetrical) {
545 case AU_surfxml_route_symmetrical:
546 case A_surfxml_route_symmetrical_YES:
547 route.symmetrical = TRUE;
549 case A_surfxml_route_symmetrical_NO:
550 route.symmetrical = FALSE;;
554 sg_platf_new_route(&route);
555 parsed_link_list = NULL;
558 void ETag_surfxml_ASroute(void){
559 s_sg_platf_route_cbarg_t ASroute;
560 memset(&ASroute,0,sizeof(ASroute));
562 ASroute.src = A_surfxml_ASroute_src;
563 ASroute.dst = A_surfxml_ASroute_dst;
565 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
566 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
567 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
569 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
570 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_ASroute_gw_src;
571 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_ASroute_gw_dst;
573 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw_src);
574 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw_dst);
577 ASroute.link_list = parsed_link_list;
579 switch (A_surfxml_ASroute_symmetrical) {
580 case AU_surfxml_ASroute_symmetrical:
581 case A_surfxml_ASroute_symmetrical_YES:
582 ASroute.symmetrical = TRUE;
584 case A_surfxml_ASroute_symmetrical_NO:
585 ASroute.symmetrical = FALSE;
589 sg_platf_new_ASroute(&ASroute);
590 parsed_link_list = NULL;
593 void ETag_surfxml_bypassRoute(void){
594 s_sg_platf_route_cbarg_t route;
595 memset(&route,0,sizeof(route));
597 route.src = A_surfxml_bypassRoute_src;
598 route.dst = A_surfxml_bypassRoute_dst;
601 route.link_list = parsed_link_list;
602 route.symmetrical = FALSE;
604 sg_platf_new_bypassRoute(&route);
605 parsed_link_list = NULL;
608 void ETag_surfxml_bypassASroute(void){
609 s_sg_platf_route_cbarg_t ASroute;
610 memset(&ASroute,0,sizeof(ASroute));
612 ASroute.src = A_surfxml_bypassASroute_src;
613 ASroute.dst = A_surfxml_bypassASroute_dst;
614 ASroute.link_list = parsed_link_list;
615 ASroute.symmetrical = FALSE;
617 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
618 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
619 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
621 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
622 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_bypassASroute_gw_src;
623 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_bypassASroute_gw_dst;
625 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw_src);
626 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw_dst);
629 sg_platf_new_bypassASroute(&ASroute);
630 parsed_link_list = NULL;
633 void ETag_surfxml_trace(void){
634 s_sg_platf_trace_cbarg_t trace;
635 memset(&trace,0,sizeof(trace));
637 trace.id = A_surfxml_trace_id;
638 trace.file = A_surfxml_trace_file;
639 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
640 trace.pc_data = surfxml_pcdata;
642 sg_platf_new_trace(&trace);
645 void STag_surfxml_trace_connect(void){
646 s_sg_platf_trace_connect_cbarg_t trace_connect;
647 memset(&trace_connect,0,sizeof(trace_connect));
649 trace_connect.element = A_surfxml_trace_connect_element;
650 trace_connect.trace = A_surfxml_trace_connect_trace;
652 switch (A_surfxml_trace_connect_kind) {
653 case AU_surfxml_trace_connect_kind:
654 case A_surfxml_trace_connect_kind_POWER:
655 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
657 case A_surfxml_trace_connect_kind_BANDWIDTH:
658 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
660 case A_surfxml_trace_connect_kind_HOST_AVAIL:
661 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
663 case A_surfxml_trace_connect_kind_LATENCY:
664 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
666 case A_surfxml_trace_connect_kind_LINK_AVAIL:
667 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
670 sg_platf_new_trace_connect(&trace_connect);
673 void STag_surfxml_AS(void){
675 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
676 AS.id = A_surfxml_AS_id;
677 AS.routing = (int)A_surfxml_AS_routing;
679 as_current_property_set = NULL;
681 sg_platf_new_AS_begin(&AS);
683 void ETag_surfxml_AS(void){
685 char *name = as_name_tab[as_prop_nb-1];
686 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
688 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
689 xbt_lib_set(as_router_lib,
691 ROUTING_PROP_ASR_LEVEL,
695 sg_platf_new_AS_end();
698 extern int _sg_init_status; /* FIXME: find a proper way to export this at some point */
700 void STag_surfxml_config(void){
702 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
703 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
704 if (_sg_init_status == 2) {
705 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
708 void ETag_surfxml_config(void){
709 xbt_dict_cursor_t cursor = NULL;
713 xbt_dict_foreach(current_property_set, cursor, key, elem) {
714 cfg = bprintf("%s:%s",key,elem);
715 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
716 xbt_cfg_set_parse(_sg_cfg_set, cfg);
718 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
721 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
722 xbt_dict_free(¤t_property_set);
723 current_property_set = NULL;
729 void STag_surfxml_process(void){
732 argv = xbt_new(char *, 1);
733 argv[0] = xbt_strdup(A_surfxml_process_function);
734 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
737 void ETag_surfxml_process(void){
738 s_sg_platf_process_cbarg_t process;
739 memset(&process,0,sizeof(process));
742 process.argv = (const char **)argv;
743 process.properties = current_property_set;
744 process.host = A_surfxml_process_host;
745 process.function = A_surfxml_process_function;
746 process.start_time = surf_parse_get_double(A_surfxml_process_start_time);
747 process.kill_time = surf_parse_get_double(A_surfxml_process_kill_time);
749 switch (A_surfxml_process_on_failure) {
750 case AU_surfxml_process_on_failure:
751 case A_surfxml_process_on_failure_DIE:
752 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
754 case A_surfxml_process_on_failure_RESTART:
755 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
759 sg_platf_new_process(&process);
760 current_property_set = NULL;
763 void STag_surfxml_argument(void){
765 argv = xbt_realloc(argv, (argc) * sizeof(char *));
766 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
769 /* ***************************************** */
770 /* TUTORIAL: New TAG */
771 void STag_surfxml_gpu(void)
773 XBT_DEBUG("STag_surfxml_gpu");
775 void ETag_surfxml_gpu(void)
777 s_sg_platf_gpu_cbarg_t gpu;
778 memset(&gpu,0,sizeof(gpu));
780 gpu.name = A_surfxml_gpu_name;
782 sg_platf_new_gpu(&gpu);
784 /* ***************************************** */
786 /* nothing to do in those functions */
787 void ETag_surfxml_prop(void){}
788 void STag_surfxml_random(void){}
789 void ETag_surfxml_random(void){}
790 void ETag_surfxml_trace_connect(void){}
791 void STag_surfxml_trace(void){}
792 void ETag_surfxml_router(void){}
793 void ETag_surfxml_host_link(void){}
794 void ETag_surfxml_cluster(void){}
795 void ETag_surfxml_cabinet(void){}
796 void ETag_surfxml_peer(void){}
797 void STag_surfxml_backbone(void){}
798 void ETag_surfxml_link_ctn(void){}
799 void ETag_surfxml_argument(void){}
801 /* Open and Close parse file */
803 void surf_parse_open(const char *file)
805 static int warned = 0; /* warn only once */
809 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
810 "If it is not what you want, go fix your code.");
816 if (!surf_input_buffer_stack)
817 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
818 if (!surf_file_to_parse_stack)
819 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
821 if (!surf_parsed_filename_stack)
822 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
823 surf_parsed_filename = xbt_strdup(file);
825 surf_file_to_parse = surf_fopen(file, "r");
826 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
827 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
828 surf_parse__switch_to_buffer(surf_input_buffer);
829 surf_parse_lineno = 1;
832 void surf_parse_close(void)
834 xbt_dynar_free(&surf_input_buffer_stack);
835 xbt_dynar_free(&surf_file_to_parse_stack);
836 xbt_dynar_free(&surf_parsed_filename_stack);
838 free(surf_parsed_filename);
840 if (surf_file_to_parse) {
841 surf_parse__delete_buffer(surf_input_buffer);
842 fclose(surf_file_to_parse);
843 surf_file_to_parse = NULL; //Must be reset for Bypass
847 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
849 static int _surf_parse(void) {
850 return surf_parse_lex();
852 int_f_void_t surf_parse = _surf_parse;
855 /* Prop tag functions */
861 /* Random tag functions */
863 double get_cpu_power(const char *power)
865 double power_scale = 0.0;
868 random_data_t random = NULL;
869 /* randomness is inserted like this: power="$rand(my_random)" */
870 if (((p = strstr(power, "$rand(")) != NULL)
871 && ((q = strstr(power, ")")) != NULL)) {
873 generator = xbt_malloc(q - (p + 6) + 1);
874 memcpy(generator, p + 6, q - (p + 6));
875 generator[q - (p + 6)] = '\0';
876 random = xbt_dict_get_or_null(random_data_list, generator);
877 xbt_assert(random, "Random generator %s undefined", generator);
878 power_scale = random_generate(random);
881 power_scale = surf_parse_get_double(power);
886 double random_min, random_max, random_mean, random_std_deviation;
887 e_random_generator_t random_generator;
890 static void init_randomness(void)
892 random_id = A_surfxml_random_id;
893 random_min = surf_parse_get_double(A_surfxml_random_min);
894 random_max = surf_parse_get_double(A_surfxml_random_max);
895 random_mean = surf_parse_get_double(A_surfxml_random_mean);
896 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
897 switch (A_surfxml_random_generator) {
898 case AU_surfxml_random_generator:
899 case A_surfxml_random_generator_NONE:
900 random_generator = NONE;
902 case A_surfxml_random_generator_DRAND48:
903 random_generator = DRAND48;
905 case A_surfxml_random_generator_RAND:
906 random_generator = RAND;
908 case A_surfxml_random_generator_RNGSTREAM:
909 random_generator = RNGSTREAM;
912 surf_parse_error("Invalid random generator");
917 static void add_randomness(void)
919 /* If needed aditional properties can be added by using the prop tag */
920 random_data_t random =
921 random_new(random_generator, 0, random_min, random_max, random_mean,
922 random_std_deviation);
923 xbt_dict_set(random_data_list, random_id, (void *) random,
928 xbt_dict_t get_as_router_properties(const char* name)
930 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);