Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make new function model_floyd_set_route for route and ASroute.
[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
8
9 #include <float.h>
10 #include "gras_config.h"
11
12 #ifdef HAVE_PCRE_LIB
13 #include <pcre.h>               /* regular expresion library */
14 #endif
15 #include "surf_private.h"
16 #include "xbt/dynar.h"
17 #include "xbt/str.h"
18 #include "xbt/config.h"
19 #include "xbt/graph.h"
20 #include "xbt/set.h"
21
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
23
24 /* Global vars */
25 routing_global_t global_routing = NULL;
26 routing_component_t current_routing = NULL;
27 model_type_t current_routing_model = NULL;
28
29 /* Prototypes of each model */
30 static void *model_full_create(void);   /* create structures for full routing model */
31 static void model_full_load(void);      /* load parse functions for full routing model */
32 static void model_full_unload(void);    /* unload parse functions for full routing model */
33 static void model_full_end(void);       /* finalize the creation of full routing model */
34 static void model_full_set_route(               /* Set the route and ASroute between src and dst */
35                 routing_component_t rc, const char *src, const char *dst, name_route_extended_t route);
36
37 static void *model_floyd_create(void);  /* create structures for floyd routing model */
38 static void model_floyd_load(void);     /* load parse functions for floyd routing model */
39 static void model_floyd_unload(void);   /* unload parse functions for floyd routing model */
40 static void model_floyd_end(void);      /* finalize the creation of floyd routing model */
41 static void model_floyd_set_route(routing_component_t rc, const char *src,
42         const char *dst, name_route_extended_t route);
43
44 static void *model_dijkstra_both_create(int cached);    /* create by calling dijkstra or dijkstracache */
45 static void *model_dijkstra_create(void);       /* create structures for dijkstra routing model */
46 static void *model_dijkstracache_create(void);  /* create structures for dijkstracache routing model */
47 static void model_dijkstra_both_load(void);     /* load parse functions for dijkstra routing model */
48 static void model_dijkstra_both_unload(void);   /* unload parse functions for dijkstra routing model */
49 static void model_dijkstra_both_end(void);      /* finalize the creation of dijkstra routing model */
50 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
51                      const char *dst, name_route_extended_t route);
52
53 static void *model_rulebased_create(void);      /* create structures for rulebased routing model */
54 static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
55 static void model_rulebased_unload(void);       /* unload parse functions for rulebased routing model */
56 static void model_rulebased_end(void);  /* finalize the creation of rulebased routing model */
57
58 static void *model_none_create(void);   /* none routing model */
59 static void model_none_load(void);      /* none routing model */
60 static void model_none_unload(void);    /* none routing model */
61 static void model_none_end(void);       /* none routing model */
62
63 static void routing_parse_Scluster(void);  /*cluster bypass */
64
65 static void routing_parse_Sconfig(void);        /*config Tag */
66 static void routing_parse_Econfig(void);        /*config Tag */
67
68 /* this lines are only for replace use like index in the model table */
69 typedef enum {
70   SURF_MODEL_FULL = 0,
71   SURF_MODEL_FLOYD,
72   SURF_MODEL_DIJKSTRA,
73   SURF_MODEL_DIJKSTRACACHE,
74   SURF_MODEL_NONE,
75 #ifdef HAVE_PCRE_LIB
76   SURF_MODEL_RULEBASED
77 #endif
78 } e_routing_types;
79
80
81 /* must be finish with null and carefull if change de order */
82 struct s_model_type routing_models[] = { {"Full",
83                                           "Full routing data (fast, large memory requirements, fully expressive)",
84                                           model_full_create,
85                                           model_full_load,
86                                           model_full_unload,
87                                           model_full_end},
88 {"Floyd",
89  "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
90  model_floyd_create, model_floyd_load, model_floyd_unload,
91  model_floyd_end},
92 {"Dijkstra",
93  "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
94  model_dijkstra_create, model_dijkstra_both_load,
95  model_dijkstra_both_unload, model_dijkstra_both_end},
96 {"DijkstraCache",
97  "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
98  model_dijkstracache_create, model_dijkstra_both_load,
99  model_dijkstra_both_unload, model_dijkstra_both_end},
100 {"none", "No routing (usable with Constant network only)",
101  model_none_create, model_none_load, model_none_unload, model_none_end},
102 #ifdef HAVE_PCRE_LIB
103 {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create,
104  model_rulebased_load, model_rulebased_unload, model_rulebased_end},
105 #endif
106 {NULL, NULL, NULL, NULL, NULL, NULL}
107 };
108
109 /* ************************************************************************** */
110 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
111
112 static void generic_set_processing_unit(routing_component_t rc,
113                                         const char *name);
114 static void generic_set_autonomous_system(routing_component_t rc,
115                                           const char *name);
116 static void generic_set_route(routing_component_t rc, const char *src,
117                               const char *dst, name_route_t route);
118 static void generic_set_ASroute(routing_component_t rc, const char *src,
119                                 const char *dst, route_extended_t e_route);
120 static void generic_set_bypassroute(routing_component_t rc,
121                                     const char *src, const char *dst,
122                                     route_extended_t e_route);
123
124 static int surf_link_resource_cmp(const void *a, const void *b);
125 static int surf_pointer_resource_cmp(const void *a, const void *b);
126
127 /* ************************************************************************** */
128 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
129
130 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc);
131 static route_extended_t generic_get_bypassroute(routing_component_t rc,
132                                                 const char *src,
133                                                 const char *dst);
134
135 /* ************************************************************************** */
136 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
137
138 static route_extended_t
139 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
140                            void *data, int order);
141 static void generic_free_route(route_t route);
142 static void generic_free_extended_route(route_extended_t e_route);
143 static routing_component_t
144 generic_autonomous_system_exist(routing_component_t rc, char *element);
145 static routing_component_t
146 generic_processing_units_exist(routing_component_t rc, char *element);
147 static void generic_src_dst_check(routing_component_t rc, const char *src,
148                                   const char *dst);
149
150 /* ************************************************************************** */
151 /* **************************** GLOBAL FUNCTIONS **************************** */
152
153 /* global parse functions */
154 static char *src = NULL;        /* temporary store the source name of a route */
155 static char *dst = NULL;        /* temporary store the destination name of a route */
156 static char *gw_src = NULL;     /* temporary store the gateway source name of a route */
157 static char *gw_dst = NULL;     /* temporary store the gateway destination name of a route */
158 static xbt_dynar_t link_list = NULL;    /* temporary store of current list link of a route */
159 /**
160  * \brief Add a "host" to the network element list
161  */
162 static void parse_S_host(char *host_id)
163 {
164   network_element_info_t info = NULL;
165   if (current_routing->hierarchy == SURF_ROUTING_NULL)
166     current_routing->hierarchy = SURF_ROUTING_BASE;
167   xbt_assert1(!xbt_dict_get_or_null
168               (global_routing->where_network_elements, host_id),
169               "Reading a host, processing unit \"%s\" already exist",
170               host_id);
171   xbt_assert1(current_routing->set_processing_unit,
172               "no defined method \"set_processing_unit\" in \"%s\"",
173               current_routing->name);
174   (*(current_routing->set_processing_unit)) (current_routing, host_id);
175   info = xbt_new0(s_network_element_info_t, 1);
176   info->rc_component = current_routing;
177   info->rc_type = SURF_NETWORK_ELEMENT_HOST;
178   xbt_dict_set(global_routing->where_network_elements, host_id,
179                (void *) info, NULL);
180 }
181
182 /*
183  * \brief Add a host to the network element list from XML
184  */
185 static void parse_S_host_XML(void)
186 {
187   parse_S_host(A_surfxml_host_id);
188 }
189
190 /*
191  * \brief Add a host to the network element list from lua script
192  */
193 static void parse_S_host_lua(char *host_id)
194 {
195   parse_S_host(host_id);
196 }
197
198
199 /**
200  * \brief Add a "router" to the network element list
201  */
202 static void parse_S_router(void)
203 {
204   network_element_info_t info = NULL;
205
206   if (current_routing->hierarchy == SURF_ROUTING_NULL)
207     current_routing->hierarchy = SURF_ROUTING_BASE;
208   xbt_assert1(!xbt_dict_get_or_null
209               (global_routing->where_network_elements,
210                A_surfxml_router_id),
211               "Reading a router, processing unit \"%s\" already exist",
212               A_surfxml_router_id);
213   xbt_assert1(current_routing->set_processing_unit,
214               "no defined method \"set_processing_unit\" in \"%s\"",
215               current_routing->name);
216   (*(current_routing->set_processing_unit)) (current_routing,
217                                              A_surfxml_router_id);
218   info = xbt_new0(s_network_element_info_t, 1);
219   info->rc_component = current_routing;
220   info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
221   xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id,
222                (void *) info, NULL);
223 #ifdef HAVE_TRACING
224   TRACE_surf_host_declaration(A_surfxml_router_id, 0);
225 #endif
226 }
227
228 /**
229  * \brief Set the endponints for a route
230  */
231 static void parse_S_route_new_and_endpoints(char *src_id, char *dst_id)
232 {
233   if (src != NULL && dst != NULL && link_list != NULL)
234     THROW2(arg_error, 0, "Route between %s to %s can not be defined",
235            src_id, dst_id);
236   src = src_id;
237   dst = dst_id;
238   xbt_assert2(strlen(src) > 0 || strlen(dst) > 0,
239               "Some limits are null in the route between \"%s\" and \"%s\"",
240               src, dst);
241   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
242 }
243
244 /**
245  * \breif Set the endpoints for a route from XML
246  */
247 static void parse_S_route_new_and_endpoints_XML(void)
248 {
249   parse_S_route_new_and_endpoints(A_surfxml_route_src,
250                                   A_surfxml_route_dst);
251 }
252
253 /**
254  * \breif Set the endpoints for a route from lua
255  */
256 static void parse_S_route_new_and_endpoints_lua(char *id_src, char *id_dst)
257 {
258   parse_S_route_new_and_endpoints(id_src, id_dst);
259 }
260
261 /**
262  * \brief Set the endponints and gateways for a ASroute
263  */
264 static void parse_S_ASroute_new_and_endpoints(void)
265 {
266   if (src != NULL && dst != NULL && link_list != NULL)
267     THROW2(arg_error, 0, "Route between %s to %s can not be defined",
268            A_surfxml_ASroute_src, A_surfxml_ASroute_dst);
269   src = A_surfxml_ASroute_src;
270   dst = A_surfxml_ASroute_dst;
271   gw_src = A_surfxml_ASroute_gw_src;
272   gw_dst = A_surfxml_ASroute_gw_dst;
273   xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
274               || strlen(gw_dst) > 0,
275               "Some limits are null in the route between \"%s\" and \"%s\"",
276               src, dst);
277   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
278 }
279
280 /**
281  * \brief Set the endponints for a bypassRoute
282  */
283 static void parse_S_bypassRoute_new_and_endpoints(void)
284 {
285   if (src != NULL && dst != NULL && link_list != NULL)
286     THROW2(arg_error, 0,
287            "Bypass Route between %s to %s can not be defined",
288            A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
289   src = A_surfxml_bypassRoute_src;
290   dst = A_surfxml_bypassRoute_dst;
291   gw_src = A_surfxml_bypassRoute_gw_src;
292   gw_dst = A_surfxml_bypassRoute_gw_dst;
293   xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0
294               || strlen(gw_dst) > 0,
295               "Some limits are null in the route between \"%s\" and \"%s\"",
296               src, dst);
297   link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
298 }
299
300 /**
301  * \brief Set a new link on the actual list of link for a route or ASroute
302  */
303 static void parse_E_link_ctn_new_elem(char *link_id)
304 {
305   char *val;
306   val = xbt_strdup(link_id);
307   xbt_dynar_push(link_list, &val);
308 }
309
310 /**
311  * \brief Set a new link on the actual list of link for a route or ASroute from XML
312  */
313
314 static void parse_E_link_ctn_new_elem_XML(void)
315 {
316   if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
317           parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
318   if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP)
319           parse_E_link_ctn_new_elem(bprintf("%s_UP",A_surfxml_link_ctn_id));
320   if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN)
321           parse_E_link_ctn_new_elem(bprintf("%s_DOWN",A_surfxml_link_ctn_id));
322 }
323
324 /**
325  * \brief Set a new link on the actual list of link for a route or ASroute from lua
326  */
327 static void parse_E_link_c_ctn_new_elem_lua(char *link_id)
328 {
329   parse_E_link_ctn_new_elem(link_id);
330 }
331
332 /**
333  * \brief Store the route by calling the set_route function of the current routing component
334  */
335 static void parse_E_route_store_route(void)
336 {
337   name_route_extended_t route = xbt_new0(s_name_route_extended_t, 1);
338   route->generic_route.link_list = link_list;
339   xbt_assert1(current_routing->set_route,
340               "no defined method \"set_route\" in \"%s\"",
341               current_routing->name);
342   (*(current_routing->set_route)) (current_routing, src, dst, route);
343   link_list = NULL;
344   src = NULL;
345   dst = NULL;
346 }
347
348 /**
349  * \brief Store the ASroute by calling the set_ASroute function of the current routing component
350  */
351 static void parse_E_ASroute_store_route(void)
352 {
353   name_route_extended_t e_route = xbt_new0(s_name_route_extended_t, 1);
354   e_route->generic_route.link_list = link_list;
355   e_route->src_gateway = xbt_strdup(gw_src);
356   e_route->dst_gateway = xbt_strdup(gw_dst);
357   xbt_assert1(current_routing->set_ASroute,
358               "no defined method \"set_ASroute\" in \"%s\"",
359               current_routing->name);
360   (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route);
361   link_list = NULL;
362   src = NULL;
363   dst = NULL;
364   gw_src = NULL;
365   gw_dst = NULL;
366 }
367
368 /**
369  * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
370  */
371 static void parse_E_bypassRoute_store_route(void)
372 {
373   route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
374   e_route->generic_route.link_list = link_list;
375   e_route->src_gateway = xbt_strdup(gw_src);
376   e_route->dst_gateway = xbt_strdup(gw_dst);
377   xbt_assert1(current_routing->set_bypassroute,
378               "no defined method \"set_bypassroute\" in \"%s\"",
379               current_routing->name);
380   (*(current_routing->set_bypassroute)) (current_routing, src, dst,
381                                          e_route);
382   link_list = NULL;
383   src = NULL;
384   dst = NULL;
385   gw_src = NULL;
386   gw_dst = NULL;
387 }
388
389 /**
390  * \brief Make a new routing component
391  *
392  * make the new structure and
393  * set the parsing functions to allows parsing the part of the routing tree
394  */
395 static void parse_S_AS(char *AS_id, char *AS_routing)
396 {
397   routing_component_t new_routing;
398   model_type_t model = NULL;
399   char *wanted = AS_routing;
400   int cpt;
401   /* seach the routing model */
402   for (cpt = 0; routing_models[cpt].name; cpt++)
403     if (!strcmp(wanted, routing_models[cpt].name))
404       model = &routing_models[cpt];
405   /* if its not exist, error */
406   if (model == NULL) {
407     fprintf(stderr, "Routing model %s not found. Existing models:\n",
408             wanted);
409     for (cpt = 0; routing_models[cpt].name; cpt++)
410       if (!strcmp(wanted, routing_models[cpt].name))
411         fprintf(stderr, "   %s: %s\n", routing_models[cpt].name,
412                 routing_models[cpt].desc);
413     xbt_die(NULL);
414   }
415
416   /* make a new routing component */
417   new_routing = (routing_component_t) (*(model->create)) ();
418   new_routing->routing = model;
419   new_routing->hierarchy = SURF_ROUTING_NULL;
420   new_routing->name = xbt_strdup(AS_id);
421   new_routing->routing_sons = xbt_dict_new();
422
423   if (current_routing == NULL && global_routing->root == NULL) {
424
425     /* it is the first one */
426     new_routing->routing_father = NULL;
427     global_routing->root = new_routing;
428
429   } else if (current_routing != NULL && global_routing->root != NULL) {
430
431     xbt_assert1(!xbt_dict_get_or_null
432                 (current_routing->routing_sons, AS_id),
433                 "The AS \"%s\" already exist", AS_id);
434     /* it is a part of the tree */
435     new_routing->routing_father = current_routing;
436     /* set the father behavior */
437     if (current_routing->hierarchy == SURF_ROUTING_NULL)
438       current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
439     /* add to the sons dictionary */
440     xbt_dict_set(current_routing->routing_sons, AS_id,
441                  (void *) new_routing, NULL);
442     /* add to the father element list */
443     (*(current_routing->set_autonomous_system)) (current_routing, AS_id);
444     /* unload the prev parse rules */
445     (*(current_routing->routing->unload)) ();
446
447   } else {
448     THROW0(arg_error, 0, "All defined components must be belong to a AS");
449   }
450   /* set the new parse rules */
451   (*(new_routing->routing->load)) ();
452   /* set the new current component of the tree */
453   current_routing = new_routing;
454 }
455
456 /*
457  * Detect the routing model type of the routing component from XML platforms
458  */
459 static void parse_S_AS_XML(void)
460 {
461   parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing);
462 }
463
464 /*
465  * define the routing model type of routing component from lua script
466  */
467 static void parse_S_AS_lua(char *id, char *mode)
468 {
469   parse_S_AS(id, mode);
470 }
471
472
473 /**
474  * \brief Finish the creation of a new routing component
475  *
476  * When you finish to read the routing component, other structures must be created. 
477  * the "end" method allow to do that for any routing model type
478  */
479 static void parse_E_AS(char *AS_id)
480 {
481
482   if (current_routing == NULL) {
483     THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id);
484   } else {
485     network_element_info_t info = NULL;
486     xbt_assert1(!xbt_dict_get_or_null
487                 (global_routing->where_network_elements,
488                  current_routing->name), "The AS \"%s\" already exist",
489                 current_routing->name);
490     info = xbt_new0(s_network_element_info_t, 1);
491     info->rc_component = current_routing->routing_father;
492     info->rc_type = SURF_NETWORK_ELEMENT_AS;
493     xbt_dict_set(global_routing->where_network_elements,
494                  current_routing->name, info, NULL);
495     (*(current_routing->routing->unload)) ();
496     (*(current_routing->routing->end)) ();
497     current_routing = current_routing->routing_father;
498     if (current_routing != NULL)
499       (*(current_routing->routing->load)) ();
500   }
501 }
502
503 /*
504  * \brief Finish the creation of a new routing component from XML
505  */
506 static void parse_E_AS_XML(void)
507 {
508   parse_E_AS(A_surfxml_AS_id);
509 }
510
511 /*
512  * \brief Finish the creation of a new routing component from lua
513  */
514 static void parse_E_AS_lua(char *id)
515 {
516   parse_E_AS(id);
517 }
518
519 /* Aux Business methods */
520
521 /**
522  * \brief Get the AS father and the first elements of the chain
523  *
524  * \param src the source host name 
525  * \param dst the destination host name
526  * 
527  * Get the common father of the to processing units, and the first different 
528  * father in the chain
529  */
530 static xbt_dynar_t elements_father(const char *src, const char *dst)
531 {
532
533   xbt_assert0(src && dst, "bad parameters for \"elements_father\" method");
534
535   xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL);
536
537   routing_component_t src_as, dst_as;
538   int index_src, index_dst, index_father_src, index_father_dst;
539   xbt_dynar_t path_src = NULL;
540   xbt_dynar_t path_dst = NULL;
541   routing_component_t current = NULL;
542   routing_component_t *current_src = NULL;
543   routing_component_t *current_dst = NULL;
544   routing_component_t *father = NULL;
545
546   /* (1) find the as where the src and dst are located */
547   src_as = ((network_element_info_t)
548             xbt_dict_get_or_null(global_routing->where_network_elements,
549                                  src))->rc_component;
550   dst_as = ((network_element_info_t)
551             xbt_dict_get_or_null(global_routing->where_network_elements,
552                                  dst))->rc_component;
553   xbt_assert2(src_as
554               && dst_as,
555               "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
556               dst);
557
558   /* (2) find the path to the root routing component */
559   path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
560   current = src_as;
561   while (current != NULL) {
562     xbt_dynar_push(path_src, &current);
563     current = current->routing_father;
564   }
565   path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
566   current = dst_as;
567   while (current != NULL) {
568     xbt_dynar_push(path_dst, &current);
569     current = current->routing_father;
570   }
571
572   /* (3) find the common father */
573   index_src = (path_src->used) - 1;
574   index_dst = (path_dst->used) - 1;
575   current_src = xbt_dynar_get_ptr(path_src, index_src);
576   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
577   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
578     current_src = xbt_dynar_get_ptr(path_src, index_src);
579     current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
580     index_src--;
581     index_dst--;
582   }
583   index_src++;
584   index_dst++;
585   current_src = xbt_dynar_get_ptr(path_src, index_src);
586   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
587
588   /* (4) they are not in the same routing component, make the path */
589   index_father_src = index_src + 1;
590   index_father_dst = index_dst + 1;
591
592   if (*current_src == *current_dst)
593     father = current_src;
594   else
595     father = xbt_dynar_get_ptr(path_src, index_father_src);
596
597   /* (5) result generation */
598   xbt_dynar_push(result, father);       /* first same the father of src and dst */
599   xbt_dynar_push(result, current_src);  /* second the first different father of src */
600   xbt_dynar_push(result, current_dst);  /* three  the first different father of dst */
601
602   xbt_dynar_free(&path_src);
603   xbt_dynar_free(&path_dst);
604
605   return result;
606 }
607
608 /* Global Business methods */
609
610 /**
611  * \brief Recursive function for get_route
612  *
613  * \param src the source host name 
614  * \param dst the destination host name
615  * 
616  * This fuction is call by "get_route". It allow to walk through the 
617  * routing components tree.
618  */
619 static route_extended_t _get_route(const char *src, const char *dst)
620 {
621
622   void *link;
623   unsigned int cpt = 0;
624
625   DEBUG2("Solve route  \"%s\" to \"%s\"", src, dst);
626
627   xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
628
629   route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
630       NULL;
631
632   xbt_dynar_t elem_father_list = elements_father(src, dst);
633
634   routing_component_t common_father =
635       xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
636   routing_component_t src_father =
637       xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
638   routing_component_t dst_father =
639       xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
640
641   e_route = xbt_new0(s_route_extended_t, 1);
642   e_route->src_gateway = NULL;
643   e_route->dst_gateway = NULL;
644   e_route->generic_route.link_list =
645       xbt_dynar_new(global_routing->size_of_link, NULL);
646
647   if (src_father == dst_father) {       /* SURF_ROUTING_BASE */
648
649     if (strcmp(src, dst)) {
650       e_route_cnt =
651           (*(common_father->get_route)) (common_father, src, dst);
652       xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src,
653                   dst);
654       xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
655         xbt_dynar_push(e_route->generic_route.link_list, &link);
656       }
657       generic_free_extended_route(e_route_cnt);
658     }
659
660   } else {                      /* SURF_ROUTING_RECURSIVE */
661
662     route_extended_t e_route_bypass = NULL;
663
664     if (common_father->get_bypass_route)
665       e_route_bypass =
666           (*(common_father->get_bypass_route)) (common_father, src, dst);
667
668     if (e_route_bypass)
669       e_route_cnt = e_route_bypass;
670     else
671       e_route_cnt =
672           (*(common_father->get_route)) (common_father, src_father->name,
673                                          dst_father->name);
674
675     xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"",
676                 src_father->name, dst_father->name);
677
678     xbt_assert2((e_route_cnt->src_gateway == NULL) ==
679                 (e_route_cnt->dst_gateway == NULL),
680                 "bad gateway for route between \"%s\" and \"%s\"", src,
681                 dst);
682
683     if (src != e_route_cnt->src_gateway) {
684       e_route_src = _get_route(src, e_route_cnt->src_gateway);
685       xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src,
686                   e_route_cnt->src_gateway);
687       xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
688         xbt_dynar_push(e_route->generic_route.link_list, &link);
689       }
690     }
691
692     xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
693       xbt_dynar_push(e_route->generic_route.link_list, &link);
694     }
695
696     if (e_route_cnt->dst_gateway != dst) {
697       e_route_dst = _get_route(e_route_cnt->dst_gateway, dst);
698       xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"",
699                   e_route_cnt->dst_gateway, dst);
700       xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
701         xbt_dynar_push(e_route->generic_route.link_list, &link);
702       }
703     }
704
705     e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
706     e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
707
708     generic_free_extended_route(e_route_src);
709     generic_free_extended_route(e_route_cnt);
710     generic_free_extended_route(e_route_dst);
711   }
712
713   xbt_dynar_free(&elem_father_list);
714
715   return e_route;
716 }
717
718 /**
719  * \brief Generic method: find a route between hosts
720  *
721  * \param src the source host name 
722  * \param dst the destination host name
723  * 
724  * walk through the routing components tree and find a route between hosts
725  * by calling the differents "get_route" functions in each routing component.
726  * No need to free the returned dynar. It will be freed at the next call.
727  */
728 static xbt_dynar_t get_route(const char *src, const char *dst)
729 {
730
731   route_extended_t e_route;
732   xbt_dynar_t elem_father_list = elements_father(src, dst);
733   routing_component_t common_father =
734       xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
735
736   if (strcmp(src, dst))
737     e_route = _get_route(src, dst);
738   else
739     e_route = (*(common_father->get_route)) (common_father, src, dst);
740
741   xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst);
742
743   if (global_routing->last_route)
744     xbt_dynar_free(&(global_routing->last_route));
745   global_routing->last_route = e_route->generic_route.link_list;
746
747   if (e_route->src_gateway)
748     xbt_free(e_route->src_gateway);
749   if (e_route->dst_gateway)
750     xbt_free(e_route->dst_gateway);
751
752   xbt_free(e_route);
753   xbt_dynar_free(&elem_father_list);
754
755   if (xbt_dynar_length(global_routing->last_route) == 0)
756     return NULL;
757   else
758     return global_routing->last_route;
759 }
760
761 /**
762  * \brief Generic method: find a route between hosts
763  *
764  * \param src the source host name
765  * \param dst the destination host name
766  *
767  * walk through the routing components tree and find a route between hosts
768  * by calling the differents "get_route" functions in each routing component.
769  * Leaves the caller the responsability to clean the returned dynar.
770  */
771 static xbt_dynar_t get_route_no_cleanup(const char *src, const char *dst)
772 {
773         xbt_dynar_t d = get_route(src,dst);
774         global_routing->last_route = NULL;
775         return d;
776 }
777
778 /**
779  * \brief Recursive function for finalize
780  *
781  * \param rc the source host name 
782  * 
783  * This fuction is call by "finalize". It allow to finalize the 
784  * AS or routing components. It delete all the structures.
785  */
786 static void _finalize(routing_component_t rc)
787 {
788   if (rc) {
789     xbt_dict_cursor_t cursor = NULL;
790     char *key;
791     routing_component_t elem;
792     xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
793       _finalize(elem);
794     }
795     xbt_dict_t tmp_sons = rc->routing_sons;
796     char *tmp_name = rc->name;
797     xbt_dict_free(&tmp_sons);
798     xbt_free(tmp_name);
799     xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"",
800                 current_routing->name);
801     (*(rc->finalize)) (rc);
802   }
803 }
804
805 /**
806  * \brief Generic method: delete all the routing structures
807  * 
808  * walk through the routing components tree and delete the structures
809  * by calling the differents "finalize" functions in each routing component
810  */
811 static void finalize(void)
812 {
813   /* delete recursibly all the tree */
814   _finalize(global_routing->root);
815   /* delete "where" dict */
816   xbt_dict_free(&(global_routing->where_network_elements));
817   /* delete last_route */
818   xbt_dynar_free(&(global_routing->last_route));
819   /* delete global routing structure */
820   xbt_free(global_routing);
821 }
822
823 static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc)
824 {
825   xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
826
827   //adding my one link routes
828   unsigned int cpt;
829   void *link;
830   xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
831   if (onelink_mine) {
832     xbt_dynar_foreach(onelink_mine, cpt, link) {
833       xbt_dynar_push(ret, &link);
834     }
835   }
836   //recursing
837   char *key;
838   xbt_dict_cursor_t cursor = NULL;
839   routing_component_t rc_child;
840   xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
841     xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
842     if (onelink_child) {
843       xbt_dynar_foreach(onelink_child, cpt, link) {
844         xbt_dynar_push(ret, &link);
845       }
846     }
847   }
848   return ret;
849 }
850
851 static xbt_dynar_t get_onelink_routes(void)
852 {
853   return recursive_get_onelink_routes(global_routing->root);
854 }
855
856 static e_surf_network_element_type_t get_network_element_type(const char
857                                                               *name)
858 {
859   network_element_info_t rc = NULL;
860   rc = xbt_dict_get(global_routing->where_network_elements, name);
861   return rc->rc_type;
862 }
863
864 /**
865  * \brief Generic method: create the global routing schema
866  * 
867  * Make a global routing structure and set all the parsing functions.
868  */
869 void routing_model_create(size_t size_of_links, void *loopback)
870 {
871
872   /* config the uniq global routing */
873   global_routing = xbt_new0(s_routing_global_t, 1);
874   global_routing->where_network_elements = xbt_dict_new();
875   global_routing->root = NULL;
876   global_routing->get_route = get_route;
877   global_routing->get_route_no_cleanup = get_route_no_cleanup;
878   global_routing->get_onelink_routes = get_onelink_routes;
879   global_routing->get_network_element_type = get_network_element_type;
880   global_routing->finalize = finalize;
881   global_routing->loopback = loopback;
882   global_routing->size_of_link = size_of_links;
883   global_routing->last_route = NULL;
884
885   /* no current routing at moment */
886   current_routing = NULL;
887
888   /* parse generic elements */
889   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
890   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
891
892   surfxml_add_callback(STag_surfxml_route_cb_list,
893                        &parse_S_route_new_and_endpoints_XML);
894   surfxml_add_callback(STag_surfxml_ASroute_cb_list,
895                        &parse_S_ASroute_new_and_endpoints);
896   surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
897                        &parse_S_bypassRoute_new_and_endpoints);
898
899   surfxml_add_callback(ETag_surfxml_link_ctn_cb_list,
900                        &parse_E_link_ctn_new_elem_XML);
901
902   surfxml_add_callback(ETag_surfxml_route_cb_list,
903                        &parse_E_route_store_route);
904   surfxml_add_callback(ETag_surfxml_ASroute_cb_list,
905                        &parse_E_ASroute_store_route);
906   surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
907                        &parse_E_bypassRoute_store_route);
908
909   surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML);
910   surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML);
911
912   surfxml_add_callback(STag_surfxml_cluster_cb_list,
913                        &routing_parse_Scluster);
914
915   surfxml_add_callback(STag_surfxml_config_cb_list,
916                                            &routing_parse_Sconfig);
917   surfxml_add_callback(ETag_surfxml_config_cb_list,
918                                            &routing_parse_Econfig);
919 }
920
921 /* ************************************************************************** */
922 /* *************************** FULL ROUTING ********************************* */
923
924 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
925
926 /* Routing model structure */
927
928 typedef struct {
929   s_routing_component_t generic_routing;
930   route_extended_t *routing_table;
931 } s_routing_component_full_t, *routing_component_full_t;
932
933 /* Business methods */
934 static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
935 {
936   xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
937
938   routing_component_full_t routing = (routing_component_full_t) rc;
939   size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
940   xbt_dict_cursor_t c1 = NULL, c2 = NULL;
941   char *k1, *d1, *k2, *d2;
942   xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
943     xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
944       int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k1);
945       int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, k2);
946       xbt_assert2(src_id
947                   && dst_id,
948                   "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
949                   src, dst);
950       route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id);
951       if (route) {
952         if (xbt_dynar_length(route->generic_route.link_list) == 1) {
953           void *link =
954               *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
955                                            0);
956           onelink_t onelink = xbt_new0(s_onelink_t, 1);
957           onelink->link_ptr = link;
958           if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
959             onelink->src = xbt_strdup(k1);
960             onelink->dst = xbt_strdup(k2);
961           } else if (routing->generic_routing.hierarchy ==
962                      SURF_ROUTING_RECURSIVE) {
963             onelink->src = xbt_strdup(route->src_gateway);
964             onelink->dst = xbt_strdup(route->dst_gateway);
965           }
966           xbt_dynar_push(ret, &onelink);
967         }
968       }
969     }
970   }
971   return ret;
972 }
973
974 static route_extended_t full_get_route(routing_component_t rc,
975                                        const char *src, const char *dst)
976 {
977   xbt_assert1(rc && src
978               && dst,
979               "Invalid params for \"get_route\" function at AS \"%s\"",
980               rc->name);
981
982   /* set utils vars */
983   routing_component_full_t routing = (routing_component_full_t) rc;
984   size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
985
986   generic_src_dst_check(rc, src, dst);
987   int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
988   int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
989   xbt_assert2(src_id
990               && dst_id,
991               "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
992               src, dst);
993
994   route_extended_t e_route = NULL;
995   route_extended_t new_e_route = NULL;
996   void *link;
997   unsigned int cpt = 0;
998
999   e_route = TO_ROUTE_FULL(*src_id, *dst_id);
1000
1001   if (e_route) {
1002     new_e_route = xbt_new0(s_route_extended_t, 1);
1003     new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
1004     new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
1005     new_e_route->generic_route.link_list =
1006         xbt_dynar_new(global_routing->size_of_link, NULL);
1007     xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
1008       xbt_dynar_push(new_e_route->generic_route.link_list, &link);
1009     }
1010   }
1011   return new_e_route;
1012 }
1013
1014 static void full_finalize(routing_component_t rc)
1015 {
1016   routing_component_full_t routing = (routing_component_full_t) rc;
1017   size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1018   int i, j;
1019   if (routing) {
1020     /* Delete routing table */
1021     for (i = 0; i < table_size; i++)
1022       for (j = 0; j < table_size; j++)
1023         generic_free_extended_route(TO_ROUTE_FULL(i, j));
1024     xbt_free(routing->routing_table);
1025     /* Delete bypass dict */
1026     xbt_dict_free(&rc->bypassRoutes);
1027     /* Delete index dict */
1028     xbt_dict_free(&rc->to_index);
1029     /* Delete structure */
1030     xbt_free(rc);
1031   }
1032 }
1033
1034 /* Creation routing model functions */
1035
1036 static void *model_full_create(void)
1037 {
1038   routing_component_full_t new_component =
1039       xbt_new0(s_routing_component_full_t, 1);
1040   new_component->generic_routing.set_processing_unit =
1041       generic_set_processing_unit;
1042   new_component->generic_routing.set_autonomous_system =
1043       generic_set_autonomous_system;
1044   new_component->generic_routing.set_route = model_full_set_route;
1045   new_component->generic_routing.set_ASroute = model_full_set_route;
1046   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1047   new_component->generic_routing.get_route = full_get_route;
1048   new_component->generic_routing.get_onelink_routes =
1049       full_get_onelink_routes;
1050   new_component->generic_routing.get_bypass_route =
1051       generic_get_bypassroute;
1052   new_component->generic_routing.finalize = full_finalize;
1053   new_component->generic_routing.to_index = xbt_dict_new();
1054   new_component->generic_routing.bypassRoutes = xbt_dict_new();
1055   return new_component;
1056 }
1057
1058 static void model_full_load(void)
1059 {
1060   /* use "surfxml_add_callback" to add a parse function call */
1061 }
1062
1063 static void model_full_unload(void)
1064 {
1065   /* use "surfxml_del_callback" to remove a parse function call */
1066 }
1067
1068 static void model_full_end(void)
1069 {
1070   unsigned int i;
1071   route_extended_t e_route;
1072
1073   /* set utils vars */
1074   routing_component_full_t routing =
1075       ((routing_component_full_t) current_routing);
1076   size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1077
1078   /* Create table if necessary */
1079   if(!routing->routing_table)
1080           routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1081
1082   /* Add the loopback if needed */
1083   if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1084     for (i = 0; i < table_size; i++) {
1085       e_route = TO_ROUTE_FULL(i, i);
1086       if (!e_route) {
1087         e_route = xbt_new0(s_route_extended_t, 1);
1088         e_route->src_gateway = NULL;
1089         e_route->dst_gateway = NULL;
1090         e_route->generic_route.link_list =
1091             xbt_dynar_new(global_routing->size_of_link, NULL);
1092         xbt_dynar_push(e_route->generic_route.link_list,
1093                        &global_routing->loopback);
1094         TO_ROUTE_FULL(i, i) = e_route;
1095       }
1096     }
1097   }
1098 }
1099
1100 static void model_full_set_route(routing_component_t rc, const char *src,
1101                 const char *dst, name_route_extended_t route)
1102 {
1103         int *src_id, *dst_id;
1104         src_id = xbt_dict_get_or_null(rc->to_index, src);
1105         dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1106         routing_component_full_t routing = ((routing_component_full_t) rc);
1107         size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1108
1109         xbt_assert2(src_id
1110                           && dst_id, "Network elements %s or %s not found", src, dst);
1111
1112         xbt_assert2(xbt_dynar_length(route->generic_route.link_list) > 0,
1113                           "Invalid count of links, must be greater than zero (%s,%s)",
1114                           src, dst);
1115
1116         if(!routing->routing_table)
1117                 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
1118
1119         if(TO_ROUTE_FULL(*src_id, *dst_id))
1120         {
1121                 char * link_name;
1122                 unsigned int i;
1123                 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1124                 xbt_dynar_foreach(route->generic_route.link_list,i,link_name)
1125                 {
1126                         void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1127                         xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1128                         xbt_dynar_push(link_route_to_test,&link);
1129                 }
1130                 xbt_assert2(!xbt_dynar_compare(
1131                           (void*)TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list,
1132                           (void*)link_route_to_test,
1133                           (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1134                           "The route between \"%s\" and \"%s\" already exist", src,dst);
1135                 xbt_free(link_route_to_test);
1136         }
1137         else
1138         {
1139                   if(!route->dst_gateway && !route->src_gateway)
1140                           DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1141                   else
1142                           DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1143                                  route->src_gateway, dst, route->dst_gateway);
1144               TO_ROUTE_FULL(*src_id, *dst_id) = generic_new_extended_route(rc->hierarchy,route,1);
1145               xbt_dynar_shrink(TO_ROUTE_FULL(*src_id, *dst_id)->generic_route.link_list, 0);
1146         }
1147
1148         if( A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES
1149                 || A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES )
1150         {
1151                 if(route->dst_gateway && route->src_gateway)
1152                 {
1153                         char * gw_src = bprintf("%s",route->src_gateway);
1154                         char * gw_dst = bprintf("%s",route->dst_gateway);
1155                         route->src_gateway = bprintf("%s",gw_dst);
1156                         route->dst_gateway = bprintf("%s",gw_src);
1157                 }
1158                 if(TO_ROUTE_FULL(*dst_id, *src_id))
1159                 {
1160                         char * link_name;
1161                         unsigned int i;
1162                         xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1163                         for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1164                         {
1165                                 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1166                                 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1167                                 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1168                                 xbt_dynar_push(link_route_to_test,&link);
1169                         }
1170                         xbt_assert2(!xbt_dynar_compare(
1171                                   (void*)TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list,
1172                               (void*)link_route_to_test,
1173                                   (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1174                                   "The route between \"%s\" and \"%s\" already exist", src,dst);
1175                         xbt_free(link_route_to_test);
1176                 }
1177                 else
1178                 {
1179                           if(!route->dst_gateway && !route->src_gateway)
1180                                   DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1181                           else
1182                                   DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1183                                          route->src_gateway, src, route->dst_gateway);
1184                       TO_ROUTE_FULL(*dst_id, *src_id) = generic_new_extended_route(rc->hierarchy,route,0);
1185                       xbt_dynar_shrink(TO_ROUTE_FULL(*dst_id, *src_id)->generic_route.link_list, 0);
1186                 }
1187
1188         }
1189 }
1190
1191 /* ************************************************************************** */
1192 /* *************************** FLOYD ROUTING ******************************** */
1193
1194 #define TO_FLOYD_COST(i,j) (routing->cost_table)[(i)+(j)*table_size]
1195 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
1196 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
1197
1198 /* Routing model structure */
1199
1200 typedef struct {
1201   s_routing_component_t generic_routing;
1202   /* vars for calculate the floyd algorith. */
1203   int *predecessor_table;
1204   double *cost_table;
1205   route_extended_t *link_table; /* char* -> int* */
1206 } s_routing_component_floyd_t, *routing_component_floyd_t;
1207
1208 static route_extended_t floyd_get_route(routing_component_t rc,
1209                                         const char *src, const char *dst);
1210
1211 /* Business methods */
1212 static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
1213 {
1214   xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
1215
1216   routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1217   //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1218   xbt_dict_cursor_t c1 = NULL, c2 = NULL;
1219   char *k1, *d1, *k2, *d2;
1220   xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
1221     xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
1222       route_extended_t route = floyd_get_route(rc, k1, k2);
1223       if (route) {
1224         if (xbt_dynar_length(route->generic_route.link_list) == 1) {
1225           void *link =
1226               *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
1227                                            0);
1228           onelink_t onelink = xbt_new0(s_onelink_t, 1);
1229           onelink->link_ptr = link;
1230           if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
1231             onelink->src = xbt_strdup(k1);
1232             onelink->dst = xbt_strdup(k2);
1233           } else if (routing->generic_routing.hierarchy ==
1234                      SURF_ROUTING_RECURSIVE) {
1235             onelink->src = xbt_strdup(route->src_gateway);
1236             onelink->dst = xbt_strdup(route->dst_gateway);
1237           }
1238           xbt_dynar_push(ret, &onelink);
1239         }
1240       }
1241     }
1242   }
1243   return ret;
1244 }
1245
1246 static route_extended_t floyd_get_route(routing_component_t rc,
1247                                         const char *src, const char *dst)
1248 {
1249   xbt_assert1(rc && src
1250               && dst,
1251               "Invalid params for \"get_route\" function at AS \"%s\"",
1252               rc->name);
1253
1254   /* set utils vars */
1255   routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1256   size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1257
1258   generic_src_dst_check(rc, src, dst);
1259   int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1260   int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1261   xbt_assert2(src_id
1262               && dst_id,
1263               "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
1264               src, dst);
1265
1266   /* create a result route */
1267   route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1268   new_e_route->generic_route.link_list =
1269       xbt_dynar_new(global_routing->size_of_link, NULL);
1270   new_e_route->src_gateway = NULL;
1271   new_e_route->dst_gateway = NULL;
1272
1273   int first = 1;
1274   int pred = *dst_id;
1275   int prev_pred = 0;
1276   char *gw_src = NULL, *gw_dst =
1277       NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1278   unsigned int cpt;
1279   void *link;
1280   xbt_dynar_t links;
1281
1282   do {
1283     prev_pred = pred;
1284     pred = TO_FLOYD_PRED(*src_id, pred);
1285     if (pred == -1)             /* if no pred in route -> no route to host */
1286       break;
1287     xbt_assert2(TO_FLOYD_LINK(pred, prev_pred),
1288                 "Invalid link for the route between \"%s\" or \"%s\"", src,
1289                 dst);
1290
1291     prev_gw_src = gw_src;
1292     prev_gw_dst = gw_dst;
1293
1294     route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred);
1295     gw_src = e_route->src_gateway;
1296     gw_dst = e_route->dst_gateway;
1297
1298     if (first)
1299       first_gw = gw_dst;
1300
1301     if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first
1302         && strcmp(gw_dst, prev_gw_src)) {
1303       xbt_dynar_t e_route_as_to_as =
1304           (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1305       xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1306                   gw_dst, prev_gw_src);
1307       links = e_route_as_to_as;
1308       int pos = 0;
1309       xbt_dynar_foreach(links, cpt, link) {
1310         xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1311                             &link);
1312         pos++;
1313       }
1314     }
1315
1316     links = e_route->generic_route.link_list;
1317     xbt_dynar_foreach(links, cpt, link) {
1318       xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1319     }
1320     first = 0;
1321
1322   } while (pred != *src_id);
1323   xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
1324               *src_id, *dst_id, src, dst);
1325
1326   if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1327     new_e_route->src_gateway = xbt_strdup(gw_src);
1328     new_e_route->dst_gateway = xbt_strdup(first_gw);
1329   }
1330
1331   return new_e_route;
1332 }
1333
1334 static void floyd_finalize(routing_component_t rc)
1335 {
1336   routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1337   int i, j;
1338   size_t table_size;
1339   if (routing) {
1340     table_size = xbt_dict_length(routing->generic_routing.to_index);
1341     /* Delete link_table */
1342     for (i = 0; i < table_size; i++)
1343       for (j = 0; j < table_size; j++)
1344         generic_free_extended_route(TO_FLOYD_LINK(i, j));
1345     xbt_free(routing->link_table);
1346     /* Delete bypass dict */
1347     xbt_dict_free(&routing->generic_routing.bypassRoutes);
1348     /* Delete index dict */
1349     xbt_dict_free(&(routing->generic_routing.to_index));
1350     /* Delete dictionary index dict, predecessor and links table */
1351     xbt_free(routing->predecessor_table);
1352     /* Delete structure */
1353     xbt_free(rc);
1354   }
1355 }
1356
1357 static void *model_floyd_create(void)
1358 {
1359   routing_component_floyd_t new_component =
1360       xbt_new0(s_routing_component_floyd_t, 1);
1361   new_component->generic_routing.set_processing_unit =
1362       generic_set_processing_unit;
1363   new_component->generic_routing.set_autonomous_system =
1364       generic_set_autonomous_system;
1365   new_component->generic_routing.set_route = model_floyd_set_route;
1366   new_component->generic_routing.set_ASroute = model_floyd_set_route;
1367   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1368   new_component->generic_routing.get_route = floyd_get_route;
1369   new_component->generic_routing.get_onelink_routes =
1370       floyd_get_onelink_routes;
1371   new_component->generic_routing.get_bypass_route =
1372       generic_get_bypassroute;
1373   new_component->generic_routing.finalize = floyd_finalize;
1374   new_component->generic_routing.to_index = xbt_dict_new();
1375   new_component->generic_routing.bypassRoutes = xbt_dict_new();
1376   new_component->generic_routing.parse_routes = xbt_dict_new();
1377   return new_component;
1378 }
1379
1380 static void model_floyd_load(void)
1381 {
1382   /* use "surfxml_add_callback" to add a parse function call */
1383 }
1384
1385 static void model_floyd_unload(void)
1386 {
1387   /* use "surfxml_del_callback" to remove a parse function call */
1388 }
1389
1390 static void model_floyd_end(void)
1391 {
1392
1393         routing_component_floyd_t routing =
1394           ((routing_component_floyd_t) current_routing);
1395
1396         unsigned int i, j, a, b, c;
1397
1398         /* set the size of table routing */
1399         size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
1400
1401         if(!routing->link_table)
1402         {
1403                 /* Create Cost, Predecessor and Link tables */
1404                 routing->cost_table = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
1405                 routing->predecessor_table = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
1406                 routing->link_table = xbt_new0(route_extended_t, table_size * table_size);    /* actual link between src and dst */
1407
1408                 /* Initialize costs and predecessors */
1409                 for (i = 0; i < table_size; i++)
1410                 for (j = 0; j < table_size; j++) {
1411                   TO_FLOYD_COST(i, j) = DBL_MAX;
1412                   TO_FLOYD_PRED(i, j) = -1;
1413                   TO_FLOYD_LINK(i, j) = NULL;       /* fixed, missing in the previous version */
1414                 }
1415         }
1416
1417         /* Add the loopback if needed */
1418         if (current_routing->hierarchy == SURF_ROUTING_BASE) {
1419                 for (i = 0; i < table_size; i++) {
1420                   route_extended_t e_route = TO_FLOYD_LINK(i, i);
1421                   if (!e_route) {
1422                         e_route = xbt_new0(s_route_extended_t, 1);
1423                         e_route->src_gateway = NULL;
1424                         e_route->dst_gateway = NULL;
1425                         e_route->generic_route.link_list =
1426                                 xbt_dynar_new(global_routing->size_of_link, NULL);
1427                         xbt_dynar_push(e_route->generic_route.link_list,
1428                                                    &global_routing->loopback);
1429                         TO_FLOYD_LINK(i, i) = e_route;
1430                         TO_FLOYD_PRED(i, i) = i;
1431                         TO_FLOYD_COST(i, i) = 1;
1432                   }
1433                 }
1434         }
1435         /* Calculate path costs */
1436         for (c = 0; c < table_size; c++) {
1437                 for (a = 0; a < table_size; a++) {
1438                   for (b = 0; b < table_size; b++) {
1439                         if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
1440                           if (TO_FLOYD_COST(a, b) == DBL_MAX ||
1441                                   (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
1442                                    TO_FLOYD_COST(a, b))) {
1443                                 TO_FLOYD_COST(a, b) =
1444                                         TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
1445                                 TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
1446                           }
1447                         }
1448                   }
1449                 }
1450         }
1451 }
1452
1453 static void model_floyd_set_route(routing_component_t rc, const char *src,
1454         const char *dst, name_route_extended_t route)
1455 {
1456         routing_component_floyd_t routing = (routing_component_floyd_t) rc;
1457
1458         /* set the size of table routing */
1459         size_t table_size = xbt_dict_length(rc->to_index);
1460         int *src_id, *dst_id;
1461         int i,j;
1462
1463         src_id = xbt_dict_get_or_null(rc->to_index, src);
1464         dst_id = xbt_dict_get_or_null(rc->to_index, dst);
1465
1466         if(!routing->link_table)
1467         {
1468                 /* Create Cost, Predecessor and Link tables */
1469                 routing->cost_table = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
1470                 routing->predecessor_table = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
1471                 routing->link_table = xbt_new0(route_extended_t, table_size * table_size);    /* actual link between src and dst */
1472
1473                 /* Initialize costs and predecessors */
1474                 for (i = 0; i < table_size; i++)
1475                 for (j = 0; j < table_size; j++) {
1476                   TO_FLOYD_COST(i, j) = DBL_MAX;
1477                   TO_FLOYD_PRED(i, j) = -1;
1478                   TO_FLOYD_LINK(i, j) = NULL;       /* fixed, missing in the previous version */
1479                 }
1480         }
1481
1482         if(TO_FLOYD_LINK(*src_id, *dst_id))
1483         {
1484                 if(!route->dst_gateway && !route->src_gateway)
1485                         DEBUG2("See Route from \"%s\" to \"%s\"", src, dst);
1486                 else
1487                         DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1488                                  route->src_gateway, dst, route->dst_gateway);
1489                 char * link_name;
1490                 unsigned int cpt;
1491                 xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1492                 xbt_dynar_foreach(route->generic_route.link_list,cpt,link_name)
1493                 {
1494                         void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1495                         xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1496                         xbt_dynar_push(link_route_to_test,&link);
1497                 }
1498                 xbt_assert2(!xbt_dynar_compare(
1499                           (void*)TO_FLOYD_LINK(*src_id, *dst_id)->generic_route.link_list,
1500                           (void*)link_route_to_test,
1501                           (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1502                           "The route between \"%s\" and \"%s\" already exist", src,dst);
1503                 xbt_free(link_route_to_test);
1504         }
1505         else
1506         {
1507                 if(!route->dst_gateway && !route->src_gateway)
1508                   DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
1509                 else
1510                   DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
1511                                  route->src_gateway, dst, route->dst_gateway);
1512
1513             TO_FLOYD_LINK(*src_id, *dst_id) =
1514                         generic_new_extended_route(rc->hierarchy, route, 1);
1515             TO_FLOYD_PRED(*src_id, *dst_id) = *src_id;
1516             TO_FLOYD_COST(*src_id, *dst_id) =
1517                         ((TO_FLOYD_LINK(*src_id, *dst_id))->generic_route.link_list)->used;   /* count of links, old model assume 1 */
1518         }
1519
1520         if( A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES
1521                 || A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES )
1522         {
1523                 if(TO_FLOYD_LINK(*dst_id, *src_id))
1524                 {
1525                         if(!route->dst_gateway && !route->src_gateway)
1526                           DEBUG2("See Route from \"%s\" to \"%s\"", dst, src);
1527                         else
1528                           DEBUG4("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1529                                          route->src_gateway, src, route->dst_gateway);
1530                         char * link_name;
1531                         unsigned int i;
1532                         xbt_dynar_t link_route_to_test = xbt_dynar_new(global_routing->size_of_link, NULL);
1533                         for(i=xbt_dynar_length(route->generic_route.link_list) ;i>0 ;i--)
1534                         {
1535                                 link_name = xbt_dynar_get_as(route->generic_route.link_list,i-1,void *);
1536                                 void *link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1537                                 xbt_assert1(link,"Link : '%s' doesn't exists.",link_name);
1538                                 xbt_dynar_push(link_route_to_test,&link);
1539                         }
1540                         xbt_assert2(!xbt_dynar_compare(
1541                                   (void*)TO_FLOYD_LINK(*dst_id, *src_id)->generic_route.link_list,
1542                               (void*)link_route_to_test,
1543                                   (int_f_cpvoid_cpvoid_t) surf_pointer_resource_cmp),
1544                                   "The route between \"%s\" and \"%s\" already exist", src,dst);
1545                         xbt_free(link_route_to_test);
1546                 }
1547                 else
1548                 {
1549                         if(route->dst_gateway && route->src_gateway)
1550                         {
1551                                 char * gw_src = bprintf("%s",route->src_gateway);
1552                                 char * gw_dst = bprintf("%s",route->dst_gateway);
1553                                 route->src_gateway = bprintf("%s",gw_dst);
1554                                 route->dst_gateway = bprintf("%s",gw_src);
1555                         }
1556
1557                         if(!route->dst_gateway && !route->src_gateway)
1558                           DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
1559                         else
1560                           DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
1561                                          route->src_gateway, src, route->dst_gateway);
1562
1563                     TO_FLOYD_LINK(*dst_id, *src_id) =
1564                                 generic_new_extended_route(rc->hierarchy, route, 0);
1565                     TO_FLOYD_PRED(*dst_id, *src_id) = *dst_id;
1566                     TO_FLOYD_COST(*dst_id, *src_id) =
1567                                 ((TO_FLOYD_LINK(*dst_id, *src_id))->generic_route.link_list)->used;   /* count of links, old model assume 1 */
1568                 }
1569         }
1570 }
1571
1572 /* ************************************************************************** */
1573 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1574
1575 typedef struct {
1576   s_routing_component_t generic_routing;
1577   xbt_graph_t route_graph;      /* xbt_graph */
1578   xbt_dict_t graph_node_map;    /* map */
1579   xbt_dict_t route_cache;       /* use in cache mode */
1580   int cached;
1581 } s_routing_component_dijkstra_t, *routing_component_dijkstra_t;
1582
1583
1584 typedef struct graph_node_data {
1585   int id;
1586   int graph_id;                 /* used for caching internal graph id's */
1587 } s_graph_node_data_t, *graph_node_data_t;
1588
1589 typedef struct graph_node_map_element {
1590   xbt_node_t node;
1591 } s_graph_node_map_element_t, *graph_node_map_element_t;
1592
1593 typedef struct route_cache_element {
1594   int *pred_arr;
1595   int size;
1596 } s_route_cache_element_t, *route_cache_element_t;
1597
1598 /* Free functions */
1599
1600 static void route_cache_elem_free(void *e)
1601 {
1602   route_cache_element_t elm = (route_cache_element_t) e;
1603   if (elm) {
1604     xbt_free(elm->pred_arr);
1605     xbt_free(elm);
1606   }
1607 }
1608
1609 static void graph_node_map_elem_free(void *e)
1610 {
1611   graph_node_map_element_t elm = (graph_node_map_element_t) e;
1612   if (elm) {
1613     xbt_free(elm);
1614   }
1615 }
1616
1617 static void graph_edge_data_free(void *e)
1618 {
1619   route_extended_t e_route = (route_extended_t) e;
1620   if (e_route) {
1621     xbt_dynar_free(&(e_route->generic_route.link_list));
1622     if (e_route->src_gateway)
1623       xbt_free(e_route->src_gateway);
1624     if (e_route->dst_gateway)
1625       xbt_free(e_route->dst_gateway);
1626     xbt_free(e_route);
1627   }
1628 }
1629
1630 /* Utility functions */
1631
1632 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc,
1633                                        int id, int graph_id)
1634 {
1635   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1636   xbt_node_t node = NULL;
1637   graph_node_data_t data = NULL;
1638   graph_node_map_element_t elm = NULL;
1639
1640   data = xbt_new0(struct graph_node_data, 1);
1641   data->id = id;
1642   data->graph_id = graph_id;
1643   node = xbt_graph_new_node(routing->route_graph, data);
1644
1645   elm = xbt_new0(struct graph_node_map_element, 1);
1646   elm->node = node;
1647   xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int),
1648                    (xbt_set_elm_t) elm, &graph_node_map_elem_free);
1649
1650   return node;
1651 }
1652
1653 static graph_node_map_element_t
1654 graph_node_map_search(routing_component_dijkstra_t rc, int id)
1655 {
1656   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1657   graph_node_map_element_t elm = (graph_node_map_element_t)
1658       xbt_dict_get_or_null_ext(routing->graph_node_map,
1659                                (char *) (&id),
1660                                sizeof(int));
1661   return elm;
1662 }
1663
1664 /* Parsing */
1665
1666 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id,
1667                                int dst_id, route_extended_t e_route)
1668 {
1669   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1670
1671   xbt_node_t src = NULL;
1672   xbt_node_t dst = NULL;
1673   graph_node_map_element_t src_elm = (graph_node_map_element_t)
1674       xbt_dict_get_or_null_ext(routing->graph_node_map,
1675                                (char *) (&src_id),
1676                                sizeof(int));
1677   graph_node_map_element_t dst_elm = (graph_node_map_element_t)
1678       xbt_dict_get_or_null_ext(routing->graph_node_map,
1679                                (char *) (&dst_id),
1680                                sizeof(int));
1681
1682   if (src_elm)
1683     src = src_elm->node;
1684
1685   if (dst_elm)
1686     dst = dst_elm->node;
1687
1688   /* add nodes if they don't exist in the graph */
1689   if (src_id == dst_id && src == NULL && dst == NULL) {
1690     src = route_graph_new_node(rc, src_id, -1);
1691     dst = src;
1692   } else {
1693     if (src == NULL) {
1694       src = route_graph_new_node(rc, src_id, -1);
1695     }
1696     if (dst == NULL) {
1697       dst = route_graph_new_node(rc, dst_id, -1);
1698     }
1699   }
1700
1701   /* add link as edge to graph */
1702   xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1703 }
1704
1705 static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
1706 {
1707   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1708
1709   xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1710
1711   xbt_node_t node = NULL;
1712   unsigned int cursor2;
1713   xbt_dynar_foreach(nodes, cursor2, node) {
1714     xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1715     xbt_edge_t edge = NULL;
1716     unsigned int cursor;
1717
1718     int found = 0;
1719     xbt_dynar_foreach(out_edges, cursor, edge) {
1720       xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1721       if (other_node == node) {
1722         found = 1;
1723         break;
1724       }
1725     }
1726
1727     if (!found) {
1728       route_extended_t e_route = xbt_new0(s_route_extended_t, 1);
1729       e_route->src_gateway = NULL;
1730       e_route->dst_gateway = NULL;
1731       e_route->generic_route.link_list =
1732           xbt_dynar_new(global_routing->size_of_link, NULL);
1733       xbt_dynar_push(e_route->generic_route.link_list,
1734                      &global_routing->loopback);
1735       xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1736     }
1737   }
1738 }
1739
1740 /* Business methods */
1741 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
1742 {
1743   xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
1744 }
1745
1746 static route_extended_t dijkstra_get_route(routing_component_t rc,
1747                                            const char *src,
1748                                            const char *dst)
1749 {
1750   xbt_assert1(rc && src
1751               && dst,
1752               "Invalid params for \"get_route\" function at AS \"%s\"",
1753               rc->name);
1754
1755   /* set utils vars */
1756   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1757
1758   generic_src_dst_check(rc, src, dst);
1759   int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
1760   int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
1761   xbt_assert2(src_id
1762               && dst_id,
1763               "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
1764               src, dst);
1765
1766   /* create a result route */
1767   route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1);
1768   new_e_route->generic_route.link_list =
1769       xbt_dynar_new(global_routing->size_of_link, NULL);
1770   new_e_route->src_gateway = NULL;
1771   new_e_route->dst_gateway = NULL;
1772
1773   int *pred_arr = NULL;
1774   int src_node_id = 0;
1775   int dst_node_id = 0;
1776   int *nodeid = NULL;
1777   int v;
1778   route_extended_t e_route;
1779   int size = 0;
1780   unsigned int cpt;
1781   void *link;
1782   xbt_dynar_t links = NULL;
1783   route_cache_element_t elm = NULL;
1784   xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1785
1786   /* Use the graph_node id mapping set to quickly find the nodes */
1787   graph_node_map_element_t src_elm =
1788       graph_node_map_search(routing, *src_id);
1789   graph_node_map_element_t dst_elm =
1790       graph_node_map_search(routing, *dst_id);
1791   xbt_assert2(src_elm != NULL
1792               && dst_elm != NULL, "src %d or dst %d does not exist",
1793               *src_id, *dst_id);
1794   src_node_id = ((graph_node_data_t)
1795                  xbt_graph_node_get_data(src_elm->node))->graph_id;
1796   dst_node_id = ((graph_node_data_t)
1797                  xbt_graph_node_get_data(dst_elm->node))->graph_id;
1798
1799   /* if the src and dst are the same *//* fixed, missing in the previous version */
1800   if (src_node_id == dst_node_id) {
1801
1802     xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1803     xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
1804     xbt_edge_t edge =
1805         xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
1806
1807     xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1808                 *dst_id);
1809
1810     e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1811
1812     links = e_route->generic_route.link_list;
1813     xbt_dynar_foreach(links, cpt, link) {
1814       xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1815     }
1816
1817     return new_e_route;
1818   }
1819
1820   if (routing->cached) {
1821     /*check if there is a cached predecessor list avail */
1822     elm = (route_cache_element_t)
1823         xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id),
1824                                  sizeof(int));
1825   }
1826
1827   if (elm) {                    /* cached mode and cache hit */
1828     pred_arr = elm->pred_arr;
1829   } else {                      /* not cached mode or cache miss */
1830     double *cost_arr = NULL;
1831     xbt_heap_t pqueue = NULL;
1832     int i = 0;
1833
1834     int nr_nodes = xbt_dynar_length(nodes);
1835     cost_arr = xbt_new0(double, nr_nodes);      /* link cost from src to other hosts */
1836     pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
1837     pqueue = xbt_heap_new(nr_nodes, xbt_free);
1838
1839     /* initialize */
1840     cost_arr[src_node_id] = 0.0;
1841
1842     for (i = 0; i < nr_nodes; i++) {
1843       if (i != src_node_id) {
1844         cost_arr[i] = DBL_MAX;
1845       }
1846
1847       pred_arr[i] = 0;
1848
1849       /* initialize priority queue */
1850       nodeid = xbt_new0(int, 1);
1851       *nodeid = i;
1852       xbt_heap_push(pqueue, nodeid, cost_arr[i]);
1853
1854     }
1855
1856     /* apply dijkstra using the indexes from the graph's node array */
1857     while (xbt_heap_size(pqueue) > 0) {
1858       int *v_id = xbt_heap_pop(pqueue);
1859       xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
1860       xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
1861       xbt_edge_t edge = NULL;
1862       unsigned int cursor;
1863
1864       xbt_dynar_foreach(out_edges, cursor, edge) {
1865         xbt_node_t u_node = xbt_graph_edge_get_target(edge);
1866         graph_node_data_t data = xbt_graph_node_get_data(u_node);
1867         int u_id = data->graph_id;
1868         route_extended_t tmp_e_route =
1869             (route_extended_t) xbt_graph_edge_get_data(edge);
1870         int cost_v_u = (tmp_e_route->generic_route.link_list)->used;    /* count of links, old model assume 1 */
1871
1872         if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
1873           pred_arr[u_id] = *v_id;
1874           cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
1875           nodeid = xbt_new0(int, 1);
1876           *nodeid = u_id;
1877           xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
1878         }
1879       }
1880
1881       /* free item popped from pqueue */
1882       xbt_free(v_id);
1883     }
1884
1885     xbt_free(cost_arr);
1886     xbt_heap_free(pqueue);
1887   }
1888
1889   /* compose route path with links */
1890   char *gw_src = NULL, *gw_dst =
1891       NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL;
1892
1893   for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
1894     xbt_node_t node_pred_v =
1895         xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
1896     xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
1897     xbt_edge_t edge =
1898         xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
1899
1900     xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id,
1901                 *dst_id);
1902
1903     prev_gw_src = gw_src;
1904     prev_gw_dst = gw_dst;
1905
1906     e_route = (route_extended_t) xbt_graph_edge_get_data(edge);
1907     gw_src = e_route->src_gateway;
1908     gw_dst = e_route->dst_gateway;
1909
1910     if (v == dst_node_id)
1911       first_gw = gw_dst;
1912
1913     if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
1914         && strcmp(gw_dst, prev_gw_src)) {
1915       xbt_dynar_t e_route_as_to_as =
1916           (*(global_routing->get_route)) (gw_dst, prev_gw_src);
1917       xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
1918                   gw_dst, prev_gw_src);
1919       links = e_route_as_to_as;
1920       int pos = 0;
1921       xbt_dynar_foreach(links, cpt, link) {
1922         xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos,
1923                             &link);
1924         pos++;
1925       }
1926     }
1927
1928     links = e_route->generic_route.link_list;
1929     xbt_dynar_foreach(links, cpt, link) {
1930       xbt_dynar_unshift(new_e_route->generic_route.link_list, &link);
1931     }
1932     size++;
1933   }
1934
1935   if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1936     new_e_route->src_gateway = xbt_strdup(gw_src);
1937     new_e_route->dst_gateway = xbt_strdup(first_gw);
1938   }
1939
1940   if (routing->cached && elm == NULL) {
1941     /* add to predecessor list of the current src-host to cache */
1942     elm = xbt_new0(struct route_cache_element, 1);
1943     elm->pred_arr = pred_arr;
1944     elm->size = size;
1945     xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int),
1946                      (xbt_set_elm_t) elm, &route_cache_elem_free);
1947   }
1948
1949   if (!routing->cached)
1950     xbt_free(pred_arr);
1951
1952   return new_e_route;
1953 }
1954
1955 static void dijkstra_finalize(routing_component_t rc)
1956 {
1957   routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1958
1959   if (routing) {
1960     xbt_graph_free_graph(routing->route_graph, &xbt_free,
1961                          &graph_edge_data_free, &xbt_free);
1962     xbt_dict_free(&routing->graph_node_map);
1963     if (routing->cached)
1964       xbt_dict_free(&routing->route_cache);
1965     /* Delete bypass dict */
1966     xbt_dict_free(&routing->generic_routing.bypassRoutes);
1967     /* Delete index dict */
1968     xbt_dict_free(&(routing->generic_routing.to_index));
1969     /* Delete structure */
1970     xbt_free(routing);
1971   }
1972 }
1973
1974 /* Creation routing model functions */
1975
1976 static void *model_dijkstra_both_create(int cached)
1977 {
1978   routing_component_dijkstra_t new_component =
1979       xbt_new0(s_routing_component_dijkstra_t, 1);
1980   new_component->generic_routing.set_processing_unit =
1981       generic_set_processing_unit;
1982   new_component->generic_routing.set_autonomous_system =
1983       generic_set_autonomous_system;
1984   new_component->generic_routing.set_route = model_dijkstra_both_set_route;
1985   new_component->generic_routing.set_ASroute = NULL; //TODO
1986   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1987   new_component->generic_routing.get_route = dijkstra_get_route;
1988   new_component->generic_routing.get_onelink_routes =
1989       dijkstra_get_onelink_routes;
1990   new_component->generic_routing.get_bypass_route =
1991       generic_get_bypassroute;
1992   new_component->generic_routing.finalize = dijkstra_finalize;
1993   new_component->cached = cached;
1994   new_component->generic_routing.to_index = xbt_dict_new();
1995   new_component->generic_routing.bypassRoutes = xbt_dict_new();
1996   new_component->generic_routing.parse_routes = xbt_dict_new();
1997   return new_component;
1998 }
1999
2000 static void *model_dijkstra_create(void)
2001 {
2002   return model_dijkstra_both_create(0);
2003 }
2004
2005 static void *model_dijkstracache_create(void)
2006 {
2007   return model_dijkstra_both_create(1);
2008 }
2009
2010 static void model_dijkstra_both_load(void)
2011 {
2012   /* use "surfxml_add_callback" to add a parse function call */
2013 }
2014
2015 static void model_dijkstra_both_unload(void)
2016 {
2017   /* use "surfxml_del_callback" to remove a parse function call */
2018 }
2019
2020 static void model_dijkstra_both_end(void)
2021 {
2022   routing_component_dijkstra_t routing =
2023       (routing_component_dijkstra_t) current_routing;
2024   xbt_dict_cursor_t cursor = NULL;
2025   char *key, *data, *end;
2026   const char *sep = "#";
2027   xbt_dynar_t keys;
2028   xbt_node_t node = NULL;
2029   unsigned int cursor2;
2030   xbt_dynar_t nodes = NULL;
2031   int src_id, dst_id;
2032   route_t route;
2033
2034   /* Create the topology graph */
2035   routing->route_graph = xbt_graph_new_graph(1, NULL);
2036   routing->graph_node_map = xbt_dict_new();
2037
2038   if (routing->cached)
2039     routing->route_cache = xbt_dict_new();
2040
2041   /* Put the routes in position */
2042   xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
2043     keys = xbt_str_split_str(key, sep);
2044     src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
2045     dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
2046     route_extended_t e_route =
2047         generic_new_extended_route(current_routing->hierarchy, data, 0);
2048     route_new_dijkstra(routing, src_id, dst_id, e_route);
2049     xbt_dynar_free(&keys);
2050   }
2051
2052   /* delete the parse table */
2053   xbt_dict_foreach(routing->generic_routing.parse_routes, cursor, key, data) {
2054     route = (route_t) data;
2055     xbt_dynar_free(&(route->link_list));
2056     xbt_free(data);
2057   }
2058
2059   /* delete parse dict */
2060   xbt_dict_free(&(routing->generic_routing.parse_routes));
2061
2062   /* Add the loopback if needed */
2063   if (current_routing->hierarchy == SURF_ROUTING_BASE)
2064     add_loopback_dijkstra(routing);
2065
2066   /* initialize graph indexes in nodes after graph has been built */
2067   nodes = xbt_graph_get_nodes(routing->route_graph);
2068
2069   xbt_dynar_foreach(nodes, cursor2, node) {
2070     graph_node_data_t data = xbt_graph_node_get_data(node);
2071     data->graph_id = cursor2;
2072   }
2073
2074 }
2075 static void model_dijkstra_both_set_route (routing_component_t rc, const char *src,
2076                      const char *dst, name_route_extended_t route)
2077 {
2078
2079
2080 }
2081
2082 #ifdef HAVE_PCRE_LIB
2083 /* ************************************************** */
2084 /* ************** RULE-BASED ROUTING **************** */
2085
2086 /* Routing model structure */
2087
2088 typedef struct {
2089   s_routing_component_t generic_routing;
2090   xbt_dict_t dict_processing_units;
2091   xbt_dict_t dict_autonomous_systems;
2092   xbt_dynar_t list_route;
2093   xbt_dynar_t list_ASroute;
2094 } s_routing_component_rulebased_t, *routing_component_rulebased_t;
2095
2096 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
2097 typedef struct s_rule_route_extended s_rule_route_extended_t,
2098     *rule_route_extended_t;
2099
2100 struct s_rule_route {
2101   xbt_dynar_t re_str_link;      // dynar of char*
2102   pcre *re_src;
2103   pcre *re_dst;
2104 };
2105
2106 struct s_rule_route_extended {
2107   s_rule_route_t generic_rule_route;
2108   char *re_src_gateway;
2109   char *re_dst_gateway;
2110 };
2111
2112 static void rule_route_free(void *e)
2113 {
2114   rule_route_t *elem = (rule_route_t *) (e);
2115   if (*elem) {
2116     xbt_dynar_free(&(*elem)->re_str_link);
2117     pcre_free((*elem)->re_src);
2118     pcre_free((*elem)->re_dst);
2119     xbt_free((*elem));
2120   }
2121   (*elem) = NULL;
2122 }
2123
2124 static void rule_route_extended_free(void *e)
2125 {
2126   rule_route_extended_t *elem = (rule_route_extended_t *) e;
2127   if (*elem) {
2128     xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
2129     pcre_free((*elem)->generic_rule_route.re_src);
2130     pcre_free((*elem)->generic_rule_route.re_dst);
2131     xbt_free((*elem)->re_src_gateway);
2132     xbt_free((*elem)->re_dst_gateway);
2133     xbt_free((*elem));
2134   }
2135 }
2136
2137 /* Parse routing model functions */
2138
2139 static void model_rulebased_set_processing_unit(routing_component_t rc,
2140                                                 const char *name)
2141 {
2142   routing_component_rulebased_t routing =
2143       (routing_component_rulebased_t) rc;
2144   xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
2145 }
2146
2147 static void model_rulebased_set_autonomous_system(routing_component_t rc,
2148                                                   const char *name)
2149 {
2150   routing_component_rulebased_t routing =
2151       (routing_component_rulebased_t) rc;
2152   xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
2153                NULL);
2154 }
2155
2156 static void model_rulebased_set_route(routing_component_t rc,
2157                                       const char *src, const char *dst,
2158                                       name_route_extended_t route)
2159 {
2160   routing_component_rulebased_t routing =
2161       (routing_component_rulebased_t) rc;
2162   rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
2163   const char *error;
2164   int erroffset;
2165   ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL);
2166   xbt_assert3(ruleroute->re_src,
2167               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2168               erroffset, src, error);
2169   ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL);
2170   xbt_assert3(ruleroute->re_src,
2171               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2172               erroffset, dst, error);
2173   ruleroute->re_str_link = route->generic_route.link_list;
2174   xbt_dynar_push(routing->list_route, &ruleroute);
2175   xbt_free(route);
2176 }
2177
2178 static void model_rulebased_set_ASroute(routing_component_t rc,
2179                                         const char *src, const char *dst,
2180                                         name_route_extended_t route)
2181 {
2182   routing_component_rulebased_t routing =
2183       (routing_component_rulebased_t) rc;
2184   rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
2185   const char *error;
2186   int erroffset;
2187   ruleroute_e->generic_rule_route.re_src =
2188       pcre_compile(src, 0, &error, &erroffset, NULL);
2189   xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2190               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2191               erroffset, src, error);
2192   ruleroute_e->generic_rule_route.re_dst =
2193       pcre_compile(dst, 0, &error, &erroffset, NULL);
2194   xbt_assert3(ruleroute_e->generic_rule_route.re_src,
2195               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
2196               erroffset, dst, error);
2197   ruleroute_e->generic_rule_route.re_str_link =
2198       route->generic_route.link_list;
2199   ruleroute_e->re_src_gateway = route->src_gateway;
2200   ruleroute_e->re_dst_gateway = route->dst_gateway;
2201   xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
2202   xbt_free(route->src_gateway);
2203   xbt_free(route->dst_gateway);
2204   xbt_free(route);
2205 }
2206
2207 static void model_rulebased_set_bypassroute(routing_component_t rc,
2208                                             const char *src,
2209                                             const char *dst,
2210                                             route_extended_t e_route)
2211 {
2212   xbt_die("bypass routing not supported for Route-Based model");
2213 }
2214
2215 #define BUFFER_SIZE 4096        /* result buffer size */
2216 #define OVECCOUNT 30            /* should be a multiple of 3 */
2217
2218 static char *remplace(char *value, const char **src_list, int src_size,
2219                       const char **dst_list, int dst_size)
2220 {
2221
2222   char result_result[BUFFER_SIZE];
2223   int i_result_buffer;
2224   int value_length = (int) strlen(value);
2225   int number = 0;
2226
2227   int i = 0;
2228   i_result_buffer = 0;
2229   do {
2230     if (value[i] == '$') {
2231       i++;                      // skip $
2232
2233       // find the number      
2234       int number_length = 0;
2235       while ('0' <= value[i + number_length]
2236              && value[i + number_length] <= '9') {
2237         number_length++;
2238       }
2239       xbt_assert2(number_length != 0,
2240                   "bad string parameter, no number indication, at offset: %d (\"%s\")",
2241                   i, value);
2242
2243       // solve number
2244       number = atoi(value + i);
2245       i = i + number_length;
2246       xbt_assert2(i + 2 < value_length,
2247                   "bad string parameter, too few chars, at offset: %d (\"%s\")",
2248                   i, value);
2249
2250       // solve the indication
2251       const char **param_list;
2252       int param_size;
2253       if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
2254         param_list = src_list;
2255         param_size = src_size;
2256       } else if (value[i] == 'd' && value[i + 1] == 's'
2257                  && value[i + 2] == 't') {
2258         param_list = dst_list;
2259         param_size = dst_size;
2260       } else {
2261         xbt_assert2(0,
2262                     "bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",
2263                     i, value);
2264       }
2265       i = i + 3;
2266
2267       xbt_assert4(param_size >= number,
2268                   "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",
2269                   i, value, param_size, number);
2270
2271       const char *param = param_list[number];
2272       int size = strlen(param);
2273       int cp;
2274       for (cp = 0; cp < size; cp++) {
2275         result_result[i_result_buffer] = param[cp];
2276         i_result_buffer++;
2277         if (i_result_buffer >= BUFFER_SIZE)
2278           break;
2279       }
2280     } else {
2281       result_result[i_result_buffer] = value[i];
2282       i_result_buffer++;
2283       i++;                      // next char
2284     }
2285
2286   } while (i < value_length && i_result_buffer < BUFFER_SIZE);
2287
2288   xbt_assert2(i_result_buffer < BUFFER_SIZE,
2289               "solving string \"%s\", small buffer size (%d)", value,
2290               BUFFER_SIZE);
2291   result_result[i_result_buffer] = 0;
2292   return xbt_strdup(result_result);
2293 }
2294
2295 static route_extended_t rulebased_get_route(routing_component_t rc,
2296                                             const char *src,
2297                                             const char *dst);
2298 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
2299 {
2300   xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
2301   routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
2302
2303   xbt_dict_cursor_t c1 = NULL;
2304   char *k1, *d1;
2305
2306   //find router
2307   char *router = NULL;
2308   xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2309     if (strstr (k1, "router")){
2310       router = k1;
2311     }
2312   }
2313   if (!router){
2314     xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2315   }
2316
2317   xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
2318     route_extended_t route = rulebased_get_route (rc, router, k1);
2319
2320     int number_of_links = xbt_dynar_length(route->generic_route.link_list);
2321     if (number_of_links != 3) {
2322       xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
2323     }
2324
2325     void *link_ptr;
2326     xbt_dynar_get_cpy (route->generic_route.link_list, 2, &link_ptr);
2327     onelink_t onelink = xbt_new0 (s_onelink_t, 1);
2328     onelink->src = xbt_strdup (k1);
2329     onelink->dst = xbt_strdup (router);
2330     onelink->link_ptr = link_ptr;
2331     xbt_dynar_push (ret, &onelink);
2332   }
2333   return ret;
2334 }
2335
2336 /* Business methods */
2337 static route_extended_t rulebased_get_route(routing_component_t rc,
2338                                             const char *src,
2339                                             const char *dst)
2340 {
2341   xbt_assert1(rc && src
2342               && dst,
2343               "Invalid params for \"get_route\" function at AS \"%s\"",
2344               rc->name);
2345
2346   /* set utils vars */
2347   routing_component_rulebased_t routing =
2348       (routing_component_rulebased_t) rc;
2349
2350   int are_processing_units;
2351   xbt_dynar_t rule_list;
2352   if (xbt_dict_get_or_null(routing->dict_processing_units, src)
2353       && xbt_dict_get_or_null(routing->dict_processing_units, dst)) {
2354     are_processing_units = 1;
2355     rule_list = routing->list_route;
2356   } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src)
2357              && xbt_dict_get_or_null(routing->dict_autonomous_systems,
2358                                      dst)) {
2359     are_processing_units = 0;
2360     rule_list = routing->list_ASroute;
2361   } else
2362     xbt_assert2(NULL,
2363                 "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
2364                 src, dst);
2365
2366   int rc_src = -1;
2367   int rc_dst = -1;
2368   int src_length = (int) strlen(src);
2369   int dst_length = (int) strlen(dst);
2370
2371   xbt_dynar_t links_list =
2372       xbt_dynar_new(global_routing->size_of_link, NULL);
2373
2374   rule_route_t ruleroute;
2375   unsigned int cpt;
2376   int ovector_src[OVECCOUNT];
2377   int ovector_dst[OVECCOUNT];
2378   const char **list_src = NULL;
2379   const char **list_dst = NULL;
2380   xbt_dynar_foreach(rule_list, cpt, ruleroute) {
2381     rc_src =
2382         pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0,
2383                   ovector_src, OVECCOUNT);
2384     if (rc_src >= 0) {
2385       rc_dst =
2386           pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0,
2387                     ovector_dst, OVECCOUNT);
2388       if (rc_dst >= 0) {
2389         xbt_assert1(!pcre_get_substring_list
2390                     (src, ovector_src, rc_src, &list_src),
2391                     "error solving substring list for src \"%s\"", src);
2392         xbt_assert1(!pcre_get_substring_list
2393                     (dst, ovector_dst, rc_dst, &list_dst),
2394                     "error solving substring list for src \"%s\"", dst);
2395         char *link_name;
2396         xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
2397           char *new_link_name =
2398               remplace(link_name, list_src, rc_src, list_dst, rc_dst);
2399           void *link =
2400               xbt_dict_get_or_null(surf_network_model->resource_set,
2401                                    new_link_name);
2402           if (link)
2403             xbt_dynar_push(links_list, &link);
2404           else
2405             THROW1(mismatch_error, 0, "Link %s not found", new_link_name);
2406           xbt_free(new_link_name);
2407         }
2408       }
2409     }
2410     if (rc_src >= 0 && rc_dst >= 0)
2411       break;
2412   }
2413
2414   route_extended_t new_e_route = NULL;
2415   if (rc_src >= 0 && rc_dst >= 0) {
2416     new_e_route = xbt_new0(s_route_extended_t, 1);
2417     new_e_route->generic_route.link_list = links_list;
2418   } else if (!strcmp(src, dst) && are_processing_units) {
2419     new_e_route = xbt_new0(s_route_extended_t, 1);
2420     xbt_dynar_push(links_list, &(global_routing->loopback));
2421     new_e_route->generic_route.link_list = links_list;
2422   } else {
2423     xbt_dynar_free(&link_list);
2424   }
2425
2426   if (!are_processing_units && new_e_route) {
2427     rule_route_extended_t ruleroute_extended =
2428         (rule_route_extended_t) ruleroute;
2429     new_e_route->src_gateway =
2430         remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
2431                  list_dst, rc_dst);
2432     new_e_route->dst_gateway =
2433         remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
2434                  list_dst, rc_dst);
2435   }
2436
2437   if (list_src)
2438     pcre_free_substring_list(list_src);
2439   if (list_dst)
2440     pcre_free_substring_list(list_dst);
2441
2442   return new_e_route;
2443 }
2444
2445 static route_extended_t rulebased_get_bypass_route(routing_component_t rc,
2446                                                    const char *src,
2447                                                    const char *dst)
2448 {
2449   return NULL;
2450 }
2451
2452 static void rulebased_finalize(routing_component_t rc)
2453 {
2454   routing_component_rulebased_t routing =
2455       (routing_component_rulebased_t) rc;
2456   if (routing) {
2457     xbt_dict_free(&routing->dict_processing_units);
2458     xbt_dict_free(&routing->dict_autonomous_systems);
2459     xbt_dynar_free(&routing->list_route);
2460     xbt_dynar_free(&routing->list_ASroute);
2461     /* Delete structure */
2462     xbt_free(routing);
2463   }
2464 }
2465
2466 /* Creation routing model functions */
2467 static void *model_rulebased_create(void)
2468 {
2469   routing_component_rulebased_t new_component =
2470       xbt_new0(s_routing_component_rulebased_t, 1);
2471   new_component->generic_routing.set_processing_unit =
2472       model_rulebased_set_processing_unit;
2473   new_component->generic_routing.set_autonomous_system =
2474       model_rulebased_set_autonomous_system;
2475   new_component->generic_routing.set_route = model_rulebased_set_route;
2476   new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
2477   new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
2478   new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
2479   new_component->generic_routing.get_route = rulebased_get_route;
2480   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;       //rulebased_get_bypass_route;
2481   new_component->generic_routing.finalize = rulebased_finalize;
2482   /* initialization of internal structures */
2483   new_component->dict_processing_units = xbt_dict_new();
2484   new_component->dict_autonomous_systems = xbt_dict_new();
2485   new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
2486   new_component->list_ASroute =
2487       xbt_dynar_new(sizeof(rule_route_extended_t),
2488                     &rule_route_extended_free);
2489   return new_component;
2490 }
2491
2492 static void model_rulebased_load(void)
2493 {
2494   /* use "surfxml_add_callback" to add a parse function call */
2495 }
2496
2497 static void model_rulebased_unload(void)
2498 {
2499   /* use "surfxml_del_callback" to remove a parse function call */
2500 }
2501
2502 static void model_rulebased_end(void)
2503 {
2504 }
2505
2506 #endif                          /* HAVE_PCRE_LIB */
2507
2508 /* ************************************************************************** */
2509 /* ******************************* NO ROUTING ******************************* */
2510
2511 /* Routing model structure */
2512 typedef struct {
2513   s_routing_component_t generic_routing;
2514 } s_routing_component_none_t, *routing_component_none_t;
2515
2516 /* Business methods */
2517 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc)
2518 {
2519   return NULL;
2520 }
2521
2522 static route_extended_t none_get_route(routing_component_t rc,
2523                                        const char *src, const char *dst)
2524 {
2525   return NULL;
2526 }
2527
2528 static route_extended_t none_get_bypass_route(routing_component_t rc,
2529                                               const char *src,
2530                                               const char *dst)
2531 {
2532   return NULL;
2533 }
2534
2535 static void none_finalize(routing_component_t rc)
2536 {
2537   xbt_free(rc);
2538 }
2539
2540 static void none_set_processing_unit(routing_component_t rc,
2541                                      const char *name)
2542 {
2543 }
2544
2545 static void none_set_autonomous_system(routing_component_t rc,
2546                                        const char *name)
2547 {
2548 }
2549
2550 /* Creation routing model functions */
2551 static void *model_none_create(void)
2552 {
2553   routing_component_none_t new_component =
2554       xbt_new0(s_routing_component_none_t, 1);
2555   new_component->generic_routing.set_processing_unit =
2556       none_set_processing_unit;
2557   new_component->generic_routing.set_autonomous_system =
2558       none_set_autonomous_system;
2559   new_component->generic_routing.set_route = NULL;
2560   new_component->generic_routing.set_ASroute = NULL;
2561   new_component->generic_routing.set_bypassroute = NULL;
2562   new_component->generic_routing.get_route = none_get_route;
2563   new_component->generic_routing.get_onelink_routes =
2564       none_get_onelink_routes;
2565   new_component->generic_routing.get_bypass_route = none_get_bypass_route;
2566   new_component->generic_routing.finalize = none_finalize;
2567   return new_component;
2568 }
2569
2570 static void model_none_load(void)
2571 {
2572 }
2573
2574 static void model_none_unload(void)
2575 {
2576 }
2577
2578 static void model_none_end(void)
2579 {
2580 }
2581
2582 /* ************************************************** */
2583 /* ********** PATERN FOR NEW ROUTING **************** */
2584
2585 /* The minimal configuration of a new routing model need the next functions,
2586  * also you need to set at the start of the file, the new model in the model
2587  * list. Remember keep the null ending of the list.
2588  */
2589 /*** Routing model structure ***/
2590 // typedef struct {
2591 //   s_routing_component_t generic_routing;
2592 //   /* things that your routing model need */
2593 // } s_routing_component_NEW_t,*routing_component_NEW_t;
2594
2595 /*** Parse routing model functions ***/
2596 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
2597 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
2598 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
2599 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
2600 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
2601
2602 /*** Business methods ***/
2603 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2604 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
2605 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
2606
2607 /*** Creation routing model functions ***/
2608 // static void* model_NEW_create(void) {
2609 //   routing_component_NEW_t new_component =  xbt_new0(s_routing_component_NEW_t,1);
2610 //   new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
2611 //   new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
2612 //   new_component->generic_routing.set_route = model_NEW_set_route;
2613 //   new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
2614 //   new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
2615 //   new_component->generic_routing.get_route = NEW_get_route;
2616 //   new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
2617 //   new_component->generic_routing.finalize = NEW_finalize;
2618 //   /* initialization of internal structures */
2619 //   return new_component;
2620 // } /* mandatory */
2621 // static void  model_NEW_load(void) {}   /* mandatory */
2622 // static void  model_NEW_unload(void) {} /* mandatory */
2623 // static void  model_NEW_end(void) {}    /* mandatory */
2624
2625 /* ************************************************************************** */
2626 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
2627
2628 static void generic_set_processing_unit(routing_component_t rc,
2629                                         const char *name)
2630 {
2631   DEBUG1("Load process unit \"%s\"", name);
2632   int *id = xbt_new0(int, 1);
2633   xbt_dict_t _to_index;
2634   _to_index = current_routing->to_index;
2635   *id = xbt_dict_length(_to_index);
2636   xbt_dict_set(_to_index, name, id, xbt_free);
2637 }
2638
2639 static void generic_set_autonomous_system(routing_component_t rc,
2640                                           const char *name)
2641 {
2642   DEBUG1("Load Autonomous system \"%s\"", name);
2643   int *id = xbt_new0(int, 1);
2644   xbt_dict_t _to_index;
2645   _to_index = current_routing->to_index;
2646   *id = xbt_dict_length(_to_index);
2647   xbt_dict_set(_to_index, name, id, xbt_free);
2648 }
2649
2650 static int surf_pointer_resource_cmp(const void *a, const void *b) {
2651         if(a == b)
2652                 return 0;
2653         return 1;
2654 }
2655
2656 static int surf_link_resource_cmp(const void *a, const void *b) {
2657         if( memcmp(a,b,global_routing->size_of_link) == 0 );
2658                 return 0;
2659         return 1;
2660 }
2661
2662 static void generic_set_route(routing_component_t rc, const char *src,
2663                               const char *dst, name_route_t route)
2664 {
2665   DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst);
2666   xbt_dict_t _parse_routes;
2667   xbt_dict_t _to_index;
2668   char *route_name;
2669   int *src_id, *dst_id,i;
2670   unsigned long nb_links = xbt_dynar_length(route->link_name_list);
2671
2672   _to_index = current_routing->to_index;
2673   _parse_routes = current_routing->parse_routes;
2674
2675   src_id = xbt_dict_get_or_null(_to_index, src);
2676   dst_id = xbt_dict_get_or_null(_to_index, dst);
2677   route_name = bprintf("%d#%d", *src_id, *dst_id);
2678
2679   route_t route_to_test;
2680   route_t route_sym = xbt_new0(s_route_t, 1);
2681
2682   xbt_assert2(src_id
2683               && dst_id, "Network elements %s or %s not found", src, dst);
2684
2685   xbt_assert2(xbt_dynar_length(route->link_name_list) > 0,
2686               "Invalid count of links, must be greater than zero (%s,%s)",
2687               src, dst);
2688
2689   route_to_test = xbt_dict_get_or_null(_parse_routes, route_name);
2690
2691   if(route_to_test)
2692           xbt_assert2(!xbt_dynar_compare(
2693                   (void*)route->link_name_list,
2694                   (void*)route_to_test->link_list,
2695                   (int_f_cpvoid_cpvoid_t) surf_link_resource_cmp),
2696                   "The route between \"%s\" and \"%s\" already exist", src,dst);
2697   else
2698   {
2699           xbt_dict_set(_parse_routes, bprintf("%d#%d", *src_id, *dst_id), route, NULL);
2700   }
2701
2702   if(A_surfxml_route_symetrical == A_surfxml_route_symetrical_YES)
2703   {
2704           route_sym->link_list = xbt_dynar_new(sizeof(char *),NULL);
2705
2706           for(i=nb_links ; i>0 ; i--)
2707           {
2708                  char *link_name = xbt_new0(char,strlen(xbt_dynar_get_as(route->link_name_list, i-1, char *)));
2709                  link_name = xbt_strdup(xbt_dynar_get_as(route->link_name_list, i-1, char *));
2710                  xbt_dynar_push_as(route_sym->link_list ,char *, link_name);
2711           }
2712           DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
2713
2714           route_to_test = xbt_dict_get_or_null(_parse_routes, bprintf("%d#%d",*dst_id, *src_id));
2715
2716           if(route_to_test)
2717                   xbt_assert2(!xbt_dynar_compare(
2718                           (void*)route_sym->link_list,
2719                           (void*)route_to_test->link_list,
2720                           (int_f_cpvoid_cpvoid_t) strcmp),
2721                   "The route between \"%s\" and \"%s\" already exist", dst,src);
2722           else
2723           {
2724                   xbt_dict_set(_parse_routes, bprintf("%d#%d",*dst_id, *src_id), route_sym, NULL);
2725           }
2726   }
2727
2728   xbt_free(route_name);
2729 }
2730
2731 static void generic_set_ASroute(routing_component_t rc, const char *src,
2732                                 const char *dst, route_extended_t e_route)
2733 {
2734   DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
2735          e_route->src_gateway, dst, e_route->dst_gateway);
2736
2737   xbt_dict_t _parse_routes;
2738   xbt_dict_t _to_index;
2739   char *route_name;
2740   int *src_id, *dst_id;
2741   _to_index = current_routing->to_index;
2742   _parse_routes = current_routing->parse_routes;
2743
2744   src_id = xbt_dict_get_or_null(_to_index, src);
2745   dst_id = xbt_dict_get_or_null(_to_index, dst);
2746   route_name = bprintf("%d#%d", *src_id, *dst_id);
2747   route_t route_to_test;
2748
2749   xbt_assert2(src_id
2750               && dst_id, "Network elements %s or %s not found", src, dst);
2751
2752   xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2753               "Invalid count of links, must be greater than zero (%s,%s)",
2754               src, dst);
2755
2756   route_to_test = xbt_dict_get_or_null(_parse_routes, route_name);
2757
2758   if(route_to_test)
2759   xbt_assert4(!xbt_dynar_compare(
2760                   (void*) (&e_route->generic_route)->link_list,
2761                   (void*) route_to_test->link_list,
2762                   (int_f_cpvoid_cpvoid_t) strcmp),
2763                   "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2764                                 src, e_route->src_gateway, dst, e_route->dst_gateway);
2765
2766   route_name = bprintf("%d#%d", *src_id, *dst_id);
2767   xbt_dict_set(_parse_routes, route_name, e_route, NULL);
2768   xbt_free(route_name);
2769
2770   unsigned long nb_links = xbt_dynar_length(e_route->generic_route.link_list);
2771
2772   if(A_surfxml_ASroute_symetrical == A_surfxml_ASroute_symetrical_YES)
2773   {
2774           int i;
2775           route_extended_t route_sym = xbt_new0(s_route_extended_t, 1);
2776           route_sym->generic_route.link_list = xbt_dynar_new(sizeof(char *),NULL);
2777           for(i=nb_links ; i>0 ; i--)
2778           {
2779                  char *link_name = xbt_new0(char,strlen(xbt_dynar_get_as(e_route->generic_route.link_list, i-1, char *)));
2780                  link_name = bprintf("%s",xbt_dynar_get_as(e_route->generic_route.link_list, i-1, char *));
2781                  xbt_dynar_push_as(route_sym->generic_route.link_list ,char *, link_name);
2782           }
2783           route_sym->src_gateway = xbt_new0( char,strlen(e_route->dst_gateway) );
2784           route_sym->src_gateway = bprintf("%s",e_route->dst_gateway);
2785           route_sym->dst_gateway = xbt_new0( char,strlen(e_route->src_gateway) );
2786           route_sym->dst_gateway = bprintf("%s",e_route->src_gateway);
2787           DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",dst, route_sym->src_gateway,src,route_sym->dst_gateway);
2788
2789           route_to_test = xbt_dict_get_or_null(_parse_routes, bprintf("%d#%d", *dst_id, *src_id));
2790           if(route_to_test)
2791           xbt_assert4(!xbt_dynar_compare(
2792                   (void*) (&route_sym->generic_route)->link_list,
2793                   (void*) route_to_test->link_list,
2794                   (int_f_cpvoid_cpvoid_t) strcmp),
2795                   "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2796                                                   dst, route_sym->src_gateway, src, route_sym->dst_gateway);
2797           xbt_dict_set(_parse_routes, bprintf("%d#%d", *dst_id, *src_id), route_sym, NULL);
2798
2799    }
2800 }
2801
2802 static void generic_set_bypassroute(routing_component_t rc,
2803                                     const char *src, const char *dst,
2804                                     route_extended_t e_route)
2805 {
2806   DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
2807   xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2808   char *route_name;
2809
2810   route_name = bprintf("%s#%s", src, dst);
2811   xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
2812               "Invalid count of links, must be greater than zero (%s,%s)",
2813               src, dst);
2814   xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
2815               "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
2816               src, e_route->src_gateway, dst, e_route->dst_gateway);
2817
2818   route_extended_t new_e_route =
2819       generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0);
2820   xbt_dynar_free(&(e_route->generic_route.link_list));
2821   xbt_free(e_route);
2822
2823   xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
2824                (void (*)(void *)) generic_free_extended_route);
2825   xbt_free(route_name);
2826 }
2827
2828 /* ************************************************************************** */
2829 /* *********************** GENERIC BUSINESS METHODS ************************* */
2830
2831 static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc)
2832 {
2833   xbt_die("\"generic_get_onelink_routes\" not implemented yet");
2834 }
2835
2836 static route_extended_t generic_get_bypassroute(routing_component_t rc,
2837                                                 const char *src,
2838                                                 const char *dst)
2839 {
2840   xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
2841   routing_component_t src_as, dst_as;
2842   int index_src, index_dst;
2843   xbt_dynar_t path_src = NULL;
2844   xbt_dynar_t path_dst = NULL;
2845   routing_component_t current = NULL;
2846   routing_component_t *current_src = NULL;
2847   routing_component_t *current_dst = NULL;
2848
2849   /* (1) find the as where the src and dst are located */
2850   src_as = ((network_element_info_t)
2851             xbt_dict_get_or_null(global_routing->where_network_elements,
2852                                  src))->rc_component;
2853   dst_as = ((network_element_info_t)
2854             xbt_dict_get_or_null(global_routing->where_network_elements,
2855                                  dst))->rc_component;
2856   xbt_assert2(src_as
2857               && dst_as,
2858               "Ask for route \"from\"(%s) or \"to\"(%s) no found", src,
2859               dst);
2860
2861   /* (2) find the path to the root routing component */
2862   path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
2863   current = src_as;
2864   while (current != NULL) {
2865     xbt_dynar_push(path_src, &current);
2866     current = current->routing_father;
2867   }
2868   path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
2869   current = dst_as;
2870   while (current != NULL) {
2871     xbt_dynar_push(path_dst, &current);
2872     current = current->routing_father;
2873   }
2874
2875   /* (3) find the common father */
2876   index_src = (path_src->used) - 1;
2877   index_dst = (path_dst->used) - 1;
2878   current_src = xbt_dynar_get_ptr(path_src, index_src);
2879   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2880   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
2881     routing_component_t *tmp_src, *tmp_dst;
2882     tmp_src = xbt_dynar_pop_ptr(path_src);
2883     tmp_dst = xbt_dynar_pop_ptr(path_dst);
2884     index_src--;
2885     index_dst--;
2886     current_src = xbt_dynar_get_ptr(path_src, index_src);
2887     current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
2888   }
2889
2890   int max_index_src = (path_src->used) - 1;
2891   int max_index_dst = (path_dst->used) - 1;
2892
2893   int max_index = max(max_index_src, max_index_dst);
2894   int i, max;
2895
2896   route_extended_t e_route_bypass = NULL;
2897
2898   for (max = 0; max <= max_index; max++) {
2899     for (i = 0; i < max; i++) {
2900       if (i <= max_index_src && max <= max_index_dst) {
2901         char *route_name = bprintf("%s#%s",
2902                                    (*(routing_component_t *)
2903                                     (xbt_dynar_get_ptr
2904                                      (path_src, i)))->name,
2905                                    (*(routing_component_t *)
2906                                     (xbt_dynar_get_ptr
2907                                      (path_dst, max)))->name);
2908         e_route_bypass =
2909             xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2910         xbt_free(route_name);
2911       }
2912       if (e_route_bypass)
2913         break;
2914       if (max <= max_index_src && i <= max_index_dst) {
2915         char *route_name = bprintf("%s#%s",
2916                                    (*(routing_component_t *)
2917                                     (xbt_dynar_get_ptr
2918                                      (path_src, max)))->name,
2919                                    (*(routing_component_t *)
2920                                     (xbt_dynar_get_ptr
2921                                      (path_dst, i)))->name);
2922         e_route_bypass =
2923             xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2924         xbt_free(route_name);
2925       }
2926       if (e_route_bypass)
2927         break;
2928     }
2929
2930     if (e_route_bypass)
2931       break;
2932
2933     if (max <= max_index_src && max <= max_index_dst) {
2934       char *route_name = bprintf("%s#%s",
2935                                  (*(routing_component_t *)
2936                                   (xbt_dynar_get_ptr
2937                                    (path_src, max)))->name,
2938                                  (*(routing_component_t *)
2939                                   (xbt_dynar_get_ptr
2940                                    (path_dst, max)))->name);
2941       e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
2942       xbt_free(route_name);
2943     }
2944     if (e_route_bypass)
2945       break;
2946   }
2947
2948   xbt_dynar_free(&path_src);
2949   xbt_dynar_free(&path_dst);
2950
2951   route_extended_t new_e_route = NULL;
2952
2953   if (e_route_bypass) {
2954     void *link;
2955     unsigned int cpt = 0;
2956     new_e_route = xbt_new0(s_route_extended_t, 1);
2957     new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
2958     new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
2959     new_e_route->generic_route.link_list =
2960         xbt_dynar_new(global_routing->size_of_link, NULL);
2961     xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
2962       xbt_dynar_push(new_e_route->generic_route.link_list, &link);
2963     }
2964   }
2965
2966   return new_e_route;
2967 }
2968
2969 /* ************************************************************************** */
2970 /* ************************* GENERIC AUX FUNCTIONS ************************** */
2971
2972 static route_extended_t
2973 generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
2974                            void *data, int order)
2975 {
2976
2977   char *link_name;
2978   route_extended_t e_route, new_e_route;
2979   route_t route;
2980   unsigned int cpt;
2981   xbt_dynar_t links = NULL, links_id = NULL;
2982
2983   new_e_route = xbt_new0(s_route_extended_t, 1);
2984   new_e_route->generic_route.link_list =
2985       xbt_dynar_new(global_routing->size_of_link, NULL);
2986   new_e_route->src_gateway = NULL;
2987   new_e_route->dst_gateway = NULL;
2988
2989   xbt_assert0(hierarchy == SURF_ROUTING_BASE
2990               || hierarchy == SURF_ROUTING_RECURSIVE,
2991               "the hierarchy type is not defined");
2992
2993   if (hierarchy == SURF_ROUTING_BASE) {
2994
2995     route = (route_t) data;
2996     links = route->link_list;
2997
2998   } else if (hierarchy == SURF_ROUTING_RECURSIVE) {
2999
3000     e_route = (route_extended_t) data;
3001     xbt_assert0(e_route->src_gateway
3002                 && e_route->dst_gateway, "bad gateway, is null");
3003     links = e_route->generic_route.link_list;
3004
3005     /* remeber not erase the gateway names */
3006     new_e_route->src_gateway = e_route->src_gateway;
3007     new_e_route->dst_gateway = e_route->dst_gateway;
3008   }
3009
3010   links_id = new_e_route->generic_route.link_list;
3011
3012   xbt_dynar_foreach(links, cpt, link_name) {
3013
3014     void *link =
3015         xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
3016     if (link) {
3017       if (order)
3018         xbt_dynar_push(links_id, &link);
3019       else
3020         xbt_dynar_unshift(links_id, &link);
3021     } else
3022       THROW1(mismatch_error, 0, "Link %s not found", link_name);
3023   }
3024
3025   return new_e_route;
3026 }
3027
3028 static void generic_free_route(route_t route)
3029 {
3030   if (route) {
3031     xbt_dynar_free(&(route->link_list));
3032     xbt_free(route);
3033   }
3034 }
3035
3036 static void generic_free_extended_route(route_extended_t e_route)
3037 {
3038   if (e_route) {
3039     xbt_dynar_free(&(e_route->generic_route.link_list));
3040     if (e_route->src_gateway)
3041       xbt_free(e_route->src_gateway);
3042     if (e_route->dst_gateway)
3043       xbt_free(e_route->dst_gateway);
3044     xbt_free(e_route);
3045   }
3046 }
3047
3048 static routing_component_t generic_as_exist(routing_component_t find_from,
3049                                             routing_component_t to_find)
3050 {
3051   //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3052   xbt_dict_cursor_t cursor = NULL;
3053   char *key;
3054   int found = 0;
3055   routing_component_t elem;
3056   xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
3057     if (to_find == elem || generic_as_exist(elem, to_find)) {
3058       found = 1;
3059       break;
3060     }
3061   }
3062   if (found)
3063     return to_find;
3064   return NULL;
3065 }
3066
3067 static routing_component_t
3068 generic_autonomous_system_exist(routing_component_t rc, char *element)
3069 {
3070   //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
3071   routing_component_t element_as, result, elem;
3072   xbt_dict_cursor_t cursor = NULL;
3073   char *key;
3074   element_as = ((network_element_info_t)
3075                 xbt_dict_get_or_null
3076                 (global_routing->where_network_elements,
3077                  element))->rc_component;
3078   result = ((routing_component_t) - 1);
3079   if (element_as != rc)
3080     result = generic_as_exist(rc, element_as);
3081
3082   int found = 0;
3083   if (result) {
3084     xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
3085       found = !strcmp(elem->name, element);
3086       if (found)
3087         break;
3088     }
3089     if (found)
3090       return element_as;
3091   }
3092   return NULL;
3093 }
3094
3095 static routing_component_t
3096 generic_processing_units_exist(routing_component_t rc, char *element)
3097 {
3098   routing_component_t element_as;
3099   element_as = ((network_element_info_t)
3100                 xbt_dict_get_or_null
3101                 (global_routing->where_network_elements,
3102                  element))->rc_component;
3103   if (element_as == rc)
3104     return element_as;
3105   return generic_as_exist(rc, element_as);
3106 }
3107
3108 static void generic_src_dst_check(routing_component_t rc, const char *src,
3109                                   const char *dst)
3110 {
3111
3112   routing_component_t src_as = ((network_element_info_t)
3113                                 xbt_dict_get_or_null
3114                                 (global_routing->where_network_elements,
3115                                  src))->rc_component;
3116   routing_component_t dst_as = ((network_element_info_t)
3117                                 xbt_dict_get_or_null
3118                                 (global_routing->where_network_elements,
3119                                  dst))->rc_component;
3120
3121   xbt_assert3(src_as != NULL && dst_as != NULL,
3122               "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
3123               src, dst, rc->name);
3124   xbt_assert4(src_as == dst_as,
3125               "The src(%s in %s) and dst(%s in %s) are in differents AS",
3126               src, src_as->name, dst, dst_as->name);
3127   xbt_assert2(rc == dst_as,
3128               "The routing component of src and dst is not the same as the network elements belong (%s==%s)",
3129               rc->name, dst_as->name);
3130 }
3131
3132 static void routing_parse_Sconfig(void)
3133 {
3134   //TODO
3135   DEBUG0("WARNING tag config not yet implemented.");
3136   DEBUG1("Configuration name = %s",A_surfxml_config_id);
3137 }
3138
3139 static void routing_parse_Econfig(void)
3140 {
3141   //TODO
3142   xbt_dict_cursor_t cursor = NULL;
3143   char *key;
3144   char *elem;
3145   xbt_dict_foreach(current_property_set, cursor, key, elem) {
3146           DEBUG2("property : %s = %s",key,elem);
3147         }
3148 }
3149
3150 static void routing_parse_Scluster(void)
3151 {
3152   static int AX_ptr = 0;
3153
3154   char *cluster_id = A_surfxml_cluster_id;
3155   char *cluster_prefix = A_surfxml_cluster_prefix;
3156   char *cluster_suffix = A_surfxml_cluster_suffix;
3157   char *cluster_radical = A_surfxml_cluster_radical;
3158   char *cluster_power = A_surfxml_cluster_power;
3159   char *cluster_bw = A_surfxml_cluster_bw;
3160   char *cluster_lat = A_surfxml_cluster_lat;
3161   char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
3162   char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
3163   char *host_id, *groups, *link_id = NULL;
3164   char *router_id, *link_router, *link_backbone, *route_src_dst;
3165   unsigned int iter;
3166   int start, end, i;
3167   xbt_dynar_t radical_elements;
3168   xbt_dynar_t radical_ends;
3169   int cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
3170   int cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
3171
3172 #ifndef HAVE_PCRE_LIB
3173   xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
3174   char *route_src, *route_dst;
3175   int j;
3176 #endif
3177
3178   static unsigned int surfxml_buffer_stack_stack_ptr = 1;
3179   static unsigned int surfxml_buffer_stack_stack[1024];
3180
3181   surfxml_buffer_stack_stack[0] = 0;
3182
3183   surfxml_bufferstack_push(1);
3184
3185   SURFXML_BUFFER_SET(AS_id, cluster_id);
3186 #ifdef HAVE_PCRE_LIB
3187   SURFXML_BUFFER_SET(AS_routing, "RuleBased");
3188   DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">", cluster_id);
3189 #else
3190   SURFXML_BUFFER_SET(AS_routing, "Full");
3191   DEBUG1("<AS id=\"%s\"\trouting=\"Full\">", cluster_id);
3192 #endif
3193   SURFXML_START_TAG(AS);
3194
3195   radical_elements = xbt_str_split(cluster_radical, ",");
3196   xbt_dynar_foreach(radical_elements, iter, groups) {
3197     radical_ends = xbt_str_split(groups, "-");
3198     switch (xbt_dynar_length(radical_ends)) {
3199     case 1:
3200       surf_parse_get_int(&start,
3201                          xbt_dynar_get_as(radical_ends, 0, char *));
3202       host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
3203 #ifndef HAVE_PCRE_LIB
3204       xbt_dynar_push_as(tab_elements_num, int, start);
3205 #endif
3206       link_id = bprintf("%s_link_%d", cluster_id, start);
3207
3208       DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3209       A_surfxml_host_state = A_surfxml_host_state_ON;
3210       SURFXML_BUFFER_SET(host_id, host_id);
3211       SURFXML_BUFFER_SET(host_power, cluster_power);
3212       SURFXML_BUFFER_SET(host_availability, "1.0");
3213       SURFXML_BUFFER_SET(host_availability_file, "");
3214       SURFXML_BUFFER_SET(host_state_file, "");
3215       SURFXML_START_TAG(host);
3216       SURFXML_END_TAG(host);
3217
3218       DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3219       A_surfxml_link_state = A_surfxml_link_state_ON;
3220       A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3221       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3222           {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
3223       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3224           {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
3225       SURFXML_BUFFER_SET(link_id, link_id);
3226       SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3227       SURFXML_BUFFER_SET(link_latency, cluster_lat);
3228       SURFXML_BUFFER_SET(link_bandwidth_file, "");
3229       SURFXML_BUFFER_SET(link_latency_file, "");
3230       SURFXML_BUFFER_SET(link_state_file, "");
3231       SURFXML_START_TAG(link);
3232       SURFXML_END_TAG(link);
3233
3234       break;
3235
3236     case 2:
3237
3238       surf_parse_get_int(&start,
3239                          xbt_dynar_get_as(radical_ends, 0, char *));
3240       surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
3241       DEBUG2("Create hosts and links from %d to %d", start, end);
3242       for (i = start; i <= end; i++) {
3243         host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
3244 #ifndef HAVE_PCRE_LIB
3245         xbt_dynar_push_as(tab_elements_num, int, i);
3246 #endif
3247         link_id = bprintf("%s_link_%d", cluster_id, i);
3248
3249         DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>", host_id, cluster_power);
3250         A_surfxml_host_state = A_surfxml_host_state_ON;
3251         SURFXML_BUFFER_SET(host_id, host_id);
3252         SURFXML_BUFFER_SET(host_power, cluster_power);
3253         SURFXML_BUFFER_SET(host_availability, "1.0");
3254         SURFXML_BUFFER_SET(host_availability_file, "");
3255         SURFXML_BUFFER_SET(host_state_file, "");
3256         SURFXML_START_TAG(host);
3257         SURFXML_END_TAG(host);
3258
3259         DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", link_id,cluster_bw, cluster_lat);
3260         A_surfxml_link_state = A_surfxml_link_state_ON;
3261         A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3262         if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3263             {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
3264         if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3265             {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
3266         SURFXML_BUFFER_SET(link_id, link_id);
3267         SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3268         SURFXML_BUFFER_SET(link_latency, cluster_lat);
3269         SURFXML_BUFFER_SET(link_bandwidth_file, "");
3270         SURFXML_BUFFER_SET(link_latency_file, "");
3271         SURFXML_BUFFER_SET(link_state_file, "");
3272         SURFXML_START_TAG(link);
3273         SURFXML_END_TAG(link);
3274       }
3275       break;
3276
3277     default:
3278       DEBUG0("Malformed radical");
3279     }
3280
3281     xbt_dynar_free(&radical_ends);
3282   }
3283
3284   DEBUG0(" ");
3285   router_id =
3286       bprintf("%s%s_router%s", cluster_prefix, cluster_id,
3287               cluster_suffix);
3288   link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id);
3289   link_backbone = bprintf("%s_backbone", cluster_id);
3290
3291   DEBUG1("<router id=\"%s\"/>", router_id);
3292   SURFXML_BUFFER_SET(router_id, router_id);;
3293   SURFXML_START_TAG(router);
3294   SURFXML_END_TAG(router);
3295
3296   DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,cluster_bw, cluster_lat);
3297   A_surfxml_link_state = A_surfxml_link_state_ON;
3298   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3299   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3300   {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FULLDUPLEX;}
3301   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FATPIPE)
3302   {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
3303   SURFXML_BUFFER_SET(link_id, link_router);
3304   SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
3305   SURFXML_BUFFER_SET(link_latency, cluster_lat);
3306   SURFXML_BUFFER_SET(link_bandwidth_file, "");
3307   SURFXML_BUFFER_SET(link_latency_file, "");
3308   SURFXML_BUFFER_SET(link_state_file, "");
3309   SURFXML_START_TAG(link);
3310   SURFXML_END_TAG(link);
3311
3312   DEBUG3("<link\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_backbone,cluster_bw, cluster_lat);
3313   A_surfxml_link_state = A_surfxml_link_state_ON;
3314   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
3315   if(cluster_bb_sharing_policy == A_surfxml_cluster_bb_sharing_policy_FATPIPE)
3316   {A_surfxml_link_sharing_policy =  A_surfxml_link_sharing_policy_FATPIPE;}
3317   SURFXML_BUFFER_SET(link_id, link_backbone);
3318   SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
3319   SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
3320   SURFXML_BUFFER_SET(link_bandwidth_file, "");
3321   SURFXML_BUFFER_SET(link_latency_file, "");
3322   SURFXML_BUFFER_SET(link_state_file, "");
3323   SURFXML_START_TAG(link);
3324   SURFXML_END_TAG(link);
3325
3326   char *new_suffix = bprintf("%s", "");
3327
3328   radical_elements = xbt_str_split(cluster_suffix, ".");
3329   xbt_dynar_foreach(radical_elements, iter, groups) {
3330     if (strcmp(groups, "")) {
3331       new_suffix = bprintf("%s\\.%s", new_suffix, groups);
3332     }
3333   }
3334   route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
3335
3336   DEBUG0(" ");
3337
3338 #ifdef HAVE_PCRE_LIB
3339
3340   DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
3341   DEBUG0("symetrical=\"NO\">");
3342   SURFXML_BUFFER_SET(route_src, route_src_dst);
3343   SURFXML_BUFFER_SET(route_dst, route_src_dst);
3344   A_surfxml_route_symetrical = A_surfxml_route_symetrical_NO;
3345   SURFXML_START_TAG(route);
3346
3347   DEBUG1("<link_ctn\tid=\"%s_link_$1src\"/>", cluster_id);
3348   SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id));
3349   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3350   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3351   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3352   SURFXML_START_TAG(link_ctn);
3353   SURFXML_END_TAG(link_ctn);
3354
3355   DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3356   SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3357   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3358   SURFXML_START_TAG(link_ctn);
3359   SURFXML_END_TAG(link_ctn);
3360
3361   DEBUG1("<link_ctn\tid=\"%s_link_$1dst\"/>", cluster_id);
3362   SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id));
3363   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3364   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3365   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3366   SURFXML_START_TAG(link_ctn);
3367   SURFXML_END_TAG(link_ctn);
3368
3369   DEBUG0("</route>");
3370   SURFXML_END_TAG(route);
3371 #else
3372   for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
3373     for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
3374       if (i == xbt_dynar_length(tab_elements_num)) {
3375         route_src = router_id;
3376       } else {
3377         route_src =
3378             bprintf("%s%d%s", cluster_prefix,
3379                     xbt_dynar_get_as(tab_elements_num, i, int),
3380                     cluster_suffix);
3381       }
3382
3383       if (j == xbt_dynar_length(tab_elements_num)) {
3384         route_dst = router_id;
3385       } else {
3386         route_dst =
3387             bprintf("%s%d%s", cluster_prefix,
3388                     xbt_dynar_get_as(tab_elements_num, j, int),
3389                     cluster_suffix);
3390       }
3391
3392       DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src, route_dst);
3393       DEBUG0("symetrical=\"NO\">");
3394       SURFXML_BUFFER_SET(route_src, route_src);
3395       SURFXML_BUFFER_SET(route_dst, route_dst);
3396       A_surfxml_route_symetrical = A_surfxml_route_symetrical_NO;
3397       SURFXML_START_TAG(route);
3398
3399       if (i == xbt_dynar_length(tab_elements_num)) {
3400         route_src = link_router;
3401       } else {
3402         route_src =
3403             bprintf("%s_link_%d", cluster_id,
3404                     xbt_dynar_get_as(tab_elements_num, i, int));
3405       }
3406
3407       if (j == xbt_dynar_length(tab_elements_num)) {
3408         route_dst = link_router;
3409       } else {
3410         route_dst =
3411             bprintf("%s_link_%d", cluster_id,
3412                     xbt_dynar_get_as(tab_elements_num, j, int));
3413       }
3414
3415       DEBUG1("<link_ctn\tid=\"%s\"/>", route_src);
3416       SURFXML_BUFFER_SET(link_ctn_id, route_src);
3417       A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3418       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3419       {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
3420       SURFXML_START_TAG(link_ctn);
3421       SURFXML_END_TAG(link_ctn);
3422
3423       DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
3424       SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
3425       A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3426       SURFXML_START_TAG(link_ctn);
3427       SURFXML_END_TAG(link_ctn);
3428
3429       DEBUG1("<link_ctn\tid=\"%s\"/>", route_dst);
3430       SURFXML_BUFFER_SET(link_ctn_id, route_dst);
3431       A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
3432       if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
3433       {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
3434       SURFXML_START_TAG(link_ctn);
3435       SURFXML_END_TAG(link_ctn);
3436
3437       DEBUG0("</route>");
3438       SURFXML_END_TAG(route);
3439     }
3440   }
3441   xbt_dynar_free(&tab_elements_num);
3442 #endif
3443
3444   DEBUG0("</AS>");
3445   SURFXML_END_TAG(AS);
3446   DEBUG0(" ");
3447
3448   surfxml_bufferstack_pop(1);
3449 }
3450
3451 /*
3452  * New methods to init the routing model component from the lua script
3453  */
3454
3455 /*
3456  * calling parse_S_AS_lua with lua values
3457  */
3458 void routing_AS_init(const char *AS_id, const char *AS_routing)
3459 {
3460   parse_S_AS_lua((char *) AS_id, (char *) AS_routing);
3461 }
3462
3463 /*
3464  * calling parse_E_AS_lua to fisnish the creation of routing component
3465  */
3466 void routing_AS_end(const char *AS_id)
3467 {
3468   parse_E_AS_lua((char *) AS_id);
3469 }
3470
3471 /*
3472  * add a host to the network element list
3473  */
3474
3475 void routing_add_host(const char *host_id)
3476 {
3477   parse_S_host_lua((char *) host_id);
3478 }
3479
3480 /*
3481  * Set a new link on the actual list of link for a route or ASroute
3482  */
3483 void routing_add_link(const char *link_id)
3484 {
3485   parse_E_link_c_ctn_new_elem_lua((char *) link_id);
3486 }
3487
3488 /*
3489  *Set the endpoints for a route
3490  */
3491 void routing_set_route(const char *src_id, const char *dst_id)
3492 {
3493   parse_S_route_new_and_endpoints_lua((char *) src_id, (char *) dst_id);
3494 }
3495
3496 /*
3497  * Store the route by calling parse_E_route_store_route
3498  */
3499 void routing_store_route(void)
3500 {
3501   parse_E_route_store_route();
3502 }