Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
do not use RouteCreationArgs outside of XML parsing
[simgrid.git] / include / simgrid / kernel / routing / StarZone.hpp
1 /* Copyright (c) 2013-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_KERNEL_ROUTING_STARZONE_HPP_
7 #define SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
8
9 #include <simgrid/kernel/routing/NetZoneImpl.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
64 class StarZone : public NetZoneImpl {
65 public:
66   explicit StarZone(const std::string& name);
67
68   void get_local_route(NetPoint* src, NetPoint* dst, Route* route, double* latency) override;
69   void get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
70                  std::map<std::string, xbt_edge_t, std::less<>>* edges) override;
71
72   void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
73                  const std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical) override;
74   void do_seal() override;
75
76 private:
77   class StarRoute {
78   public:
79     std::vector<resource::LinkImpl*> links_up;   //!< list of links UP for route (can be empty)
80     std::vector<resource::LinkImpl*> links_down; //!< list of links DOWN for route (can be empty)
81     std::vector<resource::LinkImpl*> loopback;   //!< loopback links, cannot be empty if configured
82     bool links_up_set   = false;                 //!< bool to indicate that links_up was configured (empty or not)
83     bool links_down_set = false;                 //!< same for links_down
84     NetPoint* gateway   = nullptr;
85     bool has_loopback() const { return not loopback.empty(); }
86     bool has_links_up() const { return links_up_set; }
87     bool has_links_down() const { return links_down_set; }
88   };
89   /** @brief Auxiliary method to add links to a route */
90   void add_links_to_route(const std::vector<resource::LinkImpl*>& links, Route* route, double* latency,
91                           std::unordered_set<resource::LinkImpl*>& added_links) const;
92   /** @brief Auxiliary methods to check params received in add_route method */
93   void check_add_route_param(const NetPoint* src, const NetPoint* dst, const NetPoint* gw_src, const NetPoint* gw_dst,
94                              bool symmetrical) const;
95   std::unordered_map<unsigned int, StarRoute> routes_;
96 };
97 } // namespace routing
98 } // namespace kernel
99 } // namespace simgrid
100
101 #endif /* SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ */