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"
10 #include "xbt/file.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"
27 * Stuff relative to the <include> tag
29 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
30 static std::vector<FILE*> surf_file_to_parse_stack;
31 static std::vector<std::string> surf_parsed_filename_stack;
33 static inline const char* surf_parsed_filename() // to locate parse error messages
35 return surf_parsed_filename_stack.empty() ? nullptr : surf_parsed_filename_stack.back().c_str();
38 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
43 void surf_parse_assert(bool cond, std::string msg)
46 int lineno = surf_parse_lineno;
48 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
50 xbt_die("Exiting now");
54 void surf_parse_error(std::string msg)
56 int lineno = surf_parse_lineno;
58 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
60 xbt_die("Exiting now");
63 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
65 if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
68 std::string msg = pre + hostname + post + " Existing netpoints: \n";
70 std::vector<simgrid::kernel::routing::NetPoint*> list;
71 simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
72 std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
73 return a->getName() < b->getName();
76 for (auto const& np : list) {
83 msg += "'" + np->getName() + "'";
84 if (msg.length() > 4096) {
85 msg.pop_back(); // remove trailing quote
86 msg += "...(list truncated)......";
90 surf_parse_error(msg);
93 void surf_parse_warn(std::string msg)
95 XBT_WARN("%s:%d: %s", surf_parsed_filename(), surf_parse_lineno, msg.c_str());
98 double surf_parse_get_double(std::string s)
102 } catch (std::invalid_argument& ia) {
103 surf_parse_error(s + " is not a double");
108 int surf_parse_get_int(std::string s)
112 } catch (std::invalid_argument& ia) {
113 surf_parse_error(s + " is not a double");
118 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
119 static std::vector<int>* explodesRadical(std::string radicals)
121 std::vector<int>* exploded = new std::vector<int>();
124 std::vector<std::string> radical_elements;
125 boost::split(radical_elements, radicals, boost::is_any_of(","));
126 for (auto const& group : radical_elements) {
127 std::vector<std::string> radical_ends;
128 boost::split(radical_ends, group, boost::is_any_of("-"));
129 int start = surf_parse_get_int(radical_ends.front());
132 switch (radical_ends.size()) {
137 end = surf_parse_get_int(radical_ends.back());
140 surf_parse_error(std::string("Malformed radical: ") + group);
143 for (int i = start; i <= end; i++)
144 exploded->push_back(i);
155 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
156 static double surf_parse_get_value_with_unit(const char* string, const unit_scale* units, const char* entity_kind,
157 std::string name, const char* error_msg, const char* default_unit)
162 double res = strtod(string, &ptr);
164 surf_parse_error(std::string("value out of range: ") + string);
166 surf_parse_error(std::string("cannot parse number:") + string);
167 if (ptr[0] == '\0') {
169 return res; // Ok, 0 can be unit-less
171 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
172 ptr = (char*)default_unit;
174 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
176 if (units[i].unit != nullptr)
177 res *= units[i].scale;
179 surf_parse_error(std::string("unknown unit: ") + ptr);
183 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
185 const unit_scale units[] = {{"w", 7 * 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, std::string name)
201 const unit_scale units[] = {{"EiB", pow(1024, 6)},
202 {"PiB", pow(1024, 5)},
203 {"TiB", pow(1024, 4)},
204 {"GiB", pow(1024, 3)},
205 {"MiB", pow(1024, 2)},
214 {"Eib", 0.125 * pow(1024, 6)},
215 {"Pib", 0.125 * pow(1024, 5)},
216 {"Tib", 0.125 * pow(1024, 4)},
217 {"Gib", 0.125 * pow(1024, 3)},
218 {"Mib", 0.125 * pow(1024, 2)},
219 {"Kib", 0.125 * 1024},
220 {"Eb", 0.125 * 1e18},
221 {"Pb", 0.125 * 1e15},
222 {"Tb", 0.125 * 1e12},
228 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
229 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
232 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
234 const unit_scale units[] = {{"EiBps", pow(1024, 6)},
235 {"PiBps", pow(1024, 5)},
236 {"TiBps", pow(1024, 4)},
237 {"GiBps", pow(1024, 3)},
238 {"MiBps", pow(1024, 2)},
247 {"Eibps", 0.125 * pow(1024, 6)},
248 {"Pibps", 0.125 * pow(1024, 5)},
249 {"Tibps", 0.125 * pow(1024, 4)},
250 {"Gibps", 0.125 * pow(1024, 3)},
251 {"Mibps", 0.125 * pow(1024, 2)},
252 {"Kibps", 0.125 * 1024},
253 {"Tbps", 0.125 * 1e12},
254 {"Gbps", 0.125 * 1e9},
255 {"Mbps", 0.125 * 1e6},
256 {"kbps", 0.125 * 1e3},
259 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
260 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
263 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
265 const unit_scale units[] = {{"yottaflops", 1e24}, {"Yf", 1e24}, {"zettaflops", 1e21}, {"Zf", 1e21},
266 {"exaflops", 1e18}, {"Ef", 1e18}, {"petaflops", 1e15}, {"Pf", 1e15},
267 {"teraflops", 1e12}, {"Tf", 1e12}, {"gigaflops", 1e9}, {"Gf", 1e9},
268 {"megaflops", 1e6}, {"Mf", 1e6}, {"kiloflops", 1e3}, {"kf", 1e3},
269 {"flops", 1.0}, {"f", 1.0}, {nullptr, 0}};
270 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
271 "Append 'f' or 'flops' to your speed to get flop per second", "f");
274 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
277 std::vector<double> speed_per_pstate;
279 if (strchr(speeds, ',') == nullptr){
280 double speed = surf_parse_get_speed(speeds, entity_kind, id);
281 speed_per_pstate.push_back(speed);
283 std::vector<std::string> pstate_list;
284 boost::split(pstate_list, speeds, boost::is_any_of(","));
285 for (auto speed_str : pstate_list) {
286 boost::trim(speed_str);
287 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
288 speed_per_pstate.push_back(speed);
289 XBT_DEBUG("Speed value: %f", speed);
292 return speed_per_pstate;
296 * All the callback lists that can be overridden anywhere.
297 * (this list should probably be reduced to the bare minimum to allow the models to work)
300 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
302 /* The default current property receiver. Setup in the corresponding opening callbacks. */
303 std::map<std::string, std::string>* current_property_set = nullptr;
304 std::map<std::string, std::string>* current_model_property_set = nullptr;
305 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
307 YY_BUFFER_STATE surf_input_buffer;
308 FILE *surf_file_to_parse = nullptr;
310 /* Stuff relative to storage */
311 void STag_surfxml_storage()
314 XBT_DEBUG("STag_surfxml_storage");
315 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
318 void ETag_surfxml_storage()
320 StorageCreationArgs storage;
322 storage.properties = current_property_set;
323 current_property_set = nullptr;
325 storage.id = A_surfxml_storage_id;
326 storage.type_id = A_surfxml_storage_typeId;
327 storage.content = A_surfxml_storage_content;
328 storage.attach = A_surfxml_storage_attach;
330 sg_platf_new_storage(&storage);
332 void STag_surfxml_storage___type()
335 XBT_DEBUG("STag_surfxml_storage___type");
336 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
337 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
339 void ETag_surfxml_storage___type()
341 StorageTypeCreationArgs storage_type;
343 storage_type.properties = current_property_set;
344 current_property_set = nullptr;
346 storage_type.model_properties = current_model_property_set;
347 current_model_property_set = nullptr;
349 storage_type.content = A_surfxml_storage___type_content;
350 storage_type.id = A_surfxml_storage___type_id;
351 storage_type.model = A_surfxml_storage___type_model;
353 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
354 sg_platf_new_storage_type(&storage_type);
357 void STag_surfxml_mount()
359 XBT_DEBUG("STag_surfxml_mount");
362 void ETag_surfxml_mount()
364 MountCreationArgs mount;
366 mount.name = A_surfxml_mount_name;
367 mount.storageId = A_surfxml_mount_storageId;
368 sg_platf_new_mount(&mount);
371 void STag_surfxml_include()
373 XBT_ERROR("<include> tag is deprecated, and will be removed in SimGrid v3.18. Please stop using it now (or tell us why you need it).");
374 parse_after_config();
375 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
376 surf_parsed_filename_stack.emplace_back(A_surfxml_include_file); // save file name
378 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
380 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
381 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
383 surf_input_buffer_stack.push_back(surf_input_buffer);
384 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
385 surf_parse_push_buffer_state(surf_input_buffer);
390 void ETag_surfxml_include() {
391 /* Nothing to do when done with reading the include tag.
392 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
395 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
397 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
398 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
399 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
400 * error message in that case.
402 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
403 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
404 * on a line. One day maybe, if the maya allow it.
406 int ETag_surfxml_include_state()
409 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
411 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
414 // Yeah, we were in an <include> Restore state and proceed.
415 fclose(surf_file_to_parse);
416 surf_file_to_parse_stack.pop_back();
417 surf_parse_pop_buffer_state();
418 surf_input_buffer_stack.pop_back();
420 // Restore the filename for error messages
421 surf_parsed_filename_stack.pop_back();
426 /* Stag and Etag parse functions */
428 void STag_surfxml_platform() {
429 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
431 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
432 "You're using an ancient XML file.\n"
433 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
434 "instead of MBytes, MFlops and seconds.\n"
436 "Use simgrid_update_xml to update your file automatically. "
437 "This program is installed automatically with SimGrid, or "
438 "available in the tools/ directory of the source archive.\n"
440 "Please check also out the SURF section of the ChangeLog for "
441 "the 3.1 version for more information. \n"
443 "Last, do not forget to also update your values for "
444 "the calls to MSG_task_create (if any).");
445 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
446 "You're using an old XML file.\n"
447 "Use simgrid_update_xml to update your file automatically. "
448 "This program is installed automatically with SimGrid, or "
449 "available in the tools/ directory of the source archive.");
450 xbt_assert((version >= 4.0),
451 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
452 "Changes introduced in SimGrid 3.13:\n"
453 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
454 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
455 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
456 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
458 "Use simgrid_update_xml to update your file automatically. "
459 "This program is installed automatically with SimGrid, or "
460 "available in the tools/ directory of the source archive.",
461 surf_parsed_filename(), version);
463 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
464 "That's fine, the new version is backward compatible. \n\n"
465 "Use simgrid_update_xml to update your file automatically. "
466 "This program is installed automatically with SimGrid, or "
467 "available in the tools/ directory of the source archive.",
468 version, surf_parsed_filename());
470 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
471 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
472 "Please update your code, or use another, more adapted, file.",
473 surf_parsed_filename(), version);
477 void ETag_surfxml_platform(){
481 void STag_surfxml_host(){
483 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
486 void STag_surfxml_prop()
488 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
489 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
490 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
492 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
494 if (not current_property_set)
495 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
496 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
497 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
498 current_property_set);
502 void ETag_surfxml_host() {
503 s_sg_platf_host_cbarg_t host;
504 memset(&host,0,sizeof(host));
506 host.properties = current_property_set;
507 current_property_set = nullptr;
509 host.id = A_surfxml_host_id;
511 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
513 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
514 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
515 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
516 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
517 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
518 host.coord = A_surfxml_host_coordinates;
520 sg_platf_new_host(&host);
523 void STag_surfxml_host___link(){
524 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
525 HostLinkCreationArgs host_link;
527 host_link.id = A_surfxml_host___link_id;
528 host_link.link_up = A_surfxml_host___link_up;
529 host_link.link_down = A_surfxml_host___link_down;
530 sg_platf_new_hostlink(&host_link);
533 void STag_surfxml_router(){
534 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
537 void ETag_surfxml_cluster(){
538 ClusterCreationArgs cluster;
539 cluster.properties = current_property_set;
540 current_property_set = nullptr;
542 cluster.id = A_surfxml_cluster_id;
543 cluster.prefix = A_surfxml_cluster_prefix;
544 cluster.suffix = A_surfxml_cluster_suffix;
545 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
546 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
547 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
548 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
549 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
550 if(strcmp(A_surfxml_cluster_bb___bw,""))
551 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
552 if(strcmp(A_surfxml_cluster_bb___lat,""))
553 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
554 if(strcmp(A_surfxml_cluster_limiter___link,""))
555 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
556 if(strcmp(A_surfxml_cluster_loopback___bw,""))
557 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
558 if(strcmp(A_surfxml_cluster_loopback___lat,""))
559 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
561 switch(AX_surfxml_cluster_topology){
562 case A_surfxml_cluster_topology_FLAT:
563 cluster.topology= SURF_CLUSTER_FLAT ;
565 case A_surfxml_cluster_topology_TORUS:
566 cluster.topology= SURF_CLUSTER_TORUS ;
568 case A_surfxml_cluster_topology_FAT___TREE:
569 cluster.topology = SURF_CLUSTER_FAT_TREE;
571 case A_surfxml_cluster_topology_DRAGONFLY:
572 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
575 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
578 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
579 cluster.router_id = A_surfxml_cluster_router___id;
581 switch (AX_surfxml_cluster_sharing___policy) {
582 case A_surfxml_cluster_sharing___policy_SHARED:
583 cluster.sharing_policy = SURF_LINK_SHARED;
585 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
586 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
588 case A_surfxml_cluster_sharing___policy_FATPIPE:
589 cluster.sharing_policy = SURF_LINK_FATPIPE;
592 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
595 switch (AX_surfxml_cluster_bb___sharing___policy) {
596 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
597 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
599 case A_surfxml_cluster_bb___sharing___policy_SHARED:
600 cluster.bb_sharing_policy = SURF_LINK_SHARED;
603 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
607 sg_platf_new_cluster(&cluster);
610 void STag_surfxml_cluster(){
612 parse_after_config();
613 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
616 void STag_surfxml_cabinet(){
617 parse_after_config();
618 CabinetCreationArgs cabinet;
619 cabinet.id = A_surfxml_cabinet_id;
620 cabinet.prefix = A_surfxml_cabinet_prefix;
621 cabinet.suffix = A_surfxml_cabinet_suffix;
622 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
623 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
624 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
625 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
627 sg_platf_new_cabinet(&cabinet);
630 void STag_surfxml_peer(){
631 parse_after_config();
632 PeerCreationArgs peer;
634 peer.id = std::string(A_surfxml_peer_id);
635 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
636 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
637 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
638 peer.coord = A_surfxml_peer_coordinates;
639 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
640 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
642 if (A_surfxml_peer_lat[0] != '\0')
643 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
646 sg_platf_new_peer(&peer);
649 void STag_surfxml_link(){
651 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
654 void ETag_surfxml_link(){
655 LinkCreationArgs link;
657 link.properties = current_property_set;
658 current_property_set = nullptr;
660 link.id = std::string(A_surfxml_link_id);
661 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
662 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
663 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
664 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
665 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
667 switch (A_surfxml_link_sharing___policy) {
668 case A_surfxml_link_sharing___policy_SHARED:
669 link.policy = SURF_LINK_SHARED;
671 case A_surfxml_link_sharing___policy_FATPIPE:
672 link.policy = SURF_LINK_FATPIPE;
674 case A_surfxml_link_sharing___policy_FULLDUPLEX:
675 link.policy = SURF_LINK_FULLDUPLEX;
678 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
682 sg_platf_new_link(&link);
685 void STag_surfxml_link___ctn()
687 simgrid::surf::LinkImpl* link = nullptr;
688 switch (A_surfxml_link___ctn_direction) {
689 case AU_surfxml_link___ctn_direction:
690 case A_surfxml_link___ctn_direction_NONE:
691 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
693 case A_surfxml_link___ctn_direction_UP:
694 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
696 case A_surfxml_link___ctn_direction_DOWN:
697 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
700 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
704 const char* dirname = "";
705 switch (A_surfxml_link___ctn_direction) {
706 case A_surfxml_link___ctn_direction_UP:
707 dirname = " (upward)";
709 case A_surfxml_link___ctn_direction_DOWN:
710 dirname = " (downward)";
715 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
716 parsed_link_list.push_back(link);
719 void ETag_surfxml_backbone(){
720 LinkCreationArgs link;
722 link.properties = nullptr;
723 link.id = std::string(A_surfxml_backbone_id);
724 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
725 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
726 link.policy = SURF_LINK_SHARED;
728 sg_platf_new_link(&link);
729 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
732 void STag_surfxml_route(){
733 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
734 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
737 void STag_surfxml_ASroute(){
738 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
739 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
741 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
742 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
744 void STag_surfxml_zoneRoute(){
745 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
746 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
747 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
748 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
751 void STag_surfxml_bypassRoute(){
752 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
753 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
756 void STag_surfxml_bypassASroute(){
757 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
758 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
759 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
760 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
762 void STag_surfxml_bypassZoneRoute(){
763 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
764 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
765 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
766 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
769 void ETag_surfxml_route(){
770 s_sg_platf_route_cbarg_t route;
771 memset(&route,0,sizeof(route));
773 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
774 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
775 route.gw_src = nullptr;
776 route.gw_dst = nullptr;
777 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
778 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
780 for (auto const& link : parsed_link_list)
781 route.link_list->push_back(link);
782 parsed_link_list.clear();
784 sg_platf_new_route(&route);
785 delete route.link_list;
788 void ETag_surfxml_ASroute()
790 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
791 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
792 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
793 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
794 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
795 ETag_surfxml_zoneRoute();
797 void ETag_surfxml_zoneRoute()
799 s_sg_platf_route_cbarg_t ASroute;
800 memset(&ASroute,0,sizeof(ASroute));
802 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
803 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
805 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
806 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
808 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
810 for (auto const& link : parsed_link_list)
811 ASroute.link_list->push_back(link);
812 parsed_link_list.clear();
814 switch (A_surfxml_zoneRoute_symmetrical) {
815 case AU_surfxml_zoneRoute_symmetrical:
816 case A_surfxml_zoneRoute_symmetrical_YES:
817 ASroute.symmetrical = true;
819 case A_surfxml_zoneRoute_symmetrical_NO:
820 ASroute.symmetrical = false;
826 sg_platf_new_route(&ASroute);
827 delete ASroute.link_list;
830 void ETag_surfxml_bypassRoute(){
831 s_sg_platf_route_cbarg_t route;
832 memset(&route,0,sizeof(route));
834 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
835 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
836 route.gw_src = nullptr;
837 route.gw_dst = nullptr;
838 route.symmetrical = false;
839 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
841 for (auto const& link : parsed_link_list)
842 route.link_list->push_back(link);
843 parsed_link_list.clear();
845 sg_platf_new_bypassRoute(&route);
846 delete route.link_list;
849 void ETag_surfxml_bypassASroute()
851 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
852 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
853 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
854 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
855 ETag_surfxml_bypassZoneRoute();
857 void ETag_surfxml_bypassZoneRoute()
859 s_sg_platf_route_cbarg_t ASroute;
860 memset(&ASroute,0,sizeof(ASroute));
862 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
863 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
864 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
865 for (auto const& link : parsed_link_list)
866 ASroute.link_list->push_back(link);
867 parsed_link_list.clear();
869 ASroute.symmetrical = false;
871 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
872 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
874 sg_platf_new_bypassRoute(&ASroute);
875 delete ASroute.link_list;
878 void ETag_surfxml_trace(){
879 TraceCreationArgs trace;
881 trace.id = A_surfxml_trace_id;
882 trace.file = A_surfxml_trace_file;
883 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
884 trace.pc_data = surfxml_pcdata;
886 sg_platf_new_trace(&trace);
889 void STag_surfxml_trace___connect()
891 parse_after_config();
892 TraceConnectCreationArgs trace_connect;
894 trace_connect.element = A_surfxml_trace___connect_element;
895 trace_connect.trace = A_surfxml_trace___connect_trace;
897 switch (A_surfxml_trace___connect_kind) {
898 case AU_surfxml_trace___connect_kind:
899 case A_surfxml_trace___connect_kind_SPEED:
900 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
902 case A_surfxml_trace___connect_kind_BANDWIDTH:
903 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
905 case A_surfxml_trace___connect_kind_HOST___AVAIL:
906 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
908 case A_surfxml_trace___connect_kind_LATENCY:
909 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
911 case A_surfxml_trace___connect_kind_LINK___AVAIL:
912 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
915 surf_parse_error("Invalid trace kind");
918 sg_platf_trace_connect(&trace_connect);
921 void STag_surfxml_AS()
923 AX_surfxml_zone_id = AX_surfxml_AS_id;
924 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
928 void ETag_surfxml_AS()
933 void STag_surfxml_zone()
935 parse_after_config();
937 ZoneCreationArgs zone;
938 zone.id = A_surfxml_zone_id;
939 zone.routing = static_cast<int>(A_surfxml_zone_routing);
941 sg_platf_new_Zone_begin(&zone);
944 void ETag_surfxml_zone()
946 sg_platf_new_Zone_seal();
949 void STag_surfxml_config()
952 xbt_assert(current_property_set == nullptr,
953 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
954 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
955 if (_sg_cfg_init_status == 2) {
956 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
961 void ETag_surfxml_config()
963 for (auto const& elm : *current_property_set) {
964 if (xbt_cfg_is_default_value(elm.first.c_str())) {
965 std::string cfg = elm.first + ":" + elm.second;
966 xbt_cfg_set_parse(cfg.c_str());
968 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
970 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
972 delete current_property_set;
973 current_property_set = nullptr;
979 void STag_surfxml_process()
981 AX_surfxml_actor_function = AX_surfxml_process_function;
982 STag_surfxml_actor();
985 void STag_surfxml_actor()
989 argv = xbt_new(char *, 1);
990 argv[0] = xbt_strdup(A_surfxml_actor_function);
991 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
994 void ETag_surfxml_process()
996 AX_surfxml_actor_host = AX_surfxml_process_host;
997 AX_surfxml_actor_function = AX_surfxml_process_function;
998 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
999 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1000 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1001 ETag_surfxml_actor();
1004 void ETag_surfxml_actor()
1006 s_sg_platf_process_cbarg_t actor;
1007 memset(&actor,0,sizeof(actor));
1009 actor.properties = current_property_set;
1010 current_property_set = nullptr;
1013 actor.argv = (const char **)argv;
1014 actor.host = A_surfxml_actor_host;
1015 actor.function = A_surfxml_actor_function;
1016 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1017 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1019 switch (A_surfxml_actor_on___failure) {
1020 case AU_surfxml_actor_on___failure:
1021 case A_surfxml_actor_on___failure_DIE:
1022 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1024 case A_surfxml_actor_on___failure_RESTART:
1025 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1028 surf_parse_error("Invalid on failure behavior");
1032 sg_platf_new_process(&actor);
1034 for (int i = 0; i != argc; ++i)
1040 void STag_surfxml_argument(){
1042 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1043 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1046 void STag_surfxml_model___prop(){
1047 if (not current_model_property_set)
1048 current_model_property_set = new std::map<std::string, std::string>();
1050 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1053 void ETag_surfxml_prop(){/* Nothing to do */}
1054 void STag_surfxml_random(){/* Nothing to do */}
1055 void ETag_surfxml_random(){/* Nothing to do */}
1056 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1057 void STag_surfxml_trace(){parse_after_config();}
1058 void ETag_surfxml_router(){/*Nothing to do*/}
1059 void ETag_surfxml_host___link(){/* Nothing to do */}
1060 void ETag_surfxml_cabinet(){/* Nothing to do */}
1061 void ETag_surfxml_peer(){/* Nothing to do */}
1062 void STag_surfxml_backbone(){/* Nothing to do */}
1063 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1064 void ETag_surfxml_argument(){/* Nothing to do */}
1065 void ETag_surfxml_model___prop(){/* Nothing to do */}
1067 /* Open and Close parse file */
1068 void surf_parse_open(const char *file)
1070 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1072 surf_parsed_filename_stack.emplace_back(file);
1073 std::string dir = simgrid::xbt::Path(file).getDirname();
1074 surf_path.push_back(dir);
1076 surf_file_to_parse = surf_fopen(file, "r");
1077 if (surf_file_to_parse == nullptr)
1078 xbt_die("Unable to open '%s'\n", file);
1079 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1080 surf_parse__switch_to_buffer(surf_input_buffer);
1081 surf_parse_lineno = 1;
1084 void surf_parse_close()
1086 if (surf_parsed_filename()) {
1087 surf_path.pop_back();
1090 surf_parsed_filename_stack.pop_back();
1092 if (surf_file_to_parse) {
1093 surf_parse__delete_buffer(surf_input_buffer);
1094 fclose(surf_file_to_parse);
1095 surf_file_to_parse = nullptr; //Must be reset for Bypass
1099 /* Call the lexer to parse the currently opened file */
1102 return surf_parse_lex();