/* 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"
/* ************************************************************************** */
/* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
+static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc);
+static int generic_is_router (const char *name);
static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst);
/* ************************************************************************** */
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);//->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!!!");
+ xbt_die("global \"is_router\" function not implemented yet");
}
/**
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;
} 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(const char *name)
+{
+ xbt_die("\"full_is_router\" function not implemented yet");
+}
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(const char *name)
+{
+ xbt_die("\"floyd_is_router\" function not implemented yet");
+}
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(const char *name)
+{
+ xbt_die("\"dijkstra_is_router\" function not implemented yet");
+}
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;
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(const char *name)
+{
+ 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;
} 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(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 (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);
+ #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);
for (i = start; i <= end; i++)
{
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(" ");
+#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);
DEBUG0("</route>");
SURFXML_END_TAG(route);
+#else
+ for(i=0 ; i<=tab_elements_num->elmsize ; i++)
+ {
+ for(j=0 ; j<=tab_elements_num->elmsize ; j++)
+ {
+ route_src = bprintf("%s%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,i,int),cluster_suffix);
+ 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);
+
+ route_src = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
+ route_dst = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
+
+ DEBUG2("<link:ctn\tid=\"%s_link_%d\"/>",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int));
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int)));
+ 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);
+
+ DEBUG2("<link:ctn\tid=\"%s_link_%d\"/>",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int));
+ SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int)));
+ 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);