X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6aee8176bcb1a32402d11424b1f2c027ceec1b6e..12e1d787707bb574c3930f6262a5e751c9a11043:/src/surf/network_dassf.c diff --git a/src/surf/network_dassf.c b/src/surf/network_dassf.c index c0a6c07812..ec0b99b94c 100644 --- a/src/surf/network_dassf.c +++ b/src/surf/network_dassf.c @@ -10,7 +10,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); /* surf_network_resource_t surf_network_resource = NULL; */ -static xbt_dict_t network_link_set = NULL; +/*xbt_dict_t network_link_set = NULL;*/ /* xbt_dict_t network_card_set = NULL; */ static int card_number = 0; @@ -86,18 +86,10 @@ static int network_card_new(const char *card_name) return card->id; } -static void route_new(int src_id, int dst_id, char **links, int nb_link) +static void route_new(int src_id, int dst_id, network_link_DASSF_t *link_list, int nb_link) { - network_link_DASSF_t *link_list = NULL; - int i; - ROUTE_SIZE(src_id, dst_id) = nb_link; - link_list = (ROUTE(src_id, dst_id) = xbt_new0(network_link_DASSF_t, nb_link)); - for (i = 0; i < nb_link; i++) { - link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]); - free(links[i]); - } - free(links); + ROUTE(src_id, dst_id) = link_list = xbt_realloc(link_list, sizeof(network_link_DASSF_t) * nb_link); } static void parse_network_link(void) @@ -129,8 +121,9 @@ static void parse_network_link(void) lat_initial, lat_trace, state_initial, state_trace); } -static int nb_link = 0; -static char **link_name = NULL; +static int nb_link; +static int link_list_capacity; +static network_link_DASSF_t *link_list = NULL; static int src_id = -1; static int dst_id = -1; @@ -139,19 +132,22 @@ static void parse_route_set_endpoints(void) src_id = network_card_new(A_surfxml_route_src); dst_id = network_card_new(A_surfxml_route_dst); nb_link = 0; - link_name = NULL; + link_list_capacity = 20; + link_list = xbt_new(network_link_DASSF_t, link_list_capacity); } static void parse_route_elem(void) { - nb_link++; - link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *)); - link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name); + if (nb_link == link_list_capacity) { + link_list_capacity *= 2; + link_list = xbt_realloc(link_list, link_list_capacity * sizeof(network_link_DASSF_t)); + } + link_list[nb_link++] = xbt_dict_get_or_null(network_link_set, A_surfxml_route_element_name); } static void parse_route_set_route(void) { - route_new(src_id, dst_id, link_name, nb_link); + route_new(src_id, dst_id, link_list, nb_link); } static void parse_file(const char *file) @@ -233,6 +229,10 @@ static void action_change_state(surf_action_t action, return; } +/* I nothing more happens, return the date at which the first action that will terminate does terminate */ +/* This returns the time for the first NETWORK action to complete */ +/* It would be nice to store this minimum somewhere so that the next function can + figure out whether the min comes from the network or from something else */ static double share_resources(double now) { s_surf_action_network_DASSF_t s_action; @@ -251,6 +251,13 @@ static double share_resources(double now) return min; } +/* delta: by how many time units the simulation must advance */ +/* In this function: change the state of actions that terminate */ +/* The delta may not come from the network, and thus may be different (smaller) + than the one returned by the function above */ +/* If the delta is a network-caused min, then do not emulate any timer in the + network simulation, otherwise fake a timer somehow to advance the simulation of min seconds */ + static void update_actions_state(double now, double delta) { double deltap = 0.0; @@ -267,19 +274,19 @@ static void update_actions_state(double now, double delta) deltap = delta; if (action->latency > 0) { if (action->latency > deltap) { - surf_double_update(&(action->latency),deltap); + double_update(&(action->latency),deltap); deltap = 0.0; } else { - surf_double_update(&(deltap), action->latency); + double_update(&(deltap), action->latency); action->latency = 0.0; } if ((action->latency == 0.0) && !(action->suspended)) lmm_update_variable_weight(maxmin_system, action->variable, 1.0); } - surf_double_update(&(action->generic_action.remains), + double_update(&(action->generic_action.remains), lmm_variable_getvalue(action->variable) * deltap); if (action->generic_action.max_duration != NO_MAX_DURATION) - surf_double_update(&(action->generic_action.max_duration), delta); + double_update(&(action->generic_action.max_duration), delta); /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */ @@ -291,6 +298,7 @@ static void update_actions_state(double now, double delta) action->generic_action.finish = surf_get_clock(); action_change_state((surf_action_t) action, SURF_ACTION_DONE); } else { /* Need to check that none of the resource has failed */ + /* to ignore for now */ lmm_constraint_t cnst = NULL; int i = 0; network_link_DASSF_t nw_link = NULL; @@ -311,6 +319,7 @@ static void update_actions_state(double now, double delta) return; } +/* Called only when there is a change in trace: Useless in packet-level simulation */ static void update_resource_state(void *id, tmgr_trace_event_t event_type, double value) @@ -410,6 +419,31 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate) return (surf_action_t) action; } +/* returns a NULL-terminated array of network_link_DASSF_t */ +static const void** get_route(void *src, void *dst) { + network_card_DASSF_t card_src = src; + network_card_DASSF_t card_dst = dst; + return (const void**) ROUTE(card_src->id, card_dst->id); +} + +static int get_route_size(void *src, void *dst) { + network_card_DASSF_t card_src = src; + network_card_DASSF_t card_dst = dst; + return ROUTE_SIZE(card_src->id, card_dst->id); +} + +static const char *get_link_name(const void *link) { + return ((network_link_DASSF_t) link)->name; +} + +static double get_link_bandwidth(const void *link) { + return ((network_link_DASSF_t) link)->bw_current; +} + +static double get_link_latency(const void *link) { + return ((network_link_DASSF_t) link)->lat_current; +} + static void action_suspend(surf_action_t action) { ((surf_action_network_DASSF_t) action)->suspended = 1; @@ -487,6 +521,10 @@ static void surf_network_resource_init_internal(void) get_resource_name; surf_network_resource->common_public->action_get_state = surf_action_get_state; + surf_network_resource->common_public->action_get_start_time = + surf_action_get_start_time; + surf_network_resource->common_public->action_get_finish_time = + surf_action_get_finish_time; surf_network_resource->common_public->action_free = action_free; surf_network_resource->common_public->action_cancel = action_cancel; surf_network_resource->common_public->action_recycle = action_recycle; @@ -508,6 +546,11 @@ static void surf_network_resource_init_internal(void) surf_network_resource->common_public->is_suspended = action_is_suspended; surf_network_resource->extension_public->communicate = communicate; + surf_network_resource->extension_public->get_route = get_route; + surf_network_resource->extension_public->get_route_size = get_route_size; + surf_network_resource->extension_public->get_link_name = get_link_name; + surf_network_resource->extension_public->get_link_bandwidth = get_link_bandwidth; + surf_network_resource->extension_public->get_link_latency = get_link_latency; network_link_set = xbt_dict_new(); network_card_set = xbt_dict_new();