Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move implementation bits of s4u::As into surf::AsImpl
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Mar 2016 11:20:23 +0000 (12:20 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Mar 2016 13:26:41 +0000 (14:26 +0100)
23 files changed:
include/simgrid/s4u/As.hpp [new file with mode: 0644]
src/instr/jedule/jedule_sd_binding.cpp
src/msg/msg_environment.cpp
src/s4u/s4u_as.cpp
src/s4u/s4u_engine.cpp
src/surf/AsImpl.cpp [new file with mode: 0644]
src/surf/AsImpl.hpp [moved from include/simgrid/s4u/as.hpp with 74% similarity]
src/surf/instr_routing.cpp
src/surf/network_ns3.cpp
src/surf/sg_platf.cpp
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp
src/surf/surf_routing_RoutedGraph.cpp
src/surf/surf_routing_RoutedGraph.hpp
src/surf/surf_routing_cluster.cpp
src/surf/surf_routing_cluster.hpp
src/surf/surf_routing_dijkstra.cpp
src/surf/surf_routing_floyd.cpp
src/surf/surf_routing_full.cpp
src/surf/surf_routing_none.cpp
src/surf/surf_routing_none.hpp
src/surf/xml/platf_private.hpp
tools/cmake/DefinePackages.cmake

diff --git a/include/simgrid/s4u/As.hpp b/include/simgrid/s4u/As.hpp
new file mode 100644 (file)
index 0000000..b79afa4
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (c) 2016. The SimGrid Team. All rights reserved.               */
+
+/* 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. */
+
+#ifndef SIMGRID_S4U_AS_HPP
+#define SIMGRID_S4U_AS_HPP
+
+#include "xbt/base.h"
+#include "xbt/graph.h"
+
+#include "simgrid/s4u/forward.hpp"
+#include <vector>
+#include <map>
+
+#include "src/surf/xml/platf_private.hpp" // FIXME: kill sg_platf_route_cbarg_t to remove that UGLY include
+
+namespace simgrid {
+
+namespace surf {
+  class AsImpl;
+  class Link;
+  class NetCard;
+}
+namespace s4u {
+
+/** @brief Autonomous Systems
+ *
+ * An AS is a network container, in charge of routing information between elements (hosts) and to the nearby ASes.
+ * In SimGrid, there is a hierarchy of ASes, with a unique root AS (that you can retrieve from the s4u::Engine).
+ */
+XBT_PUBLIC_CLASS As {
+protected:
+  friend simgrid::surf::AsImpl;
+
+  As(const char *name);
+  virtual ~As();
+  
+public:
+  /** @brief Seal your AS once you're done adding content, and before routing stuff through it */
+  virtual void Seal();
+  char *name();
+  As *father();;
+  xbt_dict_t children(); // Sub AS
+  xbt_dynar_t hosts();   // my content
+
+  As *father_ = nullptr; // FIXME: hide me
+public:
+  /* Add content to the AS, at parsing time. It should be sealed afterward. */
+  virtual int addComponent(surf::NetCard *elm); /* A host, a router or an AS, whatever */
+  virtual void addRoute(sg_platf_route_cbarg_t route);
+  void addBypassRoute(sg_platf_route_cbarg_t e_route);
+
+protected:
+  char *name_ = nullptr;
+  xbt_dict_t children_ = xbt_dict_new_homogeneous(NULL); // sub-ASes
+  xbt_dynar_t vertices_ = xbt_dynar_new(sizeof(char*),NULL); // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
+
+  std::map<std::pair<std::string, std::string>, std::vector<surf::Link*>*> bypassRoutes_; // srcName x dstName -> route
+
+private:
+  bool sealed_ = false; // We cannot add more content when sealed
+};
+
+}}; // Namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_AS_HPP */
index b82c48b..8e8becc 100644 (file)
@@ -18,7 +18,7 @@
 #include "simgrid/simdag.h"
 #include "src/simdag/simdag_private.h"
 
-#include "simgrid/s4u/as.hpp"
+#include "simgrid/s4u/As.hpp"
 #include "simgrid/s4u/engine.hpp"
 
 #include <stdio.h>
index a3a3b47..e7bd23f 100644 (file)
@@ -8,7 +8,7 @@
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
 
-#include "simgrid/s4u/as.hpp"
+#include "simgrid/s4u/As.hpp"
 #include "simgrid/s4u/engine.hpp"
 
 #ifdef HAVE_LUA
index 4f0cf81..60459e6 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "xbt/log.h"
 
-#include "simgrid/s4u/as.hpp"
+#include "simgrid/s4u/As.hpp"
 #include "src/surf/surf_routing.hpp"
 #include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
 
@@ -35,11 +35,9 @@ namespace simgrid {
 
       xbt_dict_free(&children_);
       xbt_dynar_free(&vertices_);
-      xbt_dynar_free(&upDownLinks);
       for (auto &kv : bypassRoutes_)
         delete kv.second;
       xbt_free(name_);
-      delete netcard_;
     }
 
     xbt_dict_t As::children()
@@ -67,10 +65,6 @@ namespace simgrid {
       return res;
     }
 
-    xbt_dynar_t As::getOneLinkRoutes() {
-      return NULL;
-    }
-
     int As::addComponent(surf::NetCard *elm) {
       xbt_dynar_push_as(vertices_, surf::NetCard*, elm);
       return xbt_dynar_length(vertices_)-1;
@@ -80,137 +74,6 @@ namespace simgrid {
       xbt_die("AS %s does not accept new routes (wrong class).",name_);
     }
 
-    /** @brief Get the common ancestor and its first childs in each line leading to src and dst */
-    static void find_common_ancestors(surf::NetCard *src, surf::NetCard *dst,
-        /* OUT */ As **common_ancestor, As **src_ancestor, As **dst_ancestor)
-    {
-    #define ROUTING_HIERARCHY_MAXDEPTH 32     /* increase if it is not enough */
-      simgrid::s4u::As *path_src[ROUTING_HIERARCHY_MAXDEPTH];
-      simgrid::s4u::As *path_dst[ROUTING_HIERARCHY_MAXDEPTH];
-      int index_src = 0;
-      int index_dst = 0;
-      simgrid::s4u::As *current_src;
-      simgrid::s4u::As *current_dst;
-      simgrid::s4u::As *father;
-
-      /* (1) find the path to root of src and dst*/
-      simgrid::s4u::As *src_as = src->containingAS();
-      simgrid::s4u::As *dst_as = dst->containingAS();
-
-      xbt_assert(src_as, "Host %s must be in an AS", src->name());
-      xbt_assert(dst_as, "Host %s must be in an AS", dst->name());
-
-      /* (2) find the path to the root routing component */
-      for (simgrid::s4u::As *current = src_as; current != NULL; current = current->father()) {
-        xbt_assert(index_src < ROUTING_HIERARCHY_MAXDEPTH, "ROUTING_HIERARCHY_MAXDEPTH should be increased for element %s", src->name());
-        path_src[index_src++] = current;
-      }
-      for (simgrid::s4u::As *current = dst_as; current != NULL; current = current->father()) {
-        xbt_assert(index_dst < ROUTING_HIERARCHY_MAXDEPTH,"ROUTING_HIERARCHY_MAXDEPTH should be increased for path_dst");
-        path_dst[index_dst++] = current;
-      }
-
-      /* (3) find the common father.
-       * Before that, index_src and index_dst may be different, they both point to NULL in path_src/path_dst
-       * So we move them down simultaneously as long as they point to the same content.
-       */
-      do {
-        current_src = path_src[--index_src];
-        current_dst = path_dst[--index_dst];
-      } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
-
-      /* (4) if we did not find a difference (index_src or index_dst went to 0), both elements are in the same AS */
-      if (current_src == current_dst)
-        father = current_src;
-      else // we found a difference
-        father = path_src[index_src + 1];
-
-      /* (5) result generation */
-      *common_ancestor = father;    /* the common father of src and dst */
-      *src_ancestor = current_src;  /* the first different father of src */
-      *dst_ancestor = current_dst;  /* the first different father of dst */
-    #undef ROUTING_HIERARCHY_MAXDEPTH
-    }
-
-
-    /* PRECONDITION: this is the common ancestor of src and dst */
-    std::vector<surf::Link*> *As::getBypassRoute(surf::NetCard *src, surf::NetCard *dst)
-    {
-      // If never set a bypass route return NULL without any further computations
-      XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name(), dst->name());
-      if (bypassRoutes_.empty())
-        return nullptr;
-
-      std::vector<surf::Link*> *bypassedRoute = nullptr;
-
-      if(dst->containingAS() == this && src->containingAS() == this ){
-        if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) {
-          bypassedRoute = bypassRoutes_.at({src->name(),dst->name()});
-          XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size());
-        }
-        return bypassedRoute;
-      }
-
-      /* (2) find the path to the root routing component */
-      std::vector<As*> path_src;
-      As *current = src->containingAS();
-      while (current != NULL) {
-        path_src.push_back(current);
-        current = current->father_;
-      }
-
-      std::vector<As*> path_dst;
-      current = dst->containingAS();
-      while (current != NULL) {
-        path_dst.push_back(current);
-        current = current->father_;
-      }
-
-      /* (3) find the common father */
-      while (path_src.size() > 1 && path_dst.size() >1
-          && path_src.at(path_src.size() -1) == path_dst.at(path_dst.size() -1)) {
-        path_src.pop_back();
-        path_dst.pop_back();
-      }
-
-      int max_index_src = path_src.size() - 1;
-      int max_index_dst = path_dst.size() - 1;
-
-      int max_index = std::max(max_index_src, max_index_dst);
-
-      for (int max = 0; max <= max_index; max++) {
-        for (int i = 0; i < max; i++) {
-          if (i <= max_index_src && max <= max_index_dst) {
-            const std::pair<std::string, std::string> key = {path_src.at(i)->name_, path_dst.at(max)->name_};
-            if (bypassRoutes_.find(key) != bypassRoutes_.end())
-              bypassedRoute = bypassRoutes_.at(key);
-          }
-          if (bypassedRoute)
-            break;
-          if (max <= max_index_src && i <= max_index_dst) {
-            const std::pair<std::string, std::string> key = {path_src.at(max)->name_, path_dst.at(i)->name_};
-            if (bypassRoutes_.find(key) != bypassRoutes_.end())
-              bypassedRoute = bypassRoutes_.at(key);
-          }
-          if (bypassedRoute)
-            break;
-        }
-
-        if (bypassedRoute)
-          break;
-
-        if (max <= max_index_src && max <= max_index_dst) {
-          const std::pair<std::string, std::string> key = {path_src.at(max)->name_, path_dst.at(max)->name_};
-          if (bypassRoutes_.find(key) != bypassRoutes_.end())
-            bypassedRoute = bypassRoutes_.at(key);
-        }
-        if (bypassedRoute)
-          break;
-      }
-
-      return bypassedRoute;
-    }
-
     void As::addBypassRoute(sg_platf_route_cbarg_t e_route){
       const char *src = e_route->src;
       const char *dst = e_route->dst;
@@ -238,65 +101,4 @@ namespace simgrid {
       bypassRoutes_.insert({{src,dst}, newRoute});
     }
 
-    /**
-     * \brief Recursive function for getRouteAndLatency
-     *
-     * \param src the source host
-     * \param dst the destination host
-     * \param links Where to store the links and the gw information
-     * \param latency If not NULL, the latency of all links will be added in it
-     */
-    void As::getRouteRecursive(surf::NetCard *src, surf::NetCard *dst,
-        /* OUT */ std::vector<surf::Link*> * links, double *latency)
-    {
-      s_sg_platf_route_cbarg_t route;
-      memset(&route,0,sizeof(route));
-
-      XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src->name(), dst->name());
-
-      /* Find how src and dst are interconnected */
-      simgrid::s4u::As *common_ancestor, *src_ancestor, *dst_ancestor;
-      find_common_ancestors(src, dst, &common_ancestor, &src_ancestor, &dst_ancestor);
-      XBT_DEBUG("elements_father: common ancestor '%s' src ancestor '%s' dst ancestor '%s'",
-          common_ancestor->name_, src_ancestor->name_, dst_ancestor->name_);
-
-      /* Check whether a direct bypass is defined. If so, use it and bail out */
-      std::vector<surf::Link*> *bypassed_route = common_ancestor->getBypassRoute(src, dst);
-      if (nullptr != bypassed_route) {
-        for (surf::Link *link : *bypassed_route) {
-          links->push_back(link);
-          if (latency)
-            *latency += link->getLatency();
-        }
-        return;
-      }
-
-      /* If src and dst are in the same AS, life is good */
-      if (src_ancestor == dst_ancestor) {       /* SURF_ROUTING_BASE */
-        route.link_list = links;
-        common_ancestor->getRouteAndLatency(src, dst, &route, latency);
-        return;
-      }
-
-      /* Not in the same AS, no bypass. We'll have to find our path between the ASes recursively*/
-
-      route.link_list = new std::vector<surf::Link*>();
-
-      common_ancestor->getRouteAndLatency(src_ancestor->netcard_, dst_ancestor->netcard_, &route, latency);
-      xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
-          "bad gateways for route from \"%s\" to \"%s\"", src->name(), dst->name());
-
-      /* If source gateway is not our source, we have to recursively find our way up to this point */
-      if (src != route.gw_src)
-        getRouteRecursive(src, route.gw_src, links, latency);
-      for (auto link: *route.link_list)
-        links->push_back(link);
-
-      /* If dest gateway is not our destination, we have to recursively find our way from this point */
-      if (route.gw_dst != dst)
-        getRouteRecursive(route.gw_dst, dst, links, latency);
-
-    }
-
-  }
-};
+}  }; // namespace simgrid::s4u
index fdba03e..f7b078e 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "simgrid/simix.h"
 #include "mc/mc.h"
-#include "simgrid/s4u/as.hpp"
+#include "simgrid/s4u/As.hpp"
 #include "simgrid/s4u/engine.hpp"
 
 XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface");
diff --git a/src/surf/AsImpl.cpp b/src/surf/AsImpl.cpp
new file mode 100644 (file)
index 0000000..36666af
--- /dev/null
@@ -0,0 +1,224 @@
+/* Copyright (c) 2006-2014. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* 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 "simgrid/s4u/As.hpp"
+#include "src/surf/AsImpl.hpp"
+#include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(AsImpl,surf, "Implementation of S4U autonomous systems");
+
+namespace simgrid {
+  namespace surf {
+
+    AsImpl::AsImpl(const char *name)
+    : As(name)
+    {
+    }
+    AsImpl::~AsImpl()
+    {
+      xbt_dynar_free(&upDownLinks);
+      delete netcard_;
+    }
+
+    xbt_dynar_t AsImpl::getOneLinkRoutes() {
+      return NULL;
+    }
+
+    /** @brief Get the common ancestor and its first childs in each line leading to src and dst */
+    static void find_common_ancestors(NetCard *src, NetCard *dst,
+        /* OUT */ AsImpl **common_ancestor, AsImpl **src_ancestor, AsImpl **dst_ancestor)
+    {
+    #define ROUTING_HIERARCHY_MAXDEPTH 32     /* increase if it is not enough */
+      AsImpl *path_src[ROUTING_HIERARCHY_MAXDEPTH];
+      AsImpl *path_dst[ROUTING_HIERARCHY_MAXDEPTH];
+      int index_src = 0;
+      int index_dst = 0;
+      AsImpl *current_src;
+      AsImpl *current_dst;
+      AsImpl *father;
+
+      /* (1) find the path to root of src and dst*/
+      AsImpl *src_as = src->containingAS();
+      AsImpl *dst_as = dst->containingAS();
+
+      xbt_assert(src_as, "Host %s must be in an AS", src->name());
+      xbt_assert(dst_as, "Host %s must be in an AS", dst->name());
+
+      /* (2) find the path to the root routing component */
+      for (AsImpl *current = src_as; current != NULL; current = static_cast<AsImpl*>(current->father())) {
+        xbt_assert(index_src < ROUTING_HIERARCHY_MAXDEPTH, "ROUTING_HIERARCHY_MAXDEPTH should be increased for element %s", src->name());
+        path_src[index_src++] = current;
+      }
+      for (AsImpl *current = dst_as; current != NULL; current = static_cast<AsImpl*>(current->father())) {
+        xbt_assert(index_dst < ROUTING_HIERARCHY_MAXDEPTH,"ROUTING_HIERARCHY_MAXDEPTH should be increased for path_dst");
+        path_dst[index_dst++] = current;
+      }
+
+      /* (3) find the common father.
+       * Before that, index_src and index_dst may be different, they both point to NULL in path_src/path_dst
+       * So we move them down simultaneously as long as they point to the same content.
+       */
+      do {
+        current_src = path_src[--index_src];
+        current_dst = path_dst[--index_dst];
+      } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
+
+      /* (4) if we did not find a difference (index_src or index_dst went to 0), both elements are in the same AS */
+      if (current_src == current_dst)
+        father = current_src;
+      else // we found a difference
+        father = path_src[index_src + 1];
+
+      /* (5) result generation */
+      *common_ancestor = father;    /* the common father of src and dst */
+      *src_ancestor = current_src;  /* the first different father of src */
+      *dst_ancestor = current_dst;  /* the first different father of dst */
+    #undef ROUTING_HIERARCHY_MAXDEPTH
+    }
+
+
+    /* PRECONDITION: this is the common ancestor of src and dst */
+    std::vector<surf::Link*> *AsImpl::getBypassRoute(surf::NetCard *src, surf::NetCard *dst)
+    {
+      // If never set a bypass route return NULL without any further computations
+      XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name(), dst->name());
+      if (bypassRoutes_.empty())
+        return nullptr;
+
+      std::vector<surf::Link*> *bypassedRoute = nullptr;
+
+      if(dst->containingAS() == this && src->containingAS() == this ){
+        if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) {
+          bypassedRoute = bypassRoutes_.at({src->name(),dst->name()});
+          XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size());
+        }
+        return bypassedRoute;
+      }
+
+      /* (2) find the path to the root routing component */
+      std::vector<As*> path_src;
+      As *current = src->containingAS();
+      while (current != NULL) {
+        path_src.push_back(current);
+        current = current->father_;
+      }
+
+      std::vector<As*> path_dst;
+      current = dst->containingAS();
+      while (current != NULL) {
+        path_dst.push_back(current);
+        current = current->father_;
+      }
+
+      /* (3) find the common father */
+      while (path_src.size() > 1 && path_dst.size() >1
+          && path_src.at(path_src.size() -1) == path_dst.at(path_dst.size() -1)) {
+        path_src.pop_back();
+        path_dst.pop_back();
+      }
+
+      int max_index_src = path_src.size() - 1;
+      int max_index_dst = path_dst.size() - 1;
+
+      int max_index = std::max(max_index_src, max_index_dst);
+
+      for (int max = 0; max <= max_index; max++) {
+        for (int i = 0; i < max; i++) {
+          if (i <= max_index_src && max <= max_index_dst) {
+            const std::pair<std::string, std::string> key = {path_src.at(i)->name(), path_dst.at(max)->name()};
+            if (bypassRoutes_.find(key) != bypassRoutes_.end())
+              bypassedRoute = bypassRoutes_.at(key);
+          }
+          if (bypassedRoute)
+            break;
+          if (max <= max_index_src && i <= max_index_dst) {
+            const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(i)->name()};
+            if (bypassRoutes_.find(key) != bypassRoutes_.end())
+              bypassedRoute = bypassRoutes_.at(key);
+          }
+          if (bypassedRoute)
+            break;
+        }
+
+        if (bypassedRoute)
+          break;
+
+        if (max <= max_index_src && max <= max_index_dst) {
+          const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(max)->name()};
+          if (bypassRoutes_.find(key) != bypassRoutes_.end())
+            bypassedRoute = bypassRoutes_.at(key);
+        }
+        if (bypassedRoute)
+          break;
+      }
+
+      return bypassedRoute;
+    }
+
+    /**
+     * \brief Recursive function for getRouteAndLatency
+     *
+     * \param src the source host
+     * \param dst the destination host
+     * \param links Where to store the links and the gw information
+     * \param latency If not NULL, the latency of all links will be added in it
+     */
+    void AsImpl::getRouteRecursive(surf::NetCard *src, surf::NetCard *dst,
+        /* OUT */ std::vector<surf::Link*> * links, double *latency)
+    {
+      s_sg_platf_route_cbarg_t route;
+      memset(&route,0,sizeof(route));
+
+      XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src->name(), dst->name());
+
+      /* Find how src and dst are interconnected */
+      AsImpl *common_ancestor, *src_ancestor, *dst_ancestor;
+      find_common_ancestors(src, dst, &common_ancestor, &src_ancestor, &dst_ancestor);
+      XBT_DEBUG("elements_father: common ancestor '%s' src ancestor '%s' dst ancestor '%s'",
+          common_ancestor->name(), src_ancestor->name(), dst_ancestor->name());
+
+      /* Check whether a direct bypass is defined. If so, use it and bail out */
+      std::vector<surf::Link*> *bypassed_route = common_ancestor->getBypassRoute(src, dst);
+      if (nullptr != bypassed_route) {
+        for (surf::Link *link : *bypassed_route) {
+          links->push_back(link);
+          if (latency)
+            *latency += link->getLatency();
+        }
+        return;
+      }
+
+      /* If src and dst are in the same AS, life is good */
+      if (src_ancestor == dst_ancestor) {       /* SURF_ROUTING_BASE */
+        route.link_list = links;
+        common_ancestor->getRouteAndLatency(src, dst, &route, latency);
+        return;
+      }
+
+      /* Not in the same AS, no bypass. We'll have to find our path between the ASes recursively*/
+
+      route.link_list = new std::vector<surf::Link*>();
+
+      common_ancestor->getRouteAndLatency(src_ancestor->netcard_, dst_ancestor->netcard_, &route, latency);
+      xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
+          "bad gateways for route from \"%s\" to \"%s\"", src->name(), dst->name());
+
+      /* If source gateway is not our source, we have to recursively find our way up to this point */
+      if (src != route.gw_src)
+        getRouteRecursive(src, route.gw_src, links, latency);
+      for (auto link: *route.link_list)
+        links->push_back(link);
+
+      /* If dest gateway is not our destination, we have to recursively find our way from this point */
+      if (route.gw_dst != dst)
+        getRouteRecursive(route.gw_dst, dst, links, latency);
+
+    }
+
+  }
+};
similarity index 74%
rename from include/simgrid/s4u/as.hpp
rename to src/surf/AsImpl.hpp
index b0b6f98..b77bac6 100644 (file)
@@ -3,46 +3,36 @@
 /* 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. */
 
-#ifndef SIMGRID_S4U_AS_HPP
-#define SIMGRID_S4U_AS_HPP
+#ifndef SIMGRID_SURF_AS_HPP
+#define SIMGRID_SURF_AS_HPP
 
 #include "xbt/base.h"
 #include "xbt/graph.h"
 
 #include "simgrid/s4u/forward.hpp"
+#include "simgrid/s4u/As.hpp"
 #include <vector>
 #include <map>
 
 #include "src/surf/xml/platf_private.hpp" // FIXME: kill sg_platf_route_cbarg_t to remove that UGLY include
 
 namespace simgrid {
-
 namespace surf {
   class Link;
   class NetCard;
   class RoutingPlatf; // FIXME: KILLME
-}
-namespace s4u {
 
 /** @brief Autonomous Systems
  *
  * An AS is a network container, in charge of routing information between elements (hosts) and to the nearby ASes.
  * In SimGrid, there is a hierarchy of ASes, with a unique root AS (that you can retrieve from the s4u::Engine).
  */
-XBT_PUBLIC_CLASS As {
+XBT_PUBLIC_CLASS AsImpl : public s4u::As {
+  friend simgrid::surf::RoutingPlatf;
 protected:
-  As(const char *name);
-  virtual ~As();
+  AsImpl(const char *name);
+  ~AsImpl();
   
-public:
-  /** @brief Seal your AS once you're done adding content, and before routing stuff through it */
-  virtual void Seal();
-  char *name();
-  As *father();;
-  xbt_dict_t children(); // Sub AS
-  xbt_dynar_t hosts();   // my content
-
-
 public:
   /**
    * @brief Probe the routing path between two points
@@ -71,13 +61,10 @@ public:
   virtual void getRouteAndLatency(surf::NetCard *src, surf::NetCard *dst, sg_platf_route_cbarg_t into, double *latency)=0;
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
   virtual xbt_dynar_t getOneLinkRoutes();
+  std::vector<surf::Link*> *getBypassRoute(surf::NetCard *src, surf::NetCard *dst);
 
   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
-
-  /* Add content to the AS, at parsing time. It should be sealed afterward. */
-  virtual int addComponent(surf::NetCard *elm); /* A host, a router or an AS, whatever */
-  virtual void addRoute(sg_platf_route_cbarg_t route);
-  void addBypassRoute(sg_platf_route_cbarg_t e_route);
+  static void getRouteRecursive(surf::NetCard *src, surf::NetCard *dst, /* OUT */ std::vector<surf::Link*> * links, double *latency);
 
 
   enum RoutingKind {
@@ -88,24 +75,9 @@ public:
   /* FIXME: protect the following fields once the construction madness is sorted out */
   RoutingKind hierarchy_ = ROUTING_NULL;
   xbt_dynar_t upDownLinks = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
-  As *father_ = nullptr;
   surf::NetCard *netcard_ = nullptr; // Our representative in the father AS
-
-protected:
-  char *name_ = nullptr;
-  xbt_dict_t children_ = xbt_dict_new_homogeneous(NULL); // sub-ASes
-  xbt_dynar_t vertices_ = xbt_dynar_new(sizeof(char*),NULL); // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
-
-private:
-  bool sealed_ = false; // We cannot add more content when sealed
-
-  friend surf::RoutingPlatf;
-  std::map<std::pair<std::string, std::string>, std::vector<surf::Link*>*> bypassRoutes_; // srcName x dstName -> route
-  static void getRouteRecursive(surf::NetCard *src, surf::NetCard *dst, /* OUT */ std::vector<surf::Link*> * links, double *latency);
-  std::vector<surf::Link*> *getBypassRoute(surf::NetCard *src, surf::NetCard *dst);
-
 };
 
 }}; // Namespace simgrid::s4u
 
-#endif /* SIMGRID_S4U_AS_HPP */
+#endif /* SIMGRID_SURF_AS_HPP */
index 1512a6a..4523960 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "src/instr/instr_private.h"
 
-#include "simgrid/s4u/as.hpp"
+#include "src/surf/AsImpl.hpp"
 #include "simgrid/s4u/engine.hpp"
 #include "surf/surf.h"
 #include "src/surf/xml/platf_private.hpp"
@@ -152,7 +152,7 @@ static void recursiveGraphExtraction (simgrid::s4u::As *as, container_t containe
     xbt_dict_cursor_t cursor = NULL;
     char *edge_name;
 
-    as->getGraph(graph, nodes, edges);
+    static_cast<simgrid::surf::AsImpl*>(as)->getGraph(graph, nodes, edges);
     xbt_dict_foreach(edges,cursor,edge_name,edge) {
         linkContainers(
           PJ_container_get((const char*) edge->src->data),
@@ -459,7 +459,7 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb
     }
   }
 
-  as->getGraph(graph, nodes, edges);
+  static_cast<simgrid::surf::AsImpl*>(as)->getGraph(graph, nodes, edges);
 }
 
 xbt_graph_t instr_routing_platform_graph (void)
index dbd4db1..f86ef2c 100644 (file)
@@ -11,7 +11,7 @@
 #include "simgrid/sg_config.h"
 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
 
-#include "simgrid/s4u/as.hpp"
+#include "simgrid/s4u/As.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
 
index 62e4fad..666778e 100644 (file)
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "surf/surf_routing.h" // FIXME: brain dead public header
+#include "src/surf/AsImpl.hpp"
+
 #include "src/surf/surf_routing_cluster.hpp"
 #include "src/surf/surf_routing_cluster_torus.hpp"
 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
+#include "src/surf/surf_routing_dijkstra.hpp"
+#include "src/surf/surf_routing_floyd.hpp"
+#include "src/surf/surf_routing_full.hpp"
+#include "src/surf/surf_routing_vivaldi.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
@@ -41,6 +47,13 @@ simgrid::xbt::signal<void(void)> on_postparse;
 
 static int surf_parse_models_setup_already_called = 0;
 
+/** The current AS in the parsing */
+static simgrid::surf::AsImpl *current_routing = NULL;
+static simgrid::surf::AsImpl* routing_get_current()
+{
+  return current_routing;
+}
+
 /** Module management function: creates all internal data structures */
 void sg_platf_init(void) {
 }
@@ -62,9 +75,9 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
   xbt_assert(! sg_host_by_name(host->id),
       "Refusing to create a second host named '%s'.", host->id);
 
-  simgrid::s4u::As* current_routing = routing_get_current();
-  if (current_routing->hierarchy_ == simgrid::s4u::As::ROUTING_NULL)
-    current_routing->hierarchy_ = simgrid::s4u::As::ROUTING_BASE;
+  simgrid::surf::AsImpl* current_routing = routing_get_current();
+  if (current_routing->hierarchy_ == simgrid::surf::AsImpl::ROUTING_NULL)
+    current_routing->hierarchy_ = simgrid::surf::AsImpl::ROUTING_BASE;
 
   simgrid::surf::NetCard *netcard =
       new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing);
@@ -120,10 +133,10 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
  */
 void sg_platf_new_router(sg_platf_router_cbarg_t router)
 {
-  simgrid::s4u::As* current_routing = routing_get_current();
+  simgrid::surf::AsImpl* current_routing = routing_get_current();
 
-  if (current_routing->hierarchy_ == simgrid::s4u::As::ROUTING_NULL)
-    current_routing->hierarchy_ = simgrid::s4u::As::ROUTING_BASE;
+  if (current_routing->hierarchy_ == simgrid::surf::AsImpl::ROUTING_NULL)
+    current_routing->hierarchy_ = simgrid::surf::AsImpl::ROUTING_BASE;
   xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
              "Refusing to create a router named '%s': this name already describes a node.", router->id);
 
@@ -202,7 +215,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
 
   // What an inventive way of initializing the AS that I have as ancestor :-(
   sg_platf_new_AS_begin(&AS);
-  simgrid::s4u::As *current_routing = routing_get_current();
+  simgrid::surf::AsImpl *current_routing = routing_get_current();
   static_cast<AsCluster*>(current_routing)->parse_specific_arguments(cluster);
 
   if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
@@ -401,6 +414,15 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
 
   simgrid::surf::on_cluster(cluster);
 }
+void routing_cluster_add_backbone(simgrid::surf::Link* bb) {
+  simgrid::surf::AsCluster *cluster = dynamic_cast<simgrid::surf::AsCluster*>(current_routing);
+
+  xbt_assert(cluster, "Only hosts from Cluster can get a backbone.");
+  xbt_assert(nullptr == cluster->backbone_, "Cluster %s already has a backbone link!", cluster->name());
+
+  cluster->backbone_ = bb;
+  XBT_DEBUG("Add a backbone to AS '%s'", current_routing->name());
+}
 
 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage)
 {
@@ -603,6 +625,88 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
   current_property_set = NULL;
 }
 
+void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
+{
+  using simgrid::surf::NetCard;
+  using simgrid::surf::AsCluster;
+
+  char *host_id = NULL;
+  char *link_id = NULL;
+  char *router_id = NULL;
+
+  XBT_DEBUG(" ");
+  host_id = bprintf("peer_%s", peer->id);
+  link_id = bprintf("link_%s", peer->id);
+  router_id = bprintf("router_%s", peer->id);
+
+  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
+  s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
+  AS.id                    = peer->id;
+  AS.routing               = A_surfxml_AS_routing_Cluster;
+  sg_platf_new_AS_begin(&AS);
+
+  XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
+  s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
+  memset(&host, 0, sizeof(host));
+  host.id = host_id;
+
+  host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
+  xbt_dynar_push(host.speed_peak,&peer->speed);
+  host.pstate = 0;
+  //host.power_peak = peer->power;
+  host.speed_trace = peer->availability_trace;
+  host.state_trace = peer->state_trace;
+  host.core_amount = 1;
+  sg_platf_new_host(&host);
+  xbt_dynar_free(&host.speed_peak);
+
+  s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
+  memset(&link, 0, sizeof(link));
+  link.policy  = SURF_LINK_SHARED;
+  link.latency = peer->lat;
+
+  char* link_up = bprintf("%s_UP",link_id);
+  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_up,
+            peer->bw_out, peer->lat);
+  link.id = link_up;
+  link.bandwidth = peer->bw_out;
+  sg_platf_new_link(&link);
+
+  char* link_down = bprintf("%s_DOWN",link_id);
+  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_down,
+            peer->bw_in, peer->lat);
+  link.id = link_down;
+  link.bandwidth = peer->bw_in;
+  sg_platf_new_link(&link);
+
+  XBT_DEBUG("<host_link\tid=\"%s\"\tup=\"%s\"\tdown=\"%s\" />", host_id,link_up,link_down);
+  s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
+  memset(&host_link, 0, sizeof(host_link));
+  host_link.id        = host_id;
+  host_link.link_up   = link_up;
+  host_link.link_down = link_down;
+  sg_platf_new_hostlink(&host_link);
+
+  XBT_DEBUG("<router id=\"%s\"/>", router_id);
+  s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
+  memset(&router, 0, sizeof(router));
+  router.id = router_id;
+  router.coord = peer->coord;
+  sg_platf_new_router(&router);
+  static_cast<AsCluster*>(current_routing)->router_ = static_cast<NetCard*>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
+
+  XBT_DEBUG("</AS>");
+  sg_platf_new_AS_end();
+  XBT_DEBUG(" ");
+
+  //xbt_dynar_free(&tab_elements_num);
+  free(router_id);
+  free(host_id);
+  free(link_id);
+  free(link_up);
+  free(link_down);
+}
+
 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
 
 void sg_platf_end() {
@@ -678,6 +782,80 @@ static void surf_config_models_setup()
 
 }
 
+/**
+ * \brief Make a new routing component to the platform
+ *
+ * Add a new autonomous system to the platform. Any elements (such as host,
+ * router or sub-AS) added after this call and before the corresponding call
+ * to sg_platf_new_AS_close() will be added to this AS.
+ *
+ * Once this function was called, the configuration concerning the used
+ * models cannot be changed anymore.
+ *
+ * @param AS_id name of this autonomous system. Must be unique in the platform
+ * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
+ */
+void routing_AS_begin(sg_platf_AS_cbarg_t AS)
+{
+  XBT_DEBUG("routing_AS_begin");
+
+  xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL),
+      "Refusing to create a second AS called \"%s\".", AS->id);
+
+  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
+                            * any further config now that we created some real content */
+
+
+  /* search the routing model */
+  simgrid::surf::AsImpl *new_as = NULL;
+  switch(AS->routing){
+    case A_surfxml_AS_routing_Cluster:        new_as = new simgrid::surf::AsCluster(AS->id);        break;
+    case A_surfxml_AS_routing_ClusterTorus:   new_as = new simgrid::surf::AsClusterTorus(AS->id);   break;
+    case A_surfxml_AS_routing_ClusterFatTree: new_as = new simgrid::surf::AsClusterFatTree(AS->id); break;
+    case A_surfxml_AS_routing_Dijkstra:       new_as = new simgrid::surf::AsDijkstra(AS->id, 0);    break;
+    case A_surfxml_AS_routing_DijkstraCache:  new_as = new simgrid::surf::AsDijkstra(AS->id, 1);    break;
+    case A_surfxml_AS_routing_Floyd:          new_as = new simgrid::surf::AsFloyd(AS->id);          break;
+    case A_surfxml_AS_routing_Full:           new_as = new simgrid::surf::AsFull(AS->id);           break;
+    case A_surfxml_AS_routing_None:           new_as = new simgrid::surf::AsNone(AS->id);           break;
+    case A_surfxml_AS_routing_Vivaldi:        new_as = new simgrid::surf::AsVivaldi(AS->id);        break;
+    default:                                  xbt_die("Not a valid model!");                        break;
+  }
+
+  /* make a new routing component */
+  simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->name(), SURF_NETWORK_ELEMENT_AS, current_routing);
+
+  if (current_routing == NULL && routing_platf->root_ == NULL) {
+    /* it is the first one */
+    routing_platf->root_ = new_as;
+    netcard->setId(-1);
+  } else if (current_routing != NULL && routing_platf->root_ != NULL) {
+
+    xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id),
+               "The AS \"%s\" already exists", AS->id);
+    /* it is a part of the tree */
+    new_as->father_ = current_routing;
+    /* set the father behavior */
+    if (current_routing->hierarchy_ == simgrid::surf::AsImpl::ROUTING_NULL)
+      current_routing->hierarchy_ = simgrid::surf::AsImpl::ROUTING_RECURSIVE;
+    /* add to the sons dictionary */
+    xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, NULL);
+    /* add to the father element list */
+    netcard->setId(current_routing->addComponent(netcard));
+  } else {
+    THROWF(arg_error, 0, "All defined components must belong to a AS");
+  }
+
+  xbt_lib_set(as_router_lib, netcard->name(), ROUTING_ASR_LEVEL, (void *) netcard);
+  XBT_DEBUG("Having set name '%s' id '%d'", new_as->name(), netcard->id());
+
+  /* set the new current component of the tree */
+  current_routing = new_as;
+  current_routing->netcard_ = netcard;
+
+  simgrid::surf::netcardCreatedCallbacks(netcard);
+  simgrid::surf::asCreatedCallbacks(new_as);
+}
+
 void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
 {
   if (!surf_parse_models_setup_already_called) {
@@ -713,3 +891,40 @@ void sg_platf_new_AS_end()
   if (TRACE_is_enabled())
     sg_instr_AS_end();
 }
+/**
+ * \brief Specify that the current description of AS is finished
+ *
+ * Once you've declared all the content of your AS, you have to close
+ * it with this call. Your AS is not usable until you call this function.
+ */
+void routing_AS_end()
+{
+  xbt_assert(current_routing, "Cannot seal the current AS: none under construction");
+  current_routing->Seal();
+  current_routing = static_cast<simgrid::surf::AsImpl*>(current_routing->father());
+}
+
+/** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
+void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t netcard_arg)
+{
+  simgrid::surf::NetCard *netcard = sg_host_by_name(netcard_arg->id)->pimpl_netcard;
+  xbt_assert(netcard, "Host '%s' not found!", netcard_arg->id);
+  xbt_assert(dynamic_cast<simgrid::surf::AsCluster*>(current_routing) ||
+             dynamic_cast<simgrid::surf::AsVivaldi*>(current_routing),
+      "Only hosts from Cluster and Vivaldi ASes can get a host_link.");
+
+  s_surf_parsing_link_up_down_t link_up_down;
+  link_up_down.link_up = Link::byName(netcard_arg->link_up);
+  link_up_down.link_down = Link::byName(netcard_arg->link_down);
+
+  xbt_assert(link_up_down.link_up, "Link '%s' not found!",netcard_arg->link_up);
+  xbt_assert(link_up_down.link_down, "Link '%s' not found!",netcard_arg->link_down);
+
+  // If dynar is is greater than netcard id and if the host_link is already defined
+  if((int)xbt_dynar_length(current_routing->upDownLinks) > netcard->id() &&
+      xbt_dynar_get_as(current_routing->upDownLinks, netcard->id(), void*))
+  surf_parse_error("Host_link for '%s' is already defined!",netcard_arg->id);
+
+  XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name(), netcard->id());
+  xbt_dynar_set_as(current_routing->upDownLinks, netcard->id(), s_surf_parsing_link_up_down_t, link_up_down);
+}
index 4cd3d07..d9847e2 100644 (file)
@@ -10,6 +10,7 @@
 #include "simgrid/sg_config.h"
 #include "storage_interface.hpp"
 
+#include "src/surf/AsImpl.hpp"
 #include "src/surf/surf_routing_cluster_torus.hpp"
 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
 #include "src/surf/surf_routing_dijkstra.hpp"
@@ -68,38 +69,6 @@ simgrid::surf::NetCard *sg_netcard_by_name_or_null(const char *name)
 simgrid::surf::RoutingPlatf *routing_platf = NULL;
 
 
-/** The current AS in the parsing */
-static simgrid::s4u::As *current_routing = NULL;
-simgrid::s4u::As* routing_get_current()
-{
-  return current_routing;
-}
-
-/** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
-void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t netcard_arg)
-{
-  simgrid::surf::NetCard *netcard = sg_host_by_name(netcard_arg->id)->pimpl_netcard;
-  xbt_assert(netcard, "Host '%s' not found!", netcard_arg->id);
-  xbt_assert(dynamic_cast<simgrid::surf::AsCluster*>(current_routing) ||
-             dynamic_cast<simgrid::surf::AsVivaldi*>(current_routing),
-      "Only hosts from Cluster and Vivaldi ASes can get a host_link.");
-
-  s_surf_parsing_link_up_down_t link_up_down;
-  link_up_down.link_up = Link::byName(netcard_arg->link_up);
-  link_up_down.link_down = Link::byName(netcard_arg->link_down);
-
-  xbt_assert(link_up_down.link_up, "Link '%s' not found!",netcard_arg->link_up);
-  xbt_assert(link_up_down.link_down, "Link '%s' not found!",netcard_arg->link_down);
-
-  // If dynar is is greater than netcard id and if the host_link is already defined
-  if((int)xbt_dynar_length(current_routing->upDownLinks) > netcard->id() &&
-      xbt_dynar_get_as(current_routing->upDownLinks, netcard->id(), void*))
-  surf_parse_error("Host_link for '%s' is already defined!",netcard_arg->id);
-
-  XBT_DEBUG("Push Host_link for host '%s' to position %d", netcard->name(), netcard->id());
-  xbt_dynar_set_as(current_routing->upDownLinks, netcard->id(), s_surf_parsing_link_up_down_t, link_up_down);
-}
-
 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
 {
   tmgr_trace_t tmgr_trace;
@@ -113,93 +82,6 @@ void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
   xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL);
 }
 
-/**
- * \brief Make a new routing component to the platform
- *
- * Add a new autonomous system to the platform. Any elements (such as host,
- * router or sub-AS) added after this call and before the corresponding call
- * to sg_platf_new_AS_close() will be added to this AS.
- *
- * Once this function was called, the configuration concerning the used
- * models cannot be changed anymore.
- *
- * @param AS_id name of this autonomous system. Must be unique in the platform
- * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
- */
-void routing_AS_begin(sg_platf_AS_cbarg_t AS)
-{
-  XBT_DEBUG("routing_AS_begin");
-
-  xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL),
-      "Refusing to create a second AS called \"%s\".", AS->id);
-
-  _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent
-                            * any further config now that we created some real content */
-
-
-  /* search the routing model */
-  simgrid::s4u::As *new_as = NULL;
-  switch(AS->routing){
-    case A_surfxml_AS_routing_Cluster:        new_as = new simgrid::surf::AsCluster(AS->id);        break;
-    case A_surfxml_AS_routing_ClusterTorus:   new_as = new simgrid::surf::AsClusterTorus(AS->id);   break;
-    case A_surfxml_AS_routing_ClusterFatTree: new_as = new simgrid::surf::AsClusterFatTree(AS->id); break;
-    case A_surfxml_AS_routing_Dijkstra:       new_as = new simgrid::surf::AsDijkstra(AS->id, 0);    break;
-    case A_surfxml_AS_routing_DijkstraCache:  new_as = new simgrid::surf::AsDijkstra(AS->id, 1);    break;
-    case A_surfxml_AS_routing_Floyd:          new_as = new simgrid::surf::AsFloyd(AS->id);          break;
-    case A_surfxml_AS_routing_Full:           new_as = new simgrid::surf::AsFull(AS->id);           break;
-    case A_surfxml_AS_routing_None:           new_as = new simgrid::surf::AsNone(AS->id);           break;
-    case A_surfxml_AS_routing_Vivaldi:        new_as = new simgrid::surf::AsVivaldi(AS->id);        break;
-    default:                                  xbt_die("Not a valid model!");                        break;
-  }
-
-  /* make a new routing component */
-  simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->name(), SURF_NETWORK_ELEMENT_AS, current_routing);
-
-  if (current_routing == NULL && routing_platf->root_ == NULL) {
-    /* it is the first one */
-    routing_platf->root_ = new_as;
-    netcard->setId(-1);
-  } else if (current_routing != NULL && routing_platf->root_ != NULL) {
-
-    xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id),
-               "The AS \"%s\" already exists", AS->id);
-    /* it is a part of the tree */
-    new_as->father_ = current_routing;
-    /* set the father behavior */
-    if (current_routing->hierarchy_ == simgrid::s4u::As::ROUTING_NULL)
-      current_routing->hierarchy_ = simgrid::s4u::As::ROUTING_RECURSIVE;
-    /* add to the sons dictionary */
-    xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, NULL);
-    /* add to the father element list */
-    netcard->setId(current_routing->addComponent(netcard));
-  } else {
-    THROWF(arg_error, 0, "All defined components must belong to a AS");
-  }
-
-  xbt_lib_set(as_router_lib, netcard->name(), ROUTING_ASR_LEVEL, (void *) netcard);
-  XBT_DEBUG("Having set name '%s' id '%d'", new_as->name(), netcard->id());
-
-  /* set the new current component of the tree */
-  current_routing = new_as;
-  current_routing->netcard_ = netcard;
-
-  simgrid::surf::netcardCreatedCallbacks(netcard);
-  simgrid::surf::asCreatedCallbacks(new_as);
-}
-
-/**
- * \brief Specify that the current description of AS is finished
- *
- * Once you've declared all the content of your AS, you have to close
- * it with this call. Your AS is not usable until you call this function.
- */
-void routing_AS_end()
-{
-  xbt_assert(current_routing, "Cannot seal the current AS: none under construction");
-  current_routing->Seal();
-  current_routing = current_routing->father();
-}
-
 namespace simgrid {
 namespace surf {
 
@@ -221,10 +103,10 @@ void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Li
 {
   XBT_DEBUG("getRouteAndLatency from %s to %s", src->name(), dst->name());
 
-  s4u::As::getRouteRecursive(src, dst, route, latency);
+  AsImpl::getRouteRecursive(src, dst, route, latency);
 }
 
-static xbt_dynar_t _recursiveGetOneLinkRoutes(s4u::As *as)
+static xbt_dynar_t _recursiveGetOneLinkRoutes(surf::AsImpl *as)
 {
   xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
 
@@ -236,7 +118,7 @@ static xbt_dynar_t _recursiveGetOneLinkRoutes(s4u::As *as)
   //recursing
   char *key;
   xbt_dict_cursor_t cursor = NULL;
-  AS_t rc_child;
+  AsImpl *rc_child;
   xbt_dict_foreach(as->children(), cursor, key, rc_child) {
     xbt_dynar_t onelink_child = _recursiveGetOneLinkRoutes(rc_child);
     if (onelink_child)
@@ -261,16 +143,6 @@ void routing_model_create(Link *loopback)
 /* ************************************************************************** */
 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
 
-void routing_cluster_add_backbone(simgrid::surf::Link* bb) {
-  simgrid::surf::AsCluster *cluster = dynamic_cast<simgrid::surf::AsCluster*>(current_routing);
-
-  xbt_assert(cluster, "Only hosts from Cluster can get a backbone.");
-  xbt_assert(nullptr == cluster->backbone_, "Cluster %s already has a backbone link!", cluster->name());
-
-  cluster->backbone_ = bb;
-  XBT_DEBUG("Add a backbone to AS '%s'", current_routing->name());
-}
-
 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
 {
   int start, end, i;
@@ -340,88 +212,6 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
   xbt_dynar_free(&radical_elements);
 }
 
-void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
-{
-  using simgrid::surf::NetCard;
-  using simgrid::surf::AsCluster;
-
-  char *host_id = NULL;
-  char *link_id = NULL;
-  char *router_id = NULL;
-
-  XBT_DEBUG(" ");
-  host_id = bprintf("peer_%s", peer->id);
-  link_id = bprintf("link_%s", peer->id);
-  router_id = bprintf("router_%s", peer->id);
-
-  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
-  s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
-  AS.id                    = peer->id;
-  AS.routing               = A_surfxml_AS_routing_Cluster;
-  sg_platf_new_AS_begin(&AS);
-
-  XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
-  s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
-  memset(&host, 0, sizeof(host));
-  host.id = host_id;
-
-  host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
-  xbt_dynar_push(host.speed_peak,&peer->speed);
-  host.pstate = 0;
-  //host.power_peak = peer->power;
-  host.speed_trace = peer->availability_trace;
-  host.state_trace = peer->state_trace;
-  host.core_amount = 1;
-  sg_platf_new_host(&host);
-  xbt_dynar_free(&host.speed_peak);
-
-  s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
-  memset(&link, 0, sizeof(link));
-  link.policy  = SURF_LINK_SHARED;
-  link.latency = peer->lat;
-
-  char* link_up = bprintf("%s_UP",link_id);
-  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_up,
-            peer->bw_out, peer->lat);
-  link.id = link_up;
-  link.bandwidth = peer->bw_out;
-  sg_platf_new_link(&link);
-
-  char* link_down = bprintf("%s_DOWN",link_id);
-  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_down,
-            peer->bw_in, peer->lat);
-  link.id = link_down;
-  link.bandwidth = peer->bw_in;
-  sg_platf_new_link(&link);
-
-  XBT_DEBUG("<host_link\tid=\"%s\"\tup=\"%s\"\tdown=\"%s\" />", host_id,link_up,link_down);
-  s_sg_platf_host_link_cbarg_t host_link = SG_PLATF_HOST_LINK_INITIALIZER;
-  memset(&host_link, 0, sizeof(host_link));
-  host_link.id        = host_id;
-  host_link.link_up   = link_up;
-  host_link.link_down = link_down;
-  sg_platf_new_hostlink(&host_link);
-
-  XBT_DEBUG("<router id=\"%s\"/>", router_id);
-  s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
-  memset(&router, 0, sizeof(router));
-  router.id = router_id;
-  router.coord = peer->coord;
-  sg_platf_new_router(&router);
-  static_cast<AsCluster*>(current_routing)->router_ = static_cast<NetCard*>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
-
-  XBT_DEBUG("</AS>");
-  sg_platf_new_AS_end();
-  XBT_DEBUG(" ");
-
-  //xbt_dynar_free(&tab_elements_num);
-  free(router_id);
-  free(host_id);
-  free(link_id);
-  free(link_up);
-  free(link_down);
-}
-
 static void check_disk_attachment()
 {
   xbt_lib_cursor_t cursor;
index cb29f19..af8f610 100644 (file)
@@ -12,8 +12,9 @@
 
 #include "surf_interface.hpp"
 #include "src/surf/xml/platf_private.hpp" // FIXME: including this here is pure madness. KILKILKIL XML.
-#include <float.h>
+#include "src/surf/AsImpl.hpp"
 
+#include <float.h>
 #include <vector>
 #include <map>
 
@@ -45,7 +46,7 @@ public:
   virtual int id()=0; // Our rank in the vertices_ array of our containing AS.
   virtual void setId(int id)=0;
   virtual char *name()=0;
-  virtual s4u::As *containingAS()=0; // This is the AS in which I am
+  virtual AsImpl *containingAS()=0; // This is the AS in which I am
   virtual bool isAS()=0;
   virtual bool isHost()=0;
   virtual bool isRouter()=0;
@@ -53,7 +54,7 @@ public:
 
 struct XBT_PRIVATE NetCardImpl : public NetCard {
 public:
-  NetCardImpl(const char *name, e_surf_network_element_type_t componentType, s4u::As *as)
+  NetCardImpl(const char *name, e_surf_network_element_type_t componentType, AsImpl *as)
   : name_(xbt_strdup(name)),
     componentType_(componentType),
     containingAS_(as)
@@ -63,7 +64,7 @@ public:
   int id()           override {return id_;}
   void setId(int id) override {id_ = id;}
   char *name()       override {return name_;}
-  s4u::As *containingAS() override {return containingAS_;}
+  AsImpl *containingAS() override {return containingAS_;}
 
   bool isAS()        override {return componentType_ == SURF_NETWORK_ELEMENT_AS;}
   bool isHost()      override {return componentType_ == SURF_NETWORK_ELEMENT_HOST;}
@@ -73,7 +74,7 @@ private:
   int id_ = -1;
   char *name_;
   e_surf_network_element_type_t componentType_;
-  s4u::As *containingAS_;
+  AsImpl *containingAS_;
 };
 
 /** @ingroup SURF_routing_interface
@@ -95,7 +96,7 @@ XBT_PUBLIC_CLASS RoutingPlatf {
 public:
   RoutingPlatf(Link *loopback);
   ~RoutingPlatf();
-  s4u::As *root_ = nullptr;
+  AsImpl *root_ = nullptr;
   Link *loopback_;
   xbt_dynar_t getOneLinkRoutes(void);
   void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
index 4fe6acc..cbacc5a 100644 (file)
@@ -32,7 +32,7 @@ namespace simgrid {
 namespace surf {
   
 AsRoutedGraph::AsRoutedGraph(const char*name)
-  : As(name)
+  : AsImpl(name)
 {
 }
 
@@ -108,9 +108,9 @@ namespace surf {
         if (route->link_list->size() == 1) {
           Link *link = route->link_list->at(0);
           Onelink *onelink;
-          if (hierarchy_ == s4u::As::ROUTING_BASE)
+          if (hierarchy_ == AsImpl::ROUTING_BASE)
             onelink = new Onelink(link, src_elm, dst_elm);
-          else if (hierarchy_ == s4u::As::ROUTING_RECURSIVE)
+          else if (hierarchy_ == AsImpl::ROUTING_RECURSIVE)
             onelink = new Onelink(link, route->gw_src, route->gw_dst);
           else
             onelink = new Onelink(link, NULL, NULL);
@@ -184,7 +184,7 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
 /* ************************************************************************** */
 /* ************************* GENERIC AUX FUNCTIONS ************************** */
 /* change a route containing link names into a route containing link entities */
-sg_platf_route_cbarg_t AsRoutedGraph::newExtendedRoute(s4u::As::RoutingKind hierarchy,
+sg_platf_route_cbarg_t AsRoutedGraph::newExtendedRoute(AsImpl::RoutingKind hierarchy,
     sg_platf_route_cbarg_t routearg, int change_order)
 {
 
@@ -193,10 +193,10 @@ sg_platf_route_cbarg_t AsRoutedGraph::newExtendedRoute(s4u::As::RoutingKind hier
   result = xbt_new0(s_sg_platf_route_cbarg_t, 1);
   result->link_list = new std::vector<Link*>();
 
-  xbt_assert(hierarchy == s4u::As::ROUTING_BASE || hierarchy == s4u::As::ROUTING_RECURSIVE,
+  xbt_assert(hierarchy == AsImpl::ROUTING_BASE || hierarchy == AsImpl::ROUTING_RECURSIVE,
       "The hierarchy of this AS is neither BASIC nor RECURSIVE, I'm lost here.");
 
-  if (hierarchy == s4u::As::ROUTING_RECURSIVE) {
+  if (hierarchy == AsImpl::ROUTING_RECURSIVE) {
     xbt_assert(routearg->gw_src && routearg->gw_dst, "NULL is obviously a deficient gateway");
 
     result->gw_src = routearg->gw_src;
index c21833d..42793ce 100644 (file)
@@ -7,7 +7,7 @@
 #include <xbt/base.h>
 
 #include "surf_routing.hpp"
-#include "simgrid/s4u/as.hpp"
+#include "src/surf/AsImpl.hpp"
 
 #ifndef SURF_ROUTING_GENERIC_HPP_
 #define SURF_ROUTING_GENERIC_HPP_
@@ -17,7 +17,7 @@ namespace surf {
 
 class XBT_PRIVATE AsRoutedGraph;
 
-class XBT_PRIVATE AsRoutedGraph : public s4u::As {
+class XBT_PRIVATE AsRoutedGraph : public AsImpl {
 public:
   AsRoutedGraph(const char*name);
   ~AsRoutedGraph();
@@ -25,7 +25,7 @@ public:
   xbt_dynar_t getOneLinkRoutes() override;
 
   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) override;
-  virtual sg_platf_route_cbarg_t newExtendedRoute(s4u::As::RoutingKind hierarchy, sg_platf_route_cbarg_t routearg, int change_order);
+  virtual sg_platf_route_cbarg_t newExtendedRoute(AsImpl::RoutingKind hierarchy, sg_platf_route_cbarg_t routearg, int change_order);
 protected:
   void getRouteCheckParams(NetCard *src, NetCard *dst);
   void addRouteCheckParams(sg_platf_route_cbarg_t route);
index 3cdfdb0..c6a21e1 100644 (file)
@@ -15,7 +15,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
 namespace simgrid {
 namespace surf {
   AsCluster::AsCluster(const char*name)
-    : As(name)
+    : AsImpl(name)
   {}
 
 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
index b3f283a..ef11fa9 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "surf_routing.hpp"
 #include "network_interface.hpp"
-#include "simgrid/s4u/as.hpp"
+#include "src/surf/AsImpl.hpp"
 
 namespace simgrid {
 namespace surf {
@@ -25,7 +25,7 @@ class XBT_PRIVATE AsCluster;
 /* ************************************************** */
 /* **************  Cluster ROUTING   **************** */
 
-class AsCluster: public s4u::As {
+class AsCluster: public AsImpl {
 public:
   AsCluster(const char*name);
 
index 1a7521e..df53419 100644 (file)
@@ -51,7 +51,7 @@ void AsDijkstra::Seal()
     graphNodeMap_ = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
 
   /* Add the loopback if needed */
-  if (routing_platf->loopback_ && hierarchy_ == s4u::As::ROUTING_BASE) {
+  if (routing_platf->loopback_ && hierarchy_ == AsImpl::ROUTING_BASE) {
     xbt_dynar_foreach(xbt_graph_get_nodes(routeGraph_), cursor, node) {
       xbt_edge_t edge = NULL;
 
@@ -259,7 +259,7 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
     if (v == dst_node_id)
       first_gw = gw_dst;
 
-    if (hierarchy_ == s4u::As::ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst->name(), prev_gw_src->name())) {
+    if (hierarchy_ == AsImpl::ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst->name(), prev_gw_src->name())) {
       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, NULL);
@@ -280,7 +280,7 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
     size++;
   }
 
-  if (hierarchy_ == s4u::As::ROUTING_RECURSIVE) {
+  if (hierarchy_ == AsImpl::ROUTING_RECURSIVE) {
     route->gw_src = gw_src;
     route->gw_dst = first_gw;
   }
index 705a648..dc5c9d7 100644 (file)
@@ -57,7 +57,7 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar
     cur = pred;
   } while (cur != src->id());
 
-  if (hierarchy_ == s4u::As::ROUTING_RECURSIVE) {
+  if (hierarchy_ == AsImpl::ROUTING_RECURSIVE) {
     route->gw_src = xbt_dynar_getlast_as(route_stack, sg_platf_route_cbarg_t)->gw_src;
     route->gw_dst = xbt_dynar_getfirst_as(route_stack, sg_platf_route_cbarg_t)->gw_dst;
   }
@@ -66,7 +66,7 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar
   while (!xbt_dynar_is_empty(route_stack)) {
     sg_platf_route_cbarg_t e_route = xbt_dynar_pop_as(route_stack, sg_platf_route_cbarg_t);
 
-    if (hierarchy_ == s4u::As::ROUTING_RECURSIVE && prev_dst_gw != NULL && strcmp(prev_dst_gw->name(), e_route->gw_src->name())) {
+    if (hierarchy_ == AsImpl::ROUTING_RECURSIVE && prev_dst_gw != NULL && strcmp(prev_dst_gw->name(), e_route->gw_src->name())) {
       routing_platf->getRouteAndLatency(prev_dst_gw, e_route->gw_src, route->link_list, lat);
     }
 
@@ -169,7 +169,7 @@ void AsFloyd::Seal(){
   }
 
   /* Add the loopback if needed */
-  if (routing_platf->loopback_ && hierarchy_ == s4u::As::ROUTING_BASE) {
+  if (routing_platf->loopback_ && hierarchy_ == AsImpl::ROUTING_BASE) {
     for (unsigned int i = 0; i < table_size; i++) {
       sg_platf_route_cbarg_t e_route = TO_FLOYD_LINK(i, i);
       if (!e_route) {
index 35468f1..a63a2b6 100644 (file)
@@ -30,7 +30,7 @@ void AsFull::Seal() {
     routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
 
   /* Add the loopback if needed */
-  if (routing_platf->loopback_ && hierarchy_ == s4u::As::ROUTING_BASE) {
+  if (routing_platf->loopback_ && hierarchy_ == AsImpl::ROUTING_BASE) {
     for (i = 0; i < table_size; i++) {
       e_route = TO_ROUTE_FULL(i, i);
       if (!e_route) {
index 1e9014f..3ef381f 100644 (file)
@@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf");
 namespace simgrid {
 namespace surf {
 AsNone::AsNone(const char*name)
-  : As(name)
+  : AsImpl(name)
 {}
 AsNone::~AsNone()
 {}
@@ -22,7 +22,7 @@ void AsNone::getRouteAndLatency(NetCard * /*src*/, NetCard * /*dst*/,
 
 void AsNone::getGraph(xbt_graph_t /*graph*/, xbt_dict_t /*nodes*/, xbt_dict_t /*edges*/)
 {
-  XBT_INFO("No routing no graph");
+  XBT_ERROR("No routing no graph");
 }
 }
 }
index 78716e7..82fdd85 100644 (file)
@@ -4,11 +4,7 @@
 /* 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/base.h>
-
-#include "surf_routing.hpp"
-#include "simgrid/s4u/as.hpp"
-
+#include "src/surf/AsImpl.hpp"
 
 #ifndef SURF_ROUTING_NONE_HPP_
 #define SURF_ROUTING_NONE_HPP_
@@ -17,7 +13,7 @@ namespace simgrid {
 namespace surf {
 
 /** No specific routing. Mainly useful with the constant network model */
-class XBT_PRIVATE AsNone : public s4u::As {
+class XBT_PRIVATE AsNone : public AsImpl {
 public:
   AsNone(const char*name);
   ~AsNone();
index 3ff896b..f80fb19 100644 (file)
@@ -247,7 +247,6 @@ typedef struct probabilist_event_generator *probabilist_event_generator_t;
 void routing_AS_begin(sg_platf_AS_cbarg_t AS);
 void routing_AS_end(void);
 void routing_cluster_add_backbone(Link* bb);
-AS_t routing_get_current();
 /*** END of the parsing cruft ***/
 
 XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
index e50a798..e421078 100644 (file)
@@ -60,6 +60,7 @@ set(EXTRA_DIST
   src/surf/xml/simgrid_dtd.h
   src/surf/xml/simgrid_dtd.c
   src/surf/xml/surfxml_sax_cb.cpp
+  src/surf/AsImpl.hpp
   src/surf/storage_interface.hpp
   src/surf/storage_n11.hpp
   src/surf/surf_interface.hpp
@@ -291,6 +292,7 @@ set(NS3_SRC
   )
 
 set(SURF_SRC
+  src/surf/AsImpl.cpp
   src/surf/cpu_cas01.cpp
   src/surf/cpu_interface.cpp
   src/surf/cpu_ti.cpp
@@ -641,7 +643,7 @@ set(headers_to_install
   include/simgrid/link.h
   include/simgrid/s4u/forward.hpp
   include/simgrid/s4u/actor.hpp
-  include/simgrid/s4u/as.hpp
+  include/simgrid/s4u/As.hpp
   include/simgrid/s4u/async.hpp
   include/simgrid/s4u/comm.hpp
   include/simgrid/s4u/engine.hpp