-/* Copyright (c) 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2009, 2010. The SimGrid Team.
* All rights reserved. */
/* 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 <float.h>
-#include <pcre.h> /* regular expresion library */
+#include "gras_config.h"
+
+#ifdef HAVE_PCRE_LIB
+ #include <pcre.h> /* regular expresion library */
+#endif
#include "surf_private.h"
#include "xbt/dynar.h"
#include "xbt/str.h"
static void routing_full_parse_Scluster(void);/*cluster bypass*/
-/* this lines are olny for replace use like index in the model table */
-#define SURF_MODEL_FULL 0
-#define SURF_MODEL_FLOYD 1
-#define SURF_MODEL_DIJKSTRA 2
-#define SURF_MODEL_DIJKSTRACACHE 3
-#define SURF_MODEL_RULEBASED 4
-#define SURF_MODEL_NONE 5
+/* this lines are only for replace use like index in the model table */
+typedef enum {
+ SURF_MODEL_FULL=0,
+ SURF_MODEL_FLOYD,
+ SURF_MODEL_DIJKSTRA,
+ SURF_MODEL_DIJKSTRACACHE,
+ SURF_MODEL_NONE,
+#ifdef HAVE_PCRE_LIB
+ SURF_MODEL_RULEBASED
+#endif
+} e_routing_types;
+
/* must be finish with null and carefull if change de order */
struct s_model_type routing_models[] =
model_dijkstra_create ,model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
{"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
model_dijkstracache_create, model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
- {"RuleBased", "Rule-Based routing data (...)",
- model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end },
{"none", "No routing (usable with Constant network only)",
model_none_create, model_none_load, model_none_unload, model_none_end },
+#ifdef HAVE_PCRE_LIB
+ {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end },
+#endif
{NULL,NULL,NULL,NULL,NULL,NULL}};
/* ************************************************************************** */
/* ************************************************************************** */
/* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
+static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc);
+static int generic_is_router (routing_component_t rc, const char *name);
static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst);
/* ************************************************************************** */
/**
* \brief Set a new link on the actual list of link for a route or ASroute
*/
-static void parse_E_link_c_ctn_new_elem(char *link_id) {
+static void parse_E_link_ctn_new_elem(char *link_id) {
char *val;
val = xbt_strdup(link_id);
xbt_dynar_push(link_list, &val);
* \brief Set a new link on the actual list of link for a route or ASroute from XML
*/
-static void parse_E_link_c_ctn_new_elem_XML(void)
+static void parse_E_link_ctn_new_elem_XML(void)
{
- parse_E_link_c_ctn_new_elem(A_surfxml_link_c_ctn_id);
+ parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
}
/**
*/
static void parse_E_link_c_ctn_new_elem_lua(char *link_id) {
- parse_E_link_c_ctn_new_elem(link_id);
+ parse_E_link_ctn_new_elem(link_id);
}
/**
xbt_free(global_routing);
}
-static void get_onelink_routes(void)
+static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc)
{
- xbt_die("get_onelink_routes function not implemented yet!!!");
+ xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
+
+ //adding my one link routes
+ unsigned int cpt;
+ void *link;
+ xbt_dynar_t onelink_mine = rc->get_onelink_routes (rc);
+ if (onelink_mine){
+ xbt_dynar_foreach(onelink_mine, cpt, link) {
+ xbt_dynar_push(ret,&link);
+ }
+ }
+
+ //recursing
+ char *key;
+ xbt_dict_cursor_t cursor=NULL;
+ routing_component_t rc_child;
+ xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
+ xbt_dynar_t onelink_child = recursive_get_onelink_routes (rc_child);
+ if (onelink_child){
+ xbt_dynar_foreach(onelink_child, cpt, link) {
+ xbt_dynar_push(ret,&link);
+ }
+ }
+ }
+ return ret;
+}
+
+static xbt_dynar_t get_onelink_routes(void)
+{
+ return recursive_get_onelink_routes (global_routing->root);
}
static int is_router(const char *name)
{
- xbt_die("is_router function not implemented yet!!!");
+ routing_component_t rc=NULL;
+ rc = xbt_dict_get(global_routing->where_network_elements,name);
+ return rc->is_router(rc, name);
}
/**
global_routing->where_network_elements = xbt_dict_new();
global_routing->root = NULL;
global_routing->get_route = get_route;
+ global_routing->get_onelink_routes = get_onelink_routes;
+ global_routing->is_router = is_router;
global_routing->finalize = finalize;
global_routing->loopback = loopback;
global_routing->size_of_link = size_of_links;
surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints);
surfxml_add_callback(STag_surfxml_bypassRoute_cb_list, &parse_S_bypassRoute_new_and_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_E_link_c_ctn_new_elem_XML);
+ surfxml_add_callback(ETag_surfxml_link_ctn_cb_list, &parse_E_link_ctn_new_elem_XML);
surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route);
surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route);
} s_routing_component_full_t,*routing_component_full_t;
/* Business methods */
+static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
+{
+ 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);
+ 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_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst);
+ route_extended_t route = TO_ROUTE_FULL(*src_id,*dst_id);
+ if (route){
+ if (xbt_dynar_length(route->generic_route.link_list) == 1){
+ void *link = *(void**)xbt_dynar_get_ptr(route->generic_route.link_list,0);
+
+ onelink_t onelink = xbt_new0 (s_onelink_t, 1);
+ onelink->src = xbt_strdup (k1);
+ onelink->dst = xbt_strdup (k2);
+ onelink->link_ptr = link;
+ xbt_dynar_push (ret, &onelink);
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+static int full_is_router(routing_component_t rc, const char *name)
+{
+ routing_component_full_t routing = (routing_component_full_t)rc;
+
+ if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
+ return 1;
+ else
+ return 0;
+}
static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
new_component->generic_routing.set_ASroute = generic_set_ASroute;
new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
new_component->generic_routing.get_route = full_get_route;
+ new_component->generic_routing.get_onelink_routes = full_get_onelink_routes;
+ new_component->generic_routing.is_router = full_is_router;
new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
new_component->generic_routing.finalize = full_finalize;
new_component->to_index = xbt_dict_new();
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, const char* src,const char* dst);
+
/* Business methods */
+static xbt_dynar_t floyd_get_onelink_routes(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);
+ 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) {
+ route_extended_t route = floyd_get_route (rc, k1, k2);
+ if (route){
+ if (xbt_dynar_length(route->generic_route.link_list) == 1){
+ void *link = *(void**)xbt_dynar_get_ptr(route->generic_route.link_list,0);
+ onelink_t onelink = xbt_new0 (s_onelink_t, 1);
+ onelink->src = xbt_strdup (k1);
+ onelink->dst = xbt_strdup (k2);
+ onelink->link_ptr = link;
+ xbt_dynar_push (ret, &onelink);
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+static int floyd_is_router(routing_component_t rc, const char *name)
+{
+ routing_component_floyd_t routing = (routing_component_floyd_t)rc;
+
+ if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
+ return 1;
+ else
+ return 0;
+}
static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
new_component->generic_routing.set_ASroute = generic_set_ASroute;
new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
new_component->generic_routing.get_route = floyd_get_route;
+ new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes;
+ new_component->generic_routing.is_router = floyd_is_router;
new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
new_component->generic_routing.finalize = floyd_finalize;
new_component->to_index = xbt_dict_new();
}
/* Business methods */
+static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
+{
+ xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
+}
+
+static int dijkstra_is_router(routing_component_t rc, const char *name)
+{
+ routing_component_dijkstra_t routing = (routing_component_dijkstra_t)rc;
+
+ if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
+ return 1;
+ else
+ return 0;
+}
static route_extended_t dijkstra_get_route(routing_component_t rc, const char* src,const char* dst) {
xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
new_component->generic_routing.set_ASroute = generic_set_ASroute;
new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
new_component->generic_routing.get_route = dijkstra_get_route;
+ new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes;
+ new_component->generic_routing.is_router = dijkstra_is_router;
new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
new_component->generic_routing.finalize = dijkstra_finalize;
new_component->cached = cached;
}
+#ifdef HAVE_PCRE_LIB
/* ************************************************** */
/* ************** RULE-BASED ROUTING **************** */
return xbt_strdup(result_result);
}
+static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
+{
+ xbt_die("\"rulebased_get_onelink_routes\" function not implemented yet");
+}
+
+static int rulebased_is_router(routing_component_t rc, const char *name)
+{
+ //routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
+
+//PIERRE FIXME
+
+ xbt_die("\"rulebased_is_router\" function not implemented yet");
+}
+
/* Business methods */
static route_extended_t rulebased_get_route(routing_component_t rc, const char* src,const char* dst) {
xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
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;
+ new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
+ new_component->generic_routing.is_router = rulebased_is_router;
new_component->generic_routing.get_route = rulebased_get_route;
new_component->generic_routing.get_bypass_route = NULL; //rulebased_get_bypass_route;
new_component->generic_routing.finalize = rulebased_finalize;
static void model_rulebased_end(void) {
}
+#endif /* HAVE_PCRE_LIB */
+
/* ************************************************************************** */
/* ******************************* NO ROUTING ******************************* */
} s_routing_component_none_t,*routing_component_none_t;
/* Business methods */
+static xbt_dynar_t none_get_onelink_routes(routing_component_t rc){
+ return NULL;
+}
+static int none_is_router(routing_component_t rc, const char *name){
+ return -1;
+}
static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
return NULL;
}
new_component->generic_routing.set_ASroute = NULL;
new_component->generic_routing.set_bypassroute = NULL;
new_component->generic_routing.get_route = none_get_route;
+ new_component->generic_routing.get_onelink_routes = none_get_onelink_routes;
+ new_component->generic_routing.is_router = none_is_router;
new_component->generic_routing.get_bypass_route = none_get_bypass_route;
new_component->generic_routing.finalize = none_finalize;
return new_component;
/* ************************************************************************** */
/* *********************** GENERIC BUSINESS METHODS ************************* */
+static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc)
+{
+ xbt_die("\"generic_get_onelink_routes\" not implemented yet");
+}
+
+static int generic_is_router (routing_component_t rc, const char *name)
+{
+ xbt_die("\"generic_is_router\" not implemented yet");
+}
+
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;
} 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 supported");
+ } else xbt_die("\"generic_get_bypassroute\" not supported");
routing_component_t src_as, dst_as;
int start, end, i;
xbt_dynar_t radical_elements;
xbt_dynar_t radical_ends;
+ #ifndef HAVE_PCRE_LIB
+ xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+ char *route_src,*route_dst;
+ int j;
+ #endif
static unsigned int surfxml_buffer_stack_stack_ptr = 1;
static unsigned int surfxml_buffer_stack_stack[1024];
surfxml_bufferstack_push(1);
- DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
SURFXML_BUFFER_SET(AS_id, cluster_id);
+#ifdef HAVE_PCRE_LIB
SURFXML_BUFFER_SET(AS_routing, "RuleBased");
+ DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
+#else
+ SURFXML_BUFFER_SET(AS_routing, "Full");
+ DEBUG1("<AS id=\"%s\"\trouting=\"Full\">",cluster_id);
+#endif
SURFXML_START_TAG(AS);
radical_elements = xbt_str_split(cluster_radical, ",");
{
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
link_id = bprintf("%s_link_%d", cluster_id, start);
DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
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
link_id = bprintf("%s_link_%d", cluster_id, i);
DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
}
DEBUG0(" ");
- router_id = bprintf("%srouter%s",cluster_prefix,cluster_suffix);
- link_router = bprintf("%s_link_router",cluster_id);
+ router_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);
- DEBUG1("<router id=\"%s\"\">",router_id);
+ DEBUG1("<router id=\"%s\"/>",router_id);
SURFXML_BUFFER_SET(router_id, router_id);;
SURFXML_START_TAG(router);
SURFXML_END_TAG(router);
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(" ");
+#ifdef HAVE_PCRE_LIB
+
DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
SURFXML_BUFFER_SET(route_src, route_src_dst);
SURFXML_BUFFER_SET(route_dst, route_src_dst);
SURFXML_START_TAG(route);
DEBUG1("<link:ctn\tid=\"%s_link_$1src\"/>",cluster_id);
- SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1src",cluster_id));
- SURFXML_START_TAG(link_c_ctn);
- SURFXML_END_TAG(link_c_ctn);
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src",cluster_id));
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
- SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_backbone",cluster_id));
- SURFXML_START_TAG(link_c_ctn);
- SURFXML_END_TAG(link_c_ctn);
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone",cluster_id));
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
DEBUG1("<link:ctn\tid=\"%s_link_$1dst\"/>",cluster_id);
- SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1dst",cluster_id));
- SURFXML_START_TAG(link_c_ctn);
- SURFXML_END_TAG(link_c_ctn);
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst",cluster_id));
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
DEBUG0("</route>");
SURFXML_END_TAG(route);
+#else
+ for(i=0 ; i<=xbt_dynar_length(tab_elements_num) ; i++)
+ {
+ for(j=0 ; j<=xbt_dynar_length(tab_elements_num) ; j++)
+ {
+ if(i == xbt_dynar_length(tab_elements_num))
+ {
+ route_src = router_id;
+ }
+ else
+ {
+ route_src = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,i,int),cluster_suffix);
+ }
+
+ if(j == xbt_dynar_length(tab_elements_num))
+ {
+ route_dst = router_id;
+ }
+ else
+ {
+ route_dst = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,j,int),cluster_suffix);
+ }
+
+ DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src,route_dst);
+ SURFXML_BUFFER_SET(route_src, route_src);
+ SURFXML_BUFFER_SET(route_dst, route_dst);
+ SURFXML_START_TAG(route);
+
+ if(i == xbt_dynar_length(tab_elements_num))
+ {
+ route_src = link_router;
+ }
+ else
+ {
+ route_src = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
+ }
+
+ if(j == xbt_dynar_length(tab_elements_num))
+ {
+ route_dst = link_router;
+ }
+ else
+ {
+ route_dst = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
+ }
+
+ DEBUG1("<link:ctn\tid=\"%s\"/>",route_src);
+ SURFXML_BUFFER_SET(link_ctn_id, route_src);
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
+
+ DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone",cluster_id));
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
+
+ DEBUG1("<link:ctn\tid=\"%s\"/>",route_dst);
+ SURFXML_BUFFER_SET(link_ctn_id, route_dst);
+ SURFXML_START_TAG(link_ctn);
+ SURFXML_END_TAG(link_ctn);
+
+ DEBUG0("</route>");
+ SURFXML_END_TAG(route);
+ }
+ }
+ xbt_dynar_free(&tab_elements_num);
+#endif
DEBUG0("</AS>");
SURFXML_END_TAG(AS);