From: navarrop Date: Thu, 24 Mar 2011 10:35:26 +0000 (+0000) Subject: Remove where_network_elements and add element in host_lib and as_router_lib X-Git-Tag: v3.6_beta2~141 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/62da5664b681577c99a3b0f51d8395876e7ecdf5 Remove where_network_elements and add element in host_lib and as_router_lib git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9828 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index e1e11d2acf..55a97783d1 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -187,7 +187,6 @@ typedef int *network_element_t; struct s_routing_global { routing_component_t root; - xbt_dict_t where_network_elements; /* char* -> network_element_info_t */ void *loopback; size_t size_of_link; xbt_dynar_t(*get_route) (const char *src, const char *dst); diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 9161f01a12..2ac012e27b 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -220,8 +220,7 @@ static void parse_S_host(const char *host_id, const char* coord) network_element_info_t info = NULL; if (current_routing->hierarchy == SURF_ROUTING_NULL) current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert1(!xbt_dict_get_or_null - (global_routing->where_network_elements, host_id), + xbt_assert1(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL), "Reading a host, processing unit \"%s\" already exists", host_id); xbt_assert1(current_routing->set_processing_unit, @@ -231,8 +230,7 @@ static void parse_S_host(const char *host_id, const char* coord) info = xbt_new0(s_network_element_info_t, 1); info->rc_component = current_routing; info->rc_type = SURF_NETWORK_ELEMENT_HOST; - xbt_dict_set(global_routing->where_network_elements, host_id, - (void *) info, xbt_free); + xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info); if (strcmp(coord,"")) { xbt_dynar_t ctn = xbt_str_split_str(coord, " "); xbt_dynar_shrink(ctn, 0); @@ -281,9 +279,7 @@ static void parse_S_router(const char *router_id) if (current_routing->hierarchy == SURF_ROUTING_NULL) current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert1(!xbt_dict_get_or_null - (global_routing->where_network_elements, - A_surfxml_router_id), + xbt_assert1(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL), "Reading a router, processing unit \"%s\" already exists", router_id); xbt_assert1(current_routing->set_processing_unit, @@ -294,12 +290,12 @@ static void parse_S_router(const char *router_id) info = xbt_new0(s_network_element_info_t, 1); info->rc_component = current_routing; info->rc_type = SURF_NETWORK_ELEMENT_ROUTER; - xbt_dict_set(global_routing->where_network_elements, router_id, - (void *) info, xbt_free); + + xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info); if (strcmp(A_surfxml_router_coordinates,"")) { - xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " "); - xbt_dynar_shrink(ctn, 0); - xbt_dict_set(coordinates, router_id, ctn, xbt_dynar_free_voidp); + xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " "); + xbt_dynar_shrink(ctn, 0); + xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn); } } @@ -594,15 +590,13 @@ static void parse_E_AS(const char *AS_id) THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id); } else { network_element_info_t info = NULL; - xbt_assert1(!xbt_dict_get_or_null - (global_routing->where_network_elements, - current_routing->name), "The AS \"%s\" already exists", - current_routing->name); + xbt_assert1(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL), + "The AS \"%s\" already exists",current_routing->name); info = xbt_new0(s_network_element_info_t, 1); info->rc_component = current_routing->routing_father; info->rc_type = SURF_NETWORK_ELEMENT_AS; - xbt_dict_set(global_routing->where_network_elements, - current_routing->name, info, xbt_free); + xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info); + (*(current_routing->routing->unload)) (); (*(current_routing->routing->end)) (); current_routing = current_routing->routing_father; @@ -641,8 +635,7 @@ static char* elements_As_name(const char *name) /* (1) find the as where the host is located */ as_comp = ((network_element_info_t) - xbt_dict_get_or_null(global_routing->where_network_elements, - name))->rc_component; + xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component; return as_comp->name; } @@ -673,12 +666,13 @@ static xbt_dynar_t elements_father(const char *src, const char *dst) routing_component_t *father = NULL; /* (1) find the as where the src and dst are located */ - src_as = ((network_element_info_t) - xbt_dict_get_or_null(global_routing->where_network_elements, - src))->rc_component; - dst_as = ((network_element_info_t) - xbt_dict_get_or_null(global_routing->where_network_elements, - dst))->rc_component; + void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL); + void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL); + if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL); + if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL); + src_as = ((network_element_info_t)src_data)->rc_component; + dst_as = ((network_element_info_t)dst_data)->rc_component; + xbt_assert2(src_as && dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, @@ -1043,8 +1037,6 @@ static void finalize(void) { /* delete recursibly all the tree */ _finalize(global_routing->root); - /* delete "where" dict */ - xbt_dict_free(&(global_routing->where_network_elements)); xbt_dict_free(&(coordinates)); /* delete last_route */ xbt_dynar_free(&(global_routing->last_route)); @@ -1089,9 +1081,14 @@ e_surf_network_element_type_t get_network_element_type(const char *name) { network_element_info_t rc = NULL; - rc = xbt_dict_get_or_null(global_routing->where_network_elements, name); - if(!rc) return SURF_NETWORK_ELEMENT_NULL; - return rc->rc_type; + + rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL); + if(rc) return rc->rc_type; + + rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL); + if(rc) return rc->rc_type; + + return SURF_NETWORK_ELEMENT_NULL; } /** @@ -1103,7 +1100,6 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ { /* config the uniq global routing */ global_routing = xbt_new0(s_routing_global_t, 1); - global_routing->where_network_elements = xbt_dict_new(); global_routing->root = NULL; global_routing->get_route = get_route; global_routing->get_latency = get_latency; @@ -2995,11 +2991,9 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc, /* (1) find the as where the src and dst are located */ src_as = ((network_element_info_t) - xbt_dict_get_or_null(global_routing->where_network_elements, - src))->rc_component; + xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL))->rc_component; dst_as = ((network_element_info_t) - xbt_dict_get_or_null(global_routing->where_network_elements, - dst))->rc_component; + xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL))->rc_component; xbt_assert2(src_as && dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, @@ -3257,9 +3251,7 @@ generic_autonomous_system_exist(routing_component_t rc, char *element) xbt_dict_cursor_t cursor = NULL; char *key; element_as = ((network_element_info_t) - xbt_dict_get_or_null - (global_routing->where_network_elements, - element))->rc_component; + xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component; result = ((routing_component_t) - 1); if (element_as != rc) result = generic_as_exist(rc, element_as); @@ -3282,9 +3274,8 @@ generic_processing_units_exist(routing_component_t rc, char *element) { routing_component_t element_as; element_as = ((network_element_info_t) - xbt_dict_get_or_null - (global_routing->where_network_elements, - element))->rc_component; + xbt_lib_get_or_null(host_lib, + element, ROUTING_HOST_LEVEL))->rc_component; if (element_as == rc) return element_as; return generic_as_exist(rc, element_as); @@ -3293,17 +3284,19 @@ generic_processing_units_exist(routing_component_t rc, char *element) static void generic_src_dst_check(routing_component_t rc, const char *src, const char *dst) { - routing_component_t src_as = ((network_element_info_t) - xbt_dict_get_or_null - (global_routing->where_network_elements, - src))->rc_component; - routing_component_t dst_as = ((network_element_info_t) - xbt_dict_get_or_null - (global_routing->where_network_elements, - dst))->rc_component; - if(src_as == NULL || dst_as == NULL) + + void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL); + void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL); + if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL); + if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL); + + if(src_data == NULL || dst_data == NULL) xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"", - src, dst, rc->name); + src, dst, rc->name); + + routing_component_t src_as = ((network_element_info_t)src_data)->rc_component; + routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component; + if(src_as != dst_as) xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS", src, src_as->name, dst, dst_as->name); diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index 456499ca38..90c7cc3bb0 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -50,9 +50,10 @@ int main(int argc, char **argv) unsigned int i; xbt_dict_t props = NULL; xbt_dict_cursor_t cursor = NULL; - xbt_dict_cursor_t cursor_src = NULL; - xbt_dict_cursor_t cursor_dst = NULL; + xbt_lib_cursor_t cursor_src = NULL; + xbt_lib_cursor_t cursor_dst = NULL; char *src,*dst,*key,*data; + char **value; xbt_ex_t e; const SD_workstation_t *hosts; @@ -96,9 +97,9 @@ int main(int argc, char **argv) } // Routers - xbt_dict_foreach(global_routing->where_network_elements, cursor, key, data) { - if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, key))->rc_type - == SURF_NETWORK_ELEMENT_ROUTER) + xbt_lib_foreach(as_router_lib, cursor_src, key, value) { + if(((network_element_info_t)xbt_lib_get_or_null(as_router_lib, key, + ROUTING_ASR_LEVEL))->rc_type == SURF_NETWORK_ELEMENT_ROUTER) { printf(" \n",key); } @@ -107,6 +108,7 @@ int main(int argc, char **argv) // Links totalLinks = SD_link_get_number(); links = SD_link_get_list(); + qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links); for (i = 0; i < totalLinks; i++) { @@ -123,21 +125,28 @@ int main(int argc, char **argv) } } - // Routes - xbt_dict_foreach(global_routing->where_network_elements, cursor_src, src, data) + + xbt_lib_foreach(host_lib, cursor_src, src, value) // Routes from host { - if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, src))->rc_type - == SURF_NETWORK_ELEMENT_ROUTER || - ((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, src))->rc_type - == SURF_NETWORK_ELEMENT_HOST) - { - xbt_dict_foreach(global_routing->where_network_elements, cursor_dst, dst, data) + xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host + { + printf(" \n " + ,src + ,dst); + xbt_dynar_t route = global_routing->get_route(src,dst); + for(i=0;iname); + printf("",link_name); + free(link_name); + } + printf("\n \n"); + } + xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router { - if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, dst))->rc_type - == SURF_NETWORK_ELEMENT_ROUTER || - ((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, dst))->rc_type - == SURF_NETWORK_ELEMENT_HOST) - { + if(get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){ printf(" \n " ,src ,dst); @@ -151,8 +160,46 @@ int main(int argc, char **argv) free(link_name); } printf("\n \n"); + } + } + } - } + xbt_lib_foreach(as_router_lib, cursor_src, src, value) // Routes from router + { + if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_ROUTER){ + xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router + { + if(get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){ + printf(" \n " + ,src + ,dst); + xbt_dynar_t route = global_routing->get_route(src,dst); + for(i=0;iname); + printf("",link_name); + free(link_name); + } + printf("\n \n"); + } + } + xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host + { + printf(" \n " + ,src + ,dst); + xbt_dynar_t route = global_routing->get_route(src,dst); + for(i=0;iname); + printf("",link_name); + free(link_name); + } + printf("\n \n"); } } } diff --git a/teshsuite/simdag/platforms/is_router_test.c b/teshsuite/simdag/platforms/is_router_test.c index 8a7a50857d..df144883a2 100644 --- a/teshsuite/simdag/platforms/is_router_test.c +++ b/teshsuite/simdag/platforms/is_router_test.c @@ -16,21 +16,27 @@ int main(int argc, char **argv) /* initialisation of SD */ int size; SD_init(&argc, argv); - xbt_dict_cursor_t cursor = NULL; + xbt_lib_cursor_t cursor = NULL; char *key, *data; /* creation of the environment */ SD_create_environment(argv[1]); - size = xbt_dict_size(global_routing->where_network_elements); + size = xbt_lib_size(host_lib) + xbt_lib_size(as_router_lib); printf("Workstation number: %d, link number: %d, elmts number: %d\n", SD_workstation_get_number(), SD_link_get_number(), size); - xbt_dict_foreach(global_routing->where_network_elements, cursor, key, data) { + xbt_lib_foreach(host_lib, cursor, key, data) { printf(" - Seen: \"%s\" is type : %d\n", key, (int) global_routing->get_network_element_type(key)); } + + xbt_lib_foreach(as_router_lib, cursor, key, data) { + printf(" - Seen: \"%s\" is type : %d\n", key, + (int) global_routing->get_network_element_type(key)); + } + SD_exit(); return 0; } diff --git a/tools/graphicator/graphicator.c b/tools/graphicator/graphicator.c index 638073abad..a760788c3d 100644 --- a/tools/graphicator/graphicator.c +++ b/tools/graphicator/graphicator.c @@ -81,12 +81,12 @@ int main(int argc, char **argv) char *graphvizFile = NULL; unsigned int i; - xbt_dict_cursor_t cursor_src = NULL; - xbt_dict_cursor_t cursor_dst = NULL; char *src; char *dst; - char *data; xbt_ex_t e; + xbt_lib_cursor_t cursor,cursor_src,cursor_dst; + char * key; + char **data; SD_init(&argc, argv); @@ -107,8 +107,10 @@ int main(int argc, char **argv) xbt_graph_t graph = xbt_graph_new_graph (0, NULL); //adding hosts - xbt_dict_foreach(global_routing->where_network_elements, cursor_src, src, data) { - xbt_graph_new_node (graph, xbt_strdup(src)); + xbt_lib_foreach(host_lib,cursor,key,data){ + if(get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST || + get_network_element_type(key) == SURF_NETWORK_ELEMENT_ROUTER ) + xbt_graph_new_node (graph, xbt_strdup(key)); } //adding links @@ -119,9 +121,9 @@ int main(int argc, char **argv) xbt_graph_new_node (graph, xbt_strdup (SD_link_get_name(links[i]))); } - xbt_dict_foreach(global_routing->where_network_elements, cursor_src, src, data) { - xbt_dict_foreach(global_routing->where_network_elements, cursor_dst, dst, data) { - if (strcmp(src,"loopback")==0 || strcmp(dst,"loopback")==0) continue; + + xbt_lib_foreach(host_lib,cursor_src,src,data){ + xbt_lib_foreach(host_lib,cursor_dst,dst,data){ xbt_node_t src_node = xbt_graph_search_node (graph, src, strcmp); xbt_node_t dst_node = xbt_graph_search_node (graph, dst, strcmp);