typedef struct {
s_routing_component_t generic_routing;
xbt_dict_t parse_routes; /* store data during the parse process */
- xbt_dict_t to_index; /* char* -> network_element_t */
xbt_dict_t bypassRoutes;
route_extended_t *routing_table;
} s_routing_component_full_t, *routing_component_full_t;
xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
routing_component_full_t routing = (routing_component_full_t) rc;
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
xbt_dict_cursor_t c1 = NULL, c2 = NULL;
char *k1, *d1, *k2, *d2;
- xbt_dict_foreach(routing->to_index, c1, k1, d1) {
- xbt_dict_foreach(routing->to_index, c2, k2, d2) {
- int *src_id = xbt_dict_get_or_null(routing->to_index, k1);
- int *dst_id = xbt_dict_get_or_null(routing->to_index, k2);
+ xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
+ xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
+ int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
+ int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
xbt_assert2(src_id
&& dst_id,
"Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
/* set utils vars */
routing_component_full_t routing = (routing_component_full_t) rc;
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
generic_src_dst_check(rc, src, dst);
- int *src_id = xbt_dict_get_or_null(routing->to_index, src);
- int *dst_id = xbt_dict_get_or_null(routing->to_index, dst);
+ int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
+ int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
xbt_assert2(src_id
&& dst_id,
"Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
static void full_finalize(routing_component_t rc)
{
routing_component_full_t routing = (routing_component_full_t) rc;
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
int i, j;
if (routing) {
/* Delete routing table */
/* Delete bypass dict */
xbt_dict_free(&routing->bypassRoutes);
/* Delete index dict */
- xbt_dict_free(&(routing->to_index));
+ xbt_dict_free(&(routing->generic_routing.to_index));
/* Delete structure */
xbt_free(rc);
}
new_component->generic_routing.get_bypass_route =
generic_get_bypassroute;
new_component->generic_routing.finalize = full_finalize;
- new_component->to_index = xbt_dict_new();
+ new_component->generic_routing.to_index = xbt_dict_new();
new_component->bypassRoutes = xbt_dict_new();
- new_component->parse_routes = xbt_dict_new();
+ new_component->generic_routing.parse_routes = xbt_dict_new();
return new_component;
}
/* set utils vars */
routing_component_full_t routing =
((routing_component_full_t) current_routing);
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
/* Create the routing table */
routing->routing_table =
xbt_new0(route_extended_t, table_size * table_size);
/* Put the routes in position */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
keys = xbt_str_split_str(key, sep);
src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
}
/* delete the parse table */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
route = (route_t) data;
xbt_dynar_free(&(route->link_list));
xbt_free(data);
}
/* delete parse dict */
- xbt_dict_free(&(routing->parse_routes));
+ xbt_dict_free(&(routing->generic_routing.parse_routes));
/* Add the loopback if needed */
if (current_routing->hierarchy == SURF_ROUTING_BASE) {
/* vars for calculate the floyd algorith. */
int *predecessor_table;
route_extended_t *link_table; /* char* -> int* */
- xbt_dict_t to_index;
xbt_dict_t bypassRoutes;
- /* store data during the parse process */
- xbt_dict_t parse_routes;
} s_routing_component_floyd_t, *routing_component_floyd_t;
static route_extended_t floyd_get_route(routing_component_t rc,
xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
routing_component_floyd_t routing = (routing_component_floyd_t) rc;
- //int table_size = xbt_dict_length(routing->to_index);
+ //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
xbt_dict_cursor_t c1 = NULL, c2 = NULL;
char *k1, *d1, *k2, *d2;
- xbt_dict_foreach(routing->to_index, c1, k1, d1) {
- xbt_dict_foreach(routing->to_index, c2, k2, d2) {
+ xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
+ xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
route_extended_t route = floyd_get_route(rc, k1, k2);
if (route) {
if (xbt_dynar_length(route->generic_route.link_list) == 1) {
/* set utils vars */
routing_component_floyd_t routing = (routing_component_floyd_t) rc;
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
generic_src_dst_check(rc, src, dst);
- int *src_id = xbt_dict_get_or_null(routing->to_index, src);
- int *dst_id = xbt_dict_get_or_null(routing->to_index, dst);
+ int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
+ int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
xbt_assert2(src_id
&& dst_id,
"Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
static void floyd_finalize(routing_component_t rc)
{
routing_component_floyd_t routing = (routing_component_floyd_t) rc;
- int i, j, table_size;
+ int i, j;
+ size_t table_size;
if (routing) {
- table_size = xbt_dict_length(routing->to_index);
+ table_size = xbt_dict_length(routing->generic_routing.to_index);
/* Delete link_table */
for (i = 0; i < table_size; i++)
for (j = 0; j < table_size; j++)
/* Delete bypass dict */
xbt_dict_free(&routing->bypassRoutes);
/* Delete index dict */
- xbt_dict_free(&(routing->to_index));
+ xbt_dict_free(&(routing->generic_routing.to_index));
/* Delete dictionary index dict, predecessor and links table */
xbt_free(routing->predecessor_table);
/* Delete structure */
new_component->generic_routing.get_bypass_route =
generic_get_bypassroute;
new_component->generic_routing.finalize = floyd_finalize;
- new_component->to_index = xbt_dict_new();
+ new_component->generic_routing.to_index = xbt_dict_new();
new_component->bypassRoutes = xbt_dict_new();
- new_component->parse_routes = xbt_dict_new();
+ new_component->generic_routing.parse_routes = xbt_dict_new();
return new_component;
}
unsigned int i, j, a, b, c;
/* set the size of inicial table */
- int table_size = xbt_dict_length(routing->to_index);
+ size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
/* Create Cost, Predecessor and Link tables */
cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */
}
/* Put the routes in position */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
keys = xbt_str_split_str(key, sep);
src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
}
/* delete the parse table */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
route_t route = (route_t) data;
xbt_dynar_free(&(route->link_list));
xbt_free(data);
}
/* delete parse dict */
- xbt_dict_free(&(routing->parse_routes));
+ xbt_dict_free(&(routing->generic_routing.parse_routes));
/* cleanup */
xbt_free(cost_table);
typedef struct {
s_routing_component_t generic_routing;
- xbt_dict_t to_index;
xbt_dict_t bypassRoutes;
xbt_graph_t route_graph; /* xbt_graph */
xbt_dict_t graph_node_map; /* map */
xbt_dict_t route_cache; /* use in cache mode */
int cached;
- xbt_dict_t parse_routes;
} s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
generic_src_dst_check(rc, src, dst);
- int *src_id = xbt_dict_get_or_null(routing->to_index, src);
- int *dst_id = xbt_dict_get_or_null(routing->to_index, dst);
+ int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
+ int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
xbt_assert2(src_id
&& dst_id,
"Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",
/* Delete bypass dict */
xbt_dict_free(&routing->bypassRoutes);
/* Delete index dict */
- xbt_dict_free(&(routing->to_index));
+ xbt_dict_free(&(routing->generic_routing.to_index));
/* Delete structure */
xbt_free(routing);
}
generic_get_bypassroute;
new_component->generic_routing.finalize = dijkstra_finalize;
new_component->cached = cached;
- new_component->to_index = xbt_dict_new();
+ new_component->generic_routing.to_index = xbt_dict_new();
new_component->bypassRoutes = xbt_dict_new();
- new_component->parse_routes = xbt_dict_new();
+ new_component->generic_routing.parse_routes = xbt_dict_new();
return new_component;
}
routing->route_cache = xbt_dict_new();
/* Put the routes in position */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
keys = xbt_str_split_str(key, sep);
src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
}
/* delete the parse table */
- xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
+ xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
route = (route_t) data;
xbt_dynar_free(&(route->link_list));
xbt_free(data);
}
/* delete parse dict */
- xbt_dict_free(&(routing->parse_routes));
+ xbt_dict_free(&(routing->generic_routing.parse_routes));
/* Add the loopback if needed */
if (current_routing->hierarchy == SURF_ROUTING_BASE)
return xbt_strdup(result_result);
}
+static route_extended_t rulebased_get_route(routing_component_t rc,
+ const char *src,
+ const char *dst);
static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
{
- xbt_die("\"rulebased_get_onelink_routes\" function not implemented yet");
+ xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
+ routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
+
+ xbt_dict_cursor_t c1 = NULL;
+ char *k1, *d1;
+
+ //find router
+ char *router = NULL;
+ xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
+ if (strstr (k1, "router")){
+ router = k1;
+ }
+ }
+ if (!router){
+ xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
+ }
+
+ xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
+ route_extended_t route = rulebased_get_route (rc, router, k1);
+
+ int number_of_links = xbt_dynar_length(route->generic_route.link_list);
+ if (number_of_links != 3) {
+ xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
+ }
+
+ void *link_ptr;
+ xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
+ onelink_t onelink = xbt_new0 (s_onelink_t, 1);
+ onelink->src = xbt_strdup (k1);
+ onelink->dst = xbt_strdup (router);
+ onelink->link_ptr = link_ptr;
+ xbt_dynar_push (ret, &onelink);
+ }
+ return ret;
}
/* Business methods */
const char *name)
{
DEBUG1("Load process unit \"%s\"", name);
- model_type_t modeltype = rc->routing;
int *id = xbt_new0(int, 1);
xbt_dict_t _to_index;
- if (modeltype == &routing_models[SURF_MODEL_FULL])
- _to_index = ((routing_component_full_t) rc)->to_index;
-
- else if (modeltype == &routing_models[SURF_MODEL_FLOYD])
- _to_index = ((routing_component_floyd_t) rc)->to_index;
-
- else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] ||
- modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE])
- _to_index = ((routing_component_dijkstra_t) rc)->to_index;
-
- else
- xbt_die("\"generic_set_processing_unit\" not supported");
+ _to_index = current_routing->to_index;
*id = xbt_dict_length(_to_index);
xbt_dict_set(_to_index, name, id, xbt_free);
}
const char *name)
{
DEBUG1("Load Autonomous system \"%s\"", name);
- model_type_t modeltype = rc->routing;
int *id = xbt_new0(int, 1);
xbt_dict_t _to_index;
- if (modeltype == &routing_models[SURF_MODEL_FULL])
- _to_index = ((routing_component_full_t) rc)->to_index;
-
- else if (modeltype == &routing_models[SURF_MODEL_FLOYD])
- _to_index = ((routing_component_floyd_t) rc)->to_index;
-
- else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] ||
- modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE])
- _to_index = ((routing_component_dijkstra_t) rc)->to_index;
-
- else
- xbt_die("\"generic_set_autonomous_system\" not supported");
+ _to_index = current_routing->to_index;
*id = xbt_dict_length(_to_index);
xbt_dict_set(_to_index, name, id, xbt_free);
}
const char *dst, route_t route)
{
DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
- model_type_t modeltype = rc->routing;
xbt_dict_t _parse_routes;
xbt_dict_t _to_index;
char *route_name;
int *src_id, *dst_id;
-
- if (modeltype == &routing_models[SURF_MODEL_FULL]) {
- _parse_routes = ((routing_component_full_t) rc)->parse_routes;
- _to_index = ((routing_component_full_t) rc)->to_index;
-
- } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) {
- _parse_routes = ((routing_component_floyd_t) rc)->parse_routes;
- _to_index = ((routing_component_floyd_t) rc)->to_index;
-
- } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] ||
- modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) {
- _parse_routes = ((routing_component_dijkstra_t) rc)->parse_routes;
- _to_index = ((routing_component_dijkstra_t) rc)->to_index;
-
- } else
- xbt_die("\"generic_set_route\" not supported");
+ _to_index = current_routing->to_index;
+ //TODO
+ _parse_routes = current_routing->parse_routes;
src_id = xbt_dict_get_or_null(_to_index, src);
dst_id = xbt_dict_get_or_null(_to_index, dst);
{
DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
e_route->src_gateway, dst, e_route->dst_gateway);
- model_type_t modeltype = rc->routing;
+
xbt_dict_t _parse_routes;
xbt_dict_t _to_index;
char *route_name;
int *src_id, *dst_id;
-
- if (modeltype == &routing_models[SURF_MODEL_FULL]) {
- _parse_routes = ((routing_component_full_t) rc)->parse_routes;
- _to_index = ((routing_component_full_t) rc)->to_index;
-
- } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) {
- _parse_routes = ((routing_component_floyd_t) rc)->parse_routes;
- _to_index = ((routing_component_floyd_t) rc)->to_index;
-
- } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] ||
- modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) {
- _parse_routes = ((routing_component_dijkstra_t) rc)->parse_routes;
- _to_index = ((routing_component_dijkstra_t) rc)->to_index;
-
- } else
- xbt_die("\"generic_set_route\" not supported");
+ _to_index = current_routing->to_index;
+ //TODO
+ _parse_routes = current_routing->parse_routes;
src_id = xbt_dict_get_or_null(_to_index, src);
dst_id = xbt_dict_get_or_null(_to_index, dst);
route_extended_t e_route, new_e_route;
route_t route;
unsigned int cpt;
- xbt_dynar_t links, links_id;
+ xbt_dynar_t links = NULL, links_id = NULL;
new_e_route = xbt_new0(s_route_extended_t, 1);
new_e_route->generic_route.link_list =
case 1:
surf_parse_get_int(&start,
xbt_dynar_get_as(radical_ends, 0, char *));
- host_id = bprintf("%s_%d%s", cluster_prefix, start, cluster_suffix);
+ host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
#ifndef HAVE_PCRE_LIB
xbt_dynar_push_as(tab_elements_num, int, start);
#endif
surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
DEBUG2("Create hosts and links from %d to %d", start, end);
for (i = start; i <= end; i++) {
- host_id = bprintf("%s_%d%s", cluster_prefix, i, cluster_suffix);
+ host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
#ifndef HAVE_PCRE_LIB
xbt_dynar_push_as(tab_elements_num, int, i);
#endif
DEBUG0(" ");
router_id =
- bprintf("%s_%s_router%s", cluster_prefix, cluster_id,
+ bprintf("%s%s_router%s", cluster_prefix, cluster_id,
cluster_suffix);
link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
link_backbone = bprintf("%s_backbone", cluster_id);
new_suffix = bprintf("%s\\.%s", new_suffix, groups);
}
}
- route_src_dst = bprintf("%s_(.*)%s", cluster_prefix, new_suffix);
+ route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
DEBUG0(" ");
route_src = router_id;
} else {
route_src =
- bprintf("%s_%d%s", cluster_prefix,
+ bprintf("%s%d%s", cluster_prefix,
xbt_dynar_get_as(tab_elements_num, i, int),
cluster_suffix);
}
route_dst = router_id;
} else {
route_dst =
- bprintf("%s_%d%s", cluster_prefix,
+ bprintf("%s%d%s", cluster_prefix,
xbt_dynar_get_as(tab_elements_num, j, int),
cluster_suffix);
}