X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/91065b676e80a8c26a356477b018f2aae9b6eea7..cb2925f9e27482e531d327f9e1e19550c5966457:/src/surf/surf_routing.c diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index aacc229e39..098651b231 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -27,6 +27,8 @@ int SD_HOST_LEVEL; //Simdag level int COORD_HOST_LEVEL=0; //Coordinates level int NS3_HOST_LEVEL; //host node for ns3 +xbt_dict_t watched_hosts_lib; + /** * @ingroup SURF_build_api * @brief A library containing all known links @@ -109,6 +111,37 @@ struct s_model_type routing_models[] = { {NULL, NULL, NULL, NULL} }; +/** + * \brief Add a "host_link" to the network element list + */ +static void parse_S_host_link(sg_platf_host_link_cbarg_t host) +{ + sg_routing_edge_t info = NULL; + info = xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL); + xbt_assert(info, "Host '%s' not found!",host->id); + xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER] || + current_routing->model_desc == &routing_models[SURF_MODEL_VIVALDI], + "You have to be in model Cluster to use tag host_link!"); + + s_surf_parsing_link_up_down_t link_up_down; + link_up_down.link_up = xbt_lib_get_or_null(link_lib, host->link_up, SURF_LINK_LEVEL); + link_up_down.link_down = xbt_lib_get_or_null(link_lib, host->link_down, SURF_LINK_LEVEL); + + xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up); + xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down); + + if(!current_routing->link_up_down_list) + current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); + + // If dynar is is greater than edge id and if the host_link is already defined + if(xbt_dynar_length(current_routing->link_up_down_list) > info->id && + xbt_dynar_get_as(current_routing->link_up_down_list,info->id,void*)) + xbt_die("Host_link for '%s' is already defined!",host->id); + + XBT_DEBUG("Push Host_link for host '%s' to position %d",info->name,info->id); + xbt_dynar_set_as(current_routing->link_up_down_list,info->id,s_surf_parsing_link_up_down_t,link_up_down); +} + /** * \brief Add a "host" to the network element list */ @@ -373,28 +406,25 @@ static void routing_parse_E_bypassASroute(void) * @param AS_id name of this autonomous system. Must be unique in the platform * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c */ -void routing_AS_begin(const char *AS_id, const char *wanted_routing_type) +void routing_AS_begin(const char *AS_id, int wanted_routing_type) { AS_t new_as; routing_model_description_t model = NULL; - int cpt; xbt_assert(!xbt_lib_get_or_null (as_router_lib, AS_id, ROUTING_ASR_LEVEL), "The AS \"%s\" already exists", AS_id); /* search the routing model */ - for (cpt = 0; routing_models[cpt].name; cpt++) - if (!strcmp(wanted_routing_type, routing_models[cpt].name)) - model = &routing_models[cpt]; - /* if its not exist, error */ - if (model == NULL) { - fprintf(stderr, "Routing model %s not found. Existing models:\n", - wanted_routing_type); - for (cpt = 0; routing_models[cpt].name; cpt++) - fprintf(stderr, " %s: %s\n", routing_models[cpt].name, - routing_models[cpt].desc); - xbt_die("dying"); + switch(wanted_routing_type){ + case A_surfxml_AS_routing_Cluster: model = &routing_models[SURF_MODEL_CLUSTER];break; + case A_surfxml_AS_routing_Dijkstra: model = &routing_models[SURF_MODEL_DIJKSTRA];break; + case A_surfxml_AS_routing_DijkstraCache: model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break; + case A_surfxml_AS_routing_Floyd: model = &routing_models[SURF_MODEL_FLOYD];break; + case A_surfxml_AS_routing_Full: model = &routing_models[SURF_MODEL_FULL];break; + case A_surfxml_AS_routing_None: model = &routing_models[SURF_MODEL_NONE];break; + case A_surfxml_AS_routing_RuleBased: model = &routing_models[SURF_MODEL_RULEBASED];break; + case A_surfxml_AS_routing_Vivaldi: model = &routing_models[SURF_MODEL_VIVALDI];break; } /* make a new routing component */ @@ -585,6 +615,7 @@ static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst, if (src_father == dst_father) { /* SURF_ROUTING_BASE */ route.link_list = *links; common_father->get_route_and_latency(common_father, src, dst, &route,latency); + // if vivaldi latency+=vivaldi(src,dst) return; } @@ -608,12 +639,13 @@ static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst, /* If source gateway is not our source, we have to recursively find our way up to this point */ if (src != src_gateway_net_elm) _get_route_and_latency(src, src_gateway_net_elm, links, latency); - xbt_dynar_merge(links, &route.link_list); /* If dest gateway is not our destination, we have to recursively find our way from this point */ if (dst_gateway_net_elm != dst) _get_route_and_latency(dst_gateway_net_elm, dst, links, latency); + + // if vivaldi latency+=vivaldi(src_gateway,dst_gateway) } /** @@ -745,6 +777,83 @@ void routing_model_create( void *loopback) /* ************************************************************************** */ /* ************************* GENERIC PARSE FUNCTIONS ************************ */ +void routing_cluster_add_backbone(void* bb) { + xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER], + "You have to be in model Cluster to use tag backbone!"); + xbt_assert(!((as_cluster_t)current_routing)->backbone,"The backbone link is already defined!"); + ((as_cluster_t)current_routing)->backbone = bb; + XBT_DEBUG("Add a backbone to AS '%s'",current_routing->name); +} + +static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet) +{ + int start, end, i; + char *groups , *host_id , *link_id = NULL; + unsigned int iter; + xbt_dynar_t radical_elements; + xbt_dynar_t radical_ends; + + //Make all hosts + radical_elements = xbt_str_split(cabinet->radical, ","); + xbt_dynar_foreach(radical_elements, iter, groups) { + + radical_ends = xbt_str_split(groups, "-"); + start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); + + switch (xbt_dynar_length(radical_ends)) { + case 1: + end = start; + break; + case 2: + end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *)); + break; + default: + surf_parse_error("Malformed radical"); + break; + } + s_sg_platf_host_cbarg_t host; + memset(&host, 0, sizeof(host)); + host.initial_state = SURF_RESOURCE_ON; + host.power_peak = cabinet->power; + host.power_scale = 1.0; + host.core_amount = 1; + + s_sg_platf_link_cbarg_t link; + memset(&link, 0, sizeof(link)); + link.state = SURF_RESOURCE_ON; + link.policy = SURF_LINK_FULLDUPLEX; + link.latency = cabinet->lat; + link.bandwidth = cabinet->bw; + + s_sg_platf_host_link_cbarg_t host_link; + memset(&host_link, 0, sizeof(host_link)); + + for (i = start; i <= end; i++) { + host_id = bprintf("%s%d%s",cabinet->prefix,i,cabinet->suffix); + link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix); + host.id = host_id; + link.id = link_id; + sg_platf_new_host(&host); + sg_platf_new_link(&link); + + char* link_up = bprintf("%s_UP",link_id); + char* link_down = bprintf("%s_DOWN",link_id); + host_link.id = host_id; + host_link.link_up = link_up; + host_link.link_down= link_down; + sg_platf_new_host_link(&host_link); + + free(host_id); + free(link_id); + free(link_up); + free(link_down); + } + + xbt_dynar_free(&radical_ends); + } + xbt_dynar_free(&radical_elements); +} + static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) { char *host_id, *groups, *link_id = NULL; @@ -767,7 +876,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) } XBT_DEBUG("", cluster->id); - sg_platf_new_AS_begin(cluster->id, "Cluster"); + sg_platf_new_AS_begin(cluster->id, A_surfxml_AS_routing_Cluster); current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); @@ -892,7 +1001,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) sg_platf_new_link(&link); - surf_routing_cluster_add_backbone(current_routing, xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL)); + routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL)); free(link_backbone); } @@ -909,28 +1018,12 @@ static void routing_parse_postparse(void) { static void routing_parse_peer(sg_platf_peer_cbarg_t peer) { - static int AX_ptr = 0; char *host_id = NULL; - char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down; - - static unsigned int surfxml_buffer_stack_stack_ptr = 1; - static unsigned int surfxml_buffer_stack_stack[1024]; - - surfxml_buffer_stack_stack[0] = 0; - - surfxml_bufferstack_push(1); - - XBT_DEBUG("", peer->id); - sg_platf_new_AS_begin(peer->id, "Full"); + char *link_id; XBT_DEBUG(" "); host_id = HOST_PEER(peer->id); - router_id = ROUTER_PEER(peer->id); - link_id_up = LINK_UP_PEER(peer->id); - link_id_down = LINK_DOWN_PEER(peer->id); - - link_router = bprintf("%s_link_router", peer->id); - link_backbone = bprintf("%s_backbone", peer->id); + link_id = LINK_PEER(peer->id); XBT_DEBUG("", host_id, peer->power); s_sg_platf_host_cbarg_t host; @@ -945,80 +1038,41 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer) host.coord = peer->coord; sg_platf_new_host(&host); - - XBT_DEBUG("", router_id, peer->coord); - s_sg_platf_router_cbarg_t router; - memset(&router, 0, sizeof(router)); - router.id = router_id; - router.coord = peer->coord; - sg_platf_new_router(&router); - - XBT_DEBUG("", link_id_up, - peer->bw_in, peer->lat); s_sg_platf_link_cbarg_t link; memset(&link, 0, sizeof(link)); link.state = SURF_RESOURCE_ON; link.policy = SURF_LINK_SHARED; - link.id = link_id_up; - link.bandwidth = peer->bw_in; link.latency = peer->lat; - sg_platf_new_link(&link); - // FIXME: dealing with full duplex is not the role of this piece of code, I'd say [Mt] - // Instead, it should be created fullduplex, and the models will do what's needed in this case - XBT_DEBUG("", link_id_down, + char* link_up = bprintf("%s_UP",link_id); + XBT_DEBUG("", link_up, peer->bw_out, peer->lat); - link.id = link_id_down; + link.id = link_up; + link.bandwidth = peer->bw_out; sg_platf_new_link(&link); - XBT_DEBUG(" "); + char* link_down = bprintf("%s_DOWN",link_id); + XBT_DEBUG("", link_down, + peer->bw_in, peer->lat); + link.id = link_down; + link.bandwidth = peer->bw_in; + sg_platf_new_link(&link); - // begin here - XBT_DEBUG(""); - SURFXML_BUFFER_SET(route_src, host_id); - SURFXML_BUFFER_SET(route_dst, router_id); - A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO; - SURFXML_START_TAG(route); - - XBT_DEBUG("", link_id_up); - SURFXML_BUFFER_SET(link_ctn_id, link_id_up); - A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE; - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); - - XBT_DEBUG(""); - SURFXML_END_TAG(route); - - //Opposite Route - XBT_DEBUG(""); - SURFXML_BUFFER_SET(route_src, router_id); - SURFXML_BUFFER_SET(route_dst, host_id); - A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO; - SURFXML_START_TAG(route); - - XBT_DEBUG("", link_id_down); - SURFXML_BUFFER_SET(link_ctn_id, link_id_down); - A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE; - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); - - XBT_DEBUG(""); - SURFXML_END_TAG(route); + XBT_DEBUG("", host_id,link_up,link_down); + s_sg_platf_host_link_cbarg_t host_link; + memset(&host_link, 0, sizeof(host_link)); + host_link.id = host_id; + host_link.link_up = link_up; + host_link.link_down= link_down; + sg_platf_new_host_link(&host_link); - XBT_DEBUG(""); - sg_platf_new_AS_end(); XBT_DEBUG(" "); //xbt_dynar_free(&tab_elements_num); free(host_id); - free(router_id); - free(link_router); - free(link_backbone); - free(link_id_up); - free(link_id_down); - surfxml_bufferstack_pop(1); + free(link_id); + free(link_up); + free(link_down); } static void routing_parse_Srandom(void) @@ -1145,6 +1199,7 @@ void routing_register_callbacks() { sg_platf_host_add_cb(parse_S_host); sg_platf_router_add_cb(parse_S_router); + sg_platf_host_link_add_cb(parse_S_host_link); surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom); @@ -1165,6 +1220,7 @@ void routing_register_callbacks() &routing_parse_E_bypassASroute); sg_platf_cluster_add_cb(routing_parse_cluster); + sg_platf_cabinet_add_cb(routing_parse_cabinet); sg_platf_peer_add_cb(routing_parse_peer); sg_platf_postparse_add_cb(routing_parse_postparse);