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 "simgrid/sg_config.hpp"
10 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
11 #include "src/kernel/resource/profile/Profile.hpp"
12 #include "src/surf/network_interface.hpp"
13 #include "src/surf/surf_interface.hpp"
14 #include "src/surf/xml/platf_private.hpp"
15 #include "surf/surf.hpp"
16 #include "xbt/file.hpp"
17 #include "xbt/parse_units.hpp"
19 #include <boost/algorithm/string/classification.hpp>
20 #include <boost/algorithm/string/split.hpp>
23 #include <unordered_map>
26 #include "simgrid_dtd.c"
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
30 std::string surf_parsed_filename; // Currently parsed file (for the error messages)
31 std::vector<simgrid::kernel::resource::LinkImpl*>
32 parsed_link_list; /* temporary store of current link list of a route */
33 std::vector<simgrid::kernel::resource::DiskImpl*> parsed_disk_list; /* temporary store of current disk list of a host */
37 void surf_parse_assert(bool cond, const std::string& msg)
40 surf_parse_error(msg);
43 void surf_parse_error(const std::string& msg)
45 throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
48 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
50 if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
53 std::string msg = pre + hostname + post + " Existing netpoints: \n";
55 std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
56 simgrid::s4u::Engine::get_instance()->get_all_netpoints();
57 std::sort(netpoints.begin(), netpoints.end(),
58 [](const simgrid::kernel::routing::NetPoint* a, const simgrid::kernel::routing::NetPoint* b) {
59 return a->get_name() < b->get_name();
62 for (auto const& np : netpoints) {
69 msg += "'" + np->get_name() + "'";
70 if (msg.length() > 4096) {
71 msg.pop_back(); // remove trailing quote
72 msg += "...(list truncated)......";
76 surf_parse_error(msg);
79 double surf_parse_get_double(const std::string& s)
83 } catch (const std::invalid_argument&) {
84 surf_parse_error(s + " is not a double");
88 int surf_parse_get_int(const std::string& s)
92 } catch (const std::invalid_argument&) {
93 surf_parse_error(s + " is not a double");
97 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
98 static std::vector<int>* explodesRadical(const std::string& radicals)
100 auto* exploded = new std::vector<int>();
103 std::vector<std::string> radical_elements;
104 boost::split(radical_elements, radicals, boost::is_any_of(","));
105 for (auto const& group : radical_elements) {
106 std::vector<std::string> radical_ends;
107 boost::split(radical_ends, group, boost::is_any_of("-"));
108 int start = surf_parse_get_int(radical_ends.front());
111 switch (radical_ends.size()) {
116 end = surf_parse_get_int(radical_ends.back());
119 surf_parse_error(std::string("Malformed radical: ") + group);
121 for (int i = start; i <= end; i++)
122 exploded->push_back(i);
130 * All the callback lists that can be overridden anywhere.
131 * (this list should probably be reduced to the bare minimum to allow the models to work)
134 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
136 std::vector<std::unordered_map<std::string, std::string>*> property_sets;
138 /* The default current property receiver. Setup in the corresponding opening callbacks. */
139 std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
141 FILE *surf_file_to_parse = nullptr;
143 /* Stuff relative to storage */
144 void STag_surfxml_storage()
146 XBT_DEBUG("STag_surfxml_storage");
147 property_sets.push_back(new std::unordered_map<std::string, std::string>());
150 void ETag_surfxml_storage()
152 simgrid::kernel::routing::StorageCreationArgs storage;
154 storage.properties = property_sets.back();
155 property_sets.pop_back();
157 storage.filename = surf_parsed_filename;
158 storage.lineno = surf_parse_lineno;
159 storage.id = A_surfxml_storage_id;
160 storage.type_id = A_surfxml_storage_typeId;
161 storage.content = A_surfxml_storage_content;
162 storage.attach = A_surfxml_storage_attach;
164 sg_platf_new_storage(&storage);
166 void STag_surfxml_storage___type()
168 XBT_DEBUG("STag_surfxml_storage___type");
169 property_sets.push_back(new std::unordered_map<std::string, std::string>());
170 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
172 void ETag_surfxml_storage___type()
174 simgrid::kernel::routing::StorageTypeCreationArgs storage_type;
176 storage_type.properties = property_sets.back();
177 property_sets.pop_back();
179 storage_type.model_properties = current_model_property_set;
180 current_model_property_set = nullptr;
182 storage_type.content = A_surfxml_storage___type_content;
183 storage_type.id = A_surfxml_storage___type_id;
184 storage_type.model = A_surfxml_storage___type_model;
186 static_cast<sg_size_t>(surf_parse_get_size(surf_parsed_filename, surf_parse_lineno, A_surfxml_storage___type_size,
187 "size of storage type", storage_type.id.c_str()));
188 sg_platf_new_storage_type(&storage_type);
191 void STag_surfxml_mount()
193 XBT_DEBUG("STag_surfxml_mount");
196 void ETag_surfxml_mount()
198 simgrid::kernel::routing::MountCreationArgs mount;
200 mount.name = A_surfxml_mount_name;
201 mount.storageId = A_surfxml_mount_storageId;
202 sg_platf_new_mount(&mount);
205 void STag_surfxml_include()
207 xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
210 void ETag_surfxml_include()
212 /* Won't happen since <include> is now removed since v3.18. */
215 /* Stag and Etag parse functions */
216 void STag_surfxml_platform() {
217 double version = surf_parse_get_double(A_surfxml_platform_version);
219 surf_parse_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
220 "You're using an ancient XML file.\n"
221 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
222 "instead of MBytes, MFlops and seconds.\n"
224 "Use simgrid_update_xml to update your file automatically. "
225 "This program is installed automatically with SimGrid, or "
226 "available in the tools/ directory of the source archive.\n"
228 "Please check also out the SURF section of the ChangeLog for "
229 "the 3.1 version for more information. \n"
231 "Last, do not forget to also update your values for "
232 "the calls to MSG_task_create (if any).");
233 surf_parse_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
234 "You're using an old XML file.\n"
235 "Use simgrid_update_xml to update your file automatically. "
236 "This program is installed automatically with SimGrid, or "
237 "available in the tools/ directory of the source archive.");
238 surf_parse_assert((version >= 4.0),
239 std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n "
240 "Changes introduced in SimGrid 3.13:\n"
241 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
242 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
243 " - DOCTYPE now point to the rignt URL.\n"
244 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
246 "Use simgrid_update_xml to update your file automatically. "
247 "This program is installed automatically with SimGrid, or "
248 "available in the tools/ directory of the source archive.");
250 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
251 "That's fine, the new version is backward compatible. \n\n"
252 "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
253 "This program is installed automatically with SimGrid, or "
254 "available in the tools/ directory of the source archive.",
255 version, surf_parsed_filename.c_str());
257 surf_parse_assert(version <= 4.1,
258 std::string("******* THIS FILE COMES FROM THE FUTURE (v:")+std::to_string(version)+") *********\n "
259 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
260 "Please update your code, or use another, more adapted, file.");
262 void ETag_surfxml_platform(){
263 simgrid::s4u::Engine::on_platform_created();
266 void STag_surfxml_host(){
267 property_sets.push_back(new std::unordered_map<std::string, std::string>());
270 void STag_surfxml_prop()
272 property_sets.back()->insert({A_surfxml_prop_id, A_surfxml_prop_value});
273 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
274 property_sets.back());
277 void ETag_surfxml_host() {
278 simgrid::kernel::routing::HostCreationArgs host;
280 host.properties = property_sets.back();
281 property_sets.pop_back();
283 host.id = A_surfxml_host_id;
285 host.speed_per_pstate =
286 xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed, "speed of host", host.id);
288 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
289 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
291 if (A_surfxml_host_availability___file[0] != '\0') {
292 XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
293 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
295 if (A_surfxml_host_speed___file[0] != '\0')
296 host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
297 host.state_trace = A_surfxml_host_state___file[0]
298 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
300 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
301 host.coord = A_surfxml_host_coordinates;
302 host.disks.swap(parsed_disk_list);
304 sg_platf_new_host(&host);
307 void STag_surfxml_disk() {
308 property_sets.push_back(new std::unordered_map<std::string, std::string>());
311 void ETag_surfxml_disk() {
312 simgrid::kernel::routing::DiskCreationArgs disk;
313 disk.properties = property_sets.back();
314 property_sets.pop_back();
316 disk.id = A_surfxml_disk_id;
317 disk.read_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_read___bw,
318 "read_bw of disk ", disk.id);
319 disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw,
320 "write_bw of disk ", disk.id);
322 parsed_disk_list.push_back(sg_platf_new_disk(&disk));
325 void STag_surfxml_host___link(){
326 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
327 simgrid::kernel::routing::HostLinkCreationArgs host_link;
329 host_link.id = A_surfxml_host___link_id;
330 host_link.link_up = A_surfxml_host___link_up;
331 host_link.link_down = A_surfxml_host___link_down;
332 sg_platf_new_hostlink(&host_link);
335 void STag_surfxml_router(){
336 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
339 void ETag_surfxml_cluster(){
340 simgrid::kernel::routing::ClusterCreationArgs cluster;
341 cluster.properties = property_sets.back();
342 property_sets.pop_back();
344 cluster.id = A_surfxml_cluster_id;
345 cluster.prefix = A_surfxml_cluster_prefix;
346 cluster.suffix = A_surfxml_cluster_suffix;
347 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
348 cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed,
349 "speed of cluster", cluster.id);
350 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
351 cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw, "bw of cluster",
354 xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat, "lat of cluster", cluster.id);
355 if(strcmp(A_surfxml_cluster_bb___bw,""))
356 cluster.bb_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___bw,
357 "bb_bw of cluster", cluster.id);
358 if(strcmp(A_surfxml_cluster_bb___lat,""))
359 cluster.bb_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___lat,
360 "bb_lat of cluster", cluster.id);
361 if(strcmp(A_surfxml_cluster_limiter___link,""))
362 cluster.limiter_link =
363 xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_limiter___link,
364 "limiter_link of cluster", cluster.id);
365 if(strcmp(A_surfxml_cluster_loopback___bw,""))
366 cluster.loopback_bw = xbt_parse_get_bandwidth(
367 surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
368 if(strcmp(A_surfxml_cluster_loopback___lat,""))
369 cluster.loopback_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___lat,
370 "loopback_lat of cluster", cluster.id);
372 switch(AX_surfxml_cluster_topology){
373 case A_surfxml_cluster_topology_FLAT:
374 cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
376 case A_surfxml_cluster_topology_TORUS:
377 cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
379 case A_surfxml_cluster_topology_FAT___TREE:
380 cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
382 case A_surfxml_cluster_topology_DRAGONFLY:
383 cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
386 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
388 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
389 cluster.router_id = A_surfxml_cluster_router___id;
391 switch (AX_surfxml_cluster_sharing___policy) {
392 case A_surfxml_cluster_sharing___policy_SHARED:
393 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
395 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
396 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
397 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
399 case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
400 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
402 case A_surfxml_cluster_sharing___policy_FATPIPE:
403 cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
406 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
408 switch (AX_surfxml_cluster_bb___sharing___policy) {
409 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
410 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
412 case A_surfxml_cluster_bb___sharing___policy_SHARED:
413 cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
416 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
419 sg_platf_new_cluster(&cluster);
422 void STag_surfxml_cluster(){
423 property_sets.push_back(new std::unordered_map<std::string, std::string>());
426 void STag_surfxml_cabinet(){
427 simgrid::kernel::routing::CabinetCreationArgs cabinet;
428 cabinet.id = A_surfxml_cabinet_id;
429 cabinet.prefix = A_surfxml_cabinet_prefix;
430 cabinet.suffix = A_surfxml_cabinet_suffix;
431 cabinet.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_speed,
432 "speed of cabinet", cabinet.id.c_str());
433 cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw, "bw of cabinet",
435 cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat, "lat of cabinet",
437 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
439 sg_platf_new_cabinet(&cabinet);
442 void STag_surfxml_peer(){
443 simgrid::kernel::routing::PeerCreationArgs peer;
445 peer.id = std::string(A_surfxml_peer_id);
446 peer.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer",
448 peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in, "bw_in of peer",
450 peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out,
451 "bw_out of peer", peer.id.c_str());
452 peer.coord = A_surfxml_peer_coordinates;
453 peer.speed_trace = nullptr;
454 if (A_surfxml_peer_availability___file[0] != '\0') {
455 XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
456 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
458 if (A_surfxml_peer_speed___file[0] != '\0')
459 peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
460 peer.state_trace = A_surfxml_peer_state___file[0]
461 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
464 if (A_surfxml_peer_lat[0] != '\0')
465 XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
468 sg_platf_new_peer(&peer);
471 void STag_surfxml_link(){
472 property_sets.push_back(new std::unordered_map<std::string, std::string>());
475 void ETag_surfxml_link(){
476 simgrid::kernel::routing::LinkCreationArgs link;
478 link.properties = property_sets.back();
479 property_sets.pop_back();
481 link.id = std::string(A_surfxml_link_id);
482 link.bandwidths = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth,
483 "bandwidth of link", link.id.c_str());
484 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
485 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
487 link.latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link",
489 link.latency_trace = A_surfxml_link_latency___file[0]
490 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
492 link.state_trace = A_surfxml_link_state___file[0]
493 ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
496 switch (A_surfxml_link_sharing___policy) {
497 case A_surfxml_link_sharing___policy_SHARED:
498 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
500 case A_surfxml_link_sharing___policy_FATPIPE:
501 link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
503 case A_surfxml_link_sharing___policy_FULLDUPLEX:
504 XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
505 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
507 case A_surfxml_link_sharing___policy_SPLITDUPLEX:
508 link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
510 case A_surfxml_link_sharing___policy_WIFI:
511 link.policy = simgrid::s4u::Link::SharingPolicy::WIFI;
514 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
517 sg_platf_new_link(&link);
520 void STag_surfxml_link___ctn()
522 simgrid::kernel::resource::LinkImpl* link = nullptr;
523 switch (A_surfxml_link___ctn_direction) {
524 case AU_surfxml_link___ctn_direction:
525 case A_surfxml_link___ctn_direction_NONE:
526 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
528 case A_surfxml_link___ctn_direction_UP:
529 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
531 case A_surfxml_link___ctn_direction_DOWN:
532 link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
535 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
539 switch (A_surfxml_link___ctn_direction) {
540 case A_surfxml_link___ctn_direction_UP:
541 dirname = " (upward)";
543 case A_surfxml_link___ctn_direction_DOWN:
544 dirname = " (downward)";
549 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
550 parsed_link_list.push_back(link);
553 void ETag_surfxml_backbone(){
554 simgrid::kernel::routing::LinkCreationArgs link;
556 link.id = std::string(A_surfxml_backbone_id);
557 link.bandwidths.push_back(xbt_parse_get_bandwidth(
558 surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str()));
559 link.latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency,
560 "latency of backbone", link.id.c_str());
561 link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
563 sg_platf_new_link(&link);
564 routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
567 void STag_surfxml_route(){
568 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
569 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
572 void STag_surfxml_ASroute(){
573 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
574 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
576 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
577 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
579 void STag_surfxml_zoneRoute(){
580 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
581 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
582 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
583 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
586 void STag_surfxml_bypassRoute(){
587 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
588 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
591 void STag_surfxml_bypassASroute(){
592 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
593 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
594 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
595 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
597 void STag_surfxml_bypassZoneRoute(){
598 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
599 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
600 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
601 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
604 void ETag_surfxml_route(){
605 simgrid::kernel::routing::RouteCreationArgs route;
607 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
608 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
609 route.symmetrical = (A_surfxml_route_symmetrical == AU_surfxml_route_symmetrical ||
610 A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES ||
611 A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_yes);
613 route.link_list.swap(parsed_link_list);
615 sg_platf_new_route(&route);
618 void ETag_surfxml_ASroute()
620 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
621 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
622 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
623 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
624 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
625 ETag_surfxml_zoneRoute();
627 void ETag_surfxml_zoneRoute()
629 simgrid::kernel::routing::RouteCreationArgs ASroute;
631 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
632 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
634 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
635 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
637 ASroute.link_list.swap(parsed_link_list);
639 ASroute.symmetrical = (A_surfxml_zoneRoute_symmetrical == AU_surfxml_zoneRoute_symmetrical ||
640 A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_YES ||
641 A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_yes);
643 sg_platf_new_route(&ASroute);
646 void ETag_surfxml_bypassRoute(){
647 simgrid::kernel::routing::RouteCreationArgs route;
649 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
650 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
651 route.symmetrical = false;
653 route.link_list.swap(parsed_link_list);
655 sg_platf_new_bypassRoute(&route);
658 void ETag_surfxml_bypassASroute()
660 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
661 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
662 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
663 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
664 ETag_surfxml_bypassZoneRoute();
666 void ETag_surfxml_bypassZoneRoute()
668 simgrid::kernel::routing::RouteCreationArgs ASroute;
670 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
671 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
672 ASroute.link_list.swap(parsed_link_list);
674 ASroute.symmetrical = false;
676 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
677 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
679 sg_platf_new_bypassRoute(&ASroute);
682 void ETag_surfxml_trace(){
683 simgrid::kernel::routing::ProfileCreationArgs trace;
685 trace.id = A_surfxml_trace_id;
686 trace.file = A_surfxml_trace_file;
687 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
688 trace.pc_data = surfxml_pcdata;
690 sg_platf_new_trace(&trace);
693 void STag_surfxml_trace___connect()
695 simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
697 trace_connect.element = A_surfxml_trace___connect_element;
698 trace_connect.trace = A_surfxml_trace___connect_trace;
700 switch (A_surfxml_trace___connect_kind) {
701 case AU_surfxml_trace___connect_kind:
702 case A_surfxml_trace___connect_kind_SPEED:
703 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
705 case A_surfxml_trace___connect_kind_BANDWIDTH:
706 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
708 case A_surfxml_trace___connect_kind_HOST___AVAIL:
709 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
711 case A_surfxml_trace___connect_kind_LATENCY:
712 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
714 case A_surfxml_trace___connect_kind_LINK___AVAIL:
715 trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
718 surf_parse_error("Invalid trace kind");
720 sg_platf_trace_connect(&trace_connect);
723 void STag_surfxml_AS()
725 AX_surfxml_zone_id = AX_surfxml_AS_id;
726 AX_surfxml_zone_routing = AX_surfxml_AS_routing;
730 void ETag_surfxml_AS()
735 void STag_surfxml_zone()
737 property_sets.push_back(new std::unordered_map<std::string, std::string>());
738 simgrid::kernel::routing::ZoneCreationArgs zone;
739 zone.id = A_surfxml_zone_id;
740 zone.routing = A_surfxml_zone_routing;
741 sg_platf_new_Zone_begin(&zone);
744 void ETag_surfxml_zone()
746 sg_platf_new_Zone_set_properties(property_sets.back());
747 delete property_sets.back();
748 property_sets.pop_back();
750 sg_platf_new_Zone_seal();
753 void STag_surfxml_config()
755 property_sets.push_back(new std::unordered_map<std::string, std::string>());
756 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
757 if (_sg_cfg_init_status == 2) {
758 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
763 void ETag_surfxml_config()
765 // Sort config elements before applying.
766 // That's a little waste of time, but not doing so would break the tests
767 auto current_property_set = property_sets.back();
769 std::vector<std::string> keys;
770 for (auto const& kv : *current_property_set) {
771 keys.push_back(kv.first);
773 std::sort(keys.begin(), keys.end());
774 for (std::string key : keys) {
775 if (simgrid::config::is_default(key.c_str())) {
776 std::string cfg = key + ":" + current_property_set->at(key);
777 simgrid::config::set_parse(cfg);
779 XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
781 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
783 delete current_property_set;
784 property_sets.pop_back();
787 static std::vector<std::string> arguments;
789 void STag_surfxml_process()
791 AX_surfxml_actor_function = AX_surfxml_process_function;
792 STag_surfxml_actor();
795 void STag_surfxml_actor()
797 property_sets.push_back(new std::unordered_map<std::string, std::string>());
798 arguments.assign(1, A_surfxml_actor_function);
801 void ETag_surfxml_process()
803 AX_surfxml_actor_host = AX_surfxml_process_host;
804 AX_surfxml_actor_function = AX_surfxml_process_function;
805 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
806 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
807 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
808 ETag_surfxml_actor();
811 void ETag_surfxml_actor()
813 simgrid::kernel::routing::ActorCreationArgs actor;
815 actor.properties = property_sets.back();
816 property_sets.pop_back();
818 actor.args.swap(arguments);
819 actor.host = A_surfxml_actor_host;
820 actor.function = A_surfxml_actor_function;
821 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
822 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
824 switch (A_surfxml_actor_on___failure) {
825 case AU_surfxml_actor_on___failure:
826 case A_surfxml_actor_on___failure_DIE:
827 actor.restart_on_failure = false;
829 case A_surfxml_actor_on___failure_RESTART:
830 actor.restart_on_failure = true;
833 surf_parse_error("Invalid on failure behavior");
836 sg_platf_new_actor(&actor);
839 void STag_surfxml_argument(){
840 arguments.emplace_back(A_surfxml_argument_value);
843 void STag_surfxml_model___prop(){
844 if (not current_model_property_set)
845 current_model_property_set = new std::unordered_map<std::string, std::string>();
847 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
850 void ETag_surfxml_prop(){/* Nothing to do */}
851 void STag_surfxml_random(){/* Nothing to do */}
852 void ETag_surfxml_random(){/* Nothing to do */}
853 void ETag_surfxml_trace___connect(){/* Nothing to do */}
854 void STag_surfxml_trace()
855 { /* Nothing to do */
857 void ETag_surfxml_router(){/*Nothing to do*/}
858 void ETag_surfxml_host___link(){/* Nothing to do */}
859 void ETag_surfxml_cabinet(){/* Nothing to do */}
860 void ETag_surfxml_peer(){/* Nothing to do */}
861 void STag_surfxml_backbone(){/* Nothing to do */}
862 void ETag_surfxml_link___ctn(){/* Nothing to do */}
863 void ETag_surfxml_argument(){/* Nothing to do */}
864 void ETag_surfxml_model___prop(){/* Nothing to do */}
866 /* Open and Close parse file */
867 YY_BUFFER_STATE surf_input_buffer;
869 void surf_parse_open(const std::string& file)
871 surf_parsed_filename = file;
872 std::string dir = simgrid::xbt::Path(file).get_dir_name();
873 surf_path.push_back(dir);
875 surf_file_to_parse = surf_fopen(file, "r");
876 if (surf_file_to_parse == nullptr)
877 throw std::invalid_argument(std::string("Unable to open '") + file + "' from '" + simgrid::xbt::Path().get_name() +
878 "'. Does this file exist?");
879 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
880 surf_parse__switch_to_buffer(surf_input_buffer);
881 surf_parse_lineno = 1;
884 void surf_parse_close()
886 surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
888 if (surf_file_to_parse) {
889 surf_parse__delete_buffer(surf_input_buffer);
890 fclose(surf_file_to_parse);
891 surf_file_to_parse = nullptr; //Must be reset for Bypass
895 /* Call the lexer to parse the currently opened file */
898 bool err = surf_parse_lex();
899 surf_parse_assert(not err, "Flex returned an error code");