Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'split_link_impl' into 'master'
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
1 /* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
18
19 #include <boost/algorithm/string/classification.hpp>
20 #include <boost/algorithm/string/split.hpp>
21 #include <string>
22 #include <tuple>
23 #include <unordered_map>
24 #include <vector>
25
26 #include "simgrid_dtd.c"
27
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
29
30 std::string surf_parsed_filename; // Currently parsed file (for the error messages)
31 std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
32
33 /* Helping functions */
34 void surf_parse_assert(bool cond, const std::string& msg)
35 {
36   if (not cond)
37     surf_parse_error(msg);
38 }
39
40 void surf_parse_error(const std::string& msg)
41 {
42   throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
43 }
44
45 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
46 {
47   if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found
48     return;
49
50   std::string msg = pre + hostname + post + " Existing netpoints: \n";
51
52   std::vector<simgrid::kernel::routing::NetPoint*> netpoints =
53       simgrid::s4u::Engine::get_instance()->get_all_netpoints();
54   std::sort(netpoints.begin(), netpoints.end(),
55             [](const simgrid::kernel::routing::NetPoint* a, const simgrid::kernel::routing::NetPoint* b) {
56               return a->get_name() < b->get_name();
57             });
58   bool first = true;
59   for (auto const& np : netpoints) {
60     if (np->is_netzone())
61       continue;
62
63     if (not first)
64       msg += ",";
65     first = false;
66     msg += "'" + np->get_name() + "'";
67     if (msg.length() > 4096) {
68       msg.pop_back(); // remove trailing quote
69       msg += "...(list truncated)......";
70       break;
71     }
72   }
73   surf_parse_error(msg);
74 }
75
76 double surf_parse_get_double(const std::string& s)
77 {
78   try {
79     return std::stod(s);
80   } catch (const std::invalid_argument&) {
81     surf_parse_error(s + " is not a double");
82   }
83 }
84
85 int surf_parse_get_int(const std::string& s)
86 {
87   try {
88     return std::stoi(s);
89   } catch (const std::invalid_argument&) {
90     surf_parse_error(s + " is not a double");
91   }
92 }
93
94 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
95 static void explodesRadical(const std::string& radicals, std::vector<int>* exploded)
96 {
97   // Make all hosts
98   std::vector<std::string> radical_elements;
99   boost::split(radical_elements, radicals, boost::is_any_of(","));
100   for (auto const& group : radical_elements) {
101     std::vector<std::string> radical_ends;
102     boost::split(radical_ends, group, boost::is_any_of("-"));
103     int start = surf_parse_get_int(radical_ends.front());
104     int end   = 0;
105
106     switch (radical_ends.size()) {
107       case 1:
108         end = start;
109         break;
110       case 2:
111         end = surf_parse_get_int(radical_ends.back());
112         break;
113       default:
114         surf_parse_error(std::string("Malformed radical: ") + group);
115     }
116     for (int i = start; i <= end; i++)
117       exploded->push_back(i);
118   }
119 }
120
121
122 /*
123  * All the callback lists that can be overridden anywhere.
124  * (this list should probably be reduced to the bare minimum to allow the models to work)
125  */
126
127 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
128
129 std::vector<std::unordered_map<std::string, std::string>> property_sets;
130
131 /* The default current property receiver. Setup in the corresponding opening callbacks. */
132 std::unordered_map<std::string, std::string> current_model_property_set;
133
134 FILE *surf_file_to_parse = nullptr;
135
136 /* Stuff relative to storage */
137 void STag_surfxml_storage()
138 {
139   xbt_die("<storage> tag was removed in SimGrid v3.27. Please stop using it now.");
140 }
141
142 void ETag_surfxml_storage()
143 {
144   /* Won't happen since <storage> is now removed since v3.27. */
145 }
146 void STag_surfxml_storage___type()
147 {
148   xbt_die("<storage_type> tag was removed in SimGrid v3.27. Please stop using it now.");
149 }
150 void ETag_surfxml_storage___type()
151 {
152   /* Won't happen since <storage_type> is now removed since v3.27. */
153 }
154
155 void STag_surfxml_mount()
156 {
157   xbt_die("<mount> tag was removed in SimGrid v3.27. Please stop using it now.");
158 }
159
160 void ETag_surfxml_mount()
161 {
162   /* Won't happen since <mount> is now removed since v3.27. */
163 }
164
165 void STag_surfxml_include()
166 {
167   xbt_die("<include> tag was removed in SimGrid v3.18. Please stop using it now.");
168 }
169
170 void ETag_surfxml_include()
171 {
172   /* Won't happen since <include> is now removed since v3.18. */
173 }
174
175 /* Stag and Etag parse functions */
176 void STag_surfxml_platform() {
177   double version = surf_parse_get_double(A_surfxml_platform_version);
178
179   surf_parse_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
180       "You're using an ancient XML file.\n"
181       "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
182       "instead of MBytes, MFlops and seconds.\n"
183
184       "Use simgrid_update_xml to update your file automatically. "
185       "This program is installed automatically with SimGrid, or "
186       "available in the tools/ directory of the source archive.\n"
187
188       "Please check also out the SURF section of the ChangeLog for "
189       "the 3.1 version for more information. \n"
190
191       "Last, do not forget to also update your values for "
192       "the calls to MSG_task_create (if any).");
193   surf_parse_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
194       "You're using an old XML file.\n"
195       "Use simgrid_update_xml to update your file automatically. "
196       "This program is installed automatically with SimGrid, or "
197       "available in the tools/ directory of the source archive.");
198   surf_parse_assert((version >= 4.0),
199              std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n "
200              "Changes introduced in SimGrid 3.13:\n"
201              "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
202              "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
203              "  - DOCTYPE now point to the rignt URL.\n"
204              "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
205              "\n\n"
206              "Use simgrid_update_xml to update your file automatically. "
207              "This program is installed automatically with SimGrid, or "
208              "available in the tools/ directory of the source archive.");
209   if (version < 4.1) {
210     XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
211              "That's fine, the new version is backward compatible. \n\n"
212              "Use simgrid_update_xml to update your file automatically to get rid of this warning. "
213              "This program is installed automatically with SimGrid, or "
214              "available in the tools/ directory of the source archive.",
215              version, surf_parsed_filename.c_str());
216   }
217   surf_parse_assert(version <= 4.1,
218              std::string("******* THIS FILE COMES FROM THE FUTURE (v:")+std::to_string(version)+") *********\n "
219              "The most recent formalism that this version of SimGrid understands is v4.1.\n"
220              "Please update your code, or use another, more adapted, file.");
221 }
222 void ETag_surfxml_platform(){
223   simgrid::s4u::Engine::on_platform_created();
224 }
225
226 void STag_surfxml_prop()
227 {
228   property_sets.back().insert({A_surfxml_prop_id, A_surfxml_prop_value});
229   XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
230             &(property_sets.back()));
231 }
232
233 void STag_surfxml_host()
234 {
235   simgrid::kernel::routing::HostCreationArgs host;
236   property_sets.emplace_back();
237   host.id = A_surfxml_host_id;
238
239   host.speed_per_pstate = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed,
240                                                    "speed of host " + host.id);
241
242   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
243   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
244
245   if (A_surfxml_host_availability___file[0] != '\0') {
246     XBT_WARN("The availability_file attribute in <host> is now deprecated. Please, use 'speed_file' instead.");
247     host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file);
248   }
249   if (A_surfxml_host_speed___file[0] != '\0')
250     host.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_host_speed___file);
251   host.state_trace = A_surfxml_host_state___file[0]
252                          ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
253                          : nullptr;
254   host.coord       = A_surfxml_host_coordinates;
255
256   sg_platf_new_host_begin(&host);
257 }
258
259 void ETag_surfxml_host()
260 {
261   sg_platf_new_host_set_properties(property_sets.back());
262   property_sets.pop_back();
263
264   sg_platf_new_host_seal(surf_parse_get_int(A_surfxml_host_pstate));
265 }
266
267 void STag_surfxml_disk() {
268   property_sets.emplace_back();
269 }
270
271 void ETag_surfxml_disk() {
272   simgrid::kernel::routing::DiskCreationArgs disk;
273   disk.properties = property_sets.back();
274   property_sets.pop_back();
275
276   disk.id       = A_surfxml_disk_id;
277   disk.read_bw  = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_read___bw,
278                                          "read_bw of disk " + disk.id);
279   disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw,
280                                           "write_bw of disk " + disk.id);
281
282   sg_platf_new_disk(&disk);
283 }
284
285 void STag_surfxml_host___link(){
286   XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
287   simgrid::kernel::routing::HostLinkCreationArgs host_link;
288
289   host_link.id        = A_surfxml_host___link_id;
290   host_link.link_up   = A_surfxml_host___link_up;
291   host_link.link_down = A_surfxml_host___link_down;
292   sg_platf_new_hostlink(&host_link);
293 }
294
295 void STag_surfxml_router(){
296   sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
297 }
298
299 void ETag_surfxml_cluster(){
300   simgrid::kernel::routing::ClusterCreationArgs cluster;
301   cluster.properties = property_sets.back();
302   property_sets.pop_back();
303
304   cluster.id          = A_surfxml_cluster_id;
305   cluster.prefix      = A_surfxml_cluster_prefix;
306   cluster.suffix      = A_surfxml_cluster_suffix;
307   explodesRadical(A_surfxml_cluster_radical, &cluster.radicals);
308
309   cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed,
310                                             "speed of cluster " + cluster.id);
311   cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
312   cluster.bw          = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw,
313                                        "bw of cluster " + cluster.id);
314   cluster.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat,
315                                    "lat of cluster " + cluster.id);
316   if(strcmp(A_surfxml_cluster_bb___bw,""))
317     cluster.bb_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___bw,
318                                             "bb_bw of cluster " + cluster.id);
319   if(strcmp(A_surfxml_cluster_bb___lat,""))
320     cluster.bb_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___lat,
321                                         "bb_lat of cluster " + cluster.id);
322   if(strcmp(A_surfxml_cluster_limiter___link,""))
323     cluster.limiter_link =
324         xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_limiter___link,
325                                 "limiter_link of cluster " + cluster.id);
326   if(strcmp(A_surfxml_cluster_loopback___bw,""))
327     cluster.loopback_bw =
328         xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw,
329                                 "loopback_bw of cluster " + cluster.id);
330   if(strcmp(A_surfxml_cluster_loopback___lat,""))
331     cluster.loopback_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___lat,
332                                               "loopback_lat of cluster " + cluster.id);
333
334   switch(AX_surfxml_cluster_topology){
335   case A_surfxml_cluster_topology_FLAT:
336     cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT;
337     break;
338   case A_surfxml_cluster_topology_TORUS:
339     cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS;
340     break;
341   case A_surfxml_cluster_topology_FAT___TREE:
342     cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE;
343     break;
344   case A_surfxml_cluster_topology_DRAGONFLY:
345     cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY;
346     break;
347   default:
348     surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
349   }
350   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
351   cluster.router_id = A_surfxml_cluster_router___id;
352
353   switch (AX_surfxml_cluster_sharing___policy) {
354   case A_surfxml_cluster_sharing___policy_SHARED:
355     cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
356     break;
357   case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
358     XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
359     cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
360     break;
361   case A_surfxml_cluster_sharing___policy_SPLITDUPLEX:
362     cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
363     break;
364   case A_surfxml_cluster_sharing___policy_FATPIPE:
365     cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
366     break;
367   default:
368     surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
369   }
370   switch (AX_surfxml_cluster_bb___sharing___policy) {
371   case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
372     cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
373     break;
374   case A_surfxml_cluster_bb___sharing___policy_SHARED:
375     cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED;
376     break;
377   default:
378     surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
379   }
380
381   sg_platf_new_tag_cluster(&cluster);
382 }
383
384 void STag_surfxml_cluster(){
385   property_sets.emplace_back();
386 }
387
388 void STag_surfxml_cabinet(){
389   simgrid::kernel::routing::CabinetCreationArgs cabinet;
390   cabinet.id      = A_surfxml_cabinet_id;
391   cabinet.prefix  = A_surfxml_cabinet_prefix;
392   cabinet.suffix  = A_surfxml_cabinet_suffix;
393   cabinet.speed   = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_speed,
394                                       "speed of cabinet " + cabinet.id);
395   cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw,
396                                        "bw of cabinet " + cabinet.id);
397   cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat,
398                                    "lat of cabinet " + cabinet.id);
399   explodesRadical(A_surfxml_cabinet_radical, &cabinet.radicals);
400
401   sg_platf_new_cabinet(&cabinet);
402 }
403
404 void STag_surfxml_peer(){
405   simgrid::kernel::routing::PeerCreationArgs peer;
406
407   peer.id          = std::string(A_surfxml_peer_id);
408   peer.speed =
409       xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer " + peer.id);
410   peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in,
411                                        "bw_in of peer " + peer.id);
412   peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out,
413                                         "bw_out of peer " + peer.id);
414   peer.coord       = A_surfxml_peer_coordinates;
415   peer.speed_trace = nullptr;
416   if (A_surfxml_peer_availability___file[0] != '\0') {
417     XBT_WARN("The availability_file attribute in <peer> is now deprecated. Please, use 'speed_file' instead.");
418     peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file);
419   }
420   if (A_surfxml_peer_speed___file[0] != '\0')
421     peer.speed_trace = simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_speed___file);
422   peer.state_trace = A_surfxml_peer_state___file[0]
423                          ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
424                          : nullptr;
425
426   if (A_surfxml_peer_lat[0] != '\0')
427     XBT_WARN("The latency attribute in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
428              A_surfxml_peer_lat);
429
430   sg_platf_new_peer(&peer);
431 }
432
433 void STag_surfxml_link(){
434   property_sets.emplace_back();
435 }
436
437 void ETag_surfxml_link(){
438   simgrid::kernel::routing::LinkCreationArgs link;
439
440   link.properties = property_sets.back();
441   property_sets.pop_back();
442
443   link.id                  = std::string(A_surfxml_link_id);
444   link.bandwidths          = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth,
445                                              "bandwidth of link " + link.id);
446   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0]
447                              ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
448                              : nullptr;
449   link.latency =
450       xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link " + link.id);
451   link.latency_trace       = A_surfxml_link_latency___file[0]
452                            ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
453                            : nullptr;
454   link.state_trace = A_surfxml_link_state___file[0]
455                          ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
456                          : nullptr;
457
458   switch (A_surfxml_link_sharing___policy) {
459   case A_surfxml_link_sharing___policy_SHARED:
460     link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
461     break;
462   case A_surfxml_link_sharing___policy_FATPIPE:
463     link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
464     break;
465   case A_surfxml_link_sharing___policy_FULLDUPLEX:
466     XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead.");
467     link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
468     break;
469   case A_surfxml_link_sharing___policy_SPLITDUPLEX:
470     link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX;
471     break;
472   case A_surfxml_link_sharing___policy_WIFI:
473     link.policy = simgrid::s4u::Link::SharingPolicy::WIFI;
474     break;
475   default:
476     surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
477   }
478
479   sg_platf_new_link(&link);
480 }
481
482 void STag_surfxml_link___ctn()
483 {
484   simgrid::s4u::Link* link;
485   simgrid::s4u::LinkInRoute::Direction direction = simgrid::s4u::LinkInRoute::Direction::NONE;
486   switch (A_surfxml_link___ctn_direction) {
487   case AU_surfxml_link___ctn_direction:
488   case A_surfxml_link___ctn_direction_NONE:
489     link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id));
490     break;
491   case A_surfxml_link___ctn_direction_UP:
492     link      = simgrid::s4u::SplitDuplexLink::by_name(std::string(A_surfxml_link___ctn_id));
493     direction = simgrid::s4u::LinkInRoute::Direction::UP;
494     break;
495   case A_surfxml_link___ctn_direction_DOWN:
496     link      = simgrid::s4u::SplitDuplexLink::by_name(std::string(A_surfxml_link___ctn_id));
497     direction = simgrid::s4u::LinkInRoute::Direction::DOWN;
498     break;
499   default:
500     surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
501   }
502
503   const char* dirname;
504   switch (A_surfxml_link___ctn_direction) {
505     case A_surfxml_link___ctn_direction_UP:
506       dirname = " (upward)";
507       break;
508     case A_surfxml_link___ctn_direction_DOWN:
509       dirname = " (downward)";
510       break;
511     default:
512       dirname = "";
513   }
514   surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
515   parsed_link_list.emplace_back(simgrid::s4u::LinkInRoute(link, direction));
516 }
517
518 void ETag_surfxml_backbone()
519 {
520   auto link = std::make_unique<simgrid::kernel::routing::LinkCreationArgs>();
521
522   link->id = std::string(A_surfxml_backbone_id);
523   link->bandwidths.push_back(xbt_parse_get_bandwidth(
524       surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone " + link->id));
525   link->latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency,
526                                      "latency of backbone " + link->id);
527   link->policy  = simgrid::s4u::Link::SharingPolicy::SHARED;
528
529   routing_cluster_add_backbone(std::move(link));
530 }
531
532 void STag_surfxml_route(){
533   surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
534   surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
535 }
536
537 void STag_surfxml_ASroute(){
538   surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
539   surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
540
541   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
542   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
543 }
544 void STag_surfxml_zoneRoute(){
545   surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
546   surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
547   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
548   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
549 }
550
551 void STag_surfxml_bypassRoute(){
552   surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
553   surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
554 }
555
556 void STag_surfxml_bypassASroute(){
557   surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
558   surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
559   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
560   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
561 }
562 void STag_surfxml_bypassZoneRoute(){
563   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
564   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
565   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
566   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
567 }
568
569 void ETag_surfxml_route(){
570   simgrid::kernel::routing::RouteCreationArgs route;
571
572   route.src         = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
573   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
574   route.symmetrical = (A_surfxml_route_symmetrical == AU_surfxml_route_symmetrical ||
575                        A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES ||
576                        A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_yes);
577
578   route.link_list.swap(parsed_link_list);
579
580   sg_platf_new_route(&route);
581 }
582
583 void ETag_surfxml_ASroute()
584 {
585   AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
586   AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
587   AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
588   AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
589   AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
590   ETag_surfxml_zoneRoute();
591 }
592 void ETag_surfxml_zoneRoute()
593 {
594   simgrid::kernel::routing::RouteCreationArgs ASroute;
595
596   ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
597   ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
598
599   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
600   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
601
602   ASroute.link_list.swap(parsed_link_list);
603
604   ASroute.symmetrical = (A_surfxml_zoneRoute_symmetrical == AU_surfxml_zoneRoute_symmetrical ||
605                          A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_YES ||
606                          A_surfxml_zoneRoute_symmetrical == A_surfxml_zoneRoute_symmetrical_yes);
607
608   sg_platf_new_route(&ASroute);
609 }
610
611 void ETag_surfxml_bypassRoute(){
612   simgrid::kernel::routing::RouteCreationArgs route;
613
614   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
615   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
616   route.symmetrical = false;
617
618   route.link_list.swap(parsed_link_list);
619
620   sg_platf_new_bypass_route(&route);
621 }
622
623 void ETag_surfxml_bypassASroute()
624 {
625   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
626   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
627   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
628   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
629   ETag_surfxml_bypassZoneRoute();
630 }
631 void ETag_surfxml_bypassZoneRoute()
632 {
633   simgrid::kernel::routing::RouteCreationArgs ASroute;
634
635   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
636   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
637   ASroute.link_list.swap(parsed_link_list);
638
639   ASroute.symmetrical = false;
640
641   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
642   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
643
644   sg_platf_new_bypass_route(&ASroute);
645 }
646
647 void ETag_surfxml_trace(){
648   simgrid::kernel::routing::ProfileCreationArgs trace;
649
650   trace.id = A_surfxml_trace_id;
651   trace.file = A_surfxml_trace_file;
652   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
653   trace.pc_data = surfxml_pcdata;
654
655   sg_platf_new_trace(&trace);
656 }
657
658 void STag_surfxml_trace___connect()
659 {
660   simgrid::kernel::routing::TraceConnectCreationArgs trace_connect;
661
662   trace_connect.element = A_surfxml_trace___connect_element;
663   trace_connect.trace = A_surfxml_trace___connect_trace;
664
665   switch (A_surfxml_trace___connect_kind) {
666   case AU_surfxml_trace___connect_kind:
667   case A_surfxml_trace___connect_kind_SPEED:
668     trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED;
669     break;
670   case A_surfxml_trace___connect_kind_BANDWIDTH:
671     trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH;
672     break;
673   case A_surfxml_trace___connect_kind_HOST___AVAIL:
674     trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL;
675     break;
676   case A_surfxml_trace___connect_kind_LATENCY:
677     trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY;
678     break;
679   case A_surfxml_trace___connect_kind_LINK___AVAIL:
680     trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL;
681     break;
682   default:
683     surf_parse_error("Invalid trace kind");
684   }
685   sg_platf_trace_connect(&trace_connect);
686 }
687
688 void STag_surfxml_AS()
689 {
690   AX_surfxml_zone_id = AX_surfxml_AS_id;
691   AX_surfxml_zone_routing = AX_surfxml_AS_routing;
692   STag_surfxml_zone();
693 }
694
695 void ETag_surfxml_AS()
696 {
697   ETag_surfxml_zone();
698 }
699
700 void STag_surfxml_zone()
701 {
702   property_sets.emplace_back();
703   simgrid::kernel::routing::ZoneCreationArgs zone;
704   zone.id      = A_surfxml_zone_id;
705   zone.routing = A_surfxml_zone_routing;
706   sg_platf_new_zone_begin(&zone);
707 }
708
709 void ETag_surfxml_zone()
710 {
711   sg_platf_new_zone_set_properties(property_sets.back());
712   property_sets.pop_back();
713   sg_platf_new_zone_seal();
714 }
715
716 void STag_surfxml_config()
717 {
718   property_sets.emplace_back();
719   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
720   if (_sg_cfg_init_status == 2) {
721     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
722                      "<link>, etc).");
723   }
724 }
725
726 void ETag_surfxml_config()
727 {
728   // Sort config elements before applying.
729   // That's a little waste of time, but not doing so would break the tests
730   auto current_property_set = property_sets.back();
731
732   std::vector<std::string> keys;
733   for (auto const& kv : current_property_set) {
734     keys.push_back(kv.first);
735   }
736   std::sort(keys.begin(), keys.end());
737   for (const std::string& key : keys) {
738     if (simgrid::config::is_default(key.c_str())) {
739       std::string cfg = key + ":" + current_property_set.at(key);
740       simgrid::config::set_parse(cfg);
741     } else
742       XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
743   }
744   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
745
746   property_sets.pop_back();
747 }
748
749 static std::vector<std::string> arguments;
750
751 void STag_surfxml_process()
752 {
753   AX_surfxml_actor_function = AX_surfxml_process_function;
754   STag_surfxml_actor();
755 }
756
757 void STag_surfxml_actor()
758 {
759   property_sets.emplace_back();
760   arguments.assign(1, A_surfxml_actor_function);
761 }
762
763 void ETag_surfxml_process()
764 {
765   AX_surfxml_actor_host = AX_surfxml_process_host;
766   AX_surfxml_actor_function = AX_surfxml_process_function;
767   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
768   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
769   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
770   ETag_surfxml_actor();
771 }
772
773 void ETag_surfxml_actor()
774 {
775   simgrid::kernel::routing::ActorCreationArgs actor;
776
777   actor.properties = property_sets.back();
778   property_sets.pop_back();
779
780   actor.args.swap(arguments);
781   actor.host       = A_surfxml_actor_host;
782   actor.function   = A_surfxml_actor_function;
783   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
784   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
785
786   switch (A_surfxml_actor_on___failure) {
787   case AU_surfxml_actor_on___failure:
788   case A_surfxml_actor_on___failure_DIE:
789     actor.restart_on_failure = false;
790     break;
791   case A_surfxml_actor_on___failure_RESTART:
792     actor.restart_on_failure = true;
793     break;
794   default:
795     surf_parse_error("Invalid on failure behavior");
796   }
797
798   sg_platf_new_actor(&actor);
799 }
800
801 void STag_surfxml_argument(){
802   arguments.emplace_back(A_surfxml_argument_value);
803 }
804
805 void STag_surfxml_model___prop(){
806   current_model_property_set.insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
807 }
808
809 void ETag_surfxml_prop(){/* Nothing to do */}
810 void STag_surfxml_random(){/* Nothing to do */}
811 void ETag_surfxml_random(){/* Nothing to do */}
812 void ETag_surfxml_trace___connect(){/* Nothing to do */}
813 void STag_surfxml_trace()
814 { /* Nothing to do */
815 }
816 void ETag_surfxml_router(){/*Nothing to do*/}
817 void ETag_surfxml_host___link(){/* Nothing to do */}
818 void ETag_surfxml_cabinet(){/* Nothing to do */}
819 void ETag_surfxml_peer(){/* Nothing to do */}
820 void STag_surfxml_backbone(){/* Nothing to do */}
821 void ETag_surfxml_link___ctn(){/* Nothing to do */}
822 void ETag_surfxml_argument(){/* Nothing to do */}
823 void ETag_surfxml_model___prop(){/* Nothing to do */}
824
825 /* Open and Close parse file */
826 YY_BUFFER_STATE surf_input_buffer;
827
828 void surf_parse_open(const std::string& file)
829 {
830   surf_parsed_filename = file;
831   std::string dir      = simgrid::xbt::Path(file).get_dir_name();
832   surf_path.push_back(dir);
833
834   surf_file_to_parse = surf_fopen(file, "r");
835   if (surf_file_to_parse == nullptr)
836     throw std::invalid_argument(std::string("Unable to open '") + file + "' from '" + simgrid::xbt::Path().get_name() +
837                                 "'. Does this file exist?");
838   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
839   surf_parse__switch_to_buffer(surf_input_buffer);
840   surf_parse_lineno = 1;
841 }
842
843 void surf_parse_close()
844 {
845   surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
846
847   if (surf_file_to_parse) {
848     surf_parse__delete_buffer(surf_input_buffer);
849     fclose(surf_file_to_parse);
850     surf_file_to_parse = nullptr; //Must be reset for Bypass
851   }
852 }
853
854 /* Call the lexer to parse the currently opened file */
855 void surf_parse()
856 {
857   bool err = surf_parse_lex();
858   surf_parse_assert(not err, "Flex returned an error code");
859 }