1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u/Engine.hpp"
7 #include "simgrid/sg_config.h"
8 #include "src/kernel/routing/NetPoint.hpp"
9 #include "src/surf/network_interface.hpp"
12 #include "src/surf/xml/platf_private.hpp"
13 #include <boost/algorithm/string.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
22 int ETag_surfxml_include_state();
24 #include "simgrid_dtd.c"
26 char* surf_parsed_filename = nullptr; // to locate parse error messages
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
33 void surf_parse_assert(bool cond, const char *fmt, ...) {
37 int lineno = surf_parse_lineno;
38 char *msg = bvprintf(fmt,va);
41 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
43 xbt_die("Exiting now");
46 void surf_parse_error(const char *fmt, ...) {
49 int lineno = surf_parse_lineno;
50 char *msg = bvprintf(fmt,va);
53 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
55 xbt_die("Exiting now");
57 void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
59 if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
62 std::string msg = std::string(pre);
65 msg += " Existing netpoints: \n";
67 std::vector<simgrid::kernel::routing::NetPoint*> list;
68 simgrid::s4u::Engine::instance()->netpointList(&list);
69 std::sort(list.begin(), list.end(),
70 [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
71 return a->name() < b->name();
74 for (auto np : list) {
81 msg += "'" + np->name() + "'";
82 if (msg.length() > 4096) {
83 msg.pop_back(); // remove trailing quote
84 msg += "...(list truncated)......";
88 surf_parse_error("%s", msg.c_str());
91 void surf_parse_warn(const char *fmt, ...) {
94 char *msg = bvprintf(fmt,va);
96 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
100 double surf_parse_get_double(const char *string) {
102 int ret = sscanf(string, "%lg", &res);
104 surf_parse_error("%s is not a double", string);
108 int surf_parse_get_int(const char *string) {
110 int ret = sscanf(string, "%d", &res);
112 surf_parse_error("%s is not an integer", string);
116 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
117 static std::vector<int>* explodesRadical(const char* radicals)
119 std::vector<int>* exploded = new std::vector<int>();
122 std::vector<std::string> radical_elements;
123 boost::split(radical_elements, radicals, boost::is_any_of(","));
124 for (auto group : radical_elements) {
125 std::vector<std::string> radical_ends;
126 boost::split(radical_ends, group, boost::is_any_of("-"));
127 int start = surf_parse_get_int((radical_ends.front()).c_str());
130 switch (radical_ends.size()) {
135 end = surf_parse_get_int((radical_ends.back()).c_str());
138 surf_parse_error("Malformed radical: %s", group.c_str());
141 for (int i = start; i <= end; i++)
142 exploded->push_back(i);
153 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
154 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
155 const char *entity_kind, const char *name, const char *error_msg, const char *default_unit)
160 double res = strtod(string, &ptr);
162 surf_parse_error("value out of range: %s", string);
164 surf_parse_error("cannot parse number: %s", string);
165 if (ptr[0] == '\0') {
167 return res; // Ok, 0 can be unit-less
169 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
170 ptr = (char*)default_unit;
172 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
174 if (units[i].unit != nullptr)
175 res *= units[i].scale;
177 surf_parse_error("unknown unit: %s", ptr);
181 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
183 const struct unit_scale units[] = {
184 { "w", 7 * 24 * 60 * 60 },
185 { "d", 24 * 60 * 60 },
195 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
196 "Append 's' to your time to get seconds", "s");
199 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
201 const struct unit_scale units[] = {
202 { "EiB", pow(1024, 6) },
203 { "PiB", pow(1024, 5) },
204 { "TiB", pow(1024, 4) },
205 { "GiB", pow(1024, 3) },
206 { "MiB", pow(1024, 2) },
215 { "Eib", 0.125 * pow(1024, 6) },
216 { "Pib", 0.125 * pow(1024, 5) },
217 { "Tib", 0.125 * pow(1024, 4) },
218 { "Gib", 0.125 * pow(1024, 3) },
219 { "Mib", 0.125 * pow(1024, 2) },
220 { "Kib", 0.125 * 1024 },
221 { "Eb", 0.125 * 1e18 },
222 { "Pb", 0.125 * 1e15 },
223 { "Tb", 0.125 * 1e12 },
224 { "Gb", 0.125 * 1e9 },
225 { "Mb", 0.125 * 1e6 },
226 { "kb", 0.125 * 1e3 },
230 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
231 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
234 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
236 const struct unit_scale units[] = {
237 { "EiBps", pow(1024, 6) },
238 { "PiBps", pow(1024, 5) },
239 { "TiBps", pow(1024, 4) },
240 { "GiBps", pow(1024, 3) },
241 { "MiBps", pow(1024, 2) },
250 { "Eibps", 0.125 * pow(1024, 6) },
251 { "Pibps", 0.125 * pow(1024, 5) },
252 { "Tibps", 0.125 * pow(1024, 4) },
253 { "Gibps", 0.125 * pow(1024, 3) },
254 { "Mibps", 0.125 * pow(1024, 2) },
255 { "Kibps", 0.125 * 1024 },
256 { "Tbps", 0.125 * 1e12 },
257 { "Gbps", 0.125 * 1e9 },
258 { "Mbps", 0.125 * 1e6 },
259 { "kbps", 0.125 * 1e3 },
263 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
264 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
267 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
269 const struct unit_scale units[] = {
270 { "yottaflops", 1e24 },
272 { "zettaflops", 1e21 },
274 { "exaflops", 1e18 },
276 { "petaflops", 1e15 },
278 { "teraflops", 1e12 },
280 { "gigaflops", 1e9 },
282 { "megaflops", 1e6 },
284 { "kiloflops", 1e3 },
290 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
291 "Append 'f' or 'flops' to your speed to get flop per second", "f");
294 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){
296 std::vector<double> speed_per_pstate;
298 if (strchr(speeds, ',') == nullptr){
299 double speed = surf_parse_get_speed(speeds, entity_kind, id);
300 speed_per_pstate.push_back(speed);
302 std::vector<std::string> pstate_list;
303 boost::split(pstate_list, speeds, boost::is_any_of(","));
304 for (auto speed_str : pstate_list) {
305 boost::trim(speed_str);
306 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
307 speed_per_pstate.push_back(speed);
308 XBT_DEBUG("Speed value: %f", speed);
311 return speed_per_pstate;
315 * All the callback lists that can be overridden anywhere.
316 * (this list should probably be reduced to the bare minimum to allow the models to work)
319 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
321 /* The default current property receiver. Setup in the corresponding opening callbacks. */
322 xbt_dict_t current_property_set = nullptr;
323 std::map<std::string, std::string>* current_model_property_set = nullptr;
324 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
326 /* dictionary of random generator data */
327 xbt_dict_t random_data_list = nullptr;
329 YY_BUFFER_STATE surf_input_buffer;
330 FILE *surf_file_to_parse = nullptr;
333 * Stuff relative to storage
335 void STag_surfxml_storage()
338 XBT_DEBUG("STag_surfxml_storage");
339 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
341 void ETag_surfxml_storage()
343 s_sg_platf_storage_cbarg_t storage;
344 memset(&storage,0,sizeof(storage));
346 storage.properties = current_property_set;
347 current_property_set = nullptr;
349 storage.id = A_surfxml_storage_id;
350 storage.type_id = A_surfxml_storage_typeId;
351 storage.content = A_surfxml_storage_content;
353 storage.attach = A_surfxml_storage_attach;
354 sg_platf_new_storage(&storage);
356 void STag_surfxml_storage___type()
359 XBT_DEBUG("STag_surfxml_storage___type");
360 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
361 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
363 void ETag_surfxml_storage___type()
365 s_sg_platf_storage_type_cbarg_t storage_type;
366 memset(&storage_type,0,sizeof(storage_type));
368 storage_type.properties = current_property_set;
369 current_property_set = nullptr;
371 storage_type.model_properties = current_model_property_set;
372 current_model_property_set = nullptr;
374 storage_type.content = A_surfxml_storage___type_content;
375 storage_type.id = A_surfxml_storage___type_id;
376 storage_type.model = A_surfxml_storage___type_model;
377 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
378 "size of storage type", storage_type.id);
379 sg_platf_new_storage_type(&storage_type);
381 void STag_surfxml_mount()
383 XBT_DEBUG("STag_surfxml_mount");
385 void ETag_surfxml_mount()
387 s_sg_platf_mount_cbarg_t mount;
388 memset(&mount,0,sizeof(mount));
390 mount.name = A_surfxml_mount_name;
391 mount.storageId = A_surfxml_mount_storageId;
392 sg_platf_new_mount(&mount);
396 * Stuff relative to the <include> tag
398 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
399 static std::vector<FILE*> surf_file_to_parse_stack;
400 static std::vector<char*> surf_parsed_filename_stack;
402 void STag_surfxml_include()
404 parse_after_config();
405 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
406 surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
407 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
409 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
411 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
412 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
414 surf_input_buffer_stack.push_back(surf_input_buffer);
415 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
416 surf_parse_push_buffer_state(surf_input_buffer);
421 void ETag_surfxml_include() {
422 /* Nothing to do when done with reading the include tag.
423 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
426 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
428 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
429 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
430 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
431 * error message in that case.
433 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
434 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
435 * on a line. One day maybe, if the maya allow it.
437 int ETag_surfxml_include_state()
440 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
442 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
445 // Yeah, we were in an <include> Restore state and proceed.
446 fclose(surf_file_to_parse);
447 surf_file_to_parse_stack.pop_back();
448 surf_parse_pop_buffer_state();
449 surf_input_buffer_stack.pop_back();
451 // Restore the filename for error messages
452 free(surf_parsed_filename);
453 surf_parsed_filename_stack.pop_back();
458 /* Stag and Etag parse functions */
460 void STag_surfxml_platform() {
461 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
463 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
464 "You're using an ancient XML file.\n"
465 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
466 "instead of MBytes, MFlops and seconds.\n"
468 "Use simgrid_update_xml to update your file automatically. "
469 "This program is installed automatically with SimGrid, or "
470 "available in the tools/ directory of the source archive.\n"
472 "Please check also out the SURF section of the ChangeLog for "
473 "the 3.1 version for more information. \n"
475 "Last, do not forget to also update your values for "
476 "the calls to MSG_task_create (if any).");
477 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
478 "You're using an old XML file.\n"
479 "Use simgrid_update_xml to update your file automatically. "
480 "This program is installed automatically with SimGrid, or "
481 "available in the tools/ directory of the source archive.");
482 xbt_assert((version >= 4.0),
483 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
484 "Changes introduced in SimGrid 3.13:\n"
485 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
486 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
487 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
488 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
490 "Use simgrid_update_xml to update your file automatically. "
491 "This program is installed automatically with SimGrid, or "
492 "available in the tools/ directory of the source archive.",
493 surf_parsed_filename, version);
495 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
496 "That's fine, the new version is backward compatible. \n\n"
497 "Use simgrid_update_xml to update your file automatically. "
498 "This program is installed automatically with SimGrid, or "
499 "available in the tools/ directory of the source archive.",
500 version, surf_parsed_filename);
502 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
503 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
504 "Please update your code, or use another, more adapted, file.",
505 surf_parsed_filename, version);
509 void ETag_surfxml_platform(){
513 void STag_surfxml_host(){
515 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
518 void STag_surfxml_prop()
520 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
521 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
522 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_zone_id);
524 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
527 if (not current_property_set)
528 current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
529 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
530 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
531 current_property_set);
535 void ETag_surfxml_host() {
536 s_sg_platf_host_cbarg_t host;
537 memset(&host,0,sizeof(host));
539 host.properties = current_property_set;
540 current_property_set = nullptr;
542 host.id = A_surfxml_host_id;
544 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
546 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
547 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
548 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
549 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
550 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
551 host.coord = A_surfxml_host_coordinates;
553 sg_platf_new_host(&host);
556 void STag_surfxml_host___link(){
557 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
558 s_sg_platf_host_link_cbarg_t host_link;
559 memset(&host_link,0,sizeof(host_link));
561 host_link.id = A_surfxml_host___link_id;
562 host_link.link_up = A_surfxml_host___link_up;
563 host_link.link_down = A_surfxml_host___link_down;
564 sg_platf_new_hostlink(&host_link);
567 void STag_surfxml_router(){
568 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
571 void ETag_surfxml_cluster(){
572 s_sg_platf_cluster_cbarg_t cluster;
573 memset(&cluster,0,sizeof(cluster));
574 cluster.properties = current_property_set;
575 current_property_set = nullptr;
577 cluster.id = A_surfxml_cluster_id;
578 cluster.prefix = A_surfxml_cluster_prefix;
579 cluster.suffix = A_surfxml_cluster_suffix;
580 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
581 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
582 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
583 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
584 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
585 if(strcmp(A_surfxml_cluster_bb___bw,""))
586 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
587 if(strcmp(A_surfxml_cluster_bb___lat,""))
588 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
589 if(strcmp(A_surfxml_cluster_limiter___link,""))
590 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
591 if(strcmp(A_surfxml_cluster_loopback___bw,""))
592 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
593 if(strcmp(A_surfxml_cluster_loopback___lat,""))
594 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
596 switch(AX_surfxml_cluster_topology){
597 case A_surfxml_cluster_topology_FLAT:
598 cluster.topology= SURF_CLUSTER_FLAT ;
600 case A_surfxml_cluster_topology_TORUS:
601 cluster.topology= SURF_CLUSTER_TORUS ;
603 case A_surfxml_cluster_topology_FAT___TREE:
604 cluster.topology = SURF_CLUSTER_FAT_TREE;
606 case A_surfxml_cluster_topology_DRAGONFLY:
607 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
610 surf_parse_error("Invalid cluster topology for cluster %s",
614 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
615 cluster.router_id = A_surfxml_cluster_router___id;
617 switch (AX_surfxml_cluster_sharing___policy) {
618 case A_surfxml_cluster_sharing___policy_SHARED:
619 cluster.sharing_policy = SURF_LINK_SHARED;
621 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
622 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
624 case A_surfxml_cluster_sharing___policy_FATPIPE:
625 cluster.sharing_policy = SURF_LINK_FATPIPE;
628 surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
631 switch (AX_surfxml_cluster_bb___sharing___policy) {
632 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
633 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
635 case A_surfxml_cluster_bb___sharing___policy_SHARED:
636 cluster.bb_sharing_policy = SURF_LINK_SHARED;
639 surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
643 sg_platf_new_cluster(&cluster);
646 void STag_surfxml_cluster(){
648 parse_after_config();
649 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
652 void STag_surfxml_cabinet(){
653 parse_after_config();
654 s_sg_platf_cabinet_cbarg_t cabinet;
655 memset(&cabinet,0,sizeof(cabinet));
656 cabinet.id = A_surfxml_cabinet_id;
657 cabinet.prefix = A_surfxml_cabinet_prefix;
658 cabinet.suffix = A_surfxml_cabinet_suffix;
659 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
660 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
661 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
662 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
664 sg_platf_new_cabinet(&cabinet);
667 void STag_surfxml_peer(){
668 parse_after_config();
669 s_sg_platf_peer_cbarg_t peer;
670 memset(&peer,0,sizeof(peer));
671 peer.id = A_surfxml_peer_id;
672 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
673 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
674 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
675 peer.coord = A_surfxml_peer_coordinates;
676 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
677 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
679 if (A_surfxml_peer_lat[0] != '\0')
680 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
683 sg_platf_new_peer(&peer);
686 void STag_surfxml_link(){
688 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
691 void ETag_surfxml_link(){
692 LinkCreationArgs link;
694 link.properties = current_property_set;
695 current_property_set = nullptr;
697 link.id = std::string(A_surfxml_link_id);
698 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
699 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
700 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
701 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
702 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
704 switch (A_surfxml_link_sharing___policy) {
705 case A_surfxml_link_sharing___policy_SHARED:
706 link.policy = SURF_LINK_SHARED;
708 case A_surfxml_link_sharing___policy_FATPIPE:
709 link.policy = SURF_LINK_FATPIPE;
711 case A_surfxml_link_sharing___policy_FULLDUPLEX:
712 link.policy = SURF_LINK_FULLDUPLEX;
715 surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
719 sg_platf_new_link(&link);
722 void STag_surfxml_link___ctn(){
724 simgrid::surf::LinkImpl* link = nullptr;
725 char *link_name=nullptr;
726 switch (A_surfxml_link___ctn_direction) {
727 case AU_surfxml_link___ctn_direction:
728 case A_surfxml_link___ctn_direction_NONE:
729 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
731 case A_surfxml_link___ctn_direction_UP:
732 link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
733 link = simgrid::surf::LinkImpl::byName(link_name);
735 case A_surfxml_link___ctn_direction_DOWN:
736 link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
737 link = simgrid::surf::LinkImpl::byName(link_name);
740 surf_parse_error("Invalid direction for link %s", link_name);
743 xbt_free(link_name); // no-op if it's already nullptr
745 const char* dirname = "";
746 switch (A_surfxml_link___ctn_direction) {
747 case A_surfxml_link___ctn_direction_UP:
748 dirname = " (upward)";
750 case A_surfxml_link___ctn_direction_DOWN:
751 dirname = " (downward)";
756 surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
757 parsed_link_list.push_back(link);
760 void ETag_surfxml_backbone(){
761 LinkCreationArgs link;
763 link.properties = nullptr;
764 link.id = std::string(A_surfxml_backbone_id);
765 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
766 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
767 link.policy = SURF_LINK_SHARED;
769 sg_platf_new_link(&link);
770 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
773 void STag_surfxml_route(){
774 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
775 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
778 void STag_surfxml_ASroute(){
779 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
780 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
782 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
783 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
785 void STag_surfxml_zoneRoute(){
786 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
787 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
788 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
789 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
792 void STag_surfxml_bypassRoute(){
793 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
794 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
797 void STag_surfxml_bypassASroute(){
798 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
799 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
800 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
801 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
803 void STag_surfxml_bypassZoneRoute(){
804 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
805 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
806 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
807 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
810 void ETag_surfxml_route(){
811 s_sg_platf_route_cbarg_t route;
812 memset(&route,0,sizeof(route));
814 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
815 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
816 route.gw_src = nullptr;
817 route.gw_dst = nullptr;
818 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
819 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
821 for (auto link: parsed_link_list)
822 route.link_list->push_back(link);
823 parsed_link_list.clear();
825 sg_platf_new_route(&route);
826 delete route.link_list;
829 void ETag_surfxml_ASroute()
831 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
832 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
833 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
834 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
835 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
836 ETag_surfxml_zoneRoute();
838 void ETag_surfxml_zoneRoute()
840 s_sg_platf_route_cbarg_t ASroute;
841 memset(&ASroute,0,sizeof(ASroute));
843 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
844 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
846 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
847 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
849 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
851 for (auto link: parsed_link_list)
852 ASroute.link_list->push_back(link);
853 parsed_link_list.clear();
855 switch (A_surfxml_zoneRoute_symmetrical) {
856 case AU_surfxml_zoneRoute_symmetrical:
857 case A_surfxml_zoneRoute_symmetrical_YES:
858 ASroute.symmetrical = true;
860 case A_surfxml_zoneRoute_symmetrical_NO:
861 ASroute.symmetrical = false;
865 sg_platf_new_route(&ASroute);
866 delete ASroute.link_list;
869 void ETag_surfxml_bypassRoute(){
870 s_sg_platf_route_cbarg_t route;
871 memset(&route,0,sizeof(route));
873 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
874 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
875 route.gw_src = nullptr;
876 route.gw_dst = nullptr;
877 route.symmetrical = false;
878 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
880 for (auto link: parsed_link_list)
881 route.link_list->push_back(link);
882 parsed_link_list.clear();
884 sg_platf_new_bypassRoute(&route);
885 delete route.link_list;
888 void ETag_surfxml_bypassASroute()
890 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
891 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
892 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
893 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
894 ETag_surfxml_bypassZoneRoute();
896 void ETag_surfxml_bypassZoneRoute()
898 s_sg_platf_route_cbarg_t ASroute;
899 memset(&ASroute,0,sizeof(ASroute));
901 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
902 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
903 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
904 for (auto link: parsed_link_list)
905 ASroute.link_list->push_back(link);
906 parsed_link_list.clear();
908 ASroute.symmetrical = false;
910 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
911 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
913 sg_platf_new_bypassRoute(&ASroute);
914 delete ASroute.link_list;
917 void ETag_surfxml_trace(){
918 s_sg_platf_trace_cbarg_t trace;
919 memset(&trace,0,sizeof(trace));
921 trace.id = A_surfxml_trace_id;
922 trace.file = A_surfxml_trace_file;
923 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
924 trace.pc_data = surfxml_pcdata;
926 sg_platf_new_trace(&trace);
929 void STag_surfxml_trace___connect()
931 parse_after_config();
932 s_sg_platf_trace_connect_cbarg_t trace_connect;
933 memset(&trace_connect,0,sizeof(trace_connect));
935 trace_connect.element = A_surfxml_trace___connect_element;
936 trace_connect.trace = A_surfxml_trace___connect_trace;
938 switch (A_surfxml_trace___connect_kind) {
939 case AU_surfxml_trace___connect_kind:
940 case A_surfxml_trace___connect_kind_SPEED:
941 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
943 case A_surfxml_trace___connect_kind_BANDWIDTH:
944 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
946 case A_surfxml_trace___connect_kind_HOST___AVAIL:
947 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
949 case A_surfxml_trace___connect_kind_LATENCY:
950 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
952 case A_surfxml_trace___connect_kind_LINK___AVAIL:
953 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
956 surf_parse_error("Invalid trace kind");
959 sg_platf_trace_connect(&trace_connect);
962 void STag_surfxml_AS()
964 AX_surfxml_zone_id = AX_surfxml_AS_id;
965 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
969 void ETag_surfxml_AS()
974 void STag_surfxml_zone()
976 parse_after_config();
978 s_sg_platf_AS_cbarg_t AS = {A_surfxml_zone_id, (int)A_surfxml_zone_routing};
980 sg_platf_new_AS_begin(&AS);
983 void ETag_surfxml_zone()
985 sg_platf_new_AS_seal();
988 void STag_surfxml_config()
991 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
992 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
993 if (_sg_cfg_init_status == 2) {
994 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
999 void ETag_surfxml_config()
1001 xbt_dict_cursor_t cursor = nullptr;
1004 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1005 if (xbt_cfg_is_default_value(key)) {
1006 std::string cfg = std::string(key) + ":" + elem;
1007 xbt_cfg_set_parse(cfg.c_str());
1009 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
1011 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1013 xbt_dict_free(¤t_property_set);
1014 current_property_set = nullptr;
1020 void STag_surfxml_process()
1022 AX_surfxml_actor_function = AX_surfxml_process_function;
1023 STag_surfxml_actor();
1025 void STag_surfxml_actor()
1029 argv = xbt_new(char *, 1);
1030 argv[0] = xbt_strdup(A_surfxml_actor_function);
1031 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
1034 void ETag_surfxml_process()
1036 AX_surfxml_actor_host = AX_surfxml_process_host;
1037 AX_surfxml_actor_function = AX_surfxml_process_function;
1038 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
1039 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1040 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1041 ETag_surfxml_actor();
1043 void ETag_surfxml_actor()
1045 s_sg_platf_process_cbarg_t actor;
1046 memset(&actor,0,sizeof(actor));
1049 actor.argv = (const char **)argv;
1050 actor.properties = current_property_set;
1051 actor.host = A_surfxml_actor_host;
1052 actor.function = A_surfxml_actor_function;
1053 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1054 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1056 switch (A_surfxml_actor_on___failure) {
1057 case AU_surfxml_actor_on___failure:
1058 case A_surfxml_actor_on___failure_DIE:
1059 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1061 case A_surfxml_actor_on___failure_RESTART:
1062 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1065 surf_parse_error("Invalid on failure behavior");
1069 sg_platf_new_process(&actor);
1071 for (int i = 0; i != argc; ++i)
1076 current_property_set = nullptr;
1079 void STag_surfxml_argument(){
1081 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1082 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1085 void STag_surfxml_model___prop(){
1086 if (not current_model_property_set)
1087 current_model_property_set = new std::map<std::string, std::string>();
1089 current_model_property_set->insert(
1090 {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
1093 void ETag_surfxml_prop(){/* Nothing to do */}
1094 void STag_surfxml_random(){/* Nothing to do */}
1095 void ETag_surfxml_random(){/* Nothing to do */}
1096 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1097 void STag_surfxml_trace(){parse_after_config();}
1098 void ETag_surfxml_router(){/*Nothing to do*/}
1099 void ETag_surfxml_host___link(){/* Nothing to do */}
1100 void ETag_surfxml_cabinet(){/* Nothing to do */}
1101 void ETag_surfxml_peer(){/* Nothing to do */}
1102 void STag_surfxml_backbone(){/* Nothing to do */}
1103 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1104 void ETag_surfxml_argument(){/* Nothing to do */}
1105 void ETag_surfxml_model___prop(){/* Nothing to do */}
1107 /* Open and Close parse file */
1108 void surf_parse_open(const char *file)
1110 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1112 surf_parsed_filename = xbt_strdup(file);
1113 char* dir = xbt_dirname(file);
1114 surf_path.push_back(std::string(dir));
1117 surf_file_to_parse = surf_fopen(file, "r");
1118 if (surf_file_to_parse == nullptr)
1119 xbt_die("Unable to open '%s'\n", file);
1120 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1121 surf_parse__switch_to_buffer(surf_input_buffer);
1122 surf_parse_lineno = 1;
1125 void surf_parse_close()
1127 if (surf_parsed_filename) {
1128 surf_path.pop_back();
1131 free(surf_parsed_filename);
1132 surf_parsed_filename = nullptr;
1134 if (surf_file_to_parse) {
1135 surf_parse__delete_buffer(surf_input_buffer);
1136 fclose(surf_file_to_parse);
1137 surf_file_to_parse = nullptr; //Must be reset for Bypass
1141 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1142 static int _surf_parse() {
1143 return surf_parse_lex();
1146 int_f_void_t surf_parse = &_surf_parse;