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 4ff5801..d30d786 100644 (file)
@@ -17,6 +17,14 @@ namespace simgrid {
   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),
@@ -26,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());
   }
+  AsImpl::~AsImpl()
+  {
+    for (auto& kv : bypassRoutes_)
+      delete kv.second;
+  }
 
   simgrid::s4u::Host* AsImpl::createHost(const char* name, std::vector<double>* speedPerPstate, int coreAmount)
   {
@@ -41,6 +54,34 @@ namespace simgrid {
     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.
@@ -160,7 +201,7 @@ namespace simgrid {
     /* Base case, no recursion is needed */
     if (dst->containingAS() == this && src->containingAS() == this) {
       if (bypassRoutes_.find({src, dst}) != bypassRoutes_.end()) {
-        AsRoute* bypassedRoute = bypassRoutes_.at({src, dst});
+        BypassRoute* bypassedRoute = bypassRoutes_.at({src, dst});
         for (surf::Link* link : bypassedRoute->links) {
           links->push_back(link);
           if (latency)
@@ -204,7 +245,7 @@ namespace simgrid {
     int max_index = std::max(max_index_src, max_index_dst);
 
     /* (3) Search for a bypass making the path up to the ancestor useless */
-    AsRoute* bypassedRoute = nullptr;
+    BypassRoute* bypassedRoute = nullptr;
     std::pair<kernel::routing::NetCard*, kernel::routing::NetCard*> key;
     for (int max = 0; max <= max_index; max++) {
       for (int i = 0; i < max; i++) {