Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf_cpu_model_pm: remove global
[simgrid.git] / include / simgrid / kernel / routing / NetZoneImpl.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_ROUTING_NETZONEIMPL_HPP
7 #define SIMGRID_ROUTING_NETZONEIMPL_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Link.hpp>
11 #include <simgrid/s4u/NetZone.hpp>
12 #include <xbt/PropertyHolder.hpp>
13 #include <xbt/graph.h>
14
15 #include <map>
16 #include <vector>
17
18 namespace simgrid {
19 namespace kernel {
20 namespace routing {
21
22 class BypassRoute {
23 public:
24   explicit BypassRoute(NetPoint* gwSrc, NetPoint* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {}
25   NetPoint* gw_src;
26   NetPoint* gw_dst;
27   std::vector<resource::LinkImpl*> links;
28 };
29
30 /** @ingroup ROUTING_API
31  *  @brief Private implementation of the Networking Zones
32  *
33  * A netzone is a network container, in charge of routing information between elements (hosts and sub-netzones)
34  * and to the nearby netzones. In SimGrid, there is a hierarchy of netzones, ie a tree with a unique root
35  * NetZone, that you can retrieve with simgrid::s4u::Engine::netRoot().
36  *
37  * The purpose of the kernel::routing module is to retrieve the routing path between two points in a time- and
38  * space-efficient manner. This is done by NetZoneImpl::getGlobalRoute(), called when creating a communication to
39  * retrieve both the list of links that the create communication will use, and the summed latency that these
40  * links represent.
41  *
42  * The network model could recompute the latency by itself from the list, but it would require an additional
43  * traversal of the link set. This operation being on the critical path of SimGrid, the routing computes the
44  * latency on the behalf of the network while constructing the link set.
45  *
46  * Finding the path between two nodes is rather complex because we navigate a hierarchy of netzones, each of them
47  * being a full network. In addition, the routing can declare shortcuts (called bypasses), either within a NetZone
48  * at the route level or directly between NetZones. Also, each NetZone can use a differing routing algorithm, depending
49  * on its class. @ref FullZone have a full matrix giving explicitly the path between any pair of their
50  * contained nodes, while @ref DijkstraZone or @ref FloydZone rely on a shortest path algorithm. @ref VivaldiZone
51  * does not even have any link but only use only coordinate information to compute the latency.
52  *
53  * So NetZoneImpl::getGlobalRoute builds the path recursively asking its specific information to each traversed NetZone
54  * with NetZoneImpl::getLocalRoute, that is redefined in each sub-class.
55  * The algorithm for that is explained in http://hal.inria.fr/hal-00650233/ (but for historical reasons, NetZones are
56  * called Autonomous Systems in this article).
57  *
58  */
59 class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
60   friend EngineImpl; // it destroys netRoot_
61   s4u::NetZone piface_;
62
63   // our content, as known to our graph routing algorithm (maps vertex_id -> vertex)
64   std::vector<kernel::routing::NetPoint*> vertices_;
65
66   NetZoneImpl* father_ = nullptr;
67   std::vector<NetZoneImpl*> children_; // sub-netzones
68   std::string name_;
69   bool sealed_ = false; // We cannot add more content when sealed
70
71   std::map<std::pair<NetPoint*, NetPoint*>, BypassRoute*> bypass_routes_; // src x dst -> route
72   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
73   resource::NetworkModel* network_model_;
74   resource::CpuModel* cpu_model_vm_;
75   resource::CpuModel* cpu_model_pm_;
76
77 protected:
78   explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model);
79   NetZoneImpl(const NetZoneImpl&) = delete;
80   NetZoneImpl& operator=(const NetZoneImpl&) = delete;
81   virtual ~NetZoneImpl();
82
83   /**
84    * @brief Probe the routing path between two points that are local to the called NetZone.
85    *
86    * @param src where from
87    * @param dst where to
88    * @param into Container into which the traversed links and gateway information should be pushed
89    * @param latency Accumulator in which the latencies should be added (caller must set it to 0)
90    */
91   virtual void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) = 0;
92   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
93   /* returns whether we found a bypass path */
94   bool get_bypass_route(routing::NetPoint* src, routing::NetPoint* dst,
95                         /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency);
96
97 public:
98   enum class RoutingMode {
99     unset = 0, /**< Undefined type                                   */
100     base,      /**< Base case: use simple link lists for routing     */
101     recursive  /**< Recursive case: also return gateway information  */
102   };
103
104   /* FIXME: protect the following fields once the construction madness is sorted out */
105   RoutingMode hierarchy_ = RoutingMode::unset;
106
107   /** @brief Retrieves the network model associated to this NetZone */
108   resource::NetworkModel* get_network_model() const { return network_model_; }
109   /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */
110   resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; }
111   /** @brief Retrieves the CPU model for physical machines associated to this NetZone */
112   resource::CpuModel* get_cpu_pm_model() const { return cpu_model_pm_; }
113
114   const s4u::NetZone* get_iface() const { return &piface_; }
115   s4u::NetZone* get_iface() { return &piface_; }
116   unsigned int get_table_size() const { return vertices_.size(); }
117   std::vector<kernel::routing::NetPoint*> get_vertices() const { return vertices_; }
118   NetZoneImpl* get_father() const { return father_; }
119   /** @brief Returns the list of direct children (no grand-children). This returns the internal data, no copy.
120    * Don't mess with it.*/
121   std::vector<NetZoneImpl*>* get_children() { return &children_; }
122   /** @brief Retrieves the name of that netzone as a C++ string */
123   const std::string& get_name() const { return name_; }
124   /** @brief Retrieves the name of that netzone as a C string */
125   const char* get_cname() const { return name_.c_str(); };
126
127   std::vector<s4u::Host*> get_all_hosts() const;
128   int get_host_count() const;
129
130   /** @brief Make a host within that NetZone */
131   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate, int core_amount);
132   /** @brief Make a link within that NetZone */
133   virtual s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths,
134                                  s4u::Link::SharingPolicy policy);
135   /** @brief Creates a new route in this NetZone */
136   virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
137                                 std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
138
139   /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
140   virtual void seal() { sealed_ = true; };
141   virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
142   virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
143                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
144                          std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
145
146   /* @brief get the route between two nodes in the full platform
147    *
148    * @param src where from
149    * @param dst where to
150    * @param links Accumulator in which all traversed links should be pushed (caller must empty it)
151    * @param latency Accumulator in which the latencies should be added (caller must set it to 0)
152    */
153   static void get_global_route(routing::NetPoint* src, routing::NetPoint* dst,
154                                /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency);
155
156   virtual void get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
157                          std::map<std::string, xbt_edge_t, std::less<>>* edges) = 0;
158 };
159 } // namespace routing
160 } // namespace kernel
161 } // namespace simgrid
162
163 #endif /* SIMGRID_ROUTING_NETZONEIMPL_HPP */