Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanups in routing
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Feb 2016 11:05:41 +0000 (12:05 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Feb 2016 11:06:04 +0000 (12:06 +0100)
- Make the link field of sg_platf_route_cbarg_t a vector<Link*>
  instead of a dynar.

- This dynar used to contain sometimes links (when computing the
  RouteAndLatency) and sometimes link names (when parsing).

- When parsing, the AS were in charge of checking that the links
  which names are given exist. Now, the parsing code has to deal with
  its own mess, to pass the expected Link*.

The situation around this data structure is still very messy because:
 - src and dst are the names while src_gw and dst_gw are the netcards
 - not all the fields are used in all usages:
   - src/dst not used in data stored in floyd/dijkstra
   - gw_* not used when adding a route (only for ASroute)
   - gw_* not used in the data stored in floyd/dijkstra but in the
     return value of getRouteAndLatency for these models.

Ultimately, this data structure should be limited to the xml world,
and proper replacement designed for each situations.

21 files changed:
src/bindings/lua/lua_platf.cpp
src/instr/instr_interface.cpp
src/simdag/sd_workstation.cpp
src/surf/network_cm02.cpp
src/surf/network_ns3.cpp
src/surf/network_ns3.hpp
src/surf/ptask_L07.cpp
src/surf/surf_private.h
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp
src/surf/surf_routing_RoutedGraph.cpp
src/surf/surf_routing_cluster.cpp
src/surf/surf_routing_cluster_fat_tree.cpp
src/surf/surf_routing_cluster_torus.cpp
src/surf/surf_routing_dijkstra.cpp
src/surf/surf_routing_floyd.cpp
src/surf/surf_routing_full.cpp
src/surf/surf_routing_vivaldi.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp
teshsuite/simdag/platforms/flatifier.cpp

index 8d07cfb..ec52f01 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "lua_private.h"
 #include "src/surf/xml/platf_private.hpp"
+#include "src/surf/network_interface.hpp"
 #include "surf/surf_routing.h"
 #include <string.h>
 #include <ctype.h>
@@ -364,9 +365,22 @@ int console_add_route(lua_State *L) {
   if (type != LUA_TSTRING) {
     XBT_ERROR("Attribute 'links' must be specified for any route and must be a string (different links separated by commas or single spaces.");
   }
-  route.link_list = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
-  if (xbt_dynar_is_empty(route.link_list))
-    xbt_dynar_push_as(route.link_list,char*,xbt_strdup(lua_tostring(L, -1)));
+  route.link_list = new std::vector<Link*>();
+  xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
+  if (xbt_dynar_is_empty(names)) {
+    /* unique name */
+    route.link_list->push_back(Link::byName(lua_tostring(L, -1)));
+  } else {
+    // Several names separated by , \t\r\n
+    unsigned int cpt;
+    char *name;
+    xbt_dynar_foreach(names, cpt, name) {
+      if (strlen(name)>0) {
+        Link *link = Link::byName(name);
+        route.link_list->push_back(link);
+      }
+    }
+  }
   lua_pop(L,1);
 
   /* We are relying on the XML bypassing mechanism since the corresponding sg_platf does not exist yet.
@@ -434,9 +448,22 @@ int console_add_ASroute(lua_State *L) {
 
   lua_pushstring(L,"links");
   lua_gettable(L,-2);
-  ASroute.link_list = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
-  if (xbt_dynar_is_empty(ASroute.link_list))
-    xbt_dynar_push_as(ASroute.link_list,char*,xbt_strdup(lua_tostring(L, -1)));
+  ASroute.link_list = new std::vector<Link*>();
+  xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
+  if (xbt_dynar_is_empty(names)) {
+    /* unique name */
+    ASroute.link_list->push_back(Link::byName(lua_tostring(L, -1)));
+  } else {
+    // Several names separated by , \t\r\n
+    unsigned int cpt;
+    char *name;
+    xbt_dynar_foreach(names, cpt, name) {
+      if (strlen(name)>0) {
+        Link *link = Link::byName(name);
+        ASroute.link_list->push_back(link);
+      }
+    }
+  }
   lua_pop(L,1);
 
   lua_pushstring(L,"symmetrical");
index 84d70e6..5be023c 100644 (file)
@@ -364,20 +364,17 @@ static void instr_user_srcdst_variable(double time,
                               double value,
                               InstrUserVariable what)
 {
-  xbt_dynar_t route=NULL;
   sg_netcard_t src_elm = sg_netcard_by_name_or_null(src);
   if(!src_elm) xbt_die("Element '%s' not found!",src);
 
   sg_netcard_t dst_elm = sg_netcard_by_name_or_null(dst);
   if(!dst_elm) xbt_die("Element '%s' not found!",dst);
 
-  routing_platf->getRouteAndLatency (src_elm, dst_elm, &route,NULL);
-  unsigned int i;
-  surf_cpp_resource_t link;
-  xbt_dynar_foreach (route, i, link) {
-    char *link_name = (char*)surf_resource_name(link);
-    instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
-  }
+  std::vector<Link*> *route = new std::vector<Link*>();
+  routing_platf->getRouteAndLatency (src_elm, dst_elm, route,NULL);
+  for (auto link : *route)
+    instr_user_variable (time, link->getName(), variable, father_type, value, what, NULL, user_link_variables);
+  delete route;
 }
 
 /** \ingroup TRACE_API
index e77d274..5241965 100644 (file)
  */
 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
 {
-  void *surf_link;
-  unsigned int cpt;
-  xbt_dynar_t surf_route = NULL;
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
+  std::vector<Link*> *route = new std::vector<Link*>();
+  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, NULL);
 
-  SD_link_t *list = xbt_new(SD_link_t, xbt_dynar_length(surf_route));
-  xbt_dynar_foreach(surf_route, cpt, surf_link) {
-    list[cpt] = (SD_link_t)surf_link;
-  }
+  int cpt=0;
+  SD_link_t *list = xbt_new(SD_link_t, route->size());
+  for (auto link : *route)
+    list[cpt++] = link;
+
+  delete route;
   return list;
 }
 
@@ -42,9 +42,11 @@ 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)
 {
-  xbt_dynar_t surf_route = NULL;
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
-  return xbt_dynar_length(surf_route);
+  std::vector<Link*> *route = new std::vector<Link*>();
+  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, NULL);
+  int size = route->size();
+  delete route;
+  return size;
 }
 
 /**
@@ -57,10 +59,10 @@ 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)
 {
-  xbt_dynar_t route = NULL;
   double latency = 0;
-
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
+  std::vector<Link*> *route = new std::vector<Link*>();
+  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency);
+  delete route;
 
   return latency;
 }
@@ -76,19 +78,17 @@ double SD_route_get_latency(sg_host_t src, sg_host_t dst)
  */
 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
 {
-  xbt_dynar_t route = NULL;
-  unsigned int cpt;
-  double latency = 0;
   double min_bandwidth = -1.0;
-  SD_link_t link;
 
-  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
+  std::vector<Link*> *route = new std::vector<Link*>();
+  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, NULL);
 
-  xbt_dynar_foreach(route, cpt, link){
+  for (auto link : *route) {
     double bandwidth = sg_link_bandwidth(link);
     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
       min_bandwidth = bandwidth;
   }
+  delete route;
 
   return min_bandwidth;
 }
index c866290..c545cf4 100644 (file)
@@ -308,41 +308,32 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
 Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
                                                 double size, double rate)
 {
-  unsigned int i;
-  void *_link;
-  NetworkCm02Link *link;
   int failed = 0;
   NetworkCm02Action *action = NULL;
   double bandwidth_bound;
   double latency = 0.0;
-  xbt_dynar_t back_route = NULL;
+  std::vector<Link*> * back_route = NULL;
   int constraints_per_variable = 0;
 
-  xbt_dynar_t route = xbt_dynar_new(sizeof(NetCard*), NULL);
+  std::vector<Link*> *route = new std::vector<Link*>();
 
   XBT_IN("(%s,%s,%g,%g)", src->name(), dst->name(), size, rate);
 
-  routing_platf->getRouteAndLatency(src, dst, &route, &latency);
-  xbt_assert(!xbt_dynar_is_empty(route) || latency,
+  routing_platf->getRouteAndLatency(src, 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(), dst->name());
 
-  xbt_dynar_foreach(route, i, _link) {
-  link = static_cast<NetworkCm02Link*>(_link);
-    if (link->isOff()) {
+  for (auto link: *route)
+    if (link->isOff())
       failed = 1;
-      break;
-    }
-  }
+
   if (sg_network_crosstraffic == 1) {
-    routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
-    xbt_dynar_foreach(back_route, i, _link) {
-      link = static_cast<NetworkCm02Link*>(_link);
-      if (link->isOff()) {
+    back_route = new std::vector<Link*>();
+    routing_platf->getRouteAndLatency(dst, src, back_route, NULL);
+    for (auto link: *back_route)
+      if (link->isOff())
         failed = 1;
-        break;
-      }
-    }
   }
 
   action = new NetworkCm02Action(this, size, failed);
@@ -359,45 +350,37 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
   }
 
   bandwidth_bound = -1.0;
-  if (sg_weight_S_parameter > 0) {
-    xbt_dynar_foreach(route, i, _link) {
-      link = static_cast<NetworkCm02Link*>(_link);
+  if (sg_weight_S_parameter > 0)
+    for (auto link : *route)
       action->m_weight += sg_weight_S_parameter / link->getBandwidth();
-    }
-  }
-  xbt_dynar_foreach(route, i, _link) {
-    link = static_cast<NetworkCm02Link*>(_link);
+
+  for (auto link : *route) {
     double bb = bandwidthFactor(size) * link->getBandwidth();
-    bandwidth_bound =
-        (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
+    bandwidth_bound = (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
   }
 
   action->m_latCurrent = action->m_latency;
   action->m_latency *= latencyFactor(size);
   action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
   if (m_haveGap) {
-    xbt_assert(!xbt_dynar_is_empty(route),
+    xbt_assert(! route->empty(),
                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
 
-    link = *static_cast<NetworkCm02Link **>(xbt_dynar_get_ptr(route, 0));
-    gapAppend(size, link, action);
-    XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
-              action, src->name(), dst->name(), action->m_senderGap,
-              action->m_latency);
+    gapAppend(size, route->at(0), action);
+    XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)", action, src->name(), dst->name(), action->m_senderGap, action->m_latency);
   }
 
-  constraints_per_variable = xbt_dynar_length(route);
+  constraints_per_variable = route->size();
   if (back_route != NULL)
-    constraints_per_variable += xbt_dynar_length(back_route);
+    constraints_per_variable += back_route->size();
 
   if (action->m_latency > 0) {
     action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
                          constraints_per_variable);
     if (p_updateMechanism == UM_LAZY) {
       // add to the heap the event when the latency is payed
-      XBT_DEBUG("Added action (%p) one latency event at date %f", action,
-                action->m_latency + action->m_lastUpdate);
-      action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
+      XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->m_latency + action->m_lastUpdate);
+      action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, route->empty() ? NORMAL : LATENCY);
     }
   } else
     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
@@ -408,21 +391,17 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
     lmm_update_variable_bound(p_maxminSystem, action->getVariable(), (action->m_latCurrent > 0) ? std::min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
   }
 
-  xbt_dynar_foreach(route, i, _link) {
-    link = static_cast<NetworkCm02Link*>(_link);
+  for (auto link: *route)
     lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), 1.0);
-  }
 
   if (sg_network_crosstraffic == 1) {
     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
-    xbt_dynar_foreach(back_route, i, _link) {
-      link = static_cast<NetworkCm02Link*>(_link);
+    for (auto link : *back_route)
       lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), .05);
-    }
     lmm_variable_concurrency_share_set(action->getVariable(),2);
   }
 
-  xbt_dynar_free(&route);
+  delete route;
   XBT_OUT();
 
   networkCommunicateCallbacks(action, src, dst, size, rate);
index 491fa43..c20f3c9 100644 (file)
@@ -273,13 +273,6 @@ Link* NetworkNS3Model::createLink(const char *name,
   return link;
 }
 
-xbt_dynar_t NetworkNS3Model::getRoute(NetCard *src, NetCard *dst)
-{
-  xbt_dynar_t route = NULL;
-  routing_platf->getRouteAndLatency(src, dst, &route, NULL);
-  return route;
-}
-
 Action *NetworkNS3Model::communicate(NetCard *src, NetCard *dst,
                                    double size, double rate)
 {
@@ -345,18 +338,13 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
       double data_sent = ns3_get_socket_sent(data);
       double data_delta_sent = data_sent - action->m_lastSent;
 
-      xbt_dynar_t route = NULL;
-
-      routing_platf->getRouteAndLatency (action->p_srcElm, action->p_dstElm, &route, NULL);
-      unsigned int i;
-      for (i = 0; i < xbt_dynar_length (route); i++){
-        NetworkNS3Link* link = ((NetworkNS3Link*)xbt_dynar_get_ptr(route, i));
-        TRACE_surf_link_set_utilization (link->getName(),
-            action->getCategory(),
-          (data_delta_sent)/delta,
-          now-delta,
-          delta);
-      }
+      std::vector<Link*> *route = new std::vector<Link*>();
+
+      routing_platf->getRouteAndLatency (action->p_srcElm, action->p_dstElm, route, NULL);
+      for (auto link : *route)
+        TRACE_surf_link_set_utilization (link->getName(), action->getCategory(), (data_delta_sent)/delta, now-delta, delta);
+      delete route;
+
       action->m_lastSent = data_sent;
     }
 
index fa19671..0a0dd90 100644 (file)
@@ -49,7 +49,6 @@ public:
       tmgr_trace_t state_trace,
       e_surf_link_sharing_policy_t policy,
       xbt_dict_t properties) override;
-  xbt_dynar_t getRoute(NetCard *src, NetCard *dst);
   Action *communicate(NetCard *src, NetCard *dst, double size, double rate);
   double next_occuring_event(double now) override;
   bool next_occuring_event_isIdempotent() {return false;}
index 5d5e099..d7cf81c 100644 (file)
@@ -186,14 +186,10 @@ Action *HostL07Model::executeParallelTask(int host_nb, sg_host_t *host_list,
 }
 
 
-L07Action::L07Action(Model *model, int host_nb,
-    sg_host_t*host_list,
-    double *flops_amount,
-    double *bytes_amount,
-    double rate)
+L07Action::L07Action(Model *model, int host_nb, sg_host_t*host_list,
+    double *flops_amount, double *bytes_amount, double rate)
   : CpuAction(model, 1, 0)
 {
-  unsigned int cpt;
   int nb_link = 0;
   int nb_used_host = 0; /* Only the hosts with something to compute (>0 flops) are counted) */
   double latency = 0.0;
@@ -211,16 +207,14 @@ L07Action::L07Action(Model *model, int host_nb,
 
         if (bytes_amount[i * host_nb + j] > 0) {
           double lat=0.0;
-          xbt_dynar_t route=NULL;
+          std::vector<Link*> *route = new std::vector<Link*>();
 
-          routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j], &route, &lat);
+          routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j], route, &lat);
           latency = MAX(latency, lat);
 
-          void *_link;
-          xbt_dynar_foreach(route, cpt, _link) {
-            LinkL07 *link = static_cast<LinkL07*>(_link);
+          for (auto link : *route)
             xbt_dict_set(ptask_parallel_task_link_set, link->getName(), link, NULL);
-          }
+          delete route;
         }
       }
     }
@@ -254,19 +248,16 @@ L07Action::L07Action(Model *model, int host_nb,
     for (int i = 0; i < host_nb; i++) {
       for (int j = 0; j < host_nb; j++) {
 
-        xbt_dynar_t route=NULL;
         if (bytes_amount[i * host_nb + j] == 0.0)
           continue;
+        std::vector<Link*> *route = new std::vector<Link*>();
 
-        routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j],
-                                                    &route, NULL);
+        routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j], route, NULL);
 
-        void *_link;
-        xbt_dynar_foreach(route, cpt, _link) {
-          LinkL07 *link = static_cast<LinkL07*>(_link);
-          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]);
+
+        delete route;
       }
     }
   }
@@ -495,14 +486,14 @@ void L07Action::updateBound()
   if (p_communicationAmount != NULL) {
     for (i = 0; i < hostNb; i++) {
       for (j = 0; j < hostNb; j++) {
-        xbt_dynar_t route=NULL;
 
         if (p_communicationAmount[i * hostNb + j] > 0) {
           double lat = 0.0;
-          routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j],
-                                                                &route, &lat);
+          std::vector<Link*> *route = new std::vector<Link*>();
+          routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j], route, &lat);
 
           lat_current = MAX(lat_current, lat * p_communicationAmount[i * hostNb + j]);
+          delete route;
         }
       }
     }
index 336a532..e427e58 100644 (file)
@@ -54,7 +54,6 @@ typedef enum {
 extern XBT_PRIVATE simgrid::trace_mgr::future_evt_set *future_evt_set;
 
 
-XBT_PUBLIC(void) routing_model_create(void *loopback);
 XBT_PUBLIC(void) routing_exit(void);
 XBT_PUBLIC(void) storage_register_callbacks(void);
 
index 073de70..1ef547b 100644 (file)
@@ -181,28 +181,21 @@ namespace surf {
     if (e_route->gw_dst) {
       XBT_DEBUG("Load bypassASroute from %s@%s to %s@%s",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
-      xbt_assert(!xbt_dynar_is_empty(e_route->link_list), "Bypass route between %s@%s and %s@%s cannot be empty.",
+      xbt_assert(!e_route->link_list->empty(), "Bypass route between %s@%s and %s@%s cannot be empty.",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
       xbt_assert(bypassRoutes_->find(route_name) == bypassRoutes_->end(),
           "The bypass route between %s@%s and %s@%s already exists.",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
     } else {
       XBT_DEBUG("Load bypassRoute from %s to %s", src, dst);
-      xbt_assert(!xbt_dynar_is_empty(e_route->link_list),                 "Bypass route between %s and %s cannot be empty.",    src, dst);
+      xbt_assert(!e_route->link_list->empty(),                            "Bypass route between %s and %s cannot be empty.",    src, dst);
       xbt_assert(bypassRoutes_->find(route_name) == bypassRoutes_->end(), "The bypass route between %s and %s already exists.", src, dst);
     }
 
-    /* Build the value that will be stored in the dict */
+    /* Build a copy that will be stored in the dict */
     std::vector<Link*> *newRoute = new std::vector<Link*>();
-    char *linkName;
-    unsigned int cpt;
-    xbt_dynar_foreach(e_route->link_list, cpt, linkName) {
-      Link *link = Link::byName(linkName);
-      if (link)
-        newRoute->push_back(link);
-      else
-        THROWF(mismatch_error, 0, "Link '%s' not found", linkName);
-    }
+    for (auto link: *e_route->link_list)
+      newRoute->push_back(link);
 
     /* Store it */
     bypassRoutes_->insert({route_name, newRoute});
@@ -460,7 +453,7 @@ static void elements_father(sg_netcard_t src, sg_netcard_t dst,
  * \param *latency the latency, if needed
  */
 static void _get_route_and_latency(simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst,
-  xbt_dynar_t * links, double *latency)
+    std::vector<Link*> * links, double *latency)
 {
   s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
   memset(&route,0,sizeof(route));
@@ -478,7 +471,7 @@ static void _get_route_and_latency(simgrid::surf::NetCard *src, simgrid::surf::N
   std::vector<Link*> *bypassed_route = common_father->getBypassRoute(src, dst);
   if (nullptr != bypassed_route) {
     for (Link *link : *bypassed_route) {
-      xbt_dynar_push(*links,&link);
+      links->push_back(link);
       if (latency)
         *latency += link->getLatency();
     }
@@ -487,14 +480,14 @@ static void _get_route_and_latency(simgrid::surf::NetCard *src, simgrid::surf::N
 
   /* If src and dst are in the same AS, life is good */
   if (src_father == dst_father) {       /* SURF_ROUTING_BASE */
-    route.link_list = *links;
+    route.link_list = links;
     common_father->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 = xbt_dynar_new(sizeof(Link*), NULL);
+  route.link_list = new std::vector<Link*>();
 
   common_father->getRouteAndLatency(src_father->netcard_, dst_father->netcard_, &route, latency);
   xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
@@ -503,7 +496,8 @@ static void _get_route_and_latency(simgrid::surf::NetCard *src, simgrid::surf::N
   /* If source gateway is not our source, we have to recursively find our way up to this point */
   if (src != route.gw_src)
     _get_route_and_latency(src, route.gw_src, links, latency);
-  xbt_dynar_merge(links, &route.link_list);
+  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)
@@ -528,13 +522,9 @@ namespace surf {
  * 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, xbt_dynar_t* route, double *latency)
+void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * route, double *latency)
 {
   XBT_DEBUG("getRouteAndLatency from %s to %s", src->name(), dst->name());
-  if (NULL == *route) {
-    xbt_dynar_reset(routing_platf->lastRoute_);
-    *route = routing_platf->lastRoute_;
-  }
 
   _get_route_and_latency(src, dst, route, latency);
 }
@@ -568,7 +558,7 @@ xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
 }
 
 /** @brief create the root AS */
-void routing_model_create( void *loopback)
+void routing_model_create(Link *loopback)
 {
   routing_platf = new simgrid::surf::RoutingPlatf(loopback);
 }
@@ -908,7 +898,7 @@ void routing_exit(void) {
 namespace simgrid {
 namespace surf {
 
-  RoutingPlatf::RoutingPlatf(void *loopback)
+  RoutingPlatf::RoutingPlatf(Link *loopback)
   : loopback_(loopback)
   {
   }
index 0ac0fa3..07afc8d 100644 (file)
@@ -18,7 +18,7 @@
 #include <map>
 
 SG_BEGIN_DECL()
-XBT_PUBLIC(void) routing_model_create( void *loopback);
+XBT_PUBLIC(void) routing_model_create(Link *loopback);
 XBT_PRIVATE xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
 XBT_PRIVATE xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges);
 SG_END_DECL()
@@ -156,13 +156,13 @@ public:
  */
 XBT_PUBLIC_CLASS RoutingPlatf {
 public:
-  RoutingPlatf(void *loopback);
+  RoutingPlatf(Link *loopback);
   ~RoutingPlatf();
   As *root_ = nullptr;
-  void *loopback_;
+  Link *loopback_;
   xbt_dynar_t lastRoute_ = xbt_dynar_new(sizeof(Link*),NULL);
   xbt_dynar_t getOneLinkRoutes(void);
-  void getRouteAndLatency(NetCard *src, NetCard *dst, xbt_dynar_t * links, double *latency);
+  void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
 };
 
 /*************
index 9f2e501..5c00da3 100644 (file)
@@ -23,7 +23,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic imple
 void routing_route_free(sg_platf_route_cbarg_t route)
 {
   if (route) {
-    xbt_dynar_free(&route->link_list);
+    delete route->link_list;
     xbt_free(route);
   }
 }
@@ -107,15 +107,12 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
           xbt_dynar_get_as(vertices_, dst, NetCard*);
 
       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
-      route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
+      route->link_list = new std::vector<Link*>();
 
       getRouteAndLatency(my_src, my_dst, route, NULL);
 
       XBT_DEBUG ("get_route_and_latency %s -> %s", my_src->name(), my_dst->name());
 
-      unsigned int cpt;
-      void *link;
-
       xbt_node_t current, previous;
       const char *previous_name, *current_name;
 
@@ -127,9 +124,8 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
         previous_name = my_src->name();
       }
 
-      xbt_dynar_foreach(route->link_list, cpt, link) {
-        const char *link_name = static_cast<simgrid::surf::Resource*>(
-          link)->getName();
+      for (auto link: *route->link_list) {
+        const char *link_name = link->getName();
         current = new_xbt_graph_node(graph, link_name, nodes);
         current_name = link_name;
         new_xbt_graph_edge(graph, previous, current, edges);
@@ -148,7 +144,7 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
       new_xbt_graph_edge(graph, previous, current, edges);
       XBT_DEBUG ("  %s -> %s", previous_name, current_name);
 
-      xbt_dynar_free (&(route->link_list));
+      delete route->link_list;
       xbt_free (route);
     }
   }
@@ -159,14 +155,13 @@ 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(e_surf_routing_hierarchy_t hierarchy,
-      sg_platf_route_cbarg_t routearg, int change_order) {
+    sg_platf_route_cbarg_t routearg, int change_order)
+{
 
   sg_platf_route_cbarg_t result;
-  char *link_name;
-  unsigned int cpt;
 
   result = xbt_new0(s_sg_platf_route_cbarg_t, 1);
-  result->link_list = xbt_dynar_new(sizeof(Link*), NULL);
+  result->link_list = new std::vector<Link*>();
 
   xbt_assert(hierarchy == SURF_ROUTING_BASE
       || hierarchy == SURF_ROUTING_RECURSIVE,
@@ -181,16 +176,11 @@ sg_platf_route_cbarg_t AsRoutedGraph::newExtendedRoute(e_surf_routing_hierarchy_
     result->gw_dst = routearg->gw_dst;
   }
 
-  xbt_dynar_foreach(routearg->link_list, cpt, link_name) {
-
-    Link *link = Link::byName(link_name);
-    if (link) {
-      if (change_order)
-        xbt_dynar_push(result->link_list, &link);
-      else
-        xbt_dynar_unshift(result->link_list, &link);
-    } else
-      THROWF(mismatch_error, 0, "Link '%s' not found", link_name);
+  for (auto link : *routearg->link_list) {
+    if (change_order)
+      result->link_list->push_back(link);
+    else
+      result->link_list->insert(result->link_list->begin(), link);
   }
 
   return result;
@@ -221,7 +211,7 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
     XBT_DEBUG("Load Route from \"%s\" to \"%s\"", srcName, dstName);
     xbt_assert(src, "Cannot add a route from %s to %s: %s does not exist.", srcName, dstName, srcName);
     xbt_assert(dst, "Cannot add a route from %s to %s: %s does not exist.", srcName, dstName, dstName);
-    xbt_assert(!xbt_dynar_is_empty(route->link_list), "Empty route (between %s and %s) forbidden.", srcName, dstName);
+    xbt_assert(! route->link_list->empty(), "Empty route (between %s and %s) forbidden.", srcName, dstName);
     xbt_assert(! src->isAS(), "When defining a route, src cannot be an AS such as '%s'. Did you meant to have an ASroute?", srcName);
     xbt_assert(! dst->isAS(), "When defining a route, dst cannot be an AS such as '%s'. Did you meant to have an ASroute?", dstName);
   } else {
@@ -240,7 +230,7 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
         srcName,route->gw_src->name(), dstName,route->gw_dst->name(), srcName);
     xbt_assert(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.",
         srcName,route->gw_src->name(), dstName,route->gw_dst->name(), dstName);
-    xbt_assert(!xbt_dynar_is_empty(route->link_list), "Empty route (between %s@%s and %s@%s) forbidden.",
+    xbt_assert(! route->link_list->empty(), "Empty route (between %s@%s and %s@%s) forbidden.",
         srcName,route->gw_src->name(), dstName,route->gw_dst->name());
   }
 }
index 81848c2..3cdfdb0 100644 (file)
@@ -28,30 +28,29 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
 
     if((src->id() == dst->id()) && has_loopback_  ){
       info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
-      xbt_dynar_push_as(route->link_list, void *, info.link_up);
+      route->link_list->push_back(info.link_up);
       if (lat)
-        *lat += static_cast<Link*>(info.link_up)->getLatency();
+        *lat += info.link_up->getLatency();
       return;
     }
 
 
     if (has_limiter_){          // limiter for sender
       info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
-      xbt_dynar_push_as(route->link_list, void *, info.link_up);
+      route->link_list->push_back((Link*)info.link_up);
     }
 
     info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
     if (info.link_up) {         // link up
-      xbt_dynar_push_as(route->link_list, void *, info.link_up);
+      route->link_list->push_back(info.link_up);
       if (lat)
-        *lat += static_cast<Link*>(info.link_up)->getLatency();
+        *lat += info.link_up->getLatency();
     }
 
   }
 
   if (backbone_) {
-    xbt_dynar_push_as(route->link_list, void *,
-      static_cast<simgrid::surf::Resource*>(backbone_));
+    route->link_list->push_back(backbone_);
     if (lat)
       *lat += backbone_->getLatency();
   }
@@ -60,13 +59,13 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
     info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
 
     if (info.link_down) {       // link down
-      xbt_dynar_push_as(route->link_list, void *, info.link_down);
+      route->link_list->push_back(info.link_down);
       if (lat)
-        *lat += static_cast<Link*>(info.link_down)->getLatency();
+        *lat += info.link_down->getLatency();
     }
     if (has_limiter_){          // limiter for receiver
         info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_, s_surf_parsing_link_up_down_t);
-        xbt_dynar_push_as(route->link_list, void *, info.link_up);
+        route->link_list->push_back(info.link_up);
     }
   }
 }
index 5eecd34..579e1e3 100644 (file)
@@ -93,7 +93,7 @@ void AsClusterFatTree::getRouteAndLatency(NetCard *src,
   /* In case destination is the source, and there is a loopback, let's get
      through it instead of going up to a switch*/
   if(source->id == destination->id && this->has_loopback_) {
-    xbt_dynar_push_as(into->link_list, void*, source->loopback);
+    into->link_list->push_back(source->loopback);
     if(latency) {
       *latency += source->loopback->getLatency();
     }
@@ -112,14 +112,14 @@ void AsClusterFatTree::getRouteAndLatency(NetCard *src,
     }
     k = this->upperLevelNodesNumber_[currentNode->level];
     d = d % k;
-    xbt_dynar_push_as(into->link_list, void*,currentNode->parents[d]->upLink);
+    into->link_list->push_back(currentNode->parents[d]->upLink);
 
     if(latency) {
       *latency += currentNode->parents[d]->upLink->getLatency();
     }
 
     if (this->has_limiter_) {
-      xbt_dynar_push_as(into->link_list, void*,currentNode->limiterLink);
+      into->link_list->push_back(currentNode->limiterLink);
     }
     currentNode = currentNode->parents[d]->upNode;
   }
@@ -133,13 +133,13 @@ void AsClusterFatTree::getRouteAndLatency(NetCard *src,
     for(unsigned int i = 0 ; i < currentNode->children.size() ; i++) {
       if(i % this->lowerLevelNodesNumber_[currentNode->level - 1] ==
          destination->label[currentNode->level - 1]) {
-        xbt_dynar_push_as(into->link_list, void*,currentNode->children[i]->downLink);
+        into->link_list->push_back(currentNode->children[i]->downLink);
         if(latency) {
           *latency += currentNode->children[i]->downLink->getLatency();
         }
         currentNode = currentNode->children[i]->downNode;
         if (this->has_limiter_) {
-          xbt_dynar_push_as(into->link_list, void*,currentNode->limiterLink);
+          into->link_list->push_back(currentNode->limiterLink);
         }
         XBT_DEBUG("%d(%u,%u) is accessible through %d(%u,%u)", destination->id,
                   destination->level, destination->position, currentNode->id,
index 2d08077..294c127 100644 (file)
@@ -119,12 +119,11 @@ namespace simgrid {
         return;
 
       if ((src->id() == dst->id()) && has_loopback_) {
-        s_surf_parsing_link_up_down_t info =
-            xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
-        xbt_dynar_push_as(route->link_list, void *, info.link_up);
+        s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
 
+        route->link_list->push_back(info.link_up);
         if (lat)
-          *lat += static_cast < Link * >(info.link_up)->getLatency();
+          *lat += info.link_up->getLatency();
         return;
       }
 
@@ -203,21 +202,19 @@ namespace simgrid {
 
         if (has_limiter_) {    // limiter for sender
           info = xbt_dynar_get_as(upDownLinks, nodeOffset + has_loopback_, s_surf_parsing_link_up_down_t);
-          xbt_dynar_push_as(route->link_list, void *, info.link_up);
+          route->link_list->push_back(info.link_up);
         }
 
         info = xbt_dynar_get_as(upDownLinks, linkOffset, s_surf_parsing_link_up_down_t);
 
         if (use_lnk_up == false) {
-          xbt_dynar_push_as(route->link_list, void *, info.link_down);
-
+          route->link_list->push_back(info.link_down);
           if (lat)
-            *lat += static_cast < Link * >(info.link_down)->getLatency();
+            *lat += info.link_down->getLatency();
         } else {
-          xbt_dynar_push_as(route->link_list, void *, info.link_up);
-
+          route->link_list->push_back(info.link_up);
           if (lat)
-            *lat += static_cast < Link * >(info.link_up)->getLatency();
+            *lat += info.link_up->getLatency();
         }
         current_node = next_node;
         next_node = 0;
@@ -225,8 +222,6 @@ namespace simgrid {
       free(myCoords);
       free(targetCoords);
 
-
-
       return;
     }
 
index 0d2108d..fcaac99 100644 (file)
@@ -30,7 +30,7 @@ static void graph_edge_data_free(void *e) // FIXME: useless code duplication
 {
   sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t) e;
   if (e_route) {
-    xbt_dynar_free(&(e_route->link_list));
+    delete e_route->link_list;
     xbt_free(e_route);
   }
 }
@@ -65,8 +65,8 @@ void AsDijkstra::Seal()
 
       if (!found) {
         sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
-        e_route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
-        xbt_dynar_push(e_route->link_list, &routing_platf->loopback_);
+        e_route->link_list = new std::vector<Link*>();
+        e_route->link_list->push_back(routing_platf->loopback_);
         xbt_graph_new_edge(routeGraph_, node, node, e_route);
       }
     }
@@ -142,18 +142,18 @@ xbt_dynar_t AsDijkstra::getOneLinkRoutes()
 {
   xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
   sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
-  route->link_list = xbt_dynar_new(sizeof(Link*),NULL);
+  route->link_list = new std::vector<Link*>();
 
   int table_size = (int)xbt_dynar_length(vertices_);
   for(int src=0; src < table_size; src++) {
     for(int dst=0; dst< table_size; dst++) {
-      xbt_dynar_reset(route->link_list);
+      route->link_list->clear();
       NetCard *src_elm = xbt_dynar_get_as(vertices_, src, NetCard*);
       NetCard *dst_elm = xbt_dynar_get_as(vertices_, dst, NetCard*);
       this->getRouteAndLatency(src_elm, dst_elm,route, NULL);
 
-      if (xbt_dynar_length(route->link_list) == 1) {
-        void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
+      if (route->link_list->size() == 1) {
+        Link *link = route->link_list->at(0);
         Onelink *onelink;
         if (hierarchy_ == SURF_ROUTING_BASE)
           onelink = new Onelink(link, src_elm, dst_elm);
@@ -177,8 +177,6 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
   int *pred_arr = NULL;
   sg_platf_route_cbarg_t e_route;
   int size = 0;
-  unsigned int cpt;
-  void *link;
   xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
 
   /* Use the graph_node id mapping set to quickly find the nodes */
@@ -200,8 +198,8 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
 
     e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
 
-    xbt_dynar_foreach(e_route->link_list, cpt, link) {
-      xbt_dynar_unshift(route->link_list, &link);
+    for (auto link: *e_route->link_list) {
+      route->link_list->insert(route->link_list->begin(), link);
       if (lat)
         *lat += static_cast<Link*>(link)->getLatency();
     }
@@ -210,8 +208,7 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
 
   route_cache_element_t elm = NULL;
   if (routeCache_) {  /* cache mode  */
-    elm = (route_cache_element_t)
-            xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int));
+    elm = (route_cache_element_t) xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int));
   }
 
   if (elm) {                    /* cached mode and cache hit */
@@ -252,7 +249,7 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
         graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
         int u_id = data->graph_id;
         sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
-        int cost_v_u = (tmp_e_route->link_list)->used;    /* count of links, old model assume 1 */
+        int cost_v_u = tmp_e_route->link_list->size();    /* count of links, old model assume 1 */
 
         if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
           pred_arr[u_id] = *v_id;
@@ -293,22 +290,20 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
       first_gw = gw_dst;
 
     if (hierarchy_ == SURF_ROUTING_RECURSIVE && v != dst_node_id && strcmp(gw_dst->name(), prev_gw_src->name())) {
-      xbt_dynar_t e_route_as_to_as=NULL;
-
-      routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
-      if (edge == NULL)
-        THROWF(arg_error,0,"No route from '%s' to '%s'", src->name(), dst->name());
-      int pos = 0;
-      xbt_dynar_foreach(e_route_as_to_as, cpt, link) {
-        xbt_dynar_insert_at(route->link_list, pos, &link);
+      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);
+      auto pos = route->link_list->begin();
+      for (auto link : *e_route_as_to_as) {
+        route->link_list->insert(pos, link);
         if (lat)
-          *lat += static_cast<Link*>(link)->getLatency();
+          *lat += link->getLatency();
         pos++;
       }
     }
 
-    xbt_dynar_foreach(e_route->link_list, cpt, link) {
-      xbt_dynar_unshift(route->link_list, &link);
+    for (auto link: *e_route->link_list) {
+      route->link_list->insert(route->link_list->begin(), link);
       if (lat)
         *lat += static_cast<Link*>(link)->getLatency();
     }
@@ -392,7 +387,7 @@ void AsDijkstra::addRoute(sg_platf_route_cbarg_t route)
     sg_platf_route_cbarg_t link_route_back = newExtendedRoute(hierarchy_, route, 0);
     newRoute(dst->id(), src->id(), link_route_back);
   }
-  xbt_dynar_free(&route->link_list);
+  delete route->link_list;
 }
 
 }
index 2f297fd..c902ac3 100644 (file)
@@ -43,21 +43,19 @@ AsFloyd::~AsFloyd(){
 xbt_dynar_t AsFloyd::getOneLinkRoutes()
 {
   xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
-  sg_platf_route_cbarg_t route =   xbt_new0(s_sg_platf_route_cbarg_t, 1);
-  route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
+  sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+  route->link_list = new std::vector<Link*>();
 
-  int src,dst;
-  sg_netcard_t src_elm, dst_elm;
   int table_size = xbt_dynar_length(vertices_);
-  for(src=0; src < table_size; src++) {
-    for(dst=0; dst< table_size; dst++) {
-      xbt_dynar_reset(route->link_list);
-      src_elm = xbt_dynar_get_as(vertices_, src, NetCard*);
-      dst_elm = xbt_dynar_get_as(vertices_, dst, NetCard*);
+  for(int src=0; src < table_size; src++) {
+    for(int dst=0; dst< table_size; dst++) {
+      route->link_list->clear();
+      NetCard *src_elm = xbt_dynar_get_as(vertices_, src, NetCard*);
+      NetCard *dst_elm = xbt_dynar_get_as(vertices_, dst, NetCard*);
       this->getRouteAndLatency(src_elm, dst_elm, route, NULL);
 
-      if (xbt_dynar_length(route->link_list) == 1) {
-        void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
+      if (route->link_list->size() == 1) {
+        void *link = route->link_list->at(0);
         Onelink *onelink;
         if (hierarchy_ == SURF_ROUTING_BASE)
           onelink = new Onelink(link, src_elm, dst_elm);
@@ -73,7 +71,7 @@ xbt_dynar_t AsFloyd::getOneLinkRoutes()
   return ret;
 }
 
-void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t res, double *lat)
+void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
 {
 
   size_t table_size = xbt_dynar_length(vertices_);
@@ -93,26 +91,22 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar
   } while (cur != src->id());
 
   if (hierarchy_ == SURF_ROUTING_RECURSIVE) {
-    res->gw_src = xbt_dynar_getlast_as(route_stack, sg_platf_route_cbarg_t)->gw_src;
-    res->gw_dst = xbt_dynar_getfirst_as(route_stack, sg_platf_route_cbarg_t)->gw_dst;
+    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;
   }
 
   sg_netcard_t prev_dst_gw = NULL;
   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);
-    xbt_dynar_t links;
-    void *link;
-    unsigned int cpt;
 
     if (hierarchy_ == SURF_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, &res->link_list, lat);
+      routing_platf->getRouteAndLatency(prev_dst_gw, e_route->gw_src, route->link_list, lat);
     }
 
-    links = e_route->link_list;
-    xbt_dynar_foreach(links, cpt, link) {
-      xbt_dynar_push_as(res->link_list, Link*, (Link*)link);
+    for (auto link: *e_route->link_list) {
+      route->link_list->push_back(link);
       if (lat)
-        *lat += static_cast<Link*>(link)->getLatency();
+        *lat += link->getLatency();
     }
 
     prev_dst_gw = e_route->gw_dst;
@@ -120,10 +114,6 @@ void AsFloyd::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbar
   xbt_dynar_free(&route_stack);
 }
 
-static int floyd_pointer_resource_cmp(const void *a, const void *b) {
-  return a != b;
-}
-
 void AsFloyd::addRoute(sg_platf_route_cbarg_t route)
 {
   /* set the size of table routing */
@@ -160,53 +150,35 @@ void AsFloyd::addRoute(sg_platf_route_cbarg_t route)
 
   TO_FLOYD_LINK(src->id(), dst->id()) = newExtendedRoute(hierarchy_, route, 1);
   TO_FLOYD_PRED(src->id(), dst->id()) = src->id();
-  TO_FLOYD_COST(src->id(), dst->id()) = ((TO_FLOYD_LINK(src->id(), dst->id()))->link_list)->used;
+  TO_FLOYD_COST(src->id(), dst->id()) = (TO_FLOYD_LINK(src->id(), dst->id()))->link_list->size();
 
 
   if (route->symmetrical == TRUE) {
-    if(TO_FLOYD_LINK(dst->id(), src->id()))
-    {
-      if(!route->gw_dst && !route->gw_src)
-        XBT_DEBUG("See Route from \"%s\" to \"%s\"", dst->name(), src->name());
-      else
-        XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst->name(), route->gw_src->name(), src->name(), route->gw_dst->name());
-
-      char * link_name;
-      xbt_dynar_t link_route_to_test = xbt_dynar_new(sizeof(Link*), NULL);
-      for(int i=xbt_dynar_length(route->link_list) ;i>0 ;i--) {
-        link_name = xbt_dynar_get_as(route->link_list,i-1,char *);
-        void *link = Link::byName(link_name);
-        xbt_assert(link,"Link : '%s' doesn't exists.",link_name);
-        xbt_dynar_push(link_route_to_test,&link);
-      }
-      xbt_assert(!xbt_dynar_compare(
-          TO_FLOYD_LINK(dst->id(), src->id())->link_list,
-          link_route_to_test,
-          (int_f_cpvoid_cpvoid_t) floyd_pointer_resource_cmp),
-          "The route between \"%s\" and \"%s\" already exists", src->name(),dst->name());
+    if (route->gw_dst) // AS route (to adapt the error message, if any)
+      xbt_assert(nullptr == TO_FLOYD_LINK(dst->id(), src->id()),
+          "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
+          dst->name(),route->gw_dst->name(),src->name(),route->gw_src->name());
+    else
+      xbt_assert(nullptr == TO_FLOYD_LINK(dst->id(), src->id()),
+          "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
+          dst->name(),src->name());
+
+    if(route->gw_dst && route->gw_src) {
+      NetCard* gw_tmp = route->gw_src;
+      route->gw_src = route->gw_dst;
+      route->gw_dst = gw_tmp;
     }
-    else {
 
-      if(route->gw_dst && route->gw_src) {
-        NetCard* gw_tmp = route->gw_src;
-        route->gw_src = route->gw_dst;
-        route->gw_dst = gw_tmp;
-      }
+    if(!route->gw_src && !route->gw_dst)
+      XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst->name(), src->name());
+    else
+      XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst->name(),
+          route->gw_src->name(), src->name(), route->gw_dst->name());
 
-      if(!route->gw_src && !route->gw_dst)
-        XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst->name(), src->name());
-      else
-        XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst->name(),
-            route->gw_src->name(), src->name(), route->gw_dst->name());
-
-      TO_FLOYD_LINK(dst->id(), src->id()) =
-         newExtendedRoute(hierarchy_, route, 0);
-      TO_FLOYD_PRED(dst->id(), src->id()) = dst->id();
-      TO_FLOYD_COST(dst->id(), src->id()) =
-          ((TO_FLOYD_LINK(dst->id(), src->id()))->link_list)->used;   /* count of links, old model assume 1 */
-    }
+    TO_FLOYD_LINK(dst->id(), src->id()) = newExtendedRoute(hierarchy_, route, 0);
+    TO_FLOYD_PRED(dst->id(), src->id()) = dst->id();
+    TO_FLOYD_COST(dst->id(), src->id()) = (TO_FLOYD_LINK(dst->id(), src->id()))->link_list->size();   /* count of links, old model assume 1 */
   }
-  xbt_dynar_free(&route->link_list);
 }
 
 void AsFloyd::Seal(){
@@ -237,8 +209,8 @@ void AsFloyd::Seal(){
         e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
         e_route->gw_src = NULL;
         e_route->gw_dst = NULL;
-        e_route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
-        xbt_dynar_push(e_route->link_list, &routing_platf->loopback_);
+        e_route->link_list = new std::vector<Link*>();
+        e_route->link_list->push_back(routing_platf->loopback_);
         TO_FLOYD_LINK(i, i) = e_route;
         TO_FLOYD_PRED(i, i) = i;
         TO_FLOYD_COST(i, i) = 1;
index 9a000f4..7d52469 100644 (file)
@@ -37,8 +37,8 @@ void AsFull::Seal() {
         e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
         e_route->gw_src = NULL;
         e_route->gw_dst = NULL;
-        e_route->link_list = xbt_dynar_new(sizeof(Link*), NULL);
-        xbt_dynar_push(e_route->link_list, &routing_platf->loopback_);
+        e_route->link_list = new std::vector<Link*>();
+        e_route->link_list->push_back(routing_platf->loopback_);
         TO_ROUTE_FULL(i, i) = e_route;
       }
     }
@@ -53,7 +53,7 @@ AsFull::~AsFull(){
     for (i = 0; i < table_size; i++)
       for (j = 0; j < table_size; j++) {
         if (TO_ROUTE_FULL(i,j)){
-          xbt_dynar_free(&TO_ROUTE_FULL(i,j)->link_list);
+          delete TO_ROUTE_FULL(i,j)->link_list;
           xbt_free(TO_ROUTE_FULL(i,j));
         }
       }
@@ -72,8 +72,8 @@ xbt_dynar_t AsFull::getOneLinkRoutes()
     for(dst=0; dst< table_size; dst++) {
       sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src,dst);
       if (route) {
-        if (xbt_dynar_length(route->link_list) == 1) {
-          void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
+        if (route->link_list->size() == 1) {
+          Link *link = route->link_list->at(0);
           Onelink *onelink;
           if (hierarchy_ == SURF_ROUTING_BASE) {
           NetCard *tmp_src = xbt_dynar_get_as(vertices_, src, sg_netcard_t);
@@ -108,27 +108,20 @@ void AsFull::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg
   size_t table_size = xbt_dynar_length(vertices_);
 
   sg_platf_route_cbarg_t e_route = NULL;
-  void *link;
-  unsigned int cpt = 0;
 
   e_route = TO_ROUTE_FULL(src->id(), dst->id());
 
   if (e_route) {
     res->gw_src = e_route->gw_src;
     res->gw_dst = e_route->gw_dst;
-    xbt_dynar_foreach(e_route->link_list, cpt, link) {
-      xbt_dynar_push(res->link_list, &link);
+    for (auto link : *e_route->link_list) {
+      res->link_list->push_back(link);
       if (lat)
         *lat += static_cast<Link*>(link)->getLatency();
     }
   }
 }
 
-static int full_pointer_resource_cmp(const void *a, const void *b)
-{
-  return a != b;
-}
-
 void AsFull::addRoute(sg_platf_route_cbarg_t route)
 {
   const char *src = route->src;
@@ -154,40 +147,25 @@ void AsFull::addRoute(sg_platf_route_cbarg_t route)
 
   /* Add the route to the base */
   TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()) = newExtendedRoute(hierarchy_, route, 1);
-  xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list, 0);
+  TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list->shrink_to_fit();
 
-  if (route->symmetrical == TRUE) {
+  if (route->symmetrical == TRUE && src_net_elm != dst_net_elm) {
     if (route->gw_dst && route->gw_src) {
       NetCard* gw_tmp = route->gw_src;
       route->gw_src = route->gw_dst;
       route->gw_dst = gw_tmp;
     }
-    if (TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())) {
-      char *link_name;
-      unsigned int i;
-      xbt_dynar_t link_route_to_test = xbt_dynar_new(sizeof(Link*), NULL);
-      for (i = xbt_dynar_length(route->link_list); i > 0; i--) {
-        link_name = xbt_dynar_get_as(route->link_list, i - 1, char *);
-        void *link = Link::byName(link_name);
-        xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
-        xbt_dynar_push(link_route_to_test, &link);
-      }
-      xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())->link_list,
-          link_route_to_test,
-          full_pointer_resource_cmp),
-          "The route between \"%s\" and \"%s\" already exists", src,
-          dst);
-    } else {
-      if (!route->gw_dst && !route->gw_src)
-        XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
-      else
-        XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
-            dst, route->gw_src->name(), src, route->gw_dst->name());
-      TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()) = newExtendedRoute(hierarchy_, route, 0);
-      xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())->link_list, 0);
-    }
+    if (route->gw_dst) // AS route (to adapt the error message, if any)
+      xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()),
+          "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
+          dst,route->gw_dst->name(),src,route->gw_src->name());
+    else
+      xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()),
+          "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.", dst,src);
+
+    TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()) = newExtendedRoute(hierarchy_, route, 0);
+    TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())->link_list->shrink_to_fit();
   }
-  xbt_dynar_free(&route->link_list);
 }
 
 }
index 985af5b..278d195 100644 (file)
@@ -54,7 +54,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
     if ((int)xbt_dynar_length(upDownLinks)>src->id()) {
       info = xbt_dynar_get_as(upDownLinks, src->id(), s_surf_parsing_link_up_down_t);
       if(info.link_up) { // link up
-        xbt_dynar_push_as(route->link_list, void*, info.link_up);
+        route->link_list->push_back(info.link_up);
         if (lat)
           *lat += static_cast<Link*>(info.link_up)->getLatency();
       }
@@ -77,7 +77,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
     if ((int)xbt_dynar_length(upDownLinks)>dst->id()) {
       info = xbt_dynar_get_as(upDownLinks, dst->id(), s_surf_parsing_link_up_down_t);
       if(info.link_down) { // link down
-        xbt_dynar_push_as(route->link_list,void*,info.link_down);
+        route->link_list->push_back(info.link_down);
         if (lat)
           *lat += static_cast<Link*>(info.link_down)->getLatency();
       }
index 260e117..9e99d90 100644 (file)
@@ -105,7 +105,7 @@ typedef struct s_sg_platf_route_cbarg {
   const char *dst;
   sg_netcard_t gw_src;
   sg_netcard_t gw_dst;
-  xbt_dynar_t link_list;
+  std::vector<Link*> *link_list;
 } s_sg_platf_route_cbarg_t;
 
 #define SG_PLATF_ROUTE_INITIALIZER {1,NULL,NULL,NULL,NULL,NULL}
@@ -305,8 +305,8 @@ XBT_PRIVATE void sg_instr_AS_end(void);
 
 typedef struct s_surf_parsing_link_up_down *surf_parsing_link_up_down_t;
 typedef struct s_surf_parsing_link_up_down {
-  void* link_up;
-  void* link_down;
+  Link* link_up;
+  Link* link_down;
 } s_surf_parsing_link_up_down_t;
 
 
index ea86273..9ba8430 100644 (file)
@@ -14,6 +14,7 @@
 #include "xbt/file.h"
 #include "xbt/dict.h"
 #include "src/surf/surf_private.h"
+#include "src/surf/network_interface.hpp"
 #include "simgrid/sg_config.h"
 #include "simgrid/link.h"
 
@@ -748,7 +749,15 @@ void ETag_surfxml_route(void){
   route.dst       = A_surfxml_route_dst;
   route.gw_src    = NULL;
   route.gw_dst    = NULL;
-  route.link_list = parsed_link_list;
+  route.link_list = new std::vector<Link*>();
+
+  unsigned int cpt;
+  char *link_name;
+  xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
+    simgrid::surf::Link *link = Link::byName(link_name);
+    route.link_list->push_back(link);
+  }
+
 
   switch (A_surfxml_route_symmetrical) {
   case AU_surfxml_route_symmetrical:
@@ -781,7 +790,14 @@ void ETag_surfxml_ASroute(void){
     surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",
                      A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);
 
-  ASroute.link_list = parsed_link_list;
+  ASroute.link_list =  new std::vector<Link*>();
+
+  unsigned int cpt;
+  char *link_name;
+  xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
+    simgrid::surf::Link *link = Link::byName(link_name);
+    ASroute.link_list->push_back(link);
+  }
 
   switch (A_surfxml_ASroute_symmetrical) {
   case AU_surfxml_ASroute_symmetrical:
@@ -805,11 +821,18 @@ void ETag_surfxml_bypassRoute(void){
   route.dst = A_surfxml_bypassRoute_dst;
   route.gw_src = NULL;
   route.gw_dst = NULL;
-  route.link_list = parsed_link_list;
   route.symmetrical = FALSE;
+  route.link_list =  new std::vector<Link*>();
 
-  sg_platf_new_bypassRoute(&route);
+  unsigned int cpt;
+  char *link_name;
+  xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
+    simgrid::surf::Link *link = Link::byName(link_name);
+    route.link_list->push_back(link);
+  }
   xbt_dynar_free(&parsed_link_list);
+
+  sg_platf_new_bypassRoute(&route);
 }
 
 void ETag_surfxml_bypassASroute(void){
@@ -818,14 +841,20 @@ void ETag_surfxml_bypassASroute(void){
 
   ASroute.src         = A_surfxml_bypassASroute_src;
   ASroute.dst         = A_surfxml_bypassASroute_dst;
-  ASroute.link_list   = parsed_link_list;
+  ASroute.link_list   =  new std::vector<Link*>();
+  unsigned int cpt;
+  char *link_name;
+  xbt_dynar_foreach(parsed_link_list, cpt, link_name) {
+    simgrid::surf::Link *link = Link::byName(link_name);
+    ASroute.link_list->push_back(link);
+  }
+  xbt_dynar_free(&parsed_link_list);
   ASroute.symmetrical = FALSE;
 
   ASroute.gw_src = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src);
   ASroute.gw_dst = sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst);
 
   sg_platf_new_bypassRoute(&ASroute);
-  xbt_dynar_free(&parsed_link_list);
 }
 
 void ETag_surfxml_trace(void){
index 22d747a..b70a591 100644 (file)
@@ -158,29 +158,26 @@ int main(int argc, char **argv)
     xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
       value1 = sg_host_by_name(src)->pimpl_netcard;
       xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
-        xbt_dynar_t route=NULL;
+        std::vector<Link*> *route = new std::vector<Link*>();
         value2 = sg_host_by_name(dst)->pimpl_netcard;
-        routing_platf->getRouteAndLatency(value1, value2, &route,NULL);
-        if (!xbt_dynar_is_empty(route)){
+        routing_platf->getRouteAndLatency(value1, value2, route,NULL);
+        if (! route->empty()){
           printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          for (auto link: *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
           printf("\n  </route>\n");
         }
+        delete route;
       }
       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
         value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
         if(value2->isRouter()){
           printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-          xbt_dynar_t route=NULL;
-          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          std::vector<Link*> *route = new std::vector<Link*>();
+          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
+          for (auto link : *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+          delete route;
           printf("\n  </route>\n");
         }
       }
@@ -193,26 +190,22 @@ int main(int argc, char **argv)
           value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
           if(value2->isRouter()){
             printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-            xbt_dynar_t route=NULL;
-            routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
-            for(i=0;i<xbt_dynar_length(route) ;i++){
-              void *link = xbt_dynar_get_as(route,i,void *);
-
-              printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-            }
+            std::vector<Link*> *route = new std::vector<Link*>();
+            routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
+            for(auto link :*route)
+              printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+            delete route;
             printf("\n  </route>\n");
           }
         }
         xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
           printf("  <route src=\"%s\" dst=\"%s\">\n  ",src, dst);
-          xbt_dynar_t route=NULL;
+          std::vector<Link*> *route = new std::vector<Link*>();
           value2 = sg_host_by_name(dst)->pimpl_netcard;
-          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route, NULL);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, NULL);
+          for(auto link : *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+          delete route;
           printf("\n  </route>\n");
         }
       }