From: Bruno Donassolo Date: Tue, 6 Apr 2021 08:52:21 +0000 (+0200) Subject: Simplify NetZone's hierarchy X-Git-Tag: v3.28~455^2~151 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3a15a2893fa0aa6b626063cb446cd1fc6b0088d8?hp=6dacf355bd5d72b9fb9da2eb229e441e626bd898 Simplify NetZone's hierarchy A NetZone is RoutingMode::base by default. When we add a child to it, it becomes RoutingMode::recursive. --- diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index d2eab40ff4..ae410c5e51 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -70,14 +70,6 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { std::map, BypassRoute*> bypass_routes_; // src x dst -> route routing::NetPoint* netpoint_ = nullptr; // Our representative in the father NetZone - std::shared_ptr network_model_; - std::shared_ptr cpu_model_vm_; - std::shared_ptr cpu_model_pm_; - std::shared_ptr disk_model_; - std::shared_ptr host_model_; - /** @brief Perform sealing procedure for derived classes, if necessary */ - virtual void do_seal(){}; - void add_child(NetZoneImpl* new_zone); protected: explicit NetZoneImpl(const std::string& name); @@ -101,14 +93,10 @@ protected: public: enum class RoutingMode { - unset = 0, /**< Undefined type */ - base, /**< Base case: use simple link lists for routing */ - recursive /**< Recursive case: also return gateway information */ + base, /**< Base case: use simple link lists for routing */ + recursive /**< Recursive case: also return gateway information */ }; - /* FIXME: protect the following fields once the construction madness is sorted out */ - RoutingMode hierarchy_ = RoutingMode::unset; - /** @brief Retrieves the network model associated to this NetZone */ const std::shared_ptr& get_network_model() const { return network_model_; } /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */ @@ -129,6 +117,8 @@ public: /** @brief Returns the list of direct children (no grand-children). This returns the internal data, no copy. * Don't mess with it.*/ std::vector* get_children() { return &children_; } + /** @brief Get current netzone hierarchy */ + RoutingMode get_hierarchy() const { return hierarchy_; } /** @brief Retrieves the name of that netzone as a C++ string */ const std::string& get_name() const { return name_; } @@ -176,6 +166,17 @@ public: virtual void get_graph(const s_xbt_graph_t* graph, std::map>* nodes, std::map>* edges) = 0; + +private: + RoutingMode hierarchy_ = RoutingMode::base; + std::shared_ptr network_model_; + std::shared_ptr cpu_model_vm_; + std::shared_ptr cpu_model_pm_; + std::shared_ptr disk_model_; + std::shared_ptr host_model_; + /** @brief Perform sealing procedure for derived classes, if necessary */ + virtual void do_seal(){}; + void add_child(NetZoneImpl* new_zone); }; } // namespace routing } // namespace kernel diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index 3b6a036a7d..6270976eae 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -40,7 +40,7 @@ void DijkstraZone::do_seal() xbt_node_t node = nullptr; /* Add the loopback if needed */ - if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) { + if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) { xbt_dynar_foreach (xbt_graph_get_nodes(route_graph_.get()), cursor, node) { bool found = false; xbt_edge_t edge = nullptr; @@ -187,7 +187,8 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr if (v == dst_node_id) first_gw = gw_dst; - if (hierarchy_ == RoutingMode::recursive && v != dst_node_id && gw_dst->get_name() != prev_gw_src->get_name()) { + if (get_hierarchy() == RoutingMode::recursive && v != dst_node_id && + gw_dst->get_name() != prev_gw_src->get_name()) { std::vector e_route_as_to_as; NetPoint* gw_dst_net_elm = nullptr; @@ -209,7 +210,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr } } - if (hierarchy_ == RoutingMode::recursive) { + if (get_hierarchy() == RoutingMode::recursive) { route->gw_src = gw_src; route->gw_dst = first_gw; } @@ -223,10 +224,10 @@ void DijkstraZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, Net { add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical); - new_edge(src->id(), dst->id(), new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true)); + new_edge(src->id(), dst->id(), new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true)); if (symmetrical) - new_edge(dst->id(), src->id(), new_extended_route(hierarchy_, gw_dst, gw_src, link_list, false)); + new_edge(dst->id(), src->id(), new_extended_route(get_hierarchy(), gw_dst, gw_src, link_list, false)); } void DijkstraZone::new_edge(int src_id, int dst_id, RouteCreationArgs* route) diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index 98903cb741..5e109f36d1 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -57,7 +57,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* cur = pred; } while (cur != src->id()); - if (hierarchy_ == RoutingMode::recursive) { + if (get_hierarchy() == RoutingMode::recursive) { route->gw_src = route_stack.back()->gw_src; route->gw_dst = route_stack.front()->gw_dst; } @@ -66,7 +66,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* while (not route_stack.empty()) { const RouteCreationArgs* e_route = route_stack.back(); route_stack.pop_back(); - if (hierarchy_ == RoutingMode::recursive && prev_dst_gw != nullptr && + if (get_hierarchy() == RoutingMode::recursive && prev_dst_gw != nullptr && prev_dst_gw->get_cname() != e_route->gw_src->get_cname()) { get_global_route(prev_dst_gw, e_route->gw_src, route->link_list, lat); } @@ -100,7 +100,7 @@ void FloydZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoi "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(), dst->get_cname()); - TO_FLOYD_LINK(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true); + TO_FLOYD_LINK(src->id(), dst->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true); TO_FLOYD_PRED(src->id(), dst->id()) = src->id(); TO_FLOYD_COST(src->id(), dst->id()) = (TO_FLOYD_LINK(src->id(), dst->id()))->link_list.size(); @@ -127,7 +127,7 @@ void FloydZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoi XBT_DEBUG("Load NetzoneRoute from \"%s(%s)\" to \"%s(%s)\"", dst->get_cname(), gw_src->get_cname(), src->get_cname(), gw_dst->get_cname()); - TO_FLOYD_LINK(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false); + TO_FLOYD_LINK(dst->id(), src->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, false); TO_FLOYD_PRED(dst->id(), src->id()) = dst->id(); TO_FLOYD_COST(dst->id(), src->id()) = (TO_FLOYD_LINK(dst->id(), src->id()))->link_list.size(); /* count of links, old model assume 1 */ @@ -141,7 +141,7 @@ void FloydZone::do_seal() init_tables(table_size); /* Add the loopback if needed */ - if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) { + if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) { for (unsigned int i = 0; i < table_size; i++) { RouteCreationArgs* route = TO_FLOYD_LINK(i, i); if (not route) { diff --git a/src/kernel/routing/FullZone.cpp b/src/kernel/routing/FullZone.cpp index 9f0c860db1..ab756c155b 100644 --- a/src/kernel/routing/FullZone.cpp +++ b/src/kernel/routing/FullZone.cpp @@ -26,7 +26,7 @@ void FullZone::do_seal() routing_table_.resize(table_size * table_size, nullptr); /* Add the loopback if needed */ - if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) { + if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) { for (unsigned int i = 0; i < table_size; i++) { RouteCreationArgs* route = TO_ROUTE_FULL(i, i); if (not route) { @@ -84,7 +84,7 @@ void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoin dst->get_cname()); /* Add the route to the base */ - TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true); + TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true); if (symmetrical && src != dst) { if (gw_dst && gw_src) { @@ -102,7 +102,7 @@ void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoin "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.", dst->get_cname(), src->get_cname()); - TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false); + TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, false); } } } // namespace routing diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 775009a199..1db3805493 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -109,6 +109,8 @@ NetZoneImpl::~NetZoneImpl() void NetZoneImpl::add_child(NetZoneImpl* new_zone) { xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname()); + /* set the father behavior */ + hierarchy_ = RoutingMode::recursive; children_.push_back(new_zone); } @@ -157,9 +159,6 @@ s4u::Link* NetZoneImpl::create_wifi_link(const std::string& name, const std::vec s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector& speed_per_pstate) { - if (hierarchy_ == RoutingMode::unset) - hierarchy_ = RoutingMode::base; - auto* res = (new surf::HostImpl(name))->get_iface(); res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this)); diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index 4df9a279fd..4a07c1a847 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -117,9 +117,6 @@ RouteCreationArgs* RoutedZone::new_extended_route(RoutingMode hierarchy, NetPoin { auto* result = new RouteCreationArgs(); - xbt_assert(hierarchy == RoutingMode::base || hierarchy == RoutingMode::recursive, - "The hierarchy of this netzone is neither BASIC nor RECURSIVE, I'm lost here."); - if (hierarchy == RoutingMode::recursive) { xbt_assert(gw_src && gw_dst, "nullptr is obviously a deficient gateway"); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e256c36881..e9e00395dd 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -91,8 +91,6 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) /** @brief Add a "router" to the network element list */ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, const char* coords) { - if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) - current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base; xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name), "Refusing to create a router named '%s': this name already describes a node.", name.c_str()); @@ -473,11 +471,6 @@ sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone) } new_zone->set_parent(current_routing); - if (current_routing) { - /* set the father behavior */ - if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) - current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive; - } return new_zone; }