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 */
26 extern AS_t current_routing;
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 xbt_dict_t as_current_property_set = NULL;
74 char* as_name_tab[1024];
75 void* as_dict_tab[1024];
79 /* dictionary of random generator data */
80 xbt_dict_t random_data_list = NULL;
82 YY_BUFFER_STATE surf_input_buffer;
83 FILE *surf_file_to_parse = NULL;
85 static void init_randomness(void);
86 static void add_randomness(void);
89 * Stuff relative to storage
91 void STag_surfxml_storage(void)
94 XBT_DEBUG("STag_surfxml_storage");
95 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
97 void ETag_surfxml_storage(void)
99 s_sg_platf_storage_cbarg_t storage;
100 memset(&storage,0,sizeof(storage));
102 storage.id = A_surfxml_storage_id;
103 storage.type_id = A_surfxml_storage_typeId;
104 storage.content = A_surfxml_storage_content;
105 storage.properties = current_property_set;
106 sg_platf_new_storage(&storage);
107 current_property_set = NULL;
109 void STag_surfxml_storage_type(void)
112 XBT_DEBUG("STag_surfxml_storage_type");
113 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
115 void ETag_surfxml_storage_type(void)
117 s_sg_platf_storage_type_cbarg_t storage_type;
118 memset(&storage_type,0,sizeof(storage_type));
120 storage_type.content = A_surfxml_storage_type_content;
121 storage_type.id = A_surfxml_storage_type_id;
122 storage_type.model = A_surfxml_storage_type_model;
123 storage_type.properties = current_property_set;
124 storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
125 sg_platf_new_storage_type(&storage_type);
126 current_property_set = NULL;
128 void STag_surfxml_mstorage(void)
130 XBT_DEBUG("STag_surfxml_mstorage");
132 void ETag_surfxml_mstorage(void)
134 s_sg_platf_mstorage_cbarg_t mstorage;
135 memset(&mstorage,0,sizeof(mstorage));
137 mstorage.name = A_surfxml_mstorage_name;
138 mstorage.type_id = A_surfxml_mstorage_typeId;
139 sg_platf_new_mstorage(&mstorage);
141 void STag_surfxml_mount(void)
143 XBT_DEBUG("STag_surfxml_mount");
145 void ETag_surfxml_mount(void)
147 s_sg_platf_mount_cbarg_t mount;
148 memset(&mount,0,sizeof(mount));
150 mount.name = A_surfxml_mount_name;
151 mount.id = A_surfxml_mount_id;
152 sg_platf_new_mount(&mount);
156 * Stuff relative to the <include> tag
158 static xbt_dynar_t surf_input_buffer_stack = NULL;
159 static xbt_dynar_t surf_file_to_parse_stack = NULL;
160 static xbt_dynar_t surf_parsed_filename_stack = NULL;
162 void STag_surfxml_include(void)
164 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
165 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
166 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
168 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
170 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
171 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
172 A_surfxml_include_file);
173 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
174 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
175 surf_parse_push_buffer_state(surf_input_buffer);
180 void ETag_surfxml_include(void) {
181 /* Nothing to do when done with reading the include tag.
182 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
185 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
187 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
188 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
189 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
190 * error message in that case.
192 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
193 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
194 * on a line. One day maybe, if the maya allow it.
196 int ETag_surfxml_include_state(void)
199 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
201 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
204 // Yeah, we were in an <include> Restore state and proceed.
205 fclose(surf_file_to_parse);
206 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
207 surf_parse_pop_buffer_state();
208 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
210 // Restore the filename for error messages
211 free(surf_parsed_filename);
212 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
218 void surf_parse_init_callbacks(void)
223 void surf_parse_reset_callbacks(void)
225 surf_parse_free_callbacks();
226 surf_parse_init_callbacks();
229 void surf_parse_free_callbacks(void)
234 /* Stag and Etag parse functions */
236 void STag_surfxml_platform(void) {
237 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
239 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
240 "You're using an ancient XML file.\n"
241 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
242 "instead of MBytes, MFlops and seconds.\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.\n"
248 "Please check also out the SURF section of the ChangeLog for "
249 "the 3.1 version for more information. \n"
251 "Last, do not forget to also update your values for "
252 "the calls to MSG_task_create (if any).");
253 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
254 "You're using an old XML file.\n"
255 "Use simgrid_update_xml to update your file automatically. "
256 "This program is installed automatically with SimGrid, or "
257 "available in the tools/ directory of the source archive.");
261 void ETag_surfxml_platform(void){
265 void STag_surfxml_host(void){
267 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
270 void STag_surfxml_prop(void)
273 if (!as_current_property_set){
274 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
275 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
276 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
277 as_dict_tab[as_prop_nb] = as_current_property_set;
278 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
281 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
284 if (!current_property_set)
285 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
286 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
290 void ETag_surfxml_host(void) {
291 s_sg_platf_host_cbarg_t host;
292 memset(&host,0,sizeof(host));
294 host.properties = current_property_set;
296 host.id = A_surfxml_host_id;
297 host.power_peak = get_cpu_power(A_surfxml_host_power);
298 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
299 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
300 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability_file);
301 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state_file);
302 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
303 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
304 if (A_surfxml_host_state == A_surfxml_host_state_ON)
305 host.initial_state = SURF_RESOURCE_ON;
306 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
307 host.initial_state = SURF_RESOURCE_OFF;
308 host.coord = A_surfxml_host_coordinates;
310 sg_platf_new_host(&host);
311 current_property_set = NULL;
314 void STag_surfxml_host_link(void){
315 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host_link_id);
316 s_sg_platf_host_link_cbarg_t host_link;
317 memset(&host_link,0,sizeof(host_link));
319 host_link.id = A_surfxml_host_link_id;
320 host_link.link_up = A_surfxml_host_link_up;
321 host_link.link_down = A_surfxml_host_link_down;
322 sg_platf_new_host_link(&host_link);
325 void STag_surfxml_router(void){
326 s_sg_platf_router_cbarg_t router;
327 memset(&router, 0, sizeof(router));
329 router.id = A_surfxml_router_id;
330 router.coord = A_surfxml_router_coordinates;
332 sg_platf_new_router(&router);
335 void STag_surfxml_cluster(void){
336 s_sg_platf_cluster_cbarg_t cluster;
337 memset(&cluster,0,sizeof(cluster));
338 cluster.id = A_surfxml_cluster_id;
339 cluster.prefix = A_surfxml_cluster_prefix;
340 cluster.suffix = A_surfxml_cluster_suffix;
341 cluster.radical = A_surfxml_cluster_radical;
342 cluster.power= surf_parse_get_double(A_surfxml_cluster_power);
343 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
344 cluster.bw = surf_parse_get_double(A_surfxml_cluster_bw);
345 cluster.lat = surf_parse_get_double(A_surfxml_cluster_lat);
346 if(strcmp(A_surfxml_cluster_bb_bw,""))
347 cluster.bb_bw = surf_parse_get_double(A_surfxml_cluster_bb_bw);
348 if(strcmp(A_surfxml_cluster_bb_lat,""))
349 cluster.bb_lat = surf_parse_get_double(A_surfxml_cluster_bb_lat);
350 cluster.router_id = A_surfxml_cluster_router_id;
352 switch (AX_surfxml_cluster_sharing_policy) {
353 case A_surfxml_cluster_sharing_policy_SHARED:
354 cluster.sharing_policy = SURF_LINK_SHARED;
356 case A_surfxml_cluster_sharing_policy_FULLDUPLEX:
357 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
359 case A_surfxml_cluster_sharing_policy_FATPIPE:
360 cluster.sharing_policy = SURF_LINK_FATPIPE;
363 surf_parse_error("Invalid cluster sharing policy for cluster %s",
367 switch (AX_surfxml_cluster_bb_sharing_policy) {
368 case A_surfxml_cluster_bb_sharing_policy_FATPIPE:
369 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
371 case A_surfxml_cluster_bb_sharing_policy_SHARED:
372 cluster.bb_sharing_policy = SURF_LINK_SHARED;
375 surf_parse_error("Invalid bb sharing policy in cluster %s",
380 cluster.availability_trace = A_surfxml_cluster_availability_file;
381 cluster.state_trace = A_surfxml_cluster_state_file;
382 sg_platf_new_cluster(&cluster);
385 void STag_surfxml_cabinet(void){
386 s_sg_platf_cabinet_cbarg_t cabinet;
387 memset(&cabinet,0,sizeof(cabinet));
388 cabinet.id = A_surfxml_cabinet_id;
389 cabinet.prefix = A_surfxml_cabinet_prefix;
390 cabinet.suffix = A_surfxml_cabinet_suffix;
391 cabinet.power = surf_parse_get_double(A_surfxml_cabinet_power);
392 cabinet.bw = surf_parse_get_double(A_surfxml_cabinet_bw);
393 cabinet.lat = surf_parse_get_double(A_surfxml_cabinet_lat);
394 cabinet.radical = A_surfxml_cabinet_radical;
396 sg_platf_new_cabinet(&cabinet);
399 void STag_surfxml_peer(void){
400 s_sg_platf_peer_cbarg_t peer;
401 memset(&peer,0,sizeof(peer));
402 peer.id = A_surfxml_peer_id;
403 peer.power = surf_parse_get_double(A_surfxml_peer_power);
404 peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
405 peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
406 peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
407 peer.coord = A_surfxml_peer_coordinates;
408 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability_file);
409 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state_file);
411 sg_platf_new_peer(&peer);
414 void STag_surfxml_link(void){
416 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
419 void ETag_surfxml_link(void){
420 s_sg_platf_link_cbarg_t link;
421 memset(&link,0,sizeof(link));
423 link.properties = current_property_set;
425 link.id = A_surfxml_link_id;
426 link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
427 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth_file);
428 link.latency = surf_parse_get_double(A_surfxml_link_latency);
429 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency_file);
431 switch (A_surfxml_link_state) {
432 case A_surfxml_link_state_ON:
433 link.state = SURF_RESOURCE_ON;
435 case A_surfxml_link_state_OFF:
436 link.state = SURF_RESOURCE_OFF;
439 surf_parse_error("invalid state for link %s", link.id);
442 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state_file);
444 switch (A_surfxml_link_sharing_policy) {
445 case A_surfxml_link_sharing_policy_SHARED:
446 link.policy = SURF_LINK_SHARED;
448 case A_surfxml_link_sharing_policy_FATPIPE:
449 link.policy = SURF_LINK_FATPIPE;
451 case A_surfxml_link_sharing_policy_FULLDUPLEX:
452 link.policy = SURF_LINK_FULLDUPLEX;
455 surf_parse_error("Invalid sharing policy in link %s", link.id);
459 sg_platf_new_link(&link);
461 current_property_set = NULL;
464 void STag_surfxml_link_ctn(void){
467 switch (A_surfxml_link_ctn_direction) {
468 case AU_surfxml_link_ctn_direction:
469 case A_surfxml_link_ctn_direction_NONE:
470 link_id = xbt_strdup(A_surfxml_link_ctn_id);
472 case A_surfxml_link_ctn_direction_UP:
473 link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
475 case A_surfxml_link_ctn_direction_DOWN:
476 link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
480 // FIXME we should push the surf link object but it don't
481 // work because of model rulebased
482 xbt_dynar_push(parsed_link_list, &link_id);
485 void ETag_surfxml_backbone(void){
486 s_sg_platf_link_cbarg_t link;
487 memset(&link,0,sizeof(link));
489 link.properties = NULL;
491 link.id = A_surfxml_backbone_id;
492 link.bandwidth = surf_parse_get_double(A_surfxml_backbone_bandwidth);
493 link.latency = surf_parse_get_double(A_surfxml_backbone_latency);
494 link.state = SURF_RESOURCE_ON;
495 link.policy = SURF_LINK_SHARED;
497 sg_platf_new_link(&link);
498 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
501 void STag_surfxml_route(void){
502 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
503 "Missing end-points while defining route \"%s\"->\"%s\"",
504 A_surfxml_route_src, A_surfxml_route_dst);
505 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
508 void STag_surfxml_ASroute(void){
509 xbt_assert(strlen(A_surfxml_ASroute_src) > 0 || strlen(A_surfxml_ASroute_dst) > 0
510 || strlen(A_surfxml_ASroute_gw_src) > 0 || strlen(A_surfxml_ASroute_gw_dst) > 0,
511 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
512 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
513 A_surfxml_ASroute_gw_src,A_surfxml_ASroute_gw_dst);
514 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
517 void STag_surfxml_bypassRoute(void){
518 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0 || strlen(A_surfxml_bypassRoute_dst) > 0,
519 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
520 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
521 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
524 void STag_surfxml_bypassASroute(void){
525 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0 || strlen(A_surfxml_bypassASroute_dst) > 0
526 || strlen(A_surfxml_bypassASroute_gw_src) > 0 || strlen(A_surfxml_bypassASroute_gw_dst) > 0,
527 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
528 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
529 A_surfxml_bypassASroute_gw_src,A_surfxml_bypassASroute_gw_dst);
530 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
533 void ETag_surfxml_route(void){
534 s_sg_platf_route_cbarg_t route;
535 memset(&route,0,sizeof(route));
537 route.src = A_surfxml_route_src;
538 route.dst = A_surfxml_route_dst;
541 route.link_list = parsed_link_list;
543 switch (A_surfxml_route_symmetrical) {
544 case AU_surfxml_route_symmetrical:
545 case A_surfxml_route_symmetrical_YES:
546 route.symmetrical = TRUE;
548 case A_surfxml_route_symmetrical_NO:
549 route.symmetrical = FALSE;;
553 sg_platf_new_route(&route);
554 parsed_link_list = NULL;
557 void ETag_surfxml_ASroute(void){
558 s_sg_platf_route_cbarg_t ASroute;
559 memset(&ASroute,0,sizeof(ASroute));
561 ASroute.src = A_surfxml_ASroute_src;
562 ASroute.dst = A_surfxml_ASroute_dst;
564 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
565 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
566 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
568 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
569 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_ASroute_gw_src;
570 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_ASroute_gw_dst;
572 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw_src);
573 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw_dst);
576 ASroute.link_list = parsed_link_list;
578 switch (A_surfxml_ASroute_symmetrical) {
579 case AU_surfxml_ASroute_symmetrical:
580 case A_surfxml_ASroute_symmetrical_YES:
581 ASroute.symmetrical = TRUE;
583 case A_surfxml_ASroute_symmetrical_NO:
584 ASroute.symmetrical = FALSE;
588 sg_platf_new_ASroute(&ASroute);
589 parsed_link_list = NULL;
592 void ETag_surfxml_bypassRoute(void){
593 s_sg_platf_route_cbarg_t route;
594 memset(&route,0,sizeof(route));
596 route.src = A_surfxml_bypassRoute_src;
597 route.dst = A_surfxml_bypassRoute_dst;
600 route.link_list = parsed_link_list;
601 route.symmetrical = FALSE;
603 sg_platf_new_bypassRoute(&route);
604 parsed_link_list = NULL;
607 void ETag_surfxml_bypassASroute(void){
608 s_sg_platf_route_cbarg_t ASroute;
609 memset(&ASroute,0,sizeof(ASroute));
611 ASroute.src = A_surfxml_bypassASroute_src;
612 ASroute.dst = A_surfxml_bypassASroute_dst;
613 ASroute.link_list = parsed_link_list;
614 ASroute.symmetrical = FALSE;
616 if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
617 // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
618 // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
620 // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
621 ASroute.gw_src = (sg_routing_edge_t) A_surfxml_bypassASroute_gw_src;
622 ASroute.gw_dst = (sg_routing_edge_t) A_surfxml_bypassASroute_gw_dst;
624 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw_src);
625 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw_dst);
628 sg_platf_new_bypassASroute(&ASroute);
629 parsed_link_list = NULL;
632 void ETag_surfxml_trace(void){
633 s_sg_platf_trace_cbarg_t trace;
634 memset(&trace,0,sizeof(trace));
636 trace.id = A_surfxml_trace_id;
637 trace.file = A_surfxml_trace_file;
638 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
639 trace.pc_data = surfxml_pcdata;
641 sg_platf_new_trace(&trace);
644 void STag_surfxml_trace_connect(void){
645 s_sg_platf_trace_connect_cbarg_t trace_connect;
646 memset(&trace_connect,0,sizeof(trace_connect));
648 trace_connect.element = A_surfxml_trace_connect_element;
649 trace_connect.trace = A_surfxml_trace_connect_trace;
651 switch (A_surfxml_trace_connect_kind) {
652 case AU_surfxml_trace_connect_kind:
653 case A_surfxml_trace_connect_kind_POWER:
654 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
656 case A_surfxml_trace_connect_kind_BANDWIDTH:
657 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
659 case A_surfxml_trace_connect_kind_HOST_AVAIL:
660 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
662 case A_surfxml_trace_connect_kind_LATENCY:
663 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
665 case A_surfxml_trace_connect_kind_LINK_AVAIL:
666 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
669 sg_platf_new_trace_connect(&trace_connect);
672 void STag_surfxml_AS(void){
674 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
675 AS.id = A_surfxml_AS_id;
676 AS.routing = (int)A_surfxml_AS_routing;
678 as_current_property_set = NULL;
680 sg_platf_new_AS_begin(&AS);
682 void ETag_surfxml_AS(void){
684 char *name = as_name_tab[as_prop_nb-1];
685 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
687 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
688 xbt_lib_set(as_router_lib,
690 ROUTING_PROP_ASR_LEVEL,
694 sg_platf_new_AS_end();
697 extern int _surf_init_status; /* FIXME: find a proper way to export this at some point */
699 void STag_surfxml_config(void){
701 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
702 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
703 if (_surf_init_status == 2) {
704 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
707 void ETag_surfxml_config(void){
708 xbt_dict_cursor_t cursor = NULL;
712 xbt_dict_foreach(current_property_set, cursor, key, elem) {
713 cfg = bprintf("%s:%s",key,elem);
714 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
715 xbt_cfg_set_parse(_surf_cfg_set, cfg);
717 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
720 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
721 xbt_dict_free(¤t_property_set);
722 current_property_set = NULL;
728 void STag_surfxml_process(void){
731 argv = xbt_new(char *, 1);
732 argv[0] = xbt_strdup(A_surfxml_process_function);
733 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
736 void ETag_surfxml_process(void){
737 s_sg_platf_process_cbarg_t process;
738 memset(&process,0,sizeof(process));
741 process.argv = (const char **)argv;
742 process.properties = current_property_set;
743 process.host = A_surfxml_process_host;
744 process.function = A_surfxml_process_function;
745 process.start_time = surf_parse_get_double(A_surfxml_process_start_time);
746 process.kill_time = surf_parse_get_double(A_surfxml_process_kill_time);
748 switch (A_surfxml_process_on_failure) {
749 case AU_surfxml_process_on_failure:
750 case A_surfxml_process_on_failure_DIE:
751 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
753 case A_surfxml_process_on_failure_RESTART:
754 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
758 sg_platf_new_process(&process);
759 current_property_set = NULL;
762 void STag_surfxml_argument(void){
764 argv = xbt_realloc(argv, (argc) * sizeof(char *));
765 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
768 /* ***************************************** */
769 /* TUTORIAL: New TAG */
770 void STag_surfxml_gpu(void)
772 XBT_DEBUG("STag_surfxml_gpu");
774 void ETag_surfxml_gpu(void)
776 s_sg_platf_gpu_cbarg_t gpu;
777 memset(&gpu,0,sizeof(gpu));
779 gpu.name = A_surfxml_gpu_name;
781 sg_platf_new_gpu(&gpu);
783 /* ***************************************** */
785 /* nothing to do in those functions */
786 void ETag_surfxml_prop(void){}
787 void STag_surfxml_random(void){}
788 void ETag_surfxml_random(void){}
789 void ETag_surfxml_trace_connect(void){}
790 void STag_surfxml_trace(void){}
791 void ETag_surfxml_router(void){}
792 void ETag_surfxml_host_link(void){}
793 void ETag_surfxml_cluster(void){}
794 void ETag_surfxml_cabinet(void){}
795 void ETag_surfxml_peer(void){}
796 void STag_surfxml_backbone(void){}
797 void ETag_surfxml_link_ctn(void){}
798 void ETag_surfxml_argument(void){}
800 /* Open and Close parse file */
802 void surf_parse_open(const char *file)
804 static int warned = 0; /* warn only once */
808 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
809 "If it is not what you want, go fix your code.");
815 if (!surf_input_buffer_stack)
816 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
817 if (!surf_file_to_parse_stack)
818 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
820 if (!surf_parsed_filename_stack)
821 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
822 surf_parsed_filename = xbt_strdup(file);
824 surf_file_to_parse = surf_fopen(file, "r");
825 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
826 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
827 surf_parse__switch_to_buffer(surf_input_buffer);
828 surf_parse_lineno = 1;
831 void surf_parse_close(void)
833 xbt_dynar_free(&surf_input_buffer_stack);
834 xbt_dynar_free(&surf_file_to_parse_stack);
835 xbt_dynar_free(&surf_parsed_filename_stack);
837 free(surf_parsed_filename);
839 if (surf_file_to_parse) {
840 surf_parse__delete_buffer(surf_input_buffer);
841 fclose(surf_file_to_parse);
842 surf_file_to_parse = NULL; //Must be reset for Bypass
846 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
848 static int _surf_parse(void) {
849 return surf_parse_lex();
851 int_f_void_t surf_parse = _surf_parse;
854 /* Prop tag functions */
860 /* Random tag functions */
862 double get_cpu_power(const char *power)
864 double power_scale = 0.0;
867 random_data_t random = NULL;
868 /* randomness is inserted like this: power="$rand(my_random)" */
869 if (((p = strstr(power, "$rand(")) != NULL)
870 && ((q = strstr(power, ")")) != NULL)) {
872 generator = xbt_malloc(q - (p + 6) + 1);
873 memcpy(generator, p + 6, q - (p + 6));
874 generator[q - (p + 6)] = '\0';
875 random = xbt_dict_get_or_null(random_data_list, generator);
876 xbt_assert(random, "Random generator %s undefined", generator);
877 power_scale = random_generate(random);
880 power_scale = surf_parse_get_double(power);
885 double random_min, random_max, random_mean, random_std_deviation;
886 e_random_generator_t random_generator;
889 static void init_randomness(void)
891 random_id = A_surfxml_random_id;
892 random_min = surf_parse_get_double(A_surfxml_random_min);
893 random_max = surf_parse_get_double(A_surfxml_random_max);
894 random_mean = surf_parse_get_double(A_surfxml_random_mean);
895 random_std_deviation = surf_parse_get_double(A_surfxml_random_std_deviation);
896 switch (A_surfxml_random_generator) {
897 case AU_surfxml_random_generator:
898 case A_surfxml_random_generator_NONE:
899 random_generator = NONE;
901 case A_surfxml_random_generator_DRAND48:
902 random_generator = DRAND48;
904 case A_surfxml_random_generator_RAND:
905 random_generator = RAND;
907 case A_surfxml_random_generator_RNGSTREAM:
908 random_generator = RNGSTREAM;
911 surf_parse_error("Invalid random generator");
916 static void add_randomness(void)
918 /* If needed aditional properties can be added by using the prop tag */
919 random_data_t random =
920 random_new(random_generator, 0, random_min, random_max, random_mean,
921 random_std_deviation);
922 xbt_dict_set(random_data_list, random_id, (void *) random,
927 xbt_dict_t get_as_router_properties(const char* name)
929 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);