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 */
33 void surf_parse_error(const char *fmt, ...) {
36 int lineno = surf_parse_lineno;
37 char *msg = bvprintf(fmt,va);
41 xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
43 void surf_parse_warn(const char *fmt, ...) {
46 char *msg = bvprintf(fmt,va);
48 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
52 double surf_parse_get_double(const char *string) {
54 int ret = sscanf(string, "%lg", &res);
56 surf_parse_error("%s is not a double", string);
57 //printf("Parsed double [%g] %s\n", res, string);
61 int surf_parse_get_int(const char *string) {
63 int ret = sscanf(string, "%d", &res);
65 surf_parse_error("%s is not an integer", string);
74 /* Note: field `unit' for the last element of parametre `units' should be
76 static double surf_parse_get_value_with_unit(const char *string,
77 const struct unit_scale *units)
83 res = strtod(string, &ptr);
85 surf_parse_error("value out of range: %s", string);
87 surf_parse_error("cannot parse number: %s", string);
88 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
90 if (units[i].unit != NULL)
91 res *= units[i].scale;
93 surf_parse_error("unknown unit: %s", ptr);
97 double surf_parse_get_time(const char *string)
99 const struct unit_scale units[] = {
100 { "w", 7 * 24 * 60 * 60 },
101 { "d", 24 * 60 * 60 },
105 { "", 1.0 }, /* default unit is seconds */
112 return surf_parse_get_value_with_unit(string, units);
115 double surf_parse_get_size(const char *string)
117 const struct unit_scale units[] = {
118 { "TiB", pow(1024, 4) },
119 { "GiB", pow(1024, 3) },
120 { "MiB", pow(1024, 2) },
127 { "", 1.0 }, /* default unit is bytes*/
128 { "Tib", 0.125 * pow(1024, 4) },
129 { "Gib", 0.125 * pow(1024, 3) },
130 { "Mib", 0.125 * pow(1024, 2) },
131 { "Kib", 0.125 * 1024 },
132 { "Tb", 0.125 * 1e12 },
133 { "Gb", 0.125 * 1e9 },
134 { "Mb", 0.125 * 1e6 },
135 { "kb", 0.125 * 1e3 },
139 return surf_parse_get_value_with_unit(string, units);
142 double surf_parse_get_bandwidth(const char *string)
144 const struct unit_scale units[] = {
145 { "TiBps", pow(1024, 4) },
146 { "GiBps", pow(1024, 3) },
147 { "MiBps", pow(1024, 2) },
154 { "", 1.0 }, /* default unit is bytes per second */
155 { "Tibps", 0.125 * pow(1024, 4) },
156 { "Gibps", 0.125 * pow(1024, 3) },
157 { "Mibps", 0.125 * pow(1024, 2) },
158 { "Kibps", 0.125 * 1024 },
159 { "Tbps", 0.125 * 1e12 },
160 { "Gbps", 0.125 * 1e9 },
161 { "Mbps", 0.125 * 1e6 },
162 { "kbps", 0.125 * 1e3 },
166 return surf_parse_get_value_with_unit(string, units);
169 double surf_parse_get_power(const char *string)
171 const struct unit_scale units[] = {
172 { "yottaflops", 1e24 },
174 { "zettaflops", 1e21 },
176 { "exaflops", 1e18 },
178 { "petaflops", 1e15 },
180 { "teraflops", 1e12 },
182 { "gigaflops", 1e9 },
184 { "megaflops", 1e6 },
186 { "kiloflops", 1e3 },
190 { "", 1.0 }, /* default unit is flops */
193 return surf_parse_get_value_with_unit(string, units);
197 * All the callback lists that can be overridden anywhere.
198 * (this list should probably be reduced to the bare minimum to allow the models to work)
201 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
203 /* The default current property receiver. Setup in the corresponding opening callbacks. */
204 xbt_dict_t current_property_set = NULL;
205 xbt_dict_t current_model_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;
220 * Stuff relative to storage
222 void STag_surfxml_storage(void)
225 XBT_DEBUG("STag_surfxml_storage");
226 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
228 void ETag_surfxml_storage(void)
230 s_sg_platf_storage_cbarg_t storage;
231 memset(&storage,0,sizeof(storage));
233 storage.id = A_surfxml_storage_id;
234 storage.type_id = A_surfxml_storage_typeId;
235 storage.content = A_surfxml_storage_content;
236 storage.content_type = A_surfxml_storage_content___type;
237 storage.properties = current_property_set;
238 storage.attach = A_surfxml_storage_attach;
239 sg_platf_new_storage(&storage);
240 current_property_set = NULL;
242 void STag_surfxml_storage___type(void)
245 XBT_DEBUG("STag_surfxml_storage___type");
246 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
247 xbt_assert(current_model_property_set == NULL, "Someone forgot to reset the model property set to NULL in its closing tag (or XML malformed)");
249 void ETag_surfxml_storage___type(void)
251 s_sg_platf_storage_type_cbarg_t storage_type;
252 memset(&storage_type,0,sizeof(storage_type));
254 storage_type.content = A_surfxml_storage___type_content;
255 storage_type.content_type = A_surfxml_storage___type_content___type;
256 storage_type.id = A_surfxml_storage___type_id;
257 storage_type.model = A_surfxml_storage___type_model;
258 storage_type.properties = current_property_set;
259 storage_type.model_properties = current_model_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;
263 current_model_property_set = NULL;
265 void STag_surfxml_mstorage(void)
267 XBT_DEBUG("STag_surfxml_mstorage");
269 void ETag_surfxml_mstorage(void)
271 s_sg_platf_mstorage_cbarg_t mstorage;
272 memset(&mstorage,0,sizeof(mstorage));
274 mstorage.name = A_surfxml_mstorage_name;
275 mstorage.type_id = A_surfxml_mstorage_typeId;
276 sg_platf_new_mstorage(&mstorage);
278 void STag_surfxml_mount(void)
280 XBT_DEBUG("STag_surfxml_mount");
282 void ETag_surfxml_mount(void)
284 s_sg_platf_mount_cbarg_t mount;
285 memset(&mount,0,sizeof(mount));
287 mount.name = A_surfxml_mount_name;
288 mount.storageId = A_surfxml_mount_storageId;
289 sg_platf_new_mount(&mount);
293 * Stuff relative to the <include> tag
295 static xbt_dynar_t surf_input_buffer_stack = NULL;
296 static xbt_dynar_t surf_file_to_parse_stack = NULL;
297 static xbt_dynar_t surf_parsed_filename_stack = NULL;
299 void STag_surfxml_include(void)
301 parse_after_config();
302 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
303 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
304 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
306 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
308 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
309 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
310 A_surfxml_include_file);
311 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
312 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
313 surf_parse_push_buffer_state(surf_input_buffer);
318 void ETag_surfxml_include(void) {
319 /* Nothing to do when done with reading the include tag.
320 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
323 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
325 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
326 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
327 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
328 * error message in that case.
330 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
331 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
332 * on a line. One day maybe, if the maya allow it.
334 int ETag_surfxml_include_state(void)
337 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
339 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
342 // Yeah, we were in an <include> Restore state and proceed.
343 fclose(surf_file_to_parse);
344 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
345 surf_parse_pop_buffer_state();
346 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
348 // Restore the filename for error messages
349 free(surf_parsed_filename);
350 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
356 void surf_parse_init_callbacks(void)
361 void surf_parse_reset_callbacks(void)
363 surf_parse_free_callbacks();
364 surf_parse_init_callbacks();
367 void surf_parse_free_callbacks(void)
372 /* Stag and Etag parse functions */
374 void STag_surfxml_platform(void) {
375 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
377 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
378 "You're using an ancient XML file.\n"
379 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
380 "instead of MBytes, MFlops and seconds.\n"
382 "Use simgrid_update_xml to update your file automatically. "
383 "This program is installed automatically with SimGrid, or "
384 "available in the tools/ directory of the source archive.\n"
386 "Please check also out the SURF section of the ChangeLog for "
387 "the 3.1 version for more information. \n"
389 "Last, do not forget to also update your values for "
390 "the calls to MSG_task_create (if any).");
391 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
392 "You're using an old XML file.\n"
393 "Use simgrid_update_xml to update your file automatically. "
394 "This program is installed automatically with SimGrid, or "
395 "available in the tools/ directory of the source archive.");
399 void ETag_surfxml_platform(void){
403 void STag_surfxml_host(void){
405 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
408 void STag_surfxml_prop(void)
411 if (!as_current_property_set){
412 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
413 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
414 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
415 as_dict_tab[as_prop_nb] = as_current_property_set;
416 XBT_DEBUG("PUSH prop %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
419 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
422 if (!current_property_set)
423 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
424 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
428 void ETag_surfxml_host(void) {
429 s_sg_platf_host_cbarg_t host;
431 memset(&host,0,sizeof(host));
434 host.properties = current_property_set;
436 host.id = A_surfxml_host_id;
438 buf = A_surfxml_host_power;
439 XBT_DEBUG("Buffer: %s", buf);
440 host.power_peak = xbt_dynar_new(sizeof(double), NULL);
441 if (strchr(buf, ',') == NULL){
442 double power_value = get_cpu_power(A_surfxml_host_power);
443 xbt_dynar_push_as(host.power_peak,double, power_value);
446 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
448 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
450 char* power_value_str;
452 xbt_dynar_get_cpy(pstate_list, i, &power_value_str);
453 xbt_str_trim(power_value_str, NULL);
454 power_value = get_cpu_power(power_value_str);
455 xbt_dynar_push_as(host.power_peak, double, power_value);
456 XBT_DEBUG("Power value: %f", power_value);
458 xbt_dynar_free(&pstate_list);
461 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
462 //host.power_peak = get_cpu_power(A_surfxml_host_power);
463 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
464 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
465 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
466 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
467 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
469 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
470 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
471 if (A_surfxml_host_state == A_surfxml_host_state_ON)
472 host.initial_state = SURF_RESOURCE_ON;
473 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
474 host.initial_state = SURF_RESOURCE_OFF;
475 host.coord = A_surfxml_host_coordinates;
477 sg_platf_new_host(&host);
478 current_property_set = NULL;
481 void STag_surfxml_host___link(void){
482 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
483 s_sg_platf_host_link_cbarg_t host_link;
484 memset(&host_link,0,sizeof(host_link));
486 host_link.id = A_surfxml_host___link_id;
487 host_link.link_up = A_surfxml_host___link_up;
488 host_link.link_down = A_surfxml_host___link_down;
489 sg_platf_new_host_link(&host_link);
492 void STag_surfxml_router(void){
493 s_sg_platf_router_cbarg_t router;
494 memset(&router, 0, sizeof(router));
496 router.id = A_surfxml_router_id;
497 router.coord = A_surfxml_router_coordinates;
499 sg_platf_new_router(&router);
502 void ETag_surfxml_cluster(void){
503 s_sg_platf_cluster_cbarg_t cluster;
504 memset(&cluster,0,sizeof(cluster));
505 cluster.properties = current_property_set;
507 cluster.id = A_surfxml_cluster_id;
508 cluster.prefix = A_surfxml_cluster_prefix;
509 cluster.suffix = A_surfxml_cluster_suffix;
510 cluster.radical = A_surfxml_cluster_radical;
511 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
512 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
513 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
514 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
515 if(strcmp(A_surfxml_cluster_bb___bw,""))
516 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
517 if(strcmp(A_surfxml_cluster_bb___lat,""))
518 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
519 if(strcmp(A_surfxml_cluster_limiter___link,""))
520 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
521 if(strcmp(A_surfxml_cluster_loopback___bw,""))
522 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
523 if(strcmp(A_surfxml_cluster_loopback___lat,""))
524 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
526 switch(AX_surfxml_cluster_topology){
527 case A_surfxml_cluster_topology_FLAT:
528 cluster.topology= SURF_CLUSTER_FLAT ;
530 case A_surfxml_cluster_topology_TORUS:
531 cluster.topology= SURF_CLUSTER_TORUS ;
533 case A_surfxml_cluster_topology_FAT___TREE:
534 cluster.topology = SURF_CLUSTER_FAT_TREE;
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 parse_after_config();
581 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
584 void STag_surfxml_cabinet(void){
585 parse_after_config();
586 s_sg_platf_cabinet_cbarg_t cabinet;
587 memset(&cabinet,0,sizeof(cabinet));
588 cabinet.id = A_surfxml_cabinet_id;
589 cabinet.prefix = A_surfxml_cabinet_prefix;
590 cabinet.suffix = A_surfxml_cabinet_suffix;
591 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
592 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
593 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
594 cabinet.radical = A_surfxml_cabinet_radical;
596 sg_platf_new_cabinet(&cabinet);
599 void STag_surfxml_peer(void){
600 parse_after_config();
601 s_sg_platf_peer_cbarg_t peer;
602 memset(&peer,0,sizeof(peer));
603 peer.id = A_surfxml_peer_id;
604 peer.power = surf_parse_get_power(A_surfxml_peer_power);
605 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
606 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
607 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
608 peer.coord = A_surfxml_peer_coordinates;
609 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
610 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
612 sg_platf_new_peer(&peer);
615 void STag_surfxml_link(void){
617 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
620 void ETag_surfxml_link(void){
621 s_sg_platf_link_cbarg_t link;
622 memset(&link,0,sizeof(link));
624 link.properties = current_property_set;
626 link.id = A_surfxml_link_id;
627 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
628 //printf("Link bandwidth [%g]\n", link.bandwidth);
629 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
630 link.latency = surf_parse_get_time(A_surfxml_link_latency);
631 //printf("Link latency [%g]\n", link.latency);
632 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
634 switch (A_surfxml_link_state) {
635 case A_surfxml_link_state_ON:
636 link.state = SURF_RESOURCE_ON;
638 case A_surfxml_link_state_OFF:
639 link.state = SURF_RESOURCE_OFF;
642 surf_parse_error("invalid state for link %s", link.id);
645 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
647 switch (A_surfxml_link_sharing___policy) {
648 case A_surfxml_link_sharing___policy_SHARED:
649 link.policy = SURF_LINK_SHARED;
651 case A_surfxml_link_sharing___policy_FATPIPE:
652 link.policy = SURF_LINK_FATPIPE;
654 case A_surfxml_link_sharing___policy_FULLDUPLEX:
655 link.policy = SURF_LINK_FULLDUPLEX;
658 surf_parse_error("Invalid sharing policy in link %s", link.id);
662 sg_platf_new_link(&link);
664 current_property_set = NULL;
667 void STag_surfxml_link___ctn(void){
670 switch (A_surfxml_link___ctn_direction) {
671 case AU_surfxml_link___ctn_direction:
672 case A_surfxml_link___ctn_direction_NONE:
673 link_id = xbt_strdup(A_surfxml_link___ctn_id);
675 case A_surfxml_link___ctn_direction_UP:
676 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
678 case A_surfxml_link___ctn_direction_DOWN:
679 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
683 // FIXME we should push the surf link object but it don't
684 // work because of model rulebased
685 xbt_dynar_push(parsed_link_list, &link_id);
688 void ETag_surfxml_backbone(void){
689 s_sg_platf_link_cbarg_t link;
690 memset(&link,0,sizeof(link));
692 link.properties = NULL;
694 link.id = A_surfxml_backbone_id;
695 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
696 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
697 link.state = SURF_RESOURCE_ON;
698 link.policy = SURF_LINK_SHARED;
700 sg_platf_new_link(&link);
701 routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, A_surfxml_backbone_id, SURF_LINK_LEVEL));
704 void STag_surfxml_route(void){
705 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
706 "Missing end-points while defining route \"%s\"->\"%s\"",
707 A_surfxml_route_src, A_surfxml_route_dst);
708 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
711 void STag_surfxml_ASroute(void){
712 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
713 || strlen(A_surfxml_ASroute_dst) > 0
714 || strlen(A_surfxml_ASroute_gw___src) > 0
715 || strlen(A_surfxml_ASroute_gw___dst) > 0,
716 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
717 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
718 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
719 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
722 void STag_surfxml_bypassRoute(void){
723 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
724 || strlen(A_surfxml_bypassRoute_dst) > 0,
725 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
726 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
727 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
730 void STag_surfxml_bypassASroute(void){
731 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
732 || strlen(A_surfxml_bypassASroute_dst) > 0
733 || strlen(A_surfxml_bypassASroute_gw___src) > 0
734 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
735 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
736 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
737 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
738 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
741 void ETag_surfxml_route(void){
742 s_sg_platf_route_cbarg_t route;
743 memset(&route,0,sizeof(route));
745 route.src = A_surfxml_route_src;
746 route.dst = A_surfxml_route_dst;
749 route.link_list = parsed_link_list;
751 switch (A_surfxml_route_symmetrical) {
752 case AU_surfxml_route_symmetrical:
753 case A_surfxml_route_symmetrical_YES:
754 route.symmetrical = TRUE;
756 case A_surfxml_route_symmetrical_NO:
757 route.symmetrical = FALSE;;
761 sg_platf_new_route(&route);
762 parsed_link_list = NULL;
765 void ETag_surfxml_ASroute(void){
766 s_sg_platf_route_cbarg_t ASroute;
767 memset(&ASroute,0,sizeof(ASroute));
769 ASroute.src = A_surfxml_ASroute_src;
770 ASroute.dst = A_surfxml_ASroute_dst;
772 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
773 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
775 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
776 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
777 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
778 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
779 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
780 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
782 ASroute.link_list = parsed_link_list;
784 switch (A_surfxml_ASroute_symmetrical) {
785 case AU_surfxml_ASroute_symmetrical:
786 case A_surfxml_ASroute_symmetrical_YES:
787 ASroute.symmetrical = TRUE;
789 case A_surfxml_ASroute_symmetrical_NO:
790 ASroute.symmetrical = FALSE;
794 sg_platf_new_ASroute(&ASroute);
795 parsed_link_list = NULL;
798 void ETag_surfxml_bypassRoute(void){
799 s_sg_platf_route_cbarg_t route;
800 memset(&route,0,sizeof(route));
802 route.src = A_surfxml_bypassRoute_src;
803 route.dst = A_surfxml_bypassRoute_dst;
806 route.link_list = parsed_link_list;
807 route.symmetrical = FALSE;
809 sg_platf_new_bypassRoute(&route);
810 parsed_link_list = NULL;
813 void ETag_surfxml_bypassASroute(void){
814 s_sg_platf_route_cbarg_t ASroute;
815 memset(&ASroute,0,sizeof(ASroute));
817 ASroute.src = A_surfxml_bypassASroute_src;
818 ASroute.dst = A_surfxml_bypassASroute_dst;
819 ASroute.link_list = parsed_link_list;
820 ASroute.symmetrical = FALSE;
822 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
823 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
825 sg_platf_new_bypassASroute(&ASroute);
826 parsed_link_list = NULL;
829 void ETag_surfxml_trace(void){
830 s_sg_platf_trace_cbarg_t trace;
831 memset(&trace,0,sizeof(trace));
833 trace.id = A_surfxml_trace_id;
834 trace.file = A_surfxml_trace_file;
835 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
836 trace.pc_data = surfxml_pcdata;
838 sg_platf_new_trace(&trace);
841 void STag_surfxml_trace___connect(void){
842 parse_after_config();
843 s_sg_platf_trace_connect_cbarg_t trace_connect;
844 memset(&trace_connect,0,sizeof(trace_connect));
846 trace_connect.element = A_surfxml_trace___connect_element;
847 trace_connect.trace = A_surfxml_trace___connect_trace;
849 switch (A_surfxml_trace___connect_kind) {
850 case AU_surfxml_trace___connect_kind:
851 case A_surfxml_trace___connect_kind_POWER:
852 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
854 case A_surfxml_trace___connect_kind_BANDWIDTH:
855 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
857 case A_surfxml_trace___connect_kind_HOST___AVAIL:
858 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
860 case A_surfxml_trace___connect_kind_LATENCY:
861 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
863 case A_surfxml_trace___connect_kind_LINK___AVAIL:
864 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
867 sg_platf_trace_connect(&trace_connect);
870 void STag_surfxml_AS(void){
871 parse_after_config();
873 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
874 AS.id = A_surfxml_AS_id;
875 AS.routing = (int)A_surfxml_AS_routing;
877 as_current_property_set = NULL;
879 sg_platf_new_AS_begin(&AS);
881 void ETag_surfxml_AS(void){
883 char *name = as_name_tab[as_prop_nb-1];
884 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
886 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
887 xbt_lib_set(as_router_lib,
889 ROUTING_PROP_ASR_LEVEL,
893 sg_platf_new_AS_end();
896 void STag_surfxml_config(void){
898 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
899 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
900 if (_sg_cfg_init_status == 2) {
901 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
904 void ETag_surfxml_config(void){
905 xbt_dict_cursor_t cursor = NULL;
909 xbt_dict_foreach(current_property_set, cursor, key, elem) {
910 cfg = bprintf("%s:%s",key,elem);
911 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
912 xbt_cfg_set_parse(_sg_cfg_set, cfg);
914 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
917 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
919 xbt_dict_free(¤t_property_set);
920 current_property_set = NULL;
926 void STag_surfxml_process(void){
929 argv = xbt_new(char *, 1);
930 argv[0] = xbt_strdup(A_surfxml_process_function);
931 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
934 void ETag_surfxml_process(void){
935 s_sg_platf_process_cbarg_t process;
936 memset(&process,0,sizeof(process));
939 process.argv = (const char **)argv;
940 process.properties = current_property_set;
941 process.host = A_surfxml_process_host;
942 process.function = A_surfxml_process_function;
943 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
944 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
946 switch (A_surfxml_process_on___failure) {
947 case AU_surfxml_process_on___failure:
948 case A_surfxml_process_on___failure_DIE:
949 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
951 case A_surfxml_process_on___failure_RESTART:
952 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
956 sg_platf_new_process(&process);
957 current_property_set = NULL;
960 void STag_surfxml_argument(void){
962 argv = xbt_realloc(argv, (argc) * sizeof(char *));
963 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
966 void STag_surfxml_model___prop(void){
967 if (!current_model_property_set)
968 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
970 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), NULL);
973 /* ***************************************** */
974 /* TUTORIAL: New TAG */
975 void STag_surfxml_gpu(void)
977 XBT_DEBUG("STag_surfxml_gpu");
979 void ETag_surfxml_gpu(void)
981 s_sg_platf_gpu_cbarg_t gpu;
982 memset(&gpu,0,sizeof(gpu));
984 gpu.name = A_surfxml_gpu_name;
986 sg_platf_new_gpu(&gpu);
988 /* ***************************************** */
990 /* nothing to do in those functions */
991 void ETag_surfxml_prop(void){}
992 void STag_surfxml_random(void){}
993 void ETag_surfxml_random(void){}
994 void ETag_surfxml_trace___connect(void){}
995 void STag_surfxml_trace(void){parse_after_config();}
996 void ETag_surfxml_router(void){}
997 void ETag_surfxml_host___link(void){}
998 void ETag_surfxml_cabinet(void){}
999 void ETag_surfxml_peer(void){}
1000 void STag_surfxml_backbone(void){}
1001 void ETag_surfxml_link___ctn(void){}
1002 void ETag_surfxml_argument(void){}
1003 void ETag_surfxml_model___prop(void){}
1005 /* Open and Close parse file */
1007 void surf_parse_open(const char *file)
1009 static int warned = 0; /* warn only once */
1013 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
1014 "If it is not what you want, go fix your code.");
1020 if (!surf_input_buffer_stack)
1021 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
1022 if (!surf_file_to_parse_stack)
1023 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
1025 if (!surf_parsed_filename_stack)
1026 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1027 surf_parsed_filename = xbt_strdup(file);
1029 surf_file_to_parse = surf_fopen(file, "r");
1030 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1031 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1032 surf_parse__switch_to_buffer(surf_input_buffer);
1033 surf_parse_lineno = 1;
1036 void surf_parse_close(void)
1038 xbt_dynar_free(&surf_input_buffer_stack);
1039 xbt_dynar_free(&surf_file_to_parse_stack);
1040 xbt_dynar_free(&surf_parsed_filename_stack);
1042 free(surf_parsed_filename);
1043 surf_parsed_filename = NULL;
1045 if (surf_file_to_parse) {
1046 surf_parse__delete_buffer(surf_input_buffer);
1047 fclose(surf_file_to_parse);
1048 surf_file_to_parse = NULL; //Must be reset for Bypass
1052 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1054 static int _surf_parse(void) {
1055 return surf_parse_lex();
1057 int_f_void_t surf_parse = _surf_parse;
1060 /* Prop tag functions */
1066 double get_cpu_power(const char *power)
1068 double power_scale = 0.0;
1071 random_data_t random = NULL;
1072 /* randomness is inserted like this: power="$rand(my_random)" */
1073 if (((p = strstr(power, "$rand(")) != NULL)
1074 && ((q = strstr(power, ")")) != NULL)) {
1076 generator = xbt_malloc(q - (p + 6) + 1);
1077 memcpy(generator, p + 6, q - (p + 6));
1078 generator[q - (p + 6)] = '\0';
1079 random = xbt_dict_get_or_null(random_data_list, generator);
1080 xbt_assert(random, "Random generator %s undefined", generator);
1081 power_scale = random_generate(random);
1084 power_scale = surf_parse_get_power(power);
1089 double random_min, random_max, random_mean, random_std_deviation;
1090 e_random_generator_t random_generator;
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);