1 /* Copyright (c) 2006-2018. 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 "xbt/file.hpp"
12 #include "src/surf/xml/platf_private.hpp"
13 #include <boost/algorithm/string.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
16 #include <initializer_list>
19 #include <unordered_map>
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
24 #include "simgrid_dtd.c"
26 static const char* surf_parsed_filename; // Currently parsed file (for the error messages)
27 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
32 void surf_parse_assert(bool cond, std::string msg)
35 int lineno = surf_parse_lineno;
37 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
39 xbt_die("Exiting now");
43 void surf_parse_error(std::string msg)
45 int lineno = surf_parse_lineno;
47 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
49 xbt_die("Exiting now");
52 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
54 if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
57 std::string msg = pre + hostname + post + " Existing netpoints: \n";
59 std::vector<simgrid::kernel::routing::NetPoint*> list;
60 simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
61 std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
62 return a->getName() < b->getName();
65 for (auto const& np : list) {
72 msg += "'" + np->getName() + "'";
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(std::string s)
86 } catch (std::invalid_argument& ia) {
87 surf_parse_error(s + " is not a double");
92 int surf_parse_get_int(std::string s)
96 } catch (std::invalid_argument& ia) {
97 surf_parse_error(s + " is not a double");
104 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
105 std::vector<int>* explodesRadical(std::string radicals)
107 std::vector<int>* exploded = new std::vector<int>();
110 std::vector<std::string> radical_elements;
111 boost::split(radical_elements, radicals, boost::is_any_of(","));
112 for (auto const& group : radical_elements) {
113 std::vector<std::string> radical_ends;
114 boost::split(radical_ends, group, boost::is_any_of("-"));
115 int start = surf_parse_get_int(radical_ends.front());
118 switch (radical_ends.size()) {
123 end = surf_parse_get_int(radical_ends.back());
126 surf_parse_error(std::string("Malformed radical: ") + group);
129 for (int i = start; i <= end; i++)
130 exploded->push_back(i);
136 class unit_scale : public std::unordered_map<std::string, double> {
138 using std::unordered_map<std::string, double>::unordered_map;
139 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
140 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
143 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
145 for (const auto& gen : generators) {
146 const std::string& unit = std::get<0>(gen);
147 double value = std::get<1>(gen);
148 const int base = std::get<2>(gen);
149 const bool abbrev = std::get<3>(gen);
151 std::vector<std::string> prefixes;
155 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
156 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
160 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
161 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
166 emplace(unit, value);
167 for (const auto& prefix : prefixes) {
169 emplace(prefix + unit, value);
174 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
175 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
176 std::string name, const char* error_msg, const char* default_unit)
180 double res = strtod(string, &ptr);
182 surf_parse_error(std::string("value out of range: ") + string);
184 surf_parse_error(std::string("cannot parse number:") + string);
185 if (ptr[0] == '\0') {
187 return res; // Ok, 0 can be unit-less
189 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
190 ptr = (char*)default_unit;
192 auto u = units.find(ptr);
193 if (u == units.end())
194 surf_parse_error(std::string("unknown unit: ") + ptr);
195 return res * u->second;
199 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
201 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
202 std::make_pair("d", 24 * 60 * 60),
203 std::make_pair("h", 60 * 60),
204 std::make_pair("m", 60),
205 std::make_pair("s", 1.0),
206 std::make_pair("ms", 1e-3),
207 std::make_pair("us", 1e-6),
208 std::make_pair("ns", 1e-9),
209 std::make_pair("ps", 1e-12)};
210 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
211 "Append 's' to your time to get seconds", "s");
214 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
216 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
217 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
218 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
219 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
222 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
224 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
225 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
226 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
227 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
230 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
232 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
233 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
234 "Append 'f' or 'flops' to your speed to get flop per second", "f");
237 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
240 std::vector<double> speed_per_pstate;
242 if (strchr(speeds, ',') == nullptr){
243 double speed = surf_parse_get_speed(speeds, entity_kind, id);
244 speed_per_pstate.push_back(speed);
246 std::vector<std::string> pstate_list;
247 boost::split(pstate_list, speeds, boost::is_any_of(","));
248 for (auto speed_str : pstate_list) {
249 boost::trim(speed_str);
250 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
251 speed_per_pstate.push_back(speed);
252 XBT_DEBUG("Speed value: %f", speed);
255 return speed_per_pstate;
259 * All the callback lists that can be overridden anywhere.
260 * (this list should probably be reduced to the bare minimum to allow the models to work)
263 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
265 /* The default current property receiver. Setup in the corresponding opening callbacks. */
266 std::map<std::string, std::string>* current_property_set = nullptr;
267 std::map<std::string, std::string>* current_model_property_set = nullptr;
268 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
270 FILE *surf_file_to_parse = nullptr;
272 /* Stuff relative to storage */
273 void STag_surfxml_storage()
276 XBT_DEBUG("STag_surfxml_storage");
277 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
280 void ETag_surfxml_storage()
282 simgrid::kernel::routing::StorageCreationArgs storage;
284 storage.properties = current_property_set;
285 current_property_set = nullptr;
287 storage.id = A_surfxml_storage_id;
288 storage.type_id = A_surfxml_storage_typeId;
289 storage.content = A_surfxml_storage_content;
290 storage.attach = A_surfxml_storage_attach;
292 sg_platf_new_storage(&storage);
294 void STag_surfxml_storage___type()
297 XBT_DEBUG("STag_surfxml_storage___type");
298 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
299 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
301 void ETag_surfxml_storage___type()
303 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
305 storage_type.properties = current_property_set;
306 current_property_set = nullptr;
308 storage_type.model_properties = current_model_property_set;
309 current_model_property_set = nullptr;
311 storage_type.content = A_surfxml_storage___type_content;
312 storage_type.id = A_surfxml_storage___type_id;
313 storage_type.model = A_surfxml_storage___type_model;
315 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
316 sg_platf_new_storage_type(&storage_type);
319 void STag_surfxml_mount()
321 XBT_DEBUG("STag_surfxml_mount");
324 void ETag_surfxml_mount()
326 simgrid::kernel::routing::MountCreationArgs mount;
328 mount.name = A_surfxml_mount_name;
329 mount.storageId = A_surfxml_mount_storageId;
330 sg_platf_new_mount(&mount);
333 void STag_surfxml_include()
335 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
338 void ETag_surfxml_include()
340 /* Won't happen since <include> is now removed since v3.18. */
343 /* Stag and Etag parse functions */
344 void STag_surfxml_platform() {
345 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
347 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
348 "You're using an ancient XML file.\n"
349 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
350 "instead of MBytes, MFlops and seconds.\n"
352 "Use simgrid_update_xml to update your file automatically. "
353 "This program is installed automatically with SimGrid, or "
354 "available in the tools/ directory of the source archive.\n"
356 "Please check also out the SURF section of the ChangeLog for "
357 "the 3.1 version for more information. \n"
359 "Last, do not forget to also update your values for "
360 "the calls to MSG_task_create (if any).");
361 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
362 "You're using an old XML file.\n"
363 "Use simgrid_update_xml to update your file automatically. "
364 "This program is installed automatically with SimGrid, or "
365 "available in the tools/ directory of the source archive.");
366 xbt_assert((version >= 4.0),
367 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
368 "Changes introduced in SimGrid 3.13:\n"
369 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
370 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
371 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
372 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
374 "Use simgrid_update_xml to update your file automatically. "
375 "This program is installed automatically with SimGrid, or "
376 "available in the tools/ directory of the source archive.",
377 surf_parsed_filename, version);
379 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
380 "That's fine, the new version is backward compatible. \n\n"
381 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
382 "This program is installed automatically with SimGrid, or "
383 "available in the tools/ directory of the source archive.",
384 version, surf_parsed_filename);
386 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
387 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
388 "Please update your code, or use another, more adapted, file.",
389 surf_parsed_filename, version);
393 void ETag_surfxml_platform(){
397 void STag_surfxml_host(){
399 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
402 void STag_surfxml_prop()
404 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
405 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
406 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
408 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
410 if (not current_property_set)
411 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
412 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
413 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
414 current_property_set);
418 void ETag_surfxml_host() {
419 simgrid::kernel::routing::HostCreationArgs host;
421 host.properties = current_property_set;
422 current_property_set = nullptr;
424 host.id = A_surfxml_host_id;
426 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
428 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
429 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
430 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
431 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
432 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
433 host.coord = A_surfxml_host_coordinates;
435 sg_platf_new_host(&host);
438 void STag_surfxml_host___link(){
439 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
440 simgrid::kernel::routing::HostLinkCreationArgs host_link;
442 host_link.id = A_surfxml_host___link_id;
443 host_link.link_up = A_surfxml_host___link_up;
444 host_link.link_down = A_surfxml_host___link_down;
445 sg_platf_new_hostlink(&host_link);
448 void STag_surfxml_router(){
449 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
452 void ETag_surfxml_cluster(){
453 simgrid::kernel::routing::ClusterCreationArgs cluster;
454 cluster.properties = current_property_set;
455 current_property_set = nullptr;
457 cluster.id = A_surfxml_cluster_id;
458 cluster.prefix = A_surfxml_cluster_prefix;
459 cluster.suffix = A_surfxml_cluster_suffix;
460 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
461 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
462 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
463 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
464 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
465 if(strcmp(A_surfxml_cluster_bb___bw,""))
466 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
467 if(strcmp(A_surfxml_cluster_bb___lat,""))
468 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
469 if(strcmp(A_surfxml_cluster_limiter___link,""))
470 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
471 if(strcmp(A_surfxml_cluster_loopback___bw,""))
472 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
473 if(strcmp(A_surfxml_cluster_loopback___lat,""))
474 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
476 switch(AX_surfxml_cluster_topology){
477 case A_surfxml_cluster_topology_FLAT:
478 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
480 case A_surfxml_cluster_topology_TORUS:
481 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
483 case A_surfxml_cluster_topology_FAT___TREE:
484 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
486 case A_surfxml_cluster_topology_DRAGONFLY:
487 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
490 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
493 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
494 cluster.router_id = A_surfxml_cluster_router___id;
496 switch (AX_surfxml_cluster_sharing___policy) {
497 case A_surfxml_cluster_sharing___policy_SHARED:
498 cluster.sharing_policy = SURF_LINK_SHARED;
500 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
501 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
502 cluster.sharing_policy = SURF_LINK_SPLITDUPLEX;
504 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
505 cluster.sharing_policy = SURF_LINK_SPLITDUPLEX;
507 case A_surfxml_cluster_sharing___policy_FATPIPE:
508 cluster.sharing_policy = SURF_LINK_FATPIPE;
511 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
514 switch (AX_surfxml_cluster_bb___sharing___policy) {
515 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
516 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
518 case A_surfxml_cluster_bb___sharing___policy_SHARED:
519 cluster.bb_sharing_policy = SURF_LINK_SHARED;
522 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
526 sg_platf_new_cluster(&cluster);
529 void STag_surfxml_cluster(){
531 parse_after_config();
532 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
535 void STag_surfxml_cabinet(){
536 parse_after_config();
537 simgrid::kernel::routing::CabinetCreationArgs cabinet;
538 cabinet.id = A_surfxml_cabinet_id;
539 cabinet.prefix = A_surfxml_cabinet_prefix;
540 cabinet.suffix = A_surfxml_cabinet_suffix;
541 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
542 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
543 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
544 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
546 sg_platf_new_cabinet(&cabinet);
549 void STag_surfxml_peer(){
550 parse_after_config();
551 simgrid::kernel::routing::PeerCreationArgs peer;
553 peer.id = std::string(A_surfxml_peer_id);
554 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
555 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
556 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
557 peer.coord = A_surfxml_peer_coordinates;
558 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
559 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
561 if (A_surfxml_peer_lat[0] != '\0')
562 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
565 sg_platf_new_peer(&peer);
568 void STag_surfxml_link(){
570 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
573 void ETag_surfxml_link(){
574 simgrid::kernel::routing::LinkCreationArgs link;
576 link.properties = current_property_set;
577 current_property_set = nullptr;
579 link.id = std::string(A_surfxml_link_id);
580 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
581 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
582 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
583 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
584 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
586 switch (A_surfxml_link_sharing___policy) {
587 case A_surfxml_link_sharing___policy_SHARED:
588 link.policy = SURF_LINK_SHARED;
590 case A_surfxml_link_sharing___policy_FATPIPE:
591 link.policy = SURF_LINK_FATPIPE;
593 case A_surfxml_link_sharing___policy_FULLDUPLEX:
594 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
595 link.policy = SURF_LINK_SPLITDUPLEX;
597 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
598 link.policy = SURF_LINK_SPLITDUPLEX;
601 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
605 sg_platf_new_link(&link);
608 void STag_surfxml_link___ctn()
610 simgrid::surf::LinkImpl* link = nullptr;
611 switch (A_surfxml_link___ctn_direction) {
612 case AU_surfxml_link___ctn_direction:
613 case A_surfxml_link___ctn_direction_NONE:
614 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
616 case A_surfxml_link___ctn_direction_UP:
617 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
619 case A_surfxml_link___ctn_direction_DOWN:
620 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
623 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
627 const char* dirname = "";
628 switch (A_surfxml_link___ctn_direction) {
629 case A_surfxml_link___ctn_direction_UP:
630 dirname = " (upward)";
632 case A_surfxml_link___ctn_direction_DOWN:
633 dirname = " (downward)";
638 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
639 parsed_link_list.push_back(link);
642 void ETag_surfxml_backbone(){
643 simgrid::kernel::routing::LinkCreationArgs link;
645 link.properties = nullptr;
646 link.id = std::string(A_surfxml_backbone_id);
647 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
648 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
649 link.policy = SURF_LINK_SHARED;
651 sg_platf_new_link(&link);
652 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
655 void STag_surfxml_route(){
656 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
657 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
660 void STag_surfxml_ASroute(){
661 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
662 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
664 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
665 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
667 void STag_surfxml_zoneRoute(){
668 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
669 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
670 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
671 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
674 void STag_surfxml_bypassRoute(){
675 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
676 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
679 void STag_surfxml_bypassASroute(){
680 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
681 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
682 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
683 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
685 void STag_surfxml_bypassZoneRoute(){
686 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
687 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
688 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
689 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
692 void ETag_surfxml_route(){
693 simgrid::kernel::routing::RouteCreationArgs route;
695 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
696 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
697 route.gw_src = nullptr;
698 route.gw_dst = nullptr;
699 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
701 route.link_list.swap(parsed_link_list);
703 sg_platf_new_route(&route);
706 void ETag_surfxml_ASroute()
708 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
709 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
710 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
711 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
712 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
713 ETag_surfxml_zoneRoute();
715 void ETag_surfxml_zoneRoute()
717 simgrid::kernel::routing::RouteCreationArgs ASroute;
719 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
720 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
722 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
723 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
725 ASroute.link_list.swap(parsed_link_list);
727 switch (A_surfxml_zoneRoute_symmetrical) {
728 case AU_surfxml_zoneRoute_symmetrical:
729 case A_surfxml_zoneRoute_symmetrical_YES:
730 ASroute.symmetrical = true;
732 case A_surfxml_zoneRoute_symmetrical_NO:
733 ASroute.symmetrical = false;
739 sg_platf_new_route(&ASroute);
742 void ETag_surfxml_bypassRoute(){
743 simgrid::kernel::routing::RouteCreationArgs route;
745 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
746 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
747 route.gw_src = nullptr;
748 route.gw_dst = nullptr;
749 route.symmetrical = false;
751 route.link_list.swap(parsed_link_list);
753 sg_platf_new_bypassRoute(&route);
756 void ETag_surfxml_bypassASroute()
758 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
759 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
760 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
761 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
762 ETag_surfxml_bypassZoneRoute();
764 void ETag_surfxml_bypassZoneRoute()
766 simgrid::kernel::routing::RouteCreationArgs ASroute;
768 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
769 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
770 ASroute.link_list.swap(parsed_link_list);
772 ASroute.symmetrical = false;
774 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
775 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
777 sg_platf_new_bypassRoute(&ASroute);
780 void ETag_surfxml_trace(){
781 simgrid::kernel::routing::TraceCreationArgs trace;
783 trace.id = A_surfxml_trace_id;
784 trace.file = A_surfxml_trace_file;
785 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
786 trace.pc_data = surfxml_pcdata;
788 sg_platf_new_trace(&trace);
791 void STag_surfxml_trace___connect()
793 parse_after_config();
794 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
796 trace_connect.element = A_surfxml_trace___connect_element;
797 trace_connect.trace = A_surfxml_trace___connect_trace;
799 switch (A_surfxml_trace___connect_kind) {
800 case AU_surfxml_trace___connect_kind:
801 case A_surfxml_trace___connect_kind_SPEED:
802 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
804 case A_surfxml_trace___connect_kind_BANDWIDTH:
805 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
807 case A_surfxml_trace___connect_kind_HOST___AVAIL:
808 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
810 case A_surfxml_trace___connect_kind_LATENCY:
811 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
813 case A_surfxml_trace___connect_kind_LINK___AVAIL:
814 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
817 surf_parse_error("Invalid trace kind");
820 sg_platf_trace_connect(&trace_connect);
823 void STag_surfxml_AS()
825 AX_surfxml_zone_id = AX_surfxml_AS_id;
826 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
830 void ETag_surfxml_AS()
835 void STag_surfxml_zone()
837 parse_after_config();
839 simgrid::kernel::routing::ZoneCreationArgs zone;
840 zone.id = A_surfxml_zone_id;
841 zone.routing = static_cast<int>(A_surfxml_zone_routing);
843 sg_platf_new_Zone_begin(&zone);
846 void ETag_surfxml_zone()
848 sg_platf_new_Zone_seal();
851 void STag_surfxml_config()
854 xbt_assert(current_property_set == nullptr,
855 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
856 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
857 if (_sg_cfg_init_status == 2) {
858 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
863 void ETag_surfxml_config()
865 for (auto const& elm : *current_property_set) {
866 if (xbt_cfg_is_default_value(elm.first.c_str())) {
867 std::string cfg = elm.first + ":" + elm.second;
868 xbt_cfg_set_parse(cfg.c_str());
870 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
872 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
874 delete current_property_set;
875 current_property_set = nullptr;
878 static std::vector<std::string> arguments;
880 void STag_surfxml_process()
882 AX_surfxml_actor_function = AX_surfxml_process_function;
883 STag_surfxml_actor();
886 void STag_surfxml_actor()
889 arguments.assign(1, A_surfxml_actor_function);
890 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
893 void ETag_surfxml_process()
895 AX_surfxml_actor_host = AX_surfxml_process_host;
896 AX_surfxml_actor_function = AX_surfxml_process_function;
897 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
898 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
899 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
900 ETag_surfxml_actor();
903 void ETag_surfxml_actor()
905 simgrid::kernel::routing::ActorCreationArgs actor;
907 actor.properties = current_property_set;
908 current_property_set = nullptr;
910 actor.args.swap(arguments);
911 actor.host = A_surfxml_actor_host;
912 actor.function = A_surfxml_actor_function;
913 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
914 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
916 switch (A_surfxml_actor_on___failure) {
917 case AU_surfxml_actor_on___failure:
918 case A_surfxml_actor_on___failure_DIE:
919 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
921 case A_surfxml_actor_on___failure_RESTART:
922 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
925 surf_parse_error("Invalid on failure behavior");
929 sg_platf_new_actor(&actor);
932 void STag_surfxml_argument(){
933 arguments.push_back(A_surfxml_argument_value);
936 void STag_surfxml_model___prop(){
937 if (not current_model_property_set)
938 current_model_property_set = new std::map<std::string, std::string>();
940 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
943 void ETag_surfxml_prop(){/* Nothing to do */}
944 void STag_surfxml_random(){/* Nothing to do */}
945 void ETag_surfxml_random(){/* Nothing to do */}
946 void ETag_surfxml_trace___connect(){/* Nothing to do */}
947 void STag_surfxml_trace(){parse_after_config();}
948 void ETag_surfxml_router(){/*Nothing to do*/}
949 void ETag_surfxml_host___link(){/* Nothing to do */}
950 void ETag_surfxml_cabinet(){/* Nothing to do */}
951 void ETag_surfxml_peer(){/* Nothing to do */}
952 void STag_surfxml_backbone(){/* Nothing to do */}
953 void ETag_surfxml_link___ctn(){/* Nothing to do */}
954 void ETag_surfxml_argument(){/* Nothing to do */}
955 void ETag_surfxml_model___prop(){/* Nothing to do */}
957 /* Open and Close parse file */
958 YY_BUFFER_STATE surf_input_buffer;
960 void surf_parse_open(const char *file)
962 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
964 surf_parsed_filename = file;
965 std::string dir = simgrid::xbt::Path(file).getDirname();
966 surf_path.push_back(dir);
968 surf_file_to_parse = surf_fopen(file, "r");
969 if (surf_file_to_parse == nullptr)
970 xbt_die("Unable to open '%s'\n", file);
971 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
972 surf_parse__switch_to_buffer(surf_input_buffer);
973 surf_parse_lineno = 1;
976 void surf_parse_close()
978 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
980 if (surf_file_to_parse) {
981 surf_parse__delete_buffer(surf_input_buffer);
982 fclose(surf_file_to_parse);
983 surf_file_to_parse = nullptr; //Must be reset for Bypass
987 /* Call the lexer to parse the currently opened file */
990 return surf_parse_lex();