Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
routing: inline method routing_get_network_element_type
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 20 Feb 2016 00:33:21 +0000 (01:33 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 20 Feb 2016 00:33:28 +0000 (01:33 +0100)
This was a C->C++ adapter

(+ rename a netcard field in instr, and other cosmetics)

src/include/surf/surf.h
src/instr/instr_paje_containers.cpp
src/instr/instr_private.h
src/simgrid/host.cpp
src/surf/sg_platf.cpp
src/surf/surf_routing.cpp
teshsuite/simdag/platforms/CMakeLists.txt
teshsuite/simdag/platforms/flatifier.cpp
teshsuite/simdag/platforms/flatifier.tesh
teshsuite/simdag/platforms/is_router_test.cpp [moved from teshsuite/simdag/platforms/is_router_test.c with 78% similarity]

index 7bb0115..a8fcd8e 100644 (file)
@@ -133,9 +133,6 @@ typedef surf_RoutingPlatf *routing_platf_t;
 
 typedef struct surf_file *surf_file_t;
 
 
 typedef struct surf_file *surf_file_t;
 
-XBT_PUBLIC(e_surf_network_element_type_t)
-  routing_get_network_element_type(const char* name);
-
 /** @Brief Specify that we use that action */
 XBT_PUBLIC(void) surf_action_ref(surf_action_t action);
 
 /** @Brief Specify that we use that action */
 XBT_PUBLIC(void) surf_action_ref(surf_action_t action);
 
index f9606bd..cab67f4 100644 (file)
@@ -60,19 +60,19 @@ container_t PJ_container_new (const char *name, e_container_types kind, containe
   //Search for network_element_t
   switch (kind){
     case INSTR_HOST:
   //Search for network_element_t
   switch (kind){
     case INSTR_HOST:
-      newContainer->net_elm = sg_host->pimpl_netcard;
-      if(!newContainer->net_elm) xbt_die("Element '%s' not found",name);
+      newContainer->netcard = sg_host->pimpl_netcard;
+      if(!newContainer->netcard) xbt_die("Element '%s' not found",name);
       break;
     case INSTR_ROUTER:
       break;
     case INSTR_ROUTER:
-      newContainer->net_elm = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL);
-      if(!newContainer->net_elm) xbt_die("Element '%s' not found",name);
+      newContainer->netcard = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL);
+      if(!newContainer->netcard) xbt_die("Element '%s' not found",name);
       break;
     case INSTR_AS:
       break;
     case INSTR_AS:
-      newContainer->net_elm = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL);
-      if(!newContainer->net_elm) xbt_die("Element '%s' not found",name);
+      newContainer->netcard = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL);
+      if(!newContainer->netcard) xbt_die("Element '%s' not found",name);
       break;
     default:
       break;
     default:
-      newContainer->net_elm = NULL;
+      newContainer->netcard = NULL;
       break;
   }
 
       break;
   }
 
index 47e937a..0bcb00f 100644 (file)
@@ -89,7 +89,7 @@ typedef enum {
 
 typedef struct s_container *container_t;
 typedef struct s_container {
 
 typedef struct s_container *container_t;
 typedef struct s_container {
-  sg_netcard_t net_elm;
+  sg_netcard_t netcard;
   char *name;     /* Unique name of this container */
   char *id;       /* Unique id of this container */
   type_t type;    /* Type of this container */
   char *name;     /* Unique name of this container */
   char *id;       /* Unique id of this container */
   type_t type;    /* Type of this container */
index 9e26ad8..cbe140a 100644 (file)
@@ -67,7 +67,7 @@ xbt_dynar_t sg_hosts_as_dynar(void)
   const char* name = nullptr;
   simgrid::s4u::Host* host = nullptr;
   xbt_dict_foreach(host_list, cursor, name, host)
   const char* name = nullptr;
   simgrid::s4u::Host* host = nullptr;
   xbt_dict_foreach(host_list, cursor, name, host)
-    if(routing_get_network_element_type(name) == SURF_NETWORK_ELEMENT_HOST)
+    if (host && host->pimpl_netcard && host->pimpl_netcard->getRcType() == SURF_NETWORK_ELEMENT_HOST)
        xbt_dynar_push(res, &host);
   return res;
 }
        xbt_dynar_push(res, &host);
   return res;
 }
index 2e0adca..e22a05c 100644 (file)
@@ -122,15 +122,14 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
 
   if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
     current_routing->hierarchy_ = SURF_ROUTING_BASE;
 
   if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
     current_routing->hierarchy_ = SURF_ROUTING_BASE;
-  xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
-             "Reading a router, processing unit \"%s\" already exists",
-             router->id);
-
-  simgrid::surf::NetCard *info = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
-  info->setId(current_routing->addComponent(info));
-  xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
-  XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->id());
-  simgrid::surf::netcardCreatedCallbacks(info);
+  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);
+
+  simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
+  netcard->setId(current_routing->addComponent(netcard));
+  xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) netcard);
+  XBT_DEBUG("Having set name '%s' id '%d'", router->id, netcard->id());
+  simgrid::surf::netcardCreatedCallbacks(netcard);
 
   if (router->coord && strcmp(router->coord, "")) {
     unsigned int cursor;
 
   if (router->coord && strcmp(router->coord, "")) {
     unsigned int cursor;
index 2fa1297..dee4649 100644 (file)
@@ -94,10 +94,10 @@ int ROUTING_PROP_ASR_LEVEL;     //Where the properties are stored
 simgrid::surf::NetCard *sg_netcard_by_name_or_null(const char *name)
 {
   sg_host_t h = sg_host_by_name(name);
 simgrid::surf::NetCard *sg_netcard_by_name_or_null(const char *name)
 {
   sg_host_t h = sg_host_by_name(name);
-  simgrid::surf::NetCard *net_elm = h==NULL?NULL: h->pimpl_netcard;
-  if (!net_elm)
-    net_elm = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
-  return net_elm;
+  simgrid::surf::NetCard *netcard = h==NULL ? NULL: h->pimpl_netcard;
+  if (!netcard)
+    netcard = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
+  return netcard;
 }
 
 /* Global vars */
 }
 
 /* Global vars */
@@ -166,7 +166,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
 {
   XBT_DEBUG("routing_AS_begin");
 
 {
   XBT_DEBUG("routing_AS_begin");
 
-  xbt_assert(NULL == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL),
+  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
       "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
@@ -214,8 +214,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
     THROWF(arg_error, 0, "All defined components must belong to a AS");
   }
 
     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_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 */
   XBT_DEBUG("Having set name '%s' id '%d'", new_as->name_, netcard->id());
 
   /* set the new current component of the tree */
@@ -432,15 +431,6 @@ xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
 }
 }
 
 }
 }
 
-e_surf_network_element_type_t routing_get_network_element_type(const char *name)
-{
-  simgrid::surf::NetCard *rc = sg_netcard_by_name_or_null(name);
-  if (rc)
-    return rc->getRcType();
-
-  return SURF_NETWORK_ELEMENT_NULL;
-}
-
 /** @brief create the root AS */
 void routing_model_create( void *loopback)
 {
 /** @brief create the root AS */
 void routing_model_create( void *loopback)
 {
index 73140d1..a47bf68 100644 (file)
@@ -1,7 +1,7 @@
 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_executable(basic_parsing_test basic_parsing_test.c)
 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_executable(basic_parsing_test basic_parsing_test.c)
-add_executable(is_router_test is_router_test.c)
+add_executable(is_router_test is_router_test.cpp)
 add_executable(flatifier flatifier.cpp)
 add_executable(basic_tracing basic_tracing.c)
 add_executable(basic_link_test basic_link_test.c)
 add_executable(flatifier flatifier.cpp)
 add_executable(basic_tracing basic_tracing.c)
 add_executable(basic_link_test basic_link_test.c)
index ccda631..c46abfc 100644 (file)
@@ -155,8 +155,8 @@ int main(int argc, char **argv)
 
     // Routers
     xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
 
     // Routers
     xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
-      if(surf_routing_edge_get_rc_type((sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key,
-          ROUTING_ASR_LEVEL)) == SURF_NETWORK_ELEMENT_ROUTER)
+      value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key, ROUTING_ASR_LEVEL);
+      if(value1->getRcType() == SURF_NETWORK_ELEMENT_ROUTER)
       {
         printf("  <router id=\"%s\"/>\n",key);
       }
       {
         printf("  <router id=\"%s\"/>\n",key);
       }
@@ -188,9 +188,7 @@ int main(int argc, char **argv)
       value1 = sg_host_by_name(src)->pimpl_netcard;
       xbt_dict_foreach(host_list, cursor_dst, dst, host2) //to host
       {
       value1 = sg_host_by_name(src)->pimpl_netcard;
       xbt_dict_foreach(host_list, cursor_dst, dst, host2) //to host
       {
-        printf("  <route src=\"%s\" dst=\"%s\">\n  "
-            ,src
-            ,dst);
+        printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
         xbt_dynar_t route=NULL;
         value2 = sg_host_by_name(dst)->pimpl_netcard;
         routing_platf->getRouteAndLatency(value1, value2, &route,NULL);
         xbt_dynar_t route=NULL;
         value2 = sg_host_by_name(dst)->pimpl_netcard;
         routing_platf->getRouteAndLatency(value1, value2, &route,NULL);
@@ -206,20 +204,16 @@ int main(int argc, char **argv)
       }
       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
       {
       }
       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
       {
-        if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
-          printf("  <route src=\"%s\" dst=\"%s\">\n  "
-              ,src
-              ,dst);
+        value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
+        if(value2->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
+          printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
           xbt_dynar_t route=NULL;
           xbt_dynar_t route=NULL;
-          value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
           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 *);
 
           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 *);
 
-            char *link_name = xbt_strdup(surf_resource_name((surf_cpp_resource_t)link));
-            printf("<%s id=\"%s\"/>",link_ctn,link_name);
-            free(link_name);
+            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
           }
           printf("\n  </route>\n");
         }
           }
           printf("\n  </route>\n");
         }
@@ -229,15 +223,13 @@ int main(int argc, char **argv)
     xbt_lib_foreach(as_router_lib, cursor_src, src, value1) // Routes from router
     {
       value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
     xbt_lib_foreach(as_router_lib, cursor_src, src, value1) // Routes from router
     {
       value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
-      if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_ROUTER){
+      if (value1->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
         xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
           {
         xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
           {
-          if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
-            printf("  <route src=\"%s\" dst=\"%s\">\n  "
-                ,src
-                ,dst);
+          value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
+          if(value2->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
+            printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
             xbt_dynar_t route=NULL;
             xbt_dynar_t route=NULL;
-            value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
             routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
             for(i=0;i<xbt_dynar_length(route) ;i++)
             {
             routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
             for(i=0;i<xbt_dynar_length(route) ;i++)
             {
index afa5236..7991374 100644 (file)
@@ -1,7 +1,5 @@
 #! ./tesh
 
 #! ./tesh
 
-! output sort
-
 $ ${bindir:=.}/flatifier$EXEEXT one_cluster.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n"
 > [  0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks.
 > <?xml version='1.0'?>
 $ ${bindir:=.}/flatifier$EXEEXT one_cluster.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n"
 > [  0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks.
 > <?xml version='1.0'?>
similarity index 78%
rename from teshsuite/simdag/platforms/is_router_test.c
rename to teshsuite/simdag/platforms/is_router_test.cpp
index cb89fab..fbe96d0 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include "simgrid/simdag.h"
 #include "surf/surf.h"
 #include <stdlib.h>
 #include "simgrid/simdag.h"
 #include "surf/surf.h"
+#include "src/surf/surf_routing.hpp"
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
@@ -26,10 +27,10 @@ int main(int argc, char **argv)
   printf("Workstation number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
 
   xbt_dict_foreach(host_list, cursor, key, data)
   printf("Workstation number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
 
   xbt_dict_foreach(host_list, cursor, key, data)
-    printf("   - Seen: \"%s\" is type : %d\n", key, (int) routing_get_network_element_type(key));
+    printf("   - Seen: \"%s\" is type : %d\n", key, (int) sg_netcard_by_name_or_null(key)->getRcType());
 
   xbt_lib_foreach(as_router_lib, cursor, key, data)
 
   xbt_lib_foreach(as_router_lib, cursor, key, data)
-    printf("   - Seen: \"%s\" is type : %d\n", key, (int) routing_get_network_element_type(key));
+    printf("   - Seen: \"%s\" is type : %d\n", key, (int) sg_netcard_by_name_or_null(key)->getRcType());
 
   SD_exit();
   return 0;
 
   SD_exit();
   return 0;