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 */
16 #include "src/surf/surf_private.h"
17 #include "src/surf/network_interface.hpp"
18 #include "simgrid/sg_config.h"
19 #include "simgrid/link.h"
21 #include "src/surf/xml/platf_private.hpp"
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
25 int ETag_surfxml_include_state(void);
27 #include "simgrid_dtd.c"
29 char* surf_parsed_filename = nullptr; // to locate parse error messages
31 xbt_dynar_t parsed_link_list = nullptr; /* temporary store of current list link of a route */
35 void surf_parse_assert(bool cond, 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");
48 void surf_parse_error(const char *fmt, ...) {
51 int lineno = surf_parse_lineno;
52 char *msg = bvprintf(fmt,va);
55 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
57 xbt_die("Exiting now");
59 void surf_parse_warn(const char *fmt, ...) {
62 char *msg = bvprintf(fmt,va);
64 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
68 double surf_parse_get_double(const char *string) {
70 int ret = sscanf(string, "%lg", &res);
72 surf_parse_error("%s is not a double", string);
76 int surf_parse_get_int(const char *string) {
78 int ret = sscanf(string, "%d", &res);
80 surf_parse_error("%s is not an integer", string);
89 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
90 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
91 const char *entity_kind, const char *name,
92 const char *error_msg, const char *default_unit)
98 res = strtod(string, &ptr);
100 surf_parse_error("value out of range: %s", string);
102 surf_parse_error("cannot parse number: %s", string);
103 if (ptr[0] == '\0') {
105 return res; // Ok, 0 can be unit-less
107 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
108 ptr = (char*)default_unit;
110 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++) {
112 if (units[i].unit != nullptr)
113 res *= units[i].scale;
115 surf_parse_error("unknown unit: %s", ptr);
119 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
121 const struct unit_scale units[] = {
122 { "w", 7 * 24 * 60 * 60 },
123 { "d", 24 * 60 * 60 },
133 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
134 "Append 's' to your time to get seconds", "s");
137 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
139 const struct unit_scale units[] = {
140 { "TiB", pow(1024, 4) },
141 { "GiB", pow(1024, 3) },
142 { "MiB", pow(1024, 2) },
149 { "Tib", 0.125 * pow(1024, 4) },
150 { "Gib", 0.125 * pow(1024, 3) },
151 { "Mib", 0.125 * pow(1024, 2) },
152 { "Kib", 0.125 * 1024 },
153 { "Tb", 0.125 * 1e12 },
154 { "Gb", 0.125 * 1e9 },
155 { "Mb", 0.125 * 1e6 },
156 { "kb", 0.125 * 1e3 },
160 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
161 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
164 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
166 const struct unit_scale units[] = {
167 { "TiBps", pow(1024, 4) },
168 { "GiBps", pow(1024, 3) },
169 { "MiBps", pow(1024, 2) },
176 { "Tibps", 0.125 * pow(1024, 4) },
177 { "Gibps", 0.125 * pow(1024, 3) },
178 { "Mibps", 0.125 * pow(1024, 2) },
179 { "Kibps", 0.125 * 1024 },
180 { "Tbps", 0.125 * 1e12 },
181 { "Gbps", 0.125 * 1e9 },
182 { "Mbps", 0.125 * 1e6 },
183 { "kbps", 0.125 * 1e3 },
187 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
188 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
191 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
193 const struct unit_scale units[] = {
194 { "yottaflops", 1e24 },
196 { "zettaflops", 1e21 },
198 { "exaflops", 1e18 },
200 { "petaflops", 1e15 },
202 { "teraflops", 1e12 },
204 { "gigaflops", 1e9 },
206 { "megaflops", 1e6 },
208 { "kiloflops", 1e3 },
214 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
215 "Append 'f' or 'flops' to your speed to get flop per second", "f");
219 * All the callback lists that can be overridden anywhere.
220 * (this list should probably be reduced to the bare minimum to allow the models to work)
223 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
225 /* The default current property receiver. Setup in the corresponding opening callbacks. */
226 xbt_dict_t current_property_set = nullptr;
227 xbt_dict_t current_model_property_set = nullptr;
228 xbt_dict_t as_current_property_set = nullptr;
230 char* as_name_tab[1024];
231 void* as_dict_tab[1024];
235 /* dictionary of random generator data */
236 xbt_dict_t random_data_list = nullptr;
238 YY_BUFFER_STATE surf_input_buffer;
239 FILE *surf_file_to_parse = nullptr;
242 * Stuff relative to storage
244 void STag_surfxml_storage(void)
247 XBT_DEBUG("STag_surfxml_storage");
248 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
250 void ETag_surfxml_storage(void)
252 s_sg_platf_storage_cbarg_t storage;
253 memset(&storage,0,sizeof(storage));
255 storage.id = A_surfxml_storage_id;
256 storage.type_id = A_surfxml_storage_typeId;
257 storage.content = A_surfxml_storage_content;
258 storage.content_type = A_surfxml_storage_content___type;
259 storage.properties = current_property_set;
260 storage.attach = A_surfxml_storage_attach;
261 sg_platf_new_storage(&storage);
262 current_property_set = nullptr;
264 void STag_surfxml_storage___type(void)
267 XBT_DEBUG("STag_surfxml_storage___type");
268 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
269 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
271 void ETag_surfxml_storage___type(void)
273 s_sg_platf_storage_type_cbarg_t storage_type;
274 memset(&storage_type,0,sizeof(storage_type));
276 storage_type.content = A_surfxml_storage___type_content;
277 storage_type.content_type = A_surfxml_storage___type_content___type;
278 storage_type.id = A_surfxml_storage___type_id;
279 storage_type.model = A_surfxml_storage___type_model;
280 storage_type.properties = current_property_set;
281 storage_type.model_properties = current_model_property_set;
282 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
283 "size of storage type", storage_type.id);
284 sg_platf_new_storage_type(&storage_type);
285 current_property_set = nullptr;
286 current_model_property_set = nullptr;
288 void STag_surfxml_mount(void)
290 XBT_DEBUG("STag_surfxml_mount");
292 void ETag_surfxml_mount(void)
294 s_sg_platf_mount_cbarg_t mount;
295 memset(&mount,0,sizeof(mount));
297 mount.name = A_surfxml_mount_name;
298 mount.storageId = A_surfxml_mount_storageId;
299 sg_platf_new_mount(&mount);
303 * Stuff relative to the <include> tag
305 static xbt_dynar_t surf_input_buffer_stack = nullptr;
306 static xbt_dynar_t surf_file_to_parse_stack = nullptr;
307 static xbt_dynar_t surf_parsed_filename_stack = nullptr;
309 void STag_surfxml_include(void)
311 parse_after_config();
312 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
313 xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
314 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
316 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
318 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
319 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
321 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
322 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
323 surf_parse_push_buffer_state(surf_input_buffer);
328 void ETag_surfxml_include(void) {
329 /* Nothing to do when done with reading the include tag.
330 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
333 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
335 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
336 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
337 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
338 * error message in that case.
340 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
341 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
342 * on a line. One day maybe, if the maya allow it.
344 int ETag_surfxml_include_state(void)
347 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
349 if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
352 // Yeah, we were in an <include> Restore state and proceed.
353 fclose(surf_file_to_parse);
354 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
355 surf_parse_pop_buffer_state();
356 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
358 // Restore the filename for error messages
359 free(surf_parsed_filename);
360 xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
365 /* Stag and Etag parse functions */
367 void STag_surfxml_platform(void) {
368 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
370 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
371 "You're using an ancient XML file.\n"
372 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
373 "instead of MBytes, MFlops and seconds.\n"
375 "Use simgrid_update_xml to update your file automatically. "
376 "This program is installed automatically with SimGrid, or "
377 "available in the tools/ directory of the source archive.\n"
379 "Please check also out the SURF section of the ChangeLog for "
380 "the 3.1 version for more information. \n"
382 "Last, do not forget to also update your values for "
383 "the calls to MSG_task_create (if any).");
384 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
385 "You're using an old XML file.\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.");
389 xbt_assert((version >= 4.0), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
390 "Changes introduced in SimGrid 3.13:\n"
391 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
392 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
393 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
394 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
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.",surf_parsed_filename, version);
402 void ETag_surfxml_platform(void){
406 void STag_surfxml_host(void){
408 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
411 void STag_surfxml_prop(void)
413 if(AS_TAG){ // We need a stack here to retrieve the most recently opened AS
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 set %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
422 XBT_DEBUG("add prop %s=%s into current AS property set", A_surfxml_prop_id, A_surfxml_prop_value);
423 xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
426 if (!current_property_set)
427 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
428 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
429 XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
433 void ETag_surfxml_host(void) {
434 s_sg_platf_host_cbarg_t host;
435 memset(&host,0,sizeof(host));
439 host.properties = current_property_set;
441 host.id = A_surfxml_host_id;
443 buf = A_surfxml_host_speed;
444 XBT_DEBUG("Buffer: %s", buf);
445 host.speed_per_pstate = xbt_dynar_new(sizeof(double), nullptr);
446 if (strchr(buf, ',') == nullptr){
447 double speed = surf_parse_get_speed(A_surfxml_host_speed,"speed of host", host.id);
448 xbt_dynar_push_as(host.speed_per_pstate,double, speed);
451 xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
454 xbt_dynar_foreach(pstate_list, i, speed_str) {
455 xbt_str_trim(speed_str, nullptr);
456 double speed = surf_parse_get_speed(speed_str,"speed of host", host.id);
457 xbt_dynar_push_as(host.speed_per_pstate, double, speed);
458 XBT_DEBUG("Speed value: %f", speed);
460 xbt_dynar_free(&pstate_list);
463 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
464 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
465 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : NULL;
466 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : NULL;
467 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
468 host.coord = A_surfxml_host_coordinates;
470 sg_platf_new_host(&host);
471 xbt_dynar_free(&host.speed_per_pstate);
472 current_property_set = nullptr;
475 void STag_surfxml_host___link(void){
476 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
477 s_sg_platf_host_link_cbarg_t host_link;
478 memset(&host_link,0,sizeof(host_link));
480 host_link.id = A_surfxml_host___link_id;
481 host_link.link_up = A_surfxml_host___link_up;
482 host_link.link_down = A_surfxml_host___link_down;
483 sg_platf_new_hostlink(&host_link);
486 void STag_surfxml_router(void){
487 s_sg_platf_router_cbarg_t router;
488 memset(&router, 0, sizeof(router));
490 router.id = A_surfxml_router_id;
491 router.coord = A_surfxml_router_coordinates;
493 sg_platf_new_router(&router);
496 void ETag_surfxml_cluster(void){
497 s_sg_platf_cluster_cbarg_t cluster;
498 memset(&cluster,0,sizeof(cluster));
499 cluster.properties = as_current_property_set;
501 cluster.id = A_surfxml_cluster_id;
502 cluster.prefix = A_surfxml_cluster_prefix;
503 cluster.suffix = A_surfxml_cluster_suffix;
504 cluster.radical = A_surfxml_cluster_radical;
505 cluster.speed = surf_parse_get_speed(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
506 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
507 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
508 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
509 if(strcmp(A_surfxml_cluster_bb___bw,""))
510 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
511 if(strcmp(A_surfxml_cluster_bb___lat,""))
512 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
513 if(strcmp(A_surfxml_cluster_limiter___link,""))
514 cluster.limiter_link = surf_parse_get_double(A_surfxml_cluster_limiter___link);
515 if(strcmp(A_surfxml_cluster_loopback___bw,""))
516 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
517 if(strcmp(A_surfxml_cluster_loopback___lat,""))
518 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
520 switch(AX_surfxml_cluster_topology){
521 case A_surfxml_cluster_topology_FLAT:
522 cluster.topology= SURF_CLUSTER_FLAT ;
524 case A_surfxml_cluster_topology_TORUS:
525 cluster.topology= SURF_CLUSTER_TORUS ;
527 case A_surfxml_cluster_topology_FAT___TREE:
528 cluster.topology = SURF_CLUSTER_FAT_TREE;
531 surf_parse_error("Invalid cluster topology for cluster %s",
535 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
536 cluster.router_id = A_surfxml_cluster_router___id;
538 switch (AX_surfxml_cluster_sharing___policy) {
539 case A_surfxml_cluster_sharing___policy_SHARED:
540 cluster.sharing_policy = SURF_LINK_SHARED;
542 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
543 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
545 case A_surfxml_cluster_sharing___policy_FATPIPE:
546 cluster.sharing_policy = SURF_LINK_FATPIPE;
549 surf_parse_error("Invalid cluster sharing policy for cluster %s",
553 switch (AX_surfxml_cluster_bb___sharing___policy) {
554 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
555 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
557 case A_surfxml_cluster_bb___sharing___policy_SHARED:
558 cluster.bb_sharing_policy = SURF_LINK_SHARED;
561 surf_parse_error("Invalid bb sharing policy in cluster %s",
566 sg_platf_new_cluster(&cluster);
568 current_property_set = nullptr;
571 void STag_surfxml_cluster(void){
572 parse_after_config();
573 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
576 void STag_surfxml_cabinet(void){
577 parse_after_config();
578 s_sg_platf_cabinet_cbarg_t cabinet;
579 memset(&cabinet,0,sizeof(cabinet));
580 cabinet.id = A_surfxml_cabinet_id;
581 cabinet.prefix = A_surfxml_cabinet_prefix;
582 cabinet.suffix = A_surfxml_cabinet_suffix;
583 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
584 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
585 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
586 cabinet.radical = A_surfxml_cabinet_radical;
588 sg_platf_new_cabinet(&cabinet);
591 void STag_surfxml_peer(void){
592 parse_after_config();
593 s_sg_platf_peer_cbarg_t peer;
594 memset(&peer,0,sizeof(peer));
595 peer.id = A_surfxml_peer_id;
596 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
597 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
598 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
599 peer.lat = surf_parse_get_time(A_surfxml_peer_lat, "lat of peer", peer.id);
600 peer.coord = A_surfxml_peer_coordinates;
601 peer.availability_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : NULL;
602 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : NULL;
604 sg_platf_new_peer(&peer);
607 void STag_surfxml_link(void){
609 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
612 void ETag_surfxml_link(void){
613 s_sg_platf_link_cbarg_t link;
614 memset(&link,0,sizeof(link));
616 link.properties = current_property_set;
617 link.id = A_surfxml_link_id;
618 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id);
619 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : NULL;
620 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id);
621 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : NULL;
622 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):NULL;
624 switch (A_surfxml_link_sharing___policy) {
625 case A_surfxml_link_sharing___policy_SHARED:
626 link.policy = SURF_LINK_SHARED;
628 case A_surfxml_link_sharing___policy_FATPIPE:
629 link.policy = SURF_LINK_FATPIPE;
631 case A_surfxml_link_sharing___policy_FULLDUPLEX:
632 link.policy = SURF_LINK_FULLDUPLEX;
635 surf_parse_error("Invalid sharing policy in link %s", link.id);
639 sg_platf_new_link(&link);
641 current_property_set = nullptr;
644 void STag_surfxml_link___ctn(void){
647 switch (A_surfxml_link___ctn_direction) {
648 case AU_surfxml_link___ctn_direction:
649 case A_surfxml_link___ctn_direction_NONE:
650 link_id = xbt_strdup(A_surfxml_link___ctn_id);
652 case A_surfxml_link___ctn_direction_UP:
653 link_id = bprintf("%s_UP", A_surfxml_link___ctn_id);
655 case A_surfxml_link___ctn_direction_DOWN:
656 link_id = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
660 // FIXME we should push the surf link object but it don't
661 // work because of model rulebased
662 xbt_dynar_push(parsed_link_list, &link_id);
665 void ETag_surfxml_backbone(void){
666 s_sg_platf_link_cbarg_t link;
667 memset(&link,0,sizeof(link));
669 link.properties = nullptr;
670 link.id = A_surfxml_backbone_id;
671 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id);
672 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id);
673 link.policy = SURF_LINK_SHARED;
675 sg_platf_new_link(&link);
676 routing_cluster_add_backbone(sg_link_by_name(A_surfxml_backbone_id));
679 void STag_surfxml_route(void){
680 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_src),
681 "Route src='%s' does name a node.", A_surfxml_route_src);
682 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_dst),
683 "Route dst='%s' does name a node.", A_surfxml_route_dst);
684 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
687 void STag_surfxml_ASroute(void){
688 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_src),
689 "ASroute src='%s' does name a node.", A_surfxml_route_src);
690 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_dst),
691 "ASroute dst='%s' does name a node.", A_surfxml_route_dst);
693 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src),
694 "ASroute gw_src='%s' does name a node.", A_surfxml_ASroute_gw___src);
695 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst),
696 "ASroute gw_dst='%s' does name a node.", A_surfxml_ASroute_gw___dst);
698 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
701 void STag_surfxml_bypassRoute(void){
702 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_src),
703 "bypassRoute src='%s' does name a node.", A_surfxml_bypassRoute_src);
704 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_dst),
705 "bypassRoute dst='%s' does name a node.", A_surfxml_bypassRoute_dst);
707 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
710 void STag_surfxml_bypassASroute(void){
711 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_src),
712 "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
713 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_dst),
714 "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
715 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src),
716 "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
717 surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
718 "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
720 parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
723 void ETag_surfxml_route(void){
724 s_sg_platf_route_cbarg_t route;
725 memset(&route,0,sizeof(route));
727 route.src = A_surfxml_route_src;
728 route.dst = A_surfxml_route_dst;
729 route.gw_src = nullptr;
730 route.gw_dst = nullptr;
731 route.link_list = new std::vector<Link*>();
732 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
736 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
737 simgrid::surf::Link *link = Link::byName(link_name);
738 route.link_list->push_back(link);
741 sg_platf_new_route(&route);
742 delete route.link_list;
743 xbt_dynar_free(&parsed_link_list);
746 void ETag_surfxml_ASroute(void){
747 s_sg_platf_route_cbarg_t ASroute;
748 memset(&ASroute,0,sizeof(ASroute));
750 ASroute.src = A_surfxml_ASroute_src;
751 ASroute.dst = A_surfxml_ASroute_dst;
753 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src);
754 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst);
756 if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)
757 surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
758 A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);
759 if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)
760 surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
761 A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
763 ASroute.link_list = new std::vector<Link*>();
767 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
768 simgrid::surf::Link *link = Link::byName(link_name);
769 ASroute.link_list->push_back(link);
771 xbt_dynar_free(&parsed_link_list);
773 switch (A_surfxml_ASroute_symmetrical) {
774 case AU_surfxml_ASroute_symmetrical:
775 case A_surfxml_ASroute_symmetrical_YES:
776 ASroute.symmetrical = true;
778 case A_surfxml_ASroute_symmetrical_NO:
779 ASroute.symmetrical = false;
783 sg_platf_new_route(&ASroute);
784 delete ASroute.link_list;
787 void ETag_surfxml_bypassRoute(void){
788 s_sg_platf_route_cbarg_t route;
789 memset(&route,0,sizeof(route));
791 route.src = A_surfxml_bypassRoute_src;
792 route.dst = A_surfxml_bypassRoute_dst;
793 route.gw_src = nullptr;
794 route.gw_dst = nullptr;
795 route.symmetrical = false;
796 route.link_list = new std::vector<Link*>();
800 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
801 simgrid::surf::Link *link = Link::byName(link_name);
802 route.link_list->push_back(link);
804 xbt_dynar_free(&parsed_link_list);
806 sg_platf_new_bypassRoute(&route);
809 void ETag_surfxml_bypassASroute(void){
810 s_sg_platf_route_cbarg_t ASroute;
811 memset(&ASroute,0,sizeof(ASroute));
813 ASroute.src = A_surfxml_bypassASroute_src;
814 ASroute.dst = A_surfxml_bypassASroute_dst;
815 ASroute.link_list = new std::vector<Link*>();
818 xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
819 simgrid::surf::Link *link = Link::byName(link_name);
820 ASroute.link_list->push_back(link);
822 xbt_dynar_free(&parsed_link_list);
823 ASroute.symmetrical = false;
825 ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src);
826 ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
828 sg_platf_new_bypassRoute(&ASroute);
831 void ETag_surfxml_trace(void){
832 s_sg_platf_trace_cbarg_t trace;
833 memset(&trace,0,sizeof(trace));
835 trace.id = A_surfxml_trace_id;
836 trace.file = A_surfxml_trace_file;
837 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
838 trace.pc_data = surfxml_pcdata;
840 sg_platf_new_trace(&trace);
843 void STag_surfxml_trace___connect(void){
844 parse_after_config();
845 s_sg_platf_trace_connect_cbarg_t trace_connect;
846 memset(&trace_connect,0,sizeof(trace_connect));
848 trace_connect.element = A_surfxml_trace___connect_element;
849 trace_connect.trace = A_surfxml_trace___connect_trace;
851 switch (A_surfxml_trace___connect_kind) {
852 case AU_surfxml_trace___connect_kind:
853 case A_surfxml_trace___connect_kind_SPEED:
854 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
856 case A_surfxml_trace___connect_kind_BANDWIDTH:
857 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
859 case A_surfxml_trace___connect_kind_HOST___AVAIL:
860 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
862 case A_surfxml_trace___connect_kind_LATENCY:
863 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
865 case A_surfxml_trace___connect_kind_LINK___AVAIL:
866 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
869 sg_platf_trace_connect(&trace_connect);
872 void STag_surfxml_AS(void){
873 parse_after_config();
875 s_sg_platf_AS_cbarg_t AS = { A_surfxml_AS_id, (int)A_surfxml_AS_routing};
877 as_current_property_set = nullptr;
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 = (xbt_dict_t) 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, name, ROUTING_PROP_ASR_LEVEL, dict);
890 sg_platf_new_AS_seal();
893 void STag_surfxml_config(void){
895 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
896 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
897 if (_sg_cfg_init_status == 2) {
898 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
901 void ETag_surfxml_config(void){
902 xbt_dict_cursor_t cursor = nullptr;
906 xbt_dict_foreach(current_property_set, cursor, key, elem) {
907 cfg = bprintf("%s:%s",key,elem);
908 if(xbt_cfg_is_default_value(key))
909 xbt_cfg_set_parse(cfg);
911 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
914 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
916 xbt_dict_free(¤t_property_set);
917 current_property_set = nullptr;
923 void STag_surfxml_process(void){
926 argv = xbt_new(char *, 1);
927 argv[0] = xbt_strdup(A_surfxml_process_function);
928 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
931 void ETag_surfxml_process(void){
932 s_sg_platf_process_cbarg_t process;
933 memset(&process,0,sizeof(process));
936 process.argv = (const char **)argv;
937 process.properties = current_property_set;
938 process.host = A_surfxml_process_host;
939 process.function = A_surfxml_process_function;
940 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
941 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
943 switch (A_surfxml_process_on___failure) {
944 case AU_surfxml_process_on___failure:
945 case A_surfxml_process_on___failure_DIE:
946 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
948 case A_surfxml_process_on___failure_RESTART:
949 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
953 sg_platf_new_process(&process);
954 current_property_set = nullptr;
957 void STag_surfxml_argument(void){
959 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
960 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
963 void STag_surfxml_model___prop(void){
964 if (!current_model_property_set)
965 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
967 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), nullptr);
970 /* nothing to do in those functions */
971 void ETag_surfxml_prop(void){}
972 void STag_surfxml_random(void){}
973 void ETag_surfxml_random(void){}
974 void ETag_surfxml_trace___connect(void){}
975 void STag_surfxml_trace(void){parse_after_config();}
976 void ETag_surfxml_router(void){}
977 void ETag_surfxml_host___link(void){}
978 void ETag_surfxml_cabinet(void){}
979 void ETag_surfxml_peer(void){}
980 void STag_surfxml_backbone(void){}
981 void ETag_surfxml_link___ctn(void){}
982 void ETag_surfxml_argument(void){}
983 void ETag_surfxml_model___prop(void){}
985 /* Open and Close parse file */
987 void surf_parse_open(const char *file)
989 xbt_assert(file, "Cannot parse the NULL file. Bypassing the parser is strongly deprecated nowadays.");
991 if (!surf_input_buffer_stack)
992 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), nullptr);
993 if (!surf_file_to_parse_stack)
994 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), nullptr);
996 if (!surf_parsed_filename_stack)
997 surf_parsed_filename_stack = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
999 surf_parsed_filename = xbt_strdup(file);
1000 char *dir = xbt_dirname(file);
1001 xbt_dynar_push(surf_path, &dir);
1003 surf_file_to_parse = surf_fopen(file, "r");
1004 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1005 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1006 surf_parse__switch_to_buffer(surf_input_buffer);
1007 surf_parse_lineno = 1;
1010 void surf_parse_close(void)
1012 xbt_dynar_free(&surf_input_buffer_stack);
1013 xbt_dynar_free(&surf_file_to_parse_stack);
1014 xbt_dynar_free(&surf_parsed_filename_stack);
1015 if (surf_parsed_filename) {
1016 char *dir = nullptr;
1017 xbt_dynar_pop(surf_path, &dir);
1021 free(surf_parsed_filename);
1022 surf_parsed_filename = nullptr;
1024 if (surf_file_to_parse) {
1025 surf_parse__delete_buffer(surf_input_buffer);
1026 fclose(surf_file_to_parse);
1027 surf_file_to_parse = nullptr; //Must be reset for Bypass
1031 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1033 static int _surf_parse(void) {
1034 return surf_parse_lex();
1036 int_f_void_t surf_parse = _surf_parse;
1039 /* Prop tag functions */
1044 xbt_dict_t get_as_router_properties(const char* name)
1046 return (xbt_dict_t)xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);