Logo AND Algorithmique Numérique Distribuée

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