X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/515690f98e16a5c252ec16d5f5373e4a318547bc..80f4255f4efe689fb70fa5da4cf28e5fbc72d865:/src/surf/surf_routing.c diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 1d4972b5ce..e55fd87684 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2009 The SimGrid team. All rights reserved. */ +/* Copyright (c) 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -66,7 +67,7 @@ typedef struct { #define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count] #define HOST2ROUTER(id) ((id)+(2<<29)) -#define ROUTER2HOST(id) ((id)-(2>>29)) +#define ROUTER2HOST(id) ((id)-(2<<29)) #define ISROUTER(id) ((id)>=(2<<29)) /* @@ -87,6 +88,9 @@ static void routing_full_parse_Shost(void) { DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count); *val = used_routing->host_count++; xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free); +#ifdef HAVE_TRACING + TRACE_surf_host_define_id (A_surfxml_host_id, *val); +#endif } static void routing_full_parse_Srouter(void) { @@ -95,6 +99,10 @@ static void routing_full_parse_Srouter(void) { HOST2ROUTER(used_routing->router_count)); *val = HOST2ROUTER(used_routing->router_count++); xbt_dict_set(used_routing->host_id,A_surfxml_router_id,val,xbt_free); +#ifdef HAVE_TRACING + TRACE_surf_host_define_id (A_surfxml_router_id, *val); + TRACE_surf_host_declaration (A_surfxml_router_id, 0); +#endif } static int src_id = -1; @@ -164,7 +172,9 @@ static void routing_full_parse_Scluster(void) char *cluster_bb_bw = A_surfxml_cluster_bb_bw; char *cluster_bb_lat = A_surfxml_cluster_bb_lat; char *backbone_name; - + unsigned int it1,it2; + char *name1,*name2; + xbt_dynar_t names = NULL; surfxml_bufferstack_push(1); /* Make set a set to parse the prefix/suffix/radical into a neat list of names */ @@ -178,10 +188,8 @@ static void routing_full_parse_Scluster(void) SURFXML_START_TAG(set); SURFXML_END_TAG(set); - xbt_dynar_t names = xbt_dict_get(set_list,cluster_id); + names = xbt_dict_get(set_list,cluster_id); - unsigned int it1,it2; - char *name1,*name2; xbt_dynar_foreach(names,it1,name1) { /* create the host */ routing_full_parse_change_cpu_data(name1, cluster_power, "1.0", "", ""); @@ -310,6 +318,9 @@ static void routing_full_parse_end(void) { new_link->link_ptr = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); DEBUG3("Adding onelink route from (#%d) to (#%d), link_name %s",src_id, dst_id, link_name); xbt_dict_set(onelink_routes, link_name, (void *)new_link, onelink_route_elem_free); +#ifdef HAVE_TRACING + TRACE_surf_link_save_endpoints (link_name, src_id, dst_id); +#endif } if(ISROUTER(src_id) || ISROUTER(dst_id)) { @@ -485,8 +496,10 @@ static void routing_floyd_parse_end(void) { xbt_dynar_t links, keys; unsigned int i,j; - + unsigned int a,b,c; int host_count = routing->generic_routing.host_count; + char * link_name = NULL; + void * link = NULL; /* Create Cost, Predecessor and Link tables */ cost_table = xbt_new0(double, host_count * host_count); //link cost from host to host @@ -516,8 +529,9 @@ static void routing_floyd_parse_end(void) { src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links)); xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id); - char * link_name = xbt_dynar_getfirst_as(links, char*); - void * link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + link_name = xbt_dynar_getfirst_as(links, char*); + link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + if (link) link_list = link; else @@ -542,7 +556,7 @@ static void routing_floyd_parse_end(void) { //Calculate path costs - unsigned int a,b,c; + for(c=0;cid = id; data->graph_id = graph_id; - xbt_node_t node = xbt_graph_new_node(routing->route_graph, data); + node = xbt_graph_new_node(routing->route_graph, data); - graph_node_map_element_t elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element)); + elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element)); elm->node = node; xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free); @@ -778,7 +795,11 @@ static void routing_dijkstra_parse_end(void) { char *key, *data, *end; const char *sep = "#"; xbt_dynar_t links, keys; - + char* link_name = NULL; + void* link = NULL; + xbt_node_t node = NULL; + unsigned int cursor2; + xbt_dynar_t nodes = NULL; /* Create the topology graph */ routing->route_graph = xbt_graph_new_graph(1, NULL); routing->graph_node_map = xbt_dict_new(); @@ -802,8 +823,8 @@ static void routing_dijkstra_parse_end(void) { xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id); - char* link_name = xbt_dynar_getfirst_as(links, char*); - void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + link_name = xbt_dynar_getfirst_as(links, char*); + link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); if (link) route_new_dijkstra(src_id,dst_id,link); else @@ -815,10 +836,8 @@ static void routing_dijkstra_parse_end(void) { add_loopback_dijkstra(); /* initialize graph indexes in nodes after graph has been built */ - xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); + nodes = xbt_graph_get_nodes(routing->route_graph); - xbt_node_t node = NULL; - unsigned int cursor2; xbt_dynar_foreach(nodes, cursor2, node) { graph_node_data_t data = xbt_graph_node_get_data(node); data->graph_id = cursor2; @@ -833,17 +852,22 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { routing_dijkstra_t routing = (routing_dijkstra_t) used_routing; int * pred_arr = NULL; - + int src_node_id = 0; + int dst_node_id = 0; + int * nodeid = NULL; + int v; + int size = 0; + void * link = NULL; + route_cache_element_t elm = NULL; xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); /*Use the graph_node id mapping set to quickly find the nodes */ graph_node_map_element_t src_elm = graph_node_map_search(src_id); graph_node_map_element_t dst_elm = graph_node_map_search(dst_id); xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", src_id, dst_id); - int src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id; - int dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id; + src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id; + dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id; - route_cache_element_t elm = NULL; if(routing->cached) { /*check if there is a cached predecessor list avail */ elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int)); @@ -872,7 +896,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { pred_arr[i] = 0; //initialize priority queue - int * nodeid = xbt_new0(int, 1); + nodeid = xbt_new0(int, 1); *nodeid = i; xbt_heap_push(pqueue, nodeid, cost_arr[i]); @@ -895,7 +919,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { pred_arr[u_id] = *v_id; cost_arr[u_id] = cost_v_u + cost_arr[*v_id]; - int * nodeid = xbt_new0(int, 1); + nodeid = xbt_new0(int, 1); *nodeid = u_id; xbt_heap_push(pqueue, nodeid, cost_arr[u_id]); } @@ -913,8 +937,6 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { //compose route path with links xbt_dynar_reset(routing->last_route); - int v; - int size = 0; for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) { xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t); xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t); @@ -922,7 +944,7 @@ static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) { xbt_assert2(edge != NULL, "no route between host %d and %d", src_id, dst_id); - void * link = xbt_graph_edge_get_data(edge); + link = xbt_graph_edge_get_data(edge); xbt_dynar_unshift(routing->last_route, &link); size++; } @@ -1017,7 +1039,6 @@ static void routing_none_finalize(void) { static void routing_model_none_create(size_t size_of_link,void *loopback) { routing_t routing = xbt_new0(s_routing_t,1); - INFO0("Null routing"); routing->name = "none"; routing->host_count = 0; routing->host_id = xbt_dict_new(); @@ -1030,3 +1051,45 @@ static void routing_model_none_create(size_t size_of_link,void *loopback) { /* Set it in position */ used_routing = (routing_t) routing; } + +/*****************************************************************/ +/******************* BYBASS THE PARSER ***************************/ + +/* + * FIXME : better to add to the routing model instead !! + * + */ +void routing_add_route(char *source_id,char *destination_id,xbt_dynar_t links_id,int action) +{ + char * link_id; + char * name; + unsigned int i; + src_id = *(int*)xbt_dict_get(used_routing->host_id,source_id); + dst_id = *(int*)xbt_dict_get(used_routing->host_id,destination_id); + DEBUG4("Route %s %d -> %s %d",source_id,src_id,destination_id,dst_id); + //set Links + xbt_dynar_foreach(links_id,i,link_id) + { + surf_add_route_element(link_id); + } + route_action = action; + if (src_id != -1 && dst_id != -1) { + name = bprintf("%x#%x", src_id, dst_id); + manage_route(route_table, name, route_action, 0); + free(name); + } + +} + +void routing_add_host(char* host_id) +{ + int *val = xbt_malloc(sizeof(int)); + DEBUG2("Seen host %s (#%d)",host_id,used_routing->host_count); + *val = used_routing->host_count++; + xbt_dict_set(used_routing->host_id,host_id,val,xbt_free); +} + +void routing_set_routes() +{ + routing_full_parse_end(); +}