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 (sg_netpoint_by_name_or_null(hostname.c_str()) != 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");
95 int surf_parse_get_int(const std::string& s)
99 } catch (std::invalid_argument& ia) {
100 surf_parse_error(s + " is not a double");
107 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
108 std::vector<int>* explodesRadical(const std::string& radicals)
110 std::vector<int>* exploded = new std::vector<int>();
113 std::vector<std::string> radical_elements;
114 boost::split(radical_elements, radicals, boost::is_any_of(","));
115 for (auto const& group : radical_elements) {
116 std::vector<std::string> radical_ends;
117 boost::split(radical_ends, group, boost::is_any_of("-"));
118 int start = surf_parse_get_int(radical_ends.front());
121 switch (radical_ends.size()) {
126 end = surf_parse_get_int(radical_ends.back());
129 surf_parse_error(std::string("Malformed radical: ") + group);
132 for (int i = start; i <= end; i++)
133 exploded->push_back(i);
139 class unit_scale : public std::unordered_map<std::string, double> {
141 using std::unordered_map<std::string, double>::unordered_map;
142 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
143 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
146 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
148 for (const auto& gen : generators) {
149 const std::string& unit = std::get<0>(gen);
150 double value = std::get<1>(gen);
151 const int base = std::get<2>(gen);
152 const bool abbrev = std::get<3>(gen);
154 std::vector<std::string> prefixes;
158 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
159 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
163 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
164 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
169 emplace(unit, value);
170 for (const auto& prefix : prefixes) {
172 emplace(prefix + unit, value);
177 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
178 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
179 const std::string& name, const char* error_msg, const char* default_unit)
183 double res = strtod(string, &ptr);
185 surf_parse_error(std::string("value out of range: ") + string);
187 surf_parse_error(std::string("cannot parse number:") + string);
188 if (ptr[0] == '\0') {
190 return res; // Ok, 0 can be unit-less
192 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
193 ptr = (char*)default_unit;
195 auto u = units.find(ptr);
196 if (u == units.end())
197 surf_parse_error(std::string("unknown unit: ") + ptr);
198 return res * u->second;
202 double surf_parse_get_time(const char* string, const char* entity_kind, const std::string& name)
204 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
205 std::make_pair("d", 24 * 60 * 60),
206 std::make_pair("h", 60 * 60),
207 std::make_pair("m", 60),
208 std::make_pair("s", 1.0),
209 std::make_pair("ms", 1e-3),
210 std::make_pair("us", 1e-6),
211 std::make_pair("ns", 1e-9),
212 std::make_pair("ps", 1e-12)};
213 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
214 "Append 's' to your time to get seconds", "s");
217 double surf_parse_get_size(const char* string, const char* entity_kind, const std::string& name)
219 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
220 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
221 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
222 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
225 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, const std::string& name)
227 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
228 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
229 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
230 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
233 double surf_parse_get_speed(const char* string, const char* entity_kind, const std::string& name)
235 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
236 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
237 "Append 'f' or 'flops' to your speed to get flop per second", "f");
240 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const std::string& id)
243 std::vector<double> speed_per_pstate;
245 if (strchr(speeds, ',') == nullptr){
246 double speed = surf_parse_get_speed(speeds, entity_kind, id);
247 speed_per_pstate.push_back(speed);
249 std::vector<std::string> pstate_list;
250 boost::split(pstate_list, speeds, boost::is_any_of(","));
251 for (auto speed_str : pstate_list) {
252 boost::trim(speed_str);
253 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
254 speed_per_pstate.push_back(speed);
255 XBT_DEBUG("Speed value: %f", speed);
258 return speed_per_pstate;
262 * All the callback lists that can be overridden anywhere.
263 * (this list should probably be reduced to the bare minimum to allow the models to work)
266 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
268 /* The default current property receiver. Setup in the corresponding opening callbacks. */
269 std::unordered_map<std::string, std::string>* current_property_set = nullptr;
270 std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
271 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
273 FILE *surf_file_to_parse = nullptr;
275 /* Stuff relative to storage */
276 void STag_surfxml_storage()
279 XBT_DEBUG("STag_surfxml_storage");
280 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
283 void ETag_surfxml_storage()
285 simgrid::kernel::routing::StorageCreationArgs storage;
287 storage.properties = current_property_set;
288 current_property_set = nullptr;
290 storage.id = A_surfxml_storage_id;
291 storage.type_id = A_surfxml_storage_typeId;
292 storage.content = A_surfxml_storage_content;
293 storage.attach = A_surfxml_storage_attach;
295 sg_platf_new_storage(&storage);
297 void STag_surfxml_storage___type()
300 XBT_DEBUG("STag_surfxml_storage___type");
301 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
302 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
304 void ETag_surfxml_storage___type()
306 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
308 storage_type.properties = current_property_set;
309 current_property_set = nullptr;
311 storage_type.model_properties = current_model_property_set;
312 current_model_property_set = nullptr;
314 storage_type.content = A_surfxml_storage___type_content;
315 storage_type.id = A_surfxml_storage___type_id;
316 storage_type.model = A_surfxml_storage___type_model;
318 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
319 sg_platf_new_storage_type(&storage_type);
322 void STag_surfxml_mount()
324 XBT_DEBUG("STag_surfxml_mount");
327 void ETag_surfxml_mount()
329 simgrid::kernel::routing::MountCreationArgs mount;
331 mount.name = A_surfxml_mount_name;
332 mount.storageId = A_surfxml_mount_storageId;
333 sg_platf_new_mount(&mount);
336 void STag_surfxml_include()
338 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
341 void ETag_surfxml_include()
343 /* Won't happen since <include> is now removed since v3.18. */
346 /* Stag and Etag parse functions */
347 void STag_surfxml_platform() {
348 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
350 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
351 "You're using an ancient XML file.\n"
352 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
353 "instead of MBytes, MFlops and seconds.\n"
355 "Use simgrid_update_xml to update your file automatically. "
356 "This program is installed automatically with SimGrid, or "
357 "available in the tools/ directory of the source archive.\n"
359 "Please check also out the SURF section of the ChangeLog for "
360 "the 3.1 version for more information. \n"
362 "Last, do not forget to also update your values for "
363 "the calls to MSG_task_create (if any).");
364 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
365 "You're using an old XML file.\n"
366 "Use simgrid_update_xml to update your file automatically. "
367 "This program is installed automatically with SimGrid, or "
368 "available in the tools/ directory of the source archive.");
369 xbt_assert((version >= 4.0),
370 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
371 "Changes introduced in SimGrid 3.13:\n"
372 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
373 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
374 " - DOCTYPE now point to the rignt URL.\n"
375 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
377 "Use simgrid_update_xml to update your file automatically. "
378 "This program is installed automatically with SimGrid, or "
379 "available in the tools/ directory of the source archive.",
380 surf_parsed_filename.c_str(), version);
382 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
383 "That's fine, the new version is backward compatible. \n\n"
384 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
385 "This program is installed automatically with SimGrid, or "
386 "available in the tools/ directory of the source archive.",
387 version, surf_parsed_filename.c_str());
389 xbt_assert(version <= 4.1,
390 "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
391 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
392 "Please update your code, or use another, more adapted, file.",
393 surf_parsed_filename.c_str(), version);
395 void ETag_surfxml_platform(){
396 simgrid::s4u::on_platform_created();
399 void STag_surfxml_host(){
401 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
404 void STag_surfxml_prop()
406 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
407 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
408 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(A_surfxml_zone_id);
410 netzone->set_property(std::string(A_surfxml_prop_id), A_surfxml_prop_value);
412 if (not current_property_set)
413 current_property_set = new std::unordered_map<std::string, std::string>; // Maybe, it should raise an error
414 current_property_set->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 current_property_set);
420 void ETag_surfxml_host() {
421 simgrid::kernel::routing::HostCreationArgs host;
423 host.properties = current_property_set;
424 current_property_set = nullptr;
426 host.id = A_surfxml_host_id;
428 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
430 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
431 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
433 host.speed_trace = nullptr;
434 if (A_surfxml_host_availability___file[0] != '\0') {
435 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
436 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
438 if (A_surfxml_host_speed___file[0] != '\0')
439 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
440 host.state_trace = A_surfxml_host_state___file[0]
441 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
443 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
444 host.coord = A_surfxml_host_coordinates;
446 sg_platf_new_host(&host);
449 void STag_surfxml_host___link(){
450 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
451 simgrid::kernel::routing::HostLinkCreationArgs host_link;
453 host_link.id = A_surfxml_host___link_id;
454 host_link.link_up = A_surfxml_host___link_up;
455 host_link.link_down = A_surfxml_host___link_down;
456 sg_platf_new_hostlink(&host_link);
459 void STag_surfxml_router(){
460 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
463 void ETag_surfxml_cluster(){
464 simgrid::kernel::routing::ClusterCreationArgs cluster;
465 cluster.properties = current_property_set;
466 current_property_set = nullptr;
468 cluster.id = A_surfxml_cluster_id;
469 cluster.prefix = A_surfxml_cluster_prefix;
470 cluster.suffix = A_surfxml_cluster_suffix;
471 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
472 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
473 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
474 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
475 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
476 if(strcmp(A_surfxml_cluster_bb___bw,""))
477 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
478 if(strcmp(A_surfxml_cluster_bb___lat,""))
479 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
480 if(strcmp(A_surfxml_cluster_limiter___link,""))
481 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
482 if(strcmp(A_surfxml_cluster_loopback___bw,""))
483 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
484 if(strcmp(A_surfxml_cluster_loopback___lat,""))
485 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
487 switch(AX_surfxml_cluster_topology){
488 case A_surfxml_cluster_topology_FLAT:
489 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
491 case A_surfxml_cluster_topology_TORUS:
492 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
494 case A_surfxml_cluster_topology_FAT___TREE:
495 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
497 case A_surfxml_cluster_topology_DRAGONFLY:
498 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
501 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
504 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
505 cluster.router_id = A_surfxml_cluster_router___id;
507 switch (AX_surfxml_cluster_sharing___policy) {
508 case A_surfxml_cluster_sharing___policy_SHARED:
509 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
511 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
512 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
513 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
515 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
516 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
518 case A_surfxml_cluster_sharing___policy_FATPIPE:
519 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
522 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
525 switch (AX_surfxml_cluster_bb___sharing___policy) {
526 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
527 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
529 case A_surfxml_cluster_bb___sharing___policy_SHARED:
530 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
533 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
537 sg_platf_new_cluster(&cluster);
540 void STag_surfxml_cluster(){
542 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
545 void STag_surfxml_cabinet(){
546 simgrid::kernel::routing::CabinetCreationArgs cabinet;
547 cabinet.id = A_surfxml_cabinet_id;
548 cabinet.prefix = A_surfxml_cabinet_prefix;
549 cabinet.suffix = A_surfxml_cabinet_suffix;
550 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
551 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
552 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
553 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
555 sg_platf_new_cabinet(&cabinet);
558 void STag_surfxml_peer(){
559 simgrid::kernel::routing::PeerCreationArgs peer;
561 peer.id = std::string(A_surfxml_peer_id);
562 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
563 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
564 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
565 peer.coord = A_surfxml_peer_coordinates;
566 peer.speed_trace = nullptr;
567 if (A_surfxml_peer_availability___file[0] != '\0') {
568 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
569 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
571 if (A_surfxml_peer_speed___file[0] != '\0')
572 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
573 peer.state_trace = A_surfxml_peer_state___file[0]
574 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
577 if (A_surfxml_peer_lat[0] != '\0')
578 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
581 sg_platf_new_peer(&peer);
584 void STag_surfxml_link(){
586 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
589 void ETag_surfxml_link(){
590 simgrid::kernel::routing::LinkCreationArgs link;
592 link.properties = current_property_set;
593 current_property_set = nullptr;
595 link.id = std::string(A_surfxml_link_id);
596 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
597 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
598 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
600 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
601 link.latency_trace = A_surfxml_link_latency___file[0]
602 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
604 link.state_trace = A_surfxml_link_state___file[0]
605 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
608 switch (A_surfxml_link_sharing___policy) {
609 case A_surfxml_link_sharing___policy_SHARED:
610 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
612 case A_surfxml_link_sharing___policy_FATPIPE:
613 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
615 case A_surfxml_link_sharing___policy_FULLDUPLEX:
616 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
617 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
619 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
620 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
623 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
627 sg_platf_new_link(&link);
630 void STag_surfxml_link___ctn()
632 simgrid::kernel::resource::LinkImpl* link = nullptr;
633 switch (A_surfxml_link___ctn_direction) {
634 case AU_surfxml_link___ctn_direction:
635 case A_surfxml_link___ctn_direction_NONE:
636 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
638 case A_surfxml_link___ctn_direction_UP:
639 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
641 case A_surfxml_link___ctn_direction_DOWN:
642 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
645 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
649 const char* dirname = "";
650 switch (A_surfxml_link___ctn_direction) {
651 case A_surfxml_link___ctn_direction_UP:
652 dirname = " (upward)";
654 case A_surfxml_link___ctn_direction_DOWN:
655 dirname = " (downward)";
660 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
661 parsed_link_list.push_back(link);
664 void ETag_surfxml_backbone(){
665 simgrid::kernel::routing::LinkCreationArgs link;
667 link.properties = nullptr;
668 link.id = std::string(A_surfxml_backbone_id);
669 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
670 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
671 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
673 sg_platf_new_link(&link);
674 routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
677 void STag_surfxml_route(){
678 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
679 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
682 void STag_surfxml_ASroute(){
683 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
684 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
686 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
687 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
689 void STag_surfxml_zoneRoute(){
690 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
691 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
692 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
693 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
696 void STag_surfxml_bypassRoute(){
697 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
698 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
701 void STag_surfxml_bypassASroute(){
702 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
703 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
704 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
705 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
707 void STag_surfxml_bypassZoneRoute(){
708 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
709 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
710 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
711 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
714 void ETag_surfxml_route(){
715 simgrid::kernel::routing::RouteCreationArgs route;
717 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
718 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
719 route.gw_src = nullptr;
720 route.gw_dst = nullptr;
721 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
723 route.link_list.swap(parsed_link_list);
725 sg_platf_new_route(&route);
728 void ETag_surfxml_ASroute()
730 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
731 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
732 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
733 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
734 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
735 ETag_surfxml_zoneRoute();
737 void ETag_surfxml_zoneRoute()
739 simgrid::kernel::routing::RouteCreationArgs ASroute;
741 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
742 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
744 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
745 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
747 ASroute.link_list.swap(parsed_link_list);
749 switch (A_surfxml_zoneRoute_symmetrical) {
750 case AU_surfxml_zoneRoute_symmetrical:
751 case A_surfxml_zoneRoute_symmetrical_YES:
752 ASroute.symmetrical = true;
754 case A_surfxml_zoneRoute_symmetrical_NO:
755 ASroute.symmetrical = false;
761 sg_platf_new_route(&ASroute);
764 void ETag_surfxml_bypassRoute(){
765 simgrid::kernel::routing::RouteCreationArgs route;
767 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
768 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
769 route.gw_src = nullptr;
770 route.gw_dst = nullptr;
771 route.symmetrical = false;
773 route.link_list.swap(parsed_link_list);
775 sg_platf_new_bypassRoute(&route);
778 void ETag_surfxml_bypassASroute()
780 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
781 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
782 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
783 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
784 ETag_surfxml_bypassZoneRoute();
786 void ETag_surfxml_bypassZoneRoute()
788 simgrid::kernel::routing::RouteCreationArgs ASroute;
790 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
791 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
792 ASroute.link_list.swap(parsed_link_list);
794 ASroute.symmetrical = false;
796 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
797 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
799 sg_platf_new_bypassRoute(&ASroute);
802 void ETag_surfxml_trace(){
803 simgrid::kernel::routing::ProfileCreationArgs trace;
805 trace.id = A_surfxml_trace_id;
806 trace.file = A_surfxml_trace_file;
807 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
808 trace.pc_data = surfxml_pcdata;
810 sg_platf_new_trace(&trace);
813 void STag_surfxml_trace___connect()
815 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
817 trace_connect.element = A_surfxml_trace___connect_element;
818 trace_connect.trace = A_surfxml_trace___connect_trace;
820 switch (A_surfxml_trace___connect_kind) {
821 case AU_surfxml_trace___connect_kind:
822 case A_surfxml_trace___connect_kind_SPEED:
823 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
825 case A_surfxml_trace___connect_kind_BANDWIDTH:
826 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
828 case A_surfxml_trace___connect_kind_HOST___AVAIL:
829 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
831 case A_surfxml_trace___connect_kind_LATENCY:
832 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
834 case A_surfxml_trace___connect_kind_LINK___AVAIL:
835 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
838 surf_parse_error("Invalid trace kind");
841 sg_platf_trace_connect(&trace_connect);
844 void STag_surfxml_AS()
846 AX_surfxml_zone_id = AX_surfxml_AS_id;
847 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
851 void ETag_surfxml_AS()
856 void STag_surfxml_zone()
859 simgrid::kernel::routing::ZoneCreationArgs zone;
860 zone.id = A_surfxml_zone_id;
861 zone.routing = static_cast<int>(A_surfxml_zone_routing);
863 sg_platf_new_Zone_begin(&zone);
866 void ETag_surfxml_zone()
868 sg_platf_new_Zone_seal();
871 void STag_surfxml_config()
874 xbt_assert(current_property_set == nullptr,
875 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
876 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
877 if (_sg_cfg_init_status == 2) {
878 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
883 void ETag_surfxml_config()
885 // Sort config elements before applying.
886 // That's a little waste of time, but not doing so would break the tests
887 std::vector<std::string> keys;
888 for (auto const& kv : *current_property_set) {
889 keys.push_back(kv.first);
891 std::sort(keys.begin(), keys.end());
892 for (std::string key : keys) {
893 if (simgrid::config::is_default(key.c_str())) {
894 std::string cfg = key + ":" + current_property_set->at(key);
895 simgrid::config::set_parse(std::move(cfg));
897 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
899 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
901 delete current_property_set;
902 current_property_set = nullptr;
905 static std::vector<std::string> arguments;
907 void STag_surfxml_process()
909 AX_surfxml_actor_function = AX_surfxml_process_function;
910 STag_surfxml_actor();
913 void STag_surfxml_actor()
916 arguments.assign(1, A_surfxml_actor_function);
917 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
920 void ETag_surfxml_process()
922 AX_surfxml_actor_host = AX_surfxml_process_host;
923 AX_surfxml_actor_function = AX_surfxml_process_function;
924 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
925 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
926 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
927 ETag_surfxml_actor();
930 void ETag_surfxml_actor()
932 simgrid::kernel::routing::ActorCreationArgs actor;
934 actor.properties = current_property_set;
935 current_property_set = nullptr;
937 actor.args.swap(arguments);
938 actor.host = A_surfxml_actor_host;
939 actor.function = A_surfxml_actor_function;
940 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
941 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
943 switch (A_surfxml_actor_on___failure) {
944 case AU_surfxml_actor_on___failure:
945 case A_surfxml_actor_on___failure_DIE:
946 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
948 case A_surfxml_actor_on___failure_RESTART:
949 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
952 surf_parse_error("Invalid on failure behavior");
956 sg_platf_new_actor(&actor);
959 void STag_surfxml_argument(){
960 arguments.push_back(A_surfxml_argument_value);
963 void STag_surfxml_model___prop(){
964 if (not current_model_property_set)
965 current_model_property_set = new std::unordered_map<std::string, std::string>();
967 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
970 void ETag_surfxml_prop(){/* Nothing to do */}
971 void STag_surfxml_random(){/* Nothing to do */}
972 void ETag_surfxml_random(){/* Nothing to do */}
973 void ETag_surfxml_trace___connect(){/* Nothing to do */}
974 void STag_surfxml_trace()
975 { /* Nothing to do */
977 void ETag_surfxml_router(){/*Nothing to do*/}
978 void ETag_surfxml_host___link(){/* Nothing to do */}
979 void ETag_surfxml_cabinet(){/* Nothing to do */}
980 void ETag_surfxml_peer(){/* Nothing to do */}
981 void STag_surfxml_backbone(){/* Nothing to do */}
982 void ETag_surfxml_link___ctn(){/* Nothing to do */}
983 void ETag_surfxml_argument(){/* Nothing to do */}
984 void ETag_surfxml_model___prop(){/* Nothing to do */}
986 /* Open and Close parse file */
987 YY_BUFFER_STATE surf_input_buffer;
989 void surf_parse_open(const std::string& file)
991 surf_parsed_filename = file;
992 std::string dir = simgrid::xbt::Path(file).get_dir_name();
993 surf_path.push_back(dir);
994 std::string cwd = simgrid::xbt::Path().get_dir_name();
996 surf_file_to_parse = surf_fopen(file, "r");
997 if (surf_file_to_parse == nullptr)
998 xbt_die("Unable to open '%s' from '%s'\n", file.c_str(), cwd.c_str());
999 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1000 surf_parse__switch_to_buffer(surf_input_buffer);
1001 surf_parse_lineno = 1;
1004 void surf_parse_close()
1006 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
1008 if (surf_file_to_parse) {
1009 surf_parse__delete_buffer(surf_input_buffer);
1010 fclose(surf_file_to_parse);
1011 surf_file_to_parse = nullptr; //Must be reset for Bypass
1015 /* Call the lexer to parse the currently opened file */
1018 return surf_parse_lex();