Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d8e242b71883482ef28cdddc420eafbde7937af4
[simgrid.git] / include / simgrid / s4u / NetZone.hpp
1 /* Copyright (c) 2016-2018. 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/signal.hpp>
11
12 #include <string>
13 #include <unordered_map>
14 #include <utility>
15 #include <vector>
16
17 namespace simgrid {
18 namespace s4u {
19
20 /** @brief Networking Zones
21  *
22  * A netzone is a network container, in charge of routing information between elements (hosts) and to the nearby
23  * netzones. In SimGrid, there is a hierarchy of netzones, with a unique root zone (that you can retrieve from the
24  * s4u::Engine).
25  */
26 class XBT_PUBLIC NetZone {
27 protected:
28   friend simgrid::kernel::routing::NetZoneImpl;
29
30   explicit NetZone(NetZone * father, std::string name);
31   virtual ~NetZone();
32
33 public:
34   /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
35   virtual void seal();
36   /** @brief Retrieves the name of that netzone as a C++ string */
37   const std::string& get_name() const { return name_; }
38   /** @brief Retrieves the name of that netzone as a C string */
39   const char* get_cname() const;
40   NetZone* get_father();
41
42   std::vector<NetZone*>* getChildren();             // Sub netzones
43   void getHosts(std::vector<s4u::Host*> * whereto); // retrieve my content as a vector of hosts
44   int getHostCount();
45
46 private:
47   std::unordered_map<std::string, std::string> properties_;
48
49 public:
50   /** Get the properties assigned to a host */
51   std::unordered_map<std::string, std::string>* getProperties();
52
53   /** Retrieve the property value (or nullptr if not set) */
54   const char* get_property(const char* key);
55   void set_property(const char* key, const char* value);
56
57   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
58   virtual int addComponent(kernel::routing::NetPoint * elm); /* A host, a router or a netzone, whatever */
59   virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
60                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
61                          std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
62   virtual void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
63                                 kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
64                                 std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical) = 0;
65
66   /*** Called on each newly created regular route (not on bypass routes) */
67   static simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
68                                    kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
69                                    std::vector<kernel::resource::LinkImpl*>& link_list)>
70       on_route_creation;
71   static simgrid::xbt::signal<void(NetZone&)> on_creation;
72   static simgrid::xbt::signal<void(NetZone&)> on_seal;
73
74   // Deprecation wrappers
75   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); }
76   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); }
77   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_cname()") const char* getCname() const { return get_cname(); }
78   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_route()") void addRoute(
79       kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
80       kernel::routing::NetPoint* gw_dst, std::vector<simgrid::kernel::resource::LinkImpl*>& link_list, bool symmetrical)
81   {
82     add_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
83   }
84   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_bypass_route()") void addBypassRoute(
85       kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
86       kernel::routing::NetPoint* gw_dst, std::vector<simgrid::kernel::resource::LinkImpl*>& link_list, bool symmetrical)
87   {
88     add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
89   }
90   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_property()") const char* getProperty(const char* key)
91   {
92     return get_property(key);
93   }
94   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::set_property()") void setProperty(const char* key, const char* value)
95   {
96     set_property(key, value);
97   }
98
99 private:
100   // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
101   std::vector<kernel::routing::NetPoint*> vertices_;
102
103 protected:
104   unsigned int get_table_size() { return vertices_.size(); }
105   std::vector<kernel::routing::NetPoint*> getVertices() { return vertices_; }
106
107 private:
108   NetZone* father_ = nullptr;
109   std::string name_;
110
111   bool sealed_ = false; // We cannot add more content when sealed
112
113   std::vector<NetZone*>* children_ = nullptr; // sub-netzones
114 };
115 }
116 }; // Namespace simgrid::s4u
117
118 #endif /* SIMGRID_S4U_NETZONE_HPP */