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);
440 xbt_dynar_free( &(e_route_cnt->generic_route.link_list) );
441 xbt_free(e_route_cnt);
444 } else { /* SURF_ROUTING_RECURSIVE */
446 e_route_cnt = (*(common_father->get_route))(common_father,src_father->name,dst_father->name);
448 xbt_assert2( (e_route_cnt->src_gateway==NULL) == (e_route_cnt->dst_gateway==NULL) ,
449 "bad gateway for route between \"%s\" and \"%s\"",src,dst);
451 if( src != e_route_cnt->src_gateway ) {
452 e_route_src = _get_route(src,e_route_cnt->src_gateway);
453 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
454 xbt_dynar_push(e_route->generic_route.link_list,&link);
458 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
459 xbt_dynar_push(e_route->generic_route.link_list,&link);
462 if( e_route_cnt->dst_gateway != dst ) {
463 e_route_dst = _get_route(e_route_cnt->dst_gateway,dst);
464 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
465 xbt_dynar_push(e_route->generic_route.link_list,&link);
469 e_route->src_gateway = e_route_cnt->src_gateway;
470 e_route->dst_gateway = e_route_cnt->dst_gateway;
472 xbt_dynar_free( &(e_route_src->generic_route.link_list) );
473 xbt_free(e_route_src);
474 xbt_dynar_free( &(e_route_cnt->generic_route.link_list) );
475 xbt_free(e_route_cnt);
476 xbt_dynar_free( &(e_route_dst->generic_route.link_list) );
477 xbt_free(e_route_dst);
480 xbt_dynar_free(&elem_father_list);
487 * \brief Generic method: find a route between hosts
489 * \param src the source host name
490 * \param dst the destination host name
492 * walk through the routing components tree and find a route between hosts
493 * by calling the differents "get_route" functions in each routing component
495 static xbt_dynar_t get_route(const char* src,const char* dst) {
497 if(global_routing->last_route) xbt_dynar_free( &(global_routing->last_route) );
499 route_extended_t e_route;
500 xbt_dynar_t elem_father_list = elements_father(src,dst);
501 routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
504 e_route = _get_route(src,dst);
506 e_route = (*(common_father->get_route))(common_father,src,dst);
508 global_routing->last_route = e_route->generic_route.link_list;
511 xbt_dynar_free(&elem_father_list);
513 if( xbt_dynar_length(global_routing->last_route)==0 )
516 return global_routing->last_route;
520 * \brief Recursive function for finalize
522 * \param rc the source host name
524 * This fuction is call by "finalize". It allow to finalize the
525 * AS or routing components. It delete all the structures.
527 static void _finalize(routing_component_t rc) {
529 xbt_dict_cursor_t cursor = NULL;
531 routing_component_t elem;
532 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
535 xbt_dict_t tmp_sons = rc->routing_sons;
536 char* tmp_name = rc->name;
537 xbt_dict_free(&tmp_sons);
539 (*(rc->finalize))(rc);
544 * \brief Generic method: delete all the routing structures
546 * walk through the routing components tree and delete the structures
547 * by calling the differents "finalize" functions in each routing component
549 static void finalize(void) {
550 /* delete recursibly all the tree */
551 _finalize(global_routing->root);
552 /* delete "where" dict */
553 xbt_dict_free(&(global_routing->where_network_elements));
554 /* delete last_route */
555 xbt_dynar_free(&(global_routing->last_route));
556 /* delete global routing structure */
557 xbt_free(global_routing);
561 * \brief Generic method: create the global routing schema
563 * Make a global routing structure and set all the parsing functions.
565 void routing_model_create(size_t size_of_links, void* loopback) {
567 /* config the uniq global routing */
568 global_routing = xbt_new0(s_routing_global_t,1);
569 global_routing->where_network_elements = xbt_dict_new();
570 global_routing->root = NULL;
571 global_routing->get_route = get_route;
572 global_routing->finalize = finalize;
573 global_routing->loopback = loopback;
574 global_routing->size_of_link = size_of_links;
575 global_routing->last_route = xbt_dynar_new(size_of_links, NULL);
577 /* no current routing at moment */
578 current_routing = NULL;
580 /* parse generic elements */
581 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host);
582 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
584 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints);
585 surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints);
587 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_E_link_c_ctn_new_elem);
589 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route);
590 surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route);
592 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
593 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
595 /* set all the as in the global where table (recursive fuction) */
596 surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_E_platform_add_parse_AS);
599 //surfxml_add_callback(ETag_surfxml_platform_cb_list, &DEBUG_exit);
603 /* ************************************************************************** */
604 /* *************************** FULL ROUTING ********************************* */
606 #define TO_ROUTE_FULL(i,j,rc) ((routing_component_full_t)rc)->routing_table[(i)+(j)*xbt_dict_length(((routing_component_full_t)rc)->to_index)]
608 /* Routing model structure */
611 s_routing_component_t generic_routing;
612 xbt_dict_t parse_routes; /* store data during the parse process */
613 xbt_dict_t to_index; /* char* -> network_element_t */
614 route_extended_t *routing_table;
615 } s_routing_component_full_t,*routing_component_full_t;
617 /* Parse routing model functions */
620 /* Business methods */
622 static void full_set_processing_units(routing_component_t rc, const char* name) {
623 DEBUG1("Full - Load process unit \"%s\"",name);
624 // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
625 int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
626 *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
627 xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
630 static void full_set_autonomous_system(routing_component_t rc, const char* name) {
631 DEBUG1("Full - Load Autonomous system \"%s\"",name);
632 // TODO: SET or ERROR e_surf_routing_hierarchy_t hierarchical
633 int *id = xbt_new0(int,1); // xbt_malloc(sizeof(int)); ?
634 *id = xbt_dict_length(((routing_component_full_t)current_routing)->to_index);
635 xbt_dict_set(((routing_component_full_t)current_routing)->to_index,name,id,xbt_free);
638 static void full_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
639 DEBUG2("Full - Load Route from \"%s\" to \"%s\"",src,dst);
640 routing_component_full_t routing = (routing_component_full_t)current_routing;
642 route_name = bprintf("%s#%s",src,dst);
643 xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
644 xbt_assert2(!xbt_dict_get_or_null(routing->parse_routes,route_name),
645 "The route between \"%s\" and \"%s\" already exist",src,dst);
646 xbt_dict_set(routing->parse_routes, route_name, route, NULL);
650 static void full_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
651 DEBUG4("Full - Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway);
652 routing_component_full_t routing = (routing_component_full_t)current_routing;
654 route_name = bprintf("%s#%s",src,dst);
655 xbt_assert2(xbt_dynar_length(link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
656 xbt_assert4(!xbt_dict_get_or_null(routing->parse_routes,route_name),
657 "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
658 src,e_route->src_gateway,dst,e_route->dst_gateway);
659 xbt_dict_set(routing->parse_routes, route_name, e_route, NULL);
663 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
665 routing_component_full_t routing = (routing_component_full_t)rc;
667 xbt_assert1(src && dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
669 routing_component_t src_as, dst_as;
672 src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
673 dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
675 xbt_assert0(src_as != NULL && dst_as != NULL, "Ask for route \"from\" or \"to\" no found");
676 xbt_assert0(src_as == dst_as, "The src and dst are in differents AS");
677 xbt_assert0(rc == dst_as, "The routing component of src and dst is not the same as the network elements belong");
679 src_id = xbt_dict_get(routing->to_index,src);
680 dst_id = xbt_dict_get(routing->to_index,dst);
682 xbt_assert0(src_id && dst_id, "Ask for route \"from\" or \"to\" no found in the local table");
686 route_extended_t e_route = TO_ROUTE_FULL(*src_id,*dst_id,routing);
687 route_extended_t new_e_route = xbt_new0(s_route_extended_t,1);
688 new_e_route->src_gateway = e_route->src_gateway;
689 new_e_route->dst_gateway = e_route->dst_gateway;
690 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
691 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
692 xbt_dynar_push(new_e_route->generic_route.link_list,&link);
697 static void full_finalize(routing_component_t rc) {
698 routing_component_full_t routing = (routing_component_full_t)rc;
701 int table_size = xbt_dict_length(routing->to_index);
702 /* Delete routing table */
703 for (i=0;i<table_size;i++) {
704 for (j=0;j<table_size;j++) {
705 route_extended_t e_route = TO_ROUTE_FULL(i,j,rc);
707 xbt_dynar_free(&(e_route->generic_route.link_list));
708 if(e_route->src_gateway) xbt_free(e_route->src_gateway);
709 if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
714 xbt_free(routing->routing_table);
715 /* Delete index dict */
716 xbt_dict_free(&(routing->to_index));
717 /* Delete structure */
722 /* Creation routing model functions */
724 static void* model_full_create() {
725 routing_component_full_t new_component = xbt_new0(s_routing_component_full_t,1);
726 new_component->generic_routing.set_processing_units = full_set_processing_units;
727 new_component->generic_routing.set_autonomous_system = full_set_autonomous_system;
728 new_component->generic_routing.set_route = full_set_route;
729 new_component->generic_routing.set_ASroute = full_set_ASroute;
730 new_component->generic_routing.get_route = full_get_route;
731 new_component->generic_routing.finalize = full_finalize;
732 new_component->to_index = xbt_dict_new();
733 new_component->parse_routes = xbt_dict_new();
734 return new_component;
737 static void model_full_load() {
738 /* use "surfxml_add_callback" to add a parse function call */
741 static void model_full_unload() {
742 /* use "surfxml_del_callback" to remove a parse function call */
745 static void model_full_end() {
747 char *key, *src_name, *dst_name, *link_name;//, *src_gw_name, *dst_gw_name;
748 const char* sep = "#";
749 int *src_id, *dst_id;
750 unsigned int i, j, cpt;
752 route_extended_t e_route, new_e_route;
756 xbt_dynar_t links, links_id;
757 xbt_dict_cursor_t cursor = NULL;
758 xbt_dynar_t keys = NULL;
760 routing_component_full_t routing = ((routing_component_full_t)current_routing);
762 int table_size = xbt_dict_length(routing->to_index);
764 /* Create the routing table */
765 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
767 /* Put the routes in position */
768 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
770 keys = xbt_str_split_str(key, sep);
772 src_name = xbt_dynar_get_as(keys, 0, char*);
773 dst_name = xbt_dynar_get_as(keys, 1, char*);
775 src_id = xbt_dict_get_or_null(routing->to_index, src_name);
776 dst_id = xbt_dict_get_or_null(routing->to_index, dst_name);
778 if (src_id == NULL || dst_id == NULL )
779 THROW2(mismatch_error,0,"Network elements %s or %s not found", src_name, dst_name);
781 new_e_route = xbt_new0(s_route_extended_t,1);
782 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
783 new_e_route->src_gateway = NULL;
784 new_e_route->dst_gateway = NULL;
785 TO_ROUTE_FULL(*src_id,*dst_id,current_routing) = new_e_route;
787 xbt_assert0(routing->generic_routing.hierarchy == SURF_ROUTING_BASE || routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE,
788 "the hierarchy type is not defined");
790 if(routing->generic_routing.hierarchy == SURF_ROUTING_BASE ) {
792 route = (route_t)data;
793 links = route->link_list;
795 } else if(routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE ) {
797 e_route = (route_extended_t)data;
798 // FIXME: HERE CHECK THE GATEWAY!!!!!!!!!
799 links = e_route->generic_route.link_list;
800 /* remeber not erase the gateway names */
801 TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->src_gateway = e_route->src_gateway;
802 TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->dst_gateway = e_route->dst_gateway;
806 links_id = TO_ROUTE_FULL(*src_id,*dst_id,current_routing)->generic_route.link_list;
808 xbt_dynar_foreach(links, cpt, link_name) {
810 void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
812 xbt_dynar_push(links_id,&link);
814 THROW1(mismatch_error,0,"Link %s not found", link_name);
817 xbt_dynar_free(&keys);
820 /* delete the parse table */
821 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
822 route = (route_t)data;
823 xbt_dynar_free(&(route->link_list));
827 /* delete parse dict */
828 xbt_dict_free(&(routing->parse_routes));
830 /* Add the loopback if needed */
831 for (i = 0; i < table_size; i++) {
832 e_route = TO_ROUTE_FULL(i, i,current_routing);
833 if(!e_route) { // && !xbt_dynar_length(e_route->generic_route.link_list)
834 e_route = xbt_new0(s_route_extended_t,1);
835 e_route->src_gateway = NULL;
836 e_route->dst_gateway = NULL;
837 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
838 xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
839 TO_ROUTE_FULL(i, i,current_routing) = e_route;
843 /* Shrink the dynar routes (save unused slots) */
844 for (i=0;i<table_size;i++)
845 for (j=0;j<table_size;j++)
846 if(TO_ROUTE_FULL(i,j,current_routing))
847 xbt_dynar_shrink(TO_ROUTE_FULL(i,j,current_routing)->generic_route.link_list,0);
850 /* ************************************************************************** */
851 /* *************************** FLOYD ROUTING ******************************** */
853 #define TO_FLOYD_COST(i,j) cost_table[(i)+(j)*table_size]
854 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
855 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
856 #define TO_FLOYD_AS(i,j) (routing->AS_table)[(i)+(j)*AS_table_size]
858 /* Routing model structure */
861 s_routing_component_t generic_routing;
862 route_extended_t last_route;
863 /* vars for calculate the floyd algorith. */
864 int *predecessor_table;
865 void** link_table; /* char* -> network_element_t* */
866 xbt_dict_t predecessor_to_index;
867 /* store information to solve any AS route */
868 xbt_dict_t AS_to_index; /* char* -> network_element_t* */
869 route_limits_t AS_table;
870 /* store data during the parse process */
871 xbt_dict_t parse_routes;
873 } s_routing_component_floyd_t,*routing_component_floyd_t;
875 /* Business methods */
877 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
882 static xbt_dict_t floyd_get_network_elements(routing_component_t rc, e_surf_network_element_type_t req_type)
887 static void floyd_finalize(routing_component_t rc) {
891 static void* model_floyd_create(void) {
895 static void model_floyd_load() {
898 static void model_floyd_unload() {
901 static void model_floyd_end() {
904 /* ************************************************************************** */
905 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
908 s_routing_component_t generic_routing;
909 xbt_graph_t route_graph;
910 xbt_dict_t graph_node_map;
911 xbt_dict_t route_cache;
912 xbt_dynar_t last_route;
914 } s_routing_component_dijkstra_t,*routing_component_dijkstra_t;
916 /* Parse routing model functions */
918 /* Business methods */
920 /* Creation routing model functions */
922 static void* model_dijkstra_create() {
926 static void model_dijkstra_load() {
929 static void model_dijkstra_unload() {
932 static void model_dijkstra_end() {
935 static void* model_dijkstracache_create() {
939 static void model_dijkstracache_load() {
942 static void model_dijkstracache_unload() {
945 static void model_dijkstracache_end() {
949 /* ************************************************************************** */
950 /* ******************************* NO ROUTING ******************************* */
952 /* Routing model structure */
954 s_routing_component_t generic_routing;
955 } s_routing_component_none_t,*routing_component_none_t;
957 /* Business methods */
958 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
961 static void none_finalize(routing_component_t rc) {
965 /* Creation routing model functions */
966 static void* model_none_create() {
967 routing_component_none_t new_component = xbt_new0(s_routing_component_none_t,1);
968 new_component->generic_routing.get_route = none_get_route;
969 new_component->generic_routing.finalize = none_finalize;
970 return new_component;
973 static void model_none_load() {}
974 static void model_none_unload() {}
975 static void model_none_end() {}
977 /* ************************************************** */
978 /* ********** PATERN FOR NEW ROUTING **************** */
980 /* The minimal configuration of a new routing model need the next functions,
981 * also you need to set at the start of the file, the new model in the model
982 * list. Remember keep the null ending of the list.
984 /* Routing model structure */
986 s_routing_component_t generic_routing;
987 /* things that your routing model need */
988 } s_routing_component_NEW_t,*routing_component_NEW_t;
990 /* Parse routing model functions */
991 static void NEW_parse_S_host(void) {} /* example*/
993 /* Business methods */
994 static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;} /* mandatory */
995 static void NEW_finalize(routing_component_t rc) {} /* mandatory */
997 /* Creation routing model functions */
998 static void* model_NEW_create() {return NULL;} /* mandatory */
999 static void model_NEW_load() {} /* mandatory */
1000 static void model_NEW_unload() {} /* mandatory */
1001 static void model_NEW_end() {} /* mandatory */
1004 ////////////////////////////////////////////////////////////////////////////////
1005 // HERE FINISH THE NEW CODE
1006 ////////////////////////////////////////////////////////////////////////////////
1008 //...... DEBUG ONLY .... //
1009 static void print_tree(routing_component_t rc) {
1010 printf("(%s %s)\n",rc->name,rc->routing->name);
1012 xbt_dict_cursor_t cursor = NULL;
1015 if( rc->routing == &(routing_models[SURF_MODEL_FULL]) )
1016 { xbt_dict_foreach(((routing_component_full_t)rc)->to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1017 else if( rc->routing == &(routing_models[SURF_MODEL_FLOYD]) )
1018 { xbt_dict_foreach(((routing_component_floyd_t)rc)->predecessor_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); }
1019 xbt_dict_foreach(((routing_component_floyd_t)rc)->AS_to_index, cursor, key, val) { printf("<%s-%d> ",key,*val); } }
1021 xbt_assert0(0, "Invalid model for call \"print_tree\"");
1023 routing_component_t elem;
1024 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
1031 //...... DEBUG ONLY .... //
1032 static void print_global() {
1033 xbt_dict_cursor_t cursor = NULL;
1035 routing_component_t elem;
1036 xbt_dict_foreach(global_routing->where_network_elements, cursor, key, elem) {
1037 printf("<%s>\n",key);
1041 //...... DEBUG ONLY .... //
1042 static void print_AS_start(void) { printf("AS!!! %s y se rutea \"%s\"\n",A_surfxml_AS_id,A_surfxml_AS_routing); }
1043 static void print_AS_end(void) { printf("AS!!! %s\n",A_surfxml_AS_id); }
1044 static void print_host(void) { printf("host!!! %s\n",A_surfxml_host_id); }
1045 static void print_link(void) { printf("link!!! %s\n",A_surfxml_link_id); }
1046 static void print_route(void) { printf("route!!! %s a %s\n",A_surfxml_route_src,A_surfxml_route_dst); }
1047 static void print_ctn(void) { printf("ctn!!! %s\n",A_surfxml_link_c_ctn_id); }
1049 //...... DEBUG ONLY .... //
1050 static void DEBUG_exit(void) {
1054 printf("-- print all the example routes --\n");
1056 const char* names[] = { "11.A","11.B","11.C",
1060 unsigned int i,j,total = 3+2+1+2;
1064 for(i=0;i<total;i++) {
1065 for(j=0;j<total;j++) {
1066 links = (*(global_routing->get_route))(names[i],names[j]);
1067 printf("route from %s to %s >>> ",names[i],names[j]);
1070 xbt_dynar_foreach(links, cpt, link) {
1071 s_surf_resource_t* generic_resource = link;
1072 printf(" %s",generic_resource->name);
1081 printf("-- /////////////////////////////////////--\n");
1082 printf("-- /////////////////////////////////////--\n");
1085 links = (*(global_routing->get_route))(names[0],names[5]);
1090 printf("route from %s to %s >>> ",names[0],names[5]);
1091 xbt_dynar_foreach(links, cpt, link) {
1092 s_surf_resource_t* generic_resource = link;
1093 printf(" %s",generic_resource->name);
1101 printf("---------- call finalize ---------\n");
1102 (*(global_routing->finalize))();
1103 printf("----------------------------------\n");
1107 printf("-------- print tree elements -----\n");
1108 print_tree(global_routing->root);
1109 printf("----------------------------------\n\n");
1111 printf("-------- network_elements --------\n");
1113 printf("----------------------------------\n\n");
1115 // char* names[] = { "11.A","11.B","11.C","121.A","121.B","122.A","13.A","13.B"};
1116 // int i,j,total = 8;
1118 // printf("-- print all the example routes --\n");
1119 // char* names[] = { "11.A","11.B","11.C"};
1120 // int i,j,total = 3;
1122 // char* names[] = { "141.A","141.B","143.A","143.B"};
1123 // int i,j,total = 4;
1125 // char* names[] = { "142.A","142.B","142.C" };
1126 // int i,j,total = 3;
1128 // char* names[] = { "142.A","142.B","142.C", "11.A","11.B","11.C","141.A","141.B","143.A","143.B","11.A","11.B","11.C","121.A","121.B","122.A","13.A","13.B"};
1129 // int i,j,total = 3+4+8+3;
1131 // const char* names[] = { "11.A","11.B","11.C",
1136 // "142.A","142.B","142.C",
1138 // "15.A","15.B","15.C"};
1139 // unsigned int i,j,total = 3+2+1+2+2+3+2+3;
1141 // printf("-- print all the example routes --\n");
1142 // xbt_dynar_t links;
1144 // for(i=0;i<total;i++) {
1145 // for(j=0;j<total;j++) {
1146 // links = (*(global_routing->get_route))(names[i],names[j]);
1147 // printf("route from %s to %s >>> ",names[i],names[j]);
1148 // unsigned int cpt=0;
1149 // xbt_dynar_foreach(links, cpt, link) {
1150 // s_surf_resource_t* generic_resource = link;
1151 // printf(" %s",generic_resource->name);
1157 // printf("----------------------------------\n\n");
1159 // printf("---------- call finalize ---------\n");
1160 // (*(global_routing->finalize))();
1161 // printf("----------------------------------\n");
1166 ////////////////////////////////////////////////////////////////////////////////
1167 // HERE END THE NEW CODE
1168 ////////////////////////////////////////////////////////////////////////////////
1170 // /* ************************************************************************** */
1171 // /* *************************** FULL ROUTING ********************************* */
1173 // s_routing_t generic_routing;
1174 // xbt_dynar_t *routing_table;
1176 // size_t size_of_link;
1177 // } s_routing_full_t,*routing_full_t;
1179 // #define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count]
1180 // #define HOST2ROUTER(id) ((id)+(2<<29))
1181 // #define ROUTER2HOST(id) ((id)-(2>>29))
1182 // #define ISROUTER(id) ((id)>=(2<<29))
1185 // * Free the onelink routes
1187 // static void onelink_route_elem_free(void *e) {
1188 // s_onelink_t tmp = (s_onelink_t)e;
1197 // static void routing_full_parse_Shost(void) {
1198 // int *val = xbt_malloc(sizeof(int));
1199 // DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count);
1200 // *val = used_routing->host_count++;
1201 // xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free);
1202 // #ifdef HAVE_TRACING
1203 // TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1207 // static void routing_full_parse_Srouter(void) {
1208 // int *val = xbt_malloc(sizeof(int));
1209 // DEBUG3("Seen router %s (%d -> #%d)",A_surfxml_router_id,used_routing->router_count,
1210 // HOST2ROUTER(used_routing->router_count));
1211 // *val = HOST2ROUTER(used_routing->router_count++);
1212 // xbt_dict_set(used_routing->host_id,A_surfxml_router_id,val,xbt_free);
1213 // #ifdef HAVE_TRACING
1214 // TRACE_surf_host_define_id (A_surfxml_host_id, *val);
1215 // TRACE_surf_host_declaration (A_surfxml_host_id, 0);
1219 // static int src_id = -1;
1220 // static int dst_id = -1;
1221 // static void routing_full_parse_Sroute_set_endpoints(void)
1223 // src_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_src);
1224 // dst_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_dst);
1225 // DEBUG4("Route %s %d -> %s %d",A_surfxml_route_src,src_id,A_surfxml_route_dst,dst_id);
1226 // route_action = A_surfxml_route_action;
1229 // static void routing_full_parse_Eroute(void)
1232 // if (src_id != -1 && dst_id != -1) {
1233 // name = bprintf("%x#%x", src_id, dst_id);
1234 // manage_route(route_table, name, route_action, 0);
1239 // /* Cluster tag functions */
1241 // static void routing_full_parse_change_cpu_data(const char *hostName,
1242 // const char *surfxml_host_power,
1243 // const char *surfxml_host_availability,
1244 // const char *surfxml_host_availability_file,
1245 // const char *surfxml_host_state_file)
1249 // SURFXML_BUFFER_SET(host_id, hostName);
1250 // SURFXML_BUFFER_SET(host_power, surfxml_host_power /*hostPower */ );
1251 // SURFXML_BUFFER_SET(host_availability, surfxml_host_availability);
1252 // SURFXML_BUFFER_SET(host_availability_file, surfxml_host_availability_file);
1253 // SURFXML_BUFFER_SET(host_state_file, surfxml_host_state_file);
1256 // static void routing_full_parse_change_link_data(const char *linkName,
1257 // const char *surfxml_link_bandwidth,
1258 // const char *surfxml_link_bandwidth_file,
1259 // const char *surfxml_link_latency,
1260 // const char *surfxml_link_latency_file,
1261 // const char *surfxml_link_state_file)
1265 // SURFXML_BUFFER_SET(link_id, linkName);
1266 // SURFXML_BUFFER_SET(link_bandwidth, surfxml_link_bandwidth);
1267 // SURFXML_BUFFER_SET(link_bandwidth_file, surfxml_link_bandwidth_file);
1268 // SURFXML_BUFFER_SET(link_latency, surfxml_link_latency);
1269 // SURFXML_BUFFER_SET(link_latency_file, surfxml_link_latency_file);
1270 // SURFXML_BUFFER_SET(link_state_file, surfxml_link_state_file);
1273 // static void routing_full_parse_Scluster(void)
1275 // static int AX_ptr = 0;
1277 // char *cluster_id = A_surfxml_cluster_id;
1278 // char *cluster_prefix = A_surfxml_cluster_prefix;
1279 // char *cluster_suffix = A_surfxml_cluster_suffix;
1280 // char *cluster_radical = A_surfxml_cluster_radical;
1281 // char *cluster_power = A_surfxml_cluster_power;
1282 // char *cluster_bw = A_surfxml_cluster_bw;
1283 // char *cluster_lat = A_surfxml_cluster_lat;
1284 // char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1285 // char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1286 // char *backbone_name;
1287 // unsigned int it1,it2;
1288 // char *name1,*name2;
1289 // xbt_dynar_t names = NULL;
1290 // surfxml_bufferstack_push(1);
1292 // /* Make set a set to parse the prefix/suffix/radical into a neat list of names */
1293 // DEBUG4("Make <set id='%s' prefix='%s' suffix='%s' radical='%s'>",
1294 // cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
1295 // SURFXML_BUFFER_SET(set_id, cluster_id);
1296 // SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1297 // SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1298 // SURFXML_BUFFER_SET(set_radical, cluster_radical);
1300 // SURFXML_START_TAG(set);
1301 // SURFXML_END_TAG(set);
1303 // names = xbt_dict_get(set_list,cluster_id);
1305 // xbt_dynar_foreach(names,it1,name1) {
1306 // /* create the host */
1307 // routing_full_parse_change_cpu_data(name1, cluster_power, "1.0", "", "");
1308 // A_surfxml_host_state = A_surfxml_host_state_ON;
1310 // SURFXML_START_TAG(host);
1311 // SURFXML_END_TAG(host);
1313 // /* Here comes the link */
1314 // routing_full_parse_change_link_data(name1, cluster_bw, "", cluster_lat, "", "");
1315 // A_surfxml_link_state = A_surfxml_link_state_ON;
1316 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
1318 // SURFXML_START_TAG(link);
1319 // SURFXML_END_TAG(link);
1322 // /* Make backbone link */
1323 // backbone_name = bprintf("%s_bb", cluster_id);
1324 // routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1326 // A_surfxml_link_state = A_surfxml_link_state_ON;
1327 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1329 // SURFXML_START_TAG(link);
1330 // SURFXML_END_TAG(link);
1332 // /* And now the internal routes */
1333 // xbt_dynar_foreach(names,it1,name1) {
1334 // xbt_dynar_foreach(names,it2,name2) {
1335 // if (strcmp(name1,name2)) {
1336 // A_surfxml_route_action = A_surfxml_route_action_POSTPEND;
1337 // SURFXML_BUFFER_SET(route_src,name1);
1338 // SURFXML_BUFFER_SET(route_dst,name2);
1339 // SURFXML_START_TAG(route); {
1340 // /* FIXME: name1 link is added by error about 20 lines below, so don't add it here
1341 // SURFXML_BUFFER_SET(link_c_ctn_id, name1);
1342 // SURFXML_START_TAG(link_c_ctn);
1343 // SURFXML_END_TAG(link_c_ctn);
1345 // SURFXML_BUFFER_SET(link_c_ctn_id, backbone_name);
1346 // SURFXML_START_TAG(link_c_ctn);
1347 // SURFXML_END_TAG(link_c_ctn);
1349 // SURFXML_BUFFER_SET(link_c_ctn_id, name2);
1350 // SURFXML_START_TAG(link_c_ctn);
1351 // SURFXML_END_TAG(link_c_ctn);
1353 // } SURFXML_END_TAG(route);
1358 // /* Make route multi with the outside world, i.e. cluster->$* */
1361 // * This also adds an elements to the routes within the cluster,
1362 // * and I guess it's wrong, but since this element is commented out in the above
1363 // * code creating the internal routes, we're good.
1364 // * To fix it, I'd say that we need a way to understand "$*-${cluster_id}" as "whole world, but the guys in that cluster"
1365 // * But for that, we need to install a real expression parser for src/dst attributes
1368 // * This also adds a dumb element (the private link) in place of the loopback. Then, since
1369 // * the loopback is added only if no link to self already exist, this fails.
1370 // * That's really dumb.
1373 // * It seems to me that it does not add the backbone to the path to outside world...
1375 // SURFXML_BUFFER_SET(route_c_multi_src, cluster_id);
1376 // SURFXML_BUFFER_SET(route_c_multi_dst, "$*");
1377 // A_surfxml_route_c_multi_symmetric = A_surfxml_route_c_multi_symmetric_NO;
1378 // A_surfxml_route_c_multi_action = A_surfxml_route_c_multi_action_PREPEND;
1380 // SURFXML_START_TAG(route_c_multi);
1382 // SURFXML_BUFFER_SET(link_c_ctn_id, "$src");
1384 // SURFXML_START_TAG(link_c_ctn);
1385 // SURFXML_END_TAG(link_c_ctn);
1387 // SURFXML_END_TAG(route_c_multi);
1389 // free(backbone_name);
1391 // /* Restore buff */
1392 // surfxml_bufferstack_pop(1);
1396 // static void routing_full_parse_end(void) {
1397 // routing_full_t routing = (routing_full_t) used_routing;
1399 // unsigned int cpt = 0;
1400 // xbt_dict_cursor_t cursor = NULL;
1401 // char *key, *data, *end;
1402 // const char *sep = "#";
1403 // xbt_dynar_t links, keys;
1404 // char *link_name = NULL;
1407 // int host_count = routing->generic_routing.host_count;
1409 // /* Create the routing table */
1410 // routing->routing_table = xbt_new0(xbt_dynar_t, host_count * host_count);
1411 // for (i=0;i<host_count;i++)
1412 // for (j=0;j<host_count;j++)
1413 // ROUTE_FULL(i,j) = xbt_dynar_new(routing->size_of_link,NULL);
1415 // /* Put the routes in position */
1416 // xbt_dict_foreach(route_table, cursor, key, data) {
1418 // links = (xbt_dynar_t) data;
1419 // keys = xbt_str_split_str(key, sep);
1421 // src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1422 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1423 // xbt_dynar_free(&keys);
1425 // if(xbt_dynar_length(links) == 1){
1426 // s_onelink_t new_link = (s_onelink_t) xbt_malloc0(sizeof(s_onelink));
1427 // new_link->src_id = src_id;
1428 // new_link->dst_id = dst_id;
1429 // link_name = xbt_dynar_getfirst_as(links, char*);
1430 // new_link->link_ptr = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1431 // DEBUG3("Adding onelink route from (#%d) to (#%d), link_name %s",src_id, dst_id, link_name);
1432 // xbt_dict_set(onelink_routes, link_name, (void *)new_link, onelink_route_elem_free);
1433 // #ifdef HAVE_TRACING
1434 // TRACE_surf_link_save_endpoints (link_name, src_id, dst_id);
1438 // if(ISROUTER(src_id) || ISROUTER(dst_id)) {
1439 // DEBUG2("There is route with a router here: (%d ,%d)",src_id,dst_id);
1440 // /* Check there is only one link in the route and store the information */
1444 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1445 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1446 // xbt_dynar_foreach(links, cpt, link_name) {
1447 // void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1449 // xbt_dynar_push(ROUTE_FULL(src_id,dst_id),&link);
1451 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1455 // /* Add the loopback if needed */
1456 // for (i = 0; i < host_count; i++)
1457 // if (!xbt_dynar_length(ROUTE_FULL(i, i)))
1458 // xbt_dynar_push(ROUTE_FULL(i,i),&routing->loopback);
1460 // /* Shrink the dynar routes (save unused slots) */
1461 // for (i=0;i<host_count;i++)
1462 // for (j=0;j<host_count;j++)
1463 // xbt_dynar_shrink(ROUTE_FULL(i,j),0);
1467 // * Business methods
1469 // static xbt_dynar_t routing_full_get_route(int src,int dst) {
1470 // xbt_assert0(!(ISROUTER(src) || ISROUTER(dst)), "Ask for route \"from\" or \"to\" a router node");
1471 // return ROUTE_FULL(src,dst);
1474 // static xbt_dict_t routing_full_get_onelink_routes(void){
1475 // return onelink_routes;
1478 // static int routing_full_is_router(int id){
1479 // return ISROUTER(id);
1482 // static void routing_full_finalize(void) {
1483 // routing_full_t routing = (routing_full_t)used_routing;
1487 // for (i = 0; i < used_routing->host_count; i++)
1488 // for (j = 0; j < used_routing->host_count; j++)
1489 // xbt_dynar_free(&ROUTE_FULL(i, j));
1490 // free(routing->routing_table);
1491 // xbt_dict_free(&used_routing->host_id);
1492 // xbt_dict_free(&onelink_routes);
1498 // static void routing_model_full_create(size_t size_of_link,void *loopback) {
1499 // /* initialize our structure */
1500 // routing_full_t routing = xbt_new0(s_routing_full_t,1);
1501 // routing->generic_routing.name = "Full";
1502 // routing->generic_routing.host_count = 0;
1503 // routing->generic_routing.get_route = routing_full_get_route;
1504 // routing->generic_routing.get_onelink_routes = routing_full_get_onelink_routes;
1505 // routing->generic_routing.is_router = routing_full_is_router;
1506 // routing->generic_routing.finalize = routing_full_finalize;
1508 // routing->size_of_link = size_of_link;
1509 // routing->loopback = loopback;
1511 // /* Set it in position */
1512 // used_routing = (routing_t) routing;
1514 // /* Set the dict for onehop routes */
1515 // onelink_routes = xbt_dict_new();
1517 // routing->generic_routing.host_id = xbt_dict_new();
1519 // /* Setup the parsing callbacks we need */
1520 // // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1521 // // surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1522 // // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_full_parse_end);
1523 // // surfxml_add_callback(STag_surfxml_route_cb_list, &routing_full_parse_Sroute_set_endpoints);
1524 // // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1525 // // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
1527 // // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1528 // // surfxml_add_callback(STag_surfxml_router_cb_list, &routing_full_parse_Srouter);
1532 /* ************************************************************************** */
1534 // static void routing_shortest_path_parse_Scluster(void)
1536 // static int AX_ptr = 0;
1538 // char *cluster_id = A_surfxml_cluster_id;
1539 // char *cluster_prefix = A_surfxml_cluster_prefix;
1540 // char *cluster_suffix = A_surfxml_cluster_suffix;
1541 // char *cluster_radical = A_surfxml_cluster_radical;
1542 // char *cluster_power = A_surfxml_cluster_power;
1543 // char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
1544 // char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
1545 // char *backbone_name;
1547 // surfxml_bufferstack_push(1);
1550 // SURFXML_BUFFER_SET(set_id, cluster_id);
1551 // SURFXML_BUFFER_SET(set_prefix, cluster_prefix);
1552 // SURFXML_BUFFER_SET(set_suffix, cluster_suffix);
1553 // SURFXML_BUFFER_SET(set_radical, cluster_radical);
1555 // SURFXML_START_TAG(set);
1556 // SURFXML_END_TAG(set);
1558 // /* Make foreach */
1559 // SURFXML_BUFFER_SET(foreach_set_id, cluster_id);
1561 // SURFXML_START_TAG(foreach);
1563 // /* Make host for the foreach */
1564 // routing_full_parse_change_cpu_data("$1", cluster_power, "1.0", "", "");
1565 // A_surfxml_host_state = A_surfxml_host_state_ON;
1567 // SURFXML_START_TAG(host);
1568 // SURFXML_END_TAG(host);
1570 // SURFXML_END_TAG(foreach);
1572 // /* Make backbone link */
1573 // backbone_name = bprintf("%s_bb", cluster_id);
1574 // routing_full_parse_change_link_data(backbone_name, cluster_bb_bw, "", cluster_bb_lat, "",
1576 // A_surfxml_link_state = A_surfxml_link_state_ON;
1577 // A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_FATPIPE;
1579 // SURFXML_START_TAG(link);
1580 // SURFXML_END_TAG(link);
1582 // free(backbone_name);
1584 // /* Restore buff */
1585 // surfxml_bufferstack_pop(1);
1588 // /* ************************************************************************** */
1589 // /* *************************** FLOYD ROUTING ********************************* */
1591 // s_routing_t generic_routing;
1592 // int *predecessor_table;
1593 // void** link_table;
1594 // xbt_dynar_t last_route;
1596 // size_t size_of_link;
1597 // } s_routing_floyd_t,*routing_floyd_t;
1599 // #define FLOYD_COST(i,j) cost_table[(i)+(j)*(used_routing)->host_count]
1600 // #define FLOYD_PRED(i,j) ((routing_floyd_t)used_routing)->predecessor_table[(i)+(j)*(used_routing)->host_count]
1601 // #define FLOYD_LINK(i,j) ((routing_floyd_t)used_routing)->link_table[(i)+(j)*(used_routing)->host_count]
1603 // static void routing_floyd_parse_end(void) {
1605 // routing_floyd_t routing = (routing_floyd_t) used_routing;
1607 // void* link_list = NULL;
1608 // double * cost_table;
1609 // xbt_dict_cursor_t cursor = NULL;
1610 // char *key,*data, *end;
1611 // const char *sep = "#";
1612 // xbt_dynar_t links, keys;
1614 // unsigned int i,j;
1615 // unsigned int a,b,c;
1616 // int host_count = routing->generic_routing.host_count;
1617 // char * link_name = NULL;
1618 // void * link = NULL;
1620 // /* Create Cost, Predecessor and Link tables */
1621 // cost_table = xbt_new0(double, host_count * host_count); //link cost from host to host
1622 // routing->predecessor_table = xbt_new0(int, host_count*host_count); //predecessor host numbers
1623 // routing->link_table = xbt_new0(void*,host_count*host_count); //actual link between src and dst
1624 // routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1626 // /* Initialize costs and predecessors*/
1627 // for(i = 0; i<host_count;i++)
1628 // for(j = 0; j<host_count;j++) {
1629 // FLOYD_COST(i,j) = DBL_MAX;
1630 // FLOYD_PRED(i,j) = -1;
1633 // /* Put the routes in position */
1634 // xbt_dict_foreach(route_table, cursor, key, data) {
1636 // links = (xbt_dynar_t)data;
1637 // keys = xbt_str_split_str(key, sep);
1640 // src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
1641 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
1642 // xbt_dynar_free(&keys);
1644 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1645 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1646 // xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id);
1648 // link_name = xbt_dynar_getfirst_as(links, char*);
1649 // link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1652 // link_list = link;
1654 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1657 // FLOYD_LINK(src_id,dst_id) = link_list;
1658 // FLOYD_PRED(src_id, dst_id) = src_id;
1661 // FLOYD_COST(src_id, dst_id) = 1; // assume 1 for now
1665 // /* Add the loopback if needed */
1666 // for (i = 0; i < host_count; i++)
1667 // if (!FLOYD_PRED(i, i)) {
1668 // FLOYD_PRED(i, i) = i;
1669 // FLOYD_COST(i, i) = 1;
1670 // FLOYD_LINK(i, i) = routing->loopback;
1674 // //Calculate path costs
1676 // for(c=0;c<host_count;c++) {
1677 // for(a=0;a<host_count;a++) {
1678 // for(b=0;b<host_count;b++) {
1679 // if(FLOYD_COST(a,c) < DBL_MAX && FLOYD_COST(c,b) < DBL_MAX) {
1680 // if(FLOYD_COST(a,b) == DBL_MAX || (FLOYD_COST(a,c)+FLOYD_COST(c,b) < FLOYD_COST(a,b))) {
1681 // FLOYD_COST(a,b) = FLOYD_COST(a,c)+FLOYD_COST(c,b);
1682 // FLOYD_PRED(a,b) = FLOYD_PRED(c,b);
1690 // free(cost_table);
1694 // * Business methods
1696 // static xbt_dynar_t routing_floyd_get_route(int src_id,int dst_id) {
1698 // routing_floyd_t routing = (routing_floyd_t) used_routing;
1700 // int pred = dst_id;
1701 // int prev_pred = 0;
1703 // xbt_dynar_reset(routing->last_route);
1706 // prev_pred = pred;
1707 // pred = FLOYD_PRED(src_id, pred);
1709 // if(pred == -1) // if no pred in route -> no route to host
1712 // xbt_dynar_unshift(routing->last_route, &FLOYD_LINK(pred,prev_pred));
1714 // } while(pred != src_id);
1716 // xbt_assert2(pred != -1, "no route from host %d to %d", src_id, dst_id);
1718 // return routing->last_route;
1721 // static void routing_floyd_finalize(void) {
1722 // routing_floyd_t routing = (routing_floyd_t)used_routing;
1725 // free(routing->link_table);
1726 // free(routing->predecessor_table);
1727 // xbt_dynar_free(&routing->last_route);
1728 // xbt_dict_free(&used_routing->host_id);
1734 // static xbt_dict_t routing_floyd_get_onelink_routes(void){
1735 // xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model Floyd");
1738 // static int routing_floyd_is_router(int id){
1739 // xbt_assert0(0,"The get_is_router feature is not supported in routing model Floyd");
1742 // static void routing_model_floyd_create(size_t size_of_link,void *loopback) {
1743 // /* initialize our structure */
1744 // routing_floyd_t routing = xbt_new0(s_routing_floyd_t,1);
1745 // routing->generic_routing.name = "Floyd";
1746 // routing->generic_routing.host_count = 0;
1747 // routing->generic_routing.host_id = xbt_dict_new();
1748 // routing->generic_routing.get_route = routing_floyd_get_route;
1749 // routing->generic_routing.get_onelink_routes = routing_floyd_get_onelink_routes;
1750 // routing->generic_routing.is_router = routing_floyd_is_router;
1751 // routing->generic_routing.finalize = routing_floyd_finalize;
1752 // routing->size_of_link = size_of_link;
1753 // routing->loopback = loopback;
1755 // /* Set it in position */
1756 // used_routing = (routing_t) routing;
1758 // /* Setup the parsing callbacks we need */
1759 // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
1760 // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_floyd_parse_end);
1761 // surfxml_add_callback(STag_surfxml_route_cb_list,
1762 // &routing_full_parse_Sroute_set_endpoints);
1763 // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
1764 // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
1768 // /* ************************************************************************** */
1769 // /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1771 // s_routing_t generic_routing;
1772 // xbt_graph_t route_graph;
1773 // xbt_dict_t graph_node_map;
1774 // xbt_dict_t route_cache;
1775 // xbt_dynar_t last_route;
1778 // size_t size_of_link;
1779 // } s_routing_dijkstra_t,*routing_dijkstra_t;
1782 // typedef struct graph_node_data {
1784 // int graph_id; //used for caching internal graph id's
1785 // } s_graph_node_data_t, * graph_node_data_t;
1787 // typedef struct graph_node_map_element {
1789 // } s_graph_node_map_element_t, * graph_node_map_element_t;
1791 // typedef struct route_cache_element {
1794 // } s_route_cache_element_t, * route_cache_element_t;
1799 // static void route_cache_elem_free(void *e) {
1800 // route_cache_element_t elm=(route_cache_element_t)e;
1803 // free(elm->pred_arr);
1808 // static void graph_node_map_elem_free(void *e) {
1809 // graph_node_map_element_t elm = (graph_node_map_element_t)e;
1817 // * Utility functions
1819 // static xbt_node_t route_graph_new_node(int id, int graph_id) {
1820 // xbt_node_t node = NULL;
1821 // graph_node_data_t data = NULL;
1822 // graph_node_map_element_t elm = NULL;
1823 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1825 // data = xbt_new0(struct graph_node_data, sizeof(struct graph_node_data));
1827 // data->graph_id = graph_id;
1828 // node = xbt_graph_new_node(routing->route_graph, data);
1830 // elm = xbt_new0(struct graph_node_map_element, sizeof(struct graph_node_map_element));
1831 // elm->node = node;
1832 // xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free);
1837 // static graph_node_map_element_t graph_node_map_search(int id) {
1838 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1840 // graph_node_map_element_t elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&id), sizeof(int));
1848 // static void route_new_dijkstra(int src_id, int dst_id, void* link) {
1849 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1851 // xbt_node_t src = NULL;
1852 // xbt_node_t dst = NULL;
1853 // graph_node_map_element_t src_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&src_id), sizeof(int));
1854 // graph_node_map_element_t dst_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&dst_id), sizeof(int));
1857 // src = src_elm->node;
1860 // dst = dst_elm->node;
1862 // //add nodes if they don't exist in the graph
1863 // if(src_id == dst_id && src == NULL && dst == NULL) {
1864 // src = route_graph_new_node(src_id, -1);
1867 // if(src == NULL) {
1868 // src = route_graph_new_node(src_id, -1);
1871 // if(dst == NULL) {
1872 // dst = route_graph_new_node(dst_id, -1);
1876 // //add link as edge to graph
1877 // xbt_graph_new_edge(routing->route_graph, src, dst, link);
1881 // static void add_loopback_dijkstra(void) {
1882 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1884 // xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1886 // xbt_node_t node = NULL;
1887 // unsigned int cursor2;
1888 // xbt_dynar_foreach(nodes, cursor2, node) {
1889 // xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1890 // xbt_edge_t edge = NULL;
1891 // unsigned int cursor;
1894 // xbt_dynar_foreach(out_edges, cursor, edge) {
1895 // xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1896 // if(other_node == node) {
1903 // xbt_graph_new_edge(routing->route_graph, node, node, &routing->loopback);
1907 // static void routing_dijkstra_parse_end(void) {
1908 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1910 // xbt_dict_cursor_t cursor = NULL;
1911 // char *key, *data, *end;
1912 // const char *sep = "#";
1913 // xbt_dynar_t links, keys;
1914 // char* link_name = NULL;
1915 // void* link = NULL;
1916 // xbt_node_t node = NULL;
1917 // unsigned int cursor2;
1918 // xbt_dynar_t nodes = NULL;
1919 // /* Create the topology graph */
1920 // routing->route_graph = xbt_graph_new_graph(1, NULL);
1921 // routing->graph_node_map = xbt_dict_new();
1922 // routing->last_route = xbt_dynar_new(routing->size_of_link, NULL);
1923 // if(routing->cached)
1924 // routing->route_cache = xbt_dict_new();
1927 // /* Put the routes in position */
1928 // xbt_dict_foreach(route_table, cursor, key, data) {
1930 // links = (xbt_dynar_t) data;
1931 // keys = xbt_str_split_str(key, sep);
1933 // src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
1934 // dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
1935 // xbt_dynar_free(&keys);
1937 // DEBUG4("Handle %d %d (from %d hosts): %ld links",
1938 // src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
1940 // xbt_assert3(xbt_dynar_length(links) == 1, "%ld links in route between host %d and %d, should be 1", xbt_dynar_length(links), src_id, dst_id);
1942 // link_name = xbt_dynar_getfirst_as(links, char*);
1943 // link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
1945 // route_new_dijkstra(src_id,dst_id,link);
1947 // THROW1(mismatch_error,0,"Link %s not found", link_name);
1951 // /* Add the loopback if needed */
1952 // add_loopback_dijkstra();
1954 // /* initialize graph indexes in nodes after graph has been built */
1955 // nodes = xbt_graph_get_nodes(routing->route_graph);
1957 // xbt_dynar_foreach(nodes, cursor2, node) {
1958 // graph_node_data_t data = xbt_graph_node_get_data(node);
1959 // data->graph_id = cursor2;
1965 // * Business methods
1967 // static xbt_dynar_t routing_dijkstra_get_route(int src_id,int dst_id) {
1969 // routing_dijkstra_t routing = (routing_dijkstra_t) used_routing;
1970 // int * pred_arr = NULL;
1971 // int src_node_id = 0;
1972 // int dst_node_id = 0;
1973 // int * nodeid = NULL;
1976 // void * link = NULL;
1977 // route_cache_element_t elm = NULL;
1978 // xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1980 // /*Use the graph_node id mapping set to quickly find the nodes */
1981 // graph_node_map_element_t src_elm = graph_node_map_search(src_id);
1982 // graph_node_map_element_t dst_elm = graph_node_map_search(dst_id);
1983 // xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", src_id, dst_id);
1984 // src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
1985 // dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
1987 // if(routing->cached) {
1988 // /*check if there is a cached predecessor list avail */
1989 // elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int));
1992 // if(elm) { //cached mode and cache hit
1993 // pred_arr = elm->pred_arr;
1994 // } else { //not cached mode or cache miss
1995 // double * cost_arr = NULL;
1996 // xbt_heap_t pqueue = NULL;
1999 // int nr_nodes = xbt_dynar_length(nodes);
2000 // cost_arr = xbt_new0(double, nr_nodes); //link cost from src to other hosts
2001 // pred_arr = xbt_new0(int, nr_nodes); //predecessors in path from src
2002 // pqueue = xbt_heap_new(nr_nodes, free);
2005 // cost_arr[src_node_id] = 0.0;
2007 // for(i = 0; i < nr_nodes; i++) {
2008 // if(i != src_node_id) {
2009 // cost_arr[i] = DBL_MAX;
2014 // //initialize priority queue
2015 // nodeid = xbt_new0(int, 1);
2017 // xbt_heap_push(pqueue, nodeid, cost_arr[i]);
2021 // // apply dijkstra using the indexes from the graph's node array
2022 // while(xbt_heap_size(pqueue) > 0) {
2023 // int * v_id = xbt_heap_pop(pqueue);
2024 // xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
2025 // xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
2026 // xbt_edge_t edge = NULL;
2027 // unsigned int cursor;
2029 // xbt_dynar_foreach(out_edges, cursor, edge) {
2030 // xbt_node_t u_node = xbt_graph_edge_get_target(edge);
2031 // graph_node_data_t data = xbt_graph_node_get_data(u_node);
2032 // int u_id = data->graph_id;
2033 // int cost_v_u = 1; //fixed link cost for now
2035 // if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
2036 // pred_arr[u_id] = *v_id;
2037 // cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
2038 // nodeid = xbt_new0(int, 1);
2040 // xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
2044 // //free item popped from pqueue
2049 // xbt_heap_free(pqueue);
2053 // //compose route path with links
2054 // xbt_dynar_reset(routing->last_route);
2056 // for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
2057 // xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
2058 // xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
2059 // xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
2061 // xbt_assert2(edge != NULL, "no route between host %d and %d", src_id, dst_id);
2063 // link = xbt_graph_edge_get_data(edge);
2064 // xbt_dynar_unshift(routing->last_route, &link);
2069 // if(routing->cached && elm == NULL) {
2070 // //add to predecessor list of the current src-host to cache
2071 // elm = xbt_new0(struct route_cache_element, sizeof(struct route_cache_element));
2072 // elm->pred_arr = pred_arr;
2073 // elm->size = size;
2074 // xbt_dict_set_ext(routing->route_cache, (char*)(&src_id), sizeof(int), (xbt_set_elm_t)elm, &route_cache_elem_free);
2077 // if(!routing->cached)
2080 // return routing->last_route;
2084 // static void routing_dijkstra_finalize(void) {
2085 // routing_dijkstra_t routing = (routing_dijkstra_t)used_routing;
2088 // xbt_graph_free_graph(routing->route_graph, &free, NULL, &free);
2089 // xbt_dict_free(&routing->graph_node_map);
2090 // if(routing->cached)
2091 // xbt_dict_free(&routing->route_cache);
2092 // xbt_dynar_free(&routing->last_route);
2093 // xbt_dict_free(&used_routing->host_id);
2099 // static xbt_dict_t routing_dijkstraboth_get_onelink_routes(void){
2100 // xbt_assert0(0,"The get_onelink_routes feature is not supported in routing model dijkstraboth");
2103 // static int routing_dijkstraboth_is_router(int id){
2104 // xbt_assert0(0,"The get_is_router feature is not supported in routing model dijkstraboth");
2110 // static void routing_model_dijkstraboth_create(size_t size_of_link,void *loopback, int cached) {
2111 // /* initialize our structure */
2112 // routing_dijkstra_t routing = xbt_new0(s_routing_dijkstra_t,1);
2113 // routing->generic_routing.name = "Dijkstra";
2114 // routing->generic_routing.host_count = 0;
2115 // routing->generic_routing.get_route = routing_dijkstra_get_route;
2116 // routing->generic_routing.get_onelink_routes = routing_dijkstraboth_get_onelink_routes;
2117 // routing->generic_routing.is_router = routing_dijkstraboth_is_router;
2118 // routing->generic_routing.finalize = routing_dijkstra_finalize;
2119 // routing->size_of_link = size_of_link;
2120 // routing->loopback = loopback;
2121 // routing->cached = cached;
2123 // /* Set it in position */
2124 // used_routing = (routing_t) routing;
2126 // /* Setup the parsing callbacks we need */
2127 // routing->generic_routing.host_id = xbt_dict_new();
2128 // surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
2129 // surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_dijkstra_parse_end);
2130 // surfxml_add_callback(STag_surfxml_route_cb_list,
2131 // &routing_full_parse_Sroute_set_endpoints);
2132 // surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
2133 // surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_shortest_path_parse_Scluster);
2136 // static void routing_model_dijkstra_create(size_t size_of_link,void *loopback) {
2137 // routing_model_dijkstraboth_create(size_of_link, loopback, 0);
2140 // static void routing_model_dijkstracache_create(size_t size_of_link,void *loopback) {
2141 // routing_model_dijkstraboth_create(size_of_link, loopback, 1);
2144 /* ************************************************** */
2145 /* ********** NO ROUTING **************************** */
2148 // static void routing_none_finalize(void) {
2149 // if (used_routing) {
2150 // xbt_dict_free(&used_routing->host_id);
2151 // free(used_routing);
2152 // used_routing=NULL;
2156 // static void routing_model_none_create(size_t size_of_link,void *loopback) {
2157 // routing_t routing = xbt_new0(s_routing_t,1);
2158 // INFO0("Null routing");
2159 // routing->name = "none";
2160 // routing->host_count = 0;
2161 // routing->host_id = xbt_dict_new();
2162 // routing->get_onelink_routes = NULL;
2163 // routing->is_router = NULL;
2164 // routing->get_route = NULL;
2166 // routing->finalize = routing_none_finalize;
2168 // /* Set it in position */
2169 // used_routing = (routing_t) routing;