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>
16 #include <initializer_list>
19 #include <unordered_map>
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
26 int ETag_surfxml_include_state();
28 #include "simgrid_dtd.c"
31 * Stuff relative to the <include> tag
33 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
34 static std::vector<FILE*> surf_file_to_parse_stack;
35 static std::vector<std::string> surf_parsed_filename_stack;
37 static inline const char* surf_parsed_filename() // to locate parse error messages
39 return surf_parsed_filename_stack.empty() ? nullptr : surf_parsed_filename_stack.back().c_str();
42 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
47 void surf_parse_assert(bool cond, std::string msg)
50 int lineno = surf_parse_lineno;
52 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
54 xbt_die("Exiting now");
58 void surf_parse_error(std::string msg)
60 int lineno = surf_parse_lineno;
62 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
64 xbt_die("Exiting now");
67 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
69 if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
72 std::string msg = pre + hostname + post + " Existing netpoints: \n";
74 std::vector<simgrid::kernel::routing::NetPoint*> list;
75 simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
76 std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
77 return a->getName() < b->getName();
80 for (auto const& np : list) {
87 msg += "'" + np->getName() + "'";
88 if (msg.length() > 4096) {
89 msg.pop_back(); // remove trailing quote
90 msg += "...(list truncated)......";
94 surf_parse_error(msg);
97 void surf_parse_warn(std::string msg)
99 XBT_WARN("%s:%d: %s", surf_parsed_filename(), surf_parse_lineno, msg.c_str());
102 double surf_parse_get_double(std::string s)
106 } catch (std::invalid_argument& ia) {
107 surf_parse_error(s + " is not a double");
112 int surf_parse_get_int(std::string s)
116 } catch (std::invalid_argument& ia) {
117 surf_parse_error(s + " is not a double");
122 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
123 static std::vector<int>* explodesRadical(std::string radicals)
125 std::vector<int>* exploded = new std::vector<int>();
128 std::vector<std::string> radical_elements;
129 boost::split(radical_elements, radicals, boost::is_any_of(","));
130 for (auto const& group : radical_elements) {
131 std::vector<std::string> radical_ends;
132 boost::split(radical_ends, group, boost::is_any_of("-"));
133 int start = surf_parse_get_int(radical_ends.front());
136 switch (radical_ends.size()) {
141 end = surf_parse_get_int(radical_ends.back());
144 surf_parse_error(std::string("Malformed radical: ") + group);
147 for (int i = start; i <= end; i++)
148 exploded->push_back(i);
155 class unit_scale : public std::unordered_map<std::string, double> {
157 using std::unordered_map<std::string, double>::unordered_map;
158 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
159 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
162 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
164 for (const auto& gen : generators) {
165 const std::string& unit = std::get<0>(gen);
166 double value = std::get<1>(gen);
167 const int base = std::get<2>(gen);
168 const bool abbrev = std::get<3>(gen);
170 std::vector<std::string> prefixes;
174 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
175 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
179 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
180 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
185 emplace(unit, value);
186 for (const auto& prefix : prefixes) {
188 emplace(prefix + unit, value);
194 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
195 static double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
196 std::string name, const char* error_msg, const char* default_unit)
200 double res = strtod(string, &ptr);
202 surf_parse_error(std::string("value out of range: ") + string);
204 surf_parse_error(std::string("cannot parse number:") + string);
205 if (ptr[0] == '\0') {
207 return res; // Ok, 0 can be unit-less
209 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
210 ptr = (char*)default_unit;
212 auto u = units.find(ptr);
213 if (u == units.end())
214 surf_parse_error(std::string("unknown unit: ") + ptr);
215 return res * u->second;
218 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
220 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
221 std::make_pair("d", 24 * 60 * 60),
222 std::make_pair("h", 60 * 60),
223 std::make_pair("m", 60),
224 std::make_pair("s", 1.0),
225 std::make_pair("ms", 1e-3),
226 std::make_pair("us", 1e-6),
227 std::make_pair("ns", 1e-9),
228 std::make_pair("ps", 1e-12)};
229 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
230 "Append 's' to your time to get seconds", "s");
233 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
235 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
236 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
237 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
238 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
241 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
243 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
244 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
245 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
246 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
249 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
251 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
252 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
253 "Append 'f' or 'flops' to your speed to get flop per second", "f");
256 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
259 std::vector<double> speed_per_pstate;
261 if (strchr(speeds, ',') == nullptr){
262 double speed = surf_parse_get_speed(speeds, entity_kind, id);
263 speed_per_pstate.push_back(speed);
265 std::vector<std::string> pstate_list;
266 boost::split(pstate_list, speeds, boost::is_any_of(","));
267 for (auto speed_str : pstate_list) {
268 boost::trim(speed_str);
269 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
270 speed_per_pstate.push_back(speed);
271 XBT_DEBUG("Speed value: %f", speed);
274 return speed_per_pstate;
278 * All the callback lists that can be overridden anywhere.
279 * (this list should probably be reduced to the bare minimum to allow the models to work)
282 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
284 /* The default current property receiver. Setup in the corresponding opening callbacks. */
285 std::map<std::string, std::string>* current_property_set = nullptr;
286 std::map<std::string, std::string>* current_model_property_set = nullptr;
287 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
289 YY_BUFFER_STATE surf_input_buffer;
290 FILE *surf_file_to_parse = nullptr;
292 /* Stuff relative to storage */
293 void STag_surfxml_storage()
296 XBT_DEBUG("STag_surfxml_storage");
297 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
300 void ETag_surfxml_storage()
302 StorageCreationArgs storage;
304 storage.properties = current_property_set;
305 current_property_set = nullptr;
307 storage.id = A_surfxml_storage_id;
308 storage.type_id = A_surfxml_storage_typeId;
309 storage.content = A_surfxml_storage_content;
310 storage.attach = A_surfxml_storage_attach;
312 sg_platf_new_storage(&storage);
314 void STag_surfxml_storage___type()
317 XBT_DEBUG("STag_surfxml_storage___type");
318 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
319 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
321 void ETag_surfxml_storage___type()
323 StorageTypeCreationArgs storage_type;
325 storage_type.properties = current_property_set;
326 current_property_set = nullptr;
328 storage_type.model_properties = current_model_property_set;
329 current_model_property_set = nullptr;
331 storage_type.content = A_surfxml_storage___type_content;
332 storage_type.id = A_surfxml_storage___type_id;
333 storage_type.model = A_surfxml_storage___type_model;
335 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
336 sg_platf_new_storage_type(&storage_type);
339 void STag_surfxml_mount()
341 XBT_DEBUG("STag_surfxml_mount");
344 void ETag_surfxml_mount()
346 MountCreationArgs mount;
348 mount.name = A_surfxml_mount_name;
349 mount.storageId = A_surfxml_mount_storageId;
350 sg_platf_new_mount(&mount);
353 void STag_surfxml_include()
355 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).");
356 parse_after_config();
357 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
358 surf_parsed_filename_stack.emplace_back(A_surfxml_include_file); // save file name
360 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
362 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
363 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
365 surf_input_buffer_stack.push_back(surf_input_buffer);
366 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
367 surf_parse_push_buffer_state(surf_input_buffer);
372 void ETag_surfxml_include() {
373 /* Nothing to do when done with reading the include tag.
374 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
377 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
379 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
380 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
381 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
382 * error message in that case.
384 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
385 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
386 * on a line. One day maybe, if the maya allow it.
388 int ETag_surfxml_include_state()
391 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
393 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
396 // Yeah, we were in an <include> Restore state and proceed.
397 fclose(surf_file_to_parse);
398 surf_file_to_parse_stack.pop_back();
399 surf_parse_pop_buffer_state();
400 surf_input_buffer_stack.pop_back();
402 // Restore the filename for error messages
403 surf_parsed_filename_stack.pop_back();
408 /* Stag and Etag parse functions */
410 void STag_surfxml_platform() {
411 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
413 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
414 "You're using an ancient XML file.\n"
415 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
416 "instead of MBytes, MFlops and seconds.\n"
418 "Use simgrid_update_xml to update your file automatically. "
419 "This program is installed automatically with SimGrid, or "
420 "available in the tools/ directory of the source archive.\n"
422 "Please check also out the SURF section of the ChangeLog for "
423 "the 3.1 version for more information. \n"
425 "Last, do not forget to also update your values for "
426 "the calls to MSG_task_create (if any).");
427 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
428 "You're using an old XML file.\n"
429 "Use simgrid_update_xml to update your file automatically. "
430 "This program is installed automatically with SimGrid, or "
431 "available in the tools/ directory of the source archive.");
432 xbt_assert((version >= 4.0),
433 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
434 "Changes introduced in SimGrid 3.13:\n"
435 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
436 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
437 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
438 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
440 "Use simgrid_update_xml to update your file automatically. "
441 "This program is installed automatically with SimGrid, or "
442 "available in the tools/ directory of the source archive.",
443 surf_parsed_filename(), version);
445 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
446 "That's fine, the new version is backward compatible. \n\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 version, surf_parsed_filename());
452 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
453 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
454 "Please update your code, or use another, more adapted, file.",
455 surf_parsed_filename(), version);
459 void ETag_surfxml_platform(){
463 void STag_surfxml_host(){
465 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
468 void STag_surfxml_prop()
470 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
471 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
472 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
474 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
476 if (not current_property_set)
477 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
478 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
479 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
480 current_property_set);
484 void ETag_surfxml_host() {
485 s_sg_platf_host_cbarg_t host;
486 memset(&host,0,sizeof(host));
488 host.properties = current_property_set;
489 current_property_set = nullptr;
491 host.id = A_surfxml_host_id;
493 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
495 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
496 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
497 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
498 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
499 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
500 host.coord = A_surfxml_host_coordinates;
502 sg_platf_new_host(&host);
505 void STag_surfxml_host___link(){
506 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
507 HostLinkCreationArgs host_link;
509 host_link.id = A_surfxml_host___link_id;
510 host_link.link_up = A_surfxml_host___link_up;
511 host_link.link_down = A_surfxml_host___link_down;
512 sg_platf_new_hostlink(&host_link);
515 void STag_surfxml_router(){
516 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
519 void ETag_surfxml_cluster(){
520 ClusterCreationArgs cluster;
521 cluster.properties = current_property_set;
522 current_property_set = nullptr;
524 cluster.id = A_surfxml_cluster_id;
525 cluster.prefix = A_surfxml_cluster_prefix;
526 cluster.suffix = A_surfxml_cluster_suffix;
527 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
528 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
529 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
530 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
531 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
532 if(strcmp(A_surfxml_cluster_bb___bw,""))
533 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
534 if(strcmp(A_surfxml_cluster_bb___lat,""))
535 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
536 if(strcmp(A_surfxml_cluster_limiter___link,""))
537 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
538 if(strcmp(A_surfxml_cluster_loopback___bw,""))
539 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
540 if(strcmp(A_surfxml_cluster_loopback___lat,""))
541 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
543 switch(AX_surfxml_cluster_topology){
544 case A_surfxml_cluster_topology_FLAT:
545 cluster.topology= SURF_CLUSTER_FLAT ;
547 case A_surfxml_cluster_topology_TORUS:
548 cluster.topology= SURF_CLUSTER_TORUS ;
550 case A_surfxml_cluster_topology_FAT___TREE:
551 cluster.topology = SURF_CLUSTER_FAT_TREE;
553 case A_surfxml_cluster_topology_DRAGONFLY:
554 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
557 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
560 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
561 cluster.router_id = A_surfxml_cluster_router___id;
563 switch (AX_surfxml_cluster_sharing___policy) {
564 case A_surfxml_cluster_sharing___policy_SHARED:
565 cluster.sharing_policy = SURF_LINK_SHARED;
567 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
568 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
570 case A_surfxml_cluster_sharing___policy_FATPIPE:
571 cluster.sharing_policy = SURF_LINK_FATPIPE;
574 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
577 switch (AX_surfxml_cluster_bb___sharing___policy) {
578 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
579 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
581 case A_surfxml_cluster_bb___sharing___policy_SHARED:
582 cluster.bb_sharing_policy = SURF_LINK_SHARED;
585 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
589 sg_platf_new_cluster(&cluster);
592 void STag_surfxml_cluster(){
594 parse_after_config();
595 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
598 void STag_surfxml_cabinet(){
599 parse_after_config();
600 CabinetCreationArgs cabinet;
601 cabinet.id = A_surfxml_cabinet_id;
602 cabinet.prefix = A_surfxml_cabinet_prefix;
603 cabinet.suffix = A_surfxml_cabinet_suffix;
604 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
605 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
606 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
607 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
609 sg_platf_new_cabinet(&cabinet);
612 void STag_surfxml_peer(){
613 parse_after_config();
614 PeerCreationArgs peer;
616 peer.id = std::string(A_surfxml_peer_id);
617 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
618 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
619 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
620 peer.coord = A_surfxml_peer_coordinates;
621 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
622 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
624 if (A_surfxml_peer_lat[0] != '\0')
625 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
628 sg_platf_new_peer(&peer);
631 void STag_surfxml_link(){
633 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
636 void ETag_surfxml_link(){
637 LinkCreationArgs link;
639 link.properties = current_property_set;
640 current_property_set = nullptr;
642 link.id = std::string(A_surfxml_link_id);
643 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
644 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
645 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
646 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
647 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
649 switch (A_surfxml_link_sharing___policy) {
650 case A_surfxml_link_sharing___policy_SHARED:
651 link.policy = SURF_LINK_SHARED;
653 case A_surfxml_link_sharing___policy_FATPIPE:
654 link.policy = SURF_LINK_FATPIPE;
656 case A_surfxml_link_sharing___policy_FULLDUPLEX:
657 link.policy = SURF_LINK_FULLDUPLEX;
660 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
664 sg_platf_new_link(&link);
667 void STag_surfxml_link___ctn()
669 simgrid::surf::LinkImpl* link = nullptr;
670 switch (A_surfxml_link___ctn_direction) {
671 case AU_surfxml_link___ctn_direction:
672 case A_surfxml_link___ctn_direction_NONE:
673 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
675 case A_surfxml_link___ctn_direction_UP:
676 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
678 case A_surfxml_link___ctn_direction_DOWN:
679 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
682 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
686 const char* dirname = "";
687 switch (A_surfxml_link___ctn_direction) {
688 case A_surfxml_link___ctn_direction_UP:
689 dirname = " (upward)";
691 case A_surfxml_link___ctn_direction_DOWN:
692 dirname = " (downward)";
697 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
698 parsed_link_list.push_back(link);
701 void ETag_surfxml_backbone(){
702 LinkCreationArgs link;
704 link.properties = nullptr;
705 link.id = std::string(A_surfxml_backbone_id);
706 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
707 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
708 link.policy = SURF_LINK_SHARED;
710 sg_platf_new_link(&link);
711 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
714 void STag_surfxml_route(){
715 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
716 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
719 void STag_surfxml_ASroute(){
720 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
721 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
723 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
724 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
726 void STag_surfxml_zoneRoute(){
727 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
728 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
729 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
730 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
733 void STag_surfxml_bypassRoute(){
734 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
735 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
738 void STag_surfxml_bypassASroute(){
739 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
740 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
741 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
742 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
744 void STag_surfxml_bypassZoneRoute(){
745 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
746 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
747 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
748 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
751 void ETag_surfxml_route(){
752 s_sg_platf_route_cbarg_t route;
753 memset(&route,0,sizeof(route));
755 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
756 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
757 route.gw_src = nullptr;
758 route.gw_dst = nullptr;
759 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
760 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
762 for (auto const& link : parsed_link_list)
763 route.link_list->push_back(link);
764 parsed_link_list.clear();
766 sg_platf_new_route(&route);
767 delete route.link_list;
770 void ETag_surfxml_ASroute()
772 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
773 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
774 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
775 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
776 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
777 ETag_surfxml_zoneRoute();
779 void ETag_surfxml_zoneRoute()
781 s_sg_platf_route_cbarg_t ASroute;
782 memset(&ASroute,0,sizeof(ASroute));
784 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
785 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
787 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
788 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
790 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
792 for (auto const& link : parsed_link_list)
793 ASroute.link_list->push_back(link);
794 parsed_link_list.clear();
796 switch (A_surfxml_zoneRoute_symmetrical) {
797 case AU_surfxml_zoneRoute_symmetrical:
798 case A_surfxml_zoneRoute_symmetrical_YES:
799 ASroute.symmetrical = true;
801 case A_surfxml_zoneRoute_symmetrical_NO:
802 ASroute.symmetrical = false;
808 sg_platf_new_route(&ASroute);
809 delete ASroute.link_list;
812 void ETag_surfxml_bypassRoute(){
813 s_sg_platf_route_cbarg_t route;
814 memset(&route,0,sizeof(route));
816 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
817 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
818 route.gw_src = nullptr;
819 route.gw_dst = nullptr;
820 route.symmetrical = false;
821 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
823 for (auto const& link : parsed_link_list)
824 route.link_list->push_back(link);
825 parsed_link_list.clear();
827 sg_platf_new_bypassRoute(&route);
828 delete route.link_list;
831 void ETag_surfxml_bypassASroute()
833 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
834 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
835 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
836 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
837 ETag_surfxml_bypassZoneRoute();
839 void ETag_surfxml_bypassZoneRoute()
841 s_sg_platf_route_cbarg_t ASroute;
842 memset(&ASroute,0,sizeof(ASroute));
844 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
845 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
846 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
847 for (auto const& link : parsed_link_list)
848 ASroute.link_list->push_back(link);
849 parsed_link_list.clear();
851 ASroute.symmetrical = false;
853 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
854 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
856 sg_platf_new_bypassRoute(&ASroute);
857 delete ASroute.link_list;
860 void ETag_surfxml_trace(){
861 TraceCreationArgs trace;
863 trace.id = A_surfxml_trace_id;
864 trace.file = A_surfxml_trace_file;
865 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
866 trace.pc_data = surfxml_pcdata;
868 sg_platf_new_trace(&trace);
871 void STag_surfxml_trace___connect()
873 parse_after_config();
874 TraceConnectCreationArgs trace_connect;
876 trace_connect.element = A_surfxml_trace___connect_element;
877 trace_connect.trace = A_surfxml_trace___connect_trace;
879 switch (A_surfxml_trace___connect_kind) {
880 case AU_surfxml_trace___connect_kind:
881 case A_surfxml_trace___connect_kind_SPEED:
882 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
884 case A_surfxml_trace___connect_kind_BANDWIDTH:
885 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
887 case A_surfxml_trace___connect_kind_HOST___AVAIL:
888 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
890 case A_surfxml_trace___connect_kind_LATENCY:
891 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
893 case A_surfxml_trace___connect_kind_LINK___AVAIL:
894 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
897 surf_parse_error("Invalid trace kind");
900 sg_platf_trace_connect(&trace_connect);
903 void STag_surfxml_AS()
905 AX_surfxml_zone_id = AX_surfxml_AS_id;
906 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
910 void ETag_surfxml_AS()
915 void STag_surfxml_zone()
917 parse_after_config();
919 ZoneCreationArgs zone;
920 zone.id = A_surfxml_zone_id;
921 zone.routing = static_cast<int>(A_surfxml_zone_routing);
923 sg_platf_new_Zone_begin(&zone);
926 void ETag_surfxml_zone()
928 sg_platf_new_Zone_seal();
931 void STag_surfxml_config()
934 xbt_assert(current_property_set == nullptr,
935 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
936 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
937 if (_sg_cfg_init_status == 2) {
938 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
943 void ETag_surfxml_config()
945 for (auto const& elm : *current_property_set) {
946 if (xbt_cfg_is_default_value(elm.first.c_str())) {
947 std::string cfg = elm.first + ":" + elm.second;
948 xbt_cfg_set_parse(cfg.c_str());
950 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
952 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
954 delete current_property_set;
955 current_property_set = nullptr;
961 void STag_surfxml_process()
963 AX_surfxml_actor_function = AX_surfxml_process_function;
964 STag_surfxml_actor();
967 void STag_surfxml_actor()
971 argv = xbt_new(char *, 1);
972 argv[0] = xbt_strdup(A_surfxml_actor_function);
973 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
976 void ETag_surfxml_process()
978 AX_surfxml_actor_host = AX_surfxml_process_host;
979 AX_surfxml_actor_function = AX_surfxml_process_function;
980 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
981 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
982 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
983 ETag_surfxml_actor();
986 void ETag_surfxml_actor()
988 s_sg_platf_process_cbarg_t actor;
989 memset(&actor,0,sizeof(actor));
991 actor.properties = current_property_set;
992 current_property_set = nullptr;
995 actor.argv = (const char **)argv;
996 actor.host = A_surfxml_actor_host;
997 actor.function = A_surfxml_actor_function;
998 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
999 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1001 switch (A_surfxml_actor_on___failure) {
1002 case AU_surfxml_actor_on___failure:
1003 case A_surfxml_actor_on___failure_DIE:
1004 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1006 case A_surfxml_actor_on___failure_RESTART:
1007 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1010 surf_parse_error("Invalid on failure behavior");
1014 sg_platf_new_process(&actor);
1016 for (int i = 0; i != argc; ++i)
1022 void STag_surfxml_argument(){
1024 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1025 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1028 void STag_surfxml_model___prop(){
1029 if (not current_model_property_set)
1030 current_model_property_set = new std::map<std::string, std::string>();
1032 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1035 void ETag_surfxml_prop(){/* Nothing to do */}
1036 void STag_surfxml_random(){/* Nothing to do */}
1037 void ETag_surfxml_random(){/* Nothing to do */}
1038 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1039 void STag_surfxml_trace(){parse_after_config();}
1040 void ETag_surfxml_router(){/*Nothing to do*/}
1041 void ETag_surfxml_host___link(){/* Nothing to do */}
1042 void ETag_surfxml_cabinet(){/* Nothing to do */}
1043 void ETag_surfxml_peer(){/* Nothing to do */}
1044 void STag_surfxml_backbone(){/* Nothing to do */}
1045 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1046 void ETag_surfxml_argument(){/* Nothing to do */}
1047 void ETag_surfxml_model___prop(){/* Nothing to do */}
1049 /* Open and Close parse file */
1050 void surf_parse_open(const char *file)
1052 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1054 surf_parsed_filename_stack.emplace_back(file);
1055 std::string dir = simgrid::xbt::Path(file).getDirname();
1056 surf_path.push_back(dir);
1058 surf_file_to_parse = surf_fopen(file, "r");
1059 if (surf_file_to_parse == nullptr)
1060 xbt_die("Unable to open '%s'\n", file);
1061 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1062 surf_parse__switch_to_buffer(surf_input_buffer);
1063 surf_parse_lineno = 1;
1066 void surf_parse_close()
1068 if (surf_parsed_filename()) {
1069 surf_path.pop_back();
1072 surf_parsed_filename_stack.pop_back();
1074 if (surf_file_to_parse) {
1075 surf_parse__delete_buffer(surf_input_buffer);
1076 fclose(surf_file_to_parse);
1077 surf_file_to_parse = nullptr; //Must be reset for Bypass
1081 /* Call the lexer to parse the currently opened file */
1084 return surf_parse_lex();