Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a9e42cc973177e0be5568ea2da0ac5cddb9c64e9
[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 #include <float.h>
8 #include "surf_private.h"
9 #include "xbt/dynar.h"
10 #include "xbt/str.h"
11 #include "xbt/config.h"
12 #include "xbt/graph.h"
13 #include "xbt/set.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf");
16
17
18 // FIXME: the next two lines cant be comented without fix the code in network.c file.
19 // routing_t used_routing = NULL;
20 // xbt_dict_t onelink_routes = NULL;
21
22 // 
23 // /* Prototypes of each model */
24 // static void routing_model_full_create(size_t size_of_link,void *loopback);
25 // // static void routing_model_floyd_create(size_t size_of_link, void*loopback);
26 // // static void routing_model_dijkstra_create(size_t size_of_link, void*loopback);
27 // // static void routing_model_dijkstracache_create(size_t size_of_link, void*loopback);
28 // //static void routing_model_none_create(size_t size_of_link, void*loopback);
29 // 
30 // /* Definition of each model */
31 // struct model_type {
32 //   const char *name;
33 //   const char *desc;
34 //   void (*fun)(size_t,void*);
35 // };
36 // 
37 // struct model_type models[] =
38 // { {"Full", "Full routing data (fast, large memory requirements, fully expressive)", routing_model_full_create },
39 // //   {"Floyd", "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)", routing_model_floyd_create },
40 // //   {"Dijkstra", "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)", routing_model_dijkstra_create },
41 // //   {"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)", routing_model_dijkstracache_create },
42 // //  {"none", "No routing (usable with Constant network only)", routing_model_none_create },
43 //     {NULL,NULL,NULL}};
44     
45 ////////////////////////////////////////////////////////////////////////////////
46 // HERE START THE NEW CODE
47 ////////////////////////////////////////////////////////////////////////////////
48
49 //...... DEBUG ONLY .... //
50 static void print_tree(routing_component_t rc);
51 static void print_global();
52 static void print_AS_start(void);
53 static void print_AS_end(void);
54 static void print_host(void);
55 static void print_link(void);
56 static void print_route(void);
57 static void print_ctn(void);
58 static void DEBUG_exit(void);
59
60 ////////////////////////////////////////////////////////////////////////////////
61 // HERE START THE NEW CODE
62 ////////////////////////////////////////////////////////////////////////////////
63
64 /* Global vars */
65 routing_global_t global_routing = NULL;
66 routing_component_t current_routing = NULL;
67 model_type_t current_routing_model = NULL;
68
69 /* Prototypes of each model */
70 static void* model_full_create(void); /* create structures for full routing model */
71 static void  model_full_load(void);   /* load parse functions for full routing model */
72 static void  model_full_unload(void); /* unload parse functions for full routing model */
73 static void  model_full_end(void);    /* finalize the creation of full routing model */
74
75 static void* model_floyd_create(void); /* create structures for floyd routing model */
76 static void  model_floyd_load(void);   /* load parse functions for floyd routing model */
77 static void  model_floyd_unload(void); /* unload parse functions for floyd routing model */
78 static void  model_floyd_end(void);    /* finalize the creation of floyd routing model */
79
80 static void* model_dijkstra_create(void); /* create structures for dijkstra routing model */
81 static void  model_dijkstra_load(void);   /* load parse functions for dijkstra routing model */
82 static void  model_dijkstra_unload(void); /* unload parse functions for dijkstra routing model */
83 static void  model_dijkstra_end(void);    /* finalize the creation of dijkstra routing model */
84
85 static void* model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
86 static void  model_dijkstracache_load(void);   /* load parse functions for dijkstracache routing model */
87 static void  model_dijkstracache_unload(void); /* unload parse functions for dijkstracache routing model */
88 static void  model_dijkstracache_end(void);    /* finalize the creation of dijkstracache routing model */
89
90 static void* model_none_create(void); /* none routing model */
91 static void  model_none_load(void);   /* none routing model */
92 static void  model_none_unload(void); /* none routing model */
93 static void  model_none_end(void);    /* none routing model */
94
95 /* Table of routing models */
96 /* must be finish with null and carefull if change de order */
97
98 #define SURF_MODEL_FULL          0
99 #define SURF_MODEL_FLOYD         1
100 #define SURF_MODEL_DIJKSTRA      2
101 #define SURF_MODEL_DIJKSTRACACHE 3
102 #define SURF_MODEL_NONE          4
103
104 struct s_model_type routing_models[] =
105 { {"Full", "Full routing data (fast, large memory requirements, fully expressive)",
106   model_full_create, model_full_load, model_full_unload, model_full_end },  
107   {"Floyd", "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
108   model_floyd_create, model_floyd_load, model_floyd_unload, model_floyd_end },
109   {"Dijkstra", "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
110   model_dijkstra_create ,model_dijkstra_load, model_dijkstra_unload, model_dijkstra_end },
111   {"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
112   model_dijkstracache_create, model_dijkstracache_load, model_dijkstracache_unload, model_dijkstracache_end },
113   {"none", "No routing (usable with Constant network only)",
114   model_none_create, model_none_load, model_none_unload, model_none_end },
115   {NULL,NULL,NULL,NULL,NULL,NULL}};
116
117   
118 /* global parse functions */
119
120 static char* src = NULL;    /* temporary store the source name of a route */
121 static char* dst = NULL;    /* temporary store the destination name of a route */
122 static char* gw_src = NULL; /* temporary store the gateway source name of a route */
123 static char* gw_dst = NULL; /* temporary store the gateway destination name of a route */
124 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */ 
125
126 /**
127  * \brief Add a "host" to the network element list
128  */
129 static void  parse_S_host(void) {
130   if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
131   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_host_id),
132       "Reading a host, processing unit \"%s\" already exist",A_surfxml_host_id);
133 // FIXME: checked by parser
134 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_BASE,
135 //       "Bad declaration of processing unit \"%s\"",A_surfxml_host_id);
136   (*(current_routing->set_processing_units))(current_routing,A_surfxml_host_id);
137   xbt_dict_set(global_routing->where_network_elements,A_surfxml_host_id,(void*)current_routing,NULL); 
138 }
139
140 /**
141  * \brief Add a "router" to the network element list
142  */
143 static void parse_S_router(void) {
144   if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
145   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_router_id),
146       "Reading a router, processing unit \"%s\" already exist",A_surfxml_router_id);
147 // FIXME: checked by parser
148 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_BASE,
149 //       "Bad declaration of processing unit \"%s\"",A_surfxml_host_id);
150   (*(current_routing->set_processing_units))(current_routing,A_surfxml_router_id);
151   xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)current_routing,NULL); 
152 }
153
154 static void parse_S_route_new_and_endpoints(void) {
155   // FIXME: checked by parser
156 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_BASE,
157 //     "Bad declaration of route in \"%s\"",current_routing->name);
158   if( src != NULL && dst != NULL && link_list != NULL )
159     THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_route_src,A_surfxml_route_dst);
160   src = A_surfxml_route_src;
161   dst = A_surfxml_route_dst;
162   link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
163 }
164
165 static void parse_S_ASroute_new_and_endpoints(void) {
166 // FIXME: checked by parser
167 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_RECURSIVE,
168 //     "Bad declaration of ASroute in \"%s\"",current_routing->name);
169   if( src != NULL && dst != NULL && link_list != NULL )
170     THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_ASroute_src,A_surfxml_ASroute_dst);
171   src = A_surfxml_ASroute_src;
172   dst = A_surfxml_ASroute_dst;
173   gw_src = A_surfxml_ASroute_gw_src;
174   gw_dst = A_surfxml_ASroute_gw_dst;
175   link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
176 }
177
178 static void parse_E_link_c_ctn_new_elem(void) {
179   char *val;
180   val = xbt_strdup(A_surfxml_link_c_ctn_id);
181   xbt_dynar_push(link_list, &val);
182 }
183
184 static void parse_E_route_store_route(void) {
185 // FIXME: checked by parser
186 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_BASE,
187 //     "Bad declaration of route in \"%s\"",current_routing->name);
188   route_t route = xbt_new(s_route_t,1);
189   route->link_list = link_list;
190   // TODO check if are correct
191   (*(current_routing->set_route))(current_routing,src,dst,route);
192   link_list = NULL;
193   src = NULL;
194   dst = NULL;
195 }
196
197 static void parse_E_ASroute_store_route(void) {
198 // FIXME: checked by parser
199 //   xbt_assert1(current_routing->hierarchy==SURF_ROUTING_RECURSIVE,
200 //     "Bad declaration of ASroute in \"%s\"",current_routing->name);
201   route_extended_t e_route = xbt_new(s_route_extended_t,1);
202   e_route->generic_route.link_list = link_list;
203   e_route->src_gateway = xbt_strdup(gw_src);
204   e_route->dst_gateway = xbt_strdup(gw_dst);
205   // TODO check if are correct
206   (*(current_routing->set_ASroute))(current_routing,src,dst,e_route);
207   link_list = NULL;
208   src = NULL;
209   dst = NULL;
210   gw_src = NULL;
211   gw_dst = NULL;
212 }
213
214 /**
215  * \brief Make a new routing component
216  *
217  * Detect the routing model type of the routing component, make the new structure and
218  * set the parsing functions to allows parsing the part of the routing tree
219  */
220 static void parse_S_AS(void) { 
221   routing_component_t new_routing;
222   model_type_t model = NULL;
223   char* wanted = A_surfxml_AS_routing;
224   int cpt;
225   /* seach the routing model */
226   for (cpt=0;routing_models[cpt].name;cpt++)
227     if (!strcmp(wanted,routing_models[cpt].name))
228           model = &routing_models[cpt];
229   /* if its not exist, error */
230   if( model == NULL ) {
231     fprintf(stderr,"Routing model %s not found. Existing models:\n",wanted);
232     for (cpt=0;routing_models[cpt].name;cpt++)
233       if (!strcmp(wanted,routing_models[cpt].name))
234         fprintf(stderr,"   %s: %s\n",routing_models[cpt].name,routing_models[cpt].desc);
235     exit(1);
236   }
237
238   /* make a new routing component */
239   new_routing = (routing_component_t)(*(model->create))();
240   
241   /* FIXME: for now, if I forget to declare */  
242   xbt_assert1( new_routing->set_processing_units,
243        "Bad routing type, \"set_processing_units\" is not declared for \"%s\"",A_surfxml_AS_id);
244   xbt_assert1( new_routing->set_autonomous_system,
245        "Bad routing type, \"set_autonomous_system\" is not declared for \"%s\"",A_surfxml_AS_id);
246   xbt_assert1( new_routing->set_route,
247        "Bad routing type, \"set_route\" is not declared for \"%s\"",A_surfxml_AS_id);
248   xbt_assert1( new_routing->set_ASroute,
249        "Bad routing type, \"set_ASroute\" is not declared for \"%s\"",A_surfxml_AS_id);
250   xbt_assert1( new_routing->finalize,
251        "Bad routing type, \"finalize\" is not declared for \"%s\"",A_surfxml_AS_id);
252        
253   new_routing->routing = model;
254   new_routing->hierarchy = SURF_ROUTING_NULL;
255   new_routing->name = xbt_strdup(A_surfxml_AS_id);
256   new_routing->routing_sons = xbt_dict_new();
257   INFO2("Routing %s for AS %s",A_surfxml_AS_routing,A_surfxml_AS_id);
258   
259   if( current_routing == NULL && global_routing->root == NULL ){
260     
261     /* it is the first one */
262     new_routing->routing_father = NULL;
263     global_routing->root = new_routing;
264     
265   } else if( current_routing != NULL && global_routing->root != NULL ) { 
266     
267     xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,A_surfxml_AS_id),
268            "The AS \"%s\" already exist",A_surfxml_AS_id);
269      /* it is a part of the tree */
270     new_routing->routing_father = current_routing;
271     /* set the father behavior */
272     if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
273 // FIXME: checked by parser
274 //     xbt_assert1(current_routing->hierarchy==SURF_ROUTING_RECURSIVE,
275 //       "Bad declaration of AS \"%s\"",A_surfxml_AS_id);
276     /* add to the sons dictionary */
277     xbt_dict_set(current_routing->routing_sons,A_surfxml_AS_id,(void*)new_routing,NULL);
278     /* add to the father element list */
279     (*(current_routing->set_autonomous_system))(current_routing,A_surfxml_AS_id);
280     /* unload the prev parse rules */
281     (*(current_routing->routing->unload))();
282     
283   } else {
284     THROW0(arg_error,0,"All defined components must be belong to a AS");
285   }
286   /* set the new parse rules */
287   (*(new_routing->routing->load))();
288   /* set the new current component of the tree */
289   current_routing = new_routing;
290 }
291
292 /**
293  * \brief Finish the creation of a new routing component
294  *
295  * When you finish to read the routing component, other structures must be created. 
296  * the "end" method allow to do that for any routing model type
297  */
298 static void parse_E_AS(void) {
299
300   if( current_routing == NULL ) {
301     THROW1(arg_error,0,"Close AS(%s), that never open",A_surfxml_AS_id);
302   } else {
303       (*(current_routing->routing->unload))();
304       (*(current_routing->routing->end))();
305       current_routing = current_routing->routing_father;
306       if( current_routing != NULL )
307         (*(current_routing->routing->load))();
308   }
309 }
310
311 /**
312  * \brief Recursive function for add the differents AS to global dict
313  *
314  * This fuction is call by "parse_E_platform_add_parse_AS". It allow to add the 
315  * AS or routing components, to the where_network_elements dictionary. In the same
316  * way as "parse_S_host", "parse_S_router" and "parse_S_gateway" do.
317  */
318 static void _add_parse_AS(routing_component_t rc) {
319   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,rc->name),
320      "The AS \"%s\" already exist",rc->name);
321   xbt_dict_set(global_routing->where_network_elements,rc->name,rc->routing_father,NULL);
322   xbt_dict_cursor_t cursor = NULL;
323   char *key;
324   routing_component_t elem;
325   xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
326     _add_parse_AS(elem);
327   } 
328 }
329
330 /**
331  * \brief Add a "AS" to the network element list
332  *
333  * Allows find a "AS" in any routing component
334  */
335 static void parse_E_platform_add_parse_AS(void) {
336   _add_parse_AS(global_routing->root);
337 }
338
339 /* Aux Business methods */
340
341 static xbt_dynar_t elements_father(const char* src,const char* dst) {
342   
343   xbt_dynar_t result = xbt_dynar_new(sizeof(char*), NULL); // &xbt_free_ref
344   
345   routing_component_t src_as, dst_as;
346   int index_src, index_dst, index_father_src, index_father_dst;
347   xbt_dynar_t path_src = NULL;
348   xbt_dynar_t path_dst = NULL;
349   routing_component_t current = NULL;
350   routing_component_t* current_src = NULL;
351   routing_component_t* current_dst = NULL;
352   routing_component_t* father = NULL;
353   
354   /* (1) find the as where the src and dst are located */
355   src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
356   dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst); 
357   xbt_assert0(src_as != NULL && dst_as  != NULL, "Ask for route \"from\" or \"to\" no found");
358   
359   /* (2) find the path to the root routing component */
360   path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
361   current = src_as; 
362   while( current != NULL ) {
363     xbt_dynar_push(path_src,&current);
364     current = current->routing_father;
365   }
366   path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
367   current = dst_as; 
368   while( current != NULL ) {
369     xbt_dynar_push(path_dst,&current);
370     current = current->routing_father;
371   }
372   
373   /* (3) find the common father */
374   index_src  = (path_src->used)-1;
375   index_dst  = (path_dst->used)-1;
376   current_src = xbt_dynar_get_ptr(path_src,index_src);
377   current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
378   while( index_src >= 0 && index_dst >= 0 && *current_src == *current_dst ) {
379     current_src = xbt_dynar_get_ptr(path_src,index_src);
380     current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
381     index_src--;
382     index_dst--;
383   }
384   index_src++;
385   index_dst++;
386   current_src = xbt_dynar_get_ptr(path_src,index_src);
387   current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
388
389   /* (4) they are not in the same routing component, make the path */
390   index_father_src = index_src+1;
391   index_father_dst = index_dst+1;
392    
393   if(*current_src==*current_dst)
394     father = current_src;
395   else
396     father = xbt_dynar_get_ptr(path_src,index_father_src);
397   
398   /* (5) result generation */
399   xbt_dynar_push(result,father); // first same the father of src and dst
400   xbt_dynar_push(result,current_src); // second the first different father of src 
401   xbt_dynar_push(result,current_dst); // three  the first different father of dst
402   
403   xbt_dynar_free(&path_src);
404   xbt_dynar_free(&path_dst);
405   
406   return result;
407 }
408
409 /* Global Business methods */
410
411 // typedef enum {
412 //   SURF_LOCAL_SOLVE = 0,   /**< No Local solve */ 
413 //   SURF_NO_LOCAL_SOLVE,       /**< Local solve */
414 // } e_surf_is_local_t;
415
416 static route_extended_t _get_route(const char* src,const char* dst) {
417   
418   void* link;
419   unsigned int cpt=0;
420   
421   DEBUG2("Solve route  \"%s\" to \"%s\"",src,dst);
422      
423   xbt_assert0(src&&dst,"bad parameters for _get_route method");
424   
425   route_extended_t e_route, e_route_cnt, e_route_src, e_route_dst;
426   
427   xbt_dynar_t elem_father_list = elements_father(src,dst);
428   
429   routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
430   routing_component_t src_father    = xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
431   routing_component_t dst_father    = xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
432   
433   e_route = xbt_new0(s_route_extended_t,1);
434   e_route->src_gateway = NULL;
435   e_route->dst_gateway = NULL;
436   e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
437   
438   if(src_father==dst_father) { /* SURF_ROUTING_BASE */
439     
440     if( strcmp(src,dst) ){
441       e_route_cnt = (*(common_father->get_route))(common_father,src,dst);
442       xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
443         xbt_dynar_push(e_route->generic_route.link_list,&link);
444       }
445     }
446     
447   } else { /* SURF_ROUTING_RECURSIVE */
448     
449       e_route_cnt = (*(common_father->get_route))(common_father,src_father->name,dst_father->name);
450       
451       xbt_assert2( (e_route_cnt->src_gateway==NULL) == (e_route_cnt->dst_gateway==NULL) ,
452         "bad gateway for route between \"%s\" and \"%s\"",src,dst);
453       
454       if( src != e_route_cnt->src_gateway ) {
455         e_route_src = _get_route(src,e_route_cnt->src_gateway);
456         xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
457           xbt_dynar_push(e_route->generic_route.link_list,&link);
458         }
459       }
460       
461       xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
462         xbt_dynar_push(e_route->generic_route.link_list,&link);
463       }
464       
465       if( e_route_cnt->dst_gateway != dst ) {
466         e_route_dst = _get_route(e_route_cnt->dst_gateway,dst);
467         xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
468           xbt_dynar_push(e_route->generic_route.link_list,&link);
469         }
470       }
471       
472       e_route->src_gateway = e_route_cnt->src_gateway;
473       e_route->dst_gateway = e_route_cnt->dst_gateway;
474
475       xbt_dynar_free( &(e_route_src->generic_route.link_list) );
476       xbt_free(e_route_src);
477       xbt_dynar_free( &(e_route_cnt->generic_route.link_list) );
478       xbt_free(e_route_cnt);
479       xbt_dynar_free( &(e_route_dst->generic_route.link_list) );
480       xbt_free(e_route_dst);
481   }
482   return e_route; 
483 }
484
485
486 /**
487  * \brief Generic method: find a route between hosts
488  *
489  * \param src the source host name 
490  * \param dst the destination host name
491  * 
492  * walk through the routing components tree and find a route between hosts
493  * by calling the differents "get_route" functions in each routing component
494  */
495 static xbt_dynar_t get_route(const char* src,const char* dst) {
496   
497   if(global_routing->last_route) xbt_dynar_free( &(global_routing->last_route) );
498   
499   route_extended_t e_route;
500   xbt_dynar_t elem_father_list = elements_father(src,dst);
501   routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
502   
503   if(strcmp(src,dst))
504     e_route = _get_route(src,dst);
505   else
506     e_route = (*(common_father->get_route))(common_father,src,dst);
507   
508   global_routing->last_route = e_route->generic_route.link_list;
509  
510   xbt_free(e_route);
511   
512   if( xbt_dynar_length(global_routing->last_route)==0 )
513     return NULL;
514   else
515     return global_routing->last_route;
516 }
517
518 /**
519  * \brief Recursive function for finalize
520  *
521  * \param rc the source host name 
522  * 
523  * This fuction is call by "finalize". It allow to finalize the 
524  * AS or routing components. It delete all the structures.
525  */
526 static void _finalize(routing_component_t rc) {
527   if(rc) {
528     xbt_dict_cursor_t cursor = NULL;
529     char *key;
530     routing_component_t elem;
531     xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
532       _finalize(elem);
533     }
534     xbt_dict_t tmp_sons = rc->routing_sons;
535     char* tmp_name = rc->name;
536     xbt_dict_free(&tmp_sons);
537     xbt_free(tmp_name);
538     (*(rc->finalize))(rc);
539   }
540 }
541
542 /**
543  * \brief Generic method: delete all the routing structures
544  * 
545  * walk through the routing components tree and delete the structures
546  * by calling the differents "finalize" functions in each routing component
547  */
548 static void finalize(void) {
549   /* delete recursibly all the tree */  
550   _finalize(global_routing->root);
551   /* delete "where" dict */
552   xbt_dict_free(&(global_routing->where_network_elements));
553   /* delete last_route */
554   xbt_dynar_free(&(global_routing->last_route));
555   /* delete global routing structure */
556   xbt_free(global_routing);
557 }
558
559 /**
560  * \brief Generic method: create the global routing schema
561  * 
562  * Make a global routing structure and set all the parsing functions.
563  */
564 void routing_model_create(size_t size_of_links, void* loopback) {
565   
566   /* config the uniq global routing */
567   global_routing = xbt_new0(s_routing_global_t,1);
568   global_routing->where_network_elements = xbt_dict_new();
569   global_routing->root = NULL;
570   global_routing->get_route = get_route;
571   global_routing->finalize = finalize;
572   global_routing->loopback = loopback;
573   global_routing->size_of_link = size_of_links;
574   global_routing->last_route = xbt_dynar_new(size_of_links, NULL);
575   
576   /* no current routing at moment */
577   current_routing = NULL;
578
579   /* parse generic elements */
580   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host);
581   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
582
583   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints);
584   surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints);
585   
586   surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_E_link_c_ctn_new_elem);
587   
588   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route);
589   surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route);
590   
591   surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
592   surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
593   
594   /* set all the as in the global where table (recursive fuction) */
595   surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_E_platform_add_parse_AS);
596   
597   /* DEBUG ONLY */  
598   //surfxml_add_callback(ETag_surfxml_platform_cb_list, &DEBUG_exit);
599
600 }
601
602 /* ************************************************************************** */
603 /* *************************** FULL ROUTING ********************************* */
604
605 #define TO_ROUTE_FULL(i,j,rc) ((routing_component_full_t)rc)->routing_table[(i)+(j)*xbt_dict_length(((routing_component_full_t)rc)->to_index)]
606
607 /* Routing model structure */
608
609 typedef struct {
610   s_routing_component_t generic_routing;
611   xbt_dict_t parse_routes; /* store data during the parse process */
612   xbt_dict_t to_index; /* char* -> network_element_t */
613   route_extended_t *routing_table;
614 } s_routing_component_full_t,*routing_component_full_t;
615
616 /* Parse routing model functions */
617
618
619 /* Business methods */
620
621 static void full_set_processing_units(routing_component_t rc, const char* name) {
622    DEBUG1("Full - Load process unit \"%s\"",name);
623    // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
624    int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
625    *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
626    xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
627 }
628
629 static void full_set_autonomous_system(routing_component_t rc, const char* name) {
630    DEBUG1("Full - Load Autonomous system \"%s\"",name);
631    // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
632    int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
633    *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
634    xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
635 }
636
637 static void full_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
638    DEBUG2("Full - Load Route from \"%s\" to \"%s\"",src,dst);
639   routing_component_full_t routing = (routing_component_full_t)current_routing;
640   char *route_name;
641   route_name = bprintf("%s#%s",src,dst);
642   xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);   
643   xbt_assert2(!xbt_dict_get_or_null(routing->parse_routes,route_name),
644     "The route between \"%s\" and \"%s\" already exist",src,dst);
645   xbt_dict_set(routing->parse_routes, route_name, route, NULL);
646   free(route_name);
647 }
648
649 static void full_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
650    DEBUG4("Full - Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway);
651   routing_component_full_t routing = (routing_component_full_t)current_routing;
652   char *route_name;
653   route_name = bprintf("%s#%s",src,dst);
654   xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);   
655   xbt_assert4(!xbt_dict_get_or_null(routing->parse_routes,route_name),
656     "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
657     src,e_route->src_gateway,dst,e_route->dst_gateway);
658   xbt_dict_set(routing->parse_routes, route_name, e_route, NULL);
659   free(route_name);
660 }
661
662 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
663
664   routing_component_full_t routing = (routing_component_full_t)rc;
665   
666   xbt_assert1(src && dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
667    
668   routing_component_t src_as, dst_as;
669   int *src_id,*dst_id;
670
671   src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
672   dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
673    
674   xbt_assert0(src_as != NULL && dst_as  != NULL, "Ask for route \"from\" or \"to\" no found");
675   xbt_assert0(src_as == dst_as, "The src and dst are in differents AS");
676   xbt_assert0(rc == dst_as, "The routing component of src and dst is not the same as the network elements belong");
677
678   src_id = xbt_dict_get(routing->to_index,src);
679   dst_id = xbt_dict_get(routing->to_index,dst);
680
681   xbt_assert0(src_id && dst_id, "Ask for route \"from\" or \"to\" no found in the local table"); 
682   
683   void* link;
684   unsigned int cpt=0;
685   route_extended_t e_route = TO_ROUTE_FULL(*src_id,*dst_id,routing);
686   route_extended_t new_e_route = xbt_new0(s_route_extended_t,1);
687   new_e_route->src_gateway = e_route->src_gateway;
688   new_e_route->dst_gateway = e_route->dst_gateway;
689   new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
690   xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
691     xbt_dynar_push(new_e_route->generic_route.link_list,&link);
692   }
693   return new_e_route;
694 }
695
696 static void full_finalize(routing_component_t rc) {
697   routing_component_full_t routing = (routing_component_full_t)rc;
698   int i,j;
699   if (routing) {
700     int table_size = xbt_dict_length(routing->to_index);
701     /* Delete routing table */
702     for (i=0;i<table_size;i++) {
703       for (j=0;j<table_size;j++) {
704         route_extended_t e_route = TO_ROUTE_FULL(i,j,rc);
705         if(e_route) {
706           xbt_dynar_free(&(e_route->generic_route.link_list));
707           if(e_route->src_gateway) xbt_free(e_route->src_gateway);
708           if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
709           xbt_free(e_route);
710         }
711       }
712     }
713     xbt_free(routing->routing_table);
714     /* Delete index dict */
715     xbt_dict_free(&(routing->to_index));
716     /* Delete structure */
717     xbt_free(rc);
718   }
719 }
720
721 /* Creation routing model functions */
722
723 static void* model_full_create() {
724   routing_component_full_t new_component =  xbt_new0(s_routing_component_full_t,1);
725   new_component->generic_routing.set_processing_units = full_set_processing_units;
726   new_component->generic_routing.set_autonomous_system = full_set_autonomous_system;
727   new_component->generic_routing.set_route = full_set_route;
728   new_component->generic_routing.set_ASroute = full_set_ASroute;
729   new_component->generic_routing.get_route = full_get_route;
730   new_component->generic_routing.finalize = full_finalize;
731   new_component->to_index = xbt_dict_new();
732   new_component->parse_routes = xbt_dict_new();
733    return new_component;
734 }
735
736 static void model_full_load() {
737  /* use "surfxml_add_callback" to add a parse function call */
738 }
739
740 static void model_full_unload() {
741  /* use "surfxml_del_callback" to remove a parse function call */
742 }
743
744 static void  model_full_end() {
745
746   char *key, *src_name, *dst_name, *link_name;//,  *src_gw_name, *dst_gw_name;
747   const char* sep = "#";
748   int *src_id, *dst_id;
749   unsigned int i, j, cpt;
750
751   route_extended_t e_route, new_e_route;
752   route_t route;
753   void* data;
754   
755   xbt_dynar_t links, links_id;
756   xbt_dict_cursor_t cursor = NULL;
757   xbt_dynar_t keys = NULL;
758
759   routing_component_full_t routing = ((routing_component_full_t)current_routing);
760   
761   int table_size = xbt_dict_length(routing->to_index);
762   
763   /* Create the routing table */
764   routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
765   
766   /* Put the routes in position */
767   xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
768     
769     keys = xbt_str_split_str(key, sep);
770
771     src_name    = xbt_dynar_get_as(keys, 0, char*);
772     dst_name    = xbt_dynar_get_as(keys, 1, char*);
773     
774     src_id = xbt_dict_get_or_null(routing->to_index, src_name);
775     dst_id = xbt_dict_get_or_null(routing->to_index, dst_name);
776     
777     if (src_id == NULL || dst_id == NULL )
778       THROW2(mismatch_error,0,"Network elements %s or %s not found", src_name, dst_name);
779     
780     new_e_route = xbt_new0(s_route_extended_t,1);
781     new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
782     new_e_route->src_gateway = NULL;
783     new_e_route->dst_gateway = NULL;
784     TO_ROUTE_FULL(*src_id,*dst_id,current_routing) = new_e_route;
785
786     xbt_assert0(routing->generic_routing.hierarchy == SURF_ROUTING_BASE || routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE,
787        "the hierarchy type is not defined");
788     
789     if(routing->generic_routing.hierarchy == SURF_ROUTING_BASE ) {
790       
791       route = (route_t)data;
792       links = route->link_list;
793       
794     } else if(routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE ) {
795
796       e_route = (route_extended_t)data;
797       // FIXME: HERE CHECK THE GATEWAY!!!!!!!!!
798       links = e_route->generic_route.link_list;
799       /* remeber not erase the gateway names */
800       TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->src_gateway = e_route->src_gateway;
801       TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->dst_gateway = e_route->dst_gateway;
802
803     }
804
805     links_id = TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->generic_route.link_list;
806     
807     xbt_dynar_foreach(links, cpt, link_name) {
808       
809       void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
810       if (link)
811         xbt_dynar_push(links_id,&link);
812       else
813         THROW1(mismatch_error,0,"Link %s not found", link_name);
814     }
815
816      xbt_dynar_free(&keys);
817    }
818
819    /* delete the parse table */
820   xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
821     route = (route_t)data;
822     xbt_dynar_free(&(route->link_list));
823     xbt_free(data);
824   }
825       
826   /* delete parse dict */
827   xbt_dict_free(&(routing->parse_routes));
828
829   /* Add the loopback if needed */
830   for (i = 0; i < table_size; i++) {
831     e_route = TO_ROUTE_FULL(i, i,current_routing);
832     if(!e_route) { // && !xbt_dynar_length(e_route->generic_route.link_list)
833       e_route = xbt_new0(s_route_extended_t,1);
834       e_route->src_gateway = NULL;
835       e_route->dst_gateway = NULL;
836       e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
837       xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
838       TO_ROUTE_FULL(i, i,current_routing) = e_route;
839     }
840   }
841
842   /* Shrink the dynar routes (save unused slots) */
843   for (i=0;i<table_size;i++)
844     for (j=0;j<table_size;j++)
845       if(TO_ROUTE_FULL(i,j,current_routing))
846         xbt_dynar_shrink(TO_ROUTE_FULL(i,j,current_routing)->generic_route.link_list,0);
847 }
848
849 /* ************************************************************************** */
850 /* *************************** FLOYD ROUTING ******************************** */
851
852 #define TO_FLOYD_COST(i,j) cost_table[(i)+(j)*table_size]
853 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
854 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
855 #define TO_FLOYD_AS(i,j)   (routing->AS_table)[(i)+(j)*AS_table_size]
856
857 /* Routing model structure */
858
859 typedef struct {
860   s_routing_component_t generic_routing;
861   route_extended_t last_route;
862   /* vars for calculate the floyd algorith. */
863   int *predecessor_table;
864   void** link_table; /* char* -> network_element_t* */
865   xbt_dict_t predecessor_to_index;
866   /* store information to solve any AS route */
867   xbt_dict_t AS_to_index; /* char* -> network_element_t* */
868   route_limits_t AS_table;
869   /* store data during the parse process */  
870   xbt_dict_t parse_routes; 
871   
872 } s_routing_component_floyd_t,*routing_component_floyd_t;
873
874 /* Business methods */
875
876 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
877
878   return NULL;
879 }
880
881 static xbt_dict_t floyd_get_network_elements(routing_component_t rc, e_surf_network_element_type_t req_type)
882 {
883   return NULL;
884 }
885
886 static void floyd_finalize(routing_component_t rc) {
887
888 }
889
890 static void* model_floyd_create(void) {
891 return NULL;
892 }
893
894 static void  model_floyd_load() {
895 }
896
897 static void  model_floyd_unload() {
898 }
899
900 static void  model_floyd_end() {
901 }
902
903 /* ************************************************************************** */
904 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
905
906 typedef struct {
907   s_routing_component_t generic_routing;
908   xbt_graph_t route_graph;
909   xbt_dict_t graph_node_map;
910   xbt_dict_t route_cache;
911   xbt_dynar_t last_route;
912   int cached;
913 } s_routing_component_dijkstra_t,*routing_component_dijkstra_t;
914
915 /* Parse routing model functions */
916
917 /* Business methods */
918
919 /* Creation routing model functions */
920
921 static void* model_dijkstra_create() {
922   return NULL;
923 }
924
925 static void  model_dijkstra_load() {
926 }
927
928 static void  model_dijkstra_unload() {
929 }
930
931 static void  model_dijkstra_end() {
932 }
933
934 static void* model_dijkstracache_create() {
935   return NULL;
936 }
937
938 static void  model_dijkstracache_load() {
939 }
940
941 static void  model_dijkstracache_unload() {
942 }
943
944 static void  model_dijkstracache_end() {
945 }
946
947
948 /* ************************************************************************** */
949 /* ******************************* NO ROUTING ******************************* */
950
951 /* Routing model structure */
952 typedef struct {
953   s_routing_component_t generic_routing;
954 } s_routing_component_none_t,*routing_component_none_t;
955
956 /* Business methods */
957 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
958   return NULL;
959 }
960 static void none_finalize(routing_component_t rc) {
961   xbt_free(rc);
962 }
963
964 /* Creation routing model functions */
965 static void* model_none_create() {
966   routing_component_none_t new_component =  xbt_new0(s_routing_component_none_t,1);
967   new_component->generic_routing.get_route = none_get_route;
968   new_component->generic_routing.finalize = none_finalize;
969   return new_component;
970 }
971
972 static void  model_none_load() {}
973 static void  model_none_unload() {}
974 static void  model_none_end() {}
975
976 /* ************************************************** */
977 /* ********** PATERN FOR NEW ROUTING **************** */
978
979 /* The minimal configuration of a new routing model need the next functions,
980  * also you need to set at the start of the file, the new model in the model
981  * list. Remember keep the null ending of the list.
982  */
983 /* Routing model structure */
984 typedef struct {
985   s_routing_component_t generic_routing;
986   /* things that your routing model need */
987 } s_routing_component_NEW_t,*routing_component_NEW_t;
988
989 /* Parse routing model functions */
990 static void NEW_parse_S_host(void) {} /* example*/
991
992 /* Business methods */
993 static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;} /* mandatory */
994 static void NEW_finalize(routing_component_t rc) {} /* mandatory */
995
996 /* Creation routing model functions */
997 static void* model_NEW_create() {return NULL;} /* mandatory */
998 static void  model_NEW_load() {}   /* mandatory */
999 static void  model_NEW_unload() {} /* mandatory */
1000 static void  model_NEW_end() {}    /* mandatory */
1001
1002
1003 ////////////////////////////////////////////////////////////////////////////////
1004 // HERE FINISH THE NEW CODE
1005 ////////////////////////////////////////////////////////////////////////////////
1006
1007 //...... DEBUG ONLY .... //
1008 static void print_tree(routing_component_t rc) {
1009   printf("(%s %s)\n",rc->name,rc->routing->name);
1010   printf("  ");
1011   xbt_dict_cursor_t cursor = NULL;
1012   char *key;
1013   int *val;  
1014   if( rc->routing == &(routing_models[SURF_MODEL_FULL]) )
1015   { xbt_dict_foreach(((routing_component_full_t)rc)->to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1016   else if( rc->routing == &(routing_models[SURF_MODEL_FLOYD]) )
1017   { xbt_dict_foreach(((routing_component_floyd_t)rc)->predecessor_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } 
1018     xbt_dict_foreach(((routing_component_floyd_t)rc)->AS_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1019   else
1020       xbt_assert0(0, "Invalid model for call \"print_tree\"");
1021   printf("\n");  
1022   routing_component_t elem;
1023   xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
1024     printf("<--\n");  
1025     print_tree(elem);
1026     printf("-->\n");
1027   }
1028 }
1029
1030 //...... DEBUG ONLY .... //
1031 static void print_global() {
1032   xbt_dict_cursor_t cursor = NULL;
1033   char *key;
1034   routing_component_t elem;  
1035   xbt_dict_foreach(global_routing->where_network_elements, cursor, key, elem) {
1036     printf("<%s>\n",key);
1037   }
1038 }
1039
1040 //...... DEBUG ONLY .... //
1041 static void print_AS_start(void) { printf("AS!!! %s y se rutea \"%s\"\n",A_surfxml_AS_id,A_surfxml_AS_routing); }
1042 static void print_AS_end(void) { printf("AS!!! %s\n",A_surfxml_AS_id); }
1043 static void print_host(void) { printf("host!!! %s\n",A_surfxml_host_id); }
1044 static void print_link(void) { printf("link!!! %s\n",A_surfxml_link_id); }
1045 static void print_route(void) { printf("route!!! %s a %s\n",A_surfxml_route_src,A_surfxml_route_dst); }
1046 static void print_ctn(void) { printf("ctn!!! %s\n",A_surfxml_link_c_ctn_id); }
1047
1048 //...... DEBUG ONLY .... //
1049 static void DEBUG_exit(void) {
1050   
1051   
1052   
1053   printf("-- print all the example routes --\n");
1054   
1055    const char* names[] = { "11.A","11.B","11.C",
1056                            "121.A","121.B",
1057                            "122.A",
1058                            "13.A","13.B" };
1059    unsigned int i,j,total = 3+2+1+2;
1060    
1061   xbt_dynar_t links;
1062   void* link;
1063   for(i=0;i<total;i++) {
1064     for(j=0;j<total;j++) {
1065       links = (*(global_routing->get_route))(names[i],names[j]);
1066       printf("route from %s to %s >>> ",names[i],names[j]);
1067       if(links) {
1068         unsigned int cpt=0;
1069         xbt_dynar_foreach(links, cpt, link) {
1070           s_surf_resource_t* generic_resource = link;
1071           printf(" %s",generic_resource->name);
1072         }
1073       } else {
1074         printf("NULL");
1075       }
1076       printf("\n");
1077     }
1078   }
1079   
1080   printf("-- /////////////////////////////////////--\n");
1081   printf("-- /////////////////////////////////////--\n");
1082
1083
1084 links = (*(global_routing->get_route))(names[0],names[5]);
1085
1086 if(links) {
1087 unsigned int cpt=0;
1088
1089 printf("route from %s to %s >>> ",names[0],names[5]);
1090   xbt_dynar_foreach(links, cpt, link) {
1091     s_surf_resource_t* generic_resource = link;
1092     printf(" %s",generic_resource->name);
1093   }
1094 } else {
1095   printf("NULL");
1096 }
1097 printf("\n");
1098   
1099   
1100   printf("---------- call finalize ---------\n");
1101   (*(global_routing->finalize))();
1102   printf("----------------------------------\n");
1103   
1104   exit(0);
1105   
1106   printf("-------- print tree elements -----\n");
1107   print_tree(global_routing->root);
1108   printf("----------------------------------\n\n");
1109   
1110   printf("-------- network_elements --------\n");
1111   print_global();
1112   printf("----------------------------------\n\n");
1113   
1114 //   char* names[] = { "11.A","11.B","11.C","121.A","121.B","122.A","13.A","13.B"};
1115 //   int i,j,total = 8;
1116
1117 //   printf("-- print all the example routes --\n");
1118 //   char* names[] = { "11.A","11.B","11.C"};
1119 //   int i,j,total = 3;
1120
1121 //   char* names[] = { "141.A","141.B","143.A","143.B"};
1122 //   int i,j,total = 4;
1123
1124 //   char* names[] = { "142.A","142.B","142.C" };
1125 //   int i,j,total = 3;
1126
1127 //   char* names[] = { "142.A","142.B","142.C", "11.A","11.B","11.C","141.A","141.B","143.A","143.B","11.A","11.B","11.C","121.A","121.B","122.A","13.A","13.B"};
1128 //   int i,j,total = 3+4+8+3;
1129
1130 //    const char* names[] = { "11.A","11.B","11.C",
1131 //                            "121.A","121.B",
1132 //                            "122.A",
1133 //                            "13.A","13.B",
1134 //                            "141.A","141.B",
1135 //                            "142.A","142.B","142.C",
1136 //                            "143.A","143.B",
1137 //                            "15.A","15.B","15.C"};
1138 //    unsigned int i,j,total = 3+2+1+2+2+3+2+3;
1139
1140 //   printf("-- print all the example routes --\n");
1141 //   xbt_dynar_t links;
1142 //   void* link;
1143 //   for(i=0;i<total;i++) {
1144 //     for(j=0;j<total;j++) {
1145 //       links = (*(global_routing->get_route))(names[i],names[j]);
1146 //       printf("route from %s to %s >>> ",names[i],names[j]);
1147 //       unsigned int cpt=0;
1148 //       xbt_dynar_foreach(links, cpt, link) {
1149 //         s_surf_resource_t* generic_resource = link;
1150 //         printf(" %s",generic_resource->name);
1151 //       }
1152 //       printf("\n");
1153 //     }
1154 //   }
1155 //   
1156 //   printf("----------------------------------\n\n");
1157 //   
1158 //   printf("---------- call finalize ---------\n");
1159 //   (*(global_routing->finalize))();
1160 //   printf("----------------------------------\n");
1161 //   
1162 //   exit(0); 
1163 }
1164
1165 ////////////////////////////////////////////////////////////////////////////////
1166 // HERE END THE NEW CODE
1167 ////////////////////////////////////////////////////////////////////////////////
1168
1169 // /* ************************************************************************** */
1170 // /* *************************** FULL ROUTING ********************************* */
1171 // typedef struct {
1172 //   s_routing_t generic_routing;
1173 //   xbt_dynar_t *routing_table;
1174 //   void *loopback;
1175 //   size_t size_of_link;
1176 // } s_routing_full_t,*routing_full_t;
1177 // 
1178 // #define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count]
1179 // #define HOST2ROUTER(id) ((id)+(2<<29))
1180 // #define ROUTER2HOST(id) ((id)-(2>>29))
1181 // #define ISROUTER(id) ((id)>=(2<<29))
1182 // 
1183 // /*
1184 //  * Free the onelink routes
1185 //  */
1186 // static void onelink_route_elem_free(void *e) {
1187 //   s_onelink_t tmp = (s_onelink_t)e;
1188 //   if(tmp) {
1189 //     free(tmp);
1190 //   }
1191 // }
1192 // 
1193 // /*
1194 //  * Parsing
1195 //  */
1196 // static void routing_full_parse_Shost(void) {
1197 //   int *val = xbt_malloc(sizeof(int));
1198 //   DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count);
1199 //   *val = used_routing->host_count++;
1200 //   xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free);
1201 // #ifdef HAVE_TRACING
1202 //   TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1203 // #endif
1204 // }
1205 // 
1206 // static void routing_full_parse_Srouter(void) {
1207 //      int *val = xbt_malloc(sizeof(int));
1208 //   DEBUG3("Seen router %s (%d -> #%d)",A_surfxml_router_id,used_routing->router_count,
1209 //              HOST2ROUTER(used_routing->router_count));
1210 //   *val = HOST2ROUTER(used_routing->router_count++);
1211 //   xbt_dict_set(used_routing->host_id,A_surfxml_router_id,val,xbt_free);
1212 // #ifdef HAVE_TRACING
1213 //   TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1214 //   TRACE_surf_host_declaration (A_surfxml_host_id, 0);
1215 // #endif
1216 // }
1217 // 
1218 // static int src_id = -1;
1219 // static int dst_id = -1;
1220 // static void routing_full_parse_Sroute_set_endpoints(void)
1221 // {
1222 //   src_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_src);
1223 //   dst_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_dst);
1224 //   DEBUG4("Route %s %d -> %s %d",A_surfxml_route_src,src_id,A_surfxml_route_dst,dst_id);
1225 //   route_action = A_surfxml_route_action;
1226 // }
1227 // 
1228 // static void routing_full_parse_Eroute(void)
1229 // {
1230 //   char *name;
1231 //   if (src_id != -1 && dst_id != -1) {
1232 //     name = bprintf("%x#%x", src_id, dst_id);
1233 //     manage_route(route_table, name, route_action, 0);
1234 //     free(name);
1235 //   }
1236 // }
1237 // 
1238 // /* Cluster tag functions */
1239 // 
1240 // static void routing_full_parse_change_cpu_data(const char *hostName,
1241 //                                   const char *surfxml_host_power,
1242 //                                   const char *surfxml_host_availability,
1243 //                                   const char *surfxml_host_availability_file,
1244 //                                   const char *surfxml_host_state_file)
1245 // {
1246 //   int AX_ptr = 0;
1247 // 
1248 //   SURFXML_BUFFER_SET(host_id, hostName);
1249 //   SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
1250 //   SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
1251 //   SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
1252 //   SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
1253 // }
1254 // 
1255 // static void routing_full_parse_change_link_data(const char *linkName,
1256 //                                    const char *surfxml_link_bandwidth,
1257 //                                    const char *surfxml_link_bandwidth_file,
1258 //                                    const char *surfxml_link_latency,
1259 //                                    const char *surfxml_link_latency_file,
1260 //                                    const char *surfxml_link_state_file)
1261 // {
1262 //   int AX_ptr = 0;
1263 // 
1264 //   SURFXML_BUFFER_SET(link_id, linkName);
1265 //   SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
1266 //   SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
1267 //   SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
1268 //   SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
1269 //   SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
1270 // }
1271 // 
1272 // static void routing_full_parse_Scluster(void)
1273 // {
1274 //   static int AX_ptr = 0;
1275 // 
1276 //   char *cluster_id = A_surfxml_cluster_id;
1277 //   char *cluster_prefix = A_surfxml_cluster_prefix;
1278 //   char *cluster_suffix = A_surfxml_cluster_suffix;
1279 //   char *cluster_radical = A_surfxml_cluster_radical;
1280 //   char *cluster_power = A_surfxml_cluster_power;
1281 //   char *cluster_bw = A_surfxml_cluster_bw;
1282 //   char *cluster_lat = A_surfxml_cluster_lat;
1283 //   char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1284 //   char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1285 //   char *backbone_name;
1286 //   unsigned int it1,it2;
1287 //   char *name1,*name2;
1288 //   xbt_dynar_t names = NULL;
1289 //   surfxml_bufferstack_push(1);
1290 // 
1291 //   /* Make set a set to parse the prefix/suffix/radical into a neat list of names */
1292 //   DEBUG4("Make <set id='%s' prefix='%s' suffix='%s' radical='%s'>",
1293 //       cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
1294 //   SURFXML_BUFFER_SET(set_id, cluster_id);
1295 //   SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1296 //   SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1297 //   SURFXML_BUFFER_SET(set_radical, cluster_radical);
1298 // 
1299 //   SURFXML_START_TAG(set);
1300 //   SURFXML_END_TAG(set);
1301 // 
1302 //   names = xbt_dict_get(set_list,cluster_id);
1303 // 
1304 //   xbt_dynar_foreach(names,it1,name1) {
1305 //     /* create the host */
1306 //     routing_full_parse_change_cpu_data(name1, cluster_power, "1.0", "", "");
1307 //     A_surfxml_host_state = A_surfxml_host_state_ON;
1308 // 
1309 //     SURFXML_START_TAG(host);
1310 //     SURFXML_END_TAG(host);
1311 // 
1312 //     /* Here comes the link */
1313 //     routing_full_parse_change_link_data(name1, cluster_bw, "", cluster_lat, "", "");
1314 //     A_surfxml_link_state = A_surfxml_link_state_ON;
1315 //     A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1316 // 
1317 //     SURFXML_START_TAG(link);
1318 //     SURFXML_END_TAG(link);
1319 //   }
1320 // 
1321 //   /* Make backbone link */
1322 //   backbone_name = bprintf("%s_bb", cluster_id);
1323 //   routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1324 //                          "");
1325 //   A_surfxml_link_state = A_surfxml_link_state_ON;
1326 //   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1327 // 
1328 //   SURFXML_START_TAG(link);
1329 //   SURFXML_END_TAG(link);
1330 // 
1331 //   /* And now the internal routes */
1332 //   xbt_dynar_foreach(names,it1,name1) {
1333 //     xbt_dynar_foreach(names,it2,name2) {
1334 //       if (strcmp(name1,name2)) {
1335 //         A_surfxml_route_action = A_surfxml_route_action_POSTPEND;
1336 //         SURFXML_BUFFER_SET(route_src,name1);
1337 //         SURFXML_BUFFER_SET(route_dst,name2);
1338 //         SURFXML_START_TAG(route); {
1339 //           /* FIXME: name1 link is added by error about 20 lines below, so don't add it here
1340 //           SURFXML_BUFFER_SET(link_c_ctn_id, name1);
1341 //           SURFXML_START_TAG(link_c_ctn);
1342 //           SURFXML_END_TAG(link_c_ctn);
1343 //            */
1344 //           SURFXML_BUFFER_SET(link_c_ctn_id, backbone_name);
1345 //           SURFXML_START_TAG(link_c_ctn);
1346 //           SURFXML_END_TAG(link_c_ctn);
1347 // 
1348 //           SURFXML_BUFFER_SET(link_c_ctn_id, name2);
1349 //           SURFXML_START_TAG(link_c_ctn);
1350 //           SURFXML_END_TAG(link_c_ctn);
1351 // 
1352 //         } SURFXML_END_TAG(route);
1353 //       }
1354 //     }
1355 //   }
1356 // 
1357 //   /* Make route multi with the outside world, i.e. cluster->$* */
1358 // 
1359 //   /* FIXME
1360 //    * This also adds an elements to the routes within the cluster,
1361 //    * and I guess it's wrong, but since this element is commented out in the above
1362 //    * code creating the internal routes, we're good.
1363 //    * To fix it, I'd say that we need a way to understand "$*-${cluster_id}" as "whole world, but the guys in that cluster"
1364 //    * But for that, we need to install a real expression parser for src/dst attributes
1365 //    *
1366 //    * FIXME
1367 //    * This also adds a dumb element (the private link) in place of the loopback. Then, since
1368 //    * the loopback is added only if no link to self already exist, this fails.
1369 //    * That's really dumb.
1370 //    *
1371 //    * FIXME
1372 //    * It seems to me that it does not add the backbone to the path to outside world...
1373 //    */
1374 //   SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1375 //   SURFXML_BUFFER_SET(route_c_multi_dst, "$*");
1376 //   A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1377 //   A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_PREPEND;
1378 // 
1379 //   SURFXML_START_TAG(route_c_multi);
1380 // 
1381 //   SURFXML_BUFFER_SET(link_c_ctn_id, "$src");
1382 // 
1383 //   SURFXML_START_TAG(link_c_ctn);
1384 //   SURFXML_END_TAG(link_c_ctn);
1385 // 
1386 //   SURFXML_END_TAG(route_c_multi);
1387 // 
1388 //   free(backbone_name);
1389 // 
1390 //   /* Restore buff */
1391 //   surfxml_bufferstack_pop(1);
1392 // }
1393 // 
1394 // 
1395 // static void routing_full_parse_end(void) {
1396 //   routing_full_t routing = (routing_full_t) used_routing;
1397 //   int nb_link = 0;
1398 //   unsigned int cpt = 0;
1399 //   xbt_dict_cursor_t cursor = NULL;
1400 //   char *key, *data, *end;
1401 //   const char *sep = "#";
1402 //   xbt_dynar_t links, keys;
1403 //   char *link_name = NULL;
1404 //   int i,j;
1405 // 
1406 //   int host_count = routing->generic_routing.host_count;
1407 // 
1408 //   /* Create the routing table */
1409 //   routing->routing_table = xbt_new0(xbt_dynar_t, host_count * host_count);
1410 //   for (i=0;i<host_count;i++)
1411 //     for (j=0;j<host_count;j++)
1412 //       ROUTE_FULL(i,j) = xbt_dynar_new(routing->size_of_link,NULL);
1413 // 
1414 //   /* Put the routes in position */
1415 //   xbt_dict_foreach(route_table, cursor, key, data) {
1416 //     nb_link = 0;
1417 //     links = (xbt_dynar_t) data;
1418 //     keys = xbt_str_split_str(key, sep);
1419 // 
1420 //     src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1421 //     dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1422 //     xbt_dynar_free(&keys);
1423 // 
1424 //     if(xbt_dynar_length(links) == 1){
1425 //       s_onelink_t new_link = (s_onelink_t) xbt_malloc0(sizeof(s_onelink));
1426 //       new_link->src_id = src_id;
1427 //       new_link->dst_id = dst_id;
1428 //       link_name = xbt_dynar_getfirst_as(links, char*);
1429 //       new_link->link_ptr = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1430 //       DEBUG3("Adding onelink route from (#%d) to (#%d), link_name %s",src_id, dst_id, link_name);
1431 //       xbt_dict_set(onelink_routes, link_name, (void *)new_link, onelink_route_elem_free);
1432 // #ifdef HAVE_TRACING
1433 //       TRACE_surf_link_save_endpoints (link_name, src_id, dst_id);
1434 // #endif
1435 //     }
1436 // 
1437 //     if(ISROUTER(src_id) || ISROUTER(dst_id)) {
1438 //                              DEBUG2("There is route with a router here: (%d ,%d)",src_id,dst_id);
1439 //                              /* Check there is only one link in the route and store the information */
1440 //                              continue;
1441 //     }
1442 // 
1443 //     DEBUG4("Handle %d %d (from %d hosts): %ld links",
1444 //         src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1445 //     xbt_dynar_foreach(links, cpt, link_name) {
1446 //       void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1447 //       if (link)
1448 //         xbt_dynar_push(ROUTE_FULL(src_id,dst_id),&link);
1449 //       else
1450 //         THROW1(mismatch_error,0,"Link %s not found", link_name);
1451 //     }
1452 //   }
1453 // 
1454 //   /* Add the loopback if needed */
1455 //   for (i = 0; i < host_count; i++)
1456 //     if (!xbt_dynar_length(ROUTE_FULL(i, i)))
1457 //       xbt_dynar_push(ROUTE_FULL(i,i),&routing->loopback);
1458 // 
1459 //   /* Shrink the dynar routes (save unused slots) */
1460 //   for (i=0;i<host_count;i++)
1461 //     for (j=0;j<host_count;j++)
1462 //       xbt_dynar_shrink(ROUTE_FULL(i,j),0);
1463 // }
1464 // 
1465 // /*
1466 //  * Business methods
1467 //  */
1468 // static xbt_dynar_t routing_full_get_route(int src,int dst) {
1469 //   xbt_assert0(!(ISROUTER(src) || ISROUTER(dst)), "Ask for route \"from\" or \"to\" a router node");
1470 //   return ROUTE_FULL(src,dst);
1471 // }
1472 // 
1473 // static xbt_dict_t routing_full_get_onelink_routes(void){
1474 //   return onelink_routes;
1475 // }
1476 // 
1477 // static int routing_full_is_router(int id){
1478 //      return ISROUTER(id);
1479 // }
1480 // 
1481 // static void routing_full_finalize(void) {
1482 //   routing_full_t routing = (routing_full_t)used_routing;
1483 //   int i,j;
1484 // 
1485 //   if (routing) {
1486 //     for (i = 0; i < used_routing->host_count; i++)
1487 //       for (j = 0; j < used_routing->host_count; j++)
1488 //         xbt_dynar_free(&ROUTE_FULL(i, j));
1489 //     free(routing->routing_table);
1490 //     xbt_dict_free(&used_routing->host_id);
1491 //     xbt_dict_free(&onelink_routes);
1492 //     free(routing);
1493 //     routing=NULL;
1494 //   }
1495 // }
1496 // 
1497 // static void routing_model_full_create(size_t size_of_link,void *loopback) {
1498 //   /* initialize our structure */
1499 //   routing_full_t routing = xbt_new0(s_routing_full_t,1);
1500 //   routing->generic_routing.name = "Full";
1501 //   routing->generic_routing.host_count = 0;
1502 //   routing->generic_routing.get_route = routing_full_get_route;
1503 //   routing->generic_routing.get_onelink_routes = routing_full_get_onelink_routes;
1504 //   routing->generic_routing.is_router = routing_full_is_router;
1505 //   routing->generic_routing.finalize = routing_full_finalize;
1506 // 
1507 //   routing->size_of_link = size_of_link;
1508 //   routing->loopback = loopback;
1509 // 
1510 //   /* Set it in position */
1511 //   used_routing = (routing_t) routing;
1512 // 
1513 //   /* Set the dict for onehop routes */
1514 //   onelink_routes =  xbt_dict_new();
1515 // 
1516 //   routing->generic_routing.host_id = xbt_dict_new();
1517 //   
1518 //   /* Setup the parsing callbacks we need */
1519 // //   surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1520 // //   surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1521 // //   surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_full_parse_end);
1522 // //   surfxml_add_callback(STag_surfxml_route_cb_list, &routing_full_parse_Sroute_set_endpoints);
1523 // //   surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1524 // //   surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
1525 // 
1526 // //   surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1527 // //   surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1528 //   
1529 // }
1530
1531 /* ************************************************************************** */
1532
1533 // static void routing_shortest_path_parse_Scluster(void)
1534 // {
1535 //   static int AX_ptr = 0;
1536 // 
1537 //   char *cluster_id = A_surfxml_cluster_id;
1538 //   char *cluster_prefix = A_surfxml_cluster_prefix;
1539 //   char *cluster_suffix = A_surfxml_cluster_suffix;
1540 //   char *cluster_radical = A_surfxml_cluster_radical;
1541 //   char *cluster_power = A_surfxml_cluster_power;
1542 //   char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1543 //   char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1544 //   char *backbone_name;
1545 // 
1546 //   surfxml_bufferstack_push(1);
1547 // 
1548 //   /* Make set */
1549 //   SURFXML_BUFFER_SET(set_id, cluster_id);
1550 //   SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1551 //   SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1552 //   SURFXML_BUFFER_SET(set_radical, cluster_radical);
1553 // 
1554 //   SURFXML_START_TAG(set);
1555 //   SURFXML_END_TAG(set);
1556 // 
1557 //   /* Make foreach */
1558 //   SURFXML_BUFFER_SET(foreach_set_id, cluster_id);
1559 // 
1560 //   SURFXML_START_TAG(foreach);
1561 // 
1562 //   /* Make host for the foreach */
1563 //   routing_full_parse_change_cpu_data("$1", cluster_power, "1.0", "", "");
1564 //   A_surfxml_host_state = A_surfxml_host_state_ON;
1565 // 
1566 //   SURFXML_START_TAG(host);
1567 //   SURFXML_END_TAG(host);
1568 // 
1569 //   SURFXML_END_TAG(foreach);
1570 // 
1571 //   /* Make backbone link */
1572 //   backbone_name = bprintf("%s_bb", cluster_id);
1573 //   routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1574 //                          "");
1575 //   A_surfxml_link_state = A_surfxml_link_state_ON;
1576 //   A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1577 // 
1578 //   SURFXML_START_TAG(link);
1579 //   SURFXML_END_TAG(link);
1580 // 
1581 //   free(backbone_name);
1582 // 
1583 //   /* Restore buff */
1584 //   surfxml_bufferstack_pop(1);
1585 // }
1586 // 
1587 // /* ************************************************************************** */
1588 // /* *************************** FLOYD ROUTING ********************************* */
1589 // typedef struct {
1590 //   s_routing_t generic_routing;
1591 //   int *predecessor_table;
1592 //   void** link_table;
1593 //   xbt_dynar_t last_route;
1594 //   void *loopback;
1595 //   size_t size_of_link;
1596 // } s_routing_floyd_t,*routing_floyd_t;
1597 // 
1598 // #define FLOYD_COST(i,j) cost_table[(i)+(j)*(used_routing)->host_count]
1599 // #define FLOYD_PRED(i,j) ((routing_floyd_t)used_routing)->predecessor_table[(i)+(j)*(used_routing)->host_count]
1600 // #define FLOYD_LINK(i,j) ((routing_floyd_t)used_routing)->link_table[(i)+(j)*(used_routing)->host_count]
1601 // 
1602 // static void routing_floyd_parse_end(void) {
1603 // 
1604 //   routing_floyd_t routing = (routing_floyd_t) used_routing;
1605 //   int nb_link = 0;
1606 //   void* link_list = NULL;
1607 //   double * cost_table;
1608 //   xbt_dict_cursor_t cursor = NULL;
1609 //   char *key,*data, *end;
1610 //   const char *sep = "#";
1611 //   xbt_dynar_t links, keys;
1612 // 
1613 //   unsigned int i,j;
1614 //   unsigned int a,b,c;
1615 //   int host_count = routing->generic_routing.host_count;
1616 //   char * link_name = NULL;
1617 //   void * link = NULL;
1618 // 
1619 //   /* Create Cost, Predecessor and Link tables */
1620 //   cost_table = xbt_new0(double, host_count * host_count); //link cost from host to host
1621 //   routing->predecessor_table = xbt_new0(int, host_count*host_count); //predecessor host numbers
1622 //   routing->link_table = xbt_new0(void*,host_count*host_count); //actual link between src and dst
1623 //   routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1624 // 
1625 //   /* Initialize costs and predecessors*/
1626 //   for(i = 0; i<host_count;i++)
1627 //     for(j = 0; j<host_count;j++) {
1628 //         FLOYD_COST(i,j) = DBL_MAX;
1629 //         FLOYD_PRED(i,j) = -1;
1630 //     }
1631 // 
1632 //    /* Put the routes in position */
1633 //   xbt_dict_foreach(route_table, cursor, key, data) {
1634 //     nb_link = 0;
1635 //     links = (xbt_dynar_t)data;
1636 //     keys = xbt_str_split_str(key, sep);
1637 // 
1638 //     
1639 //     src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
1640 //     dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
1641 //     xbt_dynar_free(&keys);
1642 //  
1643 //     DEBUG4("Handle %d %d (from %d hosts): %ld links",
1644 //         src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1645 //     xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id);
1646 //     
1647 //     link_name = xbt_dynar_getfirst_as(links, char*);
1648 //     link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1649 // 
1650 //     if (link)
1651 //       link_list = link;
1652 //     else
1653 //       THROW1(mismatch_error,0,"Link %s not found", link_name);
1654 //     
1655 // 
1656 //     FLOYD_LINK(src_id,dst_id) = link_list;
1657 //     FLOYD_PRED(src_id, dst_id) = src_id;
1658 // 
1659 //     //link cost
1660 //     FLOYD_COST(src_id, dst_id) = 1; // assume 1 for now
1661 // 
1662 //   }
1663 // 
1664 //     /* Add the loopback if needed */
1665 //   for (i = 0; i < host_count; i++)
1666 //     if (!FLOYD_PRED(i, i)) {
1667 //       FLOYD_PRED(i, i) = i;
1668 //       FLOYD_COST(i, i) = 1;
1669 //       FLOYD_LINK(i, i) = routing->loopback;
1670 //     }
1671 // 
1672 // 
1673 //   //Calculate path costs 
1674 // 
1675 //   for(c=0;c<host_count;c++) {
1676 //     for(a=0;a<host_count;a++) {
1677 //       for(b=0;b<host_count;b++) {
1678 //         if(FLOYD_COST(a,c) < DBL_MAX && FLOYD_COST(c,b) < DBL_MAX) {
1679 //           if(FLOYD_COST(a,b) == DBL_MAX || (FLOYD_COST(a,c)+FLOYD_COST(c,b) < FLOYD_COST(a,b))) {
1680 //             FLOYD_COST(a,b) = FLOYD_COST(a,c)+FLOYD_COST(c,b);
1681 //             FLOYD_PRED(a,b) = FLOYD_PRED(c,b);
1682 //           }
1683 //         }
1684 //       }
1685 //     }
1686 //   }
1687 // 
1688 //   //cleanup
1689 //   free(cost_table);
1690 // }
1691 // 
1692 // /*
1693 //  * Business methods
1694 //  */
1695 // static xbt_dynar_t routing_floyd_get_route(int src_id,int dst_id) {
1696 // 
1697 //   routing_floyd_t routing = (routing_floyd_t) used_routing;
1698 // 
1699 //   int pred = dst_id;
1700 //   int prev_pred = 0;
1701 // 
1702 //   xbt_dynar_reset(routing->last_route);
1703 // 
1704 //   do {
1705 //     prev_pred = pred;
1706 //     pred = FLOYD_PRED(src_id, pred);
1707 // 
1708 //     if(pred == -1) // if no pred in route -> no route to host
1709 //         break;
1710 // 
1711 //     xbt_dynar_unshift(routing->last_route, &FLOYD_LINK(pred,prev_pred));
1712 // 
1713 //   } while(pred != src_id);
1714 // 
1715 //   xbt_assert2(pred != -1, "no route from host %d to %d", src_id, dst_id);
1716 // 
1717 //   return routing->last_route;
1718 // }
1719 // 
1720 // static void routing_floyd_finalize(void) {
1721 //   routing_floyd_t routing = (routing_floyd_t)used_routing;
1722 // 
1723 //   if (routing) {
1724 //     free(routing->link_table);
1725 //     free(routing->predecessor_table);
1726 //     xbt_dynar_free(&routing->last_route);
1727 //     xbt_dict_free(&used_routing->host_id);
1728 //     free(routing);
1729 //     routing=NULL;
1730 //   }
1731 // }
1732 // 
1733 // static xbt_dict_t routing_floyd_get_onelink_routes(void){
1734 //   xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model Floyd");
1735 // }
1736 // 
1737 // static int routing_floyd_is_router(int id){
1738 //   xbt_assert0(0,"The get_is_router feature is not supported in routing model Floyd");
1739 // }
1740 // 
1741 // static void routing_model_floyd_create(size_t size_of_link,void *loopback) {
1742 //   /* initialize our structure */
1743 //   routing_floyd_t routing = xbt_new0(s_routing_floyd_t,1);
1744 //   routing->generic_routing.name = "Floyd";
1745 //   routing->generic_routing.host_count = 0;
1746 //   routing->generic_routing.host_id = xbt_dict_new();
1747 //   routing->generic_routing.get_route = routing_floyd_get_route;
1748 //   routing->generic_routing.get_onelink_routes = routing_floyd_get_onelink_routes;
1749 //   routing->generic_routing.is_router = routing_floyd_is_router;
1750 //   routing->generic_routing.finalize = routing_floyd_finalize;
1751 //   routing->size_of_link = size_of_link;
1752 //   routing->loopback = loopback;
1753 // 
1754 //   /* Set it in position */
1755 //   used_routing = (routing_t) routing;
1756 //   
1757 //   /* Setup the parsing callbacks we need */
1758 //   surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1759 //   surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_floyd_parse_end);
1760 //   surfxml_add_callback(STag_surfxml_route_cb_list, 
1761 //       &routing_full_parse_Sroute_set_endpoints);
1762 //   surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1763 //   surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
1764 //   
1765 // }
1766 // 
1767 // /* ************************************************************************** */
1768 // /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1769 // typedef struct {
1770 //   s_routing_t generic_routing;
1771 //   xbt_graph_t route_graph;
1772 //   xbt_dict_t graph_node_map;
1773 //   xbt_dict_t route_cache;
1774 //   xbt_dynar_t last_route;
1775 //   int cached;
1776 //   void *loopback;
1777 //   size_t size_of_link;
1778 // } s_routing_dijkstra_t,*routing_dijkstra_t;
1779 // 
1780 // 
1781 // typedef struct graph_node_data {
1782 //   int id; 
1783 //   int graph_id; //used for caching internal graph id's
1784 // } s_graph_node_data_t, * graph_node_data_t;
1785 // 
1786 // typedef struct graph_node_map_element {
1787 //   xbt_node_t node;
1788 // } s_graph_node_map_element_t, * graph_node_map_element_t;
1789 // 
1790 // typedef struct route_cache_element {
1791 //   int * pred_arr;
1792 //   int size;
1793 // } s_route_cache_element_t, * route_cache_element_t;  
1794 // 
1795 // /*
1796 //  * Free functions
1797 //  */
1798 // static void route_cache_elem_free(void *e) {
1799 //   route_cache_element_t elm=(route_cache_element_t)e;
1800 // 
1801 //   if (elm) {
1802 //     free(elm->pred_arr);
1803 //     free(elm);
1804 //   }
1805 // }
1806 // 
1807 // static void graph_node_map_elem_free(void *e) {
1808 //   graph_node_map_element_t elm = (graph_node_map_element_t)e;
1809 // 
1810 //   if(elm) {
1811 //     free(elm);
1812 //   }
1813 // }
1814 // 
1815 // /*
1816 //  * Utility functions
1817 // */
1818 // static xbt_node_t route_graph_new_node(int id, int graph_id) {
1819 //   xbt_node_t node = NULL;
1820 //   graph_node_data_t data = NULL;
1821 //   graph_node_map_element_t elm = NULL;
1822 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1823 // 
1824 //   data = xbt_new0(struct graph_node_data, sizeof(struct graph_node_data));
1825 //   data->id = id;
1826 //   data->graph_id = graph_id;
1827 //   node = xbt_graph_new_node(routing->route_graph, data);
1828 // 
1829 //   elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element));
1830 //   elm->node = node;
1831 //   xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free);
1832 // 
1833 //   return node;
1834 // }
1835 // 
1836 // static graph_node_map_element_t graph_node_map_search(int id) {
1837 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1838 // 
1839 //   graph_node_map_element_t elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&id), sizeof(int));
1840 // 
1841 //   return elm;
1842 // }
1843 // 
1844 // /*
1845 //  * Parsing
1846 //  */
1847 // static void route_new_dijkstra(int src_id, int dst_id, void* link) {
1848 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1849 // 
1850 //   xbt_node_t src = NULL;
1851 //   xbt_node_t dst = NULL;
1852 //   graph_node_map_element_t src_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&src_id), sizeof(int));
1853 //   graph_node_map_element_t dst_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&dst_id), sizeof(int));
1854 // 
1855 //   if(src_elm)
1856 //     src = src_elm->node;
1857 // 
1858 //   if(dst_elm)
1859 //     dst = dst_elm->node;
1860 // 
1861 //   //add nodes if they don't exist in the graph
1862 //   if(src_id == dst_id && src == NULL && dst == NULL) {
1863 //     src = route_graph_new_node(src_id, -1);
1864 //     dst = src;
1865 //   } else {
1866 //     if(src == NULL) {
1867 //       src = route_graph_new_node(src_id, -1);
1868 //     }
1869 //      
1870 //     if(dst == NULL) {
1871 //       dst = route_graph_new_node(dst_id, -1);
1872 //     }
1873 //   }
1874 // 
1875 //   //add link as edge to graph
1876 //   xbt_graph_new_edge(routing->route_graph, src, dst, link);
1877 //   
1878 // }
1879 // 
1880 // static void add_loopback_dijkstra(void) {
1881 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1882 // 
1883 //      xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1884 //      
1885 //      xbt_node_t node = NULL;
1886 //      unsigned int cursor2;
1887 //      xbt_dynar_foreach(nodes, cursor2, node) {
1888 //              xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node); 
1889 //              xbt_edge_t edge = NULL;
1890 //              unsigned int cursor;
1891 //      
1892 //              int found = 0;
1893 //              xbt_dynar_foreach(out_edges, cursor, edge) {
1894 //                      xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1895 //                      if(other_node == node) {
1896 //                              found = 1;
1897 //                              break;
1898 //                      }
1899 //              }
1900 // 
1901 //              if(!found)
1902 //                      xbt_graph_new_edge(routing->route_graph, node, node, &routing->loopback);
1903 //      }
1904 // }
1905 // 
1906 // static void routing_dijkstra_parse_end(void) {
1907 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1908 //   int nb_link = 0;
1909 //   xbt_dict_cursor_t cursor = NULL;
1910 //   char *key, *data, *end;
1911 //   const char *sep = "#";
1912 //   xbt_dynar_t links, keys;
1913 //   char* link_name = NULL;
1914 //   void* link = NULL;
1915 //   xbt_node_t node = NULL;
1916 //   unsigned int cursor2;
1917 //   xbt_dynar_t nodes = NULL;
1918 //   /* Create the topology graph */
1919 //   routing->route_graph = xbt_graph_new_graph(1, NULL);
1920 //   routing->graph_node_map = xbt_dict_new();
1921 //   routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1922 //   if(routing->cached)
1923 //     routing->route_cache = xbt_dict_new();
1924 // 
1925 // 
1926 //   /* Put the routes in position */
1927 //   xbt_dict_foreach(route_table, cursor, key, data) {
1928 //     nb_link = 0;
1929 //     links = (xbt_dynar_t) data;
1930 //     keys = xbt_str_split_str(key, sep);
1931 // 
1932 //     src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1933 //     dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1934 //     xbt_dynar_free(&keys);
1935 // 
1936 //     DEBUG4("Handle %d %d (from %d hosts): %ld links",
1937 //         src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1938 // 
1939 //     xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id);
1940 // 
1941 //     link_name = xbt_dynar_getfirst_as(links, char*);
1942 //     link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1943 //     if (link)
1944 //       route_new_dijkstra(src_id,dst_id,link);
1945 //     else
1946 //       THROW1(mismatch_error,0,"Link %s not found", link_name);
1947 //     
1948 //   }
1949 // 
1950 //   /* Add the loopback if needed */
1951 //   add_loopback_dijkstra();
1952 // 
1953 //   /* initialize graph indexes in nodes after graph has been built */
1954 //   nodes = xbt_graph_get_nodes(routing->route_graph);
1955 // 
1956 //   xbt_dynar_foreach(nodes, cursor2, node) {
1957 //     graph_node_data_t data = xbt_graph_node_get_data(node);
1958 //     data->graph_id = cursor2;
1959 //   }
1960 // 
1961 // }
1962 // 
1963 // /*
1964 //  * Business methods
1965 //  */
1966 // static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) {
1967 // 
1968 //   routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1969 //   int * pred_arr = NULL;
1970 //   int src_node_id = 0;
1971 //   int dst_node_id = 0;
1972 //   int * nodeid = NULL;
1973 //   int v;
1974 //   int size = 0;
1975 //   void * link = NULL;
1976 //   route_cache_element_t elm = NULL;
1977 //   xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1978 // 
1979 //   /*Use the graph_node id mapping set to quickly find the nodes */
1980 //   graph_node_map_element_t src_elm = graph_node_map_search(src_id);
1981 //   graph_node_map_element_t dst_elm = graph_node_map_search(dst_id);
1982 //   xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", src_id, dst_id);
1983 //   src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
1984 //   dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
1985 // 
1986 //   if(routing->cached) {
1987 //     /*check if there is a cached predecessor list avail */
1988 //     elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int));
1989 //   }
1990 // 
1991 //   if(elm) { //cached mode and cache hit
1992 //     pred_arr = elm->pred_arr;
1993 //   } else { //not cached mode or cache miss
1994 //     double * cost_arr = NULL;
1995 //     xbt_heap_t pqueue = NULL;
1996 //     int i = 0;
1997 // 
1998 //     int nr_nodes = xbt_dynar_length(nodes);
1999 //     cost_arr = xbt_new0(double, nr_nodes); //link cost from src to other hosts
2000 //     pred_arr = xbt_new0(int, nr_nodes); //predecessors in path from src
2001 //     pqueue = xbt_heap_new(nr_nodes, free);
2002 // 
2003 //     //initialize
2004 //     cost_arr[src_node_id] = 0.0;
2005 // 
2006 //     for(i = 0; i < nr_nodes; i++) {
2007 //       if(i != src_node_id) {
2008 //         cost_arr[i] = DBL_MAX;
2009 //       }
2010 // 
2011 //       pred_arr[i] = 0;
2012 // 
2013 //       //initialize priority queue
2014 //       nodeid = xbt_new0(int, 1);
2015 //       *nodeid = i;
2016 //       xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2017 // 
2018 //     }
2019 // 
2020 //     // apply dijkstra using the indexes from the graph's node array
2021 //     while(xbt_heap_size(pqueue) > 0) {
2022 //       int * v_id = xbt_heap_pop(pqueue);
2023 //       xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2024 //       xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node); 
2025 //       xbt_edge_t edge = NULL;
2026 //       unsigned int cursor;
2027 // 
2028 //       xbt_dynar_foreach(out_edges, cursor, edge) {
2029 //         xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2030 //         graph_node_data_t data = xbt_graph_node_get_data(u_node);
2031 //         int u_id = data->graph_id;
2032 //         int cost_v_u = 1; //fixed link cost for now
2033 // 
2034 //         if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2035 //           pred_arr[u_id] = *v_id;
2036 //           cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2037 //           nodeid = xbt_new0(int, 1);
2038 //           *nodeid = u_id;
2039 //           xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2040 //         }
2041 //       }
2042 // 
2043 //       //free item popped from pqueue
2044 //       free(v_id);
2045 //     }
2046 // 
2047 //     free(cost_arr);
2048 //     xbt_heap_free(pqueue);
2049 // 
2050 //   }
2051 // 
2052 //   //compose route path with links
2053 //   xbt_dynar_reset(routing->last_route);
2054 // 
2055 //   for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2056 //     xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2057 //     xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2058 //     xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2059 // 
2060 //     xbt_assert2(edge != NULL, "no route between host %d and %d", src_id, dst_id);
2061 // 
2062 //     link = xbt_graph_edge_get_data(edge);
2063 //     xbt_dynar_unshift(routing->last_route, &link);
2064 //     size++;
2065 //   }
2066 // 
2067 // 
2068 //   if(routing->cached && elm == NULL) {
2069 //     //add to predecessor list of the current src-host to cache
2070 //     elm = xbt_new0(struct route_cache_element, sizeof(struct route_cache_element));
2071 //     elm->pred_arr = pred_arr;
2072 //     elm->size = size;
2073 //     xbt_dict_set_ext(routing->route_cache, (char*)(&src_id), sizeof(int), (xbt_set_elm_t)elm, &route_cache_elem_free);
2074 //   }
2075 // 
2076 //   if(!routing->cached)
2077 //     free(pred_arr);
2078 // 
2079 //   return routing->last_route;
2080 // }
2081 // 
2082 // 
2083 // static void routing_dijkstra_finalize(void) {
2084 //   routing_dijkstra_t routing = (routing_dijkstra_t)used_routing;
2085 // 
2086 //   if (routing) {
2087 //     xbt_graph_free_graph(routing->route_graph, &free, NULL, &free);
2088 //     xbt_dict_free(&routing->graph_node_map);
2089 //     if(routing->cached)
2090 //       xbt_dict_free(&routing->route_cache);
2091 //     xbt_dynar_free(&routing->last_route);
2092 //     xbt_dict_free(&used_routing->host_id);
2093 //     free(routing);
2094 //     routing=NULL;
2095 //   }
2096 // }
2097 // 
2098 // static xbt_dict_t routing_dijkstraboth_get_onelink_routes(void){
2099 //   xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model dijkstraboth");
2100 // }
2101 // 
2102 // static int routing_dijkstraboth_is_router(int id){
2103 //   xbt_assert0(0,"The get_is_router feature is not supported in routing model dijkstraboth");
2104 // }
2105 // 
2106 // /*
2107 //  *
2108 //  */
2109 // static void routing_model_dijkstraboth_create(size_t size_of_link,void *loopback, int cached) {
2110 //   /* initialize our structure */
2111 //   routing_dijkstra_t routing = xbt_new0(s_routing_dijkstra_t,1);
2112 //   routing->generic_routing.name = "Dijkstra";
2113 //   routing->generic_routing.host_count = 0;
2114 //   routing->generic_routing.get_route = routing_dijkstra_get_route;
2115 //   routing->generic_routing.get_onelink_routes = routing_dijkstraboth_get_onelink_routes;
2116 //   routing->generic_routing.is_router = routing_dijkstraboth_is_router;
2117 //   routing->generic_routing.finalize = routing_dijkstra_finalize;
2118 //   routing->size_of_link = size_of_link;
2119 //   routing->loopback = loopback;
2120 //   routing->cached = cached;
2121 // 
2122 //   /* Set it in position */
2123 //   used_routing = (routing_t) routing;
2124 // 
2125 //   /* Setup the parsing callbacks we need */
2126 //   routing->generic_routing.host_id = xbt_dict_new();
2127 //   surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
2128 //   surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_dijkstra_parse_end);
2129 //   surfxml_add_callback(STag_surfxml_route_cb_list,
2130 //       &routing_full_parse_Sroute_set_endpoints);
2131 //   surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
2132 //   surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
2133 // }
2134 // 
2135 // static void routing_model_dijkstra_create(size_t size_of_link,void *loopback) {
2136 //   routing_model_dijkstraboth_create(size_of_link, loopback, 0);
2137 // }
2138 // 
2139 // static void routing_model_dijkstracache_create(size_t size_of_link,void *loopback) {
2140 //   routing_model_dijkstraboth_create(size_of_link, loopback, 1);
2141 // }
2142
2143 /* ************************************************** */
2144 /* ********** NO ROUTING **************************** */
2145
2146
2147 // static void routing_none_finalize(void) {
2148 //   if (used_routing) {
2149 //     xbt_dict_free(&used_routing->host_id);
2150 //     free(used_routing);
2151 //     used_routing=NULL;
2152 //   }
2153 // }
2154 // 
2155 // static void routing_model_none_create(size_t size_of_link,void *loopback) {
2156 //   routing_t routing = xbt_new0(s_routing_t,1);
2157 //   INFO0("Null routing");
2158 //   routing->name = "none";
2159 //   routing->host_count = 0;
2160 //   routing->host_id = xbt_dict_new();
2161 //   routing->get_onelink_routes = NULL;
2162 //   routing->is_router = NULL;
2163 //   routing->get_route = NULL;
2164 // 
2165 //   routing->finalize = routing_none_finalize;
2166 // 
2167 //   /* Set it in position */
2168 //   used_routing = (routing_t) routing;
2169 // }