Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Inventive hack to get flex raising exceptions on parse error
[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-2019. 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/platf.hpp"
15 #include "src/surf/xml/simgrid_dtd.h"
16
17 #include <map>
18 #include <string>
19 #include <vector>
20
21 namespace simgrid {
22 namespace kernel {
23 namespace routing {
24 /* ***************************************** */
25 /*
26  * Platform creation functions. Instead of passing 123 arguments to the creation functions
27  * (one for each possible XML attribute), we pass structures containing them all. It removes the
28  * chances of switching arguments by error, and reduce the burden when we add a new attribute:
29  * old models can just continue to ignore it without having to update their headers.
30  *
31  * It shouldn't be too costly at runtime, provided that structures living on the stack are
32  * used, instead of malloced structures.
33  */
34
35 struct HostCreationArgs {
36   const char* id = nullptr;
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   std::unordered_map<std::string, std::string>* properties = nullptr;
44   std::vector<simgrid::kernel::resource::DiskImpl*> disks;
45 };
46
47 class HostLinkCreationArgs {
48 public:
49   std::string id;
50   std::string link_up;
51   std::string link_down;
52 };
53
54 class LinkCreationArgs {
55 public:
56   std::string id;
57   std::vector<double> bandwidths;
58   profile::Profile* bandwidth_trace                        = nullptr;
59   double latency                      = 0;
60   profile::Profile* latency_trace                          = nullptr;
61   profile::Profile* state_trace                            = nullptr;
62   simgrid::s4u::Link::SharingPolicy policy       = simgrid::s4u::Link::SharingPolicy::FATPIPE;
63   std::unordered_map<std::string, std::string>* properties = nullptr;
64 };
65
66 class PeerCreationArgs {
67 public:
68   std::string id;
69   double speed;
70   double bw_in;
71   double bw_out;
72   std::string coord;
73   profile::Profile* speed_trace;
74   profile::Profile* state_trace;
75 };
76
77 class RouteCreationArgs {
78 public:
79   bool symmetrical = false;
80   NetPoint* src    = nullptr;
81   NetPoint* dst    = nullptr;
82   NetPoint* gw_src = nullptr;
83   NetPoint* gw_dst = nullptr;
84   std::vector<simgrid::kernel::resource::LinkImpl*> link_list;
85 };
86
87 enum class ClusterTopology { DRAGONFLY = 3, FAT_TREE = 2, FLAT = 1, TORUS = 0 };
88
89 class ClusterCreationArgs {
90 public:
91   std::string id;
92   std::string prefix;
93   std::string suffix;
94   std::vector<int>* radicals = nullptr;
95   std::vector<double> speeds;
96   int core_amount     = 0;
97   double bw           = 0;
98   double lat          = 0;
99   double bb_bw        = 0;
100   double bb_lat       = 0;
101   double loopback_bw  = 0;
102   double loopback_lat = 0;
103   double limiter_link = 0;
104   ClusterTopology topology;
105   std::string topo_parameters;
106   std::unordered_map<std::string, std::string>* properties;
107   std::string router_id;
108   simgrid::s4u::Link::SharingPolicy sharing_policy;
109   simgrid::s4u::Link::SharingPolicy bb_sharing_policy;
110 };
111
112 class CabinetCreationArgs {
113 public:
114   std::string id;
115   std::string prefix;
116   std::string suffix;
117   std::vector<int>* radicals;
118   double speed;
119   double bw;
120   double lat;
121 };
122
123 class StorageCreationArgs {
124 public:
125   std::string id;
126   std::string type_id;
127   std::string content;
128   std::unordered_map<std::string, std::string>* properties;
129   std::string attach;
130 };
131
132 class StorageTypeCreationArgs {
133 public:
134   std::string id;
135   std::string model;
136   std::string content;
137   std::unordered_map<std::string, std::string>* properties;
138   std::unordered_map<std::string, std::string>* model_properties;
139   sg_size_t size;
140 };
141
142 class DiskCreationArgs {
143 public:
144   std::string id;
145   std::unordered_map<std::string, std::string>* properties;
146   double read_bw;
147   double write_bw;
148 };
149
150 class MountCreationArgs {
151 public:
152   std::string storageId;
153   std::string name;
154 };
155
156 class ProfileCreationArgs {
157 public:
158   std::string id;
159   std::string file;
160   double periodicity;
161   std::string pc_data;
162 };
163
164 enum class TraceConnectKind { HOST_AVAIL, SPEED, LINK_AVAIL, BANDWIDTH, LATENCY };
165
166 class TraceConnectCreationArgs {
167 public:
168   TraceConnectKind kind;
169   std::string trace;
170   std::string element;
171 };
172
173 enum class ActorOnFailure { DIE, RESTART }; // FIXME: move to a better namespace
174
175 class ActorCreationArgs {
176 public:
177   std::vector<std::string> args;
178   std::unordered_map<std::string, std::string>* properties = nullptr;
179   const char* host                       = nullptr;
180   const char* function                   = nullptr;
181   double start_time                      = 0.0;
182   double kill_time                       = 0.0;
183   ActorOnFailure on_failure;
184 };
185
186 class ZoneCreationArgs {
187 public:
188   std::string id;
189   int routing;
190 };
191 }}}
192
193 /********** Routing **********/
194 void routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl* bb);
195 /*** END of the parsing cruft ***/
196
197 XBT_PUBLIC simgrid::kernel::routing::NetZoneImpl*
198 sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone);         // Begin description of new Zone
199 XBT_PUBLIC void sg_platf_new_Zone_set_properties(std::unordered_map<std::string, std::string>* props);
200 XBT_PUBLIC void sg_platf_new_Zone_seal();                                          // That Zone is fully described
201
202 XBT_PUBLIC void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* host);      // Add a host      to the current Zone
203 XBT_PUBLIC void sg_platf_new_hostlink(simgrid::kernel::routing::HostLinkCreationArgs* h);     // Add a host_link to the current Zone
204 XBT_PUBLIC void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link);          // Add a link      to the current Zone
205 XBT_PUBLIC void sg_platf_new_peer(simgrid::kernel::routing::PeerCreationArgs* peer);          // Add a peer      to the current Zone
206 XBT_PUBLIC void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* clust);   // Add a cluster   to the current Zone
207 XBT_PUBLIC void sg_platf_new_cabinet(simgrid::kernel::routing::CabinetCreationArgs* cabinet); // Add a cabinet   to the current Zone
208 XBT_PUBLIC simgrid::kernel::routing::NetPoint* // Add a router    to the current Zone
209     sg_platf_new_router(const std::string&, const char* coords);
210
211 XBT_PUBLIC void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route);             // Add a route
212 XBT_PUBLIC void sg_platf_new_bypassRoute(simgrid::kernel::routing::RouteCreationArgs* bypassroute); // Add a bypassRoute
213
214 XBT_PUBLIC void sg_platf_new_trace(simgrid::kernel::routing::ProfileCreationArgs* trace);
215
216 XBT_PUBLIC simgrid::kernel::resource::DiskImpl*
217 sg_platf_new_disk(simgrid::kernel::routing::DiskCreationArgs* disk); // Add a disk to the current host
218
219 XBT_PUBLIC void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage); // Add a storage to the current Zone
220 XBT_PUBLIC void sg_platf_new_storage_type(simgrid::kernel::routing::StorageTypeCreationArgs* storage_type);
221 XBT_PUBLIC void sg_platf_new_mount(simgrid::kernel::routing::MountCreationArgs* mount);
222
223 XBT_PUBLIC void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor);
224 XBT_PRIVATE void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect);
225
226 /* Prototypes of the functions offered by flex */
227 XBT_PUBLIC int surf_parse_lex();
228 XBT_PUBLIC int surf_parse_get_lineno();
229 XBT_PUBLIC FILE* surf_parse_get_in();
230 XBT_PUBLIC FILE* surf_parse_get_out();
231 XBT_PUBLIC int surf_parse_get_leng();
232 XBT_PUBLIC char* surf_parse_get_text();
233 XBT_PUBLIC void surf_parse_set_lineno(int line_number);
234 XBT_PUBLIC void surf_parse_set_in(FILE* in_str);
235 XBT_PUBLIC void surf_parse_set_out(FILE* out_str);
236 XBT_PUBLIC int surf_parse_get_debug();
237 XBT_PUBLIC void surf_parse_set_debug(int bdebug);
238 XBT_PUBLIC int surf_parse_lex_destroy();
239
240 namespace simgrid {
241 namespace surf {
242
243 extern XBT_PRIVATE simgrid::xbt::signal<void(kernel::routing::ClusterCreationArgs const&)> on_cluster;
244 }
245 }
246
247 #endif                          /* SG_PLATF_H */