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 "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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
25 #include "simgrid_dtd.c"
27 static const char* surf_parsed_filename; // Currently parsed file (for the error messages)
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
33 void surf_parse_assert(bool cond, std::string msg)
36 int lineno = surf_parse_lineno;
38 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
40 xbt_die("Exiting now");
44 void surf_parse_error(std::string msg)
46 int lineno = surf_parse_lineno;
48 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
50 xbt_die("Exiting now");
53 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
55 if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
58 std::string msg = pre + hostname + post + " Existing netpoints: \n";
60 std::vector<simgrid::kernel::routing::NetPoint*> list;
61 simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
62 std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
63 return a->get_name() < b->get_name();
66 for (auto const& np : list) {
73 msg += "'" + np->get_name() + "'";
74 if (msg.length() > 4096) {
75 msg.pop_back(); // remove trailing quote
76 msg += "...(list truncated)......";
80 surf_parse_error(msg);
83 double surf_parse_get_double(std::string s)
87 } catch (std::invalid_argument& ia) {
88 surf_parse_error(s + " is not a double");
93 int surf_parse_get_int(std::string s)
97 } catch (std::invalid_argument& ia) {
98 surf_parse_error(s + " is not a double");
105 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
106 std::vector<int>* explodesRadical(std::string radicals)
108 std::vector<int>* exploded = new std::vector<int>();
111 std::vector<std::string> radical_elements;
112 boost::split(radical_elements, radicals, boost::is_any_of(","));
113 for (auto const& group : radical_elements) {
114 std::vector<std::string> radical_ends;
115 boost::split(radical_ends, group, boost::is_any_of("-"));
116 int start = surf_parse_get_int(radical_ends.front());
119 switch (radical_ends.size()) {
124 end = surf_parse_get_int(radical_ends.back());
127 surf_parse_error(std::string("Malformed radical: ") + group);
130 for (int i = start; i <= end; i++)
131 exploded->push_back(i);
137 class unit_scale : public std::unordered_map<std::string, double> {
139 using std::unordered_map<std::string, double>::unordered_map;
140 // tuples are : <unit, value for unit, base (2 or 10), true if abbreviated>
141 explicit unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators);
144 unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
146 for (const auto& gen : generators) {
147 const std::string& unit = std::get<0>(gen);
148 double value = std::get<1>(gen);
149 const int base = std::get<2>(gen);
150 const bool abbrev = std::get<3>(gen);
152 std::vector<std::string> prefixes;
156 prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
157 : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
161 prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
162 : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
167 emplace(unit, value);
168 for (const auto& prefix : prefixes) {
170 emplace(prefix + unit, value);
175 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
176 double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
177 std::string name, const char* error_msg, const char* default_unit)
181 double res = strtod(string, &ptr);
183 surf_parse_error(std::string("value out of range: ") + string);
185 surf_parse_error(std::string("cannot parse number:") + string);
186 if (ptr[0] == '\0') {
188 return res; // Ok, 0 can be unit-less
190 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
191 ptr = (char*)default_unit;
193 auto u = units.find(ptr);
194 if (u == units.end())
195 surf_parse_error(std::string("unknown unit: ") + ptr);
196 return res * u->second;
200 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
202 static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
203 std::make_pair("d", 24 * 60 * 60),
204 std::make_pair("h", 60 * 60),
205 std::make_pair("m", 60),
206 std::make_pair("s", 1.0),
207 std::make_pair("ms", 1e-3),
208 std::make_pair("us", 1e-6),
209 std::make_pair("ns", 1e-9),
210 std::make_pair("ps", 1e-12)};
211 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
212 "Append 's' to your time to get seconds", "s");
215 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
217 static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
218 std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
219 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
220 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
223 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
225 static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
226 std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
227 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
228 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
231 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
233 static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
234 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
235 "Append 'f' or 'flops' to your speed to get flop per second", "f");
238 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
241 std::vector<double> speed_per_pstate;
243 if (strchr(speeds, ',') == nullptr){
244 double speed = surf_parse_get_speed(speeds, entity_kind, id);
245 speed_per_pstate.push_back(speed);
247 std::vector<std::string> pstate_list;
248 boost::split(pstate_list, speeds, boost::is_any_of(","));
249 for (auto speed_str : pstate_list) {
250 boost::trim(speed_str);
251 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
252 speed_per_pstate.push_back(speed);
253 XBT_DEBUG("Speed value: %f", speed);
256 return speed_per_pstate;
260 * All the callback lists that can be overridden anywhere.
261 * (this list should probably be reduced to the bare minimum to allow the models to work)
264 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
266 /* The default current property receiver. Setup in the corresponding opening callbacks. */
267 std::map<std::string, std::string>* current_property_set = nullptr;
268 std::map<std::string, std::string>* current_model_property_set = nullptr;
269 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
271 FILE *surf_file_to_parse = nullptr;
273 /* Stuff relative to storage */
274 void STag_surfxml_storage()
277 XBT_DEBUG("STag_surfxml_storage");
278 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
281 void ETag_surfxml_storage()
283 simgrid::kernel::routing::StorageCreationArgs storage;
285 storage.properties = current_property_set;
286 current_property_set = nullptr;
288 storage.id = A_surfxml_storage_id;
289 storage.type_id = A_surfxml_storage_typeId;
290 storage.content = A_surfxml_storage_content;
291 storage.attach = A_surfxml_storage_attach;
293 sg_platf_new_storage(&storage);
295 void STag_surfxml_storage___type()
298 XBT_DEBUG("STag_surfxml_storage___type");
299 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
300 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
302 void ETag_surfxml_storage___type()
304 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
306 storage_type.properties = current_property_set;
307 current_property_set = nullptr;
309 storage_type.model_properties = current_model_property_set;
310 current_model_property_set = nullptr;
312 storage_type.content = A_surfxml_storage___type_content;
313 storage_type.id = A_surfxml_storage___type_id;
314 storage_type.model = A_surfxml_storage___type_model;
316 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
317 sg_platf_new_storage_type(&storage_type);
320 void STag_surfxml_mount()
322 XBT_DEBUG("STag_surfxml_mount");
325 void ETag_surfxml_mount()
327 simgrid::kernel::routing::MountCreationArgs mount;
329 mount.name = A_surfxml_mount_name;
330 mount.storageId = A_surfxml_mount_storageId;
331 sg_platf_new_mount(&mount);
334 void STag_surfxml_include()
336 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
339 void ETag_surfxml_include()
341 /* Won't happen since <include> is now removed since v3.18. */
344 /* Stag and Etag parse functions */
345 void STag_surfxml_platform() {
346 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
348 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
349 "You're using an ancient XML file.\n"
350 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
351 "instead of MBytes, MFlops and seconds.\n"
353 "Use simgrid_update_xml to update your file automatically. "
354 "This program is installed automatically with SimGrid, or "
355 "available in the tools/ directory of the source archive.\n"
357 "Please check also out the SURF section of the ChangeLog for "
358 "the 3.1 version for more information. \n"
360 "Last, do not forget to also update your values for "
361 "the calls to MSG_task_create (if any).");
362 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
363 "You're using an old XML file.\n"
364 "Use simgrid_update_xml to update your file automatically. "
365 "This program is installed automatically with SimGrid, or "
366 "available in the tools/ directory of the source archive.");
367 xbt_assert((version >= 4.0),
368 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
369 "Changes introduced in SimGrid 3.13:\n"
370 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
371 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
372 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
373 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
375 "Use simgrid_update_xml to update your file automatically. "
376 "This program is installed automatically with SimGrid, or "
377 "available in the tools/ directory of the source archive.",
378 surf_parsed_filename, version);
380 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
381 "That's fine, the new version is backward compatible. \n\n"
382 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
383 "This program is installed automatically with SimGrid, or "
384 "available in the tools/ directory of the source archive.",
385 version, surf_parsed_filename);
387 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
388 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
389 "Please update your code, or use another, more adapted, file.",
390 surf_parsed_filename, version);
394 void ETag_surfxml_platform(){
398 void STag_surfxml_host(){
400 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
403 void STag_surfxml_prop()
405 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
406 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
407 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
409 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
411 if (not current_property_set)
412 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
413 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
414 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
415 current_property_set);
419 void ETag_surfxml_host() {
420 simgrid::kernel::routing::HostCreationArgs host;
422 host.properties = current_property_set;
423 current_property_set = nullptr;
425 host.id = A_surfxml_host_id;
427 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
429 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
430 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
431 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
432 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
433 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
434 host.coord = A_surfxml_host_coordinates;
436 sg_platf_new_host(&host);
439 void STag_surfxml_host___link(){
440 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
441 simgrid::kernel::routing::HostLinkCreationArgs host_link;
443 host_link.id = A_surfxml_host___link_id;
444 host_link.link_up = A_surfxml_host___link_up;
445 host_link.link_down = A_surfxml_host___link_down;
446 sg_platf_new_hostlink(&host_link);
449 void STag_surfxml_router(){
450 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
453 void ETag_surfxml_cluster(){
454 simgrid::kernel::routing::ClusterCreationArgs cluster;
455 cluster.properties = current_property_set;
456 current_property_set = nullptr;
458 cluster.id = A_surfxml_cluster_id;
459 cluster.prefix = A_surfxml_cluster_prefix;
460 cluster.suffix = A_surfxml_cluster_suffix;
461 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
462 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
463 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
464 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
465 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
466 if(strcmp(A_surfxml_cluster_bb___bw,""))
467 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
468 if(strcmp(A_surfxml_cluster_bb___lat,""))
469 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
470 if(strcmp(A_surfxml_cluster_limiter___link,""))
471 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
472 if(strcmp(A_surfxml_cluster_loopback___bw,""))
473 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
474 if(strcmp(A_surfxml_cluster_loopback___lat,""))
475 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
477 switch(AX_surfxml_cluster_topology){
478 case A_surfxml_cluster_topology_FLAT:
479 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
481 case A_surfxml_cluster_topology_TORUS:
482 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
484 case A_surfxml_cluster_topology_FAT___TREE:
485 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
487 case A_surfxml_cluster_topology_DRAGONFLY:
488 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
491 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
494 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
495 cluster.router_id = A_surfxml_cluster_router___id;
497 switch (AX_surfxml_cluster_sharing___policy) {
498 case A_surfxml_cluster_sharing___policy_SHARED:
499 cluster.sharing_policy = SURF_LINK_SHARED;
501 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
502 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
503 cluster.sharing_policy = SURF_LINK_SPLITDUPLEX;
505 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
506 cluster.sharing_policy = SURF_LINK_SPLITDUPLEX;
508 case A_surfxml_cluster_sharing___policy_FATPIPE:
509 cluster.sharing_policy = SURF_LINK_FATPIPE;
512 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
515 switch (AX_surfxml_cluster_bb___sharing___policy) {
516 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
517 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
519 case A_surfxml_cluster_bb___sharing___policy_SHARED:
520 cluster.bb_sharing_policy = SURF_LINK_SHARED;
523 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
527 sg_platf_new_cluster(&cluster);
530 void STag_surfxml_cluster(){
532 parse_after_config();
533 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
536 void STag_surfxml_cabinet(){
537 parse_after_config();
538 simgrid::kernel::routing::CabinetCreationArgs cabinet;
539 cabinet.id = A_surfxml_cabinet_id;
540 cabinet.prefix = A_surfxml_cabinet_prefix;
541 cabinet.suffix = A_surfxml_cabinet_suffix;
542 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
543 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
544 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
545 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
547 sg_platf_new_cabinet(&cabinet);
550 void STag_surfxml_peer(){
551 parse_after_config();
552 simgrid::kernel::routing::PeerCreationArgs peer;
554 peer.id = std::string(A_surfxml_peer_id);
555 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
556 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
557 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
558 peer.coord = A_surfxml_peer_coordinates;
559 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
560 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
562 if (A_surfxml_peer_lat[0] != '\0')
563 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
566 sg_platf_new_peer(&peer);
569 void STag_surfxml_link(){
571 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
574 void ETag_surfxml_link(){
575 simgrid::kernel::routing::LinkCreationArgs link;
577 link.properties = current_property_set;
578 current_property_set = nullptr;
580 link.id = std::string(A_surfxml_link_id);
581 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
582 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
583 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
584 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
585 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
587 switch (A_surfxml_link_sharing___policy) {
588 case A_surfxml_link_sharing___policy_SHARED:
589 link.policy = SURF_LINK_SHARED;
591 case A_surfxml_link_sharing___policy_FATPIPE:
592 link.policy = SURF_LINK_FATPIPE;
594 case A_surfxml_link_sharing___policy_FULLDUPLEX:
595 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
596 link.policy = SURF_LINK_SPLITDUPLEX;
598 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
599 link.policy = SURF_LINK_SPLITDUPLEX;
602 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
606 sg_platf_new_link(&link);
609 void STag_surfxml_link___ctn()
611 simgrid::surf::LinkImpl* link = nullptr;
612 switch (A_surfxml_link___ctn_direction) {
613 case AU_surfxml_link___ctn_direction:
614 case A_surfxml_link___ctn_direction_NONE:
615 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
617 case A_surfxml_link___ctn_direction_UP:
618 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
620 case A_surfxml_link___ctn_direction_DOWN:
621 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
624 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
628 const char* dirname = "";
629 switch (A_surfxml_link___ctn_direction) {
630 case A_surfxml_link___ctn_direction_UP:
631 dirname = " (upward)";
633 case A_surfxml_link___ctn_direction_DOWN:
634 dirname = " (downward)";
639 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
640 parsed_link_list.push_back(link);
643 void ETag_surfxml_backbone(){
644 simgrid::kernel::routing::LinkCreationArgs link;
646 link.properties = nullptr;
647 link.id = std::string(A_surfxml_backbone_id);
648 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
649 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
650 link.policy = SURF_LINK_SHARED;
652 sg_platf_new_link(&link);
653 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
656 void STag_surfxml_route(){
657 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
658 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
661 void STag_surfxml_ASroute(){
662 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
663 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
665 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
666 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
668 void STag_surfxml_zoneRoute(){
669 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
670 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
671 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
672 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
675 void STag_surfxml_bypassRoute(){
676 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
677 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
680 void STag_surfxml_bypassASroute(){
681 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
682 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
683 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
684 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
686 void STag_surfxml_bypassZoneRoute(){
687 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
688 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
689 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
690 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
693 void ETag_surfxml_route(){
694 simgrid::kernel::routing::RouteCreationArgs route;
696 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
697 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
698 route.gw_src = nullptr;
699 route.gw_dst = nullptr;
700 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
702 route.link_list.swap(parsed_link_list);
704 sg_platf_new_route(&route);
707 void ETag_surfxml_ASroute()
709 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
710 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
711 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
712 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
713 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
714 ETag_surfxml_zoneRoute();
716 void ETag_surfxml_zoneRoute()
718 simgrid::kernel::routing::RouteCreationArgs ASroute;
720 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
721 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
723 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
724 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
726 ASroute.link_list.swap(parsed_link_list);
728 switch (A_surfxml_zoneRoute_symmetrical) {
729 case AU_surfxml_zoneRoute_symmetrical:
730 case A_surfxml_zoneRoute_symmetrical_YES:
731 ASroute.symmetrical = true;
733 case A_surfxml_zoneRoute_symmetrical_NO:
734 ASroute.symmetrical = false;
740 sg_platf_new_route(&ASroute);
743 void ETag_surfxml_bypassRoute(){
744 simgrid::kernel::routing::RouteCreationArgs route;
746 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
747 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
748 route.gw_src = nullptr;
749 route.gw_dst = nullptr;
750 route.symmetrical = false;
752 route.link_list.swap(parsed_link_list);
754 sg_platf_new_bypassRoute(&route);
757 void ETag_surfxml_bypassASroute()
759 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
760 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
761 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
762 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
763 ETag_surfxml_bypassZoneRoute();
765 void ETag_surfxml_bypassZoneRoute()
767 simgrid::kernel::routing::RouteCreationArgs ASroute;
769 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
770 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
771 ASroute.link_list.swap(parsed_link_list);
773 ASroute.symmetrical = false;
775 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
776 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
778 sg_platf_new_bypassRoute(&ASroute);
781 void ETag_surfxml_trace(){
782 simgrid::kernel::routing::TraceCreationArgs trace;
784 trace.id = A_surfxml_trace_id;
785 trace.file = A_surfxml_trace_file;
786 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
787 trace.pc_data = surfxml_pcdata;
789 sg_platf_new_trace(&trace);
792 void STag_surfxml_trace___connect()
794 parse_after_config();
795 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
797 trace_connect.element = A_surfxml_trace___connect_element;
798 trace_connect.trace = A_surfxml_trace___connect_trace;
800 switch (A_surfxml_trace___connect_kind) {
801 case AU_surfxml_trace___connect_kind:
802 case A_surfxml_trace___connect_kind_SPEED:
803 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
805 case A_surfxml_trace___connect_kind_BANDWIDTH:
806 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
808 case A_surfxml_trace___connect_kind_HOST___AVAIL:
809 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
811 case A_surfxml_trace___connect_kind_LATENCY:
812 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
814 case A_surfxml_trace___connect_kind_LINK___AVAIL:
815 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
818 surf_parse_error("Invalid trace kind");
821 sg_platf_trace_connect(&trace_connect);
824 void STag_surfxml_AS()
826 AX_surfxml_zone_id = AX_surfxml_AS_id;
827 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
831 void ETag_surfxml_AS()
836 void STag_surfxml_zone()
838 parse_after_config();
840 simgrid::kernel::routing::ZoneCreationArgs zone;
841 zone.id = A_surfxml_zone_id;
842 zone.routing = static_cast<int>(A_surfxml_zone_routing);
844 sg_platf_new_Zone_begin(&zone);
847 void ETag_surfxml_zone()
849 sg_platf_new_Zone_seal();
852 void STag_surfxml_config()
855 xbt_assert(current_property_set == nullptr,
856 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
857 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
858 if (_sg_cfg_init_status == 2) {
859 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
864 void ETag_surfxml_config()
866 for (auto const& elm : *current_property_set) {
867 if (xbt_cfg_is_default_value(elm.first.c_str())) {
868 std::string cfg = elm.first + ":" + elm.second;
869 xbt_cfg_set_parse(cfg.c_str());
871 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
873 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
875 delete current_property_set;
876 current_property_set = nullptr;
879 static std::vector<std::string> arguments;
881 void STag_surfxml_process()
883 AX_surfxml_actor_function = AX_surfxml_process_function;
884 STag_surfxml_actor();
887 void STag_surfxml_actor()
890 arguments.assign(1, A_surfxml_actor_function);
891 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
894 void ETag_surfxml_process()
896 AX_surfxml_actor_host = AX_surfxml_process_host;
897 AX_surfxml_actor_function = AX_surfxml_process_function;
898 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
899 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
900 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
901 ETag_surfxml_actor();
904 void ETag_surfxml_actor()
906 simgrid::kernel::routing::ActorCreationArgs actor;
908 actor.properties = current_property_set;
909 current_property_set = nullptr;
911 actor.args.swap(arguments);
912 actor.host = A_surfxml_actor_host;
913 actor.function = A_surfxml_actor_function;
914 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
915 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
917 switch (A_surfxml_actor_on___failure) {
918 case AU_surfxml_actor_on___failure:
919 case A_surfxml_actor_on___failure_DIE:
920 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE;
922 case A_surfxml_actor_on___failure_RESTART:
923 actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART;
926 surf_parse_error("Invalid on failure behavior");
930 sg_platf_new_actor(&actor);
933 void STag_surfxml_argument(){
934 arguments.push_back(A_surfxml_argument_value);
937 void STag_surfxml_model___prop(){
938 if (not current_model_property_set)
939 current_model_property_set = new std::map<std::string, std::string>();
941 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
944 void ETag_surfxml_prop(){/* Nothing to do */}
945 void STag_surfxml_random(){/* Nothing to do */}
946 void ETag_surfxml_random(){/* Nothing to do */}
947 void ETag_surfxml_trace___connect(){/* Nothing to do */}
948 void STag_surfxml_trace(){parse_after_config();}
949 void ETag_surfxml_router(){/*Nothing to do*/}
950 void ETag_surfxml_host___link(){/* Nothing to do */}
951 void ETag_surfxml_cabinet(){/* Nothing to do */}
952 void ETag_surfxml_peer(){/* Nothing to do */}
953 void STag_surfxml_backbone(){/* Nothing to do */}
954 void ETag_surfxml_link___ctn(){/* Nothing to do */}
955 void ETag_surfxml_argument(){/* Nothing to do */}
956 void ETag_surfxml_model___prop(){/* Nothing to do */}
958 /* Open and Close parse file */
959 YY_BUFFER_STATE surf_input_buffer;
961 void surf_parse_open(const char *file)
963 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
965 surf_parsed_filename = file;
966 std::string dir = simgrid::xbt::Path(file).getDirname();
967 surf_path.push_back(dir);
969 surf_file_to_parse = surf_fopen(file, "r");
970 if (surf_file_to_parse == nullptr)
971 xbt_die("Unable to open '%s'\n", file);
972 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
973 surf_parse__switch_to_buffer(surf_input_buffer);
974 surf_parse_lineno = 1;
977 void surf_parse_close()
979 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
981 if (surf_file_to_parse) {
982 surf_parse__delete_buffer(surf_input_buffer);
983 fclose(surf_file_to_parse);
984 surf_file_to_parse = nullptr; //Must be reset for Bypass
988 /* Call the lexer to parse the currently opened file */
991 return surf_parse_lex();