Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
NetZone: father to parent and more accessors
[simgrid.git] / include / simgrid / s4u / NetZone.hpp
1 /* Copyright (c) 2016-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_S4U_NETZONE_HPP
7 #define SIMGRID_S4U_NETZONE_HPP
8
9 #include <simgrid/forward.h>
10 #include <xbt/graph.h>
11 #include <xbt/signal.hpp>
12
13 #include <map>
14 #include <string>
15 #include <unordered_map>
16 #include <utility>
17 #include <vector>
18
19 namespace simgrid {
20 namespace s4u {
21
22 /** @brief Networking Zones
23  *
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
26  * s4u::Engine).
27  */
28 class XBT_PUBLIC NetZone {
29   kernel::routing::NetZoneImpl* const pimpl_;
30
31 protected:
32   friend kernel::routing::NetZoneImpl;
33
34   explicit NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
35
36 public:
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;
41
42   XBT_ATTRIB_DEPRECATED_v331("Please use get_parent()") NetZone* get_father();
43   NetZone* get_parent() const;
44   NetZone* set_parent(NetZone* parent);
45
46   std::vector<Host*> get_all_hosts() const;
47   int get_host_count() const;
48
49   kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
50
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);
56
57   std::vector<NetZone*> get_children() const;
58   NetZone* add_child(NetZone* new_zone);
59
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);
62
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,
67                  bool symmetrical);
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);
71
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)>
76       on_route_creation;
77   static xbt::signal<void(NetZone const&)> on_creation;
78   static xbt::signal<void(NetZone const&)> on_seal;
79 };
80
81 } // namespace s4u
82 } // namespace simgrid
83
84 #endif /* SIMGRID_S4U_NETZONE_HPP */