Logo AND Algorithmique Numérique Distribuée

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