Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert routing_platf->getRouteAndLatency into s4u::Host->routeTo
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 5 Dec 2016 09:36:07 +0000 (10:36 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 5 Dec 2016 09:56:49 +0000 (10:56 +0100)
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.

13 files changed:
include/simgrid/s4u/engine.hpp
include/simgrid/s4u/host.hpp
src/instr/instr_interface.cpp
src/kernel/routing/AsDijkstra.cpp
src/kernel/routing/AsFloyd.cpp
src/s4u/s4u_engine.cpp
src/s4u/s4u_host.cpp
src/simdag/sd_workstation.cpp
src/surf/network_cm02.cpp
src/surf/network_ns3.cpp
src/surf/ptask_L07.cpp
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp

index 07c471c..62b88e8 100644 (file)
@@ -68,6 +68,7 @@ public:
 
   /** @brief Retrieve the root AS, containing all others */
   simgrid::s4u::As *rootAs();
 
   /** @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);
 
   /** @brief Retrieve the AS of the given name (or nullptr if not found) */
   simgrid::s4u::As *asByNameOrNull(const char *name);
 
index b6e7eff..d17f9e0 100644 (file)
@@ -102,6 +102,8 @@ public:
    */
   boost::unordered_map<std::string, Storage*> const &mountedStorages();
 
    */
   boost::unordered_map<std::string, Storage*> const &mountedStorages();
 
+  void routeTo(Host * dest, std::vector<Link*> * links, double* latency);
+
 private:
   simgrid::xbt::string name_ = "noname";
   boost::unordered_map<std::string, Storage*> *mounts = nullptr; // caching
 private:
   simgrid::xbt::string name_ = "noname";
   boost::unordered_map<std::string, Storage*> *mounts = nullptr; // caching
index 6c9f32e..7094cdd 100644 (file)
@@ -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);
 
   if(!dst_elm)
     xbt_die("Element '%s' not found!",dst);
 
-  std::vector<Link*> *route = new std::vector<Link*>();
-  routing_platf->getRouteAndLatency (src_elm, dst_elm, route,nullptr);
-  for (auto link : *route)
+  std::vector<Link*> 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);
     instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables);
-  delete route;
 }
 
 /** \ingroup TRACE_API
 }
 
 /** \ingroup TRACE_API
index eaf1b27..2102994 100644 (file)
@@ -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<Link*> *e_route_as_to_as = new std::vector<Link*>();
 
         strcmp(gw_dst->name().c_str(), prev_gw_src->name().c_str())) {
       std::vector<Link*> *e_route_as_to_as = new std::vector<Link*>();
 
-      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);
       auto pos = route->link_list->begin();
       for (auto link : *e_route_as_to_as) {
         route->link_list->insert(pos, link);
index 8c571b0..4821b05 100644 (file)
@@ -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())) {
     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) {
     }
 
     for (auto link: *e_route->link_list) {
index da624f5..1516008 100644 (file)
@@ -6,17 +6,20 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "instr/instr_interface.h"
  * 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 "mc/mc.h"
 #include "simgrid/s4u/As.hpp"
-#include "simgrid/s4u/engine.hpp"
 #include "simgrid/s4u/Mailbox.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/s4u/storage.hpp"
 #include "simgrid/simix.h"
+#include "simgrid/simix.h"
 #include "src/kernel/EngineImpl.hpp"
 #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 "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");
 
 
 XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface");
 
index 523aee6..3d8550f 100644 (file)
@@ -20,6 +20,8 @@
 #include "simgrid/s4u/host.hpp"
 #include "simgrid/s4u/storage.hpp"
 
 #include "simgrid/s4u/host.hpp"
 #include "simgrid/s4u/storage.hpp"
 
+XBT_LOG_EXTERNAL_CATEGORY(surf_route);
+
 std::unordered_map<std::string, simgrid::s4u::Host*> host_list; // FIXME: move it to Engine
 
 int MSG_HOST_LEVEL = -1;
 std::unordered_map<std::string, simgrid::s4u::Host*> 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();
 }
 
   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<Link*>* 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<std::string, Storage*> const& Host::mountedStorages() {
   if (mounts == nullptr) {
     mounts = new boost::unordered_map<std::string, Storage*> ();
 boost::unordered_map<std::string, Storage*> const& Host::mountedStorages() {
   if (mounts == nullptr) {
     mounts = new boost::unordered_map<std::string, Storage*> ();
index 44e2a0b..e4eac88 100644 (file)
  */
 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
 {
  */
 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
 {
-  std::vector<Link*> *route = new std::vector<Link*>();
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
+  std::vector<Link*> route;
+  src->routeTo(dst, &route, nullptr);
 
   int cpt=0;
 
   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++;
   }
     list[cpt] = link;
     cpt++;
   }
-  delete route;
   return list;
 }
 
   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)
 {
  */
 int SD_route_get_size(sg_host_t src, sg_host_t dst)
 {
-  std::vector<Link*> *route = new std::vector<Link*>();
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
-  int size = route->size();
-  delete route;
+  std::vector<Link*> route;
+  src->routeTo(dst, &route, nullptr);
+  int size = route.size();
   return 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;
 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
 {
   double latency = 0;
-  std::vector<Link*> *route = new std::vector<Link*>();
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency);
-  delete route;
+  std::vector<Link*> route;
+  src->routeTo(dst, &route, &latency);
 
   return 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;
 
 {
   double min_bandwidth = -1.0;
 
-  std::vector<Link*> *route = new std::vector<Link*>();
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
+  std::vector<Link*> 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;
   }
     double bandwidth = sg_link_bandwidth(link);
     if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
       min_bandwidth = bandwidth;
   }
-  delete route;
 
   return min_bandwidth;
 }
 
   return min_bandwidth;
 }
index ed0ddb2..88b131c 100644 (file)
@@ -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);
 
 
   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());
   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<Link*>();
 
   if (sg_network_crosstraffic == 1) {
     back_route = new std::vector<Link*>();
-    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;
     for (auto link: *back_route)
       if (link->isOff())
         failed = 1;
index 8613239..d5b877e 100644 (file)
@@ -253,7 +253,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
 
       std::vector<Link*> route = std::vector<Link*>();
 
 
       std::vector<Link*> route = std::vector<Link*>();
 
-      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);
 
       for (auto link : route)
         TRACE_surf_link_set_utilization (link->getName(), action->getCategory(), (data_delta_sent)/delta, now-delta, delta);
 
index 1d8e98f..f488f01 100644 (file)
@@ -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;
 
         if (bytes_amount[i * host_nb + j] > 0) {
           double lat=0.0;
-          std::vector<Link*> route;
 
 
-          routing_platf->getRouteAndLatency(hostList_->at(i)->pimpl_netcard, hostList_->at(j)->pimpl_netcard, &route,
-                                            &lat);
+          std::vector<Link*> route;
+          hostList_->at(i)->routeTo(hostList_->at(j), &route, &lat);
           latency = MAX(latency, lat);
 
           for (auto link : route)
           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;
 
         if (bytes_amount[i * host_nb + j] == 0.0)
           continue;
-        std::vector<Link*> route;
 
 
-        routing_platf->getRouteAndLatency(hostList_->at(i)->pimpl_netcard, hostList_->at(j)->pimpl_netcard, &route,
-                                          nullptr);
+        std::vector<Link*> 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]);
 
         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<Link*> route;
         if (communicationAmount_[i * hostNb + j] > 0) {
           double lat = 0.0;
           std::vector<Link*> 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]);
         }
 
           lat_current = MAX(lat_current, lat * communicationAmount_[i * hostNb + j]);
         }
index 39096a0..a360296 100644 (file)
@@ -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);
 }
 
   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<Link*> * 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 ************************ */
 
 /* ************************************************************************** */
 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
 
index dbedf32..798e4c8 100644 (file)
@@ -108,7 +108,6 @@ public:
   explicit RoutingPlatf();
   ~RoutingPlatf();
   AsImpl *root_ = nullptr;
   explicit RoutingPlatf();
   ~RoutingPlatf();
   AsImpl *root_ = nullptr;
-  void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
 };
 
 }}}
 };
 
 }}}