Logo AND Algorithmique Numérique Distribuée

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