Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[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   kernel::routing::NetZoneImpl* const pimpl_;
31
32 protected:
33   friend kernel::routing::NetZoneImpl;
34
35   explicit NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
36
37 public:
38   /** @brief Retrieves the name of that netzone as a C++ string */
39   const std::string& get_name() const;
40   /** @brief Retrieves the name of that netzone as a C string */
41   const char* get_cname() const;
42
43   XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZone* get_father();
44   NetZone* get_parent() const;
45   NetZone* set_parent(const NetZone* parent);
46
47   std::vector<Host*> get_all_hosts() const;
48   int get_host_count() const;
49
50   kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
51
52   /** Get the properties assigned to a netzone */
53   const std::unordered_map<std::string, std::string>* get_properties() const;
54   /** Retrieve the property value (or nullptr if not set) */
55   const char* get_property(const std::string& key) const;
56   void set_property(const std::string& key, const std::string& value);
57
58   std::vector<NetZone*> get_children() const;
59   NetZone* add_child(const NetZone* new_zone);
60
61   void extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
62                          std::map<std::string, xbt_edge_t, std::less<>>* edges);
63
64   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
65   int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
66
67   /**
68    * @brief Add a route between 2 netpoints
69    *
70    * Create a regular route between 2 netpoints. A netpoint can be a host
71    * or a router.
72    *
73    * @param src Source netpoint
74    * @param dst Destination netpoint
75    * @param link_list List of links used in this communication
76    * @param symmetrical Bi-directional communication
77    */
78   void add_regular_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
79                          const std::vector<Link*>& link_list, bool symmetrical = true);
80   /**
81    * @brief Add a route between 2 netzones
82    *
83    * Create a route between 2 netzones, connecting 2 gateways.
84    *
85    * @param src Source netzone's netpoint
86    * @param dst Destination netzone' netpoint
87    * @param src_gw Netpoint of the gateway in the source netzone
88    * @param dst_gw Netpoint of the gateway in the destination netzone
89    * @param link_list List of links used in this communication
90    * @param symmetrical Bi-directional communication
91    */
92   void add_netzone_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
93                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
94                          const std::vector<Link*>& link_list, bool symmetrical = true);
95
96   void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
97                  kernel::routing::NetPoint* gw_dst, const std::vector<kernel::resource::LinkImpl*>& link_list,
98                  bool symmetrical);
99   void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
100                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
101                         std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
102
103   /*** Called on each newly created regular route (not on bypass routes) */
104   static xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
105                           kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
106                           std::vector<kernel::resource::LinkImpl*> const& link_list)>
107       on_route_creation;
108   static xbt::signal<void(NetZone const&)> on_creation;
109   static xbt::signal<void(NetZone const&)> on_seal;
110
111   /**
112    * @brief Create a host
113    *
114    * @param name Host name
115    * @param speed_per_state Vector of CPU's speeds
116    */
117   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
118   /**
119    * @brief Create a Host (string version)
120    *
121    * @throw std::invalid_argument if speed format is incorrect.
122    */
123   s4u::Host* create_host(const std::string& name, const std::vector<std::string>& speed_per_pstate);
124
125   /**
126    * @brief Create a link
127    *
128    * @param name Link name
129    * @param bandwidths Link's speed (vector for wifi links)
130    * @param policy Link sharing policy
131    * @throw std::invalid_argument if bandwidth format is incorrect.
132    */
133   s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths);
134
135   /** @brief Create a link (string version) */
136   s4u::Link* create_link(const std::string& name, const std::vector<std::string>& bandwidths);
137
138   /** @brief Seal this netzone configuration */
139   void seal();
140
141 private:
142   /** @brief Auxiliary function to get list of LinkImpl */
143   static std::vector<kernel::resource::LinkImpl*> get_link_list_impl(const std::vector<Link*> link_list);
144 };
145
146 // External constructors so that the types (and the types of their content) remain hidden
147 XBT_PUBLIC NetZone* create_full_zone(const std::string& name);
148 XBT_PUBLIC NetZone* create_cluster_zone(const std::string& name);
149 XBT_PUBLIC NetZone* create_dijkstra_zone(const std::string& name, bool cache);
150 XBT_PUBLIC NetZone* create_dragonfly_zone(const std::string& name);
151 XBT_PUBLIC NetZone* create_empty_zone(const std::string& name);
152 XBT_PUBLIC NetZone* create_fatTree_zone(const std::string& name);
153 XBT_PUBLIC NetZone* create_floyd_zone(const std::string& name);
154 XBT_PUBLIC NetZone* create_torus_zone(const std::string& name);
155 XBT_PUBLIC NetZone* create_vivaldi_zone(const std::string& name);
156 XBT_PUBLIC NetZone* create_wifi_zone(const std::string& name);
157
158 } // namespace s4u
159 } // namespace simgrid
160
161 #endif /* SIMGRID_S4U_NETZONE_HPP */