Logo AND Algorithmique Numérique Distribuée

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