1 /* Copyright (c) 2006-2014. 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 current_model_property_set = NULL;
207 xbt_dict_t as_current_property_set = NULL;
209 char* as_name_tab[1024];
210 void* as_dict_tab[1024];
214 /* dictionary of random generator data */
215 xbt_dict_t random_data_list = NULL;
217 YY_BUFFER_STATE surf_input_buffer;
218 FILE *surf_file_to_parse = NULL;
220 static void init_randomness(void);
221 static void add_randomness(void);
224 * Stuff relative to storage
226 void STag_surfxml_storage(void)
229 XBT_DEBUG("STag_surfxml_storage");
230 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
232 void ETag_surfxml_storage(void)
234 s_sg_platf_storage_cbarg_t storage;
235 memset(&storage,0,sizeof(storage));
237 storage.id = A_surfxml_storage_id;
238 storage.type_id = A_surfxml_storage_typeId;
239 storage.content = A_surfxml_storage_content;
240 storage.content_type = A_surfxml_storage_content___type;
241 storage.properties = current_property_set;
242 storage.attach = A_surfxml_storage_attach;
243 sg_platf_new_storage(&storage);
244 current_property_set = NULL;
246 void STag_surfxml_storage___type(void)
249 XBT_DEBUG("STag_surfxml_storage___type");
250 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
251 xbt_assert(current_model_property_set == NULL, "Someone forgot to reset the model property set to NULL in its closing tag (or XML malformed)");
253 void ETag_surfxml_storage___type(void)
255 s_sg_platf_storage_type_cbarg_t storage_type;
256 memset(&storage_type,0,sizeof(storage_type));
258 storage_type.content = A_surfxml_storage___type_content;
259 storage_type.content_type = A_surfxml_storage___type_content___type;
260 storage_type.id = A_surfxml_storage___type_id;
261 storage_type.model = A_surfxml_storage___type_model;
262 storage_type.properties = current_property_set;
263 storage_type.model_properties = current_model_property_set;
264 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size);
265 sg_platf_new_storage_type(&storage_type);
266 current_property_set = NULL;
267 current_model_property_set = NULL;
269 void STag_surfxml_mstorage(void)
271 XBT_DEBUG("STag_surfxml_mstorage");
273 void ETag_surfxml_mstorage(void)
275 s_sg_platf_mstorage_cbarg_t mstorage;
276 memset(&mstorage,0,sizeof(mstorage));
278 mstorage.name = A_surfxml_mstorage_name;
279 mstorage.type_id = A_surfxml_mstorage_typeId;
280 sg_platf_new_mstorage(&mstorage);
282 void STag_surfxml_mount(void)
284 XBT_DEBUG("STag_surfxml_mount");
286 void ETag_surfxml_mount(void)
288 s_sg_platf_mount_cbarg_t mount;
289 memset(&mount,0,sizeof(mount));
291 mount.name = A_surfxml_mount_name;
292 mount.storageId = A_surfxml_mount_storageId;
293 sg_platf_new_mount(&mount);
297 * Stuff relative to the <include> tag
299 static xbt_dynar_t surf_input_buffer_stack = NULL;
300 static xbt_dynar_t surf_file_to_parse_stack = NULL;
301 static xbt_dynar_t surf_parsed_filename_stack = NULL;
303 void STag_surfxml_include(void)
305 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
306 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
307 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
309 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
311 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
312 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
313 A_surfxml_include_file);
314 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
315 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
316 surf_parse_push_buffer_state(surf_input_buffer);
321 void ETag_surfxml_include(void) {
322 /* Nothing to do when done with reading the include tag.
323 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
326 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
328 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
329 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
330 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
331 * error message in that case.
333 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
334 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
335 * on a line. One day maybe, if the maya allow it.
337 int ETag_surfxml_include_state(void)
340 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
342 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
345 // Yeah, we were in an <include> Restore state and proceed.
346 fclose(surf_file_to_parse);
347 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
348 surf_parse_pop_buffer_state();
349 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
351 // Restore the filename for error messages
352 free(surf_parsed_filename);
353 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
359 void surf_parse_init_callbacks(void)
364 void surf_parse_reset_callbacks(void)
366 surf_parse_free_callbacks();
367 surf_parse_init_callbacks();
370 void surf_parse_free_callbacks(void)
375 /* Stag and Etag parse functions */
377 void STag_surfxml_platform(void) {
378 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
380 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
381 "You're using an ancient XML file.\n"
382 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
383 "instead of MBytes, MFlops and seconds.\n"
385 "Use simgrid_update_xml to update your file automatically. "
386 "This program is installed automatically with SimGrid, or "
387 "available in the tools/ directory of the source archive.\n"
389 "Please check also out the SURF section of the ChangeLog for "
390 "the 3.1 version for more information. \n"
392 "Last, do not forget to also update your values for "
393 "the calls to MSG_task_create (if any).");
394 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
395 "You're using an old XML file.\n"
396 "Use simgrid_update_xml to update your file automatically. "
397 "This program is installed automatically with SimGrid, or "
398 "available in the tools/ directory of the source archive.");
402 void ETag_surfxml_platform(void){
406 void STag_surfxml_host(void){
408 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
411 void STag_surfxml_prop(void)
414 if (!as_current_property_set){
415 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
416 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
417 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
418 as_dict_tab[as_prop_nb] = as_current_property_set;
419 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
422 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
425 if (!current_property_set)
426 current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
427 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
431 void ETag_surfxml_host(void) {
432 s_sg_platf_host_cbarg_t host;
434 memset(&host,0,sizeof(host));
437 host.properties = current_property_set;
439 host.id = A_surfxml_host_id;
441 buf = A_surfxml_host_power;
442 XBT_DEBUG("Buffer: %s", buf);
443 host.power_peak = xbt_dynar_new(sizeof(double), NULL);
444 if (strchr(buf, ',') == NULL){
445 double power_value = get_cpu_power(A_surfxml_host_power);
446 xbt_dynar_push_as(host.power_peak,double, power_value);
449 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
451 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
453 char* power_value_str;
455 xbt_dynar_get_cpy(pstate_list, i, &power_value_str);
456 xbt_str_trim(power_value_str, NULL);
457 power_value = get_cpu_power(power_value_str);
458 xbt_dynar_push_as(host.power_peak, double, power_value);
459 XBT_DEBUG("Power value: %f", power_value);
461 xbt_dynar_free(&pstate_list);
464 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
465 //host.power_peak = get_cpu_power(A_surfxml_host_power);
466 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
467 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
468 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
469 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
470 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
472 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
473 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
474 if (A_surfxml_host_state == A_surfxml_host_state_ON)
475 host.initial_state = SURF_RESOURCE_ON;
476 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
477 host.initial_state = SURF_RESOURCE_OFF;
478 host.coord = A_surfxml_host_coordinates;
480 sg_platf_new_host(&host);
481 current_property_set = NULL;
484 void STag_surfxml_host___link(void){
485 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
486 s_sg_platf_host_link_cbarg_t host_link;
487 memset(&host_link,0,sizeof(host_link));
489 host_link.id = A_surfxml_host___link_id;
490 host_link.link_up = A_surfxml_host___link_up;
491 host_link.link_down = A_surfxml_host___link_down;
492 sg_platf_new_host_link(&host_link);
495 void STag_surfxml_router(void){
496 s_sg_platf_router_cbarg_t router;
497 memset(&router, 0, sizeof(router));
499 router.id = A_surfxml_router_id;
500 router.coord = A_surfxml_router_coordinates;
502 sg_platf_new_router(&router);
505 void ETag_surfxml_cluster(void){
506 s_sg_platf_cluster_cbarg_t cluster;
507 memset(&cluster,0,sizeof(cluster));
508 cluster.properties = current_property_set;
510 cluster.id = A_surfxml_cluster_id;
511 cluster.prefix = A_surfxml_cluster_prefix;
512 cluster.suffix = A_surfxml_cluster_suffix;
513 cluster.radical = A_surfxml_cluster_radical;
514 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
515 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
516 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
517 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
518 if(strcmp(A_surfxml_cluster_bb___bw,""))
519 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
520 if(strcmp(A_surfxml_cluster_bb___lat,""))
521 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
522 if(strcmp(A_surfxml_cluster_limiter___link,""))
523 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
524 if(strcmp(A_surfxml_cluster_loopback___bw,""))
525 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
526 if(strcmp(A_surfxml_cluster_loopback___lat,""))
527 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
529 switch(AX_surfxml_cluster_topology){
530 case A_surfxml_cluster_topology_FLAT:
531 cluster.topology= SURF_CLUSTER_FLAT ;
533 case A_surfxml_cluster_topology_TORUS:
534 cluster.topology= SURF_CLUSTER_TORUS ;
537 surf_parse_error("Invalid cluster topology for cluster %s",
541 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
542 cluster.router_id = A_surfxml_cluster_router___id;
544 switch (AX_surfxml_cluster_sharing___policy) {
545 case A_surfxml_cluster_sharing___policy_SHARED:
546 cluster.sharing_policy = SURF_LINK_SHARED;
548 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
549 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
551 case A_surfxml_cluster_sharing___policy_FATPIPE:
552 cluster.sharing_policy = SURF_LINK_FATPIPE;
555 surf_parse_error("Invalid cluster sharing policy for cluster %s",
559 switch (AX_surfxml_cluster_bb___sharing___policy) {
560 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
561 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
563 case A_surfxml_cluster_bb___sharing___policy_SHARED:
564 cluster.bb_sharing_policy = SURF_LINK_SHARED;
567 surf_parse_error("Invalid bb sharing policy in cluster %s",
572 cluster.availability_trace = A_surfxml_cluster_availability___file;
573 cluster.state_trace = A_surfxml_cluster_state___file;
574 sg_platf_new_cluster(&cluster);
576 current_property_set = NULL;
579 void STag_surfxml_cluster(void){
580 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
583 void STag_surfxml_cabinet(void){
584 s_sg_platf_cabinet_cbarg_t cabinet;
585 memset(&cabinet,0,sizeof(cabinet));
586 cabinet.id = A_surfxml_cabinet_id;
587 cabinet.prefix = A_surfxml_cabinet_prefix;
588 cabinet.suffix = A_surfxml_cabinet_suffix;
589 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
590 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
591 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
592 cabinet.radical = A_surfxml_cabinet_radical;
594 sg_platf_new_cabinet(&cabinet);
597 void STag_surfxml_peer(void){
598 s_sg_platf_peer_cbarg_t peer;
599 memset(&peer,0,sizeof(peer));
600 peer.id = A_surfxml_peer_id;
601 peer.power = surf_parse_get_power(A_surfxml_peer_power);
602 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
603 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
604 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
605 peer.coord = A_surfxml_peer_coordinates;
606 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
607 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
609 sg_platf_new_peer(&peer);
612 void STag_surfxml_link(void){
614 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
617 void ETag_surfxml_link(void){
618 s_sg_platf_link_cbarg_t link;
619 memset(&link,0,sizeof(link));
621 link.properties = current_property_set;
623 link.id = A_surfxml_link_id;
624 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
625 //printf("Link bandwidth [%g]\n", link.bandwidth);
626 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
627 link.latency = surf_parse_get_time(A_surfxml_link_latency);
628 //printf("Link latency [%g]\n", link.latency);
629 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
631 switch (A_surfxml_link_state) {
632 case A_surfxml_link_state_ON:
633 link.state = SURF_RESOURCE_ON;
635 case A_surfxml_link_state_OFF:
636 link.state = SURF_RESOURCE_OFF;
639 surf_parse_error("invalid state for link %s", link.id);
642 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
644 switch (A_surfxml_link_sharing___policy) {
645 case A_surfxml_link_sharing___policy_SHARED:
646 link.policy = SURF_LINK_SHARED;
648 case A_surfxml_link_sharing___policy_FATPIPE:
649 link.policy = SURF_LINK_FATPIPE;
651 case A_surfxml_link_sharing___policy_FULLDUPLEX:
652 link.policy = SURF_LINK_FULLDUPLEX;
655 surf_parse_error("Invalid sharing policy in link %s", link.id);
659 sg_platf_new_link(&link);
661 current_property_set = NULL;
664 void STag_surfxml_link___ctn(void){
667 switch (A_surfxml_link___ctn_direction) {
668 case AU_surfxml_link___ctn_direction:
669 case A_surfxml_link___ctn_direction_NONE:
670 link_id = xbt_strdup(A_surfxml_link___ctn_id);
672 case A_surfxml_link___ctn_direction_UP:
673 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
675 case A_surfxml_link___ctn_direction_DOWN:
676 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
680 // FIXME we should push the surf link object but it don't
681 // work because of model rulebased
682 xbt_dynar_push(parsed_link_list, &link_id);
685 void ETag_surfxml_backbone(void){
686 s_sg_platf_link_cbarg_t link;
687 memset(&link,0,sizeof(link));
689 link.properties = NULL;
691 link.id = A_surfxml_backbone_id;
692 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
693 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
694 link.state = SURF_RESOURCE_ON;
695 link.policy = SURF_LINK_SHARED;
697 sg_platf_new_link(&link);
698 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
701 void STag_surfxml_route(void){
702 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
703 "Missing end-points while defining route \"%s\"->\"%s\"",
704 A_surfxml_route_src, A_surfxml_route_dst);
705 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
708 void STag_surfxml_ASroute(void){
709 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
710 || strlen(A_surfxml_ASroute_dst) > 0
711 || strlen(A_surfxml_ASroute_gw___src) > 0
712 || strlen(A_surfxml_ASroute_gw___dst) > 0,
713 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
714 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
715 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
716 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
719 void STag_surfxml_bypassRoute(void){
720 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
721 || strlen(A_surfxml_bypassRoute_dst) > 0,
722 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
723 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
724 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
727 void STag_surfxml_bypassASroute(void){
728 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
729 || strlen(A_surfxml_bypassASroute_dst) > 0
730 || strlen(A_surfxml_bypassASroute_gw___src) > 0
731 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
732 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
733 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
734 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
735 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
738 void ETag_surfxml_route(void){
739 s_sg_platf_route_cbarg_t route;
740 memset(&route,0,sizeof(route));
742 route.src = A_surfxml_route_src;
743 route.dst = A_surfxml_route_dst;
746 route.link_list = parsed_link_list;
748 switch (A_surfxml_route_symmetrical) {
749 case AU_surfxml_route_symmetrical:
750 case A_surfxml_route_symmetrical_YES:
751 route.symmetrical = TRUE;
753 case A_surfxml_route_symmetrical_NO:
754 route.symmetrical = FALSE;;
758 sg_platf_new_route(&route);
759 parsed_link_list = NULL;
762 void ETag_surfxml_ASroute(void){
763 s_sg_platf_route_cbarg_t ASroute;
764 memset(&ASroute,0,sizeof(ASroute));
766 ASroute.src = A_surfxml_ASroute_src;
767 ASroute.dst = A_surfxml_ASroute_dst;
769 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
770 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
772 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
773 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
774 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
775 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
776 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
777 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
779 ASroute.link_list = parsed_link_list;
781 switch (A_surfxml_ASroute_symmetrical) {
782 case AU_surfxml_ASroute_symmetrical:
783 case A_surfxml_ASroute_symmetrical_YES:
784 ASroute.symmetrical = TRUE;
786 case A_surfxml_ASroute_symmetrical_NO:
787 ASroute.symmetrical = FALSE;
791 sg_platf_new_ASroute(&ASroute);
792 parsed_link_list = NULL;
795 void ETag_surfxml_bypassRoute(void){
796 s_sg_platf_route_cbarg_t route;
797 memset(&route,0,sizeof(route));
799 route.src = A_surfxml_bypassRoute_src;
800 route.dst = A_surfxml_bypassRoute_dst;
803 route.link_list = parsed_link_list;
804 route.symmetrical = FALSE;
806 sg_platf_new_bypassRoute(&route);
807 parsed_link_list = NULL;
810 void ETag_surfxml_bypassASroute(void){
811 s_sg_platf_route_cbarg_t ASroute;
812 memset(&ASroute,0,sizeof(ASroute));
814 ASroute.src = A_surfxml_bypassASroute_src;
815 ASroute.dst = A_surfxml_bypassASroute_dst;
816 ASroute.link_list = parsed_link_list;
817 ASroute.symmetrical = FALSE;
819 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
820 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
822 sg_platf_new_bypassASroute(&ASroute);
823 parsed_link_list = NULL;
826 void ETag_surfxml_trace(void){
827 s_sg_platf_trace_cbarg_t trace;
828 memset(&trace,0,sizeof(trace));
830 trace.id = A_surfxml_trace_id;
831 trace.file = A_surfxml_trace_file;
832 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
833 trace.pc_data = surfxml_pcdata;
835 sg_platf_new_trace(&trace);
838 void STag_surfxml_trace___connect(void){
839 s_sg_platf_trace_connect_cbarg_t trace_connect;
840 memset(&trace_connect,0,sizeof(trace_connect));
842 trace_connect.element = A_surfxml_trace___connect_element;
843 trace_connect.trace = A_surfxml_trace___connect_trace;
845 switch (A_surfxml_trace___connect_kind) {
846 case AU_surfxml_trace___connect_kind:
847 case A_surfxml_trace___connect_kind_POWER:
848 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
850 case A_surfxml_trace___connect_kind_BANDWIDTH:
851 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
853 case A_surfxml_trace___connect_kind_HOST___AVAIL:
854 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
856 case A_surfxml_trace___connect_kind_LATENCY:
857 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
859 case A_surfxml_trace___connect_kind_LINK___AVAIL:
860 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
863 sg_platf_trace_connect(&trace_connect);
866 void STag_surfxml_AS(void){
868 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
869 AS.id = A_surfxml_AS_id;
870 AS.routing = (int)A_surfxml_AS_routing;
872 as_current_property_set = NULL;
874 sg_platf_new_AS_begin(&AS);
876 void ETag_surfxml_AS(void){
878 char *name = as_name_tab[as_prop_nb-1];
879 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
881 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
882 xbt_lib_set(as_router_lib,
884 ROUTING_PROP_ASR_LEVEL,
888 sg_platf_new_AS_end();
891 void STag_surfxml_config(void){
893 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
894 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
895 if (_sg_cfg_init_status == 2) {
896 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
899 void ETag_surfxml_config(void){
900 xbt_dict_cursor_t cursor = NULL;
904 xbt_dict_foreach(current_property_set, cursor, key, elem) {
905 cfg = bprintf("%s:%s",key,elem);
906 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
907 xbt_cfg_set_parse(_sg_cfg_set, cfg);
909 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
912 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
913 xbt_dict_free(¤t_property_set);
914 current_property_set = NULL;
920 void STag_surfxml_process(void){
923 argv = xbt_new(char *, 1);
924 argv[0] = xbt_strdup(A_surfxml_process_function);
925 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
928 void ETag_surfxml_process(void){
929 s_sg_platf_process_cbarg_t process;
930 memset(&process,0,sizeof(process));
933 process.argv = (const char **)argv;
934 process.properties = current_property_set;
935 process.host = A_surfxml_process_host;
936 process.function = A_surfxml_process_function;
937 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
938 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
940 switch (A_surfxml_process_on___failure) {
941 case AU_surfxml_process_on___failure:
942 case A_surfxml_process_on___failure_DIE:
943 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
945 case A_surfxml_process_on___failure_RESTART:
946 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
950 sg_platf_new_process(&process);
951 current_property_set = NULL;
954 void STag_surfxml_argument(void){
956 argv = xbt_realloc(argv, (argc) * sizeof(char *));
957 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
960 void STag_surfxml_model___prop(void){
961 if (!current_model_property_set)
962 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
964 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), NULL);
967 /* ***************************************** */
968 /* TUTORIAL: New TAG */
969 void STag_surfxml_gpu(void)
971 XBT_DEBUG("STag_surfxml_gpu");
973 void ETag_surfxml_gpu(void)
975 s_sg_platf_gpu_cbarg_t gpu;
976 memset(&gpu,0,sizeof(gpu));
978 gpu.name = A_surfxml_gpu_name;
980 sg_platf_new_gpu(&gpu);
982 /* ***************************************** */
984 /* nothing to do in those functions */
985 void ETag_surfxml_prop(void){}
986 void STag_surfxml_random(void){}
987 void ETag_surfxml_random(void){}
988 void ETag_surfxml_trace___connect(void){}
989 void STag_surfxml_trace(void){}
990 void ETag_surfxml_router(void){}
991 void ETag_surfxml_host___link(void){}
992 void ETag_surfxml_cabinet(void){}
993 void ETag_surfxml_peer(void){}
994 void STag_surfxml_backbone(void){}
995 void ETag_surfxml_link___ctn(void){}
996 void ETag_surfxml_argument(void){}
997 void ETag_surfxml_model___prop(void){}
999 /* Open and Close parse file */
1001 void surf_parse_open(const char *file)
1003 static int warned = 0; /* warn only once */
1007 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
1008 "If it is not what you want, go fix your code.");
1014 if (!surf_input_buffer_stack)
1015 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
1016 if (!surf_file_to_parse_stack)
1017 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
1019 if (!surf_parsed_filename_stack)
1020 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1021 surf_parsed_filename = xbt_strdup(file);
1023 surf_file_to_parse = surf_fopen(file, "r");
1024 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1025 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1026 surf_parse__switch_to_buffer(surf_input_buffer);
1027 surf_parse_lineno = 1;
1030 void surf_parse_close(void)
1032 xbt_dynar_free(&surf_input_buffer_stack);
1033 xbt_dynar_free(&surf_file_to_parse_stack);
1034 xbt_dynar_free(&surf_parsed_filename_stack);
1036 free(surf_parsed_filename);
1037 surf_parsed_filename = NULL;
1039 if (surf_file_to_parse) {
1040 surf_parse__delete_buffer(surf_input_buffer);
1041 fclose(surf_file_to_parse);
1042 surf_file_to_parse = NULL; //Must be reset for Bypass
1046 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1048 static int _surf_parse(void) {
1049 return surf_parse_lex();
1051 int_f_void_t surf_parse = _surf_parse;
1054 /* Prop tag functions */
1060 /* Random tag functions */
1062 double get_cpu_power(const char *power)
1064 double power_scale = 0.0;
1067 random_data_t random = NULL;
1068 /* randomness is inserted like this: power="$rand(my_random)" */
1069 if (((p = strstr(power, "$rand(")) != NULL)
1070 && ((q = strstr(power, ")")) != NULL)) {
1072 generator = xbt_malloc(q - (p + 6) + 1);
1073 memcpy(generator, p + 6, q - (p + 6));
1074 generator[q - (p + 6)] = '\0';
1075 random = xbt_dict_get_or_null(random_data_list, generator);
1076 xbt_assert(random, "Random generator %s undefined", generator);
1077 power_scale = random_generate(random);
1080 power_scale = surf_parse_get_power(power);
1085 double random_min, random_max, random_mean, random_std_deviation;
1086 e_random_generator_t random_generator;
1089 static void init_randomness(void)
1091 random_id = A_surfxml_random_id;
1092 random_min = surf_parse_get_double(A_surfxml_random_min);
1093 random_max = surf_parse_get_double(A_surfxml_random_max);
1094 random_mean = surf_parse_get_double(A_surfxml_random_mean);
1095 random_std_deviation = surf_parse_get_double(A_surfxml_random_std___deviation);
1096 switch (A_surfxml_random_generator) {
1097 case AU_surfxml_random_generator:
1098 case A_surfxml_random_generator_NONE:
1099 random_generator = NONE;
1101 case A_surfxml_random_generator_DRAND48:
1102 random_generator = DRAND48;
1104 case A_surfxml_random_generator_RAND:
1105 random_generator = RAND;
1107 case A_surfxml_random_generator_RNGSTREAM:
1108 random_generator = RNGSTREAM;
1111 surf_parse_error("Invalid random generator");
1116 static void add_randomness(void)
1118 /* If needed, additional properties can be added by using the prop tag */
1119 random_data_t random =
1120 random_new(random_generator, 0, random_min, random_max, random_mean,
1121 random_std_deviation);
1122 xbt_dict_set(random_data_list, random_id, (void *) random,
1127 xbt_dict_t get_as_router_properties(const char* name)
1129 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);