Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implementing recursive call to get_onelink_routes
[simgrid.git] / src / surf / surf_routing.c
index f11c89b..a0b74ee 100644 (file)
@@ -1,11 +1,17 @@
-/* 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"
@@ -86,6 +92,8 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* ************************************************************************** */
 /* *************** 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);
 
 /* ************************************************************************** */
@@ -111,16 +119,35 @@ static xbt_dynar_t link_list = NULL; /* temporary store of current list link of
 /**
  * \brief Add a "host" to the network element list
  */
-static void  parse_S_host(void) {
+static void  parse_S_host(char* host_id) {
   if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
-  xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_host_id),
-      "Reading a host, processing unit \"%s\" already exist",A_surfxml_host_id);
+  xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,host_id),
+      "Reading a host, processing unit \"%s\" already exist",host_id);
   xbt_assert1(current_routing->set_processing_unit,
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
-  (*(current_routing->set_processing_unit))(current_routing,A_surfxml_host_id);
-  xbt_dict_set(global_routing->where_network_elements,A_surfxml_host_id,(void*)current_routing,NULL); 
+  (*(current_routing->set_processing_unit))(current_routing,host_id);
+  xbt_dict_set(global_routing->where_network_elements,host_id,(void*)current_routing,NULL);
+}
+
+/*
+ * \brief Add a host to the network element list from XML
+ */
+static void parse_S_host_XML(void)
+{
+       parse_S_host(A_surfxml_host_id);
 }
 
+/*
+ * \brief Add a host to the network element list from lua script
+ */
+static void parse_S_host_lua(char *host_id)
+{
+       parse_S_host(host_id);
+}
+/*
+ *
+ */
+
 /**
  * \brief Add a "router" to the network element list
  */
@@ -132,21 +159,40 @@ static void parse_S_router(void) {
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
   (*(current_routing->set_processing_unit))(current_routing,A_surfxml_router_id);
   xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)current_routing,NULL); 
+  #ifdef HAVE_TRACING
+    TRACE_surf_host_declaration (A_surfxml_router_id, 0);
+  #endif
 }
 
 /**
  * \brief Set the endponints for a route
  */
-static void parse_S_route_new_and_endpoints(void) {
+static void parse_S_route_new_and_endpoints(char *src_id,char *dst_id) {
   if( src != NULL && dst != NULL && link_list != NULL )
-    THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_route_src,A_surfxml_route_dst);
-  src = A_surfxml_route_src;
-  dst = A_surfxml_route_dst;
+    THROW2(arg_error,0,"Route between %s to %s can not be defined",src_id,dst_id);
+  src = src_id;
+  dst = dst_id;
   xbt_assert2(strlen(src)>0||strlen(dst)>0,
       "Some limits are null in the route between \"%s\" and \"%s\"",src,dst);
   link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
 }
 
+/**
+ * \breif Set the endpoints for a route from XML
+ */
+static void parse_S_route_new_and_endpoints_XML(void)
+{
+       parse_S_route_new_and_endpoints(A_surfxml_route_src,A_surfxml_route_dst);
+}
+
+/**
+ * \breif Set the endpoints for a route from lua
+ */
+static void parse_S_route_new_and_endpoints_lua(char *id_src,char *id_dst)
+{
+       parse_S_route_new_and_endpoints(id_src,id_dst);
+}
+
 /**
  * \brief Set the endponints and gateways for a ASroute
  */
@@ -180,12 +226,29 @@ static void parse_S_bypassRoute_new_and_endpoints(void) {
 /**
  * \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(void) {
+static void parse_E_link_ctn_new_elem(char *link_id) {
   char *val;
-  val = xbt_strdup(A_surfxml_link_c_ctn_id);
+  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_ctn_new_elem_XML(void)
+{
+       parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
+}
+
+/**
+ * \brief Set a new link on the actual list of link for a route or ASroute from lua
+ */
+static void parse_E_link_c_ctn_new_elem_lua(char *link_id) {
+
+       parse_E_link_ctn_new_elem(link_id);
+}
+
 /**
  * \brief Store the route by calling the set_route function of the current routing component
  */
@@ -246,13 +309,13 @@ static void parse_E_bypassRoute_store_route(void) {
 /**
  * \brief Make a new routing component
  *
- * Detect the routing model type of the routing component, make the new structure and
+ * make the new structure and
  * set the parsing functions to allows parsing the part of the routing tree
  */
-static void parse_S_AS(void) { 
+static void parse_S_AS(char* AS_id,char* AS_routing) {
   routing_component_t new_routing;
   model_type_t model = NULL;
-  char* wanted = A_surfxml_AS_routing;
+  char* wanted = AS_routing;
   int cpt;
   /* seach the routing model */
   for (cpt=0;routing_models[cpt].name;cpt++)
@@ -271,7 +334,7 @@ static void parse_S_AS(void) {
   new_routing = (routing_component_t)(*(model->create))();
   new_routing->routing = model;
   new_routing->hierarchy = SURF_ROUTING_NULL;
-  new_routing->name = xbt_strdup(A_surfxml_AS_id);
+  new_routing->name = xbt_strdup(AS_id);
   new_routing->routing_sons = xbt_dict_new();
   //INFO2("Routing %s for AS %s",A_surfxml_AS_routing,A_surfxml_AS_id);
   
@@ -283,16 +346,16 @@ static void parse_S_AS(void) {
     
   } else if( current_routing != NULL && global_routing->root != NULL ) { 
     
-    xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,A_surfxml_AS_id),
-           "The AS \"%s\" already exist",A_surfxml_AS_id);
+    xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,AS_id),
+           "The AS \"%s\" already exist",AS_id);
      /* it is a part of the tree */
     new_routing->routing_father = current_routing;
     /* set the father behavior */
     if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
     /* add to the sons dictionary */
-    xbt_dict_set(current_routing->routing_sons,A_surfxml_AS_id,(void*)new_routing,NULL);
+    xbt_dict_set(current_routing->routing_sons,AS_id,(void*)new_routing,NULL);
     /* add to the father element list */
-    (*(current_routing->set_autonomous_system))(current_routing,A_surfxml_AS_id);
+    (*(current_routing->set_autonomous_system))(current_routing,AS_id);
     /* unload the prev parse rules */
     (*(current_routing->routing->unload))();
     
@@ -305,16 +368,33 @@ static void parse_S_AS(void) {
   current_routing = new_routing;
 }
 
+/*
+ * Detect the routing model type of the routing component from XML platforms
+ */
+static void parse_S_AS_XML(void)
+{
+       parse_S_AS(A_surfxml_AS_id,A_surfxml_AS_routing);
+}
+
+/*
+ * define the routing model type of routing component from lua script
+ */
+static void parse_S_AS_lua(char* id,char* mode)
+{
+       parse_S_AS(id,mode);
+}
+
+
 /**
  * \brief Finish the creation of a new routing component
  *
  * When you finish to read the routing component, other structures must be created. 
  * the "end" method allow to do that for any routing model type
  */
-static void parse_E_AS(void) {
+static void parse_E_AS(char *AS_id) {
 
   if( current_routing == NULL ) {
-    THROW1(arg_error,0,"Close AS(%s), that never open",A_surfxml_AS_id);
+    THROW1(arg_error,0,"Close AS(%s), that never open",AS_id);
   } else {
       xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,current_routing->name),
           "The AS \"%s\" already exist",current_routing->name);
@@ -327,6 +407,22 @@ static void parse_E_AS(void) {
   }
 }
 
+/*
+ * \brief Finish the creation of a new routing component from XML
+ */
+static void parse_E_AS_XML(void)
+{
+       parse_E_AS(A_surfxml_AS_id);
+}
+
+/*
+ * \brief Finish the creation of a new routing component from lua
+ */
+static void parse_E_AS_lua(char *id)
+{
+       parse_E_AS(id);
+}
+
 /* Aux Business methods */
 
 /**
@@ -428,7 +524,7 @@ static route_extended_t _get_route(const char* src,const char* dst) {
      
   xbt_assert0(src&&dst,"bad parameters for \"_get_route\" method");
   
-  route_extended_t e_route, e_route_cnt, e_route_src, e_route_dst;
+  route_extended_t e_route, e_route_cnt, e_route_src=NULL, e_route_dst=NULL;
   
   xbt_dynar_t elem_father_list = elements_father(src,dst);
   
@@ -581,6 +677,45 @@ static void finalize(void) {
   xbt_free(global_routing);
 }
 
+static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc)
+{
+  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("global \"is_router\" function not implemented yet");
+}
+
 /**
  * \brief Generic method: create the global routing schema
  * 
@@ -593,6 +728,8 @@ void routing_model_create(size_t size_of_links, void* loopback) {
   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;
@@ -602,21 +739,21 @@ void routing_model_create(size_t size_of_links, void* loopback) {
   current_routing = NULL;
 
   /* parse generic elements */
-  surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host);
+  surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
 
-  surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints);
+  surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints_XML);
   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);
+  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);
   surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list, &parse_E_bypassRoute_store_route);
   
-  surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
-  surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
+  surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
+  surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
 
   surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
 
@@ -638,6 +775,40 @@ typedef struct {
 } 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);
@@ -699,6 +870,8 @@ static void* model_full_create(void) {
   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();
@@ -797,6 +970,15 @@ typedef struct {
 } s_routing_component_floyd_t,*routing_component_floyd_t;
 
 /* Business methods */
+static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
+{
+  xbt_die("\"floyd_get_onelink_routes\" function not implemented yet");
+}
+
+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);
@@ -819,7 +1001,7 @@ static route_extended_t floyd_get_route(routing_component_t rc, const char* src,
   int first = 1;
   int pred = *dst_id;
   int prev_pred = 0;
-  char *gw_src,*gw_dst, *prev_gw_src,*prev_gw_dst, *first_gw;
+  char *gw_src=NULL,*gw_dst=NULL, *prev_gw_src,*prev_gw_dst, *first_gw=NULL;
   unsigned int cpt;
   void* link;
   xbt_dynar_t links;
@@ -897,6 +1079,8 @@ static void* model_floyd_create(void) {
   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();
@@ -1145,6 +1329,15 @@ static void add_loopback_dijkstra(routing_component_dijkstra_t rc) {
 }
 
 /* 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);
@@ -1269,7 +1462,7 @@ static route_extended_t dijkstra_get_route(routing_component_t rc, const char* s
   }
   
   /* compose route path with links */
-  char *gw_src,*gw_dst, *prev_gw_src,*prev_gw_dst, *first_gw;
+  char *gw_src=NULL,*gw_dst=NULL, *prev_gw_src,*prev_gw_dst, *first_gw=NULL;
   
   for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
     xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
@@ -1351,6 +1544,8 @@ static void* model_dijkstra_both_create(int cached) {
   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;
@@ -1525,7 +1720,7 @@ static void model_rulebased_set_ASroute(routing_component_t rc, const char* src,
 }
 
 static void model_rulebased_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
-  xbt_die("bypass routing not support for Route-Based model");
+  xbt_die("bypass routing not supported for Route-Based model");
 }
 
 #define BUFFER_SIZE 4096  /* result buffer size */
@@ -1593,10 +1788,20 @@ static char* remplace(char* value, const char** src_list, int src_size, const ch
   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);
-  
+
   /* set utils vars */
   routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
 
@@ -1611,7 +1816,8 @@ static route_extended_t rulebased_get_route(routing_component_t rc, const char*
   } else
      xbt_assert2(NULL, "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",src,dst); 
 
-  int rc_src,rc_dst;
+  int rc_src = -1;
+  int rc_dst = -1;
   int src_length = (int)strlen(src);
   int dst_length = (int)strlen(dst);
   
@@ -1649,8 +1855,14 @@ static route_extended_t rulebased_get_route(routing_component_t rc, const char*
   if(rc_src >= 0 && rc_dst >= 0) {
     new_e_route = xbt_new0(s_route_extended_t,1);
     new_e_route->generic_route.link_list = links_list;
+  } else if( !strcmp(src,dst) && are_processing_units ) {
+    new_e_route = xbt_new0(s_route_extended_t,1);
+    xbt_dynar_push(links_list,&(global_routing->loopback));
+    new_e_route->generic_route.link_list = links_list;
+  } else { 
+    xbt_dynar_free(&link_list);
   }
-  
+
   if(!are_processing_units && new_e_route)
   {
     rule_route_extended_t ruleroute_extended = (rule_route_extended_t)ruleroute;
@@ -1688,6 +1900,8 @@ static void* model_rulebased_create(void) {
   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;
@@ -1719,6 +1933,12 @@ typedef struct {
 } 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;
 }
@@ -1741,6 +1961,8 @@ static void* model_none_create(void) {
   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;
@@ -1811,7 +2033,7 @@ static void generic_set_processing_unit(routing_component_t rc, const char* name
           modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE])
     _to_index = ((routing_component_dijkstra_t)rc)->to_index;
   
-  else xbt_die("\"generic_set_processing_unit\" not support");
+  else xbt_die("\"generic_set_processing_unit\" not supported");
   *id = xbt_dict_length(_to_index);
   xbt_dict_set(_to_index,name,id,xbt_free);
 }
@@ -1831,7 +2053,7 @@ static void generic_set_autonomous_system(routing_component_t rc, const char* na
           modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE])
     _to_index = ((routing_component_dijkstra_t)rc)->to_index;
   
-  else xbt_die("\"generic_set_autonomous_system\" not support");
+  else xbt_die("\"generic_set_autonomous_system\" not supported");
   *id = xbt_dict_length(_to_index);
   xbt_dict_set(_to_index,name,id,xbt_free);
 }
@@ -1857,7 +2079,7 @@ static void generic_set_route(routing_component_t rc, const char* src, const cha
     _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 support");
+  } else xbt_die("\"generic_set_route\" not supported");
 
   src_id = xbt_dict_get_or_null(_to_index, src);
   dst_id = xbt_dict_get_or_null(_to_index, dst);
@@ -1894,7 +2116,7 @@ static void generic_set_ASroute(routing_component_t rc, const char* src, const c
     _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 support");
+  } else xbt_die("\"generic_set_route\" not supported");
   
   src_id = xbt_dict_get_or_null(_to_index, src);
   dst_id = xbt_dict_get_or_null(_to_index, dst);
@@ -1922,7 +2144,7 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
   } 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");
+  } else xbt_die("\"generic_set_bypassroute\" not supported");
   route_name = bprintf("%s#%s",src,dst);
   xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
   xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes,route_name),
@@ -1939,6 +2161,16 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* ************************************************************************** */
 /* *********************** 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;
@@ -1950,7 +2182,7 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc, const ch
   } 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");
+  } else xbt_die("\"generic_get_bypassroute\" not supported");
  
 
   routing_component_t src_as, dst_as;
@@ -2187,6 +2419,7 @@ static void generic_src_dst_check(routing_component_t rc, const char* src, const
 
 static void routing_full_parse_Scluster(void)
 {
+       static int AX_ptr = 0;
 
        char *cluster_id = A_surfxml_cluster_id;
        char *cluster_prefix = A_surfxml_cluster_prefix;
@@ -2203,20 +2436,27 @@ static void routing_full_parse_Scluster(void)
        int start, end, i;
        xbt_dynar_t radical_elements;
        xbt_dynar_t radical_ends;
-       static int AX_ptr = 0;
-       static int surfxml_bufferstack_size = 2048;
+       #ifndef HAVE_PCRE_LIB
+               xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+               char *route_src,*route_dst;
+               int j;
+       #endif
 
-       /* allocating memory for the buffer, I think 2kB should be enough */
-       surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
+       static unsigned int surfxml_buffer_stack_stack_ptr = 1;
+       static unsigned int surfxml_buffer_stack_stack[1024];
 
-       DEBUG4("id='%s' prefix='%s' suffix='%s' radical='%s'",
-         cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
-       DEBUG5("power='%s' bw='%s' lat='%s' bb_bw='%s' bb_lat='%s'",
-                 cluster_power,cluster_bw,cluster_lat,cluster_bb_bw,cluster_bb_lat);
+       surfxml_buffer_stack_stack[0]= 0;
+
+       surfxml_bufferstack_push(1);
 
-       DEBUG1("<AS id=\"%s\"\trouting=\"Full\">",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, ",");
@@ -2228,10 +2468,12 @@ static void routing_full_parse_Scluster(void)
                        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);
-                         SURFXML_BUFFER_RESET();
                          SURFXML_BUFFER_SET(host_id, host_id);
                          SURFXML_BUFFER_SET(host_power, cluster_power);
                          SURFXML_BUFFER_SET(host_availability, "1.0");
@@ -2246,7 +2488,6 @@ static void routing_full_parse_Scluster(void)
                          SURFXML_END_TAG(host);
 
                          DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
-                         SURFXML_BUFFER_RESET();
                          SURFXML_BUFFER_SET(link_id, link_id);
                          SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
                          SURFXML_BUFFER_SET(link_latency, cluster_lat);
@@ -2264,13 +2505,16 @@ static void routing_full_parse_Scluster(void)
 
                          surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
                          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);
+                                 #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);
-                                 SURFXML_BUFFER_RESET();
                                  SURFXML_BUFFER_SET(host_id, host_id);
                                  SURFXML_BUFFER_SET(host_power, cluster_power);
                                  SURFXML_BUFFER_SET(host_availability, "1.0");
@@ -2285,7 +2529,6 @@ static void routing_full_parse_Scluster(void)
                                  SURFXML_END_TAG(host);
 
                                  DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
-                                 SURFXML_BUFFER_RESET();
                                  SURFXML_BUFFER_SET(link_id, link_id);
                                  SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
                                  SURFXML_BUFFER_SET(link_latency, cluster_lat);
@@ -2312,13 +2555,11 @@ static void routing_full_parse_Scluster(void)
        link_backbone = bprintf("%s_backbone",cluster_id);
 
        DEBUG1("<router id=\"%s\"\">",router_id);
-       SURFXML_BUFFER_RESET();
        SURFXML_BUFFER_SET(router_id, router_id);;
        SURFXML_START_TAG(router);
        SURFXML_END_TAG(router);
 
        DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_router,cluster_bw,cluster_lat);
-       SURFXML_BUFFER_RESET();
        SURFXML_BUFFER_SET(link_id, link_router);
        SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
        SURFXML_BUFFER_SET(link_latency, cluster_lat);
@@ -2331,7 +2572,6 @@ static void routing_full_parse_Scluster(void)
        SURFXML_END_TAG(link);
 
        DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_backbone,cluster_bb_bw,cluster_bb_lat);
-       SURFXML_BUFFER_RESET();
        SURFXML_BUFFER_SET(link_id, link_backbone);
        SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
        SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
@@ -2357,34 +2597,124 @@ static void routing_full_parse_Scluster(void)
 
        DEBUG0(" ");
 
+#ifdef HAVE_PCRE_LIB
+
        DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
-       SURFXML_BUFFER_RESET();
        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_$src1\"/>",cluster_id);
-       SURFXML_BUFFER_RESET();
-       SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$src1",cluster_id));
-       SURFXML_START_TAG(link_c_ctn);
-       SURFXML_END_TAG(link_c_ctn);
+       DEBUG1("<link:ctn\tid=\"%s_link_$1src\"/>",cluster_id);
+       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_RESET();
-       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_$dst1\"/>",cluster_id);
-       SURFXML_BUFFER_RESET();
-       SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$dst1",cluster_id));
-       SURFXML_START_TAG(link_c_ctn);
-       SURFXML_END_TAG(link_c_ctn);
+       DEBUG1("<link:ctn\tid=\"%s_link_$1dst\"/>",cluster_id);
+       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<=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);
+       DEBUG0(" ");
 
+       surfxml_bufferstack_pop(1);
+}
+
+/*
+ * New methods to init the routing model component from the lua script
+ */
+
+/*
+ * calling parse_S_AS_lua with lua values
+ */
+void routing_AS_init(const char* AS_id,const char* AS_routing)
+{
+       parse_S_AS_lua((char*)AS_id,(char*)AS_routing);
+}
+
+/*
+ * calling parse_E_AS_lua to fisnish the creation of routing component
+ */
+void routing_AS_end(const char *AS_id)
+{
+       parse_E_AS_lua((char*)AS_id);
+}
+
+/*
+ * add a host to the network element list
+ */
+
+void routing_add_host(const char* host_id)
+{
+       parse_S_host_lua((char*)host_id);
+}
+
+/*
+ * Set a new link on the actual list of link for a route or ASroute
+ */
+void routing_add_link(const char* link_id)
+{
+       parse_E_link_c_ctn_new_elem_lua((char*)link_id);
+}
+
+/*
+ *Set the endpoints for a route
+ */
+void routing_set_route(const char* src_id,const char *dst_id)
+{
+       parse_S_route_new_and_endpoints_lua((char*)src_id,(char*)dst_id);
+}
+
+/*
+ * Store the route by calling parse_E_route_store_route
+ */
+void routing_store_route(void)
+{
+       parse_E_route_store_route();
 }