X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/eb2dd737c66528a85f0283e3fcbd81fd19de564e..702ac78afa738128143f0b2a03bad8484001407c:/src/surf/surf_routing.c diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 9161f01a12..fd3d3e18e8 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -170,8 +170,6 @@ static char *gw_src = NULL; /* temporary store the gateway source name of a static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */ static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */ -static xbt_dict_t coordinates = NULL; - static double eculidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) { @@ -188,8 +186,13 @@ static double vivaldi_get_link_latency (routing_component_t rc,const char *src, { double euclidean_dist; xbt_dynar_t src_ctn, dst_ctn; - src_ctn = xbt_dict_get(coordinates, src); - dst_ctn = xbt_dict_get(coordinates, dst); + src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL); + if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL); + dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL); + if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL); + + if(dst_ctn == NULL || src_ctn == NULL) + xbt_die("Coord src '%s' :%p dst '%s' :%p",src,src_ctn,dst,dst_ctn); euclidean_dist = sqrt (eculidean_dist_comp(0,src_ctn,dst_ctn)+eculidean_dist_comp(1,src_ctn,dst_ctn)) +fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *))); @@ -207,7 +210,7 @@ static double vivaldi_get_link_latency (routing_component_t rc,const char *src, if (strcmp(coord,"")) { xbt_dynar_t ctn = xbt_str_split_str(coord, " "); xbt_dynar_shrink(ctn,0); - xbt_dict_set (coordinates,host_id,ctn,NULL); + xbt_lib_set(host_lib, host_id, COORD_HOST_LEVEL, ctn); } */ } @@ -220,8 +223,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,12 +233,12 @@ 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,"")) { + if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'"); xbt_dynar_t ctn = xbt_str_split_str(coord, " "); xbt_dynar_shrink(ctn, 0); - xbt_dict_set(coordinates, host_id, ctn, xbt_dynar_free_voidp); + xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn); } } @@ -281,9 +283,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 +294,13 @@ 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,"")) { + 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_dict_set(coordinates, router_id, ctn, xbt_dynar_free_voidp); + xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn); } } @@ -565,10 +566,11 @@ static void parse_S_AS_XML(void) parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing); if (strcmp(A_surfxml_AS_coordinates,"")) { + if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'"); XBT_DEBUG("%s coordinates : %s", A_surfxml_AS_id, A_surfxml_AS_coordinates); xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_AS_coordinates, " "); xbt_dynar_shrink(ctn, 0); - xbt_dict_set(coordinates, A_surfxml_AS_id, ctn, xbt_dynar_free_voidp); + xbt_lib_set(as_router_lib,A_surfxml_AS_id,COORD_ASR_LEVEL,(void *) ctn); } } @@ -594,15 +596,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 +641,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 +672,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,9 +1043,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)); /* delete global routing structure */ @@ -1089,9 +1086,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 +1105,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; @@ -1118,8 +1119,6 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ /* no current routing at moment */ current_routing = NULL; - coordinates = xbt_dict_new(); - /* parse generic elements */ surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML); surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML); @@ -1383,7 +1382,7 @@ static void model_full_set_route(routing_component_t rc, const char *src, xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL); xbt_dynar_foreach(route->generic_route.link_list,i,link_name) { - void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); xbt_assert1(link,"Link : '%s' doesn't exists.",link_name); xbt_dynar_push(link_route_to_test,&link); } @@ -1427,7 +1426,7 @@ static void model_full_set_route(routing_component_t rc, const char *src, for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--) { link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *); - void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); xbt_assert1(link,"Link : '%s' doesn't exists.",link_name); xbt_dynar_push(link_route_to_test,&link); } @@ -1755,7 +1754,7 @@ static void model_floyd_set_route(routing_component_t rc, const char *src, xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL); xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name) { - void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); xbt_assert1(link,"Link : '%s' doesn't exists.",link_name); xbt_dynar_push(link_route_to_test,&link); } @@ -1800,7 +1799,7 @@ static void model_floyd_set_route(routing_component_t rc, const char *src, for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--) { link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *); - void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); xbt_assert1(link,"Link : '%s' doesn't exists.",link_name); xbt_dynar_push(link_route_to_test,&link); } @@ -2669,8 +2668,7 @@ static route_extended_t rulebased_get_route(routing_component_t rc, char *new_link_name = remplace(link_name, list_src, rc_src, list_dst, rc_dst); void *link = - xbt_dict_get_or_null(surf_network_model->resource_set, - new_link_name); + xbt_lib_get_or_null(link_lib, new_link_name, SURF_LINK_LEVEL); if (link) xbt_dynar_push(links_list, &link); else @@ -2995,11 +2993,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, @@ -3141,7 +3137,7 @@ generic_new_route(e_surf_routing_hierarchy_t hierarchy, xbt_dynar_foreach(links, cpt, link_name) { void *link = - xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); if (link) { if (order) xbt_dynar_push(links_id, &link); @@ -3197,7 +3193,7 @@ generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, xbt_dynar_foreach(links, cpt, link_name) { void *link = - xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); if (link) { if (order) xbt_dynar_push(links_id, &link); @@ -3257,9 +3253,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 +3276,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 +3286,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); @@ -3391,9 +3386,11 @@ static void routing_parse_Scluster(void) SURFXML_BUFFER_SET(AS_id, cluster_id); #ifdef HAVE_PCRE_LIB SURFXML_BUFFER_SET(AS_routing, "RuleBased"); + SURFXML_BUFFER_SET(AS_coordinates, ""); XBT_DEBUG("", cluster_id); #else SURFXML_BUFFER_SET(AS_routing, "Full"); + SURFXML_BUFFER_SET(AS_coordinates, ""); XBT_DEBUG("", cluster_id); #endif SURFXML_START_TAG(AS); @@ -3541,6 +3538,7 @@ static void routing_parse_Scluster(void) XBT_DEBUG("", router_id); SURFXML_BUFFER_SET(router_id, router_id); + SURFXML_BUFFER_SET(router_coordinates, ""); SURFXML_START_TAG(router); SURFXML_END_TAG(router);