Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further rename the identifiers of flexml to simgrid_parse_*
[simgrid.git] / src / surf / xml / platf_private.hpp
1 /* platf_private.h - Interface to the SimGrid platforms which visibility should be limited to this directory */
2
3 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef SG_PLATF_H
9 #define SG_PLATF_H
10
11 #include "simgrid/host.h"
12 #include "simgrid/s4u/Link.hpp"
13 #include "src/surf/xml/simgrid_dtd.h"
14
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 namespace simgrid::kernel::routing {
20 /* ***************************************** */
21 /*
22  * Platform creation functions. Instead of passing 123 arguments to the creation functions
23  * (one for each possible XML attribute), we pass structures containing them all. It removes the
24  * chances of switching arguments by error, and reduce the burden when we add a new attribute:
25  * old models can just continue to ignore it without having to update their headers.
26  *
27  * It shouldn't be too costly at runtime, provided that structures living on the stack are
28  * used, instead of malloced structures.
29  */
30
31 class HostCreationArgs {
32 public:
33   std::string id;
34   std::vector<double> speed_per_pstate;
35   int pstate               = 0;
36   int core_amount          = 0;
37   profile::Profile* speed_trace                            = nullptr;
38   profile::Profile* state_trace                            = nullptr;
39   std::string coord                                        = "";
40 };
41
42 class HostLinkCreationArgs {
43 public:
44   std::string id;
45   std::string link_up;
46   std::string link_down;
47 };
48
49 class LinkCreationArgs {
50 public:
51   std::string id;
52   std::vector<double> bandwidths;
53   profile::Profile* bandwidth_trace                        = nullptr;
54   double latency                                           = 0;
55   profile::Profile* latency_trace                          = nullptr;
56   profile::Profile* state_trace                            = nullptr;
57   s4u::Link::SharingPolicy policy                          = s4u::Link::SharingPolicy::FATPIPE;
58   std::unordered_map<std::string, std::string> properties;
59 };
60
61 class PeerCreationArgs {
62 public:
63   std::string id;
64   double speed;
65   double bw_in;
66   double bw_out;
67   std::string coord;
68   profile::Profile* speed_trace;
69   profile::Profile* state_trace;
70 };
71
72 class RouteCreationArgs {
73 public:
74   bool symmetrical = false;
75   NetPoint* src    = nullptr;
76   NetPoint* dst    = nullptr;
77   NetPoint* gw_src = nullptr;
78   NetPoint* gw_dst = nullptr;
79   std::vector<simgrid::s4u::LinkInRoute> link_list;
80 };
81
82 enum class ClusterTopology { DRAGONFLY = 3, FAT_TREE = 2, FLAT = 1, TORUS = 0 };
83
84 class ClusterCreationArgs {
85 public:
86   std::string id;
87   std::string prefix;
88   std::string suffix;
89   std::vector<int> radicals;
90   std::vector<double> speeds;
91   int core_amount     = 0;
92   double bw           = 0;
93   double lat          = 0;
94   double bb_bw        = 0;
95   double bb_lat       = 0;
96   double loopback_bw  = 0;
97   double loopback_lat = 0;
98   double limiter_link = 0;
99   ClusterTopology topology = ClusterTopology::FLAT;
100   std::string topo_parameters;
101   std::unordered_map<std::string, std::string> properties;
102   std::string router_id;
103   s4u::Link::SharingPolicy sharing_policy    = s4u::Link::SharingPolicy::SPLITDUPLEX;
104   s4u::Link::SharingPolicy bb_sharing_policy = s4u::Link::SharingPolicy::SHARED;
105 };
106
107 class CabinetCreationArgs {
108 public:
109   std::string id;
110   std::string prefix;
111   std::string suffix;
112   std::vector<int> radicals;
113   double speed;
114   double bw;
115   double lat;
116 };
117
118 class ClusterZoneCreationArgs {
119 public:
120   std::string routing;
121   std::vector<HostLinkCreationArgs> host_links;
122   std::vector<CabinetCreationArgs> cabinets;
123   std::unique_ptr<LinkCreationArgs> backbone;
124 };
125
126 class DiskCreationArgs {
127 public:
128   std::string id;
129   std::unordered_map<std::string, std::string> properties;
130   double read_bw;
131   double write_bw;
132 };
133
134 class ProfileCreationArgs {
135 public:
136   std::string id;
137   std::string file;
138   double periodicity;
139   std::string pc_data;
140 };
141
142 enum class TraceConnectKind { HOST_AVAIL, SPEED, LINK_AVAIL, BANDWIDTH, LATENCY };
143
144 class TraceConnectCreationArgs {
145 public:
146   TraceConnectKind kind;
147   std::string trace;
148   std::string element;
149 };
150
151 class ActorCreationArgs {
152 public:
153   std::vector<std::string> args;
154   std::unordered_map<std::string, std::string> properties;
155   const char* host                       = nullptr;
156   const char* function                   = nullptr;
157   double start_time                      = 0.0;
158   double kill_time                       = 0.0;
159   bool restart_on_failure                                  = false;
160 };
161
162 class ZoneCreationArgs {
163 public:
164   std::string id;
165   std::string routing;
166 };
167
168 extern XBT_PRIVATE xbt::signal<void(ClusterCreationArgs const&)> on_cluster_creation;
169
170 } // namespace simgrid::kernel::routing
171
172 /********** Routing **********/
173 void routing_cluster_add_backbone(std::unique_ptr<simgrid::kernel::routing::LinkCreationArgs> link);
174 /*** END of the parsing cruft ***/
175
176 XBT_PUBLIC simgrid::kernel::routing::NetZoneImpl*
177 sg_platf_new_zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone); // Begin description of new Zone
178 XBT_PUBLIC void sg_platf_new_zone_set_properties(const std::unordered_map<std::string, std::string>& props);
179 XBT_PUBLIC void sg_platf_new_zone_seal(); // That Zone is fully described
180
181 XBT_PUBLIC void
182 sg_platf_new_host_begin(const simgrid::kernel::routing::HostCreationArgs* host); // Add a host to the current Zone
183 XBT_PUBLIC void sg_platf_new_host_set_properties(const std::unordered_map<std::string, std::string>& props);
184 XBT_PUBLIC void sg_platf_new_host_seal(int pstate); // That Host is fully described
185
186 XBT_PUBLIC void
187 sg_platf_new_hostlink(const simgrid::kernel::routing::HostLinkCreationArgs* h); // Add a host_link to the current Zone
188 XBT_PUBLIC void
189 sg_platf_new_link(const simgrid::kernel::routing::LinkCreationArgs* link); // Add a link to the current Zone
190 XBT_PUBLIC void
191 sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk); // Add a disk to the current host
192 XBT_PUBLIC void
193 sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer); // Add a peer to the current Zone
194 XBT_PUBLIC void sg_platf_new_tag_cluster(
195     simgrid::kernel::routing::ClusterCreationArgs* clust); // Add a regular cluster  to the current Zone
196 XBT_PUBLIC simgrid::kernel::routing::NetPoint*                                      // Add a router to the current Zone
197 sg_platf_new_router(const std::string&, const std::string& coords);
198 XBT_PUBLIC void
199 sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* cabinet); // Add a cabinet to the current Zone
200 XBT_PUBLIC void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route);             // Add a route
201 XBT_PUBLIC void sg_platf_new_bypass_route(simgrid::kernel::routing::RouteCreationArgs* route); // Add a bypass route
202
203 XBT_PUBLIC void sg_platf_new_trace(const simgrid::kernel::routing::ProfileCreationArgs* trace);
204
205 XBT_PUBLIC void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor);
206 XBT_PRIVATE void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect);
207
208 /* Prototypes of the functions offered by flex */
209 XBT_PUBLIC int simgrid_parse_lex();
210 XBT_PUBLIC int simgrid_parse_get_lineno();
211 XBT_PUBLIC FILE* simgrid_parse_get_in();
212 XBT_PUBLIC FILE* simgrid_parse_get_out();
213 XBT_PUBLIC int simgrid_parse_get_leng();
214 XBT_PUBLIC char* simgrid_parse_get_text();
215 XBT_PUBLIC void simgrid_parse_set_lineno(int line_number);
216 XBT_PUBLIC void simgrid_parse_set_in(FILE* in_str);
217 XBT_PUBLIC void simgrid_parse_set_out(FILE* out_str);
218 XBT_PUBLIC int simgrid_parse_get_debug();
219 XBT_PUBLIC void simgrid_parse_set_debug(int bdebug);
220 XBT_PUBLIC int simgrid_parse_lex_destroy();
221
222 #endif                          /* SG_PLATF_H */