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 <pcre.h> /* regular expresion library */
9 #include "surf_private.h"
10 #include "xbt/dynar.h"
12 #include "xbt/config.h"
13 #include "xbt/graph.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf");
19 routing_global_t global_routing = NULL;
20 routing_component_t current_routing = NULL;
21 model_type_t current_routing_model = NULL;
23 /* Prototypes of each model */
24 static void* model_full_create(void); /* create structures for full routing model */
25 static void model_full_load(void); /* load parse functions for full routing model */
26 static void model_full_unload(void); /* unload parse functions for full routing model */
27 static void model_full_end(void); /* finalize the creation of full routing model */
29 static void* model_floyd_create(void); /* create structures for floyd routing model */
30 static void model_floyd_load(void); /* load parse functions for floyd routing model */
31 static void model_floyd_unload(void); /* unload parse functions for floyd routing model */
32 static void model_floyd_end(void); /* finalize the creation of floyd routing model */
34 static void* model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */
35 static void* model_dijkstra_create(void); /* create structures for dijkstra routing model */
36 static void* model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
37 static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */
38 static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */
39 static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */
41 static void* model_rulebased_create(void); /* create structures for rulebased routing model */
42 static void model_rulebased_load(void); /* load parse functions for rulebased routing model */
43 static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */
44 static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */
46 static void* model_none_create(void); /* none routing model */
47 static void model_none_load(void); /* none routing model */
48 static void model_none_unload(void); /* none routing model */
49 static void model_none_end(void); /* none routing model */
51 static void routing_full_parse_Scluster(void);/*cluster bypass*/
53 /* this lines are olny for replace use like index in the model table */
54 #define SURF_MODEL_FULL 0
55 #define SURF_MODEL_FLOYD 1
56 #define SURF_MODEL_DIJKSTRA 2
57 #define SURF_MODEL_DIJKSTRACACHE 3
58 #define SURF_MODEL_RULEBASED 4
59 #define SURF_MODEL_NONE 5
61 /* must be finish with null and carefull if change de order */
62 struct s_model_type routing_models[] =
63 { {"Full", "Full routing data (fast, large memory requirements, fully expressive)",
64 model_full_create, model_full_load, model_full_unload, model_full_end },
65 {"Floyd", "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)",
66 model_floyd_create, model_floyd_load, model_floyd_unload, model_floyd_end },
67 {"Dijkstra", "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)",
68 model_dijkstra_create ,model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
69 {"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)",
70 model_dijkstracache_create, model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end },
71 {"RuleBased", "Rule-Based routing data (...)",
72 model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end },
73 {"none", "No routing (usable with Constant network only)",
74 model_none_create, model_none_load, model_none_unload, model_none_end },
75 {NULL,NULL,NULL,NULL,NULL,NULL}};
77 /* ************************************************************************** */
78 /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
80 static void generic_set_processing_unit(routing_component_t rc, const char* name);
81 static void generic_set_autonomous_system(routing_component_t rc, const char* name);
82 static void generic_set_route(routing_component_t rc, const char* src, const char* dst, route_t route);
83 static void generic_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route);
84 static void generic_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route);
86 /* ************************************************************************** */
87 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
89 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst);
91 /* ************************************************************************** */
92 /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
94 static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order);
95 static void generic_free_route(route_t route);
96 static void generic_free_extended_route(route_extended_t e_route);
97 static routing_component_t generic_autonomous_system_exist(routing_component_t rc, char* element);
98 static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element);
99 static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst);
101 /* ************************************************************************** */
102 /* **************************** GLOBAL FUNCTIONS **************************** */
104 /* global parse functions */
105 static char* src = NULL; /* temporary store the source name of a route */
106 static char* dst = NULL; /* temporary store the destination name of a route */
107 static char* gw_src = NULL; /* temporary store the gateway source name of a route */
108 static char* gw_dst = NULL; /* temporary store the gateway destination name of a route */
109 static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */
112 * \brief Add a "host" to the network element list
114 static void parse_S_host(void) {
115 if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
116 xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_host_id),
117 "Reading a host, processing unit \"%s\" already exist",A_surfxml_host_id);
118 xbt_assert1(current_routing->set_processing_unit,
119 "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
120 (*(current_routing->set_processing_unit))(current_routing,A_surfxml_host_id);
121 xbt_dict_set(global_routing->where_network_elements,A_surfxml_host_id,(void*)current_routing,NULL);
125 * \brief Add a "router" to the network element list
127 static void parse_S_router(void) {
128 if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
129 xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_router_id),
130 "Reading a router, processing unit \"%s\" already exist",A_surfxml_router_id);
131 xbt_assert1(current_routing->set_processing_unit,
132 "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
133 (*(current_routing->set_processing_unit))(current_routing,A_surfxml_router_id);
134 xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)current_routing,NULL);
138 * \brief Set the endponints for a route
140 static void parse_S_route_new_and_endpoints(void) {
141 if( src != NULL && dst != NULL && link_list != NULL )
142 THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_route_src,A_surfxml_route_dst);
143 src = A_surfxml_route_src;
144 dst = A_surfxml_route_dst;
145 xbt_assert2(strlen(src)>0||strlen(dst)>0,
146 "Some limits are null in the route between \"%s\" and \"%s\"",src,dst);
147 link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
151 * \brief Set the endponints and gateways for a ASroute
153 static void parse_S_ASroute_new_and_endpoints(void) {
154 if( src != NULL && dst != NULL && link_list != NULL )
155 THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_ASroute_src,A_surfxml_ASroute_dst);
156 src = A_surfxml_ASroute_src;
157 dst = A_surfxml_ASroute_dst;
158 gw_src = A_surfxml_ASroute_gw_src;
159 gw_dst = A_surfxml_ASroute_gw_dst;
160 xbt_assert2(strlen(src)>0||strlen(dst)>0||strlen(gw_src)>0||strlen(gw_dst)>0,
161 "Some limits are null in the route between \"%s\" and \"%s\"",src,dst);
162 link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
166 * \brief Set the endponints for a bypassRoute
168 static void parse_S_bypassRoute_new_and_endpoints(void) {
169 if( src != NULL && dst != NULL && link_list != NULL )
170 THROW2(arg_error,0,"Bypass Route between %s to %s can not be defined",A_surfxml_bypassRoute_src,A_surfxml_bypassRoute_dst);
171 src = A_surfxml_bypassRoute_src;
172 dst = A_surfxml_bypassRoute_dst;
173 gw_src = A_surfxml_bypassRoute_gw_src;
174 gw_dst = A_surfxml_bypassRoute_gw_dst;
175 xbt_assert2(strlen(src)>0||strlen(dst)>0||strlen(gw_src)>0||strlen(gw_dst)>0,
176 "Some limits are null in the route between \"%s\" and \"%s\"",src,dst);
177 link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref);
181 * \brief Set a new link on the actual list of link for a route or ASroute
183 static void parse_E_link_c_ctn_new_elem(void) {
185 val = xbt_strdup(A_surfxml_link_c_ctn_id);
186 xbt_dynar_push(link_list, &val);
190 * \brief Store the route by calling the set_route function of the current routing component
192 static void parse_E_route_store_route(void) {
193 route_t route = xbt_new0(s_route_t,1);
194 route->link_list = link_list;
195 // xbt_assert1(generic_processing_units_exist(current_routing,src),"the \"%s\" processing units gateway does not exist",src);
196 // xbt_assert1(generic_processing_units_exist(current_routing,dst),"the \"%s\" processing units gateway does not exist",dst);
197 xbt_assert1(current_routing->set_route,"no defined method \"set_route\" in \"%s\"",current_routing->name);
198 (*(current_routing->set_route))(current_routing,src,dst,route);
205 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
207 static void parse_E_ASroute_store_route(void) {
208 route_extended_t e_route = xbt_new0(s_route_extended_t,1);
209 e_route->generic_route.link_list = link_list;
210 e_route->src_gateway = xbt_strdup(gw_src);
211 e_route->dst_gateway = xbt_strdup(gw_dst);
212 // xbt_assert1(generic_autonomous_system_exist(current_routing,src),"the \"%s\" autonomous system does not exist",src);
213 // xbt_assert1(generic_autonomous_system_exist(current_routing,dst),"the \"%s\" autonomous system does not exist",dst);
214 // xbt_assert1(generic_processing_units_exist(current_routing,gw_src),"the \"%s\" processing units gateway does not exist",gw_src);
215 // xbt_assert1(generic_processing_units_exist(current_routing,gw_dst),"the \"%s\" processing units gateway does not exist",gw_dst);
216 xbt_assert1(current_routing->set_ASroute,"no defined method \"set_ASroute\" in \"%s\"",current_routing->name);
217 (*(current_routing->set_ASroute))(current_routing,src,dst,e_route);
226 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
228 static void parse_E_bypassRoute_store_route(void) {
229 route_extended_t e_route = xbt_new0(s_route_extended_t,1);
230 e_route->generic_route.link_list = link_list;
231 e_route->src_gateway = xbt_strdup(gw_src);
232 e_route->dst_gateway = xbt_strdup(gw_dst);
233 // xbt_assert1(generic_autonomous_system_exist(current_routing,src),"the \"%s\" autonomous system does not exist",src);
234 // xbt_assert1(generic_autonomous_system_exist(current_routing,dst),"the \"%s\" autonomous system does not exist",dst);
235 // xbt_assert1(generic_processing_units_exist(current_routing,gw_src),"the \"%s\" processing units gateway does not exist",gw_src);
236 // xbt_assert1(generic_processing_units_exist(current_routing,gw_dst),"the \"%s\" processing units gateway does not exist",gw_dst);
237 xbt_assert1(current_routing->set_bypassroute,"no defined method \"set_bypassroute\" in \"%s\"",current_routing->name);
238 (*(current_routing->set_bypassroute))(current_routing,src,dst,e_route);
247 * \brief Make a new routing component
249 * Detect the routing model type of the routing component, make the new structure and
250 * set the parsing functions to allows parsing the part of the routing tree
252 static void parse_S_AS(void) {
253 routing_component_t new_routing;
254 model_type_t model = NULL;
255 char* wanted = A_surfxml_AS_routing;
257 /* seach the routing model */
258 for (cpt=0;routing_models[cpt].name;cpt++)
259 if (!strcmp(wanted,routing_models[cpt].name))
260 model = &routing_models[cpt];
261 /* if its not exist, error */
262 if( model == NULL ) {
263 fprintf(stderr,"Routing model %s not found. Existing models:\n",wanted);
264 for (cpt=0;routing_models[cpt].name;cpt++)
265 if (!strcmp(wanted,routing_models[cpt].name))
266 fprintf(stderr," %s: %s\n",routing_models[cpt].name,routing_models[cpt].desc);
270 /* make a new routing component */
271 new_routing = (routing_component_t)(*(model->create))();
272 new_routing->routing = model;
273 new_routing->hierarchy = SURF_ROUTING_NULL;
274 new_routing->name = xbt_strdup(A_surfxml_AS_id);
275 new_routing->routing_sons = xbt_dict_new();
276 //INFO2("Routing %s for AS %s",A_surfxml_AS_routing,A_surfxml_AS_id);
278 if( current_routing == NULL && global_routing->root == NULL ){
280 /* it is the first one */
281 new_routing->routing_father = NULL;
282 global_routing->root = new_routing;
284 } else if( current_routing != NULL && global_routing->root != NULL ) {
286 xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,A_surfxml_AS_id),
287 "The AS \"%s\" already exist",A_surfxml_AS_id);
288 /* it is a part of the tree */
289 new_routing->routing_father = current_routing;
290 /* set the father behavior */
291 if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
292 /* add to the sons dictionary */
293 xbt_dict_set(current_routing->routing_sons,A_surfxml_AS_id,(void*)new_routing,NULL);
294 /* add to the father element list */
295 (*(current_routing->set_autonomous_system))(current_routing,A_surfxml_AS_id);
296 /* unload the prev parse rules */
297 (*(current_routing->routing->unload))();
300 THROW0(arg_error,0,"All defined components must be belong to a AS");
302 /* set the new parse rules */
303 (*(new_routing->routing->load))();
304 /* set the new current component of the tree */
305 current_routing = new_routing;
309 * \brief Finish the creation of a new routing component
311 * When you finish to read the routing component, other structures must be created.
312 * the "end" method allow to do that for any routing model type
314 static void parse_E_AS(void) {
316 if( current_routing == NULL ) {
317 THROW1(arg_error,0,"Close AS(%s), that never open",A_surfxml_AS_id);
319 xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,current_routing->name),
320 "The AS \"%s\" already exist",current_routing->name);
321 xbt_dict_set(global_routing->where_network_elements,current_routing->name,current_routing->routing_father,NULL);
322 (*(current_routing->routing->unload))();
323 (*(current_routing->routing->end))();
324 current_routing = current_routing->routing_father;
325 if( current_routing != NULL )
326 (*(current_routing->routing->load))();
330 /* Aux Business methods */
333 * \brief Get the AS father and the first elements of the chain
335 * \param src the source host name
336 * \param dst the destination host name
338 * Get the common father of the to processing units, and the first different
339 * father in the chain
341 static xbt_dynar_t elements_father(const char* src,const char* dst) {
343 xbt_assert0(src&&dst,"bad parameters for \"elements_father\" method");
345 xbt_dynar_t result = xbt_dynar_new(sizeof(char*), NULL);
347 routing_component_t src_as, dst_as;
348 int index_src, index_dst, index_father_src, index_father_dst;
349 xbt_dynar_t path_src = NULL;
350 xbt_dynar_t path_dst = NULL;
351 routing_component_t current = NULL;
352 routing_component_t* current_src = NULL;
353 routing_component_t* current_dst = NULL;
354 routing_component_t* father = NULL;
356 /* (1) find the as where the src and dst are located */
357 src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
358 dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
359 xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst);
361 /* (2) find the path to the root routing component */
362 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
364 while( current != NULL ) {
365 xbt_dynar_push(path_src,¤t);
366 current = current->routing_father;
368 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
370 while( current != NULL ) {
371 xbt_dynar_push(path_dst,¤t);
372 current = current->routing_father;
375 /* (3) find the common father */
376 index_src = (path_src->used)-1;
377 index_dst = (path_dst->used)-1;
378 current_src = xbt_dynar_get_ptr(path_src,index_src);
379 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
380 while( index_src >= 0 && index_dst >= 0 && *current_src == *current_dst ) {
381 current_src = xbt_dynar_get_ptr(path_src,index_src);
382 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
388 current_src = xbt_dynar_get_ptr(path_src,index_src);
389 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
391 /* (4) they are not in the same routing component, make the path */
392 index_father_src = index_src+1;
393 index_father_dst = index_dst+1;
395 if(*current_src==*current_dst)
396 father = current_src;
398 father = xbt_dynar_get_ptr(path_src,index_father_src);
400 /* (5) result generation */
401 xbt_dynar_push(result,father); /* first same the father of src and dst */
402 xbt_dynar_push(result,current_src); /* second the first different father of src */
403 xbt_dynar_push(result,current_dst); /* three the first different father of dst */
405 xbt_dynar_free(&path_src);
406 xbt_dynar_free(&path_dst);
411 /* Global Business methods */
414 * \brief Recursive function for get_route
416 * \param src the source host name
417 * \param dst the destination host name
419 * This fuction is call by "get_route". It allow to walk through the
420 * routing components tree.
422 static route_extended_t _get_route(const char* src,const char* dst) {
427 DEBUG2("Solve route \"%s\" to \"%s\"",src,dst);
429 xbt_assert0(src&&dst,"bad parameters for \"_get_route\" method");
431 route_extended_t e_route, e_route_cnt, e_route_src, e_route_dst;
433 xbt_dynar_t elem_father_list = elements_father(src,dst);
435 routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
436 routing_component_t src_father = xbt_dynar_get_as(elem_father_list, 1, routing_component_t);
437 routing_component_t dst_father = xbt_dynar_get_as(elem_father_list, 2, routing_component_t);
439 e_route = xbt_new0(s_route_extended_t,1);
440 e_route->src_gateway = NULL;
441 e_route->dst_gateway = NULL;
442 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
444 if(src_father==dst_father) { /* SURF_ROUTING_BASE */
446 if( strcmp(src,dst) ){
447 e_route_cnt = (*(common_father->get_route))(common_father,src,dst);
448 xbt_assert2(e_route_cnt,"no route between \"%s\" and \"%s\"",src,dst);
449 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
450 xbt_dynar_push(e_route->generic_route.link_list,&link);
452 generic_free_extended_route(e_route_cnt);
455 } else { /* SURF_ROUTING_RECURSIVE */
457 route_extended_t e_route_bypass = NULL;
459 if(common_father->get_bypass_route)
460 e_route_bypass = (*(common_father->get_bypass_route))(common_father,src,dst);
463 e_route_cnt = e_route_bypass;
465 e_route_cnt = (*(common_father->get_route))(common_father,src_father->name,dst_father->name);
467 xbt_assert2(e_route_cnt,"no route between \"%s\" and \"%s\"",src_father->name,dst_father->name);
469 xbt_assert2( (e_route_cnt->src_gateway==NULL) == (e_route_cnt->dst_gateway==NULL) ,
470 "bad gateway for route between \"%s\" and \"%s\"",src,dst);
472 if( src != e_route_cnt->src_gateway ) {
473 e_route_src = _get_route(src,e_route_cnt->src_gateway);
474 xbt_assert2(e_route_src,"no route between \"%s\" and \"%s\"",src,e_route_cnt->src_gateway);
475 xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) {
476 xbt_dynar_push(e_route->generic_route.link_list,&link);
480 xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) {
481 xbt_dynar_push(e_route->generic_route.link_list,&link);
484 if( e_route_cnt->dst_gateway != dst ) {
485 e_route_dst = _get_route(e_route_cnt->dst_gateway,dst);
486 xbt_assert2(e_route_dst,"no route between \"%s\" and \"%s\"",e_route_cnt->dst_gateway,dst);
487 xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) {
488 xbt_dynar_push(e_route->generic_route.link_list,&link);
492 e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway);
493 e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway);
495 generic_free_extended_route(e_route_src);
496 generic_free_extended_route(e_route_cnt);
497 generic_free_extended_route(e_route_dst);
500 xbt_dynar_free(&elem_father_list);
506 * \brief Generic method: find a route between hosts
508 * \param src the source host name
509 * \param dst the destination host name
511 * walk through the routing components tree and find a route between hosts
512 * by calling the differents "get_route" functions in each routing component
514 static xbt_dynar_t get_route(const char* src,const char* dst) {
516 route_extended_t e_route;
517 xbt_dynar_t elem_father_list = elements_father(src,dst);
518 routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t);
521 e_route = _get_route(src,dst);
523 e_route = (*(common_father->get_route))(common_father,src,dst);
525 xbt_assert2(e_route,"no route between \"%s\" and \"%s\"",src,dst);
527 if(global_routing->last_route) xbt_dynar_free( &(global_routing->last_route) );
528 global_routing->last_route = e_route->generic_route.link_list;
530 if(e_route->src_gateway) xbt_free(e_route->src_gateway);
531 if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
534 xbt_dynar_free(&elem_father_list);
536 if( xbt_dynar_length(global_routing->last_route)==0 )
539 return global_routing->last_route;
543 * \brief Recursive function for finalize
545 * \param rc the source host name
547 * This fuction is call by "finalize". It allow to finalize the
548 * AS or routing components. It delete all the structures.
550 static void _finalize(routing_component_t rc) {
552 xbt_dict_cursor_t cursor = NULL;
554 routing_component_t elem;
555 xbt_dict_foreach(rc->routing_sons, cursor, key, elem) {
558 xbt_dict_t tmp_sons = rc->routing_sons;
559 char* tmp_name = rc->name;
560 xbt_dict_free(&tmp_sons);
562 xbt_assert1(rc->finalize,"no defined method \"finalize\" in \"%s\"",current_routing->name);
563 (*(rc->finalize))(rc);
568 * \brief Generic method: delete all the routing structures
570 * walk through the routing components tree and delete the structures
571 * by calling the differents "finalize" functions in each routing component
573 static void finalize(void) {
574 /* delete recursibly all the tree */
575 _finalize(global_routing->root);
576 /* delete "where" dict */
577 xbt_dict_free(&(global_routing->where_network_elements));
578 /* delete last_route */
579 xbt_dynar_free(&(global_routing->last_route));
580 /* delete global routing structure */
581 xbt_free(global_routing);
585 * \brief Generic method: create the global routing schema
587 * Make a global routing structure and set all the parsing functions.
589 void routing_model_create(size_t size_of_links, void* loopback) {
591 /* config the uniq global routing */
592 global_routing = xbt_new0(s_routing_global_t,1);
593 global_routing->where_network_elements = xbt_dict_new();
594 global_routing->root = NULL;
595 global_routing->get_route = get_route;
596 global_routing->finalize = finalize;
597 global_routing->loopback = loopback;
598 global_routing->size_of_link = size_of_links;
599 global_routing->last_route = xbt_dynar_new(size_of_links, NULL);
601 /* no current routing at moment */
602 current_routing = NULL;
604 /* parse generic elements */
605 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host);
606 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
608 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints);
609 surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints);
610 surfxml_add_callback(STag_surfxml_bypassRoute_cb_list, &parse_S_bypassRoute_new_and_endpoints);
612 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_E_link_c_ctn_new_elem);
614 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route);
615 surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route);
616 surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list, &parse_E_bypassRoute_store_route);
618 surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS);
619 surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS);
621 surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster);
625 /* ************************************************************************** */
626 /* *************************** FULL ROUTING ********************************* */
628 #define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
630 /* Routing model structure */
633 s_routing_component_t generic_routing;
634 xbt_dict_t parse_routes; /* store data during the parse process */
635 xbt_dict_t to_index; /* char* -> network_element_t */
636 xbt_dict_t bypassRoutes;
637 route_extended_t *routing_table;
638 } s_routing_component_full_t,*routing_component_full_t;
640 /* Business methods */
642 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
643 xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
646 routing_component_full_t routing = (routing_component_full_t)rc;
647 int table_size = xbt_dict_length(routing->to_index);
649 generic_src_dst_check(rc,src,dst);
650 int *src_id = xbt_dict_get_or_null(routing->to_index,src);
651 int *dst_id = xbt_dict_get_or_null(routing->to_index,dst);
652 xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst);
654 route_extended_t e_route = NULL;
655 route_extended_t new_e_route = NULL;
659 e_route = TO_ROUTE_FULL(*src_id,*dst_id);
662 new_e_route = xbt_new0(s_route_extended_t,1);
663 new_e_route->src_gateway = xbt_strdup(e_route->src_gateway);
664 new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway);
665 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
666 xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) {
667 xbt_dynar_push(new_e_route->generic_route.link_list,&link);
673 static void full_finalize(routing_component_t rc) {
674 routing_component_full_t routing = (routing_component_full_t)rc;
675 int table_size = xbt_dict_length(routing->to_index);
678 /* Delete routing table */
679 for (i=0;i<table_size;i++)
680 for (j=0;j<table_size;j++)
681 generic_free_extended_route(TO_ROUTE_FULL(i,j));
682 xbt_free(routing->routing_table);
683 /* Delete bypass dict */
684 xbt_dict_free(&routing->bypassRoutes);
685 /* Delete index dict */
686 xbt_dict_free(&(routing->to_index));
687 /* Delete structure */
692 /* Creation routing model functions */
694 static void* model_full_create(void) {
695 routing_component_full_t new_component = xbt_new0(s_routing_component_full_t,1);
696 new_component->generic_routing.set_processing_unit = generic_set_processing_unit;
697 new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system;
698 new_component->generic_routing.set_route = generic_set_route;
699 new_component->generic_routing.set_ASroute = generic_set_ASroute;
700 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
701 new_component->generic_routing.get_route = full_get_route;
702 new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
703 new_component->generic_routing.finalize = full_finalize;
704 new_component->to_index = xbt_dict_new();
705 new_component->bypassRoutes = xbt_dict_new();
706 new_component->parse_routes = xbt_dict_new();
707 return new_component;
710 static void model_full_load(void) {
711 /* use "surfxml_add_callback" to add a parse function call */
714 static void model_full_unload(void) {
715 /* use "surfxml_del_callback" to remove a parse function call */
718 static void model_full_end(void) {
721 const char* sep = "#";
725 route_extended_t e_route;
728 xbt_dict_cursor_t cursor = NULL;
729 xbt_dynar_t keys = NULL;
732 routing_component_full_t routing = ((routing_component_full_t)current_routing);
733 int table_size = xbt_dict_length(routing->to_index);
735 /* Create the routing table */
736 routing->routing_table = xbt_new0(route_extended_t, table_size * table_size);
738 /* Put the routes in position */
739 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
740 keys = xbt_str_split_str(key, sep);
741 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
742 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
743 TO_ROUTE_FULL(src_id,dst_id) = generic_new_extended_route(current_routing->hierarchy,data,1);
744 xbt_dynar_free(&keys);
747 /* delete the parse table */
748 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
749 route = (route_t)data;
750 xbt_dynar_free(&(route->link_list));
754 /* delete parse dict */
755 xbt_dict_free(&(routing->parse_routes));
757 /* Add the loopback if needed */
758 if(current_routing->hierarchy == SURF_ROUTING_BASE) {
759 for (i = 0; i < table_size; i++) {
760 e_route = TO_ROUTE_FULL(i, i);
762 e_route = xbt_new0(s_route_extended_t,1);
763 e_route->src_gateway = NULL;
764 e_route->dst_gateway = NULL;
765 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
766 xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
767 TO_ROUTE_FULL(i, i) = e_route;
772 /* Shrink the dynar routes (save unused slots) */
773 for (i=0;i<table_size;i++)
774 for (j=0;j<table_size;j++)
775 if(TO_ROUTE_FULL(i,j))
776 xbt_dynar_shrink(TO_ROUTE_FULL(i,j)->generic_route.link_list,0);
779 /* ************************************************************************** */
780 /* *************************** FLOYD ROUTING ******************************** */
782 #define TO_FLOYD_COST(i,j) cost_table[(i)+(j)*table_size]
783 #define TO_FLOYD_PRED(i,j) (routing->predecessor_table)[(i)+(j)*table_size]
784 #define TO_FLOYD_LINK(i,j) (routing->link_table)[(i)+(j)*table_size]
786 /* Routing model structure */
789 s_routing_component_t generic_routing;
790 /* vars for calculate the floyd algorith. */
791 int *predecessor_table;
792 route_extended_t *link_table; /* char* -> int* */
794 xbt_dict_t bypassRoutes;
795 /* store data during the parse process */
796 xbt_dict_t parse_routes;
797 } s_routing_component_floyd_t,*routing_component_floyd_t;
799 /* Business methods */
801 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
802 xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
805 routing_component_floyd_t routing = (routing_component_floyd_t) rc;
806 int table_size = xbt_dict_length(routing->to_index);
808 generic_src_dst_check(rc,src,dst);
809 int *src_id = xbt_dict_get_or_null(routing->to_index,src);
810 int *dst_id = xbt_dict_get_or_null(routing->to_index,dst);
811 xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst);
813 /* create a result route */
814 route_extended_t new_e_route = xbt_new0(s_route_extended_t,1);
815 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
816 new_e_route->src_gateway = NULL;
817 new_e_route->dst_gateway = NULL;
822 char *gw_src,*gw_dst, *prev_gw_src,*prev_gw_dst, *first_gw;
829 pred = TO_FLOYD_PRED(*src_id, pred);
830 if(pred == -1) /* if no pred in route -> no route to host */
832 xbt_assert2(TO_FLOYD_LINK(pred,prev_pred),"Invalid link for the route between \"%s\" or \"%s\"", src, dst);
834 prev_gw_src = gw_src;
835 prev_gw_dst = gw_dst;
837 route_extended_t e_route = TO_FLOYD_LINK(pred,prev_pred);
838 gw_src = e_route->src_gateway;
839 gw_dst = e_route->dst_gateway;
841 if(first) first_gw = gw_dst;
843 if(rc->hierarchy == SURF_ROUTING_RECURSIVE && !first && strcmp(gw_dst,prev_gw_src)) {
844 xbt_dynar_t e_route_as_to_as = (*(global_routing->get_route))(gw_dst,prev_gw_src);
845 xbt_assert2(e_route_as_to_as,"no route between \"%s\" and \"%s\"",gw_dst,prev_gw_src);
846 links = e_route_as_to_as;
848 xbt_dynar_foreach(links, cpt, link) {
849 xbt_dynar_insert_at(new_e_route->generic_route.link_list,pos,&link);
854 links = e_route->generic_route.link_list;
855 xbt_dynar_foreach(links, cpt, link) {
856 xbt_dynar_unshift(new_e_route->generic_route.link_list,&link);
860 } while(pred != *src_id);
861 xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")", *src_id, *dst_id,src,dst);
863 if(rc->hierarchy == SURF_ROUTING_RECURSIVE) {
864 new_e_route->src_gateway = xbt_strdup(gw_src);
865 new_e_route->dst_gateway = xbt_strdup(first_gw);
871 static void floyd_finalize(routing_component_t rc) {
872 routing_component_floyd_t routing = (routing_component_floyd_t)rc;
875 table_size = xbt_dict_length(routing->to_index);
876 /* Delete link_table */
877 for (i=0;i<table_size;i++)
878 for (j=0;j<table_size;j++)
879 generic_free_extended_route(TO_FLOYD_LINK(i,j));
880 xbt_free(routing->link_table);
881 /* Delete bypass dict */
882 xbt_dict_free(&routing->bypassRoutes);
883 /* Delete index dict */
884 xbt_dict_free(&(routing->to_index));
885 /* Delete dictionary index dict, predecessor and links table */
886 xbt_free(routing->predecessor_table);
887 /* Delete structure */
892 static void* model_floyd_create(void) {
893 routing_component_floyd_t new_component = xbt_new0(s_routing_component_floyd_t,1);
894 new_component->generic_routing.set_processing_unit = generic_set_processing_unit;
895 new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system;
896 new_component->generic_routing.set_route = generic_set_route;
897 new_component->generic_routing.set_ASroute = generic_set_ASroute;
898 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
899 new_component->generic_routing.get_route = floyd_get_route;
900 new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
901 new_component->generic_routing.finalize = floyd_finalize;
902 new_component->to_index = xbt_dict_new();
903 new_component->bypassRoutes = xbt_dict_new();
904 new_component->parse_routes = xbt_dict_new();
905 return new_component;
908 static void model_floyd_load(void) {
909 /* use "surfxml_add_callback" to add a parse function call */
912 static void model_floyd_unload(void) {
913 /* use "surfxml_del_callback" to remove a parse function call */
916 static void model_floyd_end(void) {
918 routing_component_floyd_t routing = ((routing_component_floyd_t)current_routing);
919 xbt_dict_cursor_t cursor = NULL;
921 char *key,*data, *end;
922 const char *sep = "#";
925 unsigned int i,j,a,b,c;
927 /* set the size of inicial table */
928 int table_size = xbt_dict_length(routing->to_index);
930 /* Create Cost, Predecessor and Link tables */
931 cost_table = xbt_new0(double, table_size*table_size); /* link cost from host to host */
932 routing->predecessor_table = xbt_new0(int, table_size*table_size); /* predecessor host numbers */
933 routing->link_table = xbt_new0(route_extended_t, table_size*table_size); /* actual link between src and dst */
935 /* Initialize costs and predecessors*/
936 for(i = 0; i<table_size;i++)
937 for(j = 0; j<table_size;j++) {
938 TO_FLOYD_COST(i,j) = DBL_MAX;
939 TO_FLOYD_PRED(i,j) = -1;
940 TO_FLOYD_LINK(i,j) = NULL; /* fixed, missing in the previous version */
943 /* Put the routes in position */
944 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
945 keys = xbt_str_split_str(key, sep);
946 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
947 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
948 TO_FLOYD_LINK(src_id,dst_id) = generic_new_extended_route(current_routing->hierarchy,data,0);
949 TO_FLOYD_PRED(src_id,dst_id) = src_id;
951 TO_FLOYD_COST(src_id,dst_id) = ((TO_FLOYD_LINK(src_id,dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */
952 xbt_dynar_free(&keys);
955 /* Add the loopback if needed */
956 if(current_routing->hierarchy == SURF_ROUTING_BASE) {
957 for (i = 0; i < table_size; i++) {
958 route_extended_t e_route = TO_FLOYD_LINK(i, i);
960 e_route = xbt_new0(s_route_extended_t,1);
961 e_route->src_gateway = NULL;
962 e_route->dst_gateway = NULL;
963 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
964 xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
965 TO_FLOYD_LINK(i,i) = e_route;
966 TO_FLOYD_PRED(i,i) = i;
967 TO_FLOYD_COST(i,i) = 1;
971 /* Calculate path costs */
972 for(c=0;c<table_size;c++) {
973 for(a=0;a<table_size;a++) {
974 for(b=0;b<table_size;b++) {
975 if(TO_FLOYD_COST(a,c) < DBL_MAX && TO_FLOYD_COST(c,b) < DBL_MAX) {
976 if(TO_FLOYD_COST(a,b) == DBL_MAX ||
977 (TO_FLOYD_COST(a,c)+TO_FLOYD_COST(c,b) < TO_FLOYD_COST(a,b))) {
978 TO_FLOYD_COST(a,b) = TO_FLOYD_COST(a,c)+TO_FLOYD_COST(c,b);
979 TO_FLOYD_PRED(a,b) = TO_FLOYD_PRED(c,b);
986 /* delete the parse table */
987 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
988 route_t route = (route_t)data;
989 xbt_dynar_free(&(route->link_list));
993 /* delete parse dict */
994 xbt_dict_free(&(routing->parse_routes));
997 xbt_free(cost_table);
1000 /* ************************************************************************** */
1001 /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
1004 s_routing_component_t generic_routing;
1005 xbt_dict_t to_index;
1006 xbt_dict_t bypassRoutes;
1007 xbt_graph_t route_graph; /* xbt_graph */
1008 xbt_dict_t graph_node_map; /* map */
1009 xbt_dict_t route_cache; /* use in cache mode */
1011 xbt_dict_t parse_routes;
1012 } s_routing_component_dijkstra_t,*routing_component_dijkstra_t;
1015 typedef struct graph_node_data {
1017 int graph_id; /* used for caching internal graph id's */
1018 } s_graph_node_data_t, * graph_node_data_t;
1020 typedef struct graph_node_map_element {
1022 } s_graph_node_map_element_t, * graph_node_map_element_t;
1024 typedef struct route_cache_element {
1027 } s_route_cache_element_t, * route_cache_element_t;
1029 /* Free functions */
1031 static void route_cache_elem_free(void *e) {
1032 route_cache_element_t elm=(route_cache_element_t)e;
1034 xbt_free(elm->pred_arr);
1039 static void graph_node_map_elem_free(void *e) {
1040 graph_node_map_element_t elm = (graph_node_map_element_t)e;
1046 static void graph_edge_data_free(void *e) {
1047 route_extended_t e_route = (route_extended_t)e;
1049 xbt_dynar_free(&(e_route->generic_route.link_list));
1050 if(e_route->src_gateway) xbt_free(e_route->src_gateway);
1051 if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
1056 /* Utility functions */
1058 static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc, int id, int graph_id) {
1059 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1060 xbt_node_t node = NULL;
1061 graph_node_data_t data = NULL;
1062 graph_node_map_element_t elm = NULL;
1064 data = xbt_new0(struct graph_node_data, 1);
1066 data->graph_id = graph_id;
1067 node = xbt_graph_new_node(routing->route_graph, data);
1069 elm = xbt_new0(struct graph_node_map_element, 1);
1071 xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free);
1076 static graph_node_map_element_t graph_node_map_search(routing_component_dijkstra_t rc, int id) {
1077 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1078 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));
1084 static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id, int dst_id, route_extended_t e_route ) {
1085 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1087 xbt_node_t src = NULL;
1088 xbt_node_t dst = NULL;
1089 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));
1090 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));
1093 src = src_elm->node;
1096 dst = dst_elm->node;
1098 /* add nodes if they don't exist in the graph */
1099 if(src_id == dst_id && src == NULL && dst == NULL) {
1100 src = route_graph_new_node(rc,src_id, -1);
1104 src = route_graph_new_node(rc,src_id, -1);
1107 dst = route_graph_new_node(rc,dst_id, -1);
1111 /* add link as edge to graph */
1112 xbt_graph_new_edge(routing->route_graph, src, dst, e_route);
1115 static void add_loopback_dijkstra(routing_component_dijkstra_t rc) {
1116 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1118 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1120 xbt_node_t node = NULL;
1121 unsigned int cursor2;
1122 xbt_dynar_foreach(nodes, cursor2, node) {
1123 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node);
1124 xbt_edge_t edge = NULL;
1125 unsigned int cursor;
1128 xbt_dynar_foreach(out_edges, cursor, edge) {
1129 xbt_node_t other_node = xbt_graph_edge_get_target(edge);
1130 if(other_node == node) {
1137 route_extended_t e_route = xbt_new0(s_route_extended_t,1);
1138 e_route->src_gateway = NULL;
1139 e_route->dst_gateway = NULL;
1140 e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
1141 xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback);
1142 xbt_graph_new_edge(routing->route_graph, node, node, e_route);
1147 /* Business methods */
1149 static route_extended_t dijkstra_get_route(routing_component_t rc, const char* src,const char* dst) {
1150 xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
1152 /* set utils vars */
1153 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1155 generic_src_dst_check(rc,src,dst);
1156 int *src_id = xbt_dict_get_or_null(routing->to_index,src);
1157 int *dst_id = xbt_dict_get_or_null(routing->to_index,dst);
1158 xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst);
1160 /* create a result route */
1161 route_extended_t new_e_route = xbt_new0(s_route_extended_t,1);
1162 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
1163 new_e_route->src_gateway = NULL;
1164 new_e_route->dst_gateway = NULL;
1166 int *pred_arr = NULL;
1167 int src_node_id = 0;
1168 int dst_node_id = 0;
1169 int * nodeid = NULL;
1171 route_extended_t e_route;
1175 xbt_dynar_t links = NULL;
1176 route_cache_element_t elm = NULL;
1177 xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph);
1179 /* Use the graph_node id mapping set to quickly find the nodes */
1180 graph_node_map_element_t src_elm = graph_node_map_search(routing,*src_id);
1181 graph_node_map_element_t dst_elm = graph_node_map_search(routing,*dst_id);
1182 xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", *src_id, *dst_id);
1183 src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
1184 dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
1186 /* if the src and dst are the same */ /* fixed, missing in the previous version */
1187 if( src_node_id == dst_node_id ) {
1189 xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
1190 xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
1191 xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v);
1193 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, *dst_id);
1195 e_route = (route_extended_t)xbt_graph_edge_get_data(edge);
1197 links = e_route->generic_route.link_list;
1198 xbt_dynar_foreach(links, cpt, link) {
1199 xbt_dynar_unshift(new_e_route->generic_route.link_list,&link);
1205 if(routing->cached) {
1206 /*check if there is a cached predecessor list avail */
1207 elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int));
1210 if(elm) { /* cached mode and cache hit */
1211 pred_arr = elm->pred_arr;
1212 } else { /* not cached mode or cache miss */
1213 double * cost_arr = NULL;
1214 xbt_heap_t pqueue = NULL;
1217 int nr_nodes = xbt_dynar_length(nodes);
1218 cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
1219 pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
1220 pqueue = xbt_heap_new(nr_nodes, xbt_free);
1223 cost_arr[src_node_id] = 0.0;
1225 for(i = 0; i < nr_nodes; i++) {
1226 if(i != src_node_id) {
1227 cost_arr[i] = DBL_MAX;
1232 /* initialize priority queue */
1233 nodeid = xbt_new0(int, 1);
1235 xbt_heap_push(pqueue, nodeid, cost_arr[i]);
1239 /* apply dijkstra using the indexes from the graph's node array */
1240 while(xbt_heap_size(pqueue) > 0) {
1241 int * v_id = xbt_heap_pop(pqueue);
1242 xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
1243 xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
1244 xbt_edge_t edge = NULL;
1245 unsigned int cursor;
1247 xbt_dynar_foreach(out_edges, cursor, edge) {
1248 xbt_node_t u_node = xbt_graph_edge_get_target(edge);
1249 graph_node_data_t data = xbt_graph_node_get_data(u_node);
1250 int u_id = data->graph_id;
1251 route_extended_t tmp_e_route = (route_extended_t)xbt_graph_edge_get_data(edge);
1252 int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */
1254 if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
1255 pred_arr[u_id] = *v_id;
1256 cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
1257 nodeid = xbt_new0(int, 1);
1259 xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
1263 /* free item popped from pqueue */
1268 xbt_heap_free(pqueue);
1271 /* compose route path with links */
1272 char *gw_src,*gw_dst, *prev_gw_src,*prev_gw_dst, *first_gw;
1274 for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
1275 xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
1276 xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
1277 xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v);
1279 xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, *dst_id);
1281 prev_gw_src = gw_src;
1282 prev_gw_dst = gw_dst;
1284 e_route = (route_extended_t)xbt_graph_edge_get_data(edge);
1285 gw_src = e_route->src_gateway;
1286 gw_dst = e_route->dst_gateway;
1288 if(v==dst_node_id) first_gw = gw_dst;
1290 if(rc->hierarchy == SURF_ROUTING_RECURSIVE && v!=dst_node_id && strcmp(gw_dst,prev_gw_src)) {
1291 xbt_dynar_t e_route_as_to_as = (*(global_routing->get_route))(gw_dst,prev_gw_src);
1292 xbt_assert2(e_route_as_to_as,"no route between \"%s\" and \"%s\"",gw_dst,prev_gw_src);
1293 links = e_route_as_to_as;
1295 xbt_dynar_foreach(links, cpt, link) {
1296 xbt_dynar_insert_at(new_e_route->generic_route.link_list,pos,&link);
1301 links = e_route->generic_route.link_list;
1302 xbt_dynar_foreach(links, cpt, link) {
1303 xbt_dynar_unshift(new_e_route->generic_route.link_list,&link);
1308 if(rc->hierarchy == SURF_ROUTING_RECURSIVE) {
1309 new_e_route->src_gateway = xbt_strdup(gw_src);
1310 new_e_route->dst_gateway = xbt_strdup(first_gw);
1313 if(routing->cached && elm == NULL) {
1314 /* add to predecessor list of the current src-host to cache */
1315 elm = xbt_new0(struct route_cache_element, 1);
1316 elm->pred_arr = pred_arr;
1318 xbt_dict_set_ext(routing->route_cache, (char*)(&src_id), sizeof(int), (xbt_set_elm_t)elm, &route_cache_elem_free);
1321 if(!routing->cached)
1327 static void dijkstra_finalize(routing_component_t rc) {
1328 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
1331 xbt_graph_free_graph(routing->route_graph, &xbt_free, &graph_edge_data_free, &xbt_free);
1332 xbt_dict_free(&routing->graph_node_map);
1334 xbt_dict_free(&routing->route_cache);
1335 /* Delete bypass dict */
1336 xbt_dict_free(&routing->bypassRoutes);
1337 /* Delete index dict */
1338 xbt_dict_free(&(routing->to_index));
1339 /* Delete structure */
1344 /* Creation routing model functions */
1346 static void* model_dijkstra_both_create(int cached) {
1347 routing_component_dijkstra_t new_component = xbt_new0(s_routing_component_dijkstra_t,1);
1348 new_component->generic_routing.set_processing_unit = generic_set_processing_unit;
1349 new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system;
1350 new_component->generic_routing.set_route = generic_set_route;
1351 new_component->generic_routing.set_ASroute = generic_set_ASroute;
1352 new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
1353 new_component->generic_routing.get_route = dijkstra_get_route;
1354 new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
1355 new_component->generic_routing.finalize = dijkstra_finalize;
1356 new_component->cached = cached;
1357 new_component->to_index = xbt_dict_new();
1358 new_component->bypassRoutes = xbt_dict_new();
1359 new_component->parse_routes = xbt_dict_new();
1360 return new_component;
1363 static void* model_dijkstra_create(void) {
1364 return model_dijkstra_both_create(0);
1367 static void* model_dijkstracache_create(void) {
1368 return model_dijkstra_both_create(1);
1371 static void model_dijkstra_both_load(void) {
1372 /* use "surfxml_add_callback" to add a parse function call */
1375 static void model_dijkstra_both_unload(void) {
1376 /* use "surfxml_del_callback" to remove a parse function call */
1379 static void model_dijkstra_both_end(void) {
1380 routing_component_dijkstra_t routing = (routing_component_dijkstra_t) current_routing;
1381 xbt_dict_cursor_t cursor = NULL;
1382 char *key, *data, *end;
1383 const char *sep = "#";
1385 xbt_node_t node = NULL;
1386 unsigned int cursor2;
1387 xbt_dynar_t nodes = NULL;
1391 /* Create the topology graph */
1392 routing->route_graph = xbt_graph_new_graph(1, NULL);
1393 routing->graph_node_map = xbt_dict_new();
1396 routing->route_cache = xbt_dict_new();
1398 /* Put the routes in position */
1399 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
1400 keys = xbt_str_split_str(key, sep);
1401 src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10);
1402 dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10);
1403 route_extended_t e_route = generic_new_extended_route(current_routing->hierarchy,data,0);
1404 route_new_dijkstra(routing,src_id,dst_id,e_route);
1405 xbt_dynar_free(&keys);
1408 /* delete the parse table */
1409 xbt_dict_foreach(routing->parse_routes, cursor, key, data) {
1410 route = (route_t)data;
1411 xbt_dynar_free(&(route->link_list));
1415 /* delete parse dict */
1416 xbt_dict_free(&(routing->parse_routes));
1418 /* Add the loopback if needed */
1419 if(current_routing->hierarchy == SURF_ROUTING_BASE)
1420 add_loopback_dijkstra(routing);
1422 /* initialize graph indexes in nodes after graph has been built */
1423 nodes = xbt_graph_get_nodes(routing->route_graph);
1425 xbt_dynar_foreach(nodes, cursor2, node) {
1426 graph_node_data_t data = xbt_graph_node_get_data(node);
1427 data->graph_id = cursor2;
1432 /* ************************************************** */
1433 /* ************** RULE-BASED ROUTING **************** */
1435 /* Routing model structure */
1438 s_routing_component_t generic_routing;
1439 xbt_dict_t dict_processing_units;
1440 xbt_dict_t dict_autonomous_systems;
1441 xbt_dynar_t list_route;
1442 xbt_dynar_t list_ASroute;
1443 } s_routing_component_rulebased_t,*routing_component_rulebased_t;
1445 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
1446 typedef struct s_rule_route_extended s_rule_route_extended_t, *rule_route_extended_t;
1448 struct s_rule_route {
1449 xbt_dynar_t re_str_link; // dynar of char*
1454 struct s_rule_route_extended {
1455 s_rule_route_t generic_rule_route;
1456 char* re_src_gateway;
1457 char* re_dst_gateway;
1460 static void rule_route_free(void *e) {
1461 rule_route_t* elem = (rule_route_t*)(e);
1463 xbt_dynar_free(&(*elem)->re_str_link);
1464 pcre_free((*elem)->re_src);
1465 pcre_free((*elem)->re_dst);
1471 static void rule_route_extended_free(void *e) {
1472 rule_route_extended_t* elem = (rule_route_extended_t*)e;
1474 xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link);
1475 pcre_free((*elem)->generic_rule_route.re_src);
1476 pcre_free((*elem)->generic_rule_route.re_dst);
1477 xbt_free((*elem)->re_src_gateway);
1478 xbt_free((*elem)->re_dst_gateway);
1483 /* Parse routing model functions */
1485 static void model_rulebased_set_processing_unit(routing_component_t rc, const char* name) {
1486 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1487 xbt_dict_set(routing->dict_processing_units, name, (void*)(-1), NULL);
1490 static void model_rulebased_set_autonomous_system(routing_component_t rc, const char* name) {
1491 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1492 xbt_dict_set(routing->dict_autonomous_systems, name, (void*)(-1), NULL);
1495 static void model_rulebased_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
1496 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1497 rule_route_t ruleroute = xbt_new0(s_rule_route_t,1);
1500 ruleroute->re_src = pcre_compile(src,0,&error,&erroffset,NULL);
1501 xbt_assert3(ruleroute->re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, src, error);
1502 ruleroute->re_dst = pcre_compile(dst,0,&error,&erroffset,NULL);
1503 xbt_assert3(ruleroute->re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, dst, error);
1504 ruleroute->re_str_link = route->link_list;
1505 xbt_dynar_push(routing->list_route,&ruleroute);
1509 static void model_rulebased_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {
1510 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1511 rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t,1);
1514 ruleroute_e->generic_rule_route.re_src = pcre_compile(src,0,&error,&erroffset,NULL);
1515 xbt_assert3(ruleroute_e->generic_rule_route.re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, src, error);
1516 ruleroute_e->generic_rule_route.re_dst = pcre_compile(dst,0,&error,&erroffset,NULL);
1517 xbt_assert3(ruleroute_e->generic_rule_route.re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, dst, error);
1518 ruleroute_e->generic_rule_route.re_str_link = route->generic_route.link_list;
1519 ruleroute_e->re_src_gateway = route->src_gateway;
1520 ruleroute_e->re_dst_gateway = route->dst_gateway;
1521 xbt_dynar_push(routing->list_ASroute,&ruleroute_e);
1522 xbt_free(route->src_gateway);
1523 xbt_free(route->dst_gateway);
1527 static void model_rulebased_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
1528 xbt_die("bypass routing not support for Route-Based model");
1531 #define BUFFER_SIZE 4096 /* result buffer size */
1532 #define OVECCOUNT 30 /* should be a multiple of 3 */
1534 static char* remplace(char* value, const char** src_list, int src_size, const char** dst_list, int dst_size ) {
1536 char result_result[BUFFER_SIZE];
1537 int i_result_buffer;
1538 int value_length = (int)strlen(value);
1542 i_result_buffer = 0;
1544 if( value[i] == '$' ) {
1548 int number_length = 0;
1549 while( '0' <= value[i+number_length] && value[i+number_length] <= '9' ) {
1552 xbt_assert2( number_length!=0, "bad string parameter, no number indication, at offset: %d (\"%s\")",i,value);
1555 number = atoi(value+i);
1557 xbt_assert2(i+2<value_length,"bad string parameter, too few chars, at offset: %d (\"%s\")",i,value);
1559 // solve the indication
1560 const char** param_list;
1562 if( value[i] == 's' && value[i+1] == 'r' && value[i+2] == 'c' ) {
1563 param_list = src_list;
1564 param_size = src_size;
1565 } else if( value[i] == 'd' && value[i+1] == 's' && value[i+2] == 't' ) {
1566 param_list = dst_list;
1567 param_size = dst_size;
1569 xbt_assert2(0,"bad string parameter, support only \"src\" and \"dst\", at offset: %d (\"%s\")",i,value);
1573 xbt_assert4( param_size >= number, "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",i,value,param_size,number);
1575 const char* param = param_list[number];
1576 int size = strlen(param);
1578 for(cp = 0; cp < size; cp++ ) {
1579 result_result[i_result_buffer] = param[cp];
1581 if( i_result_buffer >= BUFFER_SIZE ) break;
1584 result_result[i_result_buffer] = value[i];
1589 } while(i<value_length && i_result_buffer < BUFFER_SIZE);
1591 xbt_assert2( i_result_buffer < BUFFER_SIZE, "solving string \"%s\", small buffer size (%d)",value,BUFFER_SIZE);
1592 result_result[i_result_buffer] = 0;
1593 return xbt_strdup(result_result);
1596 /* Business methods */
1597 static route_extended_t rulebased_get_route(routing_component_t rc, const char* src,const char* dst) {
1598 xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
1600 /* set utils vars */
1601 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1603 int are_processing_units;
1604 xbt_dynar_t rule_list;
1605 if( xbt_dict_get_or_null(routing->dict_processing_units,src) && xbt_dict_get_or_null(routing->dict_processing_units,dst) ) {
1606 are_processing_units = 1;
1607 rule_list = routing->list_route;
1608 } else if( xbt_dict_get_or_null(routing->dict_autonomous_systems,src) && xbt_dict_get_or_null(routing->dict_autonomous_systems,dst) ) {
1609 are_processing_units = 0;
1610 rule_list = routing->list_ASroute;
1612 xbt_assert2(NULL, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst);
1616 int src_length = (int)strlen(src);
1617 int dst_length = (int)strlen(dst);
1619 xbt_dynar_t links_list = xbt_dynar_new(global_routing->size_of_link,NULL);
1621 rule_route_t ruleroute;
1623 int ovector_src[OVECCOUNT];
1624 int ovector_dst[OVECCOUNT];
1625 const char** list_src = NULL;
1626 const char** list_dst = NULL;
1627 xbt_dynar_foreach(rule_list, cpt, ruleroute) {
1628 rc_src = pcre_exec(ruleroute->re_src,NULL,src,src_length,0,0,ovector_src,OVECCOUNT);
1630 rc_dst = pcre_exec(ruleroute->re_dst,NULL,dst,dst_length,0,0,ovector_dst,OVECCOUNT);
1632 xbt_assert1(!pcre_get_substring_list(src,ovector_src,rc_src,&list_src),"error solving substring list for src \"%s\"",src);
1633 xbt_assert1(!pcre_get_substring_list(dst,ovector_dst,rc_dst,&list_dst),"error solving substring list for src \"%s\"",dst);
1635 xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) {
1636 char* new_link_name = remplace(link_name,list_src,rc_src,list_dst,rc_dst);
1637 void* link = xbt_dict_get_or_null(surf_network_model->resource_set, new_link_name);
1639 xbt_dynar_push(links_list,&link);
1641 THROW1(mismatch_error,0,"Link %s not found", new_link_name);
1642 xbt_free(new_link_name);
1646 if( rc_src >= 0 && rc_dst >= 0 ) break;
1649 route_extended_t new_e_route = NULL;
1650 if(rc_src >= 0 && rc_dst >= 0) {
1651 new_e_route = xbt_new0(s_route_extended_t,1);
1652 new_e_route->generic_route.link_list = links_list;
1653 } else if( !strcmp(src,dst) && are_processing_units ) {
1654 new_e_route = xbt_new0(s_route_extended_t,1);
1655 xbt_dynar_push(links_list,&(global_routing->loopback));
1656 new_e_route->generic_route.link_list = links_list;
1658 xbt_dynar_free(&link_list);
1661 if(!are_processing_units && new_e_route)
1663 rule_route_extended_t ruleroute_extended = (rule_route_extended_t)ruleroute;
1664 new_e_route->src_gateway = remplace(ruleroute_extended->re_src_gateway,list_src,rc_src,list_dst,rc_dst);
1665 new_e_route->dst_gateway = remplace(ruleroute_extended->re_dst_gateway,list_src,rc_src,list_dst,rc_dst);
1668 if(list_src) pcre_free_substring_list(list_src);
1669 if(list_dst) pcre_free_substring_list(list_dst);
1674 static route_extended_t rulebased_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {
1678 static void rulebased_finalize(routing_component_t rc) {
1679 routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
1681 xbt_dict_free(&routing->dict_processing_units);
1682 xbt_dict_free(&routing->dict_autonomous_systems);
1683 xbt_dynar_free(&routing->list_route);
1684 xbt_dynar_free(&routing->list_ASroute);
1685 /* Delete structure */
1690 /* Creation routing model functions */
1691 static void* model_rulebased_create(void) {
1692 routing_component_rulebased_t new_component = xbt_new0(s_routing_component_rulebased_t,1);
1693 new_component->generic_routing.set_processing_unit = model_rulebased_set_processing_unit;
1694 new_component->generic_routing.set_autonomous_system = model_rulebased_set_autonomous_system;
1695 new_component->generic_routing.set_route = model_rulebased_set_route;
1696 new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
1697 new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
1698 new_component->generic_routing.get_route = rulebased_get_route;
1699 new_component->generic_routing.get_bypass_route = NULL; //rulebased_get_bypass_route;
1700 new_component->generic_routing.finalize = rulebased_finalize;
1701 /* initialization of internal structures */
1702 new_component->dict_processing_units = xbt_dict_new();
1703 new_component->dict_autonomous_systems = xbt_dict_new();
1704 new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
1705 new_component->list_ASroute = xbt_dynar_new(sizeof(rule_route_extended_t), &rule_route_extended_free);
1706 return new_component;
1709 static void model_rulebased_load(void) {
1710 /* use "surfxml_add_callback" to add a parse function call */
1713 static void model_rulebased_unload(void) {
1714 /* use "surfxml_del_callback" to remove a parse function call */
1717 static void model_rulebased_end(void) {
1720 /* ************************************************************************** */
1721 /* ******************************* NO ROUTING ******************************* */
1723 /* Routing model structure */
1725 s_routing_component_t generic_routing;
1726 } s_routing_component_none_t,*routing_component_none_t;
1728 /* Business methods */
1729 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
1732 static route_extended_t none_get_bypass_route(routing_component_t rc, const char* src,const char* dst){
1735 static void none_finalize(routing_component_t rc) {
1739 static void none_set_processing_unit(routing_component_t rc, const char* name) {}
1740 static void none_set_autonomous_system(routing_component_t rc, const char* name) {}
1742 /* Creation routing model functions */
1743 static void* model_none_create(void) {
1744 routing_component_none_t new_component = xbt_new0(s_routing_component_none_t,1);
1745 new_component->generic_routing.set_processing_unit = none_set_processing_unit;
1746 new_component->generic_routing.set_autonomous_system = none_set_autonomous_system;
1747 new_component->generic_routing.set_route = NULL;
1748 new_component->generic_routing.set_ASroute = NULL;
1749 new_component->generic_routing.set_bypassroute = NULL;
1750 new_component->generic_routing.get_route = none_get_route;
1751 new_component->generic_routing.get_bypass_route = none_get_bypass_route;
1752 new_component->generic_routing.finalize = none_finalize;
1753 return new_component;
1756 static void model_none_load(void) {}
1757 static void model_none_unload(void) {}
1758 static void model_none_end(void) {}
1760 /* ************************************************** */
1761 /* ********** PATERN FOR NEW ROUTING **************** */
1763 /* The minimal configuration of a new routing model need the next functions,
1764 * also you need to set at the start of the file, the new model in the model
1765 * list. Remember keep the null ending of the list.
1767 /*** Routing model structure ***/
1769 // s_routing_component_t generic_routing;
1770 // /* things that your routing model need */
1771 // } s_routing_component_NEW_t,*routing_component_NEW_t;
1773 /*** Parse routing model functions ***/
1774 // static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {}
1775 // static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {}
1776 // static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {}
1777 // static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {}
1778 // static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {}
1780 /*** Business methods ***/
1781 // static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1782 // static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;}
1783 // static void NEW_finalize(routing_component_t rc) { xbt_free(rc);}
1785 /*** Creation routing model functions ***/
1786 // static void* model_NEW_create(void) {
1787 // routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1);
1788 // new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit;
1789 // new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system;
1790 // new_component->generic_routing.set_route = model_NEW_set_route;
1791 // new_component->generic_routing.set_ASroute = model_NEW_set_ASroute;
1792 // new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute;
1793 // new_component->generic_routing.get_route = NEW_get_route;
1794 // new_component->generic_routing.get_bypass_route = NEW_get_bypass_route;
1795 // new_component->generic_routing.finalize = NEW_finalize;
1796 // /* initialization of internal structures */
1797 // return new_component;
1798 // } /* mandatory */
1799 // static void model_NEW_load(void) {} /* mandatory */
1800 // static void model_NEW_unload(void) {} /* mandatory */
1801 // static void model_NEW_end(void) {} /* mandatory */
1803 /* ************************************************************************** */
1804 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
1806 static void generic_set_processing_unit(routing_component_t rc, const char* name) {
1807 DEBUG1("Load process unit \"%s\"",name);
1808 model_type_t modeltype = rc->routing;
1809 int *id = xbt_new0(int,1);
1810 xbt_dict_t _to_index;
1811 if(modeltype==&routing_models[SURF_MODEL_FULL])
1812 _to_index = ((routing_component_full_t)rc)->to_index;
1814 else if(modeltype==&routing_models[SURF_MODEL_FLOYD])
1815 _to_index = ((routing_component_floyd_t)rc)->to_index;
1817 else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1818 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE])
1819 _to_index = ((routing_component_dijkstra_t)rc)->to_index;
1821 else xbt_die("\"generic_set_processing_unit\" not support");
1822 *id = xbt_dict_length(_to_index);
1823 xbt_dict_set(_to_index,name,id,xbt_free);
1826 static void generic_set_autonomous_system(routing_component_t rc, const char* name) {
1827 DEBUG1("Load Autonomous system \"%s\"",name);
1828 model_type_t modeltype = rc->routing;
1829 int *id = xbt_new0(int,1);
1830 xbt_dict_t _to_index;
1831 if(modeltype==&routing_models[SURF_MODEL_FULL])
1832 _to_index = ((routing_component_full_t)rc)->to_index;
1834 else if(modeltype==&routing_models[SURF_MODEL_FLOYD])
1835 _to_index = ((routing_component_floyd_t)rc)->to_index;
1837 else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1838 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE])
1839 _to_index = ((routing_component_dijkstra_t)rc)->to_index;
1841 else xbt_die("\"generic_set_autonomous_system\" not support");
1842 *id = xbt_dict_length(_to_index);
1843 xbt_dict_set(_to_index,name,id,xbt_free);
1846 static void generic_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
1847 DEBUG2("Load Route from \"%s\" to \"%s\"",src,dst);
1848 printf("Load Route from \"%s\" to \"%s\"\n",src,dst);
1849 model_type_t modeltype = rc->routing;
1850 xbt_dict_t _parse_routes;
1851 xbt_dict_t _to_index;
1853 int *src_id, *dst_id;
1855 if(modeltype==&routing_models[SURF_MODEL_FULL]) {
1856 _parse_routes = ((routing_component_full_t)rc)->parse_routes;
1857 _to_index = ((routing_component_full_t)rc)->to_index;
1859 } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) {
1860 _parse_routes = ((routing_component_floyd_t)rc)->parse_routes;
1861 _to_index = ((routing_component_floyd_t)rc)->to_index;
1863 } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1864 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) {
1865 _parse_routes = ((routing_component_dijkstra_t)rc)->parse_routes;
1866 _to_index = ((routing_component_dijkstra_t)rc)->to_index;
1868 } else xbt_die("\"generic_set_route\" not support");
1870 src_id = xbt_dict_get_or_null(_to_index, src);
1871 dst_id = xbt_dict_get_or_null(_to_index, dst);
1873 xbt_assert2(src_id&&dst_id,"Network elements %s or %s not found", src, dst);
1874 route_name = bprintf("%d#%d",*src_id,*dst_id);
1876 xbt_assert2(xbt_dynar_length(route->link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
1877 xbt_assert2(!xbt_dict_get_or_null(_parse_routes,route_name),
1878 "The route between \"%s\" and \"%s\" already exist",src,dst);
1880 xbt_dict_set(_parse_routes, route_name, route, NULL);
1881 xbt_free(route_name);
1884 static void generic_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
1885 DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway);
1886 printf("Load ASroute from \"%s(%s)\" to \"%s(%s)\"\n",src,e_route->src_gateway,dst,e_route->dst_gateway);
1887 model_type_t modeltype = rc->routing;
1888 xbt_dict_t _parse_routes;
1889 xbt_dict_t _to_index;
1891 int *src_id, *dst_id;
1893 if(modeltype==&routing_models[SURF_MODEL_FULL]) {
1894 _parse_routes = ((routing_component_full_t)rc)->parse_routes;
1895 _to_index = ((routing_component_full_t)rc)->to_index;
1897 } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) {
1898 _parse_routes = ((routing_component_floyd_t)rc)->parse_routes;
1899 _to_index = ((routing_component_floyd_t)rc)->to_index;
1901 } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1902 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) {
1903 _parse_routes = ((routing_component_dijkstra_t)rc)->parse_routes;
1904 _to_index = ((routing_component_dijkstra_t)rc)->to_index;
1906 } else xbt_die("\"generic_set_route\" not support");
1908 src_id = xbt_dict_get_or_null(_to_index, src);
1909 dst_id = xbt_dict_get_or_null(_to_index, dst);
1911 xbt_assert2(src_id&&dst_id,"Network elements %s or %s not found", src, dst);
1912 route_name = bprintf("%d#%d",*src_id,*dst_id);
1914 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
1915 xbt_assert4(!xbt_dict_get_or_null(_parse_routes,route_name),
1916 "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",src,e_route->src_gateway,dst,e_route->dst_gateway);
1918 xbt_dict_set(_parse_routes, route_name, e_route, NULL);
1919 xbt_free(route_name);
1922 static void generic_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
1923 DEBUG2("Load bypassRoute from \"%s\" to \"%s\"",src,dst);
1924 model_type_t modeltype = rc->routing;
1925 xbt_dict_t dict_bypassRoutes;
1927 if(modeltype==&routing_models[SURF_MODEL_FULL]) {
1928 dict_bypassRoutes = ((routing_component_full_t)rc)->bypassRoutes;
1929 } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) {
1930 dict_bypassRoutes = ((routing_component_floyd_t)rc)->bypassRoutes;
1931 } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1932 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) {
1933 dict_bypassRoutes = ((routing_component_dijkstra_t)rc)->bypassRoutes;
1934 } else xbt_die("\"generic_set_bypassroute\" not support");
1935 route_name = bprintf("%s#%s",src,dst);
1936 xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst);
1937 xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes,route_name),
1938 "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",src,e_route->src_gateway,dst,e_route->dst_gateway);
1940 route_extended_t new_e_route = generic_new_extended_route(SURF_ROUTING_RECURSIVE,e_route,0);
1941 xbt_dynar_free( &(e_route->generic_route.link_list) );
1944 xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, (void(*)(void*))generic_free_extended_route );
1945 xbt_free(route_name);
1948 /* ************************************************************************** */
1949 /* *********************** GENERIC BUSINESS METHODS ************************* */
1951 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst) {
1952 model_type_t modeltype = rc->routing;
1953 xbt_dict_t dict_bypassRoutes;
1955 if(modeltype==&routing_models[SURF_MODEL_FULL]) {
1956 dict_bypassRoutes = ((routing_component_full_t)rc)->bypassRoutes;
1957 } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) {
1958 dict_bypassRoutes = ((routing_component_floyd_t)rc)->bypassRoutes;
1959 } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]||
1960 modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) {
1961 dict_bypassRoutes = ((routing_component_dijkstra_t)rc)->bypassRoutes;
1962 } else xbt_die("\"generic_set_bypassroute\" not support");
1965 routing_component_t src_as, dst_as;
1966 int index_src, index_dst;
1967 xbt_dynar_t path_src = NULL;
1968 xbt_dynar_t path_dst = NULL;
1969 routing_component_t current = NULL;
1970 routing_component_t* current_src = NULL;
1971 routing_component_t* current_dst = NULL;
1973 /* (1) find the as where the src and dst are located */
1974 src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
1975 dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
1976 xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst);
1978 /* (2) find the path to the root routing component */
1979 path_src = xbt_dynar_new(sizeof(routing_component_t), NULL);
1981 while( current != NULL ) {
1982 xbt_dynar_push(path_src,¤t);
1983 current = current->routing_father;
1985 path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL);
1987 while( current != NULL ) {
1988 xbt_dynar_push(path_dst,¤t);
1989 current = current->routing_father;
1992 /* (3) find the common father */
1993 index_src = (path_src->used)-1;
1994 index_dst = (path_dst->used)-1;
1995 current_src = xbt_dynar_get_ptr(path_src,index_src);
1996 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
1997 while( index_src >= 0 && index_dst >= 0 && *current_src == *current_dst ) {
1998 routing_component_t *tmp_src,*tmp_dst;
1999 tmp_src = xbt_dynar_pop_ptr(path_src);
2000 tmp_dst = xbt_dynar_pop_ptr(path_dst);
2003 current_src = xbt_dynar_get_ptr(path_src,index_src);
2004 current_dst = xbt_dynar_get_ptr(path_dst,index_dst);
2007 int max_index_src = (path_src->used)-1;
2008 int max_index_dst = (path_dst->used)-1;
2010 int max_index = max(max_index_src,max_index_dst);
2013 route_extended_t e_route_bypass = NULL;
2015 for( max=0;max<=max_index;max++)
2019 if( i <= max_index_src && max <= max_index_dst ) {
2020 char* route_name = bprintf("%s#%s",
2021 (*(routing_component_t*)(xbt_dynar_get_ptr(path_src,i)))->name,
2022 (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,max)))->name);
2023 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name);
2024 xbt_free(route_name);
2026 if( e_route_bypass ) break;
2027 if( max <= max_index_src && i <= max_index_dst ) {
2028 char* route_name = bprintf("%s#%s",
2029 (*(routing_component_t*)(xbt_dynar_get_ptr(path_src,max)))->name,
2030 (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,i)))->name);
2031 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name);
2032 xbt_free(route_name);
2034 if( e_route_bypass ) break;
2037 if( e_route_bypass ) break;
2039 if( max <= max_index_src && max <= max_index_dst ) {
2040 char* route_name = bprintf("%s#%s",
2041 (*(routing_component_t*)(xbt_dynar_get_ptr(path_src,max)))->name,
2042 (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,max)))->name);
2043 e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name);
2044 xbt_free(route_name);
2046 if( e_route_bypass ) break;
2049 xbt_dynar_free(&path_src);
2050 xbt_dynar_free(&path_dst);
2052 route_extended_t new_e_route = NULL;
2054 if(e_route_bypass) {
2057 new_e_route = xbt_new0(s_route_extended_t,1);
2058 new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway);
2059 new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway);
2060 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
2061 xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) {
2062 xbt_dynar_push(new_e_route->generic_route.link_list,&link);
2069 /* ************************************************************************** */
2070 /* ************************* GENERIC AUX FUNCTIONS ************************** */
2072 static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order) {
2075 route_extended_t e_route, new_e_route;
2078 xbt_dynar_t links, links_id;
2080 new_e_route = xbt_new0(s_route_extended_t,1);
2081 new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
2082 new_e_route->src_gateway = NULL;
2083 new_e_route->dst_gateway = NULL;
2085 xbt_assert0(hierarchy == SURF_ROUTING_BASE || hierarchy == SURF_ROUTING_RECURSIVE,
2086 "the hierarchy type is not defined");
2088 if(hierarchy == SURF_ROUTING_BASE ) {
2090 route = (route_t)data;
2091 links = route->link_list;
2093 } else if(hierarchy == SURF_ROUTING_RECURSIVE ) {
2095 e_route = (route_extended_t)data;
2096 xbt_assert0(e_route->src_gateway&&e_route->dst_gateway,"bad gateway, is null");
2097 links = e_route->generic_route.link_list;
2099 /* remeber not erase the gateway names */
2100 new_e_route->src_gateway = e_route->src_gateway;
2101 new_e_route->dst_gateway = e_route->dst_gateway;
2104 links_id = new_e_route->generic_route.link_list;
2106 xbt_dynar_foreach(links, cpt, link_name) {
2108 void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name);
2112 xbt_dynar_push(links_id,&link);
2114 xbt_dynar_unshift(links_id,&link);
2117 THROW1(mismatch_error,0,"Link %s not found", link_name);
2123 static void generic_free_route(route_t route) {
2125 xbt_dynar_free(&(route->link_list));
2130 static void generic_free_extended_route(route_extended_t e_route) {
2132 xbt_dynar_free(&(e_route->generic_route.link_list));
2133 if(e_route->src_gateway) xbt_free(e_route->src_gateway);
2134 if(e_route->dst_gateway) xbt_free(e_route->dst_gateway);
2139 static routing_component_t generic_as_exist(routing_component_t find_from, routing_component_t to_find) {
2140 //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
2141 xbt_dict_cursor_t cursor = NULL;
2144 routing_component_t elem;
2145 xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
2146 if( to_find == elem || generic_as_exist(elem,to_find) ){
2151 if(found) return to_find;
2155 static routing_component_t generic_autonomous_system_exist(routing_component_t rc, char* element) {
2156 //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
2157 routing_component_t element_as, result, elem;
2158 xbt_dict_cursor_t cursor = NULL;
2160 element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
2161 result = ((routing_component_t)-1);
2163 result = generic_as_exist(rc,element_as);
2168 xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
2169 found = !strcmp(elem->name,element);
2172 if( found ) return element_as;
2177 static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element) {
2178 routing_component_t element_as;
2179 element_as = xbt_dict_get_or_null(global_routing->where_network_elements,element);
2180 if(element_as==rc) return element_as;
2181 return generic_as_exist(rc,element_as);
2184 static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst) {
2186 routing_component_t src_as = xbt_dict_get_or_null(global_routing->where_network_elements,src);
2187 routing_component_t dst_as = xbt_dict_get_or_null(global_routing->where_network_elements,dst);
2189 xbt_assert3(src_as != NULL && dst_as != NULL,
2190 "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",src,dst,rc->name);
2191 xbt_assert4(src_as == dst_as,
2192 "The src(%s in %s) and dst(%s in %s) are in differents AS",src,src_as->name,dst,dst_as->name);
2193 xbt_assert2(rc == dst_as,
2194 "The routing component of src and dst is not the same as the network elements belong (%s==%s)",rc->name,dst_as->name);
2197 static void routing_full_parse_Scluster(void)
2200 char *cluster_id = A_surfxml_cluster_id;
2201 char *cluster_prefix = A_surfxml_cluster_prefix;
2202 char *cluster_suffix = A_surfxml_cluster_suffix;
2203 char *cluster_radical = A_surfxml_cluster_radical;
2204 char *cluster_power = A_surfxml_cluster_power;
2205 char *cluster_bw = A_surfxml_cluster_bw;
2206 char *cluster_lat = A_surfxml_cluster_lat;
2207 char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
2208 char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
2209 char *host_id, *groups, *link_id;
2210 char *router_id, *link_router, *link_backbone, *route_src_dst;
2213 xbt_dynar_t radical_elements;
2214 xbt_dynar_t radical_ends;
2215 static int AX_ptr = 0;
2216 static int surfxml_bufferstack_size = 2048;
2218 /* allocating memory for the buffer, I think 2kB should be enough */
2219 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
2221 // DEBUG4("id='%s' prefix='%s' suffix='%s' radical='%s'",
2222 // cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
2223 // DEBUG5("power='%s' bw='%s' lat='%s' bb_bw='%s' bb_lat='%s'",
2224 // cluster_power,cluster_bw,cluster_lat,cluster_bb_bw,cluster_bb_lat);
2226 DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
2227 SURFXML_BUFFER_SET(AS_id, cluster_id);
2228 SURFXML_BUFFER_SET(AS_routing, "RuleBased");
2229 SURFXML_START_TAG(AS);
2231 radical_elements = xbt_str_split(cluster_radical, ",");
2232 xbt_dynar_foreach(radical_elements, iter, groups)
2234 radical_ends = xbt_str_split(groups, "-");
2235 switch (xbt_dynar_length(radical_ends))
2238 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
2239 host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
2240 link_id = bprintf("%s_link_%d", cluster_id, start);
2242 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
2243 SURFXML_BUFFER_RESET();
2244 SURFXML_BUFFER_SET(host_id, host_id);
2245 SURFXML_BUFFER_SET(host_power, cluster_power);
2246 SURFXML_BUFFER_SET(host_availability, "1.0");
2247 SURFXML_BUFFER_SET(host_availability_file, "");
2248 A_surfxml_host_state = A_surfxml_host_state_ON;
2249 SURFXML_BUFFER_SET(host_state_file, "");
2250 SURFXML_BUFFER_SET(host_interference_send, "1.0");
2251 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
2252 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
2253 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
2254 SURFXML_START_TAG(host);
2255 SURFXML_END_TAG(host);
2257 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
2258 SURFXML_BUFFER_RESET();
2259 SURFXML_BUFFER_SET(link_id, link_id);
2260 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
2261 SURFXML_BUFFER_SET(link_latency, cluster_lat);
2262 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2263 SURFXML_BUFFER_SET(link_latency_file, "");
2264 A_surfxml_link_state = A_surfxml_link_state_ON;
2265 SURFXML_BUFFER_SET(link_state_file, "");
2266 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2267 SURFXML_START_TAG(link);
2268 SURFXML_END_TAG(link);
2274 surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *));
2275 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
2276 for (i = start; i <= end; i++)
2278 host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
2279 link_id = bprintf("%s_link_%d", cluster_id, i);
2281 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
2282 SURFXML_BUFFER_RESET();
2283 SURFXML_BUFFER_SET(host_id, host_id);
2284 SURFXML_BUFFER_SET(host_power, cluster_power);
2285 SURFXML_BUFFER_SET(host_availability, "1.0");
2286 SURFXML_BUFFER_SET(host_availability_file, "");
2287 A_surfxml_host_state = A_surfxml_host_state_ON;
2288 SURFXML_BUFFER_SET(host_state_file, "");
2289 SURFXML_BUFFER_SET(host_interference_send, "1.0");
2290 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
2291 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
2292 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
2293 SURFXML_START_TAG(host);
2294 SURFXML_END_TAG(host);
2296 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
2297 SURFXML_BUFFER_RESET();
2298 SURFXML_BUFFER_SET(link_id, link_id);
2299 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
2300 SURFXML_BUFFER_SET(link_latency, cluster_lat);
2301 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2302 SURFXML_BUFFER_SET(link_latency_file, "");
2303 A_surfxml_link_state = A_surfxml_link_state_ON;
2304 SURFXML_BUFFER_SET(link_state_file, "");
2305 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2306 SURFXML_START_TAG(link);
2307 SURFXML_END_TAG(link);
2312 DEBUG0("Malformed radical");
2315 xbt_dynar_free(&radical_ends);
2319 router_id = bprintf("%srouter%s",cluster_prefix,cluster_suffix);
2320 link_router = bprintf("%s_link_router",cluster_id);
2321 link_backbone = bprintf("%s_backbone",cluster_id);
2323 DEBUG1("<router id=\"%s\"\">",router_id);
2324 SURFXML_BUFFER_RESET();
2325 SURFXML_BUFFER_SET(router_id, router_id);;
2326 SURFXML_START_TAG(router);
2327 SURFXML_END_TAG(router);
2329 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_router,cluster_bw,cluster_lat);
2330 SURFXML_BUFFER_RESET();
2331 SURFXML_BUFFER_SET(link_id, link_router);
2332 SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
2333 SURFXML_BUFFER_SET(link_latency, cluster_lat);
2334 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2335 SURFXML_BUFFER_SET(link_latency_file, "");
2336 A_surfxml_link_state = A_surfxml_link_state_ON;
2337 SURFXML_BUFFER_SET(link_state_file, "");
2338 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2339 SURFXML_START_TAG(link);
2340 SURFXML_END_TAG(link);
2342 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_backbone,cluster_bb_bw,cluster_bb_lat);
2343 SURFXML_BUFFER_RESET();
2344 SURFXML_BUFFER_SET(link_id, link_backbone);
2345 SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
2346 SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
2347 SURFXML_BUFFER_SET(link_bandwidth_file, "");
2348 SURFXML_BUFFER_SET(link_latency_file, "");
2349 A_surfxml_link_state = A_surfxml_link_state_ON;
2350 SURFXML_BUFFER_SET(link_state_file, "");
2351 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
2352 SURFXML_START_TAG(link);
2353 SURFXML_END_TAG(link);
2355 char *new_suffix = bprintf("%s","");
2357 radical_elements = xbt_str_split(cluster_suffix, ".");
2358 xbt_dynar_foreach(radical_elements, iter, groups)
2360 if(strcmp(groups,""))
2362 new_suffix = bprintf("%s\\.%s",new_suffix,groups);
2365 route_src_dst = bprintf("%s(.*)%s",cluster_prefix,new_suffix);
2369 DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
2370 SURFXML_BUFFER_RESET();
2371 SURFXML_BUFFER_SET(route_src, route_src_dst);
2372 SURFXML_BUFFER_SET(route_dst, route_src_dst);
2373 SURFXML_START_TAG(route);
2375 DEBUG1("<link:ctn\tid=\"%s_link_$1src\"/>",cluster_id);
2376 SURFXML_BUFFER_RESET();
2377 SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1src",cluster_id));
2378 SURFXML_START_TAG(link_c_ctn);
2379 SURFXML_END_TAG(link_c_ctn);
2381 DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
2382 SURFXML_BUFFER_RESET();
2383 SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_backbone",cluster_id));
2384 SURFXML_START_TAG(link_c_ctn);
2385 SURFXML_END_TAG(link_c_ctn);
2387 DEBUG1("<link:ctn\tid=\"%s_link_$1dst\"/>",cluster_id);
2388 SURFXML_BUFFER_RESET();
2389 SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1dst",cluster_id));
2390 SURFXML_START_TAG(link_c_ctn);
2391 SURFXML_END_TAG(link_c_ctn);
2394 SURFXML_END_TAG(route);
2397 SURFXML_END_TAG(AS);