1 /* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/Exception.hpp>
7 #include <simgrid/kernel/routing/NetPoint.hpp>
8 #include <simgrid/s4u/Engine.hpp>
9 #include <xbt/file.hpp>
10 #include <xbt/parse_units.hpp>
12 #include "simgrid/sg_config.hpp"
13 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
14 #include "src/kernel/resource/profile/Profile.hpp"
15 #include "src/surf/network_interface.hpp"
16 #include "src/surf/surf_interface.hpp"
17 #include "src/surf/xml/platf.hpp"
18 #include "src/surf/xml/platf_private.hpp"
20 #include <boost/algorithm/string/classification.hpp>
21 #include <boost/algorithm/string/split.hpp>
24 #include <unordered_map>
27 #include "simgrid_dtd.c"
29 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
31 std::string surf_parsed_filename; // Currently parsed file (for the error messages)
32 std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
34 /* Helping functions */
35 void surf_parse_assert(bool cond, const std::string& msg)
38 surf_parse_error(msg);
41 void surf_parse_error(const std::string& msg)
43 throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
46 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
48 if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
51 std::string msg = pre + hostname + post + " Existing netpoints:\n";
53 std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
54 simgrid::s4u::Engine::get_instance()->get_all_netpoints();
55 std::sort(netpoints.begin(), netpoints.end(),
56 [](const simgrid::kernel::routing::NetPoint* a, const simgrid::kernel::routing::NetPoint* b) {
57 return a->get_name() < b->get_name();
60 for (auto const& np : netpoints) {
67 msg += "'" + np->get_name() + "'";
68 if (msg.length() > 4096) {
69 msg.pop_back(); // remove trailing quote
70 msg += "...(list truncated)......";
74 surf_parse_error(msg);
77 double surf_parse_get_double(const std::string& s)
81 } catch (const std::invalid_argument&) {
82 surf_parse_error(s + " is not a double");
86 int surf_parse_get_int(const std::string& s)
90 } catch (const std::invalid_argument&) {
91 surf_parse_error(s + " is not an int");
95 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
96 static void explodesRadical(const std::string& radicals, std::vector<int>* exploded)
99 std::vector<std::string> radical_elements;
100 boost::split(radical_elements, radicals, boost::is_any_of(","));
101 for (auto const& group : radical_elements) {
102 std::vector<std::string> radical_ends;
103 boost::split(radical_ends, group, boost::is_any_of("-"));
104 int start = surf_parse_get_int(radical_ends.front());
107 switch (radical_ends.size()) {
112 end = surf_parse_get_int(radical_ends.back());
115 surf_parse_error(std::string("Malformed radical: ") + group);
117 for (int i = start; i <= end; i++)
118 exploded->push_back(i);
124 * All the callback lists that can be overridden anywhere.
125 * (this list should probably be reduced to the bare minimum to allow the models to work)
128 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
130 std::vector<std::unordered_map<std::string, std::string>> property_sets;
132 FILE *surf_file_to_parse = nullptr;
134 /* Stuff relative to storage */
135 void STag_surfxml_storage()
137 xbt_die("<storage> tag was removed in SimGrid v3.27. Please stop using it now.");
140 void ETag_surfxml_storage()
142 /* Won't happen since <storage> is now removed since v3.27. */
144 void STag_surfxml_storage___type()
146 xbt_die("<storage_type> tag was removed in SimGrid v3.27. Please stop using it now.");
148 void ETag_surfxml_storage___type()
150 /* Won't happen since <storage_type> is now removed since v3.27. */
153 void STag_surfxml_mount()
155 xbt_die("<mount> tag was removed in SimGrid v3.27. Please stop using it now.");
158 void ETag_surfxml_mount()
160 /* Won't happen since <mount> is now removed since v3.27. */
163 void STag_surfxml_include()
165 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
168 void ETag_surfxml_include()
170 /* Won't happen since <include> is now removed since v3.18. */
173 /* Stag and Etag parse functions */
174 void STag_surfxml_platform() {
175 double version = surf_parse_get_double(A_surfxml_platform_version);
177 surf_parse_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
178 "You're using an ancient XML file.\n"
179 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
180 "instead of MBytes, MFlops and seconds.\n"
182 "Use simgrid_update_xml to update your file automatically. "
183 "This program is installed automatically with SimGrid, or "
184 "available in the tools/ directory of the source archive.\n"
186 "Please check also out the SURF section of the ChangeLog for "
187 "the 3.1 version for more information. \n"
189 "Last, do not forget to also update your values for "
190 "the calls to MSG_task_create (if any).");
191 surf_parse_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
192 "You're using an old XML file.\n"
193 "Use simgrid_update_xml to update your file automatically. "
194 "This program is installed automatically with SimGrid, or "
195 "available in the tools/ directory of the source archive.");
196 surf_parse_assert((version >= 4.0),
197 std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n "
198 "Changes introduced in SimGrid 3.13:\n"
199 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
200 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
201 " - DOCTYPE now point to the rignt URL.\n"
202 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
204 "Use simgrid_update_xml to update your file automatically. "
205 "This program is installed automatically with SimGrid, or "
206 "available in the tools/ directory of the source archive.");
208 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
209 "That's fine, the new version is backward compatible. \n\n"
210 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
211 "This program is installed automatically with SimGrid, or "
212 "available in the tools/ directory of the source archive.",
213 version, surf_parsed_filename.c_str());
215 surf_parse_assert(version <= 4.1,
216 std::string("******* THIS FILE COMES FROM THE FUTURE (v:")+std::to_string(version)+") *********\n "
217 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
218 "Please update your code, or use another, more adapted, file.");
220 void ETag_surfxml_platform(){
221 simgrid::s4u::Engine::on_platform_created();
224 void STag_surfxml_prop()
226 property_sets.back().insert({A_surfxml_prop_id, A_surfxml_prop_value});
227 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
228 &(property_sets.back()));
231 void STag_surfxml_host()
233 simgrid::kernel::routing::HostCreationArgs host;
234 property_sets.emplace_back();
235 host.id = A_surfxml_host_id;
237 host.speed_per_pstate = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed,
238 "speed of host " + host.id);
240 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
241 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
243 if (A_surfxml_host_availability___file[0] != '\0') {
244 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
245 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
247 if (A_surfxml_host_speed___file[0] != '\0')
248 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
249 host.state_trace = A_surfxml_host_state___file[0]
250 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
252 host.coord = A_surfxml_host_coordinates;
254 sg_platf_new_host_begin(&host);
257 void ETag_surfxml_host()
259 sg_platf_new_host_set_properties(property_sets.back());
260 property_sets.pop_back();
262 sg_platf_new_host_seal(surf_parse_get_int(A_surfxml_host_pstate));
265 void STag_surfxml_disk() {
266 property_sets.emplace_back();
269 void ETag_surfxml_disk() {
270 simgrid::kernel::routing::DiskCreationArgs disk;
271 disk.properties = property_sets.back();
272 property_sets.pop_back();
274 disk.id = A_surfxml_disk_id;
275 disk.read_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_read___bw,
276 "read_bw of disk " + disk.id);
277 disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw,
278 "write_bw of disk " + disk.id);
280 sg_platf_new_disk(&disk);
283 void STag_surfxml_host___link(){
284 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
285 simgrid::kernel::routing::HostLinkCreationArgs host_link;
287 host_link.id = A_surfxml_host___link_id;
288 host_link.link_up = A_surfxml_host___link_up;
289 host_link.link_down = A_surfxml_host___link_down;
290 sg_platf_new_hostlink(&host_link);
293 void STag_surfxml_router(){
294 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
297 void ETag_surfxml_cluster(){
298 simgrid::kernel::routing::ClusterCreationArgs cluster;
299 cluster.properties = property_sets.back();
300 property_sets.pop_back();
302 cluster.id = A_surfxml_cluster_id;
303 cluster.prefix = A_surfxml_cluster_prefix;
304 cluster.suffix = A_surfxml_cluster_suffix;
305 explodesRadical(A_surfxml_cluster_radical, &cluster.radicals);
307 cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed,
308 "speed of cluster " + cluster.id);
309 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
310 cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw,
311 "bw of cluster " + cluster.id);
312 cluster.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat,
313 "lat of cluster " + cluster.id);
314 if(strcmp(A_surfxml_cluster_bb___bw,""))
315 cluster.bb_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___bw,
316 "bb_bw of cluster " + cluster.id);
317 if(strcmp(A_surfxml_cluster_bb___lat,""))
318 cluster.bb_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___lat,
319 "bb_lat of cluster " + cluster.id);
320 if(strcmp(A_surfxml_cluster_limiter___link,""))
321 cluster.limiter_link =
322 xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_limiter___link,
323 "limiter_link of cluster " + cluster.id);
324 if(strcmp(A_surfxml_cluster_loopback___bw,""))
325 cluster.loopback_bw =
326 xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw,
327 "loopback_bw of cluster " + cluster.id);
328 if(strcmp(A_surfxml_cluster_loopback___lat,""))
329 cluster.loopback_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___lat,
330 "loopback_lat of cluster " + cluster.id);
332 switch(AX_surfxml_cluster_topology){
333 case A_surfxml_cluster_topology_FLAT:
334 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
336 case A_surfxml_cluster_topology_TORUS:
337 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
339 case A_surfxml_cluster_topology_FAT___TREE:
340 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
342 case A_surfxml_cluster_topology_DRAGONFLY:
343 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
346 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
348 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
349 cluster.router_id = A_surfxml_cluster_router___id;
351 switch (AX_surfxml_cluster_sharing___policy) {
352 case A_surfxml_cluster_sharing___policy_SHARED:
353 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
355 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
356 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
357 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
359 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
360 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
362 case A_surfxml_cluster_sharing___policy_FATPIPE:
363 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
366 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
368 switch (AX_surfxml_cluster_bb___sharing___policy) {
369 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
370 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
372 case A_surfxml_cluster_bb___sharing___policy_SHARED:
373 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
376 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
379 sg_platf_new_tag_cluster(&cluster);
382 void STag_surfxml_cluster(){
383 property_sets.emplace_back();
386 void STag_surfxml_cabinet(){
387 simgrid::kernel::routing::CabinetCreationArgs cabinet;
388 cabinet.id = A_surfxml_cabinet_id;
389 cabinet.prefix = A_surfxml_cabinet_prefix;
390 cabinet.suffix = A_surfxml_cabinet_suffix;
391 cabinet.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_speed,
392 "speed of cabinet " + cabinet.id);
393 cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw,
394 "bw of cabinet " + cabinet.id);
395 cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat,
396 "lat of cabinet " + cabinet.id);
397 explodesRadical(A_surfxml_cabinet_radical, &cabinet.radicals);
399 sg_platf_new_cabinet(&cabinet);
402 void STag_surfxml_peer(){
403 simgrid::kernel::routing::PeerCreationArgs peer;
405 peer.id = std::string(A_surfxml_peer_id);
407 xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer " + peer.id);
408 peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in,
409 "bw_in of peer " + peer.id);
410 peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out,
411 "bw_out of peer " + peer.id);
412 peer.coord = A_surfxml_peer_coordinates;
413 peer.speed_trace = nullptr;
414 if (A_surfxml_peer_availability___file[0] != '\0') {
415 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
416 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
418 if (A_surfxml_peer_speed___file[0] != '\0')
419 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
420 peer.state_trace = A_surfxml_peer_state___file[0]
421 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
424 if (A_surfxml_peer_lat[0] != '\0')
425 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
428 sg_platf_new_peer(&peer);
431 void STag_surfxml_link(){
432 property_sets.emplace_back();
435 void ETag_surfxml_link(){
436 simgrid::kernel::routing::LinkCreationArgs link;
438 link.properties = property_sets.back();
439 property_sets.pop_back();
441 link.id = std::string(A_surfxml_link_id);
442 link.bandwidths = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth,
443 "bandwidth of link " + link.id);
444 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
445 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
448 xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link " + link.id);
449 link.latency_trace = A_surfxml_link_latency___file[0]
450 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
452 link.state_trace = A_surfxml_link_state___file[0]
453 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
456 switch (A_surfxml_link_sharing___policy) {
457 case A_surfxml_link_sharing___policy_SHARED:
458 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
460 case A_surfxml_link_sharing___policy_FATPIPE:
461 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
463 case A_surfxml_link_sharing___policy_FULLDUPLEX:
464 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
465 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
467 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
468 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
470 case A_surfxml_link_sharing___policy_WIFI:
471 link.policy = simgrid::s4u::Link::SharingPolicy::WIFI;
474 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
477 sg_platf_new_link(&link);
480 void STag_surfxml_link___ctn()
482 const auto engine = simgrid::s4u::Engine::get_instance();
483 const simgrid::s4u::Link* link;
484 simgrid::s4u::LinkInRoute::Direction direction = simgrid::s4u::LinkInRoute::Direction::NONE;
485 switch (A_surfxml_link___ctn_direction) {
486 case AU_surfxml_link___ctn_direction:
487 case A_surfxml_link___ctn_direction_NONE:
488 link = engine->link_by_name(std::string(A_surfxml_link___ctn_id));
490 case A_surfxml_link___ctn_direction_UP:
491 link = engine->split_duplex_link_by_name(std::string(A_surfxml_link___ctn_id));
492 direction = simgrid::s4u::LinkInRoute::Direction::UP;
494 case A_surfxml_link___ctn_direction_DOWN:
495 link = engine->split_duplex_link_by_name(std::string(A_surfxml_link___ctn_id));
496 direction = simgrid::s4u::LinkInRoute::Direction::DOWN;
499 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
503 switch (A_surfxml_link___ctn_direction) {
504 case A_surfxml_link___ctn_direction_UP:
505 dirname = " (upward)";
507 case A_surfxml_link___ctn_direction_DOWN:
508 dirname = " (downward)";
513 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
514 parsed_link_list.emplace_back(link, direction);
517 void ETag_surfxml_backbone()
519 auto link = std::make_unique<simgrid::kernel::routing::LinkCreationArgs>();
521 link->id = std::string(A_surfxml_backbone_id);
522 link->bandwidths.push_back(xbt_parse_get_bandwidth(
523 surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone " + link->id));
524 link->latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency,
525 "latency of backbone " + link->id);
526 link->policy = simgrid::s4u::Link::SharingPolicy::SHARED;
528 routing_cluster_add_backbone(std::move(link));
531 void STag_surfxml_route(){
532 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
533 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
536 void STag_surfxml_ASroute(){
537 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
538 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
540 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
541 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
543 void STag_surfxml_zoneRoute(){
544 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
545 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
546 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
547 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
550 void STag_surfxml_bypassRoute(){
551 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
552 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
555 void STag_surfxml_bypassASroute(){
556 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
557 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
558 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
559 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
561 void STag_surfxml_bypassZoneRoute(){
562 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
563 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
564 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
565 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
568 void ETag_surfxml_route(){
569 simgrid::kernel::routing::RouteCreationArgs route;
571 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
572 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
573 route.symmetrical = (A_surfxml_route_symmetrical == AU_surfxml_route_symmetrical ||
574 A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES ||
575 A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_yes);
577 route.link_list.swap(parsed_link_list);
579 sg_platf_new_route(&route);
582 void ETag_surfxml_ASroute()
584 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
585 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
586 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
587 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
588 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
589 ETag_surfxml_zoneRoute();
591 void ETag_surfxml_zoneRoute()
593 simgrid::kernel::routing::RouteCreationArgs ASroute;
595 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
596 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
598 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
599 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
601 ASroute.link_list.swap(parsed_link_list);
603 ASroute.symmetrical = (A_surfxml_zoneRoute_symmetrical == AU_surfxml_zoneRoute_symmetrical ||
604 A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_YES ||
605 A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_yes);
607 sg_platf_new_route(&ASroute);
610 void ETag_surfxml_bypassRoute(){
611 simgrid::kernel::routing::RouteCreationArgs route;
613 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
614 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
615 route.symmetrical = false;
617 route.link_list.swap(parsed_link_list);
619 sg_platf_new_bypass_route(&route);
622 void ETag_surfxml_bypassASroute()
624 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
625 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
626 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
627 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
628 ETag_surfxml_bypassZoneRoute();
630 void ETag_surfxml_bypassZoneRoute()
632 simgrid::kernel::routing::RouteCreationArgs ASroute;
634 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
635 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
636 ASroute.link_list.swap(parsed_link_list);
638 ASroute.symmetrical = false;
640 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
641 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
643 sg_platf_new_bypass_route(&ASroute);
646 void ETag_surfxml_trace(){
647 simgrid::kernel::routing::ProfileCreationArgs trace;
649 trace.id = A_surfxml_trace_id;
650 trace.file = A_surfxml_trace_file;
651 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
652 trace.pc_data = surfxml_pcdata;
654 sg_platf_new_trace(&trace);
657 void STag_surfxml_trace___connect()
659 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
661 trace_connect.element = A_surfxml_trace___connect_element;
662 trace_connect.trace = A_surfxml_trace___connect_trace;
664 switch (A_surfxml_trace___connect_kind) {
665 case AU_surfxml_trace___connect_kind:
666 case A_surfxml_trace___connect_kind_SPEED:
667 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
669 case A_surfxml_trace___connect_kind_BANDWIDTH:
670 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
672 case A_surfxml_trace___connect_kind_HOST___AVAIL:
673 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
675 case A_surfxml_trace___connect_kind_LATENCY:
676 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
678 case A_surfxml_trace___connect_kind_LINK___AVAIL:
679 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
682 surf_parse_error("Invalid trace kind");
684 sg_platf_trace_connect(&trace_connect);
687 void STag_surfxml_AS()
689 AX_surfxml_zone_id = AX_surfxml_AS_id;
690 AX_surfxml_zone_routing = AX_surfxml_AS_routing;
694 void ETag_surfxml_AS()
699 void STag_surfxml_zone()
701 property_sets.emplace_back();
702 simgrid::kernel::routing::ZoneCreationArgs zone;
703 zone.id = A_surfxml_zone_id;
704 zone.routing = A_surfxml_zone_routing;
705 sg_platf_new_zone_begin(&zone);
708 void ETag_surfxml_zone()
710 sg_platf_new_zone_set_properties(property_sets.back());
711 property_sets.pop_back();
712 sg_platf_new_zone_seal();
715 void STag_surfxml_config()
717 property_sets.emplace_back();
718 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
719 if (_sg_cfg_init_status == 2) {
720 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
725 void ETag_surfxml_config()
727 // Sort config elements before applying.
728 // That's a little waste of time, but not doing so would break the tests
729 auto current_property_set = property_sets.back();
731 std::vector<std::string> keys;
732 for (auto const& kv : current_property_set) {
733 keys.push_back(kv.first);
735 std::sort(keys.begin(), keys.end());
736 for (const std::string& key : keys) {
737 if (simgrid::config::is_default(key.c_str())) {
738 std::string cfg = key + ":" + current_property_set.at(key);
739 simgrid::config::set_parse(cfg);
741 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
743 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
745 property_sets.pop_back();
748 static std::vector<std::string> arguments;
750 void STag_surfxml_process()
752 AX_surfxml_actor_function = AX_surfxml_process_function;
753 STag_surfxml_actor();
756 void STag_surfxml_actor()
758 property_sets.emplace_back();
759 arguments.assign(1, A_surfxml_actor_function);
762 void ETag_surfxml_process()
764 AX_surfxml_actor_host = AX_surfxml_process_host;
765 AX_surfxml_actor_function = AX_surfxml_process_function;
766 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
767 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
768 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
769 ETag_surfxml_actor();
772 void ETag_surfxml_actor()
774 simgrid::kernel::routing::ActorCreationArgs actor;
776 actor.properties = property_sets.back();
777 property_sets.pop_back();
779 actor.args.swap(arguments);
780 actor.host = A_surfxml_actor_host;
781 actor.function = A_surfxml_actor_function;
782 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
783 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
785 switch (A_surfxml_actor_on___failure) {
786 case AU_surfxml_actor_on___failure:
787 case A_surfxml_actor_on___failure_DIE:
788 actor.restart_on_failure = false;
790 case A_surfxml_actor_on___failure_RESTART:
791 actor.restart_on_failure = true;
794 surf_parse_error("Invalid on failure behavior");
797 sg_platf_new_actor(&actor);
800 void STag_surfxml_argument(){
801 arguments.emplace_back(A_surfxml_argument_value);
804 void STag_surfxml_model___prop(){
805 XBT_INFO("Deprecated tag <model_prop> ignored");
808 void ETag_surfxml_prop(){/* Nothing to do */}
809 void STag_surfxml_random(){/* Nothing to do */}
810 void ETag_surfxml_random(){/* Nothing to do */}
811 void ETag_surfxml_trace___connect(){/* Nothing to do */}
812 void STag_surfxml_trace()
813 { /* Nothing to do */
815 void ETag_surfxml_router(){/*Nothing to do*/}
816 void ETag_surfxml_host___link(){/* Nothing to do */}
817 void ETag_surfxml_cabinet(){/* Nothing to do */}
818 void ETag_surfxml_peer(){/* Nothing to do */}
819 void STag_surfxml_backbone(){/* Nothing to do */}
820 void ETag_surfxml_link___ctn(){/* Nothing to do */}
821 void ETag_surfxml_argument(){/* Nothing to do */}
822 void ETag_surfxml_model___prop(){/* Nothing to do */}
824 /* Open and Close parse file */
825 YY_BUFFER_STATE surf_input_buffer;
827 void surf_parse_open(const std::string& file)
829 surf_parsed_filename = file;
830 std::string dir = simgrid::xbt::Path(file).get_dir_name();
831 surf_path.push_back(dir);
833 surf_file_to_parse = surf_fopen(file, "r");
834 if (surf_file_to_parse == nullptr)
835 throw std::invalid_argument(std::string("Unable to open '") + file + "' from '" + simgrid::xbt::Path().get_name() +
836 "'. Does this file exist?");
837 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
838 surf_parse__switch_to_buffer(surf_input_buffer);
839 surf_parse_lineno = 1;
842 void surf_parse_close()
844 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
846 if (surf_file_to_parse) {
847 surf_parse__delete_buffer(surf_input_buffer);
848 fclose(surf_file_to_parse);
849 surf_file_to_parse = nullptr; //Must be reset for Bypass
853 /* Call the lexer to parse the currently opened file */
856 bool err = surf_parse_lex();
857 surf_parse_assert(not err, "Flex returned an error code");