From: Martin Quinson Date: Sat, 23 Jun 2018 18:52:13 +0000 (+0200) Subject: split NetZone and NetZoneImpl as it should in s4u realm X-Git-Tag: v3.20~6 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/da23351cb44bc018edc2c181b90bcdb7083b061c split NetZone and NetZoneImpl as it should in s4u realm --- diff --git a/include/simgrid/kernel/routing/ClusterZone.hpp b/include/simgrid/kernel/routing/ClusterZone.hpp index cb1d330b45..c3135dcc6c 100644 --- a/include/simgrid/kernel/routing/ClusterZone.hpp +++ b/include/simgrid/kernel/routing/ClusterZone.hpp @@ -67,7 +67,7 @@ namespace routing { class ClusterZone : public NetZoneImpl { public: - explicit ClusterZone(NetZone* father, std::string name); + explicit ClusterZone(NetZoneImpl* father, std::string name); void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; void get_graph(xbt_graph_t graph, std::map* nodes, diff --git a/include/simgrid/kernel/routing/DijkstraZone.hpp b/include/simgrid/kernel/routing/DijkstraZone.hpp index bf7fe7670d..c4354636b0 100644 --- a/include/simgrid/kernel/routing/DijkstraZone.hpp +++ b/include/simgrid/kernel/routing/DijkstraZone.hpp @@ -33,7 +33,7 @@ namespace routing { */ class XBT_PRIVATE DijkstraZone : public RoutedZone { public: - DijkstraZone(NetZone* father, std::string name, bool cached); + DijkstraZone(NetZoneImpl* father, std::string name, bool cached); void seal() override; ~DijkstraZone() override; diff --git a/include/simgrid/kernel/routing/DragonflyZone.hpp b/include/simgrid/kernel/routing/DragonflyZone.hpp index 193f10946b..c300f7a295 100644 --- a/include/simgrid/kernel/routing/DragonflyZone.hpp +++ b/include/simgrid/kernel/routing/DragonflyZone.hpp @@ -61,7 +61,7 @@ public: */ class XBT_PUBLIC DragonflyZone : public ClusterZone { public: - explicit DragonflyZone(NetZone* father, std::string name); + explicit DragonflyZone(NetZoneImpl* father, std::string name); ~DragonflyZone() override; // void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; diff --git a/include/simgrid/kernel/routing/EmptyZone.hpp b/include/simgrid/kernel/routing/EmptyZone.hpp index 421e552772..b015de01b9 100644 --- a/include/simgrid/kernel/routing/EmptyZone.hpp +++ b/include/simgrid/kernel/routing/EmptyZone.hpp @@ -21,7 +21,7 @@ namespace routing { class XBT_PRIVATE EmptyZone : public NetZoneImpl { public: - explicit EmptyZone(NetZone* father, std::string name); + explicit EmptyZone(NetZoneImpl* father, std::string name); ~EmptyZone() override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override diff --git a/include/simgrid/kernel/routing/FatTreeZone.hpp b/include/simgrid/kernel/routing/FatTreeZone.hpp index 7fbf25f6e2..e39ef330bc 100644 --- a/include/simgrid/kernel/routing/FatTreeZone.hpp +++ b/include/simgrid/kernel/routing/FatTreeZone.hpp @@ -98,7 +98,7 @@ public: */ class XBT_PRIVATE FatTreeZone : public ClusterZone { public: - explicit FatTreeZone(NetZone* father, std::string name); + explicit FatTreeZone(NetZoneImpl* father, std::string name); ~FatTreeZone() override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; diff --git a/include/simgrid/kernel/routing/FloydZone.hpp b/include/simgrid/kernel/routing/FloydZone.hpp index 92fe57f9a1..172c694872 100644 --- a/include/simgrid/kernel/routing/FloydZone.hpp +++ b/include/simgrid/kernel/routing/FloydZone.hpp @@ -23,7 +23,7 @@ namespace routing { */ class XBT_PRIVATE FloydZone : public RoutedZone { public: - explicit FloydZone(NetZone* father, std::string name); + explicit FloydZone(NetZoneImpl* father, std::string name); ~FloydZone() override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; diff --git a/include/simgrid/kernel/routing/FullZone.hpp b/include/simgrid/kernel/routing/FullZone.hpp index 99722a1afa..bbf16f6b43 100644 --- a/include/simgrid/kernel/routing/FullZone.hpp +++ b/include/simgrid/kernel/routing/FullZone.hpp @@ -20,7 +20,7 @@ namespace routing { */ class XBT_PRIVATE FullZone : public RoutedZone { public: - explicit FullZone(NetZone* father, std::string name); + explicit FullZone(NetZoneImpl* father, std::string name); void seal() override; ~FullZone() override; diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index fd6aff2596..39d737c36e 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -11,6 +11,7 @@ #include #include +#include namespace simgrid { namespace kernel { @@ -46,20 +47,31 @@ class BypassRoute; * called Autonomous Systems in this article). * */ -class XBT_PUBLIC NetZoneImpl : public s4u::NetZone { +class XBT_PUBLIC NetZoneImpl { friend simgrid::kernel::EngineImpl; // it destroys netRoot_ protected: - explicit NetZoneImpl(NetZone* father, std::string name); + explicit NetZoneImpl(NetZoneImpl* father, std::string name); virtual ~NetZoneImpl(); + s4u::NetZone piface_; + public: + s4u::NetZone* get_iface() { return &piface_; } + /** @brief Make an host within that NetZone */ simgrid::s4u::Host* create_host(const char* name, std::vector* speed_per_pstate, int core_count, std::map* props); /** @brief Creates a new route in this NetZone */ - void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, - std::vector& link_list, bool symmetrical) override; + virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, + std::vector& link_list, bool symmetrical); + + /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */ + virtual void seal(); + virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ + virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, + kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, + std::vector& link_list, bool symmetrical); protected: /** @@ -76,7 +88,35 @@ protected: bool get_bypass_route(routing::NetPoint* src, routing::NetPoint* dst, /* OUT */ std::vector& links, double* latency); +private: + // our content, as known to our graph routing algorithm (maps vertex_id -> vertex) + std::vector vertices_; + + NetZoneImpl* father_ = nullptr; + + std::vector children_; // sub-netzones + public: + unsigned int get_table_size() { return vertices_.size(); } + std::vector get_vertices() { return vertices_; } + + NetZoneImpl* get_father(); + + std::vector* get_children(); // Sub netzones + +private: + std::string name_; + bool sealed_ = false; // We cannot add more content when sealed + +public: + /** @brief Retrieves the name of that netzone as a C++ string */ + const std::string& get_name() const { return name_; } + /** @brief Retrieves the name of that netzone as a C string */ + const char* get_cname() const; + + std::vector get_all_hosts(); + int get_host_count(); + /* @brief get the route between two nodes in the full platform * * @param src where from diff --git a/include/simgrid/kernel/routing/RoutedZone.hpp b/include/simgrid/kernel/routing/RoutedZone.hpp index 097e849207..0d1937787c 100644 --- a/include/simgrid/kernel/routing/RoutedZone.hpp +++ b/include/simgrid/kernel/routing/RoutedZone.hpp @@ -50,7 +50,7 @@ namespace routing { class XBT_PRIVATE RoutedZone : public NetZoneImpl { public: - explicit RoutedZone(NetZone* father, std::string name); + explicit RoutedZone(NetZoneImpl* father, std::string name); void get_graph(xbt_graph_t graph, std::map* nodes, std::map* edges) override; diff --git a/include/simgrid/kernel/routing/TorusZone.hpp b/include/simgrid/kernel/routing/TorusZone.hpp index 22a172e655..29e9855818 100644 --- a/include/simgrid/kernel/routing/TorusZone.hpp +++ b/include/simgrid/kernel/routing/TorusZone.hpp @@ -21,7 +21,7 @@ namespace routing { class XBT_PRIVATE TorusZone : public ClusterZone { public: - explicit TorusZone(NetZone* father, std::string name); + explicit TorusZone(NetZoneImpl* father, std::string name); void create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position) override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; void parse_specific_arguments(ClusterCreationArgs* cluster) override; diff --git a/include/simgrid/kernel/routing/VivaldiZone.hpp b/include/simgrid/kernel/routing/VivaldiZone.hpp index d1bc241494..873eddd24c 100644 --- a/include/simgrid/kernel/routing/VivaldiZone.hpp +++ b/include/simgrid/kernel/routing/VivaldiZone.hpp @@ -46,7 +46,7 @@ namespace routing { class XBT_PRIVATE VivaldiZone : public ClusterZone { public: - explicit VivaldiZone(NetZone* father, std::string name); + explicit VivaldiZone(NetZoneImpl* father, std::string name); void set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, std::string coord); void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 7f9c0ef92d..d30bc2ffed 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -132,6 +132,8 @@ public: /** @brief Retrieves all netzones of the type indicated by the template argument */ template std::vector get_filtered_netzones() { + static_assert(std::is_base_of::value, + "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl"); std::vector res; get_filtered_netzones_recursive(get_netzone_root(), &res); return res; @@ -271,10 +273,12 @@ extern XBT_PUBLIC xbt::signal on_deadlock; template XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector* whereto) { - for (auto const& elem : *(current->get_children())) { + static_assert(std::is_base_of::value, + "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl"); + for (auto const& elem : current->get_children()) { get_filtered_netzones_recursive(elem, whereto); - if (elem == dynamic_cast(elem)) - whereto->push_back(dynamic_cast(elem)); + if (elem->get_impl() == dynamic_cast(elem->get_impl())) + whereto->push_back(dynamic_cast(elem->get_impl())); } } } diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 5229b92c44..f43ca18e33 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -27,23 +27,24 @@ class XBT_PUBLIC NetZone { protected: friend simgrid::kernel::routing::NetZoneImpl; - explicit NetZone(NetZone * father, std::string name); - virtual ~NetZone(); + explicit NetZone(kernel::routing::NetZoneImpl* impl); + ~NetZone(); + + kernel::routing::NetZoneImpl* pimpl_; public: - /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */ - virtual void seal(); /** @brief Retrieves the name of that netzone as a C++ string */ - const std::string& get_name() const { return name_; } + const std::string& get_name() const; /** @brief Retrieves the name of that netzone as a C string */ const char* get_cname() const; NetZone* get_father(); - std::vector* get_children(); // Sub netzones std::vector get_all_hosts(); int get_host_count(); + kernel::routing::NetZoneImpl* get_impl() { return pimpl_; } + private: std::unordered_map properties_; @@ -51,18 +52,20 @@ public: /** Get the properties assigned to a netzone */ std::unordered_map* get_properties(); + std::vector get_children(); + /** Retrieve the property value (or nullptr if not set) */ const char* get_property(const char* key); void set_property(const char* key, const char* value); /* Add content to the netzone, at parsing time. It should be sealed afterward. */ - virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ - virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, - kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, - std::vector& link_list, bool symmetrical); - virtual void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, - kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, - std::vector& link_list, bool symmetrical) = 0; + int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ + void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src, + kernel::routing::NetPoint* gw_dst, std::vector& link_list, + bool symmetrical); + void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, + kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, + std::vector& link_list, bool symmetrical); /*** Called on each newly created regular route (not on bypass routes) */ static simgrid::xbt::signal on_creation; static simgrid::xbt::signal on_seal; -private: - // our content, as known to our graph routing algorithm (maps vertex_id -> vertex) - std::vector vertices_; - -protected: - unsigned int get_table_size() { return vertices_.size(); } - std::vector get_vertices() { return vertices_; } - -private: - NetZone* father_ = nullptr; - std::string name_; - - bool sealed_ = false; // We cannot add more content when sealed - - std::vector* children_ = nullptr; // sub-netzones - public: // Deprecation wrappers XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); } XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); } @@ -116,21 +103,20 @@ public: // Deprecation wrappers { set_property(key, value); } - XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") virtual int addComponent( - kernel::routing::NetPoint* elm) + XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") int addComponent(kernel::routing::NetPoint* elm) { return add_component(elm); } - XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector getVertices() - { - return get_vertices(); - } + XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector getVertices(); XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_host_count()") int getHostCount() { return get_host_count(); } XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_all_hosts()") void getHosts( std::vector* whereto); // retrieve my content as a vector of hosts XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_children()") std::vector* getChildren() { - return get_children(); + std::vector* res = new std::vector(); + for (auto child : get_children()) + res->push_back(child); + return res; } }; } diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index 2e08d3b20a..0d4d89fc59 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -69,14 +69,14 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, job if (not cls) return nullptr; - jtable = env->NewObjectArray(static_cast(self_as->get_children()->size()), cls, nullptr); + jtable = env->NewObjectArray(static_cast(self_as->get_children().size()), cls, nullptr); if (not jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); return nullptr; } - for (auto const& tmp_as : *self_as->get_children()) { + for (auto const& tmp_as : self_as->get_children()) { jobject tmp_jas = jnetzone_new_instance(env); if (not tmp_jas) { jxbt_throw_jni(env, "java As instantiation failed"); diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index dac0399226..1b8431dce1 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -476,12 +476,12 @@ int console_AS_open(lua_State *L) { simgrid::kernel::routing::ZoneCreationArgs AS; AS.id = id; AS.routing = mode_int; - simgrid::s4u::NetZone* new_as = sg_platf_new_Zone_begin(&AS); + simgrid::kernel::routing::NetZoneImpl* new_as = sg_platf_new_Zone_begin(&AS); /* Build a Lua representation of the new AS on the stack */ lua_newtable(L); - simgrid::s4u::NetZone** lua_as = - (simgrid::s4u::NetZone**)lua_newuserdata(L, sizeof(simgrid::s4u::NetZone*)); /* table userdatum */ + simgrid::kernel::routing::NetZoneImpl** lua_as = (simgrid::kernel::routing::NetZoneImpl**)lua_newuserdata( + L, sizeof(simgrid::kernel::routing::NetZoneImpl*)); /* table userdatum */ *lua_as = new_as; luaL_getmetatable(L, PLATF_MODULE_NAME); /* table userdatum metatable */ lua_setmetatable(L, -2); /* table userdatum */ diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 0184c25331..ec0639d4a6 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -127,9 +127,9 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t return; } XBT_DEBUG("Graph extraction for NetZone = %s", netzone->get_cname()); - if (not netzone->get_children()->empty()) { + if (not netzone->get_children().empty()) { // bottom-up recursion - for (auto const& nz_son : *netzone->get_children()) { + for (auto const& nz_son : netzone->get_children()) { container_t child_container = container->children_.at(nz_son->get_cname()); recursiveGraphExtraction(nz_son, child_container, filter); } @@ -139,7 +139,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t std::map* nodes = new std::map; std::map* edges = new std::map; - static_cast(netzone)->get_graph(graph, nodes, edges); + netzone->get_impl()->get_graph(graph, nodes, edges); for (auto elm : *edges) { xbt_edge_t edge = elm.second; linkContainers(simgrid::instr::Container::by_name(static_cast(edge->src->data)), @@ -466,15 +466,15 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map* edges, sg_netzone_t netzone, container_t container) { - if (not netzone->get_children()->empty()) { + if (not netzone->get_children().empty()) { // bottom-up recursion - for (auto const& netzone_child : *netzone->get_children()) { + for (auto const& netzone_child : netzone->get_children()) { container_t child_container = container->children_.at(netzone_child->get_cname()); recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child, child_container); } } - static_cast(netzone)->get_graph(graph, nodes, edges); + netzone->get_impl()->get_graph(graph, nodes, edges); } xbt_graph_t instr_routing_platform_graph() diff --git a/src/instr/jedule/jedule_platform.cpp b/src/instr/jedule/jedule_platform.cpp index 2b80a60011..9a02ccb3fa 100644 --- a/src/instr/jedule/jedule_platform.cpp +++ b/src/instr/jedule/jedule_platform.cpp @@ -64,13 +64,13 @@ void Container::add_resources(std::vector hosts) void Container::create_hierarchy(sg_netzone_t from_as) { - if (from_as->get_children()->empty()) { + if (from_as->get_children().empty()) { // I am no AS // add hosts to jedule platform std::vector table = from_as->get_all_hosts(); this->add_resources(table); } else { - for (auto const& nz : *from_as->get_children()) { + for (auto const& nz : from_as->get_children()) { jed_container_t child_container = new simgrid::jedule::Container(std::string(nz->get_cname())); this->add_child(child_container); child_container->create_hierarchy(nz); diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 3013d78454..500a1d1863 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -17,9 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf" namespace simgrid { namespace kernel { namespace routing { -ClusterZone::ClusterZone(NetZone* father, std::string name) : NetZoneImpl(father, name) -{ -} +ClusterZone::ClusterZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {} void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat) { diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index b5642e3075..1ce64e2d9e 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -266,7 +266,8 @@ DijkstraZone::~DijkstraZone() /* Creation routing model functions */ -DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name), cached_(cached) +DijkstraZone::DijkstraZone(NetZoneImpl* father, std::string name, bool cached) + : RoutedZone(father, name), cached_(cached) { } diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index 6d13fb294e..a5a268db4e 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -18,9 +18,7 @@ namespace simgrid { namespace kernel { namespace routing { -DragonflyZone::DragonflyZone(NetZone* father, std::string name) : ClusterZone(father, name) -{ -} +DragonflyZone::DragonflyZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {} DragonflyZone::~DragonflyZone() { diff --git a/src/kernel/routing/EmptyZone.cpp b/src/kernel/routing/EmptyZone.cpp index 78a1c677ff..a50a06c0d7 100644 --- a/src/kernel/routing/EmptyZone.cpp +++ b/src/kernel/routing/EmptyZone.cpp @@ -15,9 +15,7 @@ namespace simgrid { namespace kernel { namespace routing { -EmptyZone::EmptyZone(NetZone* father, std::string name) : NetZoneImpl(father, name) -{ -} +EmptyZone::EmptyZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {} EmptyZone::~EmptyZone() = default; diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index f32dc54238..917b40d00b 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -22,7 +22,7 @@ namespace simgrid { namespace kernel { namespace routing { -FatTreeZone::FatTreeZone(NetZone* father, std::string name) : ClusterZone(father, name) +FatTreeZone::FatTreeZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) { XBT_DEBUG("Creating a new fat tree."); } diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index 5286d2e31e..57e7ffd88e 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -22,7 +22,7 @@ namespace simgrid { namespace kernel { namespace routing { -FloydZone::FloydZone(NetZone* father, std::string name) : RoutedZone(father, name) +FloydZone::FloydZone(NetZoneImpl* father, std::string name) : RoutedZone(father, name) { predecessor_table_ = nullptr; cost_table_ = nullptr; diff --git a/src/kernel/routing/FullZone.cpp b/src/kernel/routing/FullZone.cpp index 77904a4a2b..765e13e839 100644 --- a/src/kernel/routing/FullZone.cpp +++ b/src/kernel/routing/FullZone.cpp @@ -16,9 +16,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf"); namespace simgrid { namespace kernel { namespace routing { -FullZone::FullZone(NetZone* father, std::string name) : RoutedZone(father, name) -{ -} +FullZone::FullZone(NetZoneImpl* father, std::string name) : RoutedZone(father, name) {} void FullZone::seal() { diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index e19d3ce705..9f5d38a0d5 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -26,22 +26,70 @@ public: std::vector links; }; -NetZoneImpl::NetZoneImpl(NetZone* father, std::string name) : NetZone(father, name) +NetZoneImpl::NetZoneImpl(NetZoneImpl* father, std::string name) : piface_(this), father_(father), name_(name) { xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name.c_str()), "Refusing to create a second NetZone called '%s'.", name.c_str()); - netpoint_ = new NetPoint(name, NetPoint::Type::NetZone, static_cast(father)); + netpoint_ = new NetPoint(name, NetPoint::Type::NetZone, father); XBT_DEBUG("NetZone '%s' created with the id '%u'", name.c_str(), netpoint_->id()); } NetZoneImpl::~NetZoneImpl() { + for (auto const& nz : children_) + delete nz; + for (auto const& kv : bypass_routes_) delete kv.second; simgrid::s4u::Engine::get_instance()->netpoint_unregister(netpoint_); } +const char* NetZoneImpl::get_cname() const +{ + return name_.c_str(); +} +NetZoneImpl* NetZoneImpl::get_father() +{ + return father_; +} +void NetZoneImpl::seal() +{ + sealed_ = true; +} +/** @brief Returns the list of direct children (no grand-children) + * + * This returns the internal data, no copy. Don't mess with it. + */ +std::vector* NetZoneImpl::get_children() +{ + return &children_; +} +/** @brief Returns the list of the hosts found in this NetZone (not recursively) + * + * Only the hosts that are directly contained in this NetZone are retrieved, + * not the ones contained in sub-netzones. + */ +std::vector NetZoneImpl::get_all_hosts() +{ + std::vector res; + for (auto const& card : get_vertices()) { + s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); + if (host != nullptr) + res.push_back(host); + } + return res; +} +int NetZoneImpl::get_host_count() +{ + int count = 0; + for (auto const& card : get_vertices()) { + s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); + if (host != nullptr) + count++; + } + return count; +} simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, std::vector* speedPerPstate, int coreAmount, std::map* props) @@ -64,6 +112,18 @@ simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, std::vector& /*link_list*/, bool /*symmetrical*/) +{ + xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str()); +} + void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, std::vector& link_list, bool symmetrical) { @@ -230,7 +290,7 @@ bool NetZoneImpl::get_bypass_route(routing::NetPoint* src, routing::NetPoint* ds /* (1) find the path to the root routing component */ std::vector path_src; - NetZone* current = src->get_englobing_zone(); + NetZoneImpl* current = src->get_englobing_zone(); while (current != nullptr) { path_src.push_back(static_cast(current)); current = current->father_; diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index dc502fd548..1a2058b83b 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -59,9 +59,7 @@ namespace simgrid { namespace kernel { namespace routing { -RoutedZone::RoutedZone(NetZone* father, std::string name) : NetZoneImpl(father, name) -{ -} +RoutedZone::RoutedZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {} void RoutedZone::get_graph(xbt_graph_t graph, std::map* nodes, std::map* edges) @@ -152,8 +150,8 @@ void RoutedZone::get_route_check_params(NetPoint* src, NetPoint* dst) xbt_assert(src, "Cannot find a route from nullptr to %s", dst->get_cname()); xbt_assert(dst, "Cannot find a route from %s to nullptr", src->get_cname()); - NetZone* src_as = src->get_englobing_zone(); - NetZone* dst_as = dst->get_englobing_zone(); + NetZoneImpl* src_as = src->get_englobing_zone(); + NetZoneImpl* dst_as = dst->get_englobing_zone(); xbt_assert(src_as == dst_as, "Internal error: %s@%s and %s@%s are not in the same netzone as expected. Please report that bug.", @@ -201,7 +199,7 @@ void RoutedZone::add_route_check_params(NetPoint* src, NetPoint* dst, NetPoint* dstName, gw_dst->get_cname()); } - on_route_creation(symmetrical, src, dst, gw_src, gw_dst, link_list); + piface_.on_route_creation(symmetrical, src, dst, gw_src, gw_dst, link_list); } } } diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 56896c65ab..7955bd16fd 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -29,9 +29,7 @@ inline void rankId_to_coords(int rankId, std::vector dimensions, u namespace simgrid { namespace kernel { namespace routing { -TorusZone::TorusZone(NetZone* father, std::string name) : ClusterZone(father, name) -{ -} +TorusZone::TorusZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {} void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position) { diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index 8bc5201ad1..cac8eb5212 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -59,9 +59,7 @@ static std::vector* netpoint_get_coords(NetPoint* np) return &coords->coords; } -VivaldiZone::VivaldiZone(NetZone* father, std::string name) : ClusterZone(father, name) -{ -} +VivaldiZone::VivaldiZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {} void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, std::string coord) { diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 330b7ea38f..e4372120df 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -263,13 +263,13 @@ void Engine::run() /** @brief Retrieve the root netzone, containing all others */ s4u::NetZone* Engine::get_netzone_root() { - return pimpl->netzone_root_; + return pimpl->netzone_root_->get_iface(); } /** @brief Set the root netzone, containing all others. Once set, it cannot be changed. */ void Engine::set_netzone_root(s4u::NetZone* netzone) { xbt_assert(pimpl->netzone_root_ == nullptr, "The root NetZone cannot be changed once set"); - pimpl->netzone_root_ = static_cast(netzone); + pimpl->netzone_root_ = netzone->get_impl(); } static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name) @@ -277,7 +277,7 @@ static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char if (not strcmp(current->get_cname(), name)) return current; - for (auto const& elem : *(current->get_children())) { + for (auto const& elem : current->get_children()) { simgrid::s4u::NetZone* tmp = netzone_by_name_recursive(elem, name); if (tmp != nullptr) { return tmp; diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index d361ce0b65..c9dc1bd922 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -21,21 +21,10 @@ simgrid::xbt::signal NetZone::on_creation; simgrid::xbt::signal NetZone::on_seal; -NetZone::NetZone(NetZone* father, std::string name) : father_(father), name_(name) -{ - children_ = new std::vector(); -} - -void NetZone::seal() -{ - sealed_ = true; -} +NetZone::NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {} NetZone::~NetZone() { - for (auto const& nz : *children_) - delete nz; - delete children_; } std::unordered_map* NetZone::get_properties() @@ -53,22 +42,26 @@ void NetZone::set_property(const char* key, const char* value) simgrid::simix::simcall([this, key, value] { properties_[key] = value; }); } -/** @brief Returns the list of direct children (no grand-children) - * - * This function returns the internal copy of the children, not a copy. Don't mess with it! - */ -std::vector* NetZone::get_children() +/** @brief Returns the list of direct children (no grand-children) */ +std::vector NetZone::get_children() { - return children_; + std::vector res; + for (auto child : *(pimpl_->get_children())) + res.push_back(child->get_iface()); + return res; } +const std::string& NetZone::get_name() const +{ + return pimpl_->get_name(); +} const char* NetZone::get_cname() const { - return name_.c_str(); + return pimpl_->get_cname(); } NetZone* NetZone::get_father() { - return father_; + return pimpl_->get_father()->get_iface(); } /** @brief Returns the list of the hosts found in this NetZone (not recursively) @@ -78,18 +71,12 @@ NetZone* NetZone::get_father() */ std::vector NetZone::get_all_hosts() { - std::vector res; - for (auto const& card : vertices_) { - s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); - if (host != nullptr) - res.push_back(host); - } - return res; + return pimpl_->get_all_hosts(); } void NetZone::getHosts(std::vector* whereto) { - for (auto const& card : vertices_) { + for (auto const& card : pimpl_->get_vertices()) { s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); if (host != nullptr) whereto->push_back(host); @@ -98,28 +85,30 @@ void NetZone::getHosts(std::vector* whereto) int NetZone::get_host_count() { - int count = 0; - for (auto const& card : vertices_) { - s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); - if (host != nullptr) - count++; - } - return count; + return pimpl_->get_host_count(); } int NetZone::add_component(kernel::routing::NetPoint* elm) { - vertices_.push_back(elm); - return vertices_.size() - 1; // The rank of the newly created object + return pimpl_->add_component(elm); } -void NetZone::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::NetPoint* /*dst*/, - kernel::routing::NetPoint* /*gw_src*/, kernel::routing::NetPoint* /*gw_dst*/, - std::vector& /*link_list*/, bool /*symmetrical*/) +void NetZone::add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, + kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, + std::vector& link_list, bool symmetrical) { - xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str()); + pimpl_->add_route(src, dst, gw_src, gw_dst, link_list, symmetrical); +} +void NetZone::add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, + kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, + std::vector& link_list, bool symmetrical) +{ + pimpl_->add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical); +} +std::vector NetZone::getVertices() +{ + return pimpl_->get_vertices(); } - } // namespace s4u } // namespace simgrid @@ -142,7 +131,7 @@ sg_netzone_t sg_zone_get_by_name(const char* name) void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto) { - for (auto const& elem : *netzone->get_children()) { + for (auto const& elem : netzone->get_children()) { xbt_dict_set(whereto, elem->get_cname(), static_cast(elem), nullptr); } } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index f2a59719f3..f521fd9250 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -542,7 +542,7 @@ static void surf_config_models_setup() * * @param zone the parameters defining the Zone to build. */ -simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone) +simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone) { if (not surf_parse_models_setup_already_called) { simgrid::s4u::on_platform_creation(); @@ -600,18 +600,18 @@ simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCre } if (current_routing == nullptr) { /* it is the first one */ - simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone); + simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone->get_iface()); } else { /* set the father behavior */ if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive; /* add to the sons dictionary */ - current_routing->get_children()->push_back(static_cast(new_zone)); + current_routing->get_children()->push_back(new_zone); } /* set the new current component of the tree */ current_routing = new_zone; - simgrid::s4u::NetZone::on_creation(*new_zone); // notify the signal + simgrid::s4u::NetZone::on_creation(*new_zone->get_iface()); // notify the signal return new_zone; } @@ -626,7 +626,7 @@ void sg_platf_new_Zone_seal() { xbt_assert(current_routing, "Cannot seal the current AS: none under construction"); current_routing->seal(); - simgrid::s4u::NetZone::on_seal(*current_routing); + simgrid::s4u::NetZone::on_seal(*current_routing->get_iface()); current_routing = static_cast(current_routing->get_father()); } diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 8ae587d39f..0f24ff812e 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -185,7 +185,8 @@ public: void routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl* bb); /*** END of the parsing cruft ***/ -XBT_PUBLIC simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone); // Begin description of new Zone +XBT_PUBLIC simgrid::kernel::routing::NetZoneImpl* +sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone); // Begin description of new Zone XBT_PUBLIC void sg_platf_new_Zone_seal(); // That Zone is fully described XBT_PUBLIC void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* host); // Add a host to the current Zone