Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use transparent comparator 'std::less<>' with associative string container (sonar).
[simgrid.git] / include / simgrid / s4u / NetZone.hpp
1 /* Copyright (c) 2016-2020. 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 protected:
30   friend kernel::routing::NetZoneImpl;
31
32   explicit NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
33
34 public:
35   /** @brief Retrieves the name of that netzone as a C++ string */
36   const std::string& get_name() const;
37   /** @brief Retrieves the name of that netzone as a C string */
38   const char* get_cname() const;
39
40   NetZone* get_father();
41
42   std::vector<Host*> get_all_hosts() const;
43   int get_host_count() const;
44
45   kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
46
47 private:
48   kernel::routing::NetZoneImpl* const pimpl_;
49
50 public:
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   void extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
59                          std::map<std::string, xbt_edge_t, std::less<>>* edges);
60
61   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
62   int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
63   void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
64                  kernel::routing::NetPoint* gw_dst, std::vector<kernel::resource::LinkImpl*>& link_list,
65                  bool symmetrical);
66   void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
67                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
68                         std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
69
70   /*** Called on each newly created regular route (not on bypass routes) */
71   static xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
72                           kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
73                           std::vector<kernel::resource::LinkImpl*> const& link_list)>
74       on_route_creation;
75   static xbt::signal<void(NetZone const&)> on_creation;
76   static xbt::signal<void(NetZone const&)> on_seal;
77 };
78
79 } // namespace s4u
80 } // namespace simgrid
81
82 #endif /* SIMGRID_S4U_NETZONE_HPP */