X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6b27851a012ce270cabc69c5e162ef2991e66065..8fb370cb7b0fe8f6edcec683a27ffe6e58cb3056:/src/surf/surf_routing.c?ds=sidebyside diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 1049787e34..3992b09897 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -60,14 +60,8 @@ routing_platf_t routing_platf = NULL; AS_t current_routing = NULL; /* global parse functions */ -xbt_dynar_t parsed_link_list = NULL; /* temporary store of current list link of a route */ extern xbt_dynar_t mount_list; -static const char *src = NULL; /* temporary store the source name of a route */ -static const char *dst = NULL; /* temporary store the destination name of a route */ -static char *gw_src = NULL; /* temporary store the gateway source name of a route */ -static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */ - XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); static void routing_parse_peer(sg_platf_peer_cbarg_t peer); /* peer bypass */ @@ -226,171 +220,131 @@ static void parse_S_router(sg_platf_router_cbarg_t router) } } - -/** - * \brief Set the end points for a route - */ -static void routing_parse_S_route(void) -{ - src = A_surfxml_route_src; - dst = A_surfxml_route_dst; - xbt_assert(strlen(src) > 0 || strlen(dst) > 0, - "Missing end-points while defining route \"%s\"->\"%s\"", - src, dst); - parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); -} - -/** - * \brief Set the end points and gateways for a ASroute - */ -static void routing_parse_S_ASroute(void) -{ - src = A_surfxml_ASroute_src; - dst = A_surfxml_ASroute_dst; - gw_src = A_surfxml_ASroute_gw_src; - gw_dst = A_surfxml_ASroute_gw_dst; - xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0, - "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)", - src, dst,gw_src,gw_dst); - parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); -} - -/** - * \brief Set the end points for a bypassRoute - */ -static void routing_parse_S_bypassRoute(void) -{ - src = A_surfxml_bypassRoute_src; - dst = A_surfxml_bypassRoute_dst; - gw_src = NULL; - gw_dst = NULL; - xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0, - "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)", - src, dst,gw_src,gw_dst); - parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); -} - -/** - * \brief Set the end points for a bypassASroute - */ -static void routing_parse_S_bypassASroute(void) -{ - src = A_surfxml_bypassASroute_src; - dst = A_surfxml_bypassASroute_dst; - gw_src = A_surfxml_bypassASroute_gw_src; - gw_dst = A_surfxml_bypassASroute_gw_dst; - xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0, - "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)", - src, dst,gw_src,gw_dst); - parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); -} -/** - * \brief Set a new link on the actual list of link for a route or ASroute from XML - */ - -static void routing_parse_link_ctn(void) -{ - char *link_id; - switch (A_surfxml_link_ctn_direction) { - case AU_surfxml_link_ctn_direction: - case A_surfxml_link_ctn_direction_NONE: - link_id = xbt_strdup(A_surfxml_link_ctn_id); - break; - case A_surfxml_link_ctn_direction_UP: - link_id = bprintf("%s_UP", A_surfxml_link_ctn_id); - break; - case A_surfxml_link_ctn_direction_DOWN: - link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id); - break; - } - xbt_dynar_push(parsed_link_list, &link_id); -} - /** * \brief Store the route by calling the set_route function of the current routing component */ -static void routing_parse_E_route(void) +static void parse_E_route(sg_platf_route_cbarg_t route) { - route_t route = xbt_new0(s_route_t, 1); - route->link_list = parsed_link_list; + route_t created_route = xbt_new0(s_route_t, 1); + created_route->link_list = route->link_list; + xbt_assert(current_routing->parse_route, "no defined method \"set_route\" in \"%s\"", current_routing->name); - current_routing->parse_route(current_routing, src, dst, route); - generic_free_route(route); - parsed_link_list = NULL; - src = NULL; - dst = NULL; + + current_routing->parse_route(current_routing, + route->src, route->dst, created_route); + generic_free_route(created_route); } /** * \brief Store the ASroute by calling the set_ASroute function of the current routing component */ -static void routing_parse_E_ASroute(void) +static void parse_E_ASroute(sg_platf_ASroute_cbarg_t ASroute) { route_t e_route = xbt_new0(s_route_t, 1); - e_route->link_list = parsed_link_list; + e_route->link_list = ASroute->link_list; if (!strcmp(current_routing->model_desc->name,"RuleBased")) { // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows) // // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity - e_route->src_gateway = (sg_routing_edge_t) gw_src; - e_route->dst_gateway = (sg_routing_edge_t) gw_dst; + e_route->src_gateway = (sg_routing_edge_t) ASroute->gw_src; + e_route->dst_gateway = (sg_routing_edge_t) ASroute->gw_dst; } else { - e_route->src_gateway = sg_routing_edge_by_name_or_null(gw_src); - e_route->dst_gateway = sg_routing_edge_by_name_or_null(gw_dst); + e_route->src_gateway = sg_routing_edge_by_name_or_null(ASroute->gw_src); + e_route->dst_gateway = sg_routing_edge_by_name_or_null(ASroute->gw_dst); } xbt_assert(current_routing->parse_ASroute, "no defined method \"set_ASroute\" in \"%s\"", current_routing->name); - current_routing->parse_ASroute(current_routing, src, dst, e_route); + current_routing->parse_ASroute(current_routing, ASroute->src, ASroute->dst, e_route); generic_free_route(e_route); - parsed_link_list = NULL; - src = NULL; - dst = NULL; - gw_src = NULL; - gw_dst = NULL; } /** * \brief Store the bypass route by calling the set_bypassroute function of the current routing component */ -static void routing_parse_E_bypassRoute(void) +static void parse_E_bypassRoute(sg_platf_bypassRoute_cbarg_t route) { route_t e_route = xbt_new0(s_route_t, 1); - e_route->link_list = parsed_link_list; + e_route->link_list = route->link_list; xbt_assert(current_routing->parse_bypassroute, "Bypassing mechanism not implemented by routing '%s'", current_routing->name); - current_routing->parse_bypassroute(current_routing, src, dst, e_route); - parsed_link_list = NULL; - src = NULL; - dst = NULL; - gw_src = NULL; - gw_dst = NULL; + current_routing->parse_bypassroute(current_routing, route->src, route->dst, e_route); } + /** * \brief Store the bypass route by calling the set_bypassroute function of the current routing component */ -static void routing_parse_E_bypassASroute(void) +static void parse_E_bypassASroute(sg_platf_bypassASroute_cbarg_t ASroute) { route_t e_route = xbt_new0(s_route_t, 1); - e_route->link_list = parsed_link_list; - e_route->src_gateway = sg_routing_edge_by_name_or_null(gw_src); - e_route->dst_gateway = sg_routing_edge_by_name_or_null(gw_dst); + e_route->link_list = ASroute->link_list; + e_route->src_gateway = sg_routing_edge_by_name_or_null(ASroute->gw_src); + e_route->dst_gateway = sg_routing_edge_by_name_or_null(ASroute->gw_dst); xbt_assert(current_routing->parse_bypassroute, "Bypassing mechanism not implemented by routing '%s'", current_routing->name); - current_routing->parse_bypassroute(current_routing, src, dst, e_route); - parsed_link_list = NULL; - src = NULL; - dst = NULL; - gw_src = NULL; - gw_dst = NULL; + current_routing->parse_bypassroute(current_routing, ASroute->src, ASroute->dst, e_route); +} + +static void routing_parse_trace(sg_platf_trace_cbarg_t trace) +{ + tmgr_trace_t tmgr_trace; + if (!trace->file || strcmp(trace->file, "") != 0) { + tmgr_trace = tmgr_trace_new_from_file(trace->file); + } else if (strcmp(trace->pc_data, "") == 0) { + tmgr_trace = NULL; + } else { + tmgr_trace = + tmgr_trace_new_from_string(trace->id, trace->pc_data, + trace->periodicity); + } + xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL); +} + +static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) +{ + xbt_assert(xbt_dict_get_or_null + (traces_set_list, trace_connect->trace), + "Cannot connect trace %s to %s: trace unknown", + trace_connect->trace, + trace_connect->element); + + switch (trace_connect->kind) { + case SURF_TRACE_CONNECT_KIND_HOST_AVAIL: + xbt_dict_set(trace_connect_list_host_avail, + trace_connect->trace, + xbt_strdup(trace_connect->element), NULL); + break; + case SURF_TRACE_CONNECT_KIND_POWER: + xbt_dict_set(trace_connect_list_power, trace_connect->trace, + xbt_strdup(trace_connect->element), NULL); + break; + case SURF_TRACE_CONNECT_KIND_LINK_AVAIL: + xbt_dict_set(trace_connect_list_link_avail, + trace_connect->trace, + xbt_strdup(trace_connect->element), NULL); + break; + case SURF_TRACE_CONNECT_KIND_BANDWIDTH: + xbt_dict_set(trace_connect_list_bandwidth, + trace_connect->trace, + xbt_strdup(trace_connect->element), NULL); + break; + case SURF_TRACE_CONNECT_KIND_LATENCY: + xbt_dict_set(trace_connect_list_latency, trace_connect->trace, + xbt_strdup(trace_connect->element), NULL); + break; + default: + xbt_die("Cannot connect trace %s to %s: kind of trace unknown", + trace_connect->trace, trace_connect->element); + break; + } } /** @@ -867,8 +821,8 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) xbt_dynar_t radical_elements; xbt_dynar_t radical_ends; - if (strcmp(cluster->availability_trace, "") - || strcmp(cluster->state_trace, "")) { + if ((cluster->availability_trace && strcmp(cluster->availability_trace, "")) + || (cluster->state_trace && strcmp(cluster->state_trace, ""))) { patterns = xbt_dict_new_homogeneous(xbt_free_f); xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL); xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL); @@ -908,7 +862,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) memset(&host, 0, sizeof(host)); host.id = host_id; - if (strcmp(cluster->availability_trace, "")) { + if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) { xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL); char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns); XBT_DEBUG("\tavailability_file=\"%s\"", avail_file); @@ -918,7 +872,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) XBT_DEBUG("\tavailability_file=\"\""); } - if (strcmp(cluster->state_trace, "")) { + if (cluster->state_trace && strcmp(cluster->state_trace, "")) { char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns); XBT_DEBUG("\tstate_file=\"%s\"", avail_file); host.state_trace = tmgr_trace_new_from_file(avail_file); @@ -1200,24 +1154,10 @@ 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); - - surfxml_add_callback(STag_surfxml_route_cb_list, &routing_parse_S_route); - surfxml_add_callback(STag_surfxml_ASroute_cb_list, &routing_parse_S_ASroute); - surfxml_add_callback(STag_surfxml_bypassRoute_cb_list, - &routing_parse_S_bypassRoute); - surfxml_add_callback(STag_surfxml_bypassASroute_cb_list, - &routing_parse_S_bypassASroute); - - surfxml_add_callback(ETag_surfxml_link_ctn_cb_list, &routing_parse_link_ctn); - - surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_parse_E_route); - surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &routing_parse_E_ASroute); - surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list, - &routing_parse_E_bypassRoute); - surfxml_add_callback(ETag_surfxml_bypassASroute_cb_list, - &routing_parse_E_bypassASroute); + sg_platf_route_add_cb(parse_E_route); + sg_platf_ASroute_add_cb(parse_E_ASroute); + sg_platf_bypassRoute_add_cb(parse_E_bypassRoute); + sg_platf_bypassASroute_add_cb(parse_E_bypassASroute); sg_platf_cluster_add_cb(routing_parse_cluster); sg_platf_cabinet_add_cb(routing_parse_cabinet); @@ -1229,6 +1169,9 @@ void routing_register_callbacks() sg_platf_AS_end_add_cb(routing_AS_end); sg_platf_AS_begin_add_cb(routing_AS_begin); + sg_platf_trace_add_cb(routing_parse_trace); + sg_platf_trace_connect_add_cb(routing_parse_trace_connect); + #ifdef HAVE_TRACING instr_routing_define_callbacks(); #endif