1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
8 #include "surf_private.h"
11 #include "xbt/config.h"
12 #include "xbt/graph.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf");
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;
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);
30 // /* Definition of each model */
31 // struct model_type {
34 // void (*fun)(size_t,void*);
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 },
45 ////////////////////////////////////////////////////////////////////////////////
46 // HERE START THE NEW CODE
47 ////////////////////////////////////////////////////////////////////////////////
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);
60 ////////////////////////////////////////////////////////////////////////////////
61 // HERE START THE NEW CODE
62 ////////////////////////////////////////////////////////////////////////////////
65 routing_global_t global_routing = NULL;
66 routing_component_t current_routing = NULL;
67 model_type_t current_routing_model = NULL;
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 */
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 */
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 */
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 */
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 */
95 /* Table of routing models */
96 /* must be finish with null and carefull if change de order */
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
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}};
118 /* global parse functions */
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 */
127 * \brief Add a "host" to the network element list
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);
141 * \brief Add a "router" to the network element list
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);
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);
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);
178 static void parse_E_link_c_ctn_new_elem(void) {
180 val = xbt_strdup(A_surfxml_link_c_ctn_id);
181 xbt_dynar_push(link_list, &val);
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);
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);
215 * \brief Make a new routing component
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
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;
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);
238 /* make a new routing component */
239 new_routing = (routing_component_t)(*(model->create))();
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);
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);
259 if( current_routing == NULL && global_routing->root == NULL ){
261 /* it is the first one */
262 new_routing->routing_father = NULL;
263 global_routing->root = new_routing;
265 } else if( current_routing != NULL && global_routing->root != NULL ) {
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))();
284 THROW0(arg_error,0,"All defined components must be belong to a AS");
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;
293 * \brief Finish the creation of a new routing component
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
298 static void parse_E_AS(void) {
300 if( current_routing == NULL ) {
301 THROW1(arg_error,0,"Close AS(%s), that never open",A_surfxml_AS_id);
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))();
312 * \brief Recursive function for add the differents AS to global dict
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.
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;
324 routing_component_t elem;
325 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
331 * \brief Add a "AS" to the network element list
333 * Allows find a "AS" in any routing component
335 static void parse_E_platform_add_parse_AS(void) {
336 _add_parse_AS(global_routing->root);
339 /* Aux Business methods */
341 static xbt_dynar_t elements_father(const char* src,const char* dst) {
343 xbt_dynar_t result = xbt_dynar_new(sizeof(char*), NULL); // &xbt_free_ref
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;
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");
359 /* (2) find the path to the root routing component */
360 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
362 while( current != NULL ) {
363 xbt_dynar_push(path_src,¤t);
364 current = current->routing_father;
366 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
368 while( current != NULL ) {
369 xbt_dynar_push(path_dst,¤t);
370 current = current->routing_father;
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);
386 current_src = xbt_dynar_get_ptr(path_src,index_src);
387 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
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;
393 if(*current_src==*current_dst)
394 father = current_src;
396 father = xbt_dynar_get_ptr(path_src,index_father_src);
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
403 xbt_dynar_free(&path_src);
404 xbt_dynar_free(&path_dst);
409 /* Global Business methods */
411 static route_extended_t _get_route(const char* src,const char* dst) {
416 DEBUG2("Solve route \"%s\" to \"%s\"",src,dst);
418 xbt_assert0(src&&dst,"bad parameters for _get_route method");
420 route_extended_t e_route, e_route_cnt, e_route_src, e_route_dst;
422 xbt_dynar_t elem_father_list = elements_father(src,dst);
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);
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);
433 if(src_father==dst_father) { /* SURF_ROUTING_BASE */
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);
442 } else { /* SURF_ROUTING_RECURSIVE */
444 e_route_cnt = (*(common_father->get_route))(common_father,src_father->name,dst_father->name);
446 xbt_assert2( (e_route_cnt->src_gateway==NULL) == (e_route_cnt->dst_gateway==NULL) ,
447 "bad gateway for route between \"%s\" and \"%s\"",src,dst);
449 if( src != e_route_cnt->src_gateway ) {
450 e_route_src = _get_route(src,e_route_cnt->src_gateway);
451 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
452 xbt_dynar_push(e_route->generic_route.link_list,&link);
456 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
457 xbt_dynar_push(e_route->generic_route.link_list,&link);
460 if( e_route_cnt->dst_gateway != dst ) {
461 e_route_dst = _get_route(e_route_cnt->dst_gateway,dst);
462 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
463 xbt_dynar_push(e_route->generic_route.link_list,&link);
467 e_route->src_gateway = e_route_cnt->src_gateway;
468 e_route->dst_gateway = e_route_cnt->dst_gateway;
470 xbt_dynar_free( &(e_route_src->generic_route.link_list) );
471 xbt_free(e_route_src);
472 xbt_dynar_free( &(e_route_cnt->generic_route.link_list) );
473 xbt_free(e_route_cnt);
474 xbt_dynar_free( &(e_route_dst->generic_route.link_list) );
475 xbt_free(e_route_dst);
478 xbt_dynar_free(&elem_father_list);
485 * \brief Generic method: find a route between hosts
487 * \param src the source host name
488 * \param dst the destination host name
490 * walk through the routing components tree and find a route between hosts
491 * by calling the differents "get_route" functions in each routing component
493 static xbt_dynar_t get_route(const char* src,const char* dst) {
495 if(global_routing->last_route) xbt_dynar_free( &(global_routing->last_route) );
497 route_extended_t e_route;
498 xbt_dynar_t elem_father_list = elements_father(src,dst);
499 routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
502 e_route = _get_route(src,dst);
504 e_route = (*(common_father->get_route))(common_father,src,dst);
506 global_routing->last_route = e_route->generic_route.link_list;
510 if( xbt_dynar_length(global_routing->last_route)==0 )
513 return global_routing->last_route;
517 * \brief Recursive function for finalize
519 * \param rc the source host name
521 * This fuction is call by "finalize". It allow to finalize the
522 * AS or routing components. It delete all the structures.
524 static void _finalize(routing_component_t rc) {
526 xbt_dict_cursor_t cursor = NULL;
528 routing_component_t elem;
529 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
532 xbt_dict_t tmp_sons = rc->routing_sons;
533 char* tmp_name = rc->name;
534 xbt_dict_free(&tmp_sons);
536 (*(rc->finalize))(rc);
541 * \brief Generic method: delete all the routing structures
543 * walk through the routing components tree and delete the structures
544 * by calling the differents "finalize" functions in each routing component
546 static void finalize(void) {
547 /* delete recursibly all the tree */
548 _finalize(global_routing->root);
549 /* delete "where" dict */
550 xbt_dict_free(&(global_routing->where_network_elements));
551 /* delete last_route */
552 xbt_dynar_free(&(global_routing->last_route));
553 /* delete global routing structure */
554 xbt_free(global_routing);
558 * \brief Generic method: create the global routing schema
560 * Make a global routing structure and set all the parsing functions.
562 void routing_model_create(size_t size_of_links, void* loopback) {
564 /* config the uniq global routing */
565 global_routing = xbt_new0(s_routing_global_t,1);
566 global_routing->where_network_elements = xbt_dict_new();
567 global_routing->root = NULL;
568 global_routing->get_route = get_route;
569 global_routing->finalize = finalize;
570 global_routing->loopback = loopback;
571 global_routing->size_of_link = size_of_links;
572 global_routing->last_route = xbt_dynar_new(size_of_links, NULL);
574 /* no current routing at moment */
575 current_routing = NULL;
577 /* parse generic elements */
578 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host);
579 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
581 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints);
582 surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints);
584 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_E_link_c_ctn_new_elem);
586 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route);
587 surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route);
589 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
590 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
592 /* set all the as in the global where table (recursive fuction) */
593 surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_E_platform_add_parse_AS);
596 //surfxml_add_callback(ETag_surfxml_platform_cb_list, &DEBUG_exit);
600 /* ************************************************************************** */
601 /* *************************** FULL ROUTING ********************************* */
603 #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)]
605 /* Routing model structure */
608 s_routing_component_t generic_routing;
609 xbt_dict_t parse_routes; /* store data during the parse process */
610 xbt_dict_t to_index; /* char* -> network_element_t */
611 route_extended_t *routing_table;
612 } s_routing_component_full_t,*routing_component_full_t;
614 /* Parse routing model functions */
617 /* Business methods */
619 static void full_set_processing_units(routing_component_t rc, const char* name) {
620 DEBUG1("Full - Load process unit \"%s\"",name);
621 // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
622 int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
623 *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
624 xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
627 static void full_set_autonomous_system(routing_component_t rc, const char* name) {
628 DEBUG1("Full - Load Autonomous system \"%s\"",name);
629 // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
630 int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
631 *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
632 xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
635 static void full_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
636 DEBUG2("Full - Load Route from \"%s\" to \"%s\"",src,dst);
637 routing_component_full_t routing = (routing_component_full_t)current_routing;
639 route_name = bprintf("%s#%s",src,dst);
640 xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
641 xbt_assert2(!xbt_dict_get_or_null(routing->parse_routes,route_name),
642 "The route between \"%s\" and \"%s\" already exist",src,dst);
643 xbt_dict_set(routing->parse_routes, route_name, route, NULL);
647 static void full_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
648 DEBUG4("Full - Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway);
649 routing_component_full_t routing = (routing_component_full_t)current_routing;
651 route_name = bprintf("%s#%s",src,dst);
652 xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
653 xbt_assert4(!xbt_dict_get_or_null(routing->parse_routes,route_name),
654 "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
655 src,e_route->src_gateway,dst,e_route->dst_gateway);
656 xbt_dict_set(routing->parse_routes, route_name, e_route, NULL);
660 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
662 routing_component_full_t routing = (routing_component_full_t)rc;
664 xbt_assert1(src && dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
666 routing_component_t src_as, dst_as;
669 src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
670 dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
672 xbt_assert0(src_as != NULL && dst_as != NULL, "Ask for route \"from\" or \"to\" no found");
673 xbt_assert0(src_as == dst_as, "The src and dst are in differents AS");
674 xbt_assert0(rc == dst_as, "The routing component of src and dst is not the same as the network elements belong");
676 src_id = xbt_dict_get(routing->to_index,src);
677 dst_id = xbt_dict_get(routing->to_index,dst);
679 xbt_assert0(src_id && dst_id, "Ask for route \"from\" or \"to\" no found in the local table");
683 route_extended_t e_route = TO_ROUTE_FULL(*src_id,*dst_id,routing);
684 route_extended_t new_e_route = xbt_new0(s_route_extended_t,1);
685 new_e_route->src_gateway = e_route->src_gateway;
686 new_e_route->dst_gateway = e_route->dst_gateway;
687 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
688 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
689 xbt_dynar_push(new_e_route->generic_route.link_list,&link);
694 static void full_finalize(routing_component_t rc) {
695 routing_component_full_t routing = (routing_component_full_t)rc;
698 int table_size = xbt_dict_length(routing->to_index);
699 /* Delete routing table */
700 for (i=0;i<table_size;i++) {
701 for (j=0;j<table_size;j++) {
702 route_extended_t e_route = TO_ROUTE_FULL(i,j,rc);
704 xbt_dynar_free(&(e_route->generic_route.link_list));
705 if(e_route->src_gateway) xbt_free(e_route->src_gateway);
706 if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
711 xbt_free(routing->routing_table);
712 /* Delete index dict */
713 xbt_dict_free(&(routing->to_index));
714 /* Delete structure */
719 /* Creation routing model functions */
721 static void* model_full_create() {
722 routing_component_full_t new_component = xbt_new0(s_routing_component_full_t,1);
723 new_component->generic_routing.set_processing_units = full_set_processing_units;
724 new_component->generic_routing.set_autonomous_system = full_set_autonomous_system;
725 new_component->generic_routing.set_route = full_set_route;
726 new_component->generic_routing.set_ASroute = full_set_ASroute;
727 new_component->generic_routing.get_route = full_get_route;
728 new_component->generic_routing.finalize = full_finalize;
729 new_component->to_index = xbt_dict_new();
730 new_component->parse_routes = xbt_dict_new();
731 return new_component;
734 static void model_full_load() {
735 /* use "surfxml_add_callback" to add a parse function call */
738 static void model_full_unload() {
739 /* use "surfxml_del_callback" to remove a parse function call */
742 static void model_full_end() {
744 char *key, *src_name, *dst_name, *link_name;//, *src_gw_name, *dst_gw_name;
745 const char* sep = "#";
746 int *src_id, *dst_id;
747 unsigned int i, j, cpt;
749 route_extended_t e_route, new_e_route;
753 xbt_dynar_t links, links_id;
754 xbt_dict_cursor_t cursor = NULL;
755 xbt_dynar_t keys = NULL;
757 routing_component_full_t routing = ((routing_component_full_t)current_routing);
759 int table_size = xbt_dict_length(routing->to_index);
761 /* Create the routing table */
762 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
764 /* Put the routes in position */
765 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
767 keys = xbt_str_split_str(key, sep);
769 src_name = xbt_dynar_get_as(keys, 0, char*);
770 dst_name = xbt_dynar_get_as(keys, 1, char*);
772 src_id = xbt_dict_get_or_null(routing->to_index, src_name);
773 dst_id = xbt_dict_get_or_null(routing->to_index, dst_name);
775 if (src_id == NULL || dst_id == NULL )
776 THROW2(mismatch_error,0,"Network elements %s or %s not found", src_name, dst_name);
778 new_e_route = xbt_new0(s_route_extended_t,1);
779 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
780 new_e_route->src_gateway = NULL;
781 new_e_route->dst_gateway = NULL;
782 TO_ROUTE_FULL(*src_id,*dst_id,current_routing) = new_e_route;
784 xbt_assert0(routing->generic_routing.hierarchy == SURF_ROUTING_BASE || routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE,
785 "the hierarchy type is not defined");
787 if(routing->generic_routing.hierarchy == SURF_ROUTING_BASE ) {
789 route = (route_t)data;
790 links = route->link_list;
792 } else if(routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE ) {
794 e_route = (route_extended_t)data;
795 // FIXME: HERE CHECK THE GATEWAY!!!!!!!!!
796 links = e_route->generic_route.link_list;
797 /* remeber not erase the gateway names */
798 TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->src_gateway = e_route->src_gateway;
799 TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->dst_gateway = e_route->dst_gateway;
803 links_id = TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->generic_route.link_list;
805 xbt_dynar_foreach(links, cpt, link_name) {
807 void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
809 xbt_dynar_push(links_id,&link);
811 THROW1(mismatch_error,0,"Link %s not found", link_name);
814 xbt_dynar_free(&keys);
817 /* delete the parse table */
818 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
819 route = (route_t)data;
820 xbt_dynar_free(&(route->link_list));
824 /* delete parse dict */
825 xbt_dict_free(&(routing->parse_routes));
827 /* Add the loopback if needed */
828 for (i = 0; i < table_size; i++) {
829 e_route = TO_ROUTE_FULL(i, i,current_routing);
830 if(!e_route) { // && !xbt_dynar_length(e_route->generic_route.link_list)
831 e_route = xbt_new0(s_route_extended_t,1);
832 e_route->src_gateway = NULL;
833 e_route->dst_gateway = NULL;
834 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
835 xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
836 TO_ROUTE_FULL(i, i,current_routing) = e_route;
840 /* Shrink the dynar routes (save unused slots) */
841 for (i=0;i<table_size;i++)
842 for (j=0;j<table_size;j++)
843 if(TO_ROUTE_FULL(i,j,current_routing))
844 xbt_dynar_shrink(TO_ROUTE_FULL(i,j,current_routing)->generic_route.link_list,0);
847 /* ************************************************************************** */
848 /* *************************** FLOYD ROUTING ******************************** */
850 #define TO_FLOYD_COST(i,j) cost_table[(i)+(j)*table_size]
851 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
852 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
853 #define TO_FLOYD_AS(i,j) (routing->AS_table)[(i)+(j)*AS_table_size]
855 /* Routing model structure */
858 s_routing_component_t generic_routing;
859 route_extended_t last_route;
860 /* vars for calculate the floyd algorith. */
861 int *predecessor_table;
862 void** link_table; /* char* -> network_element_t* */
863 xbt_dict_t predecessor_to_index;
864 /* store information to solve any AS route */
865 xbt_dict_t AS_to_index; /* char* -> network_element_t* */
866 route_limits_t AS_table;
867 /* store data during the parse process */
868 xbt_dict_t parse_routes;
870 } s_routing_component_floyd_t,*routing_component_floyd_t;
872 /* Business methods */
874 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
879 static xbt_dict_t floyd_get_network_elements(routing_component_t rc, e_surf_network_element_type_t req_type)
884 static void floyd_finalize(routing_component_t rc) {
888 static void* model_floyd_create(void) {
892 static void model_floyd_load() {
895 static void model_floyd_unload() {
898 static void model_floyd_end() {
901 /* ************************************************************************** */
902 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
905 s_routing_component_t generic_routing;
906 xbt_graph_t route_graph;
907 xbt_dict_t graph_node_map;
908 xbt_dict_t route_cache;
909 xbt_dynar_t last_route;
911 } s_routing_component_dijkstra_t,*routing_component_dijkstra_t;
913 /* Parse routing model functions */
915 /* Business methods */
917 /* Creation routing model functions */
919 static void* model_dijkstra_create() {
923 static void model_dijkstra_load() {
926 static void model_dijkstra_unload() {
929 static void model_dijkstra_end() {
932 static void* model_dijkstracache_create() {
936 static void model_dijkstracache_load() {
939 static void model_dijkstracache_unload() {
942 static void model_dijkstracache_end() {
946 /* ************************************************************************** */
947 /* ******************************* NO ROUTING ******************************* */
949 /* Routing model structure */
951 s_routing_component_t generic_routing;
952 } s_routing_component_none_t,*routing_component_none_t;
954 /* Business methods */
955 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
958 static void none_finalize(routing_component_t rc) {
962 /* Creation routing model functions */
963 static void* model_none_create() {
964 routing_component_none_t new_component = xbt_new0(s_routing_component_none_t,1);
965 new_component->generic_routing.get_route = none_get_route;
966 new_component->generic_routing.finalize = none_finalize;
967 return new_component;
970 static void model_none_load() {}
971 static void model_none_unload() {}
972 static void model_none_end() {}
974 /* ************************************************** */
975 /* ********** PATERN FOR NEW ROUTING **************** */
977 /* The minimal configuration of a new routing model need the next functions,
978 * also you need to set at the start of the file, the new model in the model
979 * list. Remember keep the null ending of the list.
981 /* Routing model structure */
983 s_routing_component_t generic_routing;
984 /* things that your routing model need */
985 } s_routing_component_NEW_t,*routing_component_NEW_t;
987 /* Parse routing model functions */
988 static void NEW_parse_S_host(void) {} /* example*/
990 /* Business methods */
991 static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;} /* mandatory */
992 static void NEW_finalize(routing_component_t rc) {} /* mandatory */
994 /* Creation routing model functions */
995 static void* model_NEW_create() {return NULL;} /* mandatory */
996 static void model_NEW_load() {} /* mandatory */
997 static void model_NEW_unload() {} /* mandatory */
998 static void model_NEW_end() {} /* mandatory */
1001 ////////////////////////////////////////////////////////////////////////////////
1002 // HERE FINISH THE NEW CODE
1003 ////////////////////////////////////////////////////////////////////////////////
1005 //...... DEBUG ONLY .... //
1006 static void print_tree(routing_component_t rc) {
1007 printf("(%s %s)\n",rc->name,rc->routing->name);
1009 xbt_dict_cursor_t cursor = NULL;
1012 if( rc->routing == &(routing_models[SURF_MODEL_FULL]) )
1013 { xbt_dict_foreach(((routing_component_full_t)rc)->to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1014 else if( rc->routing == &(routing_models[SURF_MODEL_FLOYD]) )
1015 { xbt_dict_foreach(((routing_component_floyd_t)rc)->predecessor_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); }
1016 xbt_dict_foreach(((routing_component_floyd_t)rc)->AS_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1018 xbt_assert0(0, "Invalid model for call \"print_tree\"");
1020 routing_component_t elem;
1021 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
1028 //...... DEBUG ONLY .... //
1029 static void print_global() {
1030 xbt_dict_cursor_t cursor = NULL;
1032 routing_component_t elem;
1033 xbt_dict_foreach(global_routing->where_network_elements, cursor, key, elem) {
1034 printf("<%s>\n",key);
1038 //...... DEBUG ONLY .... //
1039 static void print_AS_start(void) { printf("AS!!! %s y se rutea \"%s\"\n",A_surfxml_AS_id,A_surfxml_AS_routing); }
1040 static void print_AS_end(void) { printf("AS!!! %s\n",A_surfxml_AS_id); }
1041 static void print_host(void) { printf("host!!! %s\n",A_surfxml_host_id); }
1042 static void print_link(void) { printf("link!!! %s\n",A_surfxml_link_id); }
1043 static void print_route(void) { printf("route!!! %s a %s\n",A_surfxml_route_src,A_surfxml_route_dst); }
1044 static void print_ctn(void) { printf("ctn!!! %s\n",A_surfxml_link_c_ctn_id); }
1046 //...... DEBUG ONLY .... //
1047 static void DEBUG_exit(void) {
1051 printf("-- print all the example routes --\n");
1053 const char* names[] = { "11.A","11.B","11.C",
1057 unsigned int i,j,total = 3+2+1+2;
1061 for(i=0;i<total;i++) {
1062 for(j=0;j<total;j++) {
1063 links = (*(global_routing->get_route))(names[i],names[j]);
1064 printf("route from %s to %s >>> ",names[i],names[j]);
1067 xbt_dynar_foreach(links, cpt, link) {
1068 s_surf_resource_t* generic_resource = link;
1069 printf(" %s",generic_resource->name);
1078 printf("-- /////////////////////////////////////--\n");
1079 printf("-- /////////////////////////////////////--\n");
1082 links = (*(global_routing->get_route))(names[0],names[5]);
1087 printf("route from %s to %s >>> ",names[0],names[5]);
1088 xbt_dynar_foreach(links, cpt, link) {
1089 s_surf_resource_t* generic_resource = link;
1090 printf(" %s",generic_resource->name);
1098 printf("---------- call finalize ---------\n");
1099 (*(global_routing->finalize))();
1100 printf("----------------------------------\n");
1104 printf("-------- print tree elements -----\n");
1105 print_tree(global_routing->root);
1106 printf("----------------------------------\n\n");
1108 printf("-------- network_elements --------\n");
1110 printf("----------------------------------\n\n");
1112 // char* names[] = { "11.A","11.B","11.C","121.A","121.B","122.A","13.A","13.B"};
1113 // int i,j,total = 8;
1115 // printf("-- print all the example routes --\n");
1116 // char* names[] = { "11.A","11.B","11.C"};
1117 // int i,j,total = 3;
1119 // char* names[] = { "141.A","141.B","143.A","143.B"};
1120 // int i,j,total = 4;
1122 // char* names[] = { "142.A","142.B","142.C" };
1123 // int i,j,total = 3;
1125 // 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"};
1126 // int i,j,total = 3+4+8+3;
1128 // const char* names[] = { "11.A","11.B","11.C",
1133 // "142.A","142.B","142.C",
1135 // "15.A","15.B","15.C"};
1136 // unsigned int i,j,total = 3+2+1+2+2+3+2+3;
1138 // printf("-- print all the example routes --\n");
1139 // xbt_dynar_t links;
1141 // for(i=0;i<total;i++) {
1142 // for(j=0;j<total;j++) {
1143 // links = (*(global_routing->get_route))(names[i],names[j]);
1144 // printf("route from %s to %s >>> ",names[i],names[j]);
1145 // unsigned int cpt=0;
1146 // xbt_dynar_foreach(links, cpt, link) {
1147 // s_surf_resource_t* generic_resource = link;
1148 // printf(" %s",generic_resource->name);
1154 // printf("----------------------------------\n\n");
1156 // printf("---------- call finalize ---------\n");
1157 // (*(global_routing->finalize))();
1158 // printf("----------------------------------\n");
1163 ////////////////////////////////////////////////////////////////////////////////
1164 // HERE END THE NEW CODE
1165 ////////////////////////////////////////////////////////////////////////////////
1167 // /* ************************************************************************** */
1168 // /* *************************** FULL ROUTING ********************************* */
1170 // s_routing_t generic_routing;
1171 // xbt_dynar_t *routing_table;
1173 // size_t size_of_link;
1174 // } s_routing_full_t,*routing_full_t;
1176 // #define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count]
1177 // #define HOST2ROUTER(id) ((id)+(2<<29))
1178 // #define ROUTER2HOST(id) ((id)-(2>>29))
1179 // #define ISROUTER(id) ((id)>=(2<<29))
1182 // * Free the onelink routes
1184 // static void onelink_route_elem_free(void *e) {
1185 // s_onelink_t tmp = (s_onelink_t)e;
1194 // static void routing_full_parse_Shost(void) {
1195 // int *val = xbt_malloc(sizeof(int));
1196 // DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count);
1197 // *val = used_routing->host_count++;
1198 // xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free);
1199 // #ifdef HAVE_TRACING
1200 // TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1204 // static void routing_full_parse_Srouter(void) {
1205 // int *val = xbt_malloc(sizeof(int));
1206 // DEBUG3("Seen router %s (%d -> #%d)",A_surfxml_router_id,used_routing->router_count,
1207 // HOST2ROUTER(used_routing->router_count));
1208 // *val = HOST2ROUTER(used_routing->router_count++);
1209 // xbt_dict_set(used_routing->host_id,A_surfxml_router_id,val,xbt_free);
1210 // #ifdef HAVE_TRACING
1211 // TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1212 // TRACE_surf_host_declaration (A_surfxml_host_id, 0);
1216 // static int src_id = -1;
1217 // static int dst_id = -1;
1218 // static void routing_full_parse_Sroute_set_endpoints(void)
1220 // src_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_src);
1221 // dst_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_dst);
1222 // DEBUG4("Route %s %d -> %s %d",A_surfxml_route_src,src_id,A_surfxml_route_dst,dst_id);
1223 // route_action = A_surfxml_route_action;
1226 // static void routing_full_parse_Eroute(void)
1229 // if (src_id != -1 && dst_id != -1) {
1230 // name = bprintf("%x#%x", src_id, dst_id);
1231 // manage_route(route_table, name, route_action, 0);
1236 // /* Cluster tag functions */
1238 // static void routing_full_parse_change_cpu_data(const char *hostName,
1239 // const char *surfxml_host_power,
1240 // const char *surfxml_host_availability,
1241 // const char *surfxml_host_availability_file,
1242 // const char *surfxml_host_state_file)
1246 // SURFXML_BUFFER_SET(host_id, hostName);
1247 // SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
1248 // SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
1249 // SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
1250 // SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
1253 // static void routing_full_parse_change_link_data(const char *linkName,
1254 // const char *surfxml_link_bandwidth,
1255 // const char *surfxml_link_bandwidth_file,
1256 // const char *surfxml_link_latency,
1257 // const char *surfxml_link_latency_file,
1258 // const char *surfxml_link_state_file)
1262 // SURFXML_BUFFER_SET(link_id, linkName);
1263 // SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
1264 // SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
1265 // SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
1266 // SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
1267 // SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
1270 // static void routing_full_parse_Scluster(void)
1272 // static int AX_ptr = 0;
1274 // char *cluster_id = A_surfxml_cluster_id;
1275 // char *cluster_prefix = A_surfxml_cluster_prefix;
1276 // char *cluster_suffix = A_surfxml_cluster_suffix;
1277 // char *cluster_radical = A_surfxml_cluster_radical;
1278 // char *cluster_power = A_surfxml_cluster_power;
1279 // char *cluster_bw = A_surfxml_cluster_bw;
1280 // char *cluster_lat = A_surfxml_cluster_lat;
1281 // char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1282 // char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1283 // char *backbone_name;
1284 // unsigned int it1,it2;
1285 // char *name1,*name2;
1286 // xbt_dynar_t names = NULL;
1287 // surfxml_bufferstack_push(1);
1289 // /* Make set a set to parse the prefix/suffix/radical into a neat list of names */
1290 // DEBUG4("Make <set id='%s' prefix='%s' suffix='%s' radical='%s'>",
1291 // cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
1292 // SURFXML_BUFFER_SET(set_id, cluster_id);
1293 // SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1294 // SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1295 // SURFXML_BUFFER_SET(set_radical, cluster_radical);
1297 // SURFXML_START_TAG(set);
1298 // SURFXML_END_TAG(set);
1300 // names = xbt_dict_get(set_list,cluster_id);
1302 // xbt_dynar_foreach(names,it1,name1) {
1303 // /* create the host */
1304 // routing_full_parse_change_cpu_data(name1, cluster_power, "1.0", "", "");
1305 // A_surfxml_host_state = A_surfxml_host_state_ON;
1307 // SURFXML_START_TAG(host);
1308 // SURFXML_END_TAG(host);
1310 // /* Here comes the link */
1311 // routing_full_parse_change_link_data(name1, cluster_bw, "", cluster_lat, "", "");
1312 // A_surfxml_link_state = A_surfxml_link_state_ON;
1313 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1315 // SURFXML_START_TAG(link);
1316 // SURFXML_END_TAG(link);
1319 // /* Make backbone link */
1320 // backbone_name = bprintf("%s_bb", cluster_id);
1321 // routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1323 // A_surfxml_link_state = A_surfxml_link_state_ON;
1324 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1326 // SURFXML_START_TAG(link);
1327 // SURFXML_END_TAG(link);
1329 // /* And now the internal routes */
1330 // xbt_dynar_foreach(names,it1,name1) {
1331 // xbt_dynar_foreach(names,it2,name2) {
1332 // if (strcmp(name1,name2)) {
1333 // A_surfxml_route_action = A_surfxml_route_action_POSTPEND;
1334 // SURFXML_BUFFER_SET(route_src,name1);
1335 // SURFXML_BUFFER_SET(route_dst,name2);
1336 // SURFXML_START_TAG(route); {
1337 // /* FIXME: name1 link is added by error about 20 lines below, so don't add it here
1338 // SURFXML_BUFFER_SET(link_c_ctn_id, name1);
1339 // SURFXML_START_TAG(link_c_ctn);
1340 // SURFXML_END_TAG(link_c_ctn);
1342 // SURFXML_BUFFER_SET(link_c_ctn_id, backbone_name);
1343 // SURFXML_START_TAG(link_c_ctn);
1344 // SURFXML_END_TAG(link_c_ctn);
1346 // SURFXML_BUFFER_SET(link_c_ctn_id, name2);
1347 // SURFXML_START_TAG(link_c_ctn);
1348 // SURFXML_END_TAG(link_c_ctn);
1350 // } SURFXML_END_TAG(route);
1355 // /* Make route multi with the outside world, i.e. cluster->$* */
1358 // * This also adds an elements to the routes within the cluster,
1359 // * and I guess it's wrong, but since this element is commented out in the above
1360 // * code creating the internal routes, we're good.
1361 // * To fix it, I'd say that we need a way to understand "$*-${cluster_id}" as "whole world, but the guys in that cluster"
1362 // * But for that, we need to install a real expression parser for src/dst attributes
1365 // * This also adds a dumb element (the private link) in place of the loopback. Then, since
1366 // * the loopback is added only if no link to self already exist, this fails.
1367 // * That's really dumb.
1370 // * It seems to me that it does not add the backbone to the path to outside world...
1372 // SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1373 // SURFXML_BUFFER_SET(route_c_multi_dst, "$*");
1374 // A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1375 // A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_PREPEND;
1377 // SURFXML_START_TAG(route_c_multi);
1379 // SURFXML_BUFFER_SET(link_c_ctn_id, "$src");
1381 // SURFXML_START_TAG(link_c_ctn);
1382 // SURFXML_END_TAG(link_c_ctn);
1384 // SURFXML_END_TAG(route_c_multi);
1386 // free(backbone_name);
1388 // /* Restore buff */
1389 // surfxml_bufferstack_pop(1);
1393 // static void routing_full_parse_end(void) {
1394 // routing_full_t routing = (routing_full_t) used_routing;
1396 // unsigned int cpt = 0;
1397 // xbt_dict_cursor_t cursor = NULL;
1398 // char *key, *data, *end;
1399 // const char *sep = "#";
1400 // xbt_dynar_t links, keys;
1401 // char *link_name = NULL;
1404 // int host_count = routing->generic_routing.host_count;
1406 // /* Create the routing table */
1407 // routing->routing_table = xbt_new0(xbt_dynar_t, host_count * host_count);
1408 // for (i=0;i<host_count;i++)
1409 // for (j=0;j<host_count;j++)
1410 // ROUTE_FULL(i,j) = xbt_dynar_new(routing->size_of_link,NULL);
1412 // /* Put the routes in position */
1413 // xbt_dict_foreach(route_table, cursor, key, data) {
1415 // links = (xbt_dynar_t) data;
1416 // keys = xbt_str_split_str(key, sep);
1418 // src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1419 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1420 // xbt_dynar_free(&keys);
1422 // if(xbt_dynar_length(links) == 1){
1423 // s_onelink_t new_link = (s_onelink_t) xbt_malloc0(sizeof(s_onelink));
1424 // new_link->src_id = src_id;
1425 // new_link->dst_id = dst_id;
1426 // link_name = xbt_dynar_getfirst_as(links, char*);
1427 // new_link->link_ptr = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1428 // DEBUG3("Adding onelink route from (#%d) to (#%d), link_name %s",src_id, dst_id, link_name);
1429 // xbt_dict_set(onelink_routes, link_name, (void *)new_link, onelink_route_elem_free);
1430 // #ifdef HAVE_TRACING
1431 // TRACE_surf_link_save_endpoints (link_name, src_id, dst_id);
1435 // if(ISROUTER(src_id) || ISROUTER(dst_id)) {
1436 // DEBUG2("There is route with a router here: (%d ,%d)",src_id,dst_id);
1437 // /* Check there is only one link in the route and store the information */
1441 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1442 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1443 // xbt_dynar_foreach(links, cpt, link_name) {
1444 // void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1446 // xbt_dynar_push(ROUTE_FULL(src_id,dst_id),&link);
1448 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1452 // /* Add the loopback if needed */
1453 // for (i = 0; i < host_count; i++)
1454 // if (!xbt_dynar_length(ROUTE_FULL(i, i)))
1455 // xbt_dynar_push(ROUTE_FULL(i,i),&routing->loopback);
1457 // /* Shrink the dynar routes (save unused slots) */
1458 // for (i=0;i<host_count;i++)
1459 // for (j=0;j<host_count;j++)
1460 // xbt_dynar_shrink(ROUTE_FULL(i,j),0);
1464 // * Business methods
1466 // static xbt_dynar_t routing_full_get_route(int src,int dst) {
1467 // xbt_assert0(!(ISROUTER(src) || ISROUTER(dst)), "Ask for route \"from\" or \"to\" a router node");
1468 // return ROUTE_FULL(src,dst);
1471 // static xbt_dict_t routing_full_get_onelink_routes(void){
1472 // return onelink_routes;
1475 // static int routing_full_is_router(int id){
1476 // return ISROUTER(id);
1479 // static void routing_full_finalize(void) {
1480 // routing_full_t routing = (routing_full_t)used_routing;
1484 // for (i = 0; i < used_routing->host_count; i++)
1485 // for (j = 0; j < used_routing->host_count; j++)
1486 // xbt_dynar_free(&ROUTE_FULL(i, j));
1487 // free(routing->routing_table);
1488 // xbt_dict_free(&used_routing->host_id);
1489 // xbt_dict_free(&onelink_routes);
1495 // static void routing_model_full_create(size_t size_of_link,void *loopback) {
1496 // /* initialize our structure */
1497 // routing_full_t routing = xbt_new0(s_routing_full_t,1);
1498 // routing->generic_routing.name = "Full";
1499 // routing->generic_routing.host_count = 0;
1500 // routing->generic_routing.get_route = routing_full_get_route;
1501 // routing->generic_routing.get_onelink_routes = routing_full_get_onelink_routes;
1502 // routing->generic_routing.is_router = routing_full_is_router;
1503 // routing->generic_routing.finalize = routing_full_finalize;
1505 // routing->size_of_link = size_of_link;
1506 // routing->loopback = loopback;
1508 // /* Set it in position */
1509 // used_routing = (routing_t) routing;
1511 // /* Set the dict for onehop routes */
1512 // onelink_routes = xbt_dict_new();
1514 // routing->generic_routing.host_id = xbt_dict_new();
1516 // /* Setup the parsing callbacks we need */
1517 // // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1518 // // surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1519 // // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_full_parse_end);
1520 // // surfxml_add_callback(STag_surfxml_route_cb_list, &routing_full_parse_Sroute_set_endpoints);
1521 // // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1522 // // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
1524 // // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1525 // // surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1529 /* ************************************************************************** */
1531 // static void routing_shortest_path_parse_Scluster(void)
1533 // static int AX_ptr = 0;
1535 // char *cluster_id = A_surfxml_cluster_id;
1536 // char *cluster_prefix = A_surfxml_cluster_prefix;
1537 // char *cluster_suffix = A_surfxml_cluster_suffix;
1538 // char *cluster_radical = A_surfxml_cluster_radical;
1539 // char *cluster_power = A_surfxml_cluster_power;
1540 // char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1541 // char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1542 // char *backbone_name;
1544 // surfxml_bufferstack_push(1);
1547 // SURFXML_BUFFER_SET(set_id, cluster_id);
1548 // SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1549 // SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1550 // SURFXML_BUFFER_SET(set_radical, cluster_radical);
1552 // SURFXML_START_TAG(set);
1553 // SURFXML_END_TAG(set);
1555 // /* Make foreach */
1556 // SURFXML_BUFFER_SET(foreach_set_id, cluster_id);
1558 // SURFXML_START_TAG(foreach);
1560 // /* Make host for the foreach */
1561 // routing_full_parse_change_cpu_data("$1", cluster_power, "1.0", "", "");
1562 // A_surfxml_host_state = A_surfxml_host_state_ON;
1564 // SURFXML_START_TAG(host);
1565 // SURFXML_END_TAG(host);
1567 // SURFXML_END_TAG(foreach);
1569 // /* Make backbone link */
1570 // backbone_name = bprintf("%s_bb", cluster_id);
1571 // routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1573 // A_surfxml_link_state = A_surfxml_link_state_ON;
1574 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1576 // SURFXML_START_TAG(link);
1577 // SURFXML_END_TAG(link);
1579 // free(backbone_name);
1581 // /* Restore buff */
1582 // surfxml_bufferstack_pop(1);
1585 // /* ************************************************************************** */
1586 // /* *************************** FLOYD ROUTING ********************************* */
1588 // s_routing_t generic_routing;
1589 // int *predecessor_table;
1590 // void** link_table;
1591 // xbt_dynar_t last_route;
1593 // size_t size_of_link;
1594 // } s_routing_floyd_t,*routing_floyd_t;
1596 // #define FLOYD_COST(i,j) cost_table[(i)+(j)*(used_routing)->host_count]
1597 // #define FLOYD_PRED(i,j) ((routing_floyd_t)used_routing)->predecessor_table[(i)+(j)*(used_routing)->host_count]
1598 // #define FLOYD_LINK(i,j) ((routing_floyd_t)used_routing)->link_table[(i)+(j)*(used_routing)->host_count]
1600 // static void routing_floyd_parse_end(void) {
1602 // routing_floyd_t routing = (routing_floyd_t) used_routing;
1604 // void* link_list = NULL;
1605 // double * cost_table;
1606 // xbt_dict_cursor_t cursor = NULL;
1607 // char *key,*data, *end;
1608 // const char *sep = "#";
1609 // xbt_dynar_t links, keys;
1611 // unsigned int i,j;
1612 // unsigned int a,b,c;
1613 // int host_count = routing->generic_routing.host_count;
1614 // char * link_name = NULL;
1615 // void * link = NULL;
1617 // /* Create Cost, Predecessor and Link tables */
1618 // cost_table = xbt_new0(double, host_count * host_count); //link cost from host to host
1619 // routing->predecessor_table = xbt_new0(int, host_count*host_count); //predecessor host numbers
1620 // routing->link_table = xbt_new0(void*,host_count*host_count); //actual link between src and dst
1621 // routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1623 // /* Initialize costs and predecessors*/
1624 // for(i = 0; i<host_count;i++)
1625 // for(j = 0; j<host_count;j++) {
1626 // FLOYD_COST(i,j) = DBL_MAX;
1627 // FLOYD_PRED(i,j) = -1;
1630 // /* Put the routes in position */
1631 // xbt_dict_foreach(route_table, cursor, key, data) {
1633 // links = (xbt_dynar_t)data;
1634 // keys = xbt_str_split_str(key, sep);
1637 // src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
1638 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
1639 // xbt_dynar_free(&keys);
1641 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1642 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1643 // 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);
1645 // link_name = xbt_dynar_getfirst_as(links, char*);
1646 // link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1649 // link_list = link;
1651 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1654 // FLOYD_LINK(src_id,dst_id) = link_list;
1655 // FLOYD_PRED(src_id, dst_id) = src_id;
1658 // FLOYD_COST(src_id, dst_id) = 1; // assume 1 for now
1662 // /* Add the loopback if needed */
1663 // for (i = 0; i < host_count; i++)
1664 // if (!FLOYD_PRED(i, i)) {
1665 // FLOYD_PRED(i, i) = i;
1666 // FLOYD_COST(i, i) = 1;
1667 // FLOYD_LINK(i, i) = routing->loopback;
1671 // //Calculate path costs
1673 // for(c=0;c<host_count;c++) {
1674 // for(a=0;a<host_count;a++) {
1675 // for(b=0;b<host_count;b++) {
1676 // if(FLOYD_COST(a,c) < DBL_MAX && FLOYD_COST(c,b) < DBL_MAX) {
1677 // if(FLOYD_COST(a,b) == DBL_MAX || (FLOYD_COST(a,c)+FLOYD_COST(c,b) < FLOYD_COST(a,b))) {
1678 // FLOYD_COST(a,b) = FLOYD_COST(a,c)+FLOYD_COST(c,b);
1679 // FLOYD_PRED(a,b) = FLOYD_PRED(c,b);
1687 // free(cost_table);
1691 // * Business methods
1693 // static xbt_dynar_t routing_floyd_get_route(int src_id,int dst_id) {
1695 // routing_floyd_t routing = (routing_floyd_t) used_routing;
1697 // int pred = dst_id;
1698 // int prev_pred = 0;
1700 // xbt_dynar_reset(routing->last_route);
1703 // prev_pred = pred;
1704 // pred = FLOYD_PRED(src_id, pred);
1706 // if(pred == -1) // if no pred in route -> no route to host
1709 // xbt_dynar_unshift(routing->last_route, &FLOYD_LINK(pred,prev_pred));
1711 // } while(pred != src_id);
1713 // xbt_assert2(pred != -1, "no route from host %d to %d", src_id, dst_id);
1715 // return routing->last_route;
1718 // static void routing_floyd_finalize(void) {
1719 // routing_floyd_t routing = (routing_floyd_t)used_routing;
1722 // free(routing->link_table);
1723 // free(routing->predecessor_table);
1724 // xbt_dynar_free(&routing->last_route);
1725 // xbt_dict_free(&used_routing->host_id);
1731 // static xbt_dict_t routing_floyd_get_onelink_routes(void){
1732 // xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model Floyd");
1735 // static int routing_floyd_is_router(int id){
1736 // xbt_assert0(0,"The get_is_router feature is not supported in routing model Floyd");
1739 // static void routing_model_floyd_create(size_t size_of_link,void *loopback) {
1740 // /* initialize our structure */
1741 // routing_floyd_t routing = xbt_new0(s_routing_floyd_t,1);
1742 // routing->generic_routing.name = "Floyd";
1743 // routing->generic_routing.host_count = 0;
1744 // routing->generic_routing.host_id = xbt_dict_new();
1745 // routing->generic_routing.get_route = routing_floyd_get_route;
1746 // routing->generic_routing.get_onelink_routes = routing_floyd_get_onelink_routes;
1747 // routing->generic_routing.is_router = routing_floyd_is_router;
1748 // routing->generic_routing.finalize = routing_floyd_finalize;
1749 // routing->size_of_link = size_of_link;
1750 // routing->loopback = loopback;
1752 // /* Set it in position */
1753 // used_routing = (routing_t) routing;
1755 // /* Setup the parsing callbacks we need */
1756 // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1757 // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_floyd_parse_end);
1758 // surfxml_add_callback(STag_surfxml_route_cb_list,
1759 // &routing_full_parse_Sroute_set_endpoints);
1760 // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1761 // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
1765 // /* ************************************************************************** */
1766 // /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1768 // s_routing_t generic_routing;
1769 // xbt_graph_t route_graph;
1770 // xbt_dict_t graph_node_map;
1771 // xbt_dict_t route_cache;
1772 // xbt_dynar_t last_route;
1775 // size_t size_of_link;
1776 // } s_routing_dijkstra_t,*routing_dijkstra_t;
1779 // typedef struct graph_node_data {
1781 // int graph_id; //used for caching internal graph id's
1782 // } s_graph_node_data_t, * graph_node_data_t;
1784 // typedef struct graph_node_map_element {
1786 // } s_graph_node_map_element_t, * graph_node_map_element_t;
1788 // typedef struct route_cache_element {
1791 // } s_route_cache_element_t, * route_cache_element_t;
1796 // static void route_cache_elem_free(void *e) {
1797 // route_cache_element_t elm=(route_cache_element_t)e;
1800 // free(elm->pred_arr);
1805 // static void graph_node_map_elem_free(void *e) {
1806 // graph_node_map_element_t elm = (graph_node_map_element_t)e;
1814 // * Utility functions
1816 // static xbt_node_t route_graph_new_node(int id, int graph_id) {
1817 // xbt_node_t node = NULL;
1818 // graph_node_data_t data = NULL;
1819 // graph_node_map_element_t elm = NULL;
1820 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1822 // data = xbt_new0(struct graph_node_data, sizeof(struct graph_node_data));
1824 // data->graph_id = graph_id;
1825 // node = xbt_graph_new_node(routing->route_graph, data);
1827 // elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element));
1828 // elm->node = node;
1829 // xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free);
1834 // static graph_node_map_element_t graph_node_map_search(int id) {
1835 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1837 // 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));
1845 // static void route_new_dijkstra(int src_id, int dst_id, void* link) {
1846 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1848 // xbt_node_t src = NULL;
1849 // xbt_node_t dst = NULL;
1850 // 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));
1851 // graph_node_map_element_t dst_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&dst_id), sizeof(int));
1854 // src = src_elm->node;
1857 // dst = dst_elm->node;
1859 // //add nodes if they don't exist in the graph
1860 // if(src_id == dst_id && src == NULL && dst == NULL) {
1861 // src = route_graph_new_node(src_id, -1);
1864 // if(src == NULL) {
1865 // src = route_graph_new_node(src_id, -1);
1868 // if(dst == NULL) {
1869 // dst = route_graph_new_node(dst_id, -1);
1873 // //add link as edge to graph
1874 // xbt_graph_new_edge(routing->route_graph, src, dst, link);
1878 // static void add_loopback_dijkstra(void) {
1879 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1881 // xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1883 // xbt_node_t node = NULL;
1884 // unsigned int cursor2;
1885 // xbt_dynar_foreach(nodes, cursor2, node) {
1886 // xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1887 // xbt_edge_t edge = NULL;
1888 // unsigned int cursor;
1891 // xbt_dynar_foreach(out_edges, cursor, edge) {
1892 // xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1893 // if(other_node == node) {
1900 // xbt_graph_new_edge(routing->route_graph, node, node, &routing->loopback);
1904 // static void routing_dijkstra_parse_end(void) {
1905 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1907 // xbt_dict_cursor_t cursor = NULL;
1908 // char *key, *data, *end;
1909 // const char *sep = "#";
1910 // xbt_dynar_t links, keys;
1911 // char* link_name = NULL;
1912 // void* link = NULL;
1913 // xbt_node_t node = NULL;
1914 // unsigned int cursor2;
1915 // xbt_dynar_t nodes = NULL;
1916 // /* Create the topology graph */
1917 // routing->route_graph = xbt_graph_new_graph(1, NULL);
1918 // routing->graph_node_map = xbt_dict_new();
1919 // routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1920 // if(routing->cached)
1921 // routing->route_cache = xbt_dict_new();
1924 // /* Put the routes in position */
1925 // xbt_dict_foreach(route_table, cursor, key, data) {
1927 // links = (xbt_dynar_t) data;
1928 // keys = xbt_str_split_str(key, sep);
1930 // src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1931 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1932 // xbt_dynar_free(&keys);
1934 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1935 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1937 // 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);
1939 // link_name = xbt_dynar_getfirst_as(links, char*);
1940 // link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1942 // route_new_dijkstra(src_id,dst_id,link);
1944 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1948 // /* Add the loopback if needed */
1949 // add_loopback_dijkstra();
1951 // /* initialize graph indexes in nodes after graph has been built */
1952 // nodes = xbt_graph_get_nodes(routing->route_graph);
1954 // xbt_dynar_foreach(nodes, cursor2, node) {
1955 // graph_node_data_t data = xbt_graph_node_get_data(node);
1956 // data->graph_id = cursor2;
1962 // * Business methods
1964 // static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) {
1966 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1967 // int * pred_arr = NULL;
1968 // int src_node_id = 0;
1969 // int dst_node_id = 0;
1970 // int * nodeid = NULL;
1973 // void * link = NULL;
1974 // route_cache_element_t elm = NULL;
1975 // xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1977 // /*Use the graph_node id mapping set to quickly find the nodes */
1978 // graph_node_map_element_t src_elm = graph_node_map_search(src_id);
1979 // graph_node_map_element_t dst_elm = graph_node_map_search(dst_id);
1980 // xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", src_id, dst_id);
1981 // src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
1982 // dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
1984 // if(routing->cached) {
1985 // /*check if there is a cached predecessor list avail */
1986 // elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int));
1989 // if(elm) { //cached mode and cache hit
1990 // pred_arr = elm->pred_arr;
1991 // } else { //not cached mode or cache miss
1992 // double * cost_arr = NULL;
1993 // xbt_heap_t pqueue = NULL;
1996 // int nr_nodes = xbt_dynar_length(nodes);
1997 // cost_arr = xbt_new0(double, nr_nodes); //link cost from src to other hosts
1998 // pred_arr = xbt_new0(int, nr_nodes); //predecessors in path from src
1999 // pqueue = xbt_heap_new(nr_nodes, free);
2002 // cost_arr[src_node_id] = 0.0;
2004 // for(i = 0; i < nr_nodes; i++) {
2005 // if(i != src_node_id) {
2006 // cost_arr[i] = DBL_MAX;
2011 // //initialize priority queue
2012 // nodeid = xbt_new0(int, 1);
2014 // xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2018 // // apply dijkstra using the indexes from the graph's node array
2019 // while(xbt_heap_size(pqueue) > 0) {
2020 // int * v_id = xbt_heap_pop(pqueue);
2021 // xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2022 // xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2023 // xbt_edge_t edge = NULL;
2024 // unsigned int cursor;
2026 // xbt_dynar_foreach(out_edges, cursor, edge) {
2027 // xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2028 // graph_node_data_t data = xbt_graph_node_get_data(u_node);
2029 // int u_id = data->graph_id;
2030 // int cost_v_u = 1; //fixed link cost for now
2032 // if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2033 // pred_arr[u_id] = *v_id;
2034 // cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2035 // nodeid = xbt_new0(int, 1);
2037 // xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2041 // //free item popped from pqueue
2046 // xbt_heap_free(pqueue);
2050 // //compose route path with links
2051 // xbt_dynar_reset(routing->last_route);
2053 // for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2054 // xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2055 // xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2056 // xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2058 // xbt_assert2(edge != NULL, "no route between host %d and %d", src_id, dst_id);
2060 // link = xbt_graph_edge_get_data(edge);
2061 // xbt_dynar_unshift(routing->last_route, &link);
2066 // if(routing->cached && elm == NULL) {
2067 // //add to predecessor list of the current src-host to cache
2068 // elm = xbt_new0(struct route_cache_element, sizeof(struct route_cache_element));
2069 // elm->pred_arr = pred_arr;
2070 // elm->size = size;
2071 // xbt_dict_set_ext(routing->route_cache, (char*)(&src_id), sizeof(int), (xbt_set_elm_t)elm, &route_cache_elem_free);
2074 // if(!routing->cached)
2077 // return routing->last_route;
2081 // static void routing_dijkstra_finalize(void) {
2082 // routing_dijkstra_t routing = (routing_dijkstra_t)used_routing;
2085 // xbt_graph_free_graph(routing->route_graph, &free, NULL, &free);
2086 // xbt_dict_free(&routing->graph_node_map);
2087 // if(routing->cached)
2088 // xbt_dict_free(&routing->route_cache);
2089 // xbt_dynar_free(&routing->last_route);
2090 // xbt_dict_free(&used_routing->host_id);
2096 // static xbt_dict_t routing_dijkstraboth_get_onelink_routes(void){
2097 // xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model dijkstraboth");
2100 // static int routing_dijkstraboth_is_router(int id){
2101 // xbt_assert0(0,"The get_is_router feature is not supported in routing model dijkstraboth");
2107 // static void routing_model_dijkstraboth_create(size_t size_of_link,void *loopback, int cached) {
2108 // /* initialize our structure */
2109 // routing_dijkstra_t routing = xbt_new0(s_routing_dijkstra_t,1);
2110 // routing->generic_routing.name = "Dijkstra";
2111 // routing->generic_routing.host_count = 0;
2112 // routing->generic_routing.get_route = routing_dijkstra_get_route;
2113 // routing->generic_routing.get_onelink_routes = routing_dijkstraboth_get_onelink_routes;
2114 // routing->generic_routing.is_router = routing_dijkstraboth_is_router;
2115 // routing->generic_routing.finalize = routing_dijkstra_finalize;
2116 // routing->size_of_link = size_of_link;
2117 // routing->loopback = loopback;
2118 // routing->cached = cached;
2120 // /* Set it in position */
2121 // used_routing = (routing_t) routing;
2123 // /* Setup the parsing callbacks we need */
2124 // routing->generic_routing.host_id = xbt_dict_new();
2125 // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
2126 // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_dijkstra_parse_end);
2127 // surfxml_add_callback(STag_surfxml_route_cb_list,
2128 // &routing_full_parse_Sroute_set_endpoints);
2129 // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
2130 // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
2133 // static void routing_model_dijkstra_create(size_t size_of_link,void *loopback) {
2134 // routing_model_dijkstraboth_create(size_of_link, loopback, 0);
2137 // static void routing_model_dijkstracache_create(size_t size_of_link,void *loopback) {
2138 // routing_model_dijkstraboth_create(size_of_link, loopback, 1);
2141 /* ************************************************** */
2142 /* ********** NO ROUTING **************************** */
2145 // static void routing_none_finalize(void) {
2146 // if (used_routing) {
2147 // xbt_dict_free(&used_routing->host_id);
2148 // free(used_routing);
2149 // used_routing=NULL;
2153 // static void routing_model_none_create(size_t size_of_link,void *loopback) {
2154 // routing_t routing = xbt_new0(s_routing_t,1);
2155 // INFO0("Null routing");
2156 // routing->name = "none";
2157 // routing->host_count = 0;
2158 // routing->host_id = xbt_dict_new();
2159 // routing->get_onelink_routes = NULL;
2160 // routing->is_router = NULL;
2161 // routing->get_route = NULL;
2163 // routing->finalize = routing_none_finalize;
2165 // /* Set it in position */
2166 // used_routing = (routing_t) routing;