From: Martin Quinson Date: Mon, 7 Nov 2011 11:04:31 +0000 (+0100) Subject: integrate properly the router creation in sg_platf module X-Git-Tag: exp_20120216~461 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6e7f2fe14eee0c4db1b815d0130dd8888886222c?hp=2693314e2da7ab10af2c7e2660e262289745945b integrate properly the router creation in sg_platf module --- diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index 89df78dc4a..5bade91c42 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -41,10 +41,17 @@ typedef struct s_surf_parsing_host_arg { const char* V_host_coord; } s_surf_parsing_host_arg_t, *surf_parsing_host_arg_t; +typedef struct s_surf_parsing_router_arg { + const char* V_router_id; + const char* V_router_coord; +} s_surf_parsing_router_arg_t, *surf_parsing_router_arg_t; + XBT_PUBLIC(void) sg_platf_new_AS_open(const char *id, const char *mode); XBT_PUBLIC(void) sg_platf_new_AS_close(void); XBT_PUBLIC(void) sg_platf_new_host(surf_parsing_host_arg_t h); +XBT_PUBLIC(void) sg_platf_new_router(surf_parsing_router_arg_t router); + #endif /* SG_PLATF_H */ diff --git a/include/surf/surfxml_parse.h b/include/surf/surfxml_parse.h index ba6e2db572..a1c1d922f0 100644 --- a/include/surf/surfxml_parse.h +++ b/include/surf/surfxml_parse.h @@ -18,7 +18,6 @@ SG_BEGIN_DECL() XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_platform_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_platform_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_host_cb_list; -XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_router_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_router_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_link_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_link_cb_list; diff --git a/src/include/simgrid/platf_interface.h b/src/include/simgrid/platf_interface.h index 4502cb0f39..bc84e74d96 100644 --- a/src/include/simgrid/platf_interface.h +++ b/src/include/simgrid/platf_interface.h @@ -18,7 +18,9 @@ void sg_platf_exit(void); /* Managing the parsing callbacks */ typedef void (*surf_parse_host_fct_t)(surf_parsing_host_arg_t); +typedef void (*surf_parse_router_fct_t)(surf_parsing_router_arg_t); void surf_parse_host_add_cb(surf_parse_host_fct_t); +void surf_parse_router_add_cb(surf_parse_router_fct_t); diff --git a/src/include/surf/surfxml_parse_values.h b/src/include/surf/surfxml_parse_values.h index c38d061365..01e259a1de 100644 --- a/src/include/surf/surfxml_parse_values.h +++ b/src/include/surf/surfxml_parse_values.h @@ -51,12 +51,6 @@ typedef struct s_surf_parsing_cluster_arg { char* V_cluster_state_file; } s_surf_parsing_cluster_arg_t; -typedef struct s_surf_parsing_router_arg *surf_parsing_router_arg_t; -typedef struct s_surf_parsing_router_arg { - char* V_router_id; - char* V_router_coord; -} s_surf_parsing_router_arg_t; - 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; @@ -64,7 +58,6 @@ typedef struct s_surf_parsing_link_up_down { } s_surf_parsing_link_up_down_t; -extern surf_parsing_router_arg_t struct_router; extern surf_parsing_cluster_arg_t struct_cluster; extern surf_parsing_peer_arg_t struct_peer; extern surf_parsing_link_arg_t struct_lnk; diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index 9d7488c32b..183ae07762 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -266,10 +266,10 @@ static void instr_routing_parse_start_host (surf_parsing_host_arg_t host) } } -static void instr_routing_parse_start_router () +static void instr_routing_parse_start_router (surf_parsing_router_arg_t router) { container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1); - newContainer (struct_router->V_router_id, INSTR_ROUTER, father); + newContainer (router->V_router_id, INSTR_ROUTER, father); } static void instr_routing_parse_end_platform () @@ -293,7 +293,7 @@ void instr_routing_define_callbacks () if (!TRACE_needs_platform()) return; surfxml_add_callback(STag_surfxml_link_cb_list, &instr_routing_parse_start_link); surf_parse_host_add_cb(instr_routing_parse_start_host); - surfxml_add_callback(STag_surfxml_router_cb_list, &instr_routing_parse_start_router); + surf_parse_router_add_cb(instr_routing_parse_start_router); surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform); } diff --git a/src/surf/sg_platf.c b/src/surf/sg_platf.c index f47d406953..ee11d0b844 100644 --- a/src/surf/sg_platf.c +++ b/src/surf/sg_platf.c @@ -13,14 +13,17 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); xbt_dynar_t surf_parse_host_cb_list = NULL; // of functions of type: surf_parsing_host_arg_t -> void +xbt_dynar_t surf_parse_router_cb_list = NULL; // of functions of type: surf_parsing_router_arg_t -> void /** Module management function: creates all internal data structures */ void sg_platf_init(void) { surf_parse_host_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_t), NULL); + surf_parse_router_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_t), NULL); } /** Module management function: frees all internal data structures */ void sg_platf_exit(void) { xbt_dynar_free(&surf_parse_host_cb_list); + xbt_dynar_free(&surf_parse_router_cb_list); } void sg_platf_new_host(surf_parsing_host_arg_t h){ @@ -30,6 +33,19 @@ void sg_platf_new_host(surf_parsing_host_arg_t h){ if (fun) (*fun) (h); } } +void sg_platf_new_router(surf_parsing_router_arg_t router) { + unsigned int iterator; + surf_parse_router_fct_t fun; + xbt_dynar_foreach(surf_parse_router_cb_list, iterator, fun) { + if (fun) (*fun) (router); + } +} + + void surf_parse_host_add_cb(surf_parse_host_fct_t fct) { xbt_dynar_push(surf_parse_host_cb_list, &fct); } +void surf_parse_router_add_cb(surf_parse_router_fct_t fct) { + xbt_dynar_push(surf_parse_router_cb_list, &fct); +} + diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 4a4077e4b2..ccb2c3ae08 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -207,48 +207,41 @@ static void parse_S_host_lua(const char *host_id, const char *coord) /** * \brief Add a "router" to the network element list */ -static void parse_S_router(void) +static void parse_S_router(surf_parsing_router_arg_t router) { network_element_info_t info = NULL; if (current_routing->hierarchy == SURF_ROUTING_NULL) current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert(!xbt_lib_get_or_null(as_router_lib,struct_router->V_router_id, ROUTING_ASR_LEVEL), + xbt_assert(!xbt_lib_get_or_null(as_router_lib,router->V_router_id, ROUTING_ASR_LEVEL), "Reading a router, processing unit \"%s\" already exists", - struct_router->V_router_id); + router->V_router_id); xbt_assert(current_routing->set_processing_unit, "no defined method \"set_processing_unit\" in \"%s\"", current_routing->name); (*(current_routing->set_processing_unit)) (current_routing, - struct_router->V_router_id); + router->V_router_id); info = xbt_new0(s_network_element_info_t, 1); info->rc_component = current_routing; info->rc_type = SURF_NETWORK_ELEMENT_ROUTER; - xbt_lib_set(as_router_lib,struct_router->V_router_id,ROUTING_ASR_LEVEL,(void *) info); + xbt_lib_set(as_router_lib,router->V_router_id,ROUTING_ASR_LEVEL,(void *) info); if (strcmp(A_surfxml_router_coordinates,"")) { if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'"); xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " "); xbt_dynar_shrink(ctn, 0); - xbt_lib_set(as_router_lib,struct_router->V_router_id,COORD_ASR_LEVEL,(void *) ctn); + xbt_lib_set(as_router_lib,router->V_router_id,COORD_ASR_LEVEL,(void *) ctn); } } /** * brief Add a "router" to the network element list from XML description */ -static void parse_S_router_XML(void) -{ - return parse_S_router(); -} - -/** - * brief Add a "router" to the network element list from XML description - */ -static void parse_S_router_lua(const char* router_id) -{ - struct_router->V_router_id = xbt_strdup(router_id); - struct_router->V_router_coord = xbt_strdup(""); - return parse_S_router(); +static void parse_S_router_lua(const char* router_id) { + s_surf_parsing_router_arg_t router; + memset(&router,0,sizeof(router)); + router.V_router_id = router_id; + router.V_router_coord = ""; + return parse_S_router(&router); } /** @@ -969,7 +962,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ /* parse generic elements */ surf_parse_host_add_cb(parse_S_host_XML); surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML); - surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML); + surf_parse_router_add_cb(parse_S_router); surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints_XML); diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 6ee50e77e3..58d320be70 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -52,7 +52,6 @@ int surf_parse_get_int(const char *string) { xbt_dynar_t STag_surfxml_platform_cb_list = NULL; xbt_dynar_t ETag_surfxml_platform_cb_list = NULL; xbt_dynar_t ETag_surfxml_host_cb_list = NULL; -xbt_dynar_t STag_surfxml_router_cb_list = NULL; xbt_dynar_t ETag_surfxml_router_cb_list = NULL; xbt_dynar_t STag_surfxml_link_cb_list = NULL; xbt_dynar_t ETag_surfxml_link_cb_list = NULL; @@ -163,7 +162,6 @@ void surf_parse_init_callbacks(void) sg_platf_init(); ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); @@ -228,7 +226,6 @@ void surf_parse_free_callbacks(void) xbt_dynar_free(&STag_surfxml_platform_cb_list); xbt_dynar_free(&ETag_surfxml_platform_cb_list); xbt_dynar_free(&ETag_surfxml_host_cb_list); - xbt_dynar_free(&STag_surfxml_router_cb_list); xbt_dynar_free(&ETag_surfxml_router_cb_list); xbt_dynar_free(&STag_surfxml_link_cb_list); xbt_dynar_free(&ETag_surfxml_link_cb_list); @@ -317,16 +314,15 @@ void ETag_surfxml_host(void){ void STag_surfxml_router(void){ - struct_router = xbt_new0(s_surf_parsing_router_arg_t, 1); - struct_router->V_router_id = xbt_strdup(A_surfxml_router_id); - struct_router->V_router_coord = xbt_strdup(A_surfxml_router_coordinates); - surfxml_call_cb_functions(STag_surfxml_router_cb_list); + s_surf_parsing_router_arg_t router; + memset(&router, 0, sizeof(router)); + + router.V_router_id = xbt_strdup(A_surfxml_router_id); + router.V_router_coord = xbt_strdup(A_surfxml_router_coordinates); + sg_platf_new_router(&router); } void ETag_surfxml_router(void){ surfxml_call_cb_functions(ETag_surfxml_router_cb_list); - xbt_free(struct_router->V_router_id); - xbt_free(struct_router->V_router_coord); - xbt_free(struct_router); } void STag_surfxml_cluster(void){