From 8d900364a801ea8e049c5862e360aedea8093094 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 20 Feb 2016 01:33:21 +0100 Subject: [PATCH] routing: inline method routing_get_network_element_type This was a C->C++ adapter (+ rename a netcard field in instr, and other cosmetics) --- src/include/surf/surf.h | 3 -- src/instr/instr_paje_containers.cpp | 14 ++++----- src/instr/instr_private.h | 2 +- src/simgrid/host.cpp | 2 +- src/surf/sg_platf.cpp | 17 +++++------ src/surf/surf_routing.cpp | 22 ++++---------- teshsuite/simdag/platforms/CMakeLists.txt | 2 +- teshsuite/simdag/platforms/flatifier.cpp | 30 +++++++------------ teshsuite/simdag/platforms/flatifier.tesh | 2 -- .../{is_router_test.c => is_router_test.cpp} | 5 ++-- 10 files changed, 38 insertions(+), 61 deletions(-) rename teshsuite/simdag/platforms/{is_router_test.c => is_router_test.cpp} (78%) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 7bb011594e..a8fcd8e279 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -133,9 +133,6 @@ typedef surf_RoutingPlatf *routing_platf_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); diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index f9606bd78b..cab67f4014 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -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: - 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: - 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: - 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: - newContainer->net_elm = NULL; + newContainer->netcard = NULL; break; } diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index 47e937adff..0bcb00f618 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -89,7 +89,7 @@ typedef enum { 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 */ diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 9e26ad8f8e..cbe140a730 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -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) - 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; } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 2e0adcac07..e22a05c731 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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; - 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; diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 2fa1297d6d..dee4649daf 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -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 *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 */ @@ -166,7 +166,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS) { 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 @@ -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"); } - 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 */ @@ -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) { diff --git a/teshsuite/simdag/platforms/CMakeLists.txt b/teshsuite/simdag/platforms/CMakeLists.txt index 73140d103e..a47bf6866c 100644 --- a/teshsuite/simdag/platforms/CMakeLists.txt +++ b/teshsuite/simdag/platforms/CMakeLists.txt @@ -1,7 +1,7 @@ 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) diff --git a/teshsuite/simdag/platforms/flatifier.cpp b/teshsuite/simdag/platforms/flatifier.cpp index ccda6312b0..c46abfccec 100644 --- a/teshsuite/simdag/platforms/flatifier.cpp +++ b/teshsuite/simdag/platforms/flatifier.cpp @@ -155,8 +155,8 @@ int main(int argc, char **argv) // 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(" \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 { - printf(" \n " - ,src - ,dst); + printf(" \n ", src, dst); 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 { - if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){ - printf(" \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(" \n ", src, dst); 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",link_ctn,link_name); - free(link_name); + printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link)); } printf("\n \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); - 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 { - if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){ - printf(" \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(" \n ", src, dst); 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 [ 0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks. > diff --git a/teshsuite/simdag/platforms/is_router_test.c b/teshsuite/simdag/platforms/is_router_test.cpp similarity index 78% rename from teshsuite/simdag/platforms/is_router_test.c rename to teshsuite/simdag/platforms/is_router_test.cpp index cb89fab666..fbe96d08ae 100644 --- a/teshsuite/simdag/platforms/is_router_test.c +++ b/teshsuite/simdag/platforms/is_router_test.cpp @@ -8,6 +8,7 @@ #include #include "simgrid/simdag.h" #include "surf/surf.h" +#include "src/surf/surf_routing.hpp" 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(" - 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) - 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; -- 2.20.1