-void generic_set_processing_unit(routing_component_t rc,
- const char *name)
-{
- XBT_DEBUG("Load process unit \"%s\"", name);
- int *id = xbt_new0(int, 1);
- xbt_dict_t _to_index;
- _to_index = current_routing->to_index;
- *id = xbt_dict_length(_to_index);
- xbt_dict_set(_to_index, name, id, xbt_free);
-}
-
-void generic_set_autonomous_system(routing_component_t rc,
- const char *name)
-{
- XBT_DEBUG("Load Autonomous system \"%s\"", name);
- int *id = xbt_new0(int, 1);
- xbt_dict_t _to_index;
- _to_index = current_routing->to_index;
- *id = xbt_dict_length(_to_index);
- xbt_dict_set(_to_index, name, id, xbt_free);
-}
-
-int surf_pointer_resource_cmp(const void *a, const void *b)
-{
- return a != b;
-}
-
-int surf_link_resource_cmp(const void *a, const void *b)
-{
- return !!memcmp(a,b,global_routing->size_of_link);
-}
-
-void generic_set_bypassroute(routing_component_t rc,
- const char *src, const char *dst,
- route_extended_t e_route)
-{
- XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
- xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
- char *route_name;
-
- route_name = bprintf("%s#%s", src, dst);
- xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
- "Invalid count of links, must be greater than zero (%s,%s)",
- src, dst);
- xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
- "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
- src, e_route->src_gateway, dst, e_route->dst_gateway);
-
- route_extended_t new_e_route =
- generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
- xbt_dynar_free(&(e_route->generic_route.link_list));
- xbt_free(e_route);
-
- xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
- (void (*)(void *)) generic_free_extended_route);
- xbt_free(route_name);
-}
-
-/* ************************************************************************** */
-/* *********************** GENERIC BUSINESS METHODS ************************* */
-
-double generic_get_link_latency(routing_component_t rc,
- const char *src, const char *dst,
- route_extended_t route)
-{
- int need_to_clean = route?0:1;
- void * link;
- unsigned int i;
- double latency = 0.0;
-
- route = route?route:rc->get_route(rc,src,dst);
-
- xbt_dynar_foreach(route->generic_route.link_list,i,link) {
- latency += get_link_latency(link);
- }
- if(need_to_clean) generic_free_extended_route(route);
- return latency;
-}
-
-xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
-{
- xbt_die("\"generic_get_onelink_routes\" not implemented yet");
-}
-
-route_extended_t generic_get_bypassroute(routing_component_t rc,
- const char *src,
- const char *dst)
-{
- xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
- routing_component_t src_as, dst_as;
- int index_src, index_dst;
- xbt_dynar_t path_src = NULL;
- xbt_dynar_t path_dst = NULL;
- routing_component_t current = NULL;
- routing_component_t *current_src = NULL;
- routing_component_t *current_dst = NULL;
-
- /* (1) find the as where the src and dst are located */
- 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_as = ((network_element_info_t)src_data)->rc_component;
- dst_as = ((network_element_info_t)dst_data)->rc_component;
-
- /* (2) find the path to the root routing component */
- path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
- current = src_as;
- while (current != NULL) {
- xbt_dynar_push(path_src, ¤t);
- current = current->routing_father;
- }
- path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
- current = dst_as;
- while (current != NULL) {
- xbt_dynar_push(path_dst, ¤t);
- current = current->routing_father;
- }
-
- /* (3) find the common father */
- index_src = path_src->used - 1;
- index_dst = path_dst->used - 1;
- current_src = xbt_dynar_get_ptr(path_src, index_src);
- current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
- while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
- xbt_dynar_pop_ptr(path_src);
- xbt_dynar_pop_ptr(path_dst);
- index_src--;
- index_dst--;
- current_src = xbt_dynar_get_ptr(path_src, index_src);
- current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
- }
-
- int max_index_src = path_src->used - 1;
- int max_index_dst = path_dst->used - 1;
-
- int max_index = max(max_index_src, max_index_dst);
- int i, max;
-
- route_extended_t e_route_bypass = NULL;
-
- for (max = 0; max <= max_index; max++) {
- for (i = 0; i < max; i++) {
- if (i <= max_index_src && max <= max_index_dst) {
- char *route_name = bprintf("%s#%s",
- (*(routing_component_t *)
- (xbt_dynar_get_ptr
- (path_src, i)))->name,
- (*(routing_component_t *)
- (xbt_dynar_get_ptr
- (path_dst, max)))->name);
- e_route_bypass =
- xbt_dict_get_or_null(dict_bypassRoutes, route_name);
- xbt_free(route_name);
- }
- if (e_route_bypass)
- break;
- if (max <= max_index_src && i <= max_index_dst) {
- char *route_name = bprintf("%s#%s",
- (*(routing_component_t *)
- (xbt_dynar_get_ptr
- (path_src, max)))->name,
- (*(routing_component_t *)
- (xbt_dynar_get_ptr
- (path_dst, i)))->name);
- e_route_bypass =
- xbt_dict_get_or_null(dict_bypassRoutes, route_name);
- xbt_free(route_name);
- }
- if (e_route_bypass)
- break;
- }
-
- if (e_route_bypass)
- break;