1 /* Copyright (c) 2013-2021. 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/NetZoneImpl.hpp>
11 #include <unordered_map>
12 #include <unordered_set>
18 /** @ingroup ROUTING_API
19 * @brief NetZone where components are connected following a star topology
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.
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.
30 * @note: Communications between nodes inside the Star zone cannot have duplicate links.
31 * All duplicated links are automatically removed when building the route.
44 * So, a communication from the host A to the host B goes through the following links:
45 * <tt>l0, l3, l1.</tt>
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>
53 * ======+====== <-- backbone
55 * l0| l1| l2| l4| <-- links
57 * A B C D <-- netpoints
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.
64 class StarZone : public NetZoneImpl {
66 explicit StarZone(const std::string& name);
68 void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* 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;
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;
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; }
89 /** @brief Auxiliary method to add links to a route */
90 void add_links_to_route(const std::vector<resource::LinkImpl*>& links, RouteCreationArgs* 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_;
97 } // namespace routing
99 } // namespace simgrid
101 #endif /* SIMGRID_KERNEL_ROUTING_STARZONE_HPP_ */