Logo AND Algorithmique Numérique Distribuée

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