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/Exception.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/sg_config.hpp"
10 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
11 #include "src/kernel/resource/profile/Profile.hpp"
12 #include "src/surf/network_interface.hpp"
13 #include "src/surf/surf_interface.hpp"
14 #include "src/surf/xml/platf_private.hpp"
15 #include "surf/surf.hpp"
16 #include "xbt/file.hpp"
18 #include <boost/algorithm/string.hpp>
19 #include <boost/algorithm/string/classification.hpp>
20 #include <boost/algorithm/string/split.hpp>
23 #include <unordered_map>
26 #include "simgrid_dtd.c"
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
30 static std::string surf_parsed_filename; // Currently parsed file (for the error messages)
31 std::vector<simgrid::kernel::resource::LinkImpl*>
32 parsed_link_list; /* temporary store of current link list of a route */
33 std::vector<simgrid::kernel::resource::DiskImpl*> parsed_disk_list; /* temporary store of current disk list of a host */
37 void surf_parse_assert(bool cond, const std::string& msg)
40 surf_parse_error(msg);
43 void surf_parse_error(const std::string& msg)
45 throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
48 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
50 if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
53 std::string msg = pre + hostname + post + " Existing netpoints: \n";
55 std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
56 simgrid::s4u::Engine::get_instance()->get_all_netpoints();
57 std::sort(netpoints.begin(), netpoints.end(),
58 [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
59 return a->get_name() < b->get_name();
62 for (auto const& np : netpoints) {
69 msg += "'" + np->get_name() + "'";
70 if (msg.length() > 4096) {
71 msg.pop_back(); // remove trailing quote
72 msg += "...(list truncated)......";
76 surf_parse_error(std::move(msg));
79 double surf_parse_get_double(const std::string& s)
83 } catch (const std::invalid_argument&) {
84 surf_parse_error(s + " is not a double");
88 int surf_parse_get_int(const std::string& s)
92 } catch (const std::invalid_argument&) {
93 surf_parse_error(s + " is not a double");
99 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
100 std::vector<int>* explodesRadical(const std::string& radicals)
102 std::vector<int>* exploded = new std::vector<int>();
105 std::vector<std::string> radical_elements;
106 boost::split(radical_elements, radicals, boost::is_any_of(","));
107 for (auto const& group : radical_elements) {
108 std::vector<std::string> radical_ends;
109 boost::split(radical_ends, group, boost::is_any_of("-"));
110 int start = surf_parse_get_int(radical_ends.front());
113 switch (radical_ends.size()) {
118 end = surf_parse_get_int(radical_ends.back());
121 surf_parse_error(std::string("Malformed radical: ") + group);
123 for (int i = start; i <= end; i++)
124 exploded->push_back(i);
130 class unit_scale : public std::unordered_map<std::string, double> {
132 using std::unordered_map<std::string, double>::unordered_map;
133 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
134 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
137 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
139 for (const auto& gen : generators) {
140 const std::string& unit = std::get<0>(gen);
141 double value = std::get<1>(gen);
142 const int base = std::get<2>(gen);
143 const bool abbrev = std::get<3>(gen);
145 std::vector<std::string> prefixes;
149 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
150 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
154 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
155 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
160 emplace(unit, value);
161 for (const auto& prefix : prefixes) {
163 emplace(prefix + unit, value);
168 /* Note: no warning is issued for unit-less values when `name' is empty. */
169 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
170 const std::string& name, const char* error_msg, const char* default_unit)
174 double res = strtod(string, &endptr);
175 const char* ptr = endptr; // for const-correctness
177 surf_parse_error(std::string("value out of range: ") + string);
179 surf_parse_error(std::string("cannot parse number:") + string);
180 if (ptr[0] == '\0') {
181 // Ok, 0 can be unit-less
182 if (res != 0 && not name.empty())
183 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
186 auto u = units.find(ptr);
187 if (u == units.end())
188 surf_parse_error(std::string("unknown unit: ") + ptr);
189 return res * u->second;
193 double surf_parse_get_time(const char* string, const char* entity_kind, const std::string& name)
195 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
196 std::make_pair("d", 24 * 60 * 60),
197 std::make_pair("h", 60 * 60),
198 std::make_pair("m", 60),
199 std::make_pair("s", 1.0),
200 std::make_pair("ms", 1e-3),
201 std::make_pair("us", 1e-6),
202 std::make_pair("ns", 1e-9),
203 std::make_pair("ps", 1e-12)};
204 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
205 "Append 's' to your time to get seconds", "s");
208 double surf_parse_get_size(const char* string, const char* entity_kind, const std::string& name)
210 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
211 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
212 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
213 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
216 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, const std::string& name)
218 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
219 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
220 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
221 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
224 std::vector<double> surf_parse_get_bandwidths(const char* string, const char* entity_kind, const std::string& name)
226 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
227 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
229 std::vector<double> bandwidths;
230 std::vector<std::string> tokens;
231 boost::split(tokens, string, boost::is_any_of(";"));
232 for (auto token : tokens) {
233 bandwidths.push_back(surf_parse_get_value_with_unit(
234 token.c_str(), units, entity_kind, name,
235 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps"));
241 double surf_parse_get_speed(const char* string, const char* entity_kind, const std::string& name)
243 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
244 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
245 "Append 'f' or 'flops' to your speed to get flop per second", "f");
248 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const std::string& id)
251 std::vector<double> speed_per_pstate;
253 if (strchr(speeds, ',') == nullptr){
254 double speed = surf_parse_get_speed(speeds, entity_kind, id);
255 speed_per_pstate.push_back(speed);
257 std::vector<std::string> pstate_list;
258 boost::split(pstate_list, speeds, boost::is_any_of(","));
259 for (auto speed_str : pstate_list) {
260 boost::trim(speed_str);
261 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
262 speed_per_pstate.push_back(speed);
263 XBT_DEBUG("Speed value: %f", speed);
266 return speed_per_pstate;
270 * All the callback lists that can be overridden anywhere.
271 * (this list should probably be reduced to the bare minimum to allow the models to work)
274 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
276 std::vector<std::unordered_map<std::string, std::string>*> property_sets;
278 /* The default current property receiver. Setup in the corresponding opening callbacks. */
279 std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
281 FILE *surf_file_to_parse = nullptr;
283 /* Stuff relative to storage */
284 void STag_surfxml_storage()
286 XBT_DEBUG("STag_surfxml_storage");
287 property_sets.push_back(new std::unordered_map<std::string, std::string>());
290 void ETag_surfxml_storage()
292 simgrid::kernel::routing::StorageCreationArgs storage;
294 storage.properties = property_sets.back();
295 property_sets.pop_back();
297 storage.id = A_surfxml_storage_id;
298 storage.type_id = A_surfxml_storage_typeId;
299 storage.content = A_surfxml_storage_content;
300 storage.attach = A_surfxml_storage_attach;
302 sg_platf_new_storage(&storage);
304 void STag_surfxml_storage___type()
306 XBT_DEBUG("STag_surfxml_storage___type");
307 property_sets.push_back(new std::unordered_map<std::string, std::string>());
308 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
310 void ETag_surfxml_storage___type()
312 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
314 storage_type.properties = property_sets.back();
315 property_sets.pop_back();
317 storage_type.model_properties = current_model_property_set;
318 current_model_property_set = nullptr;
320 storage_type.content = A_surfxml_storage___type_content;
321 storage_type.id = A_surfxml_storage___type_id;
322 storage_type.model = A_surfxml_storage___type_model;
324 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
325 sg_platf_new_storage_type(&storage_type);
328 void STag_surfxml_mount()
330 XBT_DEBUG("STag_surfxml_mount");
333 void ETag_surfxml_mount()
335 simgrid::kernel::routing::MountCreationArgs mount;
337 mount.name = A_surfxml_mount_name;
338 mount.storageId = A_surfxml_mount_storageId;
339 sg_platf_new_mount(&mount);
342 void STag_surfxml_include()
344 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
347 void ETag_surfxml_include()
349 /* Won't happen since <include> is now removed since v3.18. */
352 /* Stag and Etag parse functions */
353 void STag_surfxml_platform() {
354 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
356 surf_parse_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
357 "You're using an ancient XML file.\n"
358 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
359 "instead of MBytes, MFlops and seconds.\n"
361 "Use simgrid_update_xml to update your file automatically. "
362 "This program is installed automatically with SimGrid, or "
363 "available in the tools/ directory of the source archive.\n"
365 "Please check also out the SURF section of the ChangeLog for "
366 "the 3.1 version for more information. \n"
368 "Last, do not forget to also update your values for "
369 "the calls to MSG_task_create (if any).");
370 surf_parse_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
371 "You're using an old XML file.\n"
372 "Use simgrid_update_xml to update your file automatically. "
373 "This program is installed automatically with SimGrid, or "
374 "available in the tools/ directory of the source archive.");
375 surf_parse_assert((version >= 4.0),
376 std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n "
377 "Changes introduced in SimGrid 3.13:\n"
378 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
379 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
380 " - DOCTYPE now point to the rignt URL.\n"
381 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
383 "Use simgrid_update_xml to update your file automatically. "
384 "This program is installed automatically with SimGrid, or "
385 "available in the tools/ directory of the source archive.");
387 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
388 "That's fine, the new version is backward compatible. \n\n"
389 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
390 "This program is installed automatically with SimGrid, or "
391 "available in the tools/ directory of the source archive.",
392 version, surf_parsed_filename.c_str());
394 surf_parse_assert(version <= 4.1,
395 std::string("******* THIS FILE COMES FROM THE FUTURE (v:")+std::to_string(version)+") *********\n "
396 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
397 "Please update your code, or use another, more adapted, file.");
399 void ETag_surfxml_platform(){
400 simgrid::s4u::Engine::on_platform_created();
403 void STag_surfxml_host(){
404 property_sets.push_back(new std::unordered_map<std::string, std::string>());
407 void STag_surfxml_prop()
409 property_sets.back()->insert({A_surfxml_prop_id, A_surfxml_prop_value});
410 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
411 property_sets.back());
414 void ETag_surfxml_host() {
415 simgrid::kernel::routing::HostCreationArgs host;
417 host.properties = property_sets.back();
418 property_sets.pop_back();
420 host.id = A_surfxml_host_id;
422 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
424 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
425 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
427 host.speed_trace = nullptr;
428 if (A_surfxml_host_availability___file[0] != '\0') {
429 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
430 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
432 if (A_surfxml_host_speed___file[0] != '\0')
433 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
434 host.state_trace = A_surfxml_host_state___file[0]
435 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
437 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
438 host.coord = A_surfxml_host_coordinates;
439 host.disks.swap(parsed_disk_list);
441 sg_platf_new_host(&host);
444 void STag_surfxml_disk() {
445 property_sets.push_back(new std::unordered_map<std::string, std::string>());
448 void ETag_surfxml_disk() {
449 simgrid::kernel::routing::DiskCreationArgs disk;
450 disk.properties = property_sets.back();
451 property_sets.pop_back();
453 disk.id = A_surfxml_disk_id;
454 disk.read_bw = surf_parse_get_bandwidth(A_surfxml_disk_read___bw, "read_bw of disk ", disk.id);
455 disk.write_bw = surf_parse_get_bandwidth(A_surfxml_disk_write___bw, "write_bw of disk ", disk.id);
457 parsed_disk_list.push_back(sg_platf_new_disk(&disk));
460 void STag_surfxml_host___link(){
461 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
462 simgrid::kernel::routing::HostLinkCreationArgs host_link;
464 host_link.id = A_surfxml_host___link_id;
465 host_link.link_up = A_surfxml_host___link_up;
466 host_link.link_down = A_surfxml_host___link_down;
467 sg_platf_new_hostlink(&host_link);
470 void STag_surfxml_router(){
471 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
474 void ETag_surfxml_cluster(){
475 simgrid::kernel::routing::ClusterCreationArgs cluster;
476 cluster.properties = property_sets.back();
477 property_sets.pop_back();
479 cluster.id = A_surfxml_cluster_id;
480 cluster.prefix = A_surfxml_cluster_prefix;
481 cluster.suffix = A_surfxml_cluster_suffix;
482 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
483 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
484 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
485 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
486 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
487 if(strcmp(A_surfxml_cluster_bb___bw,""))
488 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
489 if(strcmp(A_surfxml_cluster_bb___lat,""))
490 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
491 if(strcmp(A_surfxml_cluster_limiter___link,""))
492 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
493 if(strcmp(A_surfxml_cluster_loopback___bw,""))
494 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
495 if(strcmp(A_surfxml_cluster_loopback___lat,""))
496 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
498 switch(AX_surfxml_cluster_topology){
499 case A_surfxml_cluster_topology_FLAT:
500 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
502 case A_surfxml_cluster_topology_TORUS:
503 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
505 case A_surfxml_cluster_topology_FAT___TREE:
506 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
508 case A_surfxml_cluster_topology_DRAGONFLY:
509 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
512 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
514 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
515 cluster.router_id = A_surfxml_cluster_router___id;
517 switch (AX_surfxml_cluster_sharing___policy) {
518 case A_surfxml_cluster_sharing___policy_SHARED:
519 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
521 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
522 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
523 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
525 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
526 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
528 case A_surfxml_cluster_sharing___policy_FATPIPE:
529 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
532 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
534 switch (AX_surfxml_cluster_bb___sharing___policy) {
535 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
536 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
538 case A_surfxml_cluster_bb___sharing___policy_SHARED:
539 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
542 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
545 sg_platf_new_cluster(&cluster);
548 void STag_surfxml_cluster(){
549 property_sets.push_back(new std::unordered_map<std::string, std::string>());
552 void STag_surfxml_cabinet(){
553 simgrid::kernel::routing::CabinetCreationArgs cabinet;
554 cabinet.id = A_surfxml_cabinet_id;
555 cabinet.prefix = A_surfxml_cabinet_prefix;
556 cabinet.suffix = A_surfxml_cabinet_suffix;
557 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
558 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
559 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
560 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
562 sg_platf_new_cabinet(&cabinet);
565 void STag_surfxml_peer(){
566 simgrid::kernel::routing::PeerCreationArgs peer;
568 peer.id = std::string(A_surfxml_peer_id);
569 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
570 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
571 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
572 peer.coord = A_surfxml_peer_coordinates;
573 peer.speed_trace = nullptr;
574 if (A_surfxml_peer_availability___file[0] != '\0') {
575 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
576 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
578 if (A_surfxml_peer_speed___file[0] != '\0')
579 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
580 peer.state_trace = A_surfxml_peer_state___file[0]
581 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
584 if (A_surfxml_peer_lat[0] != '\0')
585 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
588 sg_platf_new_peer(&peer);
591 void STag_surfxml_link(){
592 property_sets.push_back(new std::unordered_map<std::string, std::string>());
595 void ETag_surfxml_link(){
596 simgrid::kernel::routing::LinkCreationArgs link;
598 link.properties = property_sets.back();
599 property_sets.pop_back();
601 link.id = std::string(A_surfxml_link_id);
602 link.bandwidths = surf_parse_get_bandwidths(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
603 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
604 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
606 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
607 link.latency_trace = A_surfxml_link_latency___file[0]
608 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
610 link.state_trace = A_surfxml_link_state___file[0]
611 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
614 switch (A_surfxml_link_sharing___policy) {
615 case A_surfxml_link_sharing___policy_SHARED:
616 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
618 case A_surfxml_link_sharing___policy_FATPIPE:
619 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
621 case A_surfxml_link_sharing___policy_FULLDUPLEX:
622 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
623 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
625 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
626 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
628 case A_surfxml_link_sharing___policy_WIFI:
629 link.policy = simgrid::s4u::Link::SharingPolicy::WIFI;
632 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
635 sg_platf_new_link(&link);
638 void STag_surfxml_link___ctn()
640 simgrid::kernel::resource::LinkImpl* link = nullptr;
641 switch (A_surfxml_link___ctn_direction) {
642 case AU_surfxml_link___ctn_direction:
643 case A_surfxml_link___ctn_direction_NONE:
644 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
646 case A_surfxml_link___ctn_direction_UP:
647 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
649 case A_surfxml_link___ctn_direction_DOWN:
650 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
653 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
656 const char* dirname = "";
657 switch (A_surfxml_link___ctn_direction) {
658 case A_surfxml_link___ctn_direction_UP:
659 dirname = " (upward)";
661 case A_surfxml_link___ctn_direction_DOWN:
662 dirname = " (downward)";
667 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
668 parsed_link_list.push_back(link);
671 void ETag_surfxml_backbone(){
672 simgrid::kernel::routing::LinkCreationArgs link;
674 link.properties = nullptr;
675 link.id = std::string(A_surfxml_backbone_id);
676 link.bandwidths.push_back(
677 surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str()));
678 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
679 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
681 sg_platf_new_link(&link);
682 routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
685 void STag_surfxml_route(){
686 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
687 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
690 void STag_surfxml_ASroute(){
691 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
692 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
694 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
695 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
697 void STag_surfxml_zoneRoute(){
698 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
699 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
700 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
701 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
704 void STag_surfxml_bypassRoute(){
705 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
706 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
709 void STag_surfxml_bypassASroute(){
710 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
711 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
712 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
713 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
715 void STag_surfxml_bypassZoneRoute(){
716 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
717 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
718 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
719 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
722 void ETag_surfxml_route(){
723 simgrid::kernel::routing::RouteCreationArgs route;
725 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
726 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
727 route.gw_src = nullptr;
728 route.gw_dst = nullptr;
729 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
731 route.link_list.swap(parsed_link_list);
733 sg_platf_new_route(&route);
736 void ETag_surfxml_ASroute()
738 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
739 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
740 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
741 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
742 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
743 ETag_surfxml_zoneRoute();
745 void ETag_surfxml_zoneRoute()
747 simgrid::kernel::routing::RouteCreationArgs ASroute;
749 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
750 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
752 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
753 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
755 ASroute.link_list.swap(parsed_link_list);
757 switch (A_surfxml_zoneRoute_symmetrical) {
758 case AU_surfxml_zoneRoute_symmetrical:
759 case A_surfxml_zoneRoute_symmetrical_YES:
760 ASroute.symmetrical = true;
762 case A_surfxml_zoneRoute_symmetrical_NO:
763 ASroute.symmetrical = false;
769 sg_platf_new_route(&ASroute);
772 void ETag_surfxml_bypassRoute(){
773 simgrid::kernel::routing::RouteCreationArgs route;
775 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
776 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
777 route.gw_src = nullptr;
778 route.gw_dst = nullptr;
779 route.symmetrical = false;
781 route.link_list.swap(parsed_link_list);
783 sg_platf_new_bypassRoute(&route);
786 void ETag_surfxml_bypassASroute()
788 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
789 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
790 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
791 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
792 ETag_surfxml_bypassZoneRoute();
794 void ETag_surfxml_bypassZoneRoute()
796 simgrid::kernel::routing::RouteCreationArgs ASroute;
798 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
799 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
800 ASroute.link_list.swap(parsed_link_list);
802 ASroute.symmetrical = false;
804 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
805 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
807 sg_platf_new_bypassRoute(&ASroute);
810 void ETag_surfxml_trace(){
811 simgrid::kernel::routing::ProfileCreationArgs trace;
813 trace.id = A_surfxml_trace_id;
814 trace.file = A_surfxml_trace_file;
815 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
816 trace.pc_data = surfxml_pcdata;
818 sg_platf_new_trace(&trace);
821 void STag_surfxml_trace___connect()
823 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
825 trace_connect.element = A_surfxml_trace___connect_element;
826 trace_connect.trace = A_surfxml_trace___connect_trace;
828 switch (A_surfxml_trace___connect_kind) {
829 case AU_surfxml_trace___connect_kind:
830 case A_surfxml_trace___connect_kind_SPEED:
831 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
833 case A_surfxml_trace___connect_kind_BANDWIDTH:
834 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
836 case A_surfxml_trace___connect_kind_HOST___AVAIL:
837 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
839 case A_surfxml_trace___connect_kind_LATENCY:
840 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
842 case A_surfxml_trace___connect_kind_LINK___AVAIL:
843 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
846 surf_parse_error("Invalid trace kind");
848 sg_platf_trace_connect(&trace_connect);
851 void STag_surfxml_AS()
853 AX_surfxml_zone_id = AX_surfxml_AS_id;
854 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
858 void ETag_surfxml_AS()
863 void STag_surfxml_zone()
865 property_sets.push_back(new std::unordered_map<std::string, std::string>());
866 simgrid::kernel::routing::ZoneCreationArgs zone;
867 zone.id = A_surfxml_zone_id;
868 zone.routing = static_cast<int>(A_surfxml_zone_routing);
869 sg_platf_new_Zone_begin(&zone);
872 void ETag_surfxml_zone()
874 sg_platf_new_Zone_set_properties(property_sets.back());
875 delete property_sets.back();
876 property_sets.pop_back();
878 sg_platf_new_Zone_seal();
881 void STag_surfxml_config()
883 property_sets.push_back(new std::unordered_map<std::string, std::string>());
884 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
885 if (_sg_cfg_init_status == 2) {
886 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
891 void ETag_surfxml_config()
893 // Sort config elements before applying.
894 // That's a little waste of time, but not doing so would break the tests
895 auto current_property_set = property_sets.back();
897 std::vector<std::string> keys;
898 for (auto const& kv : *current_property_set) {
899 keys.push_back(kv.first);
901 std::sort(keys.begin(), keys.end());
902 for (std::string key : keys) {
903 if (simgrid::config::is_default(key.c_str())) {
904 std::string cfg = key + ":" + current_property_set->at(key);
905 simgrid::config::set_parse(std::move(cfg));
907 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
909 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
911 delete current_property_set;
912 property_sets.pop_back();
915 static std::vector<std::string> arguments;
917 void STag_surfxml_process()
919 AX_surfxml_actor_function = AX_surfxml_process_function;
920 STag_surfxml_actor();
923 void STag_surfxml_actor()
925 property_sets.push_back(new std::unordered_map<std::string, std::string>());
926 arguments.assign(1, A_surfxml_actor_function);
929 void ETag_surfxml_process()
931 AX_surfxml_actor_host = AX_surfxml_process_host;
932 AX_surfxml_actor_function = AX_surfxml_process_function;
933 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
934 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
935 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
936 ETag_surfxml_actor();
939 void ETag_surfxml_actor()
941 simgrid::kernel::routing::ActorCreationArgs actor;
943 actor.properties = property_sets.back();
944 property_sets.pop_back();
946 actor.args.swap(arguments);
947 actor.host = A_surfxml_actor_host;
948 actor.function = A_surfxml_actor_function;
949 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
950 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
952 switch (A_surfxml_actor_on___failure) {
953 case AU_surfxml_actor_on___failure:
954 case A_surfxml_actor_on___failure_DIE:
955 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
957 case A_surfxml_actor_on___failure_RESTART:
958 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
961 surf_parse_error("Invalid on failure behavior");
964 sg_platf_new_actor(&actor);
967 void STag_surfxml_argument(){
968 arguments.push_back(A_surfxml_argument_value);
971 void STag_surfxml_model___prop(){
972 if (not current_model_property_set)
973 current_model_property_set = new std::unordered_map<std::string, std::string>();
975 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
978 void ETag_surfxml_prop(){/* Nothing to do */}
979 void STag_surfxml_random(){/* Nothing to do */}
980 void ETag_surfxml_random(){/* Nothing to do */}
981 void ETag_surfxml_trace___connect(){/* Nothing to do */}
982 void STag_surfxml_trace()
983 { /* Nothing to do */
985 void ETag_surfxml_router(){/*Nothing to do*/}
986 void ETag_surfxml_host___link(){/* Nothing to do */}
987 void ETag_surfxml_cabinet(){/* Nothing to do */}
988 void ETag_surfxml_peer(){/* Nothing to do */}
989 void STag_surfxml_backbone(){/* Nothing to do */}
990 void ETag_surfxml_link___ctn(){/* Nothing to do */}
991 void ETag_surfxml_argument(){/* Nothing to do */}
992 void ETag_surfxml_model___prop(){/* Nothing to do */}
994 /* Open and Close parse file */
995 YY_BUFFER_STATE surf_input_buffer;
997 void surf_parse_open(const std::string& file)
999 surf_parsed_filename = file;
1000 std::string dir = simgrid::xbt::Path(file).get_dir_name();
1001 surf_path.push_back(dir);
1003 surf_file_to_parse = surf_fopen(file, "r");
1004 if (surf_file_to_parse == nullptr)
1005 throw std::invalid_argument(std::string("Unable to open ')") + file + "' from '" + simgrid::xbt::Path().get_name() +
1006 "'. Does this file exist?");
1007 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1008 surf_parse__switch_to_buffer(surf_input_buffer);
1009 surf_parse_lineno = 1;
1012 void surf_parse_close()
1014 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
1016 if (surf_file_to_parse) {
1017 surf_parse__delete_buffer(surf_input_buffer);
1018 fclose(surf_file_to_parse);
1019 surf_file_to_parse = nullptr; //Must be reset for Bypass
1023 /* Call the lexer to parse the currently opened file */
1026 bool err = surf_parse_lex();
1027 surf_parse_assert(not err, "Flex returned an error code");