Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
actually, BypassRoute can be made private to AsImpl
[simgrid.git] / src / kernel / routing / AsImpl.cpp
index 1be8910..d30d786 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "simgrid/s4u/host.hpp"
 #include "src/kernel/routing/AsImpl.hpp"
 
 #include "simgrid/s4u/host.hpp"
 #include "src/kernel/routing/AsImpl.hpp"
-#include "src/kernel/routing/BypassRoute.hpp"
 #include "src/kernel/routing/NetCard.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/kernel/routing/NetCard.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
@@ -18,6 +17,14 @@ namespace simgrid {
   namespace kernel {
   namespace routing {
 
   namespace kernel {
   namespace routing {
 
+  class BypassRoute {
+  public:
+    explicit BypassRoute(NetCard* gwSrc, NetCard* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {}
+    const NetCard* gw_src;
+    const NetCard* gw_dst;
+    std::vector<Link*> links;
+  };
+
   AsImpl::AsImpl(As* father, const char* name) : As(father, name)
   {
     xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL),
   AsImpl::AsImpl(As* father, const char* name) : As(father, name)
   {
     xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL),
@@ -27,6 +34,11 @@ namespace simgrid {
     xbt_lib_set(as_router_lib, name, ROUTING_ASR_LEVEL, static_cast<void*>(netcard_));
     XBT_DEBUG("AS '%s' created with the id '%d'", name, netcard_->id());
   }
     xbt_lib_set(as_router_lib, name, ROUTING_ASR_LEVEL, static_cast<void*>(netcard_));
     XBT_DEBUG("AS '%s' created with the id '%d'", name, netcard_->id());
   }
+  AsImpl::~AsImpl()
+  {
+    for (auto& kv : bypassRoutes_)
+      delete kv.second;
+  }
 
   simgrid::s4u::Host* AsImpl::createHost(const char* name, std::vector<double>* speedPerPstate, int coreAmount)
   {
 
   simgrid::s4u::Host* AsImpl::createHost(const char* name, std::vector<double>* speedPerPstate, int coreAmount)
   {
@@ -42,6 +54,34 @@ namespace simgrid {
     return res;
   }
 
     return res;
   }
 
+  void AsImpl::addBypassRoute(sg_platf_route_cbarg_t e_route)
+  {
+    /* Argument validity checks */
+    if (e_route->gw_dst) {
+      XBT_DEBUG("Load bypassASroute from %s@%s to %s@%s", e_route->src->cname(), e_route->gw_src->cname(),
+                e_route->dst->cname(), e_route->gw_dst->cname());
+      xbt_assert(!e_route->link_list->empty(), "Bypass route between %s@%s and %s@%s cannot be empty.",
+                 e_route->src->cname(), e_route->gw_src->cname(), e_route->dst->cname(), e_route->gw_dst->cname());
+      xbt_assert(bypassRoutes_.find({e_route->src, e_route->dst}) == bypassRoutes_.end(),
+                 "The bypass route between %s@%s and %s@%s already exists.", e_route->src->cname(),
+                 e_route->gw_src->cname(), e_route->dst->cname(), e_route->gw_dst->cname());
+    } else {
+      XBT_DEBUG("Load bypassRoute from %s to %s", e_route->src->cname(), e_route->dst->cname());
+      xbt_assert(!e_route->link_list->empty(), "Bypass route between %s and %s cannot be empty.", e_route->src->cname(),
+                 e_route->dst->cname());
+      xbt_assert(bypassRoutes_.find({e_route->src, e_route->dst}) == bypassRoutes_.end(),
+                 "The bypass route between %s and %s already exists.", e_route->src->cname(), e_route->dst->cname());
+    }
+
+    /* Build a copy that will be stored in the dict */
+    kernel::routing::BypassRoute* newRoute = new kernel::routing::BypassRoute(e_route->gw_src, e_route->gw_dst);
+    for (auto link : *e_route->link_list)
+      newRoute->links.push_back(link);
+
+    /* Store it */
+    bypassRoutes_.insert({{e_route->src, e_route->dst}, newRoute});
+  }
+
   /** @brief Get the common ancestor and its first children in each line leading to src and dst
    *
    * In the recursive case, this sets common_ancestor, src_ancestor and dst_ancestor are set as follows.
   /** @brief Get the common ancestor and its first children in each line leading to src and dst
    *
    * In the recursive case, this sets common_ancestor, src_ancestor and dst_ancestor are set as follows.