Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d59eeb052325e84d726f197cd2a62b94c850948e
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
1 /* Copyright (c) 2006-2017. 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/s4u/Engine.hpp"
7 #include "simgrid/sg_config.h"
8 #include "src/kernel/routing/NetPoint.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "xbt/file.h"
11
12 #include "src/surf/xml/platf_private.hpp"
13 #include <boost/algorithm/string.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
16 #include <string>
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
19
20 SG_BEGIN_DECL()
21
22 int ETag_surfxml_include_state();
23
24 #include "simgrid_dtd.c"
25
26 char* surf_parsed_filename = nullptr; // to locate parse error messages
27
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
29
30 /*
31  * Helping functions
32  */
33 void surf_parse_assert(bool cond, const char *fmt, ...) {
34   if (!cond ) {
35     va_list va;
36     va_start(va,fmt);
37     int lineno = surf_parse_lineno;
38     char *msg = bvprintf(fmt,va);
39     va_end(va);
40     cleanup();
41     XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
42     surf_exit();
43     xbt_die("Exiting now");
44   }
45 }
46 void surf_parse_error(const char *fmt, ...) {
47   va_list va;
48   va_start(va,fmt);
49   int lineno = surf_parse_lineno;
50   char *msg = bvprintf(fmt,va);
51   va_end(va);
52   cleanup();
53   XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
54   surf_exit();
55   xbt_die("Exiting now");
56 }
57 void surf_parse_warn(const char *fmt, ...) {
58   va_list va;
59   va_start(va,fmt);
60   char *msg = bvprintf(fmt,va);
61   va_end(va);
62     XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
63     free(msg);
64 }
65
66 double surf_parse_get_double(const char *string) {
67   double res;
68   int ret = sscanf(string, "%lg", &res);
69   if (ret != 1)
70     surf_parse_error("%s is not a double", string);
71   return res;
72 }
73
74 int surf_parse_get_int(const char *string) {
75   int res;
76   int ret = sscanf(string, "%d", &res);
77   if (ret != 1)
78     surf_parse_error("%s is not an integer", string);
79   return res;
80 }
81
82 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
83 static std::vector<int>* explodesRadical(const char* radicals)
84 {
85   std::vector<int>* exploded = new std::vector<int>();
86
87   // Make all hosts
88   std::vector<std::string> radical_elements;
89   boost::split(radical_elements, radicals, boost::is_any_of(","));
90   for (auto group : radical_elements) {
91     std::vector<std::string> radical_ends;
92     boost::split(radical_ends, group, boost::is_any_of("-"));
93     int start                = surf_parse_get_int((radical_ends.front()).c_str());
94     int end                  = 0;
95
96     switch (radical_ends.size()) {
97       case 1:
98         end = start;
99         break;
100       case 2:
101         end = surf_parse_get_int((radical_ends.back()).c_str());
102         break;
103       default:
104         surf_parse_error("Malformed radical: %s", group.c_str());
105         break;
106     }
107     for (int i = start; i <= end; i++)
108       exploded->push_back(i);
109   }
110
111   return exploded;
112 }
113
114 struct unit_scale {
115   const char *unit;
116   double scale;
117 };
118
119 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
120 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
121     const char *entity_kind, const char *name, const char *error_msg, const char *default_unit)
122 {
123   char* ptr;
124   int i;
125   errno = 0;
126   double res   = strtod(string, &ptr);
127   if (errno == ERANGE)
128     surf_parse_error("value out of range: %s", string);
129   if (ptr == string)
130     surf_parse_error("cannot parse number: %s", string);
131   if (ptr[0] == '\0') {
132     if (res == 0)
133       return res; // Ok, 0 can be unit-less
134
135     XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
136     ptr = (char*)default_unit;
137   }
138   for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
139
140   if (units[i].unit != nullptr)
141     res *= units[i].scale;
142   else
143     surf_parse_error("unknown unit: %s", ptr);
144   return res;
145 }
146
147 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
148 {
149   const struct unit_scale units[] = {
150     { "w",  7 * 24 * 60 * 60 },
151     { "d",  24 * 60 * 60 },
152     { "h",  60 * 60 },
153     { "m",  60 },
154     { "s",  1.0 },
155     { "ms", 1e-3 },
156     { "us", 1e-6 },
157     { "ns", 1e-9 },
158     { "ps", 1e-12 },
159     { nullptr, 0 }
160   };
161   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
162       "Append 's' to your time to get seconds", "s");
163 }
164
165 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
166 {
167   const struct unit_scale units[] = {
168     { "EiB", pow(1024, 6) },
169     { "PiB", pow(1024, 5) },
170     { "TiB", pow(1024, 4) },
171     { "GiB", pow(1024, 3) },
172     { "MiB", pow(1024, 2) },
173     { "KiB", 1024 },
174     { "EB",  1e18 },
175     { "PB",  1e15 },
176     { "TB",  1e12 },
177     { "GB",  1e9 },
178     { "MB",  1e6 },
179     { "kB",  1e3 },
180     { "B",   1.0 },
181     { "Eib", 0.125 * pow(1024, 6) },
182     { "Pib", 0.125 * pow(1024, 5) },
183     { "Tib", 0.125 * pow(1024, 4) },
184     { "Gib", 0.125 * pow(1024, 3) },
185     { "Mib", 0.125 * pow(1024, 2) },
186     { "Kib", 0.125 * 1024 },
187     { "Eb",  0.125 * 1e18 },
188     { "Pb",  0.125 * 1e15 },
189     { "Tb",  0.125 * 1e12 },
190     { "Gb",  0.125 * 1e9 },
191     { "Mb",  0.125 * 1e6 },
192     { "kb",  0.125 * 1e3 },
193     { "b",   0.125 },
194     { nullptr,    0 }
195   };
196   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
197       "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
198 }
199
200 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
201 {
202   const struct unit_scale units[] = {
203     { "EiBps", pow(1024, 6) },
204     { "PiBps", pow(1024, 5) },
205     { "TiBps", pow(1024, 4) },
206     { "GiBps", pow(1024, 3) },
207     { "MiBps", pow(1024, 2) },
208     { "KiBps", 1024 },
209     { "EBps",  1e18 },
210     { "PBps",  1e15 },
211     { "TBps",  1e12 },
212     { "GBps",  1e9 },
213     { "MBps",  1e6 },
214     { "kBps",  1e3 },
215     { "Bps",   1.0 },
216     { "Eibps", 0.125 * pow(1024, 6) },
217     { "Pibps", 0.125 * pow(1024, 5) },
218     { "Tibps", 0.125 * pow(1024, 4) },
219     { "Gibps", 0.125 * pow(1024, 3) },
220     { "Mibps", 0.125 * pow(1024, 2) },
221     { "Kibps", 0.125 * 1024 },
222     { "Tbps",  0.125 * 1e12 },
223     { "Gbps",  0.125 * 1e9 },
224     { "Mbps",  0.125 * 1e6 },
225     { "kbps",  0.125 * 1e3 },
226     { "bps",   0.125 },
227     { nullptr,    0 }
228   };
229   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
230       "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
231 }
232
233 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
234 {
235   const struct unit_scale units[] = {
236     { "yottaflops", 1e24 },
237     { "Yf",         1e24 },
238     { "zettaflops", 1e21 },
239     { "Zf",         1e21 },
240     { "exaflops",   1e18 },
241     { "Ef",         1e18 },
242     { "petaflops",  1e15 },
243     { "Pf",         1e15 },
244     { "teraflops",  1e12 },
245     { "Tf",         1e12 },
246     { "gigaflops",  1e9 },
247     { "Gf",         1e9 },
248     { "megaflops",  1e6 },
249     { "Mf",         1e6 },
250     { "kiloflops",  1e3 },
251     { "kf",         1e3 },
252     { "flops",      1.0 },
253     { "f",          1.0 },
254     { nullptr,         0 }
255   };
256   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
257       "Append 'f' or 'flops' to your speed to get flop per second", "f");
258 }
259
260 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){
261
262   std::vector<double> speed_per_pstate;
263
264   if (strchr(speeds, ',') == nullptr){
265     double speed = surf_parse_get_speed(speeds, entity_kind, id);
266     speed_per_pstate.push_back(speed);
267   } else {
268     std::vector<std::string> pstate_list;
269     boost::split(pstate_list, speeds, boost::is_any_of(","));
270     for (auto speed_str : pstate_list) {
271       boost::trim(speed_str);
272       double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
273       speed_per_pstate.push_back(speed);
274       XBT_DEBUG("Speed value: %f", speed);
275     }
276   }
277   return speed_per_pstate;
278 }
279
280 /*
281  * All the callback lists that can be overridden anywhere.
282  * (this list should probably be reduced to the bare minimum to allow the models to work)
283  */
284
285 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
286
287 /* The default current property receiver. Setup in the corresponding opening callbacks. */
288 xbt_dict_t current_property_set = nullptr;
289 std::map<std::string, std::string>* current_model_property_set = nullptr;
290 int ZONE_TAG                            = 0; // Whether we just opened a zone tag (to see what to do with the properties)
291
292 /* dictionary of random generator data */
293 xbt_dict_t random_data_list = nullptr;
294
295 YY_BUFFER_STATE surf_input_buffer;
296 FILE *surf_file_to_parse = nullptr;
297
298 /*
299  * Stuff relative to storage
300  */
301 void STag_surfxml_storage()
302 {
303   ZONE_TAG = 0;
304   XBT_DEBUG("STag_surfxml_storage");
305   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
306 }
307 void ETag_surfxml_storage()
308 {
309   s_sg_platf_storage_cbarg_t storage;
310   memset(&storage,0,sizeof(storage));
311
312   storage.properties   = current_property_set;
313   current_property_set = nullptr;
314
315   storage.id           = A_surfxml_storage_id;
316   storage.type_id      = A_surfxml_storage_typeId;
317   storage.content      = A_surfxml_storage_content;
318   storage.content_type = A_surfxml_storage_content___type;
319   storage.attach       = A_surfxml_storage_attach;
320   sg_platf_new_storage(&storage);
321 }
322 void STag_surfxml_storage___type()
323 {
324   ZONE_TAG = 0;
325   XBT_DEBUG("STag_surfxml_storage___type");
326   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
327   xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
328 }
329 void ETag_surfxml_storage___type()
330 {
331   s_sg_platf_storage_type_cbarg_t storage_type;
332   memset(&storage_type,0,sizeof(storage_type));
333
334   storage_type.properties = current_property_set;
335   current_property_set    = nullptr;
336
337   storage_type.model_properties = current_model_property_set;
338   current_model_property_set    = nullptr;
339
340   storage_type.content          = A_surfxml_storage___type_content;
341   storage_type.content_type     = A_surfxml_storage___type_content___type;
342   storage_type.id               = A_surfxml_storage___type_id;
343   storage_type.model            = A_surfxml_storage___type_model;
344   storage_type.size             = surf_parse_get_size(A_surfxml_storage___type_size,
345         "size of storage type", storage_type.id);
346   sg_platf_new_storage_type(&storage_type);
347 }
348 void STag_surfxml_mount()
349 {
350   XBT_DEBUG("STag_surfxml_mount");
351 }
352 void ETag_surfxml_mount()
353 {
354   s_sg_platf_mount_cbarg_t mount;
355   memset(&mount,0,sizeof(mount));
356
357   mount.name      = A_surfxml_mount_name;
358   mount.storageId = A_surfxml_mount_storageId;
359   sg_platf_new_mount(&mount);
360 }
361
362 /*
363  * Stuff relative to the <include> tag
364  */
365 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
366 static std::vector<FILE*> surf_file_to_parse_stack;
367 static std::vector<char*> surf_parsed_filename_stack;
368
369 void STag_surfxml_include()
370 {
371   parse_after_config();
372   XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
373   surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
374   surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
375
376   surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
377
378   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
379   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
380
381   surf_input_buffer_stack.push_back(surf_input_buffer);
382   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
383   surf_parse_push_buffer_state(surf_input_buffer);
384
385   fflush(nullptr);
386 }
387
388 void ETag_surfxml_include() {
389 /* Nothing to do when done with reading the include tag.
390  * Instead, the handling should be deferred until the EOF of current buffer -- see below */
391 }
392
393 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
394  *
395  * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
396  * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
397  * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
398  * error message in that case.
399  *
400  * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
401  * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
402  * on a line. One day maybe, if the maya allow it.
403  */
404 int ETag_surfxml_include_state()
405 {
406   fflush(nullptr);
407   XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
408
409   if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
410     return 0;
411
412   // Yeah, we were in an <include> Restore state and proceed.
413   fclose(surf_file_to_parse);
414   surf_file_to_parse_stack.pop_back();
415   surf_parse_pop_buffer_state();
416   surf_input_buffer_stack.pop_back();
417
418   // Restore the filename for error messages
419   free(surf_parsed_filename);
420   surf_parsed_filename_stack.pop_back();
421
422   return 1;
423 }
424
425 /* Stag and Etag parse functions */
426
427 void STag_surfxml_platform() {
428   XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
429
430   xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
431       "You're using an ancient XML file.\n"
432       "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
433       "instead of MBytes, MFlops and seconds.\n"
434
435       "Use simgrid_update_xml to update your file automatically. "
436       "This program is installed automatically with SimGrid, or "
437       "available in the tools/ directory of the source archive.\n"
438
439       "Please check also out the SURF section of the ChangeLog for "
440       "the 3.1 version for more information. \n"
441
442       "Last, do not forget to also update your values for "
443       "the calls to MSG_task_create (if any).");
444   xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
445       "You're using an old XML file.\n"
446       "Use simgrid_update_xml to update your file automatically. "
447       "This program is installed automatically with SimGrid, or "
448       "available in the tools/ directory of the source archive.");
449   xbt_assert((version >= 4.0),
450              "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
451              "Changes introduced in SimGrid 3.13:\n"
452              "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
453              "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
454              "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
455              "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
456              "\n\n"
457              "Use simgrid_update_xml to update your file automatically. "
458              "This program is installed automatically with SimGrid, or "
459              "available in the tools/ directory of the source archive.",
460              surf_parsed_filename, version);
461   if (version < 4.1) {
462     XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
463              "That's fine, the new version is backward compatible. \n\n"
464              "Use simgrid_update_xml to update your file automatically. "
465              "This program is installed automatically with SimGrid, or "
466              "available in the tools/ directory of the source archive.",
467              version, surf_parsed_filename);
468   }
469   xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
470                              "The most recent formalism that this version of SimGrid understands is v4.1.\n"
471                              "Please update your code, or use another, more adapted, file.",
472              surf_parsed_filename, version);
473
474   sg_platf_begin();
475 }
476 void ETag_surfxml_platform(){
477   sg_platf_end();
478 }
479
480 void STag_surfxml_host(){
481   ZONE_TAG = 0;
482   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
483 }
484
485 void STag_surfxml_prop()
486 {
487   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
488     XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
489     simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_zone_id);
490
491     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
492   }
493   else{
494     if (!current_property_set)
495       current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
496     xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
497     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
498               current_property_set);
499   }
500 }
501
502 void ETag_surfxml_host()    {
503   s_sg_platf_host_cbarg_t host;
504   memset(&host,0,sizeof(host));
505
506   host.properties = current_property_set;
507   current_property_set = nullptr;
508
509   host.id = A_surfxml_host_id;
510
511   host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
512
513   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
514   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
515   host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
516   host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
517   host.pstate      = surf_parse_get_int(A_surfxml_host_pstate);
518   host.coord       = A_surfxml_host_coordinates;
519
520   sg_platf_new_host(&host);
521 }
522
523 void STag_surfxml_host___link(){
524   XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
525   s_sg_platf_host_link_cbarg_t host_link;
526   memset(&host_link,0,sizeof(host_link));
527
528   host_link.id        = A_surfxml_host___link_id;
529   host_link.link_up   = A_surfxml_host___link_up;
530   host_link.link_down = A_surfxml_host___link_down;
531   sg_platf_new_hostlink(&host_link);
532 }
533
534 void STag_surfxml_router(){
535   sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
536 }
537
538 void ETag_surfxml_cluster(){
539   s_sg_platf_cluster_cbarg_t cluster;
540   memset(&cluster,0,sizeof(cluster));
541   cluster.properties = current_property_set;
542   current_property_set = nullptr;
543
544   cluster.id          = A_surfxml_cluster_id;
545   cluster.prefix      = A_surfxml_cluster_prefix;
546   cluster.suffix      = A_surfxml_cluster_suffix;
547   cluster.radicals    = explodesRadical(A_surfxml_cluster_radical);
548   cluster.speeds      = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
549   cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
550   cluster.bw          = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
551   cluster.lat         = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
552   if(strcmp(A_surfxml_cluster_bb___bw,""))
553     cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
554   if(strcmp(A_surfxml_cluster_bb___lat,""))
555     cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
556   if(strcmp(A_surfxml_cluster_limiter___link,""))
557     cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
558   if(strcmp(A_surfxml_cluster_loopback___bw,""))
559     cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
560   if(strcmp(A_surfxml_cluster_loopback___lat,""))
561     cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
562
563   switch(AX_surfxml_cluster_topology){
564   case A_surfxml_cluster_topology_FLAT:
565     cluster.topology= SURF_CLUSTER_FLAT ;
566     break;
567   case A_surfxml_cluster_topology_TORUS:
568     cluster.topology= SURF_CLUSTER_TORUS ;
569     break;
570   case A_surfxml_cluster_topology_FAT___TREE:
571     cluster.topology = SURF_CLUSTER_FAT_TREE;
572     break;
573   case A_surfxml_cluster_topology_DRAGONFLY:
574     cluster.topology= SURF_CLUSTER_DRAGONFLY ;
575     break;
576   default:
577     surf_parse_error("Invalid cluster topology for cluster %s",
578                      cluster.id);
579     break;
580   }
581   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
582   cluster.router_id = A_surfxml_cluster_router___id;
583
584   switch (AX_surfxml_cluster_sharing___policy) {
585   case A_surfxml_cluster_sharing___policy_SHARED:
586     cluster.sharing_policy = SURF_LINK_SHARED;
587     break;
588   case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
589     cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
590     break;
591   case A_surfxml_cluster_sharing___policy_FATPIPE:
592     cluster.sharing_policy = SURF_LINK_FATPIPE;
593     break;
594   default:
595     surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
596     break;
597   }
598   switch (AX_surfxml_cluster_bb___sharing___policy) {
599   case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
600     cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
601     break;
602   case A_surfxml_cluster_bb___sharing___policy_SHARED:
603     cluster.bb_sharing_policy = SURF_LINK_SHARED;
604     break;
605   default:
606     surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
607     break;
608   }
609
610   sg_platf_new_cluster(&cluster);
611 }
612
613 void STag_surfxml_cluster(){
614   ZONE_TAG = 0;
615   parse_after_config();
616   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
617 }
618
619 void STag_surfxml_cabinet(){
620   parse_after_config();
621   s_sg_platf_cabinet_cbarg_t cabinet;
622   memset(&cabinet,0,sizeof(cabinet));
623   cabinet.id      = A_surfxml_cabinet_id;
624   cabinet.prefix  = A_surfxml_cabinet_prefix;
625   cabinet.suffix  = A_surfxml_cabinet_suffix;
626   cabinet.speed   = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
627   cabinet.bw      = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
628   cabinet.lat     = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
629   cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
630
631   sg_platf_new_cabinet(&cabinet);
632 }
633
634 void STag_surfxml_peer(){
635   parse_after_config();
636   s_sg_platf_peer_cbarg_t peer;
637   memset(&peer,0,sizeof(peer));
638   peer.id          = A_surfxml_peer_id;
639   peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
640   peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
641   peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
642   peer.coord       = A_surfxml_peer_coordinates;
643   peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
644   peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
645
646   if (A_surfxml_peer_lat[0] != '\0')
647     XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
648              A_surfxml_peer_lat);
649
650   sg_platf_new_peer(&peer);
651 }
652
653 void STag_surfxml_link(){
654   ZONE_TAG = 0;
655   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
656 }
657
658 void ETag_surfxml_link(){
659   LinkCreationArgs link;
660
661   link.properties          = current_property_set;
662   current_property_set     = nullptr;
663
664   link.id                  = std::string(A_surfxml_link_id);
665   link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
666   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
667   link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
668   link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
669   link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
670
671   switch (A_surfxml_link_sharing___policy) {
672   case A_surfxml_link_sharing___policy_SHARED:
673     link.policy = SURF_LINK_SHARED;
674     break;
675   case A_surfxml_link_sharing___policy_FATPIPE:
676      link.policy = SURF_LINK_FATPIPE;
677      break;
678   case A_surfxml_link_sharing___policy_FULLDUPLEX:
679      link.policy = SURF_LINK_FULLDUPLEX;
680      break;
681   default:
682     surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
683     break;
684   }
685
686   sg_platf_new_link(&link);
687 }
688
689 void STag_surfxml_link___ctn(){
690
691   simgrid::surf::LinkImpl* link = nullptr;
692   char *link_name=nullptr;
693   switch (A_surfxml_link___ctn_direction) {
694   case AU_surfxml_link___ctn_direction:
695   case A_surfxml_link___ctn_direction_NONE:
696     link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
697     break;
698   case A_surfxml_link___ctn_direction_UP:
699     link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
700     link      = simgrid::surf::LinkImpl::byName(link_name);
701     break;
702   case A_surfxml_link___ctn_direction_DOWN:
703     link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
704     link      = simgrid::surf::LinkImpl::byName(link_name);
705     break;
706   }
707   xbt_free(link_name); // no-op if it's already nullptr
708
709   const char* dirname = "";
710   switch (A_surfxml_link___ctn_direction) {
711     case A_surfxml_link___ctn_direction_UP:
712       dirname = " (upward)";
713       break;
714     case A_surfxml_link___ctn_direction_DOWN:
715       dirname = " (downward)";
716       break;
717     default:
718       dirname = "";
719   }
720   surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
721   parsed_link_list.push_back(link);
722 }
723
724 void ETag_surfxml_backbone(){
725   LinkCreationArgs link;
726
727   link.properties = nullptr;
728   link.id = std::string(A_surfxml_backbone_id);
729   link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
730   link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
731   link.policy = SURF_LINK_SHARED;
732
733   sg_platf_new_link(&link);
734   routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
735 }
736
737 void STag_surfxml_route(){
738   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_src), "Route src='%s' does name a node.",
739                     A_surfxml_route_src);
740   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_dst), "Route dst='%s' does name a node.",
741                     A_surfxml_route_dst);
742 }
743
744 void STag_surfxml_ASroute(){
745   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_src), "ASroute src='%s' does name a node.",
746                     A_surfxml_ASroute_src);
747   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_dst), "ASroute dst='%s' does name a node.",
748                     A_surfxml_ASroute_dst);
749
750   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___src), "ASroute gw_src='%s' does name a node.",
751                     A_surfxml_ASroute_gw___src);
752   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___dst), "ASroute gw_dst='%s' does name a node.",
753                     A_surfxml_ASroute_gw___dst);
754 }
755 void STag_surfxml_zoneRoute(){
756   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src), "zoneRoute src='%s' does name a node.",
757                     A_surfxml_zoneRoute_src);
758   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst), "zoneRoute dst='%s' does name a node.",
759                     A_surfxml_zoneRoute_dst);
760
761   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src), "zoneRoute gw_src='%s' does name a node.",
762                     A_surfxml_zoneRoute_gw___src);
763   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst), "zoneRoute gw_dst='%s' does name a node.",
764                     A_surfxml_zoneRoute_gw___dst);
765 }
766
767 void STag_surfxml_bypassRoute(){
768   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src), "bypassRoute src='%s' does name a node.",
769                     A_surfxml_bypassRoute_src);
770   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst), "bypassRoute dst='%s' does name a node.",
771                     A_surfxml_bypassRoute_dst);
772 }
773
774 void STag_surfxml_bypassASroute(){
775   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_src),
776                     "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
777   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_dst),
778                     "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
779   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___src),
780                     "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
781   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
782                     "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
783 }
784 void STag_surfxml_bypassZoneRoute(){
785   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src),
786                     "bypassASroute src='%s' does name a node.", A_surfxml_bypassZoneRoute_src);
787   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst),
788                     "bypassASroute dst='%s' does name a node.", A_surfxml_bypassZoneRoute_dst);
789   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src),
790                     "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassZoneRoute_gw___src);
791   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst),
792                     "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassZoneRoute_gw___dst);
793 }
794
795 void ETag_surfxml_route(){
796   s_sg_platf_route_cbarg_t route;
797   memset(&route,0,sizeof(route));
798
799   route.src         = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
800   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
801   route.gw_src    = nullptr;
802   route.gw_dst    = nullptr;
803   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
804   route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
805
806   for (auto link: parsed_link_list)
807     route.link_list->push_back(link);
808   parsed_link_list.clear();
809
810   sg_platf_new_route(&route);
811   delete route.link_list;
812 }
813
814 void ETag_surfxml_ASroute()
815 {
816   AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
817   AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
818   AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
819   AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
820   AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
821   ETag_surfxml_zoneRoute();
822 }
823 void ETag_surfxml_zoneRoute()
824 {
825   s_sg_platf_route_cbarg_t ASroute;
826   memset(&ASroute,0,sizeof(ASroute));
827
828   ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
829   ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
830
831   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
832   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
833
834   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
835
836   for (auto link: parsed_link_list)
837     ASroute.link_list->push_back(link);
838   parsed_link_list.clear();
839
840   switch (A_surfxml_zoneRoute_symmetrical) {
841   case AU_surfxml_zoneRoute_symmetrical:
842   case A_surfxml_zoneRoute_symmetrical_YES:
843     ASroute.symmetrical = true;
844     break;
845   case A_surfxml_zoneRoute_symmetrical_NO:
846     ASroute.symmetrical = false;
847     break;
848   }
849
850   sg_platf_new_route(&ASroute);
851   delete ASroute.link_list;
852 }
853
854 void ETag_surfxml_bypassRoute(){
855   s_sg_platf_route_cbarg_t route;
856   memset(&route,0,sizeof(route));
857
858   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
859   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
860   route.gw_src = nullptr;
861   route.gw_dst = nullptr;
862   route.symmetrical = false;
863   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
864
865   for (auto link: parsed_link_list)
866     route.link_list->push_back(link);
867   parsed_link_list.clear();
868
869   sg_platf_new_bypassRoute(&route);
870   delete route.link_list;
871 }
872
873 void ETag_surfxml_bypassASroute()
874 {
875   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
876   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
877   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
878   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
879   ETag_surfxml_bypassZoneRoute();
880 }
881 void ETag_surfxml_bypassZoneRoute()
882 {
883   s_sg_platf_route_cbarg_t ASroute;
884   memset(&ASroute,0,sizeof(ASroute));
885
886   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
887   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
888   ASroute.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
889   for (auto link: parsed_link_list)
890     ASroute.link_list->push_back(link);
891   parsed_link_list.clear();
892
893   ASroute.symmetrical = false;
894
895   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
896   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
897
898   sg_platf_new_bypassRoute(&ASroute);
899   delete ASroute.link_list;
900 }
901
902 void ETag_surfxml_trace(){
903   s_sg_platf_trace_cbarg_t trace;
904   memset(&trace,0,sizeof(trace));
905
906   trace.id = A_surfxml_trace_id;
907   trace.file = A_surfxml_trace_file;
908   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
909   trace.pc_data = surfxml_pcdata;
910
911   sg_platf_new_trace(&trace);
912 }
913
914 void STag_surfxml_trace___connect(){
915   parse_after_config();
916   s_sg_platf_trace_connect_cbarg_t trace_connect;
917   memset(&trace_connect,0,sizeof(trace_connect));
918
919   trace_connect.element = A_surfxml_trace___connect_element;
920   trace_connect.trace = A_surfxml_trace___connect_trace;
921
922   switch (A_surfxml_trace___connect_kind) {
923   case AU_surfxml_trace___connect_kind:
924   case A_surfxml_trace___connect_kind_SPEED:
925     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_SPEED;
926     break;
927   case A_surfxml_trace___connect_kind_BANDWIDTH:
928     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_BANDWIDTH;
929     break;
930   case A_surfxml_trace___connect_kind_HOST___AVAIL:
931     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
932     break;
933   case A_surfxml_trace___connect_kind_LATENCY:
934     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LATENCY;
935     break;
936   case A_surfxml_trace___connect_kind_LINK___AVAIL:
937     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
938     break;
939   }
940   sg_platf_trace_connect(&trace_connect);
941 }
942
943 void STag_surfxml_AS(){
944   AX_surfxml_zone_id = AX_surfxml_AS_id;
945   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
946   STag_surfxml_zone();
947 }
948 void ETag_surfxml_AS(){
949   ETag_surfxml_zone();
950 }
951 void STag_surfxml_zone(){
952   parse_after_config();
953   ZONE_TAG                 = 1;
954   s_sg_platf_AS_cbarg_t AS = { A_surfxml_zone_id, (int)A_surfxml_zone_routing};
955
956   sg_platf_new_AS_begin(&AS);
957 }
958 void ETag_surfxml_zone(){
959   sg_platf_new_AS_seal();
960 }
961
962 void STag_surfxml_config(){
963   ZONE_TAG = 0;
964   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
965   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
966   if (_sg_cfg_init_status == 2) {
967     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
968                      "<link>, etc).");
969   }
970 }
971 void ETag_surfxml_config(){
972   xbt_dict_cursor_t cursor = nullptr;
973   char *key;
974   char *elem;
975   xbt_dict_foreach(current_property_set, cursor, key, elem) {
976     if (xbt_cfg_is_default_value(key)) {
977       char* cfg = bprintf("%s:%s", key, elem);
978       xbt_cfg_set_parse(cfg);
979       free(cfg);
980     } else
981       XBT_INFO("The custom configuration '%s' is already defined by user!",key);
982   }
983   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
984
985   xbt_dict_free(&current_property_set);
986   current_property_set = nullptr;
987 }
988
989 static int argc;
990 static char **argv;
991
992 void STag_surfxml_process()
993 {
994   AX_surfxml_actor_function = AX_surfxml_process_function;
995   STag_surfxml_actor();
996 }
997 void STag_surfxml_actor()
998 {
999   ZONE_TAG  = 0;
1000   argc    = 1;
1001   argv    = xbt_new(char *, 1);
1002   argv[0] = xbt_strdup(A_surfxml_actor_function);
1003   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
1004 }
1005
1006 void ETag_surfxml_process()
1007 {
1008   AX_surfxml_actor_host = AX_surfxml_process_host;
1009   AX_surfxml_actor_function = AX_surfxml_process_function;
1010   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
1011   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1012   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1013   ETag_surfxml_actor();
1014 }
1015 void ETag_surfxml_actor()
1016 {
1017   s_sg_platf_process_cbarg_t actor;
1018   memset(&actor,0,sizeof(actor));
1019
1020   actor.argc       = argc;
1021   actor.argv       = (const char **)argv;
1022   actor.properties = current_property_set;
1023   actor.host       = A_surfxml_actor_host;
1024   actor.function   = A_surfxml_actor_function;
1025   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1026   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
1027
1028   switch (A_surfxml_actor_on___failure) {
1029   case AU_surfxml_actor_on___failure:
1030   case A_surfxml_actor_on___failure_DIE:
1031     actor.on_failure =  SURF_ACTOR_ON_FAILURE_DIE;
1032     break;
1033   case A_surfxml_actor_on___failure_RESTART:
1034     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
1035     break;
1036   }
1037
1038   sg_platf_new_process(&actor);
1039
1040   for (int i = 0; i != argc; ++i)
1041     xbt_free(argv[i]);
1042   xbt_free(argv);
1043   argv = nullptr;
1044
1045   current_property_set = nullptr;
1046 }
1047
1048 void STag_surfxml_argument(){
1049   argc++;
1050   argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1051   argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1052 }
1053
1054 void STag_surfxml_model___prop(){
1055   if (!current_model_property_set)
1056     current_model_property_set = new std::map<std::string, std::string>();
1057
1058   current_model_property_set->insert(
1059       {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
1060 }
1061
1062 void ETag_surfxml_prop(){/* Nothing to do */}
1063 void STag_surfxml_random(){/* Nothing to do */}
1064 void ETag_surfxml_random(){/* Nothing to do */}
1065 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1066 void STag_surfxml_trace(){parse_after_config();}
1067 void ETag_surfxml_router(){/*Nothing to do*/}
1068 void ETag_surfxml_host___link(){/* Nothing to do */}
1069 void ETag_surfxml_cabinet(){/* Nothing to do */}
1070 void ETag_surfxml_peer(){/* Nothing to do */}
1071 void STag_surfxml_backbone(){/* Nothing to do */}
1072 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1073 void ETag_surfxml_argument(){/* Nothing to do */}
1074 void ETag_surfxml_model___prop(){/* Nothing to do */}
1075
1076 /* Open and Close parse file */
1077 void surf_parse_open(const char *file)
1078 {
1079   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1080
1081   surf_parsed_filename = xbt_strdup(file);
1082   char* dir            = xbt_dirname(file);
1083   surf_path.push_back(std::string(dir));
1084   xbt_free(dir);
1085
1086   surf_file_to_parse = surf_fopen(file, "r");
1087   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1088   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1089   surf_parse__switch_to_buffer(surf_input_buffer);
1090   surf_parse_lineno = 1;
1091 }
1092
1093 void surf_parse_close()
1094 {
1095   if (surf_parsed_filename) {
1096     surf_path.pop_back();
1097   }
1098
1099   free(surf_parsed_filename);
1100   surf_parsed_filename = nullptr;
1101
1102   if (surf_file_to_parse) {
1103     surf_parse__delete_buffer(surf_input_buffer);
1104     fclose(surf_file_to_parse);
1105     surf_file_to_parse = nullptr; //Must be reset for Bypass
1106   }
1107 }
1108
1109 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1110 static int _surf_parse() {
1111   return surf_parse_lex();
1112 }
1113
1114 int_f_void_t surf_parse = _surf_parse;
1115
1116 SG_END_DECL()