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"
10 #include "xbt/file.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, std::string msg)
36 int lineno = surf_parse_lineno;
38 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
40 xbt_die("Exiting now");
44 void surf_parse_error(std::string msg)
46 int lineno = surf_parse_lineno;
48 XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
50 xbt_die("Exiting now");
53 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
55 if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
58 std::string msg = pre + hostname + post + " Existing netpoints: \n";
60 std::vector<simgrid::kernel::routing::NetPoint*> list;
61 simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
62 std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
63 return a->getName() < b->getName();
66 for (auto const& np : list) {
73 msg += "'" + np->getName() + "'";
74 if (msg.length() > 4096) {
75 msg.pop_back(); // remove trailing quote
76 msg += "...(list truncated)......";
80 surf_parse_error(msg);
83 void surf_parse_warn(std::string msg)
85 XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
88 double surf_parse_get_double(std::string s)
92 } catch (std::invalid_argument& ia) {
93 surf_parse_error(s + " is not a double");
98 int surf_parse_get_int(std::string s)
102 } catch (std::invalid_argument& ia) {
103 surf_parse_error(s + " is not a double");
108 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
109 static std::vector<int>* explodesRadical(std::string radicals)
111 std::vector<int>* exploded = new std::vector<int>();
114 std::vector<std::string> radical_elements;
115 boost::split(radical_elements, radicals, boost::is_any_of(","));
116 for (auto const& group : radical_elements) {
117 std::vector<std::string> radical_ends;
118 boost::split(radical_ends, group, boost::is_any_of("-"));
119 int start = surf_parse_get_int(radical_ends.front());
122 switch (radical_ends.size()) {
127 end = surf_parse_get_int(radical_ends.back());
130 surf_parse_error(std::string("Malformed radical: ") + group);
133 for (int i = start; i <= end; i++)
134 exploded->push_back(i);
145 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
146 static double surf_parse_get_value_with_unit(const char* string, const unit_scale* units, const char* entity_kind,
147 std::string name, const char* error_msg, const char* default_unit)
152 double res = strtod(string, &ptr);
154 surf_parse_error(std::string("value out of range: ") + string);
156 surf_parse_error(std::string("cannot parse number:") + string);
157 if (ptr[0] == '\0') {
159 return res; // Ok, 0 can be unit-less
161 XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
162 ptr = (char*)default_unit;
164 for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
166 if (units[i].unit != nullptr)
167 res *= units[i].scale;
169 surf_parse_error(std::string("unknown unit: ") + ptr);
173 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
175 const unit_scale units[] = {{"w", 7 * 24 * 60 * 60},
185 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
186 "Append 's' to your time to get seconds", "s");
189 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
191 const unit_scale units[] = {{"EiB", pow(1024, 6)},
192 {"PiB", pow(1024, 5)},
193 {"TiB", pow(1024, 4)},
194 {"GiB", pow(1024, 3)},
195 {"MiB", pow(1024, 2)},
204 {"Eib", 0.125 * pow(1024, 6)},
205 {"Pib", 0.125 * pow(1024, 5)},
206 {"Tib", 0.125 * pow(1024, 4)},
207 {"Gib", 0.125 * pow(1024, 3)},
208 {"Mib", 0.125 * pow(1024, 2)},
209 {"Kib", 0.125 * 1024},
210 {"Eb", 0.125 * 1e18},
211 {"Pb", 0.125 * 1e15},
212 {"Tb", 0.125 * 1e12},
218 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
219 "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
222 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
224 const unit_scale units[] = {{"EiBps", pow(1024, 6)},
225 {"PiBps", pow(1024, 5)},
226 {"TiBps", pow(1024, 4)},
227 {"GiBps", pow(1024, 3)},
228 {"MiBps", pow(1024, 2)},
237 {"Eibps", 0.125 * pow(1024, 6)},
238 {"Pibps", 0.125 * pow(1024, 5)},
239 {"Tibps", 0.125 * pow(1024, 4)},
240 {"Gibps", 0.125 * pow(1024, 3)},
241 {"Mibps", 0.125 * pow(1024, 2)},
242 {"Kibps", 0.125 * 1024},
243 {"Tbps", 0.125 * 1e12},
244 {"Gbps", 0.125 * 1e9},
245 {"Mbps", 0.125 * 1e6},
246 {"kbps", 0.125 * 1e3},
249 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
250 "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
253 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
255 const unit_scale units[] = {{"yottaflops", 1e24}, {"Yf", 1e24}, {"zettaflops", 1e21}, {"Zf", 1e21},
256 {"exaflops", 1e18}, {"Ef", 1e18}, {"petaflops", 1e15}, {"Pf", 1e15},
257 {"teraflops", 1e12}, {"Tf", 1e12}, {"gigaflops", 1e9}, {"Gf", 1e9},
258 {"megaflops", 1e6}, {"Mf", 1e6}, {"kiloflops", 1e3}, {"kf", 1e3},
259 {"flops", 1.0}, {"f", 1.0}, {nullptr, 0}};
260 return surf_parse_get_value_with_unit(string, units, entity_kind, name,
261 "Append 'f' or 'flops' to your speed to get flop per second", "f");
264 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
267 std::vector<double> speed_per_pstate;
269 if (strchr(speeds, ',') == nullptr){
270 double speed = surf_parse_get_speed(speeds, entity_kind, id);
271 speed_per_pstate.push_back(speed);
273 std::vector<std::string> pstate_list;
274 boost::split(pstate_list, speeds, boost::is_any_of(","));
275 for (auto speed_str : pstate_list) {
276 boost::trim(speed_str);
277 double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
278 speed_per_pstate.push_back(speed);
279 XBT_DEBUG("Speed value: %f", speed);
282 return speed_per_pstate;
286 * All the callback lists that can be overridden anywhere.
287 * (this list should probably be reduced to the bare minimum to allow the models to work)
290 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
292 /* The default current property receiver. Setup in the corresponding opening callbacks. */
293 std::map<std::string, std::string>* current_property_set = nullptr;
294 std::map<std::string, std::string>* current_model_property_set = nullptr;
295 int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
297 YY_BUFFER_STATE surf_input_buffer;
298 FILE *surf_file_to_parse = nullptr;
300 /* Stuff relative to storage */
301 void STag_surfxml_storage()
304 XBT_DEBUG("STag_surfxml_storage");
305 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
308 void ETag_surfxml_storage()
310 StorageCreationArgs storage;
312 storage.properties = current_property_set;
313 current_property_set = nullptr;
315 storage.id = A_surfxml_storage_id;
316 storage.type_id = A_surfxml_storage_typeId;
317 storage.content = A_surfxml_storage_content;
318 storage.attach = A_surfxml_storage_attach;
320 sg_platf_new_storage(&storage);
322 void STag_surfxml_storage___type()
325 XBT_DEBUG("STag_surfxml_storage___type");
326 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
327 xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
329 void ETag_surfxml_storage___type()
331 StorageTypeCreationArgs storage_type;
333 storage_type.properties = current_property_set;
334 current_property_set = nullptr;
336 storage_type.model_properties = current_model_property_set;
337 current_model_property_set = nullptr;
339 storage_type.content = A_surfxml_storage___type_content;
340 storage_type.id = A_surfxml_storage___type_id;
341 storage_type.model = A_surfxml_storage___type_model;
343 surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
344 sg_platf_new_storage_type(&storage_type);
347 void STag_surfxml_mount()
349 XBT_DEBUG("STag_surfxml_mount");
352 void ETag_surfxml_mount()
354 MountCreationArgs mount;
356 mount.name = A_surfxml_mount_name;
357 mount.storageId = A_surfxml_mount_storageId;
358 sg_platf_new_mount(&mount);
362 * Stuff relative to the <include> tag
364 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
365 static std::vector<FILE*> surf_file_to_parse_stack;
366 static std::vector<char*> surf_parsed_filename_stack;
368 void STag_surfxml_include()
370 XBT_ERROR("<include> tag is deprecated, and will be removed in SimGrid v3.18. Please stop using it now (or tell us why you need it).");
371 parse_after_config();
372 XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
373 surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
374 surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
376 surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
378 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
379 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
381 surf_input_buffer_stack.push_back(surf_input_buffer);
382 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
383 surf_parse_push_buffer_state(surf_input_buffer);
388 void ETag_surfxml_include() {
389 /* Nothing to do when done with reading the include tag.
390 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
393 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
395 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
396 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
397 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
398 * error message in that case.
400 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
401 * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
402 * on a line. One day maybe, if the maya allow it.
404 int ETag_surfxml_include_state()
407 XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
409 if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
412 // Yeah, we were in an <include> Restore state and proceed.
413 fclose(surf_file_to_parse);
414 surf_file_to_parse_stack.pop_back();
415 surf_parse_pop_buffer_state();
416 surf_input_buffer_stack.pop_back();
418 // Restore the filename for error messages
419 free(surf_parsed_filename);
420 surf_parsed_filename_stack.pop_back();
425 /* Stag and Etag parse functions */
427 void STag_surfxml_platform() {
428 XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
430 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
431 "You're using an ancient XML file.\n"
432 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
433 "instead of MBytes, MFlops and seconds.\n"
435 "Use simgrid_update_xml to update your file automatically. "
436 "This program is installed automatically with SimGrid, or "
437 "available in the tools/ directory of the source archive.\n"
439 "Please check also out the SURF section of the ChangeLog for "
440 "the 3.1 version for more information. \n"
442 "Last, do not forget to also update your values for "
443 "the calls to MSG_task_create (if any).");
444 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
445 "You're using an old XML file.\n"
446 "Use simgrid_update_xml to update your file automatically. "
447 "This program is installed automatically with SimGrid, or "
448 "available in the tools/ directory of the source archive.");
449 xbt_assert((version >= 4.0),
450 "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
451 "Changes introduced in SimGrid 3.13:\n"
452 " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
453 " - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
454 " - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
455 " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
457 "Use simgrid_update_xml to update your file automatically. "
458 "This program is installed automatically with SimGrid, or "
459 "available in the tools/ directory of the source archive.",
460 surf_parsed_filename, version);
462 XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
463 "That's fine, the new version is backward compatible. \n\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.",
467 version, surf_parsed_filename);
469 xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
470 "The most recent formalism that this version of SimGrid understands is v4.1.\n"
471 "Please update your code, or use another, more adapted, file.",
472 surf_parsed_filename, version);
476 void ETag_surfxml_platform(){
480 void STag_surfxml_host(){
482 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
485 void STag_surfxml_prop()
487 if (ZONE_TAG) { // We need to retrieve the most recently opened zone
488 XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
489 simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
491 netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
493 if (not current_property_set)
494 current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
495 current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
496 XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
497 current_property_set);
501 void ETag_surfxml_host() {
502 s_sg_platf_host_cbarg_t host;
503 memset(&host,0,sizeof(host));
505 host.properties = current_property_set;
506 current_property_set = nullptr;
508 host.id = A_surfxml_host_id;
510 host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
512 XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
513 host.core_amount = surf_parse_get_int(A_surfxml_host_core);
514 host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
515 host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
516 host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
517 host.coord = A_surfxml_host_coordinates;
519 sg_platf_new_host(&host);
522 void STag_surfxml_host___link(){
523 XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
524 HostLinkCreationArgs host_link;
526 host_link.id = A_surfxml_host___link_id;
527 host_link.link_up = A_surfxml_host___link_up;
528 host_link.link_down = A_surfxml_host___link_down;
529 sg_platf_new_hostlink(&host_link);
532 void STag_surfxml_router(){
533 sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
536 void ETag_surfxml_cluster(){
537 ClusterCreationArgs cluster;
538 cluster.properties = current_property_set;
539 current_property_set = nullptr;
541 cluster.id = A_surfxml_cluster_id;
542 cluster.prefix = A_surfxml_cluster_prefix;
543 cluster.suffix = A_surfxml_cluster_suffix;
544 cluster.radicals = explodesRadical(A_surfxml_cluster_radical);
545 cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
546 cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
547 cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
548 cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
549 if(strcmp(A_surfxml_cluster_bb___bw,""))
550 cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
551 if(strcmp(A_surfxml_cluster_bb___lat,""))
552 cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
553 if(strcmp(A_surfxml_cluster_limiter___link,""))
554 cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
555 if(strcmp(A_surfxml_cluster_loopback___bw,""))
556 cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
557 if(strcmp(A_surfxml_cluster_loopback___lat,""))
558 cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
560 switch(AX_surfxml_cluster_topology){
561 case A_surfxml_cluster_topology_FLAT:
562 cluster.topology= SURF_CLUSTER_FLAT ;
564 case A_surfxml_cluster_topology_TORUS:
565 cluster.topology= SURF_CLUSTER_TORUS ;
567 case A_surfxml_cluster_topology_FAT___TREE:
568 cluster.topology = SURF_CLUSTER_FAT_TREE;
570 case A_surfxml_cluster_topology_DRAGONFLY:
571 cluster.topology= SURF_CLUSTER_DRAGONFLY ;
574 surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
577 cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
578 cluster.router_id = A_surfxml_cluster_router___id;
580 switch (AX_surfxml_cluster_sharing___policy) {
581 case A_surfxml_cluster_sharing___policy_SHARED:
582 cluster.sharing_policy = SURF_LINK_SHARED;
584 case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
585 cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
587 case A_surfxml_cluster_sharing___policy_FATPIPE:
588 cluster.sharing_policy = SURF_LINK_FATPIPE;
591 surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
594 switch (AX_surfxml_cluster_bb___sharing___policy) {
595 case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
596 cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
598 case A_surfxml_cluster_bb___sharing___policy_SHARED:
599 cluster.bb_sharing_policy = SURF_LINK_SHARED;
602 surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
606 sg_platf_new_cluster(&cluster);
609 void STag_surfxml_cluster(){
611 parse_after_config();
612 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
615 void STag_surfxml_cabinet(){
616 parse_after_config();
617 CabinetCreationArgs cabinet;
618 cabinet.id = A_surfxml_cabinet_id;
619 cabinet.prefix = A_surfxml_cabinet_prefix;
620 cabinet.suffix = A_surfxml_cabinet_suffix;
621 cabinet.speed = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
622 cabinet.bw = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
623 cabinet.lat = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
624 cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
626 sg_platf_new_cabinet(&cabinet);
629 void STag_surfxml_peer(){
630 parse_after_config();
631 PeerCreationArgs peer;
633 peer.id = std::string(A_surfxml_peer_id);
634 peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
635 peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
636 peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
637 peer.coord = A_surfxml_peer_coordinates;
638 peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
639 peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
641 if (A_surfxml_peer_lat[0] != '\0')
642 XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
645 sg_platf_new_peer(&peer);
648 void STag_surfxml_link(){
650 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
653 void ETag_surfxml_link(){
654 LinkCreationArgs link;
656 link.properties = current_property_set;
657 current_property_set = nullptr;
659 link.id = std::string(A_surfxml_link_id);
660 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
661 link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
662 link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
663 link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
664 link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
666 switch (A_surfxml_link_sharing___policy) {
667 case A_surfxml_link_sharing___policy_SHARED:
668 link.policy = SURF_LINK_SHARED;
670 case A_surfxml_link_sharing___policy_FATPIPE:
671 link.policy = SURF_LINK_FATPIPE;
673 case A_surfxml_link_sharing___policy_FULLDUPLEX:
674 link.policy = SURF_LINK_FULLDUPLEX;
677 surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
681 sg_platf_new_link(&link);
684 void STag_surfxml_link___ctn()
686 simgrid::surf::LinkImpl* link = nullptr;
687 switch (A_surfxml_link___ctn_direction) {
688 case AU_surfxml_link___ctn_direction:
689 case A_surfxml_link___ctn_direction_NONE:
690 link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
692 case A_surfxml_link___ctn_direction_UP:
693 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
695 case A_surfxml_link___ctn_direction_DOWN:
696 link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
699 surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
703 const char* dirname = "";
704 switch (A_surfxml_link___ctn_direction) {
705 case A_surfxml_link___ctn_direction_UP:
706 dirname = " (upward)";
708 case A_surfxml_link___ctn_direction_DOWN:
709 dirname = " (downward)";
714 surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
715 parsed_link_list.push_back(link);
718 void ETag_surfxml_backbone(){
719 LinkCreationArgs link;
721 link.properties = nullptr;
722 link.id = std::string(A_surfxml_backbone_id);
723 link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
724 link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
725 link.policy = SURF_LINK_SHARED;
727 sg_platf_new_link(&link);
728 routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
731 void STag_surfxml_route(){
732 surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
733 surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
736 void STag_surfxml_ASroute(){
737 surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
738 surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
740 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
741 surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
743 void STag_surfxml_zoneRoute(){
744 surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
745 surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
746 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
747 surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
750 void STag_surfxml_bypassRoute(){
751 surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
752 surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
755 void STag_surfxml_bypassASroute(){
756 surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
757 surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
758 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
759 surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
761 void STag_surfxml_bypassZoneRoute(){
762 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
763 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
764 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
765 surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
768 void ETag_surfxml_route(){
769 s_sg_platf_route_cbarg_t route;
770 memset(&route,0,sizeof(route));
772 route.src = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
773 route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
774 route.gw_src = nullptr;
775 route.gw_dst = nullptr;
776 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
777 route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
779 for (auto const& link : parsed_link_list)
780 route.link_list->push_back(link);
781 parsed_link_list.clear();
783 sg_platf_new_route(&route);
784 delete route.link_list;
787 void ETag_surfxml_ASroute()
789 AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
790 AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
791 AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
792 AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
793 AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
794 ETag_surfxml_zoneRoute();
796 void ETag_surfxml_zoneRoute()
798 s_sg_platf_route_cbarg_t ASroute;
799 memset(&ASroute,0,sizeof(ASroute));
801 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
802 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
804 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
805 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
807 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
809 for (auto const& link : parsed_link_list)
810 ASroute.link_list->push_back(link);
811 parsed_link_list.clear();
813 switch (A_surfxml_zoneRoute_symmetrical) {
814 case AU_surfxml_zoneRoute_symmetrical:
815 case A_surfxml_zoneRoute_symmetrical_YES:
816 ASroute.symmetrical = true;
818 case A_surfxml_zoneRoute_symmetrical_NO:
819 ASroute.symmetrical = false;
825 sg_platf_new_route(&ASroute);
826 delete ASroute.link_list;
829 void ETag_surfxml_bypassRoute(){
830 s_sg_platf_route_cbarg_t route;
831 memset(&route,0,sizeof(route));
833 route.src = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
834 route.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
835 route.gw_src = nullptr;
836 route.gw_dst = nullptr;
837 route.symmetrical = false;
838 route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
840 for (auto const& link : parsed_link_list)
841 route.link_list->push_back(link);
842 parsed_link_list.clear();
844 sg_platf_new_bypassRoute(&route);
845 delete route.link_list;
848 void ETag_surfxml_bypassASroute()
850 AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
851 AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
852 AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
853 AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
854 ETag_surfxml_bypassZoneRoute();
856 void ETag_surfxml_bypassZoneRoute()
858 s_sg_platf_route_cbarg_t ASroute;
859 memset(&ASroute,0,sizeof(ASroute));
861 ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
862 ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
863 ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
864 for (auto const& link : parsed_link_list)
865 ASroute.link_list->push_back(link);
866 parsed_link_list.clear();
868 ASroute.symmetrical = false;
870 ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
871 ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
873 sg_platf_new_bypassRoute(&ASroute);
874 delete ASroute.link_list;
877 void ETag_surfxml_trace(){
878 TraceCreationArgs trace;
880 trace.id = A_surfxml_trace_id;
881 trace.file = A_surfxml_trace_file;
882 trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
883 trace.pc_data = surfxml_pcdata;
885 sg_platf_new_trace(&trace);
888 void STag_surfxml_trace___connect()
890 parse_after_config();
891 TraceConnectCreationArgs trace_connect;
893 trace_connect.element = A_surfxml_trace___connect_element;
894 trace_connect.trace = A_surfxml_trace___connect_trace;
896 switch (A_surfxml_trace___connect_kind) {
897 case AU_surfxml_trace___connect_kind:
898 case A_surfxml_trace___connect_kind_SPEED:
899 trace_connect.kind = SURF_TRACE_CONNECT_KIND_SPEED;
901 case A_surfxml_trace___connect_kind_BANDWIDTH:
902 trace_connect.kind = SURF_TRACE_CONNECT_KIND_BANDWIDTH;
904 case A_surfxml_trace___connect_kind_HOST___AVAIL:
905 trace_connect.kind = SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
907 case A_surfxml_trace___connect_kind_LATENCY:
908 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LATENCY;
910 case A_surfxml_trace___connect_kind_LINK___AVAIL:
911 trace_connect.kind = SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
914 surf_parse_error("Invalid trace kind");
917 sg_platf_trace_connect(&trace_connect);
920 void STag_surfxml_AS()
922 AX_surfxml_zone_id = AX_surfxml_AS_id;
923 AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
927 void ETag_surfxml_AS()
932 void STag_surfxml_zone()
934 parse_after_config();
936 ZoneCreationArgs zone;
937 zone.id = A_surfxml_zone_id;
938 zone.routing = static_cast<int>(A_surfxml_zone_routing);
940 sg_platf_new_Zone_begin(&zone);
943 void ETag_surfxml_zone()
945 sg_platf_new_Zone_seal();
948 void STag_surfxml_config()
951 xbt_assert(current_property_set == nullptr,
952 "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
953 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
954 if (_sg_cfg_init_status == 2) {
955 surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
960 void ETag_surfxml_config()
962 for (auto const& elm : *current_property_set) {
963 if (xbt_cfg_is_default_value(elm.first.c_str())) {
964 std::string cfg = elm.first + ":" + elm.second;
965 xbt_cfg_set_parse(cfg.c_str());
967 XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
969 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
971 delete current_property_set;
972 current_property_set = nullptr;
978 void STag_surfxml_process()
980 AX_surfxml_actor_function = AX_surfxml_process_function;
981 STag_surfxml_actor();
984 void STag_surfxml_actor()
988 argv = xbt_new(char *, 1);
989 argv[0] = xbt_strdup(A_surfxml_actor_function);
990 xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
993 void ETag_surfxml_process()
995 AX_surfxml_actor_host = AX_surfxml_process_host;
996 AX_surfxml_actor_function = AX_surfxml_process_function;
997 AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
998 AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
999 AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1000 ETag_surfxml_actor();
1003 void ETag_surfxml_actor()
1005 s_sg_platf_process_cbarg_t actor;
1006 memset(&actor,0,sizeof(actor));
1008 actor.properties = current_property_set;
1009 current_property_set = nullptr;
1012 actor.argv = (const char **)argv;
1013 actor.host = A_surfxml_actor_host;
1014 actor.function = A_surfxml_actor_function;
1015 actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1016 actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time);
1018 switch (A_surfxml_actor_on___failure) {
1019 case AU_surfxml_actor_on___failure:
1020 case A_surfxml_actor_on___failure_DIE:
1021 actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE;
1023 case A_surfxml_actor_on___failure_RESTART:
1024 actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART;
1027 surf_parse_error("Invalid on failure behavior");
1031 sg_platf_new_process(&actor);
1033 for (int i = 0; i != argc; ++i)
1039 void STag_surfxml_argument(){
1041 argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1042 argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1045 void STag_surfxml_model___prop(){
1046 if (not current_model_property_set)
1047 current_model_property_set = new std::map<std::string, std::string>();
1049 current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1052 void ETag_surfxml_prop(){/* Nothing to do */}
1053 void STag_surfxml_random(){/* Nothing to do */}
1054 void ETag_surfxml_random(){/* Nothing to do */}
1055 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1056 void STag_surfxml_trace(){parse_after_config();}
1057 void ETag_surfxml_router(){/*Nothing to do*/}
1058 void ETag_surfxml_host___link(){/* Nothing to do */}
1059 void ETag_surfxml_cabinet(){/* Nothing to do */}
1060 void ETag_surfxml_peer(){/* Nothing to do */}
1061 void STag_surfxml_backbone(){/* Nothing to do */}
1062 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1063 void ETag_surfxml_argument(){/* Nothing to do */}
1064 void ETag_surfxml_model___prop(){/* Nothing to do */}
1066 /* Open and Close parse file */
1067 void surf_parse_open(const char *file)
1069 xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1071 surf_parsed_filename = xbt_strdup(file);
1072 std::string dir = simgrid::xbt::Path(file).getDirname();
1073 surf_path.push_back(dir);
1075 surf_file_to_parse = surf_fopen(file, "r");
1076 if (surf_file_to_parse == nullptr)
1077 xbt_die("Unable to open '%s'\n", file);
1078 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1079 surf_parse__switch_to_buffer(surf_input_buffer);
1080 surf_parse_lineno = 1;
1083 void surf_parse_close()
1085 if (surf_parsed_filename) {
1086 surf_path.pop_back();
1089 free(surf_parsed_filename);
1090 surf_parsed_filename = nullptr;
1092 if (surf_file_to_parse) {
1093 surf_parse__delete_buffer(surf_input_buffer);
1094 fclose(surf_file_to_parse);
1095 surf_file_to_parse = nullptr; //Must be reset for Bypass
1099 /* Call the lexer to parse the currently opened file */
1102 return surf_parse_lex();