Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / include / simgrid / kernel / routing / StarZone.hpp
1 /* Copyright (c) 2013-2022. 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_KERNEL_ROUTING_STARZONE_HPP_
7 #define SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
8
9 #include <simgrid/kernel/routing/ClusterZone.hpp>
10
11 #include <unordered_map>
12 #include <unordered_set>
13
14 namespace simgrid {
15 namespace kernel {
16 namespace routing {
17
18 /** @ingroup ROUTING_API
19  *  @brief NetZone where components are connected following a star topology
20  *
21  *  Star zones have a collection of private links that interconnect their components.
22  *  By default, all components inside the star zone are interconnected with no links.
23  *
24  *  You can use add_route to set the links to be used during communications, 3
25  *  configurations are possible:
26  *  - (*(all) -> Component): links used in the outgoing communications from component (UP).
27  *  - (Component -> *(all)): links used in ine ingoing communication to component (DOWN).
28  *  - Loopback: links connecting the component to itself.
29  *
30  *  @note: Communications between nodes inside the Star zone cannot have duplicate links.
31  *         All duplicated links are automatically removed when building the route.
32  *
33  * \verbatim
34  *   (outer world)
35  *         |
36  *     l3 /|\ l4
37  *       / | \     <-- links
38  *      +  |  +
39  *  l0 / l1|   \l2
40  *    /    |    \
41  *   A     B     C <-- netpoints
42  * \endverbatim
43  *
44  *  So, a communication from the host A to the host B goes through the following links:
45  *   <tt>l0, l3, l1.</tt>
46  *
47  *  In the same way, a communication from host A to nodes outside this netzone will
48  *  use the same links <tt> l0, l3. </tt>
49  *
50  *  \verbatim
51  *   (outer world)
52  *         |
53  *   ======+====== <-- backbone
54  *   |   |   |   |
55  * l0| l1| l2| l4| <-- links
56  *   |   |   |   |
57  *   A   B   C   D <-- netpoints
58  * \endverbatim
59  *
60  *  In this case, a communication from A to B goes through the links: <tt> l0, backbone, l1. </tt>
61  *  Note that the backbone only appears once in the link list.
62  */
63 class StarZone : public ClusterZone { // implements the old ClusterZone
64 public:
65   explicit StarZone(const std::string& name);
66
67   void get_local_route(const NetPoint* src, const NetPoint* dst, Route* route, double* latency) override;
68   void get_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) override;
70
71   void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
72                  const std::vector<s4u::LinkInRoute>& link_list, bool symmetrical) override;
73   void do_seal() override;
74
75 private:
76   class StarRoute {
77   public:
78     std::vector<resource::StandardLinkImpl*> links_up;   //!< list of links UP for route (can be empty)
79     std::vector<resource::StandardLinkImpl*> links_down; //!< list of links DOWN for route (can be empty)
80     std::vector<resource::StandardLinkImpl*> loopback;   //!< loopback links, cannot be empty if configured
81     bool links_up_set   = false;                 //!< bool to indicate that links_up was configured (empty or not)
82     bool links_down_set = false;                 //!< same for links_down
83     NetPoint* gateway   = nullptr;
84     bool has_loopback() const { return not loopback.empty(); }
85     bool has_links_up() const { return links_up_set; }
86     bool has_links_down() const { return links_down_set; }
87   };
88   /** @brief Auxiliary method to add links to a route */
89   void add_links_to_route(const std::vector<resource::StandardLinkImpl*>& links, Route* route, double* latency,
90                           std::unordered_set<resource::StandardLinkImpl*>& added_links) const;
91   /** @brief Auxiliary methods to check params received in add_route method */
92   void check_add_route_param(const NetPoint* src, const NetPoint* dst, const NetPoint* gw_src, const NetPoint* gw_dst,
93                              bool symmetrical) const;
94   std::unordered_map<unsigned long, StarRoute> routes_;
95 };
96 } // namespace routing
97 } // namespace kernel
98 } // namespace simgrid
99
100 #endif /* SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ */