Logo AND Algorithmique Numérique Distribuée

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