1 /* Copyright (c) 2006-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include <stdarg.h> /* va_arg */
11 #include "simgrid/link.h"
12 #include "simgrid/s4u/engine.hpp"
13 #include "simgrid/sg_config.h"
14 #include "src/kernel/routing/NetPoint.hpp"
15 #include "src/surf/network_interface.hpp"
16 #include "src/surf/surf_private.h"
24 #include "src/surf/xml/platf_private.hpp"
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
30 int ETag_surfxml_include_state();
32 #include "simgrid_dtd.c"
34 char* surf_parsed_filename = nullptr; // to locate parse error messages
36 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
41 void surf_parse_assert(bool cond, const char *fmt, ...) {
45 int lineno = surf_parse_lineno;
46 char *msg = bvprintf(fmt,va);
49 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
51 xbt_die("Exiting now");
54 void surf_parse_error(const char *fmt, ...) {
57 int lineno = surf_parse_lineno;
58 char *msg = bvprintf(fmt,va);
61 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
63 xbt_die("Exiting now");
65 void surf_parse_warn(const char *fmt, ...) {
68 char *msg = bvprintf(fmt,va);
70 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
74 double surf_parse_get_double(const char *string) {
76 int ret = sscanf(string, "%lg", &res);
78 surf_parse_error("%s is not a double", string);
82 int surf_parse_get_int(const char *string) {
84 int ret = sscanf(string, "%d", &res);
86 surf_parse_error("%s is not an integer", string);
90 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
91 static std::vector<int>* explodesRadical(const char* radicals)
93 std::vector<int>* exploded = new std::vector<int>();
98 xbt_dynar_t radical_elements = xbt_str_split(radicals, ",");
99 xbt_dynar_foreach (radical_elements, iter, groups) {
101 xbt_dynar_t radical_ends = xbt_str_split(groups, "-");
102 int start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char*));
105 switch (xbt_dynar_length(radical_ends)) {
110 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char*));
113 surf_parse_error("Malformed radical: %s", groups);
117 for (int i = start; i <= end; i++)
118 exploded->push_back(i);
120 xbt_dynar_free(&radical_ends);
122 xbt_dynar_free(&radical_elements);
132 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
133 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
134 const char *entity_kind, const char *name, const char *error_msg, const char *default_unit)
139 double res = strtod(string, &ptr);
141 surf_parse_error("value out of range: %s", string);
143 surf_parse_error("cannot parse number: %s", string);
144 if (ptr[0] == '\0') {
146 return res; // Ok, 0 can be unit-less
148 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
149 ptr = (char*)default_unit;
151 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
153 if (units[i].unit != nullptr)
154 res *= units[i].scale;
156 surf_parse_error("unknown unit: %s", ptr);
160 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
162 const struct unit_scale units[] = {
163 { "w", 7 * 24 * 60 * 60 },
164 { "d", 24 * 60 * 60 },
174 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
175 "Append 's' to your time to get seconds", "s");
178 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
180 const struct unit_scale units[] = {
181 { "EiB", pow(1024, 6) },
182 { "PiB", pow(1024, 5) },
183 { "TiB", pow(1024, 4) },
184 { "GiB", pow(1024, 3) },
185 { "MiB", pow(1024, 2) },
194 { "Eib", 0.125 * pow(1024, 6) },
195 { "Pib", 0.125 * pow(1024, 5) },
196 { "Tib", 0.125 * pow(1024, 4) },
197 { "Gib", 0.125 * pow(1024, 3) },
198 { "Mib", 0.125 * pow(1024, 2) },
199 { "Kib", 0.125 * 1024 },
200 { "Eb", 0.125 * 1e18 },
201 { "Pb", 0.125 * 1e15 },
202 { "Tb", 0.125 * 1e12 },
203 { "Gb", 0.125 * 1e9 },
204 { "Mb", 0.125 * 1e6 },
205 { "kb", 0.125 * 1e3 },
209 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
210 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
213 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
215 const struct unit_scale units[] = {
216 { "EiBps", pow(1024, 6) },
217 { "PiBps", pow(1024, 5) },
218 { "TiBps", pow(1024, 4) },
219 { "GiBps", pow(1024, 3) },
220 { "MiBps", pow(1024, 2) },
229 { "Eibps", 0.125 * pow(1024, 6) },
230 { "Pibps", 0.125 * pow(1024, 5) },
231 { "Tibps", 0.125 * pow(1024, 4) },
232 { "Gibps", 0.125 * pow(1024, 3) },
233 { "Mibps", 0.125 * pow(1024, 2) },
234 { "Kibps", 0.125 * 1024 },
235 { "Tbps", 0.125 * 1e12 },
236 { "Gbps", 0.125 * 1e9 },
237 { "Mbps", 0.125 * 1e6 },
238 { "kbps", 0.125 * 1e3 },
242 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
243 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
246 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
248 const struct unit_scale units[] = {
249 { "yottaflops", 1e24 },
251 { "zettaflops", 1e21 },
253 { "exaflops", 1e18 },
255 { "petaflops", 1e15 },
257 { "teraflops", 1e12 },
259 { "gigaflops", 1e9 },
261 { "megaflops", 1e6 },
263 { "kiloflops", 1e3 },
269 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
270 "Append 'f' or 'flops' to your speed to get flop per second", "f");
273 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){
275 std::vector<double> speed_per_pstate;
277 if (strchr(speeds, ',') == nullptr){
278 double speed = surf_parse_get_speed(speeds, entity_kind, id);
279 speed_per_pstate.push_back(speed);
281 xbt_dynar_t pstate_list = xbt_str_split(speeds, ",");
284 xbt_dynar_foreach(pstate_list, i, speed_str) {
285 xbt_str_trim(speed_str, nullptr);
286 double speed = surf_parse_get_speed(speed_str,entity_kind, id);
287 speed_per_pstate.push_back(speed);
288 XBT_DEBUG("Speed value: %f", speed);
290 xbt_dynar_free(&pstate_list);
292 return speed_per_pstate;
296 * All the callback lists that can be overridden anywhere.
297 * (this list should probably be reduced to the bare minimum to allow the models to work)
300 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
302 /* The default current property receiver. Setup in the corresponding opening callbacks. */
303 xbt_dict_t current_property_set = nullptr;
304 xbt_dict_t current_model_property_set = nullptr;
305 int AS_TAG = 0; // Whether we just opened an AS tag (to see what to do with the properties)
307 /* dictionary of random generator data */
308 xbt_dict_t random_data_list = nullptr;
310 YY_BUFFER_STATE surf_input_buffer;
311 FILE *surf_file_to_parse = nullptr;
314 * Stuff relative to storage
316 void STag_surfxml_storage()
319 XBT_DEBUG("STag_surfxml_storage");
320 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
322 void ETag_surfxml_storage()
324 s_sg_platf_storage_cbarg_t storage;
325 memset(&storage,0,sizeof(storage));
327 storage.properties = current_property_set;
328 current_property_set = nullptr;
330 storage.id = A_surfxml_storage_id;
331 storage.type_id = A_surfxml_storage_typeId;
332 storage.content = A_surfxml_storage_content;
333 storage.content_type = A_surfxml_storage_content___type;
334 storage.attach = A_surfxml_storage_attach;
335 sg_platf_new_storage(&storage);
337 void STag_surfxml_storage___type()
340 XBT_DEBUG("STag_surfxml_storage___type");
341 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
342 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
344 void ETag_surfxml_storage___type()
346 s_sg_platf_storage_type_cbarg_t storage_type;
347 memset(&storage_type,0,sizeof(storage_type));
349 storage_type.properties = current_property_set;
350 current_property_set = nullptr;
352 storage_type.model_properties = current_model_property_set;
353 current_model_property_set = nullptr;
355 storage_type.content = A_surfxml_storage___type_content;
356 storage_type.content_type = A_surfxml_storage___type_content___type;
357 storage_type.id = A_surfxml_storage___type_id;
358 storage_type.model = A_surfxml_storage___type_model;
359 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
360 "size of storage type", storage_type.id);
361 sg_platf_new_storage_type(&storage_type);
363 void STag_surfxml_mount()
365 XBT_DEBUG("STag_surfxml_mount");
367 void ETag_surfxml_mount()
369 s_sg_platf_mount_cbarg_t mount;
370 memset(&mount,0,sizeof(mount));
372 mount.name = A_surfxml_mount_name;
373 mount.storageId = A_surfxml_mount_storageId;
374 sg_platf_new_mount(&mount);
378 * Stuff relative to the <include> tag
380 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
381 static std::vector<FILE*> surf_file_to_parse_stack;
382 static std::vector<char*> surf_parsed_filename_stack;
384 void STag_surfxml_include()
386 parse_after_config();
387 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
388 surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
389 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
391 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
393 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
394 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
396 surf_input_buffer_stack.push_back(surf_input_buffer);
397 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
398 surf_parse_push_buffer_state(surf_input_buffer);
403 void ETag_surfxml_include() {
404 /* Nothing to do when done with reading the include tag.
405 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
408 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
410 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
411 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
412 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
413 * error message in that case.
415 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
416 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
417 * on a line. One day maybe, if the maya allow it.
419 int ETag_surfxml_include_state()
422 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
424 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
427 // Yeah, we were in an <include> Restore state and proceed.
428 fclose(surf_file_to_parse);
429 surf_file_to_parse_stack.pop_back();
430 surf_parse_pop_buffer_state();
431 surf_input_buffer_stack.pop_back();
433 // Restore the filename for error messages
434 free(surf_parsed_filename);
435 surf_parsed_filename_stack.pop_back();
440 /* Stag and Etag parse functions */
442 void STag_surfxml_platform() {
443 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
445 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
446 "You're using an ancient XML file.\n"
447 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
448 "instead of MBytes, MFlops and seconds.\n"
450 "Use simgrid_update_xml to update your file automatically. "
451 "This program is installed automatically with SimGrid, or "
452 "available in the tools/ directory of the source archive.\n"
454 "Please check also out the SURF section of the ChangeLog for "
455 "the 3.1 version for more information. \n"
457 "Last, do not forget to also update your values for "
458 "the calls to MSG_task_create (if any).");
459 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
460 "You're using an old XML file.\n"
461 "Use simgrid_update_xml to update your file automatically. "
462 "This program is installed automatically with SimGrid, or "
463 "available in the tools/ directory of the source archive.");
464 xbt_assert((version >= 4.0), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
465 "Changes introduced in SimGrid 3.13:\n"
466 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
467 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
468 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
469 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
471 "Use simgrid_update_xml to update your file automatically. "
472 "This program is installed automatically with SimGrid, or "
473 "available in the tools/ directory of the source archive.",surf_parsed_filename, version);
477 void ETag_surfxml_platform(){
481 void STag_surfxml_host(){
483 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
486 void STag_surfxml_prop()
488 if (AS_TAG) { // We need to retrieve the most recently opened AS
489 XBT_DEBUG("Set AS property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
490 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_AS_id);
492 netzone->setProperty(A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value));
495 if (!current_property_set)
496 current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
497 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
498 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
499 current_property_set);
503 void ETag_surfxml_host() {
504 s_sg_platf_host_cbarg_t host;
505 memset(&host,0,sizeof(host));
507 host.properties = current_property_set;
508 current_property_set = nullptr;
510 host.id = A_surfxml_host_id;
512 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
514 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
515 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
516 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
517 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
518 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
519 host.coord = A_surfxml_host_coordinates;
521 sg_platf_new_host(&host);
524 void STag_surfxml_host___link(){
525 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
526 s_sg_platf_host_link_cbarg_t host_link;
527 memset(&host_link,0,sizeof(host_link));
529 host_link.id = A_surfxml_host___link_id;
530 host_link.link_up = A_surfxml_host___link_up;
531 host_link.link_down = A_surfxml_host___link_down;
532 sg_platf_new_hostlink(&host_link);
535 void STag_surfxml_router(){
536 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
539 void ETag_surfxml_cluster(){
540 s_sg_platf_cluster_cbarg_t cluster;
541 memset(&cluster,0,sizeof(cluster));
542 cluster.properties = current_property_set;
543 current_property_set = nullptr;
545 cluster.id = A_surfxml_cluster_id;
546 cluster.prefix = A_surfxml_cluster_prefix;
547 cluster.suffix = A_surfxml_cluster_suffix;
548 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
549 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
550 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
551 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
552 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
553 if(strcmp(A_surfxml_cluster_bb___bw,""))
554 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
555 if(strcmp(A_surfxml_cluster_bb___lat,""))
556 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
557 if(strcmp(A_surfxml_cluster_limiter___link,""))
558 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
559 if(strcmp(A_surfxml_cluster_loopback___bw,""))
560 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
561 if(strcmp(A_surfxml_cluster_loopback___lat,""))
562 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
564 switch(AX_surfxml_cluster_topology){
565 case A_surfxml_cluster_topology_FLAT:
566 cluster.topology= SURF_CLUSTER_FLAT ;
568 case A_surfxml_cluster_topology_TORUS:
569 cluster.topology= SURF_CLUSTER_TORUS ;
571 case A_surfxml_cluster_topology_FAT___TREE:
572 cluster.topology = SURF_CLUSTER_FAT_TREE;
574 case A_surfxml_cluster_topology_DRAGONFLY:
575 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
578 surf_parse_error("Invalid cluster topology for cluster %s",
582 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
583 cluster.router_id = A_surfxml_cluster_router___id;
585 switch (AX_surfxml_cluster_sharing___policy) {
586 case A_surfxml_cluster_sharing___policy_SHARED:
587 cluster.sharing_policy = SURF_LINK_SHARED;
589 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
590 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
592 case A_surfxml_cluster_sharing___policy_FATPIPE:
593 cluster.sharing_policy = SURF_LINK_FATPIPE;
596 surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
599 switch (AX_surfxml_cluster_bb___sharing___policy) {
600 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
601 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
603 case A_surfxml_cluster_bb___sharing___policy_SHARED:
604 cluster.bb_sharing_policy = SURF_LINK_SHARED;
607 surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
611 sg_platf_new_cluster(&cluster);
614 void STag_surfxml_cluster(){
616 parse_after_config();
617 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
620 void STag_surfxml_cabinet(){
621 parse_after_config();
622 s_sg_platf_cabinet_cbarg_t cabinet;
623 memset(&cabinet,0,sizeof(cabinet));
624 cabinet.id = A_surfxml_cabinet_id;
625 cabinet.prefix = A_surfxml_cabinet_prefix;
626 cabinet.suffix = A_surfxml_cabinet_suffix;
627 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
628 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
629 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
630 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
632 sg_platf_new_cabinet(&cabinet);
635 void STag_surfxml_peer(){
636 parse_after_config();
637 s_sg_platf_peer_cbarg_t peer;
638 memset(&peer,0,sizeof(peer));
639 peer.id = A_surfxml_peer_id;
640 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
641 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
642 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
643 peer.coord = A_surfxml_peer_coordinates;
644 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
645 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
647 if (A_surfxml_peer_lat[0] != '\0')
648 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
651 sg_platf_new_peer(&peer);
654 void STag_surfxml_link(){
656 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
659 void ETag_surfxml_link(){
660 LinkCreationArgs link;
662 link.properties = current_property_set;
663 current_property_set = nullptr;
665 link.id = std::string(A_surfxml_link_id);
666 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
667 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
668 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
669 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
670 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
672 switch (A_surfxml_link_sharing___policy) {
673 case A_surfxml_link_sharing___policy_SHARED:
674 link.policy = SURF_LINK_SHARED;
676 case A_surfxml_link_sharing___policy_FATPIPE:
677 link.policy = SURF_LINK_FATPIPE;
679 case A_surfxml_link_sharing___policy_FULLDUPLEX:
680 link.policy = SURF_LINK_FULLDUPLEX;
683 surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
687 sg_platf_new_link(&link);
690 void STag_surfxml_link___ctn(){
692 simgrid::surf::LinkImpl* link;
693 char *link_name=nullptr;
694 switch (A_surfxml_link___ctn_direction) {
695 case AU_surfxml_link___ctn_direction:
696 case A_surfxml_link___ctn_direction_NONE:
697 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
699 case A_surfxml_link___ctn_direction_UP:
700 link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
701 link = simgrid::surf::LinkImpl::byName(link_name);
703 case A_surfxml_link___ctn_direction_DOWN:
704 link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
705 link = simgrid::surf::LinkImpl::byName(link_name);
708 xbt_free(link_name); // no-op if it's already nullptr
710 surf_parse_assert(link!=nullptr,"No such link: '%s'%s", A_surfxml_link___ctn_id,
711 A_surfxml_link___ctn_direction==A_surfxml_link___ctn_direction_UP?" (upward)":
712 ( A_surfxml_link___ctn_direction==A_surfxml_link___ctn_direction_DOWN?" (downward)":
714 parsed_link_list.push_back(link);
717 void ETag_surfxml_backbone(){
718 LinkCreationArgs link;
720 link.properties = nullptr;
721 link.id = std::string(A_surfxml_backbone_id);
722 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
723 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
724 link.policy = SURF_LINK_SHARED;
726 sg_platf_new_link(&link);
727 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
730 void STag_surfxml_route(){
731 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_src), "Route src='%s' does name a node.",
732 A_surfxml_route_src);
733 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_route_dst), "Route dst='%s' does name a node.",
734 A_surfxml_route_dst);
737 void STag_surfxml_ASroute(){
738 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_src), "ASroute src='%s' does name a node.",
739 A_surfxml_route_src);
740 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_dst), "ASroute dst='%s' does name a node.",
741 A_surfxml_route_dst);
743 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___src), "ASroute gw_src='%s' does name a node.",
744 A_surfxml_ASroute_gw___src);
745 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___dst), "ASroute gw_dst='%s' does name a node.",
746 A_surfxml_ASroute_gw___dst);
749 void STag_surfxml_bypassRoute(){
750 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src), "bypassRoute src='%s' does name a node.",
751 A_surfxml_bypassRoute_src);
752 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst), "bypassRoute dst='%s' does name a node.",
753 A_surfxml_bypassRoute_dst);
756 void STag_surfxml_bypassASroute(){
757 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_src),
758 "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
759 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_dst),
760 "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
761 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___src),
762 "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
763 surf_parse_assert(sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
764 "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
767 void ETag_surfxml_route(){
768 s_sg_platf_route_cbarg_t route;
769 memset(&route,0,sizeof(route));
771 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
772 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
773 route.gw_src = nullptr;
774 route.gw_dst = nullptr;
775 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
776 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
778 for (auto link: parsed_link_list)
779 route.link_list->push_back(link);
780 parsed_link_list.clear();
782 sg_platf_new_route(&route);
783 delete route.link_list;
786 void ETag_surfxml_ASroute(){
787 s_sg_platf_route_cbarg_t ASroute;
788 memset(&ASroute,0,sizeof(ASroute));
790 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_ASroute_src); // tested to not be nullptr in start tag
791 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_ASroute_dst); // tested to not be nullptr in start tag
793 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___src); // tested to not be nullptr in start tag
794 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___dst); // tested to not be nullptr in start tag
796 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
798 for (auto link: parsed_link_list)
799 ASroute.link_list->push_back(link);
800 parsed_link_list.clear();
802 switch (A_surfxml_ASroute_symmetrical) {
803 case AU_surfxml_ASroute_symmetrical:
804 case A_surfxml_ASroute_symmetrical_YES:
805 ASroute.symmetrical = true;
807 case A_surfxml_ASroute_symmetrical_NO:
808 ASroute.symmetrical = false;
812 sg_platf_new_route(&ASroute);
813 delete ASroute.link_list;
816 void ETag_surfxml_bypassRoute(){
817 s_sg_platf_route_cbarg_t route;
818 memset(&route,0,sizeof(route));
820 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
821 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
822 route.gw_src = nullptr;
823 route.gw_dst = nullptr;
824 route.symmetrical = false;
825 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
827 for (auto link: parsed_link_list)
828 route.link_list->push_back(link);
829 parsed_link_list.clear();
831 sg_platf_new_bypassRoute(&route);
832 delete route.link_list;
835 void ETag_surfxml_bypassASroute(){
836 s_sg_platf_route_cbarg_t ASroute;
837 memset(&ASroute,0,sizeof(ASroute));
839 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_src);
840 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_dst);
841 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
842 for (auto link: parsed_link_list)
843 ASroute.link_list->push_back(link);
844 parsed_link_list.clear();
846 ASroute.symmetrical = false;
848 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___src);
849 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
851 sg_platf_new_bypassRoute(&ASroute);
852 delete ASroute.link_list;
855 void ETag_surfxml_trace(){
856 s_sg_platf_trace_cbarg_t trace;
857 memset(&trace,0,sizeof(trace));
859 trace.id = A_surfxml_trace_id;
860 trace.file = A_surfxml_trace_file;
861 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
862 trace.pc_data = surfxml_pcdata;
864 sg_platf_new_trace(&trace);
867 void STag_surfxml_trace___connect(){
868 parse_after_config();
869 s_sg_platf_trace_connect_cbarg_t trace_connect;
870 memset(&trace_connect,0,sizeof(trace_connect));
872 trace_connect.element = A_surfxml_trace___connect_element;
873 trace_connect.trace = A_surfxml_trace___connect_trace;
875 switch (A_surfxml_trace___connect_kind) {
876 case AU_surfxml_trace___connect_kind:
877 case A_surfxml_trace___connect_kind_SPEED:
878 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
880 case A_surfxml_trace___connect_kind_BANDWIDTH:
881 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
883 case A_surfxml_trace___connect_kind_HOST___AVAIL:
884 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
886 case A_surfxml_trace___connect_kind_LATENCY:
887 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
889 case A_surfxml_trace___connect_kind_LINK___AVAIL:
890 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
893 sg_platf_trace_connect(&trace_connect);
896 void STag_surfxml_AS(){
897 parse_after_config();
899 s_sg_platf_AS_cbarg_t AS = { A_surfxml_AS_id, (int)A_surfxml_AS_routing};
901 sg_platf_new_AS_begin(&AS);
903 void ETag_surfxml_AS(){
904 sg_platf_new_AS_seal();
907 void STag_surfxml_config(){
909 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
910 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
911 if (_sg_cfg_init_status == 2) {
912 surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
915 void ETag_surfxml_config(){
916 xbt_dict_cursor_t cursor = nullptr;
919 xbt_dict_foreach(current_property_set, cursor, key, elem) {
920 if (xbt_cfg_is_default_value(key)) {
921 char* cfg = bprintf("%s:%s", key, elem);
922 xbt_cfg_set_parse(cfg);
925 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
927 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
929 xbt_dict_free(¤t_property_set);
930 current_property_set = nullptr;
936 void STag_surfxml_process(){
939 argv = xbt_new(char *, 1);
940 argv[0] = xbt_strdup(A_surfxml_process_function);
941 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
944 void ETag_surfxml_process(){
945 s_sg_platf_process_cbarg_t process;
946 memset(&process,0,sizeof(process));
949 process.argv = (const char **)argv;
950 process.properties = current_property_set;
951 process.host = A_surfxml_process_host;
952 process.function = A_surfxml_process_function;
953 process.start_time = surf_parse_get_double(A_surfxml_process_start___time);
954 process.kill_time = surf_parse_get_double(A_surfxml_process_kill___time);
956 switch (A_surfxml_process_on___failure) {
957 case AU_surfxml_process_on___failure:
958 case A_surfxml_process_on___failure_DIE:
959 process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
961 case A_surfxml_process_on___failure_RESTART:
962 process.on_failure = SURF_PROCESS_ON_FAILURE_RESTART;
966 sg_platf_new_process(&process);
968 for (int i = 0; i != argc; ++i)
973 current_property_set = nullptr;
976 void STag_surfxml_argument(){
978 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
979 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
982 void STag_surfxml_model___prop(){
983 if (!current_model_property_set)
984 current_model_property_set = xbt_dict_new_homogeneous(xbt_free_f);
986 xbt_dict_set(current_model_property_set, A_surfxml_model___prop_id, xbt_strdup(A_surfxml_model___prop_value), nullptr);
989 void ETag_surfxml_prop(){/* Nothing to do */}
990 void STag_surfxml_random(){/* Nothing to do */}
991 void ETag_surfxml_random(){/* Nothing to do */}
992 void ETag_surfxml_trace___connect(){/* Nothing to do */}
993 void STag_surfxml_trace(){parse_after_config();}
994 void ETag_surfxml_router(){/*Nothing to do*/}
995 void ETag_surfxml_host___link(){/* Nothing to do */}
996 void ETag_surfxml_cabinet(){/* Nothing to do */}
997 void ETag_surfxml_peer(){/* Nothing to do */}
998 void STag_surfxml_backbone(){/* Nothing to do */}
999 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1000 void ETag_surfxml_argument(){/* Nothing to do */}
1001 void ETag_surfxml_model___prop(){/* Nothing to do */}
1003 /* Open and Close parse file */
1004 void surf_parse_open(const char *file)
1006 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1008 surf_parsed_filename = xbt_strdup(file);
1009 char *dir = xbt_dirname(file);
1010 xbt_dynar_push(surf_path, &dir);
1012 surf_file_to_parse = surf_fopen(file, "r");
1013 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
1014 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1015 surf_parse__switch_to_buffer(surf_input_buffer);
1016 surf_parse_lineno = 1;
1019 void surf_parse_close()
1021 if (surf_parsed_filename) {
1022 char *dir = nullptr;
1023 xbt_dynar_pop(surf_path, &dir);
1027 free(surf_parsed_filename);
1028 surf_parsed_filename = nullptr;
1030 if (surf_file_to_parse) {
1031 surf_parse__delete_buffer(surf_input_buffer);
1032 fclose(surf_file_to_parse);
1033 surf_file_to_parse = nullptr; //Must be reset for Bypass
1037 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1038 static int _surf_parse() {
1039 return surf_parse_lex();
1042 int_f_void_t surf_parse = _surf_parse;