1 /* Copyright (c) 2013-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
7 #define SIMGRID_KERNEL_ROUTING_STARZONE_HPP_
9 #include <simgrid/kernel/routing/ClusterZone.hpp>
11 #include <unordered_map>
12 #include <unordered_set>
14 namespace simgrid::kernel::routing {
16 /** @ingroup ROUTING_API
17 * @brief NetZone where components are connected following a star topology
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.
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.
28 * @note: Communications between nodes inside the Star zone cannot have duplicate links.
29 * All duplicated links are automatically removed when building the route.
42 * So, a communication from the host A to the host B goes through the following links:
43 * <tt>l0, l3, l1.</tt>
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>
51 * ======+====== <-- backbone
53 * l0| l1| l2| l4| <-- links
55 * A B C D <-- netpoints
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.
61 class StarZone : public ClusterZone { // implements the old ClusterZone
63 explicit StarZone(const std::string& name);
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;
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;
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; }
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_;
94 } // namespace simgrid::kernel::routing
96 #endif /* SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ */