X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7eb5c714b49414aed4cefb03119c25af814af55c..7c9b8ae2a235057d3eac28aa41a2ff89ba7b331d:/src/surf/surf_routing_rulebased.c diff --git a/src/surf/surf_routing_rulebased.c b/src/surf/surf_routing_rulebased.c index 9055898300..357c33dc5b 100644 --- a/src/surf/surf_routing_rulebased.c +++ b/src/surf/surf_routing_rulebased.c @@ -4,14 +4,10 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include "surf_routing_private.h" - -#ifdef HAVE_PCRE_LIB #include /* regular expression library */ /* Global vars */ extern routing_global_t global_routing; -extern routing_component_t current_routing; -extern model_type_t current_routing_model; extern xbt_dynar_t link_list; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_rulebased, surf, "Routing part of surf"); @@ -19,7 +15,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_rulebased, surf, "Routing part of sur /* Routing model structure */ typedef struct { - s_routing_component_t generic_routing; + s_as_t generic_routing; xbt_dict_t dict_processing_units; xbt_dict_t dict_autonomous_systems; xbt_dynar_t list_route; @@ -69,7 +65,7 @@ static void rule_route_extended_free(void *e) /* Parse routing model functions */ -static void model_rulebased_set_processing_unit(routing_component_t rc, +static void model_rulebased_parse_PU(AS_t rc, const char *name) { routing_component_rulebased_t routing = @@ -77,7 +73,7 @@ static void model_rulebased_set_processing_unit(routing_component_t rc, xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL); } -static void model_rulebased_set_autonomous_system(routing_component_t rc, +static void model_rulebased_parse_AS(AS_t rc, const char *name) { routing_component_rulebased_t routing = @@ -86,9 +82,9 @@ static void model_rulebased_set_autonomous_system(routing_component_t rc, NULL); } -static void model_rulebased_set_route(routing_component_t rc, +static void model_rulebased_parse_route(AS_t rc, const char *src, const char *dst, - name_route_extended_t route) + route_extended_t route) { routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; @@ -96,7 +92,7 @@ static void model_rulebased_set_route(routing_component_t rc, const char *error; int erroffset; - if(!strcmp(rc->routing->name,"Vivaldi")){ + if(!strcmp(rc->model_desc->name,"Vivaldi")){ if(xbt_dynar_length(route->generic_route.link_list) != 0) xbt_die("You can't have link_ctn with Model Vivaldi."); } @@ -114,9 +110,9 @@ static void model_rulebased_set_route(routing_component_t rc, xbt_free(route); } -static void model_rulebased_set_ASroute(routing_component_t rc, +static void model_rulebased_parse_ASroute(AS_t rc, const char *src, const char *dst, - name_route_extended_t route) + route_extended_t route) { routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; @@ -124,7 +120,7 @@ static void model_rulebased_set_ASroute(routing_component_t rc, const char *error; int erroffset; - if(!strcmp(rc->routing->name,"Vivaldi")){ + if(!strcmp(rc->model_desc->name,"Vivaldi")){ if(xbt_dynar_length(route->generic_route.link_list) != 0) xbt_die("You can't have link_ctn with Model Vivaldi."); } @@ -149,7 +145,7 @@ static void model_rulebased_set_ASroute(routing_component_t rc, xbt_free(route); } -static void model_rulebased_set_bypassroute(routing_component_t rc, +static void model_rulebased_parse_bypassroute(AS_t rc, const char *src, const char *dst, route_extended_t e_route) @@ -163,38 +159,25 @@ static void model_rulebased_set_bypassroute(routing_component_t rc, static char *remplace(char *value, const char **src_list, int src_size, const char **dst_list, int dst_size) { - - char result_result[BUFFER_SIZE]; - int i_result_buffer; - int value_length = (int) strlen(value); - int number = 0; - + char result[BUFFER_SIZE]; + int i_res = 0; int i = 0; - i_result_buffer = 0; - do { + + while (value[i]) { if (value[i] == '$') { - i++; // skip $ + i++; /* skip the '$' */ + if (value[i] < '0' || value[i] > '9') + xbt_die("bad string parameter, no number indication, at offset: " + "%d (\"%s\")", i, value); - // find the number - int number_length = 0; - while ('0' <= value[i + number_length] - && value[i + number_length] <= '9') { - number_length++; - } - xbt_assert(number_length != 0, - "bad string parameter, no number indication, at offset: %d (\"%s\")", - i, value); - - // solve number - number = atoi(value + i); - i = i + number_length; - xbt_assert(i + 2 < value_length, - "bad string parameter, too few chars, at offset: %d (\"%s\")", - i, value); - - // solve the indication + /* solve the number */ + int number = value[i++] - '0'; + while (value[i] >= '0' && value[i] <= '9') + number = 10 * number + (value[i++] - '0'); + + /* solve the indication */ const char **param_list; - int param_size; + _XBT_GNUC_UNUSED int param_size; if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') { param_list = src_list; param_size = src_size; @@ -206,42 +189,39 @@ static char *remplace(char *value, const char **src_list, int src_size, xbt_die("bad string parameter, support only \"src\" and \"dst\", " "at offset: %d (\"%s\")", i, value); } - i = i + 3; + i += 3; - xbt_assert(param_size >= number, - "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d", - i, value, param_size, number); + xbt_assert(number < param_size, + "bad string parameter, not enough length param_size, " + "at offset: %d (\"%s\") %d %d", i, value, param_size, number); const char *param = param_list[number]; - int size = strlen(param); - int cp; - for (cp = 0; cp < size; cp++) { - result_result[i_result_buffer] = param[cp]; - i_result_buffer++; - if (i_result_buffer >= BUFFER_SIZE) - break; - } + int j = 0; + while (param[j] && i_res < BUFFER_SIZE) + result[i_res++] = param[j++]; } else { - result_result[i_result_buffer] = value[i]; - i_result_buffer++; - i++; // next char + result[i_res++] = value[i++]; /* next char */ } - - } while (i < value_length && i_result_buffer < BUFFER_SIZE); - - xbt_assert(i_result_buffer < BUFFER_SIZE, - "solving string \"%s\", small buffer size (%d)", value, - BUFFER_SIZE); - result_result[i_result_buffer] = 0; - return xbt_strdup(result_result); + if (i_res >= BUFFER_SIZE) + xbt_die("solving string \"%s\", small buffer size (%d)", + value, BUFFER_SIZE); + } + result[i_res++] = '\0'; + char *res = xbt_malloc(i_res); + return memcpy(res, result, i_res); } -static route_extended_t rulebased_get_route(routing_component_t rc, +static route_extended_t rulebased_get_route(AS_t rc, const char *src, const char *dst); -static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc) +static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc) { xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free); + + //We have already bypass cluster routes with network NS3 + if(!strcmp(surf_network_model->name,"network NS3")) + return ret; + routing_component_rulebased_t routing = (routing_component_rulebased_t)rc; xbt_dict_cursor_t c1 = NULL; @@ -250,7 +230,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc) //find router char *router = NULL; xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) { - if (rc->get_network_element_type(k1) == SURF_NETWORK_ELEMENT_ROUTER){ + if (routing_get_network_element_type(k1) == SURF_NETWORK_ELEMENT_ROUTER){ router = k1; } } @@ -285,7 +265,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc) } /* Business methods */ -static route_extended_t rulebased_get_route(routing_component_t rc, +static route_extended_t rulebased_get_route(AS_t rc, const char *src, const char *dst) { @@ -327,7 +307,7 @@ static route_extended_t rulebased_get_route(routing_component_t rc, int ovector_dst[OVECCOUNT]; const char **list_src = NULL; const char **list_dst = NULL; - int res; + _XBT_GNUC_UNUSED int res; xbt_dynar_foreach(rule_list, cpt, ruleroute) { rc_src = pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0, @@ -390,14 +370,14 @@ static route_extended_t rulebased_get_route(routing_component_t rc, return new_e_route; } -static route_extended_t rulebased_get_bypass_route(routing_component_t rc, +static route_extended_t rulebased_get_bypass_route(AS_t rc, const char *src, const char *dst) { return NULL; } -static void rulebased_finalize(routing_component_t rc) +static void rulebased_finalize(AS_t rc) { routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; @@ -412,23 +392,20 @@ static void rulebased_finalize(routing_component_t rc) } /* Creation routing model functions */ -void *model_rulebased_create(void) -{ - routing_component_rulebased_t new_component = - xbt_new0(s_routing_component_rulebased_t, 1); - new_component->generic_routing.set_processing_unit = - model_rulebased_set_processing_unit; - new_component->generic_routing.set_autonomous_system = - model_rulebased_set_autonomous_system; - new_component->generic_routing.set_route = model_rulebased_set_route; - new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute; - new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute; +AS_t model_rulebased_create(void) { + + routing_component_rulebased_t new_component = (routing_component_rulebased_t) + model_generic_create_sized(sizeof(s_routing_component_rulebased_t)); + + new_component->generic_routing.parse_PU = model_rulebased_parse_PU; + new_component->generic_routing.parse_AS = model_rulebased_parse_AS; + new_component->generic_routing.parse_route = model_rulebased_parse_route; + new_component->generic_routing.parse_ASroute = model_rulebased_parse_ASroute; + new_component->generic_routing.parse_bypassroute = model_rulebased_parse_bypassroute; new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes; new_component->generic_routing.get_route = rulebased_get_route; - new_component->generic_routing.get_latency = generic_get_link_latency; new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route; new_component->generic_routing.finalize = rulebased_finalize; - new_component->generic_routing.get_network_element_type = get_network_element_type; /* initialization of internal structures */ new_component->dict_processing_units = xbt_dict_new(); new_component->dict_autonomous_systems = xbt_dict_new(); @@ -436,21 +413,6 @@ void *model_rulebased_create(void) new_component->list_ASroute = xbt_dynar_new(sizeof(rule_route_extended_t), &rule_route_extended_free); - return new_component; -} - -void model_rulebased_load(void) -{ - /* use "surfxml_add_callback" to add a parse function call */ -} - -void model_rulebased_unload(void) -{ - /* use "surfxml_del_callback" to remove a parse function call */ -} -void model_rulebased_end(void) -{ + return (AS_t) new_component; } - -#endif /* HAVE_PCRE_LIB */