Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hide some deprecated symbols from doxygen
[simgrid.git] / include / simgrid / s4u / NetZone.hpp
1 /* Copyright (c) 2016-2021. The SimGrid Team. All rights reserved.               */
2
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. */
5
6 #ifndef SIMGRID_S4U_NETZONE_HPP
7 #define SIMGRID_S4U_NETZONE_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Link.hpp>
11 #include <xbt/graph.h>
12 #include <xbt/signal.hpp>
13
14 #include <map>
15 #include <string>
16 #include <unordered_map>
17 #include <utility>
18 #include <vector>
19
20 namespace simgrid {
21 namespace s4u {
22
23 /** @brief Networking Zones
24  *
25  * A netzone is a network container, in charge of routing information between elements (hosts) and to the nearby
26  * netzones. In SimGrid, there is a hierarchy of netzones, with a unique root zone (that you can retrieve from the
27  * s4u::Engine).
28  */
29 class XBT_PUBLIC NetZone {
30 #ifndef DOXYGEN
31   friend kernel::routing::NetZoneImpl;
32 #endif
33
34   kernel::routing::NetZoneImpl* const pimpl_;
35
36 protected:
37   explicit NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
38
39 public:
40   /** @brief Retrieves the name of that netzone as a C++ string */
41   const std::string& get_name() const;
42   /** @brief Retrieves the name of that netzone as a C string */
43   const char* get_cname() const;
44
45   NetZone* get_parent() const;
46   NetZone* set_parent(const NetZone* parent);
47
48   std::vector<Host*> get_all_hosts() const;
49   int get_host_count() const;
50
51   kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
52
53   /** Get the properties assigned to a netzone */
54   const std::unordered_map<std::string, std::string>* get_properties() const;
55   /** Retrieve the property value (or nullptr if not set) */
56   const char* get_property(const std::string& key) const;
57   void set_property(const std::string& key, const std::string& value);
58   /** @brief Get the netpoint associated to this netzone */
59   kernel::routing::NetPoint* get_netpoint();
60
61 #ifndef DOXYGEN
62   XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZone* get_father() const;
63   std::vector<NetZone*> get_children() const;
64   XBT_ATTRIB_DEPRECATED_v332("Please use set_parent() to manage NetZone's relationship") NetZone* add_child(
65       NetZone* new_zone);
66 #endif
67
68   void extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
69                          std::map<std::string, xbt_edge_t, std::less<>>* edges);
70
71   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
72   int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
73
74   /**
75    * @brief Add a route between 2 netpoints
76    *
77    * Create a route:
78    * - route between 2 hosts/routers in same netzone, no gateway is needed
79    * - route between 2 netzones, connecting 2 gateways.
80    *
81    * @param src Source netzone's netpoint
82    * @param dst Destination netzone' netpoint
83    * @param gw_src Netpoint of the gateway in the source netzone
84    * @param gw_dst Netpoint of the gateway in the destination netzone
85    * @param link_list List of links and their direction used in this communication
86    * @param symmetrical Bi-directional communication
87    */
88   void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
89                  kernel::routing::NetPoint* gw_dst, const std::vector<LinkInRoute>& link_list, bool symmetrical = true);
90
91 #ifndef DOXYGEN
92   XBT_ATTRIB_DEPRECATED_v332("Please use add_route() method which uses s4u::LinkInRoute instead of "
93                              "LinkImpl") void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
94                                                         kernel::routing::NetPoint* gw_src,
95                                                         kernel::routing::NetPoint* gw_dst,
96                                                         const std::vector<kernel::resource::LinkImpl*>& link_list,
97                                                         bool symmetrical);
98
99   XBT_ATTRIB_DEPRECATED_v332("Please use add_bypass_route() method which uses s4u::LinkInRoute instead of "
100                              "LinkImpl") void add_bypass_route(kernel::routing::NetPoint* src,
101                                                                kernel::routing::NetPoint* dst,
102                                                                kernel::routing::NetPoint* gw_src,
103                                                                kernel::routing::NetPoint* gw_dst,
104                                                                std::vector<kernel::resource::LinkImpl*>& link_list,
105                                                                bool /*symmetrical*/);
106 #endif
107
108   void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
109                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
110                         const std::vector<LinkInRoute>& link_list);
111
112 #ifndef DOXYGEN
113   /*** Called on each newly created regular route (not on bypass routes) */
114   static xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
115                           kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
116                           std::vector<kernel::resource::LinkImpl*> const& link_list)>
117       on_route_creation; // XBT_ATTRIB_DEPRECATED_v332 : should not be used by users, used by ns3.. if necessary,
118                          // signal shouldn't use LinkImpl*
119 #endif
120
121   static xbt::signal<void(NetZone const&)> on_creation;
122   static xbt::signal<void(NetZone const&)> on_seal;
123
124   /**
125    * @brief Create a host
126    *
127    * @param name Host name
128    * @param speed_per_pstate Vector of CPU's speeds
129    */
130   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
131   s4u::Host* create_host(const std::string& name, double speed);
132   /**
133    * @brief Create a Host (string version)
134    *
135    * @throw std::invalid_argument if speed format is incorrect.
136    */
137   s4u::Host* create_host(const std::string& name, const std::vector<std::string>& speed_per_pstate);
138   s4u::Host* create_host(const std::string& name, const std::string& speed);
139
140   /**
141    * @brief Create a link
142    *
143    * @param name Link name
144    * @param bandwidths Link's speed (vector for wifi links)
145    * @throw std::invalid_argument if bandwidth format is incorrect.
146    */
147   s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths);
148   s4u::Link* create_link(const std::string& name, double bandwidth);
149
150   /** @brief Create a link (string version) */
151   s4u::Link* create_link(const std::string& name, const std::vector<std::string>& bandwidths);
152   s4u::Link* create_link(const std::string& name, const std::string& bandwidth);
153
154   /**
155    * @brief Create a split-duplex link
156    *
157    * In SimGrid, split-duplex links are a composition of 2 regular (shared) links (up/down).
158    *
159    * This function eases its utilization by creating the 2 links for you. We append a suffix
160    * "_UP" and "_DOWN" to your link name to identify each of them.
161    *
162    * Both up/down links have exactly the same bandwidth
163    *
164    * @param name Name of the link
165    * @param bandwidth Speed
166    */
167   s4u::SplitDuplexLink* create_split_duplex_link(const std::string& name, const std::string& bandwidth);
168   s4u::SplitDuplexLink* create_split_duplex_link(const std::string& name, double bandwidth);
169
170   kernel::resource::NetworkModelIntf* get_network_model() const;
171
172   /**
173    * @brief Make a router within that NetZone
174    *
175    * @param name Router name
176    */
177   kernel::routing::NetPoint* create_router(const std::string& name);
178
179   /** @brief Seal this netzone configuration */
180   NetZone* seal();
181
182 private:
183 #ifndef DOXYGEN
184   /** @brief XBT_ATTRIB_DEPRECATED_v332 Auxiliary function to convert types */
185   static std::vector<LinkInRoute> convert_to_linkInRoute(const std::vector<kernel::resource::LinkImpl*>& link_list);
186 #endif
187 };
188
189 // External constructors so that the types (and the types of their content) remain hidden
190 XBT_PUBLIC NetZone* create_full_zone(const std::string& name);
191 XBT_PUBLIC NetZone* create_star_zone(const std::string& name);
192 XBT_PUBLIC NetZone* create_dijkstra_zone(const std::string& name, bool cache);
193 XBT_PUBLIC NetZone* create_empty_zone(const std::string& name);
194 XBT_PUBLIC NetZone* create_floyd_zone(const std::string& name);
195 XBT_PUBLIC NetZone* create_vivaldi_zone(const std::string& name);
196 XBT_PUBLIC NetZone* create_wifi_zone(const std::string& name);
197
198 // Extra data structure for complex constructors
199
200 /** @brief Aggregates the callbacks used to build clusters netzones (Torus/Dragronfly/Fat-Tree) */
201 struct ClusterCallbacks {
202   /**
203    * @brief Callback used to set the netpoint and gateway located at some leaf of clusters (Torus, FatTree, etc)
204    *
205    * The netpoint can be either a host, router or another netzone.
206    * Gateway must be non-null if netpoint is a netzone
207    *
208    * @param zone: The newly create zone, needed for creating new resources (hosts, links)
209    * @param coord: the coordinates of the element
210    * @param id: Internal identifier of the element
211    * @return pair<NetPoint*, NetPoint*>: returns a pair of netpoint and gateway.
212    */
213   using ClusterNetPointCb = std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>(
214       NetZone* zone, const std::vector<unsigned int>& coord, int id);
215   /**
216    * @brief Callback used to set the links for some leaf of the cluster (Torus, FatTree, etc)
217    *
218    * The coord parameter depends on the cluster being created:
219    * - Torus: Direct translation of the Torus' dimensions, e.g. (0, 0, 0) for a 3-D Torus
220    * - Fat-Tree: A pair (level in the tree, id), e.g. (0, 0): first leaf and (1,0): first switch at level 1.
221    * - Dragonfly: a tuple (group, chassis, blades/routers, nodes), e.g. (0, 0, 0, 0) for first node in the cluster.
222    * Important: To identify the router inside a "group, chassis, blade", we use MAX_UINT in the last parameter (e.g. 0,
223    * 0, 0, 4294967295).
224    *
225    * @param zone: The newly create zone, needed for creating new resources (hosts, links)
226    * @param coord: the coordinates of the element
227    * @param id: Internal identifier of the element
228    * @return Pointer to the Link
229    */
230   using ClusterLinkCb = Link*(NetZone* zone, const std::vector<unsigned int>& coord, int id);
231
232   std::function<ClusterNetPointCb> netpoint;
233   std::function<ClusterLinkCb> loopback = {};
234   std::function<ClusterLinkCb> limiter  = {};
235   explicit ClusterCallbacks(const std::function<ClusterNetPointCb>& set_netpoint)
236       : netpoint(set_netpoint){/*nothing to do */};
237   ClusterCallbacks(const std::function<ClusterNetPointCb>& set_netpoint,
238                    const std::function<ClusterLinkCb>& set_loopback, const std::function<ClusterLinkCb>& set_limiter)
239       : netpoint(set_netpoint), loopback(set_loopback), limiter(set_limiter){/*nothing to do */};
240 };
241 /**
242  * @brief Create a torus zone
243  *
244  * Torus clusters are characterized by:
245  * - dimensions, eg. {3,3,3} creates a torus with X = 3 elements, Y = 3 and Z = 3. In total, this cluster have 27
246  * elements
247  * - inter-node communication: (bandwidth, latency, sharing_policy) the elements are connected through regular links
248  * with these characteristics
249  * More details in: <a href="https://simgrid.org/doc/latest/Platform_examples.html?highlight=torus#torus-cluster">Torus
250  * Cluster</a>
251  *
252  * Moreover, this method accepts 3 callbacks to populate the cluster: set_netpoint, set_loopback and set_limiter .
253  *
254  * Note that the all elements in a Torus cluster must have (or not) the same elements (loopback and limiter)
255  *
256  * @param name NetZone's name
257  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
258  * the netzone
259  * @param dimensions List of positive integers (> 0) which determines the torus' dimensions
260  * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
261  * @param bandwidth Characteristics of the inter-nodes link
262  * @param latency Characteristics of the inter-nodes link
263  * @param sharing_policy Characteristics of the inter-nodes link
264  * @return Pointer to new netzone
265  */
266 XBT_PUBLIC NetZone* create_torus_zone(const std::string& name, const NetZone* parent,
267                                       const std::vector<unsigned int>& dimensions,
268                                       const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
269                                       Link::SharingPolicy sharing_policy);
270
271 /** @brief Aggregates the parameters necessary to build a Fat-tree zone */
272 struct FatTreeParams {
273   unsigned int levels;
274   std::vector<unsigned int> down;
275   std::vector<unsigned int> up;
276   std::vector<unsigned int> number;
277   FatTreeParams(unsigned int n_levels, const std::vector<unsigned int>& down_links,
278                 const std::vector<unsigned int>& up_links, const std::vector<unsigned int>& links_number);
279 };
280 /**
281  * @brief Create a Fat-Tree zone
282  *
283  * Fat-Tree clusters are characterized by:
284  * - levels: number of levels in the cluster, e.g. 2 (the final tree will have n+1 levels)
285  * - downlinks: for each level, how many connections between elements below them, e.g. 2, 3: level 1 nodes are connected
286  * to 2 nodes in level 2, which are connected to 3 nodes below. Determines the number total of leaves in the tree.
287  * - uplinks: for each level, how nodes are connected, e.g. 1, 2
288  * - link count: for each level, number of links connecting the nodes, e.g. 1, 1
289  *
290  * The best way to understand it is looking to the doc available in: <a
291  * href="https://simgrid.org/doc/latest/Platform_examples.html#fat-tree-cluster">Fat Tree Cluster</a>
292  *
293  * Moreover, this method accepts 3 callbacks to populate the cluster: set_netpoint, set_loopback and set_limiter .
294  *
295  * Note that the all elements in a Fat-Tree cluster must have (or not) the same elements (loopback and limiter)
296  *
297  * @param name NetZone's name
298  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
299  * the netzone
300  * @param parameters Characteristics of this Fat-Tree
301  * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
302  * @param bandwidth Characteristics of the inter-nodes link
303  * @param latency Characteristics of the inter-nodes link
304  * @param sharing_policy Characteristics of the inter-nodes link
305  * @return Pointer to new netzone
306  */
307 XBT_PUBLIC NetZone* create_fatTree_zone(const std::string& name, const NetZone* parent, const FatTreeParams& parameters,
308                                         const ClusterCallbacks& set_callbacks, double bandwidth, double latency,
309                                         Link::SharingPolicy sharing_policy);
310
311 /** @brief Aggregates the parameters necessary to build a Dragonfly zone */
312 struct DragonflyParams {
313   std::pair<unsigned int, unsigned int> groups;
314   std::pair<unsigned int, unsigned int> chassis;
315   std::pair<unsigned int, unsigned int> routers;
316   unsigned int nodes;
317   DragonflyParams(const std::pair<unsigned int, unsigned int>& groups,
318                   const std::pair<unsigned int, unsigned int>& chassis,
319                   const std::pair<unsigned int, unsigned int>& routers, unsigned int nodes);
320 };
321 /**
322  * @brief Create a Dragonfly zone
323  *
324  * Dragonfly clusters are characterized by:
325  * - groups: number of groups and links between each group, e.g. 2,2.
326  * - chassis: number of chassis in each group and the number of links used to connect the chassis, e.g. 2,3
327  * - routers: number of routers in each chassis and their links, e.g. 3,1
328  * - nodes: number of nodes connected to each router using a single link, e.g. 2
329  *
330  * In total, the cluster will have groups * chassis * routers * nodes elements/leaves.
331  *
332  * The best way to understand it is looking to the doc available in: <a
333  * href="https://simgrid.org/doc/latest/Platform_examples.html#dragonfly-cluster">Dragonfly Cluster</a>
334  *
335  * Moreover, this method accepts 3 callbacks to populate the cluster: set_netpoint, set_loopback and set_limiter .
336  *
337  * Note that the all elements in a Dragonfly cluster must have (or not) the same elements (loopback and limiter)
338  *
339  * @param name NetZone's name
340  * @param parent Pointer to parent's netzone (nullptr if root netzone). Needed to be able to create the resources inside
341  * the netzone
342  * @param parameters Characteristics of this Dragonfly
343  * @param set_callbacks Callbacks to set properties from cluster elements (netpoint, loopback and limiter)
344  * @param bandwidth Characteristics of the inter-nodes link
345  * @param latency Characteristics of the inter-nodes link
346  * @param sharing_policy Characteristics of the inter-nodes link
347  * @return Pointer to new netzone
348  */
349 XBT_PUBLIC NetZone* create_dragonfly_zone(const std::string& name, const NetZone* parent,
350                                           const DragonflyParams& parameters, const ClusterCallbacks& set_callbacks,
351                                           double bandwidth, double latency, Link::SharingPolicy sharing_policy);
352
353 } // namespace s4u
354 } // namespace simgrid
355
356 #endif /* SIMGRID_S4U_NETZONE_HPP */