1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */
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. */
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"
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>
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
22 int ETag_surfxml_include_state();
24 #include "simgrid_dtd.c"
26 char* surf_parsed_filename = nullptr; // to locate parse error messages
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
33 void surf_parse_assert(bool cond, const char *fmt, ...) {
37 int lineno = surf_parse_lineno;
38 char *msg = bvprintf(fmt,va);
41 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
43 xbt_die("Exiting now");
46 void surf_parse_error(const char *fmt, ...) {
49 int lineno = surf_parse_lineno;
50 char *msg = bvprintf(fmt,va);
53 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
55 xbt_die("Exiting now");
57 void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
59 if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
62 std::string msg = std::string(pre);
65 msg += " Existing netpoints: \n";
67 std::vector<simgrid::kernel::routing::NetPoint*> list;
68 simgrid::s4u::Engine::instance()->netpointList(&list);
70 for (auto np : list) {
77 msg += "'" + np->name() + "'";
78 if (msg.length() > 4096) {
79 msg.pop_back(); // remove trailing quote
80 msg += "...(list truncated)......";
84 surf_parse_error("%s", msg.c_str());
87 void surf_parse_warn(const char *fmt, ...) {
90 char *msg = bvprintf(fmt,va);
92 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
96 double surf_parse_get_double(const char *string) {
98 int ret = sscanf(string, "%lg", &res);
100 surf_parse_error("%s is not a double", string);
104 int surf_parse_get_int(const char *string) {
106 int ret = sscanf(string, "%d", &res);
108 surf_parse_error("%s is not an integer", string);
112 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
113 static std::vector<int>* explodesRadical(const char* radicals)
115 std::vector<int>* exploded = new std::vector<int>();
118 std::vector<std::string> radical_elements;
119 boost::split(radical_elements, radicals, boost::is_any_of(","));
120 for (auto group : radical_elements) {
121 std::vector<std::string> radical_ends;
122 boost::split(radical_ends, group, boost::is_any_of("-"));
123 int start = surf_parse_get_int((radical_ends.front()).c_str());
126 switch (radical_ends.size()) {
131 end = surf_parse_get_int((radical_ends.back()).c_str());
134 surf_parse_error("Malformed radical: %s", group.c_str());
137 for (int i = start; i <= end; i++)
138 exploded->push_back(i);
149 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
150 static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
151 const char *entity_kind, const char *name, const char *error_msg, const char *default_unit)
156 double res = strtod(string, &ptr);
158 surf_parse_error("value out of range: %s", string);
160 surf_parse_error("cannot parse number: %s", string);
161 if (ptr[0] == '\0') {
163 return res; // Ok, 0 can be unit-less
165 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
166 ptr = (char*)default_unit;
168 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
170 if (units[i].unit != nullptr)
171 res *= units[i].scale;
173 surf_parse_error("unknown unit: %s", ptr);
177 double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
179 const struct unit_scale units[] = {
180 { "w", 7 * 24 * 60 * 60 },
181 { "d", 24 * 60 * 60 },
191 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
192 "Append 's' to your time to get seconds", "s");
195 double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
197 const struct unit_scale units[] = {
198 { "EiB", pow(1024, 6) },
199 { "PiB", pow(1024, 5) },
200 { "TiB", pow(1024, 4) },
201 { "GiB", pow(1024, 3) },
202 { "MiB", pow(1024, 2) },
211 { "Eib", 0.125 * pow(1024, 6) },
212 { "Pib", 0.125 * pow(1024, 5) },
213 { "Tib", 0.125 * pow(1024, 4) },
214 { "Gib", 0.125 * pow(1024, 3) },
215 { "Mib", 0.125 * pow(1024, 2) },
216 { "Kib", 0.125 * 1024 },
217 { "Eb", 0.125 * 1e18 },
218 { "Pb", 0.125 * 1e15 },
219 { "Tb", 0.125 * 1e12 },
220 { "Gb", 0.125 * 1e9 },
221 { "Mb", 0.125 * 1e6 },
222 { "kb", 0.125 * 1e3 },
226 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
227 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
230 double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
232 const struct unit_scale units[] = {
233 { "EiBps", pow(1024, 6) },
234 { "PiBps", pow(1024, 5) },
235 { "TiBps", pow(1024, 4) },
236 { "GiBps", pow(1024, 3) },
237 { "MiBps", pow(1024, 2) },
246 { "Eibps", 0.125 * pow(1024, 6) },
247 { "Pibps", 0.125 * pow(1024, 5) },
248 { "Tibps", 0.125 * pow(1024, 4) },
249 { "Gibps", 0.125 * pow(1024, 3) },
250 { "Mibps", 0.125 * pow(1024, 2) },
251 { "Kibps", 0.125 * 1024 },
252 { "Tbps", 0.125 * 1e12 },
253 { "Gbps", 0.125 * 1e9 },
254 { "Mbps", 0.125 * 1e6 },
255 { "kbps", 0.125 * 1e3 },
259 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
260 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
263 double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
265 const struct unit_scale units[] = {
266 { "yottaflops", 1e24 },
268 { "zettaflops", 1e21 },
270 { "exaflops", 1e18 },
272 { "petaflops", 1e15 },
274 { "teraflops", 1e12 },
276 { "gigaflops", 1e9 },
278 { "megaflops", 1e6 },
280 { "kiloflops", 1e3 },
286 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
287 "Append 'f' or 'flops' to your speed to get flop per second", "f");
290 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){
292 std::vector<double> speed_per_pstate;
294 if (strchr(speeds, ',') == nullptr){
295 double speed = surf_parse_get_speed(speeds, entity_kind, id);
296 speed_per_pstate.push_back(speed);
298 std::vector<std::string> pstate_list;
299 boost::split(pstate_list, speeds, boost::is_any_of(","));
300 for (auto speed_str : pstate_list) {
301 boost::trim(speed_str);
302 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
303 speed_per_pstate.push_back(speed);
304 XBT_DEBUG("Speed value: %f", speed);
307 return speed_per_pstate;
311 * All the callback lists that can be overridden anywhere.
312 * (this list should probably be reduced to the bare minimum to allow the models to work)
315 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
317 /* The default current property receiver. Setup in the corresponding opening callbacks. */
318 xbt_dict_t current_property_set = nullptr;
319 std::map<std::string, std::string>* current_model_property_set = nullptr;
320 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
322 /* dictionary of random generator data */
323 xbt_dict_t random_data_list = nullptr;
325 YY_BUFFER_STATE surf_input_buffer;
326 FILE *surf_file_to_parse = nullptr;
329 * Stuff relative to storage
331 void STag_surfxml_storage()
334 XBT_DEBUG("STag_surfxml_storage");
335 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
337 void ETag_surfxml_storage()
339 s_sg_platf_storage_cbarg_t storage;
340 memset(&storage,0,sizeof(storage));
342 storage.properties = current_property_set;
343 current_property_set = nullptr;
345 storage.id = A_surfxml_storage_id;
346 storage.type_id = A_surfxml_storage_typeId;
347 storage.content = A_surfxml_storage_content;
349 storage.attach = A_surfxml_storage_attach;
350 sg_platf_new_storage(&storage);
352 void STag_surfxml_storage___type()
355 XBT_DEBUG("STag_surfxml_storage___type");
356 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
357 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
359 void ETag_surfxml_storage___type()
361 s_sg_platf_storage_type_cbarg_t storage_type;
362 memset(&storage_type,0,sizeof(storage_type));
364 storage_type.properties = current_property_set;
365 current_property_set = nullptr;
367 storage_type.model_properties = current_model_property_set;
368 current_model_property_set = nullptr;
370 storage_type.content = A_surfxml_storage___type_content;
371 storage_type.id = A_surfxml_storage___type_id;
372 storage_type.model = A_surfxml_storage___type_model;
373 storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size,
374 "size of storage type", storage_type.id);
375 sg_platf_new_storage_type(&storage_type);
377 void STag_surfxml_mount()
379 XBT_DEBUG("STag_surfxml_mount");
381 void ETag_surfxml_mount()
383 s_sg_platf_mount_cbarg_t mount;
384 memset(&mount,0,sizeof(mount));
386 mount.name = A_surfxml_mount_name;
387 mount.storageId = A_surfxml_mount_storageId;
388 sg_platf_new_mount(&mount);
392 * Stuff relative to the <include> tag
394 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
395 static std::vector<FILE*> surf_file_to_parse_stack;
396 static std::vector<char*> surf_parsed_filename_stack;
398 void STag_surfxml_include()
400 parse_after_config();
401 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
402 surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
403 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
405 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
407 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
408 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
410 surf_input_buffer_stack.push_back(surf_input_buffer);
411 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
412 surf_parse_push_buffer_state(surf_input_buffer);
417 void ETag_surfxml_include() {
418 /* Nothing to do when done with reading the include tag.
419 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
422 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
424 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
425 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
426 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
427 * error message in that case.
429 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
430 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
431 * on a line. One day maybe, if the maya allow it.
433 int ETag_surfxml_include_state()
436 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
438 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
441 // Yeah, we were in an <include> Restore state and proceed.
442 fclose(surf_file_to_parse);
443 surf_file_to_parse_stack.pop_back();
444 surf_parse_pop_buffer_state();
445 surf_input_buffer_stack.pop_back();
447 // Restore the filename for error messages
448 free(surf_parsed_filename);
449 surf_parsed_filename_stack.pop_back();
454 /* Stag and Etag parse functions */
456 void STag_surfxml_platform() {
457 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
459 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
460 "You're using an ancient XML file.\n"
461 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
462 "instead of MBytes, MFlops and seconds.\n"
464 "Use simgrid_update_xml to update your file automatically. "
465 "This program is installed automatically with SimGrid, or "
466 "available in the tools/ directory of the source archive.\n"
468 "Please check also out the SURF section of the ChangeLog for "
469 "the 3.1 version for more information. \n"
471 "Last, do not forget to also update your values for "
472 "the calls to MSG_task_create (if any).");
473 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
474 "You're using an old XML file.\n"
475 "Use simgrid_update_xml to update your file automatically. "
476 "This program is installed automatically with SimGrid, or "
477 "available in the tools/ directory of the source archive.");
478 xbt_assert((version >= 4.0),
479 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
480 "Changes introduced in SimGrid 3.13:\n"
481 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
482 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
483 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
484 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
486 "Use simgrid_update_xml to update your file automatically. "
487 "This program is installed automatically with SimGrid, or "
488 "available in the tools/ directory of the source archive.",
489 surf_parsed_filename, version);
491 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
492 "That's fine, the new version is backward compatible. \n\n"
493 "Use simgrid_update_xml to update your file automatically. "
494 "This program is installed automatically with SimGrid, or "
495 "available in the tools/ directory of the source archive.",
496 version, surf_parsed_filename);
498 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
499 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
500 "Please update your code, or use another, more adapted, file.",
501 surf_parsed_filename, version);
505 void ETag_surfxml_platform(){
509 void STag_surfxml_host(){
511 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
514 void STag_surfxml_prop()
516 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
517 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
518 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_zone_id);
520 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
523 if (not current_property_set)
524 current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
525 xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
526 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
527 current_property_set);
531 void ETag_surfxml_host() {
532 s_sg_platf_host_cbarg_t host;
533 memset(&host,0,sizeof(host));
535 host.properties = current_property_set;
536 current_property_set = nullptr;
538 host.id = A_surfxml_host_id;
540 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
542 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
543 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
544 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
545 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
546 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
547 host.coord = A_surfxml_host_coordinates;
549 sg_platf_new_host(&host);
552 void STag_surfxml_host___link(){
553 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
554 s_sg_platf_host_link_cbarg_t host_link;
555 memset(&host_link,0,sizeof(host_link));
557 host_link.id = A_surfxml_host___link_id;
558 host_link.link_up = A_surfxml_host___link_up;
559 host_link.link_down = A_surfxml_host___link_down;
560 sg_platf_new_hostlink(&host_link);
563 void STag_surfxml_router(){
564 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
567 void ETag_surfxml_cluster(){
568 s_sg_platf_cluster_cbarg_t cluster;
569 memset(&cluster,0,sizeof(cluster));
570 cluster.properties = current_property_set;
571 current_property_set = nullptr;
573 cluster.id = A_surfxml_cluster_id;
574 cluster.prefix = A_surfxml_cluster_prefix;
575 cluster.suffix = A_surfxml_cluster_suffix;
576 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
577 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
578 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
579 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
580 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
581 if(strcmp(A_surfxml_cluster_bb___bw,""))
582 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
583 if(strcmp(A_surfxml_cluster_bb___lat,""))
584 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
585 if(strcmp(A_surfxml_cluster_limiter___link,""))
586 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
587 if(strcmp(A_surfxml_cluster_loopback___bw,""))
588 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
589 if(strcmp(A_surfxml_cluster_loopback___lat,""))
590 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
592 switch(AX_surfxml_cluster_topology){
593 case A_surfxml_cluster_topology_FLAT:
594 cluster.topology= SURF_CLUSTER_FLAT ;
596 case A_surfxml_cluster_topology_TORUS:
597 cluster.topology= SURF_CLUSTER_TORUS ;
599 case A_surfxml_cluster_topology_FAT___TREE:
600 cluster.topology = SURF_CLUSTER_FAT_TREE;
602 case A_surfxml_cluster_topology_DRAGONFLY:
603 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
606 surf_parse_error("Invalid cluster topology for cluster %s",
610 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
611 cluster.router_id = A_surfxml_cluster_router___id;
613 switch (AX_surfxml_cluster_sharing___policy) {
614 case A_surfxml_cluster_sharing___policy_SHARED:
615 cluster.sharing_policy = SURF_LINK_SHARED;
617 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
618 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
620 case A_surfxml_cluster_sharing___policy_FATPIPE:
621 cluster.sharing_policy = SURF_LINK_FATPIPE;
624 surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
627 switch (AX_surfxml_cluster_bb___sharing___policy) {
628 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
629 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
631 case A_surfxml_cluster_bb___sharing___policy_SHARED:
632 cluster.bb_sharing_policy = SURF_LINK_SHARED;
635 surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
639 sg_platf_new_cluster(&cluster);
642 void STag_surfxml_cluster(){
644 parse_after_config();
645 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
648 void STag_surfxml_cabinet(){
649 parse_after_config();
650 s_sg_platf_cabinet_cbarg_t cabinet;
651 memset(&cabinet,0,sizeof(cabinet));
652 cabinet.id = A_surfxml_cabinet_id;
653 cabinet.prefix = A_surfxml_cabinet_prefix;
654 cabinet.suffix = A_surfxml_cabinet_suffix;
655 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id);
656 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id);
657 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id);
658 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
660 sg_platf_new_cabinet(&cabinet);
663 void STag_surfxml_peer(){
664 parse_after_config();
665 s_sg_platf_peer_cbarg_t peer;
666 memset(&peer,0,sizeof(peer));
667 peer.id = A_surfxml_peer_id;
668 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
669 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
670 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
671 peer.coord = A_surfxml_peer_coordinates;
672 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
673 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
675 if (A_surfxml_peer_lat[0] != '\0')
676 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
679 sg_platf_new_peer(&peer);
682 void STag_surfxml_link(){
684 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
687 void ETag_surfxml_link(){
688 LinkCreationArgs link;
690 link.properties = current_property_set;
691 current_property_set = nullptr;
693 link.id = std::string(A_surfxml_link_id);
694 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
695 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
696 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
697 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
698 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
700 switch (A_surfxml_link_sharing___policy) {
701 case A_surfxml_link_sharing___policy_SHARED:
702 link.policy = SURF_LINK_SHARED;
704 case A_surfxml_link_sharing___policy_FATPIPE:
705 link.policy = SURF_LINK_FATPIPE;
707 case A_surfxml_link_sharing___policy_FULLDUPLEX:
708 link.policy = SURF_LINK_FULLDUPLEX;
711 surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
715 sg_platf_new_link(&link);
718 void STag_surfxml_link___ctn(){
720 simgrid::surf::LinkImpl* link = nullptr;
721 char *link_name=nullptr;
722 switch (A_surfxml_link___ctn_direction) {
723 case AU_surfxml_link___ctn_direction:
724 case A_surfxml_link___ctn_direction_NONE:
725 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
727 case A_surfxml_link___ctn_direction_UP:
728 link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
729 link = simgrid::surf::LinkImpl::byName(link_name);
731 case A_surfxml_link___ctn_direction_DOWN:
732 link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
733 link = simgrid::surf::LinkImpl::byName(link_name);
736 surf_parse_error("Invalid direction for link %s", link_name);
739 xbt_free(link_name); // no-op if it's already nullptr
741 const char* dirname = "";
742 switch (A_surfxml_link___ctn_direction) {
743 case A_surfxml_link___ctn_direction_UP:
744 dirname = " (upward)";
746 case A_surfxml_link___ctn_direction_DOWN:
747 dirname = " (downward)";
752 surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
753 parsed_link_list.push_back(link);
756 void ETag_surfxml_backbone(){
757 LinkCreationArgs link;
759 link.properties = nullptr;
760 link.id = std::string(A_surfxml_backbone_id);
761 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
762 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
763 link.policy = SURF_LINK_SHARED;
765 sg_platf_new_link(&link);
766 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
769 void STag_surfxml_route(){
770 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
771 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
774 void STag_surfxml_ASroute(){
775 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
776 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
778 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
779 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
781 void STag_surfxml_zoneRoute(){
782 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
783 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
784 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
785 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
788 void STag_surfxml_bypassRoute(){
789 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
790 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
793 void STag_surfxml_bypassASroute(){
794 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
795 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
796 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
797 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
799 void STag_surfxml_bypassZoneRoute(){
800 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
801 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
802 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
803 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
806 void ETag_surfxml_route(){
807 s_sg_platf_route_cbarg_t route;
808 memset(&route,0,sizeof(route));
810 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
811 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
812 route.gw_src = nullptr;
813 route.gw_dst = nullptr;
814 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
815 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
817 for (auto link: parsed_link_list)
818 route.link_list->push_back(link);
819 parsed_link_list.clear();
821 sg_platf_new_route(&route);
822 delete route.link_list;
825 void ETag_surfxml_ASroute()
827 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
828 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
829 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
830 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
831 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
832 ETag_surfxml_zoneRoute();
834 void ETag_surfxml_zoneRoute()
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_zoneRoute_src); // tested to not be nullptr in start tag
840 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
842 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
843 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
845 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
847 for (auto link: parsed_link_list)
848 ASroute.link_list->push_back(link);
849 parsed_link_list.clear();
851 switch (A_surfxml_zoneRoute_symmetrical) {
852 case AU_surfxml_zoneRoute_symmetrical:
853 case A_surfxml_zoneRoute_symmetrical_YES:
854 ASroute.symmetrical = true;
856 case A_surfxml_zoneRoute_symmetrical_NO:
857 ASroute.symmetrical = false;
861 sg_platf_new_route(&ASroute);
862 delete ASroute.link_list;
865 void ETag_surfxml_bypassRoute(){
866 s_sg_platf_route_cbarg_t route;
867 memset(&route,0,sizeof(route));
869 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
870 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
871 route.gw_src = nullptr;
872 route.gw_dst = nullptr;
873 route.symmetrical = false;
874 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
876 for (auto link: parsed_link_list)
877 route.link_list->push_back(link);
878 parsed_link_list.clear();
880 sg_platf_new_bypassRoute(&route);
881 delete route.link_list;
884 void ETag_surfxml_bypassASroute()
886 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
887 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
888 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
889 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
890 ETag_surfxml_bypassZoneRoute();
892 void ETag_surfxml_bypassZoneRoute()
894 s_sg_platf_route_cbarg_t ASroute;
895 memset(&ASroute,0,sizeof(ASroute));
897 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
898 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
899 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
900 for (auto link: parsed_link_list)
901 ASroute.link_list->push_back(link);
902 parsed_link_list.clear();
904 ASroute.symmetrical = false;
906 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
907 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
909 sg_platf_new_bypassRoute(&ASroute);
910 delete ASroute.link_list;
913 void ETag_surfxml_trace(){
914 s_sg_platf_trace_cbarg_t trace;
915 memset(&trace,0,sizeof(trace));
917 trace.id = A_surfxml_trace_id;
918 trace.file = A_surfxml_trace_file;
919 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
920 trace.pc_data = surfxml_pcdata;
922 sg_platf_new_trace(&trace);
925 void STag_surfxml_trace___connect()
927 parse_after_config();
928 s_sg_platf_trace_connect_cbarg_t trace_connect;
929 memset(&trace_connect,0,sizeof(trace_connect));
931 trace_connect.element = A_surfxml_trace___connect_element;
932 trace_connect.trace = A_surfxml_trace___connect_trace;
934 switch (A_surfxml_trace___connect_kind) {
935 case AU_surfxml_trace___connect_kind:
936 case A_surfxml_trace___connect_kind_SPEED:
937 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
939 case A_surfxml_trace___connect_kind_BANDWIDTH:
940 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
942 case A_surfxml_trace___connect_kind_HOST___AVAIL:
943 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
945 case A_surfxml_trace___connect_kind_LATENCY:
946 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
948 case A_surfxml_trace___connect_kind_LINK___AVAIL:
949 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
952 surf_parse_error("Invalid trace kind");
955 sg_platf_trace_connect(&trace_connect);
958 void STag_surfxml_AS()
960 AX_surfxml_zone_id = AX_surfxml_AS_id;
961 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
965 void ETag_surfxml_AS()
970 void STag_surfxml_zone()
972 parse_after_config();
974 s_sg_platf_AS_cbarg_t AS = {A_surfxml_zone_id, (int)A_surfxml_zone_routing};
976 sg_platf_new_AS_begin(&AS);
979 void ETag_surfxml_zone()
981 sg_platf_new_AS_seal();
984 void STag_surfxml_config()
987 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
988 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
989 if (_sg_cfg_init_status == 2) {
990 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
995 void ETag_surfxml_config()
997 xbt_dict_cursor_t cursor = nullptr;
1000 xbt_dict_foreach(current_property_set, cursor, key, elem) {
1001 if (xbt_cfg_is_default_value(key)) {
1002 std::string cfg = std::string(key) + ":" + elem;
1003 xbt_cfg_set_parse(cfg.c_str());
1005 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
1007 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1009 xbt_dict_free(¤t_property_set);
1010 current_property_set = nullptr;
1016 void STag_surfxml_process()
1018 AX_surfxml_actor_function = AX_surfxml_process_function;
1019 STag_surfxml_actor();
1021 void STag_surfxml_actor()
1025 argv = xbt_new(char *, 1);
1026 argv[0] = xbt_strdup(A_surfxml_actor_function);
1027 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
1030 void ETag_surfxml_process()
1032 AX_surfxml_actor_host = AX_surfxml_process_host;
1033 AX_surfxml_actor_function = AX_surfxml_process_function;
1034 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
1035 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1036 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1037 ETag_surfxml_actor();
1039 void ETag_surfxml_actor()
1041 s_sg_platf_process_cbarg_t actor;
1042 memset(&actor,0,sizeof(actor));
1045 actor.argv = (const char **)argv;
1046 actor.properties = current_property_set;
1047 actor.host = A_surfxml_actor_host;
1048 actor.function = A_surfxml_actor_function;
1049 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1050 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1052 switch (A_surfxml_actor_on___failure) {
1053 case AU_surfxml_actor_on___failure:
1054 case A_surfxml_actor_on___failure_DIE:
1055 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1057 case A_surfxml_actor_on___failure_RESTART:
1058 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1061 surf_parse_error("Invalid on failure behavior");
1065 sg_platf_new_process(&actor);
1067 for (int i = 0; i != argc; ++i)
1072 current_property_set = nullptr;
1075 void STag_surfxml_argument(){
1077 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1078 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1081 void STag_surfxml_model___prop(){
1082 if (not current_model_property_set)
1083 current_model_property_set = new std::map<std::string, std::string>();
1085 current_model_property_set->insert(
1086 {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
1089 void ETag_surfxml_prop(){/* Nothing to do */}
1090 void STag_surfxml_random(){/* Nothing to do */}
1091 void ETag_surfxml_random(){/* Nothing to do */}
1092 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1093 void STag_surfxml_trace(){parse_after_config();}
1094 void ETag_surfxml_router(){/*Nothing to do*/}
1095 void ETag_surfxml_host___link(){/* Nothing to do */}
1096 void ETag_surfxml_cabinet(){/* Nothing to do */}
1097 void ETag_surfxml_peer(){/* Nothing to do */}
1098 void STag_surfxml_backbone(){/* Nothing to do */}
1099 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1100 void ETag_surfxml_argument(){/* Nothing to do */}
1101 void ETag_surfxml_model___prop(){/* Nothing to do */}
1103 /* Open and Close parse file */
1104 void surf_parse_open(const char *file)
1106 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1108 surf_parsed_filename = xbt_strdup(file);
1109 char* dir = xbt_dirname(file);
1110 surf_path.push_back(std::string(dir));
1113 surf_file_to_parse = surf_fopen(file, "r");
1114 xbt_assert(surf_file_to_parse != nullptr, "Unable to open '%s'\n", file);
1115 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1116 surf_parse__switch_to_buffer(surf_input_buffer);
1117 surf_parse_lineno = 1;
1120 void surf_parse_close()
1122 if (surf_parsed_filename) {
1123 surf_path.pop_back();
1126 free(surf_parsed_filename);
1127 surf_parsed_filename = nullptr;
1129 if (surf_file_to_parse) {
1130 surf_parse__delete_buffer(surf_input_buffer);
1131 fclose(surf_file_to_parse);
1132 surf_file_to_parse = nullptr; //Must be reset for Bypass
1136 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
1137 static int _surf_parse() {
1138 return surf_parse_lex();
1141 int_f_void_t surf_parse = &_surf_parse;