Logo AND Algorithmique Numérique Distribuée

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