+/* ************************************************************************** */
+/* *********************** GENERIC BUSINESS METHODS ************************* */
+
+static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst) {
+ model_type_t modeltype = rc->routing;
+ xbt_dict_t dict_bypassRoutes;
+
+ if(modeltype==&routing_models[SURF_MODEL_FULL]) {
+ dict_bypassRoutes = ((routing_component_full_t)rc)->bypassRoutes;
+ } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) {
+ dict_bypassRoutes = ((routing_component_floyd_t)rc)->bypassRoutes;
+ } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
+ modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) {
+ dict_bypassRoutes = ((routing_component_dijkstra_t)rc)->bypassRoutes;
+ } else xbt_die("\"generic_set_bypassroute\" not support");
+
+
+ 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 */
+ src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
+ dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
+ xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst);
+
+ /* (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 ) {
+ routing_component_t *tmp_src,*tmp_dst;
+ tmp_src = xbt_dynar_pop_ptr(path_src);
+ tmp_dst = 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;
+
+ if( max <= max_index_src && max <= 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,max)))->name);
+ e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name);
+ xbt_free(route_name);
+ }
+ if( e_route_bypass ) break;
+ }
+
+ xbt_dynar_free(&path_src);
+ xbt_dynar_free(&path_dst);
+
+ route_extended_t new_e_route = NULL;
+
+ if(e_route_bypass) {
+ void* link;
+ unsigned int cpt=0;
+ new_e_route = xbt_new0(s_route_extended_t,1);
+ new_e_route->src_gateway = e_route_bypass->src_gateway;
+ new_e_route->dst_gateway = e_route_bypass->dst_gateway;
+ new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
+ xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
+ xbt_dynar_push(new_e_route->generic_route.link_list,&link);
+ }
+ }
+
+ return new_e_route;
+}
+
+/* ************************************************************************** */
+/* ************************* GENERIC AUX FUNCTIONS ************************** */
+
+static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order) {
+
+ char *link_name;
+ route_extended_t e_route, new_e_route;
+ route_t route;
+ unsigned int cpt;
+ xbt_dynar_t links, links_id;
+
+ new_e_route = xbt_new0(s_route_extended_t,1);
+ new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
+ new_e_route->src_gateway = NULL;
+ new_e_route->dst_gateway = NULL;
+
+ xbt_assert0(hierarchy == SURF_ROUTING_BASE || hierarchy == SURF_ROUTING_RECURSIVE,
+ "the hierarchy type is not defined");
+
+ if(hierarchy == SURF_ROUTING_BASE ) {
+
+ route = (route_t)data;
+ links = route->link_list;
+
+ } else if(hierarchy == SURF_ROUTING_RECURSIVE ) {