Logo AND Algorithmique Numérique Distribuée

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