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/kernel/resource/profile/FutureEvtSet.hpp"
10 #include "src/kernel/resource/profile/Profile.hpp"
11 #include "src/surf/network_interface.hpp"
12 #include "src/surf/surf_interface.hpp"
13 #include "src/surf/xml/platf_private.hpp"
14 #include "surf/surf.hpp"
15 #include "xbt/file.hpp"
17 #include <boost/algorithm/string.hpp>
18 #include <boost/algorithm/string/classification.hpp>
19 #include <boost/algorithm/string/split.hpp>
22 #include <unordered_map>
25 #include "simgrid_dtd.c"
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
29 static std::string surf_parsed_filename; // Currently parsed file (for the error messages)
30 std::vector<simgrid::kernel::resource::LinkImpl*>
31 parsed_link_list; /* temporary store of current link list of a route */
32 std::vector<simgrid::kernel::resource::DiskImpl*> parsed_disk_list; /* temporary store of current disk list of a host */
36 void surf_parse_assert(bool cond, const std::string& msg)
39 surf_parse_error(msg);
42 void surf_parse_error(const std::string& msg)
44 int lineno = surf_parse_lineno;
46 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename.c_str(), lineno, msg.c_str());
48 xbt_die("Exiting now");
51 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
53 if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
56 std::string msg = pre + hostname + post + " Existing netpoints: \n";
58 std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
59 simgrid::s4u::Engine::get_instance()->get_all_netpoints();
60 std::sort(netpoints.begin(), netpoints.end(),
61 [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
62 return a->get_name() < b->get_name();
65 for (auto const& np : netpoints) {
72 msg += "'" + np->get_name() + "'";
73 if (msg.length() > 4096) {
74 msg.pop_back(); // remove trailing quote
75 msg += "...(list truncated)......";
79 surf_parse_error(msg);
82 double surf_parse_get_double(const std::string& s)
86 } catch (const std::invalid_argument&) {
87 surf_parse_error(s + " is not a double");
91 int surf_parse_get_int(const std::string& s)
95 } catch (const std::invalid_argument&) {
96 surf_parse_error(s + " is not a double");
102 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
103 std::vector<int>* explodesRadical(const std::string& radicals)
105 std::vector<int>* exploded = new std::vector<int>();
108 std::vector<std::string> radical_elements;
109 boost::split(radical_elements, radicals, boost::is_any_of(","));
110 for (auto const& group : radical_elements) {
111 std::vector<std::string> radical_ends;
112 boost::split(radical_ends, group, boost::is_any_of("-"));
113 int start = surf_parse_get_int(radical_ends.front());
116 switch (radical_ends.size()) {
121 end = surf_parse_get_int(radical_ends.back());
124 surf_parse_error(std::string("Malformed radical: ") + group);
126 for (int i = start; i <= end; i++)
127 exploded->push_back(i);
133 class unit_scale : public std::unordered_map<std::string, double> {
135 using std::unordered_map<std::string, double>::unordered_map;
136 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
137 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
140 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
142 for (const auto& gen : generators) {
143 const std::string& unit = std::get<0>(gen);
144 double value = std::get<1>(gen);
145 const int base = std::get<2>(gen);
146 const bool abbrev = std::get<3>(gen);
148 std::vector<std::string> prefixes;
152 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
153 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
157 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
158 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
163 emplace(unit, value);
164 for (const auto& prefix : prefixes) {
166 emplace(prefix + unit, value);
171 /* Note: no warning is issued for unit-less values when `name' is empty. */
172 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
173 const std::string& name, const char* error_msg, const char* default_unit)
177 double res = strtod(string, &endptr);
178 const char* ptr = endptr; // for const-correctness
180 surf_parse_error(std::string("value out of range: ") + string);
182 surf_parse_error(std::string("cannot parse number:") + string);
183 if (ptr[0] == '\0') {
184 // Ok, 0 can be unit-less
185 if (res != 0 && not name.empty())
186 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
189 auto u = units.find(ptr);
190 if (u == units.end())
191 surf_parse_error(std::string("unknown unit: ") + ptr);
192 return res * u->second;
196 double surf_parse_get_time(const char* string, const char* entity_kind, const std::string& name)
198 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
199 std::make_pair("d", 24 * 60 * 60),
200 std::make_pair("h", 60 * 60),
201 std::make_pair("m", 60),
202 std::make_pair("s", 1.0),
203 std::make_pair("ms", 1e-3),
204 std::make_pair("us", 1e-6),
205 std::make_pair("ns", 1e-9),
206 std::make_pair("ps", 1e-12)};
207 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
208 "Append 's' to your time to get seconds", "s");
211 double surf_parse_get_size(const char* string, const char* entity_kind, const std::string& name)
213 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
214 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
215 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
216 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
219 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, const std::string& name)
221 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
222 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
223 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
224 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
227 std::vector<double> surf_parse_get_bandwidths(const char* string, const char* entity_kind, const std::string& name)
229 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
230 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
232 std::vector<double> bandwidths;
233 std::vector<std::string> tokens;
234 boost::split(tokens, string, boost::is_any_of(";"));
235 for (auto token : tokens) {
236 bandwidths.push_back(surf_parse_get_value_with_unit(
237 token.c_str(), units, entity_kind, name,
238 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps"));
244 double surf_parse_get_speed(const char* string, const char* entity_kind, const std::string& name)
246 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
247 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
248 "Append 'f' or 'flops' to your speed to get flop per second", "f");
251 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const std::string& id)
254 std::vector<double> speed_per_pstate;
256 if (strchr(speeds, ',') == nullptr){
257 double speed = surf_parse_get_speed(speeds, entity_kind, id);
258 speed_per_pstate.push_back(speed);
260 std::vector<std::string> pstate_list;
261 boost::split(pstate_list, speeds, boost::is_any_of(","));
262 for (auto speed_str : pstate_list) {
263 boost::trim(speed_str);
264 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
265 speed_per_pstate.push_back(speed);
266 XBT_DEBUG("Speed value: %f", speed);
269 return speed_per_pstate;
273 * All the callback lists that can be overridden anywhere.
274 * (this list should probably be reduced to the bare minimum to allow the models to work)
277 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
279 std::vector<std::unordered_map<std::string, std::string>*> property_sets;
281 /* The default current property receiver. Setup in the corresponding opening callbacks. */
282 std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
284 FILE *surf_file_to_parse = nullptr;
286 /* Stuff relative to storage */
287 void STag_surfxml_storage()
289 XBT_DEBUG("STag_surfxml_storage");
290 property_sets.push_back(new std::unordered_map<std::string, std::string>());
293 void ETag_surfxml_storage()
295 simgrid::kernel::routing::StorageCreationArgs storage;
297 storage.properties = property_sets.back();
298 property_sets.pop_back();
300 storage.id = A_surfxml_storage_id;
301 storage.type_id = A_surfxml_storage_typeId;
302 storage.content = A_surfxml_storage_content;
303 storage.attach = A_surfxml_storage_attach;
305 sg_platf_new_storage(&storage);
307 void STag_surfxml_storage___type()
309 XBT_DEBUG("STag_surfxml_storage___type");
310 property_sets.push_back(new std::unordered_map<std::string, std::string>());
311 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
313 void ETag_surfxml_storage___type()
315 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
317 storage_type.properties = property_sets.back();
318 property_sets.pop_back();
320 storage_type.model_properties = current_model_property_set;
321 current_model_property_set = nullptr;
323 storage_type.content = A_surfxml_storage___type_content;
324 storage_type.id = A_surfxml_storage___type_id;
325 storage_type.model = A_surfxml_storage___type_model;
327 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
328 sg_platf_new_storage_type(&storage_type);
331 void STag_surfxml_mount()
333 XBT_DEBUG("STag_surfxml_mount");
336 void ETag_surfxml_mount()
338 simgrid::kernel::routing::MountCreationArgs mount;
340 mount.name = A_surfxml_mount_name;
341 mount.storageId = A_surfxml_mount_storageId;
342 sg_platf_new_mount(&mount);
345 void STag_surfxml_include()
347 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
350 void ETag_surfxml_include()
352 /* Won't happen since <include> is now removed since v3.18. */
355 /* Stag and Etag parse functions */
356 void STag_surfxml_platform() {
357 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
359 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
360 "You're using an ancient XML file.\n"
361 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
362 "instead of MBytes, MFlops and seconds.\n"
364 "Use simgrid_update_xml to update your file automatically. "
365 "This program is installed automatically with SimGrid, or "
366 "available in the tools/ directory of the source archive.\n"
368 "Please check also out the SURF section of the ChangeLog for "
369 "the 3.1 version for more information. \n"
371 "Last, do not forget to also update your values for "
372 "the calls to MSG_task_create (if any).");
373 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
374 "You're using an old XML file.\n"
375 "Use simgrid_update_xml to update your file automatically. "
376 "This program is installed automatically with SimGrid, or "
377 "available in the tools/ directory of the source archive.");
378 xbt_assert((version >= 4.0),
379 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
380 "Changes introduced in SimGrid 3.13:\n"
381 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
382 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
383 " - DOCTYPE now point to the rignt URL.\n"
384 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
386 "Use simgrid_update_xml to update your file automatically. "
387 "This program is installed automatically with SimGrid, or "
388 "available in the tools/ directory of the source archive.",
389 surf_parsed_filename.c_str(), version);
391 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
392 "That's fine, the new version is backward compatible. \n\n"
393 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
394 "This program is installed automatically with SimGrid, or "
395 "available in the tools/ directory of the source archive.",
396 version, surf_parsed_filename.c_str());
398 xbt_assert(version <= 4.1,
399 "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
400 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
401 "Please update your code, or use another, more adapted, file.",
402 surf_parsed_filename.c_str(), version);
404 void ETag_surfxml_platform(){
405 simgrid::s4u::Engine::on_platform_created();
408 void STag_surfxml_host(){
409 property_sets.push_back(new std::unordered_map<std::string, std::string>());
412 void STag_surfxml_prop()
414 property_sets.back()->insert({A_surfxml_prop_id, A_surfxml_prop_value});
415 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
416 property_sets.back());
419 void ETag_surfxml_host() {
420 simgrid::kernel::routing::HostCreationArgs host;
422 host.properties = property_sets.back();
423 property_sets.pop_back();
425 host.id = A_surfxml_host_id;
427 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
429 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
430 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
432 host.speed_trace = nullptr;
433 if (A_surfxml_host_availability___file[0] != '\0') {
434 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
435 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
437 if (A_surfxml_host_speed___file[0] != '\0')
438 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
439 host.state_trace = A_surfxml_host_state___file[0]
440 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
442 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
443 host.coord = A_surfxml_host_coordinates;
444 host.disks.swap(parsed_disk_list);
446 sg_platf_new_host(&host);
449 void STag_surfxml_disk() {
450 property_sets.push_back(new std::unordered_map<std::string, std::string>());
453 void ETag_surfxml_disk() {
454 simgrid::kernel::routing::DiskCreationArgs disk;
455 disk.properties = property_sets.back();
456 property_sets.pop_back();
458 disk.id = A_surfxml_disk_id;
459 disk.read_bw = surf_parse_get_bandwidth(A_surfxml_disk_read___bw, "read_bw of disk ", disk.id);
460 disk.write_bw = surf_parse_get_bandwidth(A_surfxml_disk_write___bw, "write_bw of disk ", disk.id);
462 parsed_disk_list.push_back(sg_platf_new_disk(&disk));
465 void STag_surfxml_host___link(){
466 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
467 simgrid::kernel::routing::HostLinkCreationArgs host_link;
469 host_link.id = A_surfxml_host___link_id;
470 host_link.link_up = A_surfxml_host___link_up;
471 host_link.link_down = A_surfxml_host___link_down;
472 sg_platf_new_hostlink(&host_link);
475 void STag_surfxml_router(){
476 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
479 void ETag_surfxml_cluster(){
480 simgrid::kernel::routing::ClusterCreationArgs cluster;
481 cluster.properties = property_sets.back();
482 property_sets.pop_back();
484 cluster.id = A_surfxml_cluster_id;
485 cluster.prefix = A_surfxml_cluster_prefix;
486 cluster.suffix = A_surfxml_cluster_suffix;
487 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
488 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
489 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
490 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
491 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
492 if(strcmp(A_surfxml_cluster_bb___bw,""))
493 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
494 if(strcmp(A_surfxml_cluster_bb___lat,""))
495 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
496 if(strcmp(A_surfxml_cluster_limiter___link,""))
497 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
498 if(strcmp(A_surfxml_cluster_loopback___bw,""))
499 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
500 if(strcmp(A_surfxml_cluster_loopback___lat,""))
501 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
503 switch(AX_surfxml_cluster_topology){
504 case A_surfxml_cluster_topology_FLAT:
505 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
507 case A_surfxml_cluster_topology_TORUS:
508 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
510 case A_surfxml_cluster_topology_FAT___TREE:
511 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
513 case A_surfxml_cluster_topology_DRAGONFLY:
514 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
517 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
519 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
520 cluster.router_id = A_surfxml_cluster_router___id;
522 switch (AX_surfxml_cluster_sharing___policy) {
523 case A_surfxml_cluster_sharing___policy_SHARED:
524 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
526 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
527 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
528 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
530 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
531 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
533 case A_surfxml_cluster_sharing___policy_FATPIPE:
534 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
537 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
539 switch (AX_surfxml_cluster_bb___sharing___policy) {
540 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
541 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
543 case A_surfxml_cluster_bb___sharing___policy_SHARED:
544 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
547 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
550 sg_platf_new_cluster(&cluster);
553 void STag_surfxml_cluster(){
554 property_sets.push_back(new std::unordered_map<std::string, std::string>());
557 void STag_surfxml_cabinet(){
558 simgrid::kernel::routing::CabinetCreationArgs cabinet;
559 cabinet.id = A_surfxml_cabinet_id;
560 cabinet.prefix = A_surfxml_cabinet_prefix;
561 cabinet.suffix = A_surfxml_cabinet_suffix;
562 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
563 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
564 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
565 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
567 sg_platf_new_cabinet(&cabinet);
570 void STag_surfxml_peer(){
571 simgrid::kernel::routing::PeerCreationArgs peer;
573 peer.id = std::string(A_surfxml_peer_id);
574 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
575 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
576 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
577 peer.coord = A_surfxml_peer_coordinates;
578 peer.speed_trace = nullptr;
579 if (A_surfxml_peer_availability___file[0] != '\0') {
580 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
581 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
583 if (A_surfxml_peer_speed___file[0] != '\0')
584 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
585 peer.state_trace = A_surfxml_peer_state___file[0]
586 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
589 if (A_surfxml_peer_lat[0] != '\0')
590 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
593 sg_platf_new_peer(&peer);
596 void STag_surfxml_link(){
597 property_sets.push_back(new std::unordered_map<std::string, std::string>());
600 void ETag_surfxml_link(){
601 simgrid::kernel::routing::LinkCreationArgs link;
603 link.properties = property_sets.back();
604 property_sets.pop_back();
606 link.id = std::string(A_surfxml_link_id);
607 link.bandwidths = surf_parse_get_bandwidths(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
608 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
609 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
611 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
612 link.latency_trace = A_surfxml_link_latency___file[0]
613 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
615 link.state_trace = A_surfxml_link_state___file[0]
616 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
619 switch (A_surfxml_link_sharing___policy) {
620 case A_surfxml_link_sharing___policy_SHARED:
621 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
623 case A_surfxml_link_sharing___policy_FATPIPE:
624 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
626 case A_surfxml_link_sharing___policy_FULLDUPLEX:
627 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
628 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
630 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
631 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
633 case A_surfxml_link_sharing___policy_WIFI:
634 link.policy = simgrid::s4u::Link::SharingPolicy::WIFI;
637 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
640 sg_platf_new_link(&link);
643 void STag_surfxml_link___ctn()
645 simgrid::kernel::resource::LinkImpl* link = nullptr;
646 switch (A_surfxml_link___ctn_direction) {
647 case AU_surfxml_link___ctn_direction:
648 case A_surfxml_link___ctn_direction_NONE:
649 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
651 case A_surfxml_link___ctn_direction_UP:
652 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
654 case A_surfxml_link___ctn_direction_DOWN:
655 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
658 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
661 const char* dirname = "";
662 switch (A_surfxml_link___ctn_direction) {
663 case A_surfxml_link___ctn_direction_UP:
664 dirname = " (upward)";
666 case A_surfxml_link___ctn_direction_DOWN:
667 dirname = " (downward)";
672 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
673 parsed_link_list.push_back(link);
676 void ETag_surfxml_backbone(){
677 simgrid::kernel::routing::LinkCreationArgs link;
679 link.properties = nullptr;
680 link.id = std::string(A_surfxml_backbone_id);
681 link.bandwidths.push_back(
682 surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str()));
683 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
684 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
686 sg_platf_new_link(&link);
687 routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
690 void STag_surfxml_route(){
691 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
692 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
695 void STag_surfxml_ASroute(){
696 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
697 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
699 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
700 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
702 void STag_surfxml_zoneRoute(){
703 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
704 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
705 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
706 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
709 void STag_surfxml_bypassRoute(){
710 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
711 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
714 void STag_surfxml_bypassASroute(){
715 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
716 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
717 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
718 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
720 void STag_surfxml_bypassZoneRoute(){
721 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
722 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
723 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
724 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
727 void ETag_surfxml_route(){
728 simgrid::kernel::routing::RouteCreationArgs route;
730 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
731 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
732 route.gw_src = nullptr;
733 route.gw_dst = nullptr;
734 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
736 route.link_list.swap(parsed_link_list);
738 sg_platf_new_route(&route);
741 void ETag_surfxml_ASroute()
743 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
744 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
745 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
746 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
747 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
748 ETag_surfxml_zoneRoute();
750 void ETag_surfxml_zoneRoute()
752 simgrid::kernel::routing::RouteCreationArgs ASroute;
754 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
755 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
757 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
758 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
760 ASroute.link_list.swap(parsed_link_list);
762 switch (A_surfxml_zoneRoute_symmetrical) {
763 case AU_surfxml_zoneRoute_symmetrical:
764 case A_surfxml_zoneRoute_symmetrical_YES:
765 ASroute.symmetrical = true;
767 case A_surfxml_zoneRoute_symmetrical_NO:
768 ASroute.symmetrical = false;
774 sg_platf_new_route(&ASroute);
777 void ETag_surfxml_bypassRoute(){
778 simgrid::kernel::routing::RouteCreationArgs route;
780 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
781 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
782 route.gw_src = nullptr;
783 route.gw_dst = nullptr;
784 route.symmetrical = false;
786 route.link_list.swap(parsed_link_list);
788 sg_platf_new_bypassRoute(&route);
791 void ETag_surfxml_bypassASroute()
793 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
794 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
795 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
796 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
797 ETag_surfxml_bypassZoneRoute();
799 void ETag_surfxml_bypassZoneRoute()
801 simgrid::kernel::routing::RouteCreationArgs ASroute;
803 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
804 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
805 ASroute.link_list.swap(parsed_link_list);
807 ASroute.symmetrical = false;
809 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
810 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
812 sg_platf_new_bypassRoute(&ASroute);
815 void ETag_surfxml_trace(){
816 simgrid::kernel::routing::ProfileCreationArgs trace;
818 trace.id = A_surfxml_trace_id;
819 trace.file = A_surfxml_trace_file;
820 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
821 trace.pc_data = surfxml_pcdata;
823 sg_platf_new_trace(&trace);
826 void STag_surfxml_trace___connect()
828 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
830 trace_connect.element = A_surfxml_trace___connect_element;
831 trace_connect.trace = A_surfxml_trace___connect_trace;
833 switch (A_surfxml_trace___connect_kind) {
834 case AU_surfxml_trace___connect_kind:
835 case A_surfxml_trace___connect_kind_SPEED:
836 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
838 case A_surfxml_trace___connect_kind_BANDWIDTH:
839 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
841 case A_surfxml_trace___connect_kind_HOST___AVAIL:
842 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
844 case A_surfxml_trace___connect_kind_LATENCY:
845 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
847 case A_surfxml_trace___connect_kind_LINK___AVAIL:
848 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
851 surf_parse_error("Invalid trace kind");
853 sg_platf_trace_connect(&trace_connect);
856 void STag_surfxml_AS()
858 AX_surfxml_zone_id = AX_surfxml_AS_id;
859 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
863 void ETag_surfxml_AS()
868 void STag_surfxml_zone()
870 property_sets.push_back(new std::unordered_map<std::string, std::string>());
871 simgrid::kernel::routing::ZoneCreationArgs zone;
872 zone.id = A_surfxml_zone_id;
873 zone.routing = static_cast<int>(A_surfxml_zone_routing);
874 sg_platf_new_Zone_begin(&zone);
877 void ETag_surfxml_zone()
879 sg_platf_new_Zone_set_properties(property_sets.back());
880 delete property_sets.back();
881 property_sets.pop_back();
883 sg_platf_new_Zone_seal();
886 void STag_surfxml_config()
888 property_sets.push_back(new std::unordered_map<std::string, std::string>());
889 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
890 if (_sg_cfg_init_status == 2) {
891 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
896 void ETag_surfxml_config()
898 // Sort config elements before applying.
899 // That's a little waste of time, but not doing so would break the tests
900 auto current_property_set = property_sets.back();
902 std::vector<std::string> keys;
903 for (auto const& kv : *current_property_set) {
904 keys.push_back(kv.first);
906 std::sort(keys.begin(), keys.end());
907 for (std::string key : keys) {
908 if (simgrid::config::is_default(key.c_str())) {
909 std::string cfg = key + ":" + current_property_set->at(key);
910 simgrid::config::set_parse(std::move(cfg));
912 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
914 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
916 delete current_property_set;
917 property_sets.pop_back();
920 static std::vector<std::string> arguments;
922 void STag_surfxml_process()
924 AX_surfxml_actor_function = AX_surfxml_process_function;
925 STag_surfxml_actor();
928 void STag_surfxml_actor()
930 property_sets.push_back(new std::unordered_map<std::string, std::string>());
931 arguments.assign(1, A_surfxml_actor_function);
934 void ETag_surfxml_process()
936 AX_surfxml_actor_host = AX_surfxml_process_host;
937 AX_surfxml_actor_function = AX_surfxml_process_function;
938 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
939 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
940 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
941 ETag_surfxml_actor();
944 void ETag_surfxml_actor()
946 simgrid::kernel::routing::ActorCreationArgs actor;
948 actor.properties = property_sets.back();
949 property_sets.pop_back();
951 actor.args.swap(arguments);
952 actor.host = A_surfxml_actor_host;
953 actor.function = A_surfxml_actor_function;
954 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
955 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
957 switch (A_surfxml_actor_on___failure) {
958 case AU_surfxml_actor_on___failure:
959 case A_surfxml_actor_on___failure_DIE:
960 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
962 case A_surfxml_actor_on___failure_RESTART:
963 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
966 surf_parse_error("Invalid on failure behavior");
969 sg_platf_new_actor(&actor);
972 void STag_surfxml_argument(){
973 arguments.push_back(A_surfxml_argument_value);
976 void STag_surfxml_model___prop(){
977 if (not current_model_property_set)
978 current_model_property_set = new std::unordered_map<std::string, std::string>();
980 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
983 void ETag_surfxml_prop(){/* Nothing to do */}
984 void STag_surfxml_random(){/* Nothing to do */}
985 void ETag_surfxml_random(){/* Nothing to do */}
986 void ETag_surfxml_trace___connect(){/* Nothing to do */}
987 void STag_surfxml_trace()
988 { /* Nothing to do */
990 void ETag_surfxml_router(){/*Nothing to do*/}
991 void ETag_surfxml_host___link(){/* Nothing to do */}
992 void ETag_surfxml_cabinet(){/* Nothing to do */}
993 void ETag_surfxml_peer(){/* Nothing to do */}
994 void STag_surfxml_backbone(){/* Nothing to do */}
995 void ETag_surfxml_link___ctn(){/* Nothing to do */}
996 void ETag_surfxml_argument(){/* Nothing to do */}
997 void ETag_surfxml_model___prop(){/* Nothing to do */}
999 /* Open and Close parse file */
1000 YY_BUFFER_STATE surf_input_buffer;
1002 void surf_parse_open(const std::string& file)
1004 surf_parsed_filename = file;
1005 std::string dir = simgrid::xbt::Path(file).get_dir_name();
1006 surf_path.push_back(dir);
1008 surf_file_to_parse = surf_fopen(file, "r");
1009 if (surf_file_to_parse == nullptr) {
1010 std::string cwd = simgrid::xbt::Path().get_name();
1011 xbt_die("Unable to open '%s' from '%s'\n", file.c_str(), cwd.c_str());
1013 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1014 surf_parse__switch_to_buffer(surf_input_buffer);
1015 surf_parse_lineno = 1;
1018 void surf_parse_close()
1020 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
1022 if (surf_file_to_parse) {
1023 surf_parse__delete_buffer(surf_input_buffer);
1024 fclose(surf_file_to_parse);
1025 surf_file_to_parse = nullptr; //Must be reset for Bypass
1029 /* Call the lexer to parse the currently opened file */
1032 return surf_parse_lex();