Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
introduce a few synonyms in XML to allow the use of the new names
[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), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
450       "Changes introduced in SimGrid 3.13:\n"
451       "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
452       "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
453       "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
454       "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
455       "\n\n"
456       "Use simgrid_update_xml to update your file automatically. "
457       "This program is installed automatically with SimGrid, or "
458       "available in the tools/ directory of the source archive.",surf_parsed_filename, version);
459
460   sg_platf_begin();
461 }
462 void ETag_surfxml_platform(){
463   sg_platf_end();
464 }
465
466 void STag_surfxml_host(){
467   ZONE_TAG = 0;
468   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
469 }
470
471 void STag_surfxml_prop()
472 {
473   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
474     XBT_DEBUG("Set Zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
475     simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_AS_id);
476
477     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
478   }
479   else{
480     if (!current_property_set)
481       current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
482     xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
483     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
484               current_property_set);
485   }
486 }
487
488 void ETag_surfxml_host()    {
489   s_sg_platf_host_cbarg_t host;
490   memset(&host,0,sizeof(host));
491
492   host.properties = current_property_set;
493   current_property_set = nullptr;
494
495   host.id = A_surfxml_host_id;
496
497   host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
498
499   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
500   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
501   host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
502   host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
503   host.pstate      = surf_parse_get_int(A_surfxml_host_pstate);
504   host.coord       = A_surfxml_host_coordinates;
505
506   sg_platf_new_host(&host);
507 }
508
509 void STag_surfxml_host___link(){
510   XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
511   s_sg_platf_host_link_cbarg_t host_link;
512   memset(&host_link,0,sizeof(host_link));
513
514   host_link.id        = A_surfxml_host___link_id;
515   host_link.link_up   = A_surfxml_host___link_up;
516   host_link.link_down = A_surfxml_host___link_down;
517   sg_platf_new_hostlink(&host_link);
518 }
519
520 void STag_surfxml_router(){
521   sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
522 }
523
524 void ETag_surfxml_cluster(){
525   s_sg_platf_cluster_cbarg_t cluster;
526   memset(&cluster,0,sizeof(cluster));
527   cluster.properties = current_property_set;
528   current_property_set = nullptr;
529
530   cluster.id          = A_surfxml_cluster_id;
531   cluster.prefix      = A_surfxml_cluster_prefix;
532   cluster.suffix      = A_surfxml_cluster_suffix;
533   cluster.radicals    = explodesRadical(A_surfxml_cluster_radical);
534   cluster.speeds      = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
535   cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
536   cluster.bw          = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
537   cluster.lat         = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
538   if(strcmp(A_surfxml_cluster_bb___bw,""))
539     cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
540   if(strcmp(A_surfxml_cluster_bb___lat,""))
541     cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
542   if(strcmp(A_surfxml_cluster_limiter___link,""))
543     cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
544   if(strcmp(A_surfxml_cluster_loopback___bw,""))
545     cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
546   if(strcmp(A_surfxml_cluster_loopback___lat,""))
547     cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
548
549   switch(AX_surfxml_cluster_topology){
550   case A_surfxml_cluster_topology_FLAT:
551     cluster.topology= SURF_CLUSTER_FLAT ;
552     break;
553   case A_surfxml_cluster_topology_TORUS:
554     cluster.topology= SURF_CLUSTER_TORUS ;
555     break;
556   case A_surfxml_cluster_topology_FAT___TREE:
557     cluster.topology = SURF_CLUSTER_FAT_TREE;
558     break;
559   case A_surfxml_cluster_topology_DRAGONFLY:
560     cluster.topology= SURF_CLUSTER_DRAGONFLY ;
561     break;
562   default:
563     surf_parse_error("Invalid cluster topology for cluster %s",
564                      cluster.id);
565     break;
566   }
567   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
568   cluster.router_id = A_surfxml_cluster_router___id;
569
570   switch (AX_surfxml_cluster_sharing___policy) {
571   case A_surfxml_cluster_sharing___policy_SHARED:
572     cluster.sharing_policy = SURF_LINK_SHARED;
573     break;
574   case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
575     cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
576     break;
577   case A_surfxml_cluster_sharing___policy_FATPIPE:
578     cluster.sharing_policy = SURF_LINK_FATPIPE;
579     break;
580   default:
581     surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
582     break;
583   }
584   switch (AX_surfxml_cluster_bb___sharing___policy) {
585   case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
586     cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
587     break;
588   case A_surfxml_cluster_bb___sharing___policy_SHARED:
589     cluster.bb_sharing_policy = SURF_LINK_SHARED;
590     break;
591   default:
592     surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
593     break;
594   }
595
596   sg_platf_new_cluster(&cluster);
597 }
598
599 void STag_surfxml_cluster(){
600   ZONE_TAG = 0;
601   parse_after_config();
602   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
603 }
604
605 void STag_surfxml_cabinet(){
606   parse_after_config();
607   s_sg_platf_cabinet_cbarg_t cabinet;
608   memset(&cabinet,0,sizeof(cabinet));
609   cabinet.id      = A_surfxml_cabinet_id;
610   cabinet.prefix  = A_surfxml_cabinet_prefix;
611   cabinet.suffix  = A_surfxml_cabinet_suffix;
612   cabinet.speed   = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
613   cabinet.bw      = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
614   cabinet.lat     = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
615   cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
616
617   sg_platf_new_cabinet(&cabinet);
618 }
619
620 void STag_surfxml_peer(){
621   parse_after_config();
622   s_sg_platf_peer_cbarg_t peer;
623   memset(&peer,0,sizeof(peer));
624   peer.id          = A_surfxml_peer_id;
625   peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
626   peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
627   peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
628   peer.coord       = A_surfxml_peer_coordinates;
629   peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
630   peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
631
632   if (A_surfxml_peer_lat[0] != '\0')
633     XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
634              A_surfxml_peer_lat);
635
636   sg_platf_new_peer(&peer);
637 }
638
639 void STag_surfxml_link(){
640   ZONE_TAG = 0;
641   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
642 }
643
644 void ETag_surfxml_link(){
645   LinkCreationArgs link;
646
647   link.properties          = current_property_set;
648   current_property_set     = nullptr;
649
650   link.id                  = std::string(A_surfxml_link_id);
651   link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
652   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
653   link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
654   link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
655   link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
656
657   switch (A_surfxml_link_sharing___policy) {
658   case A_surfxml_link_sharing___policy_SHARED:
659     link.policy = SURF_LINK_SHARED;
660     break;
661   case A_surfxml_link_sharing___policy_FATPIPE:
662      link.policy = SURF_LINK_FATPIPE;
663      break;
664   case A_surfxml_link_sharing___policy_FULLDUPLEX:
665      link.policy = SURF_LINK_FULLDUPLEX;
666      break;
667   default:
668     surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
669     break;
670   }
671
672   sg_platf_new_link(&link);
673 }
674
675 void STag_surfxml_link___ctn(){
676
677   simgrid::surf::LinkImpl* link = nullptr;
678   char *link_name=nullptr;
679   switch (A_surfxml_link___ctn_direction) {
680   case AU_surfxml_link___ctn_direction:
681   case A_surfxml_link___ctn_direction_NONE:
682     link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
683     break;
684   case A_surfxml_link___ctn_direction_UP:
685     link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
686     link      = simgrid::surf::LinkImpl::byName(link_name);
687     break;
688   case A_surfxml_link___ctn_direction_DOWN:
689     link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
690     link      = simgrid::surf::LinkImpl::byName(link_name);
691     break;
692   }
693   xbt_free(link_name); // no-op if it's already nullptr
694
695   const char* dirname = "";
696   switch (A_surfxml_link___ctn_direction) {
697     case A_surfxml_link___ctn_direction_UP:
698       dirname = " (upward)";
699       break;
700     case A_surfxml_link___ctn_direction_DOWN:
701       dirname = " (downward)";
702       break;
703     default:
704       dirname = "";
705   }
706   surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
707   parsed_link_list.push_back(link);
708 }
709
710 void ETag_surfxml_backbone(){
711   LinkCreationArgs link;
712
713   link.properties = nullptr;
714   link.id = std::string(A_surfxml_backbone_id);
715   link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
716   link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
717   link.policy = SURF_LINK_SHARED;
718
719   sg_platf_new_link(&link);
720   routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
721 }
722
723 void STag_surfxml_route(){
724   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_src), "Route src='%s' does name a node.",
725                     A_surfxml_route_src);
726   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_dst), "Route dst='%s' does name a node.",
727                     A_surfxml_route_dst);
728 }
729
730 void STag_surfxml_ASroute(){
731   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_src), "ASroute src='%s' does name a node.",
732                     A_surfxml_ASroute_src);
733   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_dst), "ASroute dst='%s' does name a node.",
734                     A_surfxml_ASroute_dst);
735
736   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___src), "ASroute gw_src='%s' does name a node.",
737                     A_surfxml_ASroute_gw___src);
738   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___dst), "ASroute gw_dst='%s' does name a node.",
739                     A_surfxml_ASroute_gw___dst);
740 }
741 void STag_surfxml_zoneRoute(){
742   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src), "zoneRoute src='%s' does name a node.",
743                     A_surfxml_zoneRoute_src);
744   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst), "zoneRoute dst='%s' does name a node.",
745                     A_surfxml_zoneRoute_dst);
746
747   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src), "zoneRoute gw_src='%s' does name a node.",
748                     A_surfxml_zoneRoute_gw___src);
749   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst), "zoneRoute gw_dst='%s' does name a node.",
750                     A_surfxml_zoneRoute_gw___dst);
751 }
752
753 void STag_surfxml_bypassRoute(){
754   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src), "bypassRoute src='%s' does name a node.",
755                     A_surfxml_bypassRoute_src);
756   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst), "bypassRoute dst='%s' does name a node.",
757                     A_surfxml_bypassRoute_dst);
758 }
759
760 void STag_surfxml_bypassASroute(){
761   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_src),
762                     "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
763   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_dst),
764                     "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
765   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___src),
766                     "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
767   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
768                     "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
769 }
770 void STag_surfxml_bypassZoneRoute(){
771   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src),
772                     "bypassASroute src='%s' does name a node.", A_surfxml_bypassZoneRoute_src);
773   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst),
774                     "bypassASroute dst='%s' does name a node.", A_surfxml_bypassZoneRoute_dst);
775   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src),
776                     "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassZoneRoute_gw___src);
777   surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst),
778                     "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassZoneRoute_gw___dst);
779 }
780
781 void ETag_surfxml_route(){
782   s_sg_platf_route_cbarg_t route;
783   memset(&route,0,sizeof(route));
784
785   route.src         = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
786   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
787   route.gw_src    = nullptr;
788   route.gw_dst    = nullptr;
789   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
790   route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
791
792   for (auto link: parsed_link_list)
793     route.link_list->push_back(link);
794   parsed_link_list.clear();
795
796   sg_platf_new_route(&route);
797   delete route.link_list;
798 }
799
800 void ETag_surfxml_ASroute()
801 {
802   AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
803   AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
804   AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
805   AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
806   AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
807   ETag_surfxml_zoneRoute();
808 }
809 void ETag_surfxml_zoneRoute()
810 {
811   s_sg_platf_route_cbarg_t ASroute;
812   memset(&ASroute,0,sizeof(ASroute));
813
814   ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
815   ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
816
817   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
818   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
819
820   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
821
822   for (auto link: parsed_link_list)
823     ASroute.link_list->push_back(link);
824   parsed_link_list.clear();
825
826   switch (A_surfxml_zoneRoute_symmetrical) {
827   case AU_surfxml_zoneRoute_symmetrical:
828   case A_surfxml_zoneRoute_symmetrical_YES:
829     ASroute.symmetrical = true;
830     break;
831   case A_surfxml_zoneRoute_symmetrical_NO:
832     ASroute.symmetrical = false;
833     break;
834   }
835
836   sg_platf_new_route(&ASroute);
837   delete ASroute.link_list;
838 }
839
840 void ETag_surfxml_bypassRoute(){
841   s_sg_platf_route_cbarg_t route;
842   memset(&route,0,sizeof(route));
843
844   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
845   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
846   route.gw_src = nullptr;
847   route.gw_dst = nullptr;
848   route.symmetrical = false;
849   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
850
851   for (auto link: parsed_link_list)
852     route.link_list->push_back(link);
853   parsed_link_list.clear();
854
855   sg_platf_new_bypassRoute(&route);
856   delete route.link_list;
857 }
858
859 void ETag_surfxml_bypassASroute()
860 {
861   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
862   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
863   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
864   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
865   ETag_surfxml_bypassZoneRoute();
866 }
867 void ETag_surfxml_bypassZoneRoute()
868 {
869   s_sg_platf_route_cbarg_t ASroute;
870   memset(&ASroute,0,sizeof(ASroute));
871
872   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
873   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
874   ASroute.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
875   for (auto link: parsed_link_list)
876     ASroute.link_list->push_back(link);
877   parsed_link_list.clear();
878
879   ASroute.symmetrical = false;
880
881   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
882   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
883
884   sg_platf_new_bypassRoute(&ASroute);
885   delete ASroute.link_list;
886 }
887
888 void ETag_surfxml_trace(){
889   s_sg_platf_trace_cbarg_t trace;
890   memset(&trace,0,sizeof(trace));
891
892   trace.id = A_surfxml_trace_id;
893   trace.file = A_surfxml_trace_file;
894   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
895   trace.pc_data = surfxml_pcdata;
896
897   sg_platf_new_trace(&trace);
898 }
899
900 void STag_surfxml_trace___connect(){
901   parse_after_config();
902   s_sg_platf_trace_connect_cbarg_t trace_connect;
903   memset(&trace_connect,0,sizeof(trace_connect));
904
905   trace_connect.element = A_surfxml_trace___connect_element;
906   trace_connect.trace = A_surfxml_trace___connect_trace;
907
908   switch (A_surfxml_trace___connect_kind) {
909   case AU_surfxml_trace___connect_kind:
910   case A_surfxml_trace___connect_kind_SPEED:
911     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_SPEED;
912     break;
913   case A_surfxml_trace___connect_kind_BANDWIDTH:
914     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_BANDWIDTH;
915     break;
916   case A_surfxml_trace___connect_kind_HOST___AVAIL:
917     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
918     break;
919   case A_surfxml_trace___connect_kind_LATENCY:
920     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LATENCY;
921     break;
922   case A_surfxml_trace___connect_kind_LINK___AVAIL:
923     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
924     break;
925   }
926   sg_platf_trace_connect(&trace_connect);
927 }
928
929 void STag_surfxml_AS(){
930   AX_surfxml_zone_id = AX_surfxml_AS_id;
931   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
932   STag_surfxml_zone();
933 }
934 void ETag_surfxml_AS(){
935   ETag_surfxml_zone();
936 }
937 void STag_surfxml_zone(){
938   parse_after_config();
939   ZONE_TAG                   = 1;
940   s_sg_platf_AS_cbarg_t AS = { A_surfxml_zone_id, (int)A_surfxml_zone_routing};
941
942   sg_platf_new_AS_begin(&AS);
943 }
944 void ETag_surfxml_zone(){
945   sg_platf_new_AS_seal();
946 }
947
948 void STag_surfxml_config(){
949   ZONE_TAG = 0;
950   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
951   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
952   if (_sg_cfg_init_status == 2) {
953     surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
954   }
955 }
956 void ETag_surfxml_config(){
957   xbt_dict_cursor_t cursor = nullptr;
958   char *key;
959   char *elem;
960   xbt_dict_foreach(current_property_set, cursor, key, elem) {
961     if (xbt_cfg_is_default_value(key)) {
962       char* cfg = bprintf("%s:%s", key, elem);
963       xbt_cfg_set_parse(cfg);
964       free(cfg);
965     } else
966       XBT_INFO("The custom configuration '%s' is already defined by user!",key);
967   }
968   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
969
970   xbt_dict_free(&current_property_set);
971   current_property_set = nullptr;
972 }
973
974 static int argc;
975 static char **argv;
976
977 void STag_surfxml_process()
978 {
979   AX_surfxml_actor_function = AX_surfxml_process_function;
980   STag_surfxml_actor();
981 }
982 void STag_surfxml_actor()
983 {
984   ZONE_TAG  = 0;
985   argc    = 1;
986   argv    = xbt_new(char *, 1);
987   argv[0] = xbt_strdup(A_surfxml_actor_function);
988   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
989 }
990
991 void ETag_surfxml_process()
992 {
993   AX_surfxml_actor_host = AX_surfxml_process_host;
994   AX_surfxml_actor_function = AX_surfxml_process_function;
995   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
996   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
997   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
998   ETag_surfxml_actor();
999 }
1000 void ETag_surfxml_actor()
1001 {
1002   s_sg_platf_process_cbarg_t actor;
1003   memset(&actor,0,sizeof(actor));
1004
1005   actor.argc       = argc;
1006   actor.argv       = (const char **)argv;
1007   actor.properties = current_property_set;
1008   actor.host       = A_surfxml_actor_host;
1009   actor.function   = A_surfxml_actor_function;
1010   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1011   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
1012
1013   switch (A_surfxml_actor_on___failure) {
1014   case AU_surfxml_actor_on___failure:
1015   case A_surfxml_actor_on___failure_DIE:
1016     actor.on_failure =  SURF_ACTOR_ON_FAILURE_DIE;
1017     break;
1018   case A_surfxml_actor_on___failure_RESTART:
1019     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
1020     break;
1021   }
1022
1023   sg_platf_new_process(&actor);
1024
1025   for (int i = 0; i != argc; ++i)
1026     xbt_free(argv[i]);
1027   xbt_free(argv);
1028   argv = nullptr;
1029
1030   current_property_set = nullptr;
1031 }
1032
1033 void STag_surfxml_argument(){
1034   argc++;
1035   argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1036   argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1037 }
1038
1039 void STag_surfxml_model___prop(){
1040   if (!current_model_property_set)
1041     current_model_property_set = new std::map<std::string, std::string>();
1042
1043   current_model_property_set->insert(
1044       {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
1045 }
1046
1047 void ETag_surfxml_prop(){/* Nothing to do */}
1048 void STag_surfxml_random(){/* Nothing to do */}
1049 void ETag_surfxml_random(){/* Nothing to do */}
1050 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1051 void STag_surfxml_trace(){parse_after_config();}
1052 void ETag_surfxml_router(){/*Nothing to do*/}
1053 void ETag_surfxml_host___link(){/* Nothing to do */}
1054 void ETag_surfxml_cabinet(){/* Nothing to do */}
1055 void ETag_surfxml_peer(){/* Nothing to do */}
1056 void STag_surfxml_backbone(){/* Nothing to do */}
1057 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1058 void ETag_surfxml_argument(){/* Nothing to do */}
1059 void ETag_surfxml_model___prop(){/* Nothing to do */}
1060
1061 /* Open and Close parse file */
1062 void surf_parse_open(const char *file)
1063 {
1064   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1065
1066   surf_parsed_filename = xbt_strdup(file);
1067   char* dir            = xbt_dirname(file);
1068   surf_path.push_back(std::string(dir));
1069   xbt_free(dir);
1070
1071   surf_file_to_parse = surf_fopen(file, "r");
1072   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1073   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1074   surf_parse__switch_to_buffer(surf_input_buffer);
1075   surf_parse_lineno = 1;
1076 }
1077
1078 void surf_parse_close()
1079 {
1080   if (surf_parsed_filename) {
1081     surf_path.pop_back();
1082   }
1083
1084   free(surf_parsed_filename);
1085   surf_parsed_filename = nullptr;
1086
1087   if (surf_file_to_parse) {
1088     surf_parse__delete_buffer(surf_input_buffer);
1089     fclose(surf_file_to_parse);
1090     surf_file_to_parse = nullptr; //Must be reset for Bypass
1091   }
1092 }
1093
1094 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1095 static int _surf_parse() {
1096   return surf_parse_lex();
1097 }
1098
1099 int_f_void_t surf_parse = _surf_parse;
1100
1101 SG_END_DECL()