Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
routing: dedupplicate code
[simgrid.git] / src / surf / surf_routing_generic.cpp
index fc14c8f..595568e 100644 (file)
 #include "simgrid/platf_interface.h"    // platform creation API internal interface
 
 #include "surf_routing_generic.hpp"
+#include "surf_routing_private.hpp"
 #include "network_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing");
 
 static int no_bypassroute_declared = 1;
 
-void generic_free_route(sg_platf_route_cbarg_t route)
+void routing_route_free(sg_platf_route_cbarg_t route)
 {
   if (route) {
     xbt_dynar_free(&route->link_list);
@@ -31,38 +32,18 @@ void generic_free_route(sg_platf_route_cbarg_t route)
   }
 }
 
-void AsGeneric::parseRoute(sg_platf_route_cbarg_t /*route*/){
-  THROW_IMPOSSIBLE;
-}
-
-void AsGeneric::parseASroute(sg_platf_route_cbarg_t /*route*/){
-  THROW_IMPOSSIBLE;
-}
-
-void AsGeneric::getRouteAndLatency(RoutingEdge */*src*/, RoutingEdge */*dst*/, sg_platf_route_cbarg_t /*into*/, double */*latency*/){
-  THROW_IMPOSSIBLE;
-}
-
-AsGeneric::AsGeneric() {
-  p_bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route);
-}
-
-AsGeneric::~AsGeneric() {
-  xbt_dict_free(&p_bypassRoutes);
-}
-
-int AsGeneric::parsePU(RoutingEdge *elm)
+namespace simgrid {
+namespace surf {
+  
+AsGeneric::AsGeneric(const char*name)
+  : AsNone(name)
 {
-  XBT_DEBUG("Load process unit \"%s\"", elm->getName());
-  xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
-  return xbt_dynar_length(p_indexNetworkElm)-1;
+  bypassRoutes_ = xbt_dict_new_homogeneous((void (*)(void *)) routing_route_free);
 }
 
-int AsGeneric::parseAS(RoutingEdge *elm)
+AsGeneric::~AsGeneric()
 {
-  XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
-  xbt_dynar_push_as(p_indexNetworkElm, RoutingEdge*, elm);
-  return xbt_dynar_length(p_indexNetworkElm)-1;
+  xbt_dict_free(&bypassRoutes_);
 }
 
 void AsGeneric::parseBypassroute(sg_platf_route_cbarg_t e_route)
@@ -74,7 +55,7 @@ void AsGeneric::parseBypassroute(sg_platf_route_cbarg_t e_route)
     XBT_DEBUG("Load bypassASroute from \"%s\" to \"%s\"", src, dst);
   else
     XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
-  xbt_dict_t dict_bypassRoutes = p_bypassRoutes;
+  xbt_dict_t dict_bypassRoutes = bypassRoutes_;
   char *route_name;
 
   route_name = bprintf("%s#%s", src, dst);
@@ -98,14 +79,12 @@ void AsGeneric::parseBypassroute(sg_platf_route_cbarg_t e_route)
   xbt_free(route_name);
 }
 
+}
+}
+
 /* ************************************************************************** */
 /* *********************** GENERIC BUSINESS METHODS ************************* */
 
-xbt_dynar_t AsGeneric::getOneLinkRoutes() { // FIXME: kill that stub
-  xbt_die("\"generic_get_onelink_routes\" not implemented yet");
-  return NULL;
-}
-
 static const char *instr_node_name(xbt_node_t node)
 {
   void *data = xbt_graph_node_get_data(node);
@@ -151,20 +130,23 @@ xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d,
   return ret;
 }
 
+namespace simgrid {
+namespace surf {
+
 void AsGeneric::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
 {
   int src, dst;
-  int table_size = xbt_dynar_length(p_indexNetworkElm);
+  int table_size = xbt_dynar_length(vertices_);
 
 
   for (src = 0; src < table_size; src++) {
-    RoutingEdge *my_src =
-        xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdge*);
+    NetCard *my_src =
+        xbt_dynar_get_as(vertices_, src, NetCard*);
     for (dst = 0; dst < table_size; dst++) {
       if (src == dst)
         continue;
-      RoutingEdge *my_dst =
-          xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdge*);
+      NetCard *my_dst =
+          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(sg_routing_link_t), NULL);
@@ -188,7 +170,8 @@ void AsGeneric::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
       }
 
       xbt_dynar_foreach(route->link_list, cpt, link) {
-        const char *link_name = static_cast<Resource*>(link)->getName();
+        const char *link_name = static_cast<simgrid::surf::Resource*>(
+          link)->getName();
         current = new_xbt_graph_node(graph, link_name, nodes);
         current_name = link_name;
         new_xbt_graph_edge(graph, previous, current, edges);
@@ -213,8 +196,8 @@ void AsGeneric::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
   }
 }
 
-sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
-                                               RoutingEdge *dst,
+sg_platf_route_cbarg_t AsGeneric::getBypassRoute(NetCard *src,
+                                               NetCard *dst,
                                                double *lat)
 {
   // If never set a bypass route return NULL without any further computations
@@ -223,7 +206,7 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
     return NULL;
 
   sg_platf_route_cbarg_t e_route_bypass = NULL;
-  xbt_dict_t dict_bypassRoutes = p_bypassRoutes;
+  xbt_dict_t dict_bypassRoutes = bypassRoutes_;
 
   if(dst->getRcComponent() == this && src->getRcComponent() == this ){
     char *route_name = bprintf("%s#%s", src->getName(), dst->getName());
@@ -244,7 +227,7 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
     if (src == NULL || dst == NULL)
       xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
               src ? src->getName() : "(null)",
-              dst ? dst->getName() : "(null)", p_name);
+              dst ? dst->getName() : "(null)", name_);
 
     src_as = src->getRcComponent();
     dst_as = dst->getRcComponent();
@@ -254,13 +237,13 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
     current = src_as;
     while (current != NULL) {
       xbt_dynar_push(path_src, &current);
-      current = current->p_routingFather;
+      current = current->father_;
     }
     path_dst = xbt_dynar_new(sizeof(As*), NULL);
     current = dst_as;
     while (current != NULL) {
       xbt_dynar_push(path_dst, &current);
-      current = current->p_routingFather;
+      current = current->father_;
     }
 
     /* (3) find the common father */
@@ -288,9 +271,9 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
         if (i <= max_index_src && max <= max_index_dst) {
           char *route_name = bprintf("%s#%s",
               (*(As **)
-                  (xbt_dynar_get_ptr(path_src, i)))->p_name,
+                  (xbt_dynar_get_ptr(path_src, i)))->name_,
                   (*(As **)
-                      (xbt_dynar_get_ptr(path_dst, max)))->p_name);
+                      (xbt_dynar_get_ptr(path_dst, max)))->name_);
           e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
           xbt_free(route_name);
         }
@@ -299,9 +282,9 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
         if (max <= max_index_src && i <= max_index_dst) {
           char *route_name = bprintf("%s#%s",
               (*(As **)
-                  (xbt_dynar_get_ptr(path_src, max)))->p_name,
+                  (xbt_dynar_get_ptr(path_src, max)))->name_,
                   (*(As **)
-                      (xbt_dynar_get_ptr(path_dst, i)))->p_name);
+                      (xbt_dynar_get_ptr(path_dst, i)))->name_);
           e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
           xbt_free(route_name);
         }
@@ -315,9 +298,9 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
       if (max <= max_index_src && max <= max_index_dst) {
         char *route_name = bprintf("%s#%s",
             (*(As **)
-                (xbt_dynar_get_ptr(path_src, max)))->p_name,
+                (xbt_dynar_get_ptr(path_src, max)))->name_,
                 (*(As **)
-                    (xbt_dynar_get_ptr(path_dst, max)))->p_name);
+                    (xbt_dynar_get_ptr(path_dst, max)))->name_);
         e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
         xbt_free(route_name);
       }
@@ -331,7 +314,7 @@ sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdge *src,
 
   sg_platf_route_cbarg_t new_e_route = NULL;
   if (e_route_bypass) {
-         Link* link;
+    Link* link;
     unsigned int cpt = 0;
     new_e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
     new_e_route->gw_src = e_route_bypass->gw_src;
@@ -390,82 +373,31 @@ sg_platf_route_cbarg_t AsGeneric::newExtendedRoute(e_surf_routing_hierarchy_t hi
   return result;
 }
 
-
-
-As *AsGeneric::asExist(As *to_find)
-{
-  //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
-  xbt_dict_cursor_t cursor = NULL;
-  char *key;
-  int found = 0;
-  AsGeneric *elem;
-  xbt_dict_foreach(p_routingSons, cursor, key, elem) {
-    if (to_find == elem || elem->asExist(to_find)) {
-      found = 1;
-      break;
-    }
-  }
-  if (found)
-    return to_find;
-  return NULL;
-}
-
-As *AsGeneric::autonomousSystemExist(char *element)
-{
-  //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
-  As *element_as, *result, *elem;
-  xbt_dict_cursor_t cursor = NULL;
-  char *key;
-  element_as = ((RoutingEdge*)
-      xbt_lib_get_or_null(as_router_lib, element,
-          ROUTING_ASR_LEVEL))->getRcComponent();
-  result = ((As*) - 1);
-  if (element_as != this)
-    result = asExist(element_as);
-
-  int found = 0;
-  if (result) {
-    xbt_dict_foreach(element_as->p_routingSons, cursor, key, elem) {
-      found = !strcmp(elem->p_name, element);
-      if (found)
-        break;
-    }
-    if (found)
-      return element_as;
-  }
-  return NULL;
-}
-
-As *AsGeneric::processingUnitsExist(char *element)
-{
-  As *element_as = sg_host_edge(sg_host_by_name(element)) ->getRcComponent();
-  if (element_as == this)
-    return element_as;
-  return asExist(element_as);
-}
-
-void AsGeneric::srcDstCheck(RoutingEdge *src, RoutingEdge *dst)
+void AsGeneric::srcDstCheck(NetCard *src, NetCard *dst)
 {
   if (src == NULL || dst == NULL)
     xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
             src ? src->getName() : "(null)",
             dst ? dst->getName() : "(null)",
-            p_name);
+            name_);
 
   As *src_as = src->getRcComponent();
   As *dst_as = dst->getRcComponent();
 
   if (src_as != dst_as)
     xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
-        src->getName(), src_as->p_name,
-        dst->getName(), dst_as->p_name);
+        src->getName(), src_as->name_,
+        dst->getName(), dst_as->name_);
 
   if (this != dst_as)
     xbt_die
     ("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
         src->getName(),
         dst->getName(),
-        src_as->p_name,
-        dst_as->p_name,
-        p_name);
+        src_as->name_,
+        dst_as->name_,
+        name_);
+}
+
+}
 }