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. */
9 #include <stdarg.h> /* va_arg */
15 #include "surf/surfxml_parse.h"
16 #include "surf/surf_private.h"
17 #include "simgrid/sg_config.h"
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
20 "Logging specific to the SURF parsing module");
22 int ETag_surfxml_include_state(void);
24 #include "simgrid_dtd.c"
26 char* surf_parsed_filename = NULL; // to locate parse error messages
28 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
29 extern AS_t current_routing;
33 void surf_parse_error(const char *fmt, ...) {
36 char *msg = bvprintf(fmt,va);
38 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
40 void surf_parse_warn(const char *fmt, ...) {
43 char *msg = bvprintf(fmt,va);
45 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
49 double surf_parse_get_double(const char *string) {
51 int ret = sscanf(string, "%lg", &res);
53 surf_parse_error("%s is not a double", string);
54 //printf("Parsed double [%lg] %s\n", res, string);
58 int surf_parse_get_int(const char *string) {
60 int ret = sscanf(string, "%d", &res);
62 surf_parse_error("%s is not an integer", string);
71 /* Note: field `unit' for the last element of parametre `units' should be
73 static double surf_parse_get_value_with_unit(const char *string,
74 const struct unit_scale *units)
80 res = strtod(string, &ptr);
82 surf_parse_error("value out of range: %s", string);
84 surf_parse_error("cannot parse number: %s", string);
85 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
87 if (units[i].unit != NULL)
88 res *= units[i].scale;
90 surf_parse_error("unknown unit: %s", ptr);
94 double surf_parse_get_time(const char *string)
96 const struct unit_scale units[] = {
97 { "w", 7 * 24 * 60 * 60 },
98 { "d", 24 * 60 * 60 },
102 { "", 1.0 }, /* default unit is seconds */
109 return surf_parse_get_value_with_unit(string, units);
112 double surf_parse_get_bandwidth(const char *string)
114 const struct unit_scale units[] = {
115 { "TiBps", pow(1024, 4) },
116 { "GiBps", pow(1024, 3) },
117 { "MiBps", pow(1024, 2) },
124 { "", 1.0 }, /* default unit is bytes per second */
125 { "Tibps", 0.125 * pow(1024, 4) },
126 { "Gibps", 0.125 * pow(1024, 3) },
127 { "Mibps", 0.125 * pow(1024, 2) },
128 { "Kibps", 0.125 * 1024 },
129 { "Tbps", 0.125 * 1e12 },
130 { "Gbps", 0.125 * 1e9 },
131 { "Mbps", 0.125 * 1e6 },
132 { "kbps", 0.125 * 1e3 },
136 return surf_parse_get_value_with_unit(string, units);
139 double surf_parse_get_power(const char *string)
141 const struct unit_scale units[] = {
142 { "yottaflops", 1e24 },
144 { "zettaflops", 1e21 },
146 { "exaflops", 1e18 },
148 { "petaflops", 1e15 },
150 { "teraflops", 1e12 },
152 { "gigaflops", 1e9 },
154 { "megaflops", 1e6 },
156 { "kiloflops", 1e3 },
160 { "", 1.0 }, /* default unit is flops */
163 return surf_parse_get_value_with_unit(string, units);
167 * All the callback lists that can be overridden anywhere.
168 * (this list should probably be reduced to the bare minimum to allow the models to work)
171 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
173 /* The default current property receiver. Setup in the corresponding opening callbacks. */
174 xbt_dict_t current_property_set = NULL;
175 xbt_dict_t as_current_property_set = NULL;
177 char* as_name_tab[1024];
178 void* as_dict_tab[1024];
182 /* dictionary of random generator data */
183 xbt_dict_t random_data_list = NULL;
185 YY_BUFFER_STATE surf_input_buffer;
186 FILE *surf_file_to_parse = NULL;
188 static void init_randomness(void);
189 static void add_randomness(void);
192 * Stuff relative to storage
194 void STag_surfxml_storage(void)
197 XBT_DEBUG("STag_surfxml_storage");
198 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
200 void ETag_surfxml_storage(void)
202 s_sg_platf_storage_cbarg_t storage;
203 memset(&storage,0,sizeof(storage));
205 storage.id = A_surfxml_storage_id;
206 storage.type_id = A_surfxml_storage_typeId;
207 storage.content = A_surfxml_storage_content;
208 storage.properties = current_property_set;
209 sg_platf_new_storage(&storage);
210 current_property_set = NULL;
212 void STag_surfxml_storage___type(void)
215 XBT_DEBUG("STag_surfxml_storage___type");
216 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
218 void ETag_surfxml_storage___type(void)
220 s_sg_platf_storage_type_cbarg_t storage_type;
221 memset(&storage_type,0,sizeof(storage_type));
223 storage_type.content = A_surfxml_storage___type_content;
224 storage_type.id = A_surfxml_storage___type_id;
225 storage_type.model = A_surfxml_storage___type_model;
226 storage_type.properties = current_property_set;
227 storage_type.size = surf_parse_get_int(A_surfxml_storage___type_size);
228 sg_platf_new_storage_type(&storage_type);
229 current_property_set = NULL;
231 void STag_surfxml_mstorage(void)
233 XBT_DEBUG("STag_surfxml_mstorage");
235 void ETag_surfxml_mstorage(void)
237 s_sg_platf_mstorage_cbarg_t mstorage;
238 memset(&mstorage,0,sizeof(mstorage));
240 mstorage.name = A_surfxml_mstorage_name;
241 mstorage.type_id = A_surfxml_mstorage_typeId;
242 sg_platf_new_mstorage(&mstorage);
244 void STag_surfxml_mount(void)
246 XBT_DEBUG("STag_surfxml_mount");
248 void ETag_surfxml_mount(void)
250 s_sg_platf_mount_cbarg_t mount;
251 memset(&mount,0,sizeof(mount));
253 mount.name = A_surfxml_mount_name;
254 mount.id = A_surfxml_mount_id;
255 sg_platf_new_mount(&mount);
259 * Stuff relative to the <include> tag
261 static xbt_dynar_t surf_input_buffer_stack = NULL;
262 static xbt_dynar_t surf_file_to_parse_stack = NULL;
263 static xbt_dynar_t surf_parsed_filename_stack = NULL;
265 void STag_surfxml_include(void)
267 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
268 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
269 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
271 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
273 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
274 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
275 A_surfxml_include_file);
276 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
277 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
278 surf_parse_push_buffer_state(surf_input_buffer);
283 void ETag_surfxml_include(void) {
284 /* Nothing to do when done with reading the include tag.
285 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
288 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
290 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
291 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
292 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
293 * error message in that case.
295 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
296 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
297 * on a line. One day maybe, if the maya allow it.
299 int ETag_surfxml_include_state(void)
302 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
304 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
307 // Yeah, we were in an <include> Restore state and proceed.
308 fclose(surf_file_to_parse);
309 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
310 surf_parse_pop_buffer_state();
311 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
313 // Restore the filename for error messages
314 free(surf_parsed_filename);
315 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
321 void surf_parse_init_callbacks(void)
326 void surf_parse_reset_callbacks(void)
328 surf_parse_free_callbacks();
329 surf_parse_init_callbacks();
332 void surf_parse_free_callbacks(void)
337 /* Stag and Etag parse functions */
339 void STag_surfxml_platform(void) {
340 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
342 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
343 "You're using an ancient XML file.\n"
344 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
345 "instead of MBytes, MFlops and seconds.\n"
347 "Use simgrid_update_xml to update your file automatically. "
348 "This program is installed automatically with SimGrid, or "
349 "available in the tools/ directory of the source archive.\n"
351 "Please check also out the SURF section of the ChangeLog for "
352 "the 3.1 version for more information. \n"
354 "Last, do not forget to also update your values for "
355 "the calls to MSG_task_create (if any).");
356 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
357 "You're using an old XML file.\n"
358 "Use simgrid_update_xml to update your file automatically. "
359 "This program is installed automatically with SimGrid, or "
360 "available in the tools/ directory of the source archive.");
364 void ETag_surfxml_platform(void){
368 void STag_surfxml_host(void){
370 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
373 void STag_surfxml_prop(void)
376 if (!as_current_property_set){
377 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
378 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
379 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
380 as_dict_tab[as_prop_nb] = as_current_property_set;
381 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
384 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
387 if (!current_property_set)
388 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
389 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
393 void ETag_surfxml_host(void) {
394 s_sg_platf_host_cbarg_t host;
395 memset(&host,0,sizeof(host));
397 host.properties = current_property_set;
399 host.id = A_surfxml_host_id;
400 host.power_peak = get_cpu_power(A_surfxml_host_power);
401 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
402 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
403 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
404 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
405 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
406 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
407 if (A_surfxml_host_state == A_surfxml_host_state_ON)
408 host.initial_state = SURF_RESOURCE_ON;
409 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
410 host.initial_state = SURF_RESOURCE_OFF;
411 host.coord = A_surfxml_host_coordinates;
413 sg_platf_new_host(&host);
414 current_property_set = NULL;
417 void STag_surfxml_host___link(void){
418 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
419 s_sg_platf_host_link_cbarg_t host_link;
420 memset(&host_link,0,sizeof(host_link));
422 host_link.id = A_surfxml_host___link_id;
423 host_link.link_up = A_surfxml_host___link_up;
424 host_link.link_down = A_surfxml_host___link_down;
425 sg_platf_new_host_link(&host_link);
428 void STag_surfxml_router(void){
429 s_sg_platf_router_cbarg_t router;
430 memset(&router, 0, sizeof(router));
432 router.id = A_surfxml_router_id;
433 router.coord = A_surfxml_router_coordinates;
435 sg_platf_new_router(&router);
438 void ETag_surfxml_cluster(void){
439 s_sg_platf_cluster_cbarg_t cluster;
440 memset(&cluster,0,sizeof(cluster));
441 cluster.properties = current_property_set;
443 cluster.id = A_surfxml_cluster_id;
444 cluster.prefix = A_surfxml_cluster_prefix;
445 cluster.suffix = A_surfxml_cluster_suffix;
446 cluster.radical = A_surfxml_cluster_radical;
447 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
448 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
449 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
450 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
451 if(strcmp(A_surfxml_cluster_bb___bw,""))
452 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
453 if(strcmp(A_surfxml_cluster_bb___lat,""))
454 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
455 if(strcmp(A_surfxml_cluster_limiter___link,""))
456 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
457 if(strcmp(A_surfxml_cluster_loopback___bw,""))
458 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
459 if(strcmp(A_surfxml_cluster_loopback___lat,""))
460 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
461 cluster.router_id = A_surfxml_cluster_router___id;
463 switch (AX_surfxml_cluster_sharing___policy) {
464 case A_surfxml_cluster_sharing___policy_SHARED:
465 cluster.sharing_policy = SURF_LINK_SHARED;
467 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
468 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
470 case A_surfxml_cluster_sharing___policy_FATPIPE:
471 cluster.sharing_policy = SURF_LINK_FATPIPE;
474 surf_parse_error("Invalid cluster sharing policy for cluster %s",
478 switch (AX_surfxml_cluster_bb___sharing___policy) {
479 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
480 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
482 case A_surfxml_cluster_bb___sharing___policy_SHARED:
483 cluster.bb_sharing_policy = SURF_LINK_SHARED;
486 surf_parse_error("Invalid bb sharing policy in cluster %s",
491 cluster.availability_trace = A_surfxml_cluster_availability___file;
492 cluster.state_trace = A_surfxml_cluster_state___file;
493 sg_platf_new_cluster(&cluster);
495 current_property_set = NULL;
498 void STag_surfxml_cluster(void){
499 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
502 void STag_surfxml_cabinet(void){
503 s_sg_platf_cabinet_cbarg_t cabinet;
504 memset(&cabinet,0,sizeof(cabinet));
505 cabinet.id = A_surfxml_cabinet_id;
506 cabinet.prefix = A_surfxml_cabinet_prefix;
507 cabinet.suffix = A_surfxml_cabinet_suffix;
508 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
509 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
510 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
511 cabinet.radical = A_surfxml_cabinet_radical;
513 sg_platf_new_cabinet(&cabinet);
516 void STag_surfxml_peer(void){
517 s_sg_platf_peer_cbarg_t peer;
518 memset(&peer,0,sizeof(peer));
519 peer.id = A_surfxml_peer_id;
520 peer.power = surf_parse_get_power(A_surfxml_peer_power);
521 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
522 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
523 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
524 peer.coord = A_surfxml_peer_coordinates;
525 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
526 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
528 sg_platf_new_peer(&peer);
531 void STag_surfxml_link(void){
533 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
536 void ETag_surfxml_link(void){
537 s_sg_platf_link_cbarg_t link;
538 memset(&link,0,sizeof(link));
540 link.properties = current_property_set;
542 link.id = A_surfxml_link_id;
543 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
544 //printf("Link bandwidth [%lg]\n", link.bandwidth);
545 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
546 link.latency = surf_parse_get_time(A_surfxml_link_latency);
547 //printf("Link latency [%lg]\n", link.latency);
548 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
550 switch (A_surfxml_link_state) {
551 case A_surfxml_link_state_ON:
552 link.state = SURF_RESOURCE_ON;
554 case A_surfxml_link_state_OFF:
555 link.state = SURF_RESOURCE_OFF;
558 surf_parse_error("invalid state for link %s", link.id);
561 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
563 switch (A_surfxml_link_sharing___policy) {
564 case A_surfxml_link_sharing___policy_SHARED:
565 link.policy = SURF_LINK_SHARED;
567 case A_surfxml_link_sharing___policy_FATPIPE:
568 link.policy = SURF_LINK_FATPIPE;
570 case A_surfxml_link_sharing___policy_FULLDUPLEX:
571 link.policy = SURF_LINK_FULLDUPLEX;
574 surf_parse_error("Invalid sharing policy in link %s", link.id);
578 sg_platf_new_link(&link);
580 current_property_set = NULL;
583 void STag_surfxml_link___ctn(void){
586 switch (A_surfxml_link___ctn_direction) {
587 case AU_surfxml_link___ctn_direction:
588 case A_surfxml_link___ctn_direction_NONE:
589 link_id = xbt_strdup(A_surfxml_link___ctn_id);
591 case A_surfxml_link___ctn_direction_UP:
592 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
594 case A_surfxml_link___ctn_direction_DOWN:
595 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
599 // FIXME we should push the surf link object but it don't
600 // work because of model rulebased
601 xbt_dynar_push(parsed_link_list, &link_id);
604 void ETag_surfxml_backbone(void){
605 s_sg_platf_link_cbarg_t link;
606 memset(&link,0,sizeof(link));
608 link.properties = NULL;
610 link.id = A_surfxml_backbone_id;
611 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
612 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
613 link.state = SURF_RESOURCE_ON;
614 link.policy = SURF_LINK_SHARED;
616 sg_platf_new_link(&link);
617 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
620 void STag_surfxml_route(void){
621 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
622 "Missing end-points while defining route \"%s\"->\"%s\"",
623 A_surfxml_route_src, A_surfxml_route_dst);
624 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
627 void STag_surfxml_ASroute(void){
628 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
629 || strlen(A_surfxml_ASroute_dst) > 0
630 || strlen(A_surfxml_ASroute_gw___src) > 0
631 || strlen(A_surfxml_ASroute_gw___dst) > 0,
632 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
633 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
634 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
635 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
638 void STag_surfxml_bypassRoute(void){
639 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
640 || strlen(A_surfxml_bypassRoute_dst) > 0,
641 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
642 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
643 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
646 void STag_surfxml_bypassASroute(void){
647 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
648 || strlen(A_surfxml_bypassASroute_dst) > 0
649 || strlen(A_surfxml_bypassASroute_gw___src) > 0
650 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
651 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
652 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
653 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
654 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
657 void ETag_surfxml_route(void){
658 s_sg_platf_route_cbarg_t route;
659 memset(&route,0,sizeof(route));
661 route.src = A_surfxml_route_src;
662 route.dst = A_surfxml_route_dst;
665 route.link_list = parsed_link_list;
667 switch (A_surfxml_route_symmetrical) {
668 case AU_surfxml_route_symmetrical:
669 case A_surfxml_route_symmetrical_YES:
670 route.symmetrical = TRUE;
672 case A_surfxml_route_symmetrical_NO:
673 route.symmetrical = FALSE;;
677 sg_platf_new_route(&route);
678 parsed_link_list = NULL;
681 void ETag_surfxml_ASroute(void){
682 s_sg_platf_route_cbarg_t ASroute;
683 memset(&ASroute,0,sizeof(ASroute));
685 ASroute.src = A_surfxml_ASroute_src;
686 ASroute.dst = A_surfxml_ASroute_dst;
688 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
689 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
691 ASroute.link_list = parsed_link_list;
693 switch (A_surfxml_ASroute_symmetrical) {
694 case AU_surfxml_ASroute_symmetrical:
695 case A_surfxml_ASroute_symmetrical_YES:
696 ASroute.symmetrical = TRUE;
698 case A_surfxml_ASroute_symmetrical_NO:
699 ASroute.symmetrical = FALSE;
703 sg_platf_new_ASroute(&ASroute);
704 parsed_link_list = NULL;
707 void ETag_surfxml_bypassRoute(void){
708 s_sg_platf_route_cbarg_t route;
709 memset(&route,0,sizeof(route));
711 route.src = A_surfxml_bypassRoute_src;
712 route.dst = A_surfxml_bypassRoute_dst;
715 route.link_list = parsed_link_list;
716 route.symmetrical = FALSE;
718 sg_platf_new_bypassRoute(&route);
719 parsed_link_list = NULL;
722 void ETag_surfxml_bypassASroute(void){
723 s_sg_platf_route_cbarg_t ASroute;
724 memset(&ASroute,0,sizeof(ASroute));
726 ASroute.src = A_surfxml_bypassASroute_src;
727 ASroute.dst = A_surfxml_bypassASroute_dst;
728 ASroute.link_list = parsed_link_list;
729 ASroute.symmetrical = FALSE;
731 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
732 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
734 sg_platf_new_bypassASroute(&ASroute);
735 parsed_link_list = NULL;
738 void ETag_surfxml_trace(void){
739 s_sg_platf_trace_cbarg_t trace;
740 memset(&trace,0,sizeof(trace));
742 trace.id = A_surfxml_trace_id;
743 trace.file = A_surfxml_trace_file;
744 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
745 trace.pc_data = surfxml_pcdata;
747 sg_platf_new_trace(&trace);
750 void STag_surfxml_trace___connect(void){
751 s_sg_platf_trace_connect_cbarg_t trace_connect;
752 memset(&trace_connect,0,sizeof(trace_connect));
754 trace_connect.element = A_surfxml_trace___connect_element;
755 trace_connect.trace = A_surfxml_trace___connect_trace;
757 switch (A_surfxml_trace___connect_kind) {
758 case AU_surfxml_trace___connect_kind:
759 case A_surfxml_trace___connect_kind_POWER:
760 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
762 case A_surfxml_trace___connect_kind_BANDWIDTH:
763 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
765 case A_surfxml_trace___connect_kind_HOST___AVAIL:
766 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
768 case A_surfxml_trace___connect_kind_LATENCY:
769 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
771 case A_surfxml_trace___connect_kind_LINK___AVAIL:
772 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
775 sg_platf_trace_connect(&trace_connect);
778 void STag_surfxml_AS(void){
780 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
781 AS.id = A_surfxml_AS_id;
782 AS.routing = (int)A_surfxml_AS_routing;
784 as_current_property_set = NULL;
786 sg_platf_new_AS_begin(&AS);
788 void ETag_surfxml_AS(void){
790 char *name = as_name_tab[as_prop_nb-1];
791 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
793 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
794 xbt_lib_set(as_router_lib,
796 ROUTING_PROP_ASR_LEVEL,
800 sg_platf_new_AS_end();
803 extern int _sg_init_status; /* FIXME: find a proper way to export this at some point */
805 void STag_surfxml_config(void){
807 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
808 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
809 if (_sg_init_status == 2) {
810 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
813 void ETag_surfxml_config(void){
814 xbt_dict_cursor_t cursor = NULL;
818 xbt_dict_foreach(current_property_set, cursor, key, elem) {
819 cfg = bprintf("%s:%s",key,elem);
820 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
821 xbt_cfg_set_parse(_sg_cfg_set, cfg);
823 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
826 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
827 xbt_dict_free(¤t_property_set);
828 current_property_set = NULL;
834 void STag_surfxml_process(void){
837 argv = xbt_new(char *, 1);
838 argv[0] = xbt_strdup(A_surfxml_process_function);
839 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
842 void ETag_surfxml_process(void){
843 s_sg_platf_process_cbarg_t process;
844 memset(&process,0,sizeof(process));
847 process.argv = (const char **)argv;
848 process.properties = current_property_set;
849 process.host = A_surfxml_process_host;
850 process.function = A_surfxml_process_function;
851 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
852 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
854 switch (A_surfxml_process_on___failure) {
855 case AU_surfxml_process_on___failure:
856 case A_surfxml_process_on___failure_DIE:
857 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
859 case A_surfxml_process_on___failure_RESTART:
860 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
864 sg_platf_new_process(&process);
865 current_property_set = NULL;
868 void STag_surfxml_argument(void){
870 argv = xbt_realloc(argv, (argc) * sizeof(char *));
871 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
874 /* ***************************************** */
875 /* TUTORIAL: New TAG */
876 void STag_surfxml_gpu(void)
878 XBT_DEBUG("STag_surfxml_gpu");
880 void ETag_surfxml_gpu(void)
882 s_sg_platf_gpu_cbarg_t gpu;
883 memset(&gpu,0,sizeof(gpu));
885 gpu.name = A_surfxml_gpu_name;
887 sg_platf_new_gpu(&gpu);
889 /* ***************************************** */
891 /* nothing to do in those functions */
892 void ETag_surfxml_prop(void){}
893 void STag_surfxml_random(void){}
894 void ETag_surfxml_random(void){}
895 void ETag_surfxml_trace___connect(void){}
896 void STag_surfxml_trace(void){}
897 void ETag_surfxml_router(void){}
898 void ETag_surfxml_host___link(void){}
899 void ETag_surfxml_cabinet(void){}
900 void ETag_surfxml_peer(void){}
901 void STag_surfxml_backbone(void){}
902 void ETag_surfxml_link___ctn(void){}
903 void ETag_surfxml_argument(void){}
905 /* Open and Close parse file */
907 void surf_parse_open(const char *file)
909 static int warned = 0; /* warn only once */
913 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
914 "If it is not what you want, go fix your code.");
920 if (!surf_input_buffer_stack)
921 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
922 if (!surf_file_to_parse_stack)
923 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
925 if (!surf_parsed_filename_stack)
926 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
927 surf_parsed_filename = xbt_strdup(file);
929 surf_file_to_parse = surf_fopen(file, "r");
930 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
931 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
932 surf_parse__switch_to_buffer(surf_input_buffer);
933 surf_parse_lineno = 1;
936 void surf_parse_close(void)
938 xbt_dynar_free(&surf_input_buffer_stack);
939 xbt_dynar_free(&surf_file_to_parse_stack);
940 xbt_dynar_free(&surf_parsed_filename_stack);
942 free(surf_parsed_filename);
943 surf_parsed_filename = NULL;
945 if (surf_file_to_parse) {
946 surf_parse__delete_buffer(surf_input_buffer);
947 fclose(surf_file_to_parse);
948 surf_file_to_parse = NULL; //Must be reset for Bypass
952 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
954 static int _surf_parse(void) {
955 return surf_parse_lex();
957 int_f_void_t surf_parse = _surf_parse;
960 /* Prop tag functions */
966 /* Random tag functions */
968 double get_cpu_power(const char *power)
970 double power_scale = 0.0;
973 random_data_t random = NULL;
974 /* randomness is inserted like this: power="$rand(my_random)" */
975 if (((p = strstr(power, "$rand(")) != NULL)
976 && ((q = strstr(power, ")")) != NULL)) {
978 generator = xbt_malloc(q - (p + 6) + 1);
979 memcpy(generator, p + 6, q - (p + 6));
980 generator[q - (p + 6)] = '\0';
981 random = xbt_dict_get_or_null(random_data_list, generator);
982 xbt_assert(random, "Random generator %s undefined", generator);
983 power_scale = random_generate(random);
986 power_scale = surf_parse_get_power(power);
991 double random_min, random_max, random_mean, random_std_deviation;
992 e_random_generator_t random_generator;
995 static void init_randomness(void)
997 random_id = A_surfxml_random_id;
998 random_min = surf_parse_get_double(A_surfxml_random_min);
999 random_max = surf_parse_get_double(A_surfxml_random_max);
1000 random_mean = surf_parse_get_double(A_surfxml_random_mean);
1001 random_std_deviation = surf_parse_get_double(A_surfxml_random_std___deviation);
1002 switch (A_surfxml_random_generator) {
1003 case AU_surfxml_random_generator:
1004 case A_surfxml_random_generator_NONE:
1005 random_generator = NONE;
1007 case A_surfxml_random_generator_DRAND48:
1008 random_generator = DRAND48;
1010 case A_surfxml_random_generator_RAND:
1011 random_generator = RAND;
1013 case A_surfxml_random_generator_RNGSTREAM:
1014 random_generator = RNGSTREAM;
1017 surf_parse_error("Invalid random generator");
1022 static void add_randomness(void)
1024 /* If needed aditional properties can be added by using the prop tag */
1025 random_data_t random =
1026 random_new(random_generator, 0, random_min, random_max, random_mean,
1027 random_std_deviation);
1028 xbt_dict_set(random_data_list, random_id, (void *) random,
1033 xbt_dict_t get_as_router_properties(const char* name)
1035 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);