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");
125 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
126 std::vector<int>* explodesRadical(std::string radicals)
128 std::vector<int>* exploded = new std::vector<int>();
131 std::vector<std::string> radical_elements;
132 boost::split(radical_elements, radicals, boost::is_any_of(","));
133 for (auto const& group : radical_elements) {
134 std::vector<std::string> radical_ends;
135 boost::split(radical_ends, group, boost::is_any_of("-"));
136 int start = surf_parse_get_int(radical_ends.front());
139 switch (radical_ends.size()) {
144 end = surf_parse_get_int(radical_ends.back());
147 surf_parse_error(std::string("Malformed radical: ") + group);
150 for (int i = start; i <= end; i++)
151 exploded->push_back(i);
157 class unit_scale : public std::unordered_map<std::string, double> {
159 using std::unordered_map<std::string, double>::unordered_map;
160 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
161 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
164 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
166 for (const auto& gen : generators) {
167 const std::string& unit = std::get<0>(gen);
168 double value = std::get<1>(gen);
169 const int base = std::get<2>(gen);
170 const bool abbrev = std::get<3>(gen);
172 std::vector<std::string> prefixes;
176 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
177 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
181 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
182 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
187 emplace(unit, value);
188 for (const auto& prefix : prefixes) {
190 emplace(prefix + unit, value);
195 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
196 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
197 std::string name, const char* error_msg, const char* default_unit)
201 double res = strtod(string, &ptr);
203 surf_parse_error(std::string("value out of range: ") + string);
205 surf_parse_error(std::string("cannot parse number:") + string);
206 if (ptr[0] == '\0') {
208 return res; // Ok, 0 can be unit-less
210 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
211 ptr = (char*)default_unit;
213 auto u = units.find(ptr);
214 if (u == units.end())
215 surf_parse_error(std::string("unknown unit: ") + ptr);
216 return res * u->second;
222 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
224 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
225 std::make_pair("d", 24 * 60 * 60),
226 std::make_pair("h", 60 * 60),
227 std::make_pair("m", 60),
228 std::make_pair("s", 1.0),
229 std::make_pair("ms", 1e-3),
230 std::make_pair("us", 1e-6),
231 std::make_pair("ns", 1e-9),
232 std::make_pair("ps", 1e-12)};
233 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
234 "Append 's' to your time to get seconds", "s");
237 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
239 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
240 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
241 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
242 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
245 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
247 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
248 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
249 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
250 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
253 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
255 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
256 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
257 "Append 'f' or 'flops' to your speed to get flop per second", "f");
260 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
263 std::vector<double> speed_per_pstate;
265 if (strchr(speeds, ',') == nullptr){
266 double speed = surf_parse_get_speed(speeds, entity_kind, id);
267 speed_per_pstate.push_back(speed);
269 std::vector<std::string> pstate_list;
270 boost::split(pstate_list, speeds, boost::is_any_of(","));
271 for (auto speed_str : pstate_list) {
272 boost::trim(speed_str);
273 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
274 speed_per_pstate.push_back(speed);
275 XBT_DEBUG("Speed value: %f", speed);
278 return speed_per_pstate;
282 * All the callback lists that can be overridden anywhere.
283 * (this list should probably be reduced to the bare minimum to allow the models to work)
286 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
288 /* The default current property receiver. Setup in the corresponding opening callbacks. */
289 std::map<std::string, std::string>* current_property_set = nullptr;
290 std::map<std::string, std::string>* current_model_property_set = nullptr;
291 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
293 YY_BUFFER_STATE surf_input_buffer;
294 FILE *surf_file_to_parse = nullptr;
296 /* Stuff relative to storage */
297 void STag_surfxml_storage()
300 XBT_DEBUG("STag_surfxml_storage");
301 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
304 void ETag_surfxml_storage()
306 StorageCreationArgs storage;
308 storage.properties = current_property_set;
309 current_property_set = nullptr;
311 storage.id = A_surfxml_storage_id;
312 storage.type_id = A_surfxml_storage_typeId;
313 storage.content = A_surfxml_storage_content;
314 storage.attach = A_surfxml_storage_attach;
316 sg_platf_new_storage(&storage);
318 void STag_surfxml_storage___type()
321 XBT_DEBUG("STag_surfxml_storage___type");
322 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
323 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
325 void ETag_surfxml_storage___type()
327 StorageTypeCreationArgs storage_type;
329 storage_type.properties = current_property_set;
330 current_property_set = nullptr;
332 storage_type.model_properties = current_model_property_set;
333 current_model_property_set = nullptr;
335 storage_type.content = A_surfxml_storage___type_content;
336 storage_type.id = A_surfxml_storage___type_id;
337 storage_type.model = A_surfxml_storage___type_model;
339 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
340 sg_platf_new_storage_type(&storage_type);
343 void STag_surfxml_mount()
345 XBT_DEBUG("STag_surfxml_mount");
348 void ETag_surfxml_mount()
350 MountCreationArgs mount;
352 mount.name = A_surfxml_mount_name;
353 mount.storageId = A_surfxml_mount_storageId;
354 sg_platf_new_mount(&mount);
357 void STag_surfxml_include()
359 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).");
360 parse_after_config();
361 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
362 surf_parsed_filename_stack.emplace_back(A_surfxml_include_file); // save file name
364 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
366 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
367 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
369 surf_input_buffer_stack.push_back(surf_input_buffer);
370 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
371 surf_parse_push_buffer_state(surf_input_buffer);
376 void ETag_surfxml_include() {
377 /* Nothing to do when done with reading the include tag.
378 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
381 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
383 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
384 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
385 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
386 * error message in that case.
388 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
389 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
390 * on a line. One day maybe, if the maya allow it.
392 int ETag_surfxml_include_state()
395 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
397 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
400 // Yeah, we were in an <include> Restore state and proceed.
401 fclose(surf_file_to_parse);
402 surf_file_to_parse_stack.pop_back();
403 surf_parse_pop_buffer_state();
404 surf_input_buffer_stack.pop_back();
406 // Restore the filename for error messages
407 surf_parsed_filename_stack.pop_back();
412 /* Stag and Etag parse functions */
414 void STag_surfxml_platform() {
415 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
417 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
418 "You're using an ancient XML file.\n"
419 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
420 "instead of MBytes, MFlops and seconds.\n"
422 "Use simgrid_update_xml to update your file automatically. "
423 "This program is installed automatically with SimGrid, or "
424 "available in the tools/ directory of the source archive.\n"
426 "Please check also out the SURF section of the ChangeLog for "
427 "the 3.1 version for more information. \n"
429 "Last, do not forget to also update your values for "
430 "the calls to MSG_task_create (if any).");
431 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
432 "You're using an old XML file.\n"
433 "Use simgrid_update_xml to update your file automatically. "
434 "This program is installed automatically with SimGrid, or "
435 "available in the tools/ directory of the source archive.");
436 xbt_assert((version >= 4.0),
437 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
438 "Changes introduced in SimGrid 3.13:\n"
439 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
440 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
441 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
442 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
444 "Use simgrid_update_xml to update your file automatically. "
445 "This program is installed automatically with SimGrid, or "
446 "available in the tools/ directory of the source archive.",
447 surf_parsed_filename(), version);
449 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
450 "That's fine, the new version is backward compatible. \n\n"
451 "Use simgrid_update_xml to update your file automatically. "
452 "This program is installed automatically with SimGrid, or "
453 "available in the tools/ directory of the source archive.",
454 version, surf_parsed_filename());
456 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
457 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
458 "Please update your code, or use another, more adapted, file.",
459 surf_parsed_filename(), version);
463 void ETag_surfxml_platform(){
467 void STag_surfxml_host(){
469 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
472 void STag_surfxml_prop()
474 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
475 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
476 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
478 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
480 if (not current_property_set)
481 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
482 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
483 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
484 current_property_set);
488 void ETag_surfxml_host() {
489 s_sg_platf_host_cbarg_t host;
490 memset(&host,0,sizeof(host));
492 host.properties = current_property_set;
493 current_property_set = nullptr;
495 host.id = A_surfxml_host_id;
497 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
499 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
500 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
501 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
502 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
503 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
504 host.coord = A_surfxml_host_coordinates;
506 sg_platf_new_host(&host);
509 void STag_surfxml_host___link(){
510 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
511 HostLinkCreationArgs host_link;
513 host_link.id = A_surfxml_host___link_id;
514 host_link.link_up = A_surfxml_host___link_up;
515 host_link.link_down = A_surfxml_host___link_down;
516 sg_platf_new_hostlink(&host_link);
519 void STag_surfxml_router(){
520 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
523 void ETag_surfxml_cluster(){
524 ClusterCreationArgs cluster;
525 cluster.properties = current_property_set;
526 current_property_set = nullptr;
528 cluster.id = A_surfxml_cluster_id;
529 cluster.prefix = A_surfxml_cluster_prefix;
530 cluster.suffix = A_surfxml_cluster_suffix;
531 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
532 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
533 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
534 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
535 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
536 if(strcmp(A_surfxml_cluster_bb___bw,""))
537 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
538 if(strcmp(A_surfxml_cluster_bb___lat,""))
539 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
540 if(strcmp(A_surfxml_cluster_limiter___link,""))
541 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
542 if(strcmp(A_surfxml_cluster_loopback___bw,""))
543 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
544 if(strcmp(A_surfxml_cluster_loopback___lat,""))
545 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
547 switch(AX_surfxml_cluster_topology){
548 case A_surfxml_cluster_topology_FLAT:
549 cluster.topology= SURF_CLUSTER_FLAT ;
551 case A_surfxml_cluster_topology_TORUS:
552 cluster.topology= SURF_CLUSTER_TORUS ;
554 case A_surfxml_cluster_topology_FAT___TREE:
555 cluster.topology = SURF_CLUSTER_FAT_TREE;
557 case A_surfxml_cluster_topology_DRAGONFLY:
558 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
561 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
564 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
565 cluster.router_id = A_surfxml_cluster_router___id;
567 switch (AX_surfxml_cluster_sharing___policy) {
568 case A_surfxml_cluster_sharing___policy_SHARED:
569 cluster.sharing_policy = SURF_LINK_SHARED;
571 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
572 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
574 case A_surfxml_cluster_sharing___policy_FATPIPE:
575 cluster.sharing_policy = SURF_LINK_FATPIPE;
578 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
581 switch (AX_surfxml_cluster_bb___sharing___policy) {
582 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
583 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
585 case A_surfxml_cluster_bb___sharing___policy_SHARED:
586 cluster.bb_sharing_policy = SURF_LINK_SHARED;
589 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
593 sg_platf_new_cluster(&cluster);
596 void STag_surfxml_cluster(){
598 parse_after_config();
599 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
602 void STag_surfxml_cabinet(){
603 parse_after_config();
604 CabinetCreationArgs cabinet;
605 cabinet.id = A_surfxml_cabinet_id;
606 cabinet.prefix = A_surfxml_cabinet_prefix;
607 cabinet.suffix = A_surfxml_cabinet_suffix;
608 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
609 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
610 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
611 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
613 sg_platf_new_cabinet(&cabinet);
616 void STag_surfxml_peer(){
617 parse_after_config();
618 PeerCreationArgs peer;
620 peer.id = std::string(A_surfxml_peer_id);
621 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
622 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
623 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
624 peer.coord = A_surfxml_peer_coordinates;
625 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
626 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
628 if (A_surfxml_peer_lat[0] != '\0')
629 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
632 sg_platf_new_peer(&peer);
635 void STag_surfxml_link(){
637 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
640 void ETag_surfxml_link(){
641 LinkCreationArgs link;
643 link.properties = current_property_set;
644 current_property_set = nullptr;
646 link.id = std::string(A_surfxml_link_id);
647 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
648 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
649 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
650 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
651 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
653 switch (A_surfxml_link_sharing___policy) {
654 case A_surfxml_link_sharing___policy_SHARED:
655 link.policy = SURF_LINK_SHARED;
657 case A_surfxml_link_sharing___policy_FATPIPE:
658 link.policy = SURF_LINK_FATPIPE;
660 case A_surfxml_link_sharing___policy_FULLDUPLEX:
661 link.policy = SURF_LINK_FULLDUPLEX;
664 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
668 sg_platf_new_link(&link);
671 void STag_surfxml_link___ctn()
673 simgrid::surf::LinkImpl* link = nullptr;
674 switch (A_surfxml_link___ctn_direction) {
675 case AU_surfxml_link___ctn_direction:
676 case A_surfxml_link___ctn_direction_NONE:
677 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
679 case A_surfxml_link___ctn_direction_UP:
680 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
682 case A_surfxml_link___ctn_direction_DOWN:
683 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
686 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
690 const char* dirname = "";
691 switch (A_surfxml_link___ctn_direction) {
692 case A_surfxml_link___ctn_direction_UP:
693 dirname = " (upward)";
695 case A_surfxml_link___ctn_direction_DOWN:
696 dirname = " (downward)";
701 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
702 parsed_link_list.push_back(link);
705 void ETag_surfxml_backbone(){
706 LinkCreationArgs link;
708 link.properties = nullptr;
709 link.id = std::string(A_surfxml_backbone_id);
710 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
711 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
712 link.policy = SURF_LINK_SHARED;
714 sg_platf_new_link(&link);
715 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
718 void STag_surfxml_route(){
719 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
720 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
723 void STag_surfxml_ASroute(){
724 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
725 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
727 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
728 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
730 void STag_surfxml_zoneRoute(){
731 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
732 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
733 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
734 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
737 void STag_surfxml_bypassRoute(){
738 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
739 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
742 void STag_surfxml_bypassASroute(){
743 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
744 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
745 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
746 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
748 void STag_surfxml_bypassZoneRoute(){
749 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
750 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
751 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
752 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
755 void ETag_surfxml_route(){
756 s_sg_platf_route_cbarg_t route;
757 memset(&route,0,sizeof(route));
759 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
760 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
761 route.gw_src = nullptr;
762 route.gw_dst = nullptr;
763 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
764 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
766 for (auto const& link : parsed_link_list)
767 route.link_list->push_back(link);
768 parsed_link_list.clear();
770 sg_platf_new_route(&route);
771 delete route.link_list;
774 void ETag_surfxml_ASroute()
776 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
777 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
778 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
779 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
780 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
781 ETag_surfxml_zoneRoute();
783 void ETag_surfxml_zoneRoute()
785 s_sg_platf_route_cbarg_t ASroute;
786 memset(&ASroute,0,sizeof(ASroute));
788 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
789 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
791 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
792 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
794 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
796 for (auto const& link : parsed_link_list)
797 ASroute.link_list->push_back(link);
798 parsed_link_list.clear();
800 switch (A_surfxml_zoneRoute_symmetrical) {
801 case AU_surfxml_zoneRoute_symmetrical:
802 case A_surfxml_zoneRoute_symmetrical_YES:
803 ASroute.symmetrical = true;
805 case A_surfxml_zoneRoute_symmetrical_NO:
806 ASroute.symmetrical = false;
812 sg_platf_new_route(&ASroute);
813 delete ASroute.link_list;
816 void ETag_surfxml_bypassRoute(){
817 s_sg_platf_route_cbarg_t route;
818 memset(&route,0,sizeof(route));
820 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
821 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
822 route.gw_src = nullptr;
823 route.gw_dst = nullptr;
824 route.symmetrical = false;
825 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
827 for (auto const& link : parsed_link_list)
828 route.link_list->push_back(link);
829 parsed_link_list.clear();
831 sg_platf_new_bypassRoute(&route);
832 delete route.link_list;
835 void ETag_surfxml_bypassASroute()
837 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
838 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
839 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
840 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
841 ETag_surfxml_bypassZoneRoute();
843 void ETag_surfxml_bypassZoneRoute()
845 s_sg_platf_route_cbarg_t ASroute;
846 memset(&ASroute,0,sizeof(ASroute));
848 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
849 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
850 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
851 for (auto const& link : parsed_link_list)
852 ASroute.link_list->push_back(link);
853 parsed_link_list.clear();
855 ASroute.symmetrical = false;
857 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
858 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
860 sg_platf_new_bypassRoute(&ASroute);
861 delete ASroute.link_list;
864 void ETag_surfxml_trace(){
865 TraceCreationArgs trace;
867 trace.id = A_surfxml_trace_id;
868 trace.file = A_surfxml_trace_file;
869 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
870 trace.pc_data = surfxml_pcdata;
872 sg_platf_new_trace(&trace);
875 void STag_surfxml_trace___connect()
877 parse_after_config();
878 TraceConnectCreationArgs trace_connect;
880 trace_connect.element = A_surfxml_trace___connect_element;
881 trace_connect.trace = A_surfxml_trace___connect_trace;
883 switch (A_surfxml_trace___connect_kind) {
884 case AU_surfxml_trace___connect_kind:
885 case A_surfxml_trace___connect_kind_SPEED:
886 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
888 case A_surfxml_trace___connect_kind_BANDWIDTH:
889 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
891 case A_surfxml_trace___connect_kind_HOST___AVAIL:
892 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
894 case A_surfxml_trace___connect_kind_LATENCY:
895 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
897 case A_surfxml_trace___connect_kind_LINK___AVAIL:
898 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
901 surf_parse_error("Invalid trace kind");
904 sg_platf_trace_connect(&trace_connect);
907 void STag_surfxml_AS()
909 AX_surfxml_zone_id = AX_surfxml_AS_id;
910 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
914 void ETag_surfxml_AS()
919 void STag_surfxml_zone()
921 parse_after_config();
923 ZoneCreationArgs zone;
924 zone.id = A_surfxml_zone_id;
925 zone.routing = static_cast<int>(A_surfxml_zone_routing);
927 sg_platf_new_Zone_begin(&zone);
930 void ETag_surfxml_zone()
932 sg_platf_new_Zone_seal();
935 void STag_surfxml_config()
938 xbt_assert(current_property_set == nullptr,
939 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
940 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
941 if (_sg_cfg_init_status == 2) {
942 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
947 void ETag_surfxml_config()
949 for (auto const& elm : *current_property_set) {
950 if (xbt_cfg_is_default_value(elm.first.c_str())) {
951 std::string cfg = elm.first + ":" + elm.second;
952 xbt_cfg_set_parse(cfg.c_str());
954 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
956 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
958 delete current_property_set;
959 current_property_set = nullptr;
965 void STag_surfxml_process()
967 AX_surfxml_actor_function = AX_surfxml_process_function;
968 STag_surfxml_actor();
971 void STag_surfxml_actor()
975 argv = xbt_new(char *, 1);
976 argv[0] = xbt_strdup(A_surfxml_actor_function);
977 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
980 void ETag_surfxml_process()
982 AX_surfxml_actor_host = AX_surfxml_process_host;
983 AX_surfxml_actor_function = AX_surfxml_process_function;
984 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
985 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
986 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
987 ETag_surfxml_actor();
990 void ETag_surfxml_actor()
992 s_sg_platf_process_cbarg_t actor;
993 memset(&actor,0,sizeof(actor));
995 actor.properties = current_property_set;
996 current_property_set = nullptr;
999 actor.argv = (const char **)argv;
1000 actor.host = A_surfxml_actor_host;
1001 actor.function = A_surfxml_actor_function;
1002 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1003 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1005 switch (A_surfxml_actor_on___failure) {
1006 case AU_surfxml_actor_on___failure:
1007 case A_surfxml_actor_on___failure_DIE:
1008 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1010 case A_surfxml_actor_on___failure_RESTART:
1011 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1014 surf_parse_error("Invalid on failure behavior");
1018 sg_platf_new_process(&actor);
1020 for (int i = 0; i != argc; ++i)
1026 void STag_surfxml_argument(){
1028 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1029 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1032 void STag_surfxml_model___prop(){
1033 if (not current_model_property_set)
1034 current_model_property_set = new std::map<std::string, std::string>();
1036 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1039 void ETag_surfxml_prop(){/* Nothing to do */}
1040 void STag_surfxml_random(){/* Nothing to do */}
1041 void ETag_surfxml_random(){/* Nothing to do */}
1042 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1043 void STag_surfxml_trace(){parse_after_config();}
1044 void ETag_surfxml_router(){/*Nothing to do*/}
1045 void ETag_surfxml_host___link(){/* Nothing to do */}
1046 void ETag_surfxml_cabinet(){/* Nothing to do */}
1047 void ETag_surfxml_peer(){/* Nothing to do */}
1048 void STag_surfxml_backbone(){/* Nothing to do */}
1049 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1050 void ETag_surfxml_argument(){/* Nothing to do */}
1051 void ETag_surfxml_model___prop(){/* Nothing to do */}
1053 /* Open and Close parse file */
1054 void surf_parse_open(const char *file)
1056 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1058 surf_parsed_filename_stack.emplace_back(file);
1059 std::string dir = simgrid::xbt::Path(file).getDirname();
1060 surf_path.push_back(dir);
1062 surf_file_to_parse = surf_fopen(file, "r");
1063 if (surf_file_to_parse == nullptr)
1064 xbt_die("Unable to open '%s'\n", file);
1065 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1066 surf_parse__switch_to_buffer(surf_input_buffer);
1067 surf_parse_lineno = 1;
1070 void surf_parse_close()
1072 if (surf_parsed_filename()) {
1073 surf_path.pop_back();
1076 surf_parsed_filename_stack.pop_back();
1078 if (surf_file_to_parse) {
1079 surf_parse__delete_buffer(surf_input_buffer);
1080 fclose(surf_file_to_parse);
1081 surf_file_to_parse = nullptr; //Must be reset for Bypass
1085 /* Call the lexer to parse the currently opened file */
1088 return surf_parse_lex();