1 /* Copyright (c) 2016-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_S4U_NETZONE_HPP
7 #define SIMGRID_S4U_NETZONE_HPP
9 #include <simgrid/forward.h>
10 #include <xbt/graph.h>
11 #include <xbt/signal.hpp>
15 #include <unordered_map>
22 /** @brief Networking Zones
24 * A netzone is a network container, in charge of routing information between elements (hosts) and to the nearby
25 * netzones. In SimGrid, there is a hierarchy of netzones, with a unique root zone (that you can retrieve from the
28 class XBT_PUBLIC NetZone {
29 kernel::routing::NetZoneImpl* const pimpl_;
32 friend kernel::routing::NetZoneImpl;
34 explicit NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
37 /** @brief Retrieves the name of that netzone as a C++ string */
38 const std::string& get_name() const;
39 /** @brief Retrieves the name of that netzone as a C string */
40 const char* get_cname() const;
42 XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZone* get_father();
43 NetZone* get_parent() const;
44 NetZone* set_parent(const NetZone* parent);
46 std::vector<Host*> get_all_hosts() const;
47 int get_host_count() const;
49 kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
51 /** Get the properties assigned to a netzone */
52 const std::unordered_map<std::string, std::string>* get_properties() const;
53 /** Retrieve the property value (or nullptr if not set) */
54 const char* get_property(const std::string& key) const;
55 void set_property(const std::string& key, const std::string& value);
57 std::vector<NetZone*> get_children() const;
58 NetZone* add_child(const NetZone* new_zone);
60 void extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
61 std::map<std::string, xbt_edge_t, std::less<>>* edges);
63 /* Add content to the netzone, at parsing time. It should be sealed afterward. */
64 int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
65 void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
66 kernel::routing::NetPoint* gw_dst, std::vector<kernel::resource::LinkImpl*>& link_list,
68 void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
69 kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
70 std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
72 /*** Called on each newly created regular route (not on bypass routes) */
73 static xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
74 kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
75 std::vector<kernel::resource::LinkImpl*> const& link_list)>
77 static xbt::signal<void(NetZone const&)> on_creation;
78 static xbt::signal<void(NetZone const&)> on_seal;
81 * @brief Create a Host
83 * @param name Host name
84 * @param speed_per_state Vector of CPU's speeds
86 s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
87 /** @brief Create a Host (string version) */
88 s4u::Host* create_host(const std::string& name, const std::vector<std::string>& speed_per_pstate);
91 // External constructors so that the types (and the types of their content) remain hidden
92 XBT_PUBLIC NetZone* createFullZone(const std::string& name);
93 XBT_PUBLIC NetZone* createClusterZone(const std::string& name);
94 XBT_PUBLIC NetZone* createDijkstraZone(const std::string& name, bool cache);
95 XBT_PUBLIC NetZone* createDragonflyZone(const std::string& name);
96 XBT_PUBLIC NetZone* createEmptyZone(const std::string& name);
97 XBT_PUBLIC NetZone* createFatTreeZone(const std::string& name);
98 XBT_PUBLIC NetZone* createFloydZone(const std::string& name);
99 XBT_PUBLIC NetZone* createTorusZone(const std::string& name);
100 XBT_PUBLIC NetZone* createVivaldiZone(const std::string& name);
101 XBT_PUBLIC NetZone* createWifiZone(const std::string& name);
104 } // namespace simgrid
106 #endif /* SIMGRID_S4U_NETZONE_HPP */