Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0bd75d67940249abe1be980743c20fcda5535358
[simgrid.git] / src / surf / surf_routing.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team. 
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifdef HAVE_PCRE_LIB
8 #include <pcre.h>               /* regular expression library */
9 #endif
10 #include "surf_routing_private.h"
11 #include "surf/surf_routing.h"
12
13 xbt_lib_t host_lib;
14 int ROUTING_HOST_LEVEL; //Routing level
15 int     SURF_CPU_LEVEL;         //Surf cpu level
16 int SURF_WKS_LEVEL;             //Surf workstation level
17 int SIMIX_HOST_LEVEL;   //Simix level
18 int     MSG_HOST_LEVEL;         //Msg level
19 int     SD_HOST_LEVEL;          //Simdag level
20 int     COORD_HOST_LEVEL;       //Coordinates level
21 int NS3_HOST_LEVEL;             //host node for ns3
22
23 xbt_lib_t link_lib;
24 int SD_LINK_LEVEL;              //Simdag level
25 int SURF_LINK_LEVEL;    //Surf level
26 int NS3_LINK_LEVEL;             //link for ns3
27
28 xbt_lib_t as_router_lib;
29 int ROUTING_ASR_LEVEL;  //Routing level
30 int COORD_ASR_LEVEL;    //Coordinates level
31 int NS3_ASR_LEVEL;              //host node for ns3
32
33 static xbt_dict_t patterns = NULL;
34 static xbt_dict_t random_value = NULL;
35
36 /* Global vars */
37 routing_global_t global_routing = NULL;
38 routing_component_t current_routing = NULL;
39 model_type_t current_routing_model = NULL;
40
41 /* global parse functions */
42 xbt_dynar_t link_list = NULL;    /* temporary store of current list link of a route */
43 static const char *src = NULL;        /* temporary store the source name of a route */
44 static const char *dst = NULL;        /* temporary store the destination name of a route */
45 static char *gw_src = NULL;     /* temporary store the gateway source name of a route */
46 static char *gw_dst = NULL;     /* temporary store the gateway destination name of a route */
47 static double_f_cpvoid_t get_link_latency = NULL;
48
49 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
50
51 static void routing_parse_Speer(void);          /* peer bypass */
52 static void routing_parse_Srandom(void);        /* random bypass */
53 static void routing_parse_Erandom(void);        /* random bypass */
54
55 static void routing_parse_Sconfig(void);        /* config Tag */
56 static void routing_parse_Econfig(void);        /* config Tag */
57
58 static char* replace_random_parameter(char * chaine);
59 static void clean_dict_random(void);
60
61 /* this lines are only for replace use like index in the model table */
62 typedef enum {
63   SURF_MODEL_FULL = 0,
64   SURF_MODEL_FLOYD,
65   SURF_MODEL_DIJKSTRA,
66   SURF_MODEL_DIJKSTRACACHE,
67   SURF_MODEL_NONE,
68 #ifdef HAVE_PCRE_LIB
69   SURF_MODEL_RULEBASED
70 #endif
71 } e_routing_types;
72
73 struct s_model_type routing_models[] = { {"Full",
74                                           "Full routing data (fast, large memory requirements, fully expressive)",
75                                           model_full_create,
76                                           model_full_load,
77                                           model_full_unload,
78                                           model_full_end},
79 {"Floyd",
80  "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
81  model_floyd_create, model_floyd_load, model_floyd_unload,
82  model_floyd_end},
83 {"Dijkstra",
84  "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
85  model_dijkstra_create, model_dijkstra_both_load,
86  model_dijkstra_both_unload, model_dijkstra_both_end},
87 {"DijkstraCache",
88  "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
89  model_dijkstracache_create, model_dijkstra_both_load,
90  model_dijkstra_both_unload, model_dijkstra_both_end},
91 {"none", "No routing (usable with Constant network only)",
92  model_none_create, model_none_load, model_none_unload, model_none_end},
93 #ifdef HAVE_PCRE_LIB
94 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
95  model_rulebased_load, model_rulebased_unload, model_rulebased_end},
96 {"Vivaldi", "Vivaldi routing", model_rulebased_create,
97   model_rulebased_load, model_rulebased_unload, model_rulebased_end},
98 #endif
99 {NULL, NULL, NULL, NULL, NULL, NULL}
100 };
101
102 static double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
103 {
104         double src_coord, dst_coord;
105
106         src_coord = atof(xbt_dynar_get_as(src, index, char *));
107         dst_coord = atof(xbt_dynar_get_as(dst, index, char *));
108
109         return (src_coord-dst_coord)*(src_coord-dst_coord);
110
111 }
112
113 static double base_vivaldi_get_latency (const char *src, const char *dst)
114 {
115   double euclidean_dist;
116   xbt_dynar_t src_ctn, dst_ctn;
117   src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL);
118   if(!src_ctn) src_ctn = xbt_lib_get_or_null(as_router_lib, src, COORD_ASR_LEVEL);
119   dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL);
120   if(!dst_ctn) dst_ctn = xbt_lib_get_or_null(as_router_lib, dst, COORD_ASR_LEVEL);
121
122   if(dst_ctn == NULL || src_ctn == NULL)
123   xbt_die("Coord src '%s' :%p   dst '%s' :%p",src,src_ctn,dst,dst_ctn);
124
125   euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
126                                  + fabs(atof(xbt_dynar_get_as(src_ctn, 2, char *)))+fabs(atof(xbt_dynar_get_as(dst_ctn, 2, char *)));
127
128   xbt_assert(euclidean_dist>=0, "Euclidean Dist is less than 0\"%s\" and \"%.2f\"", src, euclidean_dist);
129
130   return euclidean_dist;
131 }
132
133 static double vivaldi_get_link_latency (routing_component_t rc,const char *src, const char *dst, route_extended_t e_route)
134 {
135   if(get_network_element_type(src) == SURF_NETWORK_ELEMENT_AS) {
136           int need_to_clean = e_route?0:1;
137           double latency;
138           e_route = e_route?e_route:(*(rc->get_route)) (rc, src, dst);
139           latency = base_vivaldi_get_latency(e_route->src_gateway,e_route->dst_gateway);
140           if(need_to_clean) generic_free_extended_route(e_route);
141           return latency;
142   } else {
143           return base_vivaldi_get_latency(src,dst);
144   }
145 }
146
147 /**
148  * \brief Add a "host" to the network element list
149  */
150 static void parse_S_host(const char *host_id, const char* coord)
151 {
152   network_element_info_t info = NULL;
153   if (current_routing->hierarchy == SURF_ROUTING_NULL)
154     current_routing->hierarchy = SURF_ROUTING_BASE;
155   xbt_assert(!xbt_lib_get_or_null(host_lib, host_id,ROUTING_HOST_LEVEL),
156               "Reading a host, processing unit \"%s\" already exists",
157               host_id);
158   xbt_assert(current_routing->set_processing_unit,
159               "no defined method \"set_processing_unit\" in \"%s\"",
160               current_routing->name);
161   (*(current_routing->set_processing_unit)) (current_routing, host_id);
162   info = xbt_new0(s_network_element_info_t, 1);
163   info->rc_component = current_routing;
164   info->rc_type = SURF_NETWORK_ELEMENT_HOST;
165   xbt_lib_set(host_lib,host_id,ROUTING_HOST_LEVEL,(void *) info);
166   if (strcmp(coord,"")) {
167         if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
168     xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
169     xbt_dynar_shrink(ctn, 0);
170     xbt_lib_set(host_lib,host_id,COORD_HOST_LEVEL,(void *) ctn);
171   }
172 }
173
174 static void parse_E_host(void)
175 {
176          xbt_dict_cursor_t cursor = NULL;
177           char *key;
178           char *elem;
179
180           xbt_dict_foreach(current_property_set, cursor, key, elem) {
181                   XBT_DEBUG("property : %s = %s",key,elem);
182                 }
183 }
184
185 /*
186  * \brief Add a host to the network element list from XML
187  */
188 static void parse_S_host_XML(void)
189 {
190         parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
191 }
192 static void parse_E_host_XML(void)
193 {
194         parse_E_host();
195 }
196
197 /*
198  * \brief Add a host to the network element list from lua script
199  */
200 static void parse_S_host_lua(const char *host_id, const char *coord)
201 {
202   parse_S_host(host_id, coord);
203 }
204
205
206 /**
207  * \brief Add a "router" to the network element list
208  */
209 static void parse_S_router(const char *router_id)
210 {
211   network_element_info_t info = NULL;
212
213   if (current_routing->hierarchy == SURF_ROUTING_NULL)
214     current_routing->hierarchy = SURF_ROUTING_BASE;
215   xbt_assert(!xbt_lib_get_or_null(as_router_lib,A_surfxml_router_id, ROUTING_ASR_LEVEL),
216               "Reading a router, processing unit \"%s\" already exists",
217               router_id);
218   xbt_assert(current_routing->set_processing_unit,
219               "no defined method \"set_processing_unit\" in \"%s\"",
220               current_routing->name);
221   (*(current_routing->set_processing_unit)) (current_routing,
222                                              router_id);
223   info = xbt_new0(s_network_element_info_t, 1);
224   info->rc_component = current_routing;
225   info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
226
227   xbt_lib_set(as_router_lib,router_id,ROUTING_ASR_LEVEL,(void *) info);
228   if (strcmp(A_surfxml_router_coordinates,"")) {
229         if(!COORD_ASR_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'");
230     xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_router_coordinates, " ");
231     xbt_dynar_shrink(ctn, 0);
232     xbt_lib_set(as_router_lib,router_id,COORD_ASR_LEVEL,(void *) ctn);
233   }
234 }
235
236 /**
237  * brief Add a "router" to the network element list from XML description
238  */
239 static void parse_S_router_XML(void)
240 {
241         return parse_S_router(A_surfxml_router_id);
242 }
243
244 /**
245  * brief Add a "router" to the network element list from XML description
246  */
247 static void parse_S_router_lua(const char* router_id)
248 {
249         return parse_S_router(router_id);
250 }
251
252 /**
253  * \brief Set the endponints for a route
254  */
255 static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_id)
256 {
257   if (src != NULL && dst != NULL && link_list != NULL)
258     THROWF(arg_error, 0, "Route between %s to %s can not be defined",
259            src_id, dst_id);
260   src = src_id;
261   dst = dst_id;
262   xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
263               "Some limits are null in the route between \"%s\" and \"%s\"",
264               src, dst);
265   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
266 }
267
268 /**
269  * \brief Set the endpoints for a route from XML
270  */
271 static void parse_S_route_new_and_endpoints_XML(void)
272 {
273   parse_S_route_new_and_endpoints(A_surfxml_route_src,
274                                   A_surfxml_route_dst);
275 }
276
277 /**
278  * \brief Set the endpoints for a route from lua
279  */
280 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
281 {
282   parse_S_route_new_and_endpoints(id_src, id_dst);
283 }
284
285 /**
286  * \brief Set the endponints and gateways for a ASroute
287  */
288 static void parse_S_ASroute_new_and_endpoints(void)
289 {
290   if (src != NULL && dst != NULL && link_list != NULL)
291     THROWF(arg_error, 0, "Route between %s to %s can not be defined",
292            A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
293   src = A_surfxml_ASroute_src;
294   dst = A_surfxml_ASroute_dst;
295   gw_src = A_surfxml_ASroute_gw_src;
296   gw_dst = A_surfxml_ASroute_gw_dst;
297   xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
298               || strlen(gw_dst) > 0,
299               "Some limits are null in the route between \"%s\" and \"%s\"",
300               src, dst);
301   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
302 }
303
304 /**
305  * \brief Set the endponints for a bypassRoute
306  */
307 static void parse_S_bypassRoute_new_and_endpoints(void)
308 {
309   if (src != NULL && dst != NULL && link_list != NULL)
310     THROWF(arg_error, 0,
311            "Bypass Route between %s to %s can not be defined",
312            A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
313   src = A_surfxml_bypassRoute_src;
314   dst = A_surfxml_bypassRoute_dst;
315   gw_src = A_surfxml_bypassRoute_gw_src;
316   gw_dst = A_surfxml_bypassRoute_gw_dst;
317   xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
318               || strlen(gw_dst) > 0,
319               "Some limits are null in the route between \"%s\" and \"%s\"",
320               src, dst);
321   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
322 }
323
324 /**
325  * \brief Set a new link on the actual list of link for a route or ASroute
326  */
327 static void parse_E_link_ctn_new_elem(const char *link_id)
328 {
329   char *val;
330   val = xbt_strdup(link_id);
331   xbt_dynar_push(link_list, &val);
332 }
333
334 /**
335  * \brief Set a new link on the actual list of link for a route or ASroute from XML
336  */
337
338 static void parse_E_link_ctn_new_elem_XML(void)
339 {
340   if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
341     parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
342   if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
343     char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
344     parse_E_link_ctn_new_elem(link_id);
345     free(link_id);
346   }
347   if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
348     char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
349     parse_E_link_ctn_new_elem(link_id);
350     free(link_id);
351   }
352 }
353
354 /**
355  * \brief Set a new link on the actual list of link for a route or ASroute from lua
356  */
357 static void parse_E_link_c_ctn_new_elem_lua(const char *link_id)
358 {
359   parse_E_link_ctn_new_elem(link_id);
360 }
361
362 /**
363  * \brief Store the route by calling the set_route function of the current routing component
364  */
365 static void parse_E_route_store_route(void)
366 {
367   name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
368   route->generic_route.link_list = link_list;
369   xbt_assert(current_routing->set_route,
370               "no defined method \"set_route\" in \"%s\"",
371               current_routing->name);
372   (*(current_routing->set_route)) (current_routing, src, dst, route);
373   link_list = NULL;
374   src = NULL;
375   dst = NULL;
376 }
377
378 /**
379  * \brief Store the ASroute by calling the set_ASroute function of the current routing component
380  */
381 static void parse_E_ASroute_store_route(void)
382 {
383   name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
384   e_route->generic_route.link_list = link_list;
385   e_route->src_gateway = xbt_strdup(gw_src);
386   e_route->dst_gateway = xbt_strdup(gw_dst);
387   xbt_assert(current_routing->set_ASroute,
388               "no defined method \"set_ASroute\" in \"%s\"",
389               current_routing->name);
390   (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
391   link_list = NULL;
392   src = NULL;
393   dst = NULL;
394   gw_src = NULL;
395   gw_dst = NULL;
396 }
397
398 /**
399  * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
400  */
401 static void parse_E_bypassRoute_store_route(void)
402 {
403   route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
404   e_route->generic_route.link_list = link_list;
405   e_route->src_gateway = xbt_strdup(gw_src);
406   e_route->dst_gateway = xbt_strdup(gw_dst);
407   xbt_assert(current_routing->set_bypassroute,
408               "no defined method \"set_bypassroute\" in \"%s\"",
409               current_routing->name);
410   (*(current_routing->set_bypassroute)) (current_routing, src, dst,
411                                          e_route);
412   link_list = NULL;
413   src = NULL;
414   dst = NULL;
415   gw_src = NULL;
416   gw_dst = NULL;
417 }
418
419 /**
420  * \brief Make a new routing component
421  *
422  * make the new structure and
423  * set the parsing functions to allows parsing the part of the routing tree
424  */
425 static void parse_S_AS(char *AS_id, char *AS_routing)
426 {
427   routing_component_t new_routing;
428   model_type_t model = NULL;
429   char *wanted = AS_routing;
430   int cpt;
431   /* seach the routing model */
432   for (cpt = 0; routing_models[cpt].name; cpt++)
433     if (!strcmp(wanted, routing_models[cpt].name))
434       model = &routing_models[cpt];
435   /* if its not exist, error */
436   if (model == NULL) {
437     fprintf(stderr, "Routing model %s not found. Existing models:\n",
438             wanted);
439     for (cpt = 0; routing_models[cpt].name; cpt++)
440       if (!strcmp(wanted, routing_models[cpt].name))
441         fprintf(stderr, "   %s: %s\n", routing_models[cpt].name,
442                 routing_models[cpt].desc);
443     xbt_die(NULL);
444   }
445
446   /* make a new routing component */
447   new_routing = (routing_component_t) (*(model->create)) ();
448   new_routing->routing = model;
449   new_routing->hierarchy = SURF_ROUTING_NULL;
450   new_routing->name = xbt_strdup(AS_id);
451   new_routing->routing_sons = xbt_dict_new();
452
453   /* Hack for Vivaldi */
454   if(!strcmp(model->name,"Vivaldi"))
455         new_routing->get_latency = vivaldi_get_link_latency;
456
457   if (current_routing == NULL && global_routing->root == NULL) {
458
459     /* it is the first one */
460     new_routing->routing_father = NULL;
461     global_routing->root = new_routing;
462
463   } else if (current_routing != NULL && global_routing->root != NULL) {
464
465     xbt_assert(!xbt_dict_get_or_null
466                 (current_routing->routing_sons, AS_id),
467                 "The AS \"%s\" already exists", AS_id);
468     /* it is a part of the tree */
469     new_routing->routing_father = current_routing;
470     /* set the father behavior */
471     if (current_routing->hierarchy == SURF_ROUTING_NULL)
472       current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
473     /* add to the sons dictionary */
474     xbt_dict_set(current_routing->routing_sons, AS_id,
475                  (void *) new_routing, NULL);
476     /* add to the father element list */
477     (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
478     /* unload the prev parse rules */
479     (*(current_routing->routing->unload)) ();
480
481   } else {
482     THROWF(arg_error, 0, "All defined components must be belong to a AS");
483   }
484   /* set the new parse rules */
485   (*(new_routing->routing->load)) ();
486   /* set the new current component of the tree */
487   current_routing = new_routing;
488 }
489
490 /*
491  * Detect the routing model type of the routing component from XML platforms
492  */
493 static void parse_S_AS_XML(void)
494 {
495   parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
496 }
497
498 /*
499  * define the routing model type of routing component from lua script
500  */
501 static void parse_S_AS_lua(char *id, char *mode)
502 {
503   parse_S_AS(id, mode);
504 }
505
506
507 /**
508  * \brief Finish the creation of a new routing component
509  *
510  * When you finish to read the routing component, other structures must be created. 
511  * the "end" method allow to do that for any routing model type
512  */
513 static void parse_E_AS(const char *AS_id)
514 {
515
516   if (current_routing == NULL) {
517     THROWF(arg_error, 0, "Close AS(%s), that never open", AS_id);
518   } else {
519     network_element_info_t info = NULL;
520     xbt_assert(!xbt_lib_get_or_null(as_router_lib,current_routing->name, ROUTING_ASR_LEVEL),
521                 "The AS \"%s\" already exists",current_routing->name);
522     info = xbt_new0(s_network_element_info_t, 1);
523     info->rc_component = current_routing->routing_father;
524     info->rc_type = SURF_NETWORK_ELEMENT_AS;
525     xbt_lib_set(as_router_lib,current_routing->name,ROUTING_ASR_LEVEL,(void *) info);
526
527     (*(current_routing->routing->unload)) ();
528     (*(current_routing->routing->end)) ();
529     current_routing = current_routing->routing_father;
530     if (current_routing != NULL)
531       (*(current_routing->routing->load)) ();
532   }
533 }
534
535 /*
536  * \brief Finish the creation of a new routing component from XML
537  */
538 static void parse_E_AS_XML(void)
539 {
540   parse_E_AS(A_surfxml_AS_id);
541 }
542
543 /*
544  * \brief Finish the creation of a new routing component from lua
545  */
546 static void parse_E_AS_lua(const char *id)
547 {
548   parse_E_AS(id);
549 }
550
551 /* Aux Business methods */
552
553 /**
554  * \brief Get the AS name of the element
555  *
556  * \param name the host name
557  *
558  */
559 static char* elements_As_name(const char *name)
560 {
561   routing_component_t as_comp;
562
563   /* (1) find the as where the host is located */
564   as_comp = ((network_element_info_t)
565             xbt_lib_get_or_null(host_lib,name, ROUTING_HOST_LEVEL))->rc_component;
566   return as_comp->name;
567 }
568
569
570 /**
571  * \brief Get the AS father and the first elements of the chain
572  *
573  * \param src the source host name 
574  * \param dst the destination host name
575  * 
576  * Get the common father of the to processing units, and the first different 
577  * father in the chain
578  */
579 static void elements_father(const char *src, const char *dst,
580                             routing_component_t *res_father,
581                             routing_component_t *res_src,
582                             routing_component_t *res_dst)
583 {
584   xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
585 #define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */
586   routing_component_t src_as, dst_as;
587   routing_component_t path_src[ELEMENTS_FATHER_MAXDEPTH];
588   routing_component_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
589   int index_src = 0;
590   int index_dst = 0;
591   routing_component_t current;
592   routing_component_t current_src;
593   routing_component_t current_dst;
594   routing_component_t father;
595
596   /* (1) find the as where the src and dst are located */
597   network_element_info_t src_data = xbt_lib_get_or_null(host_lib, src,
598                                                         ROUTING_HOST_LEVEL);
599   network_element_info_t dst_data = xbt_lib_get_or_null(host_lib, dst,
600                                                         ROUTING_HOST_LEVEL);
601   if (!src_data)
602     src_data = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
603   if (!dst_data)
604     dst_data = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
605   src_as = src_data->rc_component;
606   dst_as = dst_data->rc_component;
607
608   xbt_assert(src_as && dst_as,
609              "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, dst);
610
611   /* (2) find the path to the root routing component */
612   for (current = src_as ; current != NULL ; current = current->routing_father) {
613     path_src[index_src++] = current;
614     xbt_assert(index_src <= ELEMENTS_FATHER_MAXDEPTH,
615                "ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
616   }
617   for (current = dst_as ; current != NULL ; current = current->routing_father) {
618     path_dst[index_dst++] = current;
619     xbt_assert(index_dst <= ELEMENTS_FATHER_MAXDEPTH,
620                "ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
621   }
622
623   /* (3) find the common father */
624   do {
625     current_src = path_src[--index_src];
626     current_dst = path_dst[--index_dst];
627   } while (index_src > 0 && index_dst > 0 && current_src == current_dst);
628
629   /* (4) they are not in the same routing component, make the path */
630   if (current_src == current_dst)
631     father = current_src;
632   else
633     father = path_src[index_src + 1];
634
635   /* (5) result generation */
636   *res_father = father;         /* first the common father of src and dst */
637   *res_src = current_src;       /* second the first different father of src */
638   *res_dst = current_dst;       /* three  the first different father of dst */
639
640 #undef ELEMENTS_FATHER_MAXDEPTH
641 }
642
643 /* Global Business methods */
644
645 /**
646  * \brief Recursive function for get_route_latency
647  *
648  * \param src the source host name 
649  * \param dst the destination host name
650  * \param *e_route the route where the links are stored
651  * \param *latency the latency, if needed
652  * 
653  * This function is called by "get_route" and "get_latency". It allows to walk
654  * recursively through the routing components tree.
655  */
656 static void _get_route_latency(const char *src, const char *dst,
657                                xbt_dynar_t *route, double *latency)
658 {
659   XBT_DEBUG("Solve route/latency  \"%s\" to \"%s\"", src, dst);
660   xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
661
662   routing_component_t common_father;
663   routing_component_t src_father;
664   routing_component_t dst_father;
665   elements_father(src, dst, &common_father, &src_father, &dst_father);
666
667   if (src_father == dst_father) { /* SURF_ROUTING_BASE */
668
669     route_extended_t e_route = NULL;
670     if (route) {
671       e_route = common_father->get_route(common_father, src, dst);
672       xbt_assert(e_route, "no route between \"%s\" and \"%s\"", src, dst);
673       *route = e_route->generic_route.link_list;
674     }
675     if (latency) {
676       *latency = common_father->get_latency(common_father, src, dst, e_route);
677       xbt_assert(*latency >= 0.0,
678                  "latency error on route between \"%s\" and \"%s\"", src, dst);
679     }
680     if (e_route) {
681       xbt_free(e_route->src_gateway);
682       xbt_free(e_route->dst_gateway);
683       xbt_free(e_route);
684     }
685
686   } else {                      /* SURF_ROUTING_RECURSIVE */
687
688     route_extended_t e_route_bypass = NULL;
689     if (common_father->get_bypass_route)
690       e_route_bypass = common_father->get_bypass_route(common_father, src, dst);
691
692     xbt_assert(!latency || !e_route_bypass,
693                "Bypass cannot work yet with get_latency");
694
695     route_extended_t e_route_cnt = e_route_bypass
696       ? e_route_bypass
697       : common_father->get_route(common_father,
698                                src_father->name, dst_father->name);
699
700     xbt_assert(e_route_cnt, "no route between \"%s\" and \"%s\"",
701                src_father->name, dst_father->name);
702
703     xbt_assert((e_route_cnt->src_gateway == NULL) ==
704                (e_route_cnt->dst_gateway == NULL),
705                "bad gateway for route between \"%s\" and \"%s\"", src, dst);
706
707     if (route) {
708       *route = xbt_dynar_new(global_routing->size_of_link, NULL);
709     }
710     if (latency) {
711       *latency = common_father->get_latency(common_father,
712                                             src_father->name, dst_father->name,
713                                             e_route_cnt);
714       xbt_assert(*latency >= 0.0,
715                  "latency error on route between \"%s\" and \"%s\"",
716                  src_father->name, dst_father->name);
717     }
718
719     void *link;
720     unsigned int cpt;
721
722     if (strcmp(src, e_route_cnt->src_gateway)) {
723       double latency_src;
724       xbt_dynar_t route_src;
725
726       _get_route_latency(src, e_route_cnt->src_gateway,
727                          (route ? &route_src : NULL),
728                          (latency ? &latency_src : NULL));
729       if (route) {
730         xbt_assert(route_src, "no route between \"%s\" and \"%s\"",
731                    src, e_route_cnt->src_gateway);
732         xbt_dynar_foreach(route_src, cpt, link) {
733           xbt_dynar_push(*route, &link);
734         }
735         xbt_dynar_free(&route_src);
736       }
737       if (latency) {
738         xbt_assert(latency_src >= 0.0,
739                    "latency error on route between \"%s\" and \"%s\"",
740                    src, e_route_cnt->src_gateway);
741         *latency += latency_src;
742       }
743     }
744
745     if (route) {
746       xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
747         xbt_dynar_push(*route, &link);
748       }
749     }
750
751     if (strcmp(e_route_cnt->dst_gateway, dst)) {
752       double latency_dst;
753       xbt_dynar_t route_dst;
754
755       _get_route_latency(e_route_cnt->dst_gateway, dst,
756                          (route ? &route_dst : NULL),
757                          (latency ? &latency_dst : NULL));
758       if (route) {
759         xbt_assert(route_dst, "no route between \"%s\" and \"%s\"",
760                    e_route_cnt->dst_gateway, dst);
761         xbt_dynar_foreach(route_dst, cpt, link) {
762           xbt_dynar_push(*route, &link);
763         }
764         xbt_dynar_free(&route_dst);
765       }
766       if (latency) {
767         xbt_assert(latency_dst >= 0.0,
768                    "latency error on route between \"%s\" and \"%s\"",
769                    e_route_cnt->dst_gateway, dst);
770         *latency += latency_dst;
771       }
772     }
773
774     generic_free_extended_route(e_route_cnt);
775   }
776 }
777
778 /**
779  * \brief Generic function for get_route, get_route_no_cleanup, and get_latency
780  */
781 static void get_route_latency(const char *src, const char *dst,
782                               xbt_dynar_t *route, double *latency, int cleanup)
783 {
784   _get_route_latency(src, dst, route, latency);
785   xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
786   xbt_assert(!latency || *latency >= 0.0,
787              "latency error on route between \"%s\" and \"%s\"", src, dst);
788   if (route) {
789     xbt_dynar_free(&global_routing->last_route);
790     global_routing->last_route = cleanup ? *route : NULL;
791   }
792 }
793
794 /**
795  * \brief Generic method: find a route between hosts
796  *
797  * \param src the source host name 
798  * \param dst the destination host name
799  * 
800  * walk through the routing components tree and find a route between hosts
801  * by calling the differents "get_route" functions in each routing component.
802  * No need to free the returned dynar. It will be freed at the next call.
803  */
804 static xbt_dynar_t get_route(const char *src, const char *dst)
805 {
806   xbt_dynar_t route = NULL;
807   get_route_latency(src, dst, &route, NULL, 1);
808   return route;
809 }
810
811 /**
812  * \brief Generic method: find a route between hosts
813  *
814  * \param src the source host name
815  * \param dst the destination host name
816  *
817  * walk through the routing components tree and find a route between hosts
818  * by calling the differents "get_route" functions in each routing component.
819  * Leaves the caller the responsability to clean the returned dynar.
820  */
821 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
822 {
823   xbt_dynar_t route = NULL;
824   get_route_latency(src, dst, &route, NULL, 0);
825   return route;
826 }
827
828 /*Get Latency*/
829 static double get_latency(const char *src, const char *dst)
830 {
831   double latency = -1.0;
832   get_route_latency(src, dst, NULL, &latency, 0);
833   return latency;
834 }
835
836 /**
837  * \brief Recursive function for finalize
838  *
839  * \param rc the source host name 
840  * 
841  * This fuction is call by "finalize". It allow to finalize the 
842  * AS or routing components. It delete all the structures.
843  */
844 static void _finalize(routing_component_t rc)
845 {
846   if (rc) {
847     xbt_dict_cursor_t cursor = NULL;
848     char *key;
849     routing_component_t elem;
850     xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
851       _finalize(elem);
852     }
853     xbt_dict_t tmp_sons = rc->routing_sons;
854     char *tmp_name = rc->name;
855     xbt_dict_free(&tmp_sons);
856     xbt_free(tmp_name);
857     xbt_assert(rc->finalize, "no defined method \"finalize\" in \"%s\"",
858                 current_routing->name);
859     (*(rc->finalize)) (rc);
860   }
861 }
862
863 /**
864  * \brief Generic method: delete all the routing structures
865  * 
866  * walk through the routing components tree and delete the structures
867  * by calling the differents "finalize" functions in each routing component
868  */
869 static void finalize(void)
870 {
871   /* delete recursibly all the tree */
872   _finalize(global_routing->root);
873   /* delete last_route */
874   xbt_dynar_free(&(global_routing->last_route));
875   /* delete global routing structure */
876   xbt_free(global_routing);
877 }
878
879 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
880 {
881   xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
882
883   //adding my one link routes
884   unsigned int cpt;
885   void *link;
886   xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
887   if (onelink_mine) {
888     xbt_dynar_foreach(onelink_mine, cpt, link) {
889       xbt_dynar_push(ret, &link);
890     }
891   }
892   //recursing
893   char *key;
894   xbt_dict_cursor_t cursor = NULL;
895   routing_component_t rc_child;
896   xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
897     xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
898     if (onelink_child) {
899       xbt_dynar_foreach(onelink_child, cpt, link) {
900         xbt_dynar_push(ret, &link);
901       }
902     }
903   }
904   return ret;
905 }
906
907 static xbt_dynar_t get_onelink_routes(void)
908 {
909   return recursive_get_onelink_routes(global_routing->root);
910 }
911
912 e_surf_network_element_type_t get_network_element_type(const char
913                                                               *name)
914 {
915   network_element_info_t rc = NULL;
916
917   rc = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
918   if(rc) return rc->rc_type;
919
920   rc = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
921   if(rc) return rc->rc_type;
922
923   return SURF_NETWORK_ELEMENT_NULL;
924 }
925
926 /**
927  * \brief Generic method: create the global routing schema
928  * 
929  * Make a global routing structure and set all the parsing functions.
930  */
931 void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
932 {
933   /* config the uniq global routing */
934   global_routing = xbt_new0(s_routing_global_t, 1);
935   global_routing->root = NULL;
936   global_routing->get_route = get_route;
937   global_routing->get_latency = get_latency;
938   global_routing->get_route_no_cleanup = get_route_no_cleanup;
939   global_routing->get_onelink_routes = get_onelink_routes;
940   global_routing->get_network_element_type = get_network_element_type;
941   global_routing->finalize = finalize;
942   global_routing->loopback = loopback;
943   global_routing->size_of_link = size_of_links;
944   global_routing->last_route = NULL;
945   get_link_latency = get_link_latency_fun;
946   /* no current routing at moment */
947   current_routing = NULL;
948
949   /* parse generic elements */
950   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
951   surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML);
952   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML);
953
954   surfxml_add_callback(STag_surfxml_route_cb_list,
955                        &parse_S_route_new_and_endpoints_XML);
956   surfxml_add_callback(STag_surfxml_ASroute_cb_list,
957                        &parse_S_ASroute_new_and_endpoints);
958   surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
959                        &parse_S_bypassRoute_new_and_endpoints);
960
961   surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
962                        &parse_E_link_ctn_new_elem_XML);
963
964   surfxml_add_callback(ETag_surfxml_route_cb_list,
965                        &parse_E_route_store_route);
966   surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
967                        &parse_E_ASroute_store_route);
968   surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
969                        &parse_E_bypassRoute_store_route);
970
971   surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
972   surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
973
974   surfxml_add_callback(STag_surfxml_cluster_cb_list,
975                        &routing_parse_Scluster);
976
977   surfxml_add_callback(STag_surfxml_peer_cb_list,
978                          &routing_parse_Speer);
979
980   surfxml_add_callback(ETag_surfxml_platform_cb_list,
981                                                   &clean_dict_random);
982
983 #ifdef HAVE_TRACING
984   instr_routing_define_callbacks();
985 #endif
986 }
987
988 void surf_parse_add_callback_config(void)
989 {
990         surfxml_add_callback(STag_surfxml_config_cb_list, &routing_parse_Sconfig);
991         surfxml_add_callback(ETag_surfxml_config_cb_list, &routing_parse_Econfig);
992         surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
993         surfxml_add_callback(STag_surfxml_AS_cb_list, &surf_parse_models_setup);
994         surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
995 }
996
997 void surf_parse_models_setup()
998 {
999         routing_parse_Erandom();
1000         surfxml_del_callback(STag_surfxml_AS_cb_list, surf_parse_models_setup);
1001         surf_config_models_setup(platform_filename);
1002         free(platform_filename);
1003 }
1004
1005 /* ************************************************** */
1006 /* ********** PATERN FOR NEW ROUTING **************** */
1007
1008 /* The minimal configuration of a new routing model need the next functions,
1009  * also you need to set at the start of the file, the new model in the model
1010  * list. Remember keep the null ending of the list.
1011  */
1012 /*** Routing model structure ***/
1013 // typedef struct {
1014 //   s_routing_component_t generic_routing;
1015 //   /* things that your routing model need */
1016 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1017
1018 /*** Parse routing model functions ***/
1019 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1020 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1021 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1022 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1023 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1024
1025 /*** Business methods ***/
1026 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1027 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1028 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1029
1030 /*** Creation routing model functions ***/
1031 // static void* model_NEW_create(void) {
1032 //   routing_component_NEW_t new_component =  xbt_new0(s_routing_component_NEW_t,1);
1033 //   new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1034 //   new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1035 //   new_component->generic_routing.set_route = model_NEW_set_route;
1036 //   new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1037 //   new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1038 //   new_component->generic_routing.get_route = NEW_get_route;
1039 //   new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1040 //   new_component->generic_routing.finalize = NEW_finalize;
1041 //   /* initialization of internal structures */
1042 //   return new_component;
1043 // } /* mandatory */
1044 // static void  model_NEW_load(void) {}   /* mandatory */
1045 // static void  model_NEW_unload(void) {} /* mandatory */
1046 // static void  model_NEW_end(void) {}    /* mandatory */
1047
1048 /* ************************************************************************** */
1049 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1050
1051 void generic_set_processing_unit(routing_component_t rc,
1052                                         const char *name)
1053 {
1054   XBT_DEBUG("Load process unit \"%s\"", name);
1055   int *id = xbt_new0(int, 1);
1056   xbt_dict_t _to_index;
1057   _to_index = current_routing->to_index;
1058   *id = xbt_dict_length(_to_index);
1059   xbt_dict_set(_to_index, name, id, xbt_free);
1060 }
1061
1062 void generic_set_autonomous_system(routing_component_t rc,
1063                                           const char *name)
1064 {
1065   XBT_DEBUG("Load Autonomous system \"%s\"", name);
1066   int *id = xbt_new0(int, 1);
1067   xbt_dict_t _to_index;
1068   _to_index = current_routing->to_index;
1069   *id = xbt_dict_length(_to_index);
1070   xbt_dict_set(_to_index, name, id, xbt_free);
1071 }
1072
1073 int surf_pointer_resource_cmp(const void *a, const void *b)
1074 {
1075   return a != b;
1076 }
1077
1078 int surf_link_resource_cmp(const void *a, const void *b)
1079 {
1080   return !!memcmp(a,b,global_routing->size_of_link);
1081 }
1082
1083 void generic_set_bypassroute(routing_component_t rc,
1084                                     const char *src, const char *dst,
1085                                     route_extended_t e_route)
1086 {
1087   XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
1088   xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1089   char *route_name;
1090
1091   route_name = bprintf("%s#%s", src, dst);
1092   xbt_assert(xbt_dynar_length(e_route->generic_route.link_list) > 0,
1093               "Invalid count of links, must be greater than zero (%s,%s)",
1094               src, dst);
1095   xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
1096               "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
1097               src, e_route->src_gateway, dst, e_route->dst_gateway);
1098
1099   route_extended_t new_e_route =
1100       generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
1101   xbt_dynar_free(&(e_route->generic_route.link_list));
1102   xbt_free(e_route);
1103
1104   xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
1105                (void (*)(void *)) generic_free_extended_route);
1106   xbt_free(route_name);
1107 }
1108
1109 /* ************************************************************************** */
1110 /* *********************** GENERIC BUSINESS METHODS ************************* */
1111
1112 double generic_get_link_latency(routing_component_t rc,
1113                                        const char *src, const char *dst,
1114                                        route_extended_t route)
1115 {
1116         int need_to_clean = route?0:1;
1117         void * link;
1118         unsigned int i;
1119         double latency = 0.0;
1120
1121         route = route?route:rc->get_route(rc,src,dst);
1122
1123         xbt_dynar_foreach(route->generic_route.link_list,i,link) {
1124                 latency += get_link_latency(link);
1125         }
1126         if(need_to_clean) generic_free_extended_route(route);
1127   return latency;
1128 }
1129
1130 xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
1131 {
1132   xbt_die("\"generic_get_onelink_routes\" not implemented yet");
1133 }
1134
1135 route_extended_t generic_get_bypassroute(routing_component_t rc,
1136                                                 const char *src,
1137                                                 const char *dst)
1138 {
1139   xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
1140   routing_component_t src_as, dst_as;
1141   int index_src, index_dst;
1142   xbt_dynar_t path_src = NULL;
1143   xbt_dynar_t path_dst = NULL;
1144   routing_component_t current = NULL;
1145   routing_component_t *current_src = NULL;
1146   routing_component_t *current_dst = NULL;
1147
1148   /* (1) find the as where the src and dst are located */
1149   void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1150   void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1151   if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1152   if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1153
1154   if(src_data == NULL || dst_data == NULL)
1155           xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1156                      src, dst, rc->name);
1157
1158   src_as = ((network_element_info_t)src_data)->rc_component;
1159   dst_as = ((network_element_info_t)dst_data)->rc_component;
1160
1161   /* (2) find the path to the root routing component */
1162   path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1163   current = src_as;
1164   while (current != NULL) {
1165     xbt_dynar_push(path_src, &current);
1166     current = current->routing_father;
1167   }
1168   path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1169   current = dst_as;
1170   while (current != NULL) {
1171     xbt_dynar_push(path_dst, &current);
1172     current = current->routing_father;
1173   }
1174
1175   /* (3) find the common father */
1176   index_src = path_src->used - 1;
1177   index_dst = path_dst->used - 1;
1178   current_src = xbt_dynar_get_ptr(path_src, index_src);
1179   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1180   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
1181     routing_component_t *tmp_src, *tmp_dst;
1182     tmp_src = xbt_dynar_pop_ptr(path_src);
1183     tmp_dst = xbt_dynar_pop_ptr(path_dst);
1184     index_src--;
1185     index_dst--;
1186     current_src = xbt_dynar_get_ptr(path_src, index_src);
1187     current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
1188   }
1189
1190   int max_index_src = path_src->used - 1;
1191   int max_index_dst = path_dst->used - 1;
1192
1193   int max_index = max(max_index_src, max_index_dst);
1194   int i, max;
1195
1196   route_extended_t e_route_bypass = NULL;
1197
1198   for (max = 0; max <= max_index; max++) {
1199     for (i = 0; i < max; i++) {
1200       if (i <= max_index_src && max <= max_index_dst) {
1201         char *route_name = bprintf("%s#%s",
1202                                    (*(routing_component_t *)
1203                                     (xbt_dynar_get_ptr
1204                                      (path_src, i)))->name,
1205                                    (*(routing_component_t *)
1206                                     (xbt_dynar_get_ptr
1207                                      (path_dst, max)))->name);
1208         e_route_bypass =
1209             xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1210         xbt_free(route_name);
1211       }
1212       if (e_route_bypass)
1213         break;
1214       if (max <= max_index_src && i <= max_index_dst) {
1215         char *route_name = bprintf("%s#%s",
1216                                    (*(routing_component_t *)
1217                                     (xbt_dynar_get_ptr
1218                                      (path_src, max)))->name,
1219                                    (*(routing_component_t *)
1220                                     (xbt_dynar_get_ptr
1221                                      (path_dst, i)))->name);
1222         e_route_bypass =
1223             xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1224         xbt_free(route_name);
1225       }
1226       if (e_route_bypass)
1227         break;
1228     }
1229
1230     if (e_route_bypass)
1231       break;
1232
1233     if (max <= max_index_src && max <= max_index_dst) {
1234       char *route_name = bprintf("%s#%s",
1235                                  (*(routing_component_t *)
1236                                   (xbt_dynar_get_ptr
1237                                    (path_src, max)))->name,
1238                                  (*(routing_component_t *)
1239                                   (xbt_dynar_get_ptr
1240                                    (path_dst, max)))->name);
1241       e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
1242       xbt_free(route_name);
1243     }
1244     if (e_route_bypass)
1245       break;
1246   }
1247
1248   xbt_dynar_free(&path_src);
1249   xbt_dynar_free(&path_dst);
1250
1251   route_extended_t new_e_route = NULL;
1252
1253   if (e_route_bypass) {
1254     void *link;
1255     unsigned int cpt = 0;
1256     new_e_route = xbt_new0(s_route_extended_t, 1);
1257     new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
1258     new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
1259     new_e_route->generic_route.link_list =
1260         xbt_dynar_new(global_routing->size_of_link, NULL);
1261     xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
1262       xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1263     }
1264   }
1265
1266   return new_e_route;
1267 }
1268
1269 /* ************************************************************************** */
1270 /* ************************* GENERIC AUX FUNCTIONS ************************** */
1271
1272 route_t
1273 generic_new_route(e_surf_routing_hierarchy_t hierarchy,
1274                            void *data, int order)
1275 {
1276
1277   char *link_name;
1278   route_t new_route;
1279   unsigned int cpt;
1280   xbt_dynar_t links = NULL, links_id = NULL;
1281
1282   new_route = xbt_new0(s_route_t, 1);
1283   new_route->link_list =
1284       xbt_dynar_new(global_routing->size_of_link, NULL);
1285
1286   xbt_assert(hierarchy == SURF_ROUTING_BASE,
1287               "the hierarchy type is not SURF_ROUTING_BASE");
1288
1289   links = ((route_t) data)->link_list;
1290
1291
1292   links_id = new_route->link_list;
1293
1294   xbt_dynar_foreach(links, cpt, link_name) {
1295
1296     void *link =
1297                 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1298     if (link) {
1299       if (order)
1300         xbt_dynar_push(links_id, &link);
1301       else
1302         xbt_dynar_unshift(links_id, &link);
1303     } else
1304       THROWF(mismatch_error, 0, "Link %s not found", link_name);
1305   }
1306
1307   return new_route;
1308 }
1309
1310 route_extended_t
1311 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
1312                            void *data, int order)
1313 {
1314
1315   char *link_name;
1316   route_extended_t e_route, new_e_route;
1317   route_t route;
1318   unsigned int cpt;
1319   xbt_dynar_t links = NULL, links_id = NULL;
1320
1321   new_e_route = xbt_new0(s_route_extended_t, 1);
1322   new_e_route->generic_route.link_list =
1323       xbt_dynar_new(global_routing->size_of_link, NULL);
1324   new_e_route->src_gateway = NULL;
1325   new_e_route->dst_gateway = NULL;
1326
1327   xbt_assert(hierarchy == SURF_ROUTING_BASE
1328               || hierarchy == SURF_ROUTING_RECURSIVE,
1329               "the hierarchy type is not defined");
1330
1331   if (hierarchy == SURF_ROUTING_BASE) {
1332
1333     route = (route_t) data;
1334     links = route->link_list;
1335
1336   } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
1337
1338     e_route = (route_extended_t) data;
1339     xbt_assert(e_route->src_gateway
1340                 && e_route->dst_gateway, "bad gateway, is null");
1341     links = e_route->generic_route.link_list;
1342
1343     /* remeber not erase the gateway names */
1344     new_e_route->src_gateway = strdup(e_route->src_gateway);
1345     new_e_route->dst_gateway = strdup(e_route->dst_gateway);
1346   }
1347
1348   links_id = new_e_route->generic_route.link_list;
1349
1350   xbt_dynar_foreach(links, cpt, link_name) {
1351
1352     void *link =
1353                 xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
1354     if (link) {
1355       if (order)
1356         xbt_dynar_push(links_id, &link);
1357       else
1358         xbt_dynar_unshift(links_id, &link);
1359     } else
1360       THROWF(mismatch_error, 0, "Link %s not found", link_name);
1361   }
1362
1363   return new_e_route;
1364 }
1365
1366 void generic_free_route(route_t route)
1367 {
1368   if (route) {
1369     xbt_dynar_free(&(route->link_list));
1370     xbt_free(route);
1371   }
1372 }
1373
1374 void generic_free_extended_route(route_extended_t e_route)
1375 {
1376   if (e_route) {
1377     xbt_dynar_free(&(e_route->generic_route.link_list));
1378     if (e_route->src_gateway)
1379       xbt_free(e_route->src_gateway);
1380     if (e_route->dst_gateway)
1381       xbt_free(e_route->dst_gateway);
1382     xbt_free(e_route);
1383   }
1384 }
1385
1386 static routing_component_t generic_as_exist(routing_component_t find_from,
1387                                             routing_component_t to_find)
1388 {
1389   //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1390   xbt_dict_cursor_t cursor = NULL;
1391   char *key;
1392   int found = 0;
1393   routing_component_t elem;
1394   xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
1395     if (to_find == elem || generic_as_exist(elem, to_find)) {
1396       found = 1;
1397       break;
1398     }
1399   }
1400   if (found)
1401     return to_find;
1402   return NULL;
1403 }
1404
1405 routing_component_t
1406 generic_autonomous_system_exist(routing_component_t rc, char *element)
1407 {
1408   //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
1409   routing_component_t element_as, result, elem;
1410   xbt_dict_cursor_t cursor = NULL;
1411   char *key;
1412   element_as = ((network_element_info_t)
1413                 xbt_lib_get_or_null(as_router_lib, element, ROUTING_ASR_LEVEL))->rc_component;
1414   result = ((routing_component_t) - 1);
1415   if (element_as != rc)
1416     result = generic_as_exist(rc, element_as);
1417
1418   int found = 0;
1419   if (result) {
1420     xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
1421       found = !strcmp(elem->name, element);
1422       if (found)
1423         break;
1424     }
1425     if (found)
1426       return element_as;
1427   }
1428   return NULL;
1429 }
1430
1431 routing_component_t
1432 generic_processing_units_exist(routing_component_t rc, char *element)
1433 {
1434   routing_component_t element_as;
1435   element_as = ((network_element_info_t)
1436                 xbt_lib_get_or_null(host_lib,
1437                  element, ROUTING_HOST_LEVEL))->rc_component;
1438   if (element_as == rc)
1439     return element_as;
1440   return generic_as_exist(rc, element_as);
1441 }
1442
1443 void generic_src_dst_check(routing_component_t rc, const char *src,
1444                                   const char *dst)
1445 {
1446
1447   void * src_data = xbt_lib_get_or_null(host_lib,src, ROUTING_HOST_LEVEL);
1448   void * dst_data = xbt_lib_get_or_null(host_lib,dst, ROUTING_HOST_LEVEL);
1449   if(!src_data) src_data = xbt_lib_get_or_null(as_router_lib,src, ROUTING_ASR_LEVEL);
1450   if(!dst_data) dst_data = xbt_lib_get_or_null(as_router_lib,dst, ROUTING_ASR_LEVEL);
1451
1452   if(src_data == NULL || dst_data == NULL)
1453           xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
1454                      src, dst, rc->name);
1455
1456   routing_component_t src_as = ((network_element_info_t)src_data)->rc_component;
1457   routing_component_t dst_as = ((network_element_info_t)dst_data)->rc_component;
1458
1459   if(src_as != dst_as)
1460           xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
1461               src, src_as->name, dst, dst_as->name);
1462   if(rc != dst_as)
1463          xbt_die("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
1464      src,dst,src_as->name, dst_as->name,rc->name);
1465 }
1466
1467 static void routing_parse_Sconfig(void)
1468 {
1469   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
1470 }
1471
1472 static void routing_parse_Econfig(void)
1473 {
1474   xbt_dict_cursor_t cursor = NULL;
1475   char *key;
1476   char *elem;
1477   char *cfg;
1478   xbt_dict_foreach(current_property_set, cursor, key, elem) {
1479           cfg = bprintf("%s:%s",key,elem);
1480           if(xbt_cfg_is_default_value(_surf_cfg_set, key))
1481                   xbt_cfg_set_parse(_surf_cfg_set, cfg);
1482           else
1483                   XBT_INFO("The custom configuration '%s' is already define by user!",key);
1484           free(cfg);
1485   }
1486   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
1487 }
1488
1489 void routing_parse_Scluster(void)
1490 {
1491   static int AX_ptr = 0;
1492
1493   char *cluster_id = A_surfxml_cluster_id;
1494   char *cluster_prefix = A_surfxml_cluster_prefix;
1495   char *cluster_suffix = A_surfxml_cluster_suffix;
1496   char *cluster_radical = A_surfxml_cluster_radical;
1497   char *cluster_power = A_surfxml_cluster_power;
1498   char *cluster_core = A_surfxml_cluster_core;
1499   char *cluster_bw = A_surfxml_cluster_bw;
1500   char *cluster_lat = A_surfxml_cluster_lat;
1501   char *temp_cluster_bw = NULL;
1502   char *temp_cluster_lat = NULL;
1503   char *temp_cluster_power = NULL;
1504   char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1505   char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1506   char *cluster_availability_file = A_surfxml_cluster_availability_file;
1507   char *cluster_state_file = A_surfxml_cluster_state_file;
1508   char *host_id, *groups, *link_id = NULL;
1509   char *router_id, *link_backbone;
1510   char *availability_file = xbt_strdup(cluster_availability_file);
1511   char *state_file = xbt_strdup(cluster_state_file);
1512
1513   if(xbt_dict_size(patterns)==0)
1514           patterns = xbt_dict_new();
1515
1516   xbt_dict_set(patterns,"id",cluster_id,NULL);
1517   xbt_dict_set(patterns,"prefix",cluster_prefix,NULL);
1518   xbt_dict_set(patterns,"suffix",cluster_suffix,NULL);
1519
1520 #ifdef HAVE_PCRE_LIB
1521   char *route_src_dst;
1522 #endif
1523   unsigned int iter;
1524   int start, end, i;
1525   xbt_dynar_t radical_elements;
1526   xbt_dynar_t radical_ends;
1527   int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
1528   int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
1529
1530 #ifndef HAVE_PCRE_LIB
1531   xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
1532   char *route_src, *route_dst;
1533   int j;
1534 #endif
1535
1536   static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1537   static unsigned int surfxml_buffer_stack_stack[1024];
1538
1539   surfxml_buffer_stack_stack[0] = 0;
1540
1541   surfxml_bufferstack_push(1);
1542
1543   SURFXML_BUFFER_SET(AS_id, cluster_id);
1544 #ifdef HAVE_PCRE_LIB
1545   SURFXML_BUFFER_SET(AS_routing, "RuleBased");
1546   XBT_DEBUG("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
1547 #else
1548   SURFXML_BUFFER_SET(AS_routing, "Full");
1549   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
1550 #endif
1551   SURFXML_START_TAG(AS);
1552
1553   radical_elements = xbt_str_split(cluster_radical, ",");
1554   xbt_dynar_foreach(radical_elements, iter, groups) {
1555     radical_ends = xbt_str_split(groups, "-");
1556     switch (xbt_dynar_length(radical_ends)) {
1557     case 1:
1558       surf_parse_get_int(&start,
1559                          xbt_dynar_get_as(radical_ends, 0, char *));
1560       host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
1561 #ifndef HAVE_PCRE_LIB
1562       xbt_dynar_push_as(tab_elements_num, int, start);
1563 #endif
1564       link_id = bprintf("%s_link_%d", cluster_id, start);
1565
1566       xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free);
1567       temp_cluster_power = xbt_strdup(cluster_power);
1568       temp_cluster_power = replace_random_parameter(temp_cluster_power);
1569       XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1570       A_surfxml_host_state = A_surfxml_host_state_ON;
1571       SURFXML_BUFFER_SET(host_id, host_id);
1572       SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1573       SURFXML_BUFFER_SET(host_core, cluster_core);
1574       SURFXML_BUFFER_SET(host_availability, "1.0");
1575       SURFXML_BUFFER_SET(host_coordinates, "");
1576       xbt_free(availability_file);
1577       availability_file = xbt_strdup(cluster_availability_file);
1578       xbt_free(state_file);
1579       state_file = xbt_strdup(cluster_state_file);
1580       XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1581       XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1582       SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1583       SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1584       XBT_DEBUG("</host>");
1585       SURFXML_START_TAG(host);
1586       SURFXML_END_TAG(host);
1587
1588
1589       temp_cluster_bw = xbt_strdup(cluster_bw);
1590       temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1591       temp_cluster_lat = xbt_strdup(cluster_lat);
1592       temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1593       XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1594       A_surfxml_link_state = A_surfxml_link_state_ON;
1595       A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1596       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1597           {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
1598       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1599           {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
1600       SURFXML_BUFFER_SET(link_id, link_id);
1601       SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1602       SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1603       SURFXML_BUFFER_SET(link_bandwidth_file, "");
1604       SURFXML_BUFFER_SET(link_latency_file, "");
1605       SURFXML_BUFFER_SET(link_state_file, "");
1606       SURFXML_START_TAG(link);
1607       SURFXML_END_TAG(link);
1608
1609       xbt_free(temp_cluster_bw);
1610       xbt_free(temp_cluster_lat);
1611       xbt_free(temp_cluster_power);
1612       free(link_id);
1613       free(host_id);
1614       break;
1615
1616     case 2:
1617
1618       surf_parse_get_int(&start,
1619                          xbt_dynar_get_as(radical_ends, 0, char *));
1620       surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
1621       for (i = start; i <= end; i++) {
1622         host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
1623 #ifndef HAVE_PCRE_LIB
1624         xbt_dynar_push_as(tab_elements_num, int, i);
1625 #endif
1626         link_id = bprintf("%s_link_%d", cluster_id, i);
1627
1628         xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
1629         temp_cluster_power = xbt_strdup(cluster_power);
1630         temp_cluster_power = replace_random_parameter(temp_cluster_power);
1631         XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\">", host_id, temp_cluster_power);
1632         A_surfxml_host_state = A_surfxml_host_state_ON;
1633         SURFXML_BUFFER_SET(host_id, host_id);
1634         SURFXML_BUFFER_SET(host_power, temp_cluster_power);
1635         SURFXML_BUFFER_SET(host_core, cluster_core);
1636         SURFXML_BUFFER_SET(host_availability, "1.0");
1637         SURFXML_BUFFER_SET(host_coordinates, "");
1638         xbt_free(availability_file);
1639         availability_file = xbt_strdup(cluster_availability_file);
1640         xbt_free(state_file);
1641         state_file = xbt_strdup(cluster_state_file);
1642         XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns));
1643         XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns));
1644         SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns));
1645         SURFXML_BUFFER_SET(host_state_file, xbt_str_varsubst(state_file,patterns));
1646         XBT_DEBUG("</host>");
1647         SURFXML_START_TAG(host);
1648         SURFXML_END_TAG(host);
1649
1650         xbt_free(temp_cluster_power);
1651
1652         temp_cluster_bw = xbt_strdup(cluster_bw);
1653         temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1654         temp_cluster_lat = xbt_strdup(cluster_lat);
1655         temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1656         XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,temp_cluster_bw, cluster_lat);
1657         A_surfxml_link_state = A_surfxml_link_state_ON;
1658         A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1659         if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1660             {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
1661         if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1662             {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
1663         SURFXML_BUFFER_SET(link_id, link_id);
1664         SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1665         SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1666         SURFXML_BUFFER_SET(link_bandwidth_file, "");
1667         SURFXML_BUFFER_SET(link_latency_file, "");
1668         SURFXML_BUFFER_SET(link_state_file, "");
1669         SURFXML_START_TAG(link);
1670         SURFXML_END_TAG(link);
1671
1672         xbt_free(temp_cluster_bw);
1673         xbt_free(temp_cluster_lat);
1674         free(link_id);
1675         free(host_id);
1676       }
1677       break;
1678
1679     default:
1680       XBT_DEBUG("Malformed radical");
1681     }
1682
1683     xbt_dynar_free(&radical_ends);
1684   }
1685   xbt_dynar_free(&radical_elements);
1686
1687   XBT_DEBUG(" ");
1688   router_id =
1689       bprintf("%s%s_router%s", cluster_prefix, cluster_id,
1690               cluster_suffix);
1691   //link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
1692   link_backbone = bprintf("%s_backbone", cluster_id);
1693
1694   XBT_DEBUG("<router id=\"%s\"/>", router_id);
1695   SURFXML_BUFFER_SET(router_id, router_id);
1696   SURFXML_BUFFER_SET(router_coordinates, "");
1697   SURFXML_START_TAG(router);
1698   SURFXML_END_TAG(router);
1699
1700   //TODO
1701 //  xbt_dict_set(patterns, "radical", xbt_strdup("_router"), xbt_free);
1702 //  temp_cluster_bw = xbt_strdup(cluster_bw);
1703 //  temp_cluster_bw = replace_random_parameter(temp_cluster_bw);
1704 //  temp_cluster_lat = xbt_strdup(cluster_lat);
1705 //  temp_cluster_lat = replace_random_parameter(temp_cluster_lat);
1706 //  XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
1707 //  A_surfxml_link_state = A_surfxml_link_state_ON;
1708 //  A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1709 //  if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1710 //  {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
1711 //  if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
1712 //  {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
1713 //  SURFXML_BUFFER_SET(link_id, link_router);
1714 //  SURFXML_BUFFER_SET(link_bandwidth, temp_cluster_bw);
1715 //  SURFXML_BUFFER_SET(link_latency, temp_cluster_lat);
1716 //  SURFXML_BUFFER_SET(link_bandwidth_file, "");
1717 //  SURFXML_BUFFER_SET(link_latency_file, "");
1718 //  SURFXML_BUFFER_SET(link_state_file, "");
1719 //  SURFXML_START_TAG(link);
1720 //  SURFXML_END_TAG(link);
1721
1722 //  xbt_free(temp_cluster_bw);
1723 //  xbt_free(temp_cluster_lat);
1724
1725   XBT_DEBUG("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bb_bw, cluster_bb_lat);
1726   A_surfxml_link_state = A_surfxml_link_state_ON;
1727   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1728   if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
1729   {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
1730   SURFXML_BUFFER_SET(link_id, link_backbone);
1731   SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
1732   SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
1733   SURFXML_BUFFER_SET(link_bandwidth_file, "");
1734   SURFXML_BUFFER_SET(link_latency_file, "");
1735   SURFXML_BUFFER_SET(link_state_file, "");
1736   SURFXML_START_TAG(link);
1737   SURFXML_END_TAG(link);
1738
1739   XBT_DEBUG(" ");
1740
1741 #ifdef HAVE_PCRE_LIB
1742   char *new_suffix = xbt_strdup("");
1743
1744   radical_elements = xbt_str_split(cluster_suffix, ".");
1745   xbt_dynar_foreach(radical_elements, iter, groups) {
1746     if (strcmp(groups, "")) {
1747       char *old_suffix = new_suffix;
1748       new_suffix = bprintf("%s\\.%s", old_suffix, groups);
1749       free(old_suffix);
1750     }
1751   }
1752   route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
1753   xbt_dynar_free(&radical_elements);
1754   free(new_suffix);
1755
1756   char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
1757   char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
1758   char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
1759
1760   //from router to router
1761   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, router_id);
1762   XBT_DEBUG("symmetrical=\"NO\">");
1763   SURFXML_BUFFER_SET(route_src, router_id);
1764   SURFXML_BUFFER_SET(route_dst, router_id);
1765   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1766   SURFXML_START_TAG(route);
1767
1768   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1769   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1770   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1771   SURFXML_START_TAG(link_ctn);
1772   SURFXML_END_TAG(link_ctn);
1773
1774   XBT_DEBUG("</route>");
1775   SURFXML_END_TAG(route);
1776
1777   //from host to router
1778   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, router_id);
1779   XBT_DEBUG("symmetrical=\"NO\">");
1780   SURFXML_BUFFER_SET(route_src, route_src_dst);
1781   SURFXML_BUFFER_SET(route_dst, router_id);
1782   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1783   SURFXML_START_TAG(route);
1784
1785   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1786   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1787   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1788   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1789   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1790   SURFXML_START_TAG(link_ctn);
1791   SURFXML_END_TAG(link_ctn);
1792
1793   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1794   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1795   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1796   SURFXML_START_TAG(link_ctn);
1797   SURFXML_END_TAG(link_ctn);
1798
1799   XBT_DEBUG("</route>");
1800   SURFXML_END_TAG(route);
1801
1802   //from router to host
1803   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, route_src_dst);
1804   XBT_DEBUG("symmetrical=\"NO\">");
1805   SURFXML_BUFFER_SET(route_src, router_id);
1806   SURFXML_BUFFER_SET(route_dst, route_src_dst);
1807   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1808   SURFXML_START_TAG(route);
1809
1810   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1811   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1812   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1813   SURFXML_START_TAG(link_ctn);
1814   SURFXML_END_TAG(link_ctn);
1815
1816   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1817   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1818   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1819   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1820   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1821   SURFXML_START_TAG(link_ctn);
1822   SURFXML_END_TAG(link_ctn);
1823
1824   XBT_DEBUG("</route>");
1825   SURFXML_END_TAG(route);
1826
1827   //from host to host
1828   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
1829   XBT_DEBUG("symmetrical=\"NO\">");
1830   SURFXML_BUFFER_SET(route_src, route_src_dst);
1831   SURFXML_BUFFER_SET(route_dst, route_src_dst);
1832   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1833   SURFXML_START_TAG(route);
1834
1835   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_src);
1836   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
1837   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1838   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1839   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1840   SURFXML_START_TAG(link_ctn);
1841   SURFXML_END_TAG(link_ctn);
1842
1843   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
1844   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
1845   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1846   SURFXML_START_TAG(link_ctn);
1847   SURFXML_END_TAG(link_ctn);
1848
1849   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
1850   SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
1851   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1852   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1853   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1854   SURFXML_START_TAG(link_ctn);
1855   SURFXML_END_TAG(link_ctn);
1856
1857   XBT_DEBUG("</route>");
1858   SURFXML_END_TAG(route);
1859
1860   free(pcre_link_dst);
1861   free(pcre_link_backbone);
1862   free(pcre_link_src);
1863   free(route_src_dst);
1864 #else
1865   for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
1866     for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
1867       if (i == xbt_dynar_length(tab_elements_num)) {
1868         route_src = router_id;
1869       } else {
1870         route_src =
1871             bprintf("%s%d%s", cluster_prefix,
1872                     xbt_dynar_get_as(tab_elements_num, i, int),
1873                     cluster_suffix);
1874       }
1875
1876       if (j == xbt_dynar_length(tab_elements_num)) {
1877         route_dst = router_id;
1878       } else {
1879         route_dst =
1880             bprintf("%s%d%s", cluster_prefix,
1881                     xbt_dynar_get_as(tab_elements_num, j, int),
1882                     cluster_suffix);
1883       }
1884
1885       XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
1886       XBT_DEBUG("symmetrical=\"NO\">");
1887       SURFXML_BUFFER_SET(route_src, route_src);
1888       SURFXML_BUFFER_SET(route_dst, route_dst);
1889       A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
1890       SURFXML_START_TAG(route);
1891
1892       if (i != xbt_dynar_length(tab_elements_num)){
1893           route_src =
1894                 bprintf("%s_link_%d", cluster_id,
1895                         xbt_dynar_get_as(tab_elements_num, i, int));
1896                   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_src);
1897                   SURFXML_BUFFER_SET(link_ctn_id, route_src);
1898                   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1899                   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1900                   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
1901                   SURFXML_START_TAG(link_ctn);
1902                   SURFXML_END_TAG(link_ctn);
1903                   free(route_src);
1904       }
1905
1906       XBT_DEBUG("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
1907       SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
1908       A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1909       SURFXML_START_TAG(link_ctn);
1910       SURFXML_END_TAG(link_ctn);
1911
1912       if (j != xbt_dynar_length(tab_elements_num)) {
1913           route_dst =
1914                 bprintf("%s_link_%d", cluster_id,
1915                         xbt_dynar_get_as(tab_elements_num, j, int));
1916                   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", route_dst);
1917                   SURFXML_BUFFER_SET(link_ctn_id, route_dst);
1918                   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1919                   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
1920                   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
1921                   SURFXML_START_TAG(link_ctn);
1922                   SURFXML_END_TAG(link_ctn);
1923                   free(route_dst);
1924       }
1925
1926       XBT_DEBUG("</route>");
1927       SURFXML_END_TAG(route);
1928     }
1929   }
1930   xbt_dynar_free(&tab_elements_num);
1931
1932 #endif
1933
1934   free(router_id);
1935   free(link_backbone);
1936   //free(link_router);
1937   xbt_dict_free(&patterns);
1938   free(availability_file);
1939   free(state_file);
1940
1941   XBT_DEBUG("</AS>");
1942   SURFXML_END_TAG(AS);
1943   XBT_DEBUG(" ");
1944
1945   surfxml_bufferstack_pop(1);
1946 }
1947 /*
1948  * This function take a string and replace parameters from patterns dict.
1949  * It returns the new value.
1950  */
1951 static char* replace_random_parameter(char * string)
1952 {
1953   char *test_string = NULL;
1954
1955   if(xbt_dict_size(random_value)==0)
1956     return string;
1957
1958   string = xbt_str_varsubst(string, patterns); // for patterns of cluster
1959   test_string = bprintf("${%s}", string);
1960   test_string = xbt_str_varsubst(test_string,random_value); //Add ${xxxxx} for random Generator
1961
1962   if (strcmp(test_string,"")) { //if not empty, keep this value.
1963     xbt_free(string);
1964     string = test_string;
1965   } //In other case take old value (without ${})
1966   else
1967         free(test_string);
1968   return string;
1969 }
1970
1971 static void clean_dict_random(void)
1972 {
1973         xbt_dict_free(&random_value);
1974         xbt_dict_free(&patterns);
1975 }
1976
1977 static void routing_parse_Speer(void)
1978 {
1979   static int AX_ptr = 0;
1980
1981   char *peer_id = A_surfxml_peer_id;
1982   char *peer_power = A_surfxml_peer_power;
1983   char *peer_bw_in = A_surfxml_peer_bw_in;
1984   char *peer_bw_out = A_surfxml_peer_bw_out;
1985   char *peer_lat = A_surfxml_peer_lat;
1986   char *peer_coord = A_surfxml_peer_coordinates;
1987   char *peer_state_file = A_surfxml_peer_state_file;
1988   char *peer_availability_file = A_surfxml_peer_availability_file;
1989
1990   char *host_id = NULL;
1991   char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
1992
1993   static unsigned int surfxml_buffer_stack_stack_ptr = 1;
1994   static unsigned int surfxml_buffer_stack_stack[1024];
1995
1996   surfxml_buffer_stack_stack[0] = 0;
1997
1998   surfxml_bufferstack_push(1);
1999
2000   SURFXML_BUFFER_SET(AS_id, peer_id);
2001
2002   SURFXML_BUFFER_SET(AS_routing, "Full");
2003   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer_id);
2004
2005   SURFXML_START_TAG(AS);
2006
2007   XBT_DEBUG(" ");
2008   host_id = bprintf("peer_%s", peer_id);
2009   router_id = bprintf("router_%s", peer_id);
2010   link_id_up = bprintf("link_%s_up", peer_id);
2011   link_id_down = bprintf("link_%s_down", peer_id);
2012
2013   link_router = bprintf("%s_link_router", peer_id);
2014   link_backbone = bprintf("%s_backbone", peer_id);
2015
2016   XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, peer_power);
2017   A_surfxml_host_state = A_surfxml_host_state_ON;
2018   SURFXML_BUFFER_SET(host_id, host_id);
2019   SURFXML_BUFFER_SET(host_power, peer_power);
2020   SURFXML_BUFFER_SET(host_availability, "1.0");
2021   SURFXML_BUFFER_SET(host_availability_file, peer_availability_file);
2022   SURFXML_BUFFER_SET(host_state_file, peer_state_file);
2023   SURFXML_BUFFER_SET(host_coordinates, "");
2024   SURFXML_START_TAG(host);
2025   SURFXML_END_TAG(host);
2026
2027   XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer_coord);
2028   SURFXML_BUFFER_SET(router_id, router_id);
2029   SURFXML_BUFFER_SET(router_coordinates, peer_coord);
2030   SURFXML_START_TAG(router);
2031   SURFXML_END_TAG(router);
2032
2033   XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_up, peer_bw_in, peer_lat);
2034   A_surfxml_link_state = A_surfxml_link_state_ON;
2035   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2036   SURFXML_BUFFER_SET(link_id, link_id_up);
2037   SURFXML_BUFFER_SET(link_bandwidth, peer_bw_in);
2038   SURFXML_BUFFER_SET(link_latency, peer_lat);
2039   SURFXML_BUFFER_SET(link_bandwidth_file, "");
2040   SURFXML_BUFFER_SET(link_latency_file, "");
2041   SURFXML_BUFFER_SET(link_state_file, "");
2042   SURFXML_START_TAG(link);
2043   SURFXML_END_TAG(link);
2044
2045   XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id_down, peer_bw_out, peer_lat);
2046   A_surfxml_link_state = A_surfxml_link_state_ON;
2047   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2048   SURFXML_BUFFER_SET(link_id, link_id_down);
2049   SURFXML_BUFFER_SET(link_bandwidth, peer_bw_out);
2050   SURFXML_BUFFER_SET(link_latency, peer_lat);
2051   SURFXML_BUFFER_SET(link_bandwidth_file, "");
2052   SURFXML_BUFFER_SET(link_latency_file, "");
2053   SURFXML_BUFFER_SET(link_state_file, "");
2054   SURFXML_START_TAG(link);
2055   SURFXML_END_TAG(link);
2056
2057   XBT_DEBUG(" ");
2058
2059   // begin here
2060   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
2061   XBT_DEBUG("symmetrical=\"NO\">");
2062   SURFXML_BUFFER_SET(route_src, host_id);
2063   SURFXML_BUFFER_SET(route_dst, router_id);
2064   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2065   SURFXML_START_TAG(route);
2066
2067   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
2068   SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
2069   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2070   SURFXML_START_TAG(link_ctn);
2071   SURFXML_END_TAG(link_ctn);
2072
2073   XBT_DEBUG("</route>");
2074   SURFXML_END_TAG(route);
2075
2076   //Opposite Route
2077   XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
2078   XBT_DEBUG("symmetrical=\"NO\">");
2079   SURFXML_BUFFER_SET(route_src, router_id);
2080   SURFXML_BUFFER_SET(route_dst, host_id);
2081   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
2082   SURFXML_START_TAG(route);
2083
2084   XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
2085   SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
2086   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
2087   SURFXML_START_TAG(link_ctn);
2088   SURFXML_END_TAG(link_ctn);
2089
2090   XBT_DEBUG("</route>");
2091   SURFXML_END_TAG(route);
2092
2093   XBT_DEBUG("</AS>");
2094   SURFXML_END_TAG(AS);
2095   XBT_DEBUG(" ");
2096
2097   //xbt_dynar_free(&tab_elements_num);
2098         free(host_id);
2099         free(router_id);
2100         free(link_router);
2101         free(link_backbone);
2102         free(link_id_up);
2103         free(link_id_down);
2104   surfxml_bufferstack_pop(1);
2105 }
2106
2107 static void routing_parse_Srandom(void)
2108 {
2109           double mean, std, min, max, seed;
2110           char *random_id = A_surfxml_random_id;
2111           char *random_radical = A_surfxml_random_radical;
2112           char *rd_name = NULL;
2113           char *rd_value;
2114           surf_parse_get_double(&mean,A_surfxml_random_mean);
2115           surf_parse_get_double(&std,A_surfxml_random_std_deviation);
2116           surf_parse_get_double(&min,A_surfxml_random_min);
2117           surf_parse_get_double(&max,A_surfxml_random_max);
2118           surf_parse_get_double(&seed,A_surfxml_random_seed);
2119
2120           double res = 0;
2121           int i = 0;
2122           random_data_t random = xbt_new0(s_random_data_t, 1);
2123           char *tmpbuf;
2124
2125           xbt_dynar_t radical_elements;
2126           unsigned int iter;
2127           char *groups;
2128           int start, end;
2129           xbt_dynar_t radical_ends;
2130
2131           random->generator = A_surfxml_random_generator;
2132           random->seed = seed;
2133           random->min = min;
2134           random->max = max;
2135
2136           /* Check user stupidities */
2137           if (max < min)
2138             THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
2139           if (mean < min)
2140             THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
2141                    min);
2142           if (mean > max)
2143             THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
2144                    max);
2145
2146           /* normalize the mean and standard deviation before storing */
2147           random->mean = (mean - min) / (max - min);
2148           random->std = std / (max - min);
2149
2150           if (random->mean * (1 - random->mean) < random->std * random->std)
2151             THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
2152                    random->mean, random->std);
2153
2154           XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
2155           random_id,
2156           random->min,
2157           random->max,
2158           random->mean,
2159           random->std,
2160           random->generator,
2161           random->seed,
2162           random_radical);
2163
2164           if(xbt_dict_size(random_value)==0)
2165                   random_value = xbt_dict_new();
2166
2167           if(!strcmp(random_radical,""))
2168           {
2169                   res = random_generate(random);
2170                   rd_value = bprintf("%f",res);
2171                   xbt_dict_set(random_value, random_id, rd_value, free);
2172           }
2173           else
2174           {
2175                   radical_elements = xbt_str_split(random_radical, ",");
2176                   xbt_dynar_foreach(radical_elements, iter, groups) {
2177                         radical_ends = xbt_str_split(groups, "-");
2178                         switch (xbt_dynar_length(radical_ends)) {
2179                         case 1:
2180                                           xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
2181                                           res = random_generate(random);
2182                                           tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
2183                                           xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2184                                           xbt_free(tmpbuf);
2185                                           break;
2186
2187                         case 2:   surf_parse_get_int(&start,
2188                                                                                  xbt_dynar_get_as(radical_ends, 0, char *));
2189                                           surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2190                                           for (i = start; i <= end; i++) {
2191                                                   xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
2192                                                   res = random_generate(random);
2193                           tmpbuf = bprintf("%s%d",random_id,i);
2194                                                   xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
2195                           xbt_free(tmpbuf);
2196                                           }
2197                                           break;
2198                         default:
2199                                 XBT_INFO("Malformed radical");
2200                         }
2201                         res = random_generate(random);
2202                         rd_name  = bprintf("%s_router",random_id);
2203                         rd_value = bprintf("%f",res);
2204                         xbt_dict_set(random_value, rd_name, rd_value, free);
2205
2206                         xbt_dynar_free(&radical_ends);
2207                   }
2208                   free(rd_name);
2209                   xbt_dynar_free(&radical_elements);
2210           }
2211 }
2212
2213 static void routing_parse_Erandom(void)
2214 {
2215         xbt_dict_cursor_t cursor = NULL;
2216         char *key;
2217         char *elem;
2218
2219         xbt_dict_foreach(random_value, cursor, key, elem) {
2220           XBT_DEBUG("%s = %s",key,elem);
2221         }
2222
2223 }
2224
2225
2226 /*
2227  * New methods to init the routing model component from the lua script
2228  */
2229
2230 /*
2231  * calling parse_S_AS_lua with lua values
2232  */
2233 void routing_AS_init(const char *AS_id, const char *AS_routing)
2234 {
2235   parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
2236 }
2237
2238 /*
2239  * calling parse_E_AS_lua to fisnish the creation of routing component
2240  */
2241 void routing_AS_end(const char *AS_id)
2242 {
2243   parse_E_AS_lua((char *) AS_id);
2244 }
2245
2246 /*
2247  * add a host to the network element list
2248  */
2249
2250 void routing_add_host(const char *host_id)
2251 {
2252   parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
2253 }
2254
2255 /*
2256  * Set a new link on the actual list of link for a route or ASroute
2257  */
2258 void routing_add_link(const char *link_id)
2259 {
2260   parse_E_link_c_ctn_new_elem_lua((char *) link_id);
2261 }
2262
2263 /*
2264  *Set the endpoints for a route
2265  */
2266 void routing_set_route(const char *src_id, const char *dst_id)
2267 {
2268   parse_S_route_new_and_endpoints_lua(src_id, dst_id);
2269 }
2270
2271 /*
2272  * Store the route by calling parse_E_route_store_route
2273  */
2274 void routing_store_route(void)
2275 {
2276   parse_E_route_store_route();
2277 }