1 /* Copyright (c) 2006-2019. 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/kernel/routing/NetPoint.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/sg_config.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "src/surf/surf_interface.hpp"
11 #include "src/surf/xml/platf_private.hpp"
12 #include "surf/surf.hpp"
13 #include "xbt/file.hpp"
15 #include <boost/algorithm/string.hpp>
16 #include <boost/algorithm/string/classification.hpp>
17 #include <boost/algorithm/string/split.hpp>
20 #include <unordered_map>
23 #include "simgrid_dtd.c"
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
27 static std::string surf_parsed_filename; // Currently parsed file (for the error messages)
28 std::vector<simgrid::kernel::resource::LinkImpl*>
29 parsed_link_list; /* temporary store of current list link of a route */
34 void surf_parse_assert(bool cond, const std::string& msg)
37 int lineno = surf_parse_lineno;
39 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename.c_str(), lineno, msg.c_str());
41 xbt_die("Exiting now");
45 void surf_parse_error(const std::string& msg)
47 int lineno = surf_parse_lineno;
49 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename.c_str(), lineno, msg.c_str());
51 xbt_die("Exiting now");
54 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
56 if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
59 std::string msg = pre + hostname + post + " Existing netpoints: \n";
61 std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
62 simgrid::s4u::Engine::get_instance()->get_all_netpoints();
63 std::sort(netpoints.begin(), netpoints.end(),
64 [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
65 return a->get_name() < b->get_name();
68 for (auto const& np : netpoints) {
75 msg += "'" + np->get_name() + "'";
76 if (msg.length() > 4096) {
77 msg.pop_back(); // remove trailing quote
78 msg += "...(list truncated)......";
82 surf_parse_error(msg);
85 double surf_parse_get_double(const std::string& s)
89 } catch (std::invalid_argument& ia) {
90 surf_parse_error(s + " is not a double");
94 int surf_parse_get_int(const std::string& s)
98 } catch (std::invalid_argument& ia) {
99 surf_parse_error(s + " is not a double");
105 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
106 std::vector<int>* explodesRadical(const std::string& radicals)
108 std::vector<int>* exploded = new std::vector<int>();
111 std::vector<std::string> radical_elements;
112 boost::split(radical_elements, radicals, boost::is_any_of(","));
113 for (auto const& group : radical_elements) {
114 std::vector<std::string> radical_ends;
115 boost::split(radical_ends, group, boost::is_any_of("-"));
116 int start = surf_parse_get_int(radical_ends.front());
119 switch (radical_ends.size()) {
124 end = surf_parse_get_int(radical_ends.back());
127 surf_parse_error(std::string("Malformed radical: ") + group);
129 for (int i = start; i <= end; i++)
130 exploded->push_back(i);
136 class unit_scale : public std::unordered_map<std::string, double> {
138 using std::unordered_map<std::string, double>::unordered_map;
139 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
140 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
143 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
145 for (const auto& gen : generators) {
146 const std::string& unit = std::get<0>(gen);
147 double value = std::get<1>(gen);
148 const int base = std::get<2>(gen);
149 const bool abbrev = std::get<3>(gen);
151 std::vector<std::string> prefixes;
155 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
156 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
160 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
161 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
166 emplace(unit, value);
167 for (const auto& prefix : prefixes) {
169 emplace(prefix + unit, value);
174 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
175 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
176 const std::string& name, const char* error_msg, const char* default_unit)
180 double res = strtod(string, &ptr);
182 surf_parse_error(std::string("value out of range: ") + string);
184 surf_parse_error(std::string("cannot parse number:") + string);
185 if (ptr[0] == '\0') {
186 ptr = (char*)default_unit;
188 auto u = units.find(ptr);
189 if (u == units.end())
190 surf_parse_error(std::string("unknown unit: ") + ptr);
191 return res * u->second;
195 double surf_parse_get_time(const char* string, const char* entity_kind, const std::string& name)
197 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
198 std::make_pair("d", 24 * 60 * 60),
199 std::make_pair("h", 60 * 60),
200 std::make_pair("m", 60),
201 std::make_pair("s", 1.0),
202 std::make_pair("ms", 1e-3),
203 std::make_pair("us", 1e-6),
204 std::make_pair("ns", 1e-9),
205 std::make_pair("ps", 1e-12)};
206 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
207 "Append 's' to your time to get seconds", "s");
210 double surf_parse_get_size(const char* string, const char* entity_kind, const std::string& name)
212 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
213 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
214 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
215 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
218 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, const std::string& name)
220 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
221 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
222 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
223 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
226 double surf_parse_get_speed(const char* string, const char* entity_kind, const std::string& name)
228 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
229 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
230 "Append 'f' or 'flops' to your speed to get flop per second", "f");
233 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const std::string& id)
236 std::vector<double> speed_per_pstate;
238 if (strchr(speeds, ',') == nullptr){
239 double speed = surf_parse_get_speed(speeds, entity_kind, id);
240 speed_per_pstate.push_back(speed);
242 std::vector<std::string> pstate_list;
243 boost::split(pstate_list, speeds, boost::is_any_of(","));
244 for (auto speed_str : pstate_list) {
245 boost::trim(speed_str);
246 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
247 speed_per_pstate.push_back(speed);
248 XBT_DEBUG("Speed value: %f", speed);
251 return speed_per_pstate;
255 * All the callback lists that can be overridden anywhere.
256 * (this list should probably be reduced to the bare minimum to allow the models to work)
259 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
261 /* The default current property receiver. Setup in the corresponding opening callbacks. */
262 std::unordered_map<std::string, std::string>* current_property_set = nullptr;
263 std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
264 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
266 FILE *surf_file_to_parse = nullptr;
268 /* Stuff relative to storage */
269 void STag_surfxml_storage()
272 XBT_DEBUG("STag_surfxml_storage");
273 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
276 void ETag_surfxml_storage()
278 simgrid::kernel::routing::StorageCreationArgs storage;
280 storage.properties = current_property_set;
281 current_property_set = nullptr;
283 storage.id = A_surfxml_storage_id;
284 storage.type_id = A_surfxml_storage_typeId;
285 storage.content = A_surfxml_storage_content;
286 storage.attach = A_surfxml_storage_attach;
288 sg_platf_new_storage(&storage);
290 void STag_surfxml_storage___type()
293 XBT_DEBUG("STag_surfxml_storage___type");
294 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
295 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
297 void ETag_surfxml_storage___type()
299 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
301 storage_type.properties = current_property_set;
302 current_property_set = nullptr;
304 storage_type.model_properties = current_model_property_set;
305 current_model_property_set = nullptr;
307 storage_type.content = A_surfxml_storage___type_content;
308 storage_type.id = A_surfxml_storage___type_id;
309 storage_type.model = A_surfxml_storage___type_model;
311 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
312 sg_platf_new_storage_type(&storage_type);
315 void STag_surfxml_mount()
317 XBT_DEBUG("STag_surfxml_mount");
320 void ETag_surfxml_mount()
322 simgrid::kernel::routing::MountCreationArgs mount;
324 mount.name = A_surfxml_mount_name;
325 mount.storageId = A_surfxml_mount_storageId;
326 sg_platf_new_mount(&mount);
329 void STag_surfxml_include()
331 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
334 void ETag_surfxml_include()
336 /* Won't happen since <include> is now removed since v3.18. */
339 /* Stag and Etag parse functions */
340 void STag_surfxml_platform() {
341 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
343 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
344 "You're using an ancient XML file.\n"
345 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
346 "instead of MBytes, MFlops and seconds.\n"
348 "Use simgrid_update_xml to update your file automatically. "
349 "This program is installed automatically with SimGrid, or "
350 "available in the tools/ directory of the source archive.\n"
352 "Please check also out the SURF section of the ChangeLog for "
353 "the 3.1 version for more information. \n"
355 "Last, do not forget to also update your values for "
356 "the calls to MSG_task_create (if any).");
357 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
358 "You're using an old XML file.\n"
359 "Use simgrid_update_xml to update your file automatically. "
360 "This program is installed automatically with SimGrid, or "
361 "available in the tools/ directory of the source archive.");
362 xbt_assert((version >= 4.0),
363 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
364 "Changes introduced in SimGrid 3.13:\n"
365 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
366 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
367 " - DOCTYPE now point to the rignt URL.\n"
368 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
370 "Use simgrid_update_xml to update your file automatically. "
371 "This program is installed automatically with SimGrid, or "
372 "available in the tools/ directory of the source archive.",
373 surf_parsed_filename.c_str(), version);
375 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
376 "That's fine, the new version is backward compatible. \n\n"
377 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
378 "This program is installed automatically with SimGrid, or "
379 "available in the tools/ directory of the source archive.",
380 version, surf_parsed_filename.c_str());
382 xbt_assert(version <= 4.1,
383 "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
384 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
385 "Please update your code, or use another, more adapted, file.",
386 surf_parsed_filename.c_str(), version);
388 void ETag_surfxml_platform(){
389 simgrid::s4u::on_platform_created();
392 void STag_surfxml_host(){
394 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
397 void STag_surfxml_prop()
399 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
400 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
401 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(A_surfxml_zone_id);
403 netzone->set_property(std::string(A_surfxml_prop_id), A_surfxml_prop_value);
405 if (not current_property_set)
406 current_property_set = new std::unordered_map<std::string, std::string>; // Maybe, it should raise an error
407 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
408 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
409 current_property_set);
413 void ETag_surfxml_host() {
414 simgrid::kernel::routing::HostCreationArgs host;
416 host.properties = current_property_set;
417 current_property_set = nullptr;
419 host.id = A_surfxml_host_id;
421 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
423 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
424 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
426 host.speed_trace = nullptr;
427 if (A_surfxml_host_availability___file[0] != '\0') {
428 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
429 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
431 if (A_surfxml_host_speed___file[0] != '\0')
432 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
433 host.state_trace = A_surfxml_host_state___file[0]
434 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
436 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
437 host.coord = A_surfxml_host_coordinates;
439 sg_platf_new_host(&host);
442 void STag_surfxml_host___link(){
443 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
444 simgrid::kernel::routing::HostLinkCreationArgs host_link;
446 host_link.id = A_surfxml_host___link_id;
447 host_link.link_up = A_surfxml_host___link_up;
448 host_link.link_down = A_surfxml_host___link_down;
449 sg_platf_new_hostlink(&host_link);
452 void STag_surfxml_router(){
453 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
456 void ETag_surfxml_cluster(){
457 simgrid::kernel::routing::ClusterCreationArgs cluster;
458 cluster.properties = current_property_set;
459 current_property_set = nullptr;
461 cluster.id = A_surfxml_cluster_id;
462 cluster.prefix = A_surfxml_cluster_prefix;
463 cluster.suffix = A_surfxml_cluster_suffix;
464 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
465 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
466 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
467 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
468 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
469 if(strcmp(A_surfxml_cluster_bb___bw,""))
470 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
471 if(strcmp(A_surfxml_cluster_bb___lat,""))
472 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
473 if(strcmp(A_surfxml_cluster_limiter___link,""))
474 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
475 if(strcmp(A_surfxml_cluster_loopback___bw,""))
476 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
477 if(strcmp(A_surfxml_cluster_loopback___lat,""))
478 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
480 switch(AX_surfxml_cluster_topology){
481 case A_surfxml_cluster_topology_FLAT:
482 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
484 case A_surfxml_cluster_topology_TORUS:
485 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
487 case A_surfxml_cluster_topology_FAT___TREE:
488 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
490 case A_surfxml_cluster_topology_DRAGONFLY:
491 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
494 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
496 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
497 cluster.router_id = A_surfxml_cluster_router___id;
499 switch (AX_surfxml_cluster_sharing___policy) {
500 case A_surfxml_cluster_sharing___policy_SHARED:
501 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
503 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
504 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
505 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
507 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
508 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
510 case A_surfxml_cluster_sharing___policy_FATPIPE:
511 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
514 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
516 switch (AX_surfxml_cluster_bb___sharing___policy) {
517 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
518 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
520 case A_surfxml_cluster_bb___sharing___policy_SHARED:
521 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
524 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
527 sg_platf_new_cluster(&cluster);
530 void STag_surfxml_cluster(){
532 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
535 void STag_surfxml_cabinet(){
536 simgrid::kernel::routing::CabinetCreationArgs cabinet;
537 cabinet.id = A_surfxml_cabinet_id;
538 cabinet.prefix = A_surfxml_cabinet_prefix;
539 cabinet.suffix = A_surfxml_cabinet_suffix;
540 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
541 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
542 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
543 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
545 sg_platf_new_cabinet(&cabinet);
548 void STag_surfxml_peer(){
549 simgrid::kernel::routing::PeerCreationArgs peer;
551 peer.id = std::string(A_surfxml_peer_id);
552 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
553 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
554 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
555 peer.coord = A_surfxml_peer_coordinates;
556 peer.speed_trace = nullptr;
557 if (A_surfxml_peer_availability___file[0] != '\0') {
558 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
559 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
561 if (A_surfxml_peer_speed___file[0] != '\0')
562 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
563 peer.state_trace = A_surfxml_peer_state___file[0]
564 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
567 if (A_surfxml_peer_lat[0] != '\0')
568 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
571 sg_platf_new_peer(&peer);
574 void STag_surfxml_link(){
576 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
579 void ETag_surfxml_link(){
580 simgrid::kernel::routing::LinkCreationArgs link;
582 link.properties = current_property_set;
583 current_property_set = nullptr;
585 link.id = std::string(A_surfxml_link_id);
586 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
587 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
588 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
590 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
591 link.latency_trace = A_surfxml_link_latency___file[0]
592 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
594 link.state_trace = A_surfxml_link_state___file[0]
595 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
598 switch (A_surfxml_link_sharing___policy) {
599 case A_surfxml_link_sharing___policy_SHARED:
600 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
602 case A_surfxml_link_sharing___policy_FATPIPE:
603 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
605 case A_surfxml_link_sharing___policy_FULLDUPLEX:
606 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
607 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
609 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
610 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
613 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
616 sg_platf_new_link(&link);
619 void STag_surfxml_link___ctn()
621 simgrid::kernel::resource::LinkImpl* link = nullptr;
622 switch (A_surfxml_link___ctn_direction) {
623 case AU_surfxml_link___ctn_direction:
624 case A_surfxml_link___ctn_direction_NONE:
625 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
627 case A_surfxml_link___ctn_direction_UP:
628 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
630 case A_surfxml_link___ctn_direction_DOWN:
631 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
634 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
637 const char* dirname = "";
638 switch (A_surfxml_link___ctn_direction) {
639 case A_surfxml_link___ctn_direction_UP:
640 dirname = " (upward)";
642 case A_surfxml_link___ctn_direction_DOWN:
643 dirname = " (downward)";
648 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
649 parsed_link_list.push_back(link);
652 void ETag_surfxml_backbone(){
653 simgrid::kernel::routing::LinkCreationArgs link;
655 link.properties = nullptr;
656 link.id = std::string(A_surfxml_backbone_id);
657 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
658 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
659 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
661 sg_platf_new_link(&link);
662 routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
665 void STag_surfxml_route(){
666 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
667 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
670 void STag_surfxml_ASroute(){
671 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
672 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
674 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
675 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
677 void STag_surfxml_zoneRoute(){
678 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
679 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
680 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
681 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
684 void STag_surfxml_bypassRoute(){
685 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
686 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
689 void STag_surfxml_bypassASroute(){
690 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
691 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
692 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
693 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
695 void STag_surfxml_bypassZoneRoute(){
696 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
697 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
698 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
699 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
702 void ETag_surfxml_route(){
703 simgrid::kernel::routing::RouteCreationArgs route;
705 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
706 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
707 route.gw_src = nullptr;
708 route.gw_dst = nullptr;
709 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
711 route.link_list.swap(parsed_link_list);
713 sg_platf_new_route(&route);
716 void ETag_surfxml_ASroute()
718 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
719 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
720 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
721 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
722 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
723 ETag_surfxml_zoneRoute();
725 void ETag_surfxml_zoneRoute()
727 simgrid::kernel::routing::RouteCreationArgs ASroute;
729 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
730 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
732 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
733 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
735 ASroute.link_list.swap(parsed_link_list);
737 switch (A_surfxml_zoneRoute_symmetrical) {
738 case AU_surfxml_zoneRoute_symmetrical:
739 case A_surfxml_zoneRoute_symmetrical_YES:
740 ASroute.symmetrical = true;
742 case A_surfxml_zoneRoute_symmetrical_NO:
743 ASroute.symmetrical = false;
749 sg_platf_new_route(&ASroute);
752 void ETag_surfxml_bypassRoute(){
753 simgrid::kernel::routing::RouteCreationArgs route;
755 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
756 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
757 route.gw_src = nullptr;
758 route.gw_dst = nullptr;
759 route.symmetrical = false;
761 route.link_list.swap(parsed_link_list);
763 sg_platf_new_bypassRoute(&route);
766 void ETag_surfxml_bypassASroute()
768 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
769 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
770 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
771 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
772 ETag_surfxml_bypassZoneRoute();
774 void ETag_surfxml_bypassZoneRoute()
776 simgrid::kernel::routing::RouteCreationArgs ASroute;
778 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
779 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
780 ASroute.link_list.swap(parsed_link_list);
782 ASroute.symmetrical = false;
784 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
785 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
787 sg_platf_new_bypassRoute(&ASroute);
790 void ETag_surfxml_trace(){
791 simgrid::kernel::routing::ProfileCreationArgs trace;
793 trace.id = A_surfxml_trace_id;
794 trace.file = A_surfxml_trace_file;
795 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
796 trace.pc_data = surfxml_pcdata;
798 sg_platf_new_trace(&trace);
801 void STag_surfxml_trace___connect()
803 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
805 trace_connect.element = A_surfxml_trace___connect_element;
806 trace_connect.trace = A_surfxml_trace___connect_trace;
808 switch (A_surfxml_trace___connect_kind) {
809 case AU_surfxml_trace___connect_kind:
810 case A_surfxml_trace___connect_kind_SPEED:
811 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
813 case A_surfxml_trace___connect_kind_BANDWIDTH:
814 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
816 case A_surfxml_trace___connect_kind_HOST___AVAIL:
817 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
819 case A_surfxml_trace___connect_kind_LATENCY:
820 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
822 case A_surfxml_trace___connect_kind_LINK___AVAIL:
823 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
826 surf_parse_error("Invalid trace kind");
828 sg_platf_trace_connect(&trace_connect);
831 void STag_surfxml_AS()
833 AX_surfxml_zone_id = AX_surfxml_AS_id;
834 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
838 void ETag_surfxml_AS()
843 void STag_surfxml_zone()
846 simgrid::kernel::routing::ZoneCreationArgs zone;
847 zone.id = A_surfxml_zone_id;
848 zone.routing = static_cast<int>(A_surfxml_zone_routing);
850 sg_platf_new_Zone_begin(&zone);
853 void ETag_surfxml_zone()
855 sg_platf_new_Zone_seal();
858 void STag_surfxml_config()
861 xbt_assert(current_property_set == nullptr,
862 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
863 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
864 if (_sg_cfg_init_status == 2) {
865 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
870 void ETag_surfxml_config()
872 // Sort config elements before applying.
873 // That's a little waste of time, but not doing so would break the tests
874 std::vector<std::string> keys;
875 for (auto const& kv : *current_property_set) {
876 keys.push_back(kv.first);
878 std::sort(keys.begin(), keys.end());
879 for (std::string key : keys) {
880 if (simgrid::config::is_default(key.c_str())) {
881 std::string cfg = key + ":" + current_property_set->at(key);
882 simgrid::config::set_parse(std::move(cfg));
884 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
886 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
888 delete current_property_set;
889 current_property_set = nullptr;
892 static std::vector<std::string> arguments;
894 void STag_surfxml_process()
896 AX_surfxml_actor_function = AX_surfxml_process_function;
897 STag_surfxml_actor();
900 void STag_surfxml_actor()
903 arguments.assign(1, A_surfxml_actor_function);
904 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
907 void ETag_surfxml_process()
909 AX_surfxml_actor_host = AX_surfxml_process_host;
910 AX_surfxml_actor_function = AX_surfxml_process_function;
911 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
912 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
913 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
914 ETag_surfxml_actor();
917 void ETag_surfxml_actor()
919 simgrid::kernel::routing::ActorCreationArgs actor;
921 actor.properties = current_property_set;
922 current_property_set = nullptr;
924 actor.args.swap(arguments);
925 actor.host = A_surfxml_actor_host;
926 actor.function = A_surfxml_actor_function;
927 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
928 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
930 switch (A_surfxml_actor_on___failure) {
931 case AU_surfxml_actor_on___failure:
932 case A_surfxml_actor_on___failure_DIE:
933 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
935 case A_surfxml_actor_on___failure_RESTART:
936 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
939 surf_parse_error("Invalid on failure behavior");
942 sg_platf_new_actor(&actor);
945 void STag_surfxml_argument(){
946 arguments.push_back(A_surfxml_argument_value);
949 void STag_surfxml_model___prop(){
950 if (not current_model_property_set)
951 current_model_property_set = new std::unordered_map<std::string, std::string>();
953 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
956 void ETag_surfxml_prop(){/* Nothing to do */}
957 void STag_surfxml_random(){/* Nothing to do */}
958 void ETag_surfxml_random(){/* Nothing to do */}
959 void ETag_surfxml_trace___connect(){/* Nothing to do */}
960 void STag_surfxml_trace()
961 { /* Nothing to do */
963 void ETag_surfxml_router(){/*Nothing to do*/}
964 void ETag_surfxml_host___link(){/* Nothing to do */}
965 void ETag_surfxml_cabinet(){/* Nothing to do */}
966 void ETag_surfxml_peer(){/* Nothing to do */}
967 void STag_surfxml_backbone(){/* Nothing to do */}
968 void ETag_surfxml_link___ctn(){/* Nothing to do */}
969 void ETag_surfxml_argument(){/* Nothing to do */}
970 void ETag_surfxml_model___prop(){/* Nothing to do */}
972 /* Open and Close parse file */
973 YY_BUFFER_STATE surf_input_buffer;
975 void surf_parse_open(const std::string& file)
977 surf_parsed_filename = file;
978 std::string dir = simgrid::xbt::Path(file).get_dir_name();
979 surf_path.push_back(dir);
981 surf_file_to_parse = surf_fopen(file, "r");
982 if (surf_file_to_parse == nullptr) {
983 std::string cwd = simgrid::xbt::Path().get_name();
984 xbt_die("Unable to open '%s' from '%s'\n", file.c_str(), cwd.c_str());
986 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
987 surf_parse__switch_to_buffer(surf_input_buffer);
988 surf_parse_lineno = 1;
991 void surf_parse_close()
993 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
995 if (surf_file_to_parse) {
996 surf_parse__delete_buffer(surf_input_buffer);
997 fclose(surf_file_to_parse);
998 surf_file_to_parse = nullptr; //Must be reset for Bypass
1002 /* Call the lexer to parse the currently opened file */
1005 return surf_parse_lex();