1 /* Copyright (c) 2006-2013. 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 "surf/random_mgr.h"
18 #include "simgrid/sg_config.h"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
21 "Logging specific to the SURF parsing module");
23 int ETag_surfxml_include_state(void);
25 #include "simgrid_dtd.c"
27 char* surf_parsed_filename = NULL; // to locate parse error messages
29 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
30 extern AS_t current_routing;
34 void surf_parse_error(const char *fmt, ...) {
37 int lineno = surf_parse_lineno;
38 char *msg = bvprintf(fmt,va);
42 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
44 void surf_parse_warn(const char *fmt, ...) {
47 char *msg = bvprintf(fmt,va);
49 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
53 double surf_parse_get_double(const char *string) {
55 int ret = sscanf(string, "%lg", &res);
57 surf_parse_error("%s is not a double", string);
58 //printf("Parsed double [%g] %s\n", res, string);
62 int surf_parse_get_int(const char *string) {
64 int ret = sscanf(string, "%d", &res);
66 surf_parse_error("%s is not an integer", string);
75 /* Note: field `unit' for the last element of parametre `units' should be
77 static double surf_parse_get_value_with_unit(const char *string,
78 const struct unit_scale *units)
84 res = strtod(string, &ptr);
86 surf_parse_error("value out of range: %s", string);
88 surf_parse_error("cannot parse number: %s", string);
89 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
91 if (units[i].unit != NULL)
92 res *= units[i].scale;
94 surf_parse_error("unknown unit: %s", ptr);
98 double surf_parse_get_time(const char *string)
100 const struct unit_scale units[] = {
101 { "w", 7 * 24 * 60 * 60 },
102 { "d", 24 * 60 * 60 },
106 { "", 1.0 }, /* default unit is seconds */
113 return surf_parse_get_value_with_unit(string, units);
116 double surf_parse_get_size(const char *string)
118 const struct unit_scale units[] = {
119 { "TiB", pow(1024, 4) },
120 { "GiB", pow(1024, 3) },
121 { "MiB", pow(1024, 2) },
128 { "", 1.0 }, /* default unit is bytes*/
129 { "Tib", 0.125 * pow(1024, 4) },
130 { "Gib", 0.125 * pow(1024, 3) },
131 { "Mib", 0.125 * pow(1024, 2) },
132 { "Kib", 0.125 * 1024 },
133 { "Tb", 0.125 * 1e12 },
134 { "Gb", 0.125 * 1e9 },
135 { "Mb", 0.125 * 1e6 },
136 { "kb", 0.125 * 1e3 },
140 return surf_parse_get_value_with_unit(string, units);
143 double surf_parse_get_bandwidth(const char *string)
145 const struct unit_scale units[] = {
146 { "TiBps", pow(1024, 4) },
147 { "GiBps", pow(1024, 3) },
148 { "MiBps", pow(1024, 2) },
155 { "", 1.0 }, /* default unit is bytes per second */
156 { "Tibps", 0.125 * pow(1024, 4) },
157 { "Gibps", 0.125 * pow(1024, 3) },
158 { "Mibps", 0.125 * pow(1024, 2) },
159 { "Kibps", 0.125 * 1024 },
160 { "Tbps", 0.125 * 1e12 },
161 { "Gbps", 0.125 * 1e9 },
162 { "Mbps", 0.125 * 1e6 },
163 { "kbps", 0.125 * 1e3 },
167 return surf_parse_get_value_with_unit(string, units);
170 double surf_parse_get_power(const char *string)
172 const struct unit_scale units[] = {
173 { "yottaflops", 1e24 },
175 { "zettaflops", 1e21 },
177 { "exaflops", 1e18 },
179 { "petaflops", 1e15 },
181 { "teraflops", 1e12 },
183 { "gigaflops", 1e9 },
185 { "megaflops", 1e6 },
187 { "kiloflops", 1e3 },
191 { "", 1.0 }, /* default unit is flops */
194 return surf_parse_get_value_with_unit(string, units);
198 * All the callback lists that can be overridden anywhere.
199 * (this list should probably be reduced to the bare minimum to allow the models to work)
202 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
204 /* The default current property receiver. Setup in the corresponding opening callbacks. */
205 xbt_dict_t current_property_set = NULL;
206 xbt_dict_t as_current_property_set = NULL;
208 char* as_name_tab[1024];
209 void* as_dict_tab[1024];
213 /* dictionary of random generator data */
214 xbt_dict_t random_data_list = NULL;
216 YY_BUFFER_STATE surf_input_buffer;
217 FILE *surf_file_to_parse = NULL;
219 static void init_randomness(void);
220 static void add_randomness(void);
223 * Stuff relative to storage
225 void STag_surfxml_storage(void)
228 XBT_DEBUG("STag_surfxml_storage");
229 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
231 void ETag_surfxml_storage(void)
233 s_sg_platf_storage_cbarg_t storage;
234 memset(&storage,0,sizeof(storage));
236 storage.id = A_surfxml_storage_id;
237 storage.type_id = A_surfxml_storage_typeId;
238 storage.content = A_surfxml_storage_content;
239 storage.content_type = A_surfxml_storage_content___type;
240 storage.properties = current_property_set;
241 sg_platf_new_storage(&storage);
242 current_property_set = NULL;
244 void STag_surfxml_storage___type(void)
247 XBT_DEBUG("STag_surfxml_storage___type");
248 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
250 void ETag_surfxml_storage___type(void)
252 s_sg_platf_storage_type_cbarg_t storage_type;
253 memset(&storage_type,0,sizeof(storage_type));
255 storage_type.content = A_surfxml_storage___type_content;
256 storage_type.content_type = A_surfxml_storage___type_content___type;
257 storage_type.id = A_surfxml_storage___type_id;
258 storage_type.model = A_surfxml_storage___type_model;
259 storage_type.properties = current_property_set;
260 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size);
261 sg_platf_new_storage_type(&storage_type);
262 current_property_set = NULL;
264 void STag_surfxml_mstorage(void)
266 XBT_DEBUG("STag_surfxml_mstorage");
268 void ETag_surfxml_mstorage(void)
270 s_sg_platf_mstorage_cbarg_t mstorage;
271 memset(&mstorage,0,sizeof(mstorage));
273 mstorage.name = A_surfxml_mstorage_name;
274 mstorage.type_id = A_surfxml_mstorage_typeId;
275 sg_platf_new_mstorage(&mstorage);
277 void STag_surfxml_mount(void)
279 XBT_DEBUG("STag_surfxml_mount");
281 void ETag_surfxml_mount(void)
283 s_sg_platf_mount_cbarg_t mount;
284 memset(&mount,0,sizeof(mount));
286 mount.name = A_surfxml_mount_name;
287 mount.storageId = A_surfxml_mount_storageId;
288 sg_platf_new_mount(&mount);
292 * Stuff relative to the <include> tag
294 static xbt_dynar_t surf_input_buffer_stack = NULL;
295 static xbt_dynar_t surf_file_to_parse_stack = NULL;
296 static xbt_dynar_t surf_parsed_filename_stack = NULL;
298 void STag_surfxml_include(void)
300 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
301 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
302 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
304 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
306 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
307 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
308 A_surfxml_include_file);
309 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
310 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
311 surf_parse_push_buffer_state(surf_input_buffer);
316 void ETag_surfxml_include(void) {
317 /* Nothing to do when done with reading the include tag.
318 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
321 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
323 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
324 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
325 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
326 * error message in that case.
328 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
329 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
330 * on a line. One day maybe, if the maya allow it.
332 int ETag_surfxml_include_state(void)
335 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
337 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
340 // Yeah, we were in an <include> Restore state and proceed.
341 fclose(surf_file_to_parse);
342 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
343 surf_parse_pop_buffer_state();
344 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
346 // Restore the filename for error messages
347 free(surf_parsed_filename);
348 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
354 void surf_parse_init_callbacks(void)
359 void surf_parse_reset_callbacks(void)
361 surf_parse_free_callbacks();
362 surf_parse_init_callbacks();
365 void surf_parse_free_callbacks(void)
370 /* Stag and Etag parse functions */
372 void STag_surfxml_platform(void) {
373 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
375 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
376 "You're using an ancient XML file.\n"
377 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
378 "instead of MBytes, MFlops and seconds.\n"
380 "Use simgrid_update_xml to update your file automatically. "
381 "This program is installed automatically with SimGrid, or "
382 "available in the tools/ directory of the source archive.\n"
384 "Please check also out the SURF section of the ChangeLog for "
385 "the 3.1 version for more information. \n"
387 "Last, do not forget to also update your values for "
388 "the calls to MSG_task_create (if any).");
389 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
390 "You're using an old XML file.\n"
391 "Use simgrid_update_xml to update your file automatically. "
392 "This program is installed automatically with SimGrid, or "
393 "available in the tools/ directory of the source archive.");
397 void ETag_surfxml_platform(void){
401 void STag_surfxml_host(void){
403 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
406 void STag_surfxml_prop(void)
409 if (!as_current_property_set){
410 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
411 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
412 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
413 as_dict_tab[as_prop_nb] = as_current_property_set;
414 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
417 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
420 if (!current_property_set)
421 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
422 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
426 void ETag_surfxml_host(void) {
427 s_sg_platf_host_cbarg_t host;
429 memset(&host,0,sizeof(host));
432 host.properties = current_property_set;
434 host.id = A_surfxml_host_id;
436 buf = A_surfxml_host_power;
437 XBT_DEBUG("Buffer: %s", buf);
438 host.power_peak = xbt_dynar_new(sizeof(double), NULL);
439 if (strchr(buf, ',') == NULL){
440 double power_value = get_cpu_power(A_surfxml_host_power);
441 xbt_dynar_push_as(host.power_peak,double, power_value);
444 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
446 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
448 char* power_value_str;
450 xbt_dynar_get_cpy(pstate_list, i, &power_value_str);
451 xbt_str_trim(power_value_str, NULL);
452 power_value = get_cpu_power(power_value_str);
453 xbt_dynar_push_as(host.power_peak, double, power_value);
454 XBT_DEBUG("Power value: %f", power_value);
456 xbt_dynar_free(&pstate_list);
459 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
460 //host.power_peak = get_cpu_power(A_surfxml_host_power);
461 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
462 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
463 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
464 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
465 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
467 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
468 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
469 if (A_surfxml_host_state == A_surfxml_host_state_ON)
470 host.initial_state = SURF_RESOURCE_ON;
471 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
472 host.initial_state = SURF_RESOURCE_OFF;
473 host.coord = A_surfxml_host_coordinates;
475 sg_platf_new_host(&host);
476 current_property_set = NULL;
479 void STag_surfxml_host___link(void){
480 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
481 s_sg_platf_host_link_cbarg_t host_link;
482 memset(&host_link,0,sizeof(host_link));
484 host_link.id = A_surfxml_host___link_id;
485 host_link.link_up = A_surfxml_host___link_up;
486 host_link.link_down = A_surfxml_host___link_down;
487 sg_platf_new_host_link(&host_link);
490 void STag_surfxml_router(void){
491 s_sg_platf_router_cbarg_t router;
492 memset(&router, 0, sizeof(router));
494 router.id = A_surfxml_router_id;
495 router.coord = A_surfxml_router_coordinates;
497 sg_platf_new_router(&router);
500 void ETag_surfxml_cluster(void){
501 s_sg_platf_cluster_cbarg_t cluster;
502 memset(&cluster,0,sizeof(cluster));
503 cluster.properties = current_property_set;
505 cluster.id = A_surfxml_cluster_id;
506 cluster.prefix = A_surfxml_cluster_prefix;
507 cluster.suffix = A_surfxml_cluster_suffix;
508 cluster.radical = A_surfxml_cluster_radical;
509 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
510 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
511 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
512 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
513 if(strcmp(A_surfxml_cluster_bb___bw,""))
514 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
515 if(strcmp(A_surfxml_cluster_bb___lat,""))
516 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
517 if(strcmp(A_surfxml_cluster_limiter___link,""))
518 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
519 if(strcmp(A_surfxml_cluster_loopback___bw,""))
520 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
521 if(strcmp(A_surfxml_cluster_loopback___lat,""))
522 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
523 cluster.router_id = A_surfxml_cluster_router___id;
525 switch (AX_surfxml_cluster_sharing___policy) {
526 case A_surfxml_cluster_sharing___policy_SHARED:
527 cluster.sharing_policy = SURF_LINK_SHARED;
529 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
530 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
532 case A_surfxml_cluster_sharing___policy_FATPIPE:
533 cluster.sharing_policy = SURF_LINK_FATPIPE;
536 surf_parse_error("Invalid cluster sharing policy for cluster %s",
540 switch (AX_surfxml_cluster_bb___sharing___policy) {
541 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
542 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
544 case A_surfxml_cluster_bb___sharing___policy_SHARED:
545 cluster.bb_sharing_policy = SURF_LINK_SHARED;
548 surf_parse_error("Invalid bb sharing policy in cluster %s",
553 cluster.availability_trace = A_surfxml_cluster_availability___file;
554 cluster.state_trace = A_surfxml_cluster_state___file;
555 sg_platf_new_cluster(&cluster);
557 current_property_set = NULL;
560 void STag_surfxml_cluster(void){
561 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
564 void STag_surfxml_cabinet(void){
565 s_sg_platf_cabinet_cbarg_t cabinet;
566 memset(&cabinet,0,sizeof(cabinet));
567 cabinet.id = A_surfxml_cabinet_id;
568 cabinet.prefix = A_surfxml_cabinet_prefix;
569 cabinet.suffix = A_surfxml_cabinet_suffix;
570 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
571 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
572 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
573 cabinet.radical = A_surfxml_cabinet_radical;
575 sg_platf_new_cabinet(&cabinet);
578 void STag_surfxml_peer(void){
579 s_sg_platf_peer_cbarg_t peer;
580 memset(&peer,0,sizeof(peer));
581 peer.id = A_surfxml_peer_id;
582 peer.power = surf_parse_get_power(A_surfxml_peer_power);
583 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
584 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
585 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
586 peer.coord = A_surfxml_peer_coordinates;
587 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
588 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
590 sg_platf_new_peer(&peer);
593 void STag_surfxml_link(void){
595 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
598 void ETag_surfxml_link(void){
599 s_sg_platf_link_cbarg_t link;
600 memset(&link,0,sizeof(link));
602 link.properties = current_property_set;
604 link.id = A_surfxml_link_id;
605 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
606 //printf("Link bandwidth [%g]\n", link.bandwidth);
607 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
608 link.latency = surf_parse_get_time(A_surfxml_link_latency);
609 //printf("Link latency [%g]\n", link.latency);
610 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
612 switch (A_surfxml_link_state) {
613 case A_surfxml_link_state_ON:
614 link.state = SURF_RESOURCE_ON;
616 case A_surfxml_link_state_OFF:
617 link.state = SURF_RESOURCE_OFF;
620 surf_parse_error("invalid state for link %s", link.id);
623 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
625 switch (A_surfxml_link_sharing___policy) {
626 case A_surfxml_link_sharing___policy_SHARED:
627 link.policy = SURF_LINK_SHARED;
629 case A_surfxml_link_sharing___policy_FATPIPE:
630 link.policy = SURF_LINK_FATPIPE;
632 case A_surfxml_link_sharing___policy_FULLDUPLEX:
633 link.policy = SURF_LINK_FULLDUPLEX;
636 surf_parse_error("Invalid sharing policy in link %s", link.id);
640 sg_platf_new_link(&link);
642 current_property_set = NULL;
645 void STag_surfxml_link___ctn(void){
648 switch (A_surfxml_link___ctn_direction) {
649 case AU_surfxml_link___ctn_direction:
650 case A_surfxml_link___ctn_direction_NONE:
651 link_id = xbt_strdup(A_surfxml_link___ctn_id);
653 case A_surfxml_link___ctn_direction_UP:
654 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
656 case A_surfxml_link___ctn_direction_DOWN:
657 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
661 // FIXME we should push the surf link object but it don't
662 // work because of model rulebased
663 xbt_dynar_push(parsed_link_list, &link_id);
666 void ETag_surfxml_backbone(void){
667 s_sg_platf_link_cbarg_t link;
668 memset(&link,0,sizeof(link));
670 link.properties = NULL;
672 link.id = A_surfxml_backbone_id;
673 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
674 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
675 link.state = SURF_RESOURCE_ON;
676 link.policy = SURF_LINK_SHARED;
678 sg_platf_new_link(&link);
679 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
682 void STag_surfxml_route(void){
683 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
684 "Missing end-points while defining route \"%s\"->\"%s\"",
685 A_surfxml_route_src, A_surfxml_route_dst);
686 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
689 void STag_surfxml_ASroute(void){
690 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
691 || strlen(A_surfxml_ASroute_dst) > 0
692 || strlen(A_surfxml_ASroute_gw___src) > 0
693 || strlen(A_surfxml_ASroute_gw___dst) > 0,
694 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
695 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
696 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
697 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
700 void STag_surfxml_bypassRoute(void){
701 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
702 || strlen(A_surfxml_bypassRoute_dst) > 0,
703 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
704 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
705 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
708 void STag_surfxml_bypassASroute(void){
709 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
710 || strlen(A_surfxml_bypassASroute_dst) > 0
711 || strlen(A_surfxml_bypassASroute_gw___src) > 0
712 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
713 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
714 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
715 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
716 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
719 void ETag_surfxml_route(void){
720 s_sg_platf_route_cbarg_t route;
721 memset(&route,0,sizeof(route));
723 route.src = A_surfxml_route_src;
724 route.dst = A_surfxml_route_dst;
727 route.link_list = parsed_link_list;
729 switch (A_surfxml_route_symmetrical) {
730 case AU_surfxml_route_symmetrical:
731 case A_surfxml_route_symmetrical_YES:
732 route.symmetrical = TRUE;
734 case A_surfxml_route_symmetrical_NO:
735 route.symmetrical = FALSE;;
739 sg_platf_new_route(&route);
740 parsed_link_list = NULL;
743 void ETag_surfxml_ASroute(void){
744 s_sg_platf_route_cbarg_t ASroute;
745 memset(&ASroute,0,sizeof(ASroute));
747 ASroute.src = A_surfxml_ASroute_src;
748 ASroute.dst = A_surfxml_ASroute_dst;
750 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
751 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
753 ASroute.link_list = parsed_link_list;
755 switch (A_surfxml_ASroute_symmetrical) {
756 case AU_surfxml_ASroute_symmetrical:
757 case A_surfxml_ASroute_symmetrical_YES:
758 ASroute.symmetrical = TRUE;
760 case A_surfxml_ASroute_symmetrical_NO:
761 ASroute.symmetrical = FALSE;
765 sg_platf_new_ASroute(&ASroute);
766 parsed_link_list = NULL;
769 void ETag_surfxml_bypassRoute(void){
770 s_sg_platf_route_cbarg_t route;
771 memset(&route,0,sizeof(route));
773 route.src = A_surfxml_bypassRoute_src;
774 route.dst = A_surfxml_bypassRoute_dst;
777 route.link_list = parsed_link_list;
778 route.symmetrical = FALSE;
780 sg_platf_new_bypassRoute(&route);
781 parsed_link_list = NULL;
784 void ETag_surfxml_bypassASroute(void){
785 s_sg_platf_route_cbarg_t ASroute;
786 memset(&ASroute,0,sizeof(ASroute));
788 ASroute.src = A_surfxml_bypassASroute_src;
789 ASroute.dst = A_surfxml_bypassASroute_dst;
790 ASroute.link_list = parsed_link_list;
791 ASroute.symmetrical = FALSE;
793 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
794 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
796 sg_platf_new_bypassASroute(&ASroute);
797 parsed_link_list = NULL;
800 void ETag_surfxml_trace(void){
801 s_sg_platf_trace_cbarg_t trace;
802 memset(&trace,0,sizeof(trace));
804 trace.id = A_surfxml_trace_id;
805 trace.file = A_surfxml_trace_file;
806 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
807 trace.pc_data = surfxml_pcdata;
809 sg_platf_new_trace(&trace);
812 void STag_surfxml_trace___connect(void){
813 s_sg_platf_trace_connect_cbarg_t trace_connect;
814 memset(&trace_connect,0,sizeof(trace_connect));
816 trace_connect.element = A_surfxml_trace___connect_element;
817 trace_connect.trace = A_surfxml_trace___connect_trace;
819 switch (A_surfxml_trace___connect_kind) {
820 case AU_surfxml_trace___connect_kind:
821 case A_surfxml_trace___connect_kind_POWER:
822 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
824 case A_surfxml_trace___connect_kind_BANDWIDTH:
825 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
827 case A_surfxml_trace___connect_kind_HOST___AVAIL:
828 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
830 case A_surfxml_trace___connect_kind_LATENCY:
831 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
833 case A_surfxml_trace___connect_kind_LINK___AVAIL:
834 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
837 sg_platf_trace_connect(&trace_connect);
840 void STag_surfxml_AS(void){
842 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
843 AS.id = A_surfxml_AS_id;
844 AS.routing = (int)A_surfxml_AS_routing;
846 as_current_property_set = NULL;
848 sg_platf_new_AS_begin(&AS);
850 void ETag_surfxml_AS(void){
852 char *name = as_name_tab[as_prop_nb-1];
853 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
855 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
856 xbt_lib_set(as_router_lib,
858 ROUTING_PROP_ASR_LEVEL,
862 sg_platf_new_AS_end();
865 void STag_surfxml_config(void){
867 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
868 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
869 if (_sg_cfg_init_status == 2) {
870 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
873 void ETag_surfxml_config(void){
874 xbt_dict_cursor_t cursor = NULL;
878 xbt_dict_foreach(current_property_set, cursor, key, elem) {
879 cfg = bprintf("%s:%s",key,elem);
880 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
881 xbt_cfg_set_parse(_sg_cfg_set, cfg);
883 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
886 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
887 xbt_dict_free(¤t_property_set);
888 current_property_set = NULL;
894 void STag_surfxml_process(void){
897 argv = xbt_new(char *, 1);
898 argv[0] = xbt_strdup(A_surfxml_process_function);
899 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
902 void ETag_surfxml_process(void){
903 s_sg_platf_process_cbarg_t process;
904 memset(&process,0,sizeof(process));
907 process.argv = (const char **)argv;
908 process.properties = current_property_set;
909 process.host = A_surfxml_process_host;
910 process.function = A_surfxml_process_function;
911 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
912 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
914 switch (A_surfxml_process_on___failure) {
915 case AU_surfxml_process_on___failure:
916 case A_surfxml_process_on___failure_DIE:
917 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
919 case A_surfxml_process_on___failure_RESTART:
920 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
924 sg_platf_new_process(&process);
925 current_property_set = NULL;
928 void STag_surfxml_argument(void){
930 argv = xbt_realloc(argv, (argc) * sizeof(char *));
931 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
934 /* ***************************************** */
935 /* TUTORIAL: New TAG */
936 void STag_surfxml_gpu(void)
938 XBT_DEBUG("STag_surfxml_gpu");
940 void ETag_surfxml_gpu(void)
942 s_sg_platf_gpu_cbarg_t gpu;
943 memset(&gpu,0,sizeof(gpu));
945 gpu.name = A_surfxml_gpu_name;
947 sg_platf_new_gpu(&gpu);
949 /* ***************************************** */
951 /* nothing to do in those functions */
952 void ETag_surfxml_prop(void){}
953 void STag_surfxml_random(void){}
954 void ETag_surfxml_random(void){}
955 void ETag_surfxml_trace___connect(void){}
956 void STag_surfxml_trace(void){}
957 void ETag_surfxml_router(void){}
958 void ETag_surfxml_host___link(void){}
959 void ETag_surfxml_cabinet(void){}
960 void ETag_surfxml_peer(void){}
961 void STag_surfxml_backbone(void){}
962 void ETag_surfxml_link___ctn(void){}
963 void ETag_surfxml_argument(void){}
965 /* Open and Close parse file */
967 void surf_parse_open(const char *file)
969 static int warned = 0; /* warn only once */
973 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
974 "If it is not what you want, go fix your code.");
980 if (!surf_input_buffer_stack)
981 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
982 if (!surf_file_to_parse_stack)
983 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
985 if (!surf_parsed_filename_stack)
986 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
987 surf_parsed_filename = xbt_strdup(file);
989 surf_file_to_parse = surf_fopen(file, "r");
990 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
991 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
992 surf_parse__switch_to_buffer(surf_input_buffer);
993 surf_parse_lineno = 1;
996 void surf_parse_close(void)
998 xbt_dynar_free(&surf_input_buffer_stack);
999 xbt_dynar_free(&surf_file_to_parse_stack);
1000 xbt_dynar_free(&surf_parsed_filename_stack);
1002 free(surf_parsed_filename);
1003 surf_parsed_filename = NULL;
1005 if (surf_file_to_parse) {
1006 surf_parse__delete_buffer(surf_input_buffer);
1007 fclose(surf_file_to_parse);
1008 surf_file_to_parse = NULL; //Must be reset for Bypass
1012 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1014 static int _surf_parse(void) {
1015 return surf_parse_lex();
1017 int_f_void_t surf_parse = _surf_parse;
1020 /* Prop tag functions */
1026 /* Random tag functions */
1028 double get_cpu_power(const char *power)
1030 double power_scale = 0.0;
1033 random_data_t random = NULL;
1034 /* randomness is inserted like this: power="$rand(my_random)" */
1035 if (((p = strstr(power, "$rand(")) != NULL)
1036 && ((q = strstr(power, ")")) != NULL)) {
1038 generator = xbt_malloc(q - (p + 6) + 1);
1039 memcpy(generator, p + 6, q - (p + 6));
1040 generator[q - (p + 6)] = '\0';
1041 random = xbt_dict_get_or_null(random_data_list, generator);
1042 xbt_assert(random, "Random generator %s undefined", generator);
1043 power_scale = random_generate(random);
1046 power_scale = surf_parse_get_power(power);
1051 double random_min, random_max, random_mean, random_std_deviation;
1052 e_random_generator_t random_generator;
1055 static void init_randomness(void)
1057 random_id = A_surfxml_random_id;
1058 random_min = surf_parse_get_double(A_surfxml_random_min);
1059 random_max = surf_parse_get_double(A_surfxml_random_max);
1060 random_mean = surf_parse_get_double(A_surfxml_random_mean);
1061 random_std_deviation = surf_parse_get_double(A_surfxml_random_std___deviation);
1062 switch (A_surfxml_random_generator) {
1063 case AU_surfxml_random_generator:
1064 case A_surfxml_random_generator_NONE:
1065 random_generator = NONE;
1067 case A_surfxml_random_generator_DRAND48:
1068 random_generator = DRAND48;
1070 case A_surfxml_random_generator_RAND:
1071 random_generator = RAND;
1073 case A_surfxml_random_generator_RNGSTREAM:
1074 random_generator = RNGSTREAM;
1077 surf_parse_error("Invalid random generator");
1082 static void add_randomness(void)
1084 /* If needed, additional properties can be added by using the prop tag */
1085 random_data_t random =
1086 random_new(random_generator, 0, random_min, random_max, random_mean,
1087 random_std_deviation);
1088 xbt_dict_set(random_data_list, random_id, (void *) random,
1093 xbt_dict_t get_as_router_properties(const char* name)
1095 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);