From 472b2aa318353674993dffd9792f1a155f579d6f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 17 Dec 2016 19:14:40 +0100 Subject: [PATCH] reduce the public exposure of netcards_dict --- include/simgrid/s4u/engine.hpp | 7 +++++-- src/instr/instr_paje_containers.cpp | 7 ++++--- src/kernel/routing/NetCard.cpp | 6 +++--- src/kernel/routing/NetZoneImpl.cpp | 11 ++++++----- src/kernel/routing/VivaldiZone.cpp | 7 ++++--- src/s4u/s4u_engine.cpp | 5 +++++ src/surf/sg_platf.cpp | 4 ++-- teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh | 1 - teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh | 1 - 9 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index c89b3e25e4..a6ee0bda92 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -66,12 +66,15 @@ public: /** @brief Retrieve the engine singleton */ static s4u::Engine *instance(); - /** @brief Retrieve the root AS, containing all others */ + /** @brief Retrieve the root netzone, containing all others */ simgrid::s4u::NetZone* netRoot(); - /** @brief Retrieve the AS of the given name (or nullptr if not found) */ + /** @brief Retrieve the netzone of the given name (or nullptr if not found) */ simgrid::s4u::NetZone* netzoneByNameOrNull(const char* name); + /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ + simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name); + template void registerFunction(const char* name) { diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 4ca29817ac..6af90f2fd1 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -4,7 +4,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include +#include "simgrid/s4u/engine.hpp" +#include "simgrid/s4u/host.hpp" #include #include @@ -71,11 +72,11 @@ container_t PJ_container_new (const char *name, e_container_types kind, containe xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; case INSTR_ROUTER: - newContainer->netcard = static_cast(xbt_dict_get_or_null(netcards_dict, name)); + newContainer->netcard = simgrid::s4u::Engine::instance()->netcardByNameOrNull(name); xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; case INSTR_AS: - newContainer->netcard = static_cast(xbt_dict_get_or_null(netcards_dict, name)); + newContainer->netcard = simgrid::s4u::Engine::instance()->netcardByNameOrNull(name); xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; default: diff --git a/src/kernel/routing/NetCard.cpp b/src/kernel/routing/NetCard.cpp index 26f551cc53..799983e564 100644 --- a/src/kernel/routing/NetCard.cpp +++ b/src/kernel/routing/NetCard.cpp @@ -5,8 +5,9 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/routing/NetCard.hpp" +#include "simgrid/s4u/engine.hpp" +#include "simgrid/s4u/host.hpp" #include "surf/surf_routing.h" -#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); @@ -26,6 +27,5 @@ simgrid::xbt::signal NetCard::onCreation; simgrid::kernel::routing::NetCard* sg_netcard_by_name_or_null(const char* name) { sg_host_t host = sg_host_by_name(name); - return (host != nullptr) ? host->pimpl_netcard - : static_cast(xbt_dict_get_or_null(netcards_dict, name)); + return (host != nullptr) ? host->pimpl_netcard : simgrid::s4u::Engine::instance()->netcardByNameOrNull(name); } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 2944f7b332..57619a8094 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -3,14 +3,15 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "xbt/log.h" - +#include "src/kernel/routing/NetZoneImpl.hpp" +#include "simgrid/s4u/engine.hpp" #include "simgrid/s4u/host.hpp" #include "src/kernel/routing/NetCard.hpp" -#include "src/kernel/routing/NetZoneImpl.hpp" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" +#include "xbt/log.h" + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_route); namespace simgrid { @@ -27,8 +28,8 @@ public: NetZoneImpl::NetZoneImpl(NetZone* father, const char* name) : NetZone(father, name) { - xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, name), "Refusing to create a second NetZone called '%s'.", - name); + xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(name), + "Refusing to create a second NetZone called '%s'.", name); netcard_ = new NetCard(name, NetCard::Type::NetZone, static_cast(father)); xbt_dict_set(netcards_dict, name, static_cast(netcard_), nullptr); diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index 04b14a6929..75499987d4 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -5,7 +5,8 @@ #include -#include +#include "simgrid/s4u/engine.hpp" +#include "simgrid/s4u/host.hpp" #include "src/kernel/routing/NetCard.hpp" #include "src/kernel/routing/VivaldiZone.hpp" @@ -80,8 +81,8 @@ void VivaldiZone::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg if (src->isNetZone()) { char* srcName = bprintf("router_%s", src->cname()); char* dstName = bprintf("router_%s", dst->cname()); - route->gw_src = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, srcName); - route->gw_dst = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, dstName); + route->gw_src = simgrid::s4u::Engine::instance()->netcardByNameOrNull(srcName); + route->gw_dst = simgrid::s4u::Engine::instance()->netcardByNameOrNull(dstName); xbt_free(srcName); xbt_free(dstName); } diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 0f8798d95e..71bf83839b 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -111,5 +111,10 @@ NetZone* Engine::netzoneByNameOrNull(const char* name) return netzoneByNameRecursive(netRoot(), name); } +/** @brief Retrieve the netcard of the given name (or nullptr if not found) */ +simgrid::kernel::routing::NetCard* Engine::netcardByNameOrNull(const char* name) +{ + return static_cast(xbt_dict_get_or_null(netcards_dict, name)); +} } } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index af64bdeccb..9c95b66c10 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -115,7 +115,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router) if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base; - xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, router->id), + xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(router->id), "Refusing to create a router named '%s': this name already describes a node.", router->id); simgrid::kernel::routing::NetCard* netcard = @@ -307,7 +307,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) if (!router.id || !strcmp(router.id, "")) router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix); sg_platf_new_router(&router); - current_as->router_ = (simgrid::kernel::routing::NetCard*)xbt_dict_get_or_null(netcards_dict, router.id); + current_as->router_ = simgrid::s4u::Engine::instance()->netcardByNameOrNull(router.id); free(newid); //Make the backbone diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh b/teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh index 8ececd2323..a7e447259d 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh +++ b/teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh @@ -5,7 +5,6 @@ ! output sort $ $SG_TEST_EXENV ${bindir:=.}/maxmin_bench medium 5 test > [0.000000]: [surf_kernel/DEBUG] Add SURF levels -> [0.000000]: [surf_kernel/DEBUG] Add routing levels > [0.000000]: [surf_kernel/DEBUG] Create all Libs > [0.000000]: [surf_maxmin/DEBUG] Setting selective_update_active flag to 1 > [0.000000]: [surf_maxmin/DEBUG] Active constraints : 100 diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh b/teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh index 303353542f..b3edd1c94c 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh +++ b/teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh @@ -5,7 +5,6 @@ ! output sort $ $SG_TEST_EXENV ${bindir:=.}/maxmin_bench small 10 test > [0.000000]: [surf_kernel/DEBUG] Add SURF levels -> [0.000000]: [surf_kernel/DEBUG] Add routing levels > [0.000000]: [surf_kernel/DEBUG] Create all Libs > [0.000000]: [surf_maxmin/DEBUG] Setting selective_update_active flag to 1 > [0.000000]: [surf_maxmin/DEBUG] Active constraints : 10 -- 2.20.1