1 /* Copyright (c) 2006-2015. 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 */
18 #include "surf/surfxml_parse.h"
19 #include "surf/surf_private.h"
20 #include "surf/random_mgr.h"
21 #include "simgrid/sg_config.h"
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
24 "Logging specific to the SURF parsing module");
26 int ETag_surfxml_include_state(void);
28 #include "simgrid_dtd.c"
30 char* surf_parsed_filename = NULL; // to locate parse error messages
32 xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */
36 void surf_parse_error(const char *fmt, ...) {
39 int lineno = surf_parse_lineno;
40 char *msg = bvprintf(fmt,va);
43 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
45 xbt_die("Exiting now");
47 void surf_parse_warn(const char *fmt, ...) {
50 char *msg = bvprintf(fmt,va);
52 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
56 double surf_parse_get_double(const char *string) {
58 int ret = sscanf(string, "%lg", &res);
60 surf_parse_error("%s is not a double", string);
61 //printf("Parsed double [%g] %s\n", res, string);
65 int surf_parse_get_int(const char *string) {
67 int ret = sscanf(string, "%d", &res);
69 surf_parse_error("%s is not an integer", string);
78 /* Note: field `unit' for the last element of parametre `units' should be
80 static double surf_parse_get_value_with_unit(const char *string,
81 const struct unit_scale *units)
87 res = strtod(string, &ptr);
89 surf_parse_error("value out of range: %s", string);
91 surf_parse_error("cannot parse number: %s", string);
92 for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) {
94 if (units[i].unit != NULL)
95 res *= units[i].scale;
97 surf_parse_error("unknown unit: %s", ptr);
101 double surf_parse_get_time(const char *string)
103 const struct unit_scale units[] = {
104 { "w", 7 * 24 * 60 * 60 },
105 { "d", 24 * 60 * 60 },
109 { "", 1.0 }, /* default unit is seconds */
116 return surf_parse_get_value_with_unit(string, units);
119 double surf_parse_get_size(const char *string)
121 const struct unit_scale units[] = {
122 { "TiB", pow(1024, 4) },
123 { "GiB", pow(1024, 3) },
124 { "MiB", pow(1024, 2) },
131 { "", 1.0 }, /* default unit is bytes*/
132 { "Tib", 0.125 * pow(1024, 4) },
133 { "Gib", 0.125 * pow(1024, 3) },
134 { "Mib", 0.125 * pow(1024, 2) },
135 { "Kib", 0.125 * 1024 },
136 { "Tb", 0.125 * 1e12 },
137 { "Gb", 0.125 * 1e9 },
138 { "Mb", 0.125 * 1e6 },
139 { "kb", 0.125 * 1e3 },
143 return surf_parse_get_value_with_unit(string, units);
146 double surf_parse_get_bandwidth(const char *string)
148 const struct unit_scale units[] = {
149 { "TiBps", pow(1024, 4) },
150 { "GiBps", pow(1024, 3) },
151 { "MiBps", pow(1024, 2) },
158 { "", 1.0 }, /* default unit is bytes per second */
159 { "Tibps", 0.125 * pow(1024, 4) },
160 { "Gibps", 0.125 * pow(1024, 3) },
161 { "Mibps", 0.125 * pow(1024, 2) },
162 { "Kibps", 0.125 * 1024 },
163 { "Tbps", 0.125 * 1e12 },
164 { "Gbps", 0.125 * 1e9 },
165 { "Mbps", 0.125 * 1e6 },
166 { "kbps", 0.125 * 1e3 },
170 return surf_parse_get_value_with_unit(string, units);
173 double surf_parse_get_power(const char *string)
175 const struct unit_scale units[] = {
176 { "yottaflops", 1e24 },
178 { "zettaflops", 1e21 },
180 { "exaflops", 1e18 },
182 { "petaflops", 1e15 },
184 { "teraflops", 1e12 },
186 { "gigaflops", 1e9 },
188 { "megaflops", 1e6 },
190 { "kiloflops", 1e3 },
194 { "", 1.0 }, /* default unit is flops */
197 return surf_parse_get_value_with_unit(string, units);
201 * All the callback lists that can be overridden anywhere.
202 * (this list should probably be reduced to the bare minimum to allow the models to work)
205 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
207 /* The default current property receiver. Setup in the corresponding opening callbacks. */
208 xbt_dict_t current_property_set = NULL;
209 xbt_dict_t current_model_property_set = NULL;
210 xbt_dict_t as_current_property_set = NULL;
212 char* as_name_tab[1024];
213 void* as_dict_tab[1024];
217 /* dictionary of random generator data */
218 xbt_dict_t random_data_list = NULL;
220 YY_BUFFER_STATE surf_input_buffer;
221 FILE *surf_file_to_parse = NULL;
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 = SG_PLATF_STORAGE_INITIALIZER;
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 = SG_PLATF_STORAGE_TYPE_INITIALIZER;
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 = SG_PLATF_MSTORAGE_INITIALIZER;
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 = SG_PLATF_MOUNT_INITIALIZER;
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 parse_after_config();
306 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
307 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
308 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
310 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
312 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
313 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
314 A_surfxml_include_file);
315 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
316 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
317 surf_parse_push_buffer_state(surf_input_buffer);
322 void ETag_surfxml_include(void) {
323 /* Nothing to do when done with reading the include tag.
324 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
327 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
329 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
330 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
331 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
332 * error message in that case.
334 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
335 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
336 * on a line. One day maybe, if the maya allow it.
338 int ETag_surfxml_include_state(void)
341 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
343 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
346 // Yeah, we were in an <include> Restore state and proceed.
347 fclose(surf_file_to_parse);
348 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
349 surf_parse_pop_buffer_state();
350 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
352 // Restore the filename for error messages
353 free(surf_parsed_filename);
354 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
360 void surf_parse_init_callbacks(void)
365 void surf_parse_reset_callbacks(void)
367 surf_parse_free_callbacks();
368 surf_parse_init_callbacks();
371 void surf_parse_free_callbacks(void)
376 /* Stag and Etag parse functions */
378 void STag_surfxml_platform(void) {
379 _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
381 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
382 "You're using an ancient XML file.\n"
383 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
384 "instead of MBytes, MFlops and seconds.\n"
386 "Use simgrid_update_xml to update your file automatically. "
387 "This program is installed automatically with SimGrid, or "
388 "available in the tools/ directory of the source archive.\n"
390 "Please check also out the SURF section of the ChangeLog for "
391 "the 3.1 version for more information. \n"
393 "Last, do not forget to also update your values for "
394 "the calls to MSG_task_create (if any).");
395 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
396 "You're using an old XML file.\n"
397 "Use simgrid_update_xml to update your file automatically. "
398 "This program is installed automatically with SimGrid, or "
399 "available in the tools/ directory of the source archive.");
403 void ETag_surfxml_platform(void){
407 void STag_surfxml_host(void){
409 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
412 void STag_surfxml_prop(void)
415 if (!as_current_property_set){
416 xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
417 as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
418 as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
419 as_dict_tab[as_prop_nb] = as_current_property_set;
420 XBT_DEBUG("PUSH prop set %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
423 XBT_DEBUG("add prop %s=%s into current AS property set", A_surfxml_prop_id, A_surfxml_prop_value);
424 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
427 if (!current_property_set)
428 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
429 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
430 XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
434 void ETag_surfxml_host(void) {
435 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
437 memset(&host,0,sizeof(host));
440 host.properties = current_property_set;
442 host.id = A_surfxml_host_id;
444 buf = A_surfxml_host_power;
445 XBT_DEBUG("Buffer: %s", buf);
446 host.power_peak = xbt_dynar_new(sizeof(double), NULL);
447 if (strchr(buf, ',') == NULL){
448 double power_value = get_cpu_power(A_surfxml_host_power);
449 xbt_dynar_push_as(host.power_peak,double, power_value);
452 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
454 for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
456 char* power_value_str;
458 xbt_dynar_get_cpy(pstate_list, i, &power_value_str);
459 xbt_str_trim(power_value_str, NULL);
460 power_value = get_cpu_power(power_value_str);
461 xbt_dynar_push_as(host.power_peak, double, power_value);
462 XBT_DEBUG("Power value: %f", power_value);
464 xbt_dynar_free(&pstate_list);
467 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
468 //host.power_peak = get_cpu_power(A_surfxml_host_power);
469 host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
470 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
471 host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
472 host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
473 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
475 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
476 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
477 if (A_surfxml_host_state == A_surfxml_host_state_ON)
478 host.initial_state = SURF_RESOURCE_ON;
479 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
480 host.initial_state = SURF_RESOURCE_OFF;
481 host.coord = A_surfxml_host_coordinates;
483 sg_platf_new_host(&host);
484 current_property_set = NULL;
487 void STag_surfxml_host___link(void){
488 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
489 s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
490 memset(&host_link,0,sizeof(host_link));
492 host_link.id = A_surfxml_host___link_id;
493 host_link.link_up = A_surfxml_host___link_up;
494 host_link.link_down = A_surfxml_host___link_down;
495 sg_platf_new_host_link(&host_link);
498 void STag_surfxml_router(void){
499 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
500 memset(&router, 0, sizeof(router));
502 router.id = A_surfxml_router_id;
503 router.coord = A_surfxml_router_coordinates;
505 sg_platf_new_router(&router);
508 void ETag_surfxml_cluster(void){
509 s_sg_platf_cluster_cbarg_t cluster = SG_PLATF_CLUSTER_INITIALIZER;
510 memset(&cluster,0,sizeof(cluster));
511 cluster.properties = as_current_property_set;
513 cluster.id = A_surfxml_cluster_id;
514 cluster.prefix = A_surfxml_cluster_prefix;
515 cluster.suffix = A_surfxml_cluster_suffix;
516 cluster.radical = A_surfxml_cluster_radical;
517 cluster.power = surf_parse_get_power(A_surfxml_cluster_power);
518 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
519 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw);
520 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat);
521 if(strcmp(A_surfxml_cluster_bb___bw,""))
522 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw);
523 if(strcmp(A_surfxml_cluster_bb___lat,""))
524 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat);
525 if(strcmp(A_surfxml_cluster_limiter___link,""))
526 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
527 if(strcmp(A_surfxml_cluster_loopback___bw,""))
528 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw);
529 if(strcmp(A_surfxml_cluster_loopback___lat,""))
530 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat);
532 switch(AX_surfxml_cluster_topology){
533 case A_surfxml_cluster_topology_FLAT:
534 cluster.topology= SURF_CLUSTER_FLAT ;
536 case A_surfxml_cluster_topology_TORUS:
537 cluster.topology= SURF_CLUSTER_TORUS ;
539 case A_surfxml_cluster_topology_FAT___TREE:
540 cluster.topology = SURF_CLUSTER_FAT_TREE;
543 surf_parse_error("Invalid cluster topology for cluster %s",
547 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
548 cluster.router_id = A_surfxml_cluster_router___id;
550 switch (AX_surfxml_cluster_sharing___policy) {
551 case A_surfxml_cluster_sharing___policy_SHARED:
552 cluster.sharing_policy = SURF_LINK_SHARED;
554 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
555 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
557 case A_surfxml_cluster_sharing___policy_FATPIPE:
558 cluster.sharing_policy = SURF_LINK_FATPIPE;
561 surf_parse_error("Invalid cluster sharing policy for cluster %s",
565 switch (AX_surfxml_cluster_bb___sharing___policy) {
566 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
567 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
569 case A_surfxml_cluster_bb___sharing___policy_SHARED:
570 cluster.bb_sharing_policy = SURF_LINK_SHARED;
573 surf_parse_error("Invalid bb sharing policy in cluster %s",
578 cluster.availability_trace = A_surfxml_cluster_availability___file;
579 cluster.state_trace = A_surfxml_cluster_state___file;
580 sg_platf_new_cluster(&cluster);
582 current_property_set = NULL;
585 void STag_surfxml_cluster(void){
586 parse_after_config();
587 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
590 void STag_surfxml_cabinet(void){
591 parse_after_config();
592 s_sg_platf_cabinet_cbarg_t cabinet = SG_PLATF_CABINET_INITIALIZER;
593 memset(&cabinet,0,sizeof(cabinet));
594 cabinet.id = A_surfxml_cabinet_id;
595 cabinet.prefix = A_surfxml_cabinet_prefix;
596 cabinet.suffix = A_surfxml_cabinet_suffix;
597 cabinet.power = surf_parse_get_power(A_surfxml_cabinet_power);
598 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw);
599 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat);
600 cabinet.radical = A_surfxml_cabinet_radical;
602 sg_platf_new_cabinet(&cabinet);
605 void STag_surfxml_peer(void){
606 parse_after_config();
607 s_sg_platf_peer_cbarg_t peer = SG_PLATF_PEER_INITIALIZER;
608 memset(&peer,0,sizeof(peer));
609 peer.id = A_surfxml_peer_id;
610 peer.power = surf_parse_get_power(A_surfxml_peer_power);
611 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in);
612 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out);
613 peer.lat = surf_parse_get_time(A_surfxml_peer_lat);
614 peer.coord = A_surfxml_peer_coordinates;
615 peer.availability_trace = tmgr_trace_new_from_file(A_surfxml_peer_availability___file);
616 peer.state_trace = tmgr_trace_new_from_file(A_surfxml_peer_state___file);
618 sg_platf_new_peer(&peer);
621 void STag_surfxml_link(void){
623 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
626 void ETag_surfxml_link(void){
627 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
628 memset(&link,0,sizeof(link));
630 link.properties = current_property_set;
632 link.id = A_surfxml_link_id;
633 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
634 //printf("Link bandwidth [%g]\n", link.bandwidth);
635 link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
636 link.latency = surf_parse_get_time(A_surfxml_link_latency);
637 //printf("Link latency [%g]\n", link.latency);
638 link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
640 switch (A_surfxml_link_state) {
641 case A_surfxml_link_state_ON:
642 link.state = SURF_RESOURCE_ON;
644 case A_surfxml_link_state_OFF:
645 link.state = SURF_RESOURCE_OFF;
648 surf_parse_error("invalid state for link %s", link.id);
651 link.state_trace = tmgr_trace_new_from_file(A_surfxml_link_state___file);
653 switch (A_surfxml_link_sharing___policy) {
654 case A_surfxml_link_sharing___policy_SHARED:
655 link.policy = SURF_LINK_SHARED;
657 case A_surfxml_link_sharing___policy_FATPIPE:
658 link.policy = SURF_LINK_FATPIPE;
660 case A_surfxml_link_sharing___policy_FULLDUPLEX:
661 link.policy = SURF_LINK_FULLDUPLEX;
664 surf_parse_error("Invalid sharing policy in link %s", link.id);
668 sg_platf_new_link(&link);
670 current_property_set = NULL;
673 void STag_surfxml_link___ctn(void){
676 switch (A_surfxml_link___ctn_direction) {
677 case AU_surfxml_link___ctn_direction:
678 case A_surfxml_link___ctn_direction_NONE:
679 link_id = xbt_strdup(A_surfxml_link___ctn_id);
681 case A_surfxml_link___ctn_direction_UP:
682 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
684 case A_surfxml_link___ctn_direction_DOWN:
685 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
689 // FIXME we should push the surf link object but it don't
690 // work because of model rulebased
691 xbt_dynar_push(parsed_link_list, &link_id);
694 void ETag_surfxml_backbone(void){
695 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
696 memset(&link,0,sizeof(link));
698 link.properties = NULL;
700 link.id = A_surfxml_backbone_id;
701 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
702 link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
703 link.state = SURF_RESOURCE_ON;
704 link.policy = SURF_LINK_SHARED;
706 sg_platf_new_link(&link);
707 routing_cluster_add_backbone(sg_link_by_name(A_surfxml_backbone_id));
710 void STag_surfxml_route(void){
711 xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
712 "Missing end-points while defining route \"%s\"->\"%s\"",
713 A_surfxml_route_src, A_surfxml_route_dst);
714 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
717 void STag_surfxml_ASroute(void){
718 xbt_assert(strlen(A_surfxml_ASroute_src) > 0
719 || strlen(A_surfxml_ASroute_dst) > 0
720 || strlen(A_surfxml_ASroute_gw___src) > 0
721 || strlen(A_surfxml_ASroute_gw___dst) > 0,
722 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
723 A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
724 A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
725 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
728 void STag_surfxml_bypassRoute(void){
729 xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
730 || strlen(A_surfxml_bypassRoute_dst) > 0,
731 "Missing end-points while defining bupass route \"%s\"->\"%s\"",
732 A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
733 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
736 void STag_surfxml_bypassASroute(void){
737 xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
738 || strlen(A_surfxml_bypassASroute_dst) > 0
739 || strlen(A_surfxml_bypassASroute_gw___src) > 0
740 || strlen(A_surfxml_bypassASroute_gw___dst) > 0,
741 "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
742 A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
743 A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
744 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
747 void ETag_surfxml_route(void){
748 s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
749 memset(&route,0,sizeof(route));
751 route.src = A_surfxml_route_src;
752 route.dst = A_surfxml_route_dst;
755 route.link_list = parsed_link_list;
757 switch (A_surfxml_route_symmetrical) {
758 case AU_surfxml_route_symmetrical:
759 case A_surfxml_route_symmetrical_YES:
760 route.symmetrical = TRUE;
762 case A_surfxml_route_symmetrical_NO:
763 route.symmetrical = FALSE;;
767 sg_platf_new_route(&route);
768 parsed_link_list = NULL;
771 void ETag_surfxml_ASroute(void){
772 s_sg_platf_route_cbarg_t ASroute = SG_PLATF_ROUTE_INITIALIZER;
773 memset(&ASroute,0,sizeof(ASroute));
775 ASroute.src = A_surfxml_ASroute_src;
776 ASroute.dst = A_surfxml_ASroute_dst;
778 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___src);
779 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_ASroute_gw___dst);
781 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
782 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
783 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
784 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
785 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
786 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
788 ASroute.link_list = parsed_link_list;
790 switch (A_surfxml_ASroute_symmetrical) {
791 case AU_surfxml_ASroute_symmetrical:
792 case A_surfxml_ASroute_symmetrical_YES:
793 ASroute.symmetrical = TRUE;
795 case A_surfxml_ASroute_symmetrical_NO:
796 ASroute.symmetrical = FALSE;
800 sg_platf_new_ASroute(&ASroute);
801 parsed_link_list = NULL;
804 void ETag_surfxml_bypassRoute(void){
805 s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
806 memset(&route,0,sizeof(route));
808 route.src = A_surfxml_bypassRoute_src;
809 route.dst = A_surfxml_bypassRoute_dst;
812 route.link_list = parsed_link_list;
813 route.symmetrical = FALSE;
815 sg_platf_new_bypassRoute(&route);
816 parsed_link_list = NULL;
819 void ETag_surfxml_bypassASroute(void){
820 s_sg_platf_route_cbarg_t ASroute = SG_PLATF_ROUTE_INITIALIZER;
821 memset(&ASroute,0,sizeof(ASroute));
823 ASroute.src = A_surfxml_bypassASroute_src;
824 ASroute.dst = A_surfxml_bypassASroute_dst;
825 ASroute.link_list = parsed_link_list;
826 ASroute.symmetrical = FALSE;
828 ASroute.gw_src = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___src);
829 ASroute.gw_dst = sg_routing_edge_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
831 sg_platf_new_bypassASroute(&ASroute);
832 parsed_link_list = NULL;
835 void ETag_surfxml_trace(void){
836 s_sg_platf_trace_cbarg_t trace = SG_PLATF_TRACE_INITIALIZER;
837 memset(&trace,0,sizeof(trace));
839 trace.id = A_surfxml_trace_id;
840 trace.file = A_surfxml_trace_file;
841 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
842 trace.pc_data = surfxml_pcdata;
844 sg_platf_new_trace(&trace);
847 void STag_surfxml_trace___connect(void){
848 parse_after_config();
849 s_sg_platf_trace_connect_cbarg_t trace_connect = SG_PLATF_TRACE_CONNECT_INITIALIZER;
850 memset(&trace_connect,0,sizeof(trace_connect));
852 trace_connect.element = A_surfxml_trace___connect_element;
853 trace_connect.trace = A_surfxml_trace___connect_trace;
855 switch (A_surfxml_trace___connect_kind) {
856 case AU_surfxml_trace___connect_kind:
857 case A_surfxml_trace___connect_kind_POWER:
858 trace_connect.kind = SURF_TRACE_CONNECT_KIND_POWER;
860 case A_surfxml_trace___connect_kind_BANDWIDTH:
861 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
863 case A_surfxml_trace___connect_kind_HOST___AVAIL:
864 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
866 case A_surfxml_trace___connect_kind_LATENCY:
867 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
869 case A_surfxml_trace___connect_kind_LINK___AVAIL:
870 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
873 sg_platf_trace_connect(&trace_connect);
876 void STag_surfxml_AS(void){
877 parse_after_config();
879 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
880 AS.id = A_surfxml_AS_id;
881 AS.routing = (int)A_surfxml_AS_routing;
883 as_current_property_set = NULL;
885 sg_platf_new_AS_begin(&AS);
887 void ETag_surfxml_AS(void){
889 char *name = as_name_tab[as_prop_nb-1];
890 xbt_dict_t dict = as_dict_tab[as_prop_nb-1];
892 XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
893 xbt_lib_set(as_router_lib,
895 ROUTING_PROP_ASR_LEVEL,
899 sg_platf_new_AS_end();
902 void STag_surfxml_config(void){
904 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
905 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
906 if (_sg_cfg_init_status == 2) {
907 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
910 void ETag_surfxml_config(void){
911 xbt_dict_cursor_t cursor = NULL;
915 xbt_dict_foreach(current_property_set, cursor, key, elem) {
916 cfg = bprintf("%s:%s",key,elem);
917 if(xbt_cfg_is_default_value(_sg_cfg_set, key))
918 xbt_cfg_set_parse(_sg_cfg_set, cfg);
920 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
923 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
925 xbt_dict_free(¤t_property_set);
926 current_property_set = NULL;
932 void STag_surfxml_process(void){
935 argv = xbt_new(char *, 1);
936 argv[0] = xbt_strdup(A_surfxml_process_function);
937 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
940 void ETag_surfxml_process(void){
941 s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
942 memset(&process,0,sizeof(process));
945 process.argv = (const char **)argv;
946 process.properties = current_property_set;
947 process.host = A_surfxml_process_host;
948 process.function = A_surfxml_process_function;
949 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
950 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
952 switch (A_surfxml_process_on___failure) {
953 case AU_surfxml_process_on___failure:
954 case A_surfxml_process_on___failure_DIE:
955 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
957 case A_surfxml_process_on___failure_RESTART:
958 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
962 sg_platf_new_process(&process);
963 current_property_set = NULL;
966 void STag_surfxml_argument(void){
968 argv = xbt_realloc(argv, (argc) * sizeof(char *));
969 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
972 void STag_surfxml_model___prop(void){
973 if (!current_model_property_set)
974 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
976 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), NULL);
979 /* ***************************************** */
980 /* TUTORIAL: New TAG */
981 void STag_surfxml_gpu(void)
983 XBT_DEBUG("STag_surfxml_gpu");
985 void ETag_surfxml_gpu(void)
987 s_sg_platf_gpu_cbarg_t gpu = SG_PLATF_GPU_INITIALIZER;
988 memset(&gpu,0,sizeof(gpu));
990 gpu.name = A_surfxml_gpu_name;
992 sg_platf_new_gpu(&gpu);
994 /* ***************************************** */
996 /* nothing to do in those functions */
997 void ETag_surfxml_prop(void){}
998 void STag_surfxml_random(void){}
999 void ETag_surfxml_random(void){}
1000 void ETag_surfxml_trace___connect(void){}
1001 void STag_surfxml_trace(void){parse_after_config();}
1002 void ETag_surfxml_router(void){}
1003 void ETag_surfxml_host___link(void){}
1004 void ETag_surfxml_cabinet(void){}
1005 void ETag_surfxml_peer(void){}
1006 void STag_surfxml_backbone(void){}
1007 void ETag_surfxml_link___ctn(void){}
1008 void ETag_surfxml_argument(void){}
1009 void ETag_surfxml_model___prop(void){}
1011 /* Open and Close parse file */
1013 void surf_parse_open(const char *file)
1015 static int warned = 0; /* warn only once */
1019 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
1020 "If it is not what you want, go fix your code.");
1026 if (!surf_input_buffer_stack)
1027 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
1028 if (!surf_file_to_parse_stack)
1029 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
1031 if (!surf_parsed_filename_stack)
1032 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
1035 /* There is no dirname on windows... */
1036 char drive[_MAX_DRIVE];
1039 err = _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, NULL,0, NULL,0);
1040 char *dir = bprintf("%s%s",drive,dir);
1042 surf_parsed_filename = xbt_strdup(file);
1043 char *dir = dirname(surf_parsed_filename);
1045 xbt_dynar_push(surf_path, &dir);
1047 surf_file_to_parse = surf_fopen(file, "r");
1048 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1049 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1050 surf_parse__switch_to_buffer(surf_input_buffer);
1051 surf_parse_lineno = 1;
1054 void surf_parse_close(void)
1056 xbt_dynar_free(&surf_input_buffer_stack);
1057 xbt_dynar_free(&surf_file_to_parse_stack);
1058 xbt_dynar_free(&surf_parsed_filename_stack);
1059 if (surf_parsed_filename) {
1061 xbt_dynar_pop(surf_path, dir);
1065 free(surf_parsed_filename);
1066 surf_parsed_filename = NULL;
1068 if (surf_file_to_parse) {
1069 surf_parse__delete_buffer(surf_input_buffer);
1070 fclose(surf_file_to_parse);
1071 surf_file_to_parse = NULL; //Must be reset for Bypass
1075 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1077 static int _surf_parse(void) {
1078 return surf_parse_lex();
1080 int_f_void_t surf_parse = _surf_parse;
1083 /* Prop tag functions */
1089 double get_cpu_power(const char *power)
1091 double power_scale = 0.0;
1094 random_data_t random = NULL;
1095 /* randomness is inserted like this: power="$rand(my_random)" */
1096 if (((p = strstr(power, "$rand(")) != NULL)
1097 && ((q = strstr(power, ")")) != NULL)) {
1099 generator = xbt_malloc(q - (p + 6) + 1);
1100 memcpy(generator, p + 6, q - (p + 6));
1101 generator[q - (p + 6)] = '\0';
1102 random = xbt_dict_get_or_null(random_data_list, generator);
1103 xbt_assert(random, "Random generator %s undefined", generator);
1104 power_scale = random_generate(random);
1107 power_scale = surf_parse_get_power(power);
1112 double random_min, random_max, random_mean, random_std_deviation;
1113 e_random_generator_t random_generator;
1116 xbt_dict_t get_as_router_properties(const char* name)
1118 return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);