From 1d5dde64a8201a55007ccc0bcc4f267facff8d30 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 5 Dec 2016 10:36:07 +0100 Subject: [PATCH] Convert routing_platf->getRouteAndLatency into s4u::Host->routeTo The bad thing is that the public API does not expose the surf::Link type, so there is little you can do about it. For now. --- include/simgrid/s4u/engine.hpp | 1 + include/simgrid/s4u/host.hpp | 2 ++ src/instr/instr_interface.cpp | 7 +++---- src/kernel/routing/AsDijkstra.cpp | 2 +- src/kernel/routing/AsFloyd.cpp | 2 +- src/s4u/s4u_engine.cpp | 9 ++++++--- src/s4u/s4u_host.cpp | 25 +++++++++++++++++++++++++ src/simdag/sd_workstation.cpp | 28 ++++++++++++---------------- src/surf/network_cm02.cpp | 4 ++-- src/surf/network_ns3.cpp | 2 +- src/surf/ptask_L07.cpp | 13 +++++-------- src/surf/surf_routing.cpp | 31 ------------------------------- src/surf/surf_routing.hpp | 1 - 13 files changed, 59 insertions(+), 68 deletions(-) diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 07c471c996..62b88e804c 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -68,6 +68,7 @@ public: /** @brief Retrieve the root AS, containing all others */ simgrid::s4u::As *rootAs(); + /** @brief Retrieve the AS of the given name (or nullptr if not found) */ simgrid::s4u::As *asByNameOrNull(const char *name); diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index b6e7eff3b0..d17f9e0ad8 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -102,6 +102,8 @@ public: */ boost::unordered_map const &mountedStorages(); + void routeTo(Host * dest, std::vector * links, double* latency); + private: simgrid::xbt::string name_ = "noname"; boost::unordered_map *mounts = nullptr; // caching diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 6c9f32ef4e..7094cddb07 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -319,11 +319,10 @@ static void instr_user_srcdst_variable(double time, const char *src, const char if(!dst_elm) xbt_die("Element '%s' not found!",dst); - std::vector *route = new std::vector(); - routing_platf->getRouteAndLatency (src_elm, dst_elm, route,nullptr); - for (auto link : *route) + std::vector route; + simgrid::kernel::routing::AsImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr); + for (auto link : route) instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables); - delete route; } /** \ingroup TRACE_API diff --git a/src/kernel/routing/AsDijkstra.cpp b/src/kernel/routing/AsDijkstra.cpp index eaf1b27b06..2102994f06 100644 --- a/src/kernel/routing/AsDijkstra.cpp +++ b/src/kernel/routing/AsDijkstra.cpp @@ -262,7 +262,7 @@ void AsDijkstra::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_ strcmp(gw_dst->name().c_str(), prev_gw_src->name().c_str())) { std::vector *e_route_as_to_as = new std::vector(); - routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, e_route_as_to_as, nullptr); + getGlobalRoute(gw_dst_net_elm, prev_gw_src_net_elm, e_route_as_to_as, nullptr); auto pos = route->link_list->begin(); for (auto link : *e_route_as_to_as) { route->link_list->insert(pos, link); diff --git a/src/kernel/routing/AsFloyd.cpp b/src/kernel/routing/AsFloyd.cpp index 8c571b04a0..4821b05136 100644 --- a/src/kernel/routing/AsFloyd.cpp +++ b/src/kernel/routing/AsFloyd.cpp @@ -68,7 +68,7 @@ void AsFloyd::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg_t r route_stack.pop_back(); if (hierarchy_ == RoutingMode::recursive && prev_dst_gw != nullptr && strcmp(prev_dst_gw->name().c_str(), e_route->gw_src->name().c_str())) { - routing_platf->getRouteAndLatency(prev_dst_gw, e_route->gw_src, route->link_list, lat); + getGlobalRoute(prev_dst_gw, e_route->gw_src, route->link_list, lat); } for (auto link: *e_route->link_list) { diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index da624f582d..1516008afc 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -6,17 +6,20 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "instr/instr_interface.h" -#include "simgrid/simix.h" #include "mc/mc.h" #include "simgrid/s4u/As.hpp" -#include "simgrid/s4u/engine.hpp" #include "simgrid/s4u/Mailbox.hpp" +#include "simgrid/s4u/engine.hpp" +#include "simgrid/s4u/host.hpp" #include "simgrid/s4u/storage.hpp" #include "simgrid/simix.h" +#include "simgrid/simix.h" #include "src/kernel/EngineImpl.hpp" +#include "src/kernel/routing/AsImpl.hpp" -#include "surf/surf.h" // routing_platf. FIXME:KILLME. SOON +#include "src/surf/network_interface.hpp" #include "src/surf/surf_routing.hpp" // routing_platf. FIXME:KILLME. SOON +#include "surf/surf.h" // routing_platf. FIXME:KILLME. SOON XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface"); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 523aee6482..3d8550f137 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -20,6 +20,8 @@ #include "simgrid/s4u/host.hpp" #include "simgrid/s4u/storage.hpp" +XBT_LOG_EXTERNAL_CATEGORY(surf_route); + std::unordered_map host_list; // FIXME: move it to Engine int MSG_HOST_LEVEL = -1; @@ -117,6 +119,29 @@ int Host::pstatesCount() const { return this->pimpl_cpu->getNbPStates(); } +/** + * \brief Find a route toward another host + * + * \param dest [IN] where to + * \param route [OUT] where to store the list of links (must exist, cannot be nullptr). + * \param latency [OUT] where to store the latency experienced on the path (or nullptr if not interested) + * It is the caller responsibility to initialize latency to 0 (we add to provided route) + * \pre route!=nullptr + * + * walk through the routing components tree and find a route between hosts + * by calling each "get_route" function in each routing component. + */ +void Host::routeTo(Host* dest, std::vector* links, double* latency) +{ + simgrid::kernel::routing::AsImpl::getGlobalRoute(pimpl_netcard, dest->pimpl_netcard, links, latency); + if (XBT_LOG_ISENABLED(surf_route, xbt_log_priority_debug)) { + XBT_CDEBUG(surf_route, "Route from '%s' to '%s' (latency: %f):", cname(), dest->cname(), + (latency == nullptr ? -1 : *latency)); + for (auto link : *links) + XBT_CDEBUG(surf_route, "Link %s", link->getName()); + } +} + boost::unordered_map const& Host::mountedStorages() { if (mounts == nullptr) { mounts = new boost::unordered_map (); diff --git a/src/simdag/sd_workstation.cpp b/src/simdag/sd_workstation.cpp index 44e2a0bdaf..e4eac88da3 100644 --- a/src/simdag/sd_workstation.cpp +++ b/src/simdag/sd_workstation.cpp @@ -21,16 +21,15 @@ */ SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) { - std::vector *route = new std::vector(); - routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr); + std::vector route; + src->routeTo(dst, &route, nullptr); int cpt=0; - SD_link_t *list = xbt_new(SD_link_t, route->size()); - for (auto link : *route){ + SD_link_t* list = xbt_new(SD_link_t, route.size()); + for (auto link : route) { list[cpt] = link; cpt++; } - delete route; return list; } @@ -44,10 +43,9 @@ SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) */ int SD_route_get_size(sg_host_t src, sg_host_t dst) { - std::vector *route = new std::vector(); - routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr); - int size = route->size(); - delete route; + std::vector route; + src->routeTo(dst, &route, nullptr); + int size = route.size(); return size; } @@ -62,9 +60,8 @@ int SD_route_get_size(sg_host_t src, sg_host_t dst) double SD_route_get_latency(sg_host_t src, sg_host_t dst) { double latency = 0; - std::vector *route = new std::vector(); - routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency); - delete route; + std::vector route; + src->routeTo(dst, &route, &latency); return latency; } @@ -82,15 +79,14 @@ double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst) { double min_bandwidth = -1.0; - std::vector *route = new std::vector(); - routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr); + std::vector route; + src->routeTo(dst, &route, nullptr); - for (auto link : *route) { + for (auto link : route) { double bandwidth = sg_link_bandwidth(link); if (bandwidth < min_bandwidth || min_bandwidth < 0.0) min_bandwidth = bandwidth; } - delete route; return min_bandwidth; } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index ed0ddb2fbc..88b131c5dd 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -297,7 +297,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz XBT_IN("(%s,%s,%g,%g)", src->name().c_str(), dst->name().c_str(), size, rate); - routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency); + src->routeTo(dst, route, &latency); xbt_assert(!route->empty() || latency, "You're trying to send data from %s to %s but there is no connecting path between these two hosts.", src->name().c_str(), dst->name().c_str()); @@ -308,7 +308,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz if (sg_network_crosstraffic == 1) { back_route = new std::vector(); - routing_platf->getRouteAndLatency(dst->pimpl_netcard, src->pimpl_netcard, back_route, nullptr); + dst->routeTo(src, back_route, nullptr); for (auto link: *back_route) if (link->isOff()) failed = 1; diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 8613239a2f..d5b877e5f2 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -253,7 +253,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta) std::vector route = std::vector(); - routing_platf->getRouteAndLatency(action->src_->pimpl_netcard, action->dst_->pimpl_netcard, &route, nullptr); + action->src_->routeTo(action->dst_, &route, nullptr); for (auto link : route) TRACE_surf_link_set_utilization (link->getName(), action->getCategory(), (data_delta_sent)/delta, now-delta, delta); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 1d8e98f4a6..f488f01e65 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -172,10 +172,9 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, if (bytes_amount[i * host_nb + j] > 0) { double lat=0.0; - std::vector route; - routing_platf->getRouteAndLatency(hostList_->at(i)->pimpl_netcard, hostList_->at(j)->pimpl_netcard, &route, - &lat); + std::vector route; + hostList_->at(i)->routeTo(hostList_->at(j), &route, &lat); latency = MAX(latency, lat); for (auto link : route) @@ -214,10 +213,9 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, if (bytes_amount[i * host_nb + j] == 0.0) continue; - std::vector route; - routing_platf->getRouteAndLatency(hostList_->at(i)->pimpl_netcard, hostList_->at(j)->pimpl_netcard, &route, - nullptr); + std::vector route; + hostList_->at(i)->routeTo(hostList_->at(j), &route, nullptr); for (auto link : route) lmm_expand_add(model->getMaxminSystem(), link->getConstraint(), this->getVariable(), bytes_amount[i * host_nb + j]); @@ -411,8 +409,7 @@ void L07Action::updateBound() if (communicationAmount_[i * hostNb + j] > 0) { double lat = 0.0; std::vector route; - routing_platf->getRouteAndLatency(hostList_->at(i)->pimpl_netcard, hostList_->at(j)->pimpl_netcard, &route, - &lat); + hostList_->at(i)->routeTo(hostList_->at(j), &route, &lat); lat_current = MAX(lat_current, lat * communicationAmount_[i * hostNb + j]); } diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 39096a02f5..a360296dcc 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -75,37 +75,6 @@ void sg_platf_new_trace(sg_platf_trace_cbarg_t trace) xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, nullptr); } -namespace simgrid { -namespace kernel { -namespace routing { - -/** - * \brief Find a route between hosts - * - * \param src the network_element_t for src host - * \param dst the network_element_t for dst host - * \param route where to store the list of links. - * If *route=nullptr, create a short lived dynar. Else, fill the provided dynar - * \param latency where to store the latency experienced on the path (or nullptr if not interested) - * It is the caller responsibility to initialize latency to 0 (we add to provided route) - * \pre route!=nullptr - * - * walk through the routing components tree and find a route between hosts - * by calling each "get_route" function in each routing component. - */ -void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector * route, double *latency) -{ - AsImpl::getGlobalRoute(src, dst, route, latency); - if (XBT_LOG_ISENABLED(surf_route, xbt_log_priority_debug)) { - XBT_DEBUG("Route from '%s' to '%s' (latency: %f):", src->cname(), dst->cname(), - (latency == nullptr ? -1 : *latency)); - for (auto link : *route) - XBT_DEBUG("Link %s", link->getName()); - } -} - -}}} - /* ************************************************************************** */ /* ************************* GENERIC PARSE FUNCTIONS ************************ */ diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index dbedf325c4..798e4c87a2 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -108,7 +108,6 @@ public: explicit RoutingPlatf(); ~RoutingPlatf(); AsImpl *root_ = nullptr; - void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector * links, double *latency); }; }}} -- 2.20.1